ac: add glc parameter to ac_build_buffer_load_format
[mesa.git] / src / amd / common / ac_llvm_build.h
1 /*
2 * Copyright 2016 Bas Nieuwenhuizen
3 *
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:
11 *
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.
19 *
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
22 * of the Software.
23 *
24 */
25 #ifndef AC_LLVM_BUILD_H
26 #define AC_LLVM_BUILD_H
27
28 #include <stdbool.h>
29 #include <llvm-c/TargetMachine.h>
30
31 #include "amd_family.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 enum {
38 AC_CONST_ADDR_SPACE = 2, /* CONST is the only address space that selects SMEM loads */
39 AC_LOCAL_ADDR_SPACE = 3,
40 };
41
42 struct ac_llvm_context {
43 LLVMContextRef context;
44 LLVMModuleRef module;
45 LLVMBuilderRef builder;
46
47 LLVMTypeRef voidt;
48 LLVMTypeRef i1;
49 LLVMTypeRef i8;
50 LLVMTypeRef i16;
51 LLVMTypeRef i32;
52 LLVMTypeRef i64;
53 LLVMTypeRef f16;
54 LLVMTypeRef f32;
55 LLVMTypeRef f64;
56 LLVMTypeRef v2i32;
57 LLVMTypeRef v3i32;
58 LLVMTypeRef v4i32;
59 LLVMTypeRef v2f32;
60 LLVMTypeRef v4f32;
61 LLVMTypeRef v8i32;
62
63 LLVMValueRef i32_0;
64 LLVMValueRef i32_1;
65 LLVMValueRef i64_0;
66 LLVMValueRef i64_1;
67 LLVMValueRef f32_0;
68 LLVMValueRef f32_1;
69 LLVMValueRef f64_0;
70 LLVMValueRef f64_1;
71 LLVMValueRef i1true;
72 LLVMValueRef i1false;
73
74 unsigned range_md_kind;
75 unsigned invariant_load_md_kind;
76 unsigned uniform_md_kind;
77 unsigned fpmath_md_kind;
78 LLVMValueRef fpmath_md_2p5_ulp;
79 LLVMValueRef empty_md;
80
81 enum chip_class chip_class;
82 enum radeon_family family;
83
84 LLVMValueRef lds;
85 };
86
87 void
88 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context,
89 enum chip_class chip_class, enum radeon_family family);
90
91 int
92 ac_get_llvm_num_components(LLVMValueRef value);
93
94 LLVMValueRef
95 ac_llvm_extract_elem(struct ac_llvm_context *ac,
96 LLVMValueRef value,
97 int index);
98
99 unsigned ac_get_type_size(LLVMTypeRef type);
100
101 LLVMTypeRef ac_to_integer_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
102 LLVMValueRef ac_to_integer(struct ac_llvm_context *ctx, LLVMValueRef v);
103 LLVMTypeRef ac_to_float_type(struct ac_llvm_context *ctx, LLVMTypeRef t);
104 LLVMValueRef ac_to_float(struct ac_llvm_context *ctx, LLVMValueRef v);
105
106 LLVMValueRef
107 ac_build_intrinsic(struct ac_llvm_context *ctx, const char *name,
108 LLVMTypeRef return_type, LLVMValueRef *params,
109 unsigned param_count, unsigned attrib_mask);
110
111 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
112
113 LLVMValueRef
114 ac_build_phi(struct ac_llvm_context *ctx, LLVMTypeRef type,
115 unsigned count_incoming, LLVMValueRef *values,
116 LLVMBasicBlockRef *blocks);
117
118 void ac_build_optimization_barrier(struct ac_llvm_context *ctx,
119 LLVMValueRef *pvgpr);
120
121 LLVMValueRef ac_build_ballot(struct ac_llvm_context *ctx, LLVMValueRef value);
122
123 LLVMValueRef ac_build_vote_all(struct ac_llvm_context *ctx, LLVMValueRef value);
124
125 LLVMValueRef ac_build_vote_any(struct ac_llvm_context *ctx, LLVMValueRef value);
126
127 LLVMValueRef ac_build_vote_eq(struct ac_llvm_context *ctx, LLVMValueRef value);
128
129 LLVMValueRef
130 ac_build_varying_gather_values(struct ac_llvm_context *ctx, LLVMValueRef *values,
131 unsigned value_count, unsigned component);
132
133 LLVMValueRef
134 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
135 LLVMValueRef *values,
136 unsigned value_count,
137 unsigned value_stride,
138 bool load,
139 bool always_vector);
140 LLVMValueRef
141 ac_build_gather_values(struct ac_llvm_context *ctx,
142 LLVMValueRef *values,
143 unsigned value_count);
144 LLVMValueRef ac_build_expand_to_vec4(struct ac_llvm_context *ctx,
145 LLVMValueRef value,
146 unsigned num_channels);
147
148 LLVMValueRef
149 ac_build_fdiv(struct ac_llvm_context *ctx,
150 LLVMValueRef num,
151 LLVMValueRef den);
152
153 void
154 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
155 bool is_deriv, bool is_array, bool is_lod,
156 LLVMValueRef *coords_arg,
157 LLVMValueRef *derivs_arg);
158
159
160 LLVMValueRef
161 ac_build_fs_interp(struct ac_llvm_context *ctx,
162 LLVMValueRef llvm_chan,
163 LLVMValueRef attr_number,
164 LLVMValueRef params,
165 LLVMValueRef i,
166 LLVMValueRef j);
167
168 LLVMValueRef
169 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
170 LLVMValueRef parameter,
171 LLVMValueRef llvm_chan,
172 LLVMValueRef attr_number,
173 LLVMValueRef params);
174
175 LLVMValueRef
176 ac_build_gep0(struct ac_llvm_context *ctx,
177 LLVMValueRef base_ptr,
178 LLVMValueRef index);
179
180 void
181 ac_build_indexed_store(struct ac_llvm_context *ctx,
182 LLVMValueRef base_ptr, LLVMValueRef index,
183 LLVMValueRef value);
184
185 LLVMValueRef ac_build_load(struct ac_llvm_context *ctx, LLVMValueRef base_ptr,
186 LLVMValueRef index);
187 LLVMValueRef ac_build_load_invariant(struct ac_llvm_context *ctx,
188 LLVMValueRef base_ptr, LLVMValueRef index);
189 LLVMValueRef ac_build_load_to_sgpr(struct ac_llvm_context *ctx,
190 LLVMValueRef base_ptr, LLVMValueRef index);
191
192 void
193 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
194 LLVMValueRef rsrc,
195 LLVMValueRef vdata,
196 unsigned num_channels,
197 LLVMValueRef voffset,
198 LLVMValueRef soffset,
199 unsigned inst_offset,
200 bool glc,
201 bool slc,
202 bool writeonly_memory,
203 bool swizzle_enable_hint);
204 LLVMValueRef
205 ac_build_buffer_load(struct ac_llvm_context *ctx,
206 LLVMValueRef rsrc,
207 int num_channels,
208 LLVMValueRef vindex,
209 LLVMValueRef voffset,
210 LLVMValueRef soffset,
211 unsigned inst_offset,
212 unsigned glc,
213 unsigned slc,
214 bool can_speculate,
215 bool allow_smem);
216
217 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
218 LLVMValueRef rsrc,
219 LLVMValueRef vindex,
220 LLVMValueRef voffset,
221 unsigned num_channels,
222 bool glc,
223 bool can_speculate);
224
225 LLVMValueRef
226 ac_get_thread_id(struct ac_llvm_context *ctx);
227
228 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
229 #define AC_TID_MASK_TOP 0xfffffffd
230 #define AC_TID_MASK_LEFT 0xfffffffe
231
232 LLVMValueRef
233 ac_build_ddxy(struct ac_llvm_context *ctx,
234 uint32_t mask,
235 int idx,
236 LLVMValueRef val);
237
238 #define AC_SENDMSG_GS 2
239 #define AC_SENDMSG_GS_DONE 3
240
241 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
242 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
243 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
244 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
245
246 void ac_build_sendmsg(struct ac_llvm_context *ctx,
247 uint32_t msg,
248 LLVMValueRef wave_id);
249
250 LLVMValueRef ac_build_imsb(struct ac_llvm_context *ctx,
251 LLVMValueRef arg,
252 LLVMTypeRef dst_type);
253
254 LLVMValueRef ac_build_umsb(struct ac_llvm_context *ctx,
255 LLVMValueRef arg,
256 LLVMTypeRef dst_type);
257 LLVMValueRef ac_build_fmin(struct ac_llvm_context *ctx, LLVMValueRef a,
258 LLVMValueRef b);
259 LLVMValueRef ac_build_fmax(struct ac_llvm_context *ctx, LLVMValueRef a,
260 LLVMValueRef b);
261 LLVMValueRef ac_build_umin(struct ac_llvm_context *ctx, LLVMValueRef a, LLVMValueRef b);
262 LLVMValueRef ac_build_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
263
264 struct ac_export_args {
265 LLVMValueRef out[4];
266 unsigned target;
267 unsigned enabled_channels;
268 bool compr;
269 bool done;
270 bool valid_mask;
271 };
272
273 void ac_build_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
274
275 enum ac_image_opcode {
276 ac_image_sample,
277 ac_image_gather4,
278 ac_image_load,
279 ac_image_load_mip,
280 ac_image_get_lod,
281 ac_image_get_resinfo,
282 };
283
284 struct ac_image_args {
285 enum ac_image_opcode opcode;
286 bool level_zero;
287 bool bias;
288 bool lod;
289 bool deriv;
290 bool compare;
291 bool offset;
292
293 LLVMValueRef resource;
294 LLVMValueRef sampler;
295 LLVMValueRef addr;
296 unsigned dmask;
297 bool unorm;
298 bool da;
299 };
300
301 LLVMValueRef ac_build_image_opcode(struct ac_llvm_context *ctx,
302 struct ac_image_args *a);
303 LLVMValueRef ac_build_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
304 LLVMValueRef args[2]);
305 LLVMValueRef ac_build_wqm_vote(struct ac_llvm_context *ctx, LLVMValueRef i1);
306 void ac_build_kill_if_false(struct ac_llvm_context *ctx, LLVMValueRef i1);
307 LLVMValueRef ac_build_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
308 LLVMValueRef offset, LLVMValueRef width,
309 bool is_signed);
310
311 void ac_build_waitcnt(struct ac_llvm_context *ctx, unsigned simm16);
312
313 void ac_get_image_intr_name(const char *base_name,
314 LLVMTypeRef data_type,
315 LLVMTypeRef coords_type,
316 LLVMTypeRef rsrc_type,
317 char *out_name, unsigned out_len);
318
319 void ac_optimize_vs_outputs(struct ac_llvm_context *ac,
320 LLVMValueRef main_fn,
321 uint8_t *vs_output_param_offset,
322 uint32_t num_outputs,
323 uint8_t *num_param_exports);
324 void ac_init_exec_full_mask(struct ac_llvm_context *ctx);
325
326 void ac_declare_lds_as_pointer(struct ac_llvm_context *ac);
327 LLVMValueRef ac_lds_load(struct ac_llvm_context *ctx,
328 LLVMValueRef dw_addr);
329 void ac_lds_store(struct ac_llvm_context *ctx,
330 LLVMValueRef dw_addr, LLVMValueRef value);
331
332 LLVMValueRef ac_find_lsb(struct ac_llvm_context *ctx,
333 LLVMTypeRef dst_type,
334 LLVMValueRef src0);
335
336 LLVMTypeRef ac_array_in_const_addr_space(LLVMTypeRef elem_type);
337
338 #ifdef __cplusplus
339 }
340 #endif
341
342 #endif