Go to the documentation of this file.
62 #include <d3dcommon.h>
64 #ifndef NTDDI_WIN10_VB // First defined in Win SDK 10.0.19041.0
65 # define D3D_SIT_RTACCELERATIONSTRUCTURE (D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER + 1)
98 static_assert(D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER < (1 <<
ShaderInputTypeBits),
"Not enough bits to represent D3D_SHADER_INPUT_TYPE");
99 static_assert(D3D_SRV_DIMENSION_BUFFEREX < (1 <<
SRVDimBits),
"Not enough bits to represent D3D_SRV_DIMENSION");
125 D3D_SHADER_INPUT_TYPE _InputType,
126 D3D_SRV_DIMENSION _SRVDimension,
127 Uint32 _SamplerId) noexcept :
132 InputType {
static_cast<decltype(InputType)
> (_InputType) },
133 SRVDimension {
static_cast<decltype(SRVDimension)
>(_SRVDimension)},
134 SamplerOrTexSRVId {_SamplerId}
137 #ifdef DILIGENT_DEBUG
142 VERIFY(_SRVDimension < (1 <<
SRVDimBits),
"SRV dimensions is out of expected range");
157 NamesPool.CopyString(rhs.Name),
161 rhs.GetSRVDimension(),
167 "Only texture SRV can be assigned a valid texture sampler");
174 NamesPool.CopyString(rhs.Name),
178 rhs.GetSRVDimension(),
179 rhs.SamplerOrTexSRVId
194 return static_cast<D3D_SHADER_INPUT_TYPE
>(InputType);
199 return static_cast<D3D_SRV_DIMENSION
>(SRVDimension);
228 InputType == Attribs.InputType &&
229 SRVDimension == Attribs.SRVDimension &&
230 SamplerOrTexSRVId == Attribs.SamplerOrTexSRVId;
243 return SamplerOrTexSRVId;
249 void SetTexSRVId(
Uint32 TexSRVId)
251 VERIFY(
GetInputType() == D3D_SIT_SAMPLER,
"Invalid input type: D3D_SIT_SAMPLER is expected");
253 SamplerOrTexSRVId = TexSRVId;
256 Uint32 GetCombinedTexSRVId()
const
258 VERIFY(
GetInputType() == D3D_SIT_SAMPLER,
"Invalid input type: D3D_SIT_SAMPLER is expected");
259 return SamplerOrTexSRVId;
262 static_assert(
sizeof(D3DShaderResourceAttribs) ==
sizeof(
void*) +
sizeof(
Uint32) * 2,
"Unexpected sizeof(D3DShaderResourceAttribs)");
304 VERIFY(TexSRV.IsCombinedWithSampler(),
"This texture SRV is not combined with any sampler");
305 return GetSampler(TexSRV.GetCombinedSamplerId());
310 VERIFY(
Sampler.IsCombinedWithTexSRV(),
"This sampler is not combined with any texture SRV");
318 template <
typename THandleCB,
319 typename THandleSampler,
320 typename THandleTexSRV,
321 typename THandleTexUAV,
322 typename THandleBufSRV,
323 typename THandleBufUAV,
324 typename THandleAccelStruct>
326 THandleSampler HandleSampler,
327 THandleTexSRV HandleTexSRV,
328 THandleTexUAV HandleTexUAV,
329 THandleBufSRV HandleBufSRV,
330 THandleBufUAV HandleBufUAV,
331 THandleAccelStruct HandleAccelStruct)
const
335 const auto& CB =
GetCB(n);
348 HandleTexSRV(TexSRV, n);
354 HandleTexUAV(TexUAV, n);
360 HandleBufSRV(BufSRV, n);
366 HandleBufUAV(BufUAV, n);
372 HandleAccelStruct(AS, n);
375 template <
typename THandler>
378 ProcessResources(Handler, Handler, Handler, Handler, Handler, Handler, Handler);
388 #ifdef DILIGENT_DEVELOPMENT
392 bool VerifyVariables,
393 bool VerifyImmutableSamplers) noexcept;
398 Major = (m_ShaderVersion & 0x000000F0) >> 4;
399 Minor = (m_ShaderVersion & 0x0000000F);
403 template <
typename D3D_SHADER_DESC,
404 typename D3D_SHADER_INPUT_BIND_DESC,
405 typename TShaderReflection,
406 typename TNewResourceHandler>
407 void Initialize(TShaderReflection* pShaderReflection,
408 TNewResourceHandler NewResHandler,
409 const Char* ShaderName,
410 const Char* SamplerSuffix);
415 VERIFY(n < NumResources,
"Resource index (", n,
") is out of range. Resource array size: ", NumResources);
422 VERIFY(n < NumResources,
"Resource index (", n,
") is out of range. Resource array size: ", NumResources);
440 size_t ResourceNamesPoolSize,
449 std::unique_ptr<void, STDDeleterRawMem<void>> m_MemoryBuffer;
451 const char* m_SamplerSuffix =
nullptr;
452 const char* m_ShaderName =
nullptr;
455 typedef Uint16 OffsetType;
456 OffsetType m_TexSRVOffset = 0;
457 OffsetType m_TexUAVOffset = 0;
458 OffsetType m_BufSRVOffset = 0;
459 OffsetType m_BufUAVOffset = 0;
460 OffsetType m_SamplersOffset = 0;
461 OffsetType m_AccelStructsOffset = 0;
462 OffsetType m_TotalResources = 0;
466 Uint32 m_ShaderVersion = 0;
470 template <
typename D3D_SHADER_DESC,
471 typename D3D_SHADER_INPUT_BIND_DESC,
472 typename TShaderReflection,
473 typename TNewResourceHandler>
475 TNewResourceHandler NewResHandler,
476 const Char* ShaderName,
477 const Char* CombinedSamplerSuffix)
479 Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0, CurrAS = 0;
484 LoadD3DShaderResources<D3D_SHADER_DESC, D3D_SHADER_INPUT_BIND_DESC>(
487 [&](
const D3D_SHADER_DESC& d3dShaderDesc)
489 m_ShaderVersion = d3dShaderDesc.Version;
495 ResourceNamesPoolSize += strlen(ShaderName) + 1;
497 if (CombinedSamplerSuffix !=
nullptr)
498 ResourceNamesPoolSize += strlen(CombinedSamplerSuffix) + 1;
500 AllocateMemory(
GetRawAllocator(), ResCounters, ResourceNamesPoolSize, ResourceNamesPool);
505 VERIFY_EXPR(CBAttribs.GetInputType() == D3D_SIT_CBUFFER);
507 NewResHandler.OnNewCB(*pNewCB);
514 NewResHandler.OnNewTexUAV(*pNewTexUAV);
519 VERIFY_EXPR(BuffUAV.GetInputType() == D3D_SIT_UAV_RWTYPED && BuffUAV.GetSRVDimension() ==
D3D_SRV_DIMENSION_BUFFER || BuffUAV.GetInputType() == D3D_SIT_UAV_RWSTRUCTURED || BuffUAV.GetInputType() == D3D_SIT_UAV_RWBYTEADDRESS);
521 NewResHandler.OnNewBuffUAV(*pNewBufUAV);
526 VERIFY_EXPR(BuffSRV.GetInputType() == D3D_SIT_TEXTURE && BuffSRV.GetSRVDimension() ==
D3D_SRV_DIMENSION_BUFFER || BuffSRV.GetInputType() == D3D_SIT_STRUCTURED || BuffSRV.GetInputType() == D3D_SIT_BYTEADDRESS);
528 NewResHandler.OnNewBuffSRV(*pNewBuffSRV);
533 VERIFY_EXPR(SamplerAttribs.GetInputType() == D3D_SIT_SAMPLER);
535 NewResHandler.OnNewSampler(*pNewSampler);
541 VERIFY(CurrSampler ==
GetNumSamplers(),
"All samplers must be initialized before texture SRVs");
547 GetSampler(SamplerId).SetTexSRVId(CurrTexSRV);
550 NewResHandler.OnNewTexSRV(*pNewTexSRV);
557 NewResHandler.OnNewAccelStruct(*pNewAccelStruct);
561 m_ShaderName = ResourceNamesPool.
CopyString(ShaderName);
563 if (CombinedSamplerSuffix !=
nullptr)
565 m_SamplerSuffix = ResourceNamesPool.
CopyString(CombinedSamplerSuffix);
567 #ifdef DILIGENT_DEVELOPMENT
571 if (!
Sampler.IsCombinedWithTexSRV())
572 LOG_ERROR_MESSAGE(
"Shader '", ShaderName,
"' uses combined texture samplers, but sampler '",
Sampler.Name,
"' is not assigned to any texture");
579 VERIFY(CurrCB ==
GetNumCBs(),
"Not all CBs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called");
580 VERIFY(CurrTexSRV ==
GetNumTexSRV(),
"Not all Tex SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
581 VERIFY(CurrTexUAV ==
GetNumTexUAV(),
"Not all Tex UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
582 VERIFY(CurrBufSRV ==
GetNumBufSRV(),
"Not all Buf SRVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
583 VERIFY(CurrBufUAV ==
GetNumBufUAV(),
"Not all Buf UAVs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
584 VERIFY(CurrSampler ==
GetNumSamplers(),
"Not all Samplers are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
585 VERIFY(CurrAS ==
GetNumAccelStructs(),
"Not all Accel Structs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called" );
const Uint16 BindPoint
Definition: ShaderResources.hpp:86
Definition: D3DShaderResourceLoader.hpp:43
#define LOG_ERROR_MESSAGE(...)
Definition: Errors.hpp:122
char Char
Definition: BasicTypes.h:64
ShaderResources & operator=(const ShaderResources &)=delete
D3DShaderResourceAttribs & GetCB(Uint32 n) noexcept
Definition: ShaderResources.hpp:428
SHADER_TYPE
Describes the shader type.
Definition: GraphicsTypes.h:65
Uint32 GetTotalResources() const noexcept
Definition: ShaderResources.hpp:291
D3DShaderResourceAttribs(StringPool &NamesPool, const D3DShaderResourceAttribs &rhs, Uint32 _SamplerId, Uint32 _BindPoint) noexcept
Definition: ShaderResources.hpp:153
size_t GetRemainingSize() const
Definition: StringPool.hpp:154
Uint32 GetNumCBs() const noexcept
Definition: ShaderResources.hpp:284
Uint32 GetNumBufSRV() const noexcept
Definition: ShaderResources.hpp:287
HLSL resource description.
Definition: ShaderD3D.h:46
static constexpr const Uint32 SamplerOrTexSRVIdBits
Definition: ShaderResources.hpp:95
Uint32 GetCombinedSamplerId() const
Definition: ShaderResources.hpp:240
static constexpr const Uint16 MaxBindCount
Definition: ShaderResources.hpp:119
__forceinline D3DShaderResourceAttribs & GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset) noexcept
Definition: ShaderResources.hpp:413
D3DShaderResourceAttribs(StringPool &NamesPool, const D3DShaderResourceAttribs &rhs) noexcept
Definition: ShaderResources.hpp:170
Char * CopyString(const String &Str)
Definition: StringPool.hpp:124
const Char * GetShaderName() const
Definition: ShaderResources.hpp:384
static constexpr const Uint16 InvalidBindPoint
Definition: ShaderResources.hpp:117
const D3DShaderResourceAttribs & GetAccelStruct(Uint32 n) const noexcept
Definition: ShaderResources.hpp:299
const __forceinline D3DShaderResourceAttribs & GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset) const noexcept
Definition: ShaderResources.hpp:420
static constexpr const Uint32 MaxSamplerId
Definition: ShaderResources.hpp:115
static constexpr const Uint32 InvalidTexSRVId
Definition: ShaderResources.hpp:116
bool IsMultisample() const
Definition: ShaderResources.cpp:360
Vector3< T > max(const Vector3< T > &a, const Vector3< T > &b)
Definition: BasicMath.hpp:1660
size_t operator()(const Diligent::D3DShaderResourceAttribs &Attribs) const
Definition: ShaderResources.hpp:597
ShaderResources(SHADER_TYPE ShaderType) noexcept
Definition: ShaderResources.hpp:269
D3DShaderResourceAttribs(const char *_Name, UINT _BindPoint, UINT _BindCount, D3D_SHADER_INPUT_TYPE _InputType, D3D_SRV_DIMENSION _SRVDimension, Uint32 _SamplerId) noexcept
Definition: ShaderResources.hpp:122
bool IsValidBindPoint() const
Definition: ShaderResources.hpp:219
const D3DShaderResourceAttribs & GetCombinedTextureSRV(const D3DShaderResourceAttribs &Sampler) const noexcept
Definition: ShaderResources.hpp:308
const D3DShaderResourceAttribs & GetSampler(Uint32 n) const noexcept
Definition: ShaderResources.hpp:298
const D3DShaderResourceAttribs & GetTexUAV(Uint32 n) const noexcept
Definition: ShaderResources.hpp:295
RESOURCE_DIMENSION GetResourceDimension() const
Definition: ShaderResources.hpp:202
bool IsCompatibleWith(const D3DShaderResourceAttribs &Attribs) const
Definition: ShaderResources.hpp:224
const D3DShaderResourceAttribs & GetCombinedSampler(const D3DShaderResourceAttribs &TexSRV) const noexcept
Definition: ShaderResources.hpp:302
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:51
D3DShaderResourceAttribs & GetBufSRV(Uint32 n) noexcept
Definition: ShaderResources.hpp:431
#define D3D_SRV_DIMENSION_BUFFER
Definition: D3D12TypeDefinitions.h:152
const char * GetCombinedSamplerSuffix() const
Definition: ShaderResources.hpp:383
const D3DShaderResourceAttribs & GetBufSRV(Uint32 n) const noexcept
Definition: ShaderResources.hpp:296
static constexpr const Uint32 InvalidSamplerId
Definition: ShaderResources.hpp:114
RESOURCE_DIMENSION D3DSrvDimensionToResourceDimension(D3D_SRV_DIMENSION SrvDim)
Definition: D3DCommonTypeConversions.cpp:35
Uint32 GetNumAccelStructs() const noexcept
Definition: ShaderResources.hpp:290
D3DShaderResourceAttribs & GetTexUAV(Uint32 n) noexcept
Definition: ShaderResources.hpp:430
Uint32 GetNumTexUAV() const noexcept
Definition: ShaderResources.hpp:286
D3DShaderResourceAttribs & GetTexSRV(Uint32 n) noexcept
Definition: ShaderResources.hpp:429
const char *const Name
Definition: ShaderResources.hpp:84
void ProcessResources(THandler Handler) const
Definition: ShaderResources.hpp:376
D3DShaderResourceAttribs & GetSampler(Uint32 n) noexcept
Definition: ShaderResources.hpp:433
HLSLShaderResourceDesc GetHLSLShaderResourceDesc(Uint32 Index) const
Definition: ShaderResources.cpp:372
size_t GetHash() const
Definition: ShaderResources.hpp:233
void Initialize(TShaderReflection *pShaderReflection, TNewResourceHandler NewResHandler, const Char *ShaderName, const Char *SamplerSuffix)
Definition: ShaderResources.hpp:474
static constexpr const Uint32 ShaderInputTypeBits
Definition: ShaderResources.hpp:93
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
std::size_t ComputeHash(const ArgsType &... Args)
Definition: HashUtils.hpp:57
D3D_SHADER_INPUT_TYPE GetInputType() const
Definition: ShaderResources.hpp:192
Uint32 GetNumSamplers() const noexcept
Definition: ShaderResources.hpp:289
const D3DShaderResourceAttribs & GetTexSRV(Uint32 n) const noexcept
Definition: ShaderResources.hpp:294
SHADER_TYPE GetShaderType() const noexcept
Definition: ShaderResources.hpp:314
bool IsCombinedWithTexSRV() const
Definition: ShaderResources.hpp:214
bool IsCompatibleWith(const ShaderResources &Resources) const
Definition: ShaderResources.cpp:255
D3D_SRV_DIMENSION GetSRVDimension() const
Definition: ShaderResources.hpp:197
size_t GetHash() const
Definition: ShaderResources.cpp:384
D3DShaderResourceAttribs & operator=(const D3DShaderResourceAttribs &rhs)=delete
Definition: ShaderResources.hpp:80
const Uint16 BindCount
Definition: ShaderResources.hpp:87
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
const D3DShaderResourceAttribs & GetBufUAV(Uint32 n) const noexcept
Definition: ShaderResources.hpp:297
static constexpr const Uint16 MaxBindPoint
Definition: ShaderResources.hpp:118
Uint32 GetNumTexSRV() const noexcept
Definition: ShaderResources.hpp:285
Diligent::ShaderResources class.
Definition: ShaderResources.hpp:266
Definition: AdvancedMath.hpp:979
uint16_t Uint16
16-bit unsigned integer
Definition: BasicTypes.h:52
const D3DShaderResourceAttribs & GetCB(Uint32 n) const noexcept
Definition: ShaderResources.hpp:293
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
D3DShaderResourceAttribs & GetBufUAV(Uint32 n) noexcept
Definition: ShaderResources.hpp:432
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Implementation of a simple fixed-size string pool.
Definition: StringPool.hpp:42
static constexpr const Uint32 SRVDimBits
Definition: ShaderResources.hpp:94
size_t operator()(const Diligent::ShaderResources &Res) const
Definition: ShaderResources.hpp:606
void GetShaderModel(Uint32 &Major, Uint32 &Minor) const
Definition: ShaderResources.hpp:396
RESOURCE_DIMENSION
Describes resource dimension.
Definition: GraphicsTypes.h:256
D3DShaderResourceAttribs & GetAccelStruct(Uint32 n) noexcept
Definition: ShaderResources.hpp:434
bool IsUsingCombinedTextureSamplers() const
Definition: ShaderResources.hpp:382
~ShaderResources()
Definition: ShaderResources.cpp:38
HLSLShaderResourceDesc GetHLSLResourceDesc() const
Definition: ShaderResources.cpp:306
Uint16 ShaderType
Definition: DXBCUtils.cpp:70
void ProcessResources(THandleCB HandleCB, THandleSampler HandleSampler, THandleTexSRV HandleTexSRV, THandleTexUAV HandleTexUAV, THandleBufSRV HandleBufSRV, THandleBufUAV HandleBufUAV, THandleAccelStruct HandleAccelStruct) const
Definition: ShaderResources.hpp:325
Pipeline layout description.
Definition: PipelineState.h:103
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
#define D3D_SIT_RTACCELERATIONSTRUCTURE
Definition: ShaderResources.hpp:65
Uint32 GetNumBufUAV() const noexcept
Definition: ShaderResources.hpp:288
bool IsCombinedWithSampler() const
Definition: ShaderResources.hpp:209