shading.html 2.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
<HTML>

<TITLE>Shading Language Support</TITLE>

<link rel="stylesheet" type="text/css" href="mesa.css"></head>

<BODY>

<H1>Shading Language Support</H1>

<p>
This page describes the features and status of Mesa's support for the
<a href="http://opengl.org/documentation/glsl/" target="_parent">
OpenGL Shading Language</a>.
</p>

<p>
Last updated on 20 Jan 2007.
</p>

<h2>Unsupported Features</h2>

<p>
The following features of the shading language are not yet supported
in Mesa:
</p>

<ul>
<li>Arrays
<li>Structs
<li>Linking of multiple shaders is not supported
<li>Not all built-in OpenGL state variables are supported yet.
    Common variables such as gl_ModelViewMatrix and gl_NormalMatrix
    are supported.
<li>Integer operations are not fully implemented (most are implemented
    as floating point).
</ul>

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


<h2>Implementation Notes</h2>

<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
49
<li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
50
    float[4] registers.
Brian's avatar
Brian committed
51 52
<li>Float constants and variables are packed so that up to four floats
    can occupy one program parameter/register.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<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.
<li>There are massive memory leaks in the compiler.
</ul>

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


<h2>Programming Hints</h2>

<ul>
Brian's avatar
Brian committed
69
<li>Declare <em>in</em> function parameters as <em>const</em> whenever possible.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    This improves the efficiency of function inlining.
</li>
<br>
<li>To reduce register usage, declare variables within smaller scopes.
    For example, the following code:
<pre>
    void main()
    {
       vec4 a1, a2, b1, b2;
       gl_Position = expression using a1, a2.
       gl_Color = expression using b1, b2;
    }
</pre>
    Can be rewritten as follows to use half as many registers:
<pre>
    void main()
    {
       {
          vec4 a1, a2;
          gl_Position = expression using a1, a2.
       }
       {
          vec4 b1, b2;
          gl_Color = expression using b1, b2;
       }
    }
</pre>
    Alternately, rather than using several float variables, use
    a vec4 instead.  Use swizzling and writemasks to access the
    components of the vec4 as floats.
</li>
<br>
<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>
</ul>


</BODY>
</HTML>