Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / gallium / auxiliary / gallivm / lp_bld_nir.h
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
26 #ifndef LP_BLD_NIR_H
27 #define LP_BLD_NIR_H
28
29 #include "gallivm/lp_bld.h"
30 #include "gallivm/lp_bld_limits.h"
31 #include "lp_bld_type.h"
32
33 #include "gallivm/lp_bld_tgsi.h"
34 #include "nir.h"
35
36 struct nir_shader;
37
38 void lp_build_nir_soa(struct gallivm_state *gallivm,
39 struct nir_shader *shader,
40 const struct lp_build_tgsi_params *params,
41 LLVMValueRef (*outputs)[4]);
42
43 struct lp_build_nir_context
44 {
45 struct lp_build_context base;
46 struct lp_build_context uint_bld;
47 struct lp_build_context int_bld;
48 struct lp_build_context uint8_bld;
49 struct lp_build_context int8_bld;
50 struct lp_build_context uint16_bld;
51 struct lp_build_context int16_bld;
52 struct lp_build_context dbl_bld;
53 struct lp_build_context uint64_bld;
54 struct lp_build_context int64_bld;
55
56 LLVMValueRef *ssa_defs;
57 struct hash_table *regs;
58 struct hash_table *vars;
59
60 nir_shader *shader;
61
62 void (*load_ubo)(struct lp_build_nir_context *bld_base,
63 unsigned nc,
64 unsigned bit_size,
65 bool offset_is_uniform,
66 LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
67
68 void (*load_kernel_arg)(struct lp_build_nir_context *bld_base,
69 unsigned nc,
70 unsigned bit_size,
71 unsigned offset_bit_size,
72 bool offset_is_uniform,
73 LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
74
75 void (*load_global)(struct lp_build_nir_context *bld_base,
76 unsigned nc, unsigned bit_size,
77 unsigned offset_bit_size,
78 LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
79
80 void (*store_global)(struct lp_build_nir_context *bld_base,
81 unsigned writemask,
82 unsigned nc, unsigned bit_size,
83 unsigned addr_bit_size,
84 LLVMValueRef addr, LLVMValueRef dst);
85
86 void (*atomic_global)(struct lp_build_nir_context *bld_base,
87 nir_intrinsic_op op,
88 unsigned addr_bit_size,
89 LLVMValueRef addr,
90 LLVMValueRef val, LLVMValueRef val2,
91 LLVMValueRef *result);
92
93 /* for SSBO and shared memory */
94 void (*load_mem)(struct lp_build_nir_context *bld_base,
95 unsigned nc, unsigned bit_size,
96 LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
97 void (*store_mem)(struct lp_build_nir_context *bld_base,
98 unsigned writemask, unsigned nc, unsigned bit_size,
99 LLVMValueRef index, LLVMValueRef offset, LLVMValueRef dst);
100
101 void (*atomic_mem)(struct lp_build_nir_context *bld_base,
102 nir_intrinsic_op op,
103 LLVMValueRef index, LLVMValueRef offset,
104 LLVMValueRef val, LLVMValueRef val2,
105 LLVMValueRef *result);
106
107 void (*barrier)(struct lp_build_nir_context *bld_base);
108
109 void (*image_op)(struct lp_build_nir_context *bld_base,
110 struct lp_img_params *params);
111 void (*image_size)(struct lp_build_nir_context *bld_base,
112 struct lp_sampler_size_query_params *params);
113 LLVMValueRef (*get_buffer_size)(struct lp_build_nir_context *bld_base,
114 LLVMValueRef index);
115
116 void (*load_var)(struct lp_build_nir_context *bld_base,
117 nir_variable_mode deref_mode,
118 unsigned num_components,
119 unsigned bit_size,
120 nir_variable *var,
121 unsigned vertex_index,
122 LLVMValueRef indir_vertex_index,
123 unsigned const_index,
124 LLVMValueRef indir_index,
125 LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
126 void (*store_var)(struct lp_build_nir_context *bld_base,
127 nir_variable_mode deref_mode,
128 unsigned num_components,
129 unsigned bit_size,
130 nir_variable *var,
131 unsigned writemask,
132 LLVMValueRef indir_vertex_index,
133 unsigned const_index,
134 LLVMValueRef indir_index,
135 LLVMValueRef dst);
136
137 LLVMValueRef (*load_reg)(struct lp_build_nir_context *bld_base,
138 struct lp_build_context *reg_bld,
139 const nir_reg_src *reg,
140 LLVMValueRef indir_src,
141 LLVMValueRef reg_storage);
142 void (*store_reg)(struct lp_build_nir_context *bld_base,
143 struct lp_build_context *reg_bld,
144 const nir_reg_dest *reg,
145 unsigned writemask,
146 LLVMValueRef indir_src,
147 LLVMValueRef reg_storage,
148 LLVMValueRef dst[NIR_MAX_VEC_COMPONENTS]);
149
150 void (*emit_var_decl)(struct lp_build_nir_context *bld_base,
151 nir_variable *var);
152
153 void (*tex)(struct lp_build_nir_context *bld_base,
154 struct lp_sampler_params *params);
155
156 void (*tex_size)(struct lp_build_nir_context *bld_base,
157 struct lp_sampler_size_query_params *params);
158
159 void (*sysval_intrin)(struct lp_build_nir_context *bld_base,
160 nir_intrinsic_instr *instr,
161 LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
162 void (*discard)(struct lp_build_nir_context *bld_base,
163 LLVMValueRef cond);
164
165 void (*bgnloop)(struct lp_build_nir_context *bld_base);
166 void (*endloop)(struct lp_build_nir_context *bld_base);
167 void (*if_cond)(struct lp_build_nir_context *bld_base, LLVMValueRef cond);
168 void (*else_stmt)(struct lp_build_nir_context *bld_base);
169 void (*endif_stmt)(struct lp_build_nir_context *bld_base);
170 void (*break_stmt)(struct lp_build_nir_context *bld_base);
171 void (*continue_stmt)(struct lp_build_nir_context *bld_base);
172
173 void (*emit_vertex)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
174 void (*end_primitive)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
175
176 void (*vote)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
177 void (*helper_invocation)(struct lp_build_nir_context *bld_base, LLVMValueRef *dst);
178
179 void (*interp_at)(struct lp_build_nir_context *bld_base,
180 unsigned num_components,
181 nir_variable *var,
182 bool centroid, bool sample,
183 unsigned const_index,
184 LLVMValueRef indir_index,
185 LLVMValueRef offsets[2], LLVMValueRef dst[4]);
186 // LLVMValueRef main_function
187 };
188
189 struct lp_build_nir_soa_context
190 {
191 struct lp_build_nir_context bld_base;
192
193 /* Builder for scalar elements of shader's data type (float) */
194 struct lp_build_context elem_bld;
195 struct lp_build_context uint_elem_bld;
196
197 LLVMValueRef consts_ptr;
198 LLVMValueRef const_sizes_ptr;
199 LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS];
200 LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS];
201 const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
202 LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
203 LLVMValueRef context_ptr;
204 LLVMValueRef thread_data_ptr;
205
206 LLVMValueRef ssbo_ptr;
207 LLVMValueRef ssbo_sizes_ptr;
208 LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
209 LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS];
210
211 LLVMValueRef shared_ptr;
212
213 const struct lp_build_coro_suspend_info *coro;
214
215 const struct lp_build_sampler_soa *sampler;
216 const struct lp_build_image_soa *image;
217
218 const struct lp_build_gs_iface *gs_iface;
219 const struct lp_build_tcs_iface *tcs_iface;
220 const struct lp_build_tes_iface *tes_iface;
221 const struct lp_build_fs_iface *fs_iface;
222 LLVMValueRef emitted_prims_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
223 LLVMValueRef total_emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
224 LLVMValueRef emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
225 LLVMValueRef max_output_vertices_vec;
226 struct lp_bld_tgsi_system_values system_values;
227
228 nir_variable_mode indirects;
229 struct lp_build_mask_context *mask;
230 struct lp_exec_mask exec_mask;
231
232 /* We allocate/use this array of inputs if (indirects & nir_var_shader_in) is
233 * set. The inputs[] array above is unused then.
234 */
235 LLVMValueRef inputs_array;
236
237 LLVMValueRef kernel_args_ptr;
238 unsigned gs_vertex_streams;
239 };
240
241 bool
242 lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
243 struct nir_shader *nir);
244
245 void lp_build_opt_nir(struct nir_shader *nir);
246
247 static inline LLVMValueRef
248 lp_nir_array_build_gather_values(LLVMBuilderRef builder,
249 LLVMValueRef * values,
250 unsigned value_count)
251 {
252 LLVMTypeRef arr_type = LLVMArrayType(LLVMTypeOf(values[0]), value_count);
253 LLVMValueRef arr = LLVMGetUndef(arr_type);
254 unsigned i;
255
256 for (i = 0; i < value_count; i++) {
257 arr = LLVMBuildInsertValue(builder, arr, values[i], i, "");
258 }
259 return arr;
260 }
261
262
263 static inline struct lp_build_context *get_int_bld(struct lp_build_nir_context *bld_base,
264 bool is_unsigned,
265 unsigned op_bit_size)
266 {
267 if (is_unsigned) {
268 switch (op_bit_size) {
269 case 64:
270 return &bld_base->uint64_bld;
271 case 32:
272 default:
273 return &bld_base->uint_bld;
274 case 16:
275 return &bld_base->uint16_bld;
276 case 8:
277 return &bld_base->uint8_bld;
278 }
279 } else {
280 switch (op_bit_size) {
281 case 64:
282 return &bld_base->int64_bld;
283 default:
284 case 32:
285 return &bld_base->int_bld;
286 case 16:
287 return &bld_base->int16_bld;
288 case 8:
289 return &bld_base->int8_bld;
290 }
291 }
292 }
293
294 #endif