amd/common/gfx10: add GS_ALLOC_REQ message define
[mesa.git] / src / amd / common / ac_llvm_build.h
1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
27
28 #include <stdbool.h>
29 #include <llvm-c/Core.h>
30 #include "compiler/nir/nir.h"
31 #include "amd_family.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 enum {
38 AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */
39 AC_ADDR_SPACE_GLOBAL = 1,
40 AC_ADDR_SPACE_GDS = 2,
41 AC_ADDR_SPACE_LDS = 3,
42 AC_ADDR_SPACE_CONST = 4, /* Global allowing SMEM. */
43 AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */
44 };
45
46 /* Combine these with & instead of |. */
47 #define NOOP_WAITCNT 0xcf7f
48 #define LGKM_CNT 0xc07f
49 #define EXP_CNT 0xcf0f
50 #define VM_CNT 0x0f70 /* On GFX9, vmcnt has 6 bits in [0:3] and [14:15] */
51
52 struct ac_llvm_flow;
53
54 struct ac_llvm_context {
55 LLVMContextRef context;
56 LLVMModuleRef module;
57 LLVMBuilderRef builder;
58
59 LLVMTypeRef voidt;
60 LLVMTypeRef i1;
61 LLVMTypeRef i8;
62 LLVMTypeRef i16;
63 LLVMTypeRef i32;
64 LLVMTypeRef i64;
65 LLVMTypeRef intptr;
66 LLVMTypeRef f16;
67 LLVMTypeRef f32;
68 LLVMTypeRef f64;
69 LLVMTypeRef v2i16;
70 LLVMTypeRef v2i32;
71 LLVMTypeRef v3i32;
72 LLVMTypeRef v4i32;
73 LLVMTypeRef v2f32;
74 LLVMTypeRef v3f32;
75 LLVMTypeRef v4f32;
76 LLVMTypeRef v8i32;
77
78 LLVMValueRef i8_0;
79 LLVMValueRef i8_1;
80 LLVMValueRef i16_0;
81 LLVMValueRef i16_1;
82 LLVMValueRef i32_0;
83 LLVMValueRef i32_1;
84 LLVMValueRef i64_0;
85 LLVMValueRef i64_1;
86 LLVMValueRef f16_0;
87 LLVMValueRef f16_1;
88 LLVMValueRef f32_0;
89 LLVMValueRef f32_1;
90 LLVMValueRef f64_0;
91 LLVMValueRef f64_1;
92 LLVMValueRef i1true;
93 LLVMValueRef i1false;
94
95 struct ac_llvm_flow *flow;
96 unsigned flow_depth;
97 unsigned flow_depth_max;
98
99 unsigned range_md_kind;
100 unsigned invariant_load_md_kind;
101 unsigned uniform_md_kind;
102 unsigned fpmath_md_kind;
103 LLVMValueRef fpmath_md_2p5_ulp;
104 LLVMValueRef empty_md;
105
106 enum chip_class chip_class;
107 enum radeon_family family;
108
109 LLVMValueRef lds;
110 };
111
112 void
113 ac_llvm_context_init(struct ac_llvm_context *ctx,
114 enum chip_class chip_class, enum radeon_family family);
115
116 void
117 ac_llvm_context_dispose(struct ac_llvm_context *ctx);
118
119 int
120 ac_get_llvm_num_components(LLVMValueRef value);
121
122 int
123 ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type);
124
125 LLVMValueRef
126 ac_llvm_extract_elem(struct ac_llvm_context *ac,
127 LLVMValueRef value,
128 int index);
129
130 unsigned ac_get_type_size(LLVMTypeRef type);
131
132 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
133 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
134 LLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v);
135 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
136 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
137
138 LLVMValueRef
139 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
140 LLVMTypeRef return_type, LLVMValueRef *params,
141 unsigned param_count, unsigned attrib_mask);
142
143 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
144
145 LLVMValueRef
146 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
147 unsigned count_incoming, LLVMValueRef *values,
148 LLVMBasicBlockRef *blocks);
149
150 void ac_build_s_barrier(struct ac_llvm_context *ctx);
151 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
152 LLVMValueRef *pvgpr);
153
154 LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx);
155
156 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
157 LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx,
158 LLVMValueRef value);
159
160 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
161
162 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
163
164 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
165
166 LLVMValueRef
167 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
168 unsigned value_count, unsigned component);
169
170 LLVMValueRef
171 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
172 LLVMValueRef *values,
173 unsigned value_count,
174 unsigned value_stride,
175 bool load,
176 bool always_vector);
177 LLVMValueRef
178 ac_build_gather_values(struct ac_llvm_context *ctx,
179 LLVMValueRef *values,
180 unsigned value_count);
181 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
182 LLVMValueRef value,
183 unsigned num_channels);
184 LLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value);
185
186 LLVMValueRef
187 ac_build_fdiv(struct ac_llvm_context *ctx,
188 LLVMValueRef num,
189 LLVMValueRef den);
190
191 LLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx,
192 LLVMValueRef num,
193 LLVMValueRef multiplier,
194 LLVMValueRef pre_shift,
195 LLVMValueRef post_shift,
196 LLVMValueRef increment);
197 LLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx,
198 LLVMValueRef num,
199 LLVMValueRef multiplier,
200 LLVMValueRef pre_shift,
201 LLVMValueRef post_shift,
202 LLVMValueRef increment);
203 LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx,
204 LLVMValueRef num,
205 LLVMValueRef multiplier,
206 LLVMValueRef post_shift);
207
208 void
209 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
210 bool is_deriv, bool is_array, bool is_lod,
211 LLVMValueRef *coords_arg,
212 LLVMValueRef *derivs_arg);
213
214
215 LLVMValueRef
216 ac_build_fs_interp(struct ac_llvm_context *ctx,
217 LLVMValueRef llvm_chan,
218 LLVMValueRef attr_number,
219 LLVMValueRef params,
220 LLVMValueRef i,
221 LLVMValueRef j);
222
223 LLVMValueRef
224 ac_build_fs_interp_f16(struct ac_llvm_context *ctx,
225 LLVMValueRef llvm_chan,
226 LLVMValueRef attr_number,
227 LLVMValueRef params,
228 LLVMValueRef i,
229 LLVMValueRef j);
230
231 LLVMValueRef
232 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
233 LLVMValueRef parameter,
234 LLVMValueRef llvm_chan,
235 LLVMValueRef attr_number,
236 LLVMValueRef params);
237
238 LLVMValueRef
239 ac_build_gep_ptr(struct ac_llvm_context *ctx,
240 LLVMValueRef base_ptr,
241 LLVMValueRef index);
242
243 LLVMValueRef
244 ac_build_gep0(struct ac_llvm_context *ctx,
245 LLVMValueRef base_ptr,
246 LLVMValueRef index);
247 LLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr,
248 LLVMValueRef index);
249
250 void
251 ac_build_indexed_store(struct ac_llvm_context *ctx,
252 LLVMValueRef base_ptr, LLVMValueRef index,
253 LLVMValueRef value);
254
255 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
256 LLVMValueRef index);
257 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
258 LLVMValueRef base_ptr, LLVMValueRef index);
259 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
260 LLVMValueRef base_ptr, LLVMValueRef index);
261 LLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx,
262 LLVMValueRef base_ptr, LLVMValueRef index);
263
264 void
265 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
266 LLVMValueRef rsrc,
267 LLVMValueRef vdata,
268 unsigned num_channels,
269 LLVMValueRef voffset,
270 LLVMValueRef soffset,
271 unsigned inst_offset,
272 bool glc,
273 bool slc,
274 bool swizzle_enable_hint);
275
276 void
277 ac_build_buffer_store_format(struct ac_llvm_context *ctx,
278 LLVMValueRef rsrc,
279 LLVMValueRef data,
280 LLVMValueRef vindex,
281 LLVMValueRef voffset,
282 unsigned num_channels,
283 bool glc,
284 bool slc);
285
286 LLVMValueRef
287 ac_build_buffer_load(struct ac_llvm_context *ctx,
288 LLVMValueRef rsrc,
289 int num_channels,
290 LLVMValueRef vindex,
291 LLVMValueRef voffset,
292 LLVMValueRef soffset,
293 unsigned inst_offset,
294 unsigned glc,
295 unsigned slc,
296 bool can_speculate,
297 bool allow_smem);
298
299 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
300 LLVMValueRef rsrc,
301 LLVMValueRef vindex,
302 LLVMValueRef voffset,
303 unsigned num_channels,
304 bool glc,
305 bool can_speculate);
306
307 /* load_format that handles the stride & element count better if idxen is
308 * disabled by LLVM. */
309 LLVMValueRef ac_build_buffer_load_format_gfx9_safe(struct ac_llvm_context *ctx,
310 LLVMValueRef rsrc,
311 LLVMValueRef vindex,
312 LLVMValueRef voffset,
313 unsigned num_channels,
314 bool glc,
315 bool can_speculate);
316
317 LLVMValueRef
318 ac_build_tbuffer_load_short(struct ac_llvm_context *ctx,
319 LLVMValueRef rsrc,
320 LLVMValueRef voffset,
321 LLVMValueRef soffset,
322 LLVMValueRef immoffset,
323 bool glc);
324
325 LLVMValueRef
326 ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx,
327 LLVMValueRef rsrc,
328 LLVMValueRef voffset,
329 LLVMValueRef soffset,
330 LLVMValueRef immoffset,
331 bool glc);
332
333 LLVMValueRef
334 ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx,
335 LLVMValueRef rsrc,
336 LLVMValueRef vindex,
337 LLVMValueRef voffset,
338 LLVMValueRef soffset,
339 LLVMValueRef immoffset,
340 unsigned num_channels,
341 unsigned dfmt,
342 unsigned nfmt,
343 bool glc,
344 bool slc,
345 bool can_speculate);
346
347 LLVMValueRef
348 ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx,
349 LLVMValueRef rsrc,
350 LLVMValueRef voffset,
351 LLVMValueRef soffset,
352 LLVMValueRef immoffset,
353 unsigned num_channels,
354 unsigned dfmt,
355 unsigned nfmt,
356 bool glc,
357 bool slc,
358 bool can_speculate);
359
360 /* For ac_build_fetch_format.
361 *
362 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
363 */
364 enum {
365 AC_FETCH_FORMAT_FLOAT = 0,
366 AC_FETCH_FORMAT_FIXED,
367 AC_FETCH_FORMAT_UNORM,
368 AC_FETCH_FORMAT_SNORM,
369 AC_FETCH_FORMAT_USCALED,
370 AC_FETCH_FORMAT_SSCALED,
371 AC_FETCH_FORMAT_UINT,
372 AC_FETCH_FORMAT_SINT,
373 };
374
375 LLVMValueRef
376 ac_build_opencoded_load_format(struct ac_llvm_context *ctx,
377 unsigned log_size,
378 unsigned num_channels,
379 unsigned format,
380 bool reverse,
381 bool known_aligned,
382 LLVMValueRef rsrc,
383 LLVMValueRef vindex,
384 LLVMValueRef voffset,
385 LLVMValueRef soffset,
386 bool glc,
387 bool slc,
388 bool can_speculate);
389
390 void
391 ac_build_tbuffer_store_short(struct ac_llvm_context *ctx,
392 LLVMValueRef rsrc,
393 LLVMValueRef vdata,
394 LLVMValueRef voffset,
395 LLVMValueRef soffset,
396 bool glc);
397
398 void
399 ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx,
400 LLVMValueRef rsrc,
401 LLVMValueRef vdata,
402 LLVMValueRef voffset,
403 LLVMValueRef soffset,
404 bool glc);
405
406 void
407 ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx,
408 LLVMValueRef rsrc,
409 LLVMValueRef vdata,
410 LLVMValueRef vindex,
411 LLVMValueRef voffset,
412 LLVMValueRef soffset,
413 LLVMValueRef immoffset,
414 unsigned num_channels,
415 unsigned dfmt,
416 unsigned nfmt,
417 bool glc,
418 bool slc);
419
420 void
421 ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx,
422 LLVMValueRef rsrc,
423 LLVMValueRef vdata,
424 LLVMValueRef voffset,
425 LLVMValueRef soffset,
426 LLVMValueRef immoffset,
427 unsigned num_channels,
428 unsigned dfmt,
429 unsigned nfmt,
430 bool glc,
431 bool slc);
432
433 LLVMValueRef
434 ac_get_thread_id(struct ac_llvm_context *ctx);
435
436 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
437 #define AC_TID_MASK_TOP 0xfffffffd
438 #define AC_TID_MASK_LEFT 0xfffffffe
439
440 LLVMValueRef
441 ac_build_ddxy(struct ac_llvm_context *ctx,
442 uint32_t mask,
443 int idx,
444 LLVMValueRef val);
445
446 #define AC_SENDMSG_GS 2
447 #define AC_SENDMSG_GS_DONE 3
448 #define AC_SENDMSG_GS_ALLOC_REQ 9
449
450 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
451 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
452 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
453 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
454
455 void ac_build_sendmsg(struct ac_llvm_context *ctx,
456 uint32_t msg,
457 LLVMValueRef wave_id);
458
459 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
460 LLVMValueRef arg,
461 LLVMTypeRef dst_type);
462
463 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
464 LLVMValueRef arg,
465 LLVMTypeRef dst_type);
466 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
467 LLVMValueRef b);
468 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
469 LLVMValueRef b);
470 LLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a,
471 LLVMValueRef b);
472 LLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a,
473 LLVMValueRef b);
474 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
475 LLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
476 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
477
478 struct ac_export_args {
479 LLVMValueRef out[4];
480 unsigned target;
481 unsigned enabled_channels;
482 bool compr;
483 bool done;
484 bool valid_mask;
485 };
486
487 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
488
489 void ac_build_export_null(struct ac_llvm_context *ctx);
490
491 enum ac_image_opcode {
492 ac_image_sample,
493 ac_image_gather4,
494 ac_image_load,
495 ac_image_load_mip,
496 ac_image_store,
497 ac_image_store_mip,
498 ac_image_get_lod,
499 ac_image_get_resinfo,
500 ac_image_atomic,
501 ac_image_atomic_cmpswap,
502 };
503
504 enum ac_atomic_op {
505 ac_atomic_swap,
506 ac_atomic_add,
507 ac_atomic_sub,
508 ac_atomic_smin,
509 ac_atomic_umin,
510 ac_atomic_smax,
511 ac_atomic_umax,
512 ac_atomic_and,
513 ac_atomic_or,
514 ac_atomic_xor,
515 };
516
517 enum ac_image_dim {
518 ac_image_1d,
519 ac_image_2d,
520 ac_image_3d,
521 ac_image_cube, // includes cube arrays
522 ac_image_1darray,
523 ac_image_2darray,
524 ac_image_2dmsaa,
525 ac_image_2darraymsaa,
526 };
527
528 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
529 enum ac_image_cache_policy {
530 ac_glc = 1 << 0,
531 ac_slc = 1 << 1,
532 };
533
534 struct ac_image_args {
535 enum ac_image_opcode opcode : 4;
536 enum ac_atomic_op atomic : 4; /* for the ac_image_atomic opcode */
537 enum ac_image_dim dim : 3;
538 unsigned dmask : 4;
539 unsigned cache_policy : 2;
540 bool unorm : 1;
541 bool level_zero : 1;
542 unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */
543
544 LLVMValueRef resource;
545 LLVMValueRef sampler;
546 LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
547 LLVMValueRef offset;
548 LLVMValueRef bias;
549 LLVMValueRef compare;
550 LLVMValueRef derivs[6];
551 LLVMValueRef coords[4];
552 LLVMValueRef lod; // also used by ac_image_get_resinfo
553 };
554
555 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
556 struct ac_image_args *a);
557 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
558 LLVMValueRef args[2]);
559 LLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx,
560 LLVMValueRef args[2]);
561 LLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx,
562 LLVMValueRef args[2]);
563 LLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx,
564 LLVMValueRef args[2], unsigned bits, bool hi);
565 LLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx,
566 LLVMValueRef args[2], unsigned bits, bool hi);
567 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
568 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
569 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
570 LLVMValueRef offset, LLVMValueRef width,
571 bool is_signed);
572 LLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0,
573 LLVMValueRef s1, LLVMValueRef s2);
574 LLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0,
575 LLVMValueRef s1, LLVMValueRef s2);
576
577 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
578
579 LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
580 unsigned bitsize);
581
582 LLVMValueRef ac_build_fmed3(struct ac_llvm_context *ctx, LLVMValueRef src0,
583 LLVMValueRef src1, LLVMValueRef src2,
584 unsigned bitsize);
585
586 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
587 unsigned bitsize);
588
589 LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
590 unsigned bitsize);
591
592 LLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0);
593
594 LLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx,
595 LLVMValueRef src0);
596
597 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
598 LLVMValueRef main_fn,
599 uint8_t *vs_output_param_offset,
600 uint32_t num_outputs,
601 uint8_t *num_param_exports);
602 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
603
604 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
605 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
606 LLVMValueRef dw_addr);
607 void ac_lds_store(struct ac_llvm_context *ctx,
608 LLVMValueRef dw_addr, LLVMValueRef value);
609
610 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
611 LLVMTypeRef dst_type,
612 LLVMValueRef src0);
613
614 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
615 LLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type);
616
617 void ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id);
618 void ac_build_break(struct ac_llvm_context *ctx);
619 void ac_build_continue(struct ac_llvm_context *ctx);
620 void ac_build_else(struct ac_llvm_context *ctx, int lable_id);
621 void ac_build_endif(struct ac_llvm_context *ctx, int lable_id);
622 void ac_build_endloop(struct ac_llvm_context *ctx, int lable_id);
623 void ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id);
624 void ac_build_if(struct ac_llvm_context *ctx, LLVMValueRef value,
625 int lable_id);
626 void ac_build_uif(struct ac_llvm_context *ctx, LLVMValueRef value,
627 int lable_id);
628
629 LLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type,
630 const char *name);
631 LLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type,
632 const char *name);
633
634 LLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr,
635 LLVMTypeRef type);
636
637 LLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value,
638 unsigned count);
639
640 LLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param,
641 unsigned rshift, unsigned bitwidth);
642
643 void ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask,
644 LLVMValueRef *addr, bool is_array_tex);
645
646 LLVMValueRef
647 ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask);
648
649 LLVMValueRef
650 ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane);
651
652 LLVMValueRef
653 ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, LLVMValueRef lane);
654
655 LLVMValueRef
656 ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask);
657
658 LLVMValueRef
659 ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
660
661 LLVMValueRef
662 ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op);
663
664 LLVMValueRef
665 ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, unsigned cluster_size);
666
667 /**
668 * Common arguments for a scan/reduce operation that accumulates per-wave
669 * values across an entire workgroup, while respecting the order of waves.
670 */
671 struct ac_wg_scan {
672 bool enable_reduce;
673 bool enable_exclusive;
674 bool enable_inclusive;
675 nir_op op;
676 LLVMValueRef src; /* clobbered! */
677 LLVMValueRef result_reduce;
678 LLVMValueRef result_exclusive;
679 LLVMValueRef result_inclusive;
680 LLVMValueRef extra;
681 LLVMValueRef waveidx;
682 LLVMValueRef numwaves; /* only needed for "reduce" operations */
683
684 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
685 LLVMValueRef scratch;
686 unsigned maxwaves;
687 };
688
689 void
690 ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
691 void
692 ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
693 void
694 ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
695
696 void
697 ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
698 void
699 ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
700 void
701 ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws);
702
703 LLVMValueRef
704 ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src,
705 unsigned lane0, unsigned lane1, unsigned lane2, unsigned lane3);
706
707 LLVMValueRef
708 ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index);
709
710 LLVMValueRef
711 ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0,
712 unsigned bitsize);
713
714 LLVMValueRef
715 ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0,
716 unsigned bitsize);
717
718 LLVMValueRef
719 ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij);
720
721 LLVMValueRef
722 ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
723
724 LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func,
725 LLVMValueRef *args, unsigned num_args);
726
727 LLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op,
728 LLVMValueRef ptr, LLVMValueRef val,
729 const char *sync_scope);
730
731 LLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr,
732 LLVMValueRef cmp, LLVMValueRef val,
733 const char *sync_scope);
734
735 #ifdef __cplusplus
736 }
737 #endif
738
739 #endif