Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/radeonsi/si_shader_internal.h
4570 views
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 "ac_shader_abi.h"
29
#include "si_shader.h"
30
31
struct pipe_debug_callback;
32
33
#define RADEON_LLVM_MAX_INPUTS 32 * 4
34
35
/* Ideally pass the sample mask input to the PS epilog as v14, which
36
* is its usual location, so that the shader doesn't have to add v_mov.
37
*/
38
#define PS_EPILOG_SAMPLEMASK_MIN_LOC 14
39
40
struct si_shader_output_values {
41
LLVMValueRef values[4];
42
ubyte vertex_stream[4];
43
ubyte semantic;
44
};
45
46
struct si_shader_context {
47
struct ac_llvm_context ac;
48
struct si_shader *shader;
49
struct si_shader_selector *next_shader_sel;
50
struct si_screen *screen;
51
52
gl_shader_stage stage;
53
54
/* For clamping the non-constant index in resource indexing: */
55
unsigned num_const_buffers;
56
unsigned num_shader_buffers;
57
unsigned num_images;
58
unsigned num_samplers;
59
60
struct ac_shader_args args;
61
struct ac_shader_abi abi;
62
63
LLVMValueRef inputs[RADEON_LLVM_MAX_INPUTS];
64
65
LLVMBasicBlockRef merged_wrap_if_entry_block;
66
int merged_wrap_if_label;
67
68
LLVMValueRef main_fn;
69
LLVMTypeRef return_type;
70
71
struct ac_arg const_and_shader_buffers;
72
struct ac_arg samplers_and_images;
73
74
/* For merged shaders, the per-stage descriptors for the stage other
75
* than the one we're processing, used to pass them through from the
76
* first stage to the second.
77
*/
78
struct ac_arg other_const_and_shader_buffers;
79
struct ac_arg other_samplers_and_images;
80
81
struct ac_arg internal_bindings;
82
struct ac_arg bindless_samplers_and_images;
83
struct ac_arg small_prim_cull_info;
84
/* API VS */
85
struct ac_arg vb_descriptors[5];
86
struct ac_arg vertex_index0;
87
/* VS states and layout of LS outputs / TCS inputs at the end
88
* [0] = clamp vertex color
89
* [1] = indexed
90
* [2:3] = NGG: output primitive type
91
* [4:5] = NGG: provoking vertex index
92
* [6] = NGG: streamout queries enabled
93
* [7:10] = NGG: small prim filter precision = num_samples / quant_mode,
94
* but in reality it's: 1/2^n, from 1/16 to 1/4096 = 1/2^4 to 1/2^12
95
* Only the first 4 bits of the exponent are stored.
96
* Set it like this: (fui(num_samples / quant_mode) >> 23)
97
* Expand to FP32 like this: ((0x70 | value) << 23);
98
* With 0x70 = 112, we get 2^(112 + value - 127) = 2^(value - 15)
99
* = 1/2^(15 - value) in FP32
100
* [11:23] = stride between patches in DW = num_inputs * num_vertices * 4
101
* max = 32*32*4 + 32*4
102
* [24:31] = stride between vertices in DW = num_inputs * 4
103
* max = 32*4
104
*/
105
struct ac_arg vs_state_bits;
106
struct ac_arg vs_blit_inputs;
107
108
/* API TCS & TES */
109
/* Layout of TCS outputs in the offchip buffer
110
* # 6 bits
111
* [0:5] = the number of patches per threadgroup - 1, max = 63
112
* # 5 bits
113
* [6:10] = the number of output vertices per patch - 1, max = 31
114
* # 21 bits
115
* [11:31] = the offset of per patch attributes in the buffer in bytes.
116
* max = NUM_PATCHES*32*32*16 = 1M
117
*/
118
struct ac_arg tcs_offchip_layout;
119
120
/* API TCS */
121
/* Offsets where TCS outputs and TCS patch outputs live in LDS:
122
* [0:15] = TCS output patch0 offset / 16, max = NUM_PATCHES * 32 * 32 = 64K (TODO: not enough bits)
123
* [16:31] = TCS output patch0 offset for per-patch / 16
124
* max = (NUM_PATCHES + 1) * 32*32 = 66624 (TODO: not enough bits)
125
*/
126
struct ac_arg tcs_out_lds_offsets;
127
/* Layout of TCS outputs / TES inputs:
128
* [0:12] = stride between output patches in DW, num_outputs * num_vertices * 4
129
* max = 32*32*4 + 32*4 = 4224
130
* [13:18] = gl_PatchVerticesIn, max = 32
131
* [19:31] = high 13 bits of the 32-bit address of tessellation ring buffers
132
*/
133
struct ac_arg tcs_out_lds_layout;
134
135
/* API TES */
136
struct ac_arg tes_offchip_addr;
137
/* API GS */
138
struct ac_arg gs_vtx01_offset; /* in dwords (GFX9) */
139
struct ac_arg gs_vtx23_offset; /* in dwords (GFX9) */
140
struct ac_arg gs_vtx45_offset; /* in dwords (GFX9) */
141
/* PS */
142
struct ac_arg pos_fixed_pt;
143
/* CS */
144
struct ac_arg block_size;
145
struct ac_arg cs_user_data;
146
struct ac_arg cs_shaderbuf[3];
147
struct ac_arg cs_image[3];
148
149
struct ac_llvm_compiler *compiler;
150
151
/* Preloaded descriptors. */
152
LLVMValueRef esgs_ring;
153
LLVMValueRef gsvs_ring[4];
154
LLVMValueRef tess_offchip_ring;
155
156
LLVMValueRef invoc0_tess_factors[6]; /* outer[4], inner[2] */
157
LLVMValueRef gs_next_vertex[4];
158
LLVMValueRef gs_curprim_verts[4];
159
LLVMValueRef gs_generated_prims[4];
160
LLVMValueRef gs_ngg_emit;
161
LLVMValueRef gs_ngg_scratch;
162
LLVMValueRef return_value;
163
};
164
165
static inline struct si_shader_context *si_shader_context_from_abi(struct ac_shader_abi *abi)
166
{
167
return container_of(abi, struct si_shader_context, abi);
168
}
169
170
/* si_shader.c */
171
bool si_is_multi_part_shader(struct si_shader *shader);
172
bool si_is_merged_shader(struct si_shader *shader);
173
void si_add_arg_checked(struct ac_shader_args *args, enum ac_arg_regfile file, unsigned registers,
174
enum ac_arg_type type, struct ac_arg *arg, unsigned idx);
175
void si_init_shader_args(struct si_shader_context *ctx, bool ngg_cull_shader);
176
unsigned si_get_max_workgroup_size(const struct si_shader *shader);
177
bool si_vs_needs_prolog(const struct si_shader_selector *sel,
178
const struct si_vs_prolog_bits *prolog_key,
179
const struct si_shader_key *key, bool ngg_cull_shader);
180
void si_get_vs_prolog_key(const struct si_shader_info *info, unsigned num_input_sgprs,
181
bool ngg_cull_shader, const struct si_vs_prolog_bits *prolog_key,
182
struct si_shader *shader_out, union si_shader_part_key *key);
183
struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,
184
const struct si_shader_key *key,
185
bool *free_nir);
186
bool si_need_ps_prolog(const union si_shader_part_key *key);
187
void si_get_ps_prolog_key(struct si_shader *shader, union si_shader_part_key *key,
188
bool separate_prolog);
189
void si_get_ps_epilog_key(struct si_shader *shader, union si_shader_part_key *key);
190
void si_fix_resource_usage(struct si_screen *sscreen, struct si_shader *shader);
191
192
/* gfx10_shader_ngg.c */
193
bool gfx10_ngg_export_prim_early(struct si_shader *shader);
194
void gfx10_ngg_build_sendmsg_gs_alloc_req(struct si_shader_context *ctx);
195
void gfx10_ngg_build_export_prim(struct si_shader_context *ctx, LLVMValueRef user_edgeflags[3],
196
LLVMValueRef prim_passthrough);
197
void gfx10_emit_ngg_culling_epilogue(struct ac_shader_abi *abi, unsigned max_outputs,
198
LLVMValueRef *addrs);
199
void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);
200
void gfx10_ngg_gs_emit_vertex(struct si_shader_context *ctx, unsigned stream, LLVMValueRef *addrs);
201
void gfx10_ngg_gs_emit_prologue(struct si_shader_context *ctx);
202
void gfx10_ngg_gs_emit_epilogue(struct si_shader_context *ctx);
203
unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader);
204
bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);
205
206
/* si_shader_llvm.c */
207
bool si_compile_llvm(struct si_screen *sscreen, struct si_shader_binary *binary,
208
struct ac_shader_config *conf, struct ac_llvm_compiler *compiler,
209
struct ac_llvm_context *ac, struct pipe_debug_callback *debug,
210
gl_shader_stage stage, const char *name, bool less_optimized);
211
void si_llvm_context_init(struct si_shader_context *ctx, struct si_screen *sscreen,
212
struct ac_llvm_compiler *compiler, unsigned wave_size);
213
void si_llvm_create_func(struct si_shader_context *ctx, const char *name, LLVMTypeRef *return_types,
214
unsigned num_return_elems, unsigned max_workgroup_size);
215
void si_llvm_create_main_func(struct si_shader_context *ctx, bool ngg_cull_shader);
216
void si_llvm_optimize_module(struct si_shader_context *ctx);
217
void si_llvm_dispose(struct si_shader_context *ctx);
218
LLVMValueRef si_buffer_load_const(struct si_shader_context *ctx, LLVMValueRef resource,
219
LLVMValueRef offset);
220
void si_llvm_build_ret(struct si_shader_context *ctx, LLVMValueRef ret);
221
LLVMValueRef si_insert_input_ret(struct si_shader_context *ctx, LLVMValueRef ret,
222
struct ac_arg param, unsigned return_index);
223
LLVMValueRef si_insert_input_ret_float(struct si_shader_context *ctx, LLVMValueRef ret,
224
struct ac_arg param, unsigned return_index);
225
LLVMValueRef si_insert_input_ptr(struct si_shader_context *ctx, LLVMValueRef ret,
226
struct ac_arg param, unsigned return_index);
227
LLVMValueRef si_prolog_get_internal_bindings(struct si_shader_context *ctx);
228
void si_llvm_emit_barrier(struct si_shader_context *ctx);
229
void si_llvm_declare_esgs_ring(struct si_shader_context *ctx);
230
LLVMValueRef si_unpack_param(struct si_shader_context *ctx, struct ac_arg param, unsigned rshift,
231
unsigned bitwidth);
232
LLVMValueRef si_get_primitive_id(struct si_shader_context *ctx, unsigned swizzle);
233
void si_build_wrapper_function(struct si_shader_context *ctx, LLVMValueRef *parts,
234
unsigned num_parts, unsigned main_part,
235
unsigned next_shader_first_part, bool same_thread_count);
236
bool si_llvm_translate_nir(struct si_shader_context *ctx, struct si_shader *shader,
237
struct nir_shader *nir, bool free_nir, bool ngg_cull_shader);
238
bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler,
239
struct si_shader *shader, struct pipe_debug_callback *debug,
240
struct nir_shader *nir, bool free_nir);
241
242
/* si_shader_llvm_gs.c */
243
LLVMValueRef si_is_es_thread(struct si_shader_context *ctx);
244
LLVMValueRef si_is_gs_thread(struct si_shader_context *ctx);
245
void si_llvm_emit_es_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);
246
void si_preload_esgs_ring(struct si_shader_context *ctx);
247
void si_preload_gs_rings(struct si_shader_context *ctx);
248
void si_llvm_build_gs_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);
249
void si_llvm_init_gs_callbacks(struct si_shader_context *ctx);
250
251
/* si_shader_llvm_tess.c */
252
void si_llvm_preload_tes_rings(struct si_shader_context *ctx);
253
void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);
254
void si_llvm_build_tcs_epilog(struct si_shader_context *ctx, union si_shader_part_key *key);
255
void si_llvm_init_tcs_callbacks(struct si_shader_context *ctx);
256
void si_llvm_init_tes_callbacks(struct si_shader_context *ctx, bool ngg_cull_shader);
257
258
/* si_shader_llvm_ps.c */
259
LLVMValueRef si_get_sample_id(struct si_shader_context *ctx);
260
void si_llvm_build_ps_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);
261
void si_llvm_build_ps_epilog(struct si_shader_context *ctx, union si_shader_part_key *key);
262
void si_llvm_build_monolithic_ps(struct si_shader_context *ctx, struct si_shader *shader);
263
void si_llvm_init_ps_callbacks(struct si_shader_context *ctx);
264
265
/* si_shader_llvm_resources.c */
266
void si_llvm_init_resource_callbacks(struct si_shader_context *ctx);
267
268
/* si_shader_llvm_vs.c */
269
void si_llvm_load_vs_inputs(struct si_shader_context *ctx, struct nir_shader *nir);
270
void si_llvm_streamout_store_output(struct si_shader_context *ctx, 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_llvm_emit_streamout(struct si_shader_context *ctx, struct si_shader_output_values *outputs,
275
unsigned noutput, unsigned stream);
276
void si_llvm_build_vs_exports(struct si_shader_context *ctx,
277
struct si_shader_output_values *outputs, unsigned noutput);
278
void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);
279
void si_llvm_build_vs_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);
280
void si_llvm_init_vs_callbacks(struct si_shader_context *ctx, bool ngg_cull_shader);
281
282
#endif
283
284