diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-17 05:40:41 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:34:30 +0000 |
| commit | c55e817cc73086f36f0a1cc6beb75c371d16976d (patch) | |
| tree | 9cb2c4322401b9b24255bb17f8856af6d2d713b3 /Graphics/GraphicsEngineD3D12 | |
| parent | Updated DrawCommandTests to use different clear color for each test (diff) | |
| download | DiligentCore-c55e817cc73086f36f0a1cc6beb75c371d16976d.tar.gz DiligentCore-c55e817cc73086f36f0a1cc6beb75c371d16976d.zip | |
D3D12: reworked formatted buffer SRVs to be allocated as root views
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
7 files changed, 138 insertions, 118 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp index a1962d98..d6e81bc0 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp @@ -273,12 +273,13 @@ public: bool IsCompute, Uint32 FirstRootIndex); - template <bool IsCompute> void CommitRootViews(ShaderResourceCacheD3D12& ResourceCache, CommandContext& Ctx, DeviceContextD3D12Impl* pDeviceCtx, Uint32 DeviceCtxId, - Uint32 FirstRootIndex); + Uint32 FirstRootIndex, + bool IsCompute, + bool CommitDynamicBuffers); private: void CreateLayout(); @@ -305,32 +306,4 @@ private: SRBMemoryAllocator m_SRBMemAllocator; }; -template <bool IsCompute> -__forceinline void PipelineResourceSignatureD3D12Impl::CommitRootViews(ShaderResourceCacheD3D12& ResourceCache, - CommandContext& CmdCtx, - DeviceContextD3D12Impl* pDeviceCtx, - Uint32 DeviceCtxId, - Uint32 FirstRootIndex) -{ - for (Uint32 rv = 0; rv < m_RootParams.GetNumRootViews(); ++rv) - { - auto& RootView = m_RootParams.GetRootView(rv); - auto RootInd = RootView.RootIndex; - - auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(0, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - if (auto* pBuffToTransition = Res.pObject.RawPtr<BufferD3D12Impl>()) - { - bool IsDynamic = pBuffToTransition->GetDesc().Usage == USAGE_DYNAMIC; - if (IsDynamic) - { - D3D12_GPU_VIRTUAL_ADDRESS CBVAddress = pBuffToTransition->GetGPUAddress(DeviceCtxId, pDeviceCtx); - if (IsCompute) - CmdCtx.GetCommandList()->SetComputeRootConstantBufferView(FirstRootIndex + RootInd, CBVAddress); - else - CmdCtx.GetCommandList()->SetGraphicsRootConstantBufferView(FirstRootIndex + RootInd, CBVAddress); - } - } - } -} - } // namespace Diligent diff --git a/Graphics/GraphicsEngineD3D12/include/RootParamsManager.hpp b/Graphics/GraphicsEngineD3D12/include/RootParamsManager.hpp index f9d1b214..113a628a 100644 --- a/Graphics/GraphicsEngineD3D12/include/RootParamsManager.hpp +++ b/Graphics/GraphicsEngineD3D12/include/RootParamsManager.hpp @@ -150,20 +150,18 @@ __forceinline void RootParamsManager::ProcessRootTables(TOperation Operation) co { for (Uint32 rt = 0; rt < m_NumRootTables; ++rt) { - const auto& RootTable = GetRootTable(rt); - const auto RootInd = RootTable.RootIndex; - const auto& d3d12Param = RootTable.d3d12RootParam; + const auto& RootTable = GetRootTable(rt); + VERIFY(RootTable.GetDescriptorTableSize() > 0, "Unexepected empty descriptor table"); + const auto& d3d12Param = RootTable.d3d12RootParam; VERIFY_EXPR(d3d12Param.ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE); - const auto& d3d12Table = d3d12Param.DescriptorTable; - VERIFY(RootTable.GetDescriptorTableSize() > 0, "Unexepected empty descriptor table"); - bool IsResourceTable = d3d12Table.pDescriptorRanges[0].RangeType != D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; - D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType = D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES; -#ifdef DILIGENT_DEBUG - dbgHeapType = IsResourceTable ? D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV : D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; -#endif - Operation(RootInd, RootTable, d3d12Param, IsResourceTable, dbgHeapType); + const auto& d3d12Table = d3d12Param.DescriptorTable; + const auto IsResourceTable = d3d12Table.pDescriptorRanges[0].RangeType != D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; + const auto d3d12HeapType = IsResourceTable ? + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV : + D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER; + Operation(RootTable.RootIndex, RootTable, d3d12Param, IsResourceTable, d3d12HeapType); } } diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 5516604c..2a2e571a 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -93,11 +93,11 @@ BufferD3D12Impl::BufferD3D12Impl(IReferenceCounters* pRefCounters, if (AlignmentMask != 1) m_Desc.uiSizeInBytes = (m_Desc.uiSizeInBytes + AlignmentMask) & (~AlignmentMask); - if (m_Desc.Usage == USAGE_DYNAMIC && (m_Desc.BindFlags & (BIND_SHADER_RESOURCE | BIND_UNORDERED_ACCESS)) == 0) + if (m_Desc.Usage == USAGE_DYNAMIC && (m_Desc.BindFlags & BIND_UNORDERED_ACCESS) == 0) { // Dynamic constant/vertex/index buffers are suballocated in the upload heap when Map() is called. - // Dynamic buffers with SRV or UAV flags need to be allocated in GPU-only memory - // Dynamic upload heap buffer is always in D3D12_RESOURCE_STATE_GENERIC_READ state + // Dynamic buffers with UAV flags need to be allocated in GPU-only memory. + // Dynamic upload heap buffer is always in D3D12_RESOURCE_STATE_GENERIC_READ state. SetState(RESOURCE_STATE_GENERIC_READ); VERIFY_EXPR(m_DynamicData.size() == 1 + pRenderDeviceD3D12->GetNumDeferredContexts()); diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 168fbb60..7ea2e18e 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -331,7 +331,8 @@ void DeviceContextD3D12Impl::CommitRootTables(RootTableInfo& RootInfo) continue; VERIFY_EXPR(pSRB != nullptr); - pSignature->CommitRootViews<IsCompute>(pSRB->GetResourceCache(), CmdCtx, this, GetContextId(), RootSig.GetFirstRootIndex(s)); + constexpr auto CommitDynamicBuffers = true; + pSignature->CommitRootViews(pSRB->GetResourceCache(), CmdCtx, this, GetContextId(), RootSig.GetFirstRootIndex(s), IsCompute, CommitDynamicBuffers); } } @@ -1565,7 +1566,7 @@ void DeviceContextD3D12Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_F if (pd3d12Resource != nullptr) { - LOG_ERROR("Formatted or structured buffers require actual Direct3D12 backing resource and cannot be suballocated " + LOG_ERROR("Formatted buffers require actual Direct3D12 backing resource and cannot be suballocated " "from dynamic heap. In current implementation, the entire contents of the backing buffer is updated when the buffer is unmapped. " "As a consequence, the buffer cannot be mapped with MAP_FLAG_NO_OVERWRITE flag because updating the whole " "buffer will overwrite regions that may still be in use by the GPU."); diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp index 63d5571d..087237c1 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp @@ -301,21 +301,23 @@ void PipelineResourceSignatureD3D12Impl::CreateLayout() const auto UseDynamicOffset = (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS) == 0; const auto IsFormattedBuffer = (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0; + const auto IsArray = ResDesc.ArraySize != 1; d3d12RootParamType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; switch (ResDesc.ResourceType) { case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: VERIFY(!IsFormattedBuffer, "Constant buffers can't be labeled as formatted. This error should've been cuaght by ValidatePipelineResourceSignatureDesc()."); - d3d12RootParamType = UseDynamicOffset ? D3D12_ROOT_PARAMETER_TYPE_CBV : D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + d3d12RootParamType = UseDynamicOffset && !IsArray ? D3D12_ROOT_PARAMETER_TYPE_CBV : D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; break; case SHADER_RESOURCE_TYPE_BUFFER_SRV: - d3d12RootParamType = UseDynamicOffset && !IsFormattedBuffer ? D3D12_ROOT_PARAMETER_TYPE_SRV : D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + d3d12RootParamType = UseDynamicOffset && !IsFormattedBuffer && !IsArray ? D3D12_ROOT_PARAMETER_TYPE_SRV : D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; break; case SHADER_RESOURCE_TYPE_BUFFER_UAV: - d3d12RootParamType = UseDynamicOffset && !IsFormattedBuffer ? D3D12_ROOT_PARAMETER_TYPE_UAV : D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; + // Always allocate buffer UAVs in descriptor tables + d3d12RootParamType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; break; default: @@ -681,22 +683,32 @@ inline void UpdateDynamicBuffersCounter(const BufferD3D12Impl* pOldBuff, } } -#if 0 inline void UpdateDynamicBuffersCounter(const BufferViewD3D12Impl* pOldBuffView, const BufferViewD3D12Impl* pNewBuffView, - Uint32& BuffCounter) + Uint32& BuffCounter, + D3D12_ROOT_PARAMETER_TYPE d3d12RootParamType) { if (pOldBuffView != nullptr && pOldBuffView->GetBuffer<BufferD3D12Impl>()->GetDesc().Usage == USAGE_DYNAMIC) { + VERIFY_EXPR(d3d12RootParamType == D3D12_ROOT_PARAMETER_TYPE_SRV || d3d12RootParamType == D3D12_ROOT_PARAMETER_TYPE_UAV); VERIFY_EXPR(BuffCounter > 0); --BuffCounter; } if (pNewBuffView != nullptr && pNewBuffView->GetBuffer<BufferD3D12Impl>()->GetDesc().Usage == USAGE_DYNAMIC) { + DEV_CHECK_ERR(d3d12RootParamType == D3D12_ROOT_PARAMETER_TYPE_SRV || d3d12RootParamType == D3D12_ROOT_PARAMETER_TYPE_UAV, + "Dynamic buffers must be used as root views"); ++BuffCounter; } } -#endif + +inline void UpdateDynamicBuffersCounter(const TextureViewD3D12Impl*, + const TextureViewD3D12Impl*, + Uint32&, + D3D12_ROOT_PARAMETER_TYPE) +{ +} + void PipelineResourceSignatureD3D12Impl::InitializeStaticSRBResources(ShaderResourceCacheD3D12& DstResourceCache) const { @@ -751,12 +763,10 @@ void PipelineResourceSignatureD3D12Impl::InitializeStaticSRBResources(ShaderReso } else if (SrcRes.Type == SHADER_RESOURCE_TYPE_BUFFER_SRV || SrcRes.Type == SHADER_RESOURCE_TYPE_BUFFER_UAV) { - // In current implementation buffers that have views always have backing resource and are bound to descriptor tables -#if 0 UpdateDynamicBuffersCounter(DstRes.pObject.RawPtr<const BufferViewD3D12Impl>(), SrcRes.pObject.RawPtr<const BufferViewD3D12Impl>(), - DstBoundDynamicCBsCounter); -#endif + DstBoundDynamicCBsCounter, + Attr.GetD3D12RootParamType()); } DstRes.pObject = SrcRes.pObject; @@ -790,22 +800,21 @@ namespace template <class TOperation> __forceinline void ProcessCachedTableResources(Uint32 RootInd, - const D3D12_ROOT_PARAMETER& D3D12Param, + const D3D12_ROOT_PARAMETER& d3d12Param, ShaderResourceCacheD3D12& ResourceCache, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType, TOperation Operation) { - for (UINT r = 0; r < D3D12Param.DescriptorTable.NumDescriptorRanges; ++r) + auto& TableResources = ResourceCache.GetRootTable(RootInd); + for (UINT r = 0; r < d3d12Param.DescriptorTable.NumDescriptorRanges; ++r) { - const auto& range = D3D12Param.DescriptorTable.pDescriptorRanges[r]; + const auto& range = d3d12Param.DescriptorTable.pDescriptorRanges[r]; + VERIFY(dbgHeapType == D3D12DescriptorRangeTypeToD3D12HeapType(range.RangeType), "Mistmatch between descriptor heap type and descriptor range type"); for (UINT d = 0; d < range.NumDescriptors; ++d) { - VERIFY(dbgHeapType == D3D12DescriptorRangeTypeToD3D12HeapType(range.RangeType), "Mistmatch between descriptor heap type and descriptor range type"); - - auto OffsetFromTableStart = range.OffsetInDescriptorsFromTableStart + d; - auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(OffsetFromTableStart, dbgHeapType); - - Operation(OffsetFromTableStart, range, Res); + const auto Offset = range.OffsetInDescriptorsFromTableStart + d; + auto& Res = TableResources.GetResource(Offset, dbgHeapType); + Operation(Offset, range, Res); } } } @@ -1046,12 +1055,66 @@ void PipelineResourceSignatureD3D12Impl::TransitionResources(ShaderResourceCache ); } + +void PipelineResourceSignatureD3D12Impl::CommitRootViews(ShaderResourceCacheD3D12& ResourceCache, + CommandContext& CmdCtx, + DeviceContextD3D12Impl* pDeviceCtx, + Uint32 DeviceCtxId, + Uint32 BaseRootIndex, + bool IsCompute, + bool CommitDynamicBuffers) +{ + for (Uint32 rv = 0; rv < m_RootParams.GetNumRootViews(); ++rv) + { + auto& RootView = m_RootParams.GetRootView(rv); + auto RootInd = RootView.RootIndex; + + auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(0, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + if (Res.Type == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER) + { + if (auto* pBuff = Res.pObject.RawPtr<BufferD3D12Impl>()) + { + bool IsDynamic = pBuff->GetDesc().Usage == USAGE_DYNAMIC; + if (IsDynamic == CommitDynamicBuffers) + { + auto CBVAddress = pBuff->GetGPUAddress(DeviceCtxId, pDeviceCtx); + if (IsCompute) + CmdCtx.GetCommandList()->SetComputeRootConstantBufferView(BaseRootIndex + RootInd, CBVAddress); + else + CmdCtx.GetCommandList()->SetGraphicsRootConstantBufferView(BaseRootIndex + RootInd, CBVAddress); + } + } + } + else if (Res.Type == SHADER_RESOURCE_TYPE_BUFFER_SRV || + Res.Type == SHADER_RESOURCE_TYPE_BUFFER_UAV) + { + if (auto* pBuffView = Res.pObject.RawPtr<BufferViewD3D12Impl>()) + { + auto* pBuffer = pBuffView->GetBuffer<BufferD3D12Impl>(); + bool IsDynamic = pBuffer->GetDesc().Usage == USAGE_DYNAMIC; + if (IsDynamic == CommitDynamicBuffers) + { + auto SRVAddress = pBuffer->GetGPUAddress(DeviceCtxId, pDeviceCtx); + if (IsCompute) + CmdCtx.GetCommandList()->SetComputeRootShaderResourceView(BaseRootIndex + RootInd, SRVAddress); + else + CmdCtx.GetCommandList()->SetGraphicsRootShaderResourceView(BaseRootIndex + RootInd, SRVAddress); + } + } + } + else + { + UNEXPECTED("Unexpected root view resource type"); + } + } +} + void PipelineResourceSignatureD3D12Impl::CommitRootTables(ShaderResourceCacheD3D12& ResourceCache, CommandContext& CmdCtx, DeviceContextD3D12Impl* pDeviceCtx, Uint32 DeviceCtxId, bool IsCompute, - Uint32 FirstRootIndex) + Uint32 BaseRootIndex) { auto* pd3d12Device = GetDevice()->GetD3D12Device(); @@ -1102,7 +1165,7 @@ void PipelineResourceSignatureD3D12Impl::CommitRootTables(ShaderResourceCacheD3D m_RootParams.ProcessRootTables( [&](Uint32 RootInd, const RootParameter& RootTable, - const D3D12_ROOT_PARAMETER& D3D12Param, + const D3D12_ROOT_PARAMETER& d3d12Param, bool IsResourceTable, D3D12_DESCRIPTOR_HEAP_TYPE dbgHeapType) // { @@ -1111,10 +1174,9 @@ void PipelineResourceSignatureD3D12Impl::CommitRootTables(ShaderResourceCacheD3D bool IsDynamicTable = RootTable.Group == ROOT_PARAMETER_GROUP_DYNAMIC; if (IsDynamicTable) { - if (IsResourceTable) - RootTableGPUDescriptorHandle = DynamicCbvSrvUavDescriptors.GetGpuHandle(DynamicCbvSrvUavTblOffset); - else - RootTableGPUDescriptorHandle = DynamicSamplerDescriptors.GetGpuHandle(DynamicSamplerTblOffset); + RootTableGPUDescriptorHandle = IsResourceTable ? + DynamicCbvSrvUavDescriptors.GetGpuHandle(DynamicCbvSrvUavTblOffset) : + DynamicSamplerDescriptors.GetGpuHandle(DynamicSamplerTblOffset); } else { @@ -1125,14 +1187,14 @@ void PipelineResourceSignatureD3D12Impl::CommitRootTables(ShaderResourceCacheD3D } if (IsCompute) - CmdCtx.GetCommandList()->SetComputeRootDescriptorTable(FirstRootIndex + RootInd, RootTableGPUDescriptorHandle); + CmdCtx.GetCommandList()->SetComputeRootDescriptorTable(BaseRootIndex + RootInd, RootTableGPUDescriptorHandle); else - CmdCtx.GetCommandList()->SetGraphicsRootDescriptorTable(FirstRootIndex + RootInd, RootTableGPUDescriptorHandle); + CmdCtx.GetCommandList()->SetGraphicsRootDescriptorTable(BaseRootIndex + RootInd, RootTableGPUDescriptorHandle); if (IsDynamicTable) { ProcessCachedTableResources( - RootInd, D3D12Param, ResourceCache, dbgHeapType, + RootInd, d3d12Param, ResourceCache, dbgHeapType, [&](UINT OffsetFromTableStart, const D3D12_DESCRIPTOR_RANGE& range, ShaderResourceCacheD3D12::Resource& Res) // @@ -1179,25 +1241,10 @@ void PipelineResourceSignatureD3D12Impl::CommitRootTables(ShaderResourceCacheD3D VERIFY_EXPR(DynamicCbvSrvUavTblOffset == NumDynamicCbvSrvUavDescriptors); VERIFY_EXPR(DynamicSamplerTblOffset == NumDynamicSamplerDescriptors); - for (Uint32 rv = 0; rv < m_RootParams.GetNumRootViews(); ++rv) - { - auto& RootView = m_RootParams.GetRootView(rv); - auto RootInd = RootView.RootIndex; - - auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(0, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); - if (auto* pBuffToTransition = Res.pObject.RawPtr<BufferD3D12Impl>()) - { - bool IsDynamic = pBuffToTransition->GetDesc().Usage == USAGE_DYNAMIC; - if (!IsDynamic) - { - D3D12_GPU_VIRTUAL_ADDRESS CBVAddress = pBuffToTransition->GetGPUAddress(DeviceCtxId, pDeviceCtx); - if (IsCompute) - CmdCtx.GetCommandList()->SetComputeRootConstantBufferView(FirstRootIndex + RootInd, CBVAddress); - else - CmdCtx.GetCommandList()->SetGraphicsRootConstantBufferView(FirstRootIndex + RootInd, CBVAddress); - } - } - } + // Commit non-dynamic root buffer views + constexpr auto CommitDynamicBuffers = false; + CommitRootViews(ResourceCache, CmdCtx, pDeviceCtx, + DeviceCtxId, BaseRootIndex, IsCompute, CommitDynamicBuffers); } @@ -1354,7 +1401,7 @@ struct ResourceViewTraits {}; template <> -struct ResourceViewTraits<ITextureViewD3D12> +struct ResourceViewTraits<TextureViewD3D12Impl> { static const INTERFACE_ID& IID; @@ -1363,10 +1410,10 @@ struct ResourceViewTraits<ITextureViewD3D12> // return true; //} }; -const INTERFACE_ID& ResourceViewTraits<ITextureViewD3D12>::IID = IID_TextureViewD3D12; +const INTERFACE_ID& ResourceViewTraits<TextureViewD3D12Impl>::IID = IID_TextureViewD3D12; template <> -struct ResourceViewTraits<IBufferViewD3D12> +struct ResourceViewTraits<BufferViewD3D12Impl> { static const INTERFACE_ID& IID; @@ -1375,7 +1422,7 @@ struct ResourceViewTraits<IBufferViewD3D12> // return VerifyBufferViewModeD3D(pViewD3D12, Attribs); //} }; -const INTERFACE_ID& ResourceViewTraits<IBufferViewD3D12>::IID = IID_BufferViewD3D12; +const INTERFACE_ID& ResourceViewTraits<BufferViewD3D12Impl>::IID = IID_BufferViewD3D12; template <typename TResourceViewType, ///< ResType of the view (ITextureViewD3D12 or IBufferViewD3D12) @@ -1418,6 +1465,8 @@ void BindResourceHelper::CacheResourceView(IDeviceObject* pView, GetD3D12Device()->CopyDescriptorsSimple(1, ShdrVisibleHeapCPUDescriptorHandle, DstRes.CPUDescriptorHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); } + UpdateDynamicBuffersCounter(DstRes.pObject.RawPtr<const TResourceViewType>(), pViewD3D12, ResourceCache.GetDynamicRootBuffersCounter(), Attribs.GetD3D12RootParamType()); + BindSamplerProc(pViewD3D12); DstRes.pObject = std::move(pViewD3D12); @@ -1433,20 +1482,24 @@ void BindResourceHelper::BindResource(IDeviceObject* pObj) const if (ResourceCache.GetContentType() == CacheContentType::Signature) { - VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Static shader resources of a shader should not be assigned shader visible descriptor space"); + VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Static shader resources should never be assigned shader visible descriptor space."); } else if (ResourceCache.GetContentType() == CacheContentType::SRB) { - if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER && ResDesc.ArraySize == 1) + if (Attribs.GetD3D12RootParamType() == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) { - VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Non-array constant buffers are bound as root views and should not be assigned shader visible descriptor space"); + if (ResDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) + VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Shader resources allocated in non-dynamic descriptor tables must be assigned shader-visible descriptor space"); + else + VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Shader resources allocated in dynamic descriptor tables should never be assigned shader-visible descriptor space"); } else { - if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) - VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); - else - VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); + VERIFY((ResDesc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER || + ResDesc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_SRV || + ResDesc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_UAV), + "Only constant buffers and dynamic buffers views can be allocated as root views"); + VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Resourcesa allocated as root views should never be assigned shader-visible descriptor space"); } } else @@ -1465,9 +1518,9 @@ void BindResourceHelper::BindResource(IDeviceObject* pObj) const break; case SHADER_RESOURCE_TYPE_TEXTURE_SRV: - CacheResourceView<ITextureViewD3D12>( + CacheResourceView<TextureViewD3D12Impl>( pObj, TEXTURE_VIEW_SHADER_RESOURCE, - [&](ITextureViewD3D12* pTexView) // + [&](TextureViewD3D12Impl* pTexView) // { if (Attribs.IsCombinedWithSampler()) { @@ -1507,15 +1560,15 @@ void BindResourceHelper::BindResource(IDeviceObject* pObj) const break; case SHADER_RESOURCE_TYPE_TEXTURE_UAV: - CacheResourceView<ITextureViewD3D12>(pObj, TEXTURE_VIEW_UNORDERED_ACCESS, [](ITextureViewD3D12*) {}); + CacheResourceView<TextureViewD3D12Impl>(pObj, TEXTURE_VIEW_UNORDERED_ACCESS, [](TextureViewD3D12Impl*) {}); break; case SHADER_RESOURCE_TYPE_BUFFER_SRV: - CacheResourceView<IBufferViewD3D12>(pObj, BUFFER_VIEW_SHADER_RESOURCE, [](IBufferViewD3D12*) {}); + CacheResourceView<BufferViewD3D12Impl>(pObj, BUFFER_VIEW_SHADER_RESOURCE, [](BufferViewD3D12Impl*) {}); break; case SHADER_RESOURCE_TYPE_BUFFER_UAV: - CacheResourceView<IBufferViewD3D12>(pObj, BUFFER_VIEW_UNORDERED_ACCESS, [](IBufferViewD3D12*) {}); + CacheResourceView<BufferViewD3D12Impl>(pObj, BUFFER_VIEW_UNORDERED_ACCESS, [](BufferViewD3D12Impl*) {}); break; case SHADER_RESOURCE_TYPE_SAMPLER: diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index a4c8769c..642a9f98 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -437,14 +437,6 @@ void PipelineStateD3D12Impl::CreateDefaultResourceSignature(const PipelineStateC PIPELINE_RESOURCE_FLAGS Flags; GetShaderResourceTypeAndFlags(Res, Type, Flags); - // Backward compatibility: only CBV with array size == 1 will be placed as root view. - if ((Type == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER && Res.BindCount > 1) || - Type == SHADER_RESOURCE_TYPE_BUFFER_SRV || - Type == SHADER_RESOURCE_TYPE_BUFFER_UAV) - { - Flags |= PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS; - } - if (Res.BindCount == 0) { LOG_ERROR_AND_THROW("Is shader '", pShader->GetDesc().Name, "' resource '", Res.Name, "' uses runtime sized array, ", diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 4eb16933..fd890b83 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -149,7 +149,10 @@ void RootSignatureD3D12::Finalize(RenderDeviceD3D12Impl* pDeviceD3D12Impl) const auto& RootView = RootParams.GetRootView(rv); const auto& d3d12SrcParam = RootView.d3d12RootParam; const Uint32 RootIndex = FirstRootIndex + RootView.RootIndex; - VERIFY(d3d12SrcParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_CBV, "Root CBV is expected"); + VERIFY((d3d12SrcParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_CBV || + d3d12SrcParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_SRV || + d3d12SrcParam.ParameterType == D3D12_ROOT_PARAMETER_TYPE_UAV), + "Root CBV, SRV or UAV is expected"); MaxSpaceUsed = std::max(MaxSpaceUsed, d3d12SrcParam.Descriptor.RegisterSpace); d3d12Parameters[RootIndex] = d3d12SrcParam; |
