HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SlangShaderGenerator Class Reference

#include <SlangShaderGenerator.h>

+ Inheritance diagram for SlangShaderGenerator:

Public Member Functions

 SlangShaderGenerator (TypeSystemPtr typeSystem)
 Constructor. More...
 
ShaderPtr generate (const string &name, ElementPtr element, GenContext &context) const override
 
const stringgetTarget () const override
 Return a unique identifier for the target this generator is for. More...
 
virtual const stringgetVersion () const
 Return the version string for the Slang version this generator is for. More...
 
void emitVariableDeclaration (const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const override
 Emit a shader variable. More...
 
string getVertexDataPrefix (const VariableBlock &vertexData) const override
 Determine the prefix of vertex data variables. More...
 
- Public Member Functions inherited from HwShaderGenerator
virtual void addStageLightingUniforms (GenContext &context, ShaderStage &stage) const
 Emit code for active light count definitions and uniforms. More...
 
bool nodeNeedsClosureData (const ShaderNode &node) const override
 Return true if the node needs the ClosureData struct added. More...
 
void emitClosureDataArg (const ShaderNode &node, GenContext &context, ShaderStage &stage) const override
 
void emitClosureDataParameter (const ShaderNode &node, GenContext &context, ShaderStage &stage) const override
 
void applyDefaultOptions (GenOptions &options) const override
 Apply the default GenOptions for hardware shader generation. More...
 
ShaderNodeImplPtr createShaderNodeImplForNodeGraph (const NodeGraph &nodegraph) const override
 Create the shader node implementation for a NodeGraph implementation. More...
 
- Public Member Functions inherited from ShaderGenerator
virtual ~ShaderGenerator ()
 Destructor. More...
 
virtual void emitScopeBegin (ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const
 Start a new scope using the given bracket type. More...
 
virtual void emitScopeEnd (ShaderStage &stage, bool semicolon=false, bool newline=true) const
 End the current scope. More...
 
virtual void emitLineBegin (ShaderStage &stage) const
 Start a new line. More...
 
virtual void emitLineEnd (ShaderStage &stage, bool semicolon=true) const
 End the current line. More...
 
virtual void emitLineBreak (ShaderStage &stage) const
 Add a line break. More...
 
virtual void emitString (const string &str, ShaderStage &stage) const
 Add a string. More...
 
virtual void emitLine (const string &str, ShaderStage &stage, bool semicolon=true) const
 Add a single line of code, optionally appending a semicolon. More...
 
virtual void emitComment (const string &str, ShaderStage &stage) const
 Add a single line code comment. More...
 
virtual void emitBlock (const string &str, const FilePath &sourceFilename, GenContext &context, ShaderStage &stage) const
 Add a block of code. More...
 
virtual void emitLibraryInclude (const FilePath &filename, GenContext &context, ShaderStage &stage) const
 
template<typename T >
void emitValue (const T &value, ShaderStage &stage) const
 Add a value. More...
 
virtual void emitFunctionDefinition (const ShaderNode &node, GenContext &context, ShaderStage &stage) const
 Add the function definition for a single node. More...
 
virtual void emitFunctionDefinitionParameter (const ShaderPort *shaderPort, bool isOutput, GenContext &context, ShaderStage &stage) const
 
virtual void emitFunctionDefinitions (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 Add all function definitions for a graph. More...
 
virtual void emitFunctionCall (const ShaderNode &node, GenContext &context, ShaderStage &stage) const
 Add the function call for a single node. More...
 
virtual void emitFunctionCall (const ShaderNode &node, GenContext &context, ShaderStage &stage, bool checkScope) const
 
virtual void emitFunctionCalls (const ShaderGraph &graph, GenContext &context, ShaderStage &stage, uint32_t classification=0u) const
 
virtual void emitDependentFunctionCalls (const ShaderNode &node, GenContext &context, ShaderStage &stage, uint32_t classification=0u) const
 
virtual void emitFunctionBodyBegin (const ShaderNode &node, GenContext &context, ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const
 Emit code for starting a new function body. More...
 
virtual void emitFunctionBodyEnd (const ShaderNode &node, GenContext &context, ShaderStage &stage) const
 Emit code for ending a function body. More...
 
virtual void emitTypeDefinitions (GenContext &context, ShaderStage &stage) const
 Emit type definitions for all data types that needs it. More...
 
virtual void emitInput (const ShaderInput *input, GenContext &context, ShaderStage &stage) const
 
virtual void emitOutput (const ShaderOutput *output, bool includeType, bool assignValue, GenContext &context, ShaderStage &stage) const
 
virtual void emitVariableDeclarations (const VariableBlock &block, const string &qualifier, const string &separator, GenContext &context, ShaderStage &stage, bool assignValue=true) const
 
virtual string getUpstreamResult (const ShaderInput *input, GenContext &context) const
 Return the result of an upstream connection or value for an input. More...
 
const SyntaxgetSyntax () const
 Return the syntax object for the language used by the code generator. More...
 
void registerImplementation (const string &name, CreatorFunction< ShaderNodeImpl > creator)
 Register a shader node implementation for a given implementation element name. More...
 
void registerImplementation (const StringVec &nameVec, CreatorFunction< ShaderNodeImpl > creator)
 Register a shader node implementation for a given set of implementation element names. More...
 
bool implementationRegistered (const string &name) const
 Determine if a shader node implementation has been registered for a given implementation element name. More...
 
virtual ShaderNodeImplPtr createShaderNodeImplForImplementation (const Implementation &implementation) const
 Create the shader node implementation for an Implementation implementation. More...
 
virtual ShaderNodeImplPtr getImplementation (const NodeDef &nodedef, GenContext &context) const
 Return a registered shader node implementation for the given nodedef. More...
 
void setColorManagementSystem (ColorManagementSystemPtr colorManagementSystem)
 Sets the color management system. More...
 
ColorManagementSystemPtr getColorManagementSystem () const
 Returns the color management system. More...
 
void setUnitSystem (UnitSystemPtr unitSystem)
 Sets the unit system. More...
 
UnitSystemPtr getUnitSystem () const
 Returns the unit system. More...
 
TypeSystemPtr getTypeSystem () const
 Returns the type system. More...
 
const StringMapgetTokenSubstitutions () const
 Return the map of token substitutions used by the generator. More...
 
void registerRefactor (ShaderGraphRefactorPtr refactor)
 Register a shader graph refactoring pass. More...
 
const vector
< ShaderGraphRefactorPtr > & 
getRefactors () const
 Return the registered graph refactoring passes. More...
 
virtual void registerTypeDefs (const DocumentPtr &doc)
 Register type definitions from the document. More...
 
virtual void registerShaderMetadata (const DocumentPtr &doc, GenContext &context) const
 
virtual const stringgetLightDataTypevarString () const
 

Static Public Member Functions

static ShaderGeneratorPtr create (TypeSystemPtr typeSystem=nullptr)
 
- Static Public Member Functions inherited from HwShaderGenerator
static void bindLightShader (const NodeDef &nodeDef, unsigned int lightTypeId, GenContext &context)
 
static void unbindLightShader (unsigned int lightTypeId, GenContext &context)
 Unbind a light shader previously bound to the given light type id. More...
 
static void unbindLightShaders (GenContext &context)
 Unbind all light shaders previously bound. More...
 

Static Public Attributes

static const string TARGET
 Unique identifier for this generator target. More...
 
static const string VERSION
 Version string for the generator target. More...
 

Protected Member Functions

virtual void emitVertexStage (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 
virtual void emitPixelStage (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 
virtual void emitDirectives (GenContext &context, ShaderStage &stage) const
 
virtual void emitConstants (GenContext &context, ShaderStage &stage) const
 
virtual void emitUniforms (GenContext &context, ShaderStage &stage, bool emitLighting) const
 
virtual void emitInputs (GenContext &context, ShaderStage &stage) const
 
virtual void emitOutputs (GenContext &context, ShaderStage &stage) const
 
virtual bool requiresLighting (const ShaderGraph &graph) const override
 
virtual void emitSpecularEnvironment (GenContext &context, ShaderStage &stage) const
 Emit specular environment lookup code. More...
 
virtual void emitTransmissionRender (GenContext &context, ShaderStage &stage) const
 Emit transmission rendering code. More...
 
virtual void emitLightFunctionDefinitions (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 Emit function definitions for lighting code. More...
 
void SlangSyntaxFromGlsl (ShaderStage &shaderStage) const
 
- Protected Member Functions inherited from HwShaderGenerator
 HwShaderGenerator (TypeSystemPtr typeSystem, SyntaxPtr syntax)
 
virtual ShaderPtr createShader (const string &name, ElementPtr element, GenContext &context) const
 Create and initialize a new HW shader for shader generation. More...
 
void toVec4 (TypeDesc type, string &variable) const
 
- Protected Member Functions inherited from ShaderGenerator
 ShaderGenerator (TypeSystemPtr typeSystem, SyntaxPtr syntax)
 Protected constructor. More...
 
virtual ShaderStagePtr createStage (const string &name, Shader &shader) const
 Create a new stage in a shader. More...
 
void setFunctionName (const string &functionName, ShaderStage &stage) const
 Set function name for a stage. More...
 
void replaceTokens (const StringMap &substitutions, ShaderStage &stage) const
 Replace tokens with identifiers according to the given substitutions map. More...
 
void createVariables (ShaderGraphPtr graph, GenContext &context, Shader &shader) const
 

Static Protected Member Functions

static void toVec4 (TypeDesc type, string &variable)
 
static void toVec4 (const TypeDesc *type, string &variable)
 

Protected Attributes

vector< ShaderNodePtr_lightSamplingNodes
 Nodes used internally for light sampling. More...
 
- Protected Attributes inherited from ShaderGenerator
TypeSystemPtr _typeSystem
 
SyntaxPtr _syntax
 
Factory< ShaderNodeImpl_implFactory
 
ColorManagementSystemPtr _colorManagementSystem
 
UnitSystemPtr _unitSystem
 
StringMap _tokenSubstitutions
 
vector< ShaderGraphRefactorPtr_refactors
 
friend ShaderGraph
 

Additional Inherited Members

- Public Types inherited from HwShaderGenerator
enum  ClosureContextType {
  DEFAULT, REFLECTION, TRANSMISSION, INDIRECT,
  EMISSION, LIGHTING, CLOSURE
}
 Types of closure contexts for HW. More...
 
- Static Protected Attributes inherited from ShaderGenerator
static const string T_FILE_TRANSFORM_UV
 
static const string LIGHTDATA_TYPEVAR_STRING
 

Detailed Description

Base class for Slang code generation. A generator for a specific Slang target should be derived from this class.

Definition at line 22 of file SlangShaderGenerator.h.

Constructor & Destructor Documentation

SlangShaderGenerator::SlangShaderGenerator ( TypeSystemPtr  typeSystem)

Constructor.

Member Function Documentation

static ShaderGeneratorPtr SlangShaderGenerator::create ( TypeSystemPtr  typeSystem = nullptr)
inlinestatic

Creator function. If a TypeSystem is not provided it will be created internally. Optionally pass in an externally created TypeSystem here, if you want to keep type descriptions alive after the lifetime of the shader generator.

Definition at line 33 of file SlangShaderGenerator.h.

virtual void SlangShaderGenerator::emitConstants ( GenContext context,
ShaderStage stage 
) const
protectedvirtual
virtual void SlangShaderGenerator::emitDirectives ( GenContext context,
ShaderStage stage 
) const
protectedvirtual
virtual void SlangShaderGenerator::emitInputs ( GenContext context,
ShaderStage stage 
) const
protectedvirtual
virtual void SlangShaderGenerator::emitLightFunctionDefinitions ( const ShaderGraph graph,
GenContext context,
ShaderStage stage 
) const
protectedvirtual

Emit function definitions for lighting code.

virtual void SlangShaderGenerator::emitOutputs ( GenContext context,
ShaderStage stage 
) const
protectedvirtual
virtual void SlangShaderGenerator::emitPixelStage ( const ShaderGraph graph,
GenContext context,
ShaderStage stage 
) const
protectedvirtual
virtual void SlangShaderGenerator::emitSpecularEnvironment ( GenContext context,
ShaderStage stage 
) const
protectedvirtual

Emit specular environment lookup code.

virtual void SlangShaderGenerator::emitTransmissionRender ( GenContext context,
ShaderStage stage 
) const
protectedvirtual

Emit transmission rendering code.

virtual void SlangShaderGenerator::emitUniforms ( GenContext context,
ShaderStage stage,
bool  emitLighting 
) const
protectedvirtual
void SlangShaderGenerator::emitVariableDeclaration ( const ShaderPort variable,
const string qualifier,
GenContext context,
ShaderStage stage,
bool  assignValue = true 
) const
overridevirtual

Emit a shader variable.

Reimplemented from ShaderGenerator.

virtual void SlangShaderGenerator::emitVertexStage ( const ShaderGraph graph,
GenContext context,
ShaderStage stage 
) const
protectedvirtual
ShaderPtr SlangShaderGenerator::generate ( const string name,
ElementPtr  element,
GenContext context 
) const
overridevirtual

Generate a shader starting from the given element, translating the element and all dependencies upstream into shader code.

Reimplemented from ShaderGenerator.

const string& SlangShaderGenerator::getTarget ( ) const
inlineoverridevirtual

Return a unique identifier for the target this generator is for.

Reimplemented from ShaderGenerator.

Definition at line 43 of file SlangShaderGenerator.h.

virtual const string& SlangShaderGenerator::getVersion ( ) const
inlinevirtual

Return the version string for the Slang version this generator is for.

Definition at line 46 of file SlangShaderGenerator.h.

string SlangShaderGenerator::getVertexDataPrefix ( const VariableBlock vertexData) const
overridevirtual

Determine the prefix of vertex data variables.

Implements HwShaderGenerator.

virtual bool SlangShaderGenerator::requiresLighting ( const ShaderGraph graph) const
overrideprotectedvirtual

Logic to indicate whether code to support direct lighting should be emitted. By default if the graph is classified as a shader, or BSDF node then lighting is assumed to be required. Derived classes can override this logic.

Reimplemented from HwShaderGenerator.

void SlangShaderGenerator::SlangSyntaxFromGlsl ( ShaderStage shaderStage) const
protected
static void SlangShaderGenerator::toVec4 ( TypeDesc  type,
string variable 
)
staticprotected
static void SlangShaderGenerator::toVec4 ( const TypeDesc type,
string variable 
)
inlinestaticprotected

Definition at line 87 of file SlangShaderGenerator.h.

Member Data Documentation

vector<ShaderNodePtr> SlangShaderGenerator::_lightSamplingNodes
protected

Nodes used internally for light sampling.

Definition at line 92 of file SlangShaderGenerator.h.

const string SlangShaderGenerator::TARGET
static

Unique identifier for this generator target.

Definition at line 57 of file SlangShaderGenerator.h.

const string SlangShaderGenerator::VERSION
static

Version string for the generator target.

Definition at line 60 of file SlangShaderGenerator.h.


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