Mesa (main): zink: cap driver inlining using ssa allocation limit

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 13 16:14:31 UTC 2022


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Fri Jun 10 12:43:45 2022 -0400

zink: cap driver inlining using ssa allocation limit

usually inlining is optimal for cpu drivers since the majority of
time is spent in the shaders, and any amount of reduction to shader code
will be optimal

if, however, the shaders are still really big after inlining, this improvement
will be negated by the insane amount of time spent doing stupid llvm optimizer
passes, so check post-inline size to see whether it exceeds a size threshold

lavapipe release build - 1700% improvement
* spec at arb_tessellation_shader@execution at variable-indexing@tcs-output-array-vec4-index-rd-after-barrier

before: 142.15s user 0.42s system 99% cpu 2:23.14 total

after: 8.60s user 0.07s system 99% cpu 8.677 total

fixes #6647

Reviewed-by: Adam Jackson <ajax at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16977>

---

 src/gallium/drivers/zink/ci/zink-lvp-flakes.txt | 5 -----
 src/gallium/drivers/zink/zink_compiler.c        | 6 ++++++
 src/gallium/drivers/zink/zink_compiler.h        | 6 ++++++
 src/gallium/drivers/zink/zink_program.c         | 2 +-
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/zink/ci/zink-lvp-flakes.txt b/src/gallium/drivers/zink/ci/zink-lvp-flakes.txt
index d9b720efb94..d47d2f3ba1b 100644
--- a/src/gallium/drivers/zink/ci/zink-lvp-flakes.txt
+++ b/src/gallium/drivers/zink/ci/zink-lvp-flakes.txt
@@ -20,8 +20,3 @@ glx at glx-shader-sharing
 spec at arb_fragment_program@no-newline
 # glx-destroycontext-1: ../../src/xcb_conn.c:215: write_vec: Assertion `!c->out.queue_len' failed.
 glx at glx-destroycontext-1
-
-# #6647
-spec at arb_tessellation_shader@execution at variable-indexing@tcs-output-array-vec4-index-rd-after-barrier
-spec at arb_tessellation_shader@execution at variable-indexing@tcs-output-array-vec4-index-wr
-spec at arb_tessellation_shader@execution at variable-indexing@tcs-output-array-vec4-index-wr-before-barrier
diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c
index 8c9269d0afb..d62d62113c8 100644
--- a/src/gallium/drivers/zink/zink_compiler.c
+++ b/src/gallium/drivers/zink/zink_compiler.c
@@ -2010,6 +2010,10 @@ zink_shader_compile(struct zink_screen *screen, struct zink_shader *zs, nir_shad
       /* This must be done again. */
       NIR_PASS_V(nir, nir_io_add_const_offset_to_base, nir_var_shader_in |
                                                        nir_var_shader_out);
+
+      nir_function_impl *impl = nir_shader_get_entrypoint(nir);
+      if (impl->ssa_alloc > ZINK_ALWAYS_INLINE_LIMIT)
+         zs->can_inline = false;
    } else if (need_optimize)
       optimize_nir(nir);
    prune_io(nir);
@@ -2835,6 +2839,8 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
       }
    }
 
+   ret->can_inline = true;
+
    return ret;
 }
 
diff --git a/src/gallium/drivers/zink/zink_compiler.h b/src/gallium/drivers/zink/zink_compiler.h
index 3f75eb4c117..d157d9f43a6 100644
--- a/src/gallium/drivers/zink/zink_compiler.h
+++ b/src/gallium/drivers/zink/zink_compiler.h
@@ -38,6 +38,11 @@
 #define ZINK_WORKGROUP_SIZE_Y 2
 #define ZINK_WORKGROUP_SIZE_Z 3
 
+/* stop inlining shaders if they have >limit ssa vals after inlining:
+ * recompile time isn't worth the inline
+ */
+#define ZINK_ALWAYS_INLINE_LIMIT 1500
+
 struct pipe_screen;
 struct zink_context;
 struct zink_screen;
@@ -90,6 +95,7 @@ struct zink_shader {
    uint32_t ubos_used; // bitfield of which ubo indices are used
    uint32_t ssbos_used; // bitfield of which ssbo indices are used
    bool bindless;
+   bool can_inline;
    struct spirv_shader *spirv;
 
    simple_mtx_t lock;
diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c
index b62c7b90f47..242c225884c 100644
--- a/src/gallium/drivers/zink/zink_program.c
+++ b/src/gallium/drivers/zink/zink_program.c
@@ -106,7 +106,7 @@ get_shader_module_for_stage(struct zink_context *ctx, struct zink_screen *screen
    }
    if (ctx && zs->nir->info.num_inlinable_uniforms &&
        ctx->inlinable_uniforms_valid_mask & BITFIELD64_BIT(pstage)) {
-      if (screen->is_cpu || prog->inlined_variant_count[pstage] < ZINK_MAX_INLINED_VARIANTS)
+      if (zs->can_inline && (screen->is_cpu || prog->inlined_variant_count[pstage] < ZINK_MAX_INLINED_VARIANTS))
          inline_size = zs->nir->info.num_inlinable_uniforms;
       else
          key->inline_uniforms = false;



More information about the mesa-commit mailing list