Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::RHI::ShaderResourceGroupLayout Class Reference

#include <ShaderResourceGroupLayout.h>

Inherits AZStd::intrusive_base.

Public Member Functions

 AZ_RTTI (ShaderResourceGroupLayout, "{1F92C651-9B83-4379-AB5C-5201F1B2C278}")
 
 AZ_CLASS_ALLOCATOR (ShaderResourceGroupLayout, SystemAllocator)
 
bool IsFinalized () const
 
void Clear ()
 Clears the layout to an empty state. The layout must be finalized prior to usage.
 
bool Finalize ()
 
void SetName (const Name &name)
 
const Name & GetName () const
 
const AZStd::string & GetUniqueId () const
 
void SetUniqueId (const AZStd::string &uniqueId)
 
void SetShaderVariantKeyFallback (const Name &shaderConstantName, uint32_t bitSize)
 
void AddStaticSampler (const ShaderInputStaticSamplerDescriptor &sampler)
 
void AddShaderInput (const ShaderInputBufferDescriptor &buffer)
 
void AddShaderInput (const ShaderInputImageDescriptor &image)
 
void AddShaderInput (const ShaderInputBufferUnboundedArrayDescriptor &bufferUnboundedArray)
 
void AddShaderInput (const ShaderInputImageUnboundedArrayDescriptor &imageUnboundedArray)
 
void AddShaderInput (const ShaderInputSamplerDescriptor &sampler)
 
void AddShaderInput (const ShaderInputConstantDescriptor &constant)
 
void SetBindingSlot (uint32_t bindingSlot)
 
AZStd::span< const ShaderInputStaticSamplerDescriptorGetStaticSamplers () const
 Returns the full list of static samplers descriptors declared on the layout.
 
ShaderInputBufferIndex FindShaderInputBufferIndex (const Name &name) const
 
ShaderInputImageIndex FindShaderInputImageIndex (const Name &name) const
 
ShaderInputSamplerIndex FindShaderInputSamplerIndex (const Name &name) const
 
ShaderInputConstantIndex FindShaderInputConstantIndex (const Name &name) const
 
ShaderInputBufferUnboundedArrayIndex FindShaderInputBufferUnboundedArrayIndex (const Name &name) const
 
ShaderInputImageUnboundedArrayIndex FindShaderInputImageUnboundedArrayIndex (const Name &name) const
 
const ShaderInputBufferDescriptorGetShaderInput (ShaderInputBufferIndex index) const
 
const ShaderInputImageDescriptorGetShaderInput (ShaderInputImageIndex index) const
 
const ShaderInputSamplerDescriptorGetShaderInput (ShaderInputSamplerIndex index) const
 
const ShaderInputConstantDescriptorGetShaderInput (ShaderInputConstantIndex index) const
 
const ShaderInputBufferUnboundedArrayDescriptorGetShaderInput (ShaderInputBufferUnboundedArrayIndex index) const
 
const ShaderInputImageUnboundedArrayDescriptorGetShaderInput (ShaderInputImageUnboundedArrayIndex index) const
 
AZStd::span< const ShaderInputBufferDescriptorGetShaderInputListForBuffers () const
 
AZStd::span< const ShaderInputImageDescriptorGetShaderInputListForImages () const
 
AZStd::span< const ShaderInputSamplerDescriptorGetShaderInputListForSamplers () const
 
AZStd::span< const ShaderInputConstantDescriptorGetShaderInputListForConstants () const
 
AZStd::span< const ShaderInputBufferUnboundedArrayDescriptorGetShaderInputListForBufferUnboundedArrays () const
 
AZStd::span< const ShaderInputImageUnboundedArrayDescriptorGetShaderInputListForImageUnboundedArrays () const
 
Interval GetGroupInterval (ShaderInputBufferIndex inputIndex) const
 
Interval GetGroupInterval (ShaderInputImageIndex inputIndex) const
 
Interval GetGroupInterval (ShaderInputSamplerIndex inputIndex) const
 
Interval GetConstantInterval (ShaderInputConstantIndex inputIndex) const
 The interval of a constant is its byte [min, max) into the constant data.
 
uint32_t GetGroupSizeForBuffers () const
 
uint32_t GetGroupSizeForImages () const
 
