XII Release 0.1.0
Loading...
Searching...
No Matches
xiiGALShaderParser Class Reference

Classes

struct  AttributeDefinition
 
struct  EnumDefinition
 
struct  EnumValue
 
struct  ParameterDefinition
 

Public Types

using CreateResourceDeclaration = xiiDelegate<void(xiiStringView, xiiStringView, const xiiGALShaderResourceDescription&, xiiStringBuilder&)>
 Delegate to creates a new declaration and register binding for a specific shader xiiGALShaderResourceDefinition.
 

Static Public Member Functions

static xiiResult PreprocessSection (xiiStreamReader &inout_stream, xiiEnum< xiiGALShaderSections > section, xiiArrayPtr< xiiString > pCustomDefines, xiiStringBuilder &out_sResult)
 
static void ParseMaterialParameterSection (xiiStreamReader &inout_stream, xiiHybridArray< ParameterDefinition, 16 > &out_parameter, xiiHybridArray< EnumDefinition, 4 > &out_enumDefinitions)
 
static void ParsePermutationSection (xiiStringView sPermutationSection, xiiHybridArray< xiiHashedString, 16 > &out_permutationVariables, xiiHybridArray< xiiGALPermutationVariable, 16 > &out_fixedPermutationVariables)
 
static void ParsePermutationVariableConfiguration (xiiStringView sPermutationVarConfig, xiiVariant &out_defaultValue, EnumDefinition &out_enumDefinition)
 
static void ParseShaderResources (xiiStringView sShaderStageSource, xiiDynamicArray< xiiGALShaderResourceDefinition > &out_resources)
 Tries to find shader resource declarations inside the shader source.
 
static xiiResult MergeShaderResourceBindings (const xiiGALShaderProgramData &spd, xiiHashTable< xiiHashedString, xiiGALShaderResourceDescription > &out_bindings, xiiLogInterface *pLog)
 Merges the shader resource bindings of all used shader stages.
 
static xiiResult SanityCheckShaderResourceBindings (const xiiHashTable< xiiHashedString, xiiGALShaderResourceDescription > &bindings, xiiLogInterface *pLog)
 Makes sure that bindings fulfills the basic requirements that the graphics abstraction layer (GAL) has for resource bindings in a shader, e.g. that each binding has a set / slot set.
 
static void ApplyShaderResourceBindings (xiiStringView sPlatform, xiiStringView sShaderStageSource, const xiiDynamicArray< xiiGALShaderResourceDefinition > &resources, const xiiHashTable< xiiHashedString, xiiGALShaderResourceDescription > &bindings, const CreateResourceDeclaration &createDeclaration, xiiStringBuilder &out_sShaderStageSource)
 Creates a new shader source code that patches all shader resources to contain fixed set / slot bindings.
 

Member Typedef Documentation

◆ CreateResourceDeclaration

Delegate to creates a new declaration and register binding for a specific shader xiiGALShaderResourceDefinition.

Parameters
sPlatformThe platform for which the shader is being compiled. Will be one of the values returned by GetSupportedPlatforms.
sDeclarationThe shader resource declaration without any attributes, e.g. "Texture2D DiffuseTexture"
bindingThe binding that needs to be set on the output out_sDeclaration.
out_sDeclarationThe new declaration that changes sDeclaration according to the provided 'binding', e.g. "Texture2D DiffuseTexture : register(t0, space5)"

Member Function Documentation

◆ ApplyShaderResourceBindings()

void xiiGALShaderParser::ApplyShaderResourceBindings ( xiiStringView sPlatform,
xiiStringView sShaderStageSource,
const xiiDynamicArray< xiiGALShaderResourceDefinition > & resources,
const xiiHashTable< xiiHashedString, xiiGALShaderResourceDescription > & bindings,
const CreateResourceDeclaration & createDeclaration,
xiiStringBuilder & out_sShaderStageSource )
static

Creates a new shader source code that patches all shader resources to contain fixed set / slot bindings.

Parameters
sPlatformThe platform for which the shader should be patched.
sShaderStageSourceThe original shader source code that should be patched.
resourcesA list of all shader resources that need to be patched within sShaderStageSource.
bindingsThe binding information that each shader resource should have after patching. These bindings must have unique set / slots combinations for each resource.
createDeclarationThe callback to be called to generate the new shader resource declaration.
out_shaderStageSourceThe new shader source code after patching.

◆ MergeShaderResourceBindings()

xiiResult xiiGALShaderParser::MergeShaderResourceBindings ( const xiiGALShaderProgramData & spd,
xiiHashTable< xiiHashedString, xiiGALShaderResourceDescription > & out_bindings,
xiiLogInterface * pLog )
static

Merges the shader resource bindings of all used shader stages.

The function can fail if a shader resource of the same name has different signatures in two stages. E.g. the type, slot or set is different. Shader resources must be uniquely identified via name.

Parameters
spdThe shader currently being processed.
out_bindingsA hashmap from shader resource name to shader resource binding. If a binding is used in multiple stages, xiiGALShaderResourceDescription::m_Stages will be the combination of all used stages.
pLogLog interface to write errors to.
Returns
Returns failure if the shader stages could not be merged.

◆ ParseShaderResources()

void xiiGALShaderParser::ParseShaderResources ( xiiStringView sShaderStageSource,
xiiDynamicArray< xiiGALShaderResourceDefinition > & out_resources )
static

Tries to find shader resource declarations inside the shader source.

Used by the shader compiler implementations to generate resource mappings to sets/slots without creating conflicts across shader stages. For a list of supported resource declarations and possible pitfalls, please refer to https://docs.xiitechnologies.com/graphics/shaders/shader-resources.html.

Parameters
sShaderStageSourceThe shader source to parse.
out_ResourcesThe shader resources found inside the source.

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