Go to the documentation of this file.
44 template <
typename TNameCompare>
49 TNameCompare NameCompare)
51 for (
Uint32 v = 0; v < NumVars; ++v)
53 const auto& CurrVarDesc = Variables[v];
54 if (((CurrVarDesc.ShaderStages & ShaderStage) != 0) && NameCompare(CurrVarDesc.Name))
56 return CurrVarDesc.
Type;
59 return DefaultVariableType;
69 [&](
const char* VarName)
71 return strcmp(VarName, Name) == 0;
89 [&](
const char* VarName)
91 return Name.compare(VarName) == 0;
104 return ((1 << VarType) & AllowedTypeBits) != 0;
109 return 1 <<
static_cast<Uint32>(VarType);
114 if (AllowedVarTypes ==
nullptr)
117 Uint32 AllowedTypeBits = 0;
118 for (
Uint32 i = 0; i < NumAllowedTypes; ++i)
120 return AllowedTypeBits;
123 template <
typename BufferImplType>
127 const BufferImplType* pBufferImpl,
129 const char* SignatureName)
131 if (pBuffer !=
nullptr && pBufferImpl ==
nullptr)
133 std::stringstream ss;
135 if (SignatureName !=
nullptr)
137 ss <<
" defined by signature '" << SignatureName <<
'\'';
139 ss <<
". Invalid resource type: buffer is expected.";
144 bool BindingOK =
true;
145 if (pBufferImpl !=
nullptr)
147 const auto& BuffDesc = pBufferImpl->GetDesc();
150 std::stringstream ss;
151 ss <<
"Error binding buffer '" << BuffDesc.Name <<
"' to variable '" <<
GetShaderResourcePrintName(ResDesc, ArrayIndex) <<
'\'';
152 if (SignatureName !=
nullptr)
154 ss <<
" defined by signature '" << SignatureName <<
'\'';
156 ss <<
". The buffer was not created with BIND_UNIFORM_BUFFER flag.";
163 std::stringstream ss;
164 ss <<
"Error binding USAGE_DYNAMIC buffer '" << BuffDesc.Name <<
"' to variable '" <<
GetShaderResourcePrintName(ResDesc, ArrayIndex) <<
'\'';
165 if (SignatureName !=
nullptr)
167 ss <<
" defined by signature '" << SignatureName <<
'\'';
169 ss <<
". The variable was initialized with PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS flag.";
179 std::stringstream ss;
180 ss <<
"Non-null constant (uniform) buffer '" << pCachedBuffer->
GetDesc().
Name <<
"' is already bound to " << VarTypeStr
182 if (SignatureName !=
nullptr)
184 ss <<
" defined by signature '" << SignatureName <<
'\'';
186 ss <<
". Attempting to bind ";
189 ss <<
"another resource ('" << pBufferImpl->GetDesc().Name <<
"')";
195 ss <<
" is an error and may cause unpredicted behavior.";
198 ss <<
" Use another shader resource binding instance or label the variable as dynamic.";
208 template <
typename TViewTypeEnum>
214 return "texture view";
220 return "buffer view";
247 template <
typename TextureViewImplType>
251 const TextureViewImplType* pViewImpl,
255 bool BindingsOK =
true;
260 if (ResourceDim != ExpectedResourceDim)
264 ", but resource dimension expected by the shader is ",
GetResourceDimString(ExpectedResourceDim),
".");
270 if (IsMultisample && SampleCount == 1)
272 LOG_ERROR_MESSAGE(
"Texture view '", pViewImpl->GetDesc().Name,
"' bound to variable '",
276 else if (!IsMultisample && SampleCount > 1)
278 LOG_ERROR_MESSAGE(
"Texture view '", pViewImpl->GetDesc().Name,
"' bound to variable '",
289 template <
typename ResourceViewImplType,
290 typename ViewTypeEnumType>
294 const ResourceViewImplType* pViewImpl,
295 std::initializer_list<ViewTypeEnumType> ExpectedViewTypes,
299 const char* SignatureName)
301 const char* ExpectedResourceType = GetResourceTypeName<ViewTypeEnumType>();
303 if (pView !=
nullptr && pViewImpl ==
nullptr)
305 std::stringstream ss;
307 if (SignatureName !=
nullptr)
309 ss <<
" defined by signature '" << SignatureName <<
'\'';
311 ss <<
". Invalid resource type: " << ExpectedResourceType <<
" is expected.";
316 bool BindingOK =
true;
319 auto ViewType = pViewImpl->GetDesc().ViewType;
320 bool IsExpectedViewType =
false;
321 for (
auto ExpectedViewType : ExpectedViewTypes)
323 if (ExpectedViewType == ViewType)
324 IsExpectedViewType =
true;
327 if (!IsExpectedViewType)
329 std::stringstream ss;
330 ss <<
"Error binding " << ExpectedResourceType <<
" '" << pViewImpl->GetDesc().Name <<
"' to variable '"
332 if (SignatureName !=
nullptr)
334 ss <<
" defined by signature '" << SignatureName <<
'\'';
336 ss <<
". Incorrect view type: ";
337 bool IsFirstViewType =
true;
338 for (
auto ExpectedViewType : ExpectedViewTypes)
340 if (!IsFirstViewType)
345 IsFirstViewType =
false;
363 std::stringstream ss;
364 ss <<
"Non-null resource '" << pCachedView->
GetDesc().
Name <<
"' is already bound to " << VarTypeStr
366 if (SignatureName !=
nullptr)
368 ss <<
" defined by signature '" << SignatureName <<
'\'';
370 ss <<
". Attempting to bind ";
373 ss <<
"another resource ('" << pViewImpl->GetDesc().Name <<
"')";
379 ss <<
" is an error and may cause unpredicted behavior.";
382 ss <<
" Use another shader resource binding instance or label the variable as dynamic.";
392 template <
typename BufferViewImplType>
395 const BufferViewImplType* pBufferView)
397 bool BindingOK =
true;
398 if (pBufferView !=
nullptr)
400 const auto& BuffDesc = pBufferView->GetBuffer()->GetDesc();
405 LOG_ERROR_MESSAGE(
"Error binding buffer view '", pBufferView->GetDesc().Name,
"' of buffer '", BuffDesc.Name,
"' to shader variable '",
414 LOG_ERROR_MESSAGE(
"Error binding buffer view '", pBufferView->GetDesc().Name,
"' of buffer '", BuffDesc.Name,
"' to shader variable '",
425 template <
typename TLASImplType>
429 const TLASImplType* pTLASImpl,
431 const char* SignatureName)
433 if (pTLAS !=
nullptr && pTLASImpl ==
nullptr)
435 std::stringstream ss;
437 if (SignatureName !=
nullptr)
439 ss <<
" defined by signature '" << SignatureName <<
'\'';
441 ss <<
". Invalid resource type: TLAS is expected.";
446 bool BindingOK =
true;
452 std::stringstream ss;
453 ss <<
"Non-null resource '" << pCachedAS->
GetDesc().
Name <<
"' is already bound to " << VarTypeStr
455 if (SignatureName !=
nullptr)
457 ss <<
" defined by signature '" << SignatureName <<
'\'';
459 ss <<
". Attempting to bind ";
462 ss <<
"another resource ('" << pTLAS->
GetDesc().
Name <<
"')";
468 ss <<
" is an error and may cause unpredicted behavior.";
471 ss <<
" Use another shader resource binding instance or label the variable as dynamic.";
483 if (FirstElement >= ArraySize)
485 LOG_ERROR_MESSAGE(
"SetArray arguments are invalid for '", Name,
"' variable: FirstElement (", FirstElement,
") is out of allowed range 0 .. ", ArraySize - 1);
486 FirstElement = ArraySize - 1;
490 if (FirstElement + NumElements > ArraySize)
492 LOG_ERROR_MESSAGE(
"SetArray arguments are invalid for '", Name,
"' variable: specified element range (", FirstElement,
" .. ",
493 FirstElement + NumElements - 1,
") is out of array bounds 0 .. ", ArraySize - 1);
494 NumElements = ArraySize - FirstElement;
498 template <
typename ShaderVectorType>
502 if (Shaders.size() == 1)
504 Name = Shaders[0]->GetDesc().Name;
509 for (
size_t s = 0; s < Shaders.size(); ++s)
513 Name += Shaders[s]->GetDesc().Name;
521 template <
typename ThisImplType,
522 typename VarManagerType,
523 typename ResourceVariableBaseInterface = IShaderResourceVariable>
534 if (ppInterface ==
nullptr)
537 *ppInterface =
nullptr;
538 if (IID == IID_ShaderResourceVariable || IID == IID_Unknown)
562 static_cast<ThisImplType*
>(
this)->BindResource(pObject, 0);
567 Uint32 NumElements)
override final
571 for (
Uint32 elem = 0; elem < NumElements; ++elem)
572 static_cast<ThisImplType*
>(
this)->BindResource(ppObjects[elem], FirstElement + elem);
583 ResourceDesc.Name = Desc.Name;
584 ResourceDesc.Type = Desc.ResourceType;
585 ResourceDesc.ArraySize = Desc.ArraySize;
590 return m_ParentManager.GetVariableIndex(*
static_cast<const ThisImplType*
>(
this));
595 auto*
const pThis =
static_cast<ThisImplType*
>(
this);
597 const auto& ResDesc = pThis->GetDesc();
599 if ((
Flags & (1u << ResDesc.VarType)) == 0)
602 for (
Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
608 pResourceMapping->
GetResource(ResDesc.Name, &pObj, ArrInd);
611 pThis->BindResource(pObj, ArrInd);
619 "': resource is not found in the resource mapping. "
620 "Do not use BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED flag to suppress the message if this is not an issue.");
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Uint32 NumVariables
Number of elements in Variables array
Definition: PipelineState.h:111
#define LOG_ERROR_MESSAGE(...)
Definition: Errors.hpp:122
long Long
Definition: BasicAtomics.hpp:34
Base implementation of a shader variable.
Definition: ShaderResourceVariableBase.hpp:524
char Char
Definition: BasicTypes.h:64
@ RESOURCE_DIM_TEX_2D_ARRAY
Two-dimensional texture array.
Definition: GraphicsTypes.h:263
const char * GetResourceTypeName()
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
virtual Atomics::Long AddRef() override final
Definition: ShaderResourceVariableBase.hpp:545
const ShaderResourceVariableDesc * Variables
Array of shader resource variable descriptions
Definition: PipelineState.h:117
Uint32 Flags
Definition: DXBCUtils.cpp:71
@ RESOURCE_DIM_BUFFER
Buffer.
Definition: GraphicsTypes.h:259
Uint32 ArraySize
Resource array size (must be 1 for non-array resources).
Definition: PipelineResourceSignature.h:133
bool IsAllowedType(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 AllowedTypeBits) noexcept
Definition: ShaderResourceVariableBase.hpp:102
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
Uint32 GetAllowedTypeBits(const SHADER_RESOURCE_VARIABLE_TYPE *AllowedVarTypes, Uint32 NumAllowedTypes) noexcept
Definition: ShaderResourceVariableBase.hpp:112
virtual const TextureViewDesc &METHOD() GetDesc() const override=0
Returns the texture view description used to create the object.
@ SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC
Shader variable binding is dynamic. It can be set multiple times for every instance of shader resourc...
Definition: ShaderResourceVariable.h:62
bool ValidateBufferMode(const PipelineResourceDesc &ResDesc, Uint32 ArrayIndex, const BufferViewImplType *pBufferView)
Definition: ShaderResourceVariableBase.hpp:393
const Char * GetViewTypeLiteralName(TEXTURE_VIEW_TYPE TexViewType)
Overloaded function that returns the literal name of a texture view type. see GetTexViewTypeLiteralNa...
Definition: GraphicsAccessories.hpp:244
@ PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER
Indicates that this variable will be used to bind formatted buffers. Applies to SHADER_RESOURCE_TYPE_...
Definition: PipelineResourceSignature.h:109
Texture view interface.
Definition: TextureView.h:202
virtual Atomics::Long Release() override final
Definition: ShaderResourceVariableBase.hpp:550
@ USAGE_DYNAMIC
A resource that can be read by the GPU and written at least once per frame by the CPU....
Definition: GraphicsTypes.h:161
RESOURCE_DIMENSION GetResourceViewDimension(const ITextureView *pTexView)
Definition: ShaderResourceVariableBase.hpp:223
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:52
Unique interface identifier.
Definition: InterfaceID.h:37
virtual SHADER_RESOURCE_VARIABLE_TYPE GetType() const override final
Definition: ShaderResourceVariableBase.hpp:575
String GetShaderResourcePrintName(const char *Name, Uint32 ArraySize, Uint32 ArrayIndex)
Definition: GraphicsAccessories.hpp:622
virtual IReferenceCounters * GetReferenceCounters() const override final
Definition: ShaderResourceVariableBase.hpp:555
SHADER_RESOURCE_VARIABLE_TYPE VarType
Resource variable type, see Diligent::SHADER_RESOURCE_VARIABLE_TYPE.
Definition: PipelineResourceSignature.h:139
std::string GetShaderGroupName(const ShaderVectorType &Shaders)
Definition: ShaderResourceVariableBase.hpp:499
const PipelineResourceDesc & GetDesc() const
Definition: ShaderResourceVariableBase.hpp:626
virtual ReferenceCounterValueType AddRef()=0
Increments the number of strong references by 1.
@ SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE
Shader resource bound to the variable is specific to the shader resource binding instance (see Dilige...
Definition: ShaderResourceVariable.h:58
@ BIND_UNIFORM_BUFFER
A buffer can be bound as a uniform buffer.
Definition: GraphicsTypes.h:120
virtual Uint32 GetIndex() const override final
Definition: ShaderResourceVariableBase.hpp:588
bool ValidateResourceViewDimension(const char *ResName, Uint32 ArraySize, Uint32 ArrayInd, const TextureViewImplType *pViewImpl, RESOURCE_DIMENSION ExpectedResourceDim, bool IsMultisample)
Definition: ShaderResourceVariableBase.hpp:248
virtual const DeviceObjectAttribs &METHOD() GetDesc() const
Returns the object description.
const char * GetResourceTypeName< BUFFER_VIEW_TYPE >()
Definition: ShaderResourceVariableBase.hpp:218
bool VerifyResourceViewBinding(const PipelineResourceDesc &ResDesc, Uint32 ArrayIndex, const IDeviceObject *pView, const ResourceViewImplType *pViewImpl, std::initializer_list< ViewTypeEnumType > ExpectedViewTypes, RESOURCE_DIMENSION ExpectedResourceDimension, bool IsMultisample, const IDeviceObject *pCachedView, const char *SignatureName)
Definition: ShaderResourceVariableBase.hpp:291
Describes shader variable.
Definition: PipelineState.h:76
@ BUFFER_MODE_FORMATTED
Formated buffer. Access to the buffer will use format conversion operations. In this mode,...
Definition: Buffer.h:56
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
@ BIND_SHADER_RESOURCES_KEEP_EXISTING
If this flag is specified, all existing bindings will be preserved and only unresolved ones will be u...
Definition: ShaderResourceVariable.h:94
@ RESOURCE_DIM_UNDEFINED
Texture type undefined.
Definition: GraphicsTypes.h:258
const char * GetResourceTypeName< TEXTURE_VIEW_TYPE >()
Definition: ShaderResourceVariableBase.hpp:212
void VerifyAndCorrectSetArrayArguments(const char *Name, Uint32 ArraySize, Uint32 &FirstElement, Uint32 &NumElements)
Definition: ShaderResourceVariableBase.hpp:481
Pipeline resource description.
Definition: PipelineResourceSignature.h:120
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
virtual void GetResourceDesc(ShaderResourceDesc &ResourceDesc) const override final
Definition: ShaderResourceVariableBase.hpp:580
SHADER_RESOURCE_VARIABLE_TYPE Type
Shader variable type. See Diligent::SHADER_RESOURCE_VARIABLE_TYPE for a list of allowed types.
Definition: PipelineState.h:87
bool VerifyTLASResourceBinding(const PipelineResourceDesc &ResDesc, Uint32 ArrayIndex, const IDeviceObject *pTLAS, const TLASImplType *pTLASImpl, const IDeviceObject *pCachedAS, const char *SignatureName)
Definition: ShaderResourceVariableBase.hpp:426
RESOURCE_DIMENSION TextureDim
View interpretation of the original texture. For instance, one slice of a 2D texture array can be vie...
Definition: TextureView.h:90
bool VerifyConstantBufferBinding(const PipelineResourceDesc &ResDesc, Uint32 ArrayIndex, const IDeviceObject *pBuffer, const BufferImplType *pBufferImpl, const IDeviceObject *pCachedBuffer, const char *SignatureName)
Definition: ShaderResourceVariableBase.hpp:124
SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage, SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType, const ShaderResourceVariableDesc *Variables, Uint32 NumVars, TNameCompare NameCompare)
Definition: ShaderResourceVariableBase.hpp:45
@ RESOURCE_DIM_TEX_2D
Two-dimensional texture.
Definition: GraphicsTypes.h:262
virtual void SetArray(IDeviceObject *const *ppObjects, Uint32 FirstElement, Uint32 NumElements) override final
Definition: ShaderResourceVariableBase.hpp:565
void BindResources(IResourceMapping *pResourceMapping, Uint32 Flags)
Definition: ShaderResourceVariableBase.hpp:593
Uint32 GetResourceSampleCount(const ITextureView *pTexView)
Definition: ShaderResourceVariableBase.hpp:234
const char * Name
Resource name in the shader.
Definition: PipelineResourceSignature.h:123
Shader resource description.
Definition: Shader.h:390
const Char * GetShaderVariableTypeLiteralName(SHADER_RESOURCE_VARIABLE_TYPE VarType, bool bGetFullName=false)
Returns the literal name of a shader variable type. For instance, for SHADER_RESOURCE_VARIABLE_TYPE_S...
Definition: GraphicsAccessories.cpp:524
@ BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED
If this flag is specified, all shader bindings are expected to be resolved after the call....
Definition: ShaderResourceVariable.h:102
std::basic_string< Char > String
String variable.
Definition: BasicTypes.h:66
const Uint32 m_ResIndex
Definition: ShaderResourceVariableBase.hpp:633
@ PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS
Indicates that dynamic buffers will never be bound to the resource variable. Applies to SHADER_RESOUR...
Definition: PipelineResourceSignature.h:95
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
Uint32 GetAllowedTypeBit(SHADER_RESOURCE_VARIABLE_TYPE VarType)
Definition: ShaderResourceVariableBase.hpp:107
virtual void Set(IDeviceObject *pObject) override final
Definition: ShaderResourceVariableBase.hpp:560
@ BUFFER_MODE_STRUCTURED
Structured buffer. In this mode, ElementByteStride member of BufferDesc defines the structure stride.
Definition: Buffer.h:60
virtual void METHOD() GetResource(const Char *Name, IDeviceObject **ppResource, Uint32 ArrayIndex=0)
Finds a resource in the mapping.
@ BUFFER_MODE_RAW
Raw buffer. In this mode, the buffer is accessed as raw bytes. Formatted views of a raw buffer can al...
Definition: Buffer.h:67
RESOURCE_DIMENSION
Describes resource dimension.
Definition: GraphicsTypes.h:256
Buffer view interface.
Definition: BufferView.h:155
PIPELINE_RESOURCE_FLAGS Flags
Special resource flags, see Diligent::PIPELINE_RESOURCE_FLAGS.
Definition: PipelineResourceSignature.h:142
virtual void QueryInterface(const INTERFACE_ID &IID, IObject **ppInterface) override
Definition: ShaderResourceVariableBase.hpp:532
ShaderVariableBase(VarManagerType &ParentManager, Uint32 ResIndex)
Definition: ShaderResourceVariableBase.hpp:526
const Char * GetResourceDimString(RESOURCE_DIMENSION TexType)
Returns the string containing the texture type.
Definition: GraphicsAccessories.cpp:804
SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType
Default shader resource variable type. This type will be used if shader variable description is not f...
Definition: PipelineState.h:108
Pipeline layout description.
Definition: PipelineState.h:103
const Char * Name
Object name.
Definition: GraphicsTypes.h:1199
VarManagerType & m_ParentManager
Definition: ShaderResourceVariableBase.hpp:630
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
SHADER_RESOURCE_VARIABLE_TYPE
Describes the type of the shader resource variable.
Definition: ShaderResourceVariable.h:48
Resouce mapping.
Definition: ResourceMapping.h:107