Mesa (master): nir/lower_tex: ignore texture_index if tex_instr has deref src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 5 08:41:34 UTC 2021


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

Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date:   Tue Mar 30 21:37:32 2021 +0200

nir/lower_tex: ignore texture_index if tex_instr has deref src

texture_index is meaningless when a tex_instr has deref src.
Use var->data.binding instead.

This fixes the incorrect lowering on radeonsi where the same
lowering steps was applied to all tex_instr based on the needs
of the first one (since texture_index is always 0).

CC: mesa-stable
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Acked-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9931>

---

 src/compiler/nir/nir_lower_tex.c | 86 +++++++++++++++++++++++++---------------
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 96ffb4e66e3..857bc9391e5 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -302,16 +302,17 @@ static void
 convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
                    nir_ssa_def *y, nir_ssa_def *u, nir_ssa_def *v,
                    nir_ssa_def *a,
-                   const nir_lower_tex_options *options)
+                   const nir_lower_tex_options *options,
+                   unsigned texture_index)
 {
 
    const float *offset_vals;
    const nir_const_value_3_4 *m;
    assert((options->bt709_external & options->bt2020_external) == 0);
-   if (options->bt709_external & (1 << tex->texture_index)) {
+   if (options->bt709_external & (1u << texture_index)) {
       m = &bt709_csc_coeffs;
       offset_vals = bt709_csc_offsets;
-   } else if (options->bt2020_external & (1 << tex->texture_index)) {
+   } else if (options->bt2020_external & (1u << texture_index)) {
       m = &bt2020_csc_coeffs;
       offset_vals = bt2020_csc_offsets;
    } else {
@@ -342,7 +343,8 @@ convert_yuv_to_rgb(nir_builder *b, nir_tex_instr *tex,
 
 static void
 lower_y_uv_external(nir_builder *b, nir_tex_instr *tex,
-                    const nir_lower_tex_options *options)
+                    const nir_lower_tex_options *options,
+                    unsigned texture_index)
 {
    b->cursor = nir_after_instr(&tex->instr);
 
@@ -354,12 +356,14 @@ lower_y_uv_external(nir_builder *b, nir_tex_instr *tex,
                       nir_channel(b, uv, 0),
                       nir_channel(b, uv, 1),
                       nir_imm_float(b, 1.0f),
-                      options);
+                      options,
+                      texture_index);
 }
 
 static void
 lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex,
-                     const nir_lower_tex_options *options)
+                     const nir_lower_tex_options *options,
+                     unsigned texture_index)
 {
    b->cursor = nir_after_instr(&tex->instr);
 
@@ -372,12 +376,14 @@ lower_y_u_v_external(nir_builder *b, nir_tex_instr *tex,
                       nir_channel(b, u, 0),
                       nir_channel(b, v, 0),
                       nir_imm_float(b, 1.0f),
-                      options);
+                      options,
+                      texture_index);
 }
 
 static void
 lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex,
-                       const nir_lower_tex_options *options)
+                       const nir_lower_tex_options *options,
+                       unsigned texture_index)
 {
    b->cursor = nir_after_instr(&tex->instr);
 
@@ -389,12 +395,14 @@ lower_yx_xuxv_external(nir_builder *b, nir_tex_instr *tex,
                       nir_channel(b, xuxv, 1),
                       nir_channel(b, xuxv, 3),
                       nir_imm_float(b, 1.0f),
-                      options);
+                      options,
+                      texture_index);
 }
 
 static void
 lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex,
