blob: 371891711d7b4a80218079b1539d8dd3cd8e682a [file] [log] [blame]
Andreas Bollecd5c7c2012-06-12 09:05:03 +02001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html lang="en">
3<head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8">
5 <title>Shading Language Support</title>
6 <link rel="stylesheet" type="text/css" href="mesa.css">
7</head>
8<body>
Brian9595d192007-01-20 13:40:57 -07009
Andreas Bollecd5c7c2012-06-12 09:05:03 +020010<h1>Shading Language Support</h1>
Brian9595d192007-01-20 13:40:57 -070011
12<p>
13This page describes the features and status of Mesa's support for the
14<a href="http://opengl.org/documentation/glsl/" target="_parent">
15OpenGL Shading Language</a>.
16</p>
17
18<p>
Brian61d31ae2007-02-17 09:41:19 -070019Contents
20</p>
21<ul>
Brian Paul439909a2009-04-07 11:09:53 -060022<li><a href="#envvars">Environment variables</a>
Andreas Bollcc418882012-06-12 09:05:33 +020023<li><a href="#glsl120">GLSL 1.20 support</a>
Brian61d31ae2007-02-17 09:41:19 -070024<li><a href="#unsup">Unsupported Features</a>
Brian07e62082007-02-27 16:45:40 -070025<li><a href="#notes">Implementation Notes</a>
Brian61d31ae2007-02-17 09:41:19 -070026<li><a href="#hints">Programming Hints</a>
Brian Paul3bfedb72008-07-17 15:40:10 -060027<li><a href="#standalone">Stand-alone GLSL Compiler</a>
Brian07e62082007-02-27 16:45:40 -070028<li><a href="#implementation">Compiler Implementation</a>
Brian7eba12e2007-03-28 17:14:35 -060029<li><a href="#validation">Compiler Validation</a>
Brian61d31ae2007-02-17 09:41:19 -070030</ul>
31
32
Andreas Bollcc418882012-06-12 09:05:33 +020033<h2 id="envvars">Environment Variables</h2>
Brian Paul439909a2009-04-07 11:09:53 -060034
35<p>
36The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
Brian Paul85fb3e42009-10-14 11:28:28 -060037list of keywords to control some aspects of the GLSL compiler and shader
38execution. These are generally used for debugging.
Brian Paul439909a2009-04-07 11:09:53 -060039</p>
40<ul>
Brian Paulf3ec1112010-08-24 09:02:05 -060041<li><b>dump</b> - print GLSL shader code to stdout at link time
42<li><b>log</b> - log all GLSL shaders to files.
Brian Paul439909a2009-04-07 11:09:53 -060043 The filenames will be "shader_X.vert" or "shader_X.frag" where X
44 the shader ID.
Brian Paulf3ec1112010-08-24 09:02:05 -060045<li><b>nopt</b> - disable compiler optimizations
46<li><b>opt</b> - force compiler optimizations
47<li><b>uniform</b> - print message to stdout when glUniform is called
48<li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
Brian Paul85fb3e42009-10-14 11:28:28 -060049 the vertex position with ftransform() and passes through the color and
50 texcoord[0] attributes.
Brian Paulf3ec1112010-08-24 09:02:05 -060051<li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
Brian Paul85fb3e42009-10-14 11:28:28 -060052 through the color attribute.
Brian Paulf3ec1112010-08-24 09:02:05 -060053<li><b>useprog</b> - log glUseProgram calls to stderr
Brian Paul439909a2009-04-07 11:09:53 -060054</ul>
55<p>
56Example: export MESA_GLSL=dump,nopt
57</p>
58
59
Andreas Bollcc418882012-06-12 09:05:33 +020060<h2 id="glsl120">GLSL Version</h2>
Brian Paulc4341fe2008-12-15 18:30:40 -070061
62<p>
Brian Paulf3ec1112010-08-24 09:02:05 -060063The GLSL compiler currently supports version 1.20 of the shading language.
64</p>
Brian Paulc4341fe2008-12-15 18:30:40 -070065
Brian Paulf3ec1112010-08-24 09:02:05 -060066<p>
67Several GLSL extensions are also supported:
68</p>
69<ul>
70<li>GL_ARB_draw_buffers
71<li>GL_ARB_texture_rectangle
72<li>GL_ARB_fragment_coord_conventions
73<li>GL_EXT_texture_array
74</ul>
Brian Paulc4341fe2008-12-15 18:30:40 -070075
76
Andreas Bollcc418882012-06-12 09:05:33 +020077<h2 id="unsup">Unsupported Features</h2>
Brian9595d192007-01-20 13:40:57 -070078
Brian Paulf3ec1112010-08-24 09:02:05 -060079<p>XXX update this section</p>
80
Brian9595d192007-01-20 13:40:57 -070081<p>
Brian Paul439909a2009-04-07 11:09:53 -060082The following features of the shading language are not yet fully supported
Brian9595d192007-01-20 13:40:57 -070083in Mesa:
84</p>
85
86<ul>
Brian Paul439909a2009-04-07 11:09:53 -060087<li>Linking of multiple shaders does not always work. Currently, linking
88 is implemented through shader concatenation and re-compiling. This
89 doesn't always work because of some #pragma and preprocessor issues.
Brianb03e1712007-03-09 09:51:55 -070090<li>gl_ClipVertex
Brian4b1d1b72007-04-27 15:25:00 -060091<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
92 without perspective correction
Brian9595d192007-01-20 13:40:57 -070093</ul>
94
95<p>
96All other major features of the shading language should function.
97</p>
98
99
Andreas Bollcc418882012-06-12 09:05:33 +0200100<h2 id="notes">Implementation Notes</h2>
Brian9595d192007-01-20 13:40:57 -0700101
102<ul>
103<li>Shading language programs are compiled into low-level programs
104 very similar to those of GL_ARB_vertex/fragment_program.
Brianbbec2fd2007-01-28 12:11:10 -0700105<li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
Brian9595d192007-01-20 13:40:57 -0700106 float[4] registers.
Brianbbec2fd2007-01-28 12:11:10 -0700107<li>Float constants and variables are packed so that up to four floats
108 can occupy one program parameter/register.
Brian9595d192007-01-20 13:40:57 -0700109<li>All function calls are inlined.
110<li>Shaders which use too many registers will not compile.
111<li>The quality of generated code is pretty good, register usage is fair.
112<li>Shader error detection and reporting of errors (InfoLog) is not
113 very good yet.
Brian05e6fd82007-03-27 16:05:25 -0600114<li>The ftransform() function doesn't necessarily match the results of
115 fixed-function transformation.
Brian9595d192007-01-20 13:40:57 -0700116</ul>
117
118<p>
119These issues will be addressed/resolved in the future.
120</p>
121
122
Andreas Bollcc418882012-06-12 09:05:33 +0200123<h2 id="hints">Programming Hints</h2>
Brian9595d192007-01-20 13:40:57 -0700124
125<ul>
Brian9595d192007-01-20 13:40:57 -0700126<li>Use the built-in library functions whenever possible.
127 For example, instead of writing this:
128<pre>
129 float x = 1.0 / sqrt(y);
130</pre>
131 Write this:
132<pre>
133 float x = inversesqrt(y);
134</pre>
Brian7eba12e2007-03-28 17:14:35 -0600135</li>
Brian9595d192007-01-20 13:40:57 -0700136</ul>
137
138
Andreas Bollcc418882012-06-12 09:05:33 +0200139<h2 id="standalone">Stand-alone GLSL Compiler</h2>
Brian61d31ae2007-02-17 09:41:19 -0700140
141<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600142The stand-alone GLSL compiler program can be used to compile GLSL shaders
143into low-level GPU code.
Brian61d31ae2007-02-17 09:41:19 -0700144</p>
145
146<p>
147This tool is useful for:
Andreas Bolldf2be222012-06-12 09:05:22 +0200148</p>
Brian61d31ae2007-02-17 09:41:19 -0700149<ul>
150<li>Inspecting GPU code to gain insight into compilation
151<li>Generating initial GPU code for subsequent hand-tuning
152<li>Debugging the GLSL compiler itself
153</ul>
154
155<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600156After building Mesa, the compiler can be found at src/glsl/glsl_compiler
Brian61d31ae2007-02-17 09:41:19 -0700157</p>
158
159<p>
160Here's an example of using the compiler to compile a vertex shader and
161emit GL_ARB_vertex_program-style instructions:
162</p>
163<pre>
Sam Hocevarfde49432011-02-16 17:04:03 -0700164 src/glsl/glsl_compiler --dump-ast myshader.vert
Brian61d31ae2007-02-17 09:41:19 -0700165</pre>
166
Brian Paulf3ec1112010-08-24 09:02:05 -0600167Options include
168<ul>
169<li><b>--dump-ast</b> - dump GPU code
170<li><b>--dump-hir</b> - dump high-level IR code
171<li><b>--dump-lir</b> - dump low-level IR code
172<li><b>--link</b> - ???
173</ul>
174
Brian61d31ae2007-02-17 09:41:19 -0700175
Andreas Bollcc418882012-06-12 09:05:33 +0200176<h2 id="implementation">Compiler Implementation</h2>
Brian07e62082007-02-27 16:45:40 -0700177
178<p>
179The source code for Mesa's shading language compiler is in the
Brian Paulf3ec1112010-08-24 09:02:05 -0600180<code>src/glsl/</code> directory.
Brian07e62082007-02-27 16:45:40 -0700181</p>
182
183<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600184XXX provide some info about the compiler....
Brian07e62082007-02-27 16:45:40 -0700185</p>
Brian07e62082007-02-27 16:45:40 -0700186
187<p>
188The final vertex and fragment programs may be interpreted in software
189(see prog_execute.c) or translated into a specific hardware architecture
190(see drivers/dri/i915/i915_fragprog.c for example).
191</p>
192
Brian8f9db0f2007-03-23 17:49:19 -0600193<h3>Code Generation Options</h3>
194
195<p>
196Internally, there are several options that control the compiler's code
197generation and instruction selection.
198These options are seen in the gl_shader_state struct and may be set
199by the device driver to indicate its preferences:
200
201<pre>
202struct gl_shader_state
203{
204 ...
205 /** Driver-selectable options: */
206 GLboolean EmitHighLevelInstructions;
207 GLboolean EmitCondCodes;
208 GLboolean EmitComments;
209};
210</pre>
211
Andreas Bolld52419e2012-06-25 21:51:28 +0200212<dl>
213<dt>EmitHighLevelInstructions</dt>
214<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600215This option controls instruction selection for loops and conditionals.
216If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK
217instructions will be emitted.
218Otherwise, those constructs will be implemented with BRA instructions.
Andreas Bolld52419e2012-06-25 21:51:28 +0200219</dd>
Brian8f9db0f2007-03-23 17:49:19 -0600220
Andreas Bolld52419e2012-06-25 21:51:28 +0200221<dt>EmitCondCodes</dt>
222<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600223If set, condition codes (ala GL_NV_fragment_program) will be used for
224branching and looping.
225Otherwise, ordinary registers will be used (the IF instruction will
226examine the first operand's X component and do the if-part if non-zero).
227This option is only relevant if EmitHighLevelInstructions is set.
Andreas Bolld52419e2012-06-25 21:51:28 +0200228</dd>
Brian8f9db0f2007-03-23 17:49:19 -0600229
Andreas Bolld52419e2012-06-25 21:51:28 +0200230<dt>EmitComments</dt>
231<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600232If set, instructions will be annoted with comments to help with debugging.
233Extra NOP instructions will also be inserted.
Andreas Bolld52419e2012-06-25 21:51:28 +0200234</dd>
235</dl>
Brian07e62082007-02-27 16:45:40 -0700236
237
Andreas Bollcc418882012-06-12 09:05:33 +0200238<h2 id="validation">Compiler Validation</h2>
Brian7eba12e2007-03-28 17:14:35 -0600239
240<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600241Developers working on the GLSL compiler should test frequently to avoid
Brian7eba12e2007-03-28 17:14:35 -0600242regressions.
243</p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600244
Brian7eba12e2007-03-28 17:14:35 -0600245<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600246The <a href="http://people.freedesktop.org/~nh/piglit/">Piglit</a> project
247has many GLSL tests and the
248<a href="http://glean.sf.net" target="_parent">Glean</a> glsl1 test
249tests GLSL features.
Brian7eba12e2007-03-28 17:14:35 -0600250</p>
251
Brian Paulf3ec1112010-08-24 09:02:05 -0600252<p>
253The Mesa demos repository also has some good GLSL tests.
254</p>
Brian7eba12e2007-03-28 17:14:35 -0600255
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200256</body>
257</html>