17ec681f3Smrg/* 27ec681f3Smrg * Copyright 2016 Bas Nieuwenhuizen 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the 67ec681f3Smrg * "Software"), to deal in the Software without restriction, including 77ec681f3Smrg * without limitation the rights to use, copy, modify, merge, publish, 87ec681f3Smrg * distribute, sub license, and/or sell copies of the Software, and to 97ec681f3Smrg * permit persons to whom the Software is furnished to do so, subject to 107ec681f3Smrg * the following conditions: 117ec681f3Smrg * 127ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 137ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 147ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 157ec681f3Smrg * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 167ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 177ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 187ec681f3Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 197ec681f3Smrg * 207ec681f3Smrg * The above copyright notice and this permission notice (including the 217ec681f3Smrg * next paragraph) shall be included in all copies or substantial portions 227ec681f3Smrg * of the Software. 237ec681f3Smrg * 247ec681f3Smrg */ 257ec681f3Smrg#ifndef AC_LLVM_BUILD_H 267ec681f3Smrg#define AC_LLVM_BUILD_H 277ec681f3Smrg 287ec681f3Smrg#include "ac_llvm_util.h" 297ec681f3Smrg#include "ac_shader_abi.h" 307ec681f3Smrg#include "ac_shader_args.h" 317ec681f3Smrg#include "ac_shader_util.h" 327ec681f3Smrg#include "amd_family.h" 337ec681f3Smrg#include "compiler/nir/nir.h" 347ec681f3Smrg#include <llvm-c/Core.h> 357ec681f3Smrg 367ec681f3Smrg#include <stdbool.h> 377ec681f3Smrg 387ec681f3Smrg#ifdef __cplusplus 397ec681f3Smrgextern "C" { 407ec681f3Smrg#endif 417ec681f3Smrg 427ec681f3Smrgenum 437ec681f3Smrg{ 447ec681f3Smrg AC_ADDR_SPACE_FLAT = 0, /* Slower than global. */ 457ec681f3Smrg AC_ADDR_SPACE_GLOBAL = 1, 467ec681f3Smrg AC_ADDR_SPACE_GDS = 2, 477ec681f3Smrg AC_ADDR_SPACE_LDS = 3, 487ec681f3Smrg AC_ADDR_SPACE_CONST = 4, /* Global allowing SMEM. */ 497ec681f3Smrg AC_ADDR_SPACE_CONST_32BIT = 6, /* same as CONST, but the pointer type has 32 bits */ 507ec681f3Smrg}; 517ec681f3Smrg 527ec681f3Smrg#define AC_WAIT_LGKM (1 << 0) /* LDS, GDS, constant, message */ 537ec681f3Smrg#define AC_WAIT_VLOAD (1 << 1) /* VMEM load/sample instructions */ 547ec681f3Smrg#define AC_WAIT_VSTORE (1 << 2) /* VMEM store instructions */ 557ec681f3Smrg 567ec681f3Smrgstruct ac_llvm_flow; 577ec681f3Smrgstruct ac_llvm_compiler; 587ec681f3Smrg 597ec681f3Smrgstruct ac_llvm_flow_state { 607ec681f3Smrg struct ac_llvm_flow *stack; 617ec681f3Smrg unsigned depth_max; 627ec681f3Smrg unsigned depth; 637ec681f3Smrg}; 647ec681f3Smrg 657ec681f3Smrgstruct ac_llvm_context { 667ec681f3Smrg LLVMContextRef context; 677ec681f3Smrg LLVMModuleRef module; 687ec681f3Smrg LLVMBuilderRef builder; 697ec681f3Smrg 707ec681f3Smrg LLVMValueRef main_function; 717ec681f3Smrg 727ec681f3Smrg LLVMTypeRef voidt; 737ec681f3Smrg LLVMTypeRef i1; 747ec681f3Smrg LLVMTypeRef i8; 757ec681f3Smrg LLVMTypeRef i16; 767ec681f3Smrg LLVMTypeRef i32; 777ec681f3Smrg LLVMTypeRef i64; 787ec681f3Smrg LLVMTypeRef i128; 797ec681f3Smrg LLVMTypeRef intptr; 807ec681f3Smrg LLVMTypeRef f16; 817ec681f3Smrg LLVMTypeRef f32; 827ec681f3Smrg LLVMTypeRef f64; 837ec681f3Smrg LLVMTypeRef v2i16; 847ec681f3Smrg LLVMTypeRef v4i16; 857ec681f3Smrg LLVMTypeRef v2f16; 867ec681f3Smrg LLVMTypeRef v4f16; 877ec681f3Smrg LLVMTypeRef v2i32; 887ec681f3Smrg LLVMTypeRef v3i32; 897ec681f3Smrg LLVMTypeRef v4i32; 907ec681f3Smrg LLVMTypeRef v2f32; 917ec681f3Smrg LLVMTypeRef v3f32; 927ec681f3Smrg LLVMTypeRef v4f32; 937ec681f3Smrg LLVMTypeRef v8i32; 947ec681f3Smrg LLVMTypeRef iN_wavemask; 957ec681f3Smrg LLVMTypeRef iN_ballotmask; 967ec681f3Smrg 977ec681f3Smrg LLVMValueRef i8_0; 987ec681f3Smrg LLVMValueRef i8_1; 997ec681f3Smrg LLVMValueRef i16_0; 1007ec681f3Smrg LLVMValueRef i16_1; 1017ec681f3Smrg LLVMValueRef i32_0; 1027ec681f3Smrg LLVMValueRef i32_1; 1037ec681f3Smrg LLVMValueRef i64_0; 1047ec681f3Smrg LLVMValueRef i64_1; 1057ec681f3Smrg LLVMValueRef i128_0; 1067ec681f3Smrg LLVMValueRef i128_1; 1077ec681f3Smrg LLVMValueRef f16_0; 1087ec681f3Smrg LLVMValueRef f16_1; 1097ec681f3Smrg LLVMValueRef f32_0; 1107ec681f3Smrg LLVMValueRef f32_1; 1117ec681f3Smrg LLVMValueRef f64_0; 1127ec681f3Smrg LLVMValueRef f64_1; 1137ec681f3Smrg LLVMValueRef i1true; 1147ec681f3Smrg LLVMValueRef i1false; 1157ec681f3Smrg 1167ec681f3Smrg /* Temporary helper to implement demote_to_helper: 1177ec681f3Smrg * True = live lanes 1187ec681f3Smrg * False = demoted lanes 1197ec681f3Smrg */ 1207ec681f3Smrg LLVMValueRef postponed_kill; 1217ec681f3Smrg bool conditional_demote_seen; 1227ec681f3Smrg 1237ec681f3Smrg /* Since ac_nir_translate makes a local copy of ac_llvm_context, there 1247ec681f3Smrg * are two ac_llvm_contexts. Declare a pointer here, so that the control 1257ec681f3Smrg * flow stack is shared by both ac_llvm_contexts. 1267ec681f3Smrg */ 1277ec681f3Smrg struct ac_llvm_flow_state *flow; 1287ec681f3Smrg 1297ec681f3Smrg unsigned range_md_kind; 1307ec681f3Smrg unsigned invariant_load_md_kind; 1317ec681f3Smrg unsigned uniform_md_kind; 1327ec681f3Smrg LLVMValueRef empty_md; 1337ec681f3Smrg 1347ec681f3Smrg enum chip_class chip_class; 1357ec681f3Smrg enum radeon_family family; 1367ec681f3Smrg const struct radeon_info *info; 1377ec681f3Smrg 1387ec681f3Smrg unsigned wave_size; 1397ec681f3Smrg unsigned ballot_mask_bits; 1407ec681f3Smrg 1417ec681f3Smrg unsigned float_mode; 1427ec681f3Smrg 1437ec681f3Smrg LLVMValueRef lds; 1447ec681f3Smrg}; 1457ec681f3Smrg 1467ec681f3Smrgvoid ac_llvm_context_init(struct ac_llvm_context *ctx, struct ac_llvm_compiler *compiler, 1477ec681f3Smrg enum chip_class chip_class, enum radeon_family family, 1487ec681f3Smrg const struct radeon_info *info, 1497ec681f3Smrg enum ac_float_mode float_mode, unsigned wave_size, 1507ec681f3Smrg unsigned ballot_mask_bits); 1517ec681f3Smrg 1527ec681f3Smrgvoid ac_llvm_context_dispose(struct ac_llvm_context *ctx); 1537ec681f3Smrg 1547ec681f3Smrgint ac_get_llvm_num_components(LLVMValueRef value); 1557ec681f3Smrg 1567ec681f3Smrgint ac_get_elem_bits(struct ac_llvm_context *ctx, LLVMTypeRef type); 1577ec681f3Smrg 1587ec681f3SmrgLLVMValueRef ac_llvm_extract_elem(struct ac_llvm_context *ac, LLVMValueRef value, int index); 1597ec681f3Smrg 1607ec681f3Smrgunsigned ac_get_type_size(LLVMTypeRef type); 1617ec681f3Smrg 1627ec681f3SmrgLLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t); 1637ec681f3SmrgLLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v); 1647ec681f3SmrgLLVMValueRef ac_to_integer_or_pointer(struct ac_llvm_context *ctx, LLVMValueRef v); 1657ec681f3SmrgLLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t); 1667ec681f3SmrgLLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v); 1677ec681f3Smrg 1687ec681f3SmrgLLVMValueRef ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name, 1697ec681f3Smrg LLVMTypeRef return_type, LLVMValueRef *params, unsigned param_count, 1707ec681f3Smrg unsigned attrib_mask); 1717ec681f3Smrg 1727ec681f3Smrgvoid ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize); 1737ec681f3Smrg 1747ec681f3SmrgLLVMValueRef ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type, unsigned count_incoming, 1757ec681f3Smrg LLVMValueRef *values, LLVMBasicBlockRef *blocks); 1767ec681f3Smrg 1777ec681f3Smrgvoid ac_build_s_barrier(struct ac_llvm_context *ctx); 1787ec681f3Smrgvoid ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pgpr, bool sgpr); 1797ec681f3Smrg 1807ec681f3SmrgLLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, nir_scope scope); 1817ec681f3Smrg 1827ec681f3SmrgLLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value); 1837ec681f3SmrgLLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef value); 1847ec681f3Smrg 1857ec681f3SmrgLLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value); 1867ec681f3Smrg 1877ec681f3SmrgLLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value); 1887ec681f3Smrg 1897ec681f3SmrgLLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value); 1907ec681f3Smrg 1917ec681f3SmrgLLVMValueRef ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values, 1927ec681f3Smrg unsigned value_count, unsigned component); 1937ec681f3Smrg 1947ec681f3SmrgLLVMValueRef ac_build_gather_values_extended(struct ac_llvm_context *ctx, LLVMValueRef *values, 1957ec681f3Smrg unsigned value_count, unsigned value_stride, bool load, 1967ec681f3Smrg bool always_vector); 1977ec681f3SmrgLLVMValueRef ac_build_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values, 1987ec681f3Smrg unsigned value_count); 1997ec681f3Smrg 2007ec681f3SmrgLLVMValueRef ac_build_concat(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 2017ec681f3Smrg 2027ec681f3SmrgLLVMValueRef ac_extract_components(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned start, 2037ec681f3Smrg unsigned channels); 2047ec681f3Smrg 2057ec681f3SmrgLLVMValueRef ac_build_expand(struct ac_llvm_context *ctx, LLVMValueRef value, 2067ec681f3Smrg unsigned src_channels, unsigned dst_channels); 2077ec681f3Smrg 2087ec681f3SmrgLLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx, LLVMValueRef value, 2097ec681f3Smrg unsigned num_channels); 2107ec681f3SmrgLLVMValueRef ac_build_round(struct ac_llvm_context *ctx, LLVMValueRef value); 2117ec681f3Smrg 2127ec681f3SmrgLLVMValueRef ac_build_fdiv(struct ac_llvm_context *ctx, LLVMValueRef num, LLVMValueRef den); 2137ec681f3Smrg 2147ec681f3SmrgLLVMValueRef ac_build_fast_udiv(struct ac_llvm_context *ctx, LLVMValueRef num, 2157ec681f3Smrg LLVMValueRef multiplier, LLVMValueRef pre_shift, 2167ec681f3Smrg LLVMValueRef post_shift, LLVMValueRef increment); 2177ec681f3SmrgLLVMValueRef ac_build_fast_udiv_nuw(struct ac_llvm_context *ctx, LLVMValueRef num, 2187ec681f3Smrg LLVMValueRef multiplier, LLVMValueRef pre_shift, 2197ec681f3Smrg LLVMValueRef post_shift, LLVMValueRef increment); 2207ec681f3SmrgLLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx, LLVMValueRef num, 2217ec681f3Smrg LLVMValueRef multiplier, LLVMValueRef post_shift); 2227ec681f3Smrg 2237ec681f3Smrgvoid ac_prepare_cube_coords(struct ac_llvm_context *ctx, bool is_deriv, bool is_array, bool is_lod, 2247ec681f3Smrg LLVMValueRef *coords_arg, LLVMValueRef *derivs_arg); 2257ec681f3Smrg 2267ec681f3SmrgLLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan, 2277ec681f3Smrg LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i, 2287ec681f3Smrg LLVMValueRef j); 2297ec681f3Smrg 2307ec681f3SmrgLLVMValueRef ac_build_fs_interp_f16(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan, 2317ec681f3Smrg LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i, 2327ec681f3Smrg LLVMValueRef j, bool high_16bits); 2337ec681f3Smrg 2347ec681f3SmrgLLVMValueRef ac_build_fs_interp_mov(struct ac_llvm_context *ctx, LLVMValueRef parameter, 2357ec681f3Smrg LLVMValueRef llvm_chan, LLVMValueRef attr_number, 2367ec681f3Smrg LLVMValueRef params); 2377ec681f3Smrg 2387ec681f3SmrgLLVMValueRef ac_build_gep_ptr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, 2397ec681f3Smrg LLVMValueRef index); 2407ec681f3Smrg 2417ec681f3SmrgLLVMValueRef ac_build_gep0(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index); 2427ec681f3SmrgLLVMValueRef ac_build_pointer_add(struct ac_llvm_context *ctx, LLVMValueRef ptr, 2437ec681f3Smrg LLVMValueRef index); 2447ec681f3Smrg 2457ec681f3Smrgvoid ac_build_indexed_store(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index, 2467ec681f3Smrg LLVMValueRef value); 2477ec681f3Smrg 2487ec681f3SmrgLLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, LLVMValueRef index); 2497ec681f3SmrgLLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, 2507ec681f3Smrg LLVMValueRef index); 2517ec681f3SmrgLLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx, LLVMValueRef base_ptr, 2527ec681f3Smrg LLVMValueRef index); 2537ec681f3SmrgLLVMValueRef ac_build_load_to_sgpr_uint_wraparound(struct ac_llvm_context *ctx, 2547ec681f3Smrg LLVMValueRef base_ptr, LLVMValueRef index); 2557ec681f3Smrg 2567ec681f3Smrgvoid ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata, 2577ec681f3Smrg unsigned num_channels, LLVMValueRef voffset, LLVMValueRef soffset, 2587ec681f3Smrg unsigned inst_offset, unsigned cache_policy); 2597ec681f3Smrg 2607ec681f3Smrgvoid ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data, 2617ec681f3Smrg LLVMValueRef vindex, LLVMValueRef voffset, unsigned cache_policy); 2627ec681f3Smrg 2637ec681f3SmrgLLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels, 2647ec681f3Smrg LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset, 2657ec681f3Smrg unsigned inst_offset, LLVMTypeRef channel_type, 2667ec681f3Smrg unsigned cache_policy, bool can_speculate, bool allow_smem); 2677ec681f3Smrg 2687ec681f3SmrgLLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 2697ec681f3Smrg LLVMValueRef vindex, LLVMValueRef voffset, 2707ec681f3Smrg unsigned num_channels, unsigned cache_policy, 2717ec681f3Smrg bool can_speculate, bool d16, bool tfe); 2727ec681f3Smrg 2737ec681f3SmrgLLVMValueRef ac_build_tbuffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 2747ec681f3Smrg LLVMValueRef voffset, LLVMValueRef soffset, 2757ec681f3Smrg LLVMValueRef immoffset, unsigned cache_policy); 2767ec681f3Smrg 2777ec681f3SmrgLLVMValueRef ac_build_tbuffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 2787ec681f3Smrg LLVMValueRef voffset, LLVMValueRef soffset, 2797ec681f3Smrg LLVMValueRef immoffset, unsigned cache_policy); 2807ec681f3Smrg 2817ec681f3SmrgLLVMValueRef ac_build_struct_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 2827ec681f3Smrg LLVMValueRef vindex, LLVMValueRef voffset, 2837ec681f3Smrg LLVMValueRef soffset, LLVMValueRef immoffset, 2847ec681f3Smrg unsigned num_channels, unsigned dfmt, unsigned nfmt, 2857ec681f3Smrg unsigned cache_policy, bool can_speculate); 2867ec681f3Smrg 2877ec681f3SmrgLLVMValueRef ac_build_raw_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 2887ec681f3Smrg LLVMValueRef voffset, LLVMValueRef soffset, 2897ec681f3Smrg LLVMValueRef immoffset, unsigned num_channels, unsigned dfmt, 2907ec681f3Smrg unsigned nfmt, unsigned cache_policy, bool can_speculate); 2917ec681f3Smrg 2927ec681f3Smrg 2937ec681f3SmrgLLVMValueRef ac_build_opencoded_load_format(struct ac_llvm_context *ctx, unsigned log_size, 2947ec681f3Smrg unsigned num_channels, unsigned format, bool reverse, 2957ec681f3Smrg bool known_aligned, LLVMValueRef rsrc, 2967ec681f3Smrg LLVMValueRef vindex, LLVMValueRef voffset, 2977ec681f3Smrg LLVMValueRef soffset, unsigned cache_policy, 2987ec681f3Smrg bool can_speculate); 2997ec681f3Smrg 3007ec681f3Smrgvoid ac_build_tbuffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 3017ec681f3Smrg LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset, 3027ec681f3Smrg unsigned cache_policy); 3037ec681f3Smrg 3047ec681f3Smrgvoid ac_build_tbuffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata, 3057ec681f3Smrg LLVMValueRef voffset, LLVMValueRef soffset, unsigned cache_policy); 3067ec681f3Smrg 3077ec681f3Smrgvoid ac_build_struct_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc, 3087ec681f3Smrg LLVMValueRef vdata, LLVMValueRef vindex, LLVMValueRef voffset, 3097ec681f3Smrg LLVMValueRef soffset, LLVMValueRef immoffset, 3107ec681f3Smrg unsigned num_channels, unsigned dfmt, unsigned nfmt, 3117ec681f3Smrg unsigned cache_policy); 3127ec681f3Smrg 3137ec681f3Smrgvoid ac_build_raw_tbuffer_store(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata, 3147ec681f3Smrg LLVMValueRef voffset, LLVMValueRef soffset, LLVMValueRef immoffset, 3157ec681f3Smrg unsigned num_channels, unsigned dfmt, unsigned nfmt, 3167ec681f3Smrg unsigned cache_policy); 3177ec681f3Smrg 3187ec681f3Smrgvoid ac_set_range_metadata(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned lo, 3197ec681f3Smrg unsigned hi); 3207ec681f3SmrgLLVMValueRef ac_get_thread_id(struct ac_llvm_context *ctx); 3217ec681f3Smrg 3227ec681f3Smrg#define AC_TID_MASK_TOP_LEFT 0xfffffffc 3237ec681f3Smrg#define AC_TID_MASK_TOP 0xfffffffd 3247ec681f3Smrg#define AC_TID_MASK_LEFT 0xfffffffe 3257ec681f3Smrg 3267ec681f3SmrgLLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val); 3277ec681f3Smrg 3287ec681f3Smrg#define AC_SENDMSG_GS 2 3297ec681f3Smrg#define AC_SENDMSG_GS_DONE 3 3307ec681f3Smrg#define AC_SENDMSG_GS_ALLOC_REQ 9 3317ec681f3Smrg 3327ec681f3Smrg#define AC_SENDMSG_GS_OP_NOP (0 << 4) 3337ec681f3Smrg#define AC_SENDMSG_GS_OP_CUT (1 << 4) 3347ec681f3Smrg#define AC_SENDMSG_GS_OP_EMIT (2 << 4) 3357ec681f3Smrg#define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4) 3367ec681f3Smrg 3377ec681f3Smrgvoid ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t msg, LLVMValueRef wave_id); 3387ec681f3Smrg 3397ec681f3SmrgLLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type); 3407ec681f3Smrg 3417ec681f3SmrgLLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type); 3427ec681f3SmrgLLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3437ec681f3SmrgLLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3447ec681f3SmrgLLVMValueRef ac_build_imin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3457ec681f3SmrgLLVMValueRef ac_build_imax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3467ec681f3SmrgLLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3477ec681f3SmrgLLVMValueRef ac_build_umax(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b); 3487ec681f3SmrgLLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value); 3497ec681f3Smrg 3507ec681f3Smrgstruct ac_export_args { 3517ec681f3Smrg LLVMValueRef out[4]; 3527ec681f3Smrg unsigned target; 3537ec681f3Smrg unsigned enabled_channels; 3547ec681f3Smrg bool compr; 3557ec681f3Smrg bool done; 3567ec681f3Smrg bool valid_mask; 3577ec681f3Smrg}; 3587ec681f3Smrg 3597ec681f3Smrgvoid ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a); 3607ec681f3Smrg 3617ec681f3Smrgvoid ac_build_export_null(struct ac_llvm_context *ctx); 3627ec681f3Smrg 3637ec681f3Smrgenum ac_image_opcode 3647ec681f3Smrg{ 3657ec681f3Smrg ac_image_sample, 3667ec681f3Smrg ac_image_gather4, 3677ec681f3Smrg ac_image_load, 3687ec681f3Smrg ac_image_load_mip, 3697ec681f3Smrg ac_image_store, 3707ec681f3Smrg ac_image_store_mip, 3717ec681f3Smrg ac_image_get_lod, 3727ec681f3Smrg ac_image_get_resinfo, 3737ec681f3Smrg ac_image_atomic, 3747ec681f3Smrg ac_image_atomic_cmpswap, 3757ec681f3Smrg}; 3767ec681f3Smrg 3777ec681f3Smrgenum ac_atomic_op 3787ec681f3Smrg{ 3797ec681f3Smrg ac_atomic_swap, 3807ec681f3Smrg ac_atomic_add, 3817ec681f3Smrg ac_atomic_sub, 3827ec681f3Smrg ac_atomic_smin, 3837ec681f3Smrg ac_atomic_umin, 3847ec681f3Smrg ac_atomic_smax, 3857ec681f3Smrg ac_atomic_umax, 3867ec681f3Smrg ac_atomic_and, 3877ec681f3Smrg ac_atomic_or, 3887ec681f3Smrg ac_atomic_xor, 3897ec681f3Smrg ac_atomic_inc_wrap, 3907ec681f3Smrg ac_atomic_dec_wrap, 3917ec681f3Smrg ac_atomic_fmin, 3927ec681f3Smrg ac_atomic_fmax, 3937ec681f3Smrg}; 3947ec681f3Smrg 3957ec681f3Smrg/* These cache policy bits match the definitions used by the LLVM intrinsics. */ 3967ec681f3Smrgenum ac_image_cache_policy 3977ec681f3Smrg{ 3987ec681f3Smrg ac_glc = 1 << 0, /* per-CU cache control */ 3997ec681f3Smrg ac_slc = 1 << 1, /* global L2 cache control */ 4007ec681f3Smrg ac_dlc = 1 << 2, /* per-shader-array cache control */ 4017ec681f3Smrg ac_swizzled = 1 << 3, /* the access is swizzled, disabling load/store merging */ 4027ec681f3Smrg}; 4037ec681f3Smrg 4047ec681f3Smrgstruct ac_image_args { 4057ec681f3Smrg enum ac_image_opcode opcode; 4067ec681f3Smrg enum ac_atomic_op atomic; /* for the ac_image_atomic opcode */ 4077ec681f3Smrg enum ac_image_dim dim; 4087ec681f3Smrg unsigned dmask : 4; 4097ec681f3Smrg unsigned cache_policy : 3; 4107ec681f3Smrg bool unorm : 1; 4117ec681f3Smrg bool level_zero : 1; 4127ec681f3Smrg bool d16 : 1; /* GFX8+: data and return values are 16-bit */ 4137ec681f3Smrg bool a16 : 1; /* GFX9+: address components except compare, offset and bias are 16-bit */ 4147ec681f3Smrg bool g16 : 1; /* GFX10+: derivatives are 16-bit; GFX<=9: must be equal to a16 */ 4157ec681f3Smrg bool tfe : 1; 4167ec681f3Smrg unsigned attributes; /* additional call-site specific AC_FUNC_ATTRs */ 4177ec681f3Smrg 4187ec681f3Smrg LLVMValueRef resource; 4197ec681f3Smrg LLVMValueRef sampler; 4207ec681f3Smrg LLVMValueRef data[2]; /* data[0] is source data (vector); data[1] is cmp for cmpswap */ 4217ec681f3Smrg LLVMValueRef offset; 4227ec681f3Smrg LLVMValueRef bias; 4237ec681f3Smrg LLVMValueRef compare; 4247ec681f3Smrg LLVMValueRef derivs[6]; 4257ec681f3Smrg LLVMValueRef coords[4]; 4267ec681f3Smrg LLVMValueRef lod; // also used by ac_image_get_resinfo 4277ec681f3Smrg LLVMValueRef min_lod; 4287ec681f3Smrg}; 4297ec681f3Smrg 4307ec681f3SmrgLLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx, struct ac_image_args *a); 4317ec681f3SmrgLLVMValueRef ac_build_image_get_sample_count(struct ac_llvm_context *ctx, LLVMValueRef rsrc); 4327ec681f3SmrgLLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]); 4337ec681f3SmrgLLVMValueRef ac_build_cvt_pknorm_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2]); 4347ec681f3SmrgLLVMValueRef ac_build_cvt_pknorm_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2]); 4357ec681f3SmrgLLVMValueRef ac_build_cvt_pknorm_i16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]); 4367ec681f3SmrgLLVMValueRef ac_build_cvt_pknorm_u16_f16(struct ac_llvm_context *ctx, LLVMValueRef args[2]); 4377ec681f3SmrgLLVMValueRef ac_build_cvt_pk_i16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits, 4387ec681f3Smrg bool hi); 4397ec681f3SmrgLLVMValueRef ac_build_cvt_pk_u16(struct ac_llvm_context *ctx, LLVMValueRef args[2], unsigned bits, 4407ec681f3Smrg bool hi); 4417ec681f3SmrgLLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1); 4427ec681f3Smrgvoid ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1); 4437ec681f3SmrgLLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input, LLVMValueRef offset, 4447ec681f3Smrg LLVMValueRef width, bool is_signed); 4457ec681f3SmrgLLVMValueRef ac_build_imad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1, 4467ec681f3Smrg LLVMValueRef s2); 4477ec681f3SmrgLLVMValueRef ac_build_fmad(struct ac_llvm_context *ctx, LLVMValueRef s0, LLVMValueRef s1, 4487ec681f3Smrg LLVMValueRef s2); 4497ec681f3Smrg 4507ec681f3Smrgvoid ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned wait_flags); 4517ec681f3Smrg 4527ec681f3SmrgLLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize); 4537ec681f3SmrgLLVMValueRef ac_const_uint_vec(struct ac_llvm_context *ctx, LLVMTypeRef type, uint64_t value); 4547ec681f3SmrgLLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0); 4557ec681f3SmrgLLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src); 4567ec681f3SmrgLLVMValueRef ac_build_bit_count(struct ac_llvm_context *ctx, LLVMValueRef src0); 4577ec681f3Smrg 4587ec681f3SmrgLLVMValueRef ac_build_fsat(struct ac_llvm_context *ctx, LLVMValueRef src, 4597ec681f3Smrg LLVMTypeRef type); 4607ec681f3Smrg 4617ec681f3SmrgLLVMValueRef ac_build_bitfield_reverse(struct ac_llvm_context *ctx, LLVMValueRef src0); 4627ec681f3Smrg 4637ec681f3Smrgvoid ac_optimize_vs_outputs(struct ac_llvm_context *ac, LLVMValueRef main_fn, 4647ec681f3Smrg uint8_t *vs_output_param_offset, uint32_t num_outputs, 4657ec681f3Smrg uint32_t skip_output_mask, uint8_t *num_param_exports); 4667ec681f3Smrgvoid ac_init_exec_full_mask(struct ac_llvm_context *ctx); 4677ec681f3Smrg 4687ec681f3Smrgvoid ac_declare_lds_as_pointer(struct ac_llvm_context *ac); 4697ec681f3SmrgLLVMValueRef ac_lds_load(struct ac_llvm_context *ctx, LLVMValueRef dw_addr); 4707ec681f3Smrgvoid ac_lds_store(struct ac_llvm_context *ctx, LLVMValueRef dw_addr, LLVMValueRef value); 4717ec681f3Smrg 4727ec681f3SmrgLLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx, LLVMTypeRef dst_type, LLVMValueRef src0); 4737ec681f3Smrg 4747ec681f3SmrgLLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type); 4757ec681f3SmrgLLVMTypeRef ac_array_in_const32_addr_space(LLVMTypeRef elem_type); 4767ec681f3Smrg 4777ec681f3Smrgvoid ac_build_bgnloop(struct ac_llvm_context *ctx, int lable_id); 4787ec681f3Smrgvoid ac_build_break(struct ac_llvm_context *ctx); 4797ec681f3Smrgvoid ac_build_continue(struct ac_llvm_context *ctx); 4807ec681f3Smrgvoid ac_build_else(struct ac_llvm_context *ctx, int lable_id); 4817ec681f3Smrgvoid ac_build_endif(struct ac_llvm_context *ctx, int lable_id); 4827ec681f3Smrgvoid ac_build_endloop(struct ac_llvm_context *ctx, int lable_id); 4837ec681f3Smrgvoid ac_build_ifcc(struct ac_llvm_context *ctx, LLVMValueRef cond, int label_id); 4847ec681f3Smrg 4857ec681f3SmrgLLVMValueRef ac_build_alloca(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name); 4867ec681f3SmrgLLVMValueRef ac_build_alloca_undef(struct ac_llvm_context *ac, LLVMTypeRef type, const char *name); 4877ec681f3SmrgLLVMValueRef ac_build_alloca_init(struct ac_llvm_context *ac, LLVMValueRef val, const char *name); 4887ec681f3Smrg 4897ec681f3SmrgLLVMValueRef ac_cast_ptr(struct ac_llvm_context *ctx, LLVMValueRef ptr, LLVMTypeRef type); 4907ec681f3Smrg 4917ec681f3SmrgLLVMValueRef ac_trim_vector(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned count); 4927ec681f3Smrg 4937ec681f3SmrgLLVMValueRef ac_unpack_param(struct ac_llvm_context *ctx, LLVMValueRef param, unsigned rshift, 4947ec681f3Smrg unsigned bitwidth); 4957ec681f3Smrg 4967ec681f3Smrgvoid ac_apply_fmask_to_sample(struct ac_llvm_context *ac, LLVMValueRef fmask, LLVMValueRef *addr, 4977ec681f3Smrg bool is_array_tex); 4987ec681f3Smrg 4997ec681f3SmrgLLVMValueRef ac_build_ds_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned mask); 5007ec681f3Smrg 5017ec681f3SmrgLLVMValueRef ac_build_readlane_no_opt_barrier(struct ac_llvm_context *ctx, LLVMValueRef src, 5027ec681f3Smrg LLVMValueRef lane); 5037ec681f3Smrg 5047ec681f3SmrgLLVMValueRef ac_build_readlane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef lane); 5057ec681f3Smrg 5067ec681f3SmrgLLVMValueRef ac_build_writelane(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef value, 5077ec681f3Smrg LLVMValueRef lane); 5087ec681f3Smrg 5097ec681f3SmrgLLVMValueRef ac_build_mbcnt_add(struct ac_llvm_context *ctx, LLVMValueRef mask, LLVMValueRef add_src); 5107ec681f3SmrgLLVMValueRef ac_build_mbcnt(struct ac_llvm_context *ctx, LLVMValueRef mask); 5117ec681f3Smrg 5127ec681f3SmrgLLVMValueRef ac_build_inclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op); 5137ec681f3Smrg 5147ec681f3SmrgLLVMValueRef ac_build_exclusive_scan(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op); 5157ec681f3Smrg 5167ec681f3SmrgLLVMValueRef ac_build_reduce(struct ac_llvm_context *ctx, LLVMValueRef src, nir_op op, 5177ec681f3Smrg unsigned cluster_size); 5187ec681f3Smrg 5197ec681f3Smrg/** 5207ec681f3Smrg * Common arguments for a scan/reduce operation that accumulates per-wave 5217ec681f3Smrg * values across an entire workgroup, while respecting the order of waves. 5227ec681f3Smrg */ 5237ec681f3Smrgstruct ac_wg_scan { 5247ec681f3Smrg bool enable_reduce; 5257ec681f3Smrg bool enable_exclusive; 5267ec681f3Smrg bool enable_inclusive; 5277ec681f3Smrg nir_op op; 5287ec681f3Smrg LLVMValueRef src; /* clobbered! */ 5297ec681f3Smrg LLVMValueRef result_reduce; 5307ec681f3Smrg LLVMValueRef result_exclusive; 5317ec681f3Smrg LLVMValueRef result_inclusive; 5327ec681f3Smrg LLVMValueRef extra; 5337ec681f3Smrg LLVMValueRef waveidx; 5347ec681f3Smrg LLVMValueRef numwaves; /* only needed for "reduce" operations */ 5357ec681f3Smrg 5367ec681f3Smrg /* T addrspace(LDS) pointer to the same type as value, at least maxwaves entries */ 5377ec681f3Smrg LLVMValueRef scratch; 5387ec681f3Smrg unsigned maxwaves; 5397ec681f3Smrg}; 5407ec681f3Smrg 5417ec681f3Smrgvoid ac_build_wg_wavescan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5427ec681f3Smrgvoid ac_build_wg_wavescan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5437ec681f3Smrgvoid ac_build_wg_wavescan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5447ec681f3Smrg 5457ec681f3Smrgvoid ac_build_wg_scan_top(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5467ec681f3Smrgvoid ac_build_wg_scan_bottom(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5477ec681f3Smrgvoid ac_build_wg_scan(struct ac_llvm_context *ctx, struct ac_wg_scan *ws); 5487ec681f3Smrg 5497ec681f3SmrgLLVMValueRef ac_build_quad_swizzle(struct ac_llvm_context *ctx, LLVMValueRef src, unsigned lane0, 5507ec681f3Smrg unsigned lane1, unsigned lane2, unsigned lane3); 5517ec681f3Smrg 5527ec681f3SmrgLLVMValueRef ac_build_shuffle(struct ac_llvm_context *ctx, LLVMValueRef src, LLVMValueRef index); 5537ec681f3Smrg 5547ec681f3SmrgLLVMValueRef ac_build_frexp_exp(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize); 5557ec681f3Smrg 5567ec681f3SmrgLLVMValueRef ac_build_frexp_mant(struct ac_llvm_context *ctx, LLVMValueRef src0, unsigned bitsize); 5577ec681f3Smrg 5587ec681f3SmrgLLVMValueRef ac_build_canonicalize(struct ac_llvm_context *ctx, LLVMValueRef src0, 5597ec681f3Smrg unsigned bitsize); 5607ec681f3Smrg 5617ec681f3SmrgLLVMValueRef ac_build_ddxy_interp(struct ac_llvm_context *ctx, LLVMValueRef interp_ij); 5627ec681f3Smrg 5637ec681f3SmrgLLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx); 5647ec681f3Smrg 5657ec681f3SmrgLLVMValueRef ac_build_is_helper_invocation(struct ac_llvm_context *ctx); 5667ec681f3Smrg 5677ec681f3SmrgLLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMValueRef func, LLVMValueRef *args, 5687ec681f3Smrg unsigned num_args); 5697ec681f3Smrg 5707ec681f3SmrgLLVMValueRef ac_build_atomic_rmw(struct ac_llvm_context *ctx, LLVMAtomicRMWBinOp op, 5717ec681f3Smrg LLVMValueRef ptr, LLVMValueRef val, const char *sync_scope); 5727ec681f3Smrg 5737ec681f3SmrgLLVMValueRef ac_build_atomic_cmp_xchg(struct ac_llvm_context *ctx, LLVMValueRef ptr, 5747ec681f3Smrg LLVMValueRef cmp, LLVMValueRef val, const char *sync_scope); 5757ec681f3Smrg 5767ec681f3Smrgvoid ac_export_mrt_z(struct ac_llvm_context *ctx, LLVMValueRef depth, LLVMValueRef stencil, 5777ec681f3Smrg LLVMValueRef samplemask, struct ac_export_args *args); 5787ec681f3Smrg 5797ec681f3Smrgvoid ac_build_sendmsg_gs_alloc_req(struct ac_llvm_context *ctx, LLVMValueRef wave_id, 5807ec681f3Smrg LLVMValueRef vtx_cnt, LLVMValueRef prim_cnt); 5817ec681f3Smrg 5827ec681f3Smrgstruct ac_ngg_prim { 5837ec681f3Smrg unsigned num_vertices; 5847ec681f3Smrg LLVMValueRef isnull; 5857ec681f3Smrg LLVMValueRef index[3]; 5867ec681f3Smrg LLVMValueRef edgeflags; 5877ec681f3Smrg LLVMValueRef passthrough; 5887ec681f3Smrg}; 5897ec681f3Smrg 5907ec681f3SmrgLLVMValueRef ac_pack_edgeflags_for_export(struct ac_llvm_context *ctx, 5917ec681f3Smrg const struct ac_shader_args *args); 5927ec681f3SmrgLLVMValueRef ac_pack_prim_export(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim); 5937ec681f3Smrgvoid ac_build_export_prim(struct ac_llvm_context *ctx, const struct ac_ngg_prim *prim); 5947ec681f3Smrg 5957ec681f3Smrgstatic inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg) 5967ec681f3Smrg{ 5977ec681f3Smrg assert(arg.used); 5987ec681f3Smrg return LLVMGetParam(ctx->main_function, arg.arg_index); 5997ec681f3Smrg} 6007ec681f3Smrg 6017ec681f3Smrgenum ac_llvm_calling_convention 6027ec681f3Smrg{ 6037ec681f3Smrg AC_LLVM_AMDGPU_VS = 87, 6047ec681f3Smrg AC_LLVM_AMDGPU_GS = 88, 6057ec681f3Smrg AC_LLVM_AMDGPU_PS = 89, 6067ec681f3Smrg AC_LLVM_AMDGPU_CS = 90, 6077ec681f3Smrg AC_LLVM_AMDGPU_HS = 93, 6087ec681f3Smrg}; 6097ec681f3Smrg 6107ec681f3SmrgLLVMValueRef ac_build_main(const struct ac_shader_args *args, struct ac_llvm_context *ctx, 6117ec681f3Smrg enum ac_llvm_calling_convention convention, const char *name, 6127ec681f3Smrg LLVMTypeRef ret_type, LLVMModuleRef module); 6137ec681f3Smrgvoid ac_build_s_endpgm(struct ac_llvm_context *ctx); 6147ec681f3Smrg 6157ec681f3Smrgvoid ac_build_triangle_strip_indices_to_triangle(struct ac_llvm_context *ctx, LLVMValueRef is_odd, 6167ec681f3Smrg LLVMValueRef flatshade_first, 6177ec681f3Smrg LLVMValueRef index[3]); 6187ec681f3Smrg 6197ec681f3Smrg#ifdef __cplusplus 6207ec681f3Smrg} 6217ec681f3Smrg#endif 6227ec681f3Smrg 6237ec681f3Smrg#endif 624