[Mesa-dev] [PATCH v3 1/4] nir: set default lod to texture opcodes that needed it but don't provide it

Samuel Iglesias Gonsálvez siglesias at igalia.com
Wed Oct 18 07:54:28 UTC 2017


v2:
- Use helper to add a new source to the texture instruction.

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
---
 src/compiler/nir/nir_lower_tex.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 65681decb1c..676c0c21e7a 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -813,6 +813,29 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
          progress = true;
          continue;
       }
+
+      /* TXF, TXS and TXL require a LOD but not everything we implement using those
+       * three opcodes provides one.  Provide a default LOD of 0.
+       */
+      if (tex->op == nir_texop_txf || tex->op == nir_texop_txs ||
+          tex->op == nir_texop_txl || tex->op == nir_texop_query_levels ||
+          (tex->op == nir_texop_tex && b->shader->stage != MESA_SHADER_FRAGMENT)) {
+         int i;
+         bool has_lod = false;
+         for (i = 0; i < tex->num_srcs; i++) {
+            if (tex->src[i].src_type == nir_tex_src_lod) {
+               has_lod = true;
+               break;
+            }
+         }
+
+         if (!has_lod) {
+            b->cursor = nir_before_instr(&tex->instr);
+            nir_tex_instr_add_src(tex, nir_tex_src_lod, nir_src_for_ssa(nir_imm_int(b, 0)));
+            progress = true;
+            continue;
+         }
+      }
    }
 
    return progress;
-- 
2.14.2



More information about the mesa-dev mailing list