Andreas Boll | ecd5c7c | 2012-06-12 09:05:03 +0200 | [diff] [blame] | 1 | <!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> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 9 | |
Andreas Boll | ecd5c7c | 2012-06-12 09:05:03 +0200 | [diff] [blame] | 10 | <h1>Shading Language Support</h1> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 11 | |
| 12 | <p> |
| 13 | This page describes the features and status of Mesa's support for the |
| 14 | <a href="http://opengl.org/documentation/glsl/" target="_parent"> |
| 15 | OpenGL Shading Language</a>. |
| 16 | </p> |
| 17 | |
| 18 | <p> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 19 | Contents |
| 20 | </p> |
| 21 | <ul> |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 22 | <li><a href="#envvars">Environment variables</a> |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 23 | <li><a href="#120">GLSL 1.20 support</a> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 24 | <li><a href="#unsup">Unsupported Features</a> |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 25 | <li><a href="#notes">Implementation Notes</a> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 26 | <li><a href="#hints">Programming Hints</a> |
Brian Paul | 3bfedb7 | 2008-07-17 15:40:10 -0600 | [diff] [blame] | 27 | <li><a href="#standalone">Stand-alone GLSL Compiler</a> |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 28 | <li><a href="#implementation">Compiler Implementation</a> |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 29 | <li><a href="#validation">Compiler Validation</a> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 30 | </ul> |
| 31 | |
| 32 | |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 33 | |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 34 | <a name="envvars"> |
| 35 | <h2>Environment Variables</h2> |
| 36 | |
| 37 | <p> |
| 38 | The <b>MESA_GLSL</b> environment variable can be set to a comma-separated |
Brian Paul | 85fb3e4 | 2009-10-14 11:28:28 -0600 | [diff] [blame] | 39 | list of keywords to control some aspects of the GLSL compiler and shader |
| 40 | execution. These are generally used for debugging. |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 41 | </p> |
| 42 | <ul> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 43 | <li><b>dump</b> - print GLSL shader code to stdout at link time |
| 44 | <li><b>log</b> - log all GLSL shaders to files. |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 45 | The filenames will be "shader_X.vert" or "shader_X.frag" where X |
| 46 | the shader ID. |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 47 | <li><b>nopt</b> - disable compiler optimizations |
| 48 | <li><b>opt</b> - force compiler optimizations |
| 49 | <li><b>uniform</b> - print message to stdout when glUniform is called |
| 50 | <li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms |
Brian Paul | 85fb3e4 | 2009-10-14 11:28:28 -0600 | [diff] [blame] | 51 | the vertex position with ftransform() and passes through the color and |
| 52 | texcoord[0] attributes. |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 53 | <li><b>nopfrag</b> - force fragment shader to be a simple shader that passes |
Brian Paul | 85fb3e4 | 2009-10-14 11:28:28 -0600 | [diff] [blame] | 54 | through the color attribute. |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 55 | <li><b>useprog</b> - log glUseProgram calls to stderr |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 56 | </ul> |
| 57 | <p> |
| 58 | Example: export MESA_GLSL=dump,nopt |
| 59 | </p> |
| 60 | |
| 61 | |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 62 | <a name="120"> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 63 | <h2>GLSL Version</h2> |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 64 | |
| 65 | <p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 66 | The GLSL compiler currently supports version 1.20 of the shading language. |
| 67 | </p> |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 68 | |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 69 | <p> |
| 70 | Several GLSL extensions are also supported: |
| 71 | </p> |
| 72 | <ul> |
| 73 | <li>GL_ARB_draw_buffers |
| 74 | <li>GL_ARB_texture_rectangle |
| 75 | <li>GL_ARB_fragment_coord_conventions |
| 76 | <li>GL_EXT_texture_array |
| 77 | </ul> |
Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 78 | |
| 79 | |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 80 | <a name="unsup"> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 81 | <h2>Unsupported Features</h2> |
| 82 | |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 83 | <p>XXX update this section</p> |
| 84 | |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 85 | <p> |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 86 | The following features of the shading language are not yet fully supported |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 87 | in Mesa: |
| 88 | </p> |
| 89 | |
| 90 | <ul> |
Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 91 | <li>Linking of multiple shaders does not always work. Currently, linking |
| 92 | is implemented through shader concatenation and re-compiling. This |
| 93 | doesn't always work because of some #pragma and preprocessor issues. |
Brian | b03e171 | 2007-03-09 09:51:55 -0700 | [diff] [blame] | 94 | <li>gl_ClipVertex |
Brian | 4b1d1b7 | 2007-04-27 15:25:00 -0600 | [diff] [blame] | 95 | <li>The gl_Color and gl_SecondaryColor varying vars are interpolated |
| 96 | without perspective correction |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 97 | </ul> |
| 98 | |
| 99 | <p> |
| 100 | All other major features of the shading language should function. |
| 101 | </p> |
| 102 | |
| 103 | |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 104 | <a name="notes"> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 105 | <h2>Implementation Notes</h2> |
| 106 | |
| 107 | <ul> |
| 108 | <li>Shading language programs are compiled into low-level programs |
| 109 | very similar to those of GL_ARB_vertex/fragment_program. |
Brian | bbec2fd | 2007-01-28 12:11:10 -0700 | [diff] [blame] | 110 | <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 111 | float[4] registers. |
Brian | bbec2fd | 2007-01-28 12:11:10 -0700 | [diff] [blame] | 112 | <li>Float constants and variables are packed so that up to four floats |
| 113 | can occupy one program parameter/register. |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 114 | <li>All function calls are inlined. |
| 115 | <li>Shaders which use too many registers will not compile. |
| 116 | <li>The quality of generated code is pretty good, register usage is fair. |
| 117 | <li>Shader error detection and reporting of errors (InfoLog) is not |
| 118 | very good yet. |
Brian | 05e6fd8 | 2007-03-27 16:05:25 -0600 | [diff] [blame] | 119 | <li>The ftransform() function doesn't necessarily match the results of |
| 120 | fixed-function transformation. |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 121 | </ul> |
| 122 | |
| 123 | <p> |
| 124 | These issues will be addressed/resolved in the future. |
| 125 | </p> |
| 126 | |
| 127 | |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 128 | <a name="hints"> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 129 | <h2>Programming Hints</h2> |
| 130 | |
| 131 | <ul> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 132 | <li>Use the built-in library functions whenever possible. |
| 133 | For example, instead of writing this: |
| 134 | <pre> |
| 135 | float x = 1.0 / sqrt(y); |
| 136 | </pre> |
| 137 | Write this: |
| 138 | <pre> |
| 139 | float x = inversesqrt(y); |
| 140 | </pre> |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 141 | </li> |
Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 142 | </ul> |
| 143 | |
| 144 | |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 145 | <a name="standalone"> |
Brian Paul | 3bfedb7 | 2008-07-17 15:40:10 -0600 | [diff] [blame] | 146 | <h2>Stand-alone GLSL Compiler</h2> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 147 | |
| 148 | <p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 149 | The stand-alone GLSL compiler program can be used to compile GLSL shaders |
| 150 | into low-level GPU code. |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 151 | </p> |
| 152 | |
| 153 | <p> |
| 154 | This tool is useful for: |
Andreas Boll | df2be22 | 2012-06-12 09:05:22 +0200 | [diff] [blame^] | 155 | </p> |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 156 | <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 Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 163 | After building Mesa, the compiler can be found at src/glsl/glsl_compiler |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 164 | </p> |
| 165 | |
| 166 | <p> |
| 167 | Here's an example of using the compiler to compile a vertex shader and |
| 168 | emit GL_ARB_vertex_program-style instructions: |
| 169 | </p> |
| 170 | <pre> |
Sam Hocevar | fde4943 | 2011-02-16 17:04:03 -0700 | [diff] [blame] | 171 | src/glsl/glsl_compiler --dump-ast myshader.vert |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 172 | </pre> |
| 173 | |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 174 | Options 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 | |
Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 182 | |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 183 | |
| 184 | |
| 185 | <a name="implementation"> |
| 186 | <h2>Compiler Implementation</h2> |
| 187 | |
| 188 | <p> |
| 189 | The source code for Mesa's shading language compiler is in the |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 190 | <code>src/glsl/</code> directory. |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 191 | </p> |
| 192 | |
| 193 | <p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 194 | XXX provide some info about the compiler.... |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 195 | </p> |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 196 | |
| 197 | <p> |
| 198 | The final vertex and fragment programs may be interpreted in software |
| 199 | (see prog_execute.c) or translated into a specific hardware architecture |
| 200 | (see drivers/dri/i915/i915_fragprog.c for example). |
| 201 | </p> |
| 202 | |
Brian | 8f9db0f | 2007-03-23 17:49:19 -0600 | [diff] [blame] | 203 | <h3>Code Generation Options</h3> |
| 204 | |
| 205 | <p> |
| 206 | Internally, there are several options that control the compiler's code |
| 207 | generation and instruction selection. |
| 208 | These options are seen in the gl_shader_state struct and may be set |
| 209 | by the device driver to indicate its preferences: |
| 210 | |
| 211 | <pre> |
| 212 | struct gl_shader_state |
| 213 | { |
| 214 | ... |
| 215 | /** Driver-selectable options: */ |
| 216 | GLboolean EmitHighLevelInstructions; |
| 217 | GLboolean EmitCondCodes; |
| 218 | GLboolean EmitComments; |
| 219 | }; |
| 220 | </pre> |
| 221 | |
| 222 | <ul> |
| 223 | <li>EmitHighLevelInstructions |
| 224 | <br> |
| 225 | This option controls instruction selection for loops and conditionals. |
| 226 | If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK |
| 227 | instructions will be emitted. |
| 228 | Otherwise, those constructs will be implemented with BRA instructions. |
| 229 | </li> |
| 230 | |
| 231 | <li>EmitCondCodes |
| 232 | <br> |
| 233 | If set, condition codes (ala GL_NV_fragment_program) will be used for |
| 234 | branching and looping. |
| 235 | Otherwise, ordinary registers will be used (the IF instruction will |
| 236 | examine the first operand's X component and do the if-part if non-zero). |
| 237 | This option is only relevant if EmitHighLevelInstructions is set. |
| 238 | </li> |
| 239 | |
| 240 | <li>EmitComments |
| 241 | <br> |
| 242 | If set, instructions will be annoted with comments to help with debugging. |
| 243 | Extra NOP instructions will also be inserted. |
Andreas Boll | df2be22 | 2012-06-12 09:05:22 +0200 | [diff] [blame^] | 244 | </li> |
Brian | 8f9db0f | 2007-03-23 17:49:19 -0600 | [diff] [blame] | 245 | </ul> |
Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 246 | |
| 247 | |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 248 | <a name="validation"> |
| 249 | <h2>Compiler Validation</h2> |
| 250 | |
| 251 | <p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 252 | Developers working on the GLSL compiler should test frequently to avoid |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 253 | regressions. |
| 254 | </p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 255 | |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 256 | <p> |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 257 | The <a href="http://people.freedesktop.org/~nh/piglit/">Piglit</a> project |
| 258 | has many GLSL tests and the |
| 259 | <a href="http://glean.sf.net" target="_parent">Glean</a> glsl1 test |
| 260 | tests GLSL features. |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 261 | </p> |
| 262 | |
Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 263 | <p> |
| 264 | The Mesa demos repository also has some good GLSL tests. |
| 265 | </p> |
Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 266 | |
Andreas Boll | ecd5c7c | 2012-06-12 09:05:03 +0200 | [diff] [blame] | 267 | </body> |
| 268 | </html> |