diff --git a/src/dawn/native/BUILD.gn b/src/dawn/native/BUILD.gn index 49876a95f3..866a3ac412 100644 --- a/src/dawn/native/BUILD.gn +++ b/src/dawn/native/BUILD.gn @@ -403,6 +403,9 @@ source_set("sources") { "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 3a2e2fac8f..34b6f66199 100644 --- a/src/dawn/native/CMakeLists.txt +++ b/src/dawn/native/CMakeLists.txt @@ -261,6 +261,9 @@ if (DAWN_ENABLE_D3D12) "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 0000000000..cad63b7537 --- /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 Device::GetFactory() const { + return ToBackend(GetAdapter())->GetBackend()->GetFactory(); +} + +ComPtr Device::GetDxcLibrary() const { + return ToBackend(GetAdapter())->GetBackend()->GetDxcLibrary(); +} + +ComPtr Device::GetDxcCompiler() const { + return ToBackend(GetAdapter())->GetBackend()->GetDxcCompiler(); +} + +ComPtr 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 0000000000..82bfc5c259 --- /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 GetFactory() const; + + // Those DXC methods are needed by d3d::ShaderModule + // TODO(penghuang): remove them when related code is refactored to + // d3d12::ShaderModule. + ComPtr GetDxcLibrary() const; + ComPtr GetDxcCompiler() const; + ComPtr 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 0000000000..63264ad094 --- /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 +auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { + return ToBackendBase(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 0e0862a96b..892af599d6 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.cpp +++ b/src/dawn/native/d3d12/DeviceD3D12.cpp @@ -187,6 +187,11 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) { return {}; } +Device::Device(AdapterBase* adapter, + const DeviceDescriptor* descriptor, + const TogglesState& deviceToggles) + : Base(adapter, descriptor, deviceToggles) {} + Device::~Device() { Destroy(); @@ -226,10 +231,6 @@ ComPtr Device::GetDrawIndexedIndirectSignature() const { return mDrawIndexedIndirectSignature; } -ComPtr 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 @@ MaybeError Device::EnsureDXCIfRequired() { return {}; } -ComPtr Device::GetDxcLibrary() const { - return ToBackend(GetAdapter())->GetBackend()->GetDxcLibrary(); -} - -ComPtr Device::GetDxcCompiler() const { - return ToBackend(GetAdapter())->GetBackend()->GetDxcCompiler(); -} - -ComPtr 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 aa7b562a62..94ac06df12 100644 --- a/src/dawn/native/d3d12/DeviceD3D12.h +++ b/src/dawn/native/d3d12/DeviceD3D12.h @@ -19,7 +19,7 @@ #include #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 @@ class StagingDescriptorAllocator; } while (0) // Definition of backend types -class Device final : public DeviceBase { +class Device final : public d3d::Device { public: static ResultOrError> Create(Adapter* adapter, const DeviceDescriptor* descriptor, @@ -72,10 +72,6 @@ class Device final : public DeviceBase { ResidencyManager* GetResidencyManager() const; const PlatformFunctions* GetFunctions() const; - ComPtr GetFactory() const; - ComPtr GetDxcLibrary() const; - ComPtr GetDxcCompiler() const; - ComPtr GetDxcValidator() const; ResultOrError GetPendingCommandContext( Device::SubmitMode submitMode = Device::SubmitMode::Normal); @@ -169,7 +165,11 @@ class Device final : public DeviceBase { void SetLabelImpl() override; private: - using DeviceBase::DeviceBase; + using Base = d3d::Device; + + Device(AdapterBase* adapter, + const DeviceDescriptor* descriptor, + const TogglesState& deviceToggles); ResultOrError> CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override;