Skip to content

Commit

Permalink
Removed DRAW_FLAG_VERIFY_RENDER_TARGETS flag (API256003)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Feb 2, 2025
1 parent 01f8699 commit ae6da57
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 38 deletions.
34 changes: 32 additions & 2 deletions Graphics/GraphicsEngine/include/DeviceContextBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@ class DeviceContextBase : public ObjectBase<typename EngineImplTraits::DeviceCon
std::unordered_map<IBuffer*, DbgMappedBufferInfo> m_DbgMappedBuffers;
#endif
#ifdef DILIGENT_DEVELOPMENT
int m_DvpDebugGroupCount = 0;
int m_DvpDebugGroupCount = 0;
size_t m_DvpRenderTargetFormatsHash = 0;
#endif
};

Expand Down Expand Up @@ -1178,6 +1179,23 @@ inline bool DeviceContextBase<ImplementationTraits>::SetRenderTargets(const SetR
"SHADING_RATE_CAP_FLAG_NON_SUBSAMPLED_RENDER_TARGET capability is not present.");
}
}

{
std::array<TEXTURE_FORMAT, MAX_RENDER_TARGETS> RTFormats{};
for (Uint32 i = 0; i < m_NumBoundRenderTargets; ++i)
{
if (TextureViewImplType* pRTV = m_pBoundRenderTargets[i])
{
RTFormats[i] = pRTV->GetDesc().Format;
}
else
{
RTFormats[i] = TEX_FORMAT_UNKNOWN;
}
}
TEXTURE_FORMAT DSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN;
m_DvpRenderTargetFormatsHash = ComputeRenderTargetFormatsHash(m_NumBoundRenderTargets, RTFormats.data(), DSVFormat);
}
#endif

if (bBindRenderTargets)
Expand Down Expand Up @@ -1429,6 +1447,9 @@ void DeviceContextBase<ImplementationTraits>::ResetRenderTargets()
m_FramebufferHeight = 0;
m_FramebufferSlices = 0;
m_FramebufferSamples = 0;
#ifdef DILIGENT_DEVELOPMENT
m_DvpRenderTargetFormatsHash = 0;
#endif

m_pBoundDepthStencil.Release();
m_pBoundShadingRateMap.Release();
Expand Down Expand Up @@ -2455,7 +2476,16 @@ inline void DeviceContextBase<ImplementationTraits>::MultiDrawIndexed(const Mult
template <typename ImplementationTraits>
inline void DeviceContextBase<ImplementationTraits>::DvpVerifyRenderTargets() const
{
DEV_CHECK_ERR(m_pPipelineState, "No pipeline state is bound");
if (!m_pPipelineState)
{
DEV_ERROR("No pipeline state is bound");
return;
}

if (m_DvpRenderTargetFormatsHash == m_pPipelineState->DvpGetRenderTargerFormatsHash())
{
return;
}

const PipelineStateDesc& PSODesc = m_pPipelineState->GetDesc();
DEV_CHECK_ERR(PSODesc.IsAnyGraphicsPipeline() || PSODesc.IsTilePipeline(),
Expand Down
16 changes: 16 additions & 0 deletions Graphics/GraphicsEngine/include/PipelineStateBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,13 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
return m_ActiveShaderStages;
}

#ifdef DILIGENT_DEVELOPMENT
size_t DvpGetRenderTargerFormatsHash() const
{
return m_pGraphicsPipelineData ? m_pGraphicsPipelineData->dvpRenderTargetFormatsHash : 0;
}
#endif

protected:
using TNameToGroupIndexMap = std::unordered_map<HashMapStringKey, Uint32>;

Expand Down Expand Up @@ -996,6 +1003,11 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
pStrides = MemPool.CopyConstructArray<Uint32>(Strides.data(), BufferSlotsUsed);
}
GraphicsPipeline.InputLayout.LayoutElements = pLayoutElements;

#ifdef DILIGENT_DEVELOPMENT
this->m_pGraphicsPipelineData->dvpRenderTargetFormatsHash = ComputeRenderTargetFormatsHash(
GraphicsPipeline.NumRenderTargets, GraphicsPipeline.RTVFormats, GraphicsPipeline.DSVFormat);
#endif
}

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