-                       const nir_lower_tex_options *options)
+                       const nir_lower_tex_options *options,
+                       unsigned texture_index)
 {
   b->cursor = nir_after_instr(&tex->instr);
 
@@ -406,12 +414,14 @@ lower_xy_uxvx_external(nir_builder *b, nir_tex_instr *tex,
                      nir_channel(b, uxvx, 0),
                      nir_channel(b, uxvx, 2),
                      nir_imm_float(b, 1.0f),
-                     options);
+                     options,
+                     texture_index);
 }
 
 static void
 lower_ayuv_external(nir_builder *b, nir_tex_instr *tex,
-                    const nir_lower_tex_options *options)
+                    const nir_lower_tex_options *options,
+                    unsigned texture_index)
 {
   b->cursor = nir_after_instr(&tex->instr);
 
@@ -422,12 +432,14 @@ lower_ayuv_external(nir_builder *b, nir_tex_instr *tex,
                      nir_channel(b, ayuv, 1),
                      nir_channel(b, ayuv, 0),
                      nir_channel(b, ayuv, 3),
-                     options);
+                     options,
+                     texture_index);
 }
 
 static void
 lower_xyuv_external(nir_builder *b, nir_tex_instr *tex,
-                    const nir_lower_tex_options *options)
+                    const nir_lower_tex_options *options,
+                    unsigned texture_index)
 {
   b->cursor = nir_after_instr(&tex->instr);
 
@@ -438,12 +450,14 @@ lower_xyuv_external(nir_builder *b, nir_tex_instr *tex,
                      nir_channel(b, xyuv, 1),
                      nir_channel(b, xyuv, 0),
                      nir_imm_float(b, 1.0f),
-                     options);
+                     options,
+                     texture_index);
 }
 
 static void
 lower_yuv_external(nir_builder *b, nir_tex_instr *tex,
-                   const nir_lower_tex_options *options)
+                   const nir_lower_tex_options *options,
+                   unsigned texture_index)
 {
   b->cursor = nir_after_instr(&tex->instr);
 
@@ -454,7 +468,8 @@ lower_yuv_external(nir_builder *b, nir_tex_instr *tex,
                      nir_channel(b, yuv, 1),
                      nir_channel(b, yuv, 2),
                      nir_imm_float(b, 1.0f),
-                     options);
+                     options,
+                     texture_index);
 }
 
 /*
@@ -1149,38 +1164,45 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_y_uv_external) {
-         lower_y_uv_external(b, tex, options);
+      unsigned texture_index = tex->texture_index;
+      int tex_index = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref);
+      if (tex_index >= 0) {
+         nir_deref_instr *deref = nir_src_as_deref(tex->src[tex_index].src);
+         texture_index = nir_deref_instr_get_variable(deref)->data.binding;
+      }
+
+      if ((1u << texture_index) & options->lower_y_uv_external) {
+         lower_y_uv_external(b, tex, options, texture_index);
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_y_u_v_external) {
-         lower_y_u_v_external(b, tex, options);
+      if ((1u << texture_index) & options->lower_y_u_v_external) {
+         lower_y_u_v_external(b, tex, options, texture_index);
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_yx_xuxv_external) {
-         lower_yx_xuxv_external(b, tex, options);
+      if ((1u << texture_index) & options->lower_yx_xuxv_external) {
+         lower_yx_xuxv_external(b, tex, options, texture_index);
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_xy_uxvx_external) {
-         lower_xy_uxvx_external(b, tex, options);
+      if ((1u << texture_index) & options->lower_xy_uxvx_external) {
+         lower_xy_uxvx_external(b, tex, options, texture_index);
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_ayuv_external) {
-         lower_ayuv_external(b, tex, options);
+      if ((1u << texture_index) & options->lower_ayuv_external) {
+         lower_ayuv_external(b, tex, options, texture_index);
          progress = true;
       }
 
-      if ((1 << tex->texture_index) & options->lower_xyuv_external) {
-         lower_xyuv_external(b, tex, options);
+      if ((1u << texture_index) & options->lower_xyuv_external) {
+         lower_xyuv_external(b, tex, options, texture_index);
          progress = true;
       }
 
       if ((1 << tex->texture_index) & options->lower_yuv_external) {
-         lower_yuv_external(b, tex, options);
+         lower_yuv_external(b, tex, options, texture_index);
          progress = true;
       }
 
@@ -1194,7 +1216,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
       }
 
-      if (((1 << tex->texture_index) & options->swizzle_result) &&
+      if (((1u << texture_index) & options->swizzle_result) &&
           !nir_tex_instr_is_query(tex) &&
           !(tex->is_shadow && tex->is_new_style_shadow)) {
          swizzle_result(b, tex, options->swizzles[tex->texture_index]);
@@ -1202,7 +1224,7 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
       }
 
       /* should be after swizzle so we know which channels are rgb: */
-      if (((1 << tex->texture_index) & options->lower_srgb) &&
+      if (((1u << texture_index) & options->lower_srgb) &&
           !nir_tex_instr_is_query(tex) && !tex->is_shadow) {
          linearize_srgb_result(b, tex);
          progress = true;



More information about the mesa-commit mailing list