Skip to content

Commit d729b38

Browse files
ResourceSignatureD3D12: implement CommitRootConstants method (#672)
1 parent aea9cac commit d729b38

File tree

8 files changed

+88
-1
lines changed

8 files changed

+88
-1
lines changed

Graphics/GraphicsEngine/include/DeviceContextBase.hpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ class DeviceContextBase : public ObjectBase<typename EngineImplTraits::DeviceCon
381381
// buffers with dynamic offsets in all backends).
382382
SRBMaskType DynamicSRBMask = 0;
383383

384+
// Indicates which SRBs contain inline constants
385+
SRBMaskType InlineConstantsSRBMask = 0;
386+
384387
void Set(Uint32 Index, ShaderResourceBindingImplType* pSRB)
385388
{
386389
VERIFY_EXPR(Index < MAX_RESOURCE_SIGNATURES);
@@ -398,6 +401,11 @@ class DeviceContextBase : public ObjectBase<typename EngineImplTraits::DeviceCon
398401
else
399402
DynamicSRBMask &= ~SRBBit;
400403

404+
if (pResourceCache != nullptr && pResourceCache->HasInlineConstants())
405+
InlineConstantsSRBMask |= SRBBit;
406+
else
407+
InlineConstantsSRBMask &= ~SRBBit;
408+
401409
#ifdef DILIGENT_DEVELOPMENT
402410
SRBs[Index] = pSRB;
403411
if (pSRB != nullptr)
@@ -412,18 +420,26 @@ class DeviceContextBase : public ObjectBase<typename EngineImplTraits::DeviceCon
412420
}
413421

414422
// Returns the mask of SRBs whose resources need to be committed
415-
SRBMaskType GetCommitMask(bool DynamicResourcesIntact = false) const
423+
SRBMaskType GetCommitMask(bool DynamicResourcesIntact = false,
424+
bool InlineConstantsIntact = false) const
416425
{
417426
#ifdef DILIGENT_DEVELOPMENT
418427
DvpVerifyCacheRevisions();
419428
#endif
420429

421430
// Stale SRBs always have to be committed
422431
SRBMaskType CommitMask = StaleSRBMask;
432+
423433
// If dynamic resources are not intact, SRBs with dynamic resources
424434
// have to be handled
425435
if (!DynamicResourcesIntact)
426436
CommitMask |= DynamicSRBMask;
437+
438+
// If inline constants are not intact, SRBs with inline constants
439+
// have to be handled
440+
if (!InlineConstantsIntact)
441+
CommitMask |= InlineConstantsSRBMask;
442+
427443
// Only process SRBs that are used by current PSO
428444
CommitMask &= ActiveSRBMask;
429445
return CommitMask;

Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,11 @@ class ShaderResourceCacheD3D11 : public ShaderResourceCacheBase
392392
return false;
393393
}
394394

395+
bool HasInlineConstants() const
396+
{
397+
return false;
398+
}
399+
395400
#ifdef DILIGENT_DEBUG
396401
void DbgVerifyDynamicBufferMasks() const;
397402
#endif

Graphics/GraphicsEngineD3D12/include/PipelineResourceSignatureD3D12Impl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class PipelineResourceSignatureD3D12Impl final : public PipelineResourceSignatur
163163
void CommitRootViews(const CommitCacheResourcesAttribs& CommitAttribs,
164164
Uint64 BuffersMask) const;
165165

166+
void CommitRootConstants(const CommitCacheResourcesAttribs& CommitAttribs,
167+
Uint64 ConstantsMask) const;
168+
166169
const RootParamsManager& GetRootParams() const { return m_RootParams; }
167170

168171
// Adds resources and immutable samplers from this signature to the

Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,16 @@ class ShaderResourceCacheD3D12 : public ShaderResourceCacheBase
339339
// Returns the bitmask indicating root views with bound non-dynamic buffers
340340
Uint64 GetNonDynamicRootBuffersMask() const { return m_NonDynamicRootBuffersMask; }
341341

342+
// Returns the bitmask indicating constants parameters
343+
Uint64 GetRootConstantsMask() const { return m_RootConstantsMask; }
344+
342345
// Returns true if the cache contains at least one dynamic resource, i.e.
343346
// dynamic buffer or a buffer range.
344347
bool HasDynamicResources() const { return GetDynamicRootBuffersMask() != 0; }
345348

349+
// Returns true if the cache contains at least one inline constants parameter.
350+
bool HasInlineConstants() const { return GetRootConstantsMask() != 0; }
351+
346352
#ifdef DILIGENT_DEBUG
347353
void DbgValidateDynamicBuffersMask() const;
348354
#endif
@@ -392,6 +398,9 @@ class ShaderResourceCacheD3D12 : public ShaderResourceCacheBase
392398

393399
// The bitmask indicating root views with bound non-dynamic buffers
394400
Uint64 m_NonDynamicRootBuffersMask = Uint64{0};
401+
402+
// The bitmask indicating root constants parameters
403+
Uint64 m_RootConstantsMask = Uint64{0};
395404
};
396405

