Skip to content

Commit 1445dde

Browse files
Updated Shader Binding Table documentation
1 parent 5924c09 commit 1445dde

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,6 +42,7 @@
4242
#include "GraphicsAccessories.hpp"
4343
#include "ShaderResourceCacheCommon.hpp"
4444
#include "FixedLinearAllocator.hpp"
45+
#include "SRBMemoryAllocator.hpp"
4546
#include "EngineMemory.h"
4647

4748
namespace Diligent
@@ -79,12 +80,12 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
7980
{
8081
m_ActiveShaderStageIndex.fill(-1);
8182

82-
const auto NumShaders = GetNumShaders();
83-
const auto PipelineType = GetPipelineType();
83+
const Uint32 NumShaders = GetNumShaders();
84+
const PIPELINE_TYPE PipelineType = GetPipelineType();
8485
for (Uint32 s = 0; s < NumShaders; ++s)
8586
{
86-
const auto ShaderType = pPRS->GetActiveShaderStageType(s);
87-
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
87+
const SHADER_TYPE ShaderType = pPRS->GetActiveShaderStageType(s);
88+
const Int32 ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
8889

8990
m_ActiveShaderStageIndex[ShaderInd] = static_cast<Int8>(s);
9091
}
@@ -98,7 +99,7 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
9899
m_pShaderVarMgrs = MemPool.ConstructArray<ShaderVariableManagerImplType>(NumShaders, std::ref(*this), std::ref(m_ShaderResourceCache));
99100

100101
// The memory is now owned by ShaderResourceBindingBase and will be freed by Destruct().
101-
auto* Ptr = MemPool.ReleaseOwnership();
102+
void* Ptr = MemPool.ReleaseOwnership();
102103
VERIFY_EXPR(Ptr == m_pShaderVarMgrs);
103104
(void)Ptr;
104105

@@ -107,15 +108,15 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
107108

108109
pPRS->InitSRBResourceCache(m_ShaderResourceCache);
109110

110-
auto& SRBMemAllocator = pPRS->GetSRBMemoryAllocator();
111+
SRBMemoryAllocator& SRBMemAllocator = pPRS->GetSRBMemoryAllocator();
111112
for (Uint32 s = 0; s < NumShaders; ++s)
112113
{
113-
const auto ShaderType = pPRS->GetActiveShaderStageType(s);
114-
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPRS->GetPipelineType());
115-
const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
114+
const SHADER_TYPE ShaderType = pPRS->GetActiveShaderStageType(s);
115+
const Int32 ShaderInd = GetShaderTypePipelineIndex(ShaderType, pPRS->GetPipelineType());
116+
const int MgrInd = m_ActiveShaderStageIndex[ShaderInd];
116117
VERIFY_EXPR(MgrInd >= 0 && MgrInd < static_cast<int>(NumShaders));
117118

118-
auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
119+
IMemoryAllocator& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
119120

120121
// Initialize vars manager to reference mutable and dynamic variables
121122
// Note that the cache has space for all variable types
@@ -178,16 +179,16 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
178179
/// Implementation of IShaderResourceBinding::GetVariableByName().
179180
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByName(SHADER_TYPE ShaderType, const char* Name) override final
180181
{
181-
const auto PipelineType = GetPipelineType();
182+
const PIPELINE_TYPE PipelineType = GetPipelineType();
182183
if (!IsConsistentShaderType(ShaderType, PipelineType))
183184
{
184185
LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
185186
" as the stage is invalid for ", GetPipelineTypeString(PipelineType), " pipeline resource signature '", m_pPRS->GetDesc().Name, "'.");
186187
return nullptr;
187188
}
188189

189-
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
190-
const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
190+
const Int32 ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
191+
const int MgrInd = m_ActiveShaderStageIndex[ShaderInd];
191192
if (MgrInd < 0)
192193
return nullptr;
193194

@@ -198,16 +199,16 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
198199
/// Implementation of IShaderResourceBinding::GetVariableCount().
199200
virtual Uint32 DILIGENT_CALL_TYPE GetVariableCount(SHADER_TYPE ShaderType) const override final
200201
{
201-
const auto PipelineType = GetPipelineType();
202+
const PIPELINE_TYPE PipelineType = GetPipelineType();
202203
if (!IsConsistentShaderType(ShaderType, PipelineType))
203204
{
204205
LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
205206
" as the stage is invalid for ", GetPipelineTypeString(PipelineType), " pipeline resource signature '", m_pPRS->GetDesc().Name, "'.");
206207
return 0;
207208
}
208209

209-
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
210-
const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
210+
const Int32 ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
211+
const int MgrInd = m_ActiveShaderStageIndex[ShaderInd];
211212
if (MgrInd < 0)
212213
return 0;
213214

@@ -218,16 +219,16 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
218219
/// Implementation of IShaderResourceBinding::GetVariableByIndex().
219220
virtual IShaderResourceVariable* DILIGENT_CALL_TYPE GetVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final
220221
{
221-
const auto PipelineType = GetPipelineType();
222+
const PIPELINE_TYPE PipelineType = GetPipelineType();
222223
if (!IsConsistentShaderType(ShaderType, PipelineType))
223224
{
224225
LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
225226
" as the stage is invalid for ", GetPipelineTypeString(PipelineType), " pipeline resource signature '", m_pPRS->GetDesc().Name, "'.");
226227
return nullptr;
227228
}
228229

229-
const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
230-
const auto MgrInd = m_ActiveShaderStageIndex[ShaderInd];
230+
const Int32 ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
231+
const int MgrInd = m_ActiveShaderStageIndex[ShaderInd];
231232
if (MgrInd < 0)
232233
return nullptr;
233234

@@ -273,10 +274,10 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
273274
{
274275
if (m_pShaderVarMgrs != nullptr)
275276
{
276-
auto& SRBMemAllocator = GetSignature()->GetSRBMemoryAllocator();
277+
SRBMemoryAllocator& SRBMemAllocator = GetSignature()->GetSRBMemoryAllocator();
277278
for (Uint32 s = 0; s < GetNumShaders(); ++s)
278279
{
279-
auto& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
280+
IMemoryAllocator& VarDataAllocator = SRBMemAllocator.GetShaderVariableDataAllocator(s);
280281
m_pShaderVarMgrs[s].Destroy(VarDataAllocator);
281282
m_pShaderVarMgrs[s].~ShaderVariableManagerImplType();
282283
}
@@ -288,15 +289,15 @@ class ShaderResourceBindingBase : public ObjectBase<typename EngineImplTraits::S
288289
void ProcessVariables(SHADER_TYPE ShaderStages,
289290
HandlerType&& Handler) const
290291
{
291-
const auto PipelineType = GetPipelineType();
292+
const PIPELINE_TYPE PipelineType = GetPipelineType();
292293
for (size_t ShaderInd = 0; ShaderInd < m_ActiveShaderStageIndex.size(); ++ShaderInd)
293294
{
294-
const auto VarMngrInd = m_ActiveShaderStageIndex[ShaderInd];
295+
const int VarMngrInd = m_ActiveShaderStageIndex[ShaderInd];
295296
if (VarMngrInd < 0)
296297
continue;
297298

298299
// ShaderInd is the shader type pipeline index here
299-
const auto ShaderType = GetShaderTypeFromPipelineIndex(static_cast<Int32>(ShaderInd), PipelineType);
300+
const SHADER_TYPE ShaderType = GetShaderTypeFromPipelineIndex(static_cast<Int32>(ShaderInd), PipelineType);
300301
if ((ShaderStages & ShaderType) == 0)
301302
continue;
302303

Graphics/GraphicsEngine/interface/ShaderResourceBinding.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -87,23 +87,23 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject)
8787
///
8888
/// \return Variable type flags that did not pass the checks and thus may need to be updated.
8989
///
90-
/// \remarks This method may be used to perform various checks of the currently bound resources:
90+
/// This method may be used to perform various checks of the currently bound resources:
9191
///
92-
/// - BIND_SHADER_RESOURCES_UPDATE_MUTABLE and BIND_SHADER_RESOURCES_UPDATE_DYNAMIC flags
93-
/// define which variable types to examine. Note that BIND_SHADER_RESOURCES_UPDATE_STATIC
94-
/// has no effect as static resources are accessed through the PSO.
92+
/// - Diligent::BIND_SHADER_RESOURCES_UPDATE_MUTABLE and Diligent::BIND_SHADER_RESOURCES_UPDATE_DYNAMIC flags
93+
/// define which variable types to examine. Note that Diligent::BIND_SHADER_RESOURCES_UPDATE_STATIC
94+
/// has no effect as static resources are accessed through the PSO.
9595
///
96-
/// - If BIND_SHADER_RESOURCES_KEEP_EXISTING flag is not set and pResMapping is not null,
97-
/// the method will compare currently bound resources with the ones in the resource mapping.
98-
/// If any mismatch is found, the method will return the types of the variables that
99-
/// contain mismatching resources.
100-
/// Note that the situation when non-null object is bound to the variable, but the resource
101-
/// mapping does not contain an object corresponding to the variable name, does not count as
102-
/// mismatch.
96+
/// - If Diligent::BIND_SHADER_RESOURCES_KEEP_EXISTING flag is not set and pResMapping is not null,
97+
/// the method will compare currently bound resources with the ones in the resource mapping.
98+
/// If any mismatch is found, the method will return the types of the variables that
99+
/// contain mismatching resources.
100+
/// Note that the situation when non-null object is bound to the variable, but the resource
101+
/// mapping does not contain an object corresponding to the variable name, does not count as
102+
/// mismatch.
103103
///
104-
/// - If BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED flag is set, the method will check that
105-
/// all resources of the specified variable types are bound and return the types of the variables
106-
/// that are not bound.
104+
/// - If Diligent::BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED flag is set, the method will check that
105+
/// all resources of the specified variable types are bound and return the types of the variables
106+
/// that are not bound.
107107
VIRTUAL SHADER_RESOURCE_VARIABLE_TYPE_FLAGS METHOD(CheckResources)(
108108
THIS_
109109
SHADER_TYPE ShaderStages,
@@ -127,9 +127,11 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject)
127127
/// Returns the total variable count for the specific shader stage.
128128

129129
/// \param [in] ShaderType - Type of the shader.
130-
/// \remark The method only counts mutable and dynamic variables that can be accessed through
131-
/// the Shader Resource Binding object. Static variables are accessed through the Shader
132-
/// object.
130+
/// \return Total number of variables in the shader stage.
131+
///
132+
/// The method only counts mutable and dynamic variables that can be accessed through
133+
/// the Shader Resource Binding object. Static variables are accessed through the Shader
134+
/// object.
133135
VIRTUAL Uint32 METHOD(GetVariableCount)(THIS_
134136
SHADER_TYPE ShaderType) CONST PURE;
135137

@@ -140,8 +142,9 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject)
140142
/// \param [in] Index - Variable index. The index must be between 0 and the total number
141143
/// of variables in this shader stage as returned by
142144
/// IShaderResourceBinding::GetVariableCount().
143-
/// \remark Only mutable and dynamic variables can be accessed through this method.
144-
/// Static variables are accessed through the Shader object.
145+
///
146+
/// Only mutable and dynamic variables can be accessed through this method.
147+
/// Static variables are accessed through the Shader object.
145148
///
146149
/// \note This operation may potentially be expensive. If the variable will be used often, it is
147150
/// recommended to store and reuse the pointer as it never changes.

0 commit comments

Comments
 (0)