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