diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-04-07 19:12:18 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-04-07 19:12:18 +0000 |
| commit | bb5f09fa8caa3a6314da5fa5cb743e35778ed7f6 (patch) | |
| tree | 66c666bf5ba50725595cd93fb1ce6579dc4c97ef /Graphics | |
| parent | Fixed minor issue in readme (diff) | |
| download | DiligentCore-bb5f09fa8caa3a6314da5fa5cb743e35778ed7f6.tar.gz DiligentCore-bb5f09fa8caa3a6314da5fa5cb743e35778ed7f6.zip | |
Added DRAW_FLAG_VERIFY_DRAW_ATTRIBS, DRAW_FLAG_VERIFY_RENDER_TARGETS, and DRAW_FLAG_VERIFY_ALL flags (updated API Version to 240022)
Diffstat (limited to 'Graphics')
10 files changed, 113 insertions, 83 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index b7287825..a742c912 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -194,12 +194,14 @@ protected: #ifdef DEVELOPMENT bool DvpVerifyDrawArguments(const DrawAttribs& drawAttribs); + void DvpVerifyRenderTargets(); bool DvpVerifyDispatchArguments(const DispatchComputeAttribs &DispatchAttrs); void DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier); bool DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName); bool DvpVerifyBufferState (const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName); #else # define DvpVerifyDrawArguments (...)[](){return true;}() +# define DvpVerifyRenderTargets (...)[](){return true;}() # define DvpVerifyDispatchArguments (...)[](){return true;}() # define DvpVerifyStateTransitionDesc(...)do{}while(false) # define DvpVerifyTextureState (...)[](){return true;}() @@ -870,13 +872,13 @@ inline bool DeviceContextBase<BaseInterface,ImplementationTraits> :: { if (!m_pPipelineState) { - LOG_ERROR("No pipeline state is bound for a draw command"); + LOG_ERROR_MESSAGE("No pipeline state is bound for a draw command"); return false; } if (m_pPipelineState->GetDesc().IsComputePipeline) { - LOG_ERROR("Pipeline state bound for a draw command is a compute pipeline"); + LOG_ERROR_MESSAGE("Pipeline state bound for a draw command is a compute pipeline"); return false; } @@ -887,20 +889,20 @@ inline bool DeviceContextBase<BaseInterface,ImplementationTraits> :: if (drawAttribs.NumInstances == 0) { - LOG_ERROR("Number of instances cannot be 0. Use 1 for a non-instanced draw command."); + LOG_ERROR_MESSAGE("Number of instances cannot be 0. Use 1 for a non-instanced draw command."); return false; } } if (drawAttribs.IsIndexed && drawAttribs.IndexType != VT_UINT16 && drawAttribs.IndexType != VT_UINT32) { - LOG_ERROR("For an indexed draw command IndexType must be VT_UINT16 or VT_UINT32"); + LOG_ERROR_MESSAGE("For an indexed draw command IndexType must be VT_UINT16 or VT_UINT32"); return false; } if (drawAttribs.IsIndexed && !m_pIndexBuffer) { - LOG_ERROR("No index buffer is bound for indexed draw command"); + LOG_ERROR_MESSAGE("No index buffer is bound for indexed draw command"); return false; } @@ -908,6 +910,71 @@ inline bool DeviceContextBase<BaseInterface,ImplementationTraits> :: } template<typename BaseInterface, typename ImplementationTraits> +inline void DeviceContextBase<BaseInterface,ImplementationTraits> :: DvpVerifyRenderTargets() +{ + if (!m_pPipelineState) + { + LOG_ERROR("No pipeline state is bound"); + return; + } + + TEXTURE_FORMAT BoundRTVFormats[8] = {TEX_FORMAT_UNKNOWN}; + TEXTURE_FORMAT BoundDSVFormat = TEX_FORMAT_UNKNOWN; + Uint32 NumBoundRTVs = 0; + if (m_IsDefaultFramebufferBound) + { + if (m_pSwapChain) + { + BoundRTVFormats[0] = m_pSwapChain->GetDesc().ColorBufferFormat; + BoundDSVFormat = m_pSwapChain->GetDesc().DepthBufferFormat; + NumBoundRTVs = 1; + } + else + { + LOG_WARNING_MESSAGE("Failed to get bound render targets and depth-stencil buffer: swap chain is not initialized in the device context"); + return; + } + } + else + { + NumBoundRTVs = m_NumBoundRenderTargets; + for (Uint32 rt = 0; rt < NumBoundRTVs; ++rt) + { + if (auto* pRT = m_pBoundRenderTargets[rt].RawPtr()) + BoundRTVFormats[rt] = pRT->GetDesc().Format; + else + BoundRTVFormats[rt] = TEX_FORMAT_UNKNOWN; + } + + BoundDSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN; + } + + const auto& PSODesc = m_pPipelineState->GetDesc(); + const auto& GraphicsPipeline = PSODesc.GraphicsPipeline; + if (GraphicsPipeline.NumRenderTargets != NumBoundRTVs) + { + LOG_WARNING_MESSAGE("Number of currently bound render targets (", NumBoundRTVs, ") does not match the number of outputs specified by the PSO '", PSODesc.Name, "' (", Uint32{GraphicsPipeline.NumRenderTargets}, ")." ); + } + + if (BoundDSVFormat != GraphicsPipeline.DSVFormat) + { + LOG_WARNING_MESSAGE("Currently bound depth-stencil buffer format (", GetTextureFormatAttribs(BoundDSVFormat).Name, ") does not match the DSV format specified by the PSO '", PSODesc.Name, "' (", GetTextureFormatAttribs(GraphicsPipeline.DSVFormat).Name, ")." ); + } + + for (Uint32 rt = 0; rt < NumBoundRTVs; ++rt) + { + auto BoundFmt = BoundRTVFormats[rt]; + auto PSOFmt = GraphicsPipeline.RTVFormats[rt]; + if (BoundFmt != PSOFmt) + { + LOG_WARNING_MESSAGE("Render target bound to slot ", rt, " (", GetTextureFormatAttribs(BoundFmt).Name, ") does not match the RTV format specified by the PSO '", PSODesc.Name, "' (", GetTextureFormatAttribs(PSOFmt).Name, ")." ); + } + } +} + + + +template<typename BaseInterface, typename ImplementationTraits> inline bool DeviceContextBase<BaseInterface,ImplementationTraits> :: DvpVerifyDispatchArguments(const DispatchComputeAttribs& DispatchAttrs) { diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index e4db0bf3..bca337e7 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -26,7 +26,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240021 +#define DILIGENT_API_VERSION 240022 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index fef82b41..7f74ca55 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -61,7 +61,16 @@ enum DRAW_FLAGS : Uint8 /// Verify the sate of index and vertex buffers (if any) used by the draw /// command. State validation is only performed in debug and development builds /// and the flag has no effect in release build. - DRAW_FLAG_VERIFY_STATES = 0x01 + DRAW_FLAG_VERIFY_STATES = 0x01, + + /// Verify correctness of parameters passed to the draw command. + DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 0x02, + + /// Verify that render targets bound to the context are consistent with the pipeline state. + DRAW_FLAG_VERIFY_RENDER_TARGETS = 0x04, + + /// Perform all state validation checks + DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS }; DEFINE_FLAG_ENUM_OPERATORS(DRAW_FLAGS) diff --git a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h index 01a54eeb..bc5c87a6 100755 --- a/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.h @@ -297,8 +297,6 @@ private: FixedBlockMemoryAllocator m_CmdListAllocator;
#ifdef VERIFY_CONTEXT_BINDINGS
- /// Verifies that bound render target formats are consistent with the PSO
- void dbgVerifyRenderTargetFormats();
/// Helper template function used to facilitate context verification
template<UINT MaxResources, typename TD3D11ResourceType, typename TGetD3D11ResourcesType>
diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index df4a59c3..d5f074c5 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -733,10 +733,14 @@ namespace Diligent void DeviceContextD3D11Impl::Draw( DrawAttribs &drawAttribs )
{
#ifdef DEVELOPMENT
- if (!DvpVerifyDrawArguments(drawAttribs))
+ if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) != 0 && !DvpVerifyDrawArguments(drawAttribs))
return;
+
+ if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
+ DvpVerifyRenderTargets();
#endif
- const bool VerifyStates = drawAttribs.Flags & DRAW_FLAG_VERIFY_STATES;
+
+ const bool VerifyStates = (drawAttribs.Flags & DRAW_FLAG_VERIFY_STATES) != 0;
auto* pd3d11InputLayout = m_pPipelineState->GetD3D11InputLayout();
if (pd3d11InputLayout != nullptr && !m_bCommittedD3D11VBsUpToDate)
{
@@ -786,7 +790,6 @@ namespace Diligent if(m_DebugFlags & (Uint32)EngineD3D11DebugFlags::VerifyCommittedResourceRelevance)
{
// Verify bindings after all resources are set
- dbgVerifyRenderTargetFormats();
dbgVerifyCommittedSRVs();
dbgVerifyCommittedUAVs(SHADER_TYPE_COMPUTE);
dbgVerifyCommittedSamplers();
@@ -1969,68 +1972,6 @@ namespace Diligent }
#ifdef VERIFY_CONTEXT_BINDINGS
- void DeviceContextD3D11Impl::dbgVerifyRenderTargetFormats()
- {
- if (!m_pPipelineState)
- {
- LOG_ERROR("No pipeline state is bound");
- return;
- }
-
- TEXTURE_FORMAT BoundRTVFormats[8] = {TEX_FORMAT_UNKNOWN};
- TEXTURE_FORMAT BoundDSVFormat = TEX_FORMAT_UNKNOWN;
- Uint32 NumBoundRTVs = 0;
- if (m_IsDefaultFramebufferBound)
- {
- if (m_pSwapChain)
- {
- BoundRTVFormats[0] = m_pSwapChain->GetDesc().ColorBufferFormat;
- BoundDSVFormat = m_pSwapChain->GetDesc().DepthBufferFormat;
- NumBoundRTVs = 1;
- }
- else
- {
- LOG_WARNING_MESSAGE("Failed to get bound render targets and depth-stencil buffer: swap chain is not initialized in the device context");
- return;
- }
- }
- else
- {
- NumBoundRTVs = m_NumBoundRenderTargets;
- for (Uint32 rt = 0; rt < NumBoundRTVs; ++rt)
- {
- if (auto* pRT = m_pBoundRenderTargets[rt].RawPtr())
- BoundRTVFormats[rt] = pRT->GetDesc().Format;
- else
- BoundRTVFormats[rt] = TEX_FORMAT_UNKNOWN;
- }
-
- BoundDSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN;
- }
-
- const auto &PSODesc = m_pPipelineState->GetDesc();
- const auto &GraphicsPipeline = PSODesc.GraphicsPipeline;
- if (GraphicsPipeline.NumRenderTargets != NumBoundRTVs)
- {
- LOG_WARNING_MESSAGE("Number of currently bound render targets (", NumBoundRTVs, ") does not match the number of outputs specified by the PSO '", PSODesc.Name, "' (", GraphicsPipeline.NumRenderTargets, "). This is OK on D3D11 device, but will be an issue on Vulkan and D3D12." );
- }
-
- if (BoundDSVFormat != GraphicsPipeline.DSVFormat)
- {
- LOG_WARNING_MESSAGE("Currently bound depth-stencil buffer format (", GetTextureFormatAttribs(BoundDSVFormat).Name, ") does not match the DSV format specified by the PSO '", PSODesc.Name, "' (", GetTextureFormatAttribs(GraphicsPipeline.DSVFormat).Name, "). This is OK on D3D11 device, but will be an issue on Vulkan and D3D12." );
- }
-
- for (Uint32 rt = 0; rt < NumBoundRTVs; ++rt)
- {
- auto BoundFmt = BoundRTVFormats[rt];
- auto PSOFmt = GraphicsPipeline.RTVFormats[rt];
- if (BoundFmt != PSOFmt)
- {
- LOG_WARNING_MESSAGE("Render target bound to slot ", rt, " (", GetTextureFormatAttribs(BoundFmt).Name, ") does not match the RTV format specified by the PSO '", PSODesc.Name, "' (", GetTextureFormatAttribs(PSOFmt).Name, "). This is OK on D3D11 device, but will be an issue on Vulkan and D3D12." );
- }
- }
- }
-
DEFINE_D3D11CTX_FUNC_POINTERS(GetCBMethods, GetConstantBuffers)
DEFINE_D3D11CTX_FUNC_POINTERS(GetSRVMethods, GetShaderResources)
DEFINE_D3D11CTX_FUNC_POINTERS(GetSamplerMethods, GetSamplers)
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 5d3ffe4b..40b6cd38 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -171,7 +171,8 @@ IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByName(SHADE auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if( ResLayoutIndex < 0 ) { - LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return nullptr; } @@ -185,7 +186,8 @@ Uint32 ShaderResourceBindingD3D11Impl::GetVariableCount(SHADER_TYPE ShaderType) auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if( ResLayoutIndex < 0 ) { - LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return 0; } @@ -199,7 +201,8 @@ IShaderResourceVariable* ShaderResourceBindingD3D11Impl::GetVariableByIndex(SHAD auto ResLayoutIndex = m_ResourceLayoutIndex[Ind]; if( ResLayoutIndex < 0 ) { - LOG_ERROR("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return nullptr; } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index d34bc493..905f522a 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -362,8 +362,11 @@ namespace Diligent void DeviceContextD3D12Impl::Draw( DrawAttribs& drawAttribs ) { #ifdef DEVELOPMENT - if (!DvpVerifyDrawArguments(drawAttribs)) + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) != 0 && !DvpVerifyDrawArguments(drawAttribs)) return; + + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) + DvpVerifyRenderTargets(); #endif const bool VerifyStates = (drawAttribs.Flags & DRAW_FLAG_VERIFY_STATES) != 0; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index cee1c2a2..7d4c396f 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -109,7 +109,8 @@ IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariableByName(SHADE auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; if (ResLayoutInd < 0) { - LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "': shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return nullptr; } return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name); @@ -121,7 +122,8 @@ Uint32 ShaderResourceBindingD3D12Impl::GetVariableCount(SHADER_TYPE ShaderType) auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; if (ResLayoutInd < 0) { - LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables: shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return 0; } @@ -134,7 +136,8 @@ IShaderResourceVariable* ShaderResourceBindingD3D12Impl::GetVariableByIndex(SHAD auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd]; if (ResLayoutInd < 0) { - LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), " is inactive"); + LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, ": shader stage ", GetShaderTypeLiteralName(ShaderType), + " is inactive in Pipeline State '", m_pPSO->GetDesc().Name, "'"); return nullptr; } diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 4e5d4362..713be7b1 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -667,8 +667,11 @@ namespace Diligent void DeviceContextGLImpl::Draw(DrawAttribs &drawAttribs) { #ifdef DEVELOPMENT - if (!DvpVerifyDrawArguments(drawAttribs)) + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) != 0 && !DvpVerifyDrawArguments(drawAttribs)) return; + + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) + DvpVerifyRenderTargets(); #endif auto* pRenderDeviceGL = m_pDevice.RawPtr<RenderDeviceGLImpl>(); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 20522acb..384a342d 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -391,8 +391,11 @@ namespace Diligent void DeviceContextVkImpl::Draw( DrawAttribs& drawAttribs ) { #ifdef DEVELOPMENT - if (!DvpVerifyDrawArguments(drawAttribs)) + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) != 0 && !DvpVerifyDrawArguments(drawAttribs)) return; + + if ((drawAttribs.Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0) + DvpVerifyRenderTargets(); #endif EnsureVkCmdBuffer(); |
