diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-06-13 16:19:26 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-06-13 16:38:45 +0000 |
| commit | 2ab61c6b891467a705718361cc8c517789a1236c (patch) | |
| tree | 2bef0953f1000ae410fe95f80fb7124e548813e0 /Graphics/GraphicsEngineVulkan | |
| parent | Made uniform and storage buffer descriptors dynamic in pipeline layout (diff) | |
| download | DiligentCore-2ab61c6b891467a705718361cc8c517789a1236c.tar.gz DiligentCore-2ab61c6b891467a705718361cc8c517789a1236c.zip | |
Improved setting dynamic buffer offsets
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 10 insertions, 10 deletions
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<uint32_t>& 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<uint32_t> 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<SHADER_VARIABLE_TYPE>(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<uint32_t> 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<uint32_t>& 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<uin // In each descriptor set, all uniform buffers for every shader stage come first, // followed by all storage buffers for every shader stage, followed by all other resources + Uint32 OffsetInd = 0; for(Uint32 set=0; set < m_NumSets; ++set) { const auto& DescrSet = GetDescriptorSet(set); @@ -309,7 +308,7 @@ void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector<uin const auto* pBufferVk = Res.pObject.RawPtr<const BufferVkImpl>(); auto Offset = pBufferVk->GetDynamicOffset(CtxId); - Offsets.emplace_back(Offset); + Offsets[OffsetInd++] = Offset; ++res; } @@ -323,7 +322,7 @@ void ShaderResourceCacheVk::GetDynamicBufferOffset(Uint32 CtxId, std::vector<uin const auto* pBufferVkView = Res.pObject.RawPtr<const BufferViewVkImpl>(); 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<uin } #endif } + VERIFY(OffsetInd == Offsets.size(), "Incorrect number of dynamic offsets written"); } } |
