Plasma Engine  2.0
Loading...
Searching...
No Matches
plShaderParser Class Reference

Classes

struct  AttributeDefinition
 
struct  EnumDefinition
 
struct  EnumValue
 
struct  ParameterDefinition
 

Public Types

using CreateResourceDeclaration = plDelegate<void (plStringView, plStringView, const plShaderResourceBinding &, plStringBuilder &)>
 Delegate to creates a new declaration and register binding for a specific shader plShaderResourceDefinition.
 

Static Public Member Functions

static void ParseMaterialParameterSection (plStreamReader &inout_stream, plHybridArray< ParameterDefinition, 16 > &out_parameter, plHybridArray< EnumDefinition, 4 > &out_enumDefinitions)
 
static void ParsePermutationSection (plStreamReader &inout_stream, plHybridArray< plHashedString, 16 > &out_permVars, plHybridArray< plPermutationVar, 16 > &out_fixedPermVars)
 
static void ParsePermutationSection (plStringView sPermutationSection, plHybridArray< plHashedString, 16 > &out_permVars, plHybridArray< plPermutationVar, 16 > &out_fixedPermVars)
 
static void ParsePermutationVarConfig (plStringView sPermutationVarConfig, plVariant &out_defaultValue, EnumDefinition &out_enumDefinition)
 
static void ParseShaderResources (plStringView sShaderStageSource, plDynamicArray< plShaderResourceDefinition > &out_resources)
 Tries to find shader resource declarations inside the shader source.
 
static plResult MergeShaderResourceBindings (const plShaderProgramData &spd, plHashTable< plHashedString, plShaderResourceBinding > &out_bindings, plLogInterface *pLog)
 Merges the shader resource bindings of all used shader stages.
 
static plResult SanityCheckShaderResourceBindings (const plHashTable< plHashedString, plShaderResourceBinding > &bindings, plLogInterface *pLog)
 Makes sure that bindings fulfills the basic requirements that plEngine has for resource bindings in a shader, e.g. that each binding has a set / slot set.
 
static void ApplyShaderResourceBindings (plStringView sPlatform, plStringView sShaderStageSource, const plDynamicArray< plShaderResourceDefinition > &resources, const plHashTable< plHashedString, plShaderResourceBinding > &bindings, const CreateResourceDeclaration &createDeclaration, plStringBuilder &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 plShaderResourceDefinition.

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 plShaderParser::ApplyShaderResourceBindings ( plStringView sPlatform,
plStringView sShaderStageSource,
const plDynamicArray< plShaderResourceDefinition > & resources,
const plHashTable< plHashedString, plShaderResourceBinding > & bindings,
const CreateResourceDeclaration & createDeclaration,
plStringBuilder & 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()

plResult plShaderParser::MergeShaderResourceBindings ( const plShaderProgramData & spd,
plHashTable< plHashedString, plShaderResourceBinding > & out_bindings,
plLogInterface * 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, plShaderResourceBinding::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 plShaderParser::ParseShaderResources ( plStringView sShaderStageSource,
plDynamicArray< plShaderResourceDefinition > & 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://plengine.net/pages/docs/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: