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@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16476>
This commit is contained in:
Mike Blumenkrantz 2022-05-09 12:23:26 -04:00 committed by Marge Bot
parent b181080d9f
commit 3d145ec7f1
5 changed files with 40 additions and 0 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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;
}

View File

@ -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;