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>
This commit is contained in:
Peng Huang 2023-03-15 00:43:24 +00:00 committed by Dawn LUCI CQ
parent 9536ced014
commit 242e1efc98
6 changed files with 99 additions and 15 deletions

View File

@ -397,6 +397,8 @@ source_set("sources") {
if (dawn_enable_d3d12) { if (dawn_enable_d3d12) {
sources += [ sources += [
"d3d/AdapterD3D.cpp",
"d3d/AdapterD3D.h",
"d3d/BackendD3D.cpp", "d3d/BackendD3D.cpp",
"d3d/BackendD3D.h", "d3d/BackendD3D.h",
"d3d/BlobD3D.cpp", "d3d/BlobD3D.cpp",

View File

@ -253,6 +253,8 @@ endif()
if (DAWN_ENABLE_D3D12) if (DAWN_ENABLE_D3D12)
target_sources(dawn_native PRIVATE target_sources(dawn_native PRIVATE
"d3d/AdapterD3D.cpp"
"d3d/AdapterD3D.h"
"d3d/BackendD3D.cpp" "d3d/BackendD3D.cpp"
"d3d/BackendD3D.h" "d3d/BackendD3D.h"
"d3d/BlobD3D.cpp" "d3d/BlobD3D.cpp"

View File

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

View File

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

View File

@ -15,6 +15,7 @@
#include "dawn/native/d3d12/AdapterD3D12.h" #include "dawn/native/d3d12/AdapterD3D12.h"
#include <string> #include <string>
#include <utility>
#include "dawn/common/Constants.h" #include "dawn/common/Constants.h"
#include "dawn/common/Platform.h" #include "dawn/common/Platform.h"
@ -31,9 +32,7 @@ namespace dawn::native::d3d12 {
Adapter::Adapter(Backend* backend, Adapter::Adapter(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter, ComPtr<IDXGIAdapter3> hardwareAdapter,
const TogglesState& adapterToggles) const TogglesState& adapterToggles)
: AdapterBase(backend->GetInstance(), wgpu::BackendType::D3D12, adapterToggles), : Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12, adapterToggles) {}
mHardwareAdapter(hardwareAdapter),
mBackend(backend) {}
Adapter::~Adapter() { Adapter::~Adapter() {
CleanUpDebugLayerFilters(); CleanUpDebugLayerFilters();
@ -48,12 +47,8 @@ const D3D12DeviceInfo& Adapter::GetDeviceInfo() const {
return mDeviceInfo; return mDeviceInfo;
} }
IDXGIAdapter3* Adapter::GetHardwareAdapter() const {
return mHardwareAdapter.Get();
}
Backend* Adapter::GetBackend() const { Backend* Adapter::GetBackend() const {
return mBackend; return static_cast<Backend*>(Base::GetBackend());
} }
ComPtr<ID3D12Device> Adapter::GetDevice() const { ComPtr<ID3D12Device> Adapter::GetDevice() const {
@ -73,7 +68,7 @@ MaybeError Adapter::InitializeImpl() {
DAWN_TRY(InitializeDebugLayerFilters()); DAWN_TRY(InitializeDebugLayerFilters());
DXGI_ADAPTER_DESC1 adapterDesc; DXGI_ADAPTER_DESC1 adapterDesc;
mHardwareAdapter->GetDesc1(&adapterDesc); GetHardwareAdapter()->GetDesc1(&adapterDesc);
mDeviceId = adapterDesc.DeviceId; mDeviceId = adapterDesc.DeviceId;
mVendorId = adapterDesc.VendorId; 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". // Convert the adapter's D3D12 driver version to a readable string like "24.21.13.9793".
LARGE_INTEGER umdVersion; LARGE_INTEGER umdVersion;
if (mHardwareAdapter->CheckInterfaceSupport(__uuidof(IDXGIDevice), &umdVersion) != if (GetHardwareAdapter()->CheckInterfaceSupport(__uuidof(IDXGIDevice), &umdVersion) !=
DXGI_ERROR_UNSUPPORTED) { DXGI_ERROR_UNSUPPORTED) {
uint64_t encodedVersion = umdVersion.QuadPart; uint64_t encodedVersion = umdVersion.QuadPart;
uint16_t mask = 0xFFFF; uint16_t mask = 0xFFFF;
@ -355,7 +350,7 @@ MaybeError Adapter::ValidateFeatureSupportedWithDeviceTogglesImpl(
if (feature == wgpu::FeatureName::ShaderF16 || if (feature == wgpu::FeatureName::ShaderF16 ||
feature == wgpu::FeatureName::ChromiumExperimentalDp4a) { feature == wgpu::FeatureName::ChromiumExperimentalDp4a) {
DAWN_INVALID_IF(!(deviceTogglesState.IsEnabled(Toggle::UseDXC) && 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.", "Feature %s requires DXC for D3D12.",
GetInstance()->GetFeatureInfo(feature)->name); GetInstance()->GetFeatureInfo(feature)->name);
} }

View File

@ -17,6 +17,7 @@
#include "dawn/native/Adapter.h" #include "dawn/native/Adapter.h"
#include "dawn/native/d3d/AdapterD3D.h"
#include "dawn/native/d3d12/D3D12Info.h" #include "dawn/native/d3d12/D3D12Info.h"
#include "dawn/native/d3d12/d3d12_platform.h" #include "dawn/native/d3d12/d3d12_platform.h"
@ -24,7 +25,7 @@ namespace dawn::native::d3d12 {
class Backend; class Backend;
class Adapter : public AdapterBase { class Adapter : public d3d::Adapter {
public: public:
Adapter(Backend* backend, Adapter(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter, ComPtr<IDXGIAdapter3> hardwareAdapter,
@ -35,11 +36,12 @@ class Adapter : public AdapterBase {
bool SupportsExternalImages() const override; bool SupportsExternalImages() const override;
const D3D12DeviceInfo& GetDeviceInfo() const; const D3D12DeviceInfo& GetDeviceInfo() const;
IDXGIAdapter3* GetHardwareAdapter() const;
Backend* GetBackend() const; Backend* GetBackend() const;
ComPtr<ID3D12Device> GetDevice() const; ComPtr<ID3D12Device> GetDevice() const;
private: private:
using Base = d3d::Adapter;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor,
@ -60,10 +62,8 @@ class Adapter : public AdapterBase {
MaybeError InitializeDebugLayerFilters(); MaybeError InitializeDebugLayerFilters();
void CleanUpDebugLayerFilters(); void CleanUpDebugLayerFilters();
ComPtr<IDXGIAdapter3> mHardwareAdapter;
ComPtr<ID3D12Device> mD3d12Device; ComPtr<ID3D12Device> mD3d12Device;
Backend* mBackend;
D3D12DeviceInfo mDeviceInfo = {}; D3D12DeviceInfo mDeviceInfo = {};
}; };