X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgallium%2Fdrivers%2Fradeonsi%2Fsi_shader.c;h=2e4cf0884ca5e9b0c0adfb9bf0d6035c7d484112;hb=37916a66b1ab8943e052874632785f033f2f04e2;hp=392972256178eb978e313aa9e24772c877402204;hpb=363b4027fcbae3cc69ff6e55989f900398c3968a;p=mesa.git diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 39297225617..2e4cf0884ca 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -272,7 +272,7 @@ static LLVMValueRef get_tcs_out_patch_stride(struct si_shader_context *ctx) if (ctx->shader->key.mono.u.ff_tcs_inputs_to_copy) return si_unpack_param(ctx, ctx->tcs_out_lds_layout, 0, 13); - const struct tgsi_shader_info *info = &ctx->shader->selector->info; + const struct si_shader_info *info = &ctx->shader->selector->info; unsigned tcs_out_vertices = info->properties[TGSI_PROPERTY_TCS_VERTICES_OUT]; unsigned vertex_dw_stride = get_tcs_out_vertex_dw_stride_constant(ctx); unsigned num_patch_outputs = util_last_bit64(ctx->shader->selector->patch_outputs_written); @@ -383,7 +383,7 @@ void si_llvm_load_input_vs( unsigned input_index, LLVMValueRef out[4]) { - const struct tgsi_shader_info *info = &ctx->shader->selector->info; + const struct si_shader_info *info = &ctx->shader->selector->info; unsigned vs_blit_property = info->properties[TGSI_PROPERTY_VS_BLIT_SGPRS_AMD]; if (vs_blit_property) { @@ -687,7 +687,6 @@ static LLVMValueRef get_tcs_tes_buffer_address(struct si_shader_context *ctx, return base_addr; } -/* This is a generic helper that can be shared by the NIR and TGSI backends */ static LLVMValueRef get_tcs_tes_buffer_address_from_generic_indices( struct si_shader_context *ctx, LLVMValueRef vertex_index, @@ -880,7 +879,7 @@ static LLVMValueRef si_nir_load_tcs_varyings(struct ac_shader_abi *abi, bool load_input) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; LLVMValueRef dw_addr, stride; ubyte name, index; @@ -946,7 +945,7 @@ LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi, bool load_input) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; LLVMValueRef base, addr; driver_location = driver_location / 4; @@ -969,8 +968,7 @@ LLVMValueRef si_nir_load_input_tes(struct ac_shader_abi *abi, /* TODO: This will generate rather ordinary llvm code, although it * should be easy for the optimiser to fix up. In future we might want - * to refactor buffer_load(), but for now this maximises code sharing - * between the NIR and TGSI backends. + * to refactor buffer_load(). */ LLVMValueRef value[4]; for (unsigned i = 0; i < num_components; i++) { @@ -1006,7 +1004,7 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, unsigned writemask) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; const unsigned component = var->data.location_frac; unsigned driver_location = var->data.driver_location; LLVMValueRef dw_addr, stride; @@ -1055,7 +1053,7 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, name == TGSI_SEMANTIC_TESSOUTER) { /* The epilog doesn't read LDS if invocation 0 defines tess factors. */ skip_lds_store = !info->reads_tessfactor_outputs && - ctx->shader->selector->tcs_info.tessfactors_are_def_in_all_invocs; + ctx->shader->selector->info.tessfactors_are_def_in_all_invocs; is_tess_factor = true; is_tess_inner = name == TGSI_SEMANTIC_TESSINNER; } @@ -1100,7 +1098,7 @@ static void si_nir_store_output_tcs(struct ac_shader_abi *abi, /* Write tess factors into VGPRs for the epilog. */ if (is_tess_factor && - ctx->shader->selector->tcs_info.tessfactors_are_def_in_all_invocs) { + ctx->shader->selector->info.tessfactors_are_def_in_all_invocs) { if (!is_tess_inner) { LLVMBuildStore(ctx->ac.builder, value, /* outer */ ctx->invoc0_tess_factors[chan]); @@ -1128,7 +1126,7 @@ static LLVMValueRef si_llvm_load_input_gs(struct ac_shader_abi *abi, struct si_shader_context *ctx = si_shader_context_from_abi(abi); struct si_shader *shader = ctx->shader; LLVMValueRef vtx_offset, soffset; - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; unsigned semantic_name = info->input_semantic_name[input_index]; unsigned semantic_index = info->input_semantic_index[input_index]; unsigned param; @@ -1586,7 +1584,7 @@ static LLVMValueRef load_const_buffer_desc_fast_path(struct si_shader_context *c LLVMValueRef desc_elems[] = { desc0, desc1, - LLVMConstInt(ctx->i32, (sel->info.const_file_max[0] + 1) * 16, 0), + LLVMConstInt(ctx->i32, sel->info.constbuf0_num_slots * 16, 0), LLVMConstInt(ctx->i32, rsrc3, false) }; @@ -2410,7 +2408,7 @@ static void si_write_tess_factors(struct si_shader_context *ctx, if (shader->key.part.tcs.epilog.prim_mode == PIPE_PRIM_LINES) { /* For isolines, the hardware expects tess factors in the - * reverse order from what GLSL / TGSI specify. + * reverse order from what NIR specifies. */ LLVMValueRef tmp = out[0]; out[0] = out[1]; @@ -2606,7 +2604,7 @@ static void si_llvm_emit_tcs_epilogue(struct ac_shader_abi *abi, ret = LLVMBuildInsertValue(builder, ret, rel_patch_id, vgpr++, ""); ret = LLVMBuildInsertValue(builder, ret, invocation_id, vgpr++, ""); - if (ctx->shader->selector->tcs_info.tessfactors_are_def_in_all_invocs) { + if (ctx->shader->selector->info.tessfactors_are_def_in_all_invocs) { vgpr++; /* skip the tess factor LDS offset */ for (unsigned i = 0; i < 6; i++) { LLVMValueRef value = @@ -2704,7 +2702,7 @@ static void si_llvm_emit_ls_epilogue(struct ac_shader_abi *abi, { struct si_shader_context *ctx = si_shader_context_from_abi(abi); struct si_shader *shader = ctx->shader; - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; unsigned i, chan; LLVMValueRef vertex_id = ac_get_arg(&ctx->ac, ctx->rel_auto_id); LLVMValueRef vertex_dw_stride = get_tcs_in_vertex_dw_stride(ctx); @@ -2759,7 +2757,7 @@ static void si_llvm_emit_es_epilogue(struct ac_shader_abi *abi, { struct si_shader_context *ctx = si_shader_context_from_abi(abi); struct si_shader *es = ctx->shader; - struct tgsi_shader_info *info = &es->selector->info; + struct si_shader_info *info = &es->selector->info; LLVMValueRef lds_base = NULL; unsigned chan; int i; @@ -2843,7 +2841,7 @@ static void si_llvm_emit_gs_epilogue(struct ac_shader_abi *abi, LLVMValueRef *addrs) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info UNUSED *info = &ctx->shader->selector->info; + struct si_shader_info UNUSED *info = &ctx->shader->selector->info; assert(info->num_outputs <= max_outputs); @@ -2855,7 +2853,7 @@ static void si_llvm_emit_vs_epilogue(struct ac_shader_abi *abi, LLVMValueRef *addrs) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; struct si_shader_output_values *outputs = NULL; int i,j; @@ -2904,7 +2902,7 @@ static void si_llvm_emit_prim_discard_cs_epilogue(struct ac_shader_abi *abi, LLVMValueRef *addrs) { struct si_shader_context *ctx = si_shader_context_from_abi(abi); - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; LLVMValueRef pos[4] = {}; assert(info->num_outputs <= max_outputs); @@ -3033,7 +3031,7 @@ static void si_llvm_return_fs_outputs(struct ac_shader_abi *abi, { struct si_shader_context *ctx = si_shader_context_from_abi(abi); struct si_shader *shader = ctx->shader; - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; LLVMBuilderRef builder = ctx->ac.builder; unsigned i, j, first_vgpr, vgpr; @@ -3060,11 +3058,11 @@ static void si_llvm_return_fs_outputs(struct ac_shader_abi *abi, break; case TGSI_SEMANTIC_POSITION: depth = LLVMBuildLoad(builder, - addrs[4 * i + 2], ""); + addrs[4 * i + 0], ""); break; case TGSI_SEMANTIC_STENCIL: stencil = LLVMBuildLoad(builder, - addrs[4 * i + 1], ""); + addrs[4 * i + 0], ""); break; case TGSI_SEMANTIC_SAMPLEMASK: samplemask = LLVMBuildLoad(builder, @@ -3124,7 +3122,7 @@ static void si_llvm_emit_vertex(struct ac_shader_abi *abi, return; } - struct tgsi_shader_info *info = &ctx->shader->selector->info; + struct si_shader_info *info = &ctx->shader->selector->info; struct si_shader *shader = ctx->shader; LLVMValueRef soffset = ac_get_arg(&ctx->ac, ctx->gs2vs_offset); LLVMValueRef gs_next_vertex; @@ -3227,27 +3225,6 @@ static void si_llvm_emit_barrier(struct si_shader_context *ctx) ac_build_s_barrier(&ctx->ac); } -void si_create_function(struct si_shader_context *ctx, - const char *name, - LLVMTypeRef *returns, unsigned num_returns, - unsigned max_workgroup_size) -{ - si_llvm_create_func(ctx, name, returns, num_returns); - ctx->return_value = LLVMGetUndef(ctx->return_type); - - if (ctx->screen->info.address32_hi) { - ac_llvm_add_target_dep_function_attr(ctx->main_fn, - "amdgpu-32bit-address-high-bits", - ctx->screen->info.address32_hi); - } - - LLVMAddTargetDependentFunctionAttr(ctx->main_fn, - "no-signed-zeros-fp-math", - "true"); - - ac_llvm_set_workgroup_size(ctx->main_fn, max_workgroup_size); -} - static void declare_streamout_params(struct si_shader_context *ctx, struct pipe_stream_output_info *so) { @@ -3813,8 +3790,8 @@ static void create_function(struct si_shader_context *ctx) return; } - si_create_function(ctx, "main", returns, num_returns, - si_get_max_workgroup_size(shader)); + si_llvm_create_func(ctx, "main", returns, num_returns, + si_get_max_workgroup_size(shader)); /* Reserve register locations for VGPR inputs the PS prolog may need. */ if (ctx->type == PIPE_SHADER_FRAGMENT && !ctx->shader->is_monolithic) { @@ -4530,7 +4507,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen, struct si_shader *shader; LLVMBuilderRef builder; struct si_shader_output_values outputs[SI_MAX_VS_OUTPUTS]; - struct tgsi_shader_info *gsinfo = &gs_selector->info; + struct si_shader_info *gsinfo = &gs_selector->info; int i; @@ -4811,7 +4788,7 @@ static void si_dump_shader_key(const struct si_shader *shader, FILE *f) static void si_optimize_vs_outputs(struct si_shader_context *ctx) { struct si_shader *shader = ctx->shader; - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; if ((ctx->type != PIPE_SHADER_VERTEX && ctx->type != PIPE_SHADER_TESS_EVAL) || @@ -4883,8 +4860,8 @@ static void si_llvm_emit_kill(struct ac_shader_abi *abi, LLVMValueRef visible) ac_build_kill_if_false(&ctx->ac, visible); } -static bool si_compile_tgsi_main(struct si_shader_context *ctx, - struct nir_shader *nir, bool free_nir) +static bool si_build_main_function(struct si_shader_context *ctx, + struct nir_shader *nir, bool free_nir) { struct si_shader *shader = ctx->shader; struct si_shader_selector *sel = shader->selector; @@ -4951,7 +4928,7 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx, preload_ring_buffers(ctx); if (ctx->type == PIPE_SHADER_TESS_CTRL && - sel->tcs_info.tessfactors_are_def_in_all_invocs) { + sel->info.tessfactors_are_def_in_all_invocs) { for (unsigned i = 0; i < 6; i++) { ctx->invoc0_tess_factors[i] = ac_build_alloca_undef(&ctx->ac, ctx->i32, ""); @@ -5030,7 +5007,6 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx, */ if (ctx->screen->info.chip_class >= GFX9) { if (!shader->is_monolithic && - sel->info.num_instructions > 1 && /* not empty shader */ (shader->key.as_es || shader->key.as_ls) && (ctx->type == PIPE_SHADER_TESS_EVAL || (ctx->type == PIPE_SHADER_VERTEX && @@ -5119,7 +5095,7 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx, * \param shader_out The vertex shader, or the next shader if merging LS+HS or ES+GS. * \param key Output shader part key. */ -static void si_get_vs_prolog_key(const struct tgsi_shader_info *info, +static void si_get_vs_prolog_key(const struct si_shader_info *info, unsigned num_input_sgprs, const struct si_vs_prolog_bits *prolog_key, struct si_shader *shader_out, @@ -5159,7 +5135,7 @@ static void si_get_ps_prolog_key(struct si_shader *shader, union si_shader_part_key *key, bool separate_prolog) { - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; memset(key, 0, sizeof(*key)); key->ps_prolog.states = shader->key.part.ps.prolog; @@ -5308,7 +5284,7 @@ static bool si_need_ps_prolog(const union si_shader_part_key *key) static void si_get_ps_epilog_key(struct si_shader *shader, union si_shader_part_key *key) { - struct tgsi_shader_info *info = &shader->selector->info; + struct si_shader_info *info = &shader->selector->info; memset(key, 0, sizeof(*key)); key->ps_epilog.colors_written = info->colors_written; key->ps_epilog.writes_z = info->writes_z; @@ -5353,8 +5329,7 @@ static void si_build_gs_prolog_function(struct si_shader_context *ctx, } /* Create the function. */ - si_create_function(ctx, "gs_prolog", returns, num_sgprs + num_vgprs, - 0); + si_llvm_create_func(ctx, "gs_prolog", returns, num_sgprs + num_vgprs, 0); func = ctx->main_fn; /* Set the full EXEC mask for the prolog, because we are only fiddling @@ -5538,8 +5513,8 @@ static void si_build_wrapper_function(struct si_shader_context *ctx, unreachable("unexpected type"); } - si_create_function(ctx, "wrapper", returns, num_returns, - si_get_max_workgroup_size(ctx->shader)); + si_llvm_create_func(ctx, "wrapper", returns, num_returns, + si_get_max_workgroup_size(ctx->shader)); if (is_merged_shader(ctx)) ac_init_exec_full_mask(&ctx->ac); @@ -5759,10 +5734,10 @@ int si_compile_shader(struct si_screen *sscreen, struct nir_shader *nir = get_nir_shader(sel, &free_nir); int r = -1; - /* Dump TGSI code before doing TGSI->LLVM conversion in case the + /* Dump NIR before doing NIR->LLVM conversion in case the * conversion fails. */ if (si_can_dump_shader(sscreen, sel->type) && - !(sscreen->debug_flags & DBG(NO_TGSI))) { + !(sscreen->debug_flags & DBG(NO_NIR))) { nir_print_shader(nir, stderr); si_dump_streamout(&sel->so); } @@ -5775,7 +5750,7 @@ int si_compile_shader(struct si_screen *sscreen, shader->info.uses_instanceid = sel->info.uses_instanceid; - if (!si_compile_tgsi_main(&ctx, nir, free_nir)) { + if (!si_build_main_function(&ctx, nir, free_nir)) { si_llvm_dispose(&ctx); return -1; } @@ -5829,7 +5804,7 @@ int si_compile_shader(struct si_screen *sscreen, shader_ls.is_monolithic = true; si_llvm_context_set_ir(&ctx, &shader_ls); - if (!si_compile_tgsi_main(&ctx, nir, free_nir)) { + if (!si_build_main_function(&ctx, nir, free_nir)) { si_llvm_dispose(&ctx); return -1; } @@ -5897,7 +5872,7 @@ int si_compile_shader(struct si_screen *sscreen, shader_es.is_monolithic = true; si_llvm_context_set_ir(&ctx, &shader_es); - if (!si_compile_tgsi_main(&ctx, nir, free_nir)) { + if (!si_build_main_function(&ctx, nir, free_nir)) { si_llvm_dispose(&ctx); return -1; } @@ -6212,7 +6187,7 @@ static void si_build_vs_prolog_function(struct si_shader_context *ctx, returns[num_returns++] = ctx->f32; /* Create the function. */ - si_create_function(ctx, "vs_prolog", returns, num_returns, 0); + si_llvm_create_func(ctx, "vs_prolog", returns, num_returns, 0); func = ctx->main_fn; for (i = 0; i < num_input_vgprs; i++) { @@ -6443,8 +6418,8 @@ static void si_build_tcs_epilog_function(struct si_shader_context *ctx, ac_add_arg(&ctx->args, AC_ARG_VGPR, 1, AC_ARG_INT, &tess_factors[i]); /* Create the function. */ - si_create_function(ctx, "tcs_epilog", NULL, 0, - ctx->screen->info.chip_class >= GFX7 ? 128 : 0); + si_llvm_create_func(ctx, "tcs_epilog", NULL, 0, + ctx->screen->info.chip_class >= GFX7 ? 128 : 0); ac_declare_lds_as_pointer(&ctx->ac); LLVMValueRef invoc0_tess_factors[6]; @@ -6588,7 +6563,7 @@ static void si_build_ps_prolog_function(struct si_shader_context *ctx, return_types[num_returns++] = ctx->f32; /* Create the function. */ - si_create_function(ctx, "ps_prolog", return_types, num_returns, 0); + si_llvm_create_func(ctx, "ps_prolog", return_types, num_returns, 0); func = ctx->main_fn; /* Copy inputs to outputs. This should be no-op, as the registers match, @@ -6864,7 +6839,7 @@ static void si_build_ps_epilog_function(struct si_shader_context *ctx, ac_add_arg(&ctx->args, AC_ARG_VGPR, 1, AC_ARG_FLOAT, NULL); /* Create the function. */ - si_create_function(ctx, "ps_epilog", NULL, 0, 0); + si_llvm_create_func(ctx, "ps_epilog", NULL, 0, 0); /* Disable elimination of unused inputs. */ ac_llvm_add_target_dep_function_attr(ctx->main_fn, "InitialPSInputAddr", 0xffffff); @@ -7060,9 +7035,10 @@ static void si_fix_resource_usage(struct si_screen *sscreen, } } -bool si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler *compiler, - struct si_shader *shader, - struct pipe_debug_callback *debug) +bool si_create_shader_variant(struct si_screen *sscreen, + struct ac_llvm_compiler *compiler, + struct si_shader *shader, + struct pipe_debug_callback *debug) { struct si_shader_selector *sel = shader->selector; struct si_shader *mainp = *si_get_main_shader_part(sel, &shader->key); @@ -7103,7 +7079,7 @@ bool si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler *compil if (!mainp) return false; - /* Copy the compiled TGSI shader data over. */ + /* Copy the compiled shader data over. */ shader->is_binary_shared = true; shader->binary = mainp->binary; shader->config = mainp->config;