From 2ab61c6b891467a705718361cc8c517789a1236c Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 13 Jun 2018 09:19:26 -0700 Subject: Improved setting dynamic buffer offsets --- Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h | 4 ++++ Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp | 8 ++------ Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index f2c1b0a5..841c3086 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -147,6 +147,8 @@ public: return m_DynamicDescriptorPool.Allocate(SetLayout); } + std::vector& GetDynamicBufferOffsets(){return m_DynamicBufferOffsets;} + private: void CommitRenderPassAndFramebuffer(class PipelineStateVkImpl *pPipelineStateVk); void CommitVkVertexBuffers(); @@ -199,6 +201,8 @@ private: // Number of the command buffer currently being recorded by the context and that will // be submitted next Atomics::AtomicInt64 m_NextCmdBuffNumber; + + std::vector m_DynamicBufferOffsets; }; } diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp index f3e0ac2b..7bc5daff 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp @@ -434,9 +434,7 @@ void PipelineLayout::BindDescriptorSets(DeviceContextVkImpl* pCtxVkImpl, VERIFY(m_LayoutMgr.GetDescriptorSet(SHADER_VARIABLE_TYPE_STATIC).SetIndex == m_LayoutMgr.GetDescriptorSet(SHADER_VARIABLE_TYPE_MUTABLE).SetIndex, "Static and mutable variables are expected to share the same descriptor set"); -#ifdef _DEBUG Uint32 TotalDynamicDescriptors = 0; -#endif for(SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_MUTABLE; VarType <= SHADER_VARIABLE_TYPE_DYNAMIC; VarType = static_cast(VarType+1)) { const auto &Set = m_LayoutMgr.GetDescriptorSet(VarType); @@ -447,9 +445,7 @@ void PipelineLayout::BindDescriptorSets(DeviceContextVkImpl* pCtxVkImpl, vkSets[Set.SetIndex] = ResourceCache.GetDescriptorSet(Set.SetIndex).GetVkDescriptorSet(); VERIFY(vkSets[Set.SetIndex] != VK_NULL_HANDLE, "Descriptor set must not be null"); } -#ifdef _DEBUG TotalDynamicDescriptors += Set.NumDynamicDescriptors; -#endif } #ifdef _DEBUG @@ -457,9 +453,9 @@ void PipelineLayout::BindDescriptorSets(DeviceContextVkImpl* pCtxVkImpl, VERIFY(vkSets[i] != VK_NULL_HANDLE, "Descriptor set must not be null"); #endif - std::vector DynamicOffsets; + auto& DynamicOffsets = pCtxVkImpl->GetDynamicBufferOffsets(); + DynamicOffsets.resize(TotalDynamicDescriptors); ResourceCache.GetDynamicBufferOffset(pCtxVkImpl->GetContextId(), DynamicOffsets); - VERIFY(DynamicOffsets.size() == TotalDynamicDescriptors, "Incorrect size of dynamic descriptor array"); auto& CmdBuffer = pCtxVkImpl->GetCommandBuffer(); // vkCmdBindDescriptorSets causes the sets numbered [firstSet .. firstSet+descriptorSetCount-1] to use the diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp index 74a20524..fa510f60 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceCacheVk.cpp @@ -286,8 +286,6 @@ VkDescriptorImageInfo ShaderResourceCacheVk::Resource::GetSamplerDescriptorWrite void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector& Offsets)const { - Offsets.clear(); - // If any of the sets being bound include dynamic uniform or storage buffers, then // pDynamicOffsets includes one element for each array element in each dynamic descriptor // type binding in each set. Values are taken from pDynamicOffsets in an order such that @@ -297,6 +295,7 @@ void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector(); auto Offset = pBufferVk->GetDynamicOffset(CtxId); - Offsets.emplace_back(Offset); + Offsets[OffsetInd++] = Offset; ++res; } @@ -323,7 +322,7 @@ void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector(); const auto* pBufferVk = pBufferVkView->GetBufferVk(); auto Offset = pBufferVk->GetDynamicOffset(CtxId); - Offsets.emplace_back(Offset); + Offsets[OffsetInd++] = Offset; ++res; } @@ -338,6 +337,7 @@ void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector