diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 42ef3153e5b..3fc510b06da 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -2077,6 +2077,40 @@ prep_fb_attachments(struct zink_context *ctx, VkImageView *att) } } +static void +update_framebuffer_state(struct zink_context *ctx, int old_w, int old_h) +{ + if (ctx->fb_state.width != old_w || ctx->fb_state.height != old_h) + ctx->scissor_changed = true; + /* get_framebuffer adds a ref if the fb is reused or created; + * always do get_framebuffer first to avoid deleting the same fb + * we're about to use + */ + struct zink_framebuffer *fb = ctx->get_framebuffer(ctx); + struct zink_screen *screen = zink_screen(ctx->base.screen); + if (ctx->framebuffer && !screen->info.have_KHR_imageless_framebuffer) { + simple_mtx_lock(&screen->framebuffer_mtx); + struct hash_entry *he = _mesa_hash_table_search(&screen->framebuffer_cache, &ctx->framebuffer->state); + if (ctx->framebuffer && !ctx->framebuffer->state.num_attachments) { + /* if this has no attachments then its lifetime has ended */ + _mesa_hash_table_remove(&screen->framebuffer_cache, he); + he = NULL; + /* ensure an unflushed fb doesn't get destroyed by deferring it */ + util_dynarray_append(&ctx->batch.state->dead_framebuffers, struct zink_framebuffer*, ctx->framebuffer); + ctx->framebuffer = NULL; + } + /* a framebuffer loses 1 ref every time we unset it; + * we do NOT add refs here, as the ref has already been added in + * get_framebuffer() + */ + if (zink_framebuffer_reference(screen, &ctx->framebuffer, NULL) && he) + _mesa_hash_table_remove(&screen->framebuffer_cache, he); + simple_mtx_unlock(&screen->framebuffer_mtx); + } + ctx->fb_changed |= ctx->framebuffer != fb; + ctx->framebuffer = fb; +} + static unsigned begin_render_pass(struct zink_context *ctx) { @@ -2524,37 +2558,9 @@ zink_set_framebuffer_state(struct pipe_context *pctx, samples = MAX3(transient ? transient->base.nr_samples : 1, surf->texture->nr_samples, 1); zink_resource(surf->texture)->fb_binds++; } - if (ctx->fb_state.width != w || ctx->fb_state.height != h) - ctx->scissor_changed = true; rebind_fb_state(ctx, NULL, true); ctx->fb_state.samples = MAX2(samples, 1); - /* get_framebuffer adds a ref if the fb is reused or created; - * always do get_framebuffer first to avoid deleting the same fb - * we're about to use - */ - struct zink_framebuffer *fb = ctx->get_framebuffer(ctx); - struct zink_screen *screen = zink_screen(ctx->base.screen); - if (ctx->framebuffer && !screen->info.have_KHR_imageless_framebuffer) { - simple_mtx_lock(&screen->framebuffer_mtx); - struct hash_entry *he = _mesa_hash_table_search(&screen->framebuffer_cache, &ctx->framebuffer->state); - if (ctx->framebuffer && !ctx->framebuffer->state.num_attachments) { - /* if this has no attachments then its lifetime has ended */ - _mesa_hash_table_remove(&screen->framebuffer_cache, he); - he = NULL; - /* ensure an unflushed fb doesn't get destroyed by deferring it */ - util_dynarray_append(&ctx->batch.state->dead_framebuffers, struct zink_framebuffer*, ctx->framebuffer); - ctx->framebuffer = NULL; - } - /* a framebuffer loses 1 ref every time we unset it; - * we do NOT add refs here, as the ref has already been added in - * get_framebuffer() - */ - if (zink_framebuffer_reference(screen, &ctx->framebuffer, NULL) && he) - _mesa_hash_table_remove(&screen->framebuffer_cache, he); - simple_mtx_unlock(&screen->framebuffer_mtx); - } - ctx->fb_changed |= ctx->framebuffer != fb; - ctx->framebuffer = fb; + update_framebuffer_state(ctx, w, h); uint8_t rast_samples = ctx->fb_state.samples - 1; /* update the shader key if applicable: