From 242e1efc9889e53ddd363e1e63d6bc431852aeda Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Wed, 15 Mar 2023 00:43:24 +0000 Subject: [PATCH] Refactor comman code from d3d12::Adapter to base class d3d::Adapter Bug: dawn:1705 Change-Id: Ib11c25cdb2ecffe6fa27c1c1945b02cfa69810c5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124080 Reviewed-by: Austin Eng Kokoro: Kokoro Commit-Queue: Peng Huang --- src/dawn/native/BUILD.gn | 2 ++ src/dawn/native/CMakeLists.txt | 2 ++ src/dawn/native/d3d/AdapterD3D.cpp | 41 ++++++++++++++++++++++++ src/dawn/native/d3d/AdapterD3D.h | 44 ++++++++++++++++++++++++++ src/dawn/native/d3d12/AdapterD3D12.cpp | 17 ++++------ src/dawn/native/d3d12/AdapterD3D12.h | 8 ++--- 6 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 src/dawn/native/d3d/AdapterD3D.cpp create mode 100644 src/dawn/native/d3d/AdapterD3D.h diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 2d008c0bd3..f2f2bbcb21 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -397,6 +397,8 @@ source_set("sources") { if (dawn_enable_d3d12) { sources += [ + "d3d/AdapterD3D.cpp", + "d3d/AdapterD3D.h", "d3d/BackendD3D.cpp", "d3d/BackendD3D.h", "d3d/BlobD3D.cpp", diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt index b16c1e0a27..c255cd1d3c 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -253,6 +253,8 @@ endif() if (DAWN_ENABLE_D3D12) target_sources(dawn_native PRIVATE + "d3d/AdapterD3D.cpp" + "d3d/AdapterD3D.h" "d3d/BackendD3D.cpp" "d3d/BackendD3D.h" "d3d/BlobD3D.cpp" diff --git a/src/dawn/native/d3d/AdapterD3D.cpp b/src/dawn/native/d3d/AdapterD3D.cpp new file mode 100644 index 0000000000..5e3fb9284f --- /dev/null +++ b/src/dawn/native/d3d/AdapterD3D.cpp @@ -0,0 +1,41 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "dawn/native/d3d/AdapterD3D.h" + +#include + +#include "dawn/native/d3d/BackendD3D.h" + +namespace dawn::native::d3d { + +Adapter::Adapter(Backend* backend, + ComPtr hardwareAdapter, + wgpu::BackendType backendType, + const TogglesState& adapterToggles) + : AdapterBase(backend->GetInstance(), backendType, adapterToggles), + mHardwareAdapter(std::move(hardwareAdapter)), + mBackend(backend) {} + +Adapter::~Adapter() = default; + +IDXGIAdapter3* Adapter::GetHardwareAdapter() const { + return mHardwareAdapter.Get(); +} + +Backend* Adapter::GetBackend() const { + return mBackend; +} + +} // namespace dawn::native::d3d diff --git a/src/dawn/native/d3d/AdapterD3D.h b/src/dawn/native/d3d/AdapterD3D.h new file mode 100644 index 0000000000..26c9045a39 --- /dev/null +++ b/src/dawn/native/d3d/AdapterD3D.h @@ -0,0 +1,44 @@ +// Copyright 2023 The Dawn Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DAWN_NATIVE_D3D_ADAPTERD3D_H_ +#define SRC_DAWN_NATIVE_D3D_ADAPTERD3D_H_ + +#include "dawn/native/Adapter.h" + +#include "dawn/native/d3d/d3d_platform.h" + +namespace dawn::native::d3d { + +class Backend; + +class Adapter : public AdapterBase { + public: + Adapter(Backend* backend, + ComPtr hardwareAdapter, + wgpu::BackendType backendType, + const TogglesState& adapterToggles); + ~Adapter() override; + + IDXGIAdapter3* GetHardwareAdapter() const; + Backend* GetBackend() const; + + private: + ComPtr mHardwareAdapter; + Backend* mBackend; +}; + +} // namespace dawn::native::d3d + +#endif // SRC_DAWN_NATIVE_D3D_ADAPTERD3D_H_ diff --git a/src/dawn/native/d3d12/AdapterD3D12.cpp b/src/dawn/native/d3d12/AdapterD3D12.cpp index 4859208004..faecfe0985 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.cpp +++ b/src/dawn/native/d3d12/AdapterD3D12.cpp @@ -15,6 +15,7 @@ #include "dawn/native/d3d12/AdapterD3D12.h" #include +#include #include "dawn/common/Constants.h" #include "dawn/common/Platform.h" @@ -31,9 +32,7 @@ namespace dawn::native::d3d12 { Adapter::Adapter(Backend* backend, ComPtr hardwareAdapter, const TogglesState& adapterToggles) - : AdapterBase(backend->GetInstance(), wgpu::BackendType::D3D12, adapterToggles), - mHardwareAdapter(hardwareAdapter), - mBackend(backend) {} + : Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12, adapterToggles) {} Adapter::~Adapter() { CleanUpDebugLayerFilters(); @@ -48,12 +47,8 @@ const D3D12DeviceInfo& Adapter::GetDeviceInfo() const { return mDeviceInfo; } -IDXGIAdapter3* Adapter::GetHardwareAdapter() const { - return mHardwareAdapter.Get(); -} - Backend* Adapter::GetBackend() const { - return mBackend; + return static_cast(Base::GetBackend()); } ComPtr Adapter::GetDevice() const { @@ -73,7 +68,7 @@ MaybeError Adapter::InitializeImpl() { DAWN_TRY(InitializeDebugLayerFilters()); DXGI_ADAPTER_DESC1 adapterDesc; - mHardwareAdapter->GetDesc1(&adapterDesc); + GetHardwareAdapter()->GetDesc1(&adapterDesc); mDeviceId = adapterDesc.DeviceId; mVendorId = adapterDesc.VendorId; @@ -90,7 +85,7 @@ MaybeError Adapter::InitializeImpl() { // Convert the adapter's D3D12 driver version to a readable string like "24.21.13.9793". LARGE_INTEGER umdVersion; - if (mHardwareAdapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &umdVersion) != + if (GetHardwareAdapter()->CheckInterfaceSupport(__uuidof(IDXGIDevice), &umdVersion) != DXGI_ERROR_UNSUPPORTED) { uint64_t encodedVersion = umdVersion.QuadPart; uint16_t mask = 0xFFFF; @@ -355,7 +350,7 @@ MaybeError Adapter::ValidateFeatureSupportedWithDeviceTogglesImpl( if (feature == wgpu::FeatureName::ShaderF16 || feature == wgpu::FeatureName::ChromiumExperimentalDp4a) { DAWN_INVALID_IF(!(deviceTogglesState.IsEnabled(Toggle::UseDXC) && - mBackend->IsDXCAvailableAndVersionAtLeast(1, 4, 1, 4)), + GetBackend()->IsDXCAvailableAndVersionAtLeast(1, 4, 1, 4)), "Feature %s requires DXC for D3D12.", GetInstance()->GetFeatureInfo(feature)->name); } diff --git a/src/dawn/native/d3d12/AdapterD3D12.h b/src/dawn/native/d3d12/AdapterD3D12.h index 4309dff416..8b46f7f6a7 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.h +++ b/src/dawn/native/d3d12/AdapterD3D12.h @@ -17,6 +17,7 @@ #include "dawn/native/Adapter.h" +#include "dawn/native/d3d/AdapterD3D.h" #include "dawn/native/d3d12/D3D12Info.h" #include "dawn/native/d3d12/d3d12_platform.h" @@ -24,7 +25,7 @@ namespace dawn::native::d3d12 { class Backend; -class Adapter : public AdapterBase { +class Adapter : public d3d::Adapter { public: Adapter(Backend* backend, ComPtr hardwareAdapter, @@ -35,11 +36,12 @@ class Adapter : public AdapterBase { bool SupportsExternalImages() const override; const D3D12DeviceInfo& GetDeviceInfo() const; - IDXGIAdapter3* GetHardwareAdapter() const; Backend* GetBackend() const; ComPtr GetDevice() const; private: + using Base = d3d::Adapter; + void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; ResultOrError> CreateDeviceImpl(const DeviceDescriptor* descriptor, @@ -60,10 +62,8 @@ class Adapter : public AdapterBase { MaybeError InitializeDebugLayerFilters(); void CleanUpDebugLayerFilters(); - ComPtr mHardwareAdapter; ComPtr mD3d12Device; - Backend* mBackend; D3D12DeviceInfo mDeviceInfo = {}; };