Mesa (main): turnip: Short-circuit if ladder generation for constant index SSBO/UBOs.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 28 16:49:08 UTC 2021


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

Author: Emma Anholt <emma at anholt.net>
Date:   Fri Jun 25 14:02:07 2021 -0700

turnip: Short-circuit if ladder generation for constant index SSBO/UBOs.

The compiler *can* eventually chew through all the copy prop, constant
folding, and dead_cf necessary to use just our constant index, but we can
save a whole lot of hassle by chasing the MOVs up front and finding the
constant.

dEQP-VK.ubo.3_level_array.scalar.row_major_mat4.both goes from 2.0s to
1.6s on a release build (3.1s to 2.1s for a debug build like we use in CI).

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11613>

---

 src/freedreno/vulkan/tu_shader.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/freedreno/vulkan/tu_shader.c b/src/freedreno/vulkan/tu_shader.c
index cfd110e0531..af9926ebc1d 100644
--- a/src/freedreno/vulkan/tu_shader.c
+++ b/src/freedreno/vulkan/tu_shader.c
@@ -279,7 +279,7 @@ lower_ssbo_ubo_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin)
    /* The bindless base is part of the instruction, which means that part of
     * the "pointer" has to be constant. We solve this in the same way the blob
     * does, by generating a bunch of if-statements. In the usual case where
-    * the descriptor set is constant this will get optimized out.
+    * the descriptor set is constant we can skip that, though).
     */
 
    unsigned buffer_src;
@@ -290,11 +290,19 @@ lower_ssbo_ubo_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin)
       buffer_src = 0;
    }
 
-   nir_ssa_def *base_idx = nir_channel(b, intrin->src[buffer_src].ssa, 0);
+   nir_ssa_scalar scalar_idx = nir_ssa_scalar_resolved(intrin->src[buffer_src].ssa, 0);
    nir_ssa_def *descriptor_idx = nir_channel(b, intrin->src[buffer_src].ssa, 1);
 
    nir_ssa_def *results[MAX_SETS + 1] = { NULL };
 
+   if (nir_ssa_scalar_is_const(scalar_idx)) {
+      nir_ssa_def *bindless =
+         nir_bindless_resource_ir3(b, 32, descriptor_idx, .desc_set = nir_ssa_scalar_as_uint(scalar_idx));
+      nir_instr_rewrite_src_ssa(&intrin->instr, &intrin->src[buffer_src], bindless);
+      return;
+   }
+
+   nir_ssa_def *base_idx = nir_channel(b, scalar_idx.def, scalar_idx.comp);
    for (unsigned i = 0; i < MAX_SETS + 1; i++) {
       /* if (base_idx == i) { ... */
       nir_if *nif = nir_push_if(b, nir_ieq_imm(b, base_idx, i));



More information about the mesa-commit mailing list