2
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
4
* SPDX-License-Identifier: MIT
25
6
#ifndef AC_LLVM_BUILD_H
26
7
#define AC_LLVM_BUILD_H
130
112
LLVMValueRef i1true;
131
113
LLVMValueRef i1false;
133
/* Temporary helper to implement demote_to_helper:
135
* False = demoted lanes
137
LLVMValueRef postponed_kill;
138
bool conditional_demote_seen;
140
115
/* Since ac_nir_translate makes a local copy of ac_llvm_context, there
141
116
* are two ac_llvm_contexts. Declare a pointer here, so that the control
142
117
* flow stack is shared by both ac_llvm_contexts.
148
123
unsigned uniform_md_kind;
149
124
LLVMValueRef empty_md;
126
const struct radeon_info *info;
151
127
enum amd_gfx_level gfx_level;
152
enum radeon_family family;
153
bool has_3d_cube_border_color_mipmap;
155
129
unsigned wave_size;
156
130
unsigned ballot_mask_bits;
169
143
void ac_llvm_context_init(struct ac_llvm_context *ctx, struct ac_llvm_compiler *compiler,
170
enum amd_gfx_level gfx_level, enum radeon_family family,
171
bool has_3d_cube_border_color_mipmap,
172
enum ac_float_mode float_mode, unsigned wave_size,
173
unsigned ballot_mask_bits, bool exports_color_null, bool exports_mrtz);
144
const struct radeon_info *info, enum ac_float_mode float_mode,
145
unsigned wave_size, unsigned ballot_mask_bits, bool exports_color_null,
175
148
void ac_llvm_context_dispose(struct ac_llvm_context *ctx);
200
173
void ac_build_s_barrier(struct ac_llvm_context *ctx, gl_shader_stage stage);
201
174
void ac_build_optimization_barrier(struct ac_llvm_context *ctx, LLVMValueRef *pgpr, bool sgpr);
203
LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, nir_scope scope);
176
LLVMValueRef ac_build_shader_clock(struct ac_llvm_context *ctx, mesa_scope scope);
205
178
LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
206
179
LLVMValueRef ac_get_i1_sgpr_mask(struct ac_llvm_context *ctx, LLVMValueRef value);
243
216
LLVMValueRef ac_build_fast_udiv_u31_d_not_one(struct ac_llvm_context *ctx, LLVMValueRef num,
244
217
LLVMValueRef multiplier, LLVMValueRef post_shift);
246
void ac_prepare_cube_coords(struct ac_llvm_context *ctx, bool is_deriv, bool is_array, bool is_lod,
247
LLVMValueRef *coords_arg, LLVMValueRef *derivs_arg);
249
219
LLVMValueRef ac_build_fs_interp(struct ac_llvm_context *ctx, LLVMValueRef llvm_chan,
250
220
LLVMValueRef attr_number, LLVMValueRef params, LLVMValueRef i,
282
252
void ac_build_buffer_store_dword(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
283
253
LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
284
unsigned cache_policy);
254
enum gl_access_qualifier access);
286
256
void ac_build_buffer_store_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef data,
287
LLVMValueRef vindex, LLVMValueRef voffset, unsigned cache_policy);
257
LLVMValueRef vindex, LLVMValueRef voffset, enum gl_access_qualifier access);
289
259
LLVMValueRef ac_build_buffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc, int num_channels,
290
260
LLVMValueRef vindex, LLVMValueRef voffset, LLVMValueRef soffset,
291
LLVMTypeRef channel_type, unsigned cache_policy,
261
LLVMTypeRef channel_type, enum gl_access_qualifier access,
292
262
bool can_speculate, bool allow_smem);
294
264
LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
295
265
LLVMValueRef vindex, LLVMValueRef voffset,
296
unsigned num_channels, unsigned cache_policy,
266
unsigned num_channels, enum gl_access_qualifier access,
297
267
bool can_speculate, bool d16, bool tfe);
299
269
LLVMValueRef ac_build_buffer_load_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
300
270
LLVMValueRef voffset, LLVMValueRef soffset,
301
unsigned cache_policy);
271
enum gl_access_qualifier access);
303
273
LLVMValueRef ac_build_buffer_load_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
304
274
LLVMValueRef voffset, LLVMValueRef soffset,
305
unsigned cache_policy);
275
enum gl_access_qualifier access);
307
277
LLVMValueRef ac_build_safe_tbuffer_load(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
308
278
LLVMValueRef vindex, LLVMValueRef voffset,
312
282
unsigned align_offset,
313
283
unsigned align_mul,
314
284
unsigned num_channels,
315
unsigned cache_policy,
285
enum gl_access_qualifier access,
316
286
bool can_speculate);
318
288
void ac_build_buffer_store_short(struct ac_llvm_context *ctx, LLVMValueRef rsrc,
319
289
LLVMValueRef vdata, LLVMValueRef voffset, LLVMValueRef soffset,
320
unsigned cache_policy);
290
enum gl_access_qualifier access);
322
292
void ac_build_buffer_store_byte(struct ac_llvm_context *ctx, LLVMValueRef rsrc, LLVMValueRef vdata,
323
LLVMValueRef voffset, LLVMValueRef soffset, unsigned cache_policy);
293
LLVMValueRef voffset, LLVMValueRef soffset, enum gl_access_qualifier access);
325
295
void ac_set_range_metadata(struct ac_llvm_context *ctx, LLVMValueRef value, unsigned lo,
333
303
LLVMValueRef ac_build_ddxy(struct ac_llvm_context *ctx, uint32_t mask, int idx, LLVMValueRef val);
335
#define AC_SENDMSG_GS 2
336
#define AC_SENDMSG_GS_DONE 3
337
#define AC_SENDMSG_GS_ALLOC_REQ 9
339
#define AC_SENDMSG_GS_OP_NOP (0 << 4)
340
#define AC_SENDMSG_GS_OP_CUT (1 << 4)
341
#define AC_SENDMSG_GS_OP_EMIT (2 << 4)
342
#define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
344
void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t msg, LLVMValueRef wave_id);
305
void ac_build_sendmsg(struct ac_llvm_context *ctx, uint32_t imm, LLVMValueRef m0_content);
346
307
LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx, LLVMValueRef arg, LLVMTypeRef dst_type);
403
/* These cache policy bits match the definitions used by the LLVM intrinsics. */
404
enum ac_image_cache_policy
406
ac_glc = 1 << 0, /* per-CU cache control */
407
ac_slc = 1 << 1, /* global L2 cache control */
408
ac_dlc = 1 << 2, /* per-shader-array cache control */
409
ac_swizzled = 1 << 3, /* the access is swizzled, disabling load/store merging */
412
364
struct ac_image_args {
413
365
enum ac_image_opcode opcode;
414
366
enum ac_atomic_op atomic; /* for the ac_image_atomic opcode */
415
367
enum ac_image_dim dim;
368
enum gl_access_qualifier access;
416
369
unsigned dmask : 4;
417
unsigned cache_policy : 3;
419
371
bool level_zero : 1;
420
372
bool d16 : 1; /* GFX8+: data and return values are 16-bit */
538
490
LLVMValueRef ac_build_load_helper_invocation(struct ac_llvm_context *ctx);
540
LLVMValueRef ac_build_is_helper_invocation(struct ac_llvm_context *ctx);
542
492
LLVMValueRef ac_build_call(struct ac_llvm_context *ctx, LLVMTypeRef fn_type, LLVMValueRef func,
543
493
LLVMValueRef *args, unsigned num_args);
560
510
LLVMValueRef passthrough;
563
LLVMValueRef ac_pack_edgeflags_for_export(struct ac_llvm_context *ctx,
564
const struct ac_shader_args *args);
566
513
LLVMTypeRef ac_arg_type_to_pointee_type(struct ac_llvm_context *ctx, enum ac_arg_type type);
568
515
static inline LLVMValueRef ac_get_arg(struct ac_llvm_context *ctx, struct ac_arg arg)