Skip to content

Commit 93af1da

Browse files
D3D11/D3D12: improved handling of DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT/INLINE_CONSTANTS_INTACT flags
1 parent 0ffcb53 commit 93af1da

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

Graphics/GraphicsEngineD3D11/include/DeviceContextD3D11Impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ class DeviceContextD3D11Impl final : public DeviceContextBase<EngineD3D11ImplTra
359359

360360
void ClearStateCache();
361361

362-
void BindShaderResources(Uint32 BindSRBMask);
362+
void BindShaderResources(Uint32 BindSRBMask,
363+
bool DynamicBuffersIntact = false,
364+
bool InlineConstantsIntact = false);
363365

364366
static constexpr int NumShaderTypes = D3D11ResourceBindPoints::NumShaderTypes;
365367
struct TCommittedResources

Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ void DeviceContextD3D11Impl::BindDynamicCBs(const ShaderResourceCacheD3D11& R
426426
}
427427

428428

429-
void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
429+
void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask,
430+
bool DynamicBuffersIntact,
431+
bool InlineConstantsIntact)
430432
{
431433
VERIFY_EXPR(BindSRBMask != 0);
432434

@@ -473,7 +475,10 @@ void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
473475
if (PsUavBindMode != PixelShaderUAVBindMode::Bind)
474476
PsUavBindMode = PixelShaderUAVBindMode::Keep;
475477
}
476-
BindDynamicCBs(*pResourceCache, BaseBindings);
478+
if (!DynamicBuffersIntact)
479+
{
480+
BindDynamicCBs(*pResourceCache, BaseBindings);
481+
}
477482
}
478483
else
479484
{
@@ -489,13 +494,16 @@ void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
489494
"Shader resource cache does not contain inline constants, but the corresponding bit in InlineConstantsSRBMask is set. "
490495
"This may be a bug because inline constants flag in the cache never changes after SRB creation, "
491496
"while m_BindInfo.InlineConstantsSRBMask is initialized when SRB is committed.");
492-
if (PipelineResourceSignatureD3D11Impl* pSign = m_pPipelineState->GetResourceSignature(SignIdx))
493-
{
494-
pSign->UpdateInlineConstantBuffers(*pResourceCache, m_pd3d11DeviceContext);
495-
}
496-
else
497+
if ((m_BindInfo.StaleSRBMask & SignBit) != 0 || !InlineConstantsIntact)
497498
{
498-
UNEXPECTED("Pipeline resource signature is null for signature index ", SignIdx);
499+
if (PipelineResourceSignatureD3D11Impl* pSign = m_pPipelineState->GetResourceSignature(SignIdx))
500+
{
501+
pSign->UpdateInlineConstantBuffers(*pResourceCache, m_pd3d11DeviceContext);
502+
}
503+
else
504+
{
505+
UNEXPECTED("Pipeline resource signature is null for signature index ", SignIdx);
506+
}
499507
}
500508
}
501509
else
@@ -705,9 +713,11 @@ void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags)
705713
CommitD3D11VertexBuffers(m_pPipelineState);
706714
}
707715

716+
const bool DynamicBuffersIntact = (Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT) != 0;
717+
const bool InlineConstantsIntact = (Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT) != 0;
708718
if (Uint32 BindSRBMask = m_BindInfo.GetCommitMask(Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT, Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT))
709719
{
710-
BindShaderResources(BindSRBMask);
720+
BindShaderResources(BindSRBMask, DynamicBuffersIntact, InlineConstantsIntact);
711721
}
712722

713723
#ifdef DILIGENT_DEVELOPMENT

Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,11 @@ class DeviceContextD3D12Impl final : public DeviceContextNextGenBase<EngineD3D12
426426
__forceinline RootTableInfo& GetRootTableInfo(PIPELINE_TYPE PipelineType);
427427

