minor updates
[mesa.git] / docs / shading.html
1 <HTML>
2
3 <TITLE>Shading Language Support</TITLE>
4
5 <link rel="stylesheet" type="text/css" href="mesa.css"></head>
6
7 <BODY>
8
9 <H1>Shading Language Support</H1>
10
11 <p>
12 This page describes the features and status of Mesa's support for the
13 <a href="http://opengl.org/documentation/glsl/" target="_parent">
14 OpenGL Shading Language</a>.
15 </p>
16
17 <p>
18 Last updated on 20 Jan 2007.
19 </p>
20
21 <h2>Unsupported Features</h2>
22
23 <p>
24 The following features of the shading language are not yet supported
25 in Mesa:
26 </p>
27
28 <ul>
29 <li>Arrays
30 <li>Structs
31 <li>Linking of multiple shaders is not supported
32 <li>Noise functions
33 <li>Not all built-in OpenGL state variables are supported yet.
34 Common variables such as gl_ModelViewMatrix and gl_NormalMatrix
35 are supported.
36 <li>Integer operations are not fully implemented (most are implemented
37 as floating point).
38 </ul>
39
40 <p>
41 All other major features of the shading language should function.
42 </p>
43
44
45 <h2>Implementation Notes</h2>
46
47 <ul>
48 <li>Shading language programs are compiled into low-level programs
49 very similar to those of GL_ARB_vertex/fragment_program.
50 <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
51 float[4] registers.
52 <li>Float constants and variables are packed so that up to four floats
53 can occupy one program parameter/register.
54 <li>All function calls are inlined.
55 <li>Shaders which use too many registers will not compile.
56 <li>The quality of generated code is pretty good, register usage is fair.
57 <li>Shader error detection and reporting of errors (InfoLog) is not
58 very good yet.
59 <li>There are massive memory leaks in the compiler.
60 </ul>
61
62 <p>
63 These issues will be addressed/resolved in the future.
64 </p>
65
66
67 <h2>Programming Hints</h2>
68
69 <ul>
70 <li>Declare <em>in</em> function parameters as <em>const</em> whenever possible.
71 This improves the efficiency of function inlining.
72 </li>
73 <br>
74 <li>To reduce register usage, declare variables within smaller scopes.
75 For example, the following code:
76 <pre>
77 void main()
78 {
79 vec4 a1, a2, b1, b2;
80 gl_Position = expression using a1, a2.
81 gl_Color = expression using b1, b2;
82 }
83 </pre>
84 Can be rewritten as follows to use half as many registers:
85 <pre>
86 void main()
87 {
88 {
89 vec4 a1, a2;
90 gl_Position = expression using a1, a2.
91 }
92 {
93 vec4 b1, b2;
94 gl_Color = expression using b1, b2;
95 }
96 }
97 </pre>
98 Alternately, rather than using several float variables, use
99 a vec4 instead. Use swizzling and writemasks to access the
100 components of the vec4 as floats.
101 </li>
102 <br>
103 <li>Use the built-in library functions whenever possible.
104 For example, instead of writing this:
105 <pre>
106 float x = 1.0 / sqrt(y);
107 </pre>
108 Write this:
109 <pre>
110 float x = inversesqrt(y);
111 </pre>
112 </ul>
113
114
115 </BODY>
116 </HTML>