radeonsi: move SI.vs.load.input building into amd/common
[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 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct ac_llvm_context {
36 LLVMContextRef context;
37 LLVMModuleRef module;
38 LLVMBuilderRef builder;
39
40 LLVMTypeRef voidt;
41 LLVMTypeRef i1;
42 LLVMTypeRef i8;
43 LLVMTypeRef i32;
44 LLVMTypeRef f32;
45 LLVMTypeRef v4i32;
46 LLVMTypeRef v4f32;
47 LLVMTypeRef v16i8;
48
49 unsigned range_md_kind;
50 unsigned invariant_load_md_kind;
51 unsigned uniform_md_kind;
52 unsigned fpmath_md_kind;
53 LLVMValueRef fpmath_md_2p5_ulp;
54 LLVMValueRef empty_md;
55 };
56
57 void
58 ac_llvm_context_init(struct ac_llvm_context *ctx, LLVMContextRef context);
59
60 LLVMValueRef
61 ac_emit_llvm_intrinsic(struct ac_llvm_context *ctx, const char *name,
62 LLVMTypeRef return_type, LLVMValueRef *params,
63 unsigned param_count, unsigned attrib_mask);
64
65 void ac_build_type_name_for_intr(LLVMTypeRef type, char *buf, unsigned bufsize);
66
67 LLVMValueRef
68 ac_build_gather_values_extended(struct ac_llvm_context *ctx,
69 LLVMValueRef *values,
70 unsigned value_count,
71 unsigned value_stride,
72 bool load);
73 LLVMValueRef
74 ac_build_gather_values(struct ac_llvm_context *ctx,
75 LLVMValueRef *values,
76 unsigned value_count);
77
78 LLVMValueRef
79 ac_emit_fdiv(struct ac_llvm_context *ctx,
80 LLVMValueRef num,
81 LLVMValueRef den);
82
83 void
84 ac_prepare_cube_coords(struct ac_llvm_context *ctx,
85 bool is_deriv, bool is_array,
86 LLVMValueRef *coords_arg,
87 LLVMValueRef *derivs_arg);
88
89
90 LLVMValueRef
91 ac_build_fs_interp(struct ac_llvm_context *ctx,
92 LLVMValueRef llvm_chan,
93 LLVMValueRef attr_number,
94 LLVMValueRef params,
95 LLVMValueRef i,
96 LLVMValueRef j);
97
98 LLVMValueRef
99 ac_build_fs_interp_mov(struct ac_llvm_context *ctx,
100 LLVMValueRef parameter,
101 LLVMValueRef llvm_chan,
102 LLVMValueRef attr_number,
103 LLVMValueRef params);
104
105 LLVMValueRef
106 ac_build_gep0(struct ac_llvm_context *ctx,
107 LLVMValueRef base_ptr,
108 LLVMValueRef index);
109
110 void
111 ac_build_indexed_store(struct ac_llvm_context *ctx,
112 LLVMValueRef base_ptr, LLVMValueRef index,
113 LLVMValueRef value);
114
115 LLVMValueRef
116 ac_build_indexed_load(struct ac_llvm_context *ctx,
117 LLVMValueRef base_ptr, LLVMValueRef index,
118 bool uniform);
119
120 LLVMValueRef
121 ac_build_indexed_load_const(struct ac_llvm_context *ctx,
122 LLVMValueRef base_ptr, LLVMValueRef index);
123
124 void
125 ac_build_buffer_store_dword(struct ac_llvm_context *ctx,
126 LLVMValueRef rsrc,
127 LLVMValueRef vdata,
128 unsigned num_channels,
129 LLVMValueRef voffset,
130 LLVMValueRef soffset,
131 unsigned inst_offset,
132 bool glc,
133 bool slc,
134 bool writeonly_memory,
135 bool has_add_tid);
136 LLVMValueRef
137 ac_build_buffer_load(struct ac_llvm_context *ctx,
138 LLVMValueRef rsrc,
139 int num_channels,
140 LLVMValueRef vindex,
141 LLVMValueRef voffset,
142 LLVMValueRef soffset,
143 unsigned inst_offset,
144 unsigned glc,
145 unsigned slc,
146 bool readonly_memory);
147
148 LLVMValueRef ac_build_buffer_load_format(struct ac_llvm_context *ctx,
149 LLVMValueRef rsrc,
150 LLVMValueRef vindex,
151 LLVMValueRef voffset,
152 bool readonly_memory);
153
154 LLVMValueRef
155 ac_get_thread_id(struct ac_llvm_context *ctx);
156
157 #define AC_TID_MASK_TOP_LEFT 0xfffffffc
158 #define AC_TID_MASK_TOP 0xfffffffd
159 #define AC_TID_MASK_LEFT 0xfffffffe
160
161 LLVMValueRef
162 ac_emit_ddxy(struct ac_llvm_context *ctx,
163 bool has_ds_bpermute,
164 uint32_t mask,
165 int idx,
166 LLVMValueRef lds,
167 LLVMValueRef val);
168
169 #define AC_SENDMSG_GS 2
170 #define AC_SENDMSG_GS_DONE 3
171
172 #define AC_SENDMSG_GS_OP_NOP (0 << 4)
173 #define AC_SENDMSG_GS_OP_CUT (1 << 4)
174 #define AC_SENDMSG_GS_OP_EMIT (2 << 4)
175 #define AC_SENDMSG_GS_OP_EMIT_CUT (3 << 4)
176
177 void ac_emit_sendmsg(struct ac_llvm_context *ctx,
178 uint32_t msg,
179 LLVMValueRef wave_id);
180
181 LLVMValueRef ac_emit_imsb(struct ac_llvm_context *ctx,
182 LLVMValueRef arg,
183 LLVMTypeRef dst_type);
184
185 LLVMValueRef ac_emit_umsb(struct ac_llvm_context *ctx,
186 LLVMValueRef arg,
187 LLVMTypeRef dst_type);
188
189 LLVMValueRef ac_emit_clamp(struct ac_llvm_context *ctx, LLVMValueRef value);
190
191 struct ac_export_args {
192 LLVMValueRef out[4];
193 unsigned target;
194 unsigned enabled_channels;
195 bool compr;
196 bool done;
197 bool valid_mask;
198 };
199
200 void ac_emit_export(struct ac_llvm_context *ctx, struct ac_export_args *a);
201
202 enum ac_image_opcode {
203 ac_image_sample,
204 ac_image_gather4,
205 ac_image_load,
206 ac_image_load_mip,
207 ac_image_get_lod,
208 ac_image_get_resinfo,
209 };
210
211 struct ac_image_args {
212 enum ac_image_opcode opcode;
213 bool level_zero;
214 bool bias;
215 bool lod;
216 bool deriv;
217 bool compare;
218 bool offset;
219
220 LLVMValueRef resource;
221 LLVMValueRef sampler;
222 LLVMValueRef addr;
223 unsigned dmask;
224 bool unorm;
225 bool da;
226 };
227
228 LLVMValueRef ac_emit_image_opcode(struct ac_llvm_context *ctx,
229 struct ac_image_args *a);
230 LLVMValueRef ac_emit_cvt_pkrtz_f16(struct ac_llvm_context *ctx,
231 LLVMValueRef args[2]);
232 void ac_emit_kill(struct ac_llvm_context *ctx, LLVMValueRef value);
233 LLVMValueRef ac_emit_bfe(struct ac_llvm_context *ctx, LLVMValueRef input,
234 LLVMValueRef offset, LLVMValueRef width,
235 bool is_signed);
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif