Go to the documentation of this file.
57 static constexpr
Uint32 InvalidImmutableSamplerIndex = ~0u;
64 const char* ResourceName,
65 const char* SamplerSuffix);
77 template <
typename EngineImplTraits>
82 using BaseInterface =
typename EngineImplTraits::PipelineResourceSignatureInterface;
109 bool bIsDeviceInternal =
false) :
122 for (
Uint32 i = 0; i < Desc.NumResources; ++i)
124 const auto& ResDesc = Desc.Resources[i];
138 Uint32 StaticVarStageIdx = 0;
141 const auto StageBit =
ExtractLSB(StaticResStages);
151 VERIFY(m_IsDestructed,
"This object must be explicitly destructed with Destruct()");
177 const Char* Name)
override final
197 Uint32 Index)
override final
239 bool InitStaticResources)
override final
242 auto& SRBAllocator{pThisImpl->m_pDevice->GetSRBAllocator()};
244 if (InitStaticResources)
245 pThisImpl->InitializeStaticSRBResources(pResBindingImpl);
246 pResBindingImpl->QueryInterface(IID_ShaderResourceBinding,
reinterpret_cast<IObject**
>(ppShaderResourceBinding));
254 auto*
const pSRBImpl = ValidatedCast<ShaderResourceBindingImplType>(pSRB);
255 if (pSRBImpl->StaticResourcesInitialized())
257 LOG_WARNING_MESSAGE(
"Static resources have already been initialized in this shader resource binding object.");
262 #ifdef DILIGENT_DEVELOPMENT
264 const auto* pSRBSignature = pSRBImpl->GetPipelineResourceSignature();
265 DEV_CHECK_ERR(pSRBSignature->IsCompatibleWith(pThisImpl),
"Shader resource binding is not compatible with resource signature '", pThisImpl->m_Desc.Name,
"'.");
269 auto& ResourceCache = pSRBImpl->GetResourceCache();
270 pThisImpl->CopyStaticResources(ResourceCache);
272 pSRBImpl->SetStaticResourcesInitialized();
285 const auto& Other = *ValidatedCast<const PipelineResourceSignatureImplType>(pPRS);
287 if (This.GetHash() != Other.GetHash())
293 const auto ResCount = This.GetTotalResourceCount();
294 VERIFY_EXPR(ResCount == Other.GetTotalResourceCount());
295 for (
Uint32 r = 0; r < ResCount; ++r)
297 const auto& Res = This.GetResourceAttribs(r);
298 const auto& OtherRes = Other.GetResourceAttribs(r);
299 if (!Res.IsCompatibleWith(OtherRes))
308 return GetHash() != Other.GetHash();
350 if (Index == StageIndex)
366 if ((ResDesc.ShaderStages & ShaderStage) != 0 && strcmp(ResDesc.Name, ResourceName) == 0)
396 if (pSign0 == pSign1)
399 bool IsNull0 = pSign0 ==
nullptr || pSign0->IsEmpty();
400 bool IsNull1 = pSign1 ==
nullptr || pSign1->IsEmpty();
401 if (IsNull0 && IsNull1)
404 if (IsNull0 != IsNull1)
407 VERIFY_EXPR(pSign0 !=
nullptr && pSign1 !=
nullptr);
408 return pSign0->IsCompatibleWith(pSign1);
418 template <
typename HandlerType>
422 HandlerType Handler)
const
424 if (AllowedVarTypes ==
nullptr)
427 for (
Uint32 TypeIdx = 0; TypeIdx < NumAllowedTypes; ++TypeIdx)
429 const auto IdxRange = AllowedVarTypes !=
nullptr ?
432 for (
Uint32 ResIdx = IdxRange.first; ResIdx < IdxRange.second; ++ResIdx)
435 VERIFY_EXPR(AllowedVarTypes ==
nullptr || ResDesc.VarType == AllowedVarTypes[TypeIdx]);
437 if ((ResDesc.ShaderStages & AllowedStages) != 0)
439 Handler(ResDesc, ResIdx);
451 template <
typename TReserveCustomData>
454 TReserveCustomData ReserveCustomData) noexcept(
false)
458 ReserveSpaceForDescription(Allocator, Desc);
461 if (NumStaticResStages > 0)
467 ReserveCustomData(Allocator);
473 CopyDescription(Allocator, Desc);
475 if (NumStaticResStages > 0)
480 "Constructor of ShaderVariableManagerImplType must be noexcept, so we can safely construct all manager objects");
497 VERIFY(Res.Name !=
nullptr,
"Name can't be null. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
498 VERIFY(Res.Name[0] !=
'\0',
"Name can't be empty. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
499 VERIFY(Res.ShaderStages !=
SHADER_TYPE_UNKNOWN,
"ShaderStages can't be SHADER_TYPE_UNKNOWN. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
500 VERIFY(Res.ArraySize != 0,
"ArraySize can't be 0. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
508 VERIFY(SamOrTexName !=
nullptr,
"SamplerOrTextureName can't be null. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
509 VERIFY(SamOrTexName[0] !=
'\0',
"SamplerOrTextureName can't be empty. This error should've been caught by ValidatePipelineResourceSignatureDesc().");
525 auto& DstRes = pResources[i];
528 VERIFY_EXPR(SrcRes.Name !=
nullptr && SrcRes.Name[0] !=
'\0');
529 DstRes.Name = Allocator.
CopyString(SrcRes.Name);
537 return lhs.VarType < rhs.VarType;
543 #ifdef DILIGENT_DEBUG
548 for (
Uint32 idx = IdxRange.first; idx < IdxRange.second; ++idx)
549 VERIFY(pResources[idx].VarType == VarType,
"Unexpected resource var type");
556 auto& DstSam = pSamplers[i];
559 VERIFY_EXPR(SrcSam.SamplerOrTextureName !=
nullptr && SrcSam.SamplerOrTextureName[0] !=
'\0');
560 DstSam.SamplerOrTextureName = Allocator.
CopyString(SrcSam.SamplerOrTextureName);
573 VERIFY(!m_IsDestructed,
"This object has already been destructed");
605 m_IsDestructed =
true;
615 Uint32 SamplerInd = InvalidSamplerValue;
620 for (
Uint32 i = IdxRange.first; i < IdxRange.second; ++i)
645 const auto& Attr = pThisImpl->GetResourceAttribs(i);
675 static_assert(MAX_SHADERS_IN_PIPELINE == 6,
"Please update the initializer list above");
680 #ifdef DILIGENT_DEBUG
681 bool m_IsDestructed =
false;
Implementation of a linear allocator on a fixed-size memory page.
Definition: FixedLinearAllocator.hpp:45
SHADER_TYPE m_StaticResShaderStages
Definition: PipelineResourceSignatureBase.hpp:668
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
bool IsUsingSeparateSamplers() const
Definition: PipelineResourceSignatureBase.hpp:318
virtual void InitializeStaticSRBResources(IShaderResourceBinding *pSRB) const override final
Implementation of IPipelineResourceSignature::InitializeStaticSRBResources.
Definition: PipelineResourceSignatureBase.hpp:250
PIPELINE_TYPE GetPipelineType() const
Definition: PipelineResourceSignatureBase.hpp:313
void ValidatePipelineResourceSignatureDesc(const PipelineResourceSignatureDesc &Desc, const DeviceFeatures &Features) noexcept(false)
Validates pipeline resource signature description and throws an exception in case of an error.
Definition: PipelineResourceSignatureBase.cpp:40
Definition: SRBMemoryAllocator.hpp:37
Uint32 GetNumActiveShaderStages() const
Definition: PipelineResourceSignatureBase.hpp:329
Shader resource variable.
Definition: ShaderResourceVariable.h:117
char Char
Definition: BasicTypes.h:64
@ Signature
Static resources of a pipeline resource signature.
Shader resource binding interface.
Definition: ShaderResourceBinding.h:58
struct DeviceFeatures DeviceFeatures
Definition: GraphicsTypes.h:1750
bool StreqSuff(const char *RefStr, const char *Str, const char *Suff, bool NoSuffixAllowed=false)
Definition: StringTools.hpp:110
Pipeline resource signature interface.
Definition: PipelineResourceSignature.h:226
Pipeline resource signature description.
Definition: PipelineResourceSignature.h:166
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
std::enable_if< std::is_integral< T >::value, T >::type ExtractLSB(T &bits)
Returns the least-signficant bit and clears it in the input argument.
Definition: BasicMath.hpp:2195
SHADER_TYPE ShaderStages
Shader stages that this resource applies to. When multiple shader stages are specified,...
Definition: PipelineResourceSignature.h:130
const PipelineResourceDesc * Resources
A pointer to an array of resource descriptions. See Diligent::PipelineResourceDesc.
Definition: PipelineResourceSignature.h:169
Uint32 FindResource(SHADER_TYPE ShaderStage, const char *ResourceName) const
Finds a resource with the given name in the specified shader stage and returns its index in m_Desc....
Definition: PipelineResourceSignatureBase.hpp:361
@ SHADER_RESOURCE_TYPE_TEXTURE_SRV
Shader resource view of a texture (sampled image)
Definition: Shader.h:365
Uint32 Flags
Definition: DXBCUtils.cpp:71
bool IsIncompatibleWith(const PipelineResourceSignatureImplType &Other) const
Definition: PipelineResourceSignatureBase.hpp:306
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
@ SHADER_RESOURCE_TYPE_SAMPLER
Sampler (separate sampler)
Definition: Shader.h:377
@ SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES
Total number of shader variable types.
Definition: ShaderResourceVariable.h:65
PIPELINE_TYPE
Pipeline type.
Definition: PipelineState.h:295
#define UNEXPECTED(...)
Definition: DebugUtilities.hpp:77
std::array< Int8, MAX_SHADERS_IN_PIPELINE > m_StaticResStageIndex
Definition: PipelineResourceSignatureBase.hpp:674
typename EngineGLImplTraits ::PipelineResourceSignatureImplType PipelineResourceSignatureImplType
Definition: PipelineResourceSignatureBase.hpp:97
const Char * SamplerOrTextureName
The name of the sampler itself or the name of the texture variable that this immutable sampler is ass...
Definition: PipelineResourceSignature.h:58
virtual IShaderResourceVariable * GetStaticVariableByIndex(SHADER_TYPE ShaderType, Uint32 Index) override final
Implementation of IPipelineResourceSignature::GetStaticVariableByIndex.
Definition: PipelineResourceSignatureBase.hpp:196
void Destruct()
Definition: PipelineResourceSignatureBase.hpp:571
PipelineResourceSignatureDesc m_Desc
Object description.
Definition: DeviceObjectBase.hpp:182
bool PipelineResourceSignaturesCompatible(const PipelineResourceSignatureDesc &Desc0, const PipelineResourceSignatureDesc &Desc1) noexcept
Returns true if two pipeline resource signature descriptions are compatible, and false otherwise.
Definition: PipelineResourceSignatureBase.cpp:328
virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final
Implementation of IPipelineResourceSignature::GetStaticVariableCount.
Definition: PipelineResourceSignatureBase.hpp:157
const Char * CombinedSamplerSuffix
If UseCombinedTextureSamplers is true, defines the suffix added to the texture variable name to get c...
Definition: PipelineResourceSignature.h:201
Uint32 FindAssignedSampler(const PipelineResourceDesc &Tex, Uint32 InvalidSamplerValue) const
Definition: PipelineResourceSignatureBase.hpp:612
NODISCARD T * ConstructArray(size_t count, const Args &... args)
Definition: FixedLinearAllocator.hpp:224
#define DEV_CHECK_ERR(...)
Definition: DebugUtilities.hpp:90
void CalculateHash()
Definition: PipelineResourceSignatureBase.hpp:638
struct PipelineResourceSignatureDesc PipelineResourceSignatureDesc
Definition: PipelineResourceSignature.h:209
Uint32 FindImmutableSampler(const ImmutableSamplerDesc *ImtblSamplers, Uint32 NumImtblSamplers, SHADER_TYPE ShaderStages, const char *ResourceName, const char *SamplerSuffix)
Finds an immutable sampler for the resource name 'ResourceName' that is defined in shader stages 'Sha...
Definition: PipelineResourceSignatureBase.cpp:294
const ImmutableSamplerDesc & GetImmutableSamplerDesc(Uint32 SampIndex) const
Definition: PipelineResourceSignatureBase.hpp:387
Uint32 NumResources
The number of resources in Resources array.
Definition: PipelineResourceSignature.h:172
DeviceObjectBase< BaseInterface, RenderDeviceImplType, PipelineResourceSignatureDesc > TDeviceObjectBase
Definition: PipelineResourceSignatureBase.hpp:99
SHADER_RESOURCE_VARIABLE_TYPE VarType
Resource variable type, see Diligent::SHADER_RESOURCE_VARIABLE_TYPE.
Definition: PipelineResourceSignature.h:139
Uint32 GetImmutableSamplerCount() const
Definition: PipelineResourceSignatureBase.hpp:321
void ProcessResources(const SHADER_RESOURCE_VARIABLE_TYPE *AllowedVarTypes, Uint32 NumAllowedTypes, SHADER_TYPE AllowedStages, HandlerType Handler) const
Definition: PipelineResourceSignatureBase.hpp:419
NODISCARD Char * CopyString(const char *Str)
Definition: FixedLinearAllocator.hpp:251
SHADER_TYPE GetActiveShaderStageType(Uint32 StageIndex) const
Definition: PipelineResourceSignatureBase.hpp:341
~PipelineResourceSignatureBase()
Definition: PipelineResourceSignatureBase.hpp:149
virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping *pResourceMapping, Uint32 Flags) override final
Implementation of IPipelineResourceSignature::BindStaticResources.
Definition: PipelineResourceSignatureBase.hpp:216
size_t GetHash() const
Definition: PipelineResourceSignatureBase.hpp:311
int8_t Int8
8-bit signed integer
Definition: BasicTypes.h:48
Uint32 NumImmutableSamplers
The number of immutable samplers in ImmutableSamplers array.
Definition: PipelineResourceSignature.h:178
Uint32 GetTotalResourceCount() const
Definition: PipelineResourceSignatureBase.hpp:320
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:51
const char * GetCombinedSamplerSuffix() const
Definition: PipelineResourceSignatureBase.hpp:315
bool IsConsistentShaderType(SHADER_TYPE ShaderType, PIPELINE_TYPE PipelineType)
Definition: GraphicsAccessories.cpp:1388
void AddSpace(size_t size, size_t alignment) noexcept
Definition: FixedLinearAllocator.hpp:106
#define IMPLEMENT_QUERY_INTERFACE_IN_PLACE(InterfaceID, ParentClassName)
Definition: ObjectBase.hpp:59
ShaderVariableManagerImplType * m_StaticVarsMgrs
Definition: PipelineResourceSignatureBase.hpp:657
Int32 GetShaderTypePipelineIndex(SHADER_TYPE ShaderType, PIPELINE_TYPE PipelineType)
Definition: GraphicsAccessories.cpp:1422
std::pair< Uint32, Uint32 > GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE VarType) const
Definition: PipelineResourceSignatureBase.hpp:323
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
SHADER_TYPE m_ShaderStages
Definition: PipelineResourceSignatureBase.hpp:665
PIPELINE_TYPE m_PipelineType
Definition: PipelineResourceSignatureBase.hpp:670
const PipelineResourceDesc & GetResourceDesc(Uint32 ResIndex) const
Definition: PipelineResourceSignatureBase.hpp:381
std::array< Uint16, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES+1 > m_ResourceOffsets
Definition: PipelineResourceSignatureBase.hpp:662
bool IsEmpty() const
Definition: PipelineResourceSignatureBase.hpp:445
Pipeline resource description.
Definition: PipelineResourceSignature.h:120
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
@ SHADER_TYPE_UNKNOWN
Unknown shader type.
Definition: GraphicsTypes.h:67
std::unique_ptr< void, STDDeleterRawMem< void > > m_pRawMemory
Definition: PipelineResourceSignatureBase.hpp:651
bool UseCombinedTextureSamplers
If set to true, textures will be combined with texture samplers. The CombinedSamplerSuffix member def...
Definition: PipelineResourceSignature.h:194
size_t m_Hash
Definition: PipelineResourceSignatureBase.hpp:659
void AddSpaceForString(const Char *str) noexcept
Definition: FixedLinearAllocator.hpp:141
bool IsUsingCombinedSamplers() const
Definition: PipelineResourceSignatureBase.hpp:317
typename EngineGLImplTraits ::PipelineResourceSignatureInterface BaseInterface
Definition: PipelineResourceSignatureBase.hpp:82
size_t CalculatePipelineResourceSignatureDescHash(const PipelineResourceSignatureDesc &Desc) noexcept
Calculates hash of the pipeline resource signature description.
Definition: PipelineResourceSignatureBase.cpp:359
SRBMemoryAllocator m_SRBMemAllocator
Definition: PipelineResourceSignatureBase.hpp:675
@ PIPELINE_TYPE_INVALID
Definition: PipelineState.h:312
Definition: STDAllocator.hpp:182
virtual bool IsCompatibleWith(const IPipelineResourceSignature *pPRS) const override final
Implementation of IPipelineResourceSignature::IsCompatibleWith.
Definition: PipelineResourceSignatureBase.hpp:276
SHADER_RESOURCE_TYPE ResourceType
Resource type, see Diligent::SHADER_RESOURCE_TYPE.
Definition: PipelineResourceSignature.h:136
SHADER_TYPE GetShaderTypeFromPipelineIndex(Int32 Index, PIPELINE_TYPE PipelineType)
Definition: GraphicsAccessories.cpp:1466
@ SHADER_RESOURCE_VARIABLE_TYPE_STATIC
Shader resource bound to the variable is the same for all SRB instances. It must be set once directly...
Definition: ShaderResourceVariable.h:52
Uint32 FindImmutableSampler(SHADER_TYPE ShaderStage, const char *ResourceName) const
Finds an immutable with the given name in the specified shader stage and returns its index in m_Desc....
Definition: PipelineResourceSignatureBase.hpp:375
virtual IShaderResourceVariable * GetStaticVariableByName(SHADER_TYPE ShaderType, const Char *Name) override final
Implementation of IPipelineResourceSignature::GetStaticVariableByName.
Definition: PipelineResourceSignatureBase.hpp:176
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
#define LOG_WARNING_MESSAGE(...)
Definition: Errors.hpp:123
static constexpr Uint32 InvalidResourceIndex
Definition: PipelineResourceSignatureBase.hpp:358
const char * Name
Resource name in the shader.
Definition: PipelineResourceSignature.h:123
typename EngineGLImplTraits ::ShaderResourceBindingImplType ShaderResourceBindingImplType
Definition: PipelineResourceSignatureBase.hpp:94
struct ImmutableSamplerDesc ImmutableSamplerDesc
Definition: PipelineResourceSignature.h:75
SRBMemoryAllocator & GetSRBMemoryAllocator()
Definition: PipelineResourceSignatureBase.hpp:411
PIPELINE_TYPE PipelineTypeFromShaderStages(SHADER_TYPE ShaderStages)
Definition: GraphicsAccessories.cpp:1528
virtual void CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding, bool InitStaticResources) override final
Implementation of IPipelineResourceSignature::CreateShaderResourceBinding.
Definition: PipelineResourceSignatureBase.hpp:238
const char * GetPipelineTypeString(PIPELINE_TYPE PipelineType)
Definition: GraphicsAccessories.cpp:1145
struct PipelineResourceDesc PipelineResourceDesc
Definition: PipelineResourceSignature.h:162
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
const Char * GetShaderTypeLiteralName(SHADER_TYPE ShaderType)
Returns the literal name of a shader type. For instance, for a pixel shader, "SHADER_TYPE_PIXEL" will...
Definition: GraphicsAccessories.cpp:476
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
const ImmutableSamplerDesc * ImmutableSamplers
A pointer to an array of immutable samplers. See Diligent::ImmutableSamplerDesc.
Definition: PipelineResourceSignature.h:175
typename EngineImplTraits::ShaderVariableManagerImplType ShaderVariableManagerImplType
Definition: PipelineResourceSignatureBase.hpp:91
Template class implementing base functionality of the pipeline resource signature object.
Definition: PipelineResourceSignatureBase.hpp:78
ShaderResourceCacheImplType * m_pStaticResCache
Definition: PipelineResourceSignatureBase.hpp:654
static bool SignaturesCompatible(const PipelineResourceSignatureImplType *pSign0, const PipelineResourceSignatureImplType *pSign1)
Definition: PipelineResourceSignatureBase.hpp:393
Uint16 ShaderType
Definition: DXBCUtils.cpp:70
PipelineResourceSignatureBase(IReferenceCounters *pRefCounters, RenderDeviceImplType *pDevice, const PipelineResourceSignatureDesc &Desc, bool bIsDeviceInternal=false)
Definition: PipelineResourceSignatureBase.hpp:106
typename EngineImplTraits::ShaderResourceCacheImplType ShaderResourceCacheImplType
Definition: PipelineResourceSignatureBase.hpp:88
void HashCombine(std::size_t &Seed, const T &Val)
Definition: HashUtils.hpp:44
typename EngineGLImplTraits ::RenderDeviceImplType RenderDeviceImplType
Definition: PipelineResourceSignatureBase.hpp:85
FixedLinearAllocator AllocateInternalObjects(IMemoryAllocator &RawAllocator, const PipelineResourceSignatureDesc &Desc, TReserveCustomData ReserveCustomData) noexcept(false)
Definition: PipelineResourceSignatureBase.hpp:452
#define NEW_RC_OBJ(Allocator, Desc, Type,...)
Definition: RefCountedObjectImpl.hpp:698
const Char * Name
Object name.
Definition: GraphicsTypes.h:1199
Template class implementing base functionality of the device object.
Definition: DeviceObjectBase.hpp:45
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Uint32 GetNumStaticResStages() const
Definition: PipelineResourceSignatureBase.hpp:335
SHADER_RESOURCE_VARIABLE_TYPE
Describes the type of the shader resource variable.
Definition: ShaderResourceVariable.h:48
Resouce mapping.
Definition: ResourceMapping.h:107
Immutable sampler description.
Definition: PipelineResourceSignature.h:51