Module: Mesa Branch: main Commit: 625457caafb3c68e753bf26dc99e065428c45b31 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=625457caafb3c68e753bf26dc99e065428c45b31
Author: Mike Blumenkrantz <[email protected]> Date: Tue Apr 19 10:57:30 2022 -0400 zink: handle swapchain acquire failures more directly if acquire fails, the pending operation cannot be completed, so just drop it Reviewed-by: Adam Jackson <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16038> --- src/gallium/drivers/zink/zink_blit.c | 6 +++-- src/gallium/drivers/zink/zink_clear.c | 6 +++-- src/gallium/drivers/zink/zink_context.c | 42 ++++++++++++++++++++++----------- src/gallium/drivers/zink/zink_draw.cpp | 3 +++ 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c index d0d2c4e349d..71acba25899 100644 --- a/src/gallium/drivers/zink/zink_blit.c +++ b/src/gallium/drivers/zink/zink_blit.c @@ -293,8 +293,10 @@ zink_blit(struct pipe_context *pctx, struct zink_resource *src = zink_resource(info->src.resource); struct zink_resource *dst = zink_resource(info->dst.resource); bool needs_present_readback = false; - if (zink_is_swapchain(dst)) - zink_kopper_acquire(ctx, dst, UINT64_MAX); + if (zink_is_swapchain(dst)) { + if (!zink_kopper_acquire(ctx, dst, UINT64_MAX)) + return; + } if (src_desc == dst_desc || src_desc->nr_channels != 4 || src_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN || diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c index afbc3c5ad57..97d2baeb70a 100644 --- a/src/gallium/drivers/zink/zink_clear.c +++ b/src/gallium/drivers/zink/zink_clear.c @@ -154,8 +154,10 @@ clear_color_no_rp(struct zink_context *ctx, struct zink_resource *res, const uni color.uint32[2] = pcolor->ui[2]; color.uint32[3] = pcolor->ui[3]; - if (zink_is_swapchain(res)) - zink_kopper_acquire(ctx, res, UINT64_MAX); + if (zink_is_swapchain(res)) { + if (!zink_kopper_acquire(ctx, res, UINT64_MAX)) + return; + } if (zink_resource_image_needs_barrier(res, VK_IMAGE_LAYOUT_GENERAL, 0, 0) && zink_resource_image_needs_barrier(res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0)) zink_resource_image_barrier(ctx, res, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0); diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 85eca16ada4..f9d8808fbe0 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -806,8 +806,10 @@ zink_create_sampler_view(struct pipe_context *pctx, struct pipe_resource *pres, templ.u.tex.last_layer = state->u.tex.last_layer; } - if (zink_is_swapchain(res)) - zink_kopper_acquire(ctx, res, UINT64_MAX); + if (zink_is_swapchain(res)) { + if (!zink_kopper_acquire(ctx, res, UINT64_MAX)) + return NULL; + } ivci = create_ivci(screen, res, &templ, state->target); ivci.subresourceRange.levelCount = state->u.tex.last_level - state->u.tex.first_level + 1; @@ -2162,8 +2164,8 @@ setup_framebuffer(struct zink_context *ctx) struct zink_resource *res = zink_resource(ctx->fb_state.cbufs[i]->texture); if (zink_is_swapchain(res)) { has_swapchain = true; - zink_kopper_acquire(ctx, res, UINT64_MAX); - zink_surface_swapchain_update(ctx, zink_csurface(ctx->fb_state.cbufs[i])); + if (zink_kopper_acquire(ctx, res, UINT64_MAX)) + zink_surface_swapchain_update(ctx, zink_csurface(ctx->fb_state.cbufs[i])); } } if (has_swapchain && (ctx->swapchain_size.width || ctx->swapchain_size.height)) { @@ -2200,7 +2202,8 @@ prep_fb_attachment(struct zink_context *ctx, struct zink_surface *surf, unsigned VkAccessFlags access; VkPipelineStageFlags pipeline; if (zink_is_swapchain(res)) { - zink_kopper_acquire(ctx, res, UINT64_MAX); + if (!zink_kopper_acquire(ctx, res, UINT64_MAX)) + return VK_NULL_HANDLE; zink_surface_swapchain_update(ctx, surf); if (!i) zink_update_fbfetch(ctx); @@ -2221,7 +2224,7 @@ prep_fb_attachment(struct zink_context *ctx, struct zink_surface *surf, unsigned return surf->image_view; } -static void +static bool prep_fb_attachments(struct zink_context *ctx, VkImageView *att) { const unsigned cresolve_offset = ctx->fb_state.nr_cbufs + !!ctx->fb_state.zsbuf; @@ -2235,6 +2238,9 @@ prep_fb_attachments(struct zink_context *ctx, VkImageView *att) num_resolves++; } else { att[i] = prep_fb_attachment(ctx, surf, i); + if (!att[i]) + /* dead swapchain */ + return false; } } if (ctx->fb_state.zsbuf) { @@ -2247,6 +2253,7 @@ prep_fb_attachments(struct zink_context *ctx, VkImageView *att) att[ctx->fb_state.nr_cbufs] = prep_fb_attachment(ctx, surf, ctx->fb_state.nr_cbufs); } } + return true; } static unsigned @@ -2313,7 +2320,8 @@ begin_render_pass(struct zink_context *ctx) infos.pNext = NULL; infos.attachmentCount = ctx->framebuffer->state.num_attachments; infos.pAttachments = att; - prep_fb_attachments(ctx, att); + if (!prep_fb_attachments(ctx, att)) + return 0; #ifndef NDEBUG const unsigned cresolve_offset = ctx->fb_state.nr_cbufs + !!ctx->fb_state.zsbuf; for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { @@ -2653,10 +2661,13 @@ unbind_fb_surface(struct zink_context *ctx, struct pipe_surface *surf, unsigned if (changed) { if (zink_fb_clear_enabled(ctx, idx)) { if (zink_is_swapchain(res)) { - zink_kopper_acquire(ctx, res, UINT64_MAX); - zink_surface_swapchain_update(ctx, zink_csurface(surf)); + if (zink_kopper_acquire(ctx, res, UINT64_MAX)) { + zink_surface_swapchain_update(ctx, zink_csurface(surf)); + zink_fb_clears_apply(ctx, surf->texture); + } + } else { + zink_fb_clears_apply(ctx, surf->texture); } - zink_fb_clears_apply(ctx, surf->texture); } if (zink_batch_usage_exists(zink_csurface(surf)->batch_uses)) { zink_batch_reference_surface(&ctx->batch, zink_csurface(surf)); @@ -3506,18 +3517,21 @@ zink_copy_image_buffer(struct zink_context *ctx, struct zink_resource *dst, stru struct zink_resource *img = dst->base.b.target == PIPE_BUFFER ? src : dst; struct zink_resource *buf = dst->base.b.target == PIPE_BUFFER ? dst : src; struct zink_batch *batch = &ctx->batch; + bool needs_present_readback = false; zink_batch_no_rp(ctx); bool buf2img = buf == src; if (buf2img) { - if (zink_is_swapchain(img)) - zink_kopper_acquire(ctx, img, UINT64_MAX); + if (zink_is_swapchain(img)) { + if (!zink_kopper_acquire(ctx, img, UINT64_MAX)) + return; + } zink_resource_image_barrier(ctx, img, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 0, 0); zink_resource_buffer_barrier(ctx, buf, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); } else { if (zink_is_swapchain(img)) - zink_kopper_acquire_readback(ctx, img); + needs_present_readback = zink_kopper_acquire_readback(ctx, img); zink_resource_image_barrier(ctx, img, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 0, 0); zink_resource_buffer_barrier(ctx, buf, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); util_range_add(&dst->base.b, &dst->valid_buffer_range, dstx, dstx + src_box->width); @@ -3596,7 +3610,7 @@ zink_copy_image_buffer(struct zink_context *ctx, struct zink_resource *dst, stru else VKCTX(CmdCopyImageToBuffer)(batch->state->cmdbuf, img->obj->image, img->layout, buf->obj->buffer, 1, ®ion); } - if (!buf2img && img->obj->dt) + if (needs_present_readback) zink_kopper_present_readback(ctx, img); } diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp index dac434de4a4..1db2c237283 100644 --- a/src/gallium/drivers/zink/zink_draw.cpp +++ b/src/gallium/drivers/zink/zink_draw.cpp @@ -543,6 +543,9 @@ zink_draw(struct pipe_context *pctx, zink_query_update_gs_states(ctx, dinfo->was_line_loop); zink_batch_rp(ctx); + /* check dead swapchain */ + if (unlikely(!ctx->batch.in_rp)) + return; if (BATCH_CHANGED) zink_update_descriptor_refs(ctx, false);
