Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html lang="en">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8">
  5. <title>Shading Language Support</title>
  6. <link rel="stylesheet" type="text/css" href="mesa.css">
  7. </head>
  8. <body>
  9. <div class="header">
  10. <h1>The Mesa 3D Graphics Library</h1>
  11. </div>
  12. <iframe src="contents.html"></iframe>
  13. <div class="content">
  14. <h1>Shading Language Support</h1>
  15. <p>
  16. This page describes the features and status of Mesa's support for the
  17. <a href="http://opengl.org/documentation/glsl/">
  18. OpenGL Shading Language</a>.
  19. </p>
  20. <p>
  21. Contents
  22. </p>
  23. <ul>
  24. <li><a href="#envvars">Environment variables</a>
  25. <li><a href="#support">GLSL 1.40 support</a>
  26. <li><a href="#unsup">Unsupported Features</a>
  27. <li><a href="#notes">Implementation Notes</a>
  28. <li><a href="#hints">Programming Hints</a>
  29. <li><a href="#standalone">Stand-alone GLSL Compiler</a>
  30. <li><a href="#implementation">Compiler Implementation</a>
  31. <li><a href="#validation">Compiler Validation</a>
  32. </ul>
  33. <h2 id="envvars">Environment Variables</h2>
  34. <p>
  35. The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
  36. list of keywords to control some aspects of the GLSL compiler and shader
  37. execution. These are generally used for debugging.
  38. </p>
  39. <ul>
  40. <li><b>dump</b> - print GLSL shader code to stdout at link time
  41. <li><b>log</b> - log all GLSL shaders to files.
  42. The filenames will be "shader_X.vert" or "shader_X.frag" where X
  43. the shader ID.
  44. <li><b>nopt</b> - disable compiler optimizations
  45. <li><b>opt</b> - force compiler optimizations
  46. <li><b>uniform</b> - print message to stdout when glUniform is called
  47. <li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
  48. the vertex position with ftransform() and passes through the color and
  49. texcoord[0] attributes.
  50. <li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
  51. through the color attribute.
  52. <li><b>useprog</b> - log glUseProgram calls to stderr
  53. </ul>
  54. <p>
  55. Example: export MESA_GLSL=dump,nopt
  56. </p>
  57. <h2 id="support">GLSL Version</h2>
  58. <p>
  59. The GLSL compiler currently supports version 1.40 of the shading language.
  60. </p>
  61. <p>
  62. Several GLSL extensions are also supported:
  63. </p>
  64. <ul>
  65. <li>GL_ARB_draw_buffers
  66. <li>GL_ARB_fragment_coord_conventions
  67. <li>GL_ARB_shader_bit_encoding
  68. </ul>
  69. <h2 id="unsup">Unsupported Features</h2>
  70. <p>XXX update this section</p>
  71. <p>
  72. The following features of the shading language are not yet fully supported
  73. in Mesa:
  74. </p>
  75. <ul>
  76. <li>Linking of multiple shaders does not always work. Currently, linking
  77. is implemented through shader concatenation and re-compiling. This
  78. doesn't always work because of some #pragma and preprocessor issues.
  79. <li>The gl_Color and gl_SecondaryColor varying vars are interpolated
  80. without perspective correction
  81. </ul>
  82. <p>
  83. All other major features of the shading language should function.
  84. </p>
  85. <h2 id="notes">Implementation Notes</h2>
  86. <ul>
  87. <li>Shading language programs are compiled into low-level programs
  88. very similar to those of GL_ARB_vertex/fragment_program.
  89. <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
  90. float[4] registers.
  91. <li>Float constants and variables are packed so that up to four floats
  92. can occupy one program parameter/register.
  93. <li>All function calls are inlined.
  94. <li>Shaders which use too many registers will not compile.
  95. <li>The quality of generated code is pretty good, register usage is fair.
  96. <li>Shader error detection and reporting of errors (InfoLog) is not
  97. very good yet.
  98. <li>The ftransform() function doesn't necessarily match the results of
  99. fixed-function transformation.
  100. </ul>
  101. <p>
  102. These issues will be addressed/resolved in the future.
  103. </p>
  104. <h2 id="hints">Programming Hints</h2>
  105. <ul>
  106. <li>Use the built-in library functions whenever possible.
  107. For example, instead of writing this:
  108. <pre>
  109. float x = 1.0 / sqrt(y);
  110. </pre>
  111. Write this:
  112. <pre>
  113. float x = inversesqrt(y);
  114. </pre>
  115. </li>
  116. </ul>
  117. <h2 id="standalone">Stand-alone GLSL Compiler</h2>
  118. <p>
  119. The stand-alone GLSL compiler program can be used to compile GLSL shaders
  120. into low-level GPU code.
  121. </p>
  122. <p>
  123. This tool is useful for:
  124. </p>
  125. <ul>
  126. <li>Inspecting GPU code to gain insight into compilation
  127. <li>Generating initial GPU code for subsequent hand-tuning
  128. <li>Debugging the GLSL compiler itself
  129. </ul>
  130. <p>
  131. After building Mesa, the compiler can be found at src/glsl/glsl_compiler
  132. </p>
  133. <p>
  134. Here's an example of using the compiler to compile a vertex shader and
  135. emit GL_ARB_vertex_program-style instructions:
  136. </p>
  137. <pre>
  138. src/glsl/glsl_compiler --dump-ast myshader.vert
  139. </pre>
  140. Options include
  141. <ul>
  142. <li><b>--dump-ast</b> - dump GPU code
  143. <li><b>--dump-hir</b> - dump high-level IR code
  144. <li><b>--dump-lir</b> - dump low-level IR code
  145. <li><b>--link</b> - ???
  146. </ul>
  147. <h2 id="implementation">Compiler Implementation</h2>
  148. <p>
  149. The source code for Mesa's shading language compiler is in the
  150. <code>src/glsl/</code> directory.
  151. </p>
  152. <p>
  153. XXX provide some info about the compiler....
  154. </p>
  155. <p>
  156. The final vertex and fragment programs may be interpreted in software
  157. (see prog_execute.c) or translated into a specific hardware architecture
  158. (see drivers/dri/i915/i915_fragprog.c for example).
  159. </p>
  160. <h3>Code Generation Options</h3>
  161. <p>
  162. Internally, there are several options that control the compiler's code
  163. generation and instruction selection.
  164. These options are seen in the gl_shader_state struct and may be set
  165. by the device driver to indicate its preferences:
  166. <pre>
  167. struct gl_shader_state
  168. {
  169. ...
  170. /** Driver-selectable options: */
  171. GLboolean EmitHighLevelInstructions;
  172. GLboolean EmitCondCodes;
  173. GLboolean EmitComments;
  174. };
  175. </pre>
  176. <dl>
  177. <dt>EmitHighLevelInstructions</dt>
  178. <dd>
  179. This option controls instruction selection for loops and conditionals.
  180. If the option is set high-level IF/ELSE/ENDIF, LOOP/ENDLOOP, CONT/BRK
  181. instructions will be emitted.
  182. Otherwise, those constructs will be implemented with BRA instructions.
  183. </dd>
  184. <dt>EmitCondCodes</dt>
  185. <dd>
  186. If set, condition codes (ala GL_NV_fragment_program) will be used for
  187. branching and looping.
  188. Otherwise, ordinary registers will be used (the IF instruction will
  189. examine the first operand's X component and do the if-part if non-zero).
  190. This option is only relevant if EmitHighLevelInstructions is set.
  191. </dd>
  192. <dt>EmitComments</dt>
  193. <dd>
  194. If set, instructions will be annoted with comments to help with debugging.
  195. Extra NOP instructions will also be inserted.
  196. </dd>
  197. </dl>
  198. <h2 id="validation">Compiler Validation</h2>
  199. <p>
  200. Developers working on the GLSL compiler should test frequently to avoid
  201. regressions.
  202. </p>
  203. <p>
  204. The <a href="http://piglit.freedesktop.org/">Piglit</a> project
  205. has many GLSL tests.
  206. </p>
  207. <p>
  208. The Mesa demos repository also has some good GLSL tests.
  209. </p>
  210. </div>
  211. </body>
  212. </html>