aco: ignore parallelcopies to the same register on jump threading
[mesa.git] / docs / shading.html
index 847b231ca4f77f0105e59c963051198d64466745..839a61a0361380dd00ff829aafe23e9f97f53b42 100644 (file)
-<HTML>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <title>Shading Language</title>
+  <link rel="stylesheet" type="text/css" href="mesa.css">
+</head>
+<body>
 
-<TITLE>Shading Language Support</TITLE>
+<div class="header">
+  The Mesa 3D Graphics Library
+</div>
 
-<link rel="stylesheet" type="text/css" href="mesa.css"></head>
+<iframe src="contents.html"></iframe>
+<div class="content">
 
-<BODY>
-
-<H1>Shading Language Support</H1>
+<h1>Shading Language</h1>
 
 <p>
 This page describes the features and status of Mesa's support for the
-<a href="http://opengl.org/documentation/glsl/" target="_parent">
+<a href="https://opengl.org/documentation/glsl/">
 OpenGL Shading Language</a>.
 </p>
 
-<p>
-Last updated on 17 Feb 2007.
-</p>
-
 <p>
 Contents
 </p>
 <ul>
+<li><a href="#envvars">Environment variables</a>
+<li><a href="#support">GLSL 1.40 support</a>
 <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="#standalone">Stand-alone GLSL Compiler</a>
+<li><a href="#implementation">Compiler Implementation</a>
+<li><a href="#validation">Compiler Validation</a>
+</ul>
+
+
+<h2 id="envvars">Environment Variables</h2>
+
+<p>
+The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
+list of keywords to control some aspects of the GLSL compiler and shader
+execution.  These are generally used for debugging.
+</p>
+<ul>
+<li><b>dump</b> - print GLSL shader code to stdout at link time
+<li><b>log</b> - log all GLSL shaders to files.
+    The filenames will be "shader_X.vert" or "shader_X.frag" where X
+    the shader ID.
+<li><b>cache_info</b> - print debug information about shader cache
+<li><b>cache_fb</b> - force cached shaders to be ignored and do a full
+    recompile via the fallback path</li>
+<li><b>uniform</b> - print message to stdout when glUniform is called
+<li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
+    the vertex position with ftransform() and passes through the color and
+    texcoord[0] attributes.
+<li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
+    through the color attribute.
+<li><b>useprog</b> - log glUseProgram calls to stderr
+<li><b>errors</b> - GLSL compilation and link errors will be reported to stderr.
+</ul>
+<p>
+Example:  export MESA_GLSL=dump,nopt
+</p>
+
+<h3 id="replacement">Experimenting with Shader Replacements</h3>
+<p>
+Shaders can be dumped and replaced on runtime for debugging purposes. This
+feature is not currently supported by SCons build.
+
+This is controlled via following environment variables:
+</p>
+<ul>
+<li><b>MESA_SHADER_DUMP_PATH</b> - path where shader sources are dumped
+<li><b>MESA_SHADER_READ_PATH</b> - path where replacement shaders are read
+</ul>
+Note, path set must exist before running for dumping or replacing to work. 
+When both are set, these paths should be different so the dumped shaders do 
+not clobber the replacement shaders. Also, the filenames of the replacement shaders
+should match the filenames of the corresponding dumped shaders.
+
+<h3 id="capture">Capturing Shaders</h3>
+
+<p>
+Setting <b>MESA_SHADER_CAPTURE_PATH</b> to a directory will cause the compiler
+to write <code>.shader_test</code> files for use with
+<a href="https://gitlab.freedesktop.org/mesa/shader-db">shader-db</a>, a tool
+which compiler developers can use to gather statistics about shaders
+(instructions, cycles, memory accesses, and so on).
+</p>
+<p>
+Notably, this captures linked GLSL shaders - with all stages together -
+as well as ARB programs.
+</p>
+
+<h2 id="support">GLSL Version</h2>
+
+<p>
+The GLSL compiler currently supports version 3.30 of the shading language.
+</p>
+
+<p>
+Several GLSL extensions are also supported:
+</p>
+<ul>
+<li>GL_ARB_draw_buffers
+<li>GL_ARB_fragment_coord_conventions
+<li>GL_ARB_shader_bit_encoding
 </ul>
 
 
-<a name="unsup">
-<h2>Unsupported Features</h2>
+<h2 id="unsup">Unsupported Features</h2>
+
+<p>XXX update this section</p>
 
 <p>
-The following features of the shading language are not yet supported
+The following features of the shading language are not yet fully supported
 in Mesa:
 </p>
 
 <ul>
