summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-12-03 15:59:56 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-12-03 15:59:56 +0000
commitb055f0861083429bc2e6533332352f668b715493 (patch)
tree93b8844b51b9a1ab6d992c33c8b5ece5982c4248 /Graphics/GraphicsEngineD3D12
parentMade DeviceContextBase template class little more readable by keeping only tw... (diff)
downloadDiligentCore-b055f0861083429bc2e6533332352f668b715493.tar.gz
DiligentCore-b055f0861083429bc2e6533332352f668b715493.zip
Removed DRAW_FLAG_TRANSITION_VERTEX_BUFFERS, DRAW_FLAG_TRANSITION_INDEX_BUFFER, and DRAW_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER flags
Removed DISPATCH_FLAGS enum Added IndirectAttribsBufferStateTransitionMode member to DrawAttribs and DispatchComputeAttribs Added StateTransitionMode parameter to SetVertexBuffers and SetIndexBuffer methods
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h18
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp185
2 files changed, 72 insertions, 131 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
index 834bb54e..e5e160be 100644
--- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
@@ -73,15 +73,16 @@ public:
virtual void SetBlendFactors(const float* pBlendFactors = nullptr)override final;
- virtual void SetVertexBuffers( Uint32 StartSlot,
- Uint32 NumBuffersSet,
- IBuffer** ppBuffers,
- Uint32* pOffsets,
- SET_VERTEX_BUFFERS_FLAGS Flags )override final;
+ virtual void SetVertexBuffers( Uint32 StartSlot,
+ Uint32 NumBuffersSet,
+ IBuffer** ppBuffers,
+ Uint32* pOffsets,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode,
+ SET_VERTEX_BUFFERS_FLAGS Flags )override final;
virtual void InvalidateState()override final;
- virtual void SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset )override final;
+ virtual void SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )override final;
virtual void SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight )override final;
@@ -212,9 +213,8 @@ public:
Int64 GetCurrentFrameNumber()const {return m_ContextFrameNumber; }
private:
- void CommitD3D12IndexBuffer(VALUE_TYPE IndexType, bool TransitionBuffer, bool VerifyState);
- void CommitD3D12VertexBuffers(class GraphicsContext &GraphCtx, bool TransitionBuffers, bool VerifyStates);
- void TransitionD3D12VertexBuffers(class GraphicsContext &GraphCtx);
+ void CommitD3D12IndexBuffer(VALUE_TYPE IndexType);
+ void CommitD3D12VertexBuffers(class GraphicsContext& GraphCtx);
void CommitRenderTargets(SET_RENDER_TARGETS_FLAGS Flags);
void CommitViewports();
void CommitScissorRects(class GraphicsContext &GraphCtx, bool ScissorEnable);
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index e63049ff..afa16772 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -260,13 +260,12 @@ namespace Diligent
}
}
- void DeviceContextD3D12Impl::CommitD3D12IndexBuffer(VALUE_TYPE IndexType, bool TransitionBuffer, bool VerifyState)
+ void DeviceContextD3D12Impl::CommitD3D12IndexBuffer(VALUE_TYPE IndexType)
{
VERIFY( m_pIndexBuffer != nullptr, "Index buffer is not set up for indexed draw command" );
D3D12_INDEX_BUFFER_VIEW IBView;
- BufferD3D12Impl *pBuffD3D12 = static_cast<BufferD3D12Impl *>(m_pIndexBuffer.RawPtr());
- IBView.BufferLocation = pBuffD3D12->GetGPUAddress(this) + m_IndexDataStartOffset;
+ IBView.BufferLocation = m_pIndexBuffer->GetGPUAddress(this) + m_IndexDataStartOffset;
if( IndexType == VT_UINT32 )
IBView.Format = DXGI_FORMAT_R32_UINT;
else
@@ -275,7 +274,7 @@ namespace Diligent
IBView.Format = DXGI_FORMAT_R16_UINT;
}
// Note that for a dynamic buffer, what we use here is the size of the buffer itself, not the upload heap buffer!
- IBView.SizeInBytes = pBuffD3D12->GetDesc().uiSizeInBytes - m_IndexDataStartOffset;
+ IBView.SizeInBytes = m_pIndexBuffer->GetDesc().uiSizeInBytes - m_IndexDataStartOffset;
// Device context keeps strong reference to bound index buffer.
// When the buffer is unbound, the reference to the D3D12 resource
@@ -284,36 +283,24 @@ namespace Diligent
//auto *pd3d12Resource = pBuffD3D12->GetD3D12Buffer();
//GraphicsCtx.AddReferencedObject(pd3d12Resource);
- bool IsDynamic = pBuffD3D12->GetDesc().Usage == USAGE_DYNAMIC;
+ bool IsDynamic = m_pIndexBuffer->GetDesc().Usage == USAGE_DYNAMIC;
#ifdef DEVELOPMENT
if(IsDynamic)
- pBuffD3D12->DvpVerifyDynamicAllocation(this);
+ m_pIndexBuffer->DvpVerifyDynamicAllocation(this);
#endif
- auto& GraphicsCtx = GetCmdContext().AsGraphicsContext();
-
- if (TransitionBuffer)
- {
- if (pBuffD3D12->IsInKnownState() && !pBuffD3D12->CheckState(RESOURCE_STATE_INDEX_BUFFER))
- GraphicsCtx.TransitionResource(pBuffD3D12, RESOURCE_STATE_INDEX_BUFFER);
- }
-#ifdef DEVELOPMENT
- else if(VerifyState)
- {
- DvpVerifyBufferState(*pBuffD3D12, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw (DeviceContextD3D12Impl::CommitD3D12IndexBuffer())");
- }
-#endif
-
+
size_t BuffDataStartByteOffset;
- auto *pd3d12Buff = pBuffD3D12->GetD3D12Buffer(BuffDataStartByteOffset, this);
+ auto *pd3d12Buff = m_pIndexBuffer->GetD3D12Buffer(BuffDataStartByteOffset, this);
if( IsDynamic ||
m_State.CommittedD3D12IndexBuffer != pd3d12Buff ||
m_State.CommittedIBFormat != IndexType ||
m_State.CommittedD3D12IndexDataStartOffset != m_IndexDataStartOffset + BuffDataStartByteOffset)
{
- m_State.CommittedD3D12IndexBuffer = pd3d12Buff;
- m_State.CommittedIBFormat = IndexType;
+ m_State.CommittedD3D12IndexBuffer = pd3d12Buff;
+ m_State.CommittedIBFormat = IndexType;
m_State.CommittedD3D12IndexDataStartOffset = m_IndexDataStartOffset + static_cast<Uint32>(BuffDataStartByteOffset);
+ auto& GraphicsCtx = GetCmdContext().AsGraphicsContext();
GraphicsCtx.SetIndexBuffer( IBView );
}
@@ -322,18 +309,7 @@ namespace Diligent
m_State.bCommittedD3D12IBUpToDate = !IsDynamic;
}
- void DeviceContextD3D12Impl::TransitionD3D12VertexBuffers(GraphicsContext& GraphCtx)
- {
- for( Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff )
- {
- auto& CurrStream = m_VertexStreams[Buff];
- auto* pBufferD3D12 = CurrStream.pBuffer.RawPtr();
- if (pBufferD3D12 != nullptr && pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_VERTEX_BUFFER))
- GraphCtx.TransitionResource(pBufferD3D12, RESOURCE_STATE_VERTEX_BUFFER);
- }
- }
-
- void DeviceContextD3D12Impl::CommitD3D12VertexBuffers(GraphicsContext& GraphCtx, bool TransitionBuffers, bool VerifyStates)
+ void DeviceContextD3D12Impl::CommitD3D12VertexBuffers(GraphicsContext& GraphCtx)
{
// Do not initialize array with zeroes for performance reasons
D3D12_VERTEX_BUFFER_VIEW VBViews[MaxBufferSlots];// = {}
@@ -355,18 +331,6 @@ namespace Diligent
#endif
}
- if (TransitionBuffers)
- {
- if (pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_VERTEX_BUFFER))
- GraphCtx.TransitionResource(pBufferD3D12, RESOURCE_STATE_VERTEX_BUFFER);
- }
-#ifdef DEVELOPMENT
- else if (VerifyStates)
- {
- DvpVerifyBufferState(*pBufferD3D12, RESOURCE_STATE_VERTEX_BUFFER, "Using vertex buffers (DeviceContextD3D12Impl::CommitD3D12VertexBuffers())");
- }
-#endif
-
// Device context keeps strong references to all vertex buffers.
// When a buffer is unbound, a reference to D3D12 resource is added to the context,
// so there is no need to reference the resource here
@@ -404,56 +368,37 @@ namespace Diligent
{
if (m_State.CommittedIBFormat != drawAttribs.IndexType)
m_State.bCommittedD3D12IBUpToDate = false;
-
- const bool TransitionIndexBuffer = (drawAttribs.Flags & DRAW_FLAG_TRANSITION_INDEX_BUFFER) != 0;
- if (m_State.bCommittedD3D12IBUpToDate)
+ if (!m_State.bCommittedD3D12IBUpToDate)
{
- BufferD3D12Impl *pBuffD3D12 = static_cast<BufferD3D12Impl *>(m_pIndexBuffer.RawPtr());
- if (TransitionIndexBuffer)
- {
- if (pBuffD3D12->IsInKnownState() && !pBuffD3D12->CheckState(RESOURCE_STATE_INDEX_BUFFER))
- GraphCtx.TransitionResource(pBuffD3D12, RESOURCE_STATE_INDEX_BUFFER);
- }
-#ifdef DEVELOPMENT
- else if (VerifyStates)
- {
- DvpVerifyBufferState(*pBuffD3D12, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw (DeviceContextD3D12Impl::Draw())");
- }
-#endif
+ CommitD3D12IndexBuffer(drawAttribs.IndexType);
}
- else
+#ifdef DEVELOPMENT
+ if (VerifyStates)
{
- CommitD3D12IndexBuffer(drawAttribs.IndexType, TransitionIndexBuffer, VerifyStates);
+ DvpVerifyBufferState(*m_pIndexBuffer, RESOURCE_STATE_INDEX_BUFFER, "Indexed draw (DeviceContextD3D12Impl::Draw())");
}
+#endif
}
- const bool TransitionVertexBuffers = (drawAttribs.Flags & DRAW_FLAG_TRANSITION_VERTEX_BUFFERS) != 0;
- if (m_State.bCommittedD3D12VBsUpToDate)
+ if (!m_State.bCommittedD3D12VBsUpToDate)
{
- if (TransitionVertexBuffers)
- {
- TransitionD3D12VertexBuffers(GraphCtx);
- }
+ CommitD3D12VertexBuffers(GraphCtx);
+ }
+
#ifdef DEVELOPMENT
- else if (VerifyStates)
+ if (VerifyStates)
+ {
+ for( Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff )
{
- for( Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff )
+ const auto& CurrStream = m_VertexStreams[Buff];
+ const auto* pBufferD3D12 = CurrStream.pBuffer.RawPtr();
+ if (pBufferD3D12 != nullptr)
{
- const auto& CurrStream = m_VertexStreams[Buff];
- const auto* pBufferD3D12 = CurrStream.pBuffer.RawPtr();
- if (pBufferD3D12 != nullptr)
- {
- DvpVerifyBufferState(*pBufferD3D12, RESOURCE_STATE_VERTEX_BUFFER, "Using vertex buffers (DeviceContextD3D12Impl::Draw())");
- }
+ DvpVerifyBufferState(*pBufferD3D12, RESOURCE_STATE_VERTEX_BUFFER, "Using vertex buffers (DeviceContextD3D12Impl::Draw())");
}
}
-#endif
}
- else
- {
- CommitD3D12VertexBuffers(GraphCtx, TransitionVertexBuffers, VerifyStates);
- }
-
+#endif
GraphCtx.SetRootSignature( m_pPipelineState->GetD3D12RootSignature() );
if (m_State.pCommittedResourceCache != nullptr)
@@ -477,17 +422,8 @@ namespace Diligent
pIndirectDrawAttribsD3D12->DvpVerifyDynamicAllocation(this);
#endif
- if (drawAttribs.Flags & DRAW_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER)
- {
- if (pIndirectDrawAttribsD3D12->IsInKnownState() && !pIndirectDrawAttribsD3D12->CheckState(RESOURCE_STATE_INDIRECT_ARGUMENT))
- GraphCtx.TransitionResource(pIndirectDrawAttribsD3D12, RESOURCE_STATE_INDIRECT_ARGUMENT);
- }
-#ifdef DEVELOPMENT
- else if (VerifyStates)
- {
- DvpVerifyBufferState(*pIndirectDrawAttribsD3D12, RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect draw (DeviceContextD3D12Impl::Draw)");
- }
-#endif
+ TransitionOrVerifyBufferState(GraphCtx, *pIndirectDrawAttribsD3D12, drawAttribs.IndirectAttribsBufferStateTransitionMode,
+ RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect draw (DeviceContextD3D12Impl::Draw)");
size_t BuffDataStartByteOffset;
ID3D12Resource *pd3d12ArgsBuff = pIndirectDrawAttribsD3D12->GetD3D12Buffer(BuffDataStartByteOffset, this);
@@ -527,33 +463,19 @@ namespace Diligent
if( DispatchAttrs.pIndirectDispatchAttribs )
{
- if( auto *pBufferD3D12 = ValidatedCast<BufferD3D12Impl>(DispatchAttrs.pIndirectDispatchAttribs) )
- {
-#ifdef DEVELOPMENT
- if(pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC)
- pBufferD3D12->DvpVerifyDynamicAllocation(this);
-#endif
+ auto* pBufferD3D12 = ValidatedCast<BufferD3D12Impl>(DispatchAttrs.pIndirectDispatchAttribs);
- if (DispatchAttrs.Flags & DISPATCH_FLAG_TRANSITION_INDIRECT_ARGS_BUFFER)
- {
- if (pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_INDIRECT_ARGUMENT))
- ComputeCtx.TransitionResource(pBufferD3D12, RESOURCE_STATE_INDIRECT_ARGUMENT);
- }
#ifdef DEVELOPMENT
- else if (DispatchAttrs.Flags & DISPATCH_FLAG_VERIFY_STATES)
- {
- DvpVerifyBufferState(*pBufferD3D12, RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect dispatch (DeviceContextD3D12Impl::DispatchCompute)");
- }
+ if(pBufferD3D12->GetDesc().Usage == USAGE_DYNAMIC)
+ pBufferD3D12->DvpVerifyDynamicAllocation(this);
#endif
- size_t BuffDataStartByteOffset;
- ID3D12Resource *pd3d12ArgsBuff = pBufferD3D12->GetD3D12Buffer(BuffDataStartByteOffset, this);
- ComputeCtx.ExecuteIndirect(m_pDispatchIndirectSignature, pd3d12ArgsBuff, DispatchAttrs.DispatchArgsByteOffset + BuffDataStartByteOffset);
- }
- else
- {
- LOG_ERROR_MESSAGE("Valid pIndirectDrawAttribs must be provided for indirect dispatch command");
- }
+ TransitionOrVerifyBufferState(ComputeCtx, *pBufferD3D12, DispatchAttrs.IndirectAttribsBufferStateTransitionMode,
+ RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect dispatch (DeviceContextD3D12Impl::DispatchCompute)");
+
+ size_t BuffDataStartByteOffset;
+ ID3D12Resource *pd3d12ArgsBuff = pBufferD3D12->GetD3D12Buffer(BuffDataStartByteOffset, this);
+ ComputeCtx.ExecuteIndirect(m_pDispatchIndirectSignature, pd3d12ArgsBuff, DispatchAttrs.DispatchArgsByteOffset + BuffDataStartByteOffset);
}
else
ComputeCtx.Dispatch(DispatchAttrs.ThreadGroupCountX, DispatchAttrs.ThreadGroupCountY, DispatchAttrs.ThreadGroupCountZ);
@@ -715,9 +637,23 @@ namespace Diligent
EndFrame(*m_pDevice.RawPtr<RenderDeviceD3D12Impl>());
}
- void DeviceContextD3D12Impl::SetVertexBuffers( Uint32 StartSlot, Uint32 NumBuffersSet, IBuffer** ppBuffers, Uint32* pOffsets, SET_VERTEX_BUFFERS_FLAGS Flags )
+ void DeviceContextD3D12Impl::SetVertexBuffers( Uint32 StartSlot,
+ Uint32 NumBuffersSet,
+ IBuffer** ppBuffers,
+ Uint32* pOffsets,
+ RESOURCE_STATE_TRANSITION_MODE StateTransitionMode,
+ SET_VERTEX_BUFFERS_FLAGS Flags )
{
- TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pOffsets, Flags );
+ TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pOffsets, StateTransitionMode, Flags );
+
+ auto& CmdCtx = GetCmdContext();
+ for( Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff )
+ {
+ auto& CurrStream = m_VertexStreams[Buff];
+ if (auto* pBufferD3D12 = CurrStream.pBuffer.RawPtr())
+ TransitionOrVerifyBufferState(CmdCtx, *pBufferD3D12, StateTransitionMode, RESOURCE_STATE_VERTEX_BUFFER, "Setting vertex buffers (DeviceContextD3D12Impl::SetVertexBuffers)");
+ }
+
m_State.bCommittedD3D12VBsUpToDate = false;
}
@@ -730,9 +666,14 @@ namespace Diligent
m_State = State{};
}
- void DeviceContextD3D12Impl::SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset )
+ void DeviceContextD3D12Impl::SetIndexBuffer( IBuffer* pIndexBuffer, Uint32 ByteOffset, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode )
{
- TDeviceContextBase::SetIndexBuffer( pIndexBuffer, ByteOffset );
+ TDeviceContextBase::SetIndexBuffer( pIndexBuffer, ByteOffset, StateTransitionMode );
+ if (m_pIndexBuffer)
+ {
+ auto& CmdCtx = GetCmdContext();
+ TransitionOrVerifyBufferState(CmdCtx, *m_pIndexBuffer, StateTransitionMode, RESOURCE_STATE_INDEX_BUFFER, "Setting index buffer (DeviceContextD3D12Impl::SetIndexBuffer)");
+ }
m_State.bCommittedD3D12IBUpToDate = false;
}