mesa: new functions for managing list/index of uniforms
[mesa.git] / docs / shading.html
index 412c89389e51ed0d25bf8f7171575e88d0aca9c5..0a9f5f36f400e4da9c176b51bac9255529bceabf 100644 (file)
@@ -15,7 +15,7 @@ OpenGL Shading Language</a>.
 </p>
 
 <p>
-Last updated on 17 Feb 2007.
+Last updated on 28 March 2007.
 </p>
 
 <p>
@@ -23,9 +23,11 @@ Contents
 </p>
 <ul>
 <li><a href="#unsup">Unsupported Features</a>
-<li><a href="#impl">Implementation Notes</a>
+<li><a href="#notes">Implementation Notes</a>
 <li><a href="#hints">Programming Hints</a>
 <li><a href="#standalone">Stand-alone Compiler</a>
+<li><a href="#implementation">Compiler Implementation</a>
+<li><a href="#validation">Compiler Validation</a>
 </ul>
 
 
@@ -39,10 +41,14 @@ in Mesa:
 
 <ul>
 <li>Dereferencing arrays with non-constant indexes
-<li>User-defined structs
+<li>Comparison of user-defined structs
 <li>Linking of multiple shaders is not supported
-<li>Integer operations are not fully implemented (most are implemented
-    as floating point).
+<li>gl_ClipVertex
+<li>The derivative functions such as dFdx() are not implemented
+<li>The inverse trig functions asin(), acos(), and atan() are not implemented
+<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
+    without perspective correction
+<li>Floating point literal suffixes 'f' and 'F' aren't allowed.
 </ul>
 
 <p>
@@ -50,7 +56,7 @@ All other major features of the shading language should function.
 </p>
 
 
-<a name="impl">
+<a name="notes">
 <h2>Implementation Notes</h2>
 
 <ul>
@@ -65,7 +71,8 @@ All other major features of the shading language should function.
 <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.
+<li>The ftransform() function doesn't necessarily match the results of
+    fixed-function transformation.
 </ul>
 
 <p>
@@ -119,6 +126,9 @@ These issues will be addressed/resolved in the future.
 <pre>
         float x = inversesqrt(y);
 </pre>
+<li>
+   Use ++i when possible as it's more efficient than i++
+</li>
 </ul>
 
 
@@ -188,5 +198,116 @@ Over time, the correctness of the GPU programs, with respect to the ARB
 and NV languagues, should improve.
 </p>
 
+
+
+<a name="implementation">
+<h2>Compiler Implementation</h2>
+
+<p>
+The source code for Mesa's shading language compiler is in the
+<code>src/mesa/shader/slang/</code> directory.
+</p>
+
+<p>
+The compiler follows a fairly standard design and basically works as follows:
+</p>
+<ul>
+<li>The input string is tokenized (see grammar.c) and parsed
+(see slang_compiler_*.c) to produce an Abstract Syntax Tree (AST).
+The nodes in this tree are slang_operation structures
+(see slang_compile_operation.h).
+The nodes are decorated with symbol table, scoping and datatype information.
+<li>The AST is converted into an Intermediate representation (IR) tree
+(see the slang_codegen.c file).
+The IR nodes represent basic GPU instructions, like add, dot product,
+move, etc. 
+The IR tree is mostly a binary tree, but a few nodes have three or four
+children.
+In principle, the IR tree could be executed by doing an in-order traversal.
+<li>The IR tree is traversed in-order to emit code (see slang_emit.c).
+This is also when registers are allocated to store variables and temps.
+<li>In the future, a pattern-matching code generator-generator may be
+used for code generation.
+Programs such as L-BURG (Bottom-Up Rewrite Generator) and Twig look for
+patterns in IR trees, compute weights for subtrees and use the weights
+to select the best instructions to represent the sub-tree.
+<li>The emitted GPU instructions (see prog_instruction.h) are stored in a
+gl_program object (see mtypes.h).
+<li>When a fragment shader and vertex shader are linked (see slang_link.c)
+the varying vars are matched up, uniforms are merged, and vertex
+attributes are resolved (rewriting instructions as needed).
+</ul>
+
+<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>
+
+<h3>Code Generation Options</h3>
+
+<p>
+Internally, there are several options that control the compiler's code
+generation and instruction selection.
+These options are seen in the gl_shader_state struct and may be set
+by the device driver to indicate its preferences:
+
+<pre>
+struct gl_shader_state
+{
+   ...
+   /** Driver-selectable options: */
+   GLboolean EmitHighLevelInstructions;
+   GLboolean EmitCondCodes;
+   GLboolean EmitComments;
+};
+</pre>
+
+<ul>
+<li>EmitHighLevelInstructions
+<br>
+This option controls instruction selection for loops and conditionals.
+If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK
+instructions will be emitted.
+Otherwise, those constructs will be implemented with BRA instructions.
+</li>
+
+<li>EmitCondCodes
+<br>
+If set, condition codes (ala GL_NV_fragment_program) will be used for
+branching and looping.
+Otherwise, ordinary registers will be used (the IF instruction will
+examine the first operand's X component and do the if-part if non-zero).
+This option is only relevant if EmitHighLevelInstructions is set.
+</li>
+
+<li>EmitComments
+<br>
+If set, instructions will be annoted with comments to help with debugging.
+Extra NOP instructions will also be inserted.
+</br>
+
+</ul>
+
+
+<a name="validation">
+<h2>Compiler Validation</h2>
+
+<p>
+A new <a href="http://glean.sf.net" target="_parent">Glean</a> test has
+been create to exercise the GLSL compiler.
+</p>
+<p>
+The <em>glsl1</em> test runs over 150 sub-tests to check that the language
+features and built-in functions work properly.
+This test should be run frequently while working on the compiler to catch
+regressions.
+</p>
+<p>
+The test coverage is reasonably broad and complete but additional tests
+should be added.
+</p>
+
+
 </BODY>
 </HTML>