3 <TITLE>Shading Language Support
</TITLE>
5 <link rel=
"stylesheet" type=
"text/css" href=
"mesa.css"></head>
9 <H1>Shading Language Support
</H1>
12 This page describes the features and status of Mesa's support for the
13 <a href=
"http://opengl.org/documentation/glsl/" target=
"_parent">
14 OpenGL Shading Language
</a>.
18 Last updated on
17 Feb
2007.
25 <li><a href=
"#unsup">Unsupported Features
</a>
26 <li><a href=
"#impl">Implementation Notes
</a>
27 <li><a href=
"#hints">Programming Hints
</a>
28 <li><a href=
"#standalone">Stand-alone Compiler
</a>
33 <h2>Unsupported Features
</h2>
36 The following features of the shading language are not yet supported
41 <li>Dereferencing arrays with non-constant indexes
42 <li>User-defined structs
43 <li>Linking of multiple shaders is not supported
44 <li>Integer operations are not fully implemented (most are implemented
49 All other major features of the shading language should function.
54 <h2>Implementation Notes
</h2>
57 <li>Shading language programs are compiled into low-level programs
58 very similar to those of GL_ARB_vertex/fragment_program.
59 <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
61 <li>Float constants and variables are packed so that up to four floats
62 can occupy one program parameter/register.
63 <li>All function calls are inlined.
64 <li>Shaders which use too many registers will not compile.
65 <li>The quality of generated code is pretty good, register usage is fair.
66 <li>Shader error detection and reporting of errors (InfoLog) is not
68 <li>There are massive memory leaks in the compiler.
72 These issues will be addressed/resolved in the future.
77 <h2>Programming Hints
</h2>
80 <li>Declare
<em>in
</em> function parameters as
<em>const
</em> whenever possible.
81 This improves the efficiency of function inlining.
84 <li>To reduce register usage, declare variables within smaller scopes.
85 For example, the following code:
90 gl_Position = expression using a1, a2.
91 gl_Color = expression using b1, b2;
94 Can be rewritten as follows to use half as many registers:
100 gl_Position = expression using a1, a2.
104 gl_Color = expression using b1, b2;
108 Alternately, rather than using several float variables, use
109 a vec4 instead. Use swizzling and writemasks to access the
110 components of the vec4 as floats.
113 <li>Use the built-in library functions whenever possible.
114 For example, instead of writing this:
116 float x =
1.0 / sqrt(y);
120 float x = inversesqrt(y);
125 <a name=
"standalone">
126 <h2>Stand-alone Compiler
</h2>
129 A unique stand-alone GLSL compiler driver has been added to Mesa.
133 The stand-alone compiler (like a conventional command-line compiler)
134 is a tool that accepts Shading Language programs and emits low-level
139 This tool is useful for:
142 <li>Inspecting GPU code to gain insight into compilation
143 <li>Generating initial GPU code for subsequent hand-tuning
144 <li>Debugging the GLSL compiler itself
148 To build the glslcompiler program (this will be improved someday):
153 cd drivers/glslcompiler
159 Here's an example of using the compiler to compile a vertex shader and
160 emit GL_ARB_vertex_program-style instructions:
163 glslcompiler --arb --linenumbers --vs vertshader.txt
166 The output may look similar to this:
170 0: MOV result.texcoord[
0], vertex.texcoord[
0];
171 1: DP4 temp0.x, state.matrix.mvp.row[
0], vertex.position;
172 2: DP4 temp0.y, state.matrix.mvp.row[
1], vertex.position;
173 3: DP4 temp0.z, state.matrix.mvp.row[
2], vertex.position;
174 4: DP4 temp0.w, state.matrix.mvp.row[
3], vertex.position;
175 5: MOV result.position, temp0;
180 Note that some shading language constructs (such as uniform and varying
181 variables) aren't expressible in ARB or NV-style programs.
182 Therefore, the resulting output is not always legal by definition of
183 those program languages.
186 Also note that this compiler driver is still under development.
187 Over time, the correctness of the GPU programs, with respect to the ARB
188 and NV languagues, should improve.