397406
} // namespace Diligent

Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,45 @@ void PipelineResourceSignatureD3D12Impl::CommitRootViews(const CommitCacheResour
522522
}
523523
}
524524

525+
void PipelineResourceSignatureD3D12Impl::CommitRootConstants(const CommitCacheResourcesAttribs& CommitAttribs,
526+
Uint64 ConstantsMask) const
527+
{
528+
VERIFY_EXPR(CommitAttribs.pResourceCache != nullptr);
529+
530+
while (ConstantsMask != 0)
531+
{
532+
// Root constants are stored as raw data in the CPU descriptor handle pointer of
533+
// the single-resource root table.
534+
535+
const Uint64 RootIndBit = ExtractLSB(ConstantsMask);
536+
const Uint32 RootInd = PlatformMisc::GetLSB(RootIndBit);
537+
const ShaderResourceCacheD3D12::RootTable& CacheTbl = CommitAttribs.pResourceCache->GetRootTable(RootInd);
538+
const Uint32& BaseRootIndex = CommitAttribs.BaseRootIndex;
539+
540+
VERIFY_EXPR(CacheTbl.GetSize() == 1);
541+
const ShaderResourceCacheD3D12::Resource& Res = CacheTbl.GetResource(0);
542+
VERIFY_EXPR(Res.Type == SHADER_RESOURCE_TYPE_INLINE_CONSTANTS);
543+
VERIFY(Res.IsNull(), "There should be no resource bound for root constants as they contain raw data.");
544+
545+
const Uint32* pConstants = reinterpret_cast<const Uint32*>(Res.CPUDescriptorHandle.ptr);
546+
VERIFY(pConstants != nullptr, "Resources used to store root constants must have valid pointer to the data.");
547+
// The number of root constants is stored in BufferRangeSize
548+
const Uint32 NumConstants = static_cast<Uint32>(Res.BufferRangeSize);
549+
550+
ID3D12GraphicsCommandList* const pd3d12CmdList = CommitAttribs.CmdCtx.GetCommandList();
551+
if (CommitAttribs.IsCompute)
552+
{
553+
for (Uint32 i = 0; i < NumConstants; ++i)
554+
pd3d12CmdList->SetComputeRoot32BitConstant(BaseRootIndex + RootInd, pConstants[i], i);
555+
}
556+
else
557+
{
558+
for (Uint32 i = 0; i < NumConstants; ++i)
559+
pd3d12CmdList->SetGraphicsRoot32BitConstant(BaseRootIndex + RootInd, pConstants[i], i);
560+
}
561+
}
562+
}
563+
525564
void PipelineResourceSignatureD3D12Impl::CommitRootTables(const CommitCacheResourcesAttribs& CommitAttribs) const
526565
{
527566
VERIFY_EXPR(CommitAttribs.pResourceCache != nullptr);

Graphics/GraphicsEngineOpenGL/include/ShaderResourceCacheGL.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ class ShaderResourceCacheGL : public ShaderResourceCacheBase
345345
return m_DynamicUBOMask != 0 || m_DynamicSSBOMask != 0;
346346
}
347347

348+
bool HasInlineConstants() const
349+
{
350+
return false;
351+
}
352+
348353
#ifdef DILIGENT_DEBUG
349354
void DbgVerifyDynamicBufferMasks() const;
350355
#endif

Graphics/GraphicsEngineVulkan/include/ShaderResourceCacheVk.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ class ShaderResourceCacheVk : public ShaderResourceCacheBase
249249
Uint32 GetNumDescriptorSets() const { return m_NumSets; }
250250
bool HasDynamicResources() const { return m_NumDynamicBuffers > 0; }
251251

252+
bool HasInlineConstants() const
253+
{
254+
return false;
255+
}
256+
252257
ResourceCacheContentType GetContentType() const { return static_cast<ResourceCacheContentType>(m_ContentType); }
253258

254259
#ifdef DILIGENT_DEBUG

Graphics/GraphicsEngineWebGPU/include/ShaderResourceCacheWebGPU.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class ShaderResourceCacheWebGPU : public ShaderResourceCacheBase
176176
Uint32 GetNumBindGroups() const { return m_NumBindGroups; }
177177
bool HasDynamicResources() const { return m_NumDynamicBuffers > 0; }
178178

179+
bool HasInlineConstants() const
180+
{
181+
return false;
182+
}
183+
179184
ResourceCacheContentType GetContentType() const { return static_cast<ResourceCacheContentType>(m_ContentType); }
180185

181186
WGPUBindGroup UpdateBindGroup(WGPUDevice wgpuDevice, Uint32 GroupIndex, WGPUBindGroupLayout wgpuGroupLayout);

0 commit comments

Comments
 (0)