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.

ir.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 "list.h"
  24. struct ir_program {
  25. void *bong_hits;
  26. };
  27. enum ir_opcodes {
  28. ir_op_var_decl,
  29. ir_op_assign,
  30. ir_op_expression,
  31. ir_op_dereference,
  32. ir_op_jump,
  33. ir_op_label,
  34. ir_op_constant,
  35. ir_op_func_sig,
  36. ir_op_func
  37. };
  38. /**
  39. * Base class of all IR instructions
  40. */
  41. class ir_instruction : public exec_node {
  42. public:
  43. unsigned mode;
  44. const struct glsl_type *type;
  45. protected:
  46. ir_instruction(int mode);
  47. private:
  48. /**
  49. * Dummy constructor to catch bad constructors in derived classes.
  50. *
  51. * Every derived must use the constructor that sets the instructions
  52. * mode. Having the \c void constructor private prevents derived classes
  53. * from accidentally doing the wrong thing.
  54. */
  55. ir_instruction(void);
  56. };
  57. enum ir_variable_mode {
  58. ir_var_auto = 0,
  59. ir_var_uniform,
  60. ir_var_in,
  61. ir_var_out,
  62. ir_var_inout
  63. };
  64. enum ir_varaible_interpolation {
  65. ir_var_smooth = 0,
  66. ir_var_flat,
  67. ir_var_noperspective
  68. };
  69. class ir_variable : public ir_instruction {
  70. public:
  71. ir_variable(const struct glsl_type *, const char *);
  72. const char *name;
  73. unsigned read_only:1;
  74. unsigned centroid:1;
  75. unsigned invariant:1;
  76. unsigned mode:3;
  77. unsigned interpolation:2;
  78. };
  79. class ir_label : public ir_instruction {
  80. public:
  81. ir_label(const char *label);
  82. const char *label;
  83. };
  84. /*@{*/
  85. class ir_function_signature : public ir_instruction {
  86. public:
  87. ir_function_signature(void);
  88. /**
  89. * Function return type.
  90. *
  91. * \note This discards the optional precision qualifier.
  92. */
  93. const struct glsl_type *return_type;
  94. /**
  95. * List of function parameters stored as ir_variable objects.
  96. */
  97. struct exec_list parameters;
  98. /**
  99. * Pointer to the label that begins the function definition.
  100. */
  101. ir_label *definition;
  102. };
  103. /**
  104. * Header for tracking functions in the symbol table
  105. */
  106. class ir_function : public ir_instruction {
  107. public:
  108. ir_function(void);
  109. /**
  110. * Name of the function.
  111. */
  112. const char *name;
  113. struct exec_list signatures;
  114. };
  115. /*@}*/
  116. class ir_expression;
  117. class ir_dereference;
  118. class ir_assignment : public ir_instruction {
  119. public:
  120. ir_assignment(ir_instruction *lhs, ir_instruction *rhs,
  121. ir_expression *condition);
  122. /**
  123. * Left-hand side of the assignment.
  124. */
  125. ir_dereference *lhs;
  126. /**
  127. * Value being assigned
  128. *
  129. * This should be either \c ir_op_expression or \c ir_op_deference.
  130. */
  131. ir_instruction *rhs;
  132. /**
  133. * Optional condition for the assignment.
  134. */
  135. ir_expression *condition;
  136. };
  137. enum ir_expression_operation {
  138. ir_unop_bit_not,
  139. ir_unop_logic_not,
  140. ir_unop_neg,
  141. ir_unop_abs,
  142. ir_unop_rcp,
  143. ir_unop_rsq,
  144. ir_unop_exp,
  145. ir_unop_log,
  146. ir_unop_f2i, /**< Float-to-integer conversion. */
  147. ir_unop_i2f, /**< Integer-to-float conversion. */
  148. /**
  149. * \name Unary floating-point rounding operations.
  150. */
  151. /*@{*/
  152. ir_unop_trunc,
  153. ir_unop_ceil,
  154. ir_unop_floor,
  155. /*@}*/
  156. ir_binop_add,
  157. ir_binop_sub,
  158. ir_binop_mul,
  159. ir_binop_div,
  160. ir_binop_mod,
  161. /**
  162. * \name Binary comparison operators
  163. */
  164. /*@{*/
  165. ir_binop_less,
  166. ir_binop_greater,
  167. ir_binop_lequal,
  168. ir_binop_gequal,
  169. ir_binop_equal,
  170. ir_binop_nequal,
  171. /*@}*/
  172. /**
  173. * \name Bit-wise binary operations.
  174. */
  175. /*@{*/
  176. ir_binop_lshift,
  177. ir_binop_rshift,
  178. ir_binop_bit_and,
  179. ir_binop_bit_xor,
  180. ir_binop_bit_or,
  181. /*@}*/
  182. ir_binop_logic_and,
  183. ir_binop_logic_xor,
  184. ir_binop_logic_or,
  185. ir_binop_logic_not,
  186. ir_binop_dot,
  187. ir_binop_min,
  188. ir_binop_max,
  189. ir_binop_pow
  190. };
  191. class ir_expression : public ir_instruction {
  192. public:
  193. ir_expression(int op, const struct glsl_type *type,
  194. ir_instruction *, ir_instruction *);
  195. ir_expression_operation operation;
  196. ir_instruction *operands[2];
  197. };
  198. struct ir_swizzle_mask {
  199. unsigned x:2;
  200. unsigned y:2;
  201. unsigned z:2;
  202. unsigned w:2;
  203. /**
  204. * Number of components in the swizzle.
  205. */
  206. unsigned num_components:2;
  207. /**
  208. * Does the swizzle contain duplicate components?
  209. *
  210. * L-value swizzles cannot contain duplicate components.
  211. */
  212. unsigned has_duplicates:1;
  213. };
  214. class ir_dereference : public ir_instruction {
  215. public:
  216. ir_dereference(struct ir_instruction *);
  217. enum {
  218. ir_reference_variable,
  219. ir_reference_array,
  220. ir_reference_record
  221. } mode;
  222. /**
  223. * Object being dereferenced.
  224. *
  225. * Must be either an \c ir_variable or an \c ir_deference.
  226. */
  227. ir_instruction *var;
  228. union {
  229. ir_expression *array_index;
  230. const char *field;
  231. struct ir_swizzle_mask swizzle;
  232. } selector;
  233. };
  234. class ir_constant : public ir_instruction {
  235. public:
  236. ir_constant(const struct glsl_type *type, const void *data);
  237. /**
  238. * Value of the constant.
  239. *
  240. * The field used to back the values supplied by the constant is determined
  241. * by the type associated with the \c ir_instruction. Constants may be
  242. * scalars, vectors, or matrices.
  243. */
  244. union {
  245. unsigned u[16];
  246. int i[16];
  247. float f[16];
  248. bool b[16];
  249. } value;
  250. };