From 3c666172136c004b8be1c568a78aed480a57dcbc Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Thu, 14 Jul 2022 22:13:41 -0400 Subject: [PATCH] zink: move layout-setting for dynamic render attachments after no-op case this avoids unnecessarily terminating a renderpass to insert unnecessary barriers Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_context.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 9a5cb80..94e0821 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -2166,11 +2166,7 @@ begin_rendering(struct zink_context *ctx) /* init imageviews, base loadOp, formats */ for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { struct zink_surface *surf = zink_csurface(ctx->fb_state.cbufs[i]); - VkImageView iv = zink_prep_fb_attachment(ctx, surf, i); - if (!iv) - /* dead swapchain */ - return 0; - ctx->dynamic_fb.attachments[i].imageView = iv; + if (!surf || !zink_resource(surf->base.texture)->valid || (surf->is_swapchain && ctx->new_swapchain)) ctx->dynamic_fb.attachments[i].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; else @@ -2199,19 +2195,14 @@ begin_rendering(struct zink_context *ctx) struct zink_surface *surf = zink_csurface(ctx->fb_state.zsbuf); has_depth = util_format_has_depth(util_format_description(ctx->fb_state.zsbuf->format)); has_stencil = util_format_has_stencil(util_format_description(ctx->fb_state.zsbuf->format)); - VkImageView iv = zink_prep_fb_attachment(ctx, surf, ctx->fb_state.nr_cbufs); /* depth may or may not be used but init it anyway */ - ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].imageView = iv; - ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].imageLayout = zink_resource(surf->base.texture)->layout; if (zink_resource(surf->base.texture)->valid) ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; else ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; /* stencil may or may not be used but init it anyway */ - ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS+1].imageView = iv; - ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS+1].imageLayout = zink_resource(surf->base.texture)->layout; ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS+1].loadOp = ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].loadOp; if (has_depth) { @@ -2292,6 +2283,22 @@ begin_rendering(struct zink_context *ctx) if (!rp_changed && ctx->batch.in_rp) return 0; zink_batch_no_rp(ctx); + for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { + struct zink_surface *surf = zink_csurface(ctx->fb_state.cbufs[i]); + VkImageView iv = zink_prep_fb_attachment(ctx, surf, i); + if (!iv) + /* dead swapchain */ + return 0; + ctx->dynamic_fb.attachments[i].imageView = iv; + } + if (ctx->fb_state.zsbuf) { + struct zink_surface *surf = zink_csurface(ctx->fb_state.zsbuf); + VkImageView iv = zink_prep_fb_attachment(ctx, surf, ctx->fb_state.nr_cbufs); + ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].imageView = iv; + ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS].imageLayout = zink_resource(surf->base.texture)->layout; + ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS+1].imageView = iv; + ctx->dynamic_fb.attachments[PIPE_MAX_COLOR_BUFS+1].imageLayout = zink_resource(surf->base.texture)->layout; + } ctx->gfx_pipeline_state.dirty |= rp_changed; ctx->gfx_pipeline_state.rp_state = rp_state; -- 2.7.4