[Mesa-dev] [PATCH 12/12] radeonsi: don't change viewport for blits, use window-space positions

Marek Olšák maraeo at gmail.com
Fri Oct 6 14:10:15 UTC 2017


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

The viewport state was an identity anyway.
---
 src/gallium/auxiliary/util/u_blitter.c           |  4 +++-
 src/gallium/auxiliary/util/u_blitter.h           |  1 +
 src/gallium/drivers/radeonsi/si_blit.c           |  1 -
 src/gallium/drivers/radeonsi/si_pipe.c           |  1 +
 src/gallium/drivers/radeonsi/si_state_draw.c     | 10 ----------
 src/gallium/drivers/radeonsi/si_state_shaders.c  |  1 +
 src/gallium/drivers/radeonsi/si_state_viewport.c |  7 -------
 7 files changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index a5c1f17..72e22e7 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -643,21 +643,23 @@ void util_blitter_restore_fragment_states(struct blitter_context *blitter)
    /* Sample mask. */
    if (ctx->base.is_sample_mask_saved) {
       pipe->set_sample_mask(pipe, ctx->base.saved_sample_mask);
       ctx->base.is_sample_mask_saved = false;
    }
 
    /* Miscellaneous states. */
    /* 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, 0, 1, &ctx->base.saved_viewport);
+
+   if (!blitter->skip_viewport_restore)
+      pipe->set_viewport_states(pipe, 0, 1, &ctx->base.saved_viewport);
 }
 
 static void blitter_check_saved_fb_state(struct blitter_context_priv *ctx)
 {
    assert(ctx->base.saved_fb_state.nr_cbufs != ~0u);
 }
 
 static void blitter_disable_render_cond(struct blitter_context_priv *ctx)
 {
    struct pipe_context *pipe = ctx->base.pipe;
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 0dd896d..dba7739 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -106,20 +106,21 @@ struct blitter_context
    void *saved_blend_state;   /**< blend state */
    void *saved_dsa_state;     /**< depth stencil alpha state */
    void *saved_velem_state;   /**< vertex elements state */
    void *saved_rs_state;      /**< rasterizer state */
    void *saved_fs, *saved_vs, *saved_gs, *saved_tcs, *saved_tes; /**< shaders */
 
    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;
+   bool skip_viewport_restore;
    bool is_sample_mask_saved;
    unsigned saved_sample_mask;
 
    unsigned saved_num_sampler_states;
    void *saved_sampler_states[PIPE_MAX_SAMPLERS];
 
    unsigned saved_num_sampler_views;
    struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
 
    unsigned cb_slot;
