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>
This commit is contained in:
Peng Huang 2023-03-17 18:14:38 +00:00 committed by Dawn LUCI CQ
parent 6c34e11e43
commit b4c5e0d32a
7 changed files with 151 additions and 23 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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

View File

@ -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_

View File

@ -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_

View File

@ -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<ID3D12CommandSignature> Device::GetDrawIndexedIndirectSignature() const {
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 @@ MaybeError Device::EnsureDXCIfRequired() {
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();
}

View File

@ -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 @@ class StagingDescriptorAllocator;
} 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 @@ class Device final : public DeviceBase {
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 @@ 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<Ref<BindGroupBase>> CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) override;