Skip to content

Commit ae6da57

Browse files
Removed DRAW_FLAG_VERIFY_RENDER_TARGETS flag (API256003)
1 parent 01f8699 commit ae6da57

File tree

11 files changed

+75
-38
lines changed

11 files changed

+75
-38
lines changed

Graphics/GraphicsEngine/include/DeviceContextBase.hpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ class DeviceContextBase : public ObjectBase<typename EngineImplTraits::DeviceCon
693693
std::unordered_map<IBuffer*, DbgMappedBufferInfo> m_DbgMappedBuffers;
694694
#endif
695695
#ifdef DILIGENT_DEVELOPMENT
696-
int m_DvpDebugGroupCount = 0;
696+
int m_DvpDebugGroupCount = 0;
697+
size_t m_DvpRenderTargetFormatsHash = 0;
697698
#endif
698699
};
699700

@@ -1178,6 +1179,23 @@ inline bool DeviceContextBase<ImplementationTraits>::SetRenderTargets(const SetR
11781179
"SHADING_RATE_CAP_FLAG_NON_SUBSAMPLED_RENDER_TARGET capability is not present.");
11791180
}
11801181
}
1182+
1183+
{
1184+
std::array<TEXTURE_FORMAT, MAX_RENDER_TARGETS> RTFormats{};
1185+
for (Uint32 i = 0; i < m_NumBoundRenderTargets; ++i)
1186+
{
1187+
if (TextureViewImplType* pRTV = m_pBoundRenderTargets[i])
1188+
{
1189+
RTFormats[i] = pRTV->GetDesc().Format;
1190+
}
1191+
else
1192+
{
1193+
RTFormats[i] = TEX_FORMAT_UNKNOWN;
1194+
}
1195+
}
1196+
TEXTURE_FORMAT DSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN;
1197+
m_DvpRenderTargetFormatsHash = ComputeRenderTargetFormatsHash(m_NumBoundRenderTargets, RTFormats.data(), DSVFormat);
1198+
}
11811199
#endif
11821200

11831201
if (bBindRenderTargets)
@@ -1429,6 +1447,9 @@ void DeviceContextBase<ImplementationTraits>::ResetRenderTargets()
14291447
m_FramebufferHeight = 0;
14301448
m_FramebufferSlices = 0;
14311449
m_FramebufferSamples = 0;
1450+
#ifdef DILIGENT_DEVELOPMENT
1451+
m_DvpRenderTargetFormatsHash = 0;
1452+
#endif
14321453

14331454
m_pBoundDepthStencil.Release();
14341455
m_pBoundShadingRateMap.Release();
@@ -2455,7 +2476,16 @@ inline void DeviceContextBase<ImplementationTraits>::MultiDrawIndexed(const Mult
24552476
template <typename ImplementationTraits>
24562477
inline void DeviceContextBase<ImplementationTraits>::DvpVerifyRenderTargets() const
24572478
{
2458-
DEV_CHECK_ERR(m_pPipelineState, "No pipeline state is bound");
2479+
if (!m_pPipelineState)
2480+
{
2481+
DEV_ERROR("No pipeline state is bound");
2482+
return;
2483+
}
2484+
2485+
if (m_DvpRenderTargetFormatsHash == m_pPipelineState->DvpGetRenderTargerFormatsHash())
2486+
{
2487+
return;
2488+
}
24592489

24602490
const PipelineStateDesc& PSODesc = m_pPipelineState->GetDesc();
24612491
DEV_CHECK_ERR(PSODesc.IsAnyGraphicsPipeline() || PSODesc.IsTilePipeline(),

Graphics/GraphicsEngine/include/PipelineStateBase.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,13 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
772772
return m_ActiveShaderStages;
773773
}
774774

775+
#ifdef DILIGENT_DEVELOPMENT
776+
size_t DvpGetRenderTargerFormatsHash() const
777+
{
778+
return m_pGraphicsPipelineData ? m_pGraphicsPipelineData->dvpRenderTargetFormatsHash : 0;
779+
}
780+
#endif
781+
775782
protected:
776783
using TNameToGroupIndexMap = std::unordered_map<HashMapStringKey, Uint32>;
777784

@@ -996,6 +1003,11 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
9961003
pStrides = MemPool.CopyConstructArray<Uint32>(Strides.data(), BufferSlotsUsed);
9971004
}
9981005
GraphicsPipeline.InputLayout.LayoutElements = pLayoutElements;
1006+
1007+
#ifdef DILIGENT_DEVELOPMENT
1008+
this->m_pGraphicsPipelineData->dvpRenderTargetFormatsHash = ComputeRenderTargetFormatsHash(
1009+
GraphicsPipeline.NumRenderTargets, GraphicsPipeline.RTVFormats, GraphicsPipeline.DSVFormat);
1010+
#endif
9991011
}
10001012

10011013
void InitializePipelineDesc(const ComputePipelineStateCreateInfo& CreateInfo,
@@ -1313,6 +1325,10 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
13131325

13141326
Uint32* pStrides = nullptr;
13151327
Uint8 BufferSlotsUsed = 0;
1328+
1329+
#ifdef DILIGENT_DEVELOPMENT
1330+
size_t dvpRenderTargetFormatsHash = 0;
1331+
#endif
13161332
};
13171333

13181334
struct RayTracingPipelineData

Graphics/GraphicsEngine/interface/APIInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/// \file
3131
/// Diligent API information
3232

