Module: Mesa
Branch: main
Commit: 10367618da072afc4f19c21ab9b599a23dd5a762
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=10367618da072afc4f19c21ab9b599a23dd5a762

Author: Lucas Fryzek <lfry...@igalia.com>
Date:   Fri Nov 10 15:01:26 2023 -0500

gallivm/nir: Load all inputs into indirect inputs array

The code in `emit_load_var` that will attempt to read indirect inputs
expects the entire array of inputs to be there. Additionally the code
that populates `bld->inputs_array` will populate the array using the count
of `inputs_read`, without ensuring the inputs it copies are the ones read.

This change populates `bld->inputs_array` with the entire contents of 
bld->inputs
so indirect reads will always match up.

Reviewed-by: Dave Airlie <airl...@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26153>

---

 src/gallium/auxiliary/draw/draw_llvm.c         | 3 +++
 src/gallium/auxiliary/gallivm/lp_bld_nir.h     | 1 +
 src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c | 6 +++++-
 src/gallium/auxiliary/gallivm/lp_bld_tgsi.h    | 1 +
 src/gallium/drivers/llvmpipe/lp_state_fs.c     | 1 +
 5 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index f4e0d70cd32..f6f5135e637 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -596,6 +596,7 @@ generate_vs(struct draw_llvm_variant *variant,
       lp_jit_resources_constants(variant->gallivm, variant->resources_type, 
resources_ptr);
    LLVMValueRef ssbos_ptr =
       lp_jit_resources_ssbos(variant->gallivm, variant->resources_type, 
resources_ptr);
+   struct draw_llvm_variant_key *key = &variant->key;
 
    struct lp_build_tgsi_params params;
    memset(&params, 0, sizeof(params));
@@ -605,6 +606,7 @@ generate_vs(struct draw_llvm_variant *variant,
    params.consts_ptr = consts_ptr;
    params.system_values = system_values;
    params.inputs = inputs;
+   params.num_inputs = key->nr_vertex_elements;
    params.context_type = variant->context_type;
    params.context_ptr = context_ptr;
    params.resources_type = variant->resources_type;
@@ -2454,6 +2456,7 @@ draw_gs_llvm_generate(struct draw_llvm *llvm,
                                                                    
variant->resources_type,
                                                                    
resources_ptr);
 
+
    if (llvm->draw->gs.geometry_shader->state.type == PIPE_SHADER_IR_TGSI)
       lp_build_tgsi_soa(variant->gallivm,
                         tokens,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir.h 
b/src/gallium/auxiliary/gallivm/lp_bld_nir.h
index 3ef67ae8a64..4eff207aa25 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_nir.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_nir.h
@@ -275,6 +275,7 @@ struct lp_build_nir_soa_context
    LLVMValueRef consts_ptr;
    const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
    LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS];
+   int num_inputs;
    LLVMTypeRef context_type;
    LLVMValueRef context_ptr;
    LLVMTypeRef resources_type;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c 
b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
index 06dde5c5803..9a730ad6c66 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c
@@ -2196,7 +2196,10 @@ emit_prologue(struct lp_build_nir_soa_context *bld)
 {
    struct gallivm_state * gallivm = bld->bld_base.base.gallivm;
    if (bld->indirects & nir_var_shader_in && !bld->gs_iface && !bld->tcs_iface 
&& !bld->tes_iface) {
-      uint32_t num_inputs = 
util_bitcount64(bld->bld_base.shader->info.inputs_read);
+      uint32_t num_inputs = bld->num_inputs;
+      /* If this is an indirect case, the number of inputs should not be 0 */
+      assert(num_inputs > 0);
+
       unsigned index, chan;
       LLVMTypeRef vec_type = bld->bld_base.base.vec_type;
       LLVMValueRef array_size = lp_build_const_int32(gallivm, num_inputs * 4);
@@ -3037,6 +3040,7 @@ void lp_build_nir_soa_func(struct gallivm_state *gallivm,
    bld.payload_ptr = params->payload_ptr;
    bld.coro = params->coro;
    bld.kernel_args_ptr = params->kernel_args;
+   bld.num_inputs = params->num_inputs;
    bld.indirects = 0;
    if (shader->info.inputs_read_indirectly)
       bld.indirects |= nir_var_shader_in;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h 
b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
index 9ca4c6e380d..dfa467aa2c0 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi.h
@@ -267,6 +267,7 @@ struct lp_build_tgsi_params {
    LLVMValueRef const_sizes_ptr;
    const struct lp_bld_tgsi_system_values *system_values;
    const LLVMValueRef (*inputs)[4];
+   int num_inputs;
    LLVMTypeRef context_type;
    LLVMValueRef context_ptr;
    LLVMTypeRef resources_type;
diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c 
b/src/gallium/drivers/llvmpipe/lp_state_fs.c
index b380f4cd964..21312aa98e2 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_fs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c
@@ -1051,6 +1051,7 @@ generate_fs_loop(struct gallivm_state *gallivm,
    params.consts_ptr = consts_ptr;
    params.system_values = &system_values;
    params.inputs = interp->inputs;
+   params.num_inputs = interp->num_attribs - 1;
    params.context_type = context_type;
    params.context_ptr = context_ptr;
    params.resources_type = resources_type;

Reply via email to