| 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 | b5da52a | 2012-09-18 18:57:02 +0200 | [diff] [blame] | 10 | <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 Boll | ecd5c7c | 2012-06-12 09:05:03 +0200 | [diff] [blame] | 17 | <h1>Shading Language Support</h1> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 18 | |
| 19 | <p> |
| 20 | This page describes the features and status of Mesa's support for the |
| Eric Engestrom | 30cf9ff | 2017-02-09 02:10:17 +0000 | [diff] [blame] | 21 | <a href="https://opengl.org/documentation/glsl/"> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 22 | OpenGL Shading Language</a>. |
| 23 | </p> |
| 24 | |
| 25 | <p> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 26 | Contents |
| 27 | </p> |
| 28 | <ul> |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 29 | <li><a href="#envvars">Environment variables</a> |
| Andreas Boll | d495669 | 2012-10-02 15:35:27 +0200 | [diff] [blame] | 30 | <li><a href="#support">GLSL 1.40 support</a> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 31 | <li><a href="#unsup">Unsupported Features</a> |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 32 | <li><a href="#notes">Implementation Notes</a> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 33 | <li><a href="#hints">Programming Hints</a> |
| Brian Paul | 3bfedb7 | 2008-07-17 15:40:10 -0600 | [diff] [blame] | 34 | <li><a href="#standalone">Stand-alone GLSL Compiler</a> |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 35 | <li><a href="#implementation">Compiler Implementation</a> |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 36 | <li><a href="#validation">Compiler Validation</a> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 37 | </ul> |
| 38 | |
| 39 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 40 | <h2 id="envvars">Environment Variables</h2> |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 41 | |
| 42 | <p> |
| 43 | 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] | 44 | list of keywords to control some aspects of the GLSL compiler and shader |
| 45 | execution. These are generally used for debugging. |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 46 | </p> |
| 47 | <ul> |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 48 | <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 Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 50 | The filenames will be "shader_X.vert" or "shader_X.frag" where X |
| 51 | the shader ID. |
| Timothy Arceri | 30aa22d | 2016-07-08 12:44:44 +1000 | [diff] [blame] | 52 | <li><b>cache_info</b> - print debug information about shader cache |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 53 | <li><b>uniform</b> - print message to stdout when glUniform is called |
| 54 | <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] | 55 | the vertex position with ftransform() and passes through the color and |
| 56 | texcoord[0] attributes. |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 57 | <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] | 58 | through the color attribute. |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 59 | <li><b>useprog</b> - log glUseProgram calls to stderr |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 60 | </ul> |
| 61 | <p> |
| 62 | Example: export MESA_GLSL=dump,nopt |
| 63 | </p> |
| 64 | |
| Tapani Pälli | 04e201d | 2015-08-31 09:54:23 +0300 | [diff] [blame] | 65 | <p> |
| 66 | Shaders can be dumped and replaced on runtime for debugging purposes. Mesa |
| 67 | needs to be configured with '--with-sha1' to enable this functionality. This |
| 68 | feature is not currently supported by SCons build. |
| 69 | |
| 70 | This is controlled via following environment variables: |
| 71 | <ul> |
| 72 | <li><b>MESA_SHADER_DUMP_PATH</b> - path where shader sources are dumped |
| 73 | <li><b>MESA_SHADER_READ_PATH</b> - path where replacement shaders are read |
| 74 | </ul> |
| 75 | Note, path set must exist before running for dumping or replacing to work. |
| 76 | When both are set, these paths should be different so the dumped shaders do |
| 77 | not clobber the replacement shaders. |
| 78 | </p> |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 79 | |
| Andreas Boll | d495669 | 2012-10-02 15:35:27 +0200 | [diff] [blame] | 80 | <h2 id="support">GLSL Version</h2> |
| Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 81 | |
| 82 | <p> |
| Chris Forbes | f6159af | 2013-11-24 17:44:06 +1300 | [diff] [blame] | 83 | The GLSL compiler currently supports version 3.30 of the shading language. |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 84 | </p> |
| Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 85 | |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 86 | <p> |
| 87 | Several GLSL extensions are also supported: |
| 88 | </p> |
| 89 | <ul> |
| 90 | <li>GL_ARB_draw_buffers |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 91 | <li>GL_ARB_fragment_coord_conventions |
| Andreas Boll | d495669 | 2012-10-02 15:35:27 +0200 | [diff] [blame] | 92 | <li>GL_ARB_shader_bit_encoding |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 93 | </ul> |
| Brian Paul | c4341fe | 2008-12-15 18:30:40 -0700 | [diff] [blame] | 94 | |
| 95 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 96 | <h2 id="unsup">Unsupported Features</h2> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 97 | |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 98 | <p>XXX update this section</p> |
| 99 | |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 100 | <p> |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 101 | The following features of the shading language are not yet fully supported |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 102 | in Mesa: |
| 103 | </p> |
| 104 | |
| 105 | <ul> |
| Brian Paul | 439909a | 2009-04-07 11:09:53 -0600 | [diff] [blame] | 106 | <li>Linking of multiple shaders does not always work. Currently, linking |
| 107 | is implemented through shader concatenation and re-compiling. This |
| 108 | doesn't always work because of some #pragma and preprocessor issues. |
| Brian | 4b1d1b7 | 2007-04-27 15:25:00 -0600 | [diff] [blame] | 109 | <li>The gl_Color and gl_SecondaryColor varying vars are interpolated |
| 110 | without perspective correction |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 111 | </ul> |
| 112 | |
| 113 | <p> |
| 114 | All other major features of the shading language should function. |
| 115 | </p> |
| 116 | |
| 117 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 118 | <h2 id="notes">Implementation Notes</h2> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 119 | |
| 120 | <ul> |
| 121 | <li>Shading language programs are compiled into low-level programs |
| 122 | very similar to those of GL_ARB_vertex/fragment_program. |
| Brian | bbec2fd | 2007-01-28 12:11:10 -0700 | [diff] [blame] | 123 | <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 124 | float[4] registers. |
| Brian | bbec2fd | 2007-01-28 12:11:10 -0700 | [diff] [blame] | 125 | <li>Float constants and variables are packed so that up to four floats |
| 126 | can occupy one program parameter/register. |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 127 | <li>All function calls are inlined. |
| 128 | <li>Shaders which use too many registers will not compile. |
| 129 | <li>The quality of generated code is pretty good, register usage is fair. |
| 130 | <li>Shader error detection and reporting of errors (InfoLog) is not |
| 131 | very good yet. |
| Brian | 05e6fd8 | 2007-03-27 16:05:25 -0600 | [diff] [blame] | 132 | <li>The ftransform() function doesn't necessarily match the results of |
| 133 | fixed-function transformation. |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 134 | </ul> |
| 135 | |
| 136 | <p> |
| 137 | These issues will be addressed/resolved in the future. |
| 138 | </p> |
| 139 | |
| 140 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 141 | <h2 id="hints">Programming Hints</h2> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 142 | |
| 143 | <ul> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 144 | <li>Use the built-in library functions whenever possible. |
| 145 | For example, instead of writing this: |
| 146 | <pre> |
| 147 | float x = 1.0 / sqrt(y); |
| 148 | </pre> |
| 149 | Write this: |
| 150 | <pre> |
| 151 | float x = inversesqrt(y); |
| 152 | </pre> |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 153 | </li> |
| Brian | 9595d19 | 2007-01-20 13:40:57 -0700 | [diff] [blame] | 154 | </ul> |
| 155 | |
| 156 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 157 | <h2 id="standalone">Stand-alone GLSL Compiler</h2> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 158 | |
| 159 | <p> |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 160 | The stand-alone GLSL compiler program can be used to compile GLSL shaders |
| 161 | into low-level GPU code. |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 162 | </p> |
| 163 | |
| 164 | <p> |
| 165 | This tool is useful for: |
| Andreas Boll | df2be22 | 2012-06-12 09:05:22 +0200 | [diff] [blame] | 166 | </p> |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 167 | <ul> |
| 168 | <li>Inspecting GPU code to gain insight into compilation |
| 169 | <li>Generating initial GPU code for subsequent hand-tuning |
| 170 | <li>Debugging the GLSL compiler itself |
| 171 | </ul> |
| 172 | |
| 173 | <p> |
| Elie TOURNIER | 5034cf4 | 2017-01-18 13:50:11 +0000 | [diff] [blame] | 174 | After building Mesa, the compiler can be found at src/compiler/glsl/glsl_compiler |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 175 | </p> |
| 176 | |
| 177 | <p> |
| 178 | Here's an example of using the compiler to compile a vertex shader and |
| 179 | emit GL_ARB_vertex_program-style instructions: |
| 180 | </p> |
| 181 | <pre> |
| Elie TOURNIER | 5034cf4 | 2017-01-18 13:50:11 +0000 | [diff] [blame] | 182 | src/compiler/glsl/glsl_compiler --version XXX --dump-ast myshader.vert |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 183 | </pre> |
| 184 | |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 185 | Options include |
| 186 | <ul> |
| 187 | <li><b>--dump-ast</b> - dump GPU code |
| 188 | <li><b>--dump-hir</b> - dump high-level IR code |
| 189 | <li><b>--dump-lir</b> - dump low-level IR code |
| Elie TOURNIER | 5034cf4 | 2017-01-18 13:50:11 +0000 | [diff] [blame] | 190 | <li><b>--dump-builder</b> - dump GLSL IR code |
| 191 | <li><b>--link</b> - link shaders |
| 192 | <li><b>--just-log</b> - display only shader / linker info if exist, |
| 193 | without any header or separator |
| 194 | <li><b>--version</b> - [Mandatory] define the GLSL version to use |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 195 | </ul> |
| 196 | |
| Brian | 61d31ae | 2007-02-17 09:41:19 -0700 | [diff] [blame] | 197 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 198 | <h2 id="implementation">Compiler Implementation</h2> |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 199 | |
| 200 | <p> |
| 201 | The source code for Mesa's shading language compiler is in the |
| Elie TOURNIER | 5034cf4 | 2017-01-18 13:50:11 +0000 | [diff] [blame] | 202 | <code>src/compiler/glsl/</code> directory. |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 203 | </p> |
| 204 | |
| 205 | <p> |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 206 | XXX provide some info about the compiler.... |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 207 | </p> |
| Brian | 07e6208 | 2007-02-27 16:45:40 -0700 | [diff] [blame] | 208 | |
| 209 | <p> |
| 210 | The final vertex and fragment programs may be interpreted in software |
| 211 | (see prog_execute.c) or translated into a specific hardware architecture |
| 212 | (see drivers/dri/i915/i915_fragprog.c for example). |
| 213 | </p> |
| 214 | |
| Andreas Boll | cc41888 | 2012-06-12 09:05:33 +0200 | [diff] [blame] | 215 | <h2 id="validation">Compiler Validation</h2> |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 216 | |
| 217 | <p> |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 218 | Developers working on the GLSL compiler should test frequently to avoid |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 219 | regressions. |
| 220 | </p> |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 221 | |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 222 | <p> |
| Eric Engestrom | 30cf9ff | 2017-02-09 02:10:17 +0000 | [diff] [blame] | 223 | The <a href="https://piglit.freedesktop.org/">Piglit</a> project |
| Andreas Boll | d495669 | 2012-10-02 15:35:27 +0200 | [diff] [blame] | 224 | has many GLSL tests. |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 225 | </p> |
| 226 | |
| Brian Paul | f3ec111 | 2010-08-24 09:02:05 -0600 | [diff] [blame] | 227 | <p> |
| 228 | The Mesa demos repository also has some good GLSL tests. |
| 229 | </p> |
| Brian | 7eba12e | 2007-03-28 17:14:35 -0600 | [diff] [blame] | 230 | |
| Andreas Boll | b5da52a | 2012-09-18 18:57:02 +0200 | [diff] [blame] | 231 | </div> |
| Andreas Boll | ecd5c7c | 2012-06-12 09:05:03 +0200 | [diff] [blame] | 232 | </body> |
| 233 | </html> |