shading.html 6.46 KB
Newer Older
1 2 3 4 5 6 7 8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <title>Shading Language Support</title>
  <link rel="stylesheet" type="text/css" href="mesa.css">
</head>
<body>
9

Andreas Boll's avatar
Andreas Boll committed
10 11 12 13 14 15 16
<div class="header">
  <h1>The Mesa 3D Graphics Library</h1>
</div>

<iframe src="contents.html"></iframe>
<div class="content">

17
<h1>Shading Language Support</h1>
18 19 20

<p>
This page describes the features and status of Mesa's support for the
Eric Engestrom's avatar
Eric Engestrom committed
21
<a href="https://opengl.org/documentation/glsl/">
22 23 24
OpenGL Shading Language</a>.
</p>

Brian's avatar
Brian committed
25 26 27 28
<p>
Contents
</p>
<ul>
29
<li><a href="#envvars">Environment variables</a>
30
<li><a href="#support">GLSL 1.40 support</a>
Brian's avatar
Brian committed
31
<li><a href="#unsup">Unsupported Features</a>
Brian's avatar
Brian committed
32
<li><a href="#notes">Implementation Notes</a>
Brian's avatar
Brian committed
33
<li><a href="#hints">Programming Hints</a>
34
<li><a href="#standalone">Stand-alone GLSL Compiler</a>
Brian's avatar
Brian committed
35
<li><a href="#implementation">Compiler Implementation</a>
Brian's avatar
Brian committed
36
<li><a href="#validation">Compiler Validation</a>
Brian's avatar
Brian committed
37 38 39
</ul>


40
<h2 id="envvars">Environment Variables</h2>
41 42 43

<p>
The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
44 45
list of keywords to control some aspects of the GLSL compiler and shader
execution.  These are generally used for debugging.
46 47
</p>
<ul>
48 49
<li><b>dump</b> - print GLSL shader code to stdout at link time
<li><b>log</b> - log all GLSL shaders to files.
50 51
    The filenames will be "shader_X.vert" or "shader_X.frag" where X
    the shader ID.
52
<li><b>cache_info</b> - print debug information about shader cache
53 54
<li><b>cache_fb</b> - force cached shaders to be ignored and do a full
    recompile via the fallback path</li>
55 56
<li><b>uniform</b> - print message to stdout when glUniform is called
<li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
57 58
    the vertex position with ftransform() and passes through the color and
    texcoord[0] attributes.
59
<li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
60
    through the color attribute.
61
<li><b>useprog</b> - log glUseProgram calls to stderr
62 63 64 65 66
</ul>
<p>
Example:  export MESA_GLSL=dump,nopt
</p>

67
<p>
68
Shaders can be dumped and replaced on runtime for debugging purposes. This
69 70 71 72 73 74 75 76 77
feature is not currently supported by SCons build.

This is controlled via following environment variables:
<ul>
<li><b>MESA_SHADER_DUMP_PATH</b> - path where shader sources are dumped
<li><b>MESA_SHADER_READ_PATH</b> - path where replacement shaders are read
</ul>
Note, path set must exist before running for dumping or replacing to work. 
When both are set, these paths should be different so the dumped shaders do 
78 79
not clobber the replacement shaders. Also, the filenames of the replacement shaders
should match the filenames of the corresponding dumped shaders.
80
</p>
81

82
<h2 id="support">GLSL Version</h2>
Brian Paul's avatar
Brian Paul committed
83 84

<p>
85
The GLSL compiler currently supports version 3.30 of the shading language.
86 87 88 89 90
</p>

<p>
Several GLSL extensions are also supported:
</p>
Brian Paul's avatar
Brian Paul committed
91
<ul>
92 93
<li>GL_ARB_draw_buffers
<li>GL_ARB_fragment_coord_conventions
94
<li>GL_ARB_shader_bit_encoding
Brian Paul's avatar
Brian Paul committed
95 96 97
</ul>


98
<h2 id="unsup">Unsupported Features</h2>
99

100 101
<p>XXX update this section</p>

102
<p>
103
The following features of the shading language are not yet fully supported
104 105 106 107
in Mesa:
</p>

<ul>
108 109 110
<li>Linking of multiple shaders does not always work.  Currently, linking
    is implemented through shader concatenation and re-compiling.  This
    doesn't always work because of some #pragma and preprocessor issues.
Brian's avatar
Brian committed
111 112
<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
    without perspective correction
113 114 115 116 117 118 119
</ul>

<p>
All other major features of the shading language should function.
</p>


120
<h2 id="notes">Implementation Notes</h2>
121 122 123 124

