Mesa (main): zink: use global image rebind counter for dmabuf export
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri May 20 16:58:31 UTC 2022
Module: Mesa
Branch: main
Commit: 3d145ec7f1eaee0a3b77f41414df07271054da39
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=3d145ec7f1eaee0a3b77f41414df07271054da39
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Mon May 9 12:23:26 2022 -0400
zink: use global image rebind counter for dmabuf export
this is a bit less flimsy and handles more than just framebuffer rebinds
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16476>
---
src/gallium/drivers/zink/zink_context.c | 30 ++++++++++++++++++++++++++++++
src/gallium/drivers/zink/zink_context.h | 3 +++
src/gallium/drivers/zink/zink_draw.cpp | 5 +++++
src/gallium/drivers/zink/zink_resource.c | 1 +
src/gallium/drivers/zink/zink_screen.h | 1 +
5 files changed, 40 insertions(+)
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 2ca6f6407ca..e92de9f476c 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -3749,6 +3749,36 @@ zink_rebind_all_buffers(struct zink_context *ctx)
}
}
+void
+zink_rebind_all_images(struct zink_context *ctx)
+{
+ rebind_fb_state(ctx, NULL, false);
+ for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
+ for (unsigned j = 0; j < ctx->di.num_sampler_views[i]; j++) {
+ struct zink_sampler_view *sv = zink_sampler_view(ctx->sampler_views[i][j]);
+ struct zink_resource *res = zink_resource(sv->image_view->base.texture);
+ if (res->obj != sv->image_view->obj) {
+ struct pipe_surface *psurf = &sv->image_view->base;
+ zink_rebind_surface(ctx, &psurf);
+ sv->image_view = zink_surface(psurf);
+ zink_screen(ctx->base.screen)->context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW, j, 1);
+ update_descriptor_state_sampler(ctx, i, j, res);
+ }
+ }
+ for (unsigned j = 0; j < ctx->di.num_images[i]; j++) {
+ struct zink_image_view *image_view = &ctx->image_views[i][j];
+ struct zink_resource *res = zink_resource(image_view->base.resource);
+ if (ctx->image_views[i][j].surface->obj != res->obj) {
+ zink_surface_reference(zink_screen(ctx->base.screen), &image_view->surface, NULL);
+ image_view->surface = create_image_surface(ctx, &image_view->base, i == PIPE_SHADER_COMPUTE);
+ zink_screen(ctx->base.screen)->context_invalidate_descriptor_state(ctx, i, ZINK_DESCRIPTOR_TYPE_IMAGE, j, 1);
+ update_descriptor_state_image(ctx, i, j, res);
+ _mesa_set_add(ctx->need_barriers[i == PIPE_SHADER_COMPUTE], res);
+ }
+ }
+ }
+}
+
static void
zink_context_replace_buffer_storage(struct pipe_context *pctx, struct pipe_resource *dst,
struct pipe_resource *src, unsigned num_rebinds,
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 7fbfcb38b54..76394ff141b 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -309,6 +309,7 @@ struct zink_context {
struct zink_buffer_view *dummy_bufferview;
unsigned buffer_rebind_counter;
+ unsigned image_rebind_counter;
struct {
/* descriptor info */
@@ -453,6 +454,8 @@ zink_pipeline_flags_from_pipe_stage(enum pipe_shader_type pstage)
void
zink_rebind_all_buffers(struct zink_context *ctx);
+void
+zink_rebind_all_images(struct zink_context *ctx);
void
zink_flush_memory_barrier(struct zink_context *ctx, bool is_compute);
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 4aebcbe667e..1e53cc808ed 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -491,6 +491,11 @@ zink_draw(struct pipe_context *pctx,
zink_rebind_all_buffers(ctx);
}
+ if (unlikely(ctx->image_rebind_counter < screen->image_rebind_counter)) {
+ ctx->image_rebind_counter = screen->image_rebind_counter;
+ zink_rebind_all_images(ctx);
+ }
+
unsigned index_offset = 0;
unsigned index_size = dinfo->index_size;
struct pipe_resource *index_buffer = NULL;
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index fb926f41fcc..770b225e2ae 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -1305,6 +1305,7 @@ zink_resource_get_handle(struct pipe_screen *pscreen,
assert(!zink_resource_usage_is_unflushed(res));
if (!add_resource_bind(screen->copy_context, res, ZINK_BIND_DMABUF | PIPE_BIND_SHARED))
return false;
+ p_atomic_inc(&screen->image_rebind_counter);
screen->copy_context->base.flush(&screen->copy_context->base, NULL, 0);
obj = res->obj;
}
diff --git a/src/gallium/drivers/zink/zink_screen.h b/src/gallium/drivers/zink/zink_screen.h
index 776b5c14a4b..f1c7f308e6e 100644
--- a/src/gallium/drivers/zink/zink_screen.h
+++ b/src/gallium/drivers/zink/zink_screen.h
@@ -102,6 +102,7 @@ struct zink_screen {
struct zink_context *copy_context;
unsigned buffer_rebind_counter;
+ unsigned image_rebind_counter;
struct hash_table dts;
simple_mtx_t dt_lock;
More information about the mesa-commit
mailing list