Mesa (main): nir/constant_folding: Optimize txb with bias of constant zero to tex

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Dec 6 20:15:32 UTC 2021


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Tue Nov  9 15:51:41 2021 -0800

nir/constant_folding: Optimize txb with bias of constant zero to tex

v2: Fail gracefully when bias_idx < 0.  See comment in the code for the
rationale.  See also issue #5722.

All Haswell and newer Intel GPUs had similar results. (Ice Lake shown)
total instructions in shared programs: 19757733 -> 19753431 (-0.02%)
instructions in affected programs: 277248 -> 272946 (-1.55%)
helped: 1644
HURT: 1
helped stats (abs) min: 1 max: 16 x̄: 2.62 x̃: 2
helped stats (rel) min: 0.05% max: 11.11% x̄: 2.11% x̃: 1.61%
HURT stats (abs)   min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel)   min: 0.35% max: 0.35% x̄: 0.35% x̃: 0.35%
95% mean confidence interval for instructions value: -2.72 -2.51
95% mean confidence interval for instructions %-change: -2.19% -2.03%
Instructions are helped.

total cycles in shared programs: 938517439 -> 938384079 (-0.01%)
cycles in affected programs: 19548849 -> 19415489 (-0.68%)
helped: 1358
HURT: 269
helped stats (abs) min: 1 max: 2328 x̄: 133.01 x̃: 16
helped stats (rel) min: <.01% max: 41.12% x̄: 1.40% x̃: 0.48%
HURT stats (abs)   min: 1 max: 1302 x̄: 175.70 x̃: 30
HURT stats (rel)   min: <.01% max: 69.03% x̄: 6.24% x̃: 1.04%
95% mean confidence interval for cycles value: -99.14 -64.79
95% mean confidence interval for cycles %-change: -0.47% 0.19%
Inconclusive result (%-change mean confidence interval includes 0).

LOST:   21
GAINED: 32

All Ivy Bridge and older Intel GPUs had similar results. (Ivy Bridge shown)
total instructions in shared programs: 15302017 -> 15301485 (<.01%)
instructions in affected programs: 22565 -> 22033 (-2.36%)
helped: 168
HURT: 0
helped stats (abs) min: 1 max: 7 x̄: 3.17 x̃: 3
helped stats (rel) min: 0.04% max: 4.39% x̄: 3.05% x̃: 3.27%
95% mean confidence interval for instructions value: -3.45 -2.89
95% mean confidence interval for instructions %-change: -3.19% -2.91%
Instructions are helped.

total cycles in shared programs: 550119761 -> 549989147 (-0.02%)
cycles in affected programs: 12834251 -> 12703637 (-1.02%)
helped: 164
HURT: 0
helped stats (abs) min: 20 max: 4547 x̄: 796.43 x̃: 294
helped stats (rel) min: 0.23% max: 53.84% x̄: 2.05% x̃: 0.37%
95% mean confidence interval for cycles value: -942.62 -650.24
95% mean confidence interval for cycles %-change: -3.17% -0.94%
Cycles are helped.

fossil-db results:

Tiger Lake, Ice Lake, and Skylake had similar results. (Ice Lake shown)
Instructions in all programs: 142073649 -> 141307526 (-0.5%)
SENDs in all programs: 6876848 -> 6876778 (-0.0%)
Loops in all programs: 38283 -> 38283 (+0.0%)
Cycles in all programs: 8410049681 -> 8402902960 (-0.1%)
Spills in all programs: 190623 -> 190599 (-0.0%)
Fills in all programs: 297780 -> 297756 (-0.0%)

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net> [v1]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14025>

---

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

diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c
index b46239794cc..97aca6d09fb 100644
--- a/src/compiler/nir/nir_opt_constant_folding.c
+++ b/src/compiler/nir/nir_opt_constant_folding.c
@@ -305,6 +305,31 @@ try_fold_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin,
    }
 }
 
+static bool
+try_fold_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);
+
+      /* 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_instr(nir_builder *b, nir_instr *instr, void *_state)
 {
@@ -313,6 +338,8 @@ try_fold_instr(nir_builder *b, nir_instr *instr, void *_state)
       return try_fold_alu(b, nir_instr_as_alu(instr));
    case nir_instr_type_intrinsic:
       return try_fold_intrinsic(b, nir_instr_as_intrinsic(instr), _state);
+   case nir_instr_type_tex:
+      return try_fold_tex(b, nir_instr_as_tex(instr));
    default:
       /* Don't know how to constant fold */
       return false;



More information about the mesa-commit mailing list