<ul>
<li>Shading language programs are compiled into low-level programs
    very similar to those of GL_ARB_vertex/fragment_program.
Brian's avatar
Brian committed
125
<li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
126
    float[4] registers.
Brian's avatar
Brian committed
127 128
<li>Float constants and variables are packed so that up to four floats
    can occupy one program parameter/register.
129 130 131 132 133
<li>All function calls are inlined.
<li>Shaders which use too many registers will not compile.
<li>The quality of generated code is pretty good, register usage is fair.
<li>Shader error detection and reporting of errors (InfoLog) is not
    very good yet.
Brian's avatar
Brian committed
134 135
<li>The ftransform() function doesn't necessarily match the results of
    fixed-function transformation.
136 137 138 139 140 141 142
</ul>

<p>
These issues will be addressed/resolved in the future.
</p>


143
<h2 id="hints">Programming Hints</h2>
144 145 146 147 148 149 150 151 152 153 154

<ul>
<li>Use the built-in library functions whenever possible.
    For example, instead of writing this:
<pre>
        float x = 1.0 / sqrt(y);
</pre>
    Write this:
<pre>
        float x = inversesqrt(y);
</pre>
Brian's avatar
Brian committed
155
</li>
156 157 158
</ul>


159
<h2 id="standalone">Stand-alone GLSL Compiler</h2>
Brian's avatar
Brian committed
160 161

<p>
162 163
The stand-alone GLSL compiler program can be used to compile GLSL shaders
into low-level GPU code.
Brian's avatar
Brian committed
164 165 166 167
</p>

<p>
This tool is useful for:
Andreas Boll's avatar
Andreas Boll committed
168
</p>
Brian's avatar
Brian committed
169 170 171 172 173 174 175
<ul>
<li>Inspecting GPU code to gain insight into compilation
<li>Generating initial GPU code for subsequent hand-tuning
<li>Debugging the GLSL compiler itself
</ul>

<p>
Elie TOURNIER's avatar
Elie TOURNIER committed
176
After building Mesa, the compiler can be found at src/compiler/glsl/glsl_compiler
Brian's avatar
Brian committed
177 178 179 180 181 182 183
</p>

<p>
Here's an example of using the compiler to compile a vertex shader and
emit GL_ARB_vertex_program-style instructions:
</p>
<pre>
Elie TOURNIER's avatar
Elie TOURNIER committed
184
    src/compiler/glsl/glsl_compiler --version XXX --dump-ast myshader.vert
Brian's avatar
Brian committed
185 186
</pre>

187 188 189 190 191
Options include
<ul>
<li><b>--dump-ast</b> - dump GPU code
<li><b>--dump-hir</b> - dump high-level IR code
<li><b>--dump-lir</b> - dump low-level IR code
Elie TOURNIER's avatar
Elie TOURNIER committed
192 193 194 195 196
<li><b>--dump-builder</b> - dump GLSL IR code
<li><b>--link</b> - link shaders
<li><b>--just-log</b> - display only shader / linker info if exist,
without any header or separator
<li><b>--version</b> - [Mandatory] define the GLSL version to use
197 198
</ul>

Brian's avatar
Brian committed
199

200
<h2 id="implementation">Compiler Implementation</h2>
Brian's avatar
Brian committed
201 202 203

<p>
The source code for Mesa's shading language compiler is in the
Elie TOURNIER's avatar
Elie TOURNIER committed
204
<code>src/compiler/glsl/</code> directory.
Brian's avatar
Brian committed
205 206 207
</p>

<p>
208
XXX provide some info about the compiler....
Brian's avatar
Brian committed
209 210 211 212 213 214 215 216
</p>

<p>
The final vertex and fragment programs may be interpreted in software
(see prog_execute.c) or translated into a specific hardware architecture
(see drivers/dri/i915/i915_fragprog.c for example).
</p>

217
<h2 id="validation">Compiler Validation</h2>
Brian's avatar
Brian committed
218 219

<p>
220
Developers working on the GLSL compiler should test frequently to avoid
Brian's avatar
Brian committed
221 222
regressions.
</p>
223

Brian's avatar
Brian committed
224
<p>
Eric Engestrom's avatar
Eric Engestrom committed
225
The <a href="https://piglit.freedesktop.org/">Piglit</a> project
226
has many GLSL tests.
Brian's avatar
Brian committed
227 228
</p>

229 230 231
<p>
The Mesa demos repository also has some good GLSL tests.
</p>
Brian's avatar
Brian committed
232

Andreas Boll's avatar
Andreas Boll committed
233
</div>
234 235
</body>
</html>