radeonsi: remove llvm_type_is_64bit
[mesa.git] / src / gallium / drivers / radeonsi / si_shader_internal.h
1 /*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef SI_SHADER_PRIVATE_H
26 #define SI_SHADER_PRIVATE_H
27
28 #include "si_shader.h"
29 #include "ac_shader_abi.h"
30
31 #include <llvm-c/Core.h>
32 #include <llvm-c/TargetMachine.h>
33
34 struct pipe_debug_callback;
35
36 #define RADEON_LLVM_MAX_INPUTS 32 * 4
37
38 /* Ideally pass the sample mask input to the PS epilog as v14, which
39 * is its usual location, so that the shader doesn't have to add v_mov.
40 */
41 #define PS_EPILOG_SAMPLEMASK_MIN_LOC 14
42
43 struct si_shader_output_values {
44 LLVMValueRef values[4];
45 unsigned semantic_name;
46 unsigned semantic_index;
47 ubyte vertex_stream[4];
48 };
49
50 struct si_shader_context {
51 struct ac_llvm_context ac;
52 struct si_shader *shader;
53 struct si_screen *screen;
54
55 unsigned type; /* PIPE_SHADER_* specifies the type of shader. */
56
57 /* For clamping the non-constant index in resource indexing: */
58 unsigned num_const_buffers;
59 unsigned num_shader_buffers;
60 unsigned num_images;
61 unsigned num_samplers;
62
63 struct ac_shader_args args;
64 struct ac_shader_abi abi;
65
66 LLVMValueRef inputs[RADEON_LLVM_MAX_INPUTS];
67
68 LLVMBasicBlockRef merged_wrap_if_entry_block;
69 int merged_wrap_if_label;
70
71 LLVMValueRef main_fn;
72 LLVMTypeRef return_type;
73
74 struct ac_arg const_and_shader_buffers;
75 struct ac_arg samplers_and_images;
76
77 /* For merged shaders, the per-stage descriptors for the stage other
78 * than the one we're processing, used to pass them through from the
79 * first stage to the second.
80 */
81 struct ac_arg other_const_and_shader_buffers;
82 struct ac_arg other_samplers_and_images;
83
84 struct ac_arg rw_buffers;
85 struct ac_arg bindless_samplers_and_images;
86 /* Common inputs for merged shaders. */
87 struct ac_arg merged_wave_info;
88 struct ac_arg merged_scratch_offset;
89 /* API VS */
90 struct ac_arg vertex_buffers;
91 struct ac_arg vb_descriptors[5];
92 struct ac_arg rel_auto_id;
93 struct ac_arg vs_prim_id;
94 struct ac_arg vertex_index0;
95 /* VS states and layout of LS outputs / TCS inputs at the end
96 * [0] = clamp vertex color
97 * [1] = indexed
98 * [2:3] = NGG: output primitive type
99 * [4:5] = NGG: provoking vertex index
100 * [6] = NGG: streamout queries enabled
101 * [11:23] = stride between patches in DW = num_inputs * num_vertices * 4
102 * max = 32*32*4 + 32*4
103 * [24:31] = stride between vertices in DW = num_inputs * 4
104 * max = 32*4
105 */
106 struct ac_arg vs_state_bits;
107 struct ac_arg vs_blit_inputs;
108 /* HW VS */
109 struct ac_arg streamout_config;
110 struct ac_arg streamout_write_index;
111 struct ac_arg streamout_offset[4];
112
113 /* API TCS & TES */
114 /* Layout of TCS outputs in the offchip buffer
115 * # 6 bits
116 * [0:5] = the number of patches per threadgroup, max = NUM_PATCHES (40)
117 * # 6 bits
118 * [6:11] = the number of output vertices per patch, max = 32
119 * # 20 bits
120 * [12:31] = the offset of per patch attributes in the buffer in bytes.
121 * max = NUM_PATCHES*32*32*16
122 */
123 struct ac_arg tcs_offchip_layout;
124
125 /* API TCS */
126 /* Offsets where TCS outputs and TCS patch outputs live in LDS:
127 * [0:15] = TCS output patch0 offset / 16, max = NUM_PATCHES * 32 * 32
128 * [16:31] = TCS output patch0 offset for per-patch / 16
129 * max = (NUM_PATCHES + 1) * 32*32
130 */
131 struct ac_arg tcs_out_lds_offsets;
132 /* Layout of TCS outputs / TES inputs:
133 * [0:12] = stride between output patches in DW, num_outputs * num_vertices * 4
134 * max = 32*32*4 + 32*4
135 * [13:18] = gl_PatchVerticesIn, max = 32
136 * [19:31] = high 13 bits of the 32-bit address of tessellation ring buffers
137 */
138 struct ac_arg tcs_out_lds_layout;
139 struct ac_arg tcs_offchip_offset;
140 struct ac_arg tcs_factor_offset;
141
142 /* API TES */
143 struct ac_arg tes_offchip_addr;
144 struct ac_arg tes_u;
145 struct ac_arg tes_v;
146 struct ac_arg tes_rel_patch_id;
147 /* HW ES */
148 struct ac_arg es2gs_offset;
149 /* HW GS */
150 /* On gfx10:
151 * - bits 0..11: ordered_wave_id
152 * - bits 12..20: number of vertices in group
153 * - bits 22..30: number of primitives in group
154 */
155 struct ac_arg gs_tg_info;
156 /* API GS */
157 struct ac_arg gs2vs_offset;
158 struct ac_arg gs_wave_id; /* GFX6 */
159 struct ac_arg gs_vtx_offset[6]; /* in dwords (GFX6) */
160 struct ac_arg gs_vtx01_offset; /* in dwords (GFX9) */
161 struct ac_arg gs_vtx23_offset; /* in dwords (GFX9) */
162 struct ac_arg gs_vtx45_offset; /* in dwords (GFX9) */
163 /* PS */
164 struct ac_arg pos_fixed_pt;
165 /* CS */
166 struct ac_arg block_size;
167 struct ac_arg cs_user_data;
168
169 struct ac_llvm_compiler *compiler;
170
171 /* Preloaded descriptors. */
172 LLVMValueRef esgs_ring;
173 LLVMValueRef gsvs_ring[4];
174 LLVMValueRef tess_offchip_ring;
175
176 LLVMValueRef invoc0_tess_factors[6]; /* outer[4], inner[2] */
177 LLVMValueRef gs_next_vertex[4];
178 LLVMValueRef gs_curprim_verts[4];
179 LLVMValueRef gs_generated_prims[4];
180 LLVMValueRef gs_ngg_emit;
181 LLVMValueRef gs_ngg_scratch;
182 LLVMValueRef postponed_kill;
183 LLVMValueRef return_value;
184
185 LLVMTypeRef voidt;
186 LLVMTypeRef i1;
187 LLVMTypeRef i8;
188 LLVMTypeRef i32;
189 LLVMTypeRef i64;
190 LLVMTypeRef i128;
191 LLVMTypeRef f32;
192 LLVMTypeRef v2i32;
193 LLVMTypeRef v4i32;
194 LLVMTypeRef v4f32;
195 LLVMTypeRef v8i32;
196
197 LLVMValueRef i32_0;
198 LLVMValueRef i32_1;
199 LLVMValueRef i1false;
200 LLVMValueRef i1true;
201 };
202
203 static inline struct si_shader_context *
204 si_shader_context_from_abi(struct ac_shader_abi *abi)
205 {
206 struct si_shader_context *ctx = NULL;
207 return container_of(abi, ctx, abi);
208 }
209
210 unsigned si_llvm_compile(LLVMModuleRef M, struct si_shader_binary *binary,
211 struct ac_llvm_compiler *compiler,
212 struct pipe_debug_callback *debug,
213 bool less_optimized, unsigned wave_size);
214
215 LLVMValueRef si_llvm_bound_index(struct si_shader_context *ctx,
216 LLVMValueRef index,
217 unsigned num);
218
219 void si_llvm_context_init(struct si_shader_context *ctx,
220 struct si_screen *sscreen,
221 struct ac_llvm_compiler *compiler,
222 unsigned wave_size);
223 void si_llvm_context_set_ir(struct si_shader_context *ctx,
224 struct si_shader *shader);
225
226 void si_llvm_create_func(struct si_shader_context *ctx, const char *name,
227 LLVMTypeRef *return_types, unsigned num_return_elems,
228 unsigned max_workgroup_size);
229
230 void si_llvm_dispose(struct si_shader_context *ctx);
231
232 void si_llvm_optimize_module(struct si_shader_context *ctx);
233
234 LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi,
235 LLVMTypeRef type,
236 LLVMValueRef vertex_index,
237 LLVMValueRef param_index,
238 unsigned const_index,
239 unsigned location,
240 unsigned driver_location,
241 unsigned component,
242 unsigned num_components,
243 bool is_patch,
244 bool is_compact,
245 bool load_input);
246 bool si_is_merged_shader(struct si_shader_context *ctx);
247 LLVMValueRef si_get_sample_id(struct si_shader_context *ctx);
248 LLVMValueRef si_load_sampler_desc(struct si_shader_context *ctx,
249 LLVMValueRef list, LLVMValueRef index,
250 enum ac_descriptor_type type);
251 LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
252 LLVMValueRef list, LLVMValueRef index,
253 enum ac_descriptor_type desc_type,
254 bool uses_store, bool bindless);
255 LLVMValueRef si_buffer_load_const(struct si_shader_context *ctx,
256 LLVMValueRef resource, LLVMValueRef offset);
257 void si_llvm_build_ret(struct si_shader_context *ctx, LLVMValueRef ret);
258 LLVMValueRef si_prolog_get_rw_buffers(struct si_shader_context *ctx);
259 LLVMValueRef si_build_gather_64bit(struct si_shader_context *ctx,
260 LLVMTypeRef type, LLVMValueRef val1,
261 LLVMValueRef val2);
262 void si_llvm_emit_barrier(struct si_shader_context *ctx);
263 void si_declare_compute_memory(struct si_shader_context *ctx);
264 LLVMValueRef si_get_primitive_id(struct si_shader_context *ctx,
265 unsigned swizzle);
266 void si_llvm_export_vs(struct si_shader_context *ctx,
267 struct si_shader_output_values *outputs,
268 unsigned noutput);
269 void si_emit_streamout_output(struct si_shader_context *ctx,
270 LLVMValueRef const *so_buffers,
271 LLVMValueRef const *so_write_offsets,
272 struct pipe_stream_output *stream_out,
273 struct si_shader_output_values *shader_out);
274 void si_add_arg_checked(struct ac_shader_args *args,
275 enum ac_arg_regfile file,
276 unsigned registers, enum ac_arg_type type,
277 struct ac_arg *arg,
278 unsigned idx);
279
280 void si_llvm_load_input_vs(
281 struct si_shader_context *ctx,
282 unsigned input_index,
283 LLVMValueRef out[4]);
284
285 bool si_nir_build_llvm(struct si_shader_context *ctx, struct nir_shader *nir);
286
287 LLVMValueRef si_unpack_param(struct si_shader_context *ctx,
288 struct ac_arg param, unsigned rshift,
289 unsigned bitwidth);
290 LLVMValueRef si_is_es_thread(struct si_shader_context *ctx);
291 LLVMValueRef si_is_gs_thread(struct si_shader_context *ctx);
292 void si_build_wrapper_function(struct si_shader_context *ctx, LLVMValueRef *parts,
293 unsigned num_parts, unsigned main_part,
294 unsigned next_shader_first_part);
295 bool si_need_ps_prolog(const union si_shader_part_key *key);
296 void si_get_ps_prolog_key(struct si_shader *shader,
297 union si_shader_part_key *key,
298 bool separate_prolog);
299 void si_get_ps_epilog_key(struct si_shader *shader,
300 union si_shader_part_key *key);
301 LLVMValueRef si_insert_input_ret(struct si_shader_context *ctx, LLVMValueRef ret,
302 struct ac_arg param, unsigned return_index);
303 LLVMValueRef si_insert_input_ret_float(struct si_shader_context *ctx, LLVMValueRef ret,
304 struct ac_arg param, unsigned return_index);
305 LLVMValueRef si_insert_input_ptr(struct si_shader_context *ctx, LLVMValueRef ret,
306 struct ac_arg param, unsigned return_index);
307
308 void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi,
309 unsigned max_outputs,
310 LLVMValueRef *addrs);
311 void gfx10_ngg_gs_emit_vertex(struct si_shader_context *ctx,
312 unsigned stream,
313 LLVMValueRef *addrs);
314 void gfx10_ngg_gs_emit_prologue(struct si_shader_context *ctx);
315 void gfx10_ngg_gs_emit_epilogue(struct si_shader_context *ctx);
316 void gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);
317
318 /* si_shader_llvm_tess.c */
319 void si_llvm_preload_tes_rings(struct si_shader_context *ctx);
320 void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, unsigned max_outputs,
321 LLVMValueRef *addrs);
322 void si_llvm_build_tcs_epilog(struct si_shader_context *ctx,
323 union si_shader_part_key *key);
324 void si_llvm_init_tcs_callbacks(struct si_shader_context *ctx);
325 void si_llvm_init_tes_callbacks(struct si_shader_context *ctx);
326
327 /* si_shader_llvm_ps.c */
328 void si_llvm_build_ps_prolog(struct si_shader_context *ctx,
329 union si_shader_part_key *key);
330 void si_llvm_build_ps_epilog(struct si_shader_context *ctx,
331 union si_shader_part_key *key);
332 void si_llvm_build_monolithic_ps(struct si_shader_context *ctx,
333 struct si_shader *shader);
334 void si_llvm_init_ps_callbacks(struct si_shader_context *ctx);
335
336 #endif