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

Author: Marek Olšák <[email protected]>
Date:   Wed Aug  3 10:49:51 2022 -0400

ttn: set the correct sampler declaration type in the presense of txs and lod

We used the result type of lod and txs for sampler declarations,
which broke following instructions that are not lod and txs.

Use the sampler type from TGSI if it's present, not the result type
of lod and txs.

Reviewed-by: Emma Anholt <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17692>

---

 src/gallium/auxiliary/nir/tgsi_to_nir.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c 
b/src/gallium/auxiliary/nir/tgsi_to_nir.c
index 0521c24934e..31c9809f616 100644
--- a/src/gallium/auxiliary/nir/tgsi_to_nir.c
+++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c
@@ -1436,19 +1436,20 @@ ttn_tex(struct ttn_compile *c, nir_alu_dest dest, 
nir_ssa_def **src)
     */
    sview = tgsi_inst->Src[samp].Register.Index;
 
+   nir_alu_type sampler_type =
+      sview < c->num_samp_types ? c->samp_types[sview] : nir_type_float32;
+
    if (op == nir_texop_lod) {
       instr->dest_type = nir_type_float32;
-   } else if (sview < c->num_samp_types) {
-      instr->dest_type = c->samp_types[sview];
    } else {
-      instr->dest_type = nir_type_float32;
+      instr->dest_type = sampler_type;
    }
 
    nir_variable *var =
       get_sampler_var(c, sview, instr->sampler_dim,
                       instr->is_shadow,
                       instr->is_array,
-                      base_type_for_alu_type(instr->dest_type),
+                      base_type_for_alu_type(sampler_type),
                       op);
 
    nir_deref_instr *deref = nir_build_deref_var(b, var);
@@ -1609,13 +1610,16 @@ ttn_txq(struct ttn_compile *c, nir_alu_dest dest, 
nir_ssa_def **src)
                     &qlv->sampler_dim, &qlv->is_shadow, &qlv->is_array);
 
    assert(tgsi_inst->Src[1].Register.File == TGSI_FILE_SAMPLER);
-   int tex_index = tgsi_inst->Src[1].Register.Index;
+   int sview = tgsi_inst->Src[1].Register.Index;
+
+   nir_alu_type sampler_type =
+      sview < c->num_samp_types ? c->samp_types[sview] : nir_type_float32;
 
    nir_variable *var =
-      get_sampler_var(c, tex_index, txs->sampler_dim,
+      get_sampler_var(c, sview, txs->sampler_dim,
                       txs->is_shadow,
                       txs->is_array,
-                      base_type_for_alu_type(txs->dest_type),
+                      base_type_for_alu_type(sampler_type),
                       nir_texop_txs);
 
    nir_deref_instr *deref = nir_build_deref_var(b, var);

Reply via email to