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/DeviceContextD3D12Impl.cpp | 22 ++++++------- .../src/DeviceContextVkImpl.cpp | 36 ++++++++++++---------- 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 7db39b9e..275ab744 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -355,22 +355,18 @@ namespace Diligent if( DrawAttribs.IsIndirect ) { - if( auto *pBufferD3D12 = ValidatedCast(DrawAttribs.pIndirectDrawAttribs) ) - { + VERIFY(DrawAttribs.pIndirectDrawAttribs != nullptr, "Valid pIndirectDrawAttribs must be provided for indirect draw command"); + auto *pBufferD3D12 = ValidatedCast(DrawAttribs.pIndirectDrawAttribs); + #ifdef _DEBUG - if(pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC) - pBufferD3D12->DbgVerifyDynamicAllocation(m_ContextId); + if(pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC) + pBufferD3D12->DbgVerifyDynamicAllocation(m_ContextId); #endif - GraphCtx.TransitionResource(pBufferD3D12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); - size_t BuffDataStartByteOffset; - ID3D12Resource *pd3d12ArgsBuff = pBufferD3D12->GetD3D12Buffer(BuffDataStartByteOffset, m_ContextId); - GraphCtx.ExecuteIndirect(DrawAttribs.IsIndexed ? m_pDrawIndexedIndirectSignature : m_pDrawIndirectSignature, pd3d12ArgsBuff, DrawAttribs.IndirectDrawArgsOffset + BuffDataStartByteOffset); - } - else - { - LOG_ERROR_MESSAGE("Valid pIndirectDrawAttribs must be provided for indirect draw command"); - } + GraphCtx.TransitionResource(pBufferD3D12, D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT); + size_t BuffDataStartByteOffset; + ID3D12Resource *pd3d12ArgsBuff = pBufferD3D12->GetD3D12Buffer(BuffDataStartByteOffset, m_ContextId); + GraphCtx.ExecuteIndirect(DrawAttribs.IsIndexed ? m_pDrawIndexedIndirectSignature : m_pDrawIndirectSignature, pd3d12ArgsBuff, DrawAttribs.IndirectDrawArgsOffset + BuffDataStartByteOffset); } else { 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