summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-12-01 04:20:46 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-12-01 04:20:46 +0000
commit1303ae5da64c35a56768edecdf60d57f7a2fe628 (patch)
treeb240850db3f521a636bdd71435a9aafda99a89c5 /Graphics/GraphicsEngineD3D12
parentImproved type safety of different flag types (diff)
downloadDiligentCore-1303ae5da64c35a56768edecdf60d57f7a2fe628.tar.gz
DiligentCore-1303ae5da64c35a56768edecdf60d57f7a2fe628.zip
Added explicit state transition flags to SetRenderTargets method
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/CommandContext.h2
-rw-r--r--Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h47
-rw-r--r--Graphics/GraphicsEngineD3D12/src/CommandContext.cpp40
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp10
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp2
6 files changed, 72 insertions, 31 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h
index 46dbc9fe..9de975df 100644
--- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h
+++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h
@@ -185,7 +185,7 @@ public:
}
}
- void SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV );
+ void SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV, SET_RENDER_TARGETS_FLAGS Flags );
void SetViewports( UINT NumVPs, const D3D12_VIEWPORT* pVPs )
{
diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
index 142ca7cb..7eaebfcd 100644
--- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
+++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h
@@ -56,47 +56,58 @@ public:
virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
- virtual void SetPipelineState(IPipelineState *pPipelineState)override final;
+ virtual void SetPipelineState(IPipelineState* pPipelineState)override final;
- virtual void TransitionShaderResources(IPipelineState *pPipelineState, IShaderResourceBinding *pShaderResourceBinding)override final;
+ virtual void TransitionShaderResources(IPipelineState* pPipelineState, IShaderResourceBinding* pShaderResourceBinding)override final;
- virtual void CommitShaderResources(IShaderResourceBinding *pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags)override final;
+ virtual void CommitShaderResources(IShaderResourceBinding* pShaderResourceBinding, COMMIT_SHADER_RESOURCES_FLAGS Flags)override final;
virtual void SetStencilRef(Uint32 StencilRef)override final;
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,
+ 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 )override final;
- virtual void SetViewports( Uint32 NumViewports, const Viewport *pViewports, Uint32 RTWidth, Uint32 RTHeight )override final;
+ virtual void SetViewports( Uint32 NumViewports, const Viewport* pViewports, Uint32 RTWidth, Uint32 RTHeight )override final;
- virtual void SetScissorRects( Uint32 NumRects, const Rect *pRects, Uint32 RTWidth, Uint32 RTHeight )override final;
+ virtual void SetScissorRects( Uint32 NumRects, const Rect* pRects, Uint32 RTWidth, Uint32 RTHeight )override final;
- virtual void SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil )override final;
+ virtual void SetRenderTargets( Uint32 NumRenderTargets,
+ ITextureView* ppRenderTargets[],
+ ITextureView* pDepthStencil,
+ SET_RENDER_TARGETS_FLAGS Flags )override final;
- virtual void Draw( DrawAttribs &DrawAttribs )override final;
+ virtual void Draw( DrawAttribs& DrawAttribs )override final;
- virtual void DispatchCompute( const DispatchComputeAttribs &DispatchAttrs )override final;
+ virtual void DispatchCompute( const DispatchComputeAttribs& DispatchAttrs )override final;
- virtual void ClearDepthStencil( ITextureView *pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final;
+ virtual void ClearDepthStencil( ITextureView* pView, CLEAR_DEPTH_STENCIL_FLAGS ClearFlags, float fDepth, Uint8 Stencil)override final;
- virtual void ClearRenderTarget( ITextureView *pView, const float *RGBA )override final;
+ virtual void ClearRenderTarget( ITextureView* pView, const float* RGBA )override final;
virtual void Flush()override final;
- virtual void UpdateBuffer(IBuffer *pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final;
+ virtual void UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const PVoid pData)override final;
- virtual void CopyBuffer(IBuffer *pSrcBuffer, Uint32 SrcOffset, IBuffer *pDstBuffer, Uint32 DstOffset, Uint32 Size)override final;
+ virtual void CopyBuffer(IBuffer* pSrcBuffer, Uint32 SrcOffset, IBuffer* pDstBuffer, Uint32 DstOffset, Uint32 Size)override final;
virtual void MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_FLAGS MapFlags, PVoid& pMappedData)override final;
virtual void UnmapBuffer(IBuffer* pBuffer)override final;
- virtual void UpdateTexture(ITexture* pTexture, Uint32 MipLevel, Uint32 Slice, const Box& DstBox, const TextureSubResData& SubresData)override final;
+ virtual void UpdateTexture(ITexture* pTexture,
+ Uint32 MipLevel,
+ Uint32 Slice,
+ const Box& DstBox,
+ const TextureSubResData& SubresData)override final;
virtual void CopyTexture(ITexture* pSrcTexture,
Uint32 SrcMipLevel,
@@ -123,9 +134,9 @@ public:
virtual void TransitionResourceStates(Uint32 BarrierCount, StateTransitionDesc* pResourceBarriers)override final;
- virtual void FinishCommandList(class ICommandList **ppCommandList)override final;
+ virtual void FinishCommandList(class ICommandList** ppCommandList)override final;
- virtual void ExecuteCommandList(class ICommandList *pCommandList)override final;
+ virtual void ExecuteCommandList(class ICommandList* pCommandList)override final;
virtual void SignalFence(IFence* pFence, Uint64 Value)override final;
@@ -176,7 +187,7 @@ 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 CommitRenderTargets();
+ void CommitRenderTargets(SET_RENDER_TARGETS_FLAGS Flags);
void CommitViewports();
void CommitScissorRects(class GraphicsContext &GraphCtx, bool ScissorEnable);
void Flush(bool RequestNewCmdCtx);
diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
index 8d6d5d9c..a08fe172 100644
--- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp
@@ -91,7 +91,7 @@ ID3D12GraphicsCommandList* CommandContext::Close(CComPtr<ID3D12CommandAllocator>
return m_pCommandList;
}
-void GraphicsContext::SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV )
+void GraphicsContext::SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs, ITextureViewD3D12* pDSV, SET_RENDER_TARGETS_FLAGS Flags )
{
D3D12_CPU_DESCRIPTOR_HANDLE RTVHandles[8]; // Do not waste time initializing array to zero
@@ -101,8 +101,23 @@ void GraphicsContext::SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs
if( pRTV )
{
auto* pTexture = ValidatedCast<TextureD3D12Impl>( pRTV->GetTexture() );
- if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET))
- TransitionResource(pTexture, RESOURCE_STATE_RENDER_TARGET);
+ if (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR)
+ {
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET))
+ TransitionResource(pTexture, RESOURCE_STATE_RENDER_TARGET);
+ }
+#ifdef DEVELOPMENT
+ else if (Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
+ {
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_RENDER_TARGET))
+ {
+ LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' being set as render target at slot ", i, " is not transitioned to RESOURCE_STATE_RENDER_TARGET state. "
+ "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". "
+ "Use SET_RENDER_TARGETS_FLAG_TRANSITION_COLOR flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
+ }
+ }
+#endif
+
RTVHandles[i] = pRTV->GetCPUDescriptorHandle();
VERIFY_EXPR(RTVHandles[i].ptr != 0);
}
@@ -118,8 +133,23 @@ void GraphicsContext::SetRenderTargets( UINT NumRTVs, ITextureViewD3D12** ppRTVs
//}
//else
{
- if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE))
- TransitionResource(pTexture, RESOURCE_STATE_DEPTH_WRITE);
+ if (Flags & SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH)
+ {
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE))
+ TransitionResource(pTexture, RESOURCE_STATE_DEPTH_WRITE);
+ }
+#ifdef DEVELOPMENT
+ else if (Flags & SET_RENDER_TARGETS_FLAG_VERIFY_STATES)
+ {
+ if (pTexture->IsInKnownState() && !pTexture->CheckState(RESOURCE_STATE_DEPTH_WRITE))
+ {
+ LOG_ERROR_MESSAGE("Texture '", pTexture->GetDesc().Name, "' being set as depth-stencil buffer is not transitioned to RESOURCE_STATE_DEPTH_WRITE state. "
+ "Actual texture state: ", GetResourceStateString(pTexture->GetState()), ". "
+ "Use SET_RENDER_TARGETS_FLAG_TRANSITION_DEPTH flag or explicitly transition the resource using IDeviceContext::TransitionResourceStates() method.");
+ }
+
+ }
+#endif
auto DSVHandle = pDSV->GetCPUDescriptorHandle();
VERIFY_EXPR(DSVHandle.ptr != 0);
m_pCommandList->OMSetRenderTargets( NumRTVs, RTVHandles, FALSE, &DSVHandle );
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index f37691ac..01bc7e7a 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -211,7 +211,7 @@ namespace Diligent
{
GraphicsCtx.SetStencilRef(m_StencilRef);
GraphicsCtx.SetBlendFactor(m_BlendFactors);
- CommitRenderTargets();
+ CommitRenderTargets(SET_RENDER_TARGETS_FLAG_VERIFY_STATES);
CommitViewports();
}
@@ -846,7 +846,7 @@ namespace Diligent
}
- void DeviceContextD3D12Impl::CommitRenderTargets()
+ void DeviceContextD3D12Impl::CommitRenderTargets(SET_RENDER_TARGETS_FLAGS Flags)
{
const Uint32 MaxD3D12RTs = D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
Uint32 NumRenderTargets = m_NumBoundRenderTargets;
@@ -876,14 +876,14 @@ namespace Diligent
ppRTVs[rt] = m_pBoundRenderTargets[rt].RawPtr<ITextureViewD3D12>();
pDSV = m_pBoundDepthStencil.RawPtr<ITextureViewD3D12>();
}
- GetCmdContext().AsGraphicsContext().SetRenderTargets(NumRenderTargets, ppRTVs, pDSV);
+ GetCmdContext().AsGraphicsContext().SetRenderTargets(NumRenderTargets, ppRTVs, pDSV, Flags);
}
- void DeviceContextD3D12Impl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil )
+ void DeviceContextD3D12Impl::SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, SET_RENDER_TARGETS_FLAGS Flags )
{
if( TDeviceContextBase::SetRenderTargets( NumRenderTargets, ppRenderTargets, pDepthStencil ) )
{
- CommitRenderTargets();
+ CommitRenderTargets(Flags);
// Set the viewport to match the render target size
SetViewports(1, nullptr, 0, 0);
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
index c79679fc..88681445 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp
@@ -381,7 +381,7 @@ void EngineFactoryD3D12Impl::CreateSwapChainD3D12( IRenderDevice* pDe
pDeviceContextD3D12->SetSwapChain(pSwapChainD3D12);
// Bind default render target
- pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr );
+ pDeviceContextD3D12->SetRenderTargets( 0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL );
// Set default viewport
pDeviceContextD3D12->SetViewports( 1, nullptr, 0, 0 );
diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
index 610b560d..18ef3043 100644
--- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
@@ -199,7 +199,7 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew)
if (bIsDefaultFBBound)
{
// Set default render target and viewport
- pDeviceContext->SetRenderTargets(0, nullptr, nullptr);
+ pDeviceContext->SetRenderTargets(0, nullptr, nullptr, SET_RENDER_TARGETS_FLAG_TRANSITION_ALL);
pDeviceContext->SetViewports(1, nullptr, 0, 0);
}
}