pan/bi: Allow vertex txl with lod=0 as compact
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 27 May 2020 15:41:42 +0000 (11:41 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 27 May 2020 20:49:44 +0000 (16:49 -0400)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5232>

src/panfrost/bifrost/bifrost_compile.c

index 468e3b5c3b0b776a71da614ae58d668971f2e270..417c6de7b062a3cfd67a4966f44aaee406871562 100644 (file)
@@ -900,6 +900,34 @@ emit_tex_full(bi_context *ctx, nir_tex_instr *instr)
         unreachable("stub");
 }
 
+/* Normal textures ops are tex for frag shaders and txl for vertex shaders with
+ * lod a constant 0. Anything else needs a full texture op. */
+
+static bool
+bi_is_normal_tex(gl_shader_stage stage, nir_tex_instr *instr)
+{
+        if (stage == MESA_SHADER_FRAGMENT)
+                return instr->op == nir_texop_tex;
+
+        if (instr->op != nir_texop_txl)
+                return false;
+
+        for (unsigned i = 0; i < instr->num_srcs; ++i) {
+                if (instr->src[i].src_type != nir_tex_src_lod)
+                        continue;
+
+                nir_src src = instr->src[i].src;
+
+                if (!nir_src_is_const(src))
+                        continue;
+
+                if (nir_src_as_uint(src) != 0)
+                        continue;
+        }
+
+        return true;
+}
+
 static void
 emit_tex(bi_context *ctx, nir_tex_instr *instr)
 {
@@ -907,7 +935,7 @@ emit_tex(bi_context *ctx, nir_tex_instr *instr)
         unsigned sz =  nir_dest_bit_size(instr->dest);
         instr->dest_type = base | sz;
 
-        bool is_normal = instr->op == nir_texop_tex;
+        bool is_normal = bi_is_normal_tex(ctx->stage, instr);
         bool is_2d = instr->sampler_dim == GLSL_SAMPLER_DIM_2D ||
                 instr->sampler_dim == GLSL_SAMPLER_DIM_EXTERNAL;
         bool is_f = base == nir_type_float && (sz == 16 || sz == 32);