428428
template <bool IsCompute>
429-
__forceinline void CommitRootTablesAndViews(RootTableInfo& RootInfo, Uint32 CommitSRBMask, CommandContext& CmdCtx) const;
429+
__forceinline void CommitRootTablesAndViews(RootTableInfo& RootInfo,
430+
Uint32 CommitSRBMask,
431+
CommandContext& CmdCtx,
432+
bool DynamicBuffersIntact = false,
433+
bool InlineConstantsIntact = false) const;
430434

431435
#ifdef DILIGENT_DEVELOPMENT
432436
void DvpValidateCommittedShaderResources(RootTableInfo& RootInfo) const;

Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState)
370370
}
371371

372372
template <bool IsCompute>
373-
void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo, Uint32 CommitSRBMask, CommandContext& CmdCtx) const
373+
void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo,
374+
Uint32 CommitSRBMask,
375+
CommandContext& CmdCtx,
376+
bool DynamicBuffersIntact,
377+
bool InlineConstantsIntact) const
374378
{
375379
const RootSignatureD3D12& RootSig = m_pPipelineState->GetRootSignature();
376380

@@ -397,7 +401,9 @@ void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo, U
397401

398402
CommitAttribs.pResourceCache = pResourceCache;
399403
CommitAttribs.BaseRootIndex = RootSig.GetBaseRootIndex(sign);
400-
if ((RootInfo.StaleSRBMask & SignBit) != 0)
404+
405+
const bool SRBStale = (RootInfo.StaleSRBMask & SignBit) != 0;
406+
if (SRBStale)
401407
{
402408
// Commit root tables for stale SRBs only
403409
pSignature->CommitRootTables(CommitAttribs);
@@ -410,7 +416,10 @@ void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo, U
410416
DEV_CHECK_ERR((RootInfo.DynamicSRBMask & SignBit) != 0,
411417
"There are dynamic root buffers in the cache, but the bit in DynamicSRBMask is not set. This may indicate that resources "
412418
"in the cache have changed, but the SRB has not been committed before the draw/dispatch command.");
413-
pSignature->CommitRootViews(CommitAttribs, DynamicRootBuffersMask);
419+
if (SRBStale || !DynamicBuffersIntact)
420+
{
421+
pSignature->CommitRootViews(CommitAttribs, DynamicRootBuffersMask);
422+
}
414423
}
415424
else
416425
{
@@ -425,7 +434,10 @@ void DeviceContextD3D12Impl::CommitRootTablesAndViews(RootTableInfo& RootInfo, U
425434
"There are root constants in the cache, but the bit in InlineConstantsSRBMask is not set. "
426435
"This may be a bug because root constants mask in the cache never changes after SRB creation, "
427436
"while RootInfo.InlineConstantsSRBMask is initialized when SRB is committed.");
428-
pSignature->CommitRootConstants(CommitAttribs, RootConstantsMask);
437+
if (SRBStale || !InlineConstantsIntact)
438+
{
439+
pSignature->CommitRootConstants(CommitAttribs, RootConstantsMask);
440+
}
429441
}
430442
else
431443
{
@@ -645,9 +657,11 @@ void DeviceContextD3D12Impl::PrepareForDraw(GraphicsContext& GraphCtx, DRAW_FLAG
645657
#ifdef DILIGENT_DEVELOPMENT
646658
DvpValidateCommittedShaderResources(RootInfo);
647659
#endif
648-
if (Uint32 CommitSRBMask = RootInfo.GetCommitMask(Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT, Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT))
660+
const bool DynamicBuffersIntact = (Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT) != 0;
661+
const bool InlineConstantsIntact = (Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT) != 0;
662+
if (Uint32 CommitSRBMask = RootInfo.GetCommitMask(DynamicBuffersIntact, InlineConstantsIntact))
649663
{
650-
CommitRootTablesAndViews<false>(RootInfo, CommitSRBMask, GraphCtx);
664+
CommitRootTablesAndViews<false>(RootInfo, CommitSRBMask, GraphCtx, DynamicBuffersIntact, InlineConstantsIntact);
651665
}
652666

653667
#ifdef NTDDI_WIN10_19H1

0 commit comments

Comments
 (0)