blob: a12487bb86c7fee801ec865ab4f41aab13e18d99 [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 Bollb5da52a2012-09-18 18:57:02 +020010<div class="header">
11 <h1>The Mesa 3D Graphics Library</h1>
12</div>
13
14<iframe src="contents.html"></iframe>
15<div class="content">
16
Andreas Bollecd5c7c2012-06-12 09:05:03 +020017<h1>Shading Language Support</h1>
Brian9595d192007-01-20 13:40:57 -070018
19<p>
20This page describes the features and status of Mesa's support for the
Andreas Bolla73c59b2012-09-18 19:31:28 +020021<a href="http://opengl.org/documentation/glsl/">
Brian9595d192007-01-20 13:40:57 -070022OpenGL Shading Language</a>.
23</p>
24
25<p>
Brian61d31ae2007-02-17 09:41:19 -070026Contents
27</p>
28<ul>
Brian Paul439909a2009-04-07 11:09:53 -060029<li><a href="#envvars">Environment variables</a>
Andreas Bollcc418882012-06-12 09:05:33 +020030<li><a href="#glsl120">GLSL 1.20 support</a>
Brian61d31ae2007-02-17 09:41:19 -070031<li><a href="#unsup">Unsupported Features</a>
Brian07e62082007-02-27 16:45:40 -070032<li><a href="#notes">Implementation Notes</a>
Brian61d31ae2007-02-17 09:41:19 -070033<li><a href="#hints">Programming Hints</a>
Brian Paul3bfedb72008-07-17 15:40:10 -060034<li><a href="#standalone">Stand-alone GLSL Compiler</a>
Brian07e62082007-02-27 16:45:40 -070035<li><a href="#implementation">Compiler Implementation</a>
Brian7eba12e2007-03-28 17:14:35 -060036<li><a href="#validation">Compiler Validation</a>
Brian61d31ae2007-02-17 09:41:19 -070037</ul>
38
39
Andreas Bollcc418882012-06-12 09:05:33 +020040<h2 id="envvars">Environment Variables</h2>
Brian Paul439909a2009-04-07 11:09:53 -060041
42<p>
43The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
Brian Paul85fb3e42009-10-14 11:28:28 -060044list of keywords to control some aspects of the GLSL compiler and shader
45execution. These are generally used for debugging.
Brian Paul439909a2009-04-07 11:09:53 -060046</p>
47<ul>
Brian Paulf3ec1112010-08-24 09:02:05 -060048<li><b>dump</b> - print GLSL shader code to stdout at link time
49<li><b>log</b> - log all GLSL shaders to files.
Brian Paul439909a2009-04-07 11:09:53 -060050 The filenames will be "shader_X.vert" or "shader_X.frag" where X
51 the shader ID.
Brian Paulf3ec1112010-08-24 09:02:05 -060052<li><b>nopt</b> - disable compiler optimizations
53<li><b>opt</b> - force compiler optimizations
54<li><b>uniform</b> - print message to stdout when glUniform is called
55<li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
Brian Paul85fb3e42009-10-14 11:28:28 -060056 the vertex position with ftransform() and passes through the color and
57 texcoord[0] attributes.
Brian Paulf3ec1112010-08-24 09:02:05 -060058<li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
Brian Paul85fb3e42009-10-14 11:28:28 -060059 through the color attribute.
Brian Paulf3ec1112010-08-24 09:02:05 -060060<li><b>useprog</b> - log glUseProgram calls to stderr
Brian Paul439909a2009-04-07 11:09:53 -060061</ul>
62<p>
63Example: export MESA_GLSL=dump,nopt
64</p>
65
66
Andreas Bollcc418882012-06-12 09:05:33 +020067<h2 id="glsl120">GLSL Version</h2>
Brian Paulc4341fe2008-12-15 18:30:40 -070068
69<p>
Brian Paulf3ec1112010-08-24 09:02:05 -060070The GLSL compiler currently supports version 1.20 of the shading language.
71</p>
Brian Paulc4341fe2008-12-15 18:30:40 -070072
Brian Paulf3ec1112010-08-24 09:02:05 -060073<p>
74Several GLSL extensions are also supported:
75</p>
76<ul>
77<li>GL_ARB_draw_buffers
78<li>GL_ARB_texture_rectangle
79<li>GL_ARB_fragment_coord_conventions
80<li>GL_EXT_texture_array
81</ul>
Brian Paulc4341fe2008-12-15 18:30:40 -070082
83
Andreas Bollcc418882012-06-12 09:05:33 +020084<h2 id="unsup">Unsupported Features</h2>
Brian9595d192007-01-20 13:40:57 -070085
Brian Paulf3ec1112010-08-24 09:02:05 -060086<p>XXX update this section</p>
87
Brian9595d192007-01-20 13:40:57 -070088<p>
Brian Paul439909a2009-04-07 11:09:53 -060089The following features of the shading language are not yet fully supported
Brian9595d192007-01-20 13:40:57 -070090in Mesa:
91</p>
92
93<ul>
Brian Paul439909a2009-04-07 11:09:53 -060094<li>Linking of multiple shaders does not always work. Currently, linking
95 is implemented through shader concatenation and re-compiling. This
96 doesn't always work because of some #pragma and preprocessor issues.
Brianb03e1712007-03-09 09:51:55 -070097<li>gl_ClipVertex
Brian4b1d1b72007-04-27 15:25:00 -060098<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
99 without perspective correction
Brian9595d192007-01-20 13:40:57 -0700100</ul>
101
102<p>
103All other major features of the shading language should function.
104</p>
105
106
Andreas Bollcc418882012-06-12 09:05:33 +0200107<h2 id="notes">Implementation Notes</h2>
Brian9595d192007-01-20 13:40:57 -0700108
109<ul>
110<li>Shading language programs are compiled into low-level programs
111 very similar to those of GL_ARB_vertex/fragment_program.
Brianbbec2fd2007-01-28 12:11:10 -0700112<li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
Brian9595d192007-01-20 13:40:57 -0700113 float[4] registers.
Brianbbec2fd2007-01-28 12:11:10 -0700114<li>Float constants and variables are packed so that up to four floats
115 can occupy one program parameter/register.
Brian9595d192007-01-20 13:40:57 -0700116<li>All function calls are inlined.
117<li>Shaders which use too many registers will not compile.
118<li>The quality of generated code is pretty good, register usage is fair.
119<li>Shader error detection and reporting of errors (InfoLog) is not
120 very good yet.
Brian05e6fd82007-03-27 16:05:25 -0600121<li>The ftransform() function doesn't necessarily match the results of
122 fixed-function transformation.
Brian9595d192007-01-20 13:40:57 -0700123</ul>
124
125<p>
126These issues will be addressed/resolved in the future.
127</p>
128
129
Andreas Bollcc418882012-06-12 09:05:33 +0200130<h2 id="hints">Programming Hints</h2>
Brian9595d192007-01-20 13:40:57 -0700131
132<ul>
Brian9595d192007-01-20 13:40:57 -0700133<li>Use the built-in library functions whenever possible.
134 For example, instead of writing this:
135<pre>
136 float x = 1.0 / sqrt(y);
137</pre>
138 Write this:
139<pre>
140 float x = inversesqrt(y);
141</pre>
Brian7eba12e2007-03-28 17:14:35 -0600142</li>
Brian9595d192007-01-20 13:40:57 -0700143</ul>
144
145
Andreas Bollcc418882012-06-12 09:05:33 +0200146<h2 id="standalone">Stand-alone GLSL Compiler</h2>
Brian61d31ae2007-02-17 09:41:19 -0700147
148<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600149The stand-alone GLSL compiler program can be used to compile GLSL shaders
150into low-level GPU code.
Brian61d31ae2007-02-17 09:41:19 -0700151</p>
152
153<p>
154This tool is useful for:
Andreas Bolldf2be222012-06-12 09:05:22 +0200155</p>
Brian61d31ae2007-02-17 09:41:19 -0700156<ul>
157<li>Inspecting GPU code to gain insight into compilation
158<li>Generating initial GPU code for subsequent hand-tuning
159<li>Debugging the GLSL compiler itself
160</ul>
161
162<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600163After building Mesa, the compiler can be found at src/glsl/glsl_compiler
Brian61d31ae2007-02-17 09:41:19 -0700164</p>
165
166<p>
167Here's an example of using the compiler to compile a vertex shader and
168emit GL_ARB_vertex_program-style instructions:
169</p>
170<pre>
Sam Hocevarfde49432011-02-16 17:04:03 -0700171 src/glsl/glsl_compiler --dump-ast myshader.vert
Brian61d31ae2007-02-17 09:41:19 -0700172</pre>
173
Brian Paulf3ec1112010-08-24 09:02:05 -0600174Options include
175<ul>
176<li><b>--dump-ast</b> - dump GPU code
177<li><b>--dump-hir</b> - dump high-level IR code
178<li><b>--dump-lir</b> - dump low-level IR code
179<li><b>--link</b> - ???
180</ul>
181
Brian61d31ae2007-02-17 09:41:19 -0700182
Andreas Bollcc418882012-06-12 09:05:33 +0200183<h2 id="implementation">Compiler Implementation</h2>
Brian07e62082007-02-27 16:45:40 -0700184
185<p>
186The source code for Mesa's shading language compiler is in the
Brian Paulf3ec1112010-08-24 09:02:05 -0600187<code>src/glsl/</code> directory.
Brian07e62082007-02-27 16:45:40 -0700188</p>
189
190<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600191XXX provide some info about the compiler....
Brian07e62082007-02-27 16:45:40 -0700192</p>
Brian07e62082007-02-27 16:45:40 -0700193
194<p>
195The final vertex and fragment programs may be interpreted in software
196(see prog_execute.c) or translated into a specific hardware architecture
197(see drivers/dri/i915/i915_fragprog.c for example).
198</p>
199
Brian8f9db0f2007-03-23 17:49:19 -0600200<h3>Code Generation Options</h3>
201
202<p>
203Internally, there are several options that control the compiler's code
204generation and instruction selection.
205These options are seen in the gl_shader_state struct and may be set
206by the device driver to indicate its preferences:
207
208<pre>
209struct gl_shader_state
210{
211 ...
212 /** Driver-selectable options: */
213 GLboolean EmitHighLevelInstructions;
214 GLboolean EmitCondCodes;
215 GLboolean EmitComments;
216};
217</pre>
218
Andreas Bolld52419e2012-06-25 21:51:28 +0200219<dl>
220<dt>EmitHighLevelInstructions</dt>
221<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600222This option controls instruction selection for loops and conditionals.
223If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK
224instructions will be emitted.
225Otherwise, those constructs will be implemented with BRA instructions.
Andreas Bolld52419e2012-06-25 21:51:28 +0200226</dd>
Brian8f9db0f2007-03-23 17:49:19 -0600227
Andreas Bolld52419e2012-06-25 21:51:28 +0200228<dt>EmitCondCodes</dt>
229<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600230If set, condition codes (ala GL_NV_fragment_program) will be used for
231branching and looping.
232Otherwise, ordinary registers will be used (the IF instruction will
233examine the first operand's X component and do the if-part if non-zero).
234This option is only relevant if EmitHighLevelInstructions is set.
Andreas Bolld52419e2012-06-25 21:51:28 +0200235</dd>
Brian8f9db0f2007-03-23 17:49:19 -0600236
Andreas Bolld52419e2012-06-25 21:51:28 +0200237<dt>EmitComments</dt>
238<dd>
Brian8f9db0f2007-03-23 17:49:19 -0600239If set, instructions will be annoted with comments to help with debugging.
240Extra NOP instructions will also be inserted.
Andreas Bolld52419e2012-06-25 21:51:28 +0200241</dd>
242</dl>
Brian07e62082007-02-27 16:45:40 -0700243
244
Andreas Bollcc418882012-06-12 09:05:33 +0200245<h2 id="validation">Compiler Validation</h2>
Brian7eba12e2007-03-28 17:14:35 -0600246
247<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600248Developers working on the GLSL compiler should test frequently to avoid
Brian7eba12e2007-03-28 17:14:35 -0600249regressions.
250</p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600251
Brian7eba12e2007-03-28 17:14:35 -0600252<p>
Andreas Bolla73c59b2012-09-18 19:31:28 +0200253The <a href="http://piglit.freedesktop.org/">Piglit</a> project
Brian Paulf3ec1112010-08-24 09:02:05 -0600254has many GLSL tests and the
Andreas Bolla73c59b2012-09-18 19:31:28 +0200255<a href="http://glean.sf.net">Glean</a> glsl1 test tests GLSL features.
Brian7eba12e2007-03-28 17:14:35 -0600256</p>
257
Brian Paulf3ec1112010-08-24 09:02:05 -0600258<p>
259The Mesa demos repository also has some good GLSL tests.
260</p>
Brian7eba12e2007-03-28 17:14:35 -0600261
Andreas Bollb5da52a2012-09-18 18:57:02 +0200262</div>
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200263</body>
264</html>