Mesa (main): zink: rework clear_depth_stencil hook
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Apr 22 01:11:06 UTC 2022
Module: Mesa
Branch: main
Commit: c3caf5f183bb895a351f283c76ead3a9cc4781ad
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c3caf5f183bb895a351f283c76ead3a9cc4781ad
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Thu Apr 14 08:42:57 2022 -0400
zink: rework clear_depth_stencil hook
u_blitter works great, but it doesn't handle recursion, so only use
it as a last resort
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16071>
---
src/gallium/drivers/zink/zink_clear.c | 47 ++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_clear.c b/src/gallium/drivers/zink/zink_clear.c
index 5a7701ca049..1c53de569fb 100644
--- a/src/gallium/drivers/zink/zink_clear.c
+++ b/src/gallium/drivers/zink/zink_clear.c
@@ -23,6 +23,7 @@
#include "zink_context.h"
#include "zink_kopper.h"
+#include "zink_framebuffer.h"
#include "zink_query.h"
#include "zink_resource.h"
#include "zink_screen.h"
@@ -513,10 +514,50 @@ zink_clear_depth_stencil(struct pipe_context *pctx, struct pipe_surface *dst,
bool render_condition_enabled)
{
struct zink_context *ctx = zink_context(pctx);
- zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS | (render_condition_enabled ? 0 : ZINK_BLIT_NO_COND_RENDER));
- util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth, stencil, dstx, dsty, width, height);
- if (!render_condition_enabled && ctx->render_condition_active)
+ struct zink_resource *res = zink_resource(dst->texture);
+ struct u_rect rect = {dstx, dstx + width, dsty, dsty + height};
+ bool needs_rp = !zink_blit_region_fills(rect, dst->texture->width0, dst->texture->height0);
+ needs_rp |= check_3d_layers(dst);
+ bool render_condition_active = ctx->render_condition_active;
+ if (res->fb_binds) { //current depth attachment
+ struct pipe_scissor_state scissor = {dstx, dsty, dstx + width, dsty + height};
+ if (!render_condition_enabled && render_condition_active) {
+ zink_stop_conditional_render(ctx);
+ ctx->render_condition_active = false;
+ }
+ unsigned orig_width = ctx->fb_state.width, orig_height = ctx->fb_state.height;
+ bool fb_changed = !zink_blit_region_fills(rect, ctx->fb_state.width, ctx->fb_state.height);
+ if (fb_changed) {
+ ctx->fb_state.width = dstx + width;
+ ctx->fb_state.height = dsty + height;
+ zink_update_framebuffer_state(ctx, orig_width, orig_height);
+ zink_batch_no_rp(ctx);
+ }
+ zink_clear(pctx, clear_flags, &scissor, NULL, depth, stencil);
+ zink_batch_rp(ctx);
+ if (fb_changed) {
+ ctx->fb_state.width = orig_width;
+ ctx->fb_state.height = orig_height;
+ zink_update_framebuffer_state(ctx, dstx + width, dsty + height);
+ zink_batch_no_rp(ctx);
+ }
+ } else {
+ if (needs_rp) {
+ zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS | (render_condition_enabled ? 0 : ZINK_BLIT_NO_COND_RENDER));
+ util_blitter_clear_depth_stencil(ctx->blitter, dst, clear_flags, depth, stencil, dstx, dsty, width, height);
+ } else {
+ VkImageAspectFlags aspects = 0;
+ if (clear_flags & PIPE_CLEAR_DEPTH)
+ aspects |= VK_IMAGE_ASPECT_DEPTH_BIT;
+ if (clear_flags & PIPE_CLEAR_STENCIL)
+ aspects |= VK_IMAGE_ASPECT_STENCIL_BIT;
+ for (unsigned i = 0; i < res->base.b.last_level; i++)
+ clear_zs_no_rp(ctx, res, aspects, depth, stencil, i, 0, res->base.b.array_size);
+ }
+ }
+ if (!render_condition_enabled && render_condition_active)
zink_start_conditional_render(ctx);
+ ctx->render_condition_active = render_condition_active;
}
bool
More information about the mesa-commit
mailing list