Path: blob/21.2-virgl/src/gallium/drivers/radeonsi/si_shader_internal.h
4570 views
/*1* Copyright 2016 Advanced Micro Devices, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324#ifndef SI_SHADER_PRIVATE_H25#define SI_SHADER_PRIVATE_H2627#include "ac_shader_abi.h"28#include "si_shader.h"2930struct pipe_debug_callback;3132#define RADEON_LLVM_MAX_INPUTS 32 * 43334/* Ideally pass the sample mask input to the PS epilog as v14, which35* is its usual location, so that the shader doesn't have to add v_mov.36*/37#define PS_EPILOG_SAMPLEMASK_MIN_LOC 143839struct si_shader_output_values {40LLVMValueRef values[4];41ubyte vertex_stream[4];42ubyte semantic;43};4445struct si_shader_context {46struct ac_llvm_context ac;47struct si_shader *shader;48struct si_shader_selector *next_shader_sel;49struct si_screen *screen;5051gl_shader_stage stage;5253/* For clamping the non-constant index in resource indexing: */54unsigned num_const_buffers;55unsigned num_shader_buffers;56unsigned num_images;57unsigned num_samplers;5859struct ac_shader_args args;60struct ac_shader_abi abi;6162LLVMValueRef inputs[RADEON_LLVM_MAX_INPUTS];6364LLVMBasicBlockRef merged_wrap_if_entry_block;65int merged_wrap_if_label;6667LLVMValueRef main_fn;68LLVMTypeRef return_type;6970struct ac_arg const_and_shader_buffers;71struct ac_arg samplers_and_images;7273/* For merged shaders, the per-stage descriptors for the stage other74* than the one we're processing, used to pass them through from the75* first stage to the second.76*/77struct ac_arg other_const_and_shader_buffers;78struct ac_arg other_samplers_and_images;7980struct ac_arg internal_bindings;81struct ac_arg bindless_samplers_and_images;82struct ac_arg small_prim_cull_info;83/* API VS */84struct ac_arg vb_descriptors[5];85struct ac_arg vertex_index0;86/* VS states and layout of LS outputs / TCS inputs at the end87* [0] = clamp vertex color88* [1] = indexed89* [2:3] = NGG: output primitive type90* [4:5] = NGG: provoking vertex index91* [6] = NGG: streamout queries enabled92* [7:10] = NGG: small prim filter precision = num_samples / quant_mode,93* but in reality it's: 1/2^n, from 1/16 to 1/4096 = 1/2^4 to 1/2^1294* Only the first 4 bits of the exponent are stored.95* Set it like this: (fui(num_samples / quant_mode) >> 23)96* Expand to FP32 like this: ((0x70 | value) << 23);97* With 0x70 = 112, we get 2^(112 + value - 127) = 2^(value - 15)98* = 1/2^(15 - value) in FP3299* [11:23] = stride between patches in DW = num_inputs * num_vertices * 4100* max = 32*32*4 + 32*4101* [24:31] = stride between vertices in DW = num_inputs * 4102* max = 32*4103*/104struct ac_arg vs_state_bits;105struct ac_arg vs_blit_inputs;106107/* API TCS & TES */108/* Layout of TCS outputs in the offchip buffer109* # 6 bits110* [0:5] = the number of patches per threadgroup - 1, max = 63111* # 5 bits112* [6:10] = the number of output vertices per patch - 1, max = 31113* # 21 bits114* [11:31] = the offset of per patch attributes in the buffer in bytes.115* max = NUM_PATCHES*32*32*16 = 1M116*/117struct ac_arg tcs_offchip_layout;118119/* API TCS */120/* Offsets where TCS outputs and TCS patch outputs live in LDS:121* [0:15] = TCS output patch0 offset / 16, max = NUM_PATCHES * 32 * 32 = 64K (TODO: not enough bits)122* [16:31] = TCS output patch0 offset for per-patch / 16123* max = (NUM_PATCHES + 1) * 32*32 = 66624 (TODO: not enough bits)124*/125struct ac_arg tcs_out_lds_offsets;126/* Layout of TCS outputs / TES inputs:127* [0:12] = stride between output patches in DW, num_outputs * num_vertices * 4128* max = 32*32*4 + 32*4 = 4224129* [13:18] = gl_PatchVerticesIn, max = 32130* [19:31] = high 13 bits of the 32-bit address of tessellation ring buffers131*/132struct ac_arg tcs_out_lds_layout;133134/* API TES */135struct ac_arg tes_offchip_addr;136/* API GS */137struct ac_arg gs_vtx01_offset; /* in dwords (GFX9) */138struct ac_arg gs_vtx23_offset; /* in dwords (GFX9) */139struct ac_arg gs_vtx45_offset; /* in dwords (GFX9) */140/* PS */141struct ac_arg pos_fixed_pt;142/* CS */143struct ac_arg block_size;144struct ac_arg cs_user_data;145struct ac_arg cs_shaderbuf[3];146struct ac_arg cs_image[3];147148struct ac_llvm_compiler *compiler;149150/* Preloaded descriptors. */151LLVMValueRef esgs_ring;152LLVMValueRef gsvs_ring[4];153LLVMValueRef tess_offchip_ring;154155LLVMValueRef invoc0_tess_factors[6]; /* outer[4], inner[2] */156LLVMValueRef gs_next_vertex[4];157LLVMValueRef gs_curprim_verts[4];158LLVMValueRef gs_generated_prims[4];159LLVMValueRef gs_ngg_emit;160LLVMValueRef gs_ngg_scratch;161LLVMValueRef return_value;162};163164static inline struct si_shader_context *si_shader_context_from_abi(struct ac_shader_abi *abi)165{166return container_of(abi, struct si_shader_context, abi);167}168169/* si_shader.c */170bool si_is_multi_part_shader(struct si_shader *shader);171bool si_is_merged_shader(struct si_shader *shader);172void si_add_arg_checked(struct ac_shader_args *args, enum ac_arg_regfile file, unsigned registers,173enum ac_arg_type type, struct ac_arg *arg, unsigned idx);174void si_init_shader_args(struct si_shader_context *ctx, bool ngg_cull_shader);175unsigned si_get_max_workgroup_size(const struct si_shader *shader);176bool si_vs_needs_prolog(const struct si_shader_selector *sel,177const struct si_vs_prolog_bits *prolog_key,178const struct si_shader_key *key, bool ngg_cull_shader);179void si_get_vs_prolog_key(const struct si_shader_info *info, unsigned num_input_sgprs,180bool ngg_cull_shader, const struct si_vs_prolog_bits *prolog_key,181struct si_shader *shader_out, union si_shader_part_key *key);182struct nir_shader *si_get_nir_shader(struct si_shader_selector *sel,183const struct si_shader_key *key,184bool *free_nir);185bool si_need_ps_prolog(const union si_shader_part_key *key);186void si_get_ps_prolog_key(struct si_shader *shader, union si_shader_part_key *key,187bool separate_prolog);188void si_get_ps_epilog_key(struct si_shader *shader, union si_shader_part_key *key);189void si_fix_resource_usage(struct si_screen *sscreen, struct si_shader *shader);190191/* gfx10_shader_ngg.c */192bool gfx10_ngg_export_prim_early(struct si_shader *shader);193void gfx10_ngg_build_sendmsg_gs_alloc_req(struct si_shader_context *ctx);194void gfx10_ngg_build_export_prim(struct si_shader_context *ctx, LLVMValueRef user_edgeflags[3],195LLVMValueRef prim_passthrough);196void gfx10_emit_ngg_culling_epilogue(struct ac_shader_abi *abi, unsigned max_outputs,197LLVMValueRef *addrs);198void gfx10_emit_ngg_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);199void gfx10_ngg_gs_emit_vertex(struct si_shader_context *ctx, unsigned stream, LLVMValueRef *addrs);200void gfx10_ngg_gs_emit_prologue(struct si_shader_context *ctx);201void gfx10_ngg_gs_emit_epilogue(struct si_shader_context *ctx);202unsigned gfx10_ngg_get_scratch_dw_size(struct si_shader *shader);203bool gfx10_ngg_calculate_subgroup_info(struct si_shader *shader);204205/* si_shader_llvm.c */206bool si_compile_llvm(struct si_screen *sscreen, struct si_shader_binary *binary,207struct ac_shader_config *conf, struct ac_llvm_compiler *compiler,208struct ac_llvm_context *ac, struct pipe_debug_callback *debug,209gl_shader_stage stage, const char *name, bool less_optimized);210void si_llvm_context_init(struct si_shader_context *ctx, struct si_screen *sscreen,211struct ac_llvm_compiler *compiler, unsigned wave_size);212void si_llvm_create_func(struct si_shader_context *ctx, const char *name, LLVMTypeRef *return_types,213unsigned num_return_elems, unsigned max_workgroup_size);214void si_llvm_create_main_func(struct si_shader_context *ctx, bool ngg_cull_shader);215void si_llvm_optimize_module(struct si_shader_context *ctx);216void si_llvm_dispose(struct si_shader_context *ctx);217LLVMValueRef si_buffer_load_const(struct si_shader_context *ctx, LLVMValueRef resource,218LLVMValueRef offset);219void si_llvm_build_ret(struct si_shader_context *ctx, LLVMValueRef ret);220LLVMValueRef si_insert_input_ret(struct si_shader_context *ctx, LLVMValueRef ret,221struct ac_arg param, unsigned return_index);222LLVMValueRef si_insert_input_ret_float(struct si_shader_context *ctx, LLVMValueRef ret,223struct ac_arg param, unsigned return_index);224LLVMValueRef si_insert_input_ptr(struct si_shader_context *ctx, LLVMValueRef ret,225struct ac_arg param, unsigned return_index);226LLVMValueRef si_prolog_get_internal_bindings(struct si_shader_context *ctx);227void si_llvm_emit_barrier(struct si_shader_context *ctx);228void si_llvm_declare_esgs_ring(struct si_shader_context *ctx);229LLVMValueRef si_unpack_param(struct si_shader_context *ctx, struct ac_arg param, unsigned rshift,230unsigned bitwidth);231LLVMValueRef si_get_primitive_id(struct si_shader_context *ctx, unsigned swizzle);232void si_build_wrapper_function(struct si_shader_context *ctx, LLVMValueRef *parts,233unsigned num_parts, unsigned main_part,234unsigned next_shader_first_part, bool same_thread_count);235bool si_llvm_translate_nir(struct si_shader_context *ctx, struct si_shader *shader,236struct nir_shader *nir, bool free_nir, bool ngg_cull_shader);237bool si_llvm_compile_shader(struct si_screen *sscreen, struct ac_llvm_compiler *compiler,238struct si_shader *shader, struct pipe_debug_callback *debug,239struct nir_shader *nir, bool free_nir);240241/* si_shader_llvm_gs.c */242LLVMValueRef si_is_es_thread(struct si_shader_context *ctx);243LLVMValueRef si_is_gs_thread(struct si_shader_context *ctx);244void si_llvm_emit_es_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);245void si_preload_esgs_ring(struct si_shader_context *ctx);246void si_preload_gs_rings(struct si_shader_context *ctx);247void si_llvm_build_gs_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);248void si_llvm_init_gs_callbacks(struct si_shader_context *ctx);249250/* si_shader_llvm_tess.c */251void si_llvm_preload_tes_rings(struct si_shader_context *ctx);252void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);253void si_llvm_build_tcs_epilog(struct si_shader_context *ctx, union si_shader_part_key *key);254void si_llvm_init_tcs_callbacks(struct si_shader_context *ctx);255void si_llvm_init_tes_callbacks(struct si_shader_context *ctx, bool ngg_cull_shader);256257/* si_shader_llvm_ps.c */258LLVMValueRef si_get_sample_id(struct si_shader_context *ctx);259void si_llvm_build_ps_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);260void si_llvm_build_ps_epilog(struct si_shader_context *ctx, union si_shader_part_key *key);261void si_llvm_build_monolithic_ps(struct si_shader_context *ctx, struct si_shader *shader);262void si_llvm_init_ps_callbacks(struct si_shader_context *ctx);263264/* si_shader_llvm_resources.c */265void si_llvm_init_resource_callbacks(struct si_shader_context *ctx);266267/* si_shader_llvm_vs.c */268void si_llvm_load_vs_inputs(struct si_shader_context *ctx, struct nir_shader *nir);269void si_llvm_streamout_store_output(struct si_shader_context *ctx, LLVMValueRef const *so_buffers,270LLVMValueRef const *so_write_offsets,271struct pipe_stream_output *stream_out,272struct si_shader_output_values *shader_out);273void si_llvm_emit_streamout(struct si_shader_context *ctx, struct si_shader_output_values *outputs,274unsigned noutput, unsigned stream);275void si_llvm_build_vs_exports(struct si_shader_context *ctx,276struct si_shader_output_values *outputs, unsigned noutput);277void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi, unsigned max_outputs, LLVMValueRef *addrs);278void si_llvm_build_vs_prolog(struct si_shader_context *ctx, union si_shader_part_key *key);279void si_llvm_init_vs_callbacks(struct si_shader_context *ctx, bool ngg_cull_shader);280281#endif282283284