From 1171f7028845014ae6900ff77bd07ef84d1d0ae4 Mon Sep 17 00:00:00 2001 From: Stephen Pridham Date: Wed, 5 Jan 2022 12:43:40 -0500 Subject: [PATCH 1/3] Add heap tier check for creating heap --- src/d3d12/d3d12-backend.h | 1 + src/d3d12/d3d12-device.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/d3d12/d3d12-backend.h b/src/d3d12/d3d12-backend.h index 9bda5a6..723f50e 100644 --- a/src/d3d12/d3d12-backend.h +++ b/src/d3d12/d3d12-backend.h @@ -1094,6 +1094,7 @@ namespace nvrhi::d3d12 bool m_MeshletsSupported = false; bool m_VariableRateShadingSupported = false; + D3D12_FEATURE_DATA_D3D12_OPTIONS m_Options = {}; D3D12_FEATURE_DATA_D3D12_OPTIONS5 m_Options5 = {}; D3D12_FEATURE_DATA_D3D12_OPTIONS6 m_Options6 = {}; D3D12_FEATURE_DATA_D3D12_OPTIONS7 m_Options7 = {}; diff --git a/src/d3d12/d3d12-device.cpp b/src/d3d12/d3d12-device.cpp index 6fd7b71..0c50b2f 100644 --- a/src/d3d12/d3d12-device.cpp +++ b/src/d3d12/d3d12-device.cpp @@ -102,6 +102,7 @@ namespace nvrhi::d3d12 m_Resources.shaderResourceViewHeap.allocateResources(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, desc.shaderResourceViewHeapSize, true); m_Resources.samplerHeap.allocateResources(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, desc.samplerHeapSize, true); + m_Context.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &m_Options, sizeof(m_Options)); bool hasOptions5 = SUCCEEDED(m_Context.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &m_Options5, sizeof(m_Options5))); bool hasOptions6 = SUCCEEDED(m_Context.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS6, &m_Options6, sizeof(m_Options6))); bool hasOptions7 = SUCCEEDED(m_Context.device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &m_Options7, sizeof(m_Options7))); @@ -505,13 +506,25 @@ namespace nvrhi::d3d12 { D3D12_HEAP_DESC heapDesc; heapDesc.SizeInBytes = d.capacity; - heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; heapDesc.Alignment = D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT; heapDesc.Properties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN; heapDesc.Properties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN; heapDesc.Properties.CreationNodeMask = 1; // no mGPU support in nvrhi so far heapDesc.Properties.VisibleNodeMask = 1; + switch (m_Options.ResourceHeapTier) + { + case D3D12_RESOURCE_HEAP_TIER_1: + heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; + break; + case D3D12_RESOURCE_HEAP_TIER_2: + heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; + break; + default: + utils::InvalidEnum( ); + return nullptr; + } + switch (d.type) { case HeapType::DeviceLocal: From cbb98adef3a26610961424eb496cf68f107d2988 Mon Sep 17 00:00:00 2001 From: Stephen Pridham Date: Wed, 5 Jan 2022 12:54:15 -0500 Subject: [PATCH 2/3] Fix formatting issue --- src/d3d12/d3d12-device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d3d12/d3d12-device.cpp b/src/d3d12/d3d12-device.cpp index 0c50b2f..4bc24ff 100644 --- a/src/d3d12/d3d12-device.cpp +++ b/src/d3d12/d3d12-device.cpp @@ -521,7 +521,7 @@ namespace nvrhi::d3d12 heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; break; default: - utils::InvalidEnum( ); + utils::InvalidEnum(); return nullptr; } From 2c4dd45e1ec459d0ef047a22aec3662d65ab22c8 Mon Sep 17 00:00:00 2001 From: Stephen Pridham Date: Wed, 5 Jan 2022 18:53:44 -0500 Subject: [PATCH 3/3] Update so that future heap tier changes won't break this --- src/d3d12/d3d12-device.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/d3d12/d3d12-device.cpp b/src/d3d12/d3d12-device.cpp index 4bc24ff..945b4f4 100644 --- a/src/d3d12/d3d12-device.cpp +++ b/src/d3d12/d3d12-device.cpp @@ -512,18 +512,10 @@ namespace nvrhi::d3d12 heapDesc.Properties.CreationNodeMask = 1; // no mGPU support in nvrhi so far heapDesc.Properties.VisibleNodeMask = 1; - switch (m_Options.ResourceHeapTier) - { - case D3D12_RESOURCE_HEAP_TIER_1: + if (m_Options.ResourceHeapTier == D3D12_RESOURCE_HEAP_TIER_1) heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES; - break; - case D3D12_RESOURCE_HEAP_TIER_2: + else heapDesc.Flags = D3D12_HEAP_FLAG_ALLOW_ALL_BUFFERS_AND_TEXTURES; - break; - default: - utils::InvalidEnum(); - return nullptr; - } switch (d.type) {