From 95efb60fbbba9a44994b9d6d512414884ebbd217 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 18 Mar 2019 22:25:32 -0700 Subject: Improved messages about descriptor allocation failures in D3D12 backend (fixed https://github.com/DiligentGraphics/DiligentCore/issues/71). --- Graphics/GraphicsEngineD3D12/include/D3D12Utils.h | 1 - .../GraphicsEngineD3D12/src/DescriptorHeap.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 35 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h index 237a3869..344a4d31 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h @@ -27,5 +27,4 @@ namespace Diligent { const Char* GetD3D12DescriptorHeapTypeLiteralName(D3D12_DESCRIPTOR_HEAP_TYPE Type); - } diff --git a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp index 326845a9..f5a1be4d 100644 --- a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp @@ -427,7 +427,7 @@ DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) auto NewDynamicSubAllocation = m_ParentGPUHeap.AllocateDynamic(SuballocationSize); if (NewDynamicSubAllocation.IsNull()) { - LOG_ERROR_MESSAGE("Failed to suballocate region for dynamic descriptors"); + LOG_ERROR("Dynamic space in ", GetD3D12DescriptorHeapTypeLiteralName(m_ParentGPUHeap.GetHeapDesc().Type), " GPU descriptor heap is exhausted."); return DescriptorHeapAllocation(); } m_Suballocations.emplace_back(std::move(NewDynamicSubAllocation)); diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index b5809eb5..87139ef9 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -588,12 +588,22 @@ void RootSignature::InitResourceCache(RenderDeviceD3D12Impl* pDeviceD3D12Impl m_TotalSamplerSlots[SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE]; DescriptorHeapAllocation CbcSrvUavHeapSpace, SamplerHeapSpace; - if(TotalSrvCbvUavDescriptors) + if (TotalSrvCbvUavDescriptors) + { CbcSrvUavHeapSpace = pDeviceD3D12Impl->AllocateGPUDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, TotalSrvCbvUavDescriptors); + DEV_CHECK_ERR(!CbcSrvUavHeapSpace.IsNull(), + "Failed to allocate ", TotalSrvCbvUavDescriptors, " GPU-visible CBV/SRV/UAV descriptor", (TotalSrvCbvUavDescriptors > 1 ? "s" : ""), ". " + "Consider increasing GPUDescriptorHeapSize[0] in EngineD3D12CreateInfo."); + } VERIFY_EXPR(TotalSrvCbvUavDescriptors == 0 && CbcSrvUavHeapSpace.IsNull() || CbcSrvUavHeapSpace.GetNumHandles() == TotalSrvCbvUavDescriptors); - if(TotalSamplerDescriptors) + if (TotalSamplerDescriptors) + { SamplerHeapSpace = pDeviceD3D12Impl->AllocateGPUDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, TotalSamplerDescriptors); + DEV_CHECK_ERR(!SamplerHeapSpace.IsNull(), + "Failed to allocate ", TotalSamplerDescriptors, " GPU-visible Sampler descriptor", (TotalSamplerDescriptors > 1 ? "s" : ""), ". " + "Consider using static samplers in the Pipeline State Object or increasing GPUDescriptorHeapSize[1] in EngineD3D12CreateInfo."); + } VERIFY_EXPR(TotalSamplerDescriptors == 0 && SamplerHeapSpace.IsNull() || SamplerHeapSpace.GetNumHandles() == TotalSamplerDescriptors); // Iterate through all root static/mutable tables and assign start offsets. The tables are tightly packed, so @@ -891,10 +901,23 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* VERIFY_EXPR(NumDynamicCbvSrvUavDescriptors > 0 || NumDynamicSamplerDescriptors > 0); DescriptorHeapAllocation DynamicCbvSrvUavDescriptors, DynamicSamplerDescriptors; - if (NumDynamicCbvSrvUavDescriptors) + if (NumDynamicCbvSrvUavDescriptors > 0) + { DynamicCbvSrvUavDescriptors = Ctx.AllocateDynamicGPUVisibleDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, NumDynamicCbvSrvUavDescriptors); - if (NumDynamicSamplerDescriptors) + DEV_CHECK_ERR(DynamicCbvSrvUavDescriptors.GetDescriptorHeap() != nullptr, + "Failed to allocate ", NumDynamicCbvSrvUavDescriptors, " dynamic GPU-visible CBV/SRV/UAV descriptor", (NumDynamicCbvSrvUavDescriptors > 1 ? "s" : ""), ". " + "Consider increasing GPUDescriptorHeapDynamicSize[0] in EngineD3D12CreateInfo " + "or optimizing dynamic resource utilization by using static or mutable shader resource variables instead."); + } + + if (NumDynamicSamplerDescriptors > 0) + { DynamicSamplerDescriptors = Ctx.AllocateDynamicGPUVisibleDescriptor(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, NumDynamicSamplerDescriptors); + DEV_CHECK_ERR(DynamicSamplerDescriptors.GetDescriptorHeap() != nullptr, + "Failed to allocate ", NumDynamicSamplerDescriptors, " dynamic GPU-visible Sampler descriptor", (NumDynamicSamplerDescriptors > 1 ? "s" : ""), ". " + "Consider using static samplers in the Pipeline State Object, increasing GPUDescriptorHeapDynamicSize[1] in " + "EngineD3D12CreateInfo, or optimizing dynamic resource utilization by using static or mutable shader resource variables instead."); + } CommandContext::ShaderDescriptorHeaps Heaps(ResourceCache.GetSrvCbvUavDescriptorHeap(), ResourceCache.GetSamplerDescriptorHeap()); if (Heaps.pSamplerHeap == nullptr) @@ -903,9 +926,9 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* if (Heaps.pSrvCbvUavHeap == nullptr) Heaps.pSrvCbvUavHeap = DynamicCbvSrvUavDescriptors.GetDescriptorHeap(); - if (NumDynamicCbvSrvUavDescriptors) + if (NumDynamicCbvSrvUavDescriptors > 0) VERIFY(DynamicCbvSrvUavDescriptors.GetDescriptorHeap() == Heaps.pSrvCbvUavHeap, "Inconsistent CbvSrvUav descriptor heaps" ); - if (NumDynamicSamplerDescriptors) + if (NumDynamicSamplerDescriptors > 0) VERIFY(DynamicSamplerDescriptors.GetDescriptorHeap() == Heaps.pSamplerHeap, "Inconsistent Sampler descriptor heaps" ); if (Heaps) -- cgit v1.2.3