Skip to content

Commit 568135a

Browse files
azhirnovTheMostDiligent
authored andcommitted
Fix for tile shader, use MAX_RENDER_TARGETS constant instead of magic number
1 parent fd6223a commit 568135a

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

Graphics/GraphicsEngine/include/DeviceContextBase.hpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,41 +2108,58 @@ inline void DeviceContextBase<ImplementationTraits>::DvpVerifyRenderTargets() co
21082108
DEV_CHECK_ERR(m_pPipelineState, "No pipeline state is bound");
21092109

21102110
const auto& PSODesc = m_pPipelineState->GetDesc();
2111-
DEV_CHECK_ERR(PSODesc.IsAnyGraphicsPipeline(),
2111+
DEV_CHECK_ERR(PSODesc.IsAnyGraphicsPipeline() || PSODesc.IsTilePipeline(),
21122112
"Pipeline state '", PSODesc.Name, "' is not a graphics pipeline");
21132113

2114-
TEXTURE_FORMAT BoundRTVFormats[8] = {TEX_FORMAT_UNKNOWN};
2115-
TEXTURE_FORMAT BoundDSVFormat = TEX_FORMAT_UNKNOWN;
2116-
2114+
TEXTURE_FORMAT BoundRTVFormats[MAX_RENDER_TARGETS] = {};
21172115
for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt)
21182116
{
2119-
if (auto* pRT = m_pBoundRenderTargets[rt].RawPtr())
2117+
if (const auto* pRT = m_pBoundRenderTargets[rt].RawPtr())
21202118
BoundRTVFormats[rt] = pRT->GetDesc().Format;
21212119
else
21222120
BoundRTVFormats[rt] = TEX_FORMAT_UNKNOWN;
21232121
}
2122+
const auto BoundDSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN;
21242123

2125-
BoundDSVFormat = m_pBoundDepthStencil ? m_pBoundDepthStencil->GetDesc().Format : TEX_FORMAT_UNKNOWN;
2124+
Uint32 NumPipelineRenderTargets = 0;
2125+
const TEXTURE_FORMAT* PipelineRTVFormats = nullptr;
2126+
TEXTURE_FORMAT PipelineDSVFormat = TEX_FORMAT_UNKNOWN;
2127+
if (PSODesc.IsAnyGraphicsPipeline())
2128+
{
2129+
const auto& GraphicsPipeline = m_pPipelineState->GetGraphicsPipelineDesc();
2130+
NumPipelineRenderTargets = GraphicsPipeline.NumRenderTargets;
2131+
PipelineRTVFormats = GraphicsPipeline.RTVFormats;
2132+
PipelineDSVFormat = GraphicsPipeline.DSVFormat;
2133+
}
2134+
else if (PSODesc.IsTilePipeline())
2135+
{
2136+
const auto& TilePipeline = m_pPipelineState->GetTilePipelineDesc();
2137+
NumPipelineRenderTargets = TilePipeline.NumRenderTargets;
2138+
PipelineRTVFormats = TilePipeline.RTVFormats;
2139+
}
2140+
else
2141+
{
2142+
UNEXPECTED("Unexpected pipeline type");
2143+
}
21262144

2127-
const auto& GraphicsPipeline = m_pPipelineState->GetGraphicsPipelineDesc();
2128-
if (GraphicsPipeline.NumRenderTargets != m_NumBoundRenderTargets)
2145+
if (NumPipelineRenderTargets != m_NumBoundRenderTargets)
21292146
{
21302147
LOG_WARNING_MESSAGE("The number of currently bound render targets (", m_NumBoundRenderTargets,
21312148
") does not match the number of outputs specified by the PSO '", PSODesc.Name,
2132-
"' (", Uint32{GraphicsPipeline.NumRenderTargets}, ").");
2149+
"' (", NumPipelineRenderTargets, ").");
21332150
}
21342151

2135-
if (BoundDSVFormat != GraphicsPipeline.DSVFormat)
2152+
if (BoundDSVFormat != PipelineDSVFormat)
21362153
{
21372154
LOG_WARNING_MESSAGE("Currently bound depth-stencil buffer format (", GetTextureFormatAttribs(BoundDSVFormat).Name,
21382155
") does not match the DSV format specified by the PSO '", PSODesc.Name,
2139-
"' (", GetTextureFormatAttribs(GraphicsPipeline.DSVFormat).Name, ").");
2156+
"' (", GetTextureFormatAttribs(PipelineDSVFormat).Name, ").");
21402157
}
21412158

21422159
for (Uint32 rt = 0; rt < m_NumBoundRenderTargets; ++rt)
21432160
{
21442161
auto BoundFmt = BoundRTVFormats[rt];
2145-
auto PSOFmt = GraphicsPipeline.RTVFormats[rt];
2162+
auto PSOFmt = PipelineRTVFormats[rt];
21462163
if (BoundFmt != PSOFmt)
21472164
{
21482165
LOG_WARNING_MESSAGE("Render target bound to slot ", rt, " (", GetTextureFormatAttribs(BoundFmt).Name,

Graphics/GraphicsEngine/interface/PipelineState.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct GraphicsPipelineDesc
202202

203203
/// Render target formats.
204204
/// All formats must be TEX_FORMAT_UNKNOWN when pRenderPass is not null.
205-
TEXTURE_FORMAT RTVFormats[8] DEFAULT_INITIALIZER({});
205+
TEXTURE_FORMAT RTVFormats[DILIGENT_MAX_RENDER_TARGETS] DEFAULT_INITIALIZER({});
206206

207207
/// Depth-stencil format.
208208
/// Must be TEX_FORMAT_UNKNOWN when pRenderPass is not null.
@@ -553,7 +553,7 @@ struct TilePipelineDesc
553553
Uint8 SampleCount DEFAULT_INITIALIZER(1);
554554

555555
/// Render target formats.
556-
TEXTURE_FORMAT RTVFormats[8] DEFAULT_INITIALIZER({});
556+
TEXTURE_FORMAT RTVFormats[DILIGENT_MAX_RENDER_TARGETS] DEFAULT_INITIALIZER({});
557557
};
558558
typedef struct TilePipelineDesc TilePipelineDesc;
559559

Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ void DeviceContextD3D12Impl::CommitRenderTargets(RESOURCE_STATE_TRANSITION_MODE
11191119

11201120
auto& CmdCtx = GetCmdContext();
11211121

1122-
D3D12_CPU_DESCRIPTOR_HANDLE RTVHandles[8]; // Do not waste time initializing array to zero
1122+
D3D12_CPU_DESCRIPTOR_HANDLE RTVHandles[MAX_RENDER_TARGETS]; // Do not waste time initializing array to zero
11231123
D3D12_CPU_DESCRIPTOR_HANDLE DSVHandle = {};
11241124
for (UINT i = 0; i < NumRenderTargets; ++i)
11251125
{

Tests/DiligentCoreAPITest/src/Metal/TileShaderReferenceMtl.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "TextureViewMtl.h"
3232

3333
#include "InlineShaders/TileShaderTestMSL.h"
34-
#include "RayTracingTestConstants.hpp"
3534

3635
namespace Diligent
3736
{

0 commit comments

Comments
 (0)