[Mesa-dev] [PATCH 3/4] util/blitter: make sure the blitter can restore all viewports

Marek Olšák maraeo at gmail.com
Thu May 23 14:44:27 PDT 2013


Same as the the first patch: u_blitter doesn't really need to change
more than one scissor and viewport. With the start_slot parameter in
set_viewport_states and set_scissor_states, you can just save, set,
and restore the first slot. Note that the same approach is also used
for the vertex buffer (only the first slot is changed by u_blitter).

Marek

On Thu, May 23, 2013 at 10:33 PM, Zack Rusin <zackr at vmware.com> wrote:
> in case a driver supports multiple viewports the blitter needs
> to be able to restore all of them and not just the first one.
>
> Signed-off-by: Zack Rusin <zackr at vmware.com>
> ---
>  src/gallium/auxiliary/util/u_blitter.c             |    6 +++--
>  src/gallium/auxiliary/util/u_blitter.h             |   24 +++++++++++++-------
>  src/gallium/drivers/freedreno/freedreno_resource.c |    4 ++--
>  src/gallium/drivers/i915/i915_surface.c            |    4 ++--
>  src/gallium/drivers/ilo/ilo_blit.c                 |    2 +-
>  src/gallium/drivers/llvmpipe/lp_surface.c          |    4 ++--
>  src/gallium/drivers/nv30/nv30_miptree.c            |    4 ++--
>  src/gallium/drivers/r300/r300_blit.c               |    4 ++--
>  src/gallium/drivers/r600/r600_blit.c               |    4 ++--
>  src/gallium/drivers/radeonsi/r600_blit.c           |    2 +-
>  src/gallium/drivers/softpipe/sp_surface.c          |    4 ++--
>  src/gallium/drivers/svga/svga_pipe_blit.c          |    4 ++--
>  12 files changed, 38 insertions(+), 28 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
> index e985376..8274b79 100644
> --- a/src/gallium/auxiliary/util/u_blitter.c
> +++ b/src/gallium/auxiliary/util/u_blitter.c
> @@ -504,7 +504,8 @@ static void blitter_restore_fragment_states(struct blitter_context_priv *ctx)
>     /* XXX check whether these are saved and whether they need to be restored
>      * (depending on the operation) */
>     pipe->set_stencil_ref(pipe, &ctx->base.saved_stencil_ref);
> -   pipe->set_viewport_states(pipe, 1, &ctx->base.saved_viewport);
> +   pipe->set_viewport_states(pipe, ctx->base.num_saved_viewports,
> +                             ctx->base.saved_viewports);
>  }
>
>  static void blitter_check_saved_fb_state(struct blitter_context_priv *ctx)
> @@ -1496,7 +1497,8 @@ void util_blitter_blit_generic(struct blitter_context *blitter,
>     blitter_restore_textures(ctx);
>     blitter_restore_fb_state(ctx);
>     if (scissor) {
> -      pipe->set_scissor_states(pipe, 1, &ctx->base.saved_scissor);
> +      pipe->set_scissor_states(pipe, ctx->base.num_saved_scissors,
> +                               ctx->base.saved_scissors);
>     }
>     blitter_restore_render_cond(ctx);
>     blitter_unset_running_flag(ctx);
> diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
> index 1901584..5d4296a 100644
> --- a/src/gallium/auxiliary/util/u_blitter.h
> +++ b/src/gallium/auxiliary/util/u_blitter.h
> @@ -106,8 +106,10 @@ struct blitter_context
>
>     struct pipe_framebuffer_state saved_fb_state;  /**< framebuffer state */
>     struct pipe_stencil_ref saved_stencil_ref;     /**< stencil ref */
> -   struct pipe_viewport_state saved_viewport;
> -   struct pipe_scissor_state saved_scissor;
> +   struct pipe_viewport_state saved_viewports[PIPE_MAX_VIEWPORTS];
> +   unsigned num_saved_viewports;
> +   struct pipe_scissor_state saved_scissors[PIPE_MAX_VIEWPORTS];
> +   unsigned num_saved_scissors;
>     boolean is_sample_mask_saved;
>     unsigned saved_sample_mask;
>
> @@ -442,17 +444,23 @@ void util_blitter_save_framebuffer(struct blitter_context *blitter,
>  }
>
>  static INLINE
> -void util_blitter_save_viewport(struct blitter_context *blitter,
> -                                struct pipe_viewport_state *state)
> +void util_blitter_save_viewports(struct blitter_context *blitter,
> +                                 unsigned num_viewports,
> +                                 struct pipe_viewport_state *states)
>  {
> -   blitter->saved_viewport = *state;
> +   blitter->num_saved_viewports = num_viewports;
> +   memcpy(blitter->saved_viewports, states,
> +          sizeof(struct pipe_viewport_state) * num_viewports);
>  }
>
>  static INLINE
> -void util_blitter_save_scissor(struct blitter_context *blitter,
> -                               struct pipe_scissor_state *state)
> +void util_blitter_save_scissors(struct blitter_context *blitter,
> +                               unsigned num_scissors,
> +                               struct pipe_scissor_state *states)
>  {
> -   blitter->saved_scissor = *state;
> +   blitter->num_saved_scissors = num_scissors;
> +   memcpy(blitter->saved_scissors, states,
> +          sizeof(struct pipe_viewport_state) * num_scissors);
>  }
>
>  static INLINE
> diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
> index 00f3db8..7a0c68d 100644
> --- a/src/gallium/drivers/freedreno/freedreno_resource.c
> +++ b/src/gallium/drivers/freedreno/freedreno_resource.c
> @@ -254,8 +254,8 @@ fd_blit(struct pipe_context *pctx, const struct pipe_blit_info *blit_info)
>         util_blitter_save_vertex_elements(ctx->blitter, ctx->vtx);
>         util_blitter_save_vertex_shader(ctx->blitter, ctx->prog.vp);
>         util_blitter_save_rasterizer(ctx->blitter, ctx->rasterizer);
> -       util_blitter_save_viewport(ctx->blitter, &ctx->viewport);
> -       util_blitter_save_scissor(ctx->blitter, &ctx->scissor);
> +       util_blitter_save_viewports(ctx->blitter, 1, &ctx->viewport);
> +       util_blitter_save_scissors(ctx->blitter, 1, &ctx->scissor);
>         util_blitter_save_fragment_shader(ctx->blitter, ctx->prog.fp);
>         util_blitter_save_blend(ctx->blitter, ctx->blend);
>         util_blitter_save_depth_stencil_alpha(ctx->blitter, ctx->zsa);
> diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c
> index b8eef89..e46f90d 100644
> --- a/src/gallium/drivers/i915/i915_surface.c
> +++ b/src/gallium/drivers/i915/i915_surface.c
> @@ -52,8 +52,8 @@ i915_util_blitter_save_states(struct i915_context *i915)
>     util_blitter_save_rasterizer(i915->blitter, (void *)i915->rasterizer);
>     util_blitter_save_fragment_shader(i915->blitter, i915->fs);
>     util_blitter_save_vertex_shader(i915->blitter, i915->vs);
> -   util_blitter_save_viewport(i915->blitter, &i915->viewport);
> -   util_blitter_save_scissor(i915->blitter, &i915->scissor);
> +   util_blitter_save_viewports(i915->blitter, 1, &i915->viewport);
> +   util_blitter_save_scissors(i915->blitter, 1, &i915->scissor);
>     util_blitter_save_vertex_elements(i915->blitter, i915->velems);
>     util_blitter_save_vertex_buffer_slot(i915->blitter,
>                                      i915->vertex_buffers);
> diff --git a/src/gallium/drivers/ilo/ilo_blit.c b/src/gallium/drivers/ilo/ilo_blit.c
> index e3fd67c..e787861 100644
> --- a/src/gallium/drivers/ilo/ilo_blit.c
> +++ b/src/gallium/drivers/ilo/ilo_blit.c
> @@ -135,7 +135,7 @@ ilo_blitter_begin(struct ilo_context *ilo, enum ilo_blitter_op op)
>     util_blitter_save_blend(ilo->blitter, ilo->blend);
>
>     /* undocumented? */
> -   util_blitter_save_viewport(ilo->blitter, &ilo->viewport);
> +   util_blitter_save_viewports(ilo->blitter, 1, &ilo->viewport);
>     util_blitter_save_stencil_ref(ilo->blitter, &ilo->stencil_ref);
>     util_blitter_save_sample_mask(ilo->blitter, ilo->sample_mask);
>
> diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c
> index 5e6a6eb..036b129 100644
> --- a/src/gallium/drivers/llvmpipe/lp_surface.c
> +++ b/src/gallium/drivers/llvmpipe/lp_surface.c
> @@ -214,8 +214,8 @@ static void lp_blit(struct pipe_context *pipe,
>     util_blitter_save_so_targets(lp->blitter, lp->num_so_targets,
>                                  (struct pipe_stream_output_target**)lp->so_targets);
>     util_blitter_save_rasterizer(lp->blitter, (void*)lp->rasterizer);
> -   util_blitter_save_viewport(lp->blitter, &lp->viewport);
> -   util_blitter_save_scissor(lp->blitter, &lp->scissor);
> +   util_blitter_save_viewports(lp->blitter, 1, &lp->viewport);
> +   util_blitter_save_scissors(lp->blitter, 1, &lp->scissor);
>     util_blitter_save_fragment_shader(lp->blitter, lp->fs);
>     util_blitter_save_blend(lp->blitter, (void*)lp->blend);
>     util_blitter_save_depth_stencil_alpha(lp->blitter, (void*)lp->depth_stencil);
> diff --git a/src/gallium/drivers/nv30/nv30_miptree.c b/src/gallium/drivers/nv30/nv30_miptree.c
> index 4f5c445..327b170 100644
> --- a/src/gallium/drivers/nv30/nv30_miptree.c
> +++ b/src/gallium/drivers/nv30/nv30_miptree.c
> @@ -198,8 +198,8 @@ nv30_blit(struct pipe_context *pipe,
>     util_blitter_save_vertex_elements(nv30->blitter, nv30->vertex);
>     util_blitter_save_vertex_shader(nv30->blitter, nv30->vertprog.program);
>     util_blitter_save_rasterizer(nv30->blitter, nv30->rast);
> -   util_blitter_save_viewport(nv30->blitter, &nv30->viewport);
> -   util_blitter_save_scissor(nv30->blitter, &nv30->scissor);
> +   util_blitter_save_viewports(nv30->blitter, 1, &nv30->viewport);
> +   util_blitter_save_scissors(nv30->blitter, 1, &nv30->scissor);
>     util_blitter_save_fragment_shader(nv30->blitter, nv30->fragprog.program);
>     util_blitter_save_blend(nv30->blitter, nv30->blend);
>     util_blitter_save_depth_stencil_alpha(nv30->blitter,
> diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c
> index 76f8327..a5f0b61 100644
> --- a/src/gallium/drivers/r300/r300_blit.c
> +++ b/src/gallium/drivers/r300/r300_blit.c
> @@ -66,8 +66,8 @@ static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op o
>      util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state);
>      util_blitter_save_fragment_shader(r300->blitter, r300->fs.state);
>      util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state);
> -    util_blitter_save_viewport(r300->blitter, &r300->viewport);
> -    util_blitter_save_scissor(r300->blitter, r300->scissor_state.state);
> +    util_blitter_save_viewports(r300->blitter, 1, &r300->viewport);
> +    util_blitter_save_scissors(r300->blitter, 1, r300->scissor_state.state);
>      util_blitter_save_sample_mask(r300->blitter, *(unsigned*)r300->sample_mask.state);
>      util_blitter_save_vertex_buffer_slot(r300->blitter, r300->vertex_buffer);
>      util_blitter_save_vertex_elements(r300->blitter, r300->velems);
> diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
> index 058bf81..db50c63 100644
> --- a/src/gallium/drivers/r600/r600_blit.c
> +++ b/src/gallium/drivers/r600/r600_blit.c
> @@ -63,8 +63,8 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
>         util_blitter_save_rasterizer(rctx->blitter, rctx->rasterizer_state.cso);
>
>         if (op & R600_SAVE_FRAGMENT_STATE) {
> -               util_blitter_save_viewport(rctx->blitter, &rctx->viewport.state);
> -               util_blitter_save_scissor(rctx->blitter, &rctx->scissor.scissor);
> +               util_blitter_save_viewports(rctx->blitter, 1, &rctx->viewport.state);
> +               util_blitter_save_scissors(rctx->blitter, 1, &rctx->scissor.scissor);
>                 util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader);
>                 util_blitter_save_blend(rctx->blitter, rctx->blend_state.cso);
>                 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->dsa_state.cso);
> diff --git a/src/gallium/drivers/radeonsi/r600_blit.c b/src/gallium/drivers/radeonsi/r600_blit.c
> index f11f110..73c862a 100644
> --- a/src/gallium/drivers/radeonsi/r600_blit.c
> +++ b/src/gallium/drivers/radeonsi/r600_blit.c
> @@ -59,7 +59,7 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
>         util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader);
>         util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements);
>         if (rctx->queued.named.viewport) {
> -               util_blitter_save_viewport(rctx->blitter, &rctx->queued.named.viewport->viewport);
> +               util_blitter_save_viewports(rctx->blitter, 1, &rctx->queued.named.viewport->viewport);
>         }
>         util_blitter_save_vertex_buffer_slot(rctx->blitter, rctx->vertex_buffer);
>         util_blitter_save_so_targets(rctx->blitter, rctx->num_so_targets,
> diff --git a/src/gallium/drivers/softpipe/sp_surface.c b/src/gallium/drivers/softpipe/sp_surface.c
> index 911c34d..98b2ff2 100644
> --- a/src/gallium/drivers/softpipe/sp_surface.c
> +++ b/src/gallium/drivers/softpipe/sp_surface.c
> @@ -63,8 +63,8 @@ static void sp_blit(struct pipe_context *pipe,
>     util_blitter_save_so_targets(sp->blitter, sp->num_so_targets,
>                       (struct pipe_stream_output_target**)sp->so_targets);
>     util_blitter_save_rasterizer(sp->blitter, sp->rasterizer);
> -   util_blitter_save_viewport(sp->blitter, &sp->viewport);
> -   util_blitter_save_scissor(sp->blitter, &sp->scissor);
> +   util_blitter_save_viewports(sp->blitter, 1, &sp->viewport);
> +   util_blitter_save_scissors(sp->blitter, 1, &sp->scissor);
>     util_blitter_save_fragment_shader(sp->blitter, sp->fs);
>     util_blitter_save_blend(sp->blitter, sp->blend);
>     util_blitter_save_depth_stencil_alpha(sp->blitter, sp->depth_stencil);
> diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c
> index a44ed12..9571a84 100644
> --- a/src/gallium/drivers/svga/svga_pipe_blit.c
> +++ b/src/gallium/drivers/svga/svga_pipe_blit.c
> @@ -190,8 +190,8 @@ static void svga_blit(struct pipe_context *pipe,
>     /*util_blitter_save_so_targets(svga->blitter, svga->num_so_targets,
>                       (struct pipe_stream_output_target**)svga->so_targets);*/
>     util_blitter_save_rasterizer(svga->blitter, (void*)svga->curr.rast);
> -   util_blitter_save_viewport(svga->blitter, &svga->curr.viewport);
> -   util_blitter_save_scissor(svga->blitter, &svga->curr.scissor);
> +   util_blitter_save_viewports(svga->blitter, 1, &svga->curr.viewport);
> +   util_blitter_save_scissors(svga->blitter, 1, &svga->curr.scissor);
>     util_blitter_save_fragment_shader(svga->blitter, svga->curr.fs);
>     util_blitter_save_blend(svga->blitter, (void*)svga->curr.blend);
>     util_blitter_save_depth_stencil_alpha(svga->blitter,
> --
> 1.7.10.4
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list