33-
#define DILIGENT_API_VERSION 256002
33+
#define DILIGENT_API_VERSION 256003
3434

3535
#include "../../../Primitives/interface/BasicTypes.h"
3636

Graphics/GraphicsEngine/interface/DeviceContext.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -151,30 +151,24 @@ typedef struct DeviceContextDesc DeviceContextDesc;
151151
DILIGENT_TYPED_ENUM(DRAW_FLAGS, Uint8)
152152
{
153153
/// No flags.
154-
DRAW_FLAG_NONE = 0x00,
154+
DRAW_FLAG_NONE = 0u,
155155

156156
/// Verify the state of index and vertex buffers (if any) used by the draw
157157
/// command. State validation is only performed in debug and development builds
158158
/// and the flag has no effect in release build.
159-
DRAW_FLAG_VERIFY_STATES = 0x01,
159+
DRAW_FLAG_VERIFY_STATES = 1u << 0u,
160160

161161
/// Verify correctness of parameters passed to the draw command.
162162
///
163163
/// \remarks This flag only has effect in debug and development builds.
164164
/// Verification is always disabled in release configuration.
165-
DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 0x02,
166-
167-
/// Verify that render targets bound to the context are consistent with the pipeline state.
168-
///
169-
/// \remarks This flag only has effect in debug and development builds.
170-
/// Verification is always disabled in release configuration.
171-
DRAW_FLAG_VERIFY_RENDER_TARGETS = 0x04,
165+
DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 1u << 1u,
172166

173167
/// Perform all state validation checks
174168
///
175169
/// \remarks This flag only has effect in debug and development builds.
176170
/// Verification is always disabled in release configuration.
177-
DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS,
171+
DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS,
178172

179173
/// Indicates that none of the dynamic resource buffers used by the draw command
180174
/// have been modified by the CPU since the last command.
@@ -218,7 +212,7 @@ DILIGENT_TYPED_ENUM(DRAW_FLAGS, Uint8)
218212
/// (see RootSignature::CommitRootViews). When DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT is set, root views are only bound
219213
/// by the first draw command that uses the PSO + SRB pair. The flag avoids setting the same GPU virtual addresses when
220214
/// they stay unchanged.
221-
DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT = 0x08
215+
DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT = 1u << 2u
222216
};
223217
DEFINE_FLAG_ENUM_OPERATORS(DRAW_FLAGS)
224218

Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,7 @@ void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pP
634634
void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags)
635635
{
636636
#ifdef DILIGENT_DEVELOPMENT
637-
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
638-
DvpVerifyRenderTargets();
637+
DvpVerifyRenderTargets();
639638
#endif
640639

641640
auto* pd3d11InputLayout = m_pPipelineState->GetD3D11InputLayout();

Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,7 @@ void DeviceContextD3D12Impl::CommitD3D12VertexBuffers(GraphicsContext& GraphCtx)
601601
void DeviceContextD3D12Impl::PrepareForDraw(GraphicsContext& GraphCtx, DRAW_FLAGS Flags)
602602
{
603603
#ifdef DILIGENT_DEVELOPMENT
604-
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
605-
DvpVerifyRenderTargets();
604+
DvpVerifyRenderTargets();
606605
#endif
607606

608607
if (!m_State.bCommittedD3D12VBsUpToDate && m_pPipelineState->GetNumBufferSlotsUsed() > 0)

Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,7 @@ void DeviceContextGLImpl::PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenu
747747
}
748748

749749
#ifdef DILIGENT_DEVELOPMENT
750-
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
751-
DvpVerifyRenderTargets();
750+
DvpVerifyRenderTargets();
752751
#endif
753752

754753
// The program might have changed since the last SetPipelineState call if a shader was

Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,7 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags)
733733
}
734734

735735
#ifdef DILIGENT_DEVELOPMENT
736-
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
737-
DvpVerifyRenderTargets();
738-
736+
DvpVerifyRenderTargets();
739737
VERIFY((m_vkRenderPass != VK_NULL_HANDLE && m_vkFramebuffer != VK_NULL_HANDLE) || m_DynamicRenderingInfo, "No render pass is active while executing draw command");
740738
#endif
741739

Graphics/GraphicsEngineWebGPU/src/DeviceContextWebGPUImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,7 @@ void DeviceContextWebGPUImpl::ClearAttachment(Int32 RTIndex,
19861986
WGPURenderPassEncoder DeviceContextWebGPUImpl::PrepareForDraw(DRAW_FLAGS Flags)
19871987
{
19881988
#ifdef DILIGENT_DEVELOPMENT
1989-
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
1990-
DvpVerifyRenderTargets();
1989+
DvpVerifyRenderTargets();
19911990
#endif
19921991
DEV_CHECK_ERR(m_pPipelineState != nullptr, "No PSO is bound in the context");
19931992

ReleaseHistory.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Current progress
22

3+
* Removed `DRAW_FLAG_VERIFY_RENDER_TARGETS` flag (API256003)
4+
* The validation uses render target formats hash, which allows detecting format mismatches
5+
without overhead.
36
* Added `OpenXRAttribsSize` member to `APIInfo` struct (API256002)
47
* Enabled OpenXR (API256001)
58
* Added `OpenXRAttribs` struct and `pXRAttribs` member to `EngineCreateInfo` struct

0 commit comments

Comments
 (0)