Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

lp_bld_nir.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /**************************************************************************
  2. *
  3. * Copyright 2019 Red Hat.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. **************************************************************************/
  25. #ifndef LP_BLD_NIR_H
  26. #define LP_BLD_NIR_H
  27. #include "gallivm/lp_bld.h"
  28. #include "gallivm/lp_bld_limits.h"
  29. #include "lp_bld_type.h"
  30. #include "gallivm/lp_bld_tgsi.h"
  31. #include "nir.h"
  32. struct nir_shader;
  33. void lp_build_nir_soa(struct gallivm_state *gallivm,
  34. struct nir_shader *shader,
  35. const struct lp_build_tgsi_params *params,
  36. LLVMValueRef (*outputs)[4]);
  37. struct lp_build_nir_context
  38. {
  39. struct lp_build_context base;
  40. struct lp_build_context uint_bld;
  41. struct lp_build_context int_bld;
  42. struct lp_build_context uint8_bld;
  43. struct lp_build_context int8_bld;
  44. struct lp_build_context uint16_bld;
  45. struct lp_build_context int16_bld;
  46. struct lp_build_context dbl_bld;
  47. struct lp_build_context uint64_bld;
  48. struct lp_build_context int64_bld;
  49. LLVMValueRef *ssa_defs;
  50. struct hash_table *regs;
  51. struct hash_table *vars;
  52. nir_shader *shader;
  53. void (*load_ubo)(struct lp_build_nir_context *bld_base,
  54. unsigned nc,
  55. unsigned bit_size,
  56. bool offset_is_uniform,
  57. LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[4]);
  58. void (*load_kernel_arg)(struct lp_build_nir_context *bld_base,
  59. unsigned nc,
  60. unsigned bit_size,
  61. unsigned offset_bit_size,
  62. bool offset_is_uniform,
  63. LLVMValueRef offset, LLVMValueRef result[4]);
  64. void (*load_global)(struct lp_build_nir_context *bld_base,
  65. unsigned nc, unsigned bit_size,
  66. unsigned offset_bit_size,
  67. LLVMValueRef offset, LLVMValueRef result[4]);
  68. void (*store_global)(struct lp_build_nir_context *bld_base,
  69. unsigned writemask,
  70. unsigned nc, unsigned bit_size,
  71. unsigned addr_bit_size,
  72. LLVMValueRef addr, LLVMValueRef dst);
  73. void (*atomic_global)(struct lp_build_nir_context *bld_base,
  74. nir_intrinsic_op op,
  75. unsigned addr_bit_size,
  76. LLVMValueRef addr,
  77. LLVMValueRef val, LLVMValueRef val2,
  78. LLVMValueRef *result);
  79. /* for SSBO and shared memory */
  80. void (*load_mem)(struct lp_build_nir_context *bld_base,
  81. unsigned nc, unsigned bit_size,
  82. LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[4]);
  83. void (*store_mem)(struct lp_build_nir_context *bld_base,
  84. unsigned writemask, unsigned nc, unsigned bit_size,
  85. LLVMValueRef index, LLVMValueRef offset, LLVMValueRef dst);
  86. void (*atomic_mem)(struct lp_build_nir_context *bld_base,
  87. nir_intrinsic_op op,
  88. LLVMValueRef index, LLVMValueRef offset,
  89. LLVMValueRef val, LLVMValueRef val2,
  90. LLVMValueRef *result);
  91. void (*barrier)(struct lp_build_nir_context *bld_base);
  92. void (*image_op)(struct lp_build_nir_context *bld_base,
  93. struct lp_img_params *params);
  94. void (*image_size)(struct lp_build_nir_context *bld_base,
  95. struct lp_sampler_size_query_params *params);
  96. LLVMValueRef (*get_buffer_size)(struct lp_build_nir_context *bld_base,
  97. LLVMValueRef index);
  98. void (*load_var)(struct lp_build_nir_context *bld_base,
  99. nir_variable_mode deref_mode,
  100. unsigned num_components,
  101. unsigned bit_size,
  102. nir_variable *var,
  103. unsigned vertex_index,
  104. unsigned const_index,
  105. LLVMValueRef indir_index,
  106. LLVMValueRef result[4]);
  107. void (*store_var)(struct lp_build_nir_context *bld_base,
  108. nir_variable_mode deref_mode,
  109. unsigned bit_size,
  110. unsigned num_components,
  111. unsigned writemask,
  112. unsigned const_index,
  113. nir_variable *var, LLVMValueRef dst);
  114. LLVMValueRef (*load_reg)(struct lp_build_nir_context *bld_base,
  115. struct lp_build_context *reg_bld,
  116. const nir_reg_src *reg,
  117. LLVMValueRef indir_src,
  118. LLVMValueRef reg_storage);
  119. void (*store_reg)(struct lp_build_nir_context *bld_base,
  120. struct lp_build_context *reg_bld,
  121. const nir_reg_dest *reg,
  122. unsigned writemask,
  123. LLVMValueRef indir_src,
  124. LLVMValueRef reg_storage,
  125. LLVMValueRef dst[4]);
  126. void (*emit_var_decl)(struct lp_build_nir_context *bld_base,
  127. nir_variable *var);
  128. void (*tex)(struct lp_build_nir_context *bld_base,
  129. struct lp_sampler_params *params);
  130. void (*tex_size)(struct lp_build_nir_context *bld_base,
  131. struct lp_sampler_size_query_params *params);
  132. void (*sysval_intrin)(struct lp_build_nir_context *bld_base,
  133. nir_intrinsic_instr *instr,
  134. LLVMValueRef result[4]);
  135. void (*discard)(struct lp_build_nir_context *bld_base,
  136. LLVMValueRef cond);
  137. void (*bgnloop)(struct lp_build_nir_context *bld_base);
  138. void (*endloop)(struct lp_build_nir_context *bld_base);
  139. void (*if_cond)(struct lp_build_nir_context *bld_base, LLVMValueRef cond);
  140. void (*else_stmt)(struct lp_build_nir_context *bld_base);
  141. void (*endif_stmt)(struct lp_build_nir_context *bld_base);
  142. void (*break_stmt)(struct lp_build_nir_context *bld_base);
  143. void (*continue_stmt)(struct lp_build_nir_context *bld_base);
  144. void (*emit_vertex)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
  145. void (*end_primitive)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
  146. // LLVMValueRef main_function
  147. };
  148. struct lp_build_nir_soa_context
  149. {
  150. struct lp_build_nir_context bld_base;
  151. /* Builder for scalar elements of shader's data type (float) */
  152. struct lp_build_context elem_bld;
  153. struct lp_build_context uint_elem_bld;
  154. LLVMValueRef consts_ptr;
  155. LLVMValueRef const_sizes_ptr;
  156. LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS];
  157. LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS];
  158. const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
  159. LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
  160. LLVMValueRef context_ptr;
  161. LLVMValueRef thread_data_ptr;
  162. LLVMValueRef ssbo_ptr;
  163. LLVMValueRef ssbo_sizes_ptr;
  164. LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
  165. LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS];
  166. LLVMValueRef shared_ptr;
  167. const struct lp_build_coro_suspend_info *coro;
  168. const struct lp_build_sampler_soa *sampler;
  169. const struct lp_build_image_soa *image;
  170. const struct lp_build_gs_iface *gs_iface;
  171. LLVMValueRef emitted_prims_vec_ptr;
  172. LLVMValueRef total_emitted_vertices_vec_ptr;
  173. LLVMValueRef emitted_vertices_vec_ptr;
  174. LLVMValueRef max_output_vertices_vec;
  175. struct lp_bld_tgsi_system_values system_values;
  176. nir_variable_mode indirects;
  177. struct lp_build_mask_context *mask;
  178. struct lp_exec_mask exec_mask;
  179. /* We allocate/use this array of inputs if (indirects & nir_var_shader_in) is
  180. * set. The inputs[] array above is unused then.
  181. */
  182. LLVMValueRef inputs_array;
  183. LLVMValueRef kernel_args_ptr;
  184. };
  185. bool
  186. lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
  187. struct nir_shader *nir);
  188. void lp_build_opt_nir(struct nir_shader *nir);
  189. static inline LLVMValueRef
  190. lp_nir_array_build_gather_values(LLVMBuilderRef builder,
  191. LLVMValueRef * values,
  192. unsigned value_count)
  193. {
  194. LLVMTypeRef arr_type = LLVMArrayType(LLVMTypeOf(values[0]), value_count);
  195. LLVMValueRef arr = LLVMGetUndef(arr_type);
  196. unsigned i;
  197. for (i = 0; i < value_count; i++) {
  198. arr = LLVMBuildInsertValue(builder, arr, values[i], i, "");
  199. }
  200. return arr;
  201. }
  202. static inline struct lp_build_context *get_int_bld(struct lp_build_nir_context *bld_base,
  203. bool is_unsigned,
  204. unsigned op_bit_size)
  205. {
  206. if (is_unsigned) {
  207. switch (op_bit_size) {
  208. case 64:
  209. return &bld_base->uint64_bld;
  210. case 32:
  211. default:
  212. return &bld_base->uint_bld;
  213. case 16:
  214. return &bld_base->uint16_bld;
  215. case 8:
  216. return &bld_base->uint8_bld;
  217. }
  218. } else {
  219. switch (op_bit_size) {
  220. case 64:
  221. return &bld_base->int64_bld;
  222. default:
  223. case 32:
  224. return &bld_base->int_bld;
  225. case 16:
  226. return &bld_base->int16_bld;
  227. case 8:
  228. return &bld_base->int8_bld;
  229. }
  230. }
  231. }
  232. #endif