gallium: add pipe cap for scissored clears and pass scissor state to clear() hook
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 24 Mar 2020 16:02:51 +0000 (12:02 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 29 Apr 2020 18:05:06 +0000 (18:05 +0000)
this adds a new pipe cap that drivers can support which enables passing buffer
clears with scissor test enabled through to be handled by the driver instead
of having mesa draw a quad

also adjust all existing clear() hooks to have the new parameter

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Vasily Khoruzhick <anarsoul@gmail.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4310>

63 files changed:
src/gallium/auxiliary/driver_ddebug/dd_draw.c
src/gallium/auxiliary/driver_ddebug/dd_pipe.h
src/gallium/auxiliary/driver_noop/noop_pipe.c
src/gallium/auxiliary/driver_rbug/rbug_context.c
src/gallium/auxiliary/driver_trace/tr_context.c
src/gallium/auxiliary/postprocess/pp_mlaa.c
src/gallium/auxiliary/postprocess/pp_run.c
src/gallium/auxiliary/util/u_screen.c
src/gallium/auxiliary/util/u_tests.c
src/gallium/auxiliary/util/u_threaded_context.c
src/gallium/docs/source/screen.rst
src/gallium/drivers/etnaviv/etnaviv_blt.c
src/gallium/drivers/etnaviv/etnaviv_rs.c
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/i915/i915_clear.c
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/iris/iris_clear.c
src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/llvmpipe/lp_clear.c
src/gallium/drivers/llvmpipe/lp_clear.h
src/gallium/drivers/nouveau/nv30/nv30_clear.c
src/gallium/drivers/nouveau/nv50/nv50_context.h
src/gallium/drivers/nouveau/nv50/nv50_surface.c
src/gallium/drivers/nouveau/nvc0/nvc0_context.h
src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/radeonsi/si_clear.c
src/gallium/drivers/softpipe/sp_clear.c
src/gallium/drivers/softpipe/sp_clear.h
src/gallium/drivers/svga/svga_pipe_clear.c
src/gallium/drivers/swr/swr_clear.cpp
src/gallium/drivers/tegra/tegra_context.c
src/gallium/drivers/v3d/v3dx_draw.c
src/gallium/drivers/vc4/vc4_draw.c
src/gallium/drivers/virgl/virgl_context.c
src/gallium/drivers/zink/zink_context.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_defines.h
src/gallium/state_trackers/nine/nine_state.c
src/gallium/tests/graw/clear.c
src/gallium/tests/graw/fs-fragcoord.c
src/gallium/tests/graw/fs-frontface.c
src/gallium/tests/graw/fs-test.c
src/gallium/tests/graw/fs-write-z.c
src/gallium/tests/graw/gs-test.c
src/gallium/tests/graw/occlusion-query.c
src/gallium/tests/graw/quad-sample.c
src/gallium/tests/graw/quad-tex.c
src/gallium/tests/graw/shader-leak.c
src/gallium/tests/graw/tex-srgb.c
src/gallium/tests/graw/tex-swizzle.c
src/gallium/tests/graw/tri-gs.c
src/gallium/tests/graw/tri-instanced.c
src/gallium/tests/graw/tri-large.c
src/gallium/tests/graw/tri.c
src/gallium/tests/graw/vs-test.c
src/gallium/tests/trivial/quad-tex.c
src/gallium/tests/trivial/tri.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_manager.c

index a0414a6cd5e87554f8cee6dcd14b5cbc333dfd56..b93890f4f99457660e0f898453b199f60bd6f239 100644 (file)
@@ -515,6 +515,9 @@ dd_dump_clear(struct dd_draw_state *dstate, struct call_clear *info, FILE *f)
 {
    fprintf(f, "%s:\n", __func__+8);
    DUMP_M(uint, info, buffers);
+   fprintf(f, "  scissor_state: %d,%d %d,%d\n",
+              info->scissor_state.minx, info->scissor_state.miny,
+              info->scissor_state.maxx, info->scissor_state.maxy);
    DUMP_M_ADDR(color_union, info, color);
    DUMP_M(double, info, depth);
    DUMP_M(hex, info, stencil);
@@ -1478,7 +1481,7 @@ dd_context_flush_resource(struct pipe_context *_pipe,
 }
 
 static void
-dd_context_clear(struct pipe_context *_pipe, unsigned buffers,
+dd_context_clear(struct pipe_context *_pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state,
                  const union pipe_color_union *color, double depth,
                  unsigned stencil)
 {
@@ -1488,12 +1491,14 @@ dd_context_clear(struct pipe_context *_pipe, unsigned buffers,
 
    record->call.type = CALL_CLEAR;
    record->call.info.clear.buffers = buffers;
+   if (scissor_state)
+      record->call.info.clear.scissor_state = *scissor_state;
    record->call.info.clear.color = *color;
    record->call.info.clear.depth = depth;
    record->call.info.clear.stencil = stencil;
 
    dd_before_draw(dctx, record);
-   pipe->clear(pipe, buffers, color, depth, stencil);
+   pipe->clear(pipe, buffers, scissor_state, color, depth, stencil);
    dd_after_draw(dctx, record);
 }
 
index 1c3487c20113a64792ec3d8a71e796d393583da7..cf5d879c2d8ef511eea9af6e5bccb4a43bdcd46f 100644 (file)
@@ -93,6 +93,7 @@ struct call_resource_copy_region
 struct call_clear
 {
    unsigned buffers;
+   struct pipe_scissor_state scissor_state;
    union pipe_color_union color;
    double depth;
    unsigned stencil;
index 4ffff6c1db4f539588284e60b876fe3e2943266f..dc6454c916599172898355d63f4daf52e105f83e 100644 (file)
@@ -253,7 +253,7 @@ static void noop_texture_subdata(struct pipe_context *pipe,
 /*
  * clear/copy
  */
-static void noop_clear(struct pipe_context *ctx, unsigned buffers,
+static void noop_clear(struct pipe_context *ctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
                        const union pipe_color_union *color, double depth, unsigned stencil)
 {
 }
index 7c5a2929d891717bd97438a406c4db619374934b..a36f3377e8c2cc357b70bd03aef9fcc58bf6b0df 100644 (file)
@@ -921,6 +921,7 @@ rbug_flush_resource(struct pipe_context *_pipe,
 static void
 rbug_clear(struct pipe_context *_pipe,
            unsigned buffers,
+           const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color,
            double depth,
            unsigned stencil)
@@ -931,6 +932,7 @@ rbug_clear(struct pipe_context *_pipe,
    mtx_lock(&rb_pipe->call_mutex);
    pipe->clear(pipe,
                buffers,
+               scissor_state,
                color,
                depth,
                stencil);
index 083458dc147958556eb46c5af7790516f8d214eb..4b19b6c31fad28369820577ef095b28b86c93f3f 100644 (file)
@@ -1175,6 +1175,7 @@ trace_context_flush_resource(struct pipe_context *_pipe,
 static void
 trace_context_clear(struct pipe_context *_pipe,
                     unsigned buffers,
+                    const struct pipe_scissor_state *scissor_state,
                     const union pipe_color_union *color,
                     double depth,
                     unsigned stencil)
@@ -1186,6 +1187,9 @@ trace_context_clear(struct pipe_context *_pipe,
 
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(uint, buffers);
+   trace_dump_arg_begin("scissor_state");
+   trace_dump_scissor_state(scissor_state);
+   trace_dump_arg_end();
    trace_dump_arg_begin("color");
    if (color)
       trace_dump_array(float, color->f, 4);
@@ -1195,7 +1199,7 @@ trace_context_clear(struct pipe_context *_pipe,
    trace_dump_arg(float, depth);
    trace_dump_arg(uint, stencil);
 
-   pipe->clear(pipe, buffers, color, depth, stencil);
+   pipe->clear(pipe, buffers, scissor_state, color, depth, stencil);
 
    trace_dump_call_end();
 }
index e3ce5eaf015b322f83edf21ad3062d9ce039e2ab..51e3e0260fa1177803839c2b7521275f6f65131d 100644 (file)
@@ -122,7 +122,7 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    pp_filter_set_fb(p);
    pp_filter_misc_state(p);
    cso_set_depth_stencil_alpha(p->cso, &mstencil);
-   p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR0,
+   p->pipe->clear(p->pipe, PIPE_CLEAR_STENCIL | PIPE_CLEAR_COLOR0, NULL,
                   &p->clear_color, 0, 0);
 
    {
index 813225332fc1ddce2506068f2bfcdb9a749a50bf..c6987153f7303da06e5866e81dd2b1f658555a88 100644 (file)
@@ -300,5 +300,5 @@ void
 pp_filter_set_clear_fb(struct pp_program *p)
 {
    cso_set_framebuffer(p->cso, &p->framebuffer);
-   p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR0, &p->clear_color, 0, 0);
+   p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR0, NULL, &p->clear_color, 0, 0);
 }
index 54ebe77420dc0642c4cb41f94e2388dec8929f20..ae024f0e65033ce9598a109b626018ad242e9d63 100644 (file)
@@ -223,6 +223,7 @@ u_pipe_screen_get_param_defaults(struct pipe_screen *pscreen,
    case PIPE_CAP_SHAREABLE_SHADERS:
    case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
    case PIPE_CAP_CLEAR_TEXTURE:
+   case PIPE_CAP_CLEAR_SCISSORED:
    case PIPE_CAP_DRAW_PARAMETERS:
    case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
    case PIPE_CAP_MULTI_DRAW_INDIRECT:
index 8ff22bccd4eb484109b2039f28702c75eace858b..00f75906173154fa0a1a3ff5f30fa73536b76de9 100644 (file)
@@ -177,7 +177,7 @@ util_set_common_states_and_clear(struct cso_context *cso, struct pipe_context *c
    util_set_rasterizer_normal(cso);
    util_set_max_viewport(cso, cb);
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR0, (void*)clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR0, NULL, (void*)clear_color, 0, 0);
 }
 
 static void
index cfe88d310e86d7a0dcbe3ffddf5ae65b15a8b2bc..d8536af77be15b9af3320cb87b723222d413d7b9 100644 (file)
@@ -2343,20 +2343,22 @@ tc_invalidate_resource(struct pipe_context *_pipe,
 
 struct tc_clear {
    unsigned buffers;
+   struct pipe_scissor_state scissor_state;
    union pipe_color_union color;
    double depth;
    unsigned stencil;
+   bool scissor_state_set;
 };
 
 static void
 tc_call_clear(struct pipe_context *pipe, union tc_payload *payload)
 {
    struct tc_clear *p = (struct tc_clear *)payload;
-   pipe->clear(pipe, p->buffers, &p->color, p->depth, p->stencil);
+   pipe->clear(pipe, p->buffers, p->scissor_state_set ? &p->scissor_state : NULL, &p->color, p->depth, p->stencil);
 }
 
 static void
-tc_clear(struct pipe_context *_pipe, unsigned buffers,
+tc_clear(struct pipe_context *_pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state,
          const union pipe_color_union *color, double depth,
          unsigned stencil)
 {
@@ -2364,6 +2366,9 @@ tc_clear(struct pipe_context *_pipe, unsigned buffers,
    struct tc_clear *p = tc_add_struct_typed_call(tc, TC_CALL_clear, tc_clear);
 
    p->buffers = buffers;
+   if (scissor_state)
+      p->scissor_state = *scissor_state;
+   p->scissor_state_set = !!scissor_state;
    p->color = *color;
    p->depth = depth;
    p->stencil = stencil;
index a40461fed708b26ebcc09ba94e961c18f6f83160..e006ef195681771699e7d925506972f50f50783c 100644 (file)
@@ -303,6 +303,8 @@ The integer capabilities:
   a compressed block is copied to/from a plain pixel of the same size.
 * ``PIPE_CAP_CLEAR_TEXTURE``: Whether `clear_texture` will be
   available in contexts.
+* ``PIPE_CAP_CLEAR_SCISSORED``: Whether `clear` can accept a scissored
+  bounding box.
 * ``PIPE_CAP_DRAW_PARAMETERS``: Whether ``TGSI_SEMANTIC_BASEVERTEX``,
   ``TGSI_SEMANTIC_BASEINSTANCE``, and ``TGSI_SEMANTIC_DRAWID`` are
   supported in vertex shaders.
index 225d2a7c24363d7011d5176d69e97663107c11ee..63fcb8c649b321da700f72a9927a2e7ca3583394 100644 (file)
@@ -339,7 +339,7 @@ etna_blit_clear_zs_blt(struct pipe_context *pctx, struct pipe_surface *dst,
 }
 
 static void
-etna_clear_blt(struct pipe_context *pctx, unsigned buffers,
+etna_clear_blt(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color, double depth, unsigned stencil)
 {
    struct etna_context *ctx = etna_context(pctx);
index 47ba585e30422ff1901f9a90f5d82b2eb1b9438d..bcd11e05a789e0cba65e6d1963414e8d2a49a573 100644 (file)
@@ -407,7 +407,7 @@ etna_blit_clear_zs_rs(struct pipe_context *pctx, struct pipe_surface *dst,
 }
 
 static void
-etna_clear_rs(struct pipe_context *pctx, unsigned buffers,
+etna_clear_rs(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color, double depth, unsigned stencil)
 {
    struct etna_context *ctx = etna_context(pctx);
index 8be7135eb93bd0589067256eb392f02d6f4caf94..0ba2106c0cc5536dd4a4dc2f211edcdc80c132f0 100644 (file)
@@ -308,7 +308,7 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 }
 
 static void
-fd_clear(struct pipe_context *pctx, unsigned buffers,
+fd_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
                const union pipe_color_union *color, double depth, unsigned stencil)
 {
        struct fd_context *ctx = fd_context(pctx);
index a1c3314f4e2a9c84692ca88a9e80822458b8a36a..56281c23f66cbcd364078aac9c8b17354e5fa75f 100644 (file)
@@ -217,6 +217,7 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers,
  */
 void
 i915_clear_blitter(struct pipe_context *pipe, unsigned buffers,
+                   const struct pipe_scissor_state *scissor_state,
                    const union pipe_color_union *color,
                    double depth, unsigned stencil)
 {
@@ -245,6 +246,7 @@ i915_clear_blitter(struct pipe_context *pipe, unsigned buffers,
 
 void
 i915_clear_render(struct pipe_context *pipe, unsigned buffers,
+                  const struct pipe_scissor_state *scissor_state,
                   const union pipe_color_union *color,
                   double depth, unsigned stencil)
 {
index 626a17f5606c78b89e3d1e8e5aebafd4b5d0d250..1e27326093695f5916e901fbbf03b4ffdf6c76d3 100644 (file)
@@ -376,9 +376,11 @@ void i915_emit_hardware_state(struct i915_context *i915 );
  * i915_clear.c: 
  */
 void i915_clear_blitter(struct pipe_context *pipe, unsigned buffers,
+                        const struct pipe_scissor_state *scissor_state,
                         const union pipe_color_union *color,
                         double depth, unsigned stencil);
 void i915_clear_render(struct pipe_context *pipe, unsigned buffers,
+                       const struct pipe_scissor_state *scissor_state,
                        const union pipe_color_union *color,
                        double depth, unsigned stencil);
 void i915_clear_emit(struct pipe_context *pipe, unsigned buffers,
index 163783a8504b45990ed64f83b8edb32c4d574c02..4c3adfdc39f2eae96f05937cf27d98fe2a1b7ae9 100644 (file)
@@ -636,6 +636,7 @@ clear_depth_stencil(struct iris_context *ice,
 static void
 iris_clear(struct pipe_context *ctx,
            unsigned buffers,
+           const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *p_color,
            double depth,
            unsigned stencil)
index 294210709f7bc12358d5520e7d96b2c202ea3faf..15474a08f9f1308e29e3af38fcbe3725091ad717 100644 (file)
@@ -131,7 +131,7 @@ lima_damage_rect_union(struct pipe_scissor_state *rect,
 }
 
 static void
-lima_clear(struct pipe_context *pctx, unsigned buffers,
+lima_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color, double depth, unsigned stencil)
 {
    struct lima_context *ctx = lima_context(pctx);
index 064206fc238c03b3cc52504903bcd24fefcd17ef..3fd67b79dacff988aaf0e7c81be3daa3a434342b 100644 (file)
@@ -47,6 +47,7 @@
 void
 llvmpipe_clear(struct pipe_context *pipe, 
                unsigned buffers,
+               const struct pipe_scissor_state *scissor_state,
                const union pipe_color_union *color,
                double depth,
                unsigned stencil)
index 7249929cbc7fe19e82bd55ebc93362e8d807bd81..9d28d2559a3ca679778dcbf077a51c7a495ae2cf 100644 (file)
@@ -37,6 +37,7 @@ struct pipe_context;
 
 extern void
 llvmpipe_clear(struct pipe_context *pipe, unsigned buffers,
+               const struct pipe_scissor_state *scissor_state,
                const union pipe_color_union *color,
                double depth, unsigned stencil);
 
index 4e6df1eff60630c7e183a2b568b2e8d2b4df9b91..b307b6795640dacfd5eedd944286249e946629cc 100644 (file)
@@ -50,7 +50,7 @@ pack_zeta(enum pipe_format format, double depth, unsigned stencil)
 }
 
 static void
-nv30_clear(struct pipe_context *pipe, unsigned buffers,
+nv30_clear(struct pipe_context *pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color, double depth, unsigned stencil)
 {
    struct nv30_context *nv30 = nv30_context(pipe);
index b9da8b50565225875d1323d2d93816091111e7b9..9894e9d613fd08a403dcdd5362eade17dd7a172f 100644 (file)
@@ -248,6 +248,7 @@ bool nv50_state_validate_3d(struct nv50_context *, uint32_t);
 
 /* nv50_surface.c */
 extern void nv50_clear(struct pipe_context *, unsigned buffers,
+                       const struct pipe_scissor_state *scissor_state,
                        const union pipe_color_union *color,
                        double depth, unsigned stencil);
 extern void nv50_init_surface_functions(struct nv50_context *);
index 34c2633916bd1d20b8252b073500ec810d74227e..2b39c2592e08f3e19afe5e9f0bf8cf7aaa4b8a91 100644 (file)
@@ -524,7 +524,7 @@ nv50_clear_texture(struct pipe_context *pipe,
 }
 
 void
-nv50_clear(struct pipe_context *pipe, unsigned buffers,
+nv50_clear(struct pipe_context *pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color,
            double depth, unsigned stencil)
 {
index 4cfd207d4c0473b13a52c8522f890723909d9ab0..dacb48411ba0258ceafec94c426293b207f468bb 100644 (file)
@@ -356,6 +356,7 @@ bool nvc0_state_validate_3d(struct nvc0_context *, uint32_t);
 
 /* nvc0_surface.c */
 extern void nvc0_clear(struct pipe_context *, unsigned buffers,
+                       const struct pipe_scissor_state *scissor_state,
                        const union pipe_color_union *color,
                        double depth, unsigned stencil);
 extern void nvc0_init_surface_functions(struct nvc0_context *);
index 2b38fe6e7f575a0d472f7ef349deac863e638134..538effdb531bee889dceaa8bfcd2d9f4ddad69db 100644 (file)
@@ -682,6 +682,7 @@ nvc0_clear_depth_stencil(struct pipe_context *pipe,
 
 void
 nvc0_clear(struct pipe_context *pipe, unsigned buffers,
+           const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color,
            double depth, unsigned stencil)
 {
index 33fad6208b63e89a65d0e67521a34f4e78038cf9..7ff551d093b505d822f96f1848beaa34f5690bd9 100644 (file)
@@ -125,6 +125,7 @@ static void
 panfrost_clear(
         struct pipe_context *pipe,
         unsigned buffers,
+        const struct pipe_scissor_state *scissor_state,
         const union pipe_color_union *color,
         double depth, unsigned stencil)
 {
index 33344982c1ea53e1dd983fa1065902e96b3a82be..b627e01389823f00ee051137a74a833ca8e22a39 100644 (file)
@@ -202,6 +202,7 @@ DEBUG_GET_ONCE_BOOL_OPTION(hyperz, "RADEON_HYPERZ", FALSE)
 /* Clear currently bound buffers. */
 static void r300_clear(struct pipe_context* pipe,
                        unsigned buffers,
+                       const struct pipe_scissor_state *scissor_state,
                        const union pipe_color_union *color,
                        double depth,
                        unsigned stencil)
index 606b3892e3b387f7fce07e504a08b2aa9bd828e9..32154b11b7cc93b2c1a882176e303a88f5d094da 100644 (file)
@@ -463,6 +463,7 @@ static bool r600_decompress_subresource(struct pipe_context *ctx,
 }
 
 static void r600_clear(struct pipe_context *ctx, unsigned buffers,
+                      const struct pipe_scissor_state *scissor_state,
                       const union pipe_color_union *color,
                       double depth, unsigned stencil)
 {
index 8c89c9be1995473fb500a01ce6442b14222ba386..12512e7df73c2d7741105d009ba6e23cca810490 100644 (file)
@@ -540,6 +540,7 @@ static void si_do_fast_color_clear(struct si_context *sctx, unsigned *buffers,
 }
 
 static void si_clear(struct pipe_context *ctx, unsigned buffers,
+                     const struct pipe_scissor_state *scissor_state,
                      const union pipe_color_union *color, double depth, unsigned stencil)
 {
    struct si_context *sctx = (struct si_context *)ctx;
index d2626a24333ea6f8576432ca5a7b1333098afef0..300cbd077d9638a039a2a3af59f4ffaf479dc193 100644 (file)
@@ -47,6 +47,7 @@
  */
 void
 softpipe_clear(struct pipe_context *pipe, unsigned buffers,
+               const struct pipe_scissor_state *scissor_state,
                const union pipe_color_union *color,
                double depth, unsigned stencil)
 {
index 0398e5badbb60c71b1e22cd227bc198ed40f471f..b9a489a633cde1cc69f0eb6abe23086af73f3e27 100644 (file)
@@ -36,6 +36,7 @@ struct pipe_context;
 
 extern void
 softpipe_clear(struct pipe_context *pipe, unsigned buffers,
+               const struct pipe_scissor_state *scissor_state,
                const union pipe_color_union *color,
                double depth, unsigned stencil);
 
index 75507fc1752bb6b915fcc75631a3afbee7fb6ffa..89a9b533f91eeaa6154a0e8026c3444f98e1da89 100644 (file)
@@ -230,7 +230,7 @@ try_clear(struct svga_context *svga,
  * No masking, no scissor (clear entire buffer).
  */
 static void
-svga_clear(struct pipe_context *pipe, unsigned buffers,
+svga_clear(struct pipe_context *pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *color,
           double depth, unsigned stencil)
 {
index 4473f76a0a29af6274bb5a663bcc40c895c7674a..d579cbdde9f6fa294783323f8554b9454dcd60c4 100644 (file)
@@ -27,6 +27,7 @@
 static void
 swr_clear(struct pipe_context *pipe,
           unsigned buffers,
+          const struct pipe_scissor_state *scissor_state,
           const union pipe_color_union *color,
           double depth,
           unsigned stencil)
index e91baf0be343c95a6cba8c6004063cafdc1313eb..c3ae90e4d6db95ad2e9acb59af0e2394da08a7c7 100644 (file)
@@ -700,13 +700,13 @@ tegra_blit(struct pipe_context *pcontext, const struct pipe_blit_info *pinfo)
 }
 
 static void
-tegra_clear(struct pipe_context *pcontext, unsigned buffers,
+tegra_clear(struct pipe_context *pcontext, unsigned buffers, const struct pipe_scissor_state *scissor_state,
             const union pipe_color_union *color, double depth,
             unsigned stencil)
 {
    struct tegra_context *context = to_tegra_context(pcontext);
 
-   context->gpu->clear(context->gpu, buffers, color, depth, stencil);
+   context->gpu->clear(context->gpu, buffers, NULL, color, depth, stencil);
 }
 
 static void
index 9bbfe4537e72a956a550847a7f3cf1a4ee7fe60b..f4377e79d4a272446ce99c1183ef64bd79fee3cc 100644 (file)
@@ -1744,7 +1744,7 @@ v3d_tlb_clear(struct v3d_job *job, unsigned buffers,
 }
 
 static void
-v3d_clear(struct pipe_context *pctx, unsigned buffers,
+v3d_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
           const union pipe_color_union *color, double depth, unsigned stencil)
 {
         struct v3d_context *v3d = v3d_context(pctx);
index 3da60ff64a8374678f3e668068631cd209835215..b4523bb12500b39b93811c598f8cbb4470d9bd08 100644 (file)
@@ -517,7 +517,7 @@ pack_rgba(enum pipe_format format, const float *rgba)
 }
 
 static void
-vc4_clear(struct pipe_context *pctx, unsigned buffers,
+vc4_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scissor_state *scissor_state,
           const union pipe_color_union *color, double depth, unsigned stencil)
 {
         struct vc4_context *vc4 = vc4_context(pctx);
index d83bd7a40b77ee18ea5e78c330c9f3615115f872..381a9c023a824609b8cbee66e0e72598dbebd397 100644 (file)
@@ -816,6 +816,7 @@ static void virgl_bind_fs_state(struct pipe_context *ctx,
 
 static void virgl_clear(struct pipe_context *ctx,
                                 unsigned buffers,
+                                const struct pipe_scissor_state *scissor_state,
                                 const union pipe_color_union *color,
                                 double depth, unsigned stencil)
 {
index 4c2fe44da5396c8a007f8a182b86c51756687085..323f87e27acb24ad98d5536cd92672e31c26e07b 100644 (file)
@@ -812,6 +812,7 @@ zink_resource_barrier(VkCommandBuffer cmdbuf, struct zink_resource *res,
 static void
 zink_clear(struct pipe_context *pctx,
            unsigned buffers,
+           const struct pipe_scissor_state *scissor_state,
            const union pipe_color_union *pcolor,
            double depth, unsigned stencil)
 {
index 3a8b9eba462ac6479b68ad936ba33e6e545ebf6b..37957466ded4d22ef91a79b7c930c2b9b83157ac 100644 (file)
@@ -512,12 +512,14 @@ struct pipe_context {
     * The entire buffers are cleared (no scissor, no colormask, etc).
     *
     * \param buffers  bitfield of PIPE_CLEAR_* values.
+    * \param scissor_state  the scissored region to clear
     * \param color  pointer to a union of fiu array for each of r, g, b, a.
     * \param depth  depth clear value in [0,1].
     * \param stencil  stencil clear value
     */
    void (*clear)(struct pipe_context *pipe,
                  unsigned buffers,
+                 const struct pipe_scissor_state *scissor_state,
                  const union pipe_color_union *color,
                  double depth,
                  unsigned stencil);
index 13e124bf72893e7a941c458b72401d6b56713dc9..dd0c7331b693f646d05cb553a1ac93cc088a0cc1 100644 (file)
@@ -817,6 +817,7 @@ enum pipe_cap
    PIPE_CAP_SHAREABLE_SHADERS,
    PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS,
    PIPE_CAP_CLEAR_TEXTURE,
+   PIPE_CAP_CLEAR_SCISSORED,
    PIPE_CAP_DRAW_PARAMETERS,
    PIPE_CAP_TGSI_PACK_HALF_FLOAT,
    PIPE_CAP_MULTI_DRAW_INDIRECT,
index 227e953959206906a0ddec8dbe54e6ce41af0c0c..8724ec87c81934fb32aee7bd43f858f1df4ae8e4 100644 (file)
@@ -2238,7 +2238,7 @@ CSMT_ITEM_NO_WAIT(nine_context_clear_fb,
          rect.x2 >= zsbuf_surf->desc.Width &&
          rect.y2 >= zsbuf_surf->desc.Height))) {
         DBG("Clear fast path\n");
-        pipe->clear(pipe, bufs, &rgba, Z, Stencil);
+        pipe->clear(pipe, bufs, NULL, &rgba, Z, Stencil);
         return;
     }
 
index 2a08ae154854e35f15cfd2865c52a5c65f9b6f42..522799c1e1ab1967c95315529049b18530be443b 100644 (file)
@@ -28,7 +28,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {1, 0, 1, 1} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    ctx->flush(ctx, NULL, 0);
 
    graw_save_surface_to_file(ctx, surf, NULL);
index 9afea0caa0bf86d3e0d13396bf16ecf615ce185c..016bbaa0410f4e472e9eb3dcb8ccf24000b3b695 100644 (file)
@@ -185,6 +185,7 @@ draw(void)
 
    info.ctx->clear(info.ctx,
               PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
+              NULL,
               &clear_color, 1.0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
    info.ctx->flush(info.ctx, NULL, 0);
index 3ad89f6b646c982c3b963c0a05260e3bf9c86c53..956c7fee3a0615cbdee5d0e0eefc2ffb1d245fa6 100644 (file)
@@ -159,6 +159,7 @@ draw(void)
 
    info.ctx->clear(info.ctx,
               PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
+              NULL,
               &clear_color, 1.0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
    info.ctx->flush(info.ctx, NULL, 0);
index a4182be55bd9b4c0c1be49e423204f69656beaa3..346bbedd61a39d33b48a5ae75b4daaae35d5eb39 100644 (file)
@@ -232,7 +232,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
    ctx->flush(ctx, NULL, 0);
 
index 196c67bc368852df756067c833336eb865c2c703..4002dce15f1595d4e446bf4d24b6b566c19efbe6 100644 (file)
@@ -164,6 +164,7 @@ draw(void)
 
    info.ctx->clear(info.ctx,
               PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
+              NULL,
               &clear_color, 1.0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, NUM_VERTS);
    info.ctx->flush(info.ctx, NULL, 0);
index a984e0acfb01e650f8d8f2b5ba717a2e1e22266a..5d3739c728132e9fd59af2ca1dafbf04b1ab49c3 100644 (file)
@@ -318,7 +318,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    if (draw_strip)
       util_draw_arrays(ctx, PIPE_PRIM_TRIANGLE_STRIP, 0, 4);
    else
index 1232c5bb40147e2f387fe10f2ff988ea5469055c..b639a9bb9a1c3ba4fe616c2d8b805cd83f89a7a9 100644 (file)
@@ -168,6 +168,7 @@ draw(void)
 
    info.ctx->clear(info.ctx,
                    PIPE_CLEAR_COLOR | PIPE_CLEAR_DEPTHSTENCIL,
+                   NULL,
                    &clear_color, 1.0, 0);
 
    q1 = info.ctx->create_query(info.ctx, PIPE_QUERY_OCCLUSION_COUNTER, 0);
index a5029484b3ba6956645deb1d70ee1686df39c8b0..043abdf5044948d6469d3afd61ef690e49489010 100644 (file)
@@ -148,7 +148,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {.5,.5,.5,1} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(ctx, PIPE_PRIM_QUADS, 0, 4);
    ctx->flush(ctx, NULL, 0);
 
index 35ba4fa3469adc16a8ea4e16165b284bde7a230a..40caad4ae90c485c36d96afb9aea329804976d53 100644 (file)
@@ -106,7 +106,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {.5,.5,.5,1} };
 
-   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
    info.ctx->flush(info.ctx, NULL, 0);
 
index 8fa1a727f54327e536437fcea14e6d148f12c7d5..90d674745fda0dc56c3dd06a8fccaefd23eaa0ca 100644 (file)
@@ -148,7 +148,7 @@ static void draw( void )
 
       ctx->bind_fs_state(ctx, fs);
 
-      ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+      ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
       util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, 1);
       ctx->flush(ctx, NULL, 0);
 
index 503350a68d8b2e6d4f6db248b9ac28b9e48cf7b3..964b4188b51dbac58e2b0a6523fcbaeac70773cc 100644 (file)
@@ -127,7 +127,7 @@ static void draw( void )
    clear_color.f[2] = 0.5;
    clear_color.f[3] = 1.0;
 
-   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
 
    info.ctx->set_sampler_views(info.ctx, PIPE_SHADER_FRAGMENT, 0, 1, &linear_sv);
    set_vertices(vertices1, 4);
index 787f324fc356c7df0bee75588b9efea455b032ab..538e12e7477ba3235f318e9e594ddd143751a7f2 100644 (file)
@@ -107,7 +107,7 @@ static void draw(void)
    clear_color.f[2] = 0.5;
    clear_color.f[3] = 1.0;
 
-   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_QUADS, 0, 4);
    info.ctx->flush(info.ctx, NULL, 0);
 
index ed721f378b1f9d03e79e71cb3c139f4d5d44ca89..6820bc530eaff0f49b2e66ab0998ecec57798013 100644 (file)
@@ -162,7 +162,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {1,0,1,1} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(ctx, PIPE_PRIM_TRIANGLES, 0, 3);
    ctx->flush(ctx, NULL, 0);
 
index 297377b894e26f35575e4c814d132a38052ddf1d..72dce01980c8390c0fde0133bdd6ca4d02c08fa3 100644 (file)
@@ -188,7 +188,7 @@ static void draw( void )
    union pipe_color_union clear_color = { {1,0,1,1} };
    struct pipe_draw_info info;
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
 
 
    util_draw_init_info(&info);
index 78a2ddbda449d86b4bfdb543632851b2f6becc7a..e1b0888bf04c06bfec6ecc804ef3441d1713df8f 100644 (file)
@@ -106,7 +106,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {1,0,1,1} };
 
-   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_TRIANGLES, 0, 3);
    info.ctx->flush(info.ctx, NULL, 0);
 
index 2267d98a8feafa5fe1ea19dd4ca7a247c87e4259..9882384a2f67faf7c887833ef586c5ee5e3125af 100644 (file)
@@ -103,7 +103,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {1,0,1,1} };
 
-   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   info.ctx->clear(info.ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(info.ctx, PIPE_PRIM_TRIANGLES, 0, 3);
    info.ctx->flush(info.ctx, NULL, 0);
 
index b3714543b3a8715b32a6985e6ae1b91d09d8064b..1b96914ad2a4e1f9e17357fff5b52c4f6fd0ec7c 100644 (file)
@@ -220,7 +220,7 @@ static void draw( void )
 {
    union pipe_color_union clear_color = { {.1,.3,.5,0} };
 
-   ctx->clear(ctx, PIPE_CLEAR_COLOR, &clear_color, 0, 0);
+   ctx->clear(ctx, PIPE_CLEAR_COLOR, NULL, &clear_color, 0, 0);
    util_draw_arrays(ctx, PIPE_PRIM_POINTS, 0, ARRAY_SIZE(vertices));
    ctx->flush(ctx, NULL, 0);
 
index 271dee648d661669b183d7fb0fec8c21e734c498..a30cfb9b9f7b4b2c92e4ffcf114451d758b93cfc 100644 (file)
@@ -309,7 +309,7 @@ static void draw(struct program *p)
        cso_set_framebuffer(p->cso, &p->framebuffer);
 
        /* clear the render target */
-       p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0);
+       p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, NULL, &p->clear_color, 0, 0);
 
        /* set misc state we care about */
        cso_set_blend(p->cso, &p->blend);
index 1e773cb28f931d91da02b1a1f5fd7a9963343743..79bb5d95086a562a399e198547c88157b98fd437 100644 (file)
@@ -246,7 +246,7 @@ static void draw(struct program *p)
        cso_set_framebuffer(p->cso, &p->framebuffer);
 
        /* clear the render target */
-       p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, &p->clear_color, 0, 0);
+       p->pipe->clear(p->pipe, PIPE_CLEAR_COLOR, NULL, &p->clear_color, 0, 0);
 
        /* set misc state we care about */
        cso_set_blend(p->cso, &p->blend);
index b7d44d2c1b54fc7af66639ac24bfe2be73974853..e38f44ed78bc5ac3ee17683e62deef74a6227cc8 100644 (file)
@@ -432,6 +432,7 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
       = ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
    GLbitfield quad_buffers = 0x0;
    GLbitfield clear_buffers = 0x0;
+   bool have_scissor_buffers = false;
    GLuint i;
 
    st_flush_bitmap_cache(st);
@@ -462,12 +463,14 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
             unsigned surf_colormask =
                util_format_colormask(util_format_description(strb->surface->format));
 
-            if (is_scissor_enabled(ctx, rb) ||
+            bool scissor = is_scissor_enabled(ctx, rb);
+            if ((scissor && !st->can_scissor_clear) ||
                 is_window_rectangle_enabled(ctx) ||
                 ((colormask & surf_colormask) != surf_colormask))
                quad_buffers |= PIPE_CLEAR_COLOR0 << i;
             else
                clear_buffers |= PIPE_CLEAR_COLOR0 << i;
+            have_scissor_buffers |= scissor && st->can_scissor_clear;
          }
       }
    }
@@ -510,10 +513,31 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
     * renderbuffers, because it's likely to be faster.
     */
    if (clear_buffers) {
+      const struct gl_scissor_rect *scissor = &ctx->Scissor.ScissorArray[0];
+      struct pipe_scissor_state scissor_state = {
+         .minx = MAX2(scissor->X, 0),
+         .miny = MAX2(scissor->Y, 0),
+         .maxx = MAX2(scissor->X + scissor->Width, 0),
+         .maxy = MAX2(scissor->Y + scissor->Height, 0),
+
+      };
+
+      /* Now invert Y if needed.
+       * Gallium drivers use the convention Y=0=top for surfaces.
+       */
+      if (st->state.fb_orientation == Y_0_TOP) {
+         const struct gl_framebuffer *fb = ctx->DrawBuffer;
+         /* use intermediate variables to avoid uint underflow */
+         GLint miny, maxy;
+         miny = fb->Height - scissor_state.maxy;
+         maxy = fb->Height - scissor_state.miny;
+         scissor_state.miny = MAX2(miny, 0);
+         scissor_state.maxy = MAX2(maxy, 0);
+      }
       /* We can't translate the clear color to the colorbuffer format,
        * because different colorbuffers may have different formats.
        */
-      st->pipe->clear(st->pipe, clear_buffers,
+      st->pipe->clear(st->pipe, clear_buffers, have_scissor_buffers ? &scissor_state : NULL,
                       (union pipe_color_union*)&ctx->Color.ClearColor,
                       ctx->Depth.Clear, ctx->Stencil.Clear);
    }
index 267aa32ad784871030bee5fc09a67790f6a5b1e7..a4a1ce5d4ad415195d3a7b24490faabdc77284ec 100644 (file)
@@ -182,6 +182,10 @@ struct st_context
    boolean draw_needs_minmax_index;
    boolean has_hw_atomics;
 
+
+   /* driver supports scissored clears */
+   boolean can_scissor_clear;
+
    /* Some state is contained in constant objects.
     * Other state is just parameter values.
     */
index ae600737cc687f282e343e4c7bf6c8537720daee..cc1572bcc316aa1f2a15e4bf128f967290182f64 100644 (file)
@@ -984,6 +984,8 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       }
    }
 
+   st->can_scissor_clear = !!st->pipe->screen->get_param(st->pipe->screen, PIPE_CAP_CLEAR_SCISSORED);
+
    st->invalidate_on_gl_viewport =
       smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE);