[Mesa-dev] [PATCH 06/18] gallium/u_blitter: cleanup

Marek Olšák maraeo at gmail.com
Thu Aug 17 18:31:27 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/util/u_blitter.c         | 42 ++++++--------------------
 src/gallium/auxiliary/util/u_blitter.h         |  1 -
 src/gallium/drivers/freedreno/freedreno_draw.c |  2 +-
 3 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 0fea7fc..9303179 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -116,27 +116,20 @@ struct blitter_context_priv
 
    /* Sampler state. */
    void *sampler_state;
    void *sampler_state_linear;
    void *sampler_state_rect;
    void *sampler_state_rect_linear;
 
    /* Rasterizer state. */
    void *rs_state, *rs_state_scissor, *rs_discard_state;
 
-   /* Viewport state. */
-   struct pipe_viewport_state viewport;
-
-   /* Destination surface dimensions. */
-   unsigned dst_width;
-   unsigned dst_height;
-
    boolean has_geometry_shader;
    boolean has_tessellation;
    boolean has_layered;
    boolean has_stream_out;
    boolean has_stencil_export;
    boolean has_texture_multisample;
    boolean has_tex_lz;
    boolean has_txf;
    boolean cube_as_2darray;
    boolean cached_all_shaders;
@@ -726,27 +719,28 @@ static void blitter_set_rectangle(struct blitter_context_priv *ctx,
    ctx->vertices[1][0][0] = 1;  /*v1.x*/
    ctx->vertices[1][0][1] = -1; /*v1.y*/
 
    ctx->vertices[2][0][0] = 1;  /*v2.x*/
    ctx->vertices[2][0][1] = 1;  /*v2.y*/
 
    ctx->vertices[3][0][0] = -1; /*v3.x*/
    ctx->vertices[3][0][1] = 1;  /*v3.y*/
 
    /* viewport */
-   ctx->viewport.scale[0] = width / 2.0;
-   ctx->viewport.scale[1] = height / 2.0;
-   ctx->viewport.scale[2] = 0;
-   ctx->viewport.translate[0] = width / 2.0 + x1;
-   ctx->viewport.translate[1] = height / 2.0 + y1;
-   ctx->viewport.translate[2] = depth;
-   ctx->base.pipe->set_viewport_states(ctx->base.pipe, 0, 1, &ctx->viewport);
+   struct pipe_viewport_state viewport;
+   viewport.scale[0] = width / 2.0;
+   viewport.scale[1] = height / 2.0;
+   viewport.scale[2] = 0;
+   viewport.translate[0] = width / 2.0 + x1;
+   viewport.translate[1] = height / 2.0 + y1;
+   viewport.translate[2] = depth;
+   ctx->base.pipe->set_viewport_states(ctx->base.pipe, 0, 1, &viewport);
 }
 
 static void blitter_set_clear_color(struct blitter_context_priv *ctx,
                                     const union pipe_color_union *color)
 {
    int i;
 
    if (color) {
       for (i = 0; i < 4; i++) {
          uint32_t *uiverts = (uint32_t *)ctx->vertices[i][1];
@@ -864,27 +858,20 @@ static void blitter_set_texcoords(struct blitter_context_priv *ctx,
    case PIPE_TEXTURE_2D:
       for (i = 0; i < 4; i++) {
          ctx->vertices[i][1][3] = (float) sample; /*r*/
       }
       break;
 
    default:;
    }
 }
 
-static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx,
-                                       unsigned width, unsigned height)
-{
-   ctx->dst_width = width;
-   ctx->dst_height = height;
-}
-
 static void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx,
                                          enum pipe_format src_format,
                                          enum pipe_format dst_format,
                                          enum pipe_texture_target target,
                                          unsigned src_nr_samples,
                                          unsigned dst_nr_samples,
                                          unsigned filter,
                                          bool use_txf)
 {
    struct pipe_context *pipe = ctx->base.pipe;
@@ -1330,21 +1317,20 @@ static void *get_clear_blend_state(struct blitter_context_priv *ctx,
             blend.rt[i].colormask = PIPE_MASK_RGBA;
          }
       }
 
       ctx->blend_clear[index] = pipe->create_blend_state(pipe, &blend);
    }
    return ctx->blend_clear[index];
 }
 
 void util_blitter_common_clear_setup(struct blitter_context *blitter,
-                                     unsigned width, unsigned height,
                                      unsigned clear_buffers,
                                      void *custom_blend, void *custom_dsa)
 {
    struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
    struct pipe_context *pipe = ctx->base.pipe;
 
    util_blitter_set_running_flag(blitter);
    blitter_check_saved_vertex_states(ctx);
    blitter_check_saved_fragment_states(ctx);
    blitter_disable_render_cond(ctx);
@@ -1362,38 +1348,37 @@ void util_blitter_common_clear_setup(struct blitter_context *blitter,
       pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_stencil);
    } else if (clear_buffers & PIPE_CLEAR_DEPTH) {
       pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_write_depth_keep_stencil);
    } else if (clear_buffers & PIPE_CLEAR_STENCIL) {
       pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_write_stencil);
    } else {
       pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
    }
 
    pipe->set_sample_mask(pipe, ~0);
-   blitter_set_dst_dimensions(ctx, width, height);
 }
 
 static void util_blitter_clear_custom(struct blitter_context *blitter,
                                       unsigned width, unsigned height,
                                       unsigned num_layers,
                                       unsigned clear_buffers,
                                       const union pipe_color_union *color,
                                       double depth, unsigned stencil,
                                       void *custom_blend, void *custom_dsa)
 {
    struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
    struct pipe_context *pipe = ctx->base.pipe;
    struct pipe_stencil_ref sr = { { 0 } };
 
    assert(ctx->has_layered || num_layers <= 1);
 
-   util_blitter_common_clear_setup(blitter, width, height, clear_buffers,
+   util_blitter_common_clear_setup(blitter, clear_buffers,
                                    custom_blend, custom_dsa);
 
    sr.ref_value[0] = stencil & 0xff;
    pipe->set_stencil_ref(pipe, &sr);
 
    pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
    bind_fs_write_all_cbufs(ctx);
 
    if (num_layers > 1 && ctx->has_layered) {
       blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
@@ -1620,22 +1605,20 @@ static void do_blits(struct blitter_context_priv *ctx,
    unsigned src_samples = src->texture->nr_samples;
    unsigned dst_samples = dst->texture->nr_samples;
    enum pipe_texture_target src_target = src->target;
    struct pipe_framebuffer_state fb_state = {0};
 
    /* Initialize framebuffer state. */
    fb_state.width = dst->width;
    fb_state.height = dst->height;
    fb_state.nr_cbufs = is_zsbuf ? 0 : 1;
 
-   blitter_set_dst_dimensions(ctx, fb_state.width, fb_state.height);
-
    if ((src_target == PIPE_TEXTURE_1D ||
         src_target == PIPE_TEXTURE_2D ||
         src_target == PIPE_TEXTURE_RECT) &&
        src_samples <= 1) {
       /* Draw the quad with the draw_rectangle callback. */
 
       /* Set texture coordinates. - use a pipe color union
        * for interface purposes.
        * XXX pipe_color_union is a wrong name since we use that to set
        * texture coordinates too.
@@ -2107,22 +2090,20 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
 
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
    fb_state.height = dstsurf->height;
    fb_state.nr_cbufs = 1;
    fb_state.cbufs[0] = dstsurf;
    fb_state.zsbuf = 0;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
-   blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
-
    num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1;
    if (num_layers > 1 && ctx->has_layered) {
       blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
       blitter_set_clear_color(ctx, color);
       blitter_draw(ctx, dstx, dsty, dstx+width, dsty+height, 0, num_layers);
    }
    else {
       blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
                               UTIL_BLITTER_ATTRIB_COLOR, color);
@@ -2185,22 +2166,20 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
 
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
    fb_state.height = dstsurf->height;
    fb_state.nr_cbufs = 0;
    fb_state.cbufs[0] = 0;
    fb_state.zsbuf = dstsurf;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
-   blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
-
    num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1;
    if (num_layers > 1 && ctx->has_layered) {
       blitter_set_common_draw_rect_state(ctx, FALSE, TRUE);
       blitter_draw(ctx, dstx, dsty, dstx+width, dsty+height, (float) depth, num_layers);
    }
    else {
       blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
       blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height,
                               (float) depth,
                               UTIL_BLITTER_ATTRIB_NONE, NULL);
@@ -2254,21 +2233,20 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
 	   fb_state.nr_cbufs = 1;
    } else {
 	   fb_state.cbufs[0] = NULL;
 	   fb_state.nr_cbufs = 0;
    }
    fb_state.zsbuf = zsurf;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, sample_mask);
 
    blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
-   blitter_set_dst_dimensions(ctx, zsurf->width, zsurf->height);
    blitter->draw_rectangle(blitter, 0, 0, zsurf->width, zsurf->height, depth,
                            UTIL_BLITTER_ATTRIB_NONE, NULL);
 
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
 
@@ -2454,21 +2432,20 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
    /* set a framebuffer state */
    fb_state.width = src->width0;
    fb_state.height = src->height0;
    fb_state.nr_cbufs = 2;
    fb_state.cbufs[0] = srcsurf;
    fb_state.cbufs[1] = dstsurf;
    fb_state.zsbuf = NULL;
    pipe->set_framebuffer_state(pipe, &fb_state);
 
    blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
-   blitter_set_dst_dimensions(ctx, src->width0, src->height0);
    blitter->draw_rectangle(blitter, 0, 0, src->width0, src->height0,
                            0, 0, NULL);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 
    pipe_surface_reference(&srcsurf, NULL);
    pipe_surface_reference(&dstsurf, NULL);
@@ -2504,20 +2481,19 @@ void util_blitter_custom_color(struct blitter_context *blitter,
    /* set a framebuffer state */
    fb_state.width = dstsurf->width;
    fb_state.height = dstsurf->height;
    fb_state.nr_cbufs = 1;
    fb_state.cbufs[0] = dstsurf;
    fb_state.zsbuf = 0;
    pipe->set_framebuffer_state(pipe, &fb_state);
    pipe->set_sample_mask(pipe, ~0);
 
    blitter_set_common_draw_rect_state(ctx, FALSE, FALSE);
-   blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
    blitter->draw_rectangle(blitter, 0, 0, dstsurf->width, dstsurf->height,
                            0, 0, NULL);
 
    util_blitter_restore_vertex_states(blitter);
    util_blitter_restore_fragment_states(blitter);
    util_blitter_restore_fb_state(blitter);
    util_blitter_restore_render_cond(blitter);
    util_blitter_unset_running_flag(blitter);
 }
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 912af83..81b948f 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -535,21 +535,20 @@ util_blitter_save_render_condition(struct blitter_context *blitter,
                                    struct pipe_query *query,
                                    boolean condition,
                                    enum pipe_render_cond_flag mode)
 {
    blitter->saved_render_cond_query = query;
    blitter->saved_render_cond_mode = mode;
    blitter->saved_render_cond_cond = condition;
 }
 
 void util_blitter_common_clear_setup(struct blitter_context *blitter,
-                                     unsigned width, unsigned height,
                                      unsigned clear_buffers,
                                      void *custom_blend, void *custom_dsa);
 
 void util_blitter_set_running_flag(struct blitter_context *blitter);
 void util_blitter_unset_running_flag(struct blitter_context *blitter);
 
 void util_blitter_restore_vertex_states(struct blitter_context *blitter);
 void util_blitter_restore_fragment_states(struct blitter_context *blitter);
 void util_blitter_restore_render_cond(struct blitter_context *blitter);
 void util_blitter_restore_fb_state(struct blitter_context *blitter);
diff --git a/src/gallium/drivers/freedreno/freedreno_draw.c b/src/gallium/drivers/freedreno/freedreno_draw.c
index a4a1975..d514700 100644
--- a/src/gallium/drivers/freedreno/freedreno_draw.c
+++ b/src/gallium/drivers/freedreno/freedreno_draw.c
@@ -242,21 +242,21 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 static void
 fd_blitter_clear(struct pipe_context *pctx, unsigned buffers,
 		const union pipe_color_union *color, double depth, unsigned stencil)
 {
 	struct fd_context *ctx = fd_context(pctx);
 	struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
 	struct blitter_context *blitter = ctx->blitter;
 
 	fd_blitter_pipe_begin(ctx, false, true, FD_STAGE_CLEAR);
 
-	util_blitter_common_clear_setup(blitter, pfb->width, pfb->height,
+	util_blitter_common_clear_setup(blitter,
 			buffers, NULL, NULL);
 
 	struct pipe_stencil_ref sr = {
 		.ref_value = { stencil & 0xff }
 	};
 	pctx->set_stencil_ref(pctx, &sr);
 
 	struct pipe_constant_buffer cb = {
 		.buffer_size = 16,
 		.user_buffer = &color->ui,
-- 
2.7.4



More information about the mesa-dev mailing list