Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

shading.html 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <HTML>
  2. <TITLE>Shading Language Support</TITLE>
  3. <link rel="stylesheet" type="text/css" href="mesa.css"></head>
  4. <BODY>
  5. <H1>Shading Language Support</H1>
  6. <p>
  7. This page describes the features and status of Mesa's support for the
  8. <a href="http://opengl.org/documentation/glsl/" target="_parent">
  9. OpenGL Shading Language</a>.
  10. </p>
  11. <p>
  12. Contents
  13. </p>
  14. <ul>
  15. <li><a href="#envvars">Environment variables</a>
  16. <li><a href="#120">GLSL 1.20 support</a>
  17. <li><a href="#unsup">Unsupported Features</a>
  18. <li><a href="#notes">Implementation Notes</a>
  19. <li><a href="#hints">Programming Hints</a>
  20. <li><a href="#standalone">Stand-alone GLSL Compiler</a>
  21. <li><a href="#implementation">Compiler Implementation</a>
  22. <li><a href="#validation">Compiler Validation</a>
  23. </ul>
  24. <a name="envvars">
  25. <h2>Environment Variables</h2>
  26. <p>
  27. The <b>MESA_GLSL</b> environment variable can be set to a comma-separated
  28. list of keywords to control some aspects of the GLSL compiler and shader
  29. execution. These are generally used for debugging.
  30. </p>
  31. <ul>
  32. <li><b>dump</b> - print GLSL shader code to stdout at link time
  33. <li><b>log</b> - log all GLSL shaders to files.
  34. The filenames will be "shader_X.vert" or "shader_X.frag" where X
  35. the shader ID.
  36. <li><b>nopt</b> - disable compiler optimizations
  37. <li><b>opt</b> - force compiler optimizations
  38. <li><b>uniform</b> - print message to stdout when glUniform is called
  39. <li><b>nopvert</b> - force vertex shaders to be a simple shader that just transforms
  40. the vertex position with ftransform() and passes through the color and
  41. texcoord[0] attributes.
  42. <li><b>nopfrag</b> - force fragment shader to be a simple shader that passes
  43. through the color attribute.
  44. <li><b>useprog</b> - log glUseProgram calls to stderr
  45. </ul>
  46. <p>
  47. Example: export MESA_GLSL=dump,nopt
  48. </p>
  49. <a name="120">
  50. <h2>GLSL Version</h2>
  51. <p>
  52. The GLSL compiler currently supports version 1.20 of the shading language.
  53. </p>
  54. <p>
  55. Several GLSL extensions are also supported:
  56. </p>
  57. <ul>
  58. <li>GL_ARB_draw_buffers
  59. <li>GL_ARB_texture_rectangle
  60. <li>GL_ARB_fragment_coord_conventions
  61. <li>GL_EXT_texture_array
  62. </ul>
  63. <a name="unsup">
  64. <h2>Unsupported Features</h2>
  65. <p>XXX update this section</p>
  66. <p>
  67. The following features of the shading language are not yet fully supported
  68. in Mesa:
  69. </p>
  70. <ul>
  71. <li>Linking of multiple shaders does not always work. Currently, linking
  72. is implemented through shader concatenation and re-compiling. This
  73. doesn't always work because of some #pragma and preprocessor issues.
  74. <li>gl_ClipVertex
  75. <li>The gl_Color and gl_SecondaryColor varying vars are interpolated
  76. without perspective correction
  77. </ul>
  78. <p>
  79. All other major features of the shading language should function.
  80. </p>
  81. <a name="notes">
  82. <h2>Implementation Notes</h2>
  83. <ul>
  84. <li>Shading language programs are compiled into low-level programs
  85. very similar to those of GL_ARB_vertex/fragment_program.
  86. <li>All vector types (vec2, vec3, vec4, bvec2, etc) currently occupy full
  87. float[4] registers.
  88. <li>Float constants and variables are packed so that up to four floats
  89. can occupy one program parameter/register.
  90. <li>All function calls are inlined.
  91. <li>Shaders which use too many registers will not compile.
  92. <li>The quality of generated code is pretty good, register usage is fair.
  93. <li>Shader error detection and reporting of errors (InfoLog) is not
  94. very good yet.
  95. <li>The ftransform() function doesn't necessarily match the results of
  96. fixed-function transformation.
  97. </ul>
  98. <p>
  99. These issues will be addressed/resolved in the future.
  100. </p>
  101. <a name="hints">
  102. <h2>Programming Hints</h2>
  103. <ul>
  104. <li>Use the built-in library functions whenever possible.
  105. For example, instead of writing this:
  106. <pre>
  107. float x = 1.0 / sqrt(y);
  108. </pre>
  109. Write this:
  110. <pre>
  111. float x = inversesqrt(y);
  112. </pre>
  113. </li>
  114. </ul>
  115. <a name="standalone">
  116. <h2>Stand-alone GLSL Compiler</h2>
  117. <p>
  118. The stand-alone GLSL compiler program can be used to compile GLSL shaders
  119. into low-level GPU code.
  120. </p>
  121. <p>
  122. This tool is useful for:
  123. <p>
  124. <ul>
  125. <li>Inspecting GPU code to gain insight into compilation
  126. <li>Generating initial GPU code for subsequent hand-tuning
  127. <li>Debugging the GLSL compiler itself
  128. </ul>
  129. <p>
  130. After building Mesa, the compiler can be found at src/glsl/glsl_compiler
  131. </p>
  132. <p>
  133. Here's an example of using the compiler to compile a vertex shader and
  134. emit GL_ARB_vertex_program-style instructions:
  135. </p>
  136. <pre>
  137. src/glsl/glsl_compiler --dump-ast myshader.vert
  138. </pre>
  139. Options include
  140. <ul>
  141. <li><b>--dump-ast</b> - dump GPU code
  142. <li><b>--dump-hir</b> - dump high-level IR code
  143. <li><b>--dump-lir</b> - dump low-level IR code
  144. <li><b>--link</b> - ???
  145. </ul>
  146. <a name="implementation">
  147. <h2>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. <ul>
  177. <li>EmitHighLevelInstructions
  178. <br>
  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. </li>
  184. <li>EmitCondCodes
  185. <br>
  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. </li>
  192. <li>EmitComments
  193. <br>
  194. If set, instructions will be annoted with comments to help with debugging.
  195. Extra NOP instructions will also be inserted.
  196. </br>
  197. </ul>
  198. <a name="validation">
  199. <h2>Compiler Validation</h2>
  200. <p>
  201. Developers working on the GLSL compiler should test frequently to avoid
  202. regressions.
  203. </p>
  204. <p>
  205. The <a href="http://people.freedesktop.org/~nh/piglit/">Piglit</a> project
  206. has many GLSL tests and the
  207. <a href="http://glean.sf.net" target="_parent">Glean</a> glsl1 test
  208. tests GLSL features.
  209. </p>
  210. <p>
  211. The Mesa demos repository also has some good GLSL tests.
  212. </p>
  213. </BODY>
  214. </HTML>