gallium/util: allow scissored blits for stencil-fallback
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 1 Oct 2020 11:02:34 +0000 (13:02 +0200)
committerMarge Bot <eric+marge@anholt.net>
Fri, 2 Oct 2020 07:14:18 +0000 (07:14 +0000)
It's also useful to be able to use scissor-testing for fallback-blits,
as an CTS test-case does just that.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6960>

src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_blitter.h

index 1de3f75..01b56f3 100644 (file)
@@ -2821,7 +2821,8 @@ util_blitter_stencil_fallback(struct blitter_context *blitter,
                               const struct pipe_box *dstbox,
                               struct pipe_resource *src,
                               unsigned src_level,
-                              const struct pipe_box *srcbox)
+                              const struct pipe_box *srcbox,
+                              const struct pipe_scissor_state *scissor)
 {
    struct blitter_context_priv *ctx = (struct blitter_context_priv *)blitter;
    struct pipe_context *pipe = ctx->base.pipe;
@@ -2857,13 +2858,24 @@ util_blitter_stencil_fallback(struct blitter_context *blitter,
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
-   blitter_set_common_draw_rect_state(ctx, false,
+   blitter_set_common_draw_rect_state(ctx, scissor != NULL,
       util_framebuffer_get_num_samples(&fb_state) > 1);
    blitter_set_dst_dimensions(ctx, dst_view->width, dst_view->height);
 
-   pipe->clear_depth_stencil(pipe, dst_view, PIPE_CLEAR_STENCIL, 0.0, 0,
-                             dstbox->x, dstbox->y, dstbox->width, dstbox->height,
-                             true);
+   if (scissor) {
+      pipe->clear_depth_stencil(pipe, dst_view, PIPE_CLEAR_STENCIL, 0.0, 0,
+                                MAX2(dstbox->x, scissor->minx),
+                                MAX2(dstbox->y, scissor->miny),
+                                MIN2(dstbox->x + dstbox->width, scissor->maxx) - dstbox->x,
+                                MIN2(dstbox->y + dstbox->height, scissor->maxy) - dstbox->y,
+                                true);
+      pipe->set_scissor_states(pipe, 0, 1, scissor);
+   } else {
+      pipe->clear_depth_stencil(pipe, dst_view, PIPE_CLEAR_STENCIL, 0.0, 0,
+                                dstbox->x, dstbox->y,
+                                dstbox->width, dstbox->height,
+                                true);
+   }
 
    pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &src_view);
    pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &ctx->sampler_state);
@@ -2904,6 +2916,9 @@ util_blitter_stencil_fallback(struct blitter_context *blitter,
                               &coord);
    }
 
+   if (scissor)
+      pipe->set_scissor_states(pipe, 0, 1, &ctx->base.saved_scissor);
+
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_textures(blitter);
index 2ec113d..79605d3 100644 (file)
@@ -407,7 +407,8 @@ void util_blitter_stencil_fallback(struct blitter_context *blitter,
                                    const struct pipe_box *dstbox,
                                    struct pipe_resource *src,
                                    unsigned src_level,
-                                   const struct pipe_box *srcbox);
+                                   const struct pipe_box *srcbox,
+                                   const struct pipe_scissor_state *scissor);
 
 /* The functions below should be used to save currently bound constant state
  * objects inside a driver. The objects are automatically restored at the end