cso: don't destroy CSOs that are saved
authorMarek Olšák <marek.olsak@amd.com>
Sat, 6 Aug 2022 21:30:02 +0000 (17:30 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 19 Oct 2022 04:56:55 +0000 (04:56 +0000)
I think this can't happen in practice, but better safe than sorry.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19129>

src/gallium/auxiliary/cso_cache/cso_context.c

index 4c0502a..1f95272 100644 (file)
@@ -137,19 +137,23 @@ delete_cso(struct cso_context *ctx,
 {
    switch (type) {
    case CSO_BLEND:
-      if (ctx->blend == ((struct cso_blend*)state)->data)
+      if (ctx->blend == ((struct cso_blend*)state)->data ||
+          ctx->blend_saved == ((struct cso_blend*)state)->data)
          return false;
       break;
    case CSO_DEPTH_STENCIL_ALPHA:
-      if (ctx->depth_stencil == ((struct cso_depth_stencil_alpha*)state)->data)
+      if (ctx->depth_stencil == ((struct cso_depth_stencil_alpha*)state)->data ||
+          ctx->depth_stencil_saved == ((struct cso_depth_stencil_alpha*)state)->data)
          return false;
       break;
    case CSO_RASTERIZER:
-      if (ctx->rasterizer == ((struct cso_rasterizer*)state)->data)
+      if (ctx->rasterizer == ((struct cso_rasterizer*)state)->data ||
+          ctx->rasterizer_saved == ((struct cso_rasterizer*)state)->data)
          return false;
       break;
    case CSO_VELEMENTS:
-      if (ctx->velements == ((struct cso_velements*)state)->data)
+      if (ctx->velements == ((struct cso_velements*)state)->data ||
+          ctx->velements_saved == ((struct cso_velements*)state)->data)
          return false;
       break;
    case CSO_SAMPLER:
@@ -184,7 +188,7 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type,
       return;
 
    if (type == CSO_SAMPLER) {
-      samplers_to_restore = MALLOC(PIPE_SHADER_TYPES * PIPE_MAX_SAMPLERS *
+      samplers_to_restore = MALLOC((PIPE_SHADER_TYPES + 2) * PIPE_MAX_SAMPLERS *
                                    sizeof(*samplers_to_restore));
 
       /* Temporarily remove currently bound sampler states from the hash
@@ -198,6 +202,18 @@ sanitize_hash(struct cso_hash *hash, enum cso_cache_type type,
                samplers_to_restore[to_restore++] = sampler;
          }
       }
+      for (int j = 0; j < PIPE_MAX_SAMPLERS; j++) {
+         struct cso_sampler *sampler = ctx->fragment_samplers_saved.cso_samplers[j];
+
+         if (sampler && cso_hash_take(hash, sampler->hash_key))
+            samplers_to_restore[to_restore++] = sampler;
+      }
+      for (int j = 0; j < PIPE_MAX_SAMPLERS; j++) {
+         struct cso_sampler *sampler = ctx->compute_samplers_saved.cso_samplers[j];
+
+         if (sampler && cso_hash_take(hash, sampler->hash_key))
+            samplers_to_restore[to_restore++] = sampler;
+      }
    }
 
    struct cso_hash_iter iter = cso_hash_first_node(hash);