Mesa (main): cso: don't look up a sampler CSO if the last one is identical

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jun 27 13:07:33 UTC 2021


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

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Mon Jun  7 09:58:48 2021 -0400

cso: don't look up a sampler CSO if the last one is identical

This is benefical when sampler states are identical often, and detrimental
if they are not. The average case seems to be in favor of this.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11428>

---

 src/gallium/auxiliary/cso_cache/cso_context.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 868b04a2ebe..d49b5161c04 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -1258,7 +1258,31 @@ cso_set_samplers(struct cso_context *ctx,
       if (!templates[i])
          continue;
 
-      cso_single_sampler(ctx, shader_stage, i, templates[i]);
+      /* Reuse the same sampler state CSO if 2 consecutive sampler states
+       * are identical.
+       *
+       * The trivial case where both pointers are equal doesn't occur in
+       * frequented codepaths.
+       *
+       * Reuse rate:
+       * - Borderlands 2: 55%
+       * - Hitman: 65%
+       * - Rocket League: 75%
+       * - Tomb Raider: 50-65%
+       * - XCOM 2: 55%
+       */
+      if (last >= 0 &&
+          !memcmp(templates[i], templates[last],
+                  sizeof(struct pipe_sampler_state))) {
+         ctx->samplers[shader_stage].cso_samplers[i] =
+            ctx->samplers[shader_stage].cso_samplers[last];
+         ctx->samplers[shader_stage].samplers[i] =
+            ctx->samplers[shader_stage].samplers[last];
+      } else {
+         /* Look up the sampler state CSO. */
+         cso_set_sampler(ctx, shader_stage, i, templates[i]);
+      }
+
       last = i;
    }
 



More information about the mesa-commit mailing list