Shading Language Support
This page describes the features and status of Mesa's support for the
OpenGL Shading Language.
Last updated on 20 Jan 2007.
Unsupported Features
The following features of the shading language are not yet supported
in Mesa:
- Arrays
- Structs
- Linking of multiple shaders is not supported
- Noise functions
- Not all built-in OpenGL state variables are supported yet.
Common variables such as gl_ModelViewMatrix and gl_NormalMatrix
are supported.
- Integer operations are not fully implemented (most are implemented
as floating point).
All other major features of the shading language should function.
Implementation Notes
- Shading language programs are compiled into low-level programs
very similar to those of GL_ARB_vertex/fragment_program.
- All float/int/bool and vector types currently occupy full
float[4] registers.
- Float constants are packed so that up to four floats can occupy one
program parameter/register.
- All function calls are inlined.
- Shaders which use too many registers will not compile.
- The quality of generated code is pretty good, register usage is fair.
- Shader error detection and reporting of errors (InfoLog) is not
very good yet.
- There are massive memory leaks in the compiler.
These issues will be addressed/resolved in the future.
Programming Hints
- Always declare in function parameters as const.
This improves the efficiency of function inlining.
- To reduce register usage, declare variables within smaller scopes.
For example, the following code:
void main()
{
vec4 a1, a2, b1, b2;
gl_Position = expression using a1, a2.
gl_Color = expression using b1, b2;
}
Can be rewritten as follows to use half as many registers:
void main()
{
{
vec4 a1, a2;
gl_Position = expression using a1, a2.
}
{
vec4 b1, b2;
gl_Color = expression using b1, b2;
}
}
Alternately, rather than using several float variables, use
a vec4 instead. Use swizzling and writemasks to access the
components of the vec4 as floats.
- Use the built-in library functions whenever possible.
For example, instead of writing this:
float x = 1.0 / sqrt(y);
Write this:
float x = inversesqrt(y);