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
28 #include "ac_shader_abi.h"
29 #include "ac_shader_args.h"
30 #include "ac_shader_util.h"
31 #include "amd_family.h"
32 #include "compiler/nir/nir.h"
33 #include <llvm-c/Core.h>
43 AC_ADDR_SPACE_FLAT
= 0, /* Slower than global. */
44 AC_ADDR_SPACE_GLOBAL
= 1,
45 AC_ADDR_SPACE_GDS
= 2,
46 AC_ADDR_SPACE_LDS
= 3,
47 AC_ADDR_SPACE_CONST
= 4, /* Global allowing SMEM. */
48 AC_ADDR_SPACE_CONST_32BIT
= 6, /* same as CONST, but the pointer type has 32 bits */
51 #define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */
52 #define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */
53 #define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */
56 struct ac_llvm_compiler
;
59 struct ac_llvm_flow_state
{
60 struct ac_llvm_flow
*stack
;
65 struct ac_llvm_context
{
66 LLVMContextRef context
;
68 LLVMBuilderRef builder
;
70 LLVMValueRef main_function
;
94 LLVMTypeRef iN_wavemask
;
95 LLVMTypeRef iN_ballotmask
;
114 LLVMValueRef i1false
;
116 /* Temporary helper to implement demote_to_helper:
118 * False = demoted lanes
120 LLVMValueRef postponed_kill
;
122 /* Since ac_nir_translate makes a local copy of ac_llvm_context, there
123 * are two ac_llvm_contexts. Declare a pointer here, so that the control
124 * flow stack is shared by both ac_llvm_contexts.
126 struct ac_llvm_flow_state
*flow
;
128 unsigned range_md_kind
;
129 unsigned invariant_load_md_kind
;
130 unsigned uniform_md_kind
;
131 LLVMValueRef empty_md
;
133 enum chip_class chip_class
;
134 enum radeon_family family
;
137 unsigned ballot_mask_bits
;
144 void ac_llvm_context_init(struct ac_llvm_context
*ctx
, struct ac_llvm_compiler
*compiler
,
145 enum chip_class chip_class
, enum radeon_family family
,
146 enum ac_float_mode float_mode
, unsigned wave_size
,
147 unsigned ballot_mask_bits
);
149 void ac_llvm_context_dispose(struct ac_llvm_context
*ctx
);
151 int ac_get_llvm_num_components(LLVMValueRef value
);
153 int ac_get_elem_bits(struct ac_llvm_context
*ctx
, LLVMTypeRef type
);
155 LLVMValueRef
ac_llvm_extract_elem(struct ac_llvm_context
*ac
, LLVMValueRef value
, int index
);
157 unsigned ac_get_type_size(LLVMTypeRef type
);
159 LLVMTypeRef
ac_to_integer_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
160 LLVMValueRef
ac_to_integer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
161 LLVMValueRef
ac_to_integer_or_pointer(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
162 LLVMTypeRef
ac_to_float_type(struct ac_llvm_context
*ctx
, LLVMTypeRef t
);
163 LLVMValueRef
ac_to_float(struct ac_llvm_context
*ctx
, LLVMValueRef v
);
165 LLVMValueRef
ac_build_intrinsic(struct ac_llvm_context
*ctx
, const char *name
,
166 LLVMTypeRef return_type
, LLVMValueRef
*params
, unsigned param_count
,
167 unsigned attrib_mask
);
169 void ac_build_type_name_for_intr(LLVMTypeRef type
, char *buf
, unsigned bufsize
);
171 LLVMValueRef
ac_build_phi(struct ac_llvm_context
*ctx
, LLVMTypeRef type
, unsigned count_incoming
,
172 LLVMValueRef
*values
, LLVMBasicBlockRef
*blocks
);
174 void ac_build_s_barrier(struct ac_llvm_context
*ctx
);
175 void ac_build_optimization_barrier(struct ac_llvm_context
*ctx
, LLVMValueRef
*pvgpr
);
177 LLVMValueRef
ac_build_shader_clock(struct ac_llvm_context
*ctx
, nir_scope scope
);
179 LLVMValueRef
ac_build_ballot(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
180 LLVMValueRef
ac_get_i1_sgpr_mask(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
182 LLVMValueRef
ac_build_vote_all(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
184 LLVMValueRef
ac_build_vote_any(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
186 LLVMValueRef
ac_build_vote_eq(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
188 LLVMValueRef
ac_build_varying_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
189 unsigned value_count
, unsigned component
);
191 LLVMValueRef
ac_build_gather_values_extended(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
192 unsigned value_count
, unsigned value_stride
, bool load
,
194 LLVMValueRef
ac_build_gather_values(struct ac_llvm_context
*ctx
, LLVMValueRef
*values
,
195 unsigned value_count
);
197 LLVMValueRef
ac_extract_components(struct ac_llvm_context
*ctx
, LLVMValueRef value
, unsigned start
,
200 LLVMValueRef
ac_build_expand_to_vec4(struct ac_llvm_context
*ctx
, LLVMValueRef value
,
201 unsigned num_channels
);
202 LLVMValueRef
ac_build_round(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
204 LLVMValueRef
ac_build_fdiv(struct ac_llvm_context
*ctx
, LLVMValueRef num
, LLVMValueRef den
);
206 LLVMValueRef
ac_build_fast_udiv(struct ac_llvm_context
*ctx
, LLVMValueRef num
,
207 LLVMValueRef multiplier
, LLVMValueRef pre_shift
,
208 LLVMValueRef post_shift
, LLVMValueRef increment
);
209 LLVMValueRef
ac_build_fast_udiv_nuw(struct ac_llvm_context
*ctx
, LLVMValueRef num
,
210 LLVMValueRef multiplier
, LLVMValueRef pre_shift
,
211 LLVMValueRef post_shift
, LLVMValueRef increment
);
212 LLVMValueRef
ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context
*ctx
, LLVMValueRef num
,
213 LLVMValueRef multiplier
, LLVMValueRef post_shift
);
215 void ac_prepare_cube_coords(struct ac_llvm_context
*ctx
, bool is_deriv
, bool is_array
, bool is_lod
,
216 LLVMValueRef
*coords_arg
, LLVMValueRef
*derivs_arg
);
218 LLVMValueRef
ac_build_fs_interp(struct ac_llvm_context
*ctx
, LLVMValueRef llvm_chan
,
219 LLVMValueRef attr_number
, LLVMValueRef params
, LLVMValueRef i
,
222 LLVMValueRef
ac_build_fs_interp_f16(struct ac_llvm_context
*ctx
, LLVMValueRef llvm_chan
,
223 LLVMValueRef attr_number
, LLVMValueRef params
, LLVMValueRef i
,
226 LLVMValueRef
ac_build_fs_interp_mov(struct ac_llvm_context
*ctx
, LLVMValueRef parameter
,
227 LLVMValueRef llvm_chan
, LLVMValueRef attr_number
,
228 LLVMValueRef params
);
230 LLVMValueRef
ac_build_gep_ptr(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
233 LLVMValueRef
ac_build_gep0(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
, LLVMValueRef index
);
234 LLVMValueRef
ac_build_pointer_add(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
237 void ac_build_indexed_store(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
, LLVMValueRef index
,
240 LLVMValueRef
ac_build_load(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
, LLVMValueRef index
);
241 LLVMValueRef
ac_build_load_invariant(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
243 LLVMValueRef
ac_build_load_to_sgpr(struct ac_llvm_context
*ctx
, LLVMValueRef base_ptr
,
245 LLVMValueRef
ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context
*ctx
,
246 LLVMValueRef base_ptr
, LLVMValueRef index
);
248 void ac_build_buffer_store_dword(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
, LLVMValueRef vdata
,
249 unsigned num_channels
, LLVMValueRef voffset
, LLVMValueRef soffset
,
250 unsigned inst_offset
, unsigned cache_policy
);
252 void ac_build_buffer_store_format(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
, LLVMValueRef data
,
253 LLVMValueRef vindex
, LLVMValueRef voffset
, unsigned cache_policy
);
255 LLVMValueRef
ac_build_buffer_load(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
, int num_channels
,
256 LLVMValueRef vindex
, LLVMValueRef voffset
, LLVMValueRef soffset
,
257 unsigned inst_offset
, unsigned cache_policy
, bool can_speculate
,
260 LLVMValueRef
ac_build_buffer_load_format(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
261 LLVMValueRef vindex
, LLVMValueRef voffset
,
262 unsigned num_channels
, unsigned cache_policy
,
263 bool can_speculate
, bool d16
);
265 LLVMValueRef
ac_build_tbuffer_load_short(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
266 LLVMValueRef voffset
, LLVMValueRef soffset
,
267 LLVMValueRef immoffset
, unsigned cache_policy
);
269 LLVMValueRef
ac_build_tbuffer_load_byte(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
270 LLVMValueRef voffset
, LLVMValueRef soffset
,
271 LLVMValueRef immoffset
, unsigned cache_policy
);
273 LLVMValueRef
ac_build_struct_tbuffer_load(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
274 LLVMValueRef vindex
, LLVMValueRef voffset
,
275 LLVMValueRef soffset
, LLVMValueRef immoffset
,
276 unsigned num_channels
, unsigned dfmt
, unsigned nfmt
,
277 unsigned cache_policy
, bool can_speculate
);
279 LLVMValueRef
ac_build_raw_tbuffer_load(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
280 LLVMValueRef voffset
, LLVMValueRef soffset
,
281 LLVMValueRef immoffset
, unsigned num_channels
, unsigned dfmt
,
282 unsigned nfmt
, unsigned cache_policy
, bool can_speculate
);
284 /* For ac_build_fetch_format.
286 * Note: FLOAT must be 0 (used for convenience of encoding in radeonsi).
290 AC_FETCH_FORMAT_FLOAT
= 0,
291 AC_FETCH_FORMAT_FIXED
,
292 AC_FETCH_FORMAT_UNORM
,
293 AC_FETCH_FORMAT_SNORM
,
294 AC_FETCH_FORMAT_USCALED
,
295 AC_FETCH_FORMAT_SSCALED
,
296 AC_FETCH_FORMAT_UINT
,
297 AC_FETCH_FORMAT_SINT
,
300 LLVMValueRef
ac_build_opencoded_load_format(struct ac_llvm_context
*ctx
, unsigned log_size
,
301 unsigned num_channels
, unsigned format
, bool reverse
,
302 bool known_aligned
, LLVMValueRef rsrc
,
303 LLVMValueRef vindex
, LLVMValueRef voffset
,
304 LLVMValueRef soffset
, unsigned cache_policy
,
307 void ac_build_tbuffer_store_short(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
308 LLVMValueRef vdata
, LLVMValueRef voffset
, LLVMValueRef soffset
,
309 unsigned cache_policy
);
311 void ac_build_tbuffer_store_byte(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
, LLVMValueRef vdata
,
312 LLVMValueRef voffset
, LLVMValueRef soffset
, unsigned cache_policy
);
314 void ac_build_struct_tbuffer_store(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
,
315 LLVMValueRef vdata
, LLVMValueRef vindex
, LLVMValueRef voffset
,
316 LLVMValueRef soffset
, LLVMValueRef immoffset
,
317 unsigned num_channels
, unsigned dfmt
, unsigned nfmt
,
318 unsigned cache_policy
);
320 void ac_build_raw_tbuffer_store(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
, LLVMValueRef vdata
,
321 LLVMValueRef voffset
, LLVMValueRef soffset
, LLVMValueRef immoffset
,
322 unsigned num_channels
, unsigned dfmt
, unsigned nfmt
,
323 unsigned cache_policy
);
325 LLVMValueRef
ac_get_thread_id(struct ac_llvm_context
*ctx
);
327 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
328 #define AC_TID_MASK_TOP 0xfffffffd
329 #define AC_TID_MASK_LEFT 0xfffffffe
331 LLVMValueRef
ac_build_ddxy(struct ac_llvm_context
*ctx
, uint32_t mask
, int idx
, LLVMValueRef val
);
333 #define AC_SENDMSG_GS 2
334 #define AC_SENDMSG_GS_DONE 3
335 #define AC_SENDMSG_GS_ALLOC_REQ 9
337 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
338 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
339 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
340 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
342 void ac_build_sendmsg(struct ac_llvm_context
*ctx
, uint32_t msg
, LLVMValueRef wave_id
);
344 LLVMValueRef
ac_build_imsb(struct ac_llvm_context
*ctx
, LLVMValueRef arg
, LLVMTypeRef dst_type
);
346 LLVMValueRef
ac_build_umsb(struct ac_llvm_context
*ctx
, LLVMValueRef arg
, LLVMTypeRef dst_type
);
347 LLVMValueRef
ac_build_fmin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
348 LLVMValueRef
ac_build_fmax(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
349 LLVMValueRef
ac_build_imin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
350 LLVMValueRef
ac_build_imax(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
351 LLVMValueRef
ac_build_umin(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
352 LLVMValueRef
ac_build_umax(struct ac_llvm_context
*ctx
, LLVMValueRef a
, LLVMValueRef b
);
353 LLVMValueRef
ac_build_clamp(struct ac_llvm_context
*ctx
, LLVMValueRef value
);
355 struct ac_export_args
{
358 unsigned enabled_channels
;
364 void ac_build_export(struct ac_llvm_context
*ctx
, struct ac_export_args
*a
);
366 void ac_build_export_null(struct ac_llvm_context
*ctx
);
377 ac_image_get_resinfo
,
379 ac_image_atomic_cmpswap
,
398 /* These cache policy bits match the definitions used by the LLVM intrinsics. */
399 enum ac_image_cache_policy
401 ac_glc
= 1 << 0, /* per-CU cache control */
402 ac_slc
= 1 << 1, /* global L2 cache control */
403 ac_dlc
= 1 << 2, /* per-shader-array cache control */
404 ac_swizzled
= 1 << 3, /* the access is swizzled, disabling load/store merging */
407 struct ac_image_args
{
408 enum ac_image_opcode opcode
: 4;
409 enum ac_atomic_op atomic
: 4; /* for the ac_image_atomic opcode */
410 enum ac_image_dim dim
: 3;
412 unsigned cache_policy
: 3;
415 bool d16
: 1; /* data and return values are 16-bit, requires GFX8+ */
416 unsigned attributes
; /* additional call-site specific AC_FUNC_ATTRs */
418 LLVMValueRef resource
;
419 LLVMValueRef sampler
;
420 LLVMValueRef data
[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */
423 LLVMValueRef compare
;
424 LLVMValueRef derivs
[6];
425 LLVMValueRef coords
[4];
426 LLVMValueRef lod
; // also used by ac_image_get_resinfo
427 LLVMValueRef min_lod
;
430 LLVMValueRef
ac_build_image_opcode(struct ac_llvm_context
*ctx
, struct ac_image_args
*a
);
431 LLVMValueRef
ac_build_image_get_sample_count(struct ac_llvm_context
*ctx
, LLVMValueRef rsrc
);
432 LLVMValueRef
ac_build_cvt_pkrtz_f16(struct ac_llvm_context
*ctx
, LLVMValueRef args
[2]);
433 LLVMValueRef
ac_build_cvt_pknorm_i16(struct ac_llvm_context
*ctx
, LLVMValueRef args
[2]);
434 LLVMValueRef
ac_build_cvt_pknorm_u16(struct ac_llvm_context
*ctx
, LLVMValueRef args
[2]);
435 LLVMValueRef
ac_build_cvt_pk_i16(struct ac_llvm_context
*ctx
, LLVMValueRef args
[2], unsigned bits
,
437 LLVMValueRef
ac_build_cvt_pk_u16(struct ac_llvm_context
*ctx
, LLVMValueRef args
[2], unsigned bits
,
439 LLVMValueRef
ac_build_wqm_vote(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
440 void ac_build_kill_if_false(struct ac_llvm_context
*ctx
, LLVMValueRef i1
);
441 LLVMValueRef
ac_build_bfe(struct ac_llvm_context
*ctx
, LLVMValueRef input
, LLVMValueRef offset
,
442 LLVMValueRef width
, bool is_signed
);
443 LLVMValueRef
ac_build_imad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
, LLVMValueRef s1
,
445 LLVMValueRef
ac_build_fmad(struct ac_llvm_context
*ctx
, LLVMValueRef s0
, LLVMValueRef s1
,
448 void ac_build_waitcnt(struct ac_llvm_context
*ctx
, unsigned wait_flags
);
450 LLVMValueRef
ac_build_fract(struct ac_llvm_context
*ctx
, LLVMValueRef src0
, unsigned bitsize
);
451 LLVMValueRef
ac_const_uint_vec(struct ac_llvm_context
*ctx
, LLVMTypeRef type
, uint64_t value
);
452 LLVMValueRef
ac_build_isign(struct ac_llvm_context
*ctx
, LLVMValueRef src0
);
453 LLVMValueRef
ac_build_fsign(struct ac_llvm_context
*ctx
, LLVMValueRef src
);
454 LLVMValueRef
ac_build_bit_count(struct ac_llvm_context
*ctx
, LLVMValueRef src0
);
456 LLVMValueRef
ac_build_bitfield_reverse(struct ac_llvm_context
*ctx
, LLVMValueRef src0
);
458 void ac_optimize_vs_outputs(struct ac_llvm_context
*ac
, LLVMValueRef main_fn
,
459 uint8_t *vs_output_param_offset
, uint32_t num_outputs
,
460 uint32_t skip_output_mask
, uint8_t *num_param_exports
);
461 void ac_init_exec_full_mask(struct ac_llvm_context
*ctx
);
463 void ac_declare_lds_as_pointer(struct ac_llvm_context
*ac
);
464 LLVMValueRef
ac_lds_load(struct ac_llvm_context
*ctx
, LLVMValueRef dw_addr
);
465 void ac_lds_store(struct ac_llvm_context
*ctx
, LLVMValueRef dw_addr
, LLVMValueRef value
);
467 LLVMValueRef
ac_find_lsb(struct ac_llvm_context
*ctx
, LLVMTypeRef dst_type
, LLVMValueRef src0
);
469 LLVMTypeRef
ac_array_in_const_addr_space(LLVMTypeRef elem_type
);
470 LLVMTypeRef
ac_array_in_const32_addr_space(LLVMTypeRef elem_type
);
472 void ac_build_bgnloop(struct ac_llvm_context
*ctx
, int lable_id
);
473 void ac_build_break(struct ac_llvm_context
*ctx
);
474 void ac_build_continue(struct ac_llvm_context
*ctx
);
475 void ac_build_else(struct ac_llvm_context
*ctx
, int lable_id
);
476 void ac_build_endif(struct ac_llvm_context
*ctx
, int lable_id
);
477 void ac_build_endloop(struct ac_llvm_context
*ctx
, int lable_id
);
478 void ac_build_ifcc(struct ac_llvm_context
*ctx
, LLVMValueRef cond
, int label_id
);
479 void ac_build_if(struct ac_llvm_context
*ctx
, LLVMValueRef value
, int lable_id
);
480 void ac_build_uif(struct ac_llvm_context
*ctx
, LLVMValueRef value
, int lable_id
);
482 LLVMValueRef
ac_build_alloca(struct ac_llvm_context
*ac
, LLVMTypeRef type
, const char *name
);
483 LLVMValueRef
ac_build_alloca_undef(struct ac_llvm_context
*ac
, LLVMTypeRef type
, const char *name
);
485 LLVMValueRef
ac_cast_ptr(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
, LLVMTypeRef type
);
487 LLVMValueRef
ac_trim_vector(struct ac_llvm_context
*ctx
, LLVMValueRef value
, unsigned count
);
489 LLVMValueRef
ac_unpack_param(struct ac_llvm_context
*ctx
, LLVMValueRef param
, unsigned rshift
,
492 void ac_apply_fmask_to_sample(struct ac_llvm_context
*ac
, LLVMValueRef fmask
, LLVMValueRef
*addr
,
495 LLVMValueRef
ac_build_ds_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, unsigned mask
);
497 LLVMValueRef
ac_build_readlane_no_opt_barrier(struct ac_llvm_context
*ctx
, LLVMValueRef src
,
500 LLVMValueRef
ac_build_readlane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef lane
);
502 LLVMValueRef
ac_build_writelane(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef value
,
505 LLVMValueRef
ac_build_mbcnt(struct ac_llvm_context
*ctx
, LLVMValueRef mask
);
507 LLVMValueRef
ac_build_inclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
509 LLVMValueRef
ac_build_exclusive_scan(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
);
511 LLVMValueRef
ac_build_reduce(struct ac_llvm_context
*ctx
, LLVMValueRef src
, nir_op op
,
512 unsigned cluster_size
);
515 * Common arguments for a scan/reduce operation that accumulates per-wave
516 * values across an entire workgroup, while respecting the order of waves.
520 bool enable_exclusive
;
521 bool enable_inclusive
;
523 LLVMValueRef src
; /* clobbered! */
524 LLVMValueRef result_reduce
;
525 LLVMValueRef result_exclusive
;
526 LLVMValueRef result_inclusive
;
528 LLVMValueRef waveidx
;
529 LLVMValueRef numwaves
; /* only needed for "reduce" operations */
531 /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */
532 LLVMValueRef scratch
;
536 void ac_build_wg_wavescan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
537 void ac_build_wg_wavescan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
538 void ac_build_wg_wavescan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
540 void ac_build_wg_scan_top(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
541 void ac_build_wg_scan_bottom(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
542 void ac_build_wg_scan(struct ac_llvm_context
*ctx
, struct ac_wg_scan
*ws
);
544 LLVMValueRef
ac_build_quad_swizzle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, unsigned lane0
,
545 unsigned lane1
, unsigned lane2
, unsigned lane3
);
547 LLVMValueRef
ac_build_shuffle(struct ac_llvm_context
*ctx
, LLVMValueRef src
, LLVMValueRef index
);
549 LLVMValueRef
ac_build_frexp_exp(struct ac_llvm_context
*ctx
, LLVMValueRef src0
, unsigned bitsize
);
551 LLVMValueRef
ac_build_frexp_mant(struct ac_llvm_context
*ctx
, LLVMValueRef src0
, unsigned bitsize
);
553 LLVMValueRef
ac_build_canonicalize(struct ac_llvm_context
*ctx
, LLVMValueRef src0
,
556 LLVMValueRef
ac_build_ddxy_interp(struct ac_llvm_context
*ctx
, LLVMValueRef interp_ij
);
558 LLVMValueRef
ac_build_load_helper_invocation(struct ac_llvm_context
*ctx
);
560 LLVMValueRef
ac_build_is_helper_invocation(struct ac_llvm_context
*ctx
);
562 LLVMValueRef
ac_build_call(struct ac_llvm_context
*ctx
, LLVMValueRef func
, LLVMValueRef
*args
,
565 LLVMValueRef
ac_build_atomic_rmw(struct ac_llvm_context
*ctx
, LLVMAtomicRMWBinOp op
,
566 LLVMValueRef ptr
, LLVMValueRef val
, const char *sync_scope
);
568 LLVMValueRef
ac_build_atomic_cmp_xchg(struct ac_llvm_context
*ctx
, LLVMValueRef ptr
,
569 LLVMValueRef cmp
, LLVMValueRef val
, const char *sync_scope
);
571 void ac_export_mrt_z(struct ac_llvm_context
*ctx
, LLVMValueRef depth
, LLVMValueRef stencil
,
572 LLVMValueRef samplemask
, struct ac_export_args
*args
);
574 void ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context
*ctx
, LLVMValueRef wave_id
,
575 LLVMValueRef vtx_cnt
, LLVMValueRef prim_cnt
);
578 unsigned num_vertices
;
580 LLVMValueRef index
[3];
581 LLVMValueRef edgeflag
[3];
582 LLVMValueRef passthrough
;
585 LLVMValueRef
ac_pack_prim_export(struct ac_llvm_context
*ctx
, const struct ac_ngg_prim
*prim
);
586 void ac_build_export_prim(struct ac_llvm_context
*ctx
, const struct ac_ngg_prim
*prim
);
588 static inline LLVMValueRef
ac_get_arg(struct ac_llvm_context
*ctx
, struct ac_arg arg
)
591 return LLVMGetParam(ctx
->main_function
, arg
.arg_index
);
594 enum ac_llvm_calling_convention
596 AC_LLVM_AMDGPU_VS
= 87,
597 AC_LLVM_AMDGPU_GS
= 88,
598 AC_LLVM_AMDGPU_PS
= 89,
599 AC_LLVM_AMDGPU_CS
= 90,
600 AC_LLVM_AMDGPU_HS
= 93,
603 LLVMValueRef
ac_build_main(const struct ac_shader_args
*args
, struct ac_llvm_context
*ctx
,
604 enum ac_llvm_calling_convention convention
, const char *name
,
605 LLVMTypeRef ret_type
, LLVMModuleRef module
);
606 void ac_build_s_endpgm(struct ac_llvm_context
*ctx
);
608 LLVMValueRef
ac_prefix_bitcount(struct ac_llvm_context
*ctx
, LLVMValueRef mask
, LLVMValueRef index
);
609 LLVMValueRef
ac_prefix_bitcount_2x64(struct ac_llvm_context
*ctx
, LLVMValueRef mask
[2],
611 void ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context
*ctx
, LLVMValueRef is_odd
,
612 LLVMValueRef flatshade_first
,
613 LLVMValueRef index
[3]);