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
,
187 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
188 LLVMValueRef
ac_get_i1_sgpr_mask(struct ac_llvm_context
*ctx
,
191 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
193 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
195 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
198 ac_build_varying_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
199 unsigned value_count
, unsigned component
);
202 ac_build_gather_values_extended(struct ac_llvm_context
*ctx
,
203 LLVMValueRef
*values
,
204 unsigned value_count
,
205 unsigned value_stride
,
209 ac_build_gather_values(struct ac_llvm_context
*ctx
,
210 LLVMValueRef
*values
,
211 unsigned value_count
);
214 ac_extract_components(struct ac_llvm_context
*ctx
,
219 LLVMValueRef
ac_build_expand_to_vec4(struct ac_llvm_context
*ctx
,
221 unsigned num_channels
);
222 LLVMValueRef
ac_build_round(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
225 ac_build_fdiv(struct ac_llvm_context
*ctx
,
229 LLVMValueRef
ac_build_fast_udiv(struct ac_llvm_context
*ctx
,
231 LLVMValueRef multiplier
,
232 LLVMValueRef pre_shift
,
233 LLVMValueRef post_shift
,
234 LLVMValueRef increment
);
235 LLVMValueRef
ac_build_fast_udiv_nuw(struct ac_llvm_context
*ctx
,
237 LLVMValueRef multiplier
,
238 LLVMValueRef pre_shift
,
239 LLVMValueRef post_shift
,
240 LLVMValueRef increment
);
241 LLVMValueRef
ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context
*ctx
,
243 LLVMValueRef multiplier
,
244 LLVMValueRef post_shift
);
247 ac_prepare_cube_coords(struct ac_llvm_context
*ctx
,
248 bool is_deriv
, bool is_array
, bool is_lod
,
249 LLVMValueRef
*coords_arg
,
250 LLVMValueRef
*derivs_arg
);
254 ac_build_fs_interp(struct ac_llvm_context
*ctx
,
255 LLVMValueRef llvm_chan
,
256 LLVMValueRef attr_number
,
262 ac_build_fs_interp_f16(struct ac_llvm_context
*ctx
,
263 LLVMValueRef llvm_chan
,
264 LLVMValueRef attr_number
,
270 ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
,
271 LLVMValueRef parameter
,
272 LLVMValueRef llvm_chan
,
273 LLVMValueRef attr_number
,
274 LLVMValueRef params
);
277 ac_build_gep_ptr(struct ac_llvm_context
*ctx
,
278 LLVMValueRef base_ptr
,
282 ac_build_gep0(struct ac_llvm_context
*ctx
,
283 LLVMValueRef base_ptr
,
285 LLVMValueRef
ac_build_pointer_add(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
289 ac_build_indexed_store(struct ac_llvm_context
*ctx
,
290 LLVMValueRef base_ptr
, LLVMValueRef index
,
293 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
295 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
,
296 LLVMValueRef base_ptr
, LLVMValueRef index
);
297 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
,
298 LLVMValueRef base_ptr
, LLVMValueRef index
);
299 LLVMValueRef
ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context
*ctx
,
300 LLVMValueRef base_ptr
, LLVMValueRef index
);
303 ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
,
306 unsigned num_channels
,
307 LLVMValueRef voffset
,
308 LLVMValueRef soffset
,
309 unsigned inst_offset
,
310 unsigned cache_policy
);
313 ac_build_buffer_store_format(struct ac_llvm_context
*ctx
,
317 LLVMValueRef voffset
,
318 unsigned num_channels
,
319 unsigned cache_policy
);
322 ac_build_buffer_load(struct ac_llvm_context
*ctx
,
326 LLVMValueRef voffset
,
327 LLVMValueRef soffset
,
328 unsigned inst_offset
,
329 unsigned cache_policy
,
333 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
,
336 LLVMValueRef voffset
,
337 unsigned num_channels
,
338 unsigned cache_policy
,
342 ac_build_tbuffer_load_short(struct ac_llvm_context
*ctx
,
344 LLVMValueRef voffset
,
345 LLVMValueRef soffset
,
346 LLVMValueRef immoffset
,
347 unsigned cache_policy
);
350 ac_build_tbuffer_load_byte(struct ac_llvm_context
*ctx
,
352 LLVMValueRef voffset
,
353 LLVMValueRef soffset
,
354 LLVMValueRef immoffset
,
355 unsigned cache_policy
);
358 ac_build_struct_tbuffer_load(struct ac_llvm_context
*ctx
,
361 LLVMValueRef voffset
,
362 LLVMValueRef soffset
,
363 LLVMValueRef immoffset
,
364 unsigned num_channels
,
367 unsigned cache_policy
,
371 ac_build_raw_tbuffer_load(struct ac_llvm_context
*ctx
,
373 LLVMValueRef voffset
,
374 LLVMValueRef soffset
,
375 LLVMValueRef immoffset
,
376 unsigned num_channels
,
379 unsigned cache_policy
,
382 /* For ac_build_fetch_format.
384 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
387 AC_FETCH_FORMAT_FLOAT
= 0,
388 AC_FETCH_FORMAT_FIXED
,
389 AC_FETCH_FORMAT_UNORM
,
390 AC_FETCH_FORMAT_SNORM
,
391 AC_FETCH_FORMAT_USCALED
,
392 AC_FETCH_FORMAT_SSCALED
,
393 AC_FETCH_FORMAT_UINT
,
394 AC_FETCH_FORMAT_SINT
,
398 ac_build_opencoded_load_format(struct ac_llvm_context
*ctx
,
400 unsigned num_channels
,
406 LLVMValueRef voffset
,
407 LLVMValueRef soffset
,
408 unsigned cache_policy
,
412 ac_build_tbuffer_store_short(struct ac_llvm_context
*ctx
,
415 LLVMValueRef voffset
,
416 LLVMValueRef soffset
,
417 unsigned cache_policy
);
420 ac_build_tbuffer_store_byte(struct ac_llvm_context
*ctx
,
423 LLVMValueRef voffset
,
424 LLVMValueRef soffset
,
425 unsigned cache_policy
);
428 ac_build_struct_tbuffer_store(struct ac_llvm_context
*ctx
,
432 LLVMValueRef voffset
,
433 LLVMValueRef soffset
,
434 LLVMValueRef immoffset
,
435 unsigned num_channels
,
438 unsigned cache_policy
);
441 ac_build_raw_tbuffer_store(struct ac_llvm_context
*ctx
,
444 LLVMValueRef voffset
,
445 LLVMValueRef soffset
,
446 LLVMValueRef immoffset
,
447 unsigned num_channels
,
450 unsigned cache_policy
);
453 ac_get_thread_id(struct ac_llvm_context
*ctx
);
455 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
456 #define AC_TID_MASK_TOP 0xfffffffd
457 #define AC_TID_MASK_LEFT 0xfffffffe
460 ac_build_ddxy(struct ac_llvm_context
*ctx
,
465 #define AC_SENDMSG_GS 2
466 #define AC_SENDMSG_GS_DONE 3
467 #define AC_SENDMSG_GS_ALLOC_REQ 9
469 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
470 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
471 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
472 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
474 void ac_build_sendmsg(struct ac_llvm_context
*ctx
,
476 LLVMValueRef wave_id
);
478 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
,
480 LLVMTypeRef dst_type
);
482 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
,
484 LLVMTypeRef dst_type
);
485 LLVMValueRef
ac_build_fmin(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
487 LLVMValueRef
ac_build_fmax(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
489 LLVMValueRef
ac_build_imin(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
491 LLVMValueRef
ac_build_imax(struct ac_llvm_context
*ctx
, LLVMValueRef a
,
493 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
494 LLVMValueRef
ac_build_umax(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
495 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
497 struct ac_export_args
{
500 unsigned enabled_channels
;
506 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
508 void ac_build_export_null(struct ac_llvm_context
*ctx
);
510 enum ac_image_opcode
{
518 ac_image_get_resinfo
,
520 ac_image_atomic_cmpswap
,
538 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
539 enum ac_image_cache_policy
{
540 ac_glc
= 1 << 0, /* per-CU cache control */
541 ac_slc
= 1 << 1, /* global L2 cache control */
542 ac_dlc
= 1 << 2, /* per-shader-array cache control */
543 ac_swizzled
= 1 << 3, /* the access is swizzled, disabling load/store merging */
546 struct ac_image_args
{
547 enum ac_image_opcode opcode
: 4;
548 enum ac_atomic_op atomic
: 4; /* for the ac_image_atomic opcode */
549 enum ac_image_dim dim
: 3;
551 unsigned cache_policy
: 3;
554 unsigned attributes
; /* additional call-site specific AC_FUNC_ATTRs */
556 LLVMValueRef resource
;
557 LLVMValueRef sampler
;
558 LLVMValueRef data
[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
561 LLVMValueRef compare
;
562 LLVMValueRef derivs
[6];
563 LLVMValueRef coords
[4];
564 LLVMValueRef lod
; // also used by ac_image_get_resinfo
565 LLVMValueRef min_lod
;
568 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
,
569 struct ac_image_args
*a
);
570 LLVMValueRef
ac_build_image_get_sample_count(struct ac_llvm_context
*ctx
,
572 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
,
573 LLVMValueRef args
[2]);
574 LLVMValueRef
ac_build_cvt_pknorm_i16(struct ac_llvm_context
*ctx
,
575 LLVMValueRef args
[2]);
576 LLVMValueRef
ac_build_cvt_pknorm_u16(struct ac_llvm_context
*ctx
,
577 LLVMValueRef args
[2]);
578 LLVMValueRef
ac_build_cvt_pk_i16(struct ac_llvm_context
*ctx
,
579 LLVMValueRef args
[2], unsigned bits
, bool hi
);
580 LLVMValueRef
ac_build_cvt_pk_u16(struct ac_llvm_context
*ctx
,
581 LLVMValueRef args
[2], unsigned bits
, bool hi
);
582 LLVMValueRef
ac_build_wqm_vote(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
583 void ac_build_kill_if_false(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
584 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
,
585 LLVMValueRef offset
, LLVMValueRef width
,
587 LLVMValueRef
ac_build_imad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
,
588 LLVMValueRef s1
, LLVMValueRef s2
);
589 LLVMValueRef
ac_build_fmad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
,
590 LLVMValueRef s1
, LLVMValueRef s2
);
592 void ac_build_waitcnt(struct ac_llvm_context
*ctx
, unsigned wait_flags
);
594 LLVMValueRef
ac_build_fract(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
597 LLVMValueRef
ac_build_fmed3(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
598 LLVMValueRef src1
, LLVMValueRef src2
,
601 LLVMValueRef
ac_build_isign(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
604 LLVMValueRef
ac_build_fsign(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
607 LLVMValueRef
ac_build_bit_count(struct ac_llvm_context
*ctx
, LLVMValueRef src0
);
609 LLVMValueRef
ac_build_bitfield_reverse(struct ac_llvm_context
*ctx
,
612 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
,
613 LLVMValueRef main_fn
,
614 uint8_t *vs_output_param_offset
,
615 uint32_t num_outputs
,
616 uint32_t skip_output_mask
,
617 uint8_t *num_param_exports
);
618 void ac_init_exec_full_mask(struct ac_llvm_context
*ctx
);
620 void ac_declare_lds_as_pointer(struct ac_llvm_context
*ac
);
621 LLVMValueRef
ac_lds_load(struct ac_llvm_context
*ctx
,
622 LLVMValueRef dw_addr
);
623 void ac_lds_store(struct ac_llvm_context
*ctx
,
624 LLVMValueRef dw_addr
, LLVMValueRef value
);
626 LLVMValueRef
ac_find_lsb(struct ac_llvm_context
*ctx
,
627 LLVMTypeRef dst_type
,
630 LLVMTypeRef
ac_array_in_const_addr_space(LLVMTypeRef elem_type
);
631 LLVMTypeRef
ac_array_in_const32_addr_space(LLVMTypeRef elem_type
);
633 void ac_build_bgnloop(struct ac_llvm_context
*ctx
, int lable_id
);
634 void ac_build_break(struct ac_llvm_context
*ctx
);
635 void ac_build_continue(struct ac_llvm_context
*ctx
);
636 void ac_build_else(struct ac_llvm_context
*ctx
, int lable_id
);
637 void ac_build_endif(struct ac_llvm_context
*ctx
, int lable_id
);
638 void ac_build_endloop(struct ac_llvm_context
*ctx
, int lable_id
);
639 void ac_build_ifcc(struct ac_llvm_context
*ctx
, LLVMValueRef cond
, int label_id
);
640 void ac_build_if(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
642 void ac_build_uif(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
645 LLVMValueRef
ac_build_alloca(struct ac_llvm_context
*ac
, LLVMTypeRef type
,
647 LLVMValueRef
ac_build_alloca_undef(struct ac_llvm_context
*ac
, LLVMTypeRef type
,
650 LLVMValueRef
ac_cast_ptr(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
653 LLVMValueRef
ac_trim_vector(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
656 LLVMValueRef
ac_unpack_param(struct ac_llvm_context
*ctx
, LLVMValueRef param
,
657 unsigned rshift
, unsigned bitwidth
);
659 void ac_apply_fmask_to_sample(struct ac_llvm_context
*ac
, LLVMValueRef fmask
,
660 LLVMValueRef
*addr
, bool is_array_tex
);
663 ac_build_ds_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, unsigned mask
);
665 LLVMValueRef
ac_build_readlane_no_opt_barrier(struct ac_llvm_context
*ctx
,
666 LLVMValueRef src
, LLVMValueRef lane
);
669 ac_build_readlane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef lane
);
672 ac_build_writelane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef value
, LLVMValueRef lane
);
675 ac_build_mbcnt(struct ac_llvm_context
*ctx
, LLVMValueRef mask
);
678 ac_build_inclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
681 ac_build_exclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
684 ac_build_reduce(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
, unsigned cluster_size
);
687 * Common arguments for a scan/reduce operation that accumulates per-wave
688 * values across an entire workgroup, while respecting the order of waves.
692 bool enable_exclusive
;
693 bool enable_inclusive
;
695 LLVMValueRef src
; /* clobbered! */
696 LLVMValueRef result_reduce
;
697 LLVMValueRef result_exclusive
;
698 LLVMValueRef result_inclusive
;
700 LLVMValueRef waveidx
;
701 LLVMValueRef numwaves
; /* only needed for "reduce" operations */
703 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
704 LLVMValueRef scratch
;
709 ac_build_wg_wavescan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
711 ac_build_wg_wavescan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
713 ac_build_wg_wavescan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
716 ac_build_wg_scan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
718 ac_build_wg_scan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
720 ac_build_wg_scan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
723 ac_build_quad_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
,
724 unsigned lane0
, unsigned lane1
, unsigned lane2
, unsigned lane3
);
727 ac_build_shuffle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef index
);
730 ac_build_frexp_exp(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
734 ac_build_frexp_mant(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
738 ac_build_canonicalize(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
742 ac_build_ddxy_interp(struct ac_llvm_context
*ctx
, LLVMValueRef interp_ij
);
745 ac_build_load_helper_invocation(struct ac_llvm_context
*ctx
);
748 ac_build_is_helper_invocation(struct ac_llvm_context
*ctx
);
750 LLVMValueRef
ac_build_call(struct ac_llvm_context
*ctx
, LLVMValueRef func
,
751 LLVMValueRef
*args
, unsigned num_args
);
753 LLVMValueRef
ac_build_atomic_rmw(struct ac_llvm_context
*ctx
, LLVMAtomicRMWBinOp op
,
754 LLVMValueRef ptr
, LLVMValueRef val
,
755 const char *sync_scope
);
757 LLVMValueRef
ac_build_atomic_cmp_xchg(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
758 LLVMValueRef cmp
, LLVMValueRef val
,
759 const char *sync_scope
);
762 ac_export_mrt_z(struct ac_llvm_context
*ctx
, LLVMValueRef depth
,
763 LLVMValueRef stencil
, LLVMValueRef samplemask
,
764 struct ac_export_args
*args
);
766 void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context
*ctx
, LLVMValueRef wave_id
,
767 LLVMValueRef vtx_cnt
, LLVMValueRef prim_cnt
);
770 unsigned num_vertices
;
772 LLVMValueRef index
[3];
773 LLVMValueRef edgeflag
[3];
774 LLVMValueRef passthrough
;
777 LLVMValueRef
ac_pack_prim_export(struct ac_llvm_context
*ctx
,
778 const struct ac_ngg_prim
*prim
);
779 void ac_build_export_prim(struct ac_llvm_context
*ctx
,
780 const struct ac_ngg_prim
*prim
);
782 static inline LLVMValueRef
783 ac_get_arg(struct ac_llvm_context
*ctx
, struct ac_arg arg
)
786 return LLVMGetParam(ctx
->main_function
, arg
.arg_index
);
789 enum ac_llvm_calling_convention
{
790 AC_LLVM_AMDGPU_VS
= 87,
791 AC_LLVM_AMDGPU_GS
= 88,
792 AC_LLVM_AMDGPU_PS
= 89,
793 AC_LLVM_AMDGPU_CS
= 90,
794 AC_LLVM_AMDGPU_HS
= 93,
797 LLVMValueRef
ac_build_main(const struct ac_shader_args
*args
,
798 struct ac_llvm_context
*ctx
,
799 enum ac_llvm_calling_convention convention
,
800 const char *name
, LLVMTypeRef ret_type
,
801 LLVMModuleRef module
);
802 void ac_build_s_endpgm(struct ac_llvm_context
*ctx
);
804 LLVMValueRef
ac_prefix_bitcount(struct ac_llvm_context
*ctx
,
805 LLVMValueRef mask
, LLVMValueRef index
);
806 LLVMValueRef
ac_prefix_bitcount_2x64(struct ac_llvm_context
*ctx
,
807 LLVMValueRef mask
[2], LLVMValueRef index
);
808 void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context
*ctx
,
810 LLVMValueRef flatshade_first
,
811 LLVMValueRef index
[3]);