From b8e93abd113941debba723b1b1284c581505e6f1 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 27 Oct 2020 10:00:14 +1000 Subject: [PATCH] gallivm: rework translator to allow per-impl work. 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 Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_nir.c | 15 ++++++--------- src/gallium/auxiliary/gallivm/lp_bld_nir.h | 9 ++++++++- src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c | 3 ++- src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 23 +++++++++++++++++------ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.c b/src/gallium/auxiliary/gallivm/lp_bld_nir.c index 7fd2050..aab7c80 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.c @@ -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); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h b/src/gallium/auxiliary/gallivm/lp_bld_nir.h index 443a7b4..14e77d7 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h @@ -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); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c index f1da5b1..6ede095 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_aos.c @@ -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)); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index cd4438e..baa533e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -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); +} -- 2.7.4