nir: set default lod to texture opcodes that needed it but don't provide it
authorSamuel Iglesias Gonsálvez <siglesias@igalia.com>
Mon, 9 Oct 2017 10:24:06 +0000 (12:24 +0200)
committerSamuel Iglesias Gonsálvez <siglesias@igalia.com>
Fri, 20 Oct 2017 06:29:09 +0000 (08:29 +0200)
v2:
- Use helper to add a new source to the texture instruction.

v3:
- Use nir_tex_instr_src_index() to simplify the patch (Jason).

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_lower_tex.c

index 65681decb1c0d49561536cc8098938a6fd9df0bd..c6f001b62caac07157a4d61bc7a830b7bdb5c596 100644 (file)
@@ -813,6 +813,19 @@ 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 ((nir_tex_instr_src_index(tex, nir_tex_src_lod) == -1) &&
+          (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))) {
+         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;