
When the regular expression is matched, the corresponding C code is executed. Each line begins with a regular expression followed by a statement written in C code. The source file is hlsl_lexer.ll and is processed by flex to produce C code. The lexer tokenizes the HLSL input by matching regular expressions to corresponding tokens. The HLSL parser is built in two parts: the lexer and the parser. See GenerateGlsl and especially the ir_gen_glsl_visitor class for details. This mapping table is parsed by Unreal to allow the binding of parameters. In addition to producing definitions of all structs and uniform buffers and the source itself, a mapping table is written out in comments at the top of the file. The conversion from IR to GLSL is relatively straight-forward. See PackUniforms for details.Īfter uniforms have been packed, a second round of optimizations is run on the IR to simplify the code generated when packing uniforms.įinally the optimized IR is converted to GLSL source code. Global uniforms are packed in to arrays with mapping information retained so the engine may bind parameters to the relevant portion of the uniform array. See OptimizeIR and especially do_optimization_pass for details. Several optimization passes are performed on the IR including function inlining, dead code elimination, constant propagation, elimination of common subexpressions, and so on.

This stage will add global declarations for input and output variables to the IR, compute the inputs for the HLSL entry point, call the HLSL entry point, and write outputs to the global output variables. During this stage, the compiler performs functions such as implicit conversions, function overload resolution, generating instructions for intrinsics, and so on. This process happens in the function _mesa_ast_to_hir.

The AST is compiled in to Mesa intermediate representation. See the section on parsing for more information. The lexer and parser are generated by flex and bison respectively. This is done in the function _mesa_hlsl_parse. The HLSL source is parsed in to an abstract syntax tree.

Unreal performs preprocessing using MCPP before compilation and therefore skips this step. This stage is optional and may be omitted by using the NoPreprocess flag. The code is run through a C-like preprocessor. This function performs all steps needed to generate GLSL code from the source HLSL with the requested options.

The main library entry point is HLSLCrossCompile. When you rebuild the HLSLCC library, add a space to OpenGLShaders.cpp to force the module to re-link. UnrealBuildTool does not detect changes to external libraries, such as the HLSLCC.
