nir/lower_mediump: Add an option to only fold if all tex sources can be folded.
authorGeorg Lehmann <dadschoorse@gmail.com>
Wed, 6 Jul 2022 15:00:34 +0000 (17:00 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 21 Jul 2022 19:15:03 +0000 (19:15 +0000)
Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16978>

src/compiler/nir/nir.h
src/compiler/nir/nir_lower_mediump.c

index 35d4ff5..82a2177 100644 (file)
@@ -5343,6 +5343,7 @@ bool nir_unpack_16bit_varying_slots(nir_shader *nir, nir_variable_mode modes);
 struct nir_fold_tex_srcs_options {
    unsigned sampler_dims;
    unsigned src_types;
+   bool only_fold_all; /* Only fold sources if all of them can be folded. */
 };
 
 struct nir_fold_16bit_tex_image_options {
index 54ad83b..7a89827 100644 (file)
@@ -692,7 +692,7 @@ fold_16bit_tex_srcs(nir_builder *b, nir_tex_instr *tex,
    if (!(options->sampler_dims & BITFIELD_BIT(tex->sampler_dim)))
       return false;
 
-   bool changed = false;
+   unsigned fold_srcs = 0;
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       /* Filter out sources that should be ignored. */
       if (!(BITFIELD_BIT(tex->src[i].src_type) & options->src_types))
@@ -707,14 +707,19 @@ fold_16bit_tex_srcs(nir_builder *b, nir_tex_instr *tex,
        * because it's out of bounds and the higher bits don't
        * matter.
        */
-      if (!can_fold_16bit_src(src->ssa, src_type, false))
-         continue;
+      if (can_fold_16bit_src(src->ssa, src_type, false))
+         fold_srcs |= (1 << i);
+      else if (options->only_fold_all)
+         return false;
+   }
 
+   u_foreach_bit(i, fold_srcs) {
+      nir_src *src = &tex->src[i].src;
+      nir_alu_type src_type = nir_tex_instr_src_type(tex, i) | src->ssa->bit_size;
       fold_16bit_src(b, &tex->instr, src, src_type);
-      changed = true;
    }
 
-   return changed;
+   return !!fold_srcs;
 }
 
 static bool