gallivm: rework translator to allow per-impl work.
authorDave Airlie <airlied@redhat.com>
Tue, 27 Oct 2020 00:00:14 +0000 (10:00 +1000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 01:57:50 +0000 (01:57 +0000)
This allows a function implementation to be targetted, this will
only be used by the compute shader paths, so keep a compat path
for all the others.

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24687>

src/gallium/auxiliary/gallivm/lp_bld_nir.c
src/gallium/auxiliary/gallivm/lp_bld_nir.h
src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c
src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c

index 7fd2050..aab7c80 100644 (file)
@@ -2870,10 +2870,9 @@ lp_build_nir_prepasses(struct nir_shader *nir)
 }
 
 bool lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
-                       struct nir_shader *nir)
+                       struct nir_shader *nir,
+                       nir_function_impl *impl)
 {
-   struct nir_function *func;
-
    nir_foreach_shader_out_variable(variable, nir)
       handle_shader_output_decl(bld_base, nir, variable);
 
@@ -2899,17 +2898,15 @@ bool lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
                                             _mesa_key_pointer_equal);
    bld_base->range_ht = _mesa_pointer_hash_table_create(NULL);
 
-   func = (struct nir_function *)exec_list_get_head(&nir->functions);
-
-   nir_foreach_reg_decl(reg, func->impl) {
+   nir_foreach_reg_decl(reg, impl) {
       LLVMTypeRef type = get_register_type(bld_base, reg);
       LLVMValueRef reg_alloc = lp_build_alloca(bld_base->base.gallivm,
                                                type, "reg");
       _mesa_hash_table_insert(bld_base->regs, reg, reg_alloc);
    }
-   nir_index_ssa_defs(func->impl);
-   bld_base->ssa_defs = calloc(func->impl->ssa_alloc, sizeof(LLVMValueRef));
-   visit_cf_list(bld_base, &func->impl->body);
+   nir_index_ssa_defs(impl);
+   bld_base->ssa_defs = calloc(impl->ssa_alloc, sizeof(LLVMValueRef));
+   visit_cf_list(bld_base, &impl->body);
 
    free(bld_base->ssa_defs);
    ralloc_free(bld_base->vars);
index 443a7b4..14e77d7 100644 (file)
@@ -40,6 +40,12 @@ void lp_build_nir_soa(struct gallivm_state *gallivm,
                       const struct lp_build_tgsi_params *params,
                       LLVMValueRef (*outputs)[4]);
 
+void lp_build_nir_soa_func(struct gallivm_state *gallivm,
+                           struct nir_shader *shader,
+                           nir_function_impl *impl,
+                           const struct lp_build_tgsi_params *params,
+                           LLVMValueRef (*outputs)[4]);
+
 void lp_build_nir_aos(struct gallivm_state *gallivm,
                       struct nir_shader *shader,
                       struct lp_type type,
@@ -300,7 +306,8 @@ lp_build_nir_prepasses(struct nir_shader *nir);
 
 bool
 lp_build_nir_llvm(struct lp_build_nir_context *bld_base,
-                  struct nir_shader *nir);
+                  struct nir_shader *nir,
+                  nir_function_impl *impl);
 
 void
 lp_build_opt_nir(struct nir_shader *nir);
index f1da5b1..6ede095 100644 (file)
@@ -397,5 +397,6 @@ lp_build_nir_aos(struct gallivm_state *gallivm,
    lp_build_nir_prepasses(shader);
    NIR_PASS_V(shader, nir_move_vec_src_uses_to_dest);
    NIR_PASS_V(shader, nir_lower_vec_to_regs, NULL, NULL);
-   lp_build_nir_llvm(&bld.bld_base, shader);
+   lp_build_nir_llvm(&bld.bld_base, shader,
+                     nir_shader_get_entrypoint(shader));
 }
index cd4438e..baa533e 100644 (file)
@@ -2800,10 +2800,11 @@ emit_clock(struct lp_build_nir_context *bld_base,
    dst[1] = lp_build_broadcast_scalar(uint_bld, hi);
 }
 
-void lp_build_nir_soa(struct gallivm_state *gallivm,
-                      struct nir_shader *shader,
-                      const struct lp_build_tgsi_params *params,
-                      LLVMValueRef (*outputs)[4])
+void lp_build_nir_soa_func(struct gallivm_state *gallivm,
+                           struct nir_shader *shader,
+                           nir_function_impl *impl,
+                           const struct lp_build_tgsi_params *params,
+                           LLVMValueRef (*outputs)[4])
 {
    struct lp_build_nir_soa_context bld;
    const struct lp_type type = params->type;
@@ -2973,8 +2974,7 @@ void lp_build_nir_soa(struct gallivm_state *gallivm,
    }
 
    emit_prologue(&bld);
-   lp_build_nir_prepasses(shader);
-   lp_build_nir_llvm(&bld.bld_base, shader);
+   lp_build_nir_llvm(&bld.bld_base, shader, impl);
 
    if (bld.gs_iface) {
       LLVMBuilderRef builder = bld.bld_base.base.gallivm->builder;
@@ -2996,3 +2996,14 @@ void lp_build_nir_soa(struct gallivm_state *gallivm,
    }
    lp_exec_mask_fini(&bld.exec_mask);
 }
+
+void lp_build_nir_soa(struct gallivm_state *gallivm,
+                      struct nir_shader *shader,
+                      const struct lp_build_tgsi_params *params,
+                      LLVMValueRef (*outputs)[4])
+{
+   lp_build_nir_prepasses(shader);
+   lp_build_nir_soa_func(gallivm, shader,
+                         nir_shader_get_entrypoint(shader),
+                         params, outputs);
+}