-<li>Dereferencing arrays with non-constant indexes
-<li>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>Linking of multiple shaders does not always work.  Currently, linking
+    is implemented through shader concatenation and re-compiling.  This
+    doesn't always work because of some #pragma and preprocessor issues.
+<li>The gl_Color and gl_SecondaryColor varying vars are interpolated
+    without perspective correction
 </ul>
 
 <p>
@@ -50,8 +133,7 @@ All other major features of the shading language should function.
 </p>
 
 
-<a name="impl">
-<h2>Implementation Notes</h2>
+<h2 id="notes">Implementation Notes</h2>
 
 <ul>
 <li>Shading language programs are compiled into low-level programs
@@ -65,7 +147,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>
@@ -73,43 +156,9 @@ These issues will be addressed/resolved in the future.
 </p>
 
 
-<a name="hints">
-<h2>Programming Hints</h2>
+<h2 id="hints">Programming Hints</h2>
 
 <ul>
-<li>Declare <em>in</em> function parameters as <em>const</em> whenever possible.
-    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>
@@ -119,25 +168,20 @@ These issues will be addressed/resolved in the future.
 <pre>
         float x = inversesqrt(y);
 </pre>
+</li>
 </ul>
 
 
-<a name="standalone">
-<h2>Stand-alone Compiler</h2>
+<h2 id="standalone">Stand-alone GLSL Compiler</h2>
 
 <p>
-A unique stand-alone GLSL compiler driver has been added to Mesa.
-<p>
-
-<p>
-The stand-alone compiler (like a conventional command-line compiler)
-is a tool that accepts Shading Language programs and emits low-level
-GPU programs.
+The stand-alone GLSL compiler program can be used to compile GLSL shaders
+into low-level GPU code.
 </p>
 
 <p>
 This tool is useful for:
-<p>
+</p>
 <ul>
 <li>Inspecting GPU code to gain insight into compilation
 <li>Generating initial GPU code for subsequent hand-tuning
@@ -145,7 +189,7 @@ This tool is useful for:
 </ul>
 
 <p>
-(compiler build instructions TBD)
+After building Mesa, the compiler can be found at src/compiler/glsl/glsl_compiler
 </p>
 
 <p>
@@ -153,33 +197,55 @@ Here's an example of using the compiler to compile a vertex shader and
 emit GL_ARB_vertex_program-style instructions:
 </p>
 <pre>
-    glslcompiler --arb --linenumbers --vs vertshader.txt
+    src/compiler/glsl/glsl_compiler --version XXX --dump-ast myshader.vert
 </pre>
+
+Options include
+<ul>
+<li><b>--dump-ast</b> - dump GPU code
+<li><b>--dump-hir</b> - dump high-level IR code
+<li><b>--dump-lir</b> - dump low-level IR code
+<li><b>--dump-builder</b> - dump GLSL IR code
+<li><b>--link</b> - link shaders
+<li><b>--just-log</b> - display only shader / linker info if exist,
+without any header or separator
+<li><b>--version</b> - [Mandatory] define the GLSL version to use
+</ul>
+
+
+<h2 id="implementation">Compiler Implementation</h2>
+
 <p>
-The output may look similar to this:
+The source code for Mesa's shading language compiler is in the
+<code>src/compiler/glsl/</code> directory.
+</p>
+
+<p>
+XXX provide some info about the compiler....
 </p>
-<pre>
-!!ARBvp1.0
-  0: MOV result.texcoord[0], vertex.texcoord[0];
-  1: DP4 temp0.x, state.matrix.mvp.row[0], vertex.position;
-  2: DP4 temp0.y, state.matrix.mvp.row[1], vertex.position;
-  3: DP4 temp0.z, state.matrix.mvp.row[2], vertex.position;
-  4: DP4 temp0.w, state.matrix.mvp.row[3], vertex.position;
-  5: MOV result.position, temp0;
-  6: END
-</pre>
 
 <p>
-Note that some shading language constructs (such as uniform and varying
-variables) aren't expressible in ARB or NV-style programs.
-Therefore, the resulting output is not always legal by definition of
-those program languages.
+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>
+
+<h2 id="validation">Compiler Validation</h2>
+
+<p>
+Developers working on the GLSL compiler should test frequently to avoid
+regressions.
+</p>
+
+<p>
+The <a href="https://piglit.freedesktop.org/">Piglit</a> project
+has many GLSL tests.
+</p>
+
 <p>
-Also note that this compiler driver is still under development.
-Over time, the correctness of the GPU programs, with respect to the ARB
-and NV languagues, should improve.
+The Mesa demos repository also has some good GLSL tests.
 </p>
 
-</BODY>
-</HTML>
+</div>
+</body>
+</html>