Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/auxiliary/gallivm/lp_bld_nir.h
4565 views
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
/** Value range analysis hash table used in code generation. */
61
struct hash_table *range_ht;
62
63
nir_shader *shader;
64
65
void (*load_ubo)(struct lp_build_nir_context *bld_base,
66
unsigned nc,
67
unsigned bit_size,
68
bool offset_is_uniform,
69
LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
70
71
void (*load_kernel_arg)(struct lp_build_nir_context *bld_base,
72
unsigned nc,
73
unsigned bit_size,
74
unsigned offset_bit_size,
75
bool offset_is_uniform,
76
LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
77
78
void (*load_global)(struct lp_build_nir_context *bld_base,
79
unsigned nc, unsigned bit_size,
80
unsigned offset_bit_size,
81
LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
82
83
void (*store_global)(struct lp_build_nir_context *bld_base,
84
unsigned writemask,
85
unsigned nc, unsigned bit_size,
86
unsigned addr_bit_size,
87
LLVMValueRef addr, LLVMValueRef dst);
88
89
void (*atomic_global)(struct lp_build_nir_context *bld_base,
90
nir_intrinsic_op op,
91
unsigned addr_bit_size,
92
unsigned val_bit_size,
93
LLVMValueRef addr,
94
LLVMValueRef val, LLVMValueRef val2,
95
LLVMValueRef *result);
96
97
/* for SSBO and shared memory */
98
void (*load_mem)(struct lp_build_nir_context *bld_base,
99
unsigned nc, unsigned bit_size,
100
LLVMValueRef index, LLVMValueRef offset, LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
101
void (*store_mem)(struct lp_build_nir_context *bld_base,
102
unsigned writemask, unsigned nc, unsigned bit_size,
103
LLVMValueRef index, LLVMValueRef offset, LLVMValueRef dst);
104
105
void (*atomic_mem)(struct lp_build_nir_context *bld_base,
106
nir_intrinsic_op op,
107
unsigned bit_size,
108
LLVMValueRef index, LLVMValueRef offset,
109
LLVMValueRef val, LLVMValueRef val2,
110
LLVMValueRef *result);
111
112
void (*barrier)(struct lp_build_nir_context *bld_base);
113
114
void (*image_op)(struct lp_build_nir_context *bld_base,
115
struct lp_img_params *params);
116
void (*image_size)(struct lp_build_nir_context *bld_base,
117
struct lp_sampler_size_query_params *params);
118
LLVMValueRef (*get_ssbo_size)(struct lp_build_nir_context *bld_base,
119
LLVMValueRef index);
120
121
void (*load_var)(struct lp_build_nir_context *bld_base,
122
nir_variable_mode deref_mode,
123
unsigned num_components,
124
unsigned bit_size,
125
nir_variable *var,
126
unsigned vertex_index,
127
LLVMValueRef indir_vertex_index,
128
unsigned const_index,
129
LLVMValueRef indir_index,
130
LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
131
void (*store_var)(struct lp_build_nir_context *bld_base,
132
nir_variable_mode deref_mode,
133
unsigned num_components,
134
unsigned bit_size,
135
nir_variable *var,
136
unsigned writemask,
137
LLVMValueRef indir_vertex_index,
138
unsigned const_index,
139
LLVMValueRef indir_index,
140
LLVMValueRef dst);
141
142
LLVMValueRef (*load_reg)(struct lp_build_nir_context *bld_base,
143
struct lp_build_context *reg_bld,
144
const nir_reg_src *reg,
145
LLVMValueRef indir_src,
146
LLVMValueRef reg_storage);
147
void (*store_reg)(struct lp_build_nir_context *bld_base,
148
struct lp_build_context *reg_bld,
149
const nir_reg_dest *reg,
150
unsigned writemask,
151
LLVMValueRef indir_src,
152
LLVMValueRef reg_storage,
153
LLVMValueRef dst[NIR_MAX_VEC_COMPONENTS]);
154
155
void (*load_scratch)(struct lp_build_nir_context *bld_base,
156
unsigned nc, unsigned bit_size,
157
LLVMValueRef offset,
158
LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
159
void (*store_scratch)(struct lp_build_nir_context *bld_base,
160
unsigned writemask, unsigned nc,
161
unsigned bit_size, LLVMValueRef offset,
162
LLVMValueRef val);
163
164
void (*emit_var_decl)(struct lp_build_nir_context *bld_base,
165
nir_variable *var);
166
167
void (*tex)(struct lp_build_nir_context *bld_base,
168
struct lp_sampler_params *params);
169
170
void (*tex_size)(struct lp_build_nir_context *bld_base,
171
struct lp_sampler_size_query_params *params);
172
173
void (*sysval_intrin)(struct lp_build_nir_context *bld_base,
174
nir_intrinsic_instr *instr,
175
LLVMValueRef result[NIR_MAX_VEC_COMPONENTS]);
176
void (*discard)(struct lp_build_nir_context *bld_base,
177
LLVMValueRef cond);
178
179
void (*bgnloop)(struct lp_build_nir_context *bld_base);
180
void (*endloop)(struct lp_build_nir_context *bld_base);
181
void (*if_cond)(struct lp_build_nir_context *bld_base, LLVMValueRef cond);
182
void (*else_stmt)(struct lp_build_nir_context *bld_base);
183
void (*endif_stmt)(struct lp_build_nir_context *bld_base);
184
void (*break_stmt)(struct lp_build_nir_context *bld_base);
185
void (*continue_stmt)(struct lp_build_nir_context *bld_base);
186
187
void (*emit_vertex)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
188
void (*end_primitive)(struct lp_build_nir_context *bld_base, uint32_t stream_id);
189
190
void (*vote)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
191
void (*elect)(struct lp_build_nir_context *bld_base, LLVMValueRef dst[4]);
192
void (*reduce)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
193
void (*ballot)(struct lp_build_nir_context *bld_base, LLVMValueRef src, nir_intrinsic_instr *instr, LLVMValueRef dst[4]);
194
void (*read_invocation)(struct lp_build_nir_context *bld_base,
195
LLVMValueRef src, unsigned bit_size, LLVMValueRef invoc,
196
LLVMValueRef dst[4]);
197
void (*helper_invocation)(struct lp_build_nir_context *bld_base, LLVMValueRef *dst);
198
199
void (*interp_at)(struct lp_build_nir_context *bld_base,
200
unsigned num_components,
201
nir_variable *var,
202
bool centroid, bool sample,
203
unsigned const_index,
204
LLVMValueRef indir_index,
205
LLVMValueRef offsets[2], LLVMValueRef dst[4]);
206
// LLVMValueRef main_function
207
};
208
209
struct lp_build_nir_soa_context
210
{
211
struct lp_build_nir_context bld_base;
212
213
/* Builder for scalar elements of shader's data type (float) */
214
struct lp_build_context elem_bld;
215
struct lp_build_context uint_elem_bld;
216
217
LLVMValueRef consts_ptr;
218
LLVMValueRef const_sizes_ptr;
219
LLVMValueRef consts[LP_MAX_TGSI_CONST_BUFFERS];
220
LLVMValueRef consts_sizes[LP_MAX_TGSI_CONST_BUFFERS];
221
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
222
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
223
LLVMValueRef context_ptr;
224
LLVMValueRef thread_data_ptr;
225
226
LLVMValueRef ssbo_ptr;
227
LLVMValueRef ssbo_sizes_ptr;
228
LLVMValueRef ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
229
LLVMValueRef ssbo_sizes[LP_MAX_TGSI_SHADER_BUFFERS];
230
231
LLVMValueRef shared_ptr;
232
LLVMValueRef scratch_ptr;
233
unsigned scratch_size;
234
235
const struct lp_build_coro_suspend_info *coro;
236
237
const struct lp_build_sampler_soa *sampler;
238
const struct lp_build_image_soa *image;
239
240
const struct lp_build_gs_iface *gs_iface;
241
const struct lp_build_tcs_iface *tcs_iface;
242
const struct lp_build_tes_iface *tes_iface;
243
const struct lp_build_fs_iface *fs_iface;
244
LLVMValueRef emitted_prims_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
245
LLVMValueRef total_emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
246
LLVMValueRef emitted_vertices_vec_ptr[PIPE_MAX_VERTEX_STREAMS];
247
LLVMValueRef max_output_vertices_vec;
248
struct lp_bld_tgsi_system_values system_values;
249
250
nir_variable_mode indirects;
251
struct lp_build_mask_context *mask;
252
struct lp_exec_mask exec_mask;
253
254
/* We allocate/use this array of inputs if (indirects & nir_var_shader_in) is
255
* set. The inputs[] array above is unused then.
256
*/
257
LLVMValueRef inputs_array;
258
259
LLVMValueRef kernel_args_ptr;
260
unsigned gs_vertex_streams;
261
};
262
263
bool
264
lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
265
struct nir_shader *nir);
266
267
void lp_build_opt_nir(struct nir_shader *nir);
268
269
static inline LLVMValueRef
270
lp_nir_array_build_gather_values(LLVMBuilderRef builder,
271
LLVMValueRef * values,
272
unsigned value_count)
273
{
274
LLVMTypeRef arr_type = LLVMArrayType(LLVMTypeOf(values[0]), value_count);
275
LLVMValueRef arr = LLVMGetUndef(arr_type);
276
unsigned i;
277
278
for (i = 0; i < value_count; i++) {
279
arr = LLVMBuildInsertValue(builder, arr, values[i], i, "");
280
}
281
return arr;
282
}
283
284
static inline struct lp_build_context *get_flt_bld(struct lp_build_nir_context *bld_base,
285
unsigned op_bit_size)
286
{
287
switch (op_bit_size) {
288
case 64:
289
return &bld_base->dbl_bld;
290
default:
291
case 32:
292
return &bld_base->base;
293
}
294
}
295
296
static inline struct lp_build_context *get_int_bld(struct lp_build_nir_context *bld_base,
297
bool is_unsigned,
298
unsigned op_bit_size)
299
{
300
if (is_unsigned) {
301
switch (op_bit_size) {
302
case 64:
303
return &bld_base->uint64_bld;
304
case 32:
305
default:
306
return &bld_base->uint_bld;
307
case 16:
308
return &bld_base->uint16_bld;
309
case 8:
310
return &bld_base->uint8_bld;
311
}
312
} else {
313
switch (op_bit_size) {
314
case 64:
315
return &bld_base->int64_bld;
316
default:
317
case 32:
318
return &bld_base->int_bld;
319
case 16:
320
return &bld_base->int16_bld;
321
case 8:
322
return &bld_base->int8_bld;
323
}
324
}
325
}
326
327
#endif
328
329