diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-10-20 07:13:28 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-10-20 07:13:28 +0000 |
| commit | 457e3c83ce5b08e95ae1cc07e9bc82296a003a28 (patch) | |
| tree | d51f9435e91e96042fd38ec1b7629e50f126e1d6 /Graphics | |
| parent | Added HLSLVersion, GLSLVersion and GLESSLVersion to ShaderCreateInfo struct (... (diff) | |
| download | DiligentCore-457e3c83ce5b08e95ae1cc07e9bc82296a003a28.tar.gz DiligentCore-457e3c83ce5b08e95ae1cc07e9bc82296a003a28.zip | |
Added DRAW_FLAG_RESOURCE_BUFFERS_INTACT flag (API Version 240036)
Diffstat (limited to 'Graphics')
7 files changed, 70 insertions, 16 deletions
diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index 36cb5c36..74e125ca 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -26,7 +26,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240035 +#define DILIGENT_API_VERSION 240036 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 45f057c9..1e50262e 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -70,7 +70,40 @@ enum DRAW_FLAGS : Uint8 DRAW_FLAG_VERIFY_RENDER_TARGETS = 0x04, /// Perform all state validation checks - DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS + DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS, + + /// Indicates that none of the resource buffers used by the draw command + /// have been modified by the CPU since the last command. + /// + /// \remarks D3D12 and Vulkan back-ends have to perform some work to make data in buffers + /// available to draw commands. By default the engine assumes that the CPU may + /// change the data after every command. For example, if a draw command uses a constant + /// buffer, the engine assumes that the CPU may write new data to the buffer (for example, new + /// transformation matrices), before every draw call. This is not always the case, however, + /// and the application may inform the engine that the data in the buffer stay intact to avoid + /// extra work.\n + /// This flag is most useful when application issues a series of draw commands that use the same + /// resources that do not change between the commands.\n + /// Note that after a new PSO is bound or an SRB is committed, the engine will always set all + /// required buffers regardless of the flag. The flag will only take effect on the second and + /// susbequent draw calls that use the same PSO and SRB.\n + /// The flag has no effect in D3D11 and OpenGL backends. + /// + /// Technical details + /// + /// Vulkan backend allocates VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC descriptors for uniform (constant), + /// buffers and VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC descritptors for storage buffers. + /// Note that HLSL structured buffers are mapped to read-only storage buffers in SPIRV and RW buffers + /// are mapped to RW-storage buffers. + /// By default, all dynamic descriptor sets are updated every time a draw command is issued (see + /// PipelineStateVkImpl::BindDescriptorSetsWithDynamicOffsets). When DRAW_FLAG_RESOURCE_BUFFERS_INTACT is + /// specified, dynamic descriptor sets are only be bound by the first draw command that uses the PSO and the SRB. + /// + /// Direct3D12 backend binds constant buffers to root views. By default the engine assumes that the buffers + /// may be modified by the CPU between draw commands and always commits root views (see RootSignature::CommitRootViews). + /// When DRAW_FLAG_RESOURCE_BUFFERS_INTACT is set, root views are only committed by the first draw command that uses + /// the PSO and the SRB pair. + DRAW_FLAG_RESOURCE_BUFFERS_INTACT = 0x08 }; DEFINE_FLAG_ENUM_OPERATORS(DRAW_FLAGS) diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index 2bcb8004..b9561b3b 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -288,12 +288,16 @@ private: VALUE_TYPE CommittedIBFormat = VT_UNDEFINED; Uint32 CommittedD3D12IndexDataStartOffset = 0; - // Flag indicating if currently committed D3D12 vertex buffers are up to date + // Indicates if currently committed D3D12 vertex buffers are up to date bool bCommittedD3D12VBsUpToDate = false; - // Fl indicating if currently committed D3D11 index buffer is up to date + // Indicates if currently committed D3D11 index buffer is up to date bool bCommittedD3D12IBUpToDate = false; + // Indicates if root views have been committed since the time SRB + // has been committed. + bool bRootViewsCommitted = false; + class ShaderResourceCacheD3D12* pCommittedResourceCache = nullptr; }m_State; diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 1a3a4985..c1608c4a 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -229,6 +229,7 @@ namespace Diligent } } m_State.pCommittedResourceCache = nullptr; + m_State.bRootViewsCommitted = false; } void DeviceContextD3D12Impl::TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding) @@ -250,6 +251,7 @@ namespace Diligent m_pPipelineState->CommitAndTransitionShaderResources(pShaderResourceBinding, Ctx, true, StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION, StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_VERIFY); + m_State.bRootViewsCommitted = false; } void DeviceContextD3D12Impl::SetStencilRef(Uint32 StencilRef) @@ -392,7 +394,11 @@ namespace Diligent if (m_State.pCommittedResourceCache != nullptr) { - m_pPipelineState->GetRootSignature().CommitRootViews(*m_State.pCommittedResourceCache, GraphCtx, false, this); + if (!m_State.bRootViewsCommitted || (Flags & DRAW_FLAG_RESOURCE_BUFFERS_INTACT) == 0) + { + m_pPipelineState->GetRootSignature().CommitRootViews(*m_State.pCommittedResourceCache, GraphCtx, false, this); + m_State.bRootViewsCommitted = true; + } } #ifdef DEVELOPMENT else diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h b/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h index 902dcdd4..e34ee108 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h +++ b/Graphics/GraphicsEngineVulkan/include/PipelineLayout.h @@ -90,10 +90,11 @@ public: { std::vector<VkDescriptorSet> vkSets; std::vector<uint32_t> DynamicOffsets; - const ShaderResourceCacheVk* pResourceCache = nullptr; - VkPipelineBindPoint BindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; - Uint32 SetCout = 0; - Uint32 DynamicOffsetCount = 0; + const ShaderResourceCacheVk* pResourceCache = nullptr; + VkPipelineBindPoint BindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; + Uint32 SetCout = 0; + Uint32 DynamicOffsetCount = 0; + bool DynamicDescriptorsBound = false; #ifdef _DEBUG const PipelineLayout* pDbgPipelineLayout = nullptr; #endif @@ -105,16 +106,17 @@ public: void Reset() { - SetCout = 0; - DynamicOffsetCount = 0; + pResourceCache = nullptr; + BindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; + SetCout = 0; + DynamicOffsetCount = 0; + DynamicDescriptorsBound = false; + #ifdef _DEBUG // In release mode, do not clear vectors as this causes unnecessary work vkSets.clear(); DynamicOffsets.clear(); -#endif - pResourceCache = nullptr; - BindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; -#ifdef _DEBUG + pDbgPipelineLayout = nullptr; #endif } @@ -246,6 +248,8 @@ __forceinline void PipelineLayout::BindDescriptorSetsWithDynamicOffsets(VulkanUt // dynamicOffsetCount must equal the total number of dynamic descriptors in the sets being bound (13.2.5) BindInfo.DynamicOffsetCount, BindInfo.DynamicOffsets.data()); + + BindInfo.DynamicDescriptorsBound = true; } } diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 2bc18ce1..454429b8 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -421,7 +421,12 @@ namespace Diligent #endif if (m_DescrSetBindInfo.DynamicOffsetCount != 0) - m_pPipelineState->BindDescriptorSetsWithDynamicOffsets(GetCommandBuffer(), m_ContextId, this, m_DescrSetBindInfo); + { + if (!m_DescrSetBindInfo.DynamicDescriptorsBound || (Flags & DRAW_FLAG_RESOURCE_BUFFERS_INTACT) == 0) + { + m_pPipelineState->BindDescriptorSetsWithDynamicOffsets(GetCommandBuffer(), m_ContextId, this, m_DescrSetBindInfo); + } + } #if 0 #ifdef _DEBUG else diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index b978f3c6..b3b97ec6 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -499,6 +499,8 @@ void PipelineLayout::PrepareDescriptorSets(DeviceContextVkImpl* pCtxVkI 0, nullptr); } + + BindInfo.DynamicDescriptorsBound = false; } } |