uint32_t GetGroupSizeForBufferUnboundedArrays () const
 
uint32_t GetGroupSizeForImageUnboundedArrays () const
 
uint32_t GetGroupSizeForSamplers () const
 
uint32_t GetConstantDataSize () const
 Constants are different and live in an opaque buffer of bytes instead of a resource group.
 
uint32_t GetBindingSlot () const
 
uint32_t GetShaderVariantKeyFallbackSize () const
 Returns the ShaderVariantKey fallback size in bits, or 0 if this SRG can't handle that function.
 
bool HasShaderVariantKeyFallbackEntry () const
 Returns true if the ShaderResourceGroup has been designated as a ShaderVariantKey fallback.
 
const RHI::ShaderInputConstantIndexGetShaderVariantKeyFallbackConstantIndex () const
 Returns the ShaderVariantKey fallback index, or invalid index if this SRG is not designated as fallback.
 
HashValue64 GetHash () const
 Returns the hash computed in Finalize.
 
const ConstantsLayoutGetConstantsLayout () const
 Returns the constants data layout;.
 
bool ValidateAccess (RHI::ShaderInputConstantIndex inputIndex) const
 
bool ValidateAccess (RHI::ShaderInputBufferIndex inputIndex, uint32_t arrayIndex) const
 
bool ValidateAccess (RHI::ShaderInputImageIndex inputIndex, uint32_t arrayIndex) const
 
bool ValidateAccess (RHI::ShaderInputSamplerIndex inputIndex, uint32_t arrayIndex) const
 
bool ValidateAccess (RHI::ShaderInputBufferUnboundedArrayIndex inputIndex) const
 
bool ValidateAccess (RHI::ShaderInputImageUnboundedArrayIndex inputIndex) const
 

Static Public Member Functions

static void Reflect (ReflectContext *context)
 
static Ptr< ShaderResourceGroupLayoutCreate ()
 

Friends

template<typename , typename >
struct AnyTypeInfoConcept
 
template<typename , bool , bool >
struct Serialize::InstanceFactory
 

Detailed Description

ShaderResourceGroupLayout defines a set of valid shader inputs to a ShaderResourceGroup.

Each 'shader input' adheres to the following type:

  • Buffer (Constant, Read, Read-Write).
  • Image (Read, Read-Write)
  • Sampler
  • Constant

Buffers, images, and samplers are collectively called 'resources'. These three types form disjoint groups. Each resource shader input has an array of resources. These arrays are flattened into a 'resource group' for each resource type. For example, if a buffer input at index '0' has two elements, and the buffer input at index '1' has three, the "buffer shader resource group" forms a list of five elements.

Each shader input maps to a named definition in a shader source file. This name is retained in order to support a basic name-to-index reflection API.

Constant shader inputs are treated a bit differently. Each constant input spans a range of bytes in an implicit constant buffer.

To use the class, assign shader inputs using AddShaderInput, and call Finalize to complete construction of the layout. This class is intended to be built using an offline shader compiler, and serialized to / from disk.

Member Function Documentation

◆ AddShaderInput()

void AZ::RHI::ShaderResourceGroupLayout::AddShaderInput ( const ShaderInputBufferDescriptor buffer)

Adds a shader input to the shader resource group layout. The layout maintains a separate list for each type of shader input. Order in each list is preserved.

◆ AddStaticSampler()

void AZ::RHI::ShaderResourceGroupLayout::AddStaticSampler ( const ShaderInputStaticSamplerDescriptor sampler)

Adds a static sampler to the layout. Static samplers are immutable and cannot be assigned at runtime.

◆ Finalize()

bool AZ::RHI::ShaderResourceGroupLayout::Finalize ( )

Finalizes the layout for access. Must be called prior to usage or serialization. It is not permitted to mutate the layout once Finalize is called. Clear must be called first. If the call fails, the layout is cleared back to an empty state and false is returned. Otherwise, true is returned and the layout is considered finalized.

◆ FindShaderInputBufferIndex()

ShaderInputBufferIndex AZ::RHI::ShaderResourceGroupLayout::FindShaderInputBufferIndex ( const Name &  name) const

Resolves an shader input name to an index for each type of shader input. To maximize performance, the name to index resolve should be done as an initialization step and the indices cached.

