Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ir_variable.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright © 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "glsl_parser_extras.h"
  24. #include "glsl_symbol_table.h"
  25. #include "ir.h"
  26. #include "builtin_variables.h"
  27. #ifndef Elements
  28. #define Elements(x) (sizeof(x)/sizeof(*(x)))
  29. #endif
  30. static void
  31. add_builtin_variable(const builtin_variable *proto, exec_list *instructions,
  32. glsl_symbol_table *symtab)
  33. {
  34. /* Create a new variable declaration from the description supplied by
  35. * the caller.
  36. */
  37. const glsl_type *const type = symtab->get_type(proto->type);
  38. assert(type != NULL);
  39. ir_variable *var = new ir_variable(type, proto->name);
  40. var->mode = proto->mode;
  41. if (var->mode != ir_var_out)
  42. var->read_only = true;
  43. /* Once the variable is created an initialized, add it to the symbol table
  44. * and add the declaration to the IR stream.
  45. */
  46. instructions->push_tail(var);
  47. symtab->add_variable(var->name, var);
  48. }
  49. static void
  50. generate_110_vs_variables(exec_list *instructions,
  51. glsl_symbol_table *symtab)
  52. {
  53. for (unsigned i = 0; i < Elements(builtin_core_vs_variables); i++) {
  54. add_builtin_variable(& builtin_core_vs_variables[i],
  55. instructions, symtab);
  56. }
  57. for (unsigned i = 0
  58. ; i < Elements(builtin_110_deprecated_vs_variables)
  59. ; i++) {
  60. add_builtin_variable(& builtin_110_deprecated_vs_variables[i],
  61. instructions, symtab);
  62. }
  63. /* FINISHME: Add support fo gl_TexCoord. The size of this array is
  64. * FINISHME: implementation dependent based on the value of
  65. * FINISHME: GL_MAX_TEXTURE_COORDS.
  66. */
  67. }
  68. static void
  69. generate_120_vs_variables(exec_list *instructions,
  70. glsl_symbol_table *symtab)
  71. {
  72. /* GLSL version 1.20 did not add any built-in variables in the vertex
  73. * shader.
  74. */
  75. generate_110_vs_variables(instructions, symtab);
  76. }
  77. static void
  78. generate_130_vs_variables(exec_list *instructions,
  79. glsl_symbol_table *symtab)
  80. {
  81. generate_120_vs_variables(instructions, symtab);
  82. for (unsigned i = 0; i < Elements(builtin_130_vs_variables); i++) {
  83. add_builtin_variable(& builtin_130_vs_variables[i],
  84. instructions, symtab);
  85. }
  86. /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
  87. * FINISHME: implementation dependent based on the value of
  88. * FINISHME: GL_MAX_CLIP_DISTANCES.
  89. */
  90. }
  91. static void
  92. initialize_vs_variables(exec_list *instructions,
  93. struct _mesa_glsl_parse_state *state)
  94. {
  95. switch (state->language_version) {
  96. case 110:
  97. generate_110_vs_variables(instructions, state->symbols);
  98. break;
  99. case 120:
  100. generate_120_vs_variables(instructions, state->symbols);
  101. break;
  102. case 130:
  103. generate_130_vs_variables(instructions, state->symbols);
  104. break;
  105. }
  106. }
  107. static void
  108. generate_110_fs_variables(exec_list *instructions,
  109. glsl_symbol_table *symtab)
  110. {
  111. for (unsigned i = 0; i < Elements(builtin_core_fs_variables); i++) {
  112. add_builtin_variable(& builtin_core_fs_variables[i],
  113. instructions, symtab);
  114. }
  115. /* FINISHME: Add support for gl_FragData[GL_MAX_DRAW_BUFFERS]. */
  116. }
  117. static void
  118. generate_120_fs_variables(exec_list *instructions,
  119. glsl_symbol_table *symtab)
  120. {
  121. /* GLSL version 1.20 did not add any built-in variables in the fragment
  122. * shader.
  123. */
  124. generate_110_fs_variables(instructions, symtab);
  125. }
  126. static void
  127. generate_130_fs_variables(exec_list *instructions,
  128. glsl_symbol_table *symtab)
  129. {
  130. generate_120_fs_variables(instructions, symtab);
  131. /* FINISHME: Add support fo gl_ClipDistance. The size of this array is
  132. * FINISHME: implementation dependent based on the value of
  133. * FINISHME: GL_MAX_CLIP_DISTANCES.
  134. */
  135. }
  136. static void
  137. initialize_fs_variables(exec_list *instructions,
  138. struct _mesa_glsl_parse_state *state)
  139. {
  140. switch (state->language_version) {
  141. case 110:
  142. generate_110_fs_variables(instructions, state->symbols);
  143. break;
  144. case 120:
  145. generate_120_fs_variables(instructions, state->symbols);
  146. break;
  147. case 130:
  148. generate_130_fs_variables(instructions, state->symbols);
  149. break;
  150. }
  151. }
  152. void
  153. _mesa_glsl_initialize_variables(exec_list *instructions,
  154. struct _mesa_glsl_parse_state *state)
  155. {
  156. switch (state->target) {
  157. case vertex_shader:
  158. initialize_vs_variables(instructions, state);
  159. break;
  160. case geometry_shader:
  161. break;
  162. case fragment_shader:
  163. initialize_fs_variables(instructions, state);
  164. break;
  165. }
  166. }