Stand-alone GLSL Compiler
The stand-alone GLSL compiler program can be used to compile GLSL shaders
into low-level GPU code.
This tool is useful for:
- Inspecting GPU code to gain insight into compilation
- Generating initial GPU code for subsequent hand-tuning
- Debugging the GLSL compiler itself
After building Mesa, the compiler can be found at src/glsl/glsl_compiler
Here's an example of using the compiler to compile a vertex shader and
emit GL_ARB_vertex_program-style instructions:
src/glsl/glslcompiler --dump-ast myshader.vert
Options include
- --dump-ast - dump GPU code
- --dump-hir - dump high-level IR code
- --dump-lir - dump low-level IR code
- --link - ???
Compiler Implementation
The source code for Mesa's shading language compiler is in the
src/glsl/
directory.
XXX provide some info about the compiler....
The final vertex and fragment programs may be interpreted in software
(see prog_execute.c) or translated into a specific hardware architecture
(see drivers/dri/i915/i915_fragprog.c for example).
Code Generation Options
Internally, there are several options that control the compiler's code
generation and instruction selection.
These options are seen in the gl_shader_state struct and may be set
by the device driver to indicate its preferences:
struct gl_shader_state
{
...
/** Driver-selectable options: */
GLboolean EmitHighLevelInstructions;
GLboolean EmitCondCodes;
GLboolean EmitComments;
};
- EmitHighLevelInstructions
This option controls instruction selection for loops and conditionals.
If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK
instructions will be emitted.
Otherwise, those constructs will be implemented with BRA instructions.
- EmitCondCodes
If set, condition codes (ala GL_NV_fragment_program) will be used for
branching and looping.
Otherwise, ordinary registers will be used (the IF instruction will
examine the first operand's X component and do the if-part if non-zero).
This option is only relevant if EmitHighLevelInstructions is set.
- EmitComments
If set, instructions will be annoted with comments to help with debugging.
Extra NOP instructions will also be inserted.