CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
ShaderCompiler.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "IncludeHandler.hpp"
11#include "Log.hpp"
12#include "Reflection.hpp"
13#include "Targets.hpp"
14
16
22
23#include <istream>
24#include <memory>
25#include <ostream>
26
28
31 struct Warnings {
32 enum : UInt32 {
34 Basic = (1 << 0),
35
37 Syntax = (1 << 1),
38
40 PreProcessor = (1 << 2),
41
43 UnusedVariables = (1 << 3),
44
47
50
53
55 UnlocatedObjects = (1 << 7),
56
59
61 CodeReflection = (1 << 9),
62
64 IndexBoundary = (1 << 10),
65
67 All = (~0u),
68 };
69 };
70
73 struct Extensions {
74 enum : UInt32 {
76 LayoutAttribute = (1 << 0),
77
79 SpaceAttribute = (1 << 1),
80
82 All = (~0u)
83 };
84 };
85
88 struct Formatting {
90 bool alwaysBracedScopes = true;
91
93 bool blanks = true;
94
97 bool compactWrappers = false;
98
101
103 bool lineMarks = false;
104
106 bool lineSeparation = true;
107
111 bool newLineOpenScope = false;
112 };
113
115 struct Options {
118 bool allowExtensions = false;
119
123 bool autoBinding = false;
124
128
130 bool explicitBinding = false;
131
133 bool obfuscate = false;
134
136 bool optimize = false;
137
138 //TODO: maybe merge this option with "optimize" (preferWrappers == !optimize)
141 bool preferWrappers = false;
142
144 bool preprocessOnly = false;
145
147 bool preserveComments = false;
148
151 bool rowMajorAlignment = false;
152
155 bool separateSamplers = false;
156
159 bool separateShaders = false;
160
163 bool showAST = false;
164
167 bool showTimes = false;
168
169 //TODO: remove this option, and determine automatically when unrolling initializers are required!
172
175 bool validateOnly = false;
176
180 };
181
189
193
198
202
208
212 bool useAlwaysSemantics = false;
213
218 bool renameBufferFields = false;
219 };
220
265
275
281 bool enabled = false;
282
286
288 String bufferName = "xsp_buffer";
289 };
290
325
339
340} // namespace CeresEngine::ShaderCompiler
Interface for handling new include streams.
Definition IncludeHandler.hpp:21
Log base class.
Definition Log.hpp:19
Pre-processor to substitute macros and include directives.
Definition PreProcessor.hpp:38
Definition AST.hpp:33
InputShaderVersion
Input shader version enumeration.
Definition Targets.hpp:40
@ HLSL5
HLSL Shader Model 5.0 (DirectX 11).
ShaderTarget
Shader target enumeration.
Definition Targets.hpp:16
@ Undefined
Undefined shader target.
bool compileShader(const ShaderInput &inputDesc, const ShaderOutput &outputDesc, Log *log=nullptr, Reflection::ReflectionData *reflectionData=nullptr)
Cross compiles the shader code from the specified input stream into the specified output shader code.
OutputShaderVersion
Output shader version enumeration.
Definition Targets.hpp:67
@ GLSL
Auto-detect minimal required GLSL version (for OpenGL 2+).
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
std::int32_t Int32
Definition DataTypes.hpp:21
sfl::small_vector< T, N, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > SmallVector
SmallVector is a sequence container similar to Vector.
Definition SmallVector.hpp:31
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Language extension flags.
Definition ShaderCompiler.hpp:73
@ SpaceAttribute
Enables the 'space' attribute extension for a stronger type system (e.g. "[space(OBJECT,...
Definition ShaderCompiler.hpp:79
@ LayoutAttribute
Enables the 'layout' attribute extension (e.g. "[layout(rgba8)]").
Definition ShaderCompiler.hpp:76
@ All
All extensions.
Definition ShaderCompiler.hpp:82
Formatting descriptor structure for the output shader.
Definition ShaderCompiler.hpp:88
String indent
Indentation string for code generation. By default, String(4, ' ').
Definition ShaderCompiler.hpp:100
bool lineMarks
If true, line marks are allowed. By default, false.
Definition ShaderCompiler.hpp:103
bool newLineOpenScope
If true, the '{'-braces for an open scope gets its own line.
Definition ShaderCompiler.hpp:111
bool lineSeparation
If true, auto-formatting of line separation is allowed. By default, true.
Definition ShaderCompiler.hpp:106
bool compactWrappers
If true, wrapper functions for special intrinsics are written in a compact formatting (i....
Definition ShaderCompiler.hpp:97
bool alwaysBracedScopes
If true, scopes are always written in braces. By default, true.
Definition ShaderCompiler.hpp:90
bool blanks
If true, blank lines are allowed. By default, true.
Definition ShaderCompiler.hpp:93
Name mangling descriptor structure for shader input/output variables (also referred to as "varyings")...
Definition ShaderCompiler.hpp:185
String reservedWordPrefix
Name mangling prefix for reserved words (such as "texture", "main", "sin" etc.).
Definition ShaderCompiler.hpp:197
String namespacePrefix
Name mangling prefix for namespaces like structures or classes.
Definition ShaderCompiler.hpp:207
bool useAlwaysSemantics
If true, shader input/output variables are always renamed to their semantics, even for vertex input a...
Definition ShaderCompiler.hpp:212
bool renameBufferFields
If true, the data fields of a 'buffer'-objects is renamed rather than the outer identifier.
Definition ShaderCompiler.hpp:218
String temporaryPrefix
Name mangling prefix for temporary variables.
Definition ShaderCompiler.hpp:201
String inputPrefix
Name mangling prefix for shader input variables.
Definition ShaderCompiler.hpp:188
String outputPrefix
Name mangling prefix for shader output variables.
Definition ShaderCompiler.hpp:192
Structure for additional translation options.
Definition ShaderCompiler.hpp:115
Int32 autoBindingStartSlot
Index to start generating binding slots from.
Definition ShaderCompiler.hpp:127
bool rowMajorAlignment
If true, matrices have row-major alignment.
Definition ShaderCompiler.hpp:151
bool obfuscate
If true, code obfuscation is performed. By default, false.
Definition ShaderCompiler.hpp:133
bool autoBinding
If true, binding slots for all buffer types will be generated sequentially, starting with index at 'a...
Definition ShaderCompiler.hpp:123
bool preprocessOnly
If true, only the preprocessed source code will be written out. By default, false.
Definition ShaderCompiler.hpp:144
bool preferWrappers
If true, intrinsics are prefered to be implemented as wrappers (instead of inlining).
Definition ShaderCompiler.hpp:141
bool preserveComments
If true, commentaries are preserved for each statement. By default, false.
Definition ShaderCompiler.hpp:147
bool optimize
If true, little code optimizations are performed. By default, false.
Definition ShaderCompiler.hpp:136
bool separateSamplers
If true, generated GLSL code will contain separate sampler and texture objects when supported.
Definition ShaderCompiler.hpp:155
bool showAST
If true, the AST (Abstract Syntax Tree) will be written to the log output.
Definition ShaderCompiler.hpp:163
bool showTimes
If true, the timings of the different compilation processes are written to the log output.
Definition ShaderCompiler.hpp:167
bool explicitBinding
If true, explicit binding slots are enabled. By default, false.
Definition ShaderCompiler.hpp:130
bool writeGeneratorHeader
If true, the generator header with metadata is written as first comment to the output.
Definition ShaderCompiler.hpp:179
bool unrollArrayInitializers
If true, array initializations will be unrolled. By default, false.
Definition ShaderCompiler.hpp:171
bool separateShaders
If true, generated GLSL code will support the 'ARB_separate_shader_objects' extension.
Definition ShaderCompiler.hpp:159
bool allowExtensions
If true, the shader output may contain GLSL extensions, if the target shader version is too low.
Definition ShaderCompiler.hpp:118
bool validateOnly
If true, the source code is only validated, but no output code will be generated.
Definition ShaderCompiler.hpp:175
Structure for shader output statistics (e.g. texture/buffer binding points).
Definition Reflection.hpp:418
Shader input descriptor structure.
Definition ShaderCompiler.hpp:223
SPtr< std::istream > sourceCode
Specifies the input source code stream.
Definition ShaderCompiler.hpp:229
String entryPoint
Specifies the HLSL shader entry point. By default, "main".
Definition ShaderCompiler.hpp:239
InputShaderVersion shaderVersion
Specifies the input shader version (e.g.
Definition ShaderCompiler.hpp:233
ShaderTarget shaderTarget
Specifies the target shader (Vertex, Fragment etc.). By default, ShaderTarget::Undefined.
Definition ShaderCompiler.hpp:236
String secondaryEntryPoint
Specifies the secondary HLSL shader entry point.
Definition ShaderCompiler.hpp:247
UInt32 warnings
Compiler warning flags.
Definition ShaderCompiler.hpp:252
IncludeHandler * includeHandler
Optional pointer to the implementation of the "IncludeHandler" interface.
Definition ShaderCompiler.hpp:263
String filename
Specifies the filename of the input shader code.
Definition ShaderCompiler.hpp:226
UInt32 extensions
Language extension flags.
Definition ShaderCompiler.hpp:257
Shader output descriptor structure.
Definition ShaderCompiler.hpp:293
OutputShaderVersion shaderVersion
Specifies the output shader version.
Definition ShaderCompiler.hpp:305
UniformPacking uniformPacking
Optional parameters to pack all global uniforms into a single output uniform buffer.
Definition ShaderCompiler.hpp:314
NameMangling nameMangling
Specifies the options for name mangling.
Definition ShaderCompiler.hpp:323
String filename
Specifies the filename of the output shader code.
Definition ShaderCompiler.hpp:296
Formatting formatting
Output code formatting descriptor.
Definition ShaderCompiler.hpp:320
std::ostream * sourceCode
Specifies the output source code stream.
Definition ShaderCompiler.hpp:301
SmallVector< VertexSemantic, 10 > vertexSemantics
Optional list of vertex semantic layouts, to bind a vertex attribute (semantic name) to a location in...
Definition ShaderCompiler.hpp:310
Options options
Additional options to configure the code generation.
Definition ShaderCompiler.hpp:317
Uniform packing parameter structure.
Definition ShaderCompiler.hpp:278
Int32 bindingSlot
Index of the binding slot for this uniform buffer.
Definition ShaderCompiler.hpp:285
bool enabled
If true, all global uniform statements will be packed into a single uniform buffer (except for textur...
Definition ShaderCompiler.hpp:281
String bufferName
Name of the uniform buffer. By default, "xsp_buffer".
Definition ShaderCompiler.hpp:288
Vertex shader semantic (or rather attribute) layout structure.
Definition ShaderCompiler.hpp:268
Int32 location
Specifies the binding location.
Definition ShaderCompiler.hpp:273
String semantic
Specifies the shader semantic (or rather attribute).
Definition ShaderCompiler.hpp:270
Compiler warning flags.
Definition ShaderCompiler.hpp:31
@ IndexBoundary
Warning for index boundary violations.
Definition ShaderCompiler.hpp:64
@ Basic
Warning for basic issues (control path, disabled code etc.).
Definition ShaderCompiler.hpp:34
@ Syntax
Warning for syntactic issues.
Definition ShaderCompiler.hpp:37
@ RequiredExtensions
Warning for required extensions in the output code.
Definition ShaderCompiler.hpp:58
@ UnlocatedObjects
Warning for optional objects that where not found.
Definition ShaderCompiler.hpp:55
@ DeclarationShadowing
Warning for declarations that shadow a previous local (e.g. for-loops or variables in class hierarchy...
Definition ShaderCompiler.hpp:52
@ CodeReflection
Warning for issues during code reflection.
Definition ShaderCompiler.hpp:61
@ All
All warnings.
Definition ShaderCompiler.hpp:67
@ UnusedVariables
Warning for unused variables.
Definition ShaderCompiler.hpp:43
@ ImplicitTypeConversions
Warning for specific implicit type conversions.
Definition ShaderCompiler.hpp:49
@ EmptyStatementBody
Warning for statements with empty body.
Definition ShaderCompiler.hpp:46