Improve D3D12 adapter initialization.
Gather device info at device initialization rather than adapter initialization. BUG=dawn:144 Change-Id: I07e114731a37f3738daa585afa99675f2fd36289 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7700 Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
0e646e95e0
commit
970101a102
2
BUILD.gn
2
BUILD.gn
|
@ -176,6 +176,8 @@ source_set("libdawn_native_sources") {
|
||||||
"src/dawn_native/d3d12/CommandBufferD3D12.h",
|
"src/dawn_native/d3d12/CommandBufferD3D12.h",
|
||||||
"src/dawn_native/d3d12/ComputePipelineD3D12.cpp",
|
"src/dawn_native/d3d12/ComputePipelineD3D12.cpp",
|
||||||
"src/dawn_native/d3d12/ComputePipelineD3D12.h",
|
"src/dawn_native/d3d12/ComputePipelineD3D12.h",
|
||||||
|
"src/dawn_native/d3d12/D3D12Info.cpp",
|
||||||
|
"src/dawn_native/d3d12/D3D12Info.h",
|
||||||
"src/dawn_native/d3d12/DescriptorHeapAllocator.cpp",
|
"src/dawn_native/d3d12/DescriptorHeapAllocator.cpp",
|
||||||
"src/dawn_native/d3d12/DescriptorHeapAllocator.h",
|
"src/dawn_native/d3d12/DescriptorHeapAllocator.h",
|
||||||
"src/dawn_native/d3d12/DeviceD3D12.cpp",
|
"src/dawn_native/d3d12/DeviceD3D12.cpp",
|
||||||
|
|
|
@ -38,6 +38,36 @@ namespace dawn_native { namespace d3d12 {
|
||||||
: AdapterBase(backend->GetInstance(), BackendType::D3D12),
|
: AdapterBase(backend->GetInstance(), BackendType::D3D12),
|
||||||
mHardwareAdapter(hardwareAdapter),
|
mHardwareAdapter(hardwareAdapter),
|
||||||
mBackend(backend) {
|
mBackend(backend) {
|
||||||
|
}
|
||||||
|
|
||||||
|
const D3D12DeviceInfo& Adapter::GetDeviceInfo() const {
|
||||||
|
return mDeviceInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
IDXGIAdapter1* Adapter::GetHardwareAdapter() const {
|
||||||
|
return mHardwareAdapter.Get();
|
||||||
|
}
|
||||||
|
|
||||||
|
Backend* Adapter::GetBackend() const {
|
||||||
|
return mBackend;
|
||||||
|
}
|
||||||
|
|
||||||
|
ComPtr<ID3D12Device> Adapter::GetDevice() const {
|
||||||
|
return mD3d12Device;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeError Adapter::Initialize() {
|
||||||
|
// D3D12 cannot check for feature support without a device.
|
||||||
|
// Create the device to populate the adapter properties then reuse it when needed for actual
|
||||||
|
// rendering.
|
||||||
|
const PlatformFunctions* functions = GetBackend()->GetFunctions();
|
||||||
|
if (FAILED(functions->d3d12CreateDevice(GetHardwareAdapter(), D3D_FEATURE_LEVEL_11_0,
|
||||||
|
_uuidof(ID3D12Device), &mD3d12Device))) {
|
||||||
|
return DAWN_CONTEXT_LOST_ERROR("D3D12CreateDevice failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
DAWN_TRY_ASSIGN(mDeviceInfo, GatherDeviceInfo(*this));
|
||||||
|
|
||||||
DXGI_ADAPTER_DESC1 adapterDesc;
|
DXGI_ADAPTER_DESC1 adapterDesc;
|
||||||
mHardwareAdapter->GetDesc1(&adapterDesc);
|
mHardwareAdapter->GetDesc1(&adapterDesc);
|
||||||
|
|
||||||
|
@ -47,43 +77,20 @@ namespace dawn_native { namespace d3d12 {
|
||||||
if (adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
|
if (adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
|
||||||
mDeviceType = DeviceType::CPU;
|
mDeviceType = DeviceType::CPU;
|
||||||
} else {
|
} else {
|
||||||
// Using DXGI_ADAPTER_DESC1 approach to determine integrated vs dedicated is
|
mDeviceType = (mDeviceInfo.isUMA) ? DeviceType::IntegratedGPU : DeviceType::DiscreteGPU;
|
||||||
// vendor-specific.
|
|
||||||
switch (mPCIInfo.vendorId) {
|
|
||||||
case kVendorID_Intel: {
|
|
||||||
// On Intel GPUs, dedicated video memory is always set to 128MB when the GPU is
|
|
||||||
// integrated.
|
|
||||||
static constexpr uint64_t kDedicatedVideoMemory = 128 * 1024 * 1024;
|
|
||||||
mDeviceType = (adapterDesc.DedicatedVideoMemory == kDedicatedVideoMemory)
|
|
||||||
? DeviceType::IntegratedGPU
|
|
||||||
: DeviceType::DiscreteGPU;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
// TODO: Support additional GPU vendors.
|
|
||||||
mDeviceType = DeviceType::Unknown;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring_convert<DeletableFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> converter(
|
std::wstring_convert<DeletableFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> converter(
|
||||||
"Error converting");
|
"Error converting");
|
||||||
mPCIInfo.name = converter.to_bytes(adapterDesc.Description);
|
mPCIInfo.name = converter.to_bytes(adapterDesc.Description);
|
||||||
}
|
|
||||||
|
|
||||||
Backend* Adapter::GetBackend() const {
|
return {};
|
||||||
return mBackend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<DeviceBase*> Adapter::CreateDeviceImpl(const DeviceDescriptor* descriptor) {
|
ResultOrError<DeviceBase*> Adapter::CreateDeviceImpl(const DeviceDescriptor* descriptor) {
|
||||||
ComPtr<ID3D12Device> d3d12Device;
|
std::unique_ptr<Device> device = std::make_unique<Device>(this, descriptor);
|
||||||
if (FAILED(mBackend->GetFunctions()->d3d12CreateDevice(
|
DAWN_TRY(device->Initialize());
|
||||||
mHardwareAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&d3d12Device)))) {
|
return device.release();
|
||||||
return DAWN_CONTEXT_LOST_ERROR("D3D12CreateDevice failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(d3d12Device != nullptr);
|
|
||||||
return new Device(this, d3d12Device, descriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}} // namespace dawn_native::d3d12
|
}} // namespace dawn_native::d3d12
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "dawn_native/Adapter.h"
|
#include "dawn_native/Adapter.h"
|
||||||
|
|
||||||
|
#include "dawn_native/d3d12/D3D12Info.h"
|
||||||
#include "dawn_native/d3d12/d3d12_platform.h"
|
#include "dawn_native/d3d12/d3d12_platform.h"
|
||||||
|
|
||||||
namespace dawn_native { namespace d3d12 {
|
namespace dawn_native { namespace d3d12 {
|
||||||
|
@ -28,13 +29,21 @@ namespace dawn_native { namespace d3d12 {
|
||||||
Adapter(Backend* backend, ComPtr<IDXGIAdapter1> hardwareAdapter);
|
Adapter(Backend* backend, ComPtr<IDXGIAdapter1> hardwareAdapter);
|
||||||
virtual ~Adapter() = default;
|
virtual ~Adapter() = default;
|
||||||
|
|
||||||
|
const D3D12DeviceInfo& GetDeviceInfo() const;
|
||||||
|
IDXGIAdapter1* GetHardwareAdapter() const;
|
||||||
Backend* GetBackend() const;
|
Backend* GetBackend() const;
|
||||||
|
ComPtr<ID3D12Device> GetDevice() const;
|
||||||
|
|
||||||
|
MaybeError Initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResultOrError<DeviceBase*> CreateDeviceImpl(const DeviceDescriptor* descriptor) override;
|
ResultOrError<DeviceBase*> CreateDeviceImpl(const DeviceDescriptor* descriptor) override;
|
||||||
|
|
||||||
ComPtr<IDXGIAdapter1> mHardwareAdapter;
|
ComPtr<IDXGIAdapter1> mHardwareAdapter;
|
||||||
|
ComPtr<ID3D12Device> mD3d12Device;
|
||||||
|
|
||||||
Backend* mBackend;
|
Backend* mBackend;
|
||||||
|
D3D12DeviceInfo mDeviceInfo = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // namespace dawn_native::d3d12
|
}} // namespace dawn_native::d3d12
|
||||||
|
|
|
@ -92,10 +92,13 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(dxgiAdapter != nullptr);
|
ASSERT(dxgiAdapter != nullptr);
|
||||||
if (SUCCEEDED(mFunctions->d3d12CreateDevice(dxgiAdapter.Get(), D3D_FEATURE_LEVEL_11_0,
|
|
||||||
_uuidof(ID3D12Device), nullptr))) {
|
std::unique_ptr<Adapter> adapter = std::make_unique<Adapter>(this, dxgiAdapter);
|
||||||
adapters.push_back(std::make_unique<Adapter>(this, dxgiAdapter));
|
if (GetInstance()->ConsumedError(adapter->Initialize())) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
adapters.push_back(std::move(adapter));
|
||||||
}
|
}
|
||||||
|
|
||||||
return adapters;
|
return adapters;
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright 2019 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/d3d12/D3D12Info.h"
|
||||||
|
|
||||||
|
#include "dawn_native/D3D12/AdapterD3D12.h"
|
||||||
|
#include "dawn_native/D3D12/BackendD3D12.h"
|
||||||
|
|
||||||
|
#include "dawn_native/d3d12/PlatformFunctions.h"
|
||||||
|
|
||||||
|
namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
|
ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
|
||||||
|
D3D12DeviceInfo info = {};
|
||||||
|
|
||||||
|
// Gather info about device memory
|
||||||
|
{
|
||||||
|
// Newer builds replace D3D_FEATURE_DATA_ARCHITECTURE with
|
||||||
|
// D3D_FEATURE_DATA_ARCHITECTURE1. However, D3D_FEATURE_DATA_ARCHITECTURE can be used
|
||||||
|
// for backwards compat.
|
||||||
|
// https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/ne-d3d12-d3d12_feature
|
||||||
|
D3D12_FEATURE_DATA_ARCHITECTURE arch = {};
|
||||||
|
if (FAILED(adapter.GetDevice()->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch,
|
||||||
|
sizeof(arch)))) {
|
||||||
|
return DAWN_CONTEXT_LOST_ERROR("CheckFeatureSupport failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
info.isUMA = arch.UMA;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}} // namespace dawn_native::d3d12
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright 2019 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 DAWNNATIVE_D3D12_D3D12INFO_H_
|
||||||
|
#define DAWNNATIVE_D3D12_D3D12INFO_H_
|
||||||
|
|
||||||
|
#include "dawn_native/Error.h"
|
||||||
|
#include "dawn_native/d3d12/d3d12_platform.h"
|
||||||
|
|
||||||
|
namespace dawn_native { namespace d3d12 {
|
||||||
|
|
||||||
|
class Adapter;
|
||||||
|
|
||||||
|
struct D3D12DeviceInfo {
|
||||||
|
bool isUMA;
|
||||||
|
};
|
||||||
|
|
||||||
|
ResultOrError<D3D12DeviceInfo> GatherDeviceInfo(const Adapter& adapter);
|
||||||
|
}} // namespace dawn_native::d3d12
|
||||||
|
|
||||||
|
#endif // DAWNNATIVE_D3D12_D3D12INFO_H_
|
|
@ -43,13 +43,18 @@ namespace dawn_native { namespace d3d12 {
|
||||||
ASSERT(SUCCEEDED(hr));
|
ASSERT(SUCCEEDED(hr));
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::Device(Adapter* adapter,
|
Device::Device(Adapter* adapter, const DeviceDescriptor* descriptor)
|
||||||
ComPtr<ID3D12Device> d3d12Device,
|
: DeviceBase(adapter, descriptor) {
|
||||||
const DeviceDescriptor* descriptor)
|
|
||||||
: DeviceBase(adapter, descriptor), mD3d12Device(d3d12Device) {
|
|
||||||
if (descriptor != nullptr) {
|
if (descriptor != nullptr) {
|
||||||
ApplyToggleOverrides(descriptor);
|
ApplyToggleOverrides(descriptor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeError Device::Initialize() {
|
||||||
|
mD3d12Device = ToBackend(GetAdapter())->GetDevice();
|
||||||
|
|
||||||
|
ASSERT(mD3d12Device != nullptr);
|
||||||
|
|
||||||
// Create device-global objects
|
// Create device-global objects
|
||||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||||
|
@ -96,6 +101,8 @@ namespace dawn_native { namespace d3d12 {
|
||||||
->GetD3D12Device()
|
->GetD3D12Device()
|
||||||
->CreateCommandSignature(&programDesc, NULL,
|
->CreateCommandSignature(&programDesc, NULL,
|
||||||
IID_PPV_ARGS(&mDrawIndexedIndirectSignature));
|
IID_PPV_ARGS(&mDrawIndexedIndirectSignature));
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device() {
|
Device::~Device() {
|
||||||
|
|
|
@ -37,11 +37,11 @@ namespace dawn_native { namespace d3d12 {
|
||||||
// Definition of backend types
|
// Definition of backend types
|
||||||
class Device : public DeviceBase {
|
class Device : public DeviceBase {
|
||||||
public:
|
public:
|
||||||
Device(Adapter* adapter,
|
Device(Adapter* adapter, const DeviceDescriptor* descriptor);
|
||||||
ComPtr<ID3D12Device> d3d12Device,
|
|
||||||
const DeviceDescriptor* descriptor);
|
|
||||||
~Device();
|
~Device();
|
||||||
|
|
||||||
|
MaybeError Initialize();
|
||||||
|
|
||||||
CommandBufferBase* CreateCommandBuffer(CommandEncoderBase* encoder) override;
|
CommandBufferBase* CreateCommandBuffer(CommandEncoderBase* encoder) override;
|
||||||
|
|
||||||
Serial GetCompletedCommandSerial() const final override;
|
Serial GetCompletedCommandSerial() const final override;
|
||||||
|
@ -108,7 +108,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
ComPtr<ID3D12Fence> mFence;
|
ComPtr<ID3D12Fence> mFence;
|
||||||
HANDLE mFenceEvent;
|
HANDLE mFenceEvent;
|
||||||
|
|
||||||
ComPtr<ID3D12Device> mD3d12Device;
|
ComPtr<ID3D12Device> mD3d12Device; // Device is owned by adapter and will not be outlived.
|
||||||
ComPtr<ID3D12CommandQueue> mCommandQueue;
|
ComPtr<ID3D12CommandQueue> mCommandQueue;
|
||||||
|
|
||||||
ComPtr<ID3D12CommandSignature> mDispatchIndirectSignature;
|
ComPtr<ID3D12CommandSignature> mDispatchIndirectSignature;
|
||||||
|
|
Loading…
Reference in New Issue