From 47eb24bb2abc8741667ae0fc7423515c93057e37 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 20 Nov 2018 22:01:03 -0800 Subject: Added explicit control of vertex buffer, index buffer and indirect draw arguments buffer transitions to the API --- .../include/DeviceContextD3D11Impl.h | 4 +- .../src/DeviceContextD3D11Impl.cpp | 47 +++++++++++++++++----- 2 files changed, 39 insertions(+), 12 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index a858d543..661dd405 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -117,10 +117,10 @@ public: private: /// Commits d3d11 index buffer to the d3d11 device context. - void CommitD3D11IndexBuffer(VALUE_TYPE IndexType); + void CommitD3D11IndexBuffer(VALUE_TYPE IndexType, bool TransitionBuffer); /// Commits d3d11 vertex buffers to the d3d11 device context. - void CommitD3D11VertexBuffers(class PipelineStateD3D11Impl* pPipelineStateD3D11); + void CommitD3D11VertexBuffers(class PipelineStateD3D11Impl* pPipelineStateD3D11, bool TransitionBuffers); /// Helper template function used to facilitate resource unbinding template(); - if( pBuffD3D11->IsInKnownState() && pBuffD3D11->CheckState(RESOURCE_STATE_UNORDERED_ACCESS) ) + if (TransitionBuffer) { - UnbindResourceFromUAV(pBuffD3D11, pBuffD3D11->m_pd3d11Buffer); - pBuffD3D11->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + if( pBuffD3D11->IsInKnownState() && pBuffD3D11->CheckState(RESOURCE_STATE_UNORDERED_ACCESS) ) + { + UnbindResourceFromUAV(pBuffD3D11, pBuffD3D11->m_pd3d11Buffer); + pBuffD3D11->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + } + } +#ifdef DEVELOPMENT + else + { + if( pBuffD3D11->IsInKnownState() && pBuffD3D11->CheckState(RESOURCE_STATE_UNORDERED_ACCESS) ) + { + LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11->GetDesc().Name, "' used as index buffer is in RESOURCE_STATE_UNORDERED_ACCESS state." + " Use DRAW_FLAG_TRANSITION_INDEX_BUFFER flag or explicitly transition the buffer to RESOURCE_STATE_INDEX_BUFFER state."); + + } } +#endif if( m_CommittedD3D11IndexBuffer != pBuffD3D11->m_pd3d11Buffer || m_CommittedIBFormat != IndexType || @@ -693,7 +707,7 @@ namespace Diligent m_bCommittedD3D11IBUpToDate = true; } - void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pPipelineStateD3D11) + void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pPipelineStateD3D11, bool TransitionBuffers) { VERIFY( m_NumVertexStreams <= MaxBufferSlots, "Too many buffers are being set" ); UINT NumBuffersToSet = std::max(m_NumVertexStreams, m_NumCommittedD3D11VBs ); @@ -709,11 +723,24 @@ namespace Diligent auto Stride = Strides[Slot]; auto Offset = CurrStream.Offset; - if(pBuffD3D11Impl != nullptr && pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + if (TransitionBuffers) { - UnbindResourceFromUAV(pBuffD3D11Impl, pd3d11Buffer); - pBuffD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + if (pBuffD3D11Impl != nullptr && pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + { + UnbindResourceFromUAV(pBuffD3D11Impl, pd3d11Buffer); + pBuffD3D11Impl->ClearState(RESOURCE_STATE_UNORDERED_ACCESS); + } } +#ifdef DEVELOPMENT + else + { + if (pBuffD3D11Impl != nullptr && pBuffD3D11Impl->IsInKnownState() && pBuffD3D11Impl->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) + { + LOG_ERROR_MESSAGE("Buffer '", pBuffD3D11Impl->GetDesc().Name, "' used as vertex buffer at slot ", Slot, " is in RESOURCE_STATE_UNORDERED_ACCESS state. " + "Use DRAW_FLAG_TRANSITION_VERTEX_BUFFER flag or explicitly transition the buffer to RESOURCE_STATE_VERTEX_BUFFER state."); + } + } +#endif // It is safe to perform raw pointer check because device context keeps // all buffers alive. @@ -761,7 +788,7 @@ namespace Diligent if( pd3d11InputLayout != nullptr && !m_bCommittedD3D11VBsUpToDate ) { VERIFY( m_NumVertexStreams >= m_pPipelineState->GetNumBufferSlotsUsed(), "Currently bound pipeline state \"", m_pPipelineState->GetDesc().Name, "\" expects ", m_pPipelineState->GetNumBufferSlotsUsed(), " input buffer slots, but only ", m_NumVertexStreams, " is bound"); - CommitD3D11VertexBuffers(m_pPipelineState); + CommitD3D11VertexBuffers(m_pPipelineState, drawAttribs.Flags & DRAW_FLAG_TRANSITION_VERTEX_BUFFERS); } if( drawAttribs.IsIndexed ) @@ -770,7 +797,7 @@ namespace Diligent m_bCommittedD3D11IBUpToDate = false; if(!m_bCommittedD3D11IBUpToDate) { - CommitD3D11IndexBuffer(drawAttribs.IndexType); + CommitD3D11IndexBuffer(drawAttribs.IndexType, drawAttribs.Flags & DRAW_FLAG_TRANSITION_INDEX_BUFFER); } } -- cgit v1.2.3