From: Nicolai Hähnle <[email protected]>

The idea is that adding prolog and epilog code will be pulled out into the
caller.
---
 src/gallium/drivers/radeonsi/si_shader.c | 103 +++++++++++++++++--------------
 1 file changed, 58 insertions(+), 45 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader.c 
b/src/gallium/drivers/radeonsi/si_shader.c
index 8871742..6ae63c8 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -6667,54 +6667,29 @@ static void si_eliminate_const_vs_outputs(struct 
si_shader_context *ctx)
                                                            
V_008DFC_SQ_EXP_PARAM + new_count, 0));
                                shader->info.vs_output_param_offset[out] = 
new_count;
                                new_count++;
                                break;
                        }
                }
                shader->info.nr_param_exports = new_count;
        }
 }
 
-int si_compile_tgsi_shader(struct si_screen *sscreen,
-                          LLVMTargetMachineRef tm,
-                          struct si_shader *shader,
-                          bool is_monolithic,
-                          struct pipe_debug_callback *debug)
+static bool si_compile_tgsi_main(struct si_shader_context *ctx,
+                                struct si_shader *shader)
 {
        struct si_shader_selector *sel = shader->selector;
-       struct si_shader_context ctx;
-       struct lp_build_tgsi_context *bld_base;
-       LLVMModuleRef mod;
-       int r = 0;
-
-       /* Dump TGSI code before doing TGSI->LLVM conversion in case the
-        * conversion fails. */
-       if (r600_can_dump_shader(&sscreen->b, sel->info.processor) &&
-           !(sscreen->b.debug_flags & DBG_NO_TGSI)) {
-               tgsi_dump(sel->tokens, 0);
-               si_dump_streamout(&sel->so);
-       }
-
-       si_init_shader_ctx(&ctx, sscreen, shader, tm);
-       ctx.is_monolithic = is_monolithic;
-
-       memset(shader->info.vs_output_param_offset, 0xff,
-              sizeof(shader->info.vs_output_param_offset));
-
-       shader->info.uses_instanceid = sel->info.uses_instanceid;
-
-       bld_base = &ctx.soa.bld_base;
-       ctx.load_system_value = declare_system_value;
+       struct lp_build_tgsi_context *bld_base = &ctx->soa.bld_base;
 
-       switch (ctx.type) {
+       switch (ctx->type) {
        case PIPE_SHADER_VERTEX:
-               ctx.load_input = declare_input_vs;
+               ctx->load_input = declare_input_vs;
                if (shader->key.vs.as_ls)
                        bld_base->emit_epilogue = si_llvm_emit_ls_epilogue;
                else if (shader->key.vs.as_es)
                        bld_base->emit_epilogue = si_llvm_emit_es_epilogue;
                else
                        bld_base->emit_epilogue = si_llvm_emit_vs_epilogue;
                break;
        case PIPE_SHADER_TESS_CTRL:
                bld_base->emit_fetch_funcs[TGSI_FILE_INPUT] = fetch_input_tcs;
                bld_base->emit_fetch_funcs[TGSI_FILE_OUTPUT] = fetch_output_tcs;
@@ -6726,61 +6701,98 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                if (shader->key.tes.as_es)
                        bld_base->emit_epilogue = si_llvm_emit_es_epilogue;
                else
                        bld_base->emit_epilogue = si_llvm_emit_vs_epilogue;
                break;
        case PIPE_SHADER_GEOMETRY:
                bld_base->emit_fetch_funcs[TGSI_FILE_INPUT] = fetch_input_gs;
                bld_base->emit_epilogue = si_llvm_emit_gs_epilogue;
                break;
        case PIPE_SHADER_FRAGMENT:
-               ctx.load_input = declare_input_fs;
-               if (is_monolithic)
+               ctx->load_input = declare_input_fs;
+               if (ctx->is_monolithic)
                        bld_base->emit_epilogue = si_llvm_emit_fs_epilogue;
                else
                        bld_base->emit_epilogue = si_llvm_return_fs_outputs;
                break;
        case PIPE_SHADER_COMPUTE:
-               ctx.declare_memory_region = declare_compute_memory;
+               ctx->declare_memory_region = declare_compute_memory;
                break;
        default:
                assert(!"Unsupported shader type");
-               return -1;
+               return false;
        }
 
-       create_meta_data(&ctx);
-       create_function(&ctx);
-       preload_ring_buffers(&ctx);
+       create_meta_data(ctx);
+       create_function(ctx);
+       preload_ring_buffers(ctx);
 
-       if (ctx.is_monolithic && sel->type == PIPE_SHADER_FRAGMENT &&
+       if (ctx->is_monolithic && sel->type == PIPE_SHADER_FRAGMENT &&
            shader->key.ps.prolog.poly_stipple) {
-               LLVMValueRef list = LLVMGetParam(ctx.main_fn,
+               LLVMValueRef list = LLVMGetParam(ctx->main_fn,
                                                 SI_PARAM_RW_BUFFERS);
-               si_llvm_emit_polygon_stipple(&ctx, list,
+               si_llvm_emit_polygon_stipple(ctx, list,
                                             SI_PARAM_POS_FIXED_PT);
        }
 
-       if (ctx.type == PIPE_SHADER_GEOMETRY) {
+       if (ctx->type == PIPE_SHADER_GEOMETRY) {
                int i;
                for (i = 0; i < 4; i++) {
-                       ctx.gs_next_vertex[i] =
+                       ctx->gs_next_vertex[i] =
                                lp_build_alloca(bld_base->base.gallivm,
-                                               ctx.i32, "");
+                                               ctx->i32, "");
                }
        }
 
        if (!lp_build_tgsi_llvm(bld_base, sel->tokens)) {
                fprintf(stderr, "Failed to translate shader from TGSI to 
LLVM\n");
-               goto out;
+               return false;
        }
 
-       si_llvm_build_ret(&ctx, ctx.return_value);
+       si_llvm_build_ret(ctx, ctx->return_value);
+       return true;
+}
+
+int si_compile_tgsi_shader(struct si_screen *sscreen,
+                          LLVMTargetMachineRef tm,
+                          struct si_shader *shader,
+                          bool is_monolithic,
+                          struct pipe_debug_callback *debug)
+{
+       struct si_shader_selector *sel = shader->selector;
+       struct si_shader_context ctx;
+       struct lp_build_tgsi_context *bld_base;
+       LLVMModuleRef mod;
+       int r = -1;
+
+       /* Dump TGSI code before doing TGSI->LLVM conversion in case the
+        * conversion fails. */
+       if (r600_can_dump_shader(&sscreen->b, sel->info.processor) &&
+           !(sscreen->b.debug_flags & DBG_NO_TGSI)) {
+               tgsi_dump(sel->tokens, 0);
+               si_dump_streamout(&sel->so);
+       }
+
+       si_init_shader_ctx(&ctx, sscreen, shader, tm);
+       ctx.is_monolithic = is_monolithic;
+
+       memset(shader->info.vs_output_param_offset, 0xff,
+              sizeof(shader->info.vs_output_param_offset));
+
+       shader->info.uses_instanceid = sel->info.uses_instanceid;
+
+       bld_base = &ctx.soa.bld_base;
+       ctx.load_system_value = declare_system_value;
+
+       if (!si_compile_tgsi_main(&ctx, shader))
+               goto out;
+
        mod = bld_base->base.gallivm->module;
 
        /* Dump LLVM IR before any optimization passes */
        if (sscreen->b.debug_flags & DBG_PREOPT_IR &&
            r600_can_dump_shader(&sscreen->b, ctx.type))
                LLVMDumpModule(mod);
 
        si_llvm_finalize_module(&ctx,
                                    r600_extra_shader_checks(&sscreen->b, 
ctx.type));
 
@@ -6887,20 +6899,21 @@ int si_compile_tgsi_shader(struct si_screen *sscreen,
                shader->gs_copy_shader->selector = shader->selector;
                ctx.shader = shader->gs_copy_shader;
                if ((r = si_generate_gs_copy_shader(sscreen, &ctx,
                                                    shader, debug))) {
                        free(shader->gs_copy_shader);
                        shader->gs_copy_shader = NULL;
                        goto out;
                }
        }
 
+       r = 0;
 out:
        return r;
 }
 
 /**
  * Create, compile and return a shader part (prolog or epilog).
  *
  * \param sscreen      screen
  * \param list         list of shader parts of the same category
  * \param key          shader part key
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to