blob: cf989ce9029a6a420ef55f94419d7ec37b8c165d [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 Bolld4956692012-10-02 15:35:27 +020030<li><a href="#support">GLSL 1.40 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
Tapani Pälli04e201d2015-08-31 09:54:23 +030066<p>
67Shaders can be dumped and replaced on runtime for debugging purposes. Mesa
68needs to be configured with '--with-sha1' to enable this functionality. This
69feature is not currently supported by SCons build.
70
71This is controlled via following environment variables:
72<ul>
73<li><b>MESA_SHADER_DUMP_PATH</b> - path where shader sources are dumped
74<li><b>MESA_SHADER_READ_PATH</b> - path where replacement shaders are read
75</ul>
76Note, path set must exist before running for dumping or replacing to work.
77When both are set, these paths should be different so the dumped shaders do
78not clobber the replacement shaders.
79</p>
Brian Paul439909a2009-04-07 11:09:53 -060080
Andreas Bolld4956692012-10-02 15:35:27 +020081<h2 id="support">GLSL Version</h2>
Brian Paulc4341fe2008-12-15 18:30:40 -070082
83<p>
Chris Forbesf6159af2013-11-24 17:44:06 +130084The GLSL compiler currently supports version 3.30 of the shading language.
Brian Paulf3ec1112010-08-24 09:02:05 -060085</p>
Brian Paulc4341fe2008-12-15 18:30:40 -070086
Brian Paulf3ec1112010-08-24 09:02:05 -060087<p>
88Several GLSL extensions are also supported:
89</p>
90<ul>
91<li>GL_ARB_draw_buffers
Brian Paulf3ec1112010-08-24 09:02:05 -060092<li>GL_ARB_fragment_coord_conventions
Andreas Bolld4956692012-10-02 15:35:27 +020093<li>GL_ARB_shader_bit_encoding
Brian Paulf3ec1112010-08-24 09:02:05 -060094</ul>
Brian Paulc4341fe2008-12-15 18:30:40 -070095
96
Andreas Bollcc418882012-06-12 09:05:33 +020097<h2 id="unsup">Unsupported Features</h2>
Brian9595d192007-01-20 13:40:57 -070098
Brian Paulf3ec1112010-08-24 09:02:05 -060099<p>XXX update this section</p>
100
Brian9595d192007-01-20 13:40:57 -0700101<p>
Brian Paul439909a2009-04-07 11:09:53 -0600102The following features of the shading language are not yet fully supported
Brian9595d192007-01-20 13:40:57 -0700103in Mesa:
104</p>
105
106<ul>
Brian Paul439909a2009-04-07 11:09:53 -0600107<li>Linking of multiple shaders does not always work. Currently, linking
108 is implemented through shader concatenation and re-compiling. This
109 doesn't always work because of some #pragma and preprocessor issues.
Brian4b1d1b72007-04-27 15:25:00 -0600110<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
111 without perspective correction
Brian9595d192007-01-20 13:40:57 -0700112</ul>
113
114<p>
115All other major features of the shading language should function.
116</p>
117
118
Andreas Bollcc418882012-06-12 09:05:33 +0200119<h2 id="notes">Implementation Notes</h2>
Brian9595d192007-01-20 13:40:57 -0700120
121<ul>
122<li>Shading language programs are compiled into low-level programs
123 very similar to those of GL_ARB_vertex/fragment_program.
Brianbbec2fd2007-01-28 12:11:10 -0700124<li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
Brian9595d192007-01-20 13:40:57 -0700125 float[4] registers.
Brianbbec2fd2007-01-28 12:11:10 -0700126<li>Float constants and variables are packed so that up to four floats
127 can occupy one program parameter/register.
Brian9595d192007-01-20 13:40:57 -0700128<li>All function calls are inlined.
129<li>Shaders which use too many registers will not compile.
130<li>The quality of generated code is pretty good, register usage is fair.
131<li>Shader error detection and reporting of errors (InfoLog) is not
132 very good yet.
Brian05e6fd82007-03-27 16:05:25 -0600133<li>The ftransform() function doesn't necessarily match the results of
134 fixed-function transformation.
Brian9595d192007-01-20 13:40:57 -0700135</ul>
136
137<p>
138These issues will be addressed/resolved in the future.
139</p>
140
141
Andreas Bollcc418882012-06-12 09:05:33 +0200142<h2 id="hints">Programming Hints</h2>
Brian9595d192007-01-20 13:40:57 -0700143
144<ul>
Brian9595d192007-01-20 13:40:57 -0700145<li>Use the built-in library functions whenever possible.
146 For example, instead of writing this:
147<pre>
148 float x = 1.0 / sqrt(y);
149</pre>
150 Write this:
151<pre>
152 float x = inversesqrt(y);
153</pre>
Brian7eba12e2007-03-28 17:14:35 -0600154</li>
Brian9595d192007-01-20 13:40:57 -0700155</ul>
156
157
Andreas Bollcc418882012-06-12 09:05:33 +0200158<h2 id="standalone">Stand-alone GLSL Compiler</h2>
Brian61d31ae2007-02-17 09:41:19 -0700159
160<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600161The stand-alone GLSL compiler program can be used to compile GLSL shaders
162into low-level GPU code.
Brian61d31ae2007-02-17 09:41:19 -0700163</p>
164
165<p>
166This tool is useful for:
Andreas Bolldf2be222012-06-12 09:05:22 +0200167</p>
Brian61d31ae2007-02-17 09:41:19 -0700168<ul>
169<li>Inspecting GPU code to gain insight into compilation
170<li>Generating initial GPU code for subsequent hand-tuning
171<li>Debugging the GLSL compiler itself
172</ul>
173
174<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600175After building Mesa, the compiler can be found at src/glsl/glsl_compiler
Brian61d31ae2007-02-17 09:41:19 -0700176</p>
177
178<p>
179Here's an example of using the compiler to compile a vertex shader and
180emit GL_ARB_vertex_program-style instructions:
181</p>
182<pre>
Sam Hocevarfde49432011-02-16 17:04:03 -0700183 src/glsl/glsl_compiler --dump-ast myshader.vert
Brian61d31ae2007-02-17 09:41:19 -0700184</pre>
185
Brian Paulf3ec1112010-08-24 09:02:05 -0600186Options include
187<ul>
188<li><b>--dump-ast</b> - dump GPU code
189<li><b>--dump-hir</b> - dump high-level IR code
190<li><b>--dump-lir</b> - dump low-level IR code
191<li><b>--link</b> - ???
192</ul>
193
Brian61d31ae2007-02-17 09:41:19 -0700194
Andreas Bollcc418882012-06-12 09:05:33 +0200195<h2 id="implementation">Compiler Implementation</h2>
Brian07e62082007-02-27 16:45:40 -0700196
197<p>
198The source code for Mesa's shading language compiler is in the
Brian Paulf3ec1112010-08-24 09:02:05 -0600199<code>src/glsl/</code> directory.
Brian07e62082007-02-27 16:45:40 -0700200</p>
201
202<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600203XXX provide some info about the compiler....
Brian07e62082007-02-27 16:45:40 -0700204</p>
Brian07e62082007-02-27 16:45:40 -0700205
206<p>
207The final vertex and fragment programs may be interpreted in software
208(see prog_execute.c) or translated into a specific hardware architecture
209(see drivers/dri/i915/i915_fragprog.c for example).
210</p>
211
Andreas Bollcc418882012-06-12 09:05:33 +0200212<h2 id="validation">Compiler Validation</h2>
Brian7eba12e2007-03-28 17:14:35 -0600213
214<p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600215Developers working on the GLSL compiler should test frequently to avoid
Brian7eba12e2007-03-28 17:14:35 -0600216regressions.
217</p>
Brian Paulf3ec1112010-08-24 09:02:05 -0600218
Brian7eba12e2007-03-28 17:14:35 -0600219<p>
Andreas Bolla73c59b2012-09-18 19:31:28 +0200220The <a href="http://piglit.freedesktop.org/">Piglit</a> project
Andreas Bolld4956692012-10-02 15:35:27 +0200221has many GLSL tests.
Brian7eba12e2007-03-28 17:14:35 -0600222</p>
223
Brian Paulf3ec1112010-08-24 09:02:05 -0600224<p>
225The Mesa demos repository also has some good GLSL tests.
226</p>
Brian7eba12e2007-03-28 17:14:35 -0600227
Andreas Bollb5da52a2012-09-18 18:57:02 +0200228</div>
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200229</body>
230</html>