◆ GetBindingSlot()

uint32_t AZ::RHI::ShaderResourceGroupLayout::GetBindingSlot ( ) const

Returns the binding slot allocated to this layout. Each layout occupies a logical binding slot on a command list. All shader resource groups which use the layout are bound to that slot.

◆ GetGroupInterval()

Interval AZ::RHI::ShaderResourceGroupLayout::GetGroupInterval ( ShaderInputBufferIndex  inputIndex) const

Each shader input may contain multiple shader resources. The layout computes a separate shader resource group for each resource type. For example, given shader inputs 'A', 'B' and 'C':

Shader Input List: (A) (B) (C) Shader Resource Group: [0, 1, 2] [3, 4] [5]

[A, B, C] form a list of three shader inputs. But the shader resource group forms a group of six resources. The following methods provide a mapping from a shader input index to an interval of resources in the resource group.

The following methods return an interval - [min, max) - into the shader resource group for that resource type.

◆ GetGroupSizeForBuffers()

uint32_t AZ::RHI::ShaderResourceGroupLayout::GetGroupSizeForBuffers ( ) const

Returns the total size of the flat resource table for each type of resource. Note that this size is not 1-to-1 with the 'shader input list' for that type of resource, since a shader input may be an array of resources.

NOTE: The resource table maps to the following types per resource:

◆ GetShaderInput()

const ShaderInputBufferDescriptor & AZ::RHI::ShaderResourceGroupLayout::GetShaderInput ( ShaderInputBufferIndex  index) const

Returns the shader input associated with the requested index. It is not permitted to call this method with a null index. An assert will fire otherwise.

◆ GetShaderInputListForBuffers()

AZStd::span< const ShaderInputBufferDescriptor > AZ::RHI::ShaderResourceGroupLayout::GetShaderInputListForBuffers ( ) const

Returns the full lists of each kind of shader input added to the layout. Inputs maintain their original order with respect to AddShaderInput. Each type of shader input has its own separate list.

◆ GetUniqueId()

const AZStd::string & AZ::RHI::ShaderResourceGroupLayout::GetUniqueId ( ) const
inline

This string will be used at runtime for both ShaderResourceGroup and ShaderResourceGroupPool to create a unique InstanceId to avoid redundant copies in memory.

◆ SetBindingSlot()

void AZ::RHI::ShaderResourceGroupLayout::SetBindingSlot ( uint32_t  bindingSlot)

Assigns the shader resource group binding slot to the layout. The binding slot is defined by the shader content and dictates which logical slot to use when binding shader resource groups to command lists.

◆ SetShaderVariantKeyFallback()

void AZ::RHI::ShaderResourceGroupLayout::SetShaderVariantKeyFallback ( const Name &  shaderConstantName,
uint32_t  bitSize 
)

Designates this SRG as ShaderVariantKey fallback by providing the generated shader constant name and its length in bits.

◆ SetUniqueId()

void AZ::RHI::ShaderResourceGroupLayout::SetUniqueId ( const AZStd::string &  uniqueId)
inline

The Set function as described above. It is usually the Source azsl/azsli/srgi file where this SRG comes from.

◆ ValidateAccess() [1/3]

bool AZ::RHI::ShaderResourceGroupLayout::ValidateAccess ( RHI::ShaderInputBufferIndex  inputIndex,
uint32_t  arrayIndex 
) const

Validates that the inputIndex is valid and the arrayIndex is less than the total array size of the shader input. Emits an assert and returns false on failure; returns true on success. If validation is disabled true is always returned.

◆ ValidateAccess() [2/3]

bool AZ::RHI::ShaderResourceGroupLayout::ValidateAccess ( RHI::ShaderInputBufferUnboundedArrayIndex  inputIndex) const

Validates that the inputIndex is valid. Emits an assert and returns false on failure; returns true on success. If validation is disabled true is always returned.

◆ ValidateAccess() [3/3]

bool AZ::RHI::ShaderResourceGroupLayout::ValidateAccess ( RHI::ShaderInputConstantIndex  inputIndex) const

Validates that the inputIndex is valid. Emits an assert and returns false on failure; returns true on success. If validation is disabled true is always returned.


The documentation for this class was generated from the following file: