From e8f6cc0e5f96af00a4f8c384d0b086f5a4f703d4 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 1 Jun 2018 08:33:49 -0700 Subject: Implemented indirect rendering in Vk --- .../src/DeviceContextVkImpl.cpp | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index e41db8c5..0ba8ea70 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -397,8 +397,6 @@ namespace Diligent CommitVkVertexBuffers(); #if 0 - GraphCtx.SetRootSignature( pPipelineStateVk->GetVkRootSignature() ); - if(m_pCommittedResourceCache != nullptr) { pPipelineStateVk->GetRootSignature().CommitRootViews(*m_pCommittedResourceCache, GraphCtx, false, m_ContextId); @@ -411,30 +409,36 @@ namespace Diligent } #endif #endif + if( DrawAttribs.IsIndirect ) + { + VERIFY(DrawAttribs.pIndirectDrawAttribs != nullptr, "Valid pIndirectDrawAttribs must be provided for indirect draw command"); + + auto *pBufferVk = ValidatedCast(DrawAttribs.pIndirectDrawAttribs); + + // Buffer memory barries must be executed outside of render pass + if(!pBufferVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT)) + BufferMemoryBarrier(*pBufferVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT); + } if(m_CommandBuffer.GetState().RenderPass == VK_NULL_HANDLE) CommitRenderPassAndFramebuffer(pPipelineStateVk); if( DrawAttribs.IsIndirect ) { -#if 0 if( auto *pBufferVk = ValidatedCast(DrawAttribs.pIndirectDrawAttribs) ) { -#ifdef _DEBUG - if(pBufferVk->GetDesc().Usage == USAGE_DYNAMIC) - pBufferVk->DbgVerifyDynamicAllocation(m_ContextId); -#endif +//#ifdef _DEBUG +// if(pBufferVk->GetDesc().Usage == USAGE_DYNAMIC) +// pBufferVk->DbgVerifyDynamicAllocation(m_ContextId); +//#endif + if(!pBufferVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT)) + BufferMemoryBarrier(*pBufferVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT); - GraphCtx.TransitionResource(pBufferVk, Vk_RESOURCE_STATE_INDIRECT_ARGUMENT); - size_t BuffDataStartByteOffset; - IVkResource *pVkArgsBuff = pBufferVk->GetVkBuffer(BuffDataStartByteOffset, m_ContextId); - GraphCtx.ExecuteIndirect(DrawAttribs.IsIndexed ? m_pDrawIndexedIndirectSignature : m_pDrawIndirectSignature, pVkArgsBuff, DrawAttribs.IndirectDrawArgsOffset + BuffDataStartByteOffset); - } - else - { - LOG_ERROR_MESSAGE("Valid pIndirectDrawAttribs must be provided for indirect draw command"); + if( DrawAttribs.IsIndexed ) + m_CommandBuffer.DrawIndexedIndirect(pBufferVk->GetVkBuffer(), DrawAttribs.IndirectDrawArgsOffset, 1, 0); + else + m_CommandBuffer.DrawIndirect(pBufferVk->GetVkBuffer(), DrawAttribs.IndirectDrawArgsOffset, 1, 0); } -#endif } else { -- cgit v1.2.3