diff --git a/include/dawn/native/D3D11Backend.h b/include/dawn/native/D3D11Backend.h index b090071799..5fae9565cc 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 adapter); +struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions + : public d3d::PhysicalDeviceDiscoveryOptions { + PhysicalDeviceDiscoveryOptions(); + explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr adapter); }; +// TODO(dawn:1774): Deprecated. +using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions; + DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr GetD3D11Device(WGPUDevice device); } // namespace dawn::native::d3d11 diff --git a/include/dawn/native/D3D12Backend.h b/include/dawn/native/D3D12Backend.h index cb148051df..eb0ca2be3e 100644 --- a/include/dawn/native/D3D12Backend.h +++ b/include/dawn/native/D3D12Backend.h @@ -38,11 +38,15 @@ DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device, uint64_t requestedReservationSize, MemorySegment memorySegment); -struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public d3d::AdapterDiscoveryOptions { - AdapterDiscoveryOptions(); - explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr adapter); +struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions + : public d3d::PhysicalDeviceDiscoveryOptions { + PhysicalDeviceDiscoveryOptions(); + explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr 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 590f8fa226..d791d3e875 100644 --- a/include/dawn/native/D3DBackend.h +++ b/include/dawn/native/D3DBackend.h @@ -30,11 +30,16 @@ class ExternalImageDXGIImpl; DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr GetDXGIAdapter(WGPUAdapter adapter); -struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase { - AdapterDiscoveryOptions(WGPUBackendType type, Microsoft::WRL::ComPtr adapter); +struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions + : public PhysicalDeviceDiscoveryOptionsBase { + PhysicalDeviceDiscoveryOptions(WGPUBackendType type, + Microsoft::WRL::ComPtr adapter); Microsoft::WRL::ComPtr 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 477c57de29..9ebaae828b 100644 --- a/include/dawn/native/DawnNative.h +++ b/include/dawn/native/DawnNative.h @@ -118,15 +118,19 @@ class DAWN_NATIVE_EXPORT Adapter { 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 @@ class DAWN_NATIVE_EXPORT Instance { 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 GetAdapters() const; const ToggleInfo* GetToggleInfo(const char* toggleName); diff --git a/include/dawn/native/MetalBackend.h b/include/dawn/native/MetalBackend.h index a41cb6b437..c401d7d474 100644 --- a/include/dawn/native/MetalBackend.h +++ b/include/dawn/native/MetalBackend.h @@ -35,10 +35,14 @@ typedef __IOSurface* IOSurfaceRef; 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`. // 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 fd41b70427..580c444b78 100644 --- a/include/dawn/native/OpenGLBackend.h +++ b/include/dawn/native/OpenGLBackend.h @@ -21,14 +21,18 @@ typedef void* EGLImage; 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 a056356f04..a677388e6f 100644 --- a/include/dawn/native/VulkanBackend.h +++ b/include/dawn/native/VulkanBackend.h @@ -28,12 +28,16 @@ DAWN_NATIVE_EXPORT VkInstance GetInstance(WGPUDevice device); 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 406be4c7c9..fdd288bcef 100644 --- a/src/dawn/fuzzers/DawnWireServerFuzzer.cpp +++ b/src/dawn/fuzzers/DawnWireServerFuzzer.cpp @@ -70,7 +70,7 @@ int DawnWireServerFuzzer::Initialize(int* argc, char*** argv) { 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 8d4dd6af3f..88634031d9 100644 --- a/src/dawn/native/BackendConnection.cpp +++ b/src/dawn/native/BackendConnection.cpp @@ -28,9 +28,9 @@ InstanceBase* BackendConnection::GetInstance() const { return mInstance; } -ResultOrError>> BackendConnection::DiscoverAdapters( - const AdapterDiscoveryOptionsBase* options) { - return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend."); +ResultOrError>> 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 920141a946..951a78153b 100644 --- a/src/dawn/native/BackendConnection.h +++ b/src/dawn/native/BackendConnection.h @@ -34,13 +34,13 @@ class BackendConnection { 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> 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> DiscoverDefaultPhysicalDevices() = 0; - // Returns new adapters created with the backend-specific options. - virtual ResultOrError>> DiscoverAdapters( - const AdapterDiscoveryOptionsBase* options); + // Returns new physical devices created with the backend-specific options. + virtual ResultOrError>> DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* options); private: InstanceBase* mInstance = nullptr; diff --git a/src/dawn/native/DawnNative.cpp b/src/dawn/native/DawnNative.cpp index 2de16e74f8..6594b647eb 100644 --- a/src/dawn/native/DawnNative.cpp +++ b/src/dawn/native/DawnNative.cpp @@ -132,7 +132,7 @@ void Adapter::ResetInternalDeviceForTesting() { // AdapterDiscoverOptionsBase -AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type) +PhysicalDeviceDiscoveryOptionsBase::PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType type) : backendType(type) {} // DawnInstanceDescriptor @@ -162,12 +162,22 @@ Instance::~Instance() { } } -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 Instance::GetAdapters() const { diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp index 98482e1baa..f84becf77e 100644 --- a/src/dawn/native/Instance.cpp +++ b/src/dawn/native/Instance.cpp @@ -217,10 +217,10 @@ ResultOrError> InstanceBase::RequestAdapterInternal( 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 @@ ResultOrError> InstanceBase::RequestAdapterInternal( return Ref(nullptr); #endif // defined(DAWN_ENABLE_BACKEND_VULKAN) } else { - DiscoverDefaultAdapters(); + DiscoverDefaultPhysicalDevices(); } wgpu::AdapterType preferredType; @@ -314,7 +314,7 @@ ResultOrError> InstanceBase::RequestAdapterInternal( 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 @@ void InstanceBase::DiscoverDefaultAdapters() { // Query and merge all default adapters for all backends for (std::unique_ptr& backend : mBackends) { - std::vector> physicalDevices = backend->DiscoverDefaultAdapters(); + std::vector> physicalDevices = + backend->DiscoverDefaultPhysicalDevices(); for (Ref& physicalDevice : physicalDevices) { ASSERT(physicalDevice->GetBackendType() == backend->GetType()); @@ -338,8 +339,8 @@ void InstanceBase::DiscoverDefaultAdapters() { } // 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 @@ void InstanceBase::EnsureBackendConnection(wgpu::BackendType backendType) { mBackendsConnected.set(backendType); } -MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options) { +MaybeError InstanceBase::DiscoverPhysicalDevicesInternal( + const PhysicalDeviceDiscoveryOptionsBase* options) { wgpu::BackendType backendType = static_cast(options->backendType); DAWN_TRY(ValidateBackendType(backendType)); @@ -468,7 +470,7 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB foundBackend = true; std::vector> newPhysicalDevices; - DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options)); + DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverPhysicalDevices(options)); for (Ref& physicalDevice : newPhysicalDevices) { ASSERT(physicalDevice->GetBackendType() == backend->GetType()); diff --git a/src/dawn/native/Instance.h b/src/dawn/native/Instance.h index b149e6d98d..aabb9a621b 100644 --- a/src/dawn/native/Instance.h +++ b/src/dawn/native/Instance.h @@ -58,9 +58,10 @@ class InstanceBase final : public RefCountedWithExternalCount { 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> GetAdapters() const; // Used to handle error that happen up to device creation. @@ -134,7 +135,7 @@ class InstanceBase final : public RefCountedWithExternalCount { // 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> RequestAdapterInternal(const RequestAdapterOptions* options); diff --git a/src/dawn/native/d3d/BackendD3D.cpp b/src/dawn/native/d3d/BackendD3D.cpp index a9006f49fa..9d998706bf 100644 --- a/src/dawn/native/d3d/BackendD3D.cpp +++ b/src/dawn/native/d3d/BackendD3D.cpp @@ -238,35 +238,35 @@ const PlatformFunctions* Backend::GetFunctions() const { return mFunctions.get(); } -std::vector> Backend::DiscoverDefaultAdapters() { - AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr); - std::vector> adapters; - if (GetInstance()->ConsumedError(DiscoverAdapters(&options), &adapters)) { +std::vector> Backend::DiscoverDefaultPhysicalDevices() { + PhysicalDeviceDiscoveryOptions options(ToAPI(GetType()), nullptr); + std::vector> physicalDevices; + if (GetInstance()->ConsumedError(DiscoverPhysicalDevices(&options), &physicalDevices)) { return {}; } - return adapters; + return physicalDevices; } -ResultOrError>> Backend::DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) { +ResultOrError>> Backend::DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* optionsBase) { ASSERT(optionsBase->backendType == ToAPI(GetType())); - const AdapterDiscoveryOptions* options = - static_cast(optionsBase); + const PhysicalDeviceDiscoveryOptions* options = + static_cast(optionsBase); - std::vector> adapters; + std::vector> physicalDevices; if (options->dxgiAdapter != nullptr) { // |dxgiAdapter| was provided. Discover just that adapter. Ref 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 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 @@ ResultOrError>> Backend::DiscoverAdapters( 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 957dad7371..261e59f192 100644 --- a/src/dawn/native/d3d/BackendD3D.h +++ b/src/dawn/native/d3d/BackendD3D.h @@ -75,9 +75,9 @@ class Backend : public BackendConnection { const PlatformFunctions* GetFunctions() const; - std::vector> DiscoverDefaultAdapters() override; - ResultOrError>> DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) override; + std::vector> DiscoverDefaultPhysicalDevices() override; + ResultOrError>> DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override; protected: virtual ResultOrError> CreatePhysicalDeviceFromIDXGIAdapter( diff --git a/src/dawn/native/d3d/D3DBackend.cpp b/src/dawn/native/d3d/D3DBackend.cpp index c03d4e8d1b..063fa23c1c 100644 --- a/src/dawn/native/d3d/D3DBackend.cpp +++ b/src/dawn/native/d3d/D3DBackend.cpp @@ -33,9 +33,10 @@ Microsoft::WRL::ComPtr GetDXGIAdapter(WGPUAdapter adapter) { return ToBackend(FromAPI(adapter)->GetPhysicalDevice())->GetHardwareAdapter(); } -AdapterDiscoveryOptions::AdapterDiscoveryOptions(WGPUBackendType type, - Microsoft::WRL::ComPtr adapter) - : AdapterDiscoveryOptionsBase(type), dxgiAdapter(std::move(adapter)) {} +PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions( + WGPUBackendType type, + Microsoft::WRL::ComPtr 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 f4d4c0811e..a7d71680ed 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 adapter) - : d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {} +PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr adapter) + : d3d::PhysicalDeviceDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {} Microsoft::WRL::ComPtr 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 db693ed916..bd5c5e7b52 100644 --- a/src/dawn/native/d3d12/D3D12Backend.cpp +++ b/src/dawn/native/d3d12/D3D12Backend.cpp @@ -39,9 +39,10 @@ uint64_t SetExternalMemoryReservation(WGPUDevice device, memorySegment, requestedReservationSize); } -AdapterDiscoveryOptions::AdapterDiscoveryOptions() : AdapterDiscoveryOptions(nullptr) {} +PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions() + : PhysicalDeviceDiscoveryOptions(nullptr) {} -AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr adapter) - : d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D12, std::move(adapter)) {} +PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr 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 c8abec1b63..d87dd5436d 100644 --- a/src/dawn/native/metal/BackendMTL.h +++ b/src/dawn/native/metal/BackendMTL.h @@ -26,9 +26,9 @@ class Backend : public BackendConnection { explicit Backend(InstanceBase* instance); ~Backend() override; - std::vector> DiscoverDefaultAdapters() override; - ResultOrError>> DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) override; + std::vector> DiscoverDefaultPhysicalDevices() override; + ResultOrError>> 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 ff80849b72..79f70ee547 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -819,9 +819,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac Backend::~Backend() = default; -std::vector> Backend::DiscoverDefaultAdapters() { - AdapterDiscoveryOptions options; - auto result = DiscoverAdapters(&options); +std::vector> Backend::DiscoverDefaultPhysicalDevices() { + PhysicalDeviceDiscoveryOptions options; + auto result = DiscoverPhysicalDevices(&options); if (result.IsError()) { GetInstance()->ConsumedError(result.AcquireError()); return {}; @@ -829,8 +829,8 @@ std::vector> Backend::DiscoverDefaultAdapters() { return result.AcquireSuccess(); } -ResultOrError>> Backend::DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) { +ResultOrError>> Backend::DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* optionsBase) { ASSERT(optionsBase->backendType == WGPUBackendType_Metal); std::vector> physicalDevices; diff --git a/src/dawn/native/metal/MetalBackend.mm b/src/dawn/native/metal/MetalBackend.mm index 0bbc2657a6..e785c15901 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 69f9411db2..0ea402bc4d 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp @@ -86,7 +86,7 @@ class Backend : public BackendConnection { explicit Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::BackendType::Null) {} - std::vector> DiscoverDefaultAdapters() override { + std::vector> DiscoverDefaultPhysicalDevices() override { // There is always a single Null adapter because it is purely CPU based and doesn't // depend on the system. std::vector> physicalDevices; diff --git a/src/dawn/native/opengl/BackendGL.cpp b/src/dawn/native/opengl/BackendGL.cpp index 6915bb59b8..90ffd6195d 100644 --- a/src/dawn/native/opengl/BackendGL.cpp +++ b/src/dawn/native/opengl/BackendGL.cpp @@ -33,8 +33,8 @@ namespace dawn::native::opengl { Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType) : BackendConnection(instance, backendType) {} -std::vector> Backend::DiscoverDefaultAdapters() { - std::vector> adapters; +std::vector> Backend::DiscoverDefaultPhysicalDevices() { + std::vector> physicalDevices; #if DAWN_PLATFORM_IS(WINDOWS) const char* eglLib = "libEGL.dll"; #elif DAWN_PLATFORM_IS(MACOS) @@ -46,7 +46,7 @@ std::vector> Backend::DiscoverDefaultAdapters() { return {}; } - AdapterDiscoveryOptions options(ToAPI(GetType())); + PhysicalDeviceDiscoveryOptions options(ToAPI(GetType())); options.getProc = reinterpret_cast(mLibEGL.GetProc("eglGetProcAddress")); if (!options.getProc) { @@ -69,39 +69,41 @@ std::vector> Backend::DiscoverDefaultAdapters() { 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>> Backend::DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) { - // TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't +ResultOrError>> 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(optionsBase->backendType) == GetType()); - const AdapterDiscoveryOptions* options = - static_cast(optionsBase); + const PhysicalDeviceDiscoveryOptions* options = + static_cast(optionsBase); - DAWN_INVALID_IF(options->getProc == nullptr, "AdapterDiscoveryOptions::getProc must be set"); + DAWN_INVALID_IF(options->getProc == nullptr, + "PhysicalDeviceDiscoveryOptions::getProc must be set"); - Ref adapter = AcquireRef(new PhysicalDevice( + Ref physicalDevice = AcquireRef(new PhysicalDevice( GetInstance(), static_cast(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> adapters{std::move(adapter)}; + mCreatedPhysicalDevice = true; + std::vector> 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 d427ed558e..87b3cf26fb 100644 --- a/src/dawn/native/opengl/BackendGL.h +++ b/src/dawn/native/opengl/BackendGL.h @@ -26,12 +26,12 @@ class Backend : public BackendConnection { public: Backend(InstanceBase* instance, wgpu::BackendType backendType); - std::vector> DiscoverDefaultAdapters() override; - ResultOrError>> DiscoverAdapters( - const AdapterDiscoveryOptionsBase* option) override; + std::vector> DiscoverDefaultPhysicalDevices() override; + ResultOrError>> 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 7a4c720b1d..7606613406 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 8f5dc5d2ff..89d1b08d24 100644 --- a/src/dawn/native/vulkan/BackendVk.cpp +++ b/src/dawn/native/vulkan/BackendVk.cpp @@ -457,9 +457,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac Backend::~Backend() = default; -std::vector> Backend::DiscoverDefaultAdapters() { - AdapterDiscoveryOptions options; - auto result = DiscoverAdapters(&options); +std::vector> Backend::DiscoverDefaultPhysicalDevices() { + PhysicalDeviceDiscoveryOptions options; + auto result = DiscoverPhysicalDevices(&options); if (result.IsError()) { GetInstance()->ConsumedError(result.AcquireError()); return {}; @@ -467,12 +467,12 @@ std::vector> Backend::DiscoverDefaultAdapters() { return result.AcquireSuccess(); } -ResultOrError>> Backend::DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) { +ResultOrError>> Backend::DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* optionsBase) { ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan); - const AdapterDiscoveryOptions* options = - static_cast(optionsBase); + const PhysicalDeviceDiscoveryOptions* options = + static_cast(optionsBase); std::vector> physicalDevices; diff --git a/src/dawn/native/vulkan/BackendVk.h b/src/dawn/native/vulkan/BackendVk.h index 0c6c659807..cf45a70a6f 100644 --- a/src/dawn/native/vulkan/BackendVk.h +++ b/src/dawn/native/vulkan/BackendVk.h @@ -91,9 +91,9 @@ class Backend : public BackendConnection { MaybeError Initialize(); - std::vector> DiscoverDefaultAdapters() override; - ResultOrError>> DiscoverAdapters( - const AdapterDiscoveryOptionsBase* optionsBase) override; + std::vector> DiscoverDefaultPhysicalDevices() override; + ResultOrError>> DiscoverPhysicalDevices( + const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override; private: ityp::array, 2> mVulkanInstances = {}; diff --git a/src/dawn/native/vulkan/VulkanBackend.cpp b/src/dawn/native/vulkan/VulkanBackend.cpp index c4f282fe88..e2c183cc9d 100644 --- a/src/dawn/native/vulkan/VulkanBackend.cpp +++ b/src/dawn/native/vulkan/VulkanBackend.cpp @@ -36,8 +36,8 @@ DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, con 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 5be6a914bf..c3176d63f3 100644 --- a/src/dawn/samples/ManualSwapChainTest.cpp +++ b/src/dawn/samples/ManualSwapChainTest.cpp @@ -272,7 +272,7 @@ int main(int argc, const char* argv[]) { dawnProcSetProcs(&procs); instance = std::make_unique(); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); std::vector adapters = instance->GetAdapters(); dawn::native::Adapter chosenAdapter; diff --git a/src/dawn/samples/SampleUtils.cpp b/src/dawn/samples/SampleUtils.cpp index 9d11d889c2..33e886b66d 100644 --- a/src/dawn/samples/SampleUtils.cpp +++ b/src/dawn/samples/SampleUtils.cpp @@ -128,7 +128,7 @@ wgpu::Device CreateCppDawnDevice() { } instance = std::make_unique(); - 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 40a922e3d6..faea36c0c8 100644 --- a/src/dawn/tests/BUILD.gn +++ b/src/dawn/tests/BUILD.gn @@ -485,7 +485,7 @@ source_set("end2end_tests_sources") { ] sources = [ - "end2end/AdapterDiscoveryTests.cpp", + "end2end/AdapterCreationTests.cpp", "end2end/BasicTests.cpp", "end2end/BindGroupTests.cpp", "end2end/BufferTests.cpp", @@ -536,6 +536,7 @@ source_set("end2end_tests_sources") { "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 f71dde7b35..5e81c1c1de 100644 --- a/src/dawn/tests/DawnNativeTest.cpp +++ b/src/dawn/tests/DawnNativeTest.cpp @@ -64,7 +64,7 @@ void DawnNativeTest::SetUp() { instance = std::make_unique( reinterpret_cast(&instanceDesc)); instance->EnableAdapterBlocklist(false); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); std::vector adapters = instance->GetAdapters(); diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index 11a14df808..f34e69cb9f 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -416,7 +416,7 @@ std::unique_ptr DawnTestEnvironment::CreateInstanceAndDi } #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 660de4ad31..4549ec05e2 100644 --- a/src/dawn/tests/benchmarks/NullDeviceSetup.cpp +++ b/src/dawn/tests/benchmarks/NullDeviceSetup.cpp @@ -33,7 +33,7 @@ void SetupNullBackend(const benchmark::State& state) { if (!nativeInstance) { nativeInstance = std::make_unique(); - nativeInstance->DiscoverDefaultAdapters(); + nativeInstance->DiscoverDefaultPhysicalDevices(); } if (!nullBackendAdapter) { diff --git a/src/dawn/tests/end2end/AdapterDiscoveryTests.cpp b/src/dawn/tests/end2end/AdapterCreationTests.cpp similarity index 50% rename from src/dawn/tests/end2end/AdapterDiscoveryTests.cpp rename to src/dawn/tests/end2end/AdapterCreationTests.cpp index 904272d52f..bc3bba00b3 100644 --- a/src/dawn/tests/end2end/AdapterDiscoveryTests.cpp +++ b/src/dawn/tests/end2end/AdapterCreationTests.cpp @@ -1,4 +1,4 @@ -// Copyright 2021 The Dawn Authors +// 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. @@ -16,36 +16,11 @@ #include #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 +#include "gtest/gtest.h" namespace dawn { namespace { @@ -54,209 +29,15 @@ 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 dxgiFactory; - HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory)); - ASSERT_EQ(hr, S_OK); - - for (uint32_t adapterIndex = 0;; ++adapterIndex) { - ComPtr 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 dxgiFactory; - HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory)); - ASSERT_EQ(hr, S_OK); - - for (uint32_t adapterIndex = 0;; ++adapterIndex) { - ComPtr 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()); + dawnProcSetProcs(&native::GetProcs()); { - auto nativeInstance = std::make_unique(); - nativeInstance->DiscoverDefaultAdapters(); - for (dawn_native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) { + auto nativeInstance = std::make_unique(); + nativeInstance->DiscoverDefaultPhysicalDevices(); + for (native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) { anyAdapterAvailable = true; wgpu::AdapterProperties properties; diff --git a/src/dawn/tests/end2end/DeviceInitializationTests.cpp b/src/dawn/tests/end2end/DeviceInitializationTests.cpp index 69e4d5e863..03df13580a 100644 --- a/src/dawn/tests/end2end/DeviceInitializationTests.cpp +++ b/src/dawn/tests/end2end/DeviceInitializationTests.cpp @@ -78,7 +78,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) { { auto instance = std::make_unique(); instance->EnableAdapterBlocklist(false); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); for (const native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; adapter.GetProperties(&properties); @@ -96,7 +96,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) { auto instance = std::make_unique(); instance->EnableAdapterBlocklist(false); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); for (native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; adapter.GetProperties(&properties); @@ -127,7 +127,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) { { auto instance = std::make_unique(); instance->EnableAdapterBlocklist(false); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); for (const native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; adapter.GetProperties(&properties); @@ -152,7 +152,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) { // 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 0000000000..8ac0bdeb36 --- /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 +#include + +#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 + +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 dxgiFactory; + HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory)); + ASSERT_EQ(hr, S_OK); + + for (uint32_t adapterIndex = 0;; ++adapterIndex) { + ComPtr 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 dxgiFactory; + HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory)); + ASSERT_EQ(hr, S_OK); + + for (uint32_t adapterIndex = 0;; ++adapterIndex) { + ComPtr 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 0b69561bd8..256955ed23 100644 --- a/src/dawn/tests/unittests/ToggleTests.cpp +++ b/src/dawn/tests/unittests/ToggleTests.cpp @@ -170,10 +170,10 @@ TEST_F(InstanceToggleTest, InstanceTogglesInheritToAdapterAndDevice) { 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 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 620b4d553f..ea505c2137 100644 --- a/src/dawn/tests/unittests/native/DeviceCreationTests.cpp +++ b/src/dawn/tests/unittests/native/DeviceCreationTests.cpp @@ -43,7 +43,7 @@ class DeviceCreationTest : public testing::Test { // Create an instance with default toggles and create an adapter from it. WGPUInstanceDescriptor safeInstanceDesc = {}; instance = std::make_unique(&safeInstanceDesc); - instance->DiscoverDefaultAdapters(); + instance->DiscoverDefaultPhysicalDevices(); for (dawn::native::Adapter& nativeAdapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; nativeAdapter.GetProperties(&properties); @@ -67,7 +67,7 @@ class DeviceCreationTest : public testing::Test { unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain; unsafeInstanceDisallow = std::make_unique(&unsafeInstanceDesc); - unsafeInstanceDisallow->DiscoverDefaultAdapters(); + unsafeInstanceDisallow->DiscoverDefaultPhysicalDevices(); for (dawn::native::Adapter& nativeAdapter : unsafeInstanceDisallow->GetAdapters()) { wgpu::AdapterProperties properties; nativeAdapter.GetProperties(&properties); @@ -90,7 +90,7 @@ class DeviceCreationTest : public testing::Test { unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain; unsafeInstance = std::make_unique(&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 310021eba7..f032ba2c08 100644 --- a/src/dawn/tests/unittests/validation/ValidationTest.cpp +++ b/src/dawn/tests/unittests/validation/ValidationTest.cpp @@ -145,7 +145,7 @@ void ValidationTest::SetUp() { mDawnInstance = std::make_unique(&instanceDesc); - mDawnInstance->DiscoverDefaultAdapters(); + mDawnInstance->DiscoverDefaultPhysicalDevices(); mInstance = mWireHelper->RegisterInstance(mDawnInstance->Get()); std::string traceName =