Mesa (main): zink: unify resource rebinding

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed May 12 02:50:20 UTC 2021


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

Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date:   Wed Jan 13 14:12:45 2021 -0500

zink: unify resource rebinding

this improves handling for shader images

Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10699>

---

 src/gallium/drivers/zink/zink_context.c  | 41 ++++++++++++++++++++++++++++----
 src/gallium/drivers/zink/zink_resource.c | 30 +----------------------
 2 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index c4af042af0f..34c139a1104 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -2525,11 +2525,9 @@ zink_rebind_framebuffer(struct zink_context *ctx, struct zink_resource *res)
       zink_batch_no_rp(ctx);
 }
 
-void
-zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
+static void
+rebind_buffer(struct zink_context *ctx, struct zink_resource *res)
 {
-   assert(res->base.b.target == PIPE_BUFFER);
-
    if (res->bind_history & ZINK_RESOURCE_USAGE_STREAMOUT)
       ctx->dirty_so_targets = true;
    /* force counter buffer reset */
@@ -2636,6 +2634,41 @@ zink_resource_commit(struct pipe_context *pctx, struct pipe_resource *pres, unsi
    return true;
 }
 
+static void
+rebind_image(struct zink_context *ctx, struct zink_resource *res)
+{
+    zink_rebind_framebuffer(ctx, res);
+    for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
+       if (res->bind_history & BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
+          for (unsigned j = 0; j < ctx->num_sampler_views[i]; j++) {
+             struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]);
+             if (sv && sv->base.texture == &res->base.b) {
+                 struct pipe_surface *psurf = &sv->image_view->base;
+                 zink_rebind_surface(ctx, &psurf);
+                 sv->image_view = zink_surface(psurf);
+                 zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW);
+                 update_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, j);
+             }
+          }
+       }
+       for (unsigned j = 0; j < ctx->di.num_images[i]; j++) {
+          if (zink_resource(ctx->image_views[i][j].base.resource) == res) {
+             zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_IMAGE);
+             update_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_IMAGE, j);
+          }
+       }
+    }
+}
+
+void
+zink_resource_rebind(struct zink_context *ctx, struct zink_resource *res)
+{
+   if (res->base.b.target == PIPE_BUFFER)
+      rebind_buffer(ctx, res);
+   else
+      rebind_image(ctx, res);
+}
+
 static void
 zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resource *dst, struct pipe_resource *src)
 {
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index d0d9df53eb4..67e3f37e69f 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -1232,35 +1232,7 @@ zink_resource_object_init_storage(struct zink_context *ctx, struct zink_resource
       zink_resource_object_reference(screen, &old_obj, NULL);
    }
 
-   if (res->bind_history & BITFIELD64_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
-      for (unsigned shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
-         if (res->bind_stages & (1 << shader)) {
-            for (unsigned i = 0; i < ZINK_DESCRIPTOR_TYPE_IMAGE; i++) {
-               if (res->bind_history & BITFIELD64_BIT(i))
-                  zink_context_invalidate_descriptor_state(ctx, shader, i);
-            }
-         }
-      }
-   }
-   if (res->obj->is_buffer)
-      zink_resource_rebind(ctx, res);
-   else {
-      zink_rebind_framebuffer(ctx, res);
-      /* this will be cleaned up in future commits */
-      if (res->bind_history & BITFIELD_BIT(ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW)) {
-         for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
-            for (unsigned j = 0; j < ctx->num_sampler_views[i]; j++) {
-               struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]);
-               if (sv && sv->base.texture == &res->base.b) {
-                   struct pipe_surface *psurf = &sv->image_view->base;
-                   zink_rebind_surface(ctx, &psurf);
-                   sv->image_view = zink_surface(psurf);
-                   zink_context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW);
-               }
-            }
-         }
-      }
-   }
+   zink_resource_rebind(ctx, res);
 
    return true;
 }



More information about the mesa-commit mailing list