Skip to content

Commit da6e90f

Browse files
D3D11/D3D12: improved handling of DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT/INLINE_CONSTANTS_INTACT flags
1 parent 846b40a commit da6e90f

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
@@ -360,7 +360,9 @@ class DeviceContextD3D11Impl final : public DeviceContextBase<EngineD3D11ImplTra
360360

361361
void ClearStateCache();
362362

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

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

Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp

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

425425

426-
void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
426+
void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask,
427+
bool DynamicBuffersIntact,
428+
bool InlineConstantsIntact)
427429
{
428430
VERIFY_EXPR(BindSRBMask != 0);
429431

@@ -470,7 +472,10 @@ void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
470472
if (PsUavBindMode != PixelShaderUAVBindMode::Bind)
471473
PsUavBindMode = PixelShaderUAVBindMode::Keep;
472474
}
473-
BindDynamicCBs(*pResourceCache, BaseBindings);
475+
if (!DynamicBuffersIntact)
476+
{
477+
BindDynamicCBs(*pResourceCache, BaseBindings);
478+
}
474479
}
475480
else
476481
{
@@ -486,13 +491,16 @@ void DeviceContextD3D11Impl::BindShaderResources(Uint32 BindSRBMask)
486491
"Shader resource cache does not contain inline constants, but the corresponding bit in InlineConstantsSRBMask is set. "
487492
"This may be a bug because inline constants flag in the cache never changes after SRB creation, "
488493
"while m_BindInfo.InlineConstantsSRBMask is initialized when SRB is committed.");
489-
if (PipelineResourceSignatureD3D11Impl* pSign = m_pPipelineState->GetResourceSignature(SignIdx))
490-
{
491-
pSign->UpdateInlineConstantBuffers(*pResourceCache, m_pd3d11DeviceContext);
492-
}
493-
else
494+
if ((m_BindInfo.StaleSRBMask & SignBit) != 0 || !InlineConstantsIntact)
494495
{
495-
UNEXPECTED("Pipeline resource signature is null for signature index ", SignIdx);
496+
if (PipelineResourceSignatureD3D11Impl* pSign = m_pPipelineState->GetResourceSignature(SignIdx))
497+
{
498+
pSign->UpdateInlineConstantBuffers(*pResourceCache, m_pd3d11DeviceContext);
499+
}
500+
else
501+
{
502+
UNEXPECTED("Pipeline resource signature is null for signature index ", SignIdx);
503+
}
496504
}
497505
}
498506
else
@@ -702,9 +710,11 @@ void DeviceContextD3D11Impl::PrepareForDraw(DRAW_FLAGS Flags)
702710
CommitD3D11VertexBuffers(m_pPipelineState);
703711
}
704712

713+
const bool DynamicBuffersIntact = (Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT) != 0;
714+
const bool InlineConstantsIntact = (Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT) != 0;
705715
if (Uint32 BindSRBMask = m_BindInfo.GetCommitMask(Flags & DRAW_FLAG_DYNAMIC_RESOURCE_BUFFERS_INTACT, Flags & DRAW_FLAG_INLINE_CONSTANTS_INTACT))
706716
{
707-
BindShaderResources(BindSRBMask);
717+
BindShaderResources(BindSRBMask, DynamicBuffersIntact, InlineConstantsIntact);
708718
}
709719

710720
#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)