From 3dc8d813321b9288f3b1c9c752e4a6eb23d2a7d3 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 28 May 2025 13:04:58 -0400 Subject: [PATCH] zink: delete zink_ctx_surface::needs_mutable this was some awfulness required because previously pipe_surface objects could be created from a different thread, but now they are only ever created by the driver Part-of: --- src/gallium/drivers/zink/zink_context.c | 18 --------------- src/gallium/drivers/zink/zink_surface.c | 30 ++++++++----------------- src/gallium/drivers/zink/zink_types.h | 1 - 3 files changed, 9 insertions(+), 40 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index f1ff331a75f..6ce5a70b12b 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -3817,22 +3817,6 @@ zink_set_null_fs(struct zink_context *ctx) ctx->base.bind_fs_state(&ctx->base, ctx->null_fs); } -static void -check_framebuffer_surface_mutable(struct pipe_context *pctx, struct pipe_surface *psurf) -{ - struct zink_context *ctx = zink_context(pctx); - struct zink_ctx_surface *csurf = (struct zink_ctx_surface *)psurf; - if (!csurf->needs_mutable) - return; - zink_resource_object_init_mutable(ctx, zink_resource(psurf->texture)); - struct pipe_surface *psurf2 = pctx->create_surface(pctx, psurf->texture, psurf); - pipe_resource_reference(&psurf2->texture, NULL); - struct zink_ctx_surface *csurf2 = (struct zink_ctx_surface *)psurf2; - zink_surface_reference(zink_screen(pctx->screen), &csurf->surf, csurf2->surf); - pctx->surface_destroy(pctx, psurf2); - csurf->needs_mutable = false; -} - static bool framebuffer_surface_needs_mutable(const struct pipe_resource *pres, const struct pipe_surface *templ) { @@ -3951,7 +3935,6 @@ zink_set_framebuffer_state(struct pipe_context *pctx, if (!samples) samples = MAX3(ctx->fb_state.cbufs[i].nr_samples, psurf->texture->nr_samples, 1); struct zink_resource *res = zink_resource(psurf->texture); - check_framebuffer_surface_mutable(pctx, psurf); if (zink_csurface(psurf)->ivci.subresourceRange.layerCount > layers) ctx->fb_layer_mismatch |= BITFIELD_BIT(i); if (res->obj->dt) { @@ -3975,7 +3958,6 @@ zink_set_framebuffer_state(struct pipe_context *pctx, } if (ctx->fb_state.zsbuf.texture) { struct pipe_surface *psurf = ctx->fb_zsbuf; - check_framebuffer_surface_mutable(pctx, psurf); if (ctx->fb_state.zsbuf.nr_samples) { ctx->transient_attachments |= BITFIELD_BIT(PIPE_MAX_COLOR_BUFS); framebuffer_surface_init_transient(ctx, psurf, PIPE_MAX_COLOR_BUFS); diff --git a/src/gallium/drivers/zink/zink_surface.c b/src/gallium/drivers/zink/zink_surface.c index 5a665a6cc02..e3d54550ee2 100644 --- a/src/gallium/drivers/zink/zink_surface.c +++ b/src/gallium/drivers/zink/zink_surface.c @@ -260,9 +260,6 @@ zink_surface_destroy(struct pipe_context *pctx, struct pipe_surface *psurface) { struct zink_ctx_surface *csurf = (struct zink_ctx_surface *)psurface; - if (csurf->needs_mutable) - /* this has an extra resource ref */ - pipe_resource_reference(&csurf->base.texture, NULL); zink_surface_reference(zink_screen(pctx->screen), &csurf->surf, NULL); /* ensure this gets repopulated if another transient surface is created */ struct zink_resource *res = zink_resource(psurface->texture); @@ -277,14 +274,12 @@ zink_create_surface(struct pipe_context *pctx, struct pipe_resource *pres, const struct pipe_surface *templ) { + struct zink_context *ctx = zink_context(pctx); struct zink_resource *res = zink_resource(pres); struct zink_screen *screen = zink_screen(pctx->screen); bool is_array = templ->last_layer != templ->first_layer; - bool needs_mutable = false; enum pipe_texture_target target_2d[] = {PIPE_TEXTURE_2D, PIPE_TEXTURE_2D_ARRAY}; if (!res->obj->dt && zink_format_needs_mutable(pres->format, templ->format)) { - /* mutable not set by default */ - needs_mutable = !(res->base.b.bind & ZINK_BIND_MUTABLE); /* VUID-VkImageViewCreateInfo-image-07072 If image was created with the VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT flag and @@ -296,12 +291,10 @@ zink_create_surface(struct pipe_context *pctx, if (util_format_is_compressed(pres->format) && templ->first_layer != templ->last_layer && (!screen->info.have_KHR_maintenance6 || !screen->info.maint6_props.blockTexelViewCompatibleMultipleLayers)) return NULL; - } - - if (!screen->threaded && needs_mutable) { - /* this is fine without tc */ - needs_mutable = false; - zink_resource_object_init_mutable(zink_context(pctx), res); + + /* mutable not set by default */ + if (!(res->base.b.bind & ZINK_BIND_MUTABLE)) + zink_resource_object_init_mutable(ctx, res); } if (!zink_get_format(screen, templ->format)) @@ -320,26 +313,21 @@ zink_create_surface(struct pipe_context *pctx, } surface->is_swapchain = true; - } else if (!needs_mutable) { + } else { surface = zink_get_surface(zink_context(pctx), pres, templ, &ivci); if (unlikely(!surface)) { - mesa_loge("ZINK: failed to get non-mutable surface!"); + mesa_loge("ZINK: failed to get surface!"); return NULL; } } - struct zink_ctx_surface *csurf = wrap_surface(pctx, surface, needs_mutable ? templ : &surface->base); /* move ownership of surface */ + struct zink_ctx_surface *csurf = wrap_surface(pctx, surface, &surface->base); /* move ownership of surface */ if (!unlikely (csurf)) { mesa_loge("ZINK: failed to allocate csurf!"); return NULL; } - csurf->needs_mutable = needs_mutable; - if (needs_mutable) { - struct pipe_resource *ref = NULL; - pipe_resource_reference(&ref, pres); - init_pipe_surface_info(pctx, &csurf->base, templ, pres); - } + init_pipe_surface_info(pctx, &csurf->base, templ, pres); /* this may or may not be set previously depending whether templ->texture is set */ csurf->base.texture = pres; diff --git a/src/gallium/drivers/zink/zink_types.h b/src/gallium/drivers/zink/zink_types.h index 519a869ffb8..45a4056544f 100644 --- a/src/gallium/drivers/zink/zink_types.h +++ b/src/gallium/drivers/zink/zink_types.h @@ -1558,7 +1558,6 @@ struct zink_surface { struct zink_ctx_surface { struct pipe_surface base; struct zink_surface *surf; //the actual surface - bool needs_mutable; }; /* use this cast for framebuffer surfaces */