Refactor some common code from d3d12::Device to base d3d::Device
Bug: dawn:1705
Change-Id: Ibb69e4a60f77810b688dbd64d3ccf3b07478bad3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124522
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 49876a9..866a3ac 100644
--- a/src/dawn/native/BUILD.gn
+++ b/src/dawn/native/BUILD.gn
@@ -403,6 +403,9 @@
"d3d/BlobD3D.h",
"d3d/D3DError.cpp",
"d3d/D3DError.h",
+ "d3d/DeviceD3D.cpp",
+ "d3d/DeviceD3D.h",
+ "d3d/Forward.h",
"d3d/PlatformFunctions.cpp",
"d3d/PlatformFunctions.h",
"d3d/UtilsD3D.cpp",
diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt
index 3a2e2fa..34b6f66 100644
--- a/src/dawn/native/CMakeLists.txt
+++ b/src/dawn/native/CMakeLists.txt
@@ -261,6 +261,9 @@
"d3d/BlobD3D.h"
"d3d/D3DError.cpp"
"d3d/D3DError.h"
+ "d3d/DeviceD3D.cpp"
+ "d3d/DeviceD3D.h"
+ "d3d/Forward.h"
"d3d/PlatformFunctions.cpp"
"d3d/PlatformFunctions.h"
"d3d/UtilsD3D.cpp"
diff --git a/src/dawn/native/d3d/DeviceD3D.cpp b/src/dawn/native/d3d/DeviceD3D.cpp
new file mode 100644
index 0000000..cad63b7
--- /dev/null
+++ b/src/dawn/native/d3d/DeviceD3D.cpp
@@ -0,0 +1,50 @@
+// 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/DeviceD3D.h"
+
+#include "dawn/native/d3d/AdapterD3D.h"
+#include "dawn/native/d3d/BackendD3D.h"
+#include "dawn/native/d3d/Forward.h"
+
+namespace dawn::native::d3d {
+
+Device::Device(AdapterBase* adapter,
+ const DeviceDescriptor* descriptor,
+ const TogglesState& deviceToggles)
+ : DeviceBase(adapter, descriptor, deviceToggles) {}
+
+Device::~Device() = default;
+
+const PlatformFunctions* Device::GetFunctions() const {
+ return ToBackend(GetAdapter())->GetBackend()->GetFunctions();
+}
+
+ComPtr<IDXGIFactory4> Device::GetFactory() const {
+ return ToBackend(GetAdapter())->GetBackend()->GetFactory();
+}
+
+ComPtr<IDxcLibrary> Device::GetDxcLibrary() const {
+ return ToBackend(GetAdapter())->GetBackend()->GetDxcLibrary();
+}
+
+ComPtr<IDxcCompiler> Device::GetDxcCompiler() const {
+ return ToBackend(GetAdapter())->GetBackend()->GetDxcCompiler();
+}
+
+ComPtr<IDxcValidator> Device::GetDxcValidator() const {
+ return ToBackend(GetAdapter())->GetBackend()->GetDxcValidator();
+}
+
+} // namespace dawn::native::d3d
diff --git a/src/dawn/native/d3d/DeviceD3D.h b/src/dawn/native/d3d/DeviceD3D.h
new file mode 100644
index 0000000..82bfc5c
--- /dev/null
+++ b/src/dawn/native/d3d/DeviceD3D.h
@@ -0,0 +1,46 @@
+// 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_DEVICED3D_H_
+#define SRC_DAWN_NATIVE_D3D_DEVICED3D_H_
+
+#include "dawn/native/Device.h"
+
+#include "dawn/native/d3d/d3d_platform.h"
+
+namespace dawn::native::d3d {
+
+class PlatformFunctions;
+
+class Device : public DeviceBase {
+ public:
+ Device(AdapterBase* adapter,
+ const DeviceDescriptor* descriptor,
+ const TogglesState& deviceToggles);
+ ~Device() override;
+
+ const PlatformFunctions* GetFunctions() const;
+ ComPtr<IDXGIFactory4> GetFactory() const;
+
+ // Those DXC methods are needed by d3d::ShaderModule
+ // TODO(penghuang): remove them when related code is refactored to
+ // d3d12::ShaderModule.
+ ComPtr<IDxcLibrary> GetDxcLibrary() const;
+ ComPtr<IDxcCompiler> GetDxcCompiler() const;
+ ComPtr<IDxcValidator> GetDxcValidator() const;
+};
+
+} // namespace dawn::native::d3d
+
+#endif // SRC_DAWN_NATIVE_D3D_DEVICED3D_H_
diff --git a/src/dawn/native/d3d/Forward.h b/src/dawn/native/d3d/Forward.h
new file mode 100644
index 0000000..63264ad
--- /dev/null
+++ b/src/dawn/native/d3d/Forward.h
@@ -0,0 +1,37 @@
+// 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_FORWARD_H_
+#define SRC_DAWN_NATIVE_D3D_FORWARD_H_
+
+#include "dawn/native/ToBackend.h"
+
+namespace dawn::native::d3d {
+
+class Adapter;
+class Device;
+
+struct D3DBackendTraits {
+ using AdapterType = Adapter;
+ using DeviceType = Device;
+};
+
+template <typename T>
+auto ToBackend(T&& common) -> decltype(ToBackendBase<D3DBackendTraits>(common)) {
+ return ToBackendBase<D3DBackendTraits>(common);
+}
+
+} // namespace dawn::native::d3d
+
+#endif // SRC_DAWN_NATIVE_D3D_FORWARD_H_
diff --git a/src/dawn/native/d3d12/DeviceD3D12.cpp b/src/dawn/native/d3d12/DeviceD3D12.cpp
index 0e0862a..892af59 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/DeviceD3D12.cpp
@@ -187,6 +187,11 @@
return {};
}
+Device::Device(AdapterBase* adapter,
+ const DeviceDescriptor* descriptor,
+ const TogglesState& deviceToggles)
+ : Base(adapter, descriptor, deviceToggles) {}
+
Device::~Device() {
Destroy();
@@ -226,10 +231,6 @@
return mDrawIndexedIndirectSignature;
}
-ComPtr<IDXGIFactory4> Device::GetFactory() const {
- return ToBackend(GetAdapter())->GetBackend()->GetFactory();
-}
-
// Ensure DXC if use_dxc toggles are set and validated.
MaybeError Device::EnsureDXCIfRequired() {
if (IsToggleEnabled(Toggle::UseDXC)) {
@@ -242,18 +243,6 @@
return {};
}
-ComPtr<IDxcLibrary> Device::GetDxcLibrary() const {
- return ToBackend(GetAdapter())->GetBackend()->GetDxcLibrary();
-}
-
-ComPtr<IDxcCompiler> Device::GetDxcCompiler() const {
- return ToBackend(GetAdapter())->GetBackend()->GetDxcCompiler();
-}
-
-ComPtr<IDxcValidator> Device::GetDxcValidator() const {
- return ToBackend(GetAdapter())->GetBackend()->GetDxcValidator();
-}
-
const PlatformFunctions* Device::GetFunctions() const {
return ToBackend(GetAdapter())->GetBackend()->GetFunctions();
}
diff --git a/src/dawn/native/d3d12/DeviceD3D12.h b/src/dawn/native/d3d12/DeviceD3D12.h
index aa7b562..94ac06d 100644
--- a/src/dawn/native/d3d12/DeviceD3D12.h
+++ b/src/dawn/native/d3d12/DeviceD3D12.h
@@ -19,7 +19,7 @@
#include <vector>
#include "dawn/common/SerialQueue.h"
-#include "dawn/native/Device.h"
+#include "dawn/native/d3d/DeviceD3D.h"
#include "dawn/native/d3d12/CommandRecordingContext.h"
#include "dawn/native/d3d12/D3D12Info.h"
#include "dawn/native/d3d12/Forward.h"
@@ -44,7 +44,7 @@
} while (0)
// Definition of backend types
-class Device final : public DeviceBase {
+class Device final : public d3d::Device {
public:
static ResultOrError<Ref<Device>> Create(Adapter* adapter,
const DeviceDescriptor* descriptor,
@@ -72,10 +72,6 @@
ResidencyManager* GetResidencyManager() const;
const PlatformFunctions* GetFunctions() const;
- ComPtr<IDXGIFactory4> GetFactory() const;
- ComPtr<IDxcLibrary> GetDxcLibrary() const;
- ComPtr<IDxcCompiler> GetDxcCompiler() const;
- ComPtr<IDxcValidator> GetDxcValidator() const;
ResultOrError<CommandRecordingContext*> GetPendingCommandContext(
Device::SubmitMode submitMode = Device::SubmitMode::Normal);
@@ -169,7 +165,11 @@
void SetLabelImpl() override;
private:
- using DeviceBase::DeviceBase;
+ using Base = d3d::Device;
+
+ Device(AdapterBase* adapter,
+ const DeviceDescriptor* descriptor,
+ const TogglesState& deviceToggles);
ResultOrError<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;