Skip to content

Commit 5924c09

Browse files
Updated Shader Binding Table documentation
ShaderBindingTableBase: don't use auto where unnecessary
1 parent 3d527cc commit 5924c09

File tree

3 files changed

+63
-49
lines changed

3 files changed

+63
-49
lines changed

Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 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");
@@ -81,7 +81,7 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
8181
bool bIsDeviceInternal = false) :
8282
TDeviceObjectBase{pRefCounters, pDevice, Desc, bIsDeviceInternal}
8383
{
84-
const auto& RTProps = this->GetDevice()->GetAdapterInfo().RayTracing;
84+
const RayTracingProperties& RTProps = this->GetDevice()->GetAdapterInfo().RayTracing;
8585
if (!this->GetDevice()->GetFeatures().RayTracing)
8686
LOG_ERROR_AND_THROW("Ray tracing is not supported by device");
8787

@@ -113,7 +113,7 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
113113

114114
this->m_Desc.pPSO = pPSO;
115115

116-
const auto& RayTracingProps = this->GetDevice()->GetAdapterInfo().RayTracing;
116+
const RayTracingProperties& RayTracingProps = this->GetDevice()->GetAdapterInfo().RayTracing;
117117
try
118118
{
119119
ValidateShaderBindingTableDesc(this->m_Desc, RayTracingProps.ShaderGroupHandleSize, RayTracingProps.MaxShaderRecordStride);
@@ -205,9 +205,9 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
205205
VERIFY_EXPR((pData == nullptr) || (DataSize == this->m_ShaderRecordSize));
206206
VERIFY_EXPR(pTLAS != nullptr);
207207

208-
auto* const pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
209-
const auto Info = pTLASImpl->GetBuildInfo();
210-
const auto Desc = pTLASImpl->GetInstanceDesc(pInstanceName);
208+
TopLevelASImplType* const pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
209+
const TLASBuildInfo Info = pTLASImpl->GetBuildInfo();
210+
const TLASInstanceDesc Desc = pTLASImpl->GetInstanceDesc(pInstanceName);
211211

212212
VERIFY_EXPR(Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_GEOMETRY);
213213
VERIFY_EXPR(RayOffsetInHitGroupIndex < Info.HitGroupStride);
@@ -247,9 +247,9 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
247247
VERIFY_EXPR((pData == nullptr) || (DataSize == this->m_ShaderRecordSize));
248248
VERIFY_EXPR(pTLAS != nullptr);
249249

250-
auto* const pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
251-
const auto Info = pTLASImpl->GetBuildInfo();
252-
const auto Desc = pTLASImpl->GetInstanceDesc(pInstanceName);
250+
TopLevelASImplType* const pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
251+
const TLASBuildInfo Info = pTLASImpl->GetBuildInfo();
252+
const TLASInstanceDesc Desc = pTLASImpl->GetInstanceDesc(pInstanceName);
253253

254254
VERIFY_EXPR(Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_GEOMETRY ||
255255
Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_INSTANCE);
@@ -303,8 +303,8 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
303303
VERIFY_EXPR((pData == nullptr) || (DataSize == this->m_ShaderRecordSize));
304304
VERIFY_EXPR(pTLAS != nullptr);
305305

306-
auto* pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
307-
const auto Info = pTLASImpl->GetBuildInfo();
306+
TopLevelASImplType* pTLASImpl = ClassPtrCast<TopLevelASImplType>(pTLAS);
307+
const TLASBuildInfo Info = pTLASImpl->GetBuildInfo();
308308
VERIFY_EXPR(Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_GEOMETRY ||
309309
Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_INSTANCE ||
310310
Info.BindingMode == HIT_GROUP_BINDING_MODE_PER_TLAS);
@@ -353,9 +353,9 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
353353
#ifdef DILIGENT_DEVELOPMENT
354354
static_assert(EmptyElem != 0, "must not be zero");
355355

356-
const auto Stride = this->m_ShaderRecordStride;
357-
const auto ShSize = this->GetDevice()->GetAdapterInfo().RayTracing.ShaderGroupHandleSize;
358-
const auto FindPattern = [&](const std::vector<Uint8>& Data, const char* GroupName) -> bool //
356+
const Uint32 Stride = this->m_ShaderRecordStride;
357+
const Uint32 ShSize = this->GetDevice()->GetAdapterInfo().RayTracing.ShaderGroupHandleSize;
358+
const auto FindPattern = [&](const std::vector<Uint8>& Data, const char* GroupName) -> bool //
359359
{
360360
for (size_t i = 0; i < Data.size(); i += Stride)
361361
{
@@ -399,8 +399,8 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
399399
{
400400
for (size_t i = 0; i < m_DbgHitGroupBindings.size(); ++i)
401401
{
402-
auto& Binding = m_DbgHitGroupBindings[i];
403-
auto pTLAS = Binding.pTLAS.Lock();
402+
HitGroupBinding& Binding = m_DbgHitGroupBindings[i];
403+
RefCntAutoPtr<TopLevelASImplType> pTLAS = Binding.pTLAS.Lock();
404404
if (!Binding.IsBound)
405405
{
406406
LOG_INFO_MESSAGE("Shader binding table '", this->m_Desc.Name, "' is not valid: hit group at index (", i, ") is not bound.");
@@ -449,7 +449,7 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
449449
BindingTable& HitShaderBindingTable,
450450
BindingTable& CallableShaderBindingTable)
451451
{
452-
const auto ShaderGroupBaseAlignment = this->GetDevice()->GetAdapterInfo().RayTracing.ShaderGroupBaseAlignment;
452+
const Uint32 ShaderGroupBaseAlignment = this->GetDevice()->GetAdapterInfo().RayTracing.ShaderGroupBaseAlignment;
453453

454454
const auto AlignToLarger = [ShaderGroupBaseAlignment](size_t offset) -> Uint32 {
455455
return AlignUp(static_cast<Uint32>(offset), ShaderGroupBaseAlignment);
@@ -552,7 +552,7 @@ class ShaderBindingTableBase : public DeviceObjectBase<typename EngineImplTraits
552552
{
553553
this->m_DbgHitGroupBindings.resize(std::max(this->m_DbgHitGroupBindings.size(), Index + 1));
554554

555-
auto& Binding = this->m_DbgHitGroupBindings[Index];
555+
HitGroupBinding& Binding{this->m_DbgHitGroupBindings[Index]};
556556
Binding.pTLAS = pTLAS;
557557
Binding.Version = pTLAS ? pTLAS->GetVersion() : ~0u;
558558
Binding.IsBound = true;

Graphics/GraphicsEngine/interface/ShaderBindingTable.h

Lines changed: 42 additions & 28 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");
@@ -98,29 +98,35 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
9898
/// \param [in] Flags - Flags that specify which type of validation to perform.
9999
/// \return True if SBT content is valid, and false otherwise.
100100
///
101+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
102+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
103+
///
104+
/// This method is only implemented in development build and has no effect in release build.
105+
///
101106
/// \note Access to the SBT must be externally synchronized.
102-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
103-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
104-
/// This method is only implemented in development build and has no effect in release build.
105107
VIRTUAL Bool METHOD(Verify)(THIS_
106108
VERIFY_SBT_FLAGS Flags) CONST PURE;
107109

108110

109111
/// Resets the SBT with the new pipeline state. This is more efficient than creating a new SBT.
110112

113+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
114+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
115+
///
111116
/// \note Access to the SBT must be externally synchronized.
112-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
113-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
114117
VIRTUAL void METHOD(Reset)(THIS_
115118
IPipelineState* pPSO) PURE;
116119

117120

121+
/// Resets hit groups in the SBT.
122+
118123
/// After TLAS or BLAS was rebuilt or updated, hit group shader bindings may have become invalid,
119124
/// you can reset hit groups only and keep ray-gen, miss and callable shader bindings intact.
120-
125+
///
126+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
127+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
128+
///
121129
/// \note Access to the SBT must be externally synchronized.
122-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
123-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
124130
VIRTUAL void METHOD(ResetHitGroups)(THIS) PURE;
125131

126132

@@ -131,9 +137,10 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
131137
/// \param [in] pData - Shader record data, can be null.
132138
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
133139
///
140+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
141+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
142+
///
134143
/// \note Access to the SBT must be externally synchronized.
135-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
136-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
137144
VIRTUAL void METHOD(BindRayGenShader)(THIS_
138145
const Char* pShaderGroupName,
139146
const void* pData DEFAULT_INITIALIZER(nullptr),
@@ -150,9 +157,10 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
150157
/// \param [in] pData - Shader record data, can be null.
151158
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
152159
///
160+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
161+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
162+
///
153163
/// \note Access to the SBT must be externally synchronized.
154-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
155-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
156164
VIRTUAL void METHOD(BindMissShader)(THIS_
157165
const Char* pShaderGroupName,
158166
Uint32 MissIndex,
@@ -178,11 +186,13 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
178186
/// \param [in] pData - Shader record data, can be null.
179187
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
180188
///
181-
/// \note Access to the SBT must be externally synchronized.
182-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
183-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
184-
/// Access to the TLAS must be externally synchronized.
185-
/// Access to the BLAS that was used in the TLAS instance with name pInstanceName must be externally synchronized.
189+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
190+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
191+
///
192+
/// \note
193+
/// Access to the BLAS that was used in the TLAS instance with name pInstanceName must be externally synchronized.\n
194+
/// Access to the TLAS must be externally synchronized.\n
195+
/// Access to the SBT must be externally synchronized.
186196
VIRTUAL void METHOD(BindHitGroupForGeometry)(THIS_
187197
ITopLevelAS* pTLAS,
188198
const Char* pInstanceName,
@@ -202,12 +212,13 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
202212
/// \param [in] pData - Shader record data, can be null.
203213
/// \param [in] DataSize - Shader record data size, should equal to RayTracingPipelineDesc::ShaderRecordSize.
204214
///
205-
/// \note Access to the SBT must be externally synchronized.
206-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
207-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
215+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
216+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
208217
///
209218
/// \remarks Use IBottomLevelAS::GetGeometryIndex(), ITopLevelAS::GetBuildInfo(),
210219
/// ITopLevelAS::GetInstanceDesc().ContributionToHitGroupIndex to calculate the binding index.
220+
///
221+
/// \note Access to the SBT must be externally synchronized.
211222
VIRTUAL void METHOD(BindHitGroupByIndex)(THIS_
212223
Uint32 BindingIndex,
213224
const Char* pShaderGroupName,
@@ -230,9 +241,10 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
230241
/// \param [in] pData - Shader record data, can be null.
231242
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
232243
///
244+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
245+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
246+
///
233247
/// \note Access to the SBT and TLAS must be externally synchronized.
234-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
235-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
236248
VIRTUAL void METHOD(BindHitGroupForInstance)(THIS_
237249
ITopLevelAS* pTLAS,
238250
const Char* pInstanceName,
@@ -255,9 +267,10 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
255267
/// \param [in] pData - Shader record data, can be null.
256268
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
257269
///
258-
/// \note Access to the SBT and TLAS must be externally synchronized.
259-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
260-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
270+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
271+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
272+
///
273+
/// \note Access to the SBT and TLAS must be externally synchronized.
261274
VIRTUAL void METHOD(BindHitGroupForTLAS)(THIS_
262275
ITopLevelAS* pTLAS,
263276
Uint32 RayOffsetInHitGroupIndex,
@@ -276,9 +289,10 @@ DILIGENT_BEGIN_INTERFACE(IShaderBindingTable, IDeviceObject)
276289
/// \param [in] pData - Shader record data, can be null.
277290
/// \param [in] DataSize - Shader record data size, should be equal to RayTracingPipelineDesc::ShaderRecordSize.
278291
///
292+
/// The function does not modify the data used by IDeviceContext::TraceRays() and
293+
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
294+
///
279295
/// \note Access to the SBT must be externally synchronized.
280-
/// The function does not modify the data used by IDeviceContext::TraceRays() and
281-
/// IDeviceContext::TraceRaysIndirect() commands, so they can run in parallel.
282296
VIRTUAL void METHOD(BindCallableShader)(THIS_
283297
const Char* pShaderGroupName,
284298
Uint32 CallableIndex,

Graphics/GraphicsEngine/src/ShaderBindingTableBase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 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");
@@ -45,8 +45,8 @@ void ValidateShaderBindingTableDesc(const ShaderBindingTableDesc& Desc, Uint32 S
4545
}
4646

4747

48-
const auto ShaderRecordSize = Desc.pPSO->GetRayTracingPipelineDesc().ShaderRecordSize;
49-
const auto ShaderRecordStride = ShaderRecordSize + ShaderGroupHandleSize;
48+
const Uint32 ShaderRecordSize = Desc.pPSO->GetRayTracingPipelineDesc().ShaderRecordSize;
49+
const Uint32 ShaderRecordStride = ShaderRecordSize + ShaderGroupHandleSize;
5050

5151
if (ShaderRecordStride > MaxShaderRecordStride)
5252
{

0 commit comments

Comments
 (0)