Dawn: Deprecate DiscoverAdapters with DiscoverPhysicalDevices
This CL deprecate Discover[Default]Adapters and replace them with
Discover[Default]PhysicalDevices. This help clearify the behavior of
discovering physical devices and requesting / getting adapters, and
prepare for adding adapter toggles in GetAdapters.
Related end-to-end tests AdapterDiscoveryTests are split into
PhysicalDeviceDiscoveryTests and AdapterCreationTests as well.
Bug: dawn:1774, dawn:1495
Change-Id: Iac3d9da3022e5eb3c6dd6b3e3b2224f523792289
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133968
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/include/dawn/native/D3D11Backend.h b/include/dawn/native/D3D11Backend.h
index b090071..5fae956 100644
--- a/include/dawn/native/D3D11Backend.h
+++ b/include/dawn/native/D3D11Backend.h
@@ -25,11 +25,15 @@
namespace dawn::native::d3d11 {
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public d3d::AdapterDiscoveryOptions {
- AdapterDiscoveryOptions();
- explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public d3d::PhysicalDeviceDiscoveryOptions {
+ PhysicalDeviceDiscoveryOptions();
+ explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device(WGPUDevice device);
} // namespace dawn::native::d3d11
diff --git a/include/dawn/native/D3D12Backend.h b/include/dawn/native/D3D12Backend.h
index cb14805..eb0ca2b 100644
--- a/include/dawn/native/D3D12Backend.h
+++ b/include/dawn/native/D3D12Backend.h
@@ -38,11 +38,15 @@
uint64_t requestedReservationSize,
MemorySegment memorySegment);
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public d3d::AdapterDiscoveryOptions {
- AdapterDiscoveryOptions();
- explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public d3d::PhysicalDeviceDiscoveryOptions {
+ PhysicalDeviceDiscoveryOptions();
+ explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
} // namespace dawn::native::d3d12
#endif // INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
diff --git a/include/dawn/native/D3DBackend.h b/include/dawn/native/D3DBackend.h
index 590f8fa..d791d3e 100644
--- a/include/dawn/native/D3DBackend.h
+++ b/include/dawn/native/D3DBackend.h
@@ -30,11 +30,16 @@
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter);
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
- AdapterDiscoveryOptions(WGPUBackendType type, Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public PhysicalDeviceDiscoveryOptionsBase {
+ PhysicalDeviceDiscoveryOptions(WGPUBackendType type,
+ Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor {
public:
ExternalImageDescriptorDXGISharedHandle();
diff --git a/include/dawn/native/DawnNative.h b/include/dawn/native/DawnNative.h
index 477c57d..9ebaae8 100644
--- a/include/dawn/native/DawnNative.h
+++ b/include/dawn/native/DawnNative.h
@@ -118,15 +118,19 @@
AdapterBase* mImpl = nullptr;
};
-// Base class for options passed to Instance::DiscoverAdapters.
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
+// Base class for options passed to Instance::DiscoverPhysicalDevices.
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptionsBase {
public:
const WGPUBackendType backendType;
protected:
- explicit AdapterDiscoveryOptionsBase(WGPUBackendType type);
+ explicit PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType type);
};
+// Deprecated, use PhysicalDeviceDiscoveryOptionsBase instead.
+// TODO(dawn:1774): Remove this.
+using AdapterDiscoveryOptionsBase = PhysicalDeviceDiscoveryOptionsBase;
+
enum BackendValidationLevel { Full, Partial, Disabled };
// Can be chained in InstanceDescriptor
@@ -156,15 +160,20 @@
Instance(const Instance& other) = delete;
Instance& operator=(const Instance& other) = delete;
- // Gather all adapters in the system that can be accessed with no special options. These
- // adapters will later be returned by GetAdapters.
- void DiscoverDefaultAdapters();
+ // Gather all physical devices in the system that can be accessed with no special options.
+ void DiscoverDefaultPhysicalDevices();
- // Adds adapters that can be discovered with the options provided (like a getProcAddress).
- // The backend is chosen based on the type of the options used. Returns true on success.
+ // Adds physical devices that can be discovered with the options provided (like a
+ // getProcAddress). The backend is chosen based on the type of the options used. Returns true on
+ // success.
+ bool DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options);
+
+ // Deprecated, use DiscoverDefaultPhysicalDevices and DiscoverPhysicalDevices instead.
+ // TODO(Dawn:1774): Remove these.
+ void DiscoverDefaultAdapters();
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
- // Returns all the adapters that the instance knows about.
+ // Returns a vector of adapters, one for each physical device the instance knows about.
std::vector<Adapter> GetAdapters() const;
const ToggleInfo* GetToggleInfo(const char* toggleName);
diff --git a/include/dawn/native/MetalBackend.h b/include/dawn/native/MetalBackend.h
index a41cb6b..c401d7d 100644
--- a/include/dawn/native/MetalBackend.h
+++ b/include/dawn/native/MetalBackend.h
@@ -35,10 +35,14 @@
namespace dawn::native::metal {
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
- AdapterDiscoveryOptions();
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public PhysicalDeviceDiscoveryOptionsBase {
+ PhysicalDeviceDiscoveryOptions();
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
struct DAWN_NATIVE_EXPORT ExternalImageMTLSharedEventDescriptor {
// Shared event handle `id<MTLSharedEvent>`.
// This never passes ownership to the callee (when used as an input
diff --git a/include/dawn/native/OpenGLBackend.h b/include/dawn/native/OpenGLBackend.h
index fd41b70..580c444 100644
--- a/include/dawn/native/OpenGLBackend.h
+++ b/include/dawn/native/OpenGLBackend.h
@@ -21,14 +21,18 @@
namespace dawn::native::opengl {
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
- explicit AdapterDiscoveryOptions(WGPUBackendType type);
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public PhysicalDeviceDiscoveryOptionsBase {
+ explicit PhysicalDeviceDiscoveryOptions(WGPUBackendType type);
void* (*getProc)(const char*);
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
// TODO(crbug.com/dawn/810): This struct can be removed once Chrome is no longer using it.
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public AdapterDiscoveryOptions {
+struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public PhysicalDeviceDiscoveryOptions {
AdapterDiscoveryOptionsES();
};
diff --git a/include/dawn/native/VulkanBackend.h b/include/dawn/native/VulkanBackend.h
index a056356..a677388 100644
--- a/include/dawn/native/VulkanBackend.h
+++ b/include/dawn/native/VulkanBackend.h
@@ -28,12 +28,16 @@
DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, const char* pName);
-struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
- AdapterDiscoveryOptions();
+struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
+ : public PhysicalDeviceDiscoveryOptionsBase {
+ PhysicalDeviceDiscoveryOptions();
bool forceSwiftShader = false;
};
+// TODO(dawn:1774): Deprecated.
+using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
+
enum class NeedsDedicatedAllocation {
Yes,
No,
diff --git a/src/dawn/fuzzers/DawnWireServerFuzzer.cpp b/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
index 406be4c..fdd288b 100644
--- a/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
+++ b/src/dawn/fuzzers/DawnWireServerFuzzer.cpp
@@ -70,7 +70,7 @@
sVulkanLoader.Open(dawn::GetExecutableDirectory().value_or("") + "vulkan-1.dll");
#endif
- sInstance->DiscoverDefaultAdapters();
+ sInstance->DiscoverDefaultPhysicalDevices();
return 0;
}
diff --git a/src/dawn/native/BackendConnection.cpp b/src/dawn/native/BackendConnection.cpp
index 8d4dd6a..8863403 100644
--- a/src/dawn/native/BackendConnection.cpp
+++ b/src/dawn/native/BackendConnection.cpp
@@ -28,9 +28,9 @@
return mInstance;
}
-ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* options) {
- return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend.");
+ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* options) {
+ return DAWN_VALIDATION_ERROR("DiscoverPhysicalDevices not implemented for this backend.");
}
} // namespace dawn::native
diff --git a/src/dawn/native/BackendConnection.h b/src/dawn/native/BackendConnection.h
index 920141a..951a781 100644
--- a/src/dawn/native/BackendConnection.h
+++ b/src/dawn/native/BackendConnection.h
@@ -34,13 +34,13 @@
wgpu::BackendType GetType() const;
InstanceBase* GetInstance() const;
- // Returns all the adapters for the system that can be created by the backend, without extra
- // options (such as debug adapters, custom driver libraries, etc.)
- virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() = 0;
+ // Returns all the physical devices for the system that can be created by the backend, without
+ // extra options (such as debug adapters, custom driver libraries, etc.)
+ virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() = 0;
- // Returns new adapters created with the backend-specific options.
- virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* options);
+ // Returns new physical devices created with the backend-specific options.
+ virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* options);
private:
InstanceBase* mInstance = nullptr;
diff --git a/src/dawn/native/DawnNative.cpp b/src/dawn/native/DawnNative.cpp
index 2de16e7..6594b64 100644
--- a/src/dawn/native/DawnNative.cpp
+++ b/src/dawn/native/DawnNative.cpp
@@ -132,7 +132,7 @@
// AdapterDiscoverOptionsBase
-AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type)
+PhysicalDeviceDiscoveryOptionsBase::PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType type)
: backendType(type) {}
// DawnInstanceDescriptor
@@ -162,12 +162,22 @@
}
}
-void Instance::DiscoverDefaultAdapters() {
- mImpl->DiscoverDefaultAdapters();
+void Instance::DiscoverDefaultPhysicalDevices() {
+ mImpl->DiscoverDefaultPhysicalDevices();
}
+bool Instance::DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options) {
+ return mImpl->DiscoverPhysicalDevices(options);
+}
+
+// Deprecated.
+void Instance::DiscoverDefaultAdapters() {
+ mImpl->DiscoverDefaultPhysicalDevices();
+}
+
+// Deprecated.
bool Instance::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) {
- return mImpl->DiscoverAdapters(options);
+ return mImpl->DiscoverPhysicalDevices(options);
}
std::vector<Adapter> Instance::GetAdapters() const {
diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp
index 98482e1..f84becf 100644
--- a/src/dawn/native/Instance.cpp
+++ b/src/dawn/native/Instance.cpp
@@ -217,10 +217,10 @@
if (options->forceFallbackAdapter) {
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
if (GetEnabledBackends()[wgpu::BackendType::Vulkan]) {
- dawn_native::vulkan::AdapterDiscoveryOptions vulkanOptions;
+ dawn_native::vulkan::PhysicalDeviceDiscoveryOptions vulkanOptions;
vulkanOptions.forceSwiftShader = true;
- MaybeError result = DiscoverAdaptersInternal(&vulkanOptions);
+ MaybeError result = DiscoverPhysicalDevicesInternal(&vulkanOptions);
if (result.IsError()) {
dawn::WarningLog() << absl::StrFormat(
"Skipping Vulkan Swiftshader adapter because initialization failed: %s",
@@ -232,7 +232,7 @@
return Ref<AdapterBase>(nullptr);
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
} else {
- DiscoverDefaultAdapters();
+ DiscoverDefaultPhysicalDevices();
}
wgpu::AdapterType preferredType;
@@ -314,7 +314,7 @@
new AdapterBase(std::move(selectedPhysicalDevice), featureLevel, adapterToggles));
}
-void InstanceBase::DiscoverDefaultAdapters() {
+void InstanceBase::DiscoverDefaultPhysicalDevices() {
for (wgpu::BackendType b : IterateBitSet(GetEnabledBackends())) {
EnsureBackendConnection(b);
}
@@ -325,7 +325,8 @@
// Query and merge all default adapters for all backends
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
- std::vector<Ref<PhysicalDeviceBase>> physicalDevices = backend->DiscoverDefaultAdapters();
+ std::vector<Ref<PhysicalDeviceBase>> physicalDevices =
+ backend->DiscoverDefaultPhysicalDevices();
for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
@@ -338,8 +339,8 @@
}
// This is just a wrapper around the real logic that uses Error.h error handling.
-bool InstanceBase::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) {
- MaybeError result = DiscoverAdaptersInternal(options);
+bool InstanceBase::DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options) {
+ MaybeError result = DiscoverPhysicalDevicesInternal(options);
if (result.IsError()) {
dawn::WarningLog() << absl::StrFormat(
@@ -450,7 +451,8 @@
mBackendsConnected.set(backendType);
}
-MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options) {
+MaybeError InstanceBase::DiscoverPhysicalDevicesInternal(
+ const PhysicalDeviceDiscoveryOptionsBase* options) {
wgpu::BackendType backendType = static_cast<wgpu::BackendType>(options->backendType);
DAWN_TRY(ValidateBackendType(backendType));
@@ -468,7 +470,7 @@
foundBackend = true;
std::vector<Ref<PhysicalDeviceBase>> newPhysicalDevices;
- DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options));
+ DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverPhysicalDevices(options));
for (Ref<PhysicalDeviceBase>& physicalDevice : newPhysicalDevices) {
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
diff --git a/src/dawn/native/Instance.h b/src/dawn/native/Instance.h
index b149e6d..aabb9a6 100644
--- a/src/dawn/native/Instance.h
+++ b/src/dawn/native/Instance.h
@@ -58,9 +58,10 @@
WGPURequestAdapterCallback callback,
void* userdata);
- void DiscoverDefaultAdapters();
- bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
+ void DiscoverDefaultPhysicalDevices();
+ bool DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options);
+ // Return adapters created on every known physical device.
std::vector<Ref<AdapterBase>> GetAdapters() const;
// Used to handle error that happen up to device creation.
@@ -134,7 +135,7 @@
// Lazily creates connections to all backends that have been compiled.
void EnsureBackendConnection(wgpu::BackendType backendType);
- MaybeError DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options);
+ MaybeError DiscoverPhysicalDevicesInternal(const PhysicalDeviceDiscoveryOptionsBase* options);
ResultOrError<Ref<AdapterBase>> RequestAdapterInternal(const RequestAdapterOptions* options);
diff --git a/src/dawn/native/d3d/BackendD3D.cpp b/src/dawn/native/d3d/BackendD3D.cpp
index a9006f4..9d99870 100644
--- a/src/dawn/native/d3d/BackendD3D.cpp
+++ b/src/dawn/native/d3d/BackendD3D.cpp
@@ -238,35 +238,35 @@
return mFunctions.get();
}
-std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
- AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr);
- std::vector<Ref<PhysicalDeviceBase>> adapters;
- if (GetInstance()->ConsumedError(DiscoverAdapters(&options), &adapters)) {
+std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
+ PhysicalDeviceDiscoveryOptions options(ToAPI(GetType()), nullptr);
+ std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
+ if (GetInstance()->ConsumedError(DiscoverPhysicalDevices(&options), &physicalDevices)) {
return {};
}
- return adapters;
+ return physicalDevices;
}
-ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) {
+ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == ToAPI(GetType()));
- const AdapterDiscoveryOptions* options =
- static_cast<const AdapterDiscoveryOptions*>(optionsBase);
+ const PhysicalDeviceDiscoveryOptions* options =
+ static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
- std::vector<Ref<PhysicalDeviceBase>> adapters;
+ std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
if (options->dxgiAdapter != nullptr) {
// |dxgiAdapter| was provided. Discover just that adapter.
Ref<PhysicalDeviceBase> adapter;
DAWN_TRY_ASSIGN(adapter, CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter));
- adapters.push_back(std::move(adapter));
- return std::move(adapters);
+ physicalDevices.push_back(std::move(adapter));
+ return std::move(physicalDevices);
}
- // Enumerate and discover all available adapters.
+ // Enumerate and discover all available physicalDevices.
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
if (GetFactory()->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
- break; // No more adapters to enumerate.
+ break; // No more physicalDevices to enumerate.
}
ASSERT(dxgiAdapter != nullptr);
@@ -276,10 +276,10 @@
continue;
}
- adapters.push_back(std::move(adapter));
+ physicalDevices.push_back(std::move(adapter));
}
- return adapters;
+ return physicalDevices;
}
} // namespace dawn::native::d3d
diff --git a/src/dawn/native/d3d/BackendD3D.h b/src/dawn/native/d3d/BackendD3D.h
index 957dad7..261e59f 100644
--- a/src/dawn/native/d3d/BackendD3D.h
+++ b/src/dawn/native/d3d/BackendD3D.h
@@ -75,9 +75,9 @@
const PlatformFunctions* GetFunctions() const;
- std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
- ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) override;
+ std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
+ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
protected:
virtual ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
diff --git a/src/dawn/native/d3d/D3DBackend.cpp b/src/dawn/native/d3d/D3DBackend.cpp
index c03d4e8..063fa23 100644
--- a/src/dawn/native/d3d/D3DBackend.cpp
+++ b/src/dawn/native/d3d/D3DBackend.cpp
@@ -33,9 +33,10 @@
return ToBackend(FromAPI(adapter)->GetPhysicalDevice())->GetHardwareAdapter();
}
-AdapterDiscoveryOptions::AdapterDiscoveryOptions(WGPUBackendType type,
- Microsoft::WRL::ComPtr<IDXGIAdapter> adapter)
- : AdapterDiscoveryOptionsBase(type), dxgiAdapter(std::move(adapter)) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(
+ WGPUBackendType type,
+ Microsoft::WRL::ComPtr<IDXGIAdapter> adapter)
+ : PhysicalDeviceDiscoveryOptionsBase(type), dxgiAdapter(std::move(adapter)) {}
ExternalImageDescriptorDXGISharedHandle::ExternalImageDescriptorDXGISharedHandle()
: ExternalImageDescriptor(ExternalImageType::DXGISharedHandle) {}
diff --git a/src/dawn/native/d3d11/D3D11Backend.cpp b/src/dawn/native/d3d11/D3D11Backend.cpp
index f4d4c08..a7d7168 100644
--- a/src/dawn/native/d3d11/D3D11Backend.cpp
+++ b/src/dawn/native/d3d11/D3D11Backend.cpp
@@ -25,10 +25,11 @@
namespace dawn::native::d3d11 {
-AdapterDiscoveryOptions::AdapterDiscoveryOptions() : AdapterDiscoveryOptions(nullptr) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
+ : PhysicalDeviceDiscoveryOptions(nullptr) {}
-AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
- : d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
+ : d3d::PhysicalDeviceDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {}
Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device(WGPUDevice device) {
return ToBackend(FromAPI(device))->GetD3D11Device();
diff --git a/src/dawn/native/d3d12/D3D12Backend.cpp b/src/dawn/native/d3d12/D3D12Backend.cpp
index db693ed..bd5c5e7 100644
--- a/src/dawn/native/d3d12/D3D12Backend.cpp
+++ b/src/dawn/native/d3d12/D3D12Backend.cpp
@@ -39,9 +39,10 @@
memorySegment, requestedReservationSize);
}
-AdapterDiscoveryOptions::AdapterDiscoveryOptions() : AdapterDiscoveryOptions(nullptr) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
+ : PhysicalDeviceDiscoveryOptions(nullptr) {}
-AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
- : d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D12, std::move(adapter)) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
+ : d3d::PhysicalDeviceDiscoveryOptions(WGPUBackendType_D3D12, std::move(adapter)) {}
} // namespace dawn::native::d3d12
diff --git a/src/dawn/native/metal/BackendMTL.h b/src/dawn/native/metal/BackendMTL.h
index c8abec1..d87dd54 100644
--- a/src/dawn/native/metal/BackendMTL.h
+++ b/src/dawn/native/metal/BackendMTL.h
@@ -26,9 +26,9 @@
explicit Backend(InstanceBase* instance);
~Backend() override;
- std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
- ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) override;
+ std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
+ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
};
} // namespace dawn::native::metal
diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm
index ff80849..79f70ee 100644
--- a/src/dawn/native/metal/BackendMTL.mm
+++ b/src/dawn/native/metal/BackendMTL.mm
@@ -819,9 +819,9 @@
Backend::~Backend() = default;
-std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
- AdapterDiscoveryOptions options;
- auto result = DiscoverAdapters(&options);
+std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
+ PhysicalDeviceDiscoveryOptions options;
+ auto result = DiscoverPhysicalDevices(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
return {};
@@ -829,8 +829,8 @@
return result.AcquireSuccess();
}
-ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) {
+ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == WGPUBackendType_Metal);
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
diff --git a/src/dawn/native/metal/MetalBackend.mm b/src/dawn/native/metal/MetalBackend.mm
index 0bbc265..e785c15 100644
--- a/src/dawn/native/metal/MetalBackend.mm
+++ b/src/dawn/native/metal/MetalBackend.mm
@@ -23,8 +23,8 @@
namespace dawn::native::metal {
-AdapterDiscoveryOptions::AdapterDiscoveryOptions()
- : AdapterDiscoveryOptionsBase(WGPUBackendType_Metal) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
+ : PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType_Metal) {}
ExternalImageDescriptorIOSurface::ExternalImageDescriptorIOSurface()
: ExternalImageDescriptor(ExternalImageType::IOSurface) {}
diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp
index 69f9411..0ea402b 100644
--- a/src/dawn/native/null/DeviceNull.cpp
+++ b/src/dawn/native/null/DeviceNull.cpp
@@ -86,7 +86,7 @@
explicit Backend(InstanceBase* instance)
: BackendConnection(instance, wgpu::BackendType::Null) {}
- std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override {
+ std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override {
// There is always a single Null adapter because it is purely CPU based and doesn't
// depend on the system.
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
diff --git a/src/dawn/native/opengl/BackendGL.cpp b/src/dawn/native/opengl/BackendGL.cpp
index 6915bb5..90ffd61 100644
--- a/src/dawn/native/opengl/BackendGL.cpp
+++ b/src/dawn/native/opengl/BackendGL.cpp
@@ -33,8 +33,8 @@
Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType)
: BackendConnection(instance, backendType) {}
-std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
- std::vector<Ref<PhysicalDeviceBase>> adapters;
+std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
+ std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
#if DAWN_PLATFORM_IS(WINDOWS)
const char* eglLib = "libEGL.dll";
#elif DAWN_PLATFORM_IS(MACOS)
@@ -46,7 +46,7 @@
return {};
}
- AdapterDiscoveryOptions options(ToAPI(GetType()));
+ PhysicalDeviceDiscoveryOptions options(ToAPI(GetType()));
options.getProc =
reinterpret_cast<void* (*)(const char*)>(mLibEGL.GetProc("eglGetProcAddress"));
if (!options.getProc) {
@@ -69,39 +69,41 @@
context->MakeCurrent();
- auto result = DiscoverAdapters(&options);
+ auto result = DiscoverPhysicalDevices(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
} else {
auto value = result.AcquireSuccess();
- adapters.insert(adapters.end(), value.begin(), value.end());
+ physicalDevices.insert(physicalDevices.end(), value.begin(), value.end());
}
egl.MakeCurrent(prevDisplay, prevDrawSurface, prevReadSurface, prevContext);
- return adapters;
+ return physicalDevices;
}
-ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) {
- // TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't
+ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
+ // TODO(cwallez@chromium.org): For now only create a single OpenGL physicalDevice because don't
// know how to handle MakeCurrent.
- DAWN_INVALID_IF(mCreatedAdapter, "The OpenGL backend can only create a single adapter.");
+ DAWN_INVALID_IF(mCreatedPhysicalDevice,
+ "The OpenGL backend can only create a single physicalDevice.");
ASSERT(static_cast<wgpu::BackendType>(optionsBase->backendType) == GetType());
- const AdapterDiscoveryOptions* options =
- static_cast<const AdapterDiscoveryOptions*>(optionsBase);
+ const PhysicalDeviceDiscoveryOptions* options =
+ static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
- DAWN_INVALID_IF(options->getProc == nullptr, "AdapterDiscoveryOptions::getProc must be set");
+ DAWN_INVALID_IF(options->getProc == nullptr,
+ "PhysicalDeviceDiscoveryOptions::getProc must be set");
- Ref<PhysicalDevice> adapter = AcquireRef(new PhysicalDevice(
+ Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(
GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType)));
- DAWN_TRY(adapter->InitializeGLFunctions(options->getProc));
- DAWN_TRY(adapter->Initialize());
+ DAWN_TRY(physicalDevice->InitializeGLFunctions(options->getProc));
+ DAWN_TRY(physicalDevice->Initialize());
- mCreatedAdapter = true;
- std::vector<Ref<PhysicalDeviceBase>> adapters{std::move(adapter)};
+ mCreatedPhysicalDevice = true;
+ std::vector<Ref<PhysicalDeviceBase>> adapters{std::move(physicalDevice)};
return std::move(adapters);
}
diff --git a/src/dawn/native/opengl/BackendGL.h b/src/dawn/native/opengl/BackendGL.h
index d427ed5..87b3cf2 100644
--- a/src/dawn/native/opengl/BackendGL.h
+++ b/src/dawn/native/opengl/BackendGL.h
@@ -26,12 +26,12 @@
public:
Backend(InstanceBase* instance, wgpu::BackendType backendType);
- std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
- ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* option) override;
+ std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
+ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* option) override;
private:
- bool mCreatedAdapter = false;
+ bool mCreatedPhysicalDevice = false;
DynamicLib mLibEGL;
};
diff --git a/src/dawn/native/opengl/OpenGLBackend.cpp b/src/dawn/native/opengl/OpenGLBackend.cpp
index 7a4c720..7606613 100644
--- a/src/dawn/native/opengl/OpenGLBackend.cpp
+++ b/src/dawn/native/opengl/OpenGLBackend.cpp
@@ -21,11 +21,11 @@
namespace dawn::native::opengl {
-AdapterDiscoveryOptions::AdapterDiscoveryOptions(WGPUBackendType type)
- : AdapterDiscoveryOptionsBase(type) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(WGPUBackendType type)
+ : PhysicalDeviceDiscoveryOptionsBase(type) {}
AdapterDiscoveryOptionsES::AdapterDiscoveryOptionsES()
- : AdapterDiscoveryOptions(WGPUBackendType_OpenGLES) {}
+ : PhysicalDeviceDiscoveryOptions(WGPUBackendType_OpenGLES) {}
ExternalImageDescriptorEGLImage::ExternalImageDescriptorEGLImage()
: ExternalImageDescriptor(ExternalImageType::EGLImage) {}
diff --git a/src/dawn/native/vulkan/BackendVk.cpp b/src/dawn/native/vulkan/BackendVk.cpp
index 8f5dc5d..89d1b08 100644
--- a/src/dawn/native/vulkan/BackendVk.cpp
+++ b/src/dawn/native/vulkan/BackendVk.cpp
@@ -457,9 +457,9 @@
Backend::~Backend() = default;
-std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
- AdapterDiscoveryOptions options;
- auto result = DiscoverAdapters(&options);
+std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
+ PhysicalDeviceDiscoveryOptions options;
+ auto result = DiscoverPhysicalDevices(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
return {};
@@ -467,12 +467,12 @@
return result.AcquireSuccess();
}
-ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) {
+ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan);
- const AdapterDiscoveryOptions* options =
- static_cast<const AdapterDiscoveryOptions*>(optionsBase);
+ const PhysicalDeviceDiscoveryOptions* options =
+ static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
diff --git a/src/dawn/native/vulkan/BackendVk.h b/src/dawn/native/vulkan/BackendVk.h
index 0c6c659..cf45a70 100644
--- a/src/dawn/native/vulkan/BackendVk.h
+++ b/src/dawn/native/vulkan/BackendVk.h
@@ -91,9 +91,9 @@
MaybeError Initialize();
- std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
- ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
- const AdapterDiscoveryOptionsBase* optionsBase) override;
+ std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
+ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
+ const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
private:
ityp::array<ICD, Ref<VulkanInstance>, 2> mVulkanInstances = {};
diff --git a/src/dawn/native/vulkan/VulkanBackend.cpp b/src/dawn/native/vulkan/VulkanBackend.cpp
index c4f282f..e2c183c 100644
--- a/src/dawn/native/vulkan/VulkanBackend.cpp
+++ b/src/dawn/native/vulkan/VulkanBackend.cpp
@@ -36,8 +36,8 @@
return (*backendDevice->fn.GetInstanceProcAddr)(backendDevice->GetVkInstance(), pName);
}
-AdapterDiscoveryOptions::AdapterDiscoveryOptions()
- : AdapterDiscoveryOptionsBase(WGPUBackendType_Vulkan) {}
+PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
+ : PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType_Vulkan) {}
#if DAWN_PLATFORM_IS(LINUX)
ExternalImageDescriptorOpaqueFD::ExternalImageDescriptorOpaqueFD()
diff --git a/src/dawn/samples/ManualSwapChainTest.cpp b/src/dawn/samples/ManualSwapChainTest.cpp
index 5be6a91..c3176d6 100644
--- a/src/dawn/samples/ManualSwapChainTest.cpp
+++ b/src/dawn/samples/ManualSwapChainTest.cpp
@@ -272,7 +272,7 @@
dawnProcSetProcs(&procs);
instance = std::make_unique<dawn::native::Instance>();
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
std::vector<dawn::native::Adapter> adapters = instance->GetAdapters();
dawn::native::Adapter chosenAdapter;
diff --git a/src/dawn/samples/SampleUtils.cpp b/src/dawn/samples/SampleUtils.cpp
index 9d11d88..33e886b 100644
--- a/src/dawn/samples/SampleUtils.cpp
+++ b/src/dawn/samples/SampleUtils.cpp
@@ -128,7 +128,7 @@
}
instance = std::make_unique<dawn::native::Instance>();
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
// Get an adapter for the backend to use, and create the device.
dawn::native::Adapter backendAdapter;
diff --git a/src/dawn/tests/BUILD.gn b/src/dawn/tests/BUILD.gn
index 40a922e..faea36c 100644
--- a/src/dawn/tests/BUILD.gn
+++ b/src/dawn/tests/BUILD.gn
@@ -485,7 +485,7 @@
]
sources = [
- "end2end/AdapterDiscoveryTests.cpp",
+ "end2end/AdapterCreationTests.cpp",
"end2end/BasicTests.cpp",
"end2end/BindGroupTests.cpp",
"end2end/BufferTests.cpp",
@@ -536,6 +536,7 @@
"end2end/NonzeroTextureCreationTests.cpp",
"end2end/ObjectCachingTests.cpp",
"end2end/OpArrayLengthTests.cpp",
+ "end2end/PhysicalDeviceDiscoveryTests.cpp",
"end2end/PipelineCachingTests.cpp",
"end2end/PipelineLayoutTests.cpp",
"end2end/PrimitiveStateTests.cpp",
diff --git a/src/dawn/tests/DawnNativeTest.cpp b/src/dawn/tests/DawnNativeTest.cpp
index f71dde7..5e81c1c 100644
--- a/src/dawn/tests/DawnNativeTest.cpp
+++ b/src/dawn/tests/DawnNativeTest.cpp
@@ -64,7 +64,7 @@
instance = std::make_unique<dawn::native::Instance>(
reinterpret_cast<const WGPUInstanceDescriptor*>(&instanceDesc));
instance->EnableAdapterBlocklist(false);
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
std::vector<dawn::native::Adapter> adapters = instance->GetAdapters();
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 11a14df..f34e69c 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -416,7 +416,7 @@
}
#endif // DAWN_ENABLE_BACKEND_OPENGLES
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
return instance;
}
diff --git a/src/dawn/tests/benchmarks/NullDeviceSetup.cpp b/src/dawn/tests/benchmarks/NullDeviceSetup.cpp
index 660de4a..4549ec0 100644
--- a/src/dawn/tests/benchmarks/NullDeviceSetup.cpp
+++ b/src/dawn/tests/benchmarks/NullDeviceSetup.cpp
@@ -33,7 +33,7 @@
if (!nativeInstance) {
nativeInstance = std::make_unique<dawn::native::Instance>();
- nativeInstance->DiscoverDefaultAdapters();
+ nativeInstance->DiscoverDefaultPhysicalDevices();
}
if (!nullBackendAdapter) {
diff --git a/src/dawn/tests/end2end/AdapterCreationTests.cpp b/src/dawn/tests/end2end/AdapterCreationTests.cpp
new file mode 100644
index 0000000..bc3bba0
--- /dev/null
+++ b/src/dawn/tests/end2end/AdapterCreationTests.cpp
@@ -0,0 +1,230 @@
+// Copyright 2023 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <memory>
+#include <utility>
+
+#include "dawn/common/GPUInfo.h"
+#include "dawn/dawn_proc.h"
+#include "dawn/native/DawnNative.h"
+#include "dawn/tests/MockCallback.h"
+#include "dawn/webgpu_cpp.h"
+#include "gtest/gtest.h"
+
+namespace dawn {
+namespace {
+
+using testing::_;
+using testing::MockCallback;
+using testing::SaveArg;
+
+class AdapterCreationTest : public ::testing::Test {
+ protected:
+ void SetUp() override {
+ dawnProcSetProcs(&native::GetProcs());
+
+ {
+ auto nativeInstance = std::make_unique<native::Instance>();
+ nativeInstance->DiscoverDefaultPhysicalDevices();
+ for (native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) {
+ anyAdapterAvailable = true;
+
+ wgpu::AdapterProperties properties;
+ nativeAdapter.GetProperties(&properties);
+ if (properties.compatibilityMode) {
+ continue;
+ }
+ swiftShaderAvailable |=
+ gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
+ discreteGPUAvailable |= properties.adapterType == wgpu::AdapterType::DiscreteGPU;
+ integratedGPUAvailable |=
+ properties.adapterType == wgpu::AdapterType::IntegratedGPU;
+ }
+ }
+
+ instance = wgpu::CreateInstance();
+ }
+
+ void TearDown() override {
+ instance = nullptr;
+ dawnProcSetProcs(nullptr);
+ }
+
+ wgpu::Instance instance;
+ bool anyAdapterAvailable = false;
+ bool swiftShaderAvailable = false;
+ bool discreteGPUAvailable = false;
+ bool integratedGPUAvailable = false;
+};
+
+// Test that requesting the default adapter works
+TEST_F(AdapterCreationTest, DefaultAdapter) {
+ wgpu::RequestAdapterOptions options = {};
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+}
+
+// Test that passing nullptr for the options gets the default adapter
+TEST_F(AdapterCreationTest, NullGivesDefaultAdapter) {
+ wgpu::RequestAdapterOptions options = {};
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this + 1))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(nullptr, cb.Callback(), cb.MakeUserdata(this + 1));
+
+ wgpu::Adapter adapter2 = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter2 != nullptr, anyAdapterAvailable);
+}
+
+// Test that requesting the fallback adapter returns SwiftShader.
+TEST_F(AdapterCreationTest, FallbackAdapter) {
+ wgpu::RequestAdapterOptions options = {};
+ options.forceFallbackAdapter = true;
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, swiftShaderAvailable);
+ if (adapter != nullptr) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
+ EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
+ }
+}
+
+// Test that requesting a high performance GPU works
+TEST_F(AdapterCreationTest, PreferHighPerformance) {
+ wgpu::RequestAdapterOptions options = {};
+ options.powerPreference = wgpu::PowerPreference::HighPerformance;
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+ if (discreteGPUAvailable) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+ EXPECT_EQ(properties.adapterType, wgpu::AdapterType::DiscreteGPU);
+ }
+}
+
+// Test that requesting a low power GPU works
+TEST_F(AdapterCreationTest, PreferLowPower) {
+ wgpu::RequestAdapterOptions options = {};
+ options.powerPreference = wgpu::PowerPreference::LowPower;
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+ if (integratedGPUAvailable) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+ EXPECT_EQ(properties.adapterType, wgpu::AdapterType::IntegratedGPU);
+ }
+}
+
+// Test that requesting a Compatibility adapter is supported.
+TEST_F(AdapterCreationTest, Compatibility) {
+ wgpu::RequestAdapterOptions options = {};
+ options.compatibilityMode = true;
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+ EXPECT_TRUE(properties.compatibilityMode);
+}
+
+// Test that requesting a Non-Compatibility adapter is supported and is default.
+TEST_F(AdapterCreationTest, NonCompatibility) {
+ wgpu::RequestAdapterOptions options = {};
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+ EXPECT_FALSE(properties.compatibilityMode);
+}
+
+// Test that GetInstance() returns the correct Instance.
+TEST_F(AdapterCreationTest, GetInstance) {
+ wgpu::RequestAdapterOptions options = {};
+
+ MockCallback<WGPURequestAdapterCallback> cb;
+
+ WGPUAdapter cAdapter = nullptr;
+ EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
+ .WillOnce(SaveArg<1>(&cAdapter));
+ instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
+
+ wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
+ EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
+
+ EXPECT_EQ(adapter.GetInstance().Get(), instance.Get());
+}
+
+} // anonymous namespace
+} // namespace dawn
diff --git a/src/dawn/tests/end2end/AdapterDiscoveryTests.cpp b/src/dawn/tests/end2end/AdapterDiscoveryTests.cpp
deleted file mode 100644
index 904272d..0000000
--- a/src/dawn/tests/end2end/AdapterDiscoveryTests.cpp
+++ /dev/null
@@ -1,449 +0,0 @@
-// Copyright 2021 The Dawn Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include <memory>
-#include <utility>
-
-#include "dawn/common/GPUInfo.h"
-#include "dawn/common/Log.h"
-#include "dawn/common/Platform.h"
-#include "dawn/common/SystemUtils.h"
-#include "dawn/dawn_proc.h"
-#include "dawn/native/DawnNative.h"
-#include "dawn/tests/MockCallback.h"
-#include "dawn/webgpu_cpp.h"
-
-#if defined(DAWN_ENABLE_BACKEND_VULKAN)
-#include "dawn/native/VulkanBackend.h"
-#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
-
-#if defined(DAWN_ENABLE_BACKEND_D3D11)
-#include "dawn/native/D3D11Backend.h"
-#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
-
-#if defined(DAWN_ENABLE_BACKEND_D3D12)
-#include "dawn/native/D3D12Backend.h"
-#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
-
-#if defined(DAWN_ENABLE_BACKEND_METAL)
-#include "dawn/native/MetalBackend.h"
-#endif // defined(DAWN_ENABLE_BACKEND_METAL)
-
-#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
-#include "GLFW/glfw3.h"
-#include "dawn/native/OpenGLBackend.h"
-#endif // defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
-
-#include <gtest/gtest.h>
-
-namespace dawn {
-namespace {
-
-using testing::_;
-using testing::MockCallback;
-using testing::SaveArg;
-
-class AdapterDiscoveryTests : public ::testing::Test {};
-
-#if defined(DAWN_ENABLE_BACKEND_VULKAN)
-// Test only discovering the SwiftShader adapter
-TEST(AdapterDiscoveryTests, OnlySwiftShader) {
- native::Instance instance;
-
- native::vulkan::AdapterDiscoveryOptions options;
- options.forceSwiftShader = true;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- EXPECT_LE(adapters.size(), 2u); // 0 or 2 SwiftShader adapters.
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
- EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
- EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
- }
-}
-
-// Test discovering only Vulkan adapters
-TEST(AdapterDiscoveryTests, OnlyVulkan) {
- native::Instance instance;
-
- native::vulkan::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
- }
-}
-#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
-
-#if defined(DAWN_ENABLE_BACKEND_D3D11)
-// Test discovering only D3D11 adapters
-TEST(AdapterDiscoveryTests, OnlyD3D11) {
- native::Instance instance;
-
- native::d3d11::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
- }
-}
-
-// Test discovering a D3D11 adapter from a prexisting DXGI adapter
-TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D11) {
- using Microsoft::WRL::ComPtr;
-
- ComPtr<IDXGIFactory4> dxgiFactory;
- HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
- ASSERT_EQ(hr, S_OK);
-
- for (uint32_t adapterIndex = 0;; ++adapterIndex) {
- ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
- if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
- break; // No more adapters to enumerate.
- }
-
- native::Instance instance;
-
- native::d3d11::AdapterDiscoveryOptions options;
- options.dxgiAdapter = std::move(dxgiAdapter);
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
- }
- }
-}
-#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
-
-#if defined(DAWN_ENABLE_BACKEND_D3D12)
-// Test discovering only D3D12 adapters
-TEST(AdapterDiscoveryTests, OnlyD3D12) {
- native::Instance instance;
-
- native::d3d12::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
- }
-}
-
-// Test discovering a D3D12 adapter from a prexisting DXGI adapter
-TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D12) {
- using Microsoft::WRL::ComPtr;
-
- ComPtr<IDXGIFactory4> dxgiFactory;
- HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
- ASSERT_EQ(hr, S_OK);
-
- for (uint32_t adapterIndex = 0;; ++adapterIndex) {
- ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
- if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
- break; // No more adapters to enumerate.
- }
-
- native::Instance instance;
-
- native::d3d12::AdapterDiscoveryOptions options;
- options.dxgiAdapter = std::move(dxgiAdapter);
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
- }
- }
-}
-#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
-
-#if defined(DAWN_ENABLE_BACKEND_METAL)
-// Test discovering only Metal adapters
-TEST(AdapterDiscoveryTests, OnlyMetal) {
- native::Instance instance;
-
- native::metal::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.backendType, wgpu::BackendType::Metal);
- }
-}
-#endif // defined(DAWN_ENABLE_BACKEND_METAL)
-
-#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(DAWN_ENABLE_BACKEND_VULKAN)
-// Test discovering the Metal backend, then the Vulkan backend
-// does not duplicate adapters.
-TEST(AdapterDiscoveryTests, OneBackendThenTheOther) {
- native::Instance instance;
- uint32_t metalAdapterCount = 0;
- {
- native::metal::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- const auto& adapters = instance.GetAdapters();
- metalAdapterCount = adapters.size();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- ASSERT_EQ(properties.backendType, wgpu::BackendType::Metal);
- }
- }
- {
- native::vulkan::AdapterDiscoveryOptions options;
- instance.DiscoverAdapters(&options);
-
- uint32_t metalAdapterCount2 = 0;
- const auto& adapters = instance.GetAdapters();
- for (const auto& adapter : adapters) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_TRUE(properties.backendType == wgpu::BackendType::Metal ||
- properties.backendType == wgpu::BackendType::Vulkan);
- if (properties.backendType == wgpu::BackendType::Metal) {
- metalAdapterCount2++;
- }
- }
- EXPECT_EQ(metalAdapterCount, metalAdapterCount2);
- }
-}
-#endif // defined(DAWN_ENABLE_BACKEND_VULKAN) && defined(DAWN_ENABLE_BACKEND_METAL)
-
-class AdapterCreationTest : public ::testing::Test {
- protected:
- void SetUp() override {
- dawnProcSetProcs(&dawn_native::GetProcs());
-
- {
- auto nativeInstance = std::make_unique<dawn_native::Instance>();
- nativeInstance->DiscoverDefaultAdapters();
- for (dawn_native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) {
- anyAdapterAvailable = true;
-
- wgpu::AdapterProperties properties;
- nativeAdapter.GetProperties(&properties);
- if (properties.compatibilityMode) {
- continue;
- }
- swiftShaderAvailable |=
- gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
- discreteGPUAvailable |= properties.adapterType == wgpu::AdapterType::DiscreteGPU;
- integratedGPUAvailable |=
- properties.adapterType == wgpu::AdapterType::IntegratedGPU;
- }
- }
-
- instance = wgpu::CreateInstance();
- }
-
- void TearDown() override {
- instance = nullptr;
- dawnProcSetProcs(nullptr);
- }
-
- wgpu::Instance instance;
- bool anyAdapterAvailable = false;
- bool swiftShaderAvailable = false;
- bool discreteGPUAvailable = false;
- bool integratedGPUAvailable = false;
-};
-
-// Test that requesting the default adapter works
-TEST_F(AdapterCreationTest, DefaultAdapter) {
- wgpu::RequestAdapterOptions options = {};
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
-}
-
-// Test that passing nullptr for the options gets the default adapter
-TEST_F(AdapterCreationTest, NullGivesDefaultAdapter) {
- wgpu::RequestAdapterOptions options = {};
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
-
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this + 1))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(nullptr, cb.Callback(), cb.MakeUserdata(this + 1));
-
- wgpu::Adapter adapter2 = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter2 != nullptr, anyAdapterAvailable);
-}
-
-// Test that requesting the fallback adapter returns SwiftShader.
-TEST_F(AdapterCreationTest, FallbackAdapter) {
- wgpu::RequestAdapterOptions options = {};
- options.forceFallbackAdapter = true;
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, swiftShaderAvailable);
- if (adapter != nullptr) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
-
- EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
- EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
- }
-}
-
-// Test that requesting a high performance GPU works
-TEST_F(AdapterCreationTest, PreferHighPerformance) {
- wgpu::RequestAdapterOptions options = {};
- options.powerPreference = wgpu::PowerPreference::HighPerformance;
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
- if (discreteGPUAvailable) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
- EXPECT_EQ(properties.adapterType, wgpu::AdapterType::DiscreteGPU);
- }
-}
-
-// Test that requesting a low power GPU works
-TEST_F(AdapterCreationTest, PreferLowPower) {
- wgpu::RequestAdapterOptions options = {};
- options.powerPreference = wgpu::PowerPreference::LowPower;
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
- if (integratedGPUAvailable) {
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
- EXPECT_EQ(properties.adapterType, wgpu::AdapterType::IntegratedGPU);
- }
-}
-
-// Test that requesting a Compatibility adapter is supported.
-TEST_F(AdapterCreationTest, Compatibility) {
- wgpu::RequestAdapterOptions options = {};
- options.compatibilityMode = true;
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
-
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
- EXPECT_TRUE(properties.compatibilityMode);
-}
-
-// Test that requesting a Non-Compatibility adapter is supported and is default.
-TEST_F(AdapterCreationTest, NonCompatibility) {
- wgpu::RequestAdapterOptions options = {};
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
-
- wgpu::AdapterProperties properties;
- adapter.GetProperties(&properties);
- EXPECT_FALSE(properties.compatibilityMode);
-}
-
-// Test that GetInstance() returns the correct Instance.
-TEST_F(AdapterCreationTest, GetInstance) {
- wgpu::RequestAdapterOptions options = {};
-
- MockCallback<WGPURequestAdapterCallback> cb;
-
- WGPUAdapter cAdapter = nullptr;
- EXPECT_CALL(cb, Call(WGPURequestAdapterStatus_Success, _, nullptr, this))
- .WillOnce(SaveArg<1>(&cAdapter));
- instance.RequestAdapter(&options, cb.Callback(), cb.MakeUserdata(this));
-
- wgpu::Adapter adapter = wgpu::Adapter::Acquire(cAdapter);
- EXPECT_EQ(adapter != nullptr, anyAdapterAvailable);
-
- EXPECT_EQ(adapter.GetInstance().Get(), instance.Get());
-}
-
-} // anonymous namespace
-} // namespace dawn
diff --git a/src/dawn/tests/end2end/DeviceInitializationTests.cpp b/src/dawn/tests/end2end/DeviceInitializationTests.cpp
index 69e4d5e..03df135 100644
--- a/src/dawn/tests/end2end/DeviceInitializationTests.cpp
+++ b/src/dawn/tests/end2end/DeviceInitializationTests.cpp
@@ -78,7 +78,7 @@
{
auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false);
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
for (const native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
@@ -96,7 +96,7 @@
auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false);
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
for (native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
@@ -127,7 +127,7 @@
{
auto instance = std::make_unique<native::Instance>();
instance->EnableAdapterBlocklist(false);
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
for (const native::Adapter& adapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
@@ -152,7 +152,7 @@
// It will only be valid as long as the instance is alive.
WGPUInstance unsafeInstancePtr = instance->Get();
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
for (native::Adapter& nativeAdapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties;
nativeAdapter.GetProperties(&properties);
diff --git a/src/dawn/tests/end2end/PhysicalDeviceDiscoveryTests.cpp b/src/dawn/tests/end2end/PhysicalDeviceDiscoveryTests.cpp
new file mode 100644
index 0000000..8ac0bde
--- /dev/null
+++ b/src/dawn/tests/end2end/PhysicalDeviceDiscoveryTests.cpp
@@ -0,0 +1,243 @@
+// Copyright 2021 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <memory>
+#include <utility>
+
+#include "dawn/common/GPUInfo.h"
+#include "dawn/native/DawnNative.h"
+#include "dawn/webgpu_cpp.h"
+
+#if defined(DAWN_ENABLE_BACKEND_VULKAN)
+#include "dawn/native/VulkanBackend.h"
+#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
+
+#if defined(DAWN_ENABLE_BACKEND_D3D11)
+#include "dawn/native/D3D11Backend.h"
+#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
+
+#if defined(DAWN_ENABLE_BACKEND_D3D12)
+#include "dawn/native/D3D12Backend.h"
+#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
+
+#if defined(DAWN_ENABLE_BACKEND_METAL)
+#include "dawn/native/MetalBackend.h"
+#endif // defined(DAWN_ENABLE_BACKEND_METAL)
+
+#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
+#include "GLFW/glfw3.h"
+#include "dawn/native/OpenGLBackend.h"
+#endif // defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
+
+#include <gtest/gtest.h>
+
+namespace dawn {
+namespace {
+
+class PhysicalDeviceDiscoveryTests : public ::testing::Test {};
+
+#if defined(DAWN_ENABLE_BACKEND_VULKAN)
+// Test only discovering the SwiftShader physical devices
+TEST(PhysicalDeviceDiscoveryTests, OnlySwiftShader) {
+ native::Instance instance;
+
+ native::vulkan::PhysicalDeviceDiscoveryOptions options;
+ options.forceSwiftShader = true;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ EXPECT_LE(adapters.size(), 2u); // 0 or 2 SwiftShader adapters.
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
+ EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
+ EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
+ }
+}
+
+// Test discovering only Vulkan physical devices
+TEST(PhysicalDeviceDiscoveryTests, OnlyVulkan) {
+ native::Instance instance;
+
+ native::vulkan::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
+ }
+}
+#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
+
+#if defined(DAWN_ENABLE_BACKEND_D3D11)
+// Test discovering only D3D11 physical devices
+TEST(PhysicalDeviceDiscoveryTests, OnlyD3D11) {
+ native::Instance instance;
+
+ native::d3d11::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
+ }
+}
+
+// Test discovering a D3D11 physical device from a prexisting DXGI adapter
+TEST(PhysicalDeviceDiscoveryTests, MatchingDXGIAdapterD3D11) {
+ using Microsoft::WRL::ComPtr;
+
+ ComPtr<IDXGIFactory4> dxgiFactory;
+ HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
+ ASSERT_EQ(hr, S_OK);
+
+ for (uint32_t adapterIndex = 0;; ++adapterIndex) {
+ ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
+ if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
+ break; // No more adapters to enumerate.
+ }
+
+ native::Instance instance;
+
+ native::d3d11::PhysicalDeviceDiscoveryOptions options;
+ options.dxgiAdapter = std::move(dxgiAdapter);
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
+ }
+ }
+}
+#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
+
+#if defined(DAWN_ENABLE_BACKEND_D3D12)
+// Test discovering only D3D12 physical devices
+TEST(PhysicalDeviceDiscoveryTests, OnlyD3D12) {
+ native::Instance instance;
+
+ native::d3d12::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
+ }
+}
+
+// Test discovering a D3D12 physical device from a prexisting DXGI adapter
+TEST(PhysicalDeviceDiscoveryTests, MatchingDXGIAdapterD3D12) {
+ using Microsoft::WRL::ComPtr;
+
+ ComPtr<IDXGIFactory4> dxgiFactory;
+ HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
+ ASSERT_EQ(hr, S_OK);
+
+ for (uint32_t adapterIndex = 0;; ++adapterIndex) {
+ ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
+ if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
+ break; // No more adapters to enumerate.
+ }
+
+ native::Instance instance;
+
+ native::d3d12::PhysicalDeviceDiscoveryOptions options;
+ options.dxgiAdapter = std::move(dxgiAdapter);
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
+ }
+ }
+}
+#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
+
+#if defined(DAWN_ENABLE_BACKEND_METAL)
+// Test discovering only Metal physical devices
+TEST(PhysicalDeviceDiscoveryTests, OnlyMetal) {
+ native::Instance instance;
+
+ native::metal::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_EQ(properties.backendType, wgpu::BackendType::Metal);
+ }
+}
+#endif // defined(DAWN_ENABLE_BACKEND_METAL)
+
+#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(DAWN_ENABLE_BACKEND_VULKAN)
+// Test discovering the Metal backend, then the Vulkan backend
+// does not duplicate physical devices.
+TEST(PhysicalDeviceDiscoveryTests, OneBackendThenTheOther) {
+ native::Instance instance;
+ uint32_t metalAdapterCount = 0;
+ {
+ native::metal::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ const auto& adapters = instance.GetAdapters();
+ metalAdapterCount = adapters.size();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ ASSERT_EQ(properties.backendType, wgpu::BackendType::Metal);
+ }
+ }
+ {
+ native::vulkan::PhysicalDeviceDiscoveryOptions options;
+ instance.DiscoverPhysicalDevices(&options);
+
+ uint32_t metalAdapterCount2 = 0;
+ const auto& adapters = instance.GetAdapters();
+ for (const auto& adapter : adapters) {
+ wgpu::AdapterProperties properties;
+ adapter.GetProperties(&properties);
+
+ EXPECT_TRUE(properties.backendType == wgpu::BackendType::Metal ||
+ properties.backendType == wgpu::BackendType::Vulkan);
+ if (properties.backendType == wgpu::BackendType::Metal) {
+ metalAdapterCount2++;
+ }
+ }
+ EXPECT_EQ(metalAdapterCount, metalAdapterCount2);
+ }
+}
+#endif // defined(DAWN_ENABLE_BACKEND_VULKAN) && defined(DAWN_ENABLE_BACKEND_METAL)
+
+} // anonymous namespace
+} // namespace dawn
diff --git a/src/dawn/tests/unittests/ToggleTests.cpp b/src/dawn/tests/unittests/ToggleTests.cpp
index 0b69561..256955e 100644
--- a/src/dawn/tests/unittests/ToggleTests.cpp
+++ b/src/dawn/tests/unittests/ToggleTests.cpp
@@ -170,10 +170,10 @@
native::InstanceBase* instance = native::FromAPI(nativeInstance->Get());
const native::TogglesState& instanceTogglesState = instance->GetTogglesState();
- // Discover adapters with default toggles.
- instance->DiscoverDefaultAdapters();
+ // Discover physical devices.
+ instance->DiscoverDefaultPhysicalDevices();
- // Get the adapter created by instance with default toggles.
+ // Get the adapters created by instance with default toggles.
Ref<native::AdapterBase> nullAdapter;
for (auto& adapter : instance->GetAdapters()) {
if (adapter->GetPhysicalDevice()->GetBackendType() == wgpu::BackendType::Null) {
diff --git a/src/dawn/tests/unittests/native/DeviceCreationTests.cpp b/src/dawn/tests/unittests/native/DeviceCreationTests.cpp
index 620b4d5..ea505c2 100644
--- a/src/dawn/tests/unittests/native/DeviceCreationTests.cpp
+++ b/src/dawn/tests/unittests/native/DeviceCreationTests.cpp
@@ -43,7 +43,7 @@
// Create an instance with default toggles and create an adapter from it.
WGPUInstanceDescriptor safeInstanceDesc = {};
instance = std::make_unique<dawn::native::Instance>(&safeInstanceDesc);
- instance->DiscoverDefaultAdapters();
+ instance->DiscoverDefaultPhysicalDevices();
for (dawn::native::Adapter& nativeAdapter : instance->GetAdapters()) {
wgpu::AdapterProperties properties;
nativeAdapter.GetProperties(&properties);
@@ -67,7 +67,7 @@
unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain;
unsafeInstanceDisallow = std::make_unique<dawn::native::Instance>(&unsafeInstanceDesc);
- unsafeInstanceDisallow->DiscoverDefaultAdapters();
+ unsafeInstanceDisallow->DiscoverDefaultPhysicalDevices();
for (dawn::native::Adapter& nativeAdapter : unsafeInstanceDisallow->GetAdapters()) {
wgpu::AdapterProperties properties;
nativeAdapter.GetProperties(&properties);
@@ -90,7 +90,7 @@
unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain;
unsafeInstance = std::make_unique<dawn::native::Instance>(&unsafeInstanceDesc);
- unsafeInstance->DiscoverDefaultAdapters();
+ unsafeInstance->DiscoverDefaultPhysicalDevices();
for (dawn::native::Adapter& nativeAdapter : unsafeInstance->GetAdapters()) {
wgpu::AdapterProperties properties;
nativeAdapter.GetProperties(&properties);
diff --git a/src/dawn/tests/unittests/validation/ValidationTest.cpp b/src/dawn/tests/unittests/validation/ValidationTest.cpp
index 310021e..f032ba2 100644
--- a/src/dawn/tests/unittests/validation/ValidationTest.cpp
+++ b/src/dawn/tests/unittests/validation/ValidationTest.cpp
@@ -145,7 +145,7 @@
mDawnInstance = std::make_unique<dawn::native::Instance>(&instanceDesc);
- mDawnInstance->DiscoverDefaultAdapters();
+ mDawnInstance->DiscoverDefaultPhysicalDevices();
mInstance = mWireHelper->RegisterInstance(mDawnInstance->Get());
std::string traceName =