2 * Copyright 2016 Bas Nieuwenhuizen
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:
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.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
29 #include <llvm-c/Core.h>
30 #include "compiler/nir/nir.h"
31 #include "amd_family.h"
32 #include "ac_shader_util.h"
33 #include "ac_shader_args.h"
34 #include "ac_shader_abi.h"
41 AC_ADDR_SPACE_FLAT
= 0, /* Slower than global. */
42 AC_ADDR_SPACE_GLOBAL
= 1,
43 AC_ADDR_SPACE_GDS
= 2,
44 AC_ADDR_SPACE_LDS
= 3,
45 AC_ADDR_SPACE_CONST
= 4, /* Global allowing SMEM. */
46 AC_ADDR_SPACE_CONST_32BIT
= 6, /* same as CONST, but the pointer type has 32 bits */
49 #define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */
50 #define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */
51 #define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */
54 struct ac_llvm_compiler
;
57 struct ac_llvm_flow_state
{
58 struct ac_llvm_flow
*stack
;
63 struct ac_llvm_context
{
64 LLVMContextRef context
;
66 LLVMBuilderRef builder
;
68 LLVMValueRef main_function
;
89 LLVMTypeRef iN_wavemask
;
90 LLVMTypeRef iN_ballotmask
;
109 LLVMValueRef i1false
;
111 /* Temporary helper to implement demote_to_helper:
113 * False = demoted lanes
115 LLVMValueRef postponed_kill
;
117 /* Since ac_nir_translate makes a local copy of ac_llvm_context, there
118 * are two ac_llvm_contexts. Declare a pointer here, so that the control
119 * flow stack is shared by both ac_llvm_contexts.
121 struct ac_llvm_flow_state
*flow
;
123 unsigned range_md_kind
;
124 unsigned invariant_load_md_kind
;
125 unsigned uniform_md_kind
;
126 LLVMValueRef empty_md
;
128 enum chip_class chip_class
;
129 enum radeon_family family
;
132 unsigned ballot_mask_bits
;
140 ac_llvm_context_init(struct ac_llvm_context
*ctx
,
141 struct ac_llvm_compiler
*compiler
,
142 enum chip_class chip_class
, enum radeon_family family
,
143 enum ac_float_mode float_mode
, unsigned wave_size
,
144 unsigned ballot_mask_bits
);
147 ac_llvm_context_dispose(struct ac_llvm_context
*ctx
);
150 ac_get_llvm_num_components(LLVMValueRef value
);
153 ac_get_elem_bits(struct ac_llvm_context
*ctx
, LLVMTypeRef type
);
156 ac_llvm_extract_elem(struct ac_llvm_context
*ac
,
160 unsigned ac_get_type_size(LLVMTypeRef type
);
162 LLVMTypeRef
ac_to_integer_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
163 LLVMValueRef
ac_to_integer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
164 LLVMValueRef
ac_to_integer_or_pointer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
165 LLVMTypeRef
ac_to_float_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
166 LLVMValueRef
ac_to_float(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
169 ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
170 LLVMTypeRef return_type
, LLVMValueRef
*params
,
171 unsigned param_count
, unsigned attrib_mask
);
173 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
176 ac_build_phi(struct ac_llvm_context
*ctx
, LLVMTypeRef type
,
177 unsigned count_incoming
, LLVMValueRef
*values
,
178 LLVMBasicBlockRef
*blocks
);
180 void ac_build_s_barrier(struct ac_llvm_context
*ctx
);
181 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
,
182 LLVMValueRef
*pvgpr
);
184 LLVMValueRef
ac_build_shader_clock(struct ac_llvm_context
*ctx
);
186 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
187 LLVMValueRef
ac_get_i1_sgpr_mask(struct ac_llvm_context
*ctx
,
190 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
192 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
194 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
197 ac_build_varying_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
198 unsigned value_count
, unsigned component
);
201 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
202 LLVMValueRef
*values
,
203 unsigned value_count
,
204 unsigned value_stride
,
208 ac_build_gather_values(struct ac_llvm_context
*ctx
,
209 LLVMValueRef
*values
,
210 unsigned value_count
);
213 ac_extract_components(struct ac_llvm_context
*ctx
,
218 LLVMValueRef
ac_build_expand_to_vec4(struct ac_llvm_context
*ctx
,
220 unsigned num_channels
);
221 LLVMValueRef
ac_build_round(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
224 ac_build_fdiv(struct ac_llvm_context
*ctx
,
228 LLVMValueRef
ac_build_fast_udiv(struct ac_llvm_context
*ctx
,
230 LLVMValueRef multiplier
,
231 LLVMValueRef pre_shift
,
232 LLVMValueRef post_shift
,
233 LLVMValueRef increment
);
234 LLVMValueRef
ac_build_fast_udiv_nuw(struct ac_llvm_context
*ctx
,
236 LLVMValueRef multiplier
,
237 LLVMValueRef pre_shift
,
238 LLVMValueRef post_shift
,
239 LLVMValueRef increment
);
240 LLVMValueRef
ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context
*ctx
,
242 LLVMValueRef multiplier
,
243 LLVMValueRef post_shift
);
246 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
247 bool is_deriv
, bool is_array
, bool is_lod
,
248 LLVMValueRef
*coords_arg
,
249 LLVMValueRef
*derivs_arg
);
253 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
254 LLVMValueRef llvm_chan
,
255 LLVMValueRef attr_number
,
261 ac_build_fs_interp_f16(struct ac_llvm_context
*ctx
,
262 LLVMValueRef llvm_chan
,
263 LLVMValueRef attr_number
,
269 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
270 LLVMValueRef parameter
,
271 LLVMValueRef llvm_chan
,
272 LLVMValueRef attr_number
,
273 LLVMValueRef params
);
276 ac_build_gep_ptr(struct ac_llvm_context
*ctx
,
277 LLVMValueRef base_ptr
,
281 ac_build_gep0(struct ac_llvm_context
*ctx
,
282 LLVMValueRef base_ptr
,
284 LLVMValueRef
ac_build_pointer_add(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
288 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
289 LLVMValueRef base_ptr
, LLVMValueRef index
,
292 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
294 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
,
295 LLVMValueRef base_ptr
, LLVMValueRef index
);
296 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
,
297 LLVMValueRef base_ptr
, LLVMValueRef index
);
298 LLVMValueRef
ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context
*ctx
,
299 LLVMValueRef base_ptr
, LLVMValueRef index
);
302 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
305 unsigned num_channels
,
306 LLVMValueRef voffset
,
307 LLVMValueRef soffset
,
308 unsigned inst_offset
,
309 unsigned cache_policy
);
312 ac_build_buffer_store_format(struct ac_llvm_context
*ctx
,
316 LLVMValueRef voffset
,
317 unsigned num_channels
,
318 unsigned cache_policy
);
321 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
325 LLVMValueRef voffset
,
326 LLVMValueRef soffset
,
327 unsigned inst_offset
,
328 unsigned cache_policy
,
332 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
335 LLVMValueRef voffset
,
336 unsigned num_channels
,
337 unsigned cache_policy
,
341 ac_build_tbuffer_load_short(struct ac_llvm_context
*ctx
,
343 LLVMValueRef voffset
,
344 LLVMValueRef soffset
,
345 LLVMValueRef immoffset
,
346 unsigned cache_policy
);
349 ac_build_tbuffer_load_byte(struct ac_llvm_context
*ctx
,
351 LLVMValueRef voffset
,
352 LLVMValueRef soffset
,
353 LLVMValueRef immoffset
,
354 unsigned cache_policy
);
357 ac_build_struct_tbuffer_load(struct ac_llvm_context
*ctx
,
360 LLVMValueRef voffset
,
361 LLVMValueRef soffset
,
362 LLVMValueRef immoffset
,
363 unsigned num_channels
,
366 unsigned cache_policy
,
370 ac_build_raw_tbuffer_load(struct ac_llvm_context
*ctx
,
372 LLVMValueRef voffset
,
373 LLVMValueRef soffset
,
374 LLVMValueRef immoffset
,
375 unsigned num_channels
,
378 unsigned cache_policy
,
381 /* For ac_build_fetch_format.
383 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
386 AC_FETCH_FORMAT_FLOAT
= 0,
387 AC_FETCH_FORMAT_FIXED
,
388 AC_FETCH_FORMAT_UNORM
,
389 AC_FETCH_FORMAT_SNORM
,
390 AC_FETCH_FORMAT_USCALED
,
391 AC_FETCH_FORMAT_SSCALED
,
392 AC_FETCH_FORMAT_UINT
,
393 AC_FETCH_FORMAT_SINT
,
397 ac_build_opencoded_load_format(struct ac_llvm_context
*ctx
,
399 unsigned num_channels
,
405 LLVMValueRef voffset
,
406 LLVMValueRef soffset
,
407 unsigned cache_policy
,
411 ac_build_tbuffer_store_short(struct ac_llvm_context
*ctx
,
414 LLVMValueRef voffset
,
415 LLVMValueRef soffset
,
416 unsigned cache_policy
);
419 ac_build_tbuffer_store_byte(struct ac_llvm_context
*ctx
,
422 LLVMValueRef voffset
,
423 LLVMValueRef soffset
,
424 unsigned cache_policy
);
427 ac_build_struct_tbuffer_store(struct ac_llvm_context
*ctx
,
431 LLVMValueRef voffset
,
432 LLVMValueRef soffset
,
433 LLVMValueRef immoffset
,
434 unsigned num_channels
,
437 unsigned cache_policy
);
440 ac_build_raw_tbuffer_store(struct ac_llvm_context
*ctx
,
443 LLVMValueRef voffset
,
444 LLVMValueRef soffset
,
445 LLVMValueRef immoffset
,
446 unsigned num_channels
,
449 unsigned cache_policy
);
452 ac_get_thread_id(struct ac_llvm_context
*ctx
);
454 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
455 #define AC_TID_MASK_TOP 0xfffffffd
456 #define AC_TID_MASK_LEFT 0xfffffffe
459 ac_build_ddxy(struct ac_llvm_context
*ctx
,
464 #define AC_SENDMSG_GS 2
465 #define AC_SENDMSG_GS_DONE 3
466 #define AC_SENDMSG_GS_ALLOC_REQ 9
468 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
469 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
470 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
471 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
473 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
475 LLVMValueRef wave_id
);
477 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
479 LLVMTypeRef dst_type
);
481 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
483 LLVMTypeRef dst_type
);
484 LLVMValueRef
ac_build_fmin(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
486 LLVMValueRef
ac_build_fmax(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
488 LLVMValueRef
ac_build_imin(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
490 LLVMValueRef
ac_build_imax(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
492 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
493 LLVMValueRef
ac_build_umax(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
494 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
496 struct ac_export_args
{
499 unsigned enabled_channels
;
505 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
507 void ac_build_export_null(struct ac_llvm_context
*ctx
);
509 enum ac_image_opcode
{
517 ac_image_get_resinfo
,
519 ac_image_atomic_cmpswap
,
537 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
538 enum ac_image_cache_policy
{
539 ac_glc
= 1 << 0, /* per-CU cache control */
540 ac_slc
= 1 << 1, /* global L2 cache control */
541 ac_dlc
= 1 << 2, /* per-shader-array cache control */
542 ac_swizzled
= 1 << 3, /* the access is swizzled, disabling load/store merging */
545 struct ac_image_args
{
546 enum ac_image_opcode opcode
: 4;
547 enum ac_atomic_op atomic
: 4; /* for the ac_image_atomic opcode */
548 enum ac_image_dim dim
: 3;
550 unsigned cache_policy
: 3;
553 unsigned attributes
; /* additional call-site specific AC_FUNC_ATTRs */
555 LLVMValueRef resource
;
556 LLVMValueRef sampler
;
557 LLVMValueRef data
[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
560 LLVMValueRef compare
;
561 LLVMValueRef derivs
[6];
562 LLVMValueRef coords
[4];
563 LLVMValueRef lod
; // also used by ac_image_get_resinfo
566 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
567 struct ac_image_args
*a
);
568 LLVMValueRef
ac_build_image_get_sample_count(struct ac_llvm_context
*ctx
,
570 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
571 LLVMValueRef args
[2]);
572 LLVMValueRef
ac_build_cvt_pknorm_i16(struct ac_llvm_context
*ctx
,
573 LLVMValueRef args
[2]);
574 LLVMValueRef
ac_build_cvt_pknorm_u16(struct ac_llvm_context
*ctx
,
575 LLVMValueRef args
[2]);
576 LLVMValueRef
ac_build_cvt_pk_i16(struct ac_llvm_context
*ctx
,
577 LLVMValueRef args
[2], unsigned bits
, bool hi
);
578 LLVMValueRef
ac_build_cvt_pk_u16(struct ac_llvm_context
*ctx
,
579 LLVMValueRef args
[2], unsigned bits
, bool hi
);
580 LLVMValueRef
ac_build_wqm_vote(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
581 void ac_build_kill_if_false(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
582 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
583 LLVMValueRef offset
, LLVMValueRef width
,
585 LLVMValueRef
ac_build_imad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
,
586 LLVMValueRef s1
, LLVMValueRef s2
);
587 LLVMValueRef
ac_build_fmad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
,
588 LLVMValueRef s1
, LLVMValueRef s2
);
590 void ac_build_waitcnt(struct ac_llvm_context
*ctx
, unsigned wait_flags
);
592 LLVMValueRef
ac_build_fract(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
595 LLVMValueRef
ac_build_fmed3(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
596 LLVMValueRef src1
, LLVMValueRef src2
,
599 LLVMValueRef
ac_build_isign(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
602 LLVMValueRef
ac_build_fsign(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
605 LLVMValueRef
ac_build_bit_count(struct ac_llvm_context
*ctx
, LLVMValueRef src0
);
607 LLVMValueRef
ac_build_bitfield_reverse(struct ac_llvm_context
*ctx
,
610 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
611 LLVMValueRef main_fn
,
612 uint8_t *vs_output_param_offset
,
613 uint32_t num_outputs
,
614 uint8_t *num_param_exports
);
615 void ac_init_exec_full_mask(struct ac_llvm_context
*ctx
);
617 void ac_declare_lds_as_pointer(struct ac_llvm_context
*ac
);
618 LLVMValueRef
ac_lds_load(struct ac_llvm_context
*ctx
,
619 LLVMValueRef dw_addr
);
620 void ac_lds_store(struct ac_llvm_context
*ctx
,
621 LLVMValueRef dw_addr
, LLVMValueRef value
);
623 LLVMValueRef
ac_find_lsb(struct ac_llvm_context
*ctx
,
624 LLVMTypeRef dst_type
,
627 LLVMTypeRef
ac_array_in_const_addr_space(LLVMTypeRef elem_type
);
628 LLVMTypeRef
ac_array_in_const32_addr_space(LLVMTypeRef elem_type
);
630 void ac_build_bgnloop(struct ac_llvm_context
*ctx
, int lable_id
);
631 void ac_build_break(struct ac_llvm_context
*ctx
);
632 void ac_build_continue(struct ac_llvm_context
*ctx
);
633 void ac_build_else(struct ac_llvm_context
*ctx
, int lable_id
);
634 void ac_build_endif(struct ac_llvm_context
*ctx
, int lable_id
);
635 void ac_build_endloop(struct ac_llvm_context
*ctx
, int lable_id
);
636 void ac_build_ifcc(struct ac_llvm_context
*ctx
, LLVMValueRef cond
, int label_id
);
637 void ac_build_if(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
639 void ac_build_uif(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
642 LLVMValueRef
ac_build_alloca(struct ac_llvm_context
*ac
, LLVMTypeRef type
,
644 LLVMValueRef
ac_build_alloca_undef(struct ac_llvm_context
*ac
, LLVMTypeRef type
,
647 LLVMValueRef
ac_cast_ptr(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
650 LLVMValueRef
ac_trim_vector(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
653 LLVMValueRef
ac_unpack_param(struct ac_llvm_context
*ctx
, LLVMValueRef param
,
654 unsigned rshift
, unsigned bitwidth
);
656 void ac_apply_fmask_to_sample(struct ac_llvm_context
*ac
, LLVMValueRef fmask
,
657 LLVMValueRef
*addr
, bool is_array_tex
);
660 ac_build_ds_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, unsigned mask
);
662 LLVMValueRef
ac_build_readlane_no_opt_barrier(struct ac_llvm_context
*ctx
,
663 LLVMValueRef src
, LLVMValueRef lane
);
666 ac_build_readlane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef lane
);
669 ac_build_writelane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef value
, LLVMValueRef lane
);
672 ac_build_mbcnt(struct ac_llvm_context
*ctx
, LLVMValueRef mask
);
675 ac_build_inclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
678 ac_build_exclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
681 ac_build_reduce(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
, unsigned cluster_size
);
684 * Common arguments for a scan/reduce operation that accumulates per-wave
685 * values across an entire workgroup, while respecting the order of waves.
689 bool enable_exclusive
;
690 bool enable_inclusive
;
692 LLVMValueRef src
; /* clobbered! */
693 LLVMValueRef result_reduce
;
694 LLVMValueRef result_exclusive
;
695 LLVMValueRef result_inclusive
;
697 LLVMValueRef waveidx
;
698 LLVMValueRef numwaves
; /* only needed for "reduce" operations */
700 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
701 LLVMValueRef scratch
;
706 ac_build_wg_wavescan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
708 ac_build_wg_wavescan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
710 ac_build_wg_wavescan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
713 ac_build_wg_scan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
715 ac_build_wg_scan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
717 ac_build_wg_scan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
720 ac_build_quad_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
,
721 unsigned lane0
, unsigned lane1
, unsigned lane2
, unsigned lane3
);
724 ac_build_shuffle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef index
);
727 ac_build_frexp_exp(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
731 ac_build_frexp_mant(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
735 ac_build_canonicalize(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
739 ac_build_ddxy_interp(struct ac_llvm_context
*ctx
, LLVMValueRef interp_ij
);
742 ac_build_load_helper_invocation(struct ac_llvm_context
*ctx
);
745 ac_build_is_helper_invocation(struct ac_llvm_context
*ctx
);
747 LLVMValueRef
ac_build_call(struct ac_llvm_context
*ctx
, LLVMValueRef func
,
748 LLVMValueRef
*args
, unsigned num_args
);
750 LLVMValueRef
ac_build_atomic_rmw(struct ac_llvm_context
*ctx
, LLVMAtomicRMWBinOp op
,
751 LLVMValueRef ptr
, LLVMValueRef val
,
752 const char *sync_scope
);
754 LLVMValueRef
ac_build_atomic_cmp_xchg(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
755 LLVMValueRef cmp
, LLVMValueRef val
,
756 const char *sync_scope
);
759 ac_export_mrt_z(struct ac_llvm_context
*ctx
, LLVMValueRef depth
,
760 LLVMValueRef stencil
, LLVMValueRef samplemask
,
761 struct ac_export_args
*args
);
763 void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context
*ctx
, LLVMValueRef wave_id
,
764 LLVMValueRef vtx_cnt
, LLVMValueRef prim_cnt
);
767 unsigned num_vertices
;
769 LLVMValueRef index
[3];
770 LLVMValueRef edgeflag
[3];
771 LLVMValueRef passthrough
;
774 LLVMValueRef
ac_pack_prim_export(struct ac_llvm_context
*ctx
,
775 const struct ac_ngg_prim
*prim
);
776 void ac_build_export_prim(struct ac_llvm_context
*ctx
,
777 const struct ac_ngg_prim
*prim
);
779 static inline LLVMValueRef
780 ac_get_arg(struct ac_llvm_context
*ctx
, struct ac_arg arg
)
783 return LLVMGetParam(ctx
->main_function
, arg
.arg_index
);
786 enum ac_llvm_calling_convention
{
787 AC_LLVM_AMDGPU_VS
= 87,
788 AC_LLVM_AMDGPU_GS
= 88,
789 AC_LLVM_AMDGPU_PS
= 89,
790 AC_LLVM_AMDGPU_CS
= 90,
791 AC_LLVM_AMDGPU_HS
= 93,
794 LLVMValueRef
ac_build_main(const struct ac_shader_args
*args
,
795 struct ac_llvm_context
*ctx
,
796 enum ac_llvm_calling_convention convention
,
797 const char *name
, LLVMTypeRef ret_type
,
798 LLVMModuleRef module
);
799 void ac_build_s_endpgm(struct ac_llvm_context
*ctx
);
801 LLVMValueRef
ac_prefix_bitcount(struct ac_llvm_context
*ctx
,
802 LLVMValueRef mask
, LLVMValueRef index
);
803 LLVMValueRef
ac_prefix_bitcount_2x64(struct ac_llvm_context
*ctx
,
804 LLVMValueRef mask
[2], LLVMValueRef index
);
805 void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context
*ctx
,
807 LLVMValueRef flatshade_first
,
808 LLVMValueRef index
[3]);