radeonsi: fold si_create_function into si_llvm_create_func
[mesa.git] / src / gallium / drivers / radeonsi / si_shader.c
index cfeab51d129f9af7ffca224da2e5ccdb87631381..2e4cf0884ca5e9b0c0adfb9bf0d6035c7d484112 100644 (file)
@@ -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) {
@@ -879,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;
 
@@ -945,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;
@@ -1004,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;
@@ -1053,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;
                        }
@@ -1098,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]);
@@ -1126,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;
@@ -1584,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)
        };
 
@@ -2604,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 =
@@ -2702,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);
@@ -2757,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;
@@ -2841,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);
 
@@ -2853,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;
 
@@ -2902,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);
@@ -3031,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;
 
@@ -3122,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;
@@ -3225,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)
 {
@@ -3811,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) {
@@ -4528,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;
 
 
@@ -4809,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) ||
@@ -4881,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;
@@ -4949,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, "");
@@ -5028,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 &&
@@ -5117,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,
@@ -5157,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;
@@ -5306,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;
@@ -5351,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
@@ -5536,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);
@@ -5773,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;
        }
@@ -5827,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;
                        }
@@ -5895,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;
                        }
@@ -6210,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++) {
@@ -6441,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];
@@ -6586,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,
@@ -6862,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);
@@ -7058,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);