Uint32* pStrides = nullptr;
Uint8 BufferSlotsUsed = 0;

#ifdef DILIGENT_DEVELOPMENT
size_t dvpRenderTargetFormatsHash = 0;
#endif
};

struct RayTracingPipelineData
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngine/interface/APIInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/// \file
/// Diligent API information

#define DILIGENT_API_VERSION 256002
#define DILIGENT_API_VERSION 256003

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

Expand Down
18 changes: 6 additions & 12 deletions Graphics/GraphicsEngine/interface/DeviceContext.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2024 Diligent Graphics LLC
* Copyright 2019-2025 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -151,30 +151,24 @@ typedef struct DeviceContextDesc DeviceContextDesc;
DILIGENT_TYPED_ENUM(DRAW_FLAGS, Uint8)
{
/// No flags.
DRAW_FLAG_NONE = 0x00,
DRAW_FLAG_NONE = 0u,

/// Verify the state 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 = 1u << 0u,

/// Verify correctness of parameters passed to the draw command.
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 0x02,

/// Verify that render targets bound to the context are consistent with the pipeline state.
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_RENDER_TARGETS = 0x04,
DRAW_FLAG_VERIFY_DRAW_ATTRIBS = 1u << 1u,

/// Perform all state validation checks
///
/// \remarks This flag only has effect in debug and development builds.
/// Verification is always disabled in release configuration.
DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS | DRAW_FLAG_VERIFY_RENDER_TARGETS,
DRAW_FLAG_VERIFY_ALL = DRAW_FLAG_VERIFY_STATES | DRAW_FLAG_VERIFY_DRAW_ATTRIBS,

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

Expand Down
3 changes: 1 addition & 2 deletions Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,7 @@ void DeviceContextD3D11Impl::CommitD3D11VertexBuffers(PipelineStateD3D11Impl* pP
void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags)
{
#ifdef DILIGENT_DEVELOPMENT
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
DvpVerifyRenderTargets();
DvpVerifyRenderTargets();
#endif

auto* pd3d11InputLayout = m_pPipelineState->GetD3D11InputLayout();
Expand Down
3 changes: 1 addition & 2 deletions Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,7 @@ void DeviceContextD3D12Impl::CommitD3D12VertexBuffers(GraphicsContext& GraphCtx)
void DeviceContextD3D12Impl::PrepareForDraw(GraphicsContext& GraphCtx, DRAW_FLAGS Flags)
{
#ifdef DILIGENT_DEVELOPMENT
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
DvpVerifyRenderTargets();
DvpVerifyRenderTargets();
#endif

if (!m_State.bCommittedD3D12VBsUpToDate && m_pPipelineState->GetNumBufferSlotsUsed() > 0)
Expand Down
3 changes: 1 addition & 2 deletions Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ void DeviceContextGLImpl::PrepareForDraw(DRAW_FLAGS Flags, bool IsIndexed, GLenu
}

#ifdef DILIGENT_DEVELOPMENT
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
DvpVerifyRenderTargets();
DvpVerifyRenderTargets();
#endif

// The program might have changed since the last SetPipelineState call if a shader was
Expand Down
4 changes: 1 addition & 3 deletions Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,7 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags)
}

#ifdef DILIGENT_DEVELOPMENT
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
DvpVerifyRenderTargets();

DvpVerifyRenderTargets();
VERIFY((m_vkRenderPass != VK_NULL_HANDLE && m_vkFramebuffer != VK_NULL_HANDLE) || m_DynamicRenderingInfo, "No render pass is active while executing draw command");
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,7 @@ void DeviceContextWebGPUImpl::ClearAttachment(Int32 RTIndex,
WGPURenderPassEncoder DeviceContextWebGPUImpl::PrepareForDraw(DRAW_FLAGS Flags)
{
#ifdef DILIGENT_DEVELOPMENT
if ((Flags & DRAW_FLAG_VERIFY_RENDER_TARGETS) != 0)
DvpVerifyRenderTargets();
DvpVerifyRenderTargets();
#endif
DEV_CHECK_ERR(m_pPipelineState != nullptr, "No PSO is bound in the context");

Expand Down
3 changes: 3 additions & 0 deletions ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Current progress

* Removed `DRAW_FLAG_VERIFY_RENDER_TARGETS` flag (API256003)
* The validation uses render target formats hash, which allows detecting format mismatches
without overhead.
* Added `OpenXRAttribsSize` member to `APIInfo` struct (API256002)
* Enabled OpenXR (API256001)
* Added `OpenXRAttribs` struct and `pXRAttribs` member to `EngineCreateInfo` struct
Expand Down
24 changes: 12 additions & 12 deletions Tests/DiligentCoreAPITest/src/TileShaderTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2025 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,26 +53,26 @@ namespace

TEST(TileShaderTest, DrawQuad)
{
auto* pEnv = GPUTestingEnvironment::GetInstance();
auto* pDevice = pEnv->GetDevice();
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
IRenderDevice* pDevice = pEnv->GetDevice();
if (!pDevice->GetDeviceInfo().Features.TileShaders)
{
GTEST_SKIP() << "Tile shader is not supported by this device";
}

GPUTestingEnvironment::ScopedReset EnvironmentAutoReset;

auto* pSwapChain = pEnv->GetSwapChain();
auto* pContext = pEnv->GetDeviceContext();
const auto& SCDesc = pSwapChain->GetDesc();
ISwapChain* pSwapChain = pEnv->GetSwapChain();
IDeviceContext* pContext = pEnv->GetDeviceContext();
const SwapChainDesc& SCDesc = pSwapChain->GetDesc();

RefCntAutoPtr<ITestingSwapChain> pTestingSwapChain(pSwapChain, IID_TestingSwapChain);
if (pTestingSwapChain)
{
pContext->Flush();
pContext->InvalidateState();

auto DeviceType = pDevice->GetDeviceInfo().Type;
RENDER_DEVICE_TYPE DeviceType = pDevice->GetDeviceInfo().Type;
switch (DeviceType)
{
#if METAL_SUPPORTED
Expand All @@ -94,8 +94,8 @@ TEST(TileShaderTest, DrawQuad)
{
GraphicsPipelineStateCreateInfo PSOCreateInfo;

auto& PSODesc = PSOCreateInfo.PSODesc;
auto& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline;
PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc;
GraphicsPipelineDesc& GraphicsPipeline = PSOCreateInfo.GraphicsPipeline;

PSODesc.Name = "Tile shader test - graphics pipeline";

Expand Down Expand Up @@ -141,8 +141,8 @@ TEST(TileShaderTest, DrawQuad)
{
TilePipelineStateCreateInfo PSOCreateInfo;

auto& PSODesc = PSOCreateInfo.PSODesc;
auto& TilePipeline = PSOCreateInfo.TilePipeline;
PipelineStateDesc& PSODesc = PSOCreateInfo.PSODesc;
TilePipelineDesc& TilePipeline = PSOCreateInfo.TilePipeline;

PSODesc.Name = "Tile shader test - tile pipeline";

Expand Down Expand Up @@ -195,7 +195,7 @@ TEST(TileShaderTest, DrawQuad)
ASSERT_NE(TileSizeX, 0u);
ASSERT_NE(TileSizeY, 0u);

pContext->DispatchTile(DispatchTileAttribs{1, 1, DRAW_FLAG_VERIFY_RENDER_TARGETS});
pContext->DispatchTile(DispatchTileAttribs{1, 1});
}
pSwapChain->Present();
}
Expand Down

0 comments on commit ae6da57

Please sign in to comment.