diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c index 69a97be7979..d9be12f65ff 100644 --- a/src/gallium/drivers/zink/zink_clear.c +++ b/src/gallium/drivers/zink/zink_clear.c @@ -525,3 +525,46 @@ zink_clear_apply_conditionals(struct zink_context *ctx) } } } + +static void +fb_clears_apply_or_discard_internal(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only, int i) +{ + struct zink_framebuffer_clear *fb_clear = &ctx->fb_clears[i]; + if (fb_clear->enabled) { + if (zink_blit_region_fills(region, pres->width0, pres->height0)) { + /* we know we can skip these */ + zink_fb_clears_discard(ctx, pres); + return; + } + for (int j = 0; j < zink_fb_clear_count(fb_clear); j++) { + struct zink_framebuffer_clear_data *clear = zink_fb_clear_element(fb_clear, j); + struct u_rect scissor = {clear->scissor.minx, clear->scissor.maxx, + clear->scissor.miny, clear->scissor.maxy}; + if (!clear->has_scissor || zink_blit_region_covers(region, scissor)) { + /* this is a clear that isn't fully covered by our pending write */ + if (!discard_only) + fb_clears_apply_internal(ctx, pres, i); + return; + } + } + /* if we haven't already returned, then we know we can discard */ + zink_fb_clears_discard(ctx, pres); + } +} + +void +zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only) +{ + if (zink_resource(pres)->aspect == VK_IMAGE_ASPECT_COLOR_BIT) { + for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { + if (ctx->fb_state.cbufs[i] && ctx->fb_state.cbufs[i]->texture == pres) { + fb_clears_apply_or_discard_internal(ctx, pres, region, discard_only, i); + return; + } + } + } else { + if (ctx->fb_clears[PIPE_MAX_COLOR_BUFS].enabled && ctx->fb_state.zsbuf && ctx->fb_state.zsbuf->texture == pres) { + fb_clears_apply_or_discard_internal(ctx, pres, region, discard_only, PIPE_MAX_COLOR_BUFS); + } + } +} diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h index 13943f1afa6..43bf80e1826 100644 --- a/src/gallium/drivers/zink/zink_context.h +++ b/src/gallium/drivers/zink/zink_context.h @@ -340,6 +340,9 @@ zink_fb_clears_apply(struct zink_context *ctx, struct pipe_resource *pres); void zink_fb_clears_discard(struct zink_context *ctx, struct pipe_resource *pres); +void +zink_fb_clears_apply_or_discard(struct zink_context *ctx, struct pipe_resource *pres, struct u_rect region, bool discard_only); + void zink_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *dinfo,