zink: add batch refs for transient images

ensure these don't get deleted while in use

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24309>
(cherry picked from commit 5ac2291c6b)
This commit is contained in:
Mike Blumenkrantz 2023-07-24 16:26:53 -04:00 committed by Eric Engestrom
parent f449edb6c1
commit f9aa9aecf4
2 changed files with 17 additions and 9 deletions

View file

@ -886,7 +886,7 @@
"description": "zink: add batch refs for transient images",
"nominated": true,
"nomination_type": 0,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null
},

View file

@ -2811,6 +2811,17 @@ update_layered_rendering_state(struct zink_context *ctx)
&framebffer_is_layered);
}
ALWAYS_INLINE static void
batch_ref_fb_surface(struct zink_context *ctx, struct pipe_surface *psurf)
{
if (!psurf)
return;
zink_batch_reference_resource(&ctx->batch, zink_resource(psurf->texture));
struct zink_surface *transient = zink_transient_surface(psurf);
if (transient)
zink_batch_reference_resource(&ctx->batch, zink_resource(transient->base.texture));
}
void
zink_batch_rp(struct zink_context *ctx)
{
@ -2865,12 +2876,9 @@ zink_batch_rp(struct zink_context *ctx)
zink_start_conditional_render(ctx);
zink_clear_framebuffer(ctx, clear_buffers);
if (ctx->pipeline_changed[0]) {
for (unsigned i = 0; i < ctx->fb_state.nr_cbufs; i++) {
if (ctx->fb_state.cbufs[i])
zink_batch_reference_resource(&ctx->batch, zink_resource(ctx->fb_state.cbufs[i]->texture));
}
if (ctx->fb_state.zsbuf)
zink_batch_reference_resource(&ctx->batch, zink_resource(ctx->fb_state.zsbuf->texture));
for (unsigned i = 0; i < ctx->fb_state.nr_cbufs; i++)
batch_ref_fb_surface(ctx, ctx->fb_state.cbufs[i]);
batch_ref_fb_surface(ctx, ctx->fb_state.zsbuf);
}
}
/* unable to previously determine that queries didn't split renderpasses: ensure queries start inside renderpass */
@ -3468,7 +3476,7 @@ zink_set_framebuffer_state(struct pipe_context *pctx,
}
res->fb_bind_count++;
res->fb_binds |= BITFIELD_BIT(i);
zink_batch_reference_resource(&ctx->batch, res);
batch_ref_fb_surface(ctx, ctx->fb_state.cbufs[i]);
if (util_format_has_alpha1(psurf->format)) {
if (!res->valid && !zink_fb_clear_full_exists(ctx, i))
ctx->void_clears |= (PIPE_CLEAR_COLOR0 << i);
@ -3480,7 +3488,7 @@ zink_set_framebuffer_state(struct pipe_context *pctx,
struct pipe_surface *psurf = ctx->fb_state.zsbuf;
struct zink_surface *transient = zink_transient_surface(psurf);
check_framebuffer_surface_mutable(pctx, psurf);
zink_batch_reference_resource(&ctx->batch, zink_resource(psurf->texture));
batch_ref_fb_surface(ctx, ctx->fb_state.zsbuf);
if (transient || psurf->nr_samples)
ctx->transient_attachments |= BITFIELD_BIT(PIPE_MAX_COLOR_BUFS);
if (!samples)