ShaderCompiler namespace
Offline shader preprocessing tool, see Shader compilation.
Shared with the game at runtime: the reflection types the tool writes into the generated shader headers (Sources/Shaders/Generated) live in this namespace as well, and that is how the backends of nCine::
Namespaces
- namespace VertexIdRewrite
Classes
- struct Attribute
- struct AttributeDecl
- struct AttributeInfo
- Vertex attribute ("in" declaration in the vertex stage).
- struct BackendArtifacts
- The stage artifacts only a platform-specific compiler can produce.
- struct BlockDecl
- struct BlockInfo
- std140 uniform block
- struct BlockMember
- class ConsoleFixedFunction
- Transpiles
fixed_functionblocks into C++ effect functions over the EffectContext contract. - class ConstFolder
- Computes literal constant-folding rewrites for one fold unit.
- struct Diagnostic
- Error description pointing into the input file.
- class Emitter
- Emits the generated C++ header and the "--check" reflection dump.
- class Essl100Emitter
- Transforms an already-lowered modern-GLSL stage source into ESSL 100 (OpenGL ES 2.0).
- struct Expr
- One expression-tree node; the type-free shape shared by the AST-based lowerings.
- struct Field
- struct FixedFunctionBlock
- One captured "void fixed_function([<target>[, <target>...]]) { ... }" block.
- struct FixedFunctionResult
- Outcome of transpiling one fixed_function block variant to C++.
- struct FoldEdit
- One computed rewrite: columns [Begin, End) of line Index collapse to Replacement.
- struct FoldInputLine
- One input line range of a fold unit (positions must be valid in the rewritable original text).
- struct Function
- struct GlobalVarDecl
- class GlslExprTokenizer
- GLSL expression tokenizer (reusable outside the folder).
- struct GlslInstanceMember
- One scalar/vector member of the per-instance std140 block, with its baked byte offset.
- class GlslReflector
- Parses global-scope GLSL declarations and computes std140 layouts.
- class GlslToCpp
- Transpiles lowered fragment GLSL into a C++ software-renderer fragment function.
- struct GlslToCppResult
- Outcome of transpiling one fragment shader to C++.
- struct GlslToken
- One GLSL expression token with its position in the source line it came from.
- class HlslEmitter
- Transforms an already-lowered modern-GLSL stage source into HLSL (Shader Model 4/5).
- struct MemberInfo
- Member of a struct or std140 uniform block.
- struct Param
- class Parser
- Grows the shared typed AST (declarations + per-function statement trees) from an already-lowered modern-GLSL stage token stream.
- class Preprocessor
- Object-like macro preprocessor used to produce the per-variant declaration stream for reflection.
- struct Program
- struct ProgramReflection
- One lowered program (document plus per-variant reflection) to be emitted into a generated header.
- struct ProgramVariant
- class RuntimeProgram
- A ".shader" program compiled at runtime, owning its sources and reflection.
- struct RuntimeVariant
- One variant of a runtime-compiled program: lowered stage sources plus merged reflection.
- struct SamplerBinding
- A sampler uniform's texture-unit assignment, taken from the program's reflection.
- struct SamplerDecl
- struct ShaderDocument
- Lowered ".shader" document — directives plus raw (unpreprocessed) per-stage GLSL line streams.
- class ShaderParser
- Parses and lowers the ".shader" input language.
- struct SourceLine
- One line of source text together with its 1-based line number in the original ".shader" file.
- struct StageReflection
- Reflection data collected from one stage (or merged for a whole program).
- struct Stmt
- struct StructDecl
- struct StructInfo
- User struct declaration with its computed std140 layout.
- struct TextureBinding
- struct TextureDirective
- Texture unit assignment for a sampler uniform — from a "texture_unit(N)" uniform hint or the implicit canvas TEXTURE registration.
- struct TextureInfo
- Sampler uniform with its optional "texture_unit(N)" hint unit assignment.
- struct TyRef
- A type plus, for Ty::Struct, the user struct name (so struct-typed members resolve their fields).
- struct Uniform
- struct UniformBlock
- struct UniformDecl
- struct UniformInfo
- Loose (non-block, non-sampler) uniform.
- struct VariantReflection
- Reflection of one program variant (the unnamed base or a named variant), merged across stages.
- struct VaryingDecl
- class VulkanGlslEmitter
- Transforms an already-lowered modern-GLSL stage source into Vulkan-flavored GLSL ("#version 450").
Enums
-
enum class UniformType : std::
uint8_t { Float, Int, UInt, Bool, Vec2, Vec3, Vec4, IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, BVec2, BVec3, BVec4, Mat2, Mat3, Mat4, Sampler2D, Sampler3D, SamplerCube, Struct } -
enum class RenderMode : std::
uint32_t { BlendMix = 0x01, BlendAdd = 0x02, BlendSub = 0x04, BlendMul = 0x08, BlendPremulAlpha = 0x10, Unshaded = 0x20 } - enum class FixedFunctionBackend { Pvr, Gx, Gu, Gs }
- Fixed-function backend a generated aggregate header targets.
-
enum class FixedFunctionRequirements : std::
uint8_t { None = 0, NeedsTexelStep = 0x01, NeedsUniforms = 0x02, NeedsStripBuilder = 0x04, NeedsQuadAxes = 0x08 } - Optional
EffectContextfacilities an emitted function calls, as single-bit flags. -
enum class GlslTokenType : std::
uint8_t { Identifier, IntLiteral, UIntLiteral, FloatLiteral, BoolLiteral, Operator, End } - Classification of one GLSL expression token.
- enum class ExprKind { IntLit, UIntLit, FloatLit, BoolLit, Ident, Member, Index, Call, Unary, Binary, Assign, Conditional }
- Kind of an Expr node (the union across the AST-based targets).
-
enum class GlslType : std::
uint8_t { Float, Int, UInt, Bool, Vec2, Vec3, Vec4, IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, BVec2, BVec3, BVec4, Mat2, Mat3, Mat4, Sampler2D, Sampler3D, SamplerCube, Struct } - Data type of a uniform, block member or vertex attribute.
- enum class Ty { Void, Float, Int, UInt, Bool, Vec2, Vec3, Vec4, IVec2, IVec3, IVec4, UVec2, UVec3, UVec4, BVec2, BVec3, BVec4, Mat2, Mat3, Mat4, Sampler2D, Sampler3D, SamplerCube, Struct, Unknown }
- Scalar/vector/matrix/opaque type of the translated GLSL subset (uint/uvec kept distinct).
- enum class StmtKind { Block, VarDecl, ExprStmt, If, For, Return }
-
enum class FixedFunctionTarget : std::
uint8_t { Pvr, Gx, Gu, Gs } - One backend a "void fixed_function(...) { ... }" block can name in its parentheses.
-
enum RenderModeMask : std::
uint32_t { RenderModeBlendMix = 0x01, RenderModeBlendAdd = 0x02, RenderModeBlendSub = 0x04, RenderModeBlendMul = 0x08, RenderModeBlendPremulAlpha = 0x10, RenderModeUnshaded = 0x20 } - "render_mode" flags (bit values match ShaderCompiler::RenderMode in the generated ShaderCompilerTypes.h)
Typedefs
-
using SpirvCompileFn = Function<bool(StringView vulkanGlsl, bool vertexStage, SmallVectorImpl<std::
uint32_t>& spirv, String& log)> - Offline SPIR-V compiler callback injected into EmitHeader.
-
using DxbcCompileFn = Function<bool(StringView hlsl, bool vertexStage, SmallVectorImpl<std::
uint8_t>& dxbc, String& log)> - Offline DXBC compiler callback injected into EmitHeader.
-
using ExprPtr = std::
unique_ptr<Expr> -
using StmtPtr = std::
unique_ptr<Stmt> - using FileReader = Function<bool(StringView path, String& content)>
- Reads the content of the file at
pathintocontent, returns false on failure.
Functions
- auto IsQualifier(StringView k) -> bool
- True for a type-qualifier keyword the AST parsers skip (precision / interpolation / const).
-
auto BinPrec(StringView op) -> std::
int32_t - auto MakeExpr(ExprKind kind, String text = {}) -> ExprPtr
- Allocates an Expr of the given kind, optionally carrying literal/identifier/operator text.
- auto TokenizeStage(StringView glsl, SmallVectorImpl<GlslToken>& tokens, String& reason) -> bool
- auto IsMatrix(Ty t) -> bool
- auto IsVector(Ty t) -> bool
- auto IsSampler(Ty t) -> bool
-
auto Comps(Ty t) -> std::
int32_t - auto BaseScalar(Ty t) -> Ty
-
auto MakeVec(Ty scalar,
std::
int32_t n) -> Ty - auto MatrixColumn(Ty t) -> Ty
- auto TryBuiltinType(StringView k, Ty& out) -> bool
- auto MakeStmt(StmtKind kind) -> StmtPtr
- auto CompileRuntimeProgram(StringView content, StringView baseDir, FileReader& reader, RuntimeProgram& out, Diagnostic& diag) -> bool
- Compiles a ".shader" source into a RuntimeProgram.
- auto FixedFunctionTargetName(FixedFunctionTarget target) -> const char*
- Spelling of
targetas it is written inside a block's parentheses. - auto FixedFunctionTargetList(const SmallVectorImpl<FixedFunctionTarget>& targets) -> String
- The target list of a block, spelled the way the block declares it — e.g.
pvr, gu(empty for the generic block).
Variables
-
std::
uint16_t SymbolicArraySize constexpr
Enum documentation
enum class ShaderCompiler:: UniformType : std:: uint8_t
enum class ShaderCompiler:: RenderMode : std:: uint32_t
enum class ShaderCompiler:: FixedFunctionBackend
Fixed-function backend a generated aggregate header targets.
| Enumerators | |
|---|---|
| Pvr |
Dreamcast (CLX2 via KallistiOS) |
| Gx |
Wii/GameCube (Flipper/Hollywood) |
| Gu |
PlayStation Portable (Graphics Engine via sceGu) |
| Gs |
PlayStation 2 (Graphics Synthesizer via PS2SDK's libdraw) |
enum class ShaderCompiler:: FixedFunctionRequirements : std:: uint8_t
Optional EffectContext facilities an emitted function calls, as single-bit flags.
Mirrors nCine::RHI::FixedFunctionRequirements (FixedFunctionPass.h) name for name and bit for bit — Main.cpp renders these values as that enum's members in the generated table, and the backends gate their per-draw context setup on them.
| Enumerators | |
|---|---|
| None |
|
| NeedsTexelStep |
|
| NeedsUniforms |
|
| NeedsStripBuilder |
|
| NeedsQuadAxes |
|
enum class ShaderCompiler:: GlslTokenType : std:: uint8_t
Classification of one GLSL expression token.
| Enumerators | |
|---|---|
| Identifier |
Identifiers and keywords ( |
| IntLiteral |
Decimal, hex or octal integer without a suffix. |
| UIntLiteral |
Integer with a |
| FloatLiteral |
Contains |
| BoolLiteral |
|
| Operator |
Operators and punctuation, longest-match ( |
| End |
Synthetic terminator. |
enum class ShaderCompiler:: ExprKind
#include <Utilities/ShaderCompiler/GlslAst.h>
Kind of an Expr node (the union across the AST-based targets).
enum class ShaderCompiler:: GlslType : std:: uint8_t
Data type of a uniform, block member or vertex attribute.
enum class ShaderCompiler:: Ty
Scalar/vector/matrix/opaque type of the translated GLSL subset (uint/uvec kept distinct).
enum class ShaderCompiler:: StmtKind
enum class ShaderCompiler:: FixedFunctionTarget : std:: uint8_t
One backend a "void fixed_function(...) { ... }" block can name in its parentheses.
| Enumerators | |
|---|---|
| Pvr |
Dreamcast-specific override (wins over the generic block for that backend) |
| Gx |
Wii/GameCube-specific override (wins over the generic block for that backend) |
| Gu |
PlayStation Portable-specific override (wins over the generic block for that backend) |
| Gs |
PlayStation 2-specific override (wins over the generic block for that backend) |
enum ShaderCompiler:: RenderModeMask : std:: uint32_t
"render_mode" flags (bit values match ShaderCompiler::RenderMode in the generated ShaderCompilerTypes.h)
Typedef documentation
using ShaderCompiler:: SpirvCompileFn = Function<bool(StringView vulkanGlsl, bool vertexStage, SmallVectorImpl<std:: uint32_t>& spirv, String& log)>
#include <Utilities/ShaderCompiler/Emit.h>
Offline SPIR-V compiler callback injected into EmitHeader.
Compiles the Vulkan-flavored GLSL vulkanGlsl of one stage (vertexStage selects vertex vs. fragment) to SPIR-V words in spirv, returning false (and optionally filling log) when glslang is unavailable or the compile fails. Passing an empty function omits SPIR-V (the VkVsSpirv/VkFsSpirv fields are emitted as nullptr/0). Injected by the caller so Emit stays free of the process-spawning and glslang-locating code, which lives in the offline Main.cpp.
using ShaderCompiler:: DxbcCompileFn = Function<bool(StringView hlsl, bool vertexStage, SmallVectorImpl<std:: uint8_t>& dxbc, String& log)>
#include <Utilities/ShaderCompiler/Emit.h>
Offline DXBC compiler callback injected into EmitHeader.
Compiles the HLSL hlsl of one stage (vertexStage selects vertex vs. fragment) to DXBC bytecode in dxbc, returning false (and optionally filling log) when the compile fails. Passing an empty function omits DXBC — the HLSL sources are embedded instead (the HlslVsDxbc/HlslFsDxbc fields are emitted as nullptr/0 and the D3D11 backend runtime-compiles the text). Injected by the caller so Emit stays free of the d3dcompiler_47-loading code, which lives in the offline Main.cpp.
using ShaderCompiler:: ExprPtr = std:: unique_ptr<Expr>
#include <Utilities/ShaderCompiler/GlslAst.h>
using ShaderCompiler:: StmtPtr = std:: unique_ptr<Stmt>
using ShaderCompiler:: FileReader = Function<bool(StringView path, String& content)>
Reads the content of the file at path into content, returns false on failure.
Function documentation
bool ShaderCompiler:: IsQualifier(StringView k)
#include <Utilities/ShaderCompiler/GlslAst.h>
True for a type-qualifier keyword the AST parsers skip (precision / interpolation / const).
std:: int32_t ShaderCompiler:: BinPrec(StringView op)
#include <Utilities/ShaderCompiler/GlslAst.h>
Precedence of a binary/assignment operator, mirroring ConstFold's model (assignment = 1, ternary handled separately at 2). Returns -1 for anything that is not a binary operator.
ExprPtr ShaderCompiler:: MakeExpr(ExprKind kind,
String text = {})
#include <Utilities/ShaderCompiler/GlslAst.h>
Allocates an Expr of the given kind, optionally carrying literal/identifier/operator text.
bool ShaderCompiler:: TokenizeStage(StringView glsl,
SmallVectorImpl<GlslToken>& tokens,
String& reason)
#include <Utilities/ShaderCompiler/GlslAst.h>
Splits, strips comments from, preprocesses and tokenizes a GLSL stage source, appending a trailing GlslTokenType::reason) only if preprocessing fails.
std:: int32_t ShaderCompiler:: Comps(Ty t)
Ty ShaderCompiler:: BaseScalar(Ty t)
Ty ShaderCompiler:: MakeVec(Ty scalar,
std:: int32_t n)
Ty ShaderCompiler:: MatrixColumn(Ty t)
bool ShaderCompiler:: TryBuiltinType(StringView k,
Ty& out)
StmtPtr ShaderCompiler:: MakeStmt(StmtKind kind)
bool ShaderCompiler:: CompileRuntimeProgram(StringView content,
StringView baseDir,
FileReader& reader,
RuntimeProgram& out,
Diagnostic& diag)
Compiles a ".shader" source into a RuntimeProgram.
| Parameters | |
|---|---|
| content | The raw ".shader" file content (before include expansion) |
| baseDir | Directory that "#include" paths are resolved against |
| reader | Reads referenced include files (the engine passes its virtual filesystem) |
| out | Receives the compiled program |
| diag | Receives the error location and message on failure |
const char* ShaderCompiler:: FixedFunctionTargetName(FixedFunctionTarget target)
Spelling of target as it is written inside a block's parentheses.
String ShaderCompiler:: FixedFunctionTargetList(const SmallVectorImpl<FixedFunctionTarget>& targets)
The target list of a block, spelled the way the block declares it — e.g. pvr, gu (empty for the generic block).
The canonical spelling (declaration order, one ", " between entries) rather than the raw source text, so a provenance comment in a generated header cannot change just because somebody reformatted the parentheses in the shader file.
Variable documentation
std:: uint16_t ShaderCompiler:: SymbolicArraySize constexpr