diff --git a/src/gallium/drivers/radeonsi/si_blit.c b/src/gallium/drivers/radeonsi/si_blit.c
index b3f44c3..40f8550 100644
--- a/src/gallium/drivers/radeonsi/si_blit.c
+++ b/src/gallium/drivers/radeonsi/si_blit.c
@@ -61,21 +61,20 @@ static void si_blitter_begin(struct pipe_context *ctx, enum si_blitter_op op)
 	util_blitter_save_so_targets(sctx->blitter, sctx->b.streamout.num_targets,
 				     (struct pipe_stream_output_target**)sctx->b.streamout.targets);
 	util_blitter_save_rasterizer(sctx->blitter, sctx->queued.named.rasterizer);
 
 	if (op & SI_SAVE_FRAGMENT_STATE) {
 		util_blitter_save_blend(sctx->blitter, sctx->queued.named.blend);
 		util_blitter_save_depth_stencil_alpha(sctx->blitter, sctx->queued.named.dsa);
 		util_blitter_save_stencil_ref(sctx->blitter, &sctx->stencil_ref.state);
 		util_blitter_save_fragment_shader(sctx->blitter, sctx->ps_shader.cso);
 		util_blitter_save_sample_mask(sctx->blitter, sctx->sample_mask.sample_mask);
-		util_blitter_save_viewport(sctx->blitter, &sctx->viewports.states[0]);
 		util_blitter_save_scissor(sctx->blitter, &sctx->scissors.states[0]);
 	}
 
 	if (op & SI_SAVE_FRAMEBUFFER)
 		util_blitter_save_framebuffer(sctx->blitter, &sctx->framebuffer.state);
 
 	if (op & SI_SAVE_TEXTURES) {
 		util_blitter_save_fragment_sampler_states(
 			sctx->blitter, 2,
 			(void**)sctx->samplers[PIPE_SHADER_FRAGMENT].sampler_states);
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index f922f17..f0bfeb6 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -248,20 +248,21 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
 	else
 		si_init_dma_functions(sctx);
 
 	if (sscreen->b.debug_flags & DBG_FORCE_DMA)
 		sctx->b.b.resource_copy_region = sctx->b.dma_copy;
 
 	sctx->blitter = util_blitter_create(&sctx->b.b);
 	if (sctx->blitter == NULL)
 		goto fail;
 	sctx->blitter->draw_rectangle = si_draw_rectangle;
+	sctx->blitter->skip_viewport_restore = true;
 
 	sctx->sample_mask.sample_mask = 0xffff;
 
 	/* these must be last */
 	si_begin_new_cs(sctx);
 
 	if (sctx->b.chip_class >= GFX9) {
 		sctx->wait_mem_scratch = (struct r600_resource*)
 			pipe_buffer_create(screen, 0, PIPE_USAGE_DEFAULT, 4);
 		if (!sctx->wait_mem_scratch)
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c
index 8e54151..c6c15c1 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -1508,30 +1508,20 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
 void si_draw_rectangle(struct blitter_context *blitter,
 		       void *vertex_elements_cso,
 		       blitter_get_vs_func get_vs,
 		       int x1, int y1, int x2, int y2,
 		       float depth, unsigned num_instances,
 		       enum blitter_attrib_type type,
 		       const union blitter_attrib *attrib)
 {
 	struct pipe_context *pipe = util_blitter_get_pipe(blitter);
 	struct si_context *sctx = (struct si_context*)pipe;
-	struct pipe_viewport_state viewport;
-
-	/* setup viewport */
-	viewport.scale[0] = 1.0f;
-	viewport.scale[1] = 1.0f;
-	viewport.scale[2] = 1.0f;
-	viewport.translate[0] = 0.0f;
-	viewport.translate[1] = 0.0f;
-	viewport.translate[2] = 0.0f;
-	pipe->set_viewport_states(pipe, 0, 1, &viewport);
 
 	/* Pack position coordinates as signed int16. */
 	sctx->vs_blit_sh_data[0] = (uint32_t)(x1 & 0xffff) |
 				   ((uint32_t)(y1 & 0xffff) << 16);
 	sctx->vs_blit_sh_data[1] = (uint32_t)(x2 & 0xffff) |
 				   ((uint32_t)(y2 & 0xffff) << 16);
 	sctx->vs_blit_sh_data[2] = fui(depth);
 
 	switch (type) {
 	case UTIL_BLITTER_ATTRIB_COLOR:
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index 90c3cf7..40a76c8 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -3435,20 +3435,21 @@ void *si_get_blit_vs(struct si_context *sctx, enum blitter_attrib_type type,
 	}
 	if (*vs)
 		return *vs;
 
 	struct ureg_program *ureg = ureg_create(PIPE_SHADER_VERTEX);
 	if (!ureg)
 		return NULL;
 
 	/* Tell the shader to load VS inputs from SGPRs: */
 	ureg_property(ureg, TGSI_PROPERTY_VS_BLIT_SGPRS, vs_blit_property);
+	ureg_property(ureg, TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION, true);
 
 	/* This is just a pass-through shader with 1-3 MOV instructions. */
 	ureg_MOV(ureg,
 		 ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0),
 		 ureg_DECL_vs_input(ureg, 0));
 
 	if (type != UTIL_BLITTER_ATTRIB_NONE) {
 		ureg_MOV(ureg,
 			 ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 0),
 			 ureg_DECL_vs_input(ureg, 1));
diff --git a/src/gallium/drivers/radeonsi/si_state_viewport.c b/src/gallium/drivers/radeonsi/si_state_viewport.c
index 0d6b7a8..f416558 100644
--- a/src/gallium/drivers/radeonsi/si_state_viewport.c
+++ b/src/gallium/drivers/radeonsi/si_state_viewport.c
@@ -56,27 +56,20 @@ static void si_get_scissor_from_viewport(struct si_context *ctx,
 					 struct si_signed_scissor *scissor)
 {
 	float tmp, minx, miny, maxx, maxy;
 
 	/* Convert (-1, -1) and (1, 1) from clip space into window space. */
 	minx = -vp->scale[0] + vp->translate[0];
 	miny = -vp->scale[1] + vp->translate[1];
 	maxx = vp->scale[0] + vp->translate[0];
 	maxy = vp->scale[1] + vp->translate[1];
 
-	/* r600_draw_rectangle sets this. Disable the scissor. */
-	if (minx == -1 && miny == -1 && maxx == 1 && maxy == 1) {
-		scissor->minx = scissor->miny = 0;
-		scissor->maxx = scissor->maxy = SI_MAX_SCISSOR;
-		return;
-	}
-
 	/* Handle inverted viewports. */
 	if (minx > maxx) {
 		tmp = minx;
 		minx = maxx;
 		maxx = tmp;
 	}
 	if (miny > maxy) {
 		tmp = miny;
 		miny = maxy;
 		maxy = tmp;
-- 
2.7.4



More information about the mesa-dev mailing list