From e4877b7e68992846f472c71fe62bc253efd68b8d Mon Sep 17 00:00:00 2001 From: Stephen White Date: Mon, 1 May 2023 16:39:04 +0000 Subject: [PATCH] Rename AdapterBase -> PhysicalDeviceBase. AdapterBase will become a (thin) wrapper class in an upcoming patch, allowing a single PhysicalDeviceBase to be wrapped in multiple AdapterBases, each with different toggles and flags. For now, alias AdapterBase to PhysicalDeviceBase. Design doc: https://docs.google.com/document/d/1Ag3UAD6D1OVt9-MwKltzLefVhwKRdX0RqML2etrYVS4/edit Change-Id: Ie77e99508be5285b651aa24ccb412bc9ff8b0111 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/130300 Reviewed-by: Austin Eng Kokoro: Kokoro Commit-Queue: Stephen White --- include/dawn/native/DawnNative.h | 9 +- src/dawn/native/Adapter.h | 121 +-------------- src/dawn/native/BUILD.gn | 3 +- src/dawn/native/BackendConnection.cpp | 2 +- src/dawn/native/BackendConnection.h | 6 +- src/dawn/native/CMakeLists.txt | 3 +- src/dawn/native/CommandValidation.cpp | 2 +- src/dawn/native/DawnNative.cpp | 4 +- src/dawn/native/Device.cpp | 6 +- src/dawn/native/Forward.h | 4 +- .../{Adapter.cpp => PhysicalDevice.cpp} | 67 +++++---- src/dawn/native/PhysicalDevice.h | 141 ++++++++++++++++++ src/dawn/native/SwapChain.cpp | 2 +- src/dawn/native/Texture.cpp | 2 +- src/dawn/native/ToBackend.h | 2 +- src/dawn/native/d3d/AdapterD3D.cpp | 2 +- src/dawn/native/d3d/AdapterD3D.h | 4 +- src/dawn/native/d3d/BackendD3D.cpp | 13 +- src/dawn/native/d3d/BackendD3D.h | 6 +- src/dawn/native/d3d11/AdapterD3D11.h | 2 +- src/dawn/native/d3d11/BackendD3D11.cpp | 2 +- src/dawn/native/d3d11/BackendD3D11.h | 2 +- src/dawn/native/d3d12/AdapterD3D12.h | 4 +- src/dawn/native/d3d12/BackendD3D12.cpp | 2 +- src/dawn/native/d3d12/BackendD3D12.h | 2 +- src/dawn/native/metal/BackendMTL.h | 4 +- src/dawn/native/metal/BackendMTL.mm | 14 +- src/dawn/native/null/DeviceNull.cpp | 6 +- src/dawn/native/null/DeviceNull.h | 8 +- src/dawn/native/opengl/AdapterGL.cpp | 2 +- src/dawn/native/opengl/AdapterGL.h | 6 +- src/dawn/native/opengl/BackendGL.cpp | 9 +- src/dawn/native/opengl/BackendGL.h | 4 +- src/dawn/native/vulkan/AdapterVk.cpp | 2 +- src/dawn/native/vulkan/AdapterVk.h | 6 +- src/dawn/native/vulkan/BackendVk.cpp | 7 +- src/dawn/native/vulkan/BackendVk.h | 4 +- .../unittests/validation/ValidationTest.cpp | 1 + 38 files changed, 262 insertions(+), 224 deletions(-) rename src/dawn/native/{Adapter.cpp => PhysicalDevice.cpp} (82%) create mode 100644 src/dawn/native/PhysicalDevice.h diff --git a/include/dawn/native/DawnNative.h b/include/dawn/native/DawnNative.h index 06e3f1182e..d7362a53d4 100644 --- a/include/dawn/native/DawnNative.h +++ b/include/dawn/native/DawnNative.h @@ -34,8 +34,7 @@ struct DeviceDescriptor; namespace dawn::native { class InstanceBase; -class AdapterBase; - +class PhysicalDeviceBase; // An optional parameter of Adapter::CreateDevice() to send additional information when creating // a Device. For example, we can use it to enable a workaround, optimization or feature. struct DAWN_NATIVE_EXPORT DawnDeviceDescriptor { @@ -85,8 +84,10 @@ struct FeatureInfo { class DAWN_NATIVE_EXPORT Adapter { public: Adapter(); + // TODO(dawn:1774): all references to PhysicalDeviceBase in this class will go back to + // using AdapterBase once the latter becomes a real class again. // NOLINTNEXTLINE(runtime/explicit) - Adapter(AdapterBase* impl); + Adapter(PhysicalDeviceBase* impl); ~Adapter(); Adapter(const Adapter& other); @@ -131,7 +132,7 @@ class DAWN_NATIVE_EXPORT Adapter { void ResetInternalDeviceForTesting(); private: - AdapterBase* mImpl = nullptr; + PhysicalDeviceBase* mImpl = nullptr; }; // Base class for options passed to Instance::DiscoverAdapters. diff --git a/src/dawn/native/Adapter.h b/src/dawn/native/Adapter.h index 2e8897573e..04af41ea45 100644 --- a/src/dawn/native/Adapter.h +++ b/src/dawn/native/Adapter.h @@ -15,127 +15,12 @@ #ifndef SRC_DAWN_NATIVE_ADAPTER_H_ #define SRC_DAWN_NATIVE_ADAPTER_H_ -#include -#include - -#include "dawn/native/DawnNative.h" - -#include "dawn/common/GPUInfo.h" -#include "dawn/common/RefCounted.h" -#include "dawn/common/ityp_span.h" -#include "dawn/native/Error.h" -#include "dawn/native/Features.h" -#include "dawn/native/Limits.h" -#include "dawn/native/Toggles.h" -#include "dawn/native/dawn_platform.h" +#include "dawn/native/PhysicalDevice.h" namespace dawn::native { -class DeviceBase; +using AdapterBase = PhysicalDeviceBase; -class AdapterBase : public RefCounted { - public: - AdapterBase(InstanceBase* instance, - wgpu::BackendType backend, - const TogglesState& adapterToggles); - ~AdapterBase() override; - - MaybeError Initialize(); - - // WebGPU API - InstanceBase* APIGetInstance() const; - bool APIGetLimits(SupportedLimits* limits) const; - void APIGetProperties(AdapterProperties* properties) const; - bool APIHasFeature(wgpu::FeatureName feature) const; - size_t APIEnumerateFeatures(wgpu::FeatureName* features) const; - void APIRequestDevice(const DeviceDescriptor* descriptor, - WGPURequestDeviceCallback callback, - void* userdata); - DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr); - - uint32_t GetVendorId() const; - uint32_t GetDeviceId() const; - const gpu_info::DriverVersion& GetDriverVersion() const; - wgpu::BackendType GetBackendType() const; - - // This method differs from APIGetInstance() in that it won't increase the ref count of the - // instance. - InstanceBase* GetInstance() const; - - void ResetInternalDeviceForTesting(); - - FeaturesSet GetSupportedFeatures() const; - bool SupportsAllRequiredFeatures( - const ityp::span& features) const; - - bool GetLimits(SupportedLimits* limits) const; - - void SetUseTieredLimits(bool useTieredLimits); - - // Get the actual toggles state of the adapter. - const TogglesState& GetTogglesState() const; - - virtual bool SupportsExternalImages() const = 0; - - protected: - uint32_t mVendorId = 0xFFFFFFFF; - std::string mVendorName; - std::string mArchitectureName; - uint32_t mDeviceId = 0xFFFFFFFF; - std::string mName; - wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown; - gpu_info::DriverVersion mDriverVersion; - std::string mDriverDescription; - - // Mark a feature as enabled in mSupportedFeatures. - void EnableFeature(Feature feature); - // Check if a feature os supported by this adapter AND suitable with given toggles. - // TODO(dawn:1495): After implementing adapter toggles, remove this and use adapter toggles - // instead of device toggles to validate supported features. - MaybeError ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature, - const TogglesState& toggles) const; - // Used for the tests that intend to use an adapter without all features enabled. - void SetSupportedFeaturesForTesting(const std::vector& requiredFeatures); - - private: - // Backend-specific force-setting and defaulting device toggles - virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0; - - virtual ResultOrError> CreateDeviceImpl(const DeviceDescriptor* descriptor, - const TogglesState& deviceToggles) = 0; - - virtual MaybeError InitializeImpl() = 0; - - // Check base WebGPU features and discover supported features. - virtual void InitializeSupportedFeaturesImpl() = 0; - - // Check base WebGPU limits and populate supported limits. - virtual MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) = 0; - - virtual void InitializeVendorArchitectureImpl(); - - virtual MaybeError ValidateFeatureSupportedWithTogglesImpl( - wgpu::FeatureName feature, - const TogglesState& toggles) const = 0; - - ResultOrError> CreateDeviceInternal(const DeviceDescriptor* descriptor); - - virtual MaybeError ResetInternalDeviceForTestingImpl(); - Ref mInstance; - wgpu::BackendType mBackend; - - // Adapter toggles state, currently only inherited from instance toggles state. - TogglesState mTogglesState; - - // Features set that CAN be supported by devices of this adapter. Some features in this set may - // be guarded by toggles, and creating a device with these features required may result in a - // validation error if proper toggles are not enabled/disabled. - FeaturesSet mSupportedFeatures; - - CombinedLimits mLimits; - bool mUseTieredLimits = false; -}; - -} // namespace dawn::native +} #endif // SRC_DAWN_NATIVE_ADAPTER_H_ diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 8db76d0fab..828b4501c3 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -184,7 +184,6 @@ source_set("sources") { sources = get_target_outputs(":utils_gen") sources += [ - "Adapter.cpp", "Adapter.h", "ApplyClearColorValueWithDrawHelper.cpp", "ApplyClearColorValueWithDrawHelper.h", @@ -290,6 +289,8 @@ source_set("sources") { "PassResourceUsageTracker.h", "PerStage.cpp", "PerStage.h", + "PhysicalDevice.cpp", + "PhysicalDevice.h", "Pipeline.cpp", "Pipeline.h", "PipelineCache.cpp", diff --git a/src/dawn/native/BackendConnection.cpp b/src/dawn/native/BackendConnection.cpp index 303b8b1d6f..90b74fbb4f 100644 --- a/src/dawn/native/BackendConnection.cpp +++ b/src/dawn/native/BackendConnection.cpp @@ -28,7 +28,7 @@ InstanceBase* BackendConnection::GetInstance() const { return mInstance; } -ResultOrError>> BackendConnection::DiscoverAdapters( +ResultOrError>> BackendConnection::DiscoverAdapters( const AdapterDiscoveryOptionsBase* options, const TogglesState& adapterToggles) { return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend."); diff --git a/src/dawn/native/BackendConnection.h b/src/dawn/native/BackendConnection.h index 8d279df570..3c0748e5b3 100644 --- a/src/dawn/native/BackendConnection.h +++ b/src/dawn/native/BackendConnection.h @@ -18,8 +18,8 @@ #include #include -#include "dawn/native/Adapter.h" #include "dawn/native/DawnNative.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/Toggles.h" namespace dawn::native { @@ -36,11 +36,11 @@ class BackendConnection { // 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( + virtual std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) = 0; // Returns new adapters created with the backend-specific options. - virtual ResultOrError>> DiscoverAdapters( + virtual ResultOrError>> DiscoverAdapters( const AdapterDiscoveryOptionsBase* options, const TogglesState& adapterToggles); diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index 89fd13bfdb..4ff89dfac5 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -30,7 +30,6 @@ target_sources(dawn_native PRIVATE "${DAWN_INCLUDE_DIR}/dawn/native/DawnNative.h" "${DAWN_INCLUDE_DIR}/dawn/native/dawn_native_export.h" ${DAWN_NATIVE_UTILS_GEN_SOURCES} - "Adapter.cpp" "Adapter.h" "ApplyClearColorValueWithDrawHelper.cpp" "ApplyClearColorValueWithDrawHelper.h" @@ -136,6 +135,8 @@ target_sources(dawn_native PRIVATE "PassResourceUsageTracker.h" "PerStage.cpp" "PerStage.h" + "PhysicalDevice.cpp" + "PhysicalDevice.h" "Pipeline.cpp" "Pipeline.h" "PipelineCache.cpp" diff --git a/src/dawn/native/CommandValidation.cpp b/src/dawn/native/CommandValidation.cpp index eff94f2c9d..f420b85fb3 100644 --- a/src/dawn/native/CommandValidation.cpp +++ b/src/dawn/native/CommandValidation.cpp @@ -22,7 +22,6 @@ #include "dawn/common/BitSetIterator.h" #include "dawn/common/Numeric.h" -#include "dawn/native/Adapter.h" #include "dawn/native/BindGroup.h" #include "dawn/native/Buffer.h" #include "dawn/native/CommandBufferStateTracker.h" @@ -30,6 +29,7 @@ #include "dawn/native/Device.h" #include "dawn/native/Instance.h" #include "dawn/native/PassResourceUsage.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/QuerySet.h" #include "dawn/native/RenderBundle.h" #include "dawn/native/RenderPipeline.h" diff --git a/src/dawn/native/DawnNative.cpp b/src/dawn/native/DawnNative.cpp index 21d8f41748..1ff26894e0 100644 --- a/src/dawn/native/DawnNative.cpp +++ b/src/dawn/native/DawnNative.cpp @@ -81,7 +81,7 @@ DawnDeviceDescriptor::~DawnDeviceDescriptor() = default; Adapter::Adapter() = default; -Adapter::Adapter(AdapterBase* impl) : mImpl(impl) { +Adapter::Adapter(PhysicalDeviceBase* impl) : mImpl(impl) { if (mImpl != nullptr) { mImpl->Reference(); } @@ -210,7 +210,7 @@ bool Instance::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) { std::vector Instance::GetAdapters() const { // Adapters are owned by mImpl so it is safe to return non RAII pointers to them std::vector adapters; - for (const Ref& adapter : mImpl->GetAdapters()) { + for (const Ref& adapter : mImpl->GetAdapters()) { adapters.push_back(Adapter(adapter.Get())); } return adapters; diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp index abebac8138..f14c67a110 100644 --- a/src/dawn/native/Device.cpp +++ b/src/dawn/native/Device.cpp @@ -21,7 +21,6 @@ #include "dawn/common/Log.h" #include "dawn/common/Version_autogen.h" -#include "dawn/native/Adapter.h" #include "dawn/native/AsyncTask.h" #include "dawn/native/AttachmentState.h" #include "dawn/native/BindGroup.h" @@ -42,6 +41,7 @@ #include "dawn/native/Instance.h" #include "dawn/native/InternalPipelineStore.h" #include "dawn/native/ObjectType_autogen.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/PipelineCache.h" #include "dawn/native/QuerySet.h" #include "dawn/native/Queue.h" @@ -719,7 +719,7 @@ ApiObjectList* DeviceBase::GetObjectTrackingList(ObjectType type) { return &mObjectLists[type]; } -AdapterBase* DeviceBase::GetAdapter() const { +PhysicalDeviceBase* DeviceBase::GetAdapter() const { return mAdapter.Get(); } @@ -1345,7 +1345,7 @@ MaybeError DeviceBase::Tick() { return {}; } -AdapterBase* DeviceBase::APIGetAdapter() { +PhysicalDeviceBase* DeviceBase::APIGetAdapter() { mAdapter->Reference(); return mAdapter.Get(); } diff --git a/src/dawn/native/Forward.h b/src/dawn/native/Forward.h index 8f63e202db..f280785acf 100644 --- a/src/dawn/native/Forward.h +++ b/src/dawn/native/Forward.h @@ -24,7 +24,6 @@ namespace dawn::native { enum class ObjectType : uint32_t; -class AdapterBase; class BindGroupBase; class BindGroupLayoutBase; class BufferBase; @@ -34,6 +33,7 @@ class CommandEncoder; class ComputePassEncoder; class ExternalTextureBase; class InstanceBase; +class PhysicalDeviceBase; class PipelineBase; class PipelineCacheBase; class PipelineLayoutBase; @@ -51,6 +51,8 @@ class SwapChainBase; class TextureBase; class TextureViewBase; +using AdapterBase = PhysicalDeviceBase; + class DeviceBase; template diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/PhysicalDevice.cpp similarity index 82% rename from src/dawn/native/Adapter.cpp rename to src/dawn/native/PhysicalDevice.cpp index 7e037cc2c3..54e318a4f0 100644 --- a/src/dawn/native/Adapter.cpp +++ b/src/dawn/native/PhysicalDevice.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "dawn/native/Adapter.h" +#include "dawn/native/PhysicalDevice.h" #include #include @@ -27,16 +27,16 @@ namespace dawn::native { -AdapterBase::AdapterBase(InstanceBase* instance, - wgpu::BackendType backend, - const TogglesState& adapterToggles) +PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance, + wgpu::BackendType backend, + const TogglesState& adapterToggles) : mInstance(instance), mBackend(backend), mTogglesState(adapterToggles) { ASSERT(adapterToggles.GetStage() == ToggleStage::Adapter); } -AdapterBase::~AdapterBase() = default; +PhysicalDeviceBase::~PhysicalDeviceBase() = default; -MaybeError AdapterBase::Initialize() { +MaybeError PhysicalDeviceBase::Initialize() { DAWN_TRY_CONTEXT(InitializeImpl(), "initializing adapter (backend=%s)", mBackend); InitializeVendorArchitectureImpl(); @@ -84,18 +84,18 @@ MaybeError AdapterBase::Initialize() { return {}; } -InstanceBase* AdapterBase::APIGetInstance() const { +InstanceBase* PhysicalDeviceBase::APIGetInstance() const { auto instance = GetInstance(); ASSERT(instance != nullptr); instance->APIReference(); return instance; } -bool AdapterBase::APIGetLimits(SupportedLimits* limits) const { +bool PhysicalDeviceBase::APIGetLimits(SupportedLimits* limits) const { return GetLimits(limits); } -void AdapterBase::APIGetProperties(AdapterProperties* properties) const { +void PhysicalDeviceBase::APIGetProperties(AdapterProperties* properties) const { MaybeError result = ValidateSingleSType(properties->nextInChain, wgpu::SType::DawnAdapterPropertiesPowerPreference); if (result.IsError()) { @@ -119,15 +119,15 @@ void AdapterBase::APIGetProperties(AdapterProperties* properties) const { properties->backendType = mBackend; } -bool AdapterBase::APIHasFeature(wgpu::FeatureName feature) const { +bool PhysicalDeviceBase::APIHasFeature(wgpu::FeatureName feature) const { return mSupportedFeatures.IsEnabled(feature); } -size_t AdapterBase::APIEnumerateFeatures(wgpu::FeatureName* features) const { +size_t PhysicalDeviceBase::APIEnumerateFeatures(wgpu::FeatureName* features) const { return mSupportedFeatures.EnumerateFeatures(features); } -DeviceBase* AdapterBase::APICreateDevice(const DeviceDescriptor* descriptor) { +DeviceBase* PhysicalDeviceBase::APICreateDevice(const DeviceDescriptor* descriptor) { DeviceDescriptor defaultDesc = {}; if (descriptor == nullptr) { descriptor = &defaultDesc; @@ -140,9 +140,9 @@ DeviceBase* AdapterBase::APICreateDevice(const DeviceDescriptor* descriptor) { return result.AcquireSuccess().Detach(); } -void AdapterBase::APIRequestDevice(const DeviceDescriptor* descriptor, - WGPURequestDeviceCallback callback, - void* userdata) { +void PhysicalDeviceBase::APIRequestDevice(const DeviceDescriptor* descriptor, + WGPURequestDeviceCallback callback, + void* userdata) { static constexpr DeviceDescriptor kDefaultDescriptor = {}; if (descriptor == nullptr) { descriptor = &kDefaultDescriptor; @@ -165,36 +165,36 @@ void AdapterBase::APIRequestDevice(const DeviceDescriptor* descriptor, callback(status, ToAPI(device.Detach()), nullptr, userdata); } -void AdapterBase::InitializeVendorArchitectureImpl() { +void PhysicalDeviceBase::InitializeVendorArchitectureImpl() { mVendorName = gpu_info::GetVendorName(mVendorId); mArchitectureName = gpu_info::GetArchitectureName(mVendorId, mDeviceId); } -uint32_t AdapterBase::GetVendorId() const { +uint32_t PhysicalDeviceBase::GetVendorId() const { return mVendorId; } -uint32_t AdapterBase::GetDeviceId() const { +uint32_t PhysicalDeviceBase::GetDeviceId() const { return mDeviceId; } -const gpu_info::DriverVersion& AdapterBase::GetDriverVersion() const { +const gpu_info::DriverVersion& PhysicalDeviceBase::GetDriverVersion() const { return mDriverVersion; } -wgpu::BackendType AdapterBase::GetBackendType() const { +wgpu::BackendType PhysicalDeviceBase::GetBackendType() const { return mBackend; } -InstanceBase* AdapterBase::GetInstance() const { +InstanceBase* PhysicalDeviceBase::GetInstance() const { return mInstance.Get(); } -FeaturesSet AdapterBase::GetSupportedFeatures() const { +FeaturesSet PhysicalDeviceBase::GetSupportedFeatures() const { return mSupportedFeatures; } -bool AdapterBase::SupportsAllRequiredFeatures( +bool PhysicalDeviceBase::SupportsAllRequiredFeatures( const ityp::span& features) const { for (wgpu::FeatureName f : features) { if (!mSupportedFeatures.IsEnabled(f)) { @@ -204,7 +204,7 @@ bool AdapterBase::SupportsAllRequiredFeatures( return true; } -bool AdapterBase::GetLimits(SupportedLimits* limits) const { +bool PhysicalDeviceBase::GetLimits(SupportedLimits* limits) const { ASSERT(limits != nullptr); if (limits->nextInChain != nullptr) { return false; @@ -217,16 +217,17 @@ bool AdapterBase::GetLimits(SupportedLimits* limits) const { return true; } -const TogglesState& AdapterBase::GetTogglesState() const { +const TogglesState& PhysicalDeviceBase::GetTogglesState() const { return mTogglesState; } -void AdapterBase::EnableFeature(Feature feature) { +void PhysicalDeviceBase::EnableFeature(Feature feature) { mSupportedFeatures.EnableFeature(feature); } -MaybeError AdapterBase::ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature, - const TogglesState& toggles) const { +MaybeError PhysicalDeviceBase::ValidateFeatureSupportedWithToggles( + wgpu::FeatureName feature, + const TogglesState& toggles) const { DAWN_TRY(ValidateFeatureName(feature)); DAWN_INVALID_IF(!mSupportedFeatures.IsEnabled(feature), "Requested feature %s is not supported.", feature); @@ -243,7 +244,7 @@ MaybeError AdapterBase::ValidateFeatureSupportedWithToggles(wgpu::FeatureName fe return ValidateFeatureSupportedWithTogglesImpl(feature, toggles); } -void AdapterBase::SetSupportedFeaturesForTesting( +void PhysicalDeviceBase::SetSupportedFeaturesForTesting( const std::vector& requiredFeatures) { mSupportedFeatures = {}; for (wgpu::FeatureName f : requiredFeatures) { @@ -251,7 +252,7 @@ void AdapterBase::SetSupportedFeaturesForTesting( } } -ResultOrError> AdapterBase::CreateDeviceInternal( +ResultOrError> PhysicalDeviceBase::CreateDeviceInternal( const DeviceDescriptor* descriptor) { ASSERT(descriptor != nullptr); @@ -291,15 +292,15 @@ ResultOrError> AdapterBase::CreateDeviceInternal( return CreateDeviceImpl(descriptor, deviceToggles); } -void AdapterBase::SetUseTieredLimits(bool useTieredLimits) { +void PhysicalDeviceBase::SetUseTieredLimits(bool useTieredLimits) { mUseTieredLimits = useTieredLimits; } -void AdapterBase::ResetInternalDeviceForTesting() { +void PhysicalDeviceBase::ResetInternalDeviceForTesting() { mInstance->ConsumedError(ResetInternalDeviceForTestingImpl()); } -MaybeError AdapterBase::ResetInternalDeviceForTestingImpl() { +MaybeError PhysicalDeviceBase::ResetInternalDeviceForTestingImpl() { return DAWN_INTERNAL_ERROR( "ResetInternalDeviceForTesting should only be used with the D3D12 backend."); } diff --git a/src/dawn/native/PhysicalDevice.h b/src/dawn/native/PhysicalDevice.h new file mode 100644 index 0000000000..009de1b859 --- /dev/null +++ b/src/dawn/native/PhysicalDevice.h @@ -0,0 +1,141 @@ +// Copyright 2018 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. + +#ifndef SRC_DAWN_NATIVE_PHYSICALDEVICE_H_ +#define SRC_DAWN_NATIVE_PHYSICALDEVICE_H_ + +#include +#include + +#include "dawn/native/DawnNative.h" + +#include "dawn/common/GPUInfo.h" +#include "dawn/common/RefCounted.h" +#include "dawn/common/ityp_span.h" +#include "dawn/native/Error.h" +#include "dawn/native/Features.h" +#include "dawn/native/Limits.h" +#include "dawn/native/Toggles.h" +#include "dawn/native/dawn_platform.h" + +namespace dawn::native { + +class DeviceBase; + +class PhysicalDeviceBase : public RefCounted { + public: + PhysicalDeviceBase(InstanceBase* instance, + wgpu::BackendType backend, + const TogglesState& adapterToggles); + ~PhysicalDeviceBase() override; + + MaybeError Initialize(); + + // WebGPU API + InstanceBase* APIGetInstance() const; + bool APIGetLimits(SupportedLimits* limits) const; + void APIGetProperties(AdapterProperties* properties) const; + bool APIHasFeature(wgpu::FeatureName feature) const; + size_t APIEnumerateFeatures(wgpu::FeatureName* features) const; + void APIRequestDevice(const DeviceDescriptor* descriptor, + WGPURequestDeviceCallback callback, + void* userdata); + DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr); + + uint32_t GetVendorId() const; + uint32_t GetDeviceId() const; + const gpu_info::DriverVersion& GetDriverVersion() const; + wgpu::BackendType GetBackendType() const; + + // This method differs from APIGetInstance() in that it won't increase the ref count of the + // instance. + InstanceBase* GetInstance() const; + + void ResetInternalDeviceForTesting(); + + FeaturesSet GetSupportedFeatures() const; + bool SupportsAllRequiredFeatures( + const ityp::span& features) const; + + bool GetLimits(SupportedLimits* limits) const; + + void SetUseTieredLimits(bool useTieredLimits); + + // Get the actual toggles state of the adapter. + const TogglesState& GetTogglesState() const; + + virtual bool SupportsExternalImages() const = 0; + + protected: + uint32_t mVendorId = 0xFFFFFFFF; + std::string mVendorName; + std::string mArchitectureName; + uint32_t mDeviceId = 0xFFFFFFFF; + std::string mName; + wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown; + gpu_info::DriverVersion mDriverVersion; + std::string mDriverDescription; + + // Mark a feature as enabled in mSupportedFeatures. + void EnableFeature(Feature feature); + // Check if a feature os supported by this adapter AND suitable with given toggles. + // TODO(dawn:1495): After implementing adapter toggles, remove this and use adapter toggles + // instead of device toggles to validate supported features. + MaybeError ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature, + const TogglesState& toggles) const; + // Used for the tests that intend to use an adapter without all features enabled. + void SetSupportedFeaturesForTesting(const std::vector& requiredFeatures); + + private: + // Backend-specific force-setting and defaulting device toggles + virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0; + + virtual ResultOrError> CreateDeviceImpl(const DeviceDescriptor* descriptor, + const TogglesState& deviceToggles) = 0; + + virtual MaybeError InitializeImpl() = 0; + + // Check base WebGPU features and discover supported features. + virtual void InitializeSupportedFeaturesImpl() = 0; + + // Check base WebGPU limits and populate supported limits. + virtual MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) = 0; + + virtual void InitializeVendorArchitectureImpl(); + + virtual MaybeError ValidateFeatureSupportedWithTogglesImpl( + wgpu::FeatureName feature, + const TogglesState& toggles) const = 0; + + ResultOrError> CreateDeviceInternal(const DeviceDescriptor* descriptor); + + virtual MaybeError ResetInternalDeviceForTestingImpl(); + Ref mInstance; + wgpu::BackendType mBackend; + + // Adapter toggles state, currently only inherited from instance toggles state. + TogglesState mTogglesState; + + // Features set that CAN be supported by devices of this adapter. Some features in this set may + // be guarded by toggles, and creating a device with these features required may result in a + // validation error if proper toggles are not enabled/disabled. + FeaturesSet mSupportedFeatures; + + CombinedLimits mLimits; + bool mUseTieredLimits = false; +}; + +} // namespace dawn::native + +#endif // SRC_DAWN_NATIVE_PHYSICALDEVICE_H_ diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp index 97590acfb8..da06e3ac73 100644 --- a/src/dawn/native/SwapChain.cpp +++ b/src/dawn/native/SwapChain.cpp @@ -15,9 +15,9 @@ #include "dawn/native/SwapChain.h" #include "dawn/common/Constants.h" -#include "dawn/native/Adapter.h" #include "dawn/native/Device.h" #include "dawn/native/ObjectType_autogen.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/Surface.h" #include "dawn/native/Texture.h" #include "dawn/native/ValidationUtils_autogen.h" diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp index 6a97f4dc74..521ad8bf90 100644 --- a/src/dawn/native/Texture.cpp +++ b/src/dawn/native/Texture.cpp @@ -20,12 +20,12 @@ #include "dawn/common/Assert.h" #include "dawn/common/Constants.h" #include "dawn/common/Math.h" -#include "dawn/native/Adapter.h" #include "dawn/native/ChainUtils_autogen.h" #include "dawn/native/Device.h" #include "dawn/native/EnumMaskIterator.h" #include "dawn/native/ObjectType_autogen.h" #include "dawn/native/PassResourceUsage.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/ValidationUtils_autogen.h" namespace dawn::native { diff --git a/src/dawn/native/ToBackend.h b/src/dawn/native/ToBackend.h index 9b40c662c6..a4758e27ca 100644 --- a/src/dawn/native/ToBackend.h +++ b/src/dawn/native/ToBackend.h @@ -24,7 +24,7 @@ template struct ToBackendTraits; template -struct ToBackendTraits { +struct ToBackendTraits { using BackendType = typename BackendTraits::AdapterType; }; diff --git a/src/dawn/native/d3d/AdapterD3D.cpp b/src/dawn/native/d3d/AdapterD3D.cpp index b2e3746261..34dd1592e2 100644 --- a/src/dawn/native/d3d/AdapterD3D.cpp +++ b/src/dawn/native/d3d/AdapterD3D.cpp @@ -26,7 +26,7 @@ Adapter::Adapter(Backend* backend, ComPtr hardwareAdapter, wgpu::BackendType backendType, const TogglesState& adapterToggles) - : AdapterBase(backend->GetInstance(), backendType, adapterToggles), + : PhysicalDeviceBase(backend->GetInstance(), backendType, adapterToggles), mHardwareAdapter(std::move(hardwareAdapter)), mBackend(backend) {} diff --git a/src/dawn/native/d3d/AdapterD3D.h b/src/dawn/native/d3d/AdapterD3D.h index da5ceee00a..86ada890dc 100644 --- a/src/dawn/native/d3d/AdapterD3D.h +++ b/src/dawn/native/d3d/AdapterD3D.h @@ -15,7 +15,7 @@ #ifndef SRC_DAWN_NATIVE_D3D_ADAPTERD3D_H_ #define SRC_DAWN_NATIVE_D3D_ADAPTERD3D_H_ -#include "dawn/native/Adapter.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/d3d/d3d_platform.h" @@ -23,7 +23,7 @@ namespace dawn::native::d3d { class Backend; -class Adapter : public AdapterBase { +class Adapter : public PhysicalDeviceBase { public: Adapter(Backend* backend, ComPtr hardwareAdapter, diff --git a/src/dawn/native/d3d/BackendD3D.cpp b/src/dawn/native/d3d/BackendD3D.cpp index 2fd5b7b7c5..3c36033d07 100644 --- a/src/dawn/native/d3d/BackendD3D.cpp +++ b/src/dawn/native/d3d/BackendD3D.cpp @@ -238,26 +238,27 @@ const PlatformFunctions* Backend::GetFunctions() const { return mFunctions.get(); } -std::vector> Backend::DiscoverDefaultAdapters(const TogglesState& adapterToggles) { +std::vector> Backend::DiscoverDefaultAdapters( + const TogglesState& adapterToggles) { AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr); - std::vector> adapters; + std::vector> adapters; if (GetInstance()->ConsumedError(DiscoverAdapters(&options, adapterToggles), &adapters)) { return {}; } return adapters; } -ResultOrError>> Backend::DiscoverAdapters( +ResultOrError>> Backend::DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) { ASSERT(optionsBase->backendType == ToAPI(GetType())); const AdapterDiscoveryOptions* options = static_cast(optionsBase); - std::vector> adapters; + std::vector> adapters; if (options->dxgiAdapter != nullptr) { // |dxgiAdapter| was provided. Discover just that adapter. - Ref adapter; + Ref adapter; DAWN_TRY_ASSIGN(adapter, CreateAdapterFromIDXGIAdapter(options->dxgiAdapter, adapterToggles)); adapters.push_back(std::move(adapter)); @@ -272,7 +273,7 @@ ResultOrError>> Backend::DiscoverAdapters( } ASSERT(dxgiAdapter != nullptr); - Ref adapter; + Ref adapter; if (GetInstance()->ConsumedError(CreateAdapterFromIDXGIAdapter(dxgiAdapter, adapterToggles), &adapter)) { continue; diff --git a/src/dawn/native/d3d/BackendD3D.h b/src/dawn/native/d3d/BackendD3D.h index efb53bc09b..a4137130f0 100644 --- a/src/dawn/native/d3d/BackendD3D.h +++ b/src/dawn/native/d3d/BackendD3D.h @@ -75,14 +75,14 @@ class Backend : public BackendConnection { const PlatformFunctions* GetFunctions() const; - std::vector> DiscoverDefaultAdapters( + std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) override; - ResultOrError>> DiscoverAdapters( + ResultOrError>> DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) override; protected: - virtual ResultOrError> CreateAdapterFromIDXGIAdapter( + virtual ResultOrError> CreateAdapterFromIDXGIAdapter( ComPtr dxgiAdapter, const TogglesState& adapterToggles) = 0; diff --git a/src/dawn/native/d3d11/AdapterD3D11.h b/src/dawn/native/d3d11/AdapterD3D11.h index ff63d922d6..41c281b38e 100644 --- a/src/dawn/native/d3d11/AdapterD3D11.h +++ b/src/dawn/native/d3d11/AdapterD3D11.h @@ -31,7 +31,7 @@ class Adapter : public d3d::Adapter { const TogglesState& adapterToggles); ~Adapter() override; - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override; const DeviceInfo& GetDeviceInfo() const; diff --git a/src/dawn/native/d3d11/BackendD3D11.cpp b/src/dawn/native/d3d11/BackendD3D11.cpp index 4340ee26c6..6bdf1e73fb 100644 --- a/src/dawn/native/d3d11/BackendD3D11.cpp +++ b/src/dawn/native/d3d11/BackendD3D11.cpp @@ -41,7 +41,7 @@ const PlatformFunctions* Backend::GetFunctions() const { return static_cast(Base::GetFunctions()); } -ResultOrError> Backend::CreateAdapterFromIDXGIAdapter( +ResultOrError> Backend::CreateAdapterFromIDXGIAdapter( ComPtr dxgiAdapter, const TogglesState& adapterToggles) { ComPtr dxgiAdapter3; diff --git a/src/dawn/native/d3d11/BackendD3D11.h b/src/dawn/native/d3d11/BackendD3D11.h index 422aff6bf6..8e3cbb7df0 100644 --- a/src/dawn/native/d3d11/BackendD3D11.h +++ b/src/dawn/native/d3d11/BackendD3D11.h @@ -31,7 +31,7 @@ class Backend : public d3d::Backend { const PlatformFunctions* GetFunctions() const; protected: - ResultOrError> CreateAdapterFromIDXGIAdapter( + ResultOrError> CreateAdapterFromIDXGIAdapter( ComPtr dxgiAdapter, const TogglesState& adapterToggles) override; diff --git a/src/dawn/native/d3d12/AdapterD3D12.h b/src/dawn/native/d3d12/AdapterD3D12.h index 63b0ae6547..cbdd03f9bb 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.h +++ b/src/dawn/native/d3d12/AdapterD3D12.h @@ -15,7 +15,7 @@ #ifndef SRC_DAWN_NATIVE_D3D12_ADAPTERD3D12_H_ #define SRC_DAWN_NATIVE_D3D12_ADAPTERD3D12_H_ -#include "dawn/native/Adapter.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/d3d/AdapterD3D.h" #include "dawn/native/d3d12/D3D12Info.h" @@ -32,7 +32,7 @@ class Adapter : public d3d::Adapter { const TogglesState& adapterToggles); ~Adapter() override; - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override; const D3D12DeviceInfo& GetDeviceInfo() const; diff --git a/src/dawn/native/d3d12/BackendD3D12.cpp b/src/dawn/native/d3d12/BackendD3D12.cpp index b0ccf6a531..5cece4a60b 100644 --- a/src/dawn/native/d3d12/BackendD3D12.cpp +++ b/src/dawn/native/d3d12/BackendD3D12.cpp @@ -63,7 +63,7 @@ const PlatformFunctions* Backend::GetFunctions() const { return static_cast(Base::GetFunctions()); } -ResultOrError> Backend::CreateAdapterFromIDXGIAdapter( +ResultOrError> Backend::CreateAdapterFromIDXGIAdapter( ComPtr dxgiAdapter, const TogglesState& adapterToggles) { ComPtr dxgiAdapter3; diff --git a/src/dawn/native/d3d12/BackendD3D12.h b/src/dawn/native/d3d12/BackendD3D12.h index 8342084c4c..6170bc0f71 100644 --- a/src/dawn/native/d3d12/BackendD3D12.h +++ b/src/dawn/native/d3d12/BackendD3D12.h @@ -35,7 +35,7 @@ class Backend final : public d3d::Backend { const PlatformFunctions* GetFunctions() const; protected: - ResultOrError> CreateAdapterFromIDXGIAdapter( + ResultOrError> CreateAdapterFromIDXGIAdapter( ComPtr dxgiAdapter, const TogglesState& adapterToggles) override; diff --git a/src/dawn/native/metal/BackendMTL.h b/src/dawn/native/metal/BackendMTL.h index b5b9601b03..38025ee1e1 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( + std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) override; - ResultOrError>> DiscoverAdapters( + ResultOrError>> DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) override; }; diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm index c751b6adb5..8e467632ed 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -253,10 +253,11 @@ DAWN_NOINLINE bool IsGPUCounterSupported(id device, // The Metal backend's Adapter. -class Adapter : public AdapterBase { +class Adapter : public PhysicalDeviceBase { public: Adapter(InstanceBase* instance, id device, const TogglesState& requiredAdapterToggle) - : AdapterBase(instance, wgpu::BackendType::Metal, requiredAdapterToggle), mDevice(device) { + : PhysicalDeviceBase(instance, wgpu::BackendType::Metal, requiredAdapterToggle), + mDevice(device) { mName = std::string([[*mDevice name] UTF8String]); PCIIDs ids; @@ -283,7 +284,7 @@ class Adapter : public AdapterBase { mDriverDescription = "Metal driver on " + std::string(systemName) + [osVersion UTF8String]; } - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override { // Via dawn::native::metal::WrapIOSurface return true; @@ -786,7 +787,8 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac Backend::~Backend() = default; -std::vector> Backend::DiscoverDefaultAdapters(const TogglesState& adapterToggles) { +std::vector> Backend::DiscoverDefaultAdapters( + const TogglesState& adapterToggles) { AdapterDiscoveryOptions options; auto result = DiscoverAdapters(&options, adapterToggles); if (result.IsError()) { @@ -796,12 +798,12 @@ std::vector> Backend::DiscoverDefaultAdapters(const TogglesStat return result.AcquireSuccess(); } -ResultOrError>> Backend::DiscoverAdapters( +ResultOrError>> Backend::DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) { ASSERT(optionsBase->backendType == WGPUBackendType_Metal); - std::vector> adapters; + std::vector> adapters; #if DAWN_PLATFORM_IS(MACOS) NSRef>> devices = AcquireNSRef(MTLCopyAllDevices()); diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp index 0bf820edf2..26632fdb0b 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp @@ -35,7 +35,7 @@ Adapter::Adapter(InstanceBase* instance) TogglesState(ToggleStage::Adapter).InheritFrom(instance->GetTogglesState())) {} Adapter::Adapter(InstanceBase* instance, const TogglesState& adapterToggles) - : AdapterBase(instance, wgpu::BackendType::Null, adapterToggles) { + : PhysicalDeviceBase(instance, wgpu::BackendType::Null, adapterToggles) { mVendorId = 0; mDeviceId = 0; mName = "Null backend"; @@ -83,11 +83,11 @@ class Backend : public BackendConnection { explicit Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::BackendType::Null) {} - std::vector> DiscoverDefaultAdapters( + std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) override { // There is always a single Null adapter because it is purely CPU based and doesn't // depend on the system. - std::vector> adapters; + std::vector> adapters; Ref adapter = AcquireRef(new Adapter(GetInstance(), adapterToggles)); adapters.push_back(std::move(adapter)); return adapters; diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h index 927c458b7a..641ca3284e 100644 --- a/src/dawn/native/null/DeviceNull.h +++ b/src/dawn/native/null/DeviceNull.h @@ -18,7 +18,6 @@ #include #include -#include "dawn/native/Adapter.h" #include "dawn/native/BindGroup.h" #include "dawn/native/BindGroupLayout.h" #include "dawn/native/Buffer.h" @@ -26,6 +25,7 @@ #include "dawn/native/CommandEncoder.h" #include "dawn/native/ComputePipeline.h" #include "dawn/native/Device.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/PipelineLayout.h" #include "dawn/native/QuerySet.h" #include "dawn/native/Queue.h" @@ -170,7 +170,7 @@ class Device final : public DeviceBase { size_t mMemoryUsage = 0; }; -class Adapter : public AdapterBase { +class Adapter : public PhysicalDeviceBase { public: // Create null adapter without providing toggles state for testing, only inherit instance's // toggles state @@ -178,11 +178,11 @@ class Adapter : public AdapterBase { Adapter(InstanceBase* instance, const TogglesState& adapterToggles); ~Adapter() override; - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override; // Used for the tests that intend to use an adapter without all features enabled. - using AdapterBase::SetSupportedFeaturesForTesting; + using PhysicalDeviceBase::SetSupportedFeaturesForTesting; private: MaybeError InitializeImpl() override; diff --git a/src/dawn/native/opengl/AdapterGL.cpp b/src/dawn/native/opengl/AdapterGL.cpp index afd75b4d6d..c1b1f33dc7 100644 --- a/src/dawn/native/opengl/AdapterGL.cpp +++ b/src/dawn/native/opengl/AdapterGL.cpp @@ -56,7 +56,7 @@ uint32_t GetVendorIdFromVendors(const char* vendor) { Adapter::Adapter(InstanceBase* instance, wgpu::BackendType backendType, const TogglesState& adapterToggle) - : AdapterBase(instance, backendType, adapterToggle) {} + : PhysicalDeviceBase(instance, backendType, adapterToggle) {} MaybeError Adapter::InitializeGLFunctions(void* (*getProc)(const char*)) { // Use getProc to populate the dispatch table diff --git a/src/dawn/native/opengl/AdapterGL.h b/src/dawn/native/opengl/AdapterGL.h index 7f43ce0486..7e67e961f1 100644 --- a/src/dawn/native/opengl/AdapterGL.h +++ b/src/dawn/native/opengl/AdapterGL.h @@ -15,13 +15,13 @@ #ifndef SRC_DAWN_NATIVE_OPENGL_ADAPTERGL_H_ #define SRC_DAWN_NATIVE_OPENGL_ADAPTERGL_H_ -#include "dawn/native/Adapter.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/native/opengl/EGLFunctions.h" #include "dawn/native/opengl/OpenGLFunctions.h" namespace dawn::native::opengl { -class Adapter : public AdapterBase { +class Adapter : public PhysicalDeviceBase { public: Adapter(InstanceBase* instance, wgpu::BackendType backendType, @@ -31,7 +31,7 @@ class Adapter : public AdapterBase { ~Adapter() override = default; - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override; private: diff --git a/src/dawn/native/opengl/BackendGL.cpp b/src/dawn/native/opengl/BackendGL.cpp index dec797614f..f94b2e0270 100644 --- a/src/dawn/native/opengl/BackendGL.cpp +++ b/src/dawn/native/opengl/BackendGL.cpp @@ -33,8 +33,9 @@ namespace dawn::native::opengl { Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType) : BackendConnection(instance, backendType) {} -std::vector> Backend::DiscoverDefaultAdapters(const TogglesState& adapterToggles) { - std::vector> adapters; +std::vector> Backend::DiscoverDefaultAdapters( + const TogglesState& adapterToggles) { + std::vector> adapters; #if DAWN_PLATFORM_IS(WINDOWS) const char* eglLib = "libEGL.dll"; #elif DAWN_PLATFORM_IS(MACOS) @@ -83,7 +84,7 @@ std::vector> Backend::DiscoverDefaultAdapters(const TogglesStat return adapters; } -ResultOrError>> Backend::DiscoverAdapters( +ResultOrError>> Backend::DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) { // TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't @@ -102,7 +103,7 @@ ResultOrError>> Backend::DiscoverAdapters( DAWN_TRY(adapter->Initialize()); mCreatedAdapter = true; - std::vector> adapters{std::move(adapter)}; + std::vector> adapters{std::move(adapter)}; return std::move(adapters); } diff --git a/src/dawn/native/opengl/BackendGL.h b/src/dawn/native/opengl/BackendGL.h index e31dd8d586..3e045b2316 100644 --- a/src/dawn/native/opengl/BackendGL.h +++ b/src/dawn/native/opengl/BackendGL.h @@ -26,9 +26,9 @@ class Backend : public BackendConnection { public: Backend(InstanceBase* instance, wgpu::BackendType backendType); - std::vector> DiscoverDefaultAdapters( + std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) override; - ResultOrError>> DiscoverAdapters( + ResultOrError>> DiscoverAdapters( const AdapterDiscoveryOptionsBase* option, const TogglesState& adapterToggless) override; diff --git a/src/dawn/native/vulkan/AdapterVk.cpp b/src/dawn/native/vulkan/AdapterVk.cpp index 6e71a8f1ba..d3b1f3e2e3 100644 --- a/src/dawn/native/vulkan/AdapterVk.cpp +++ b/src/dawn/native/vulkan/AdapterVk.cpp @@ -60,7 +60,7 @@ Adapter::Adapter(InstanceBase* instance, VulkanInstance* vulkanInstance, VkPhysicalDevice physicalDevice, const TogglesState& adapterToggles) - : AdapterBase(instance, wgpu::BackendType::Vulkan, adapterToggles), + : PhysicalDeviceBase(instance, wgpu::BackendType::Vulkan, adapterToggles), mPhysicalDevice(physicalDevice), mVulkanInstance(vulkanInstance) {} diff --git a/src/dawn/native/vulkan/AdapterVk.h b/src/dawn/native/vulkan/AdapterVk.h index 0eb9317285..b1139ddcdc 100644 --- a/src/dawn/native/vulkan/AdapterVk.h +++ b/src/dawn/native/vulkan/AdapterVk.h @@ -15,7 +15,7 @@ #ifndef SRC_DAWN_NATIVE_VULKAN_ADAPTERVK_H_ #define SRC_DAWN_NATIVE_VULKAN_ADAPTERVK_H_ -#include "dawn/native/Adapter.h" +#include "dawn/native/PhysicalDevice.h" #include "dawn/common/RefCounted.h" #include "dawn/common/vulkan_platform.h" @@ -25,7 +25,7 @@ namespace dawn::native::vulkan { class VulkanInstance; -class Adapter : public AdapterBase { +class Adapter : public PhysicalDeviceBase { public: Adapter(InstanceBase* instance, VulkanInstance* vulkanInstance, @@ -33,7 +33,7 @@ class Adapter : public AdapterBase { const TogglesState& adapterToggles); ~Adapter() override; - // AdapterBase Implementation + // PhysicalDeviceBase Implementation bool SupportsExternalImages() const override; const VulkanDeviceInfo& GetDeviceInfo() const; diff --git a/src/dawn/native/vulkan/BackendVk.cpp b/src/dawn/native/vulkan/BackendVk.cpp index 7b5c41fc1b..5b1f014bbf 100644 --- a/src/dawn/native/vulkan/BackendVk.cpp +++ b/src/dawn/native/vulkan/BackendVk.cpp @@ -457,7 +457,8 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac Backend::~Backend() = default; -std::vector> Backend::DiscoverDefaultAdapters(const TogglesState& adapterToggles) { +std::vector> Backend::DiscoverDefaultAdapters( + const TogglesState& adapterToggles) { AdapterDiscoveryOptions options; auto result = DiscoverAdapters(&options, adapterToggles); if (result.IsError()) { @@ -467,7 +468,7 @@ std::vector> Backend::DiscoverDefaultAdapters(const TogglesStat return result.AcquireSuccess(); } -ResultOrError>> Backend::DiscoverAdapters( +ResultOrError>> Backend::DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) { ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan); @@ -475,7 +476,7 @@ ResultOrError>> Backend::DiscoverAdapters( const AdapterDiscoveryOptions* options = static_cast(optionsBase); - std::vector> adapters; + std::vector> adapters; InstanceBase* instance = GetInstance(); for (ICD icd : kICDs) { diff --git a/src/dawn/native/vulkan/BackendVk.h b/src/dawn/native/vulkan/BackendVk.h index f8f033990b..30f05296fc 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( + std::vector> DiscoverDefaultAdapters( const TogglesState& adapterToggles) override; - ResultOrError>> DiscoverAdapters( + ResultOrError>> DiscoverAdapters( const AdapterDiscoveryOptionsBase* optionsBase, const TogglesState& adapterToggles) override; diff --git a/src/dawn/tests/unittests/validation/ValidationTest.cpp b/src/dawn/tests/unittests/validation/ValidationTest.cpp index 708da78481..b573c39979 100644 --- a/src/dawn/tests/unittests/validation/ValidationTest.cpp +++ b/src/dawn/tests/unittests/validation/ValidationTest.cpp @@ -18,6 +18,7 @@ #include "dawn/common/Assert.h" #include "dawn/common/SystemUtils.h" #include "dawn/dawn_proc.h" +#include "dawn/native/Adapter.h" #include "dawn/native/NullBackend.h" #include "dawn/tests/ToggleParser.h" #include "dawn/tests/unittests/validation/ValidationTest.h"