Mesa (main): nir/constant_folding: Break TXB folding into a helper function

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 26 23:13:05 UTC 2022


Module: Mesa
Branch: main
Commit: 9332598b26232e5c70e2050dd38e56efffe80d61
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9332598b26232e5c70e2050dd38e56efffe80d61

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Tue Apr 26 11:28:36 2022 -0500

nir/constant_folding: Break TXB folding into a helper function

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16171>

---

 src/compiler/nir/nir_opt_constant_folding.c | 43 ++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c
index 97aca6d09fb..72e1f2ffe29 100644
--- a/src/compiler/nir/nir_opt_constant_folding.c
+++ b/src/compiler/nir/nir_opt_constant_folding.c
@@ -306,30 +306,41 @@ try_fold_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin,
 }
 
 static bool
-try_fold_tex(nir_builder *b, nir_tex_instr *tex)
+try_fold_txb_to_tex(nir_builder *b, nir_tex_instr *tex)
 {
-   /* txb with a bias of constant zero is just tex. */
-   if (tex->op == nir_texop_txb) {
-      const int bias_idx = nir_tex_instr_src_index(tex, nir_tex_src_bias);
+   assert(tex->op == nir_texop_txb);
 
-      /* nir_to_tgsi_lower_tex mangles many kinds of texture instructions,
-       * including txb, into invalid states.  It removes the special
-       * parameters and appends the values to the texture coordinate.
-       */
-      if (bias_idx < 0)
-         return false;
+   const int bias_idx = nir_tex_instr_src_index(tex, nir_tex_src_bias);
 
-      if (nir_src_is_const(tex->src[bias_idx].src) &&
-          nir_src_as_float(tex->src[bias_idx].src) == 0.0) {
-         nir_tex_instr_remove_src(tex, bias_idx);
-         tex->op = nir_texop_tex;
-         return true;
-      }
+   /* nir_to_tgsi_lower_tex mangles many kinds of texture instructions,
+    * including txb, into invalid states.  It removes the special
+    * parameters and appends the values to the texture coordinate.
+    */
+   if (bias_idx < 0)
+      return false;
+
+   if (nir_src_is_const(tex->src[bias_idx].src) &&
+       nir_src_as_float(tex->src[bias_idx].src) == 0.0) {
+      nir_tex_instr_remove_src(tex, bias_idx);
+      tex->op = nir_texop_tex;
+      return true;
    }
 
    return false;
 }
 
+static bool
+try_fold_tex(nir_builder *b, nir_tex_instr *tex)
+{
+   bool progress = false;
+
+   /* txb with a bias of constant zero is just tex. */
+   if (tex->op == nir_texop_txb)
+      progress |= try_fold_txb_to_tex(b, tex);
+
+   return progress;
+}
+
 static bool
 try_fold_instr(nir_builder *b, nir_instr *instr, void *_state)
 {



More information about the mesa-commit mailing list