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 <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Peng Huang <penghuang@chromium.org>
diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn
index 2d008c0..f2f2bbc 100644
--- a/src/dawn/native/BUILD.gn
+++ b/src/dawn/native/BUILD.gn
@@ -397,6 +397,8 @@
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 b16c1e0..c255cd1 100644
--- a/src/dawn/native/CMakeLists.txt
+++ b/src/dawn/native/CMakeLists.txt
@@ -253,6 +253,8 @@
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 0000000..5e3fb92
--- /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 <utility>
+
+#include "dawn/native/d3d/BackendD3D.h"
+
+namespace dawn::native::d3d {
+
+Adapter::Adapter(Backend* backend,
+ ComPtr<IDXGIAdapter3> 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 0000000..26c9045
--- /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<IDXGIAdapter3> hardwareAdapter,
+ wgpu::BackendType backendType,
+ const TogglesState& adapterToggles);
+ ~Adapter() override;
+
+ IDXGIAdapter3* GetHardwareAdapter() const;
+ Backend* GetBackend() const;
+
+ private:
+ ComPtr<IDXGIAdapter3> 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 4859208..faecfe0 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 <string>
+#include <utility>
#include "dawn/common/Constants.h"
#include "dawn/common/Platform.h"
@@ -31,9 +32,7 @@
Adapter::Adapter(Backend* backend,
ComPtr<IDXGIAdapter3> 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 @@
return mDeviceInfo;
}
-IDXGIAdapter3* Adapter::GetHardwareAdapter() const {
- return mHardwareAdapter.Get();
-}
-
Backend* Adapter::GetBackend() const {
- return mBackend;
+ return static_cast<Backend*>(Base::GetBackend());
}
ComPtr<ID3D12Device> Adapter::GetDevice() const {
@@ -73,7 +68,7 @@
DAWN_TRY(InitializeDebugLayerFilters());
DXGI_ADAPTER_DESC1 adapterDesc;
- mHardwareAdapter->GetDesc1(&adapterDesc);
+ GetHardwareAdapter()->GetDesc1(&adapterDesc);
mDeviceId = adapterDesc.DeviceId;
mVendorId = adapterDesc.VendorId;
@@ -90,7 +85,7 @@
// 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 @@
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 4309dff4..8b46f7f 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 @@
class Backend;
-class Adapter : public AdapterBase {
+class Adapter : public d3d::Adapter {
public:
Adapter(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
@@ -35,11 +36,12 @@
bool SupportsExternalImages() const override;
const D3D12DeviceInfo& GetDeviceInfo() const;
- IDXGIAdapter3* GetHardwareAdapter() const;
Backend* GetBackend() const;
ComPtr<ID3D12Device> GetDevice() const;
private:
+ using Base = d3d::Adapter;
+
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor,
@@ -60,10 +62,8 @@
MaybeError InitializeDebugLayerFilters();
void CleanUpDebugLayerFilters();
- ComPtr<IDXGIAdapter3> mHardwareAdapter;
ComPtr<ID3D12Device> mD3d12Device;
- Backend* mBackend;
D3D12DeviceInfo mDeviceInfo = {};
};