[Mesa-dev] [PATCH 17/19] r600g: implement MSAA color resolve

Marek Olšák maraeo at gmail.com
Thu Aug 9 09:07:29 PDT 2012


---
 src/gallium/auxiliary/util/u_blitter.c     |   61 +++++++++++++++++++++
 src/gallium/auxiliary/util/u_blitter.h     |    8 +++
 src/gallium/drivers/r600/evergreen_state.c |   24 +++++++--
 src/gallium/drivers/r600/r600_blit.c       |   80 ++++++++++++++++++++++++++++
 src/gallium/drivers/r600/r600_pipe.c       |    4 ++
 src/gallium/drivers/r600/r600_pipe.h       |    3 ++
 6 files changed, 177 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 1e37322..a5510d5 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -1491,3 +1491,64 @@ void util_blitter_copy_buffer(struct blitter_context *blitter,
    blitter_unset_running_flag(ctx);
    pipe_so_target_reference(&so_target, NULL);
 }
+
+/* probably radeon specific */
+void util_blitter_resolve_color_custom(struct blitter_context *blitter,
+				       struct pipe_resource *dst,
+				       unsigned dst_level,
+				       unsigned dst_layer,
+				       struct pipe_resource *src,
+				       unsigned src_layer,
+				       void *custom_blend)
+{
+   struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
+   struct pipe_context *pipe = ctx->base.pipe;
+   struct pipe_framebuffer_state fb_state;
+   struct pipe_surface *srcsurf, *dstsurf, surf_tmpl;
+
+   blitter_set_running_flag(ctx);
+   blitter_check_saved_vertex_states(ctx);
+   blitter_check_saved_fragment_states(ctx);
+
+   /* bind states */
+   pipe->bind_blend_state(pipe, custom_blend);
+   pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
+   pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
+   pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE));
+
+   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+   surf_tmpl.format = dst->format;
+   surf_tmpl.u.tex.level = dst_level;
+   surf_tmpl.u.tex.first_layer = dst_layer;
+   surf_tmpl.u.tex.last_layer = dst_layer;
+   surf_tmpl.usage = PIPE_BIND_RENDER_TARGET;
+
+   dstsurf = pipe->create_surface(pipe, dst, &surf_tmpl);
+
+   surf_tmpl.u.tex.level = 0;
+   surf_tmpl.u.tex.first_layer = src_layer;
+   surf_tmpl.u.tex.last_layer = src_layer;
+
+   srcsurf = pipe->create_surface(pipe, src, &surf_tmpl);
+
+   /* 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);
+   blitter_set_dst_dimensions(ctx, src->width0, src->height0);
+   blitter->draw_rectangle(blitter, 0, 0, src->width0, src->height0,
+                           0, 0, NULL);
+   blitter_restore_fb_state(ctx);
+   blitter_restore_vertex_states(ctx);
+   blitter_restore_fragment_states(ctx);
+   blitter_unset_running_flag(ctx);
+
+   pipe_surface_reference(&srcsurf, NULL);
+   pipe_surface_reference(&dstsurf, NULL);
+}
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 1881e6a..1207a9ae 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -300,6 +300,14 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
 				       unsigned sample_mask,
 				       void *dsa_stage, float depth);
 
+void util_blitter_resolve_color_custom(struct blitter_context *blitter,
+                                       struct pipe_resource *dst,
+                                       unsigned dst_level,
+                                       unsigned dst_layer,
+                                       struct pipe_resource *src,
+                                       unsigned src_layer,
+                                       void *custom_blend);
+
 /* The functions below should be used to save currently bound constant state
  * objects inside a driver. The objects are automatically restored at the end
  * of the util_blitter_{clear, copy_region, fill_region} functions and then
diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 08c76bc..e6e2fb2 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -669,8 +669,8 @@ boolean evergreen_is_format_supported(struct pipe_screen *screen,
 	return retval == usage;
 }
 
-static void *evergreen_create_blend_state(struct pipe_context *ctx,
-					const struct pipe_blend_state *state)
+static void *evergreen_create_blend_state_mode(struct pipe_context *ctx,
+					       const struct pipe_blend_state *state, int mode)
 {
 	struct r600_context *rctx = (struct r600_context *)ctx;
 	struct r600_pipe_blend *blend = CALLOC_STRUCT(r600_pipe_blend);
@@ -706,7 +706,7 @@ static void *evergreen_create_blend_state(struct pipe_context *ctx,
 	blend->cb_target_mask = target_mask;
 
 	if (target_mask)
-		color_control |= S_028808_MODE(V_028808_CB_NORMAL);
+		color_control |= S_028808_MODE(mode);
 	else
 		color_control |= S_028808_MODE(V_028808_CB_DISABLE);
 
@@ -756,6 +756,13 @@ static void *evergreen_create_blend_state(struct pipe_context *ctx,
 	return rstate;
 }
 
+static void *evergreen_create_blend_state(struct pipe_context *ctx,
+					const struct pipe_blend_state *state)
+{
+
+	return evergreen_create_blend_state_mode(ctx, state, V_028808_CB_NORMAL);
+}
+
 static void *evergreen_create_dsa_state(struct pipe_context *ctx,
 				   const struct pipe_depth_stencil_alpha_state *state)
 {
@@ -2991,6 +2998,17 @@ void evergreen_fetch_shader(struct pipe_context *ctx,
 				ve->fetch_shader, RADEON_USAGE_READ);
 }
 
+void *evergreen_create_resolve_blend(struct r600_context *rctx)
+{
+	struct pipe_blend_state blend;
+	struct r600_pipe_state *rstate;
+
+	memset(&blend, 0, sizeof(blend));
+	blend.rt[0].colormask = 0xf;
+	rstate = evergreen_create_blend_state_mode(&rctx->context, &blend, V_028808_CB_RESOLVE);
+	return rstate;
+}
+
 void *evergreen_create_db_flush_dsa(struct r600_context *rctx)
 {
 	struct pipe_depth_stencil_alpha_state dsa = {{0}};
diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index 41c2ef5..547386d 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -42,6 +42,8 @@ enum r600_blitter_op /* bitmask */
 			     R600_DISABLE_RENDER_COND,
 
 	R600_DECOMPRESS    = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND,
+
+	R600_COLOR_RESOLVE = R600_SAVE_FRAGMENT_STATE | R600_SAVE_FRAMEBUFFER | R600_DISABLE_RENDER_COND
 };
 
 static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op)
@@ -288,6 +290,82 @@ static void r600_copy_first_sample(struct pipe_context *ctx,
 	pipe_sampler_view_reference(&src_view, NULL);
 }
 
+static boolean is_simple_resolve(const struct pipe_resolve_info *info)
+{
+   unsigned dst_width = u_minify(info->dst.res->width0, info->dst.level);
+   unsigned dst_height = u_minify(info->dst.res->height0, info->dst.level);
+
+   return info->dst.res->format == info->src.res->format &&
+          dst_width == info->src.res->width0 &&
+          dst_height == info->src.res->height0 &&
+          info->dst.x0 == 0 &&
+          info->dst.y0 == 0 &&
+          info->dst.x1 == dst_width &&
+          info->dst.y1 == dst_height &&
+          info->src.x0 == 0 &&
+          info->src.y0 == 0 &&
+          info->src.x1 == dst_width &&
+          info->src.y1 == dst_height;
+}
+
+static void r600_color_resolve(struct pipe_context *ctx,
+			       const struct pipe_resolve_info *info)
+{
+	struct r600_context *rctx = (struct r600_context *)ctx;
+	struct pipe_screen *screen = ctx->screen;
+	struct pipe_resource *tmp, templ;
+	struct pipe_box box;
+
+	assert((info->mask & PIPE_MASK_RGBA) == PIPE_MASK_RGBA);
+
+	if (is_simple_resolve(info)) {
+		r600_blitter_begin(ctx, R600_COLOR_RESOLVE);
+		util_blitter_resolve_color_custom(rctx->blitter,
+						  info->dst.res, info->dst.level, info->dst.layer,
+						  info->src.res, info->src.layer,
+						  rctx->custom_blend_resolve);
+		r600_blitter_end(ctx);
+		return;
+	}
+
+	/* resolve into a temporary texture, then blit */
+	templ.target = PIPE_TEXTURE_2D;
+	templ.format = info->src.res->format;
+	templ.width0 = info->src.res->width0;
+	templ.height0 = info->src.res->height0;
+	templ.depth0 = 1;
+	templ.array_size = 1;
+	templ.last_level = 0;
+	templ.nr_samples = 0;
+	templ.usage = PIPE_USAGE_STATIC;
+	templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+	templ.flags = 0;
+
+	tmp = screen->resource_create(screen, &templ);
+
+	/* XXX use scissor, so that only the needed part of the resource is resolved */
+	r600_blitter_begin(ctx, R600_COLOR_RESOLVE);
+	util_blitter_resolve_color_custom(rctx->blitter,
+					  tmp, 0, 0,
+					  info->src.res, info->src.layer,
+					  rctx->custom_blend_resolve);
+	r600_blitter_end(ctx);
+
+	/* this is correct for upside-down blits too */
+	u_box_2d(info->src.x0,
+		 info->src.y0,
+		 info->src.x1 - info->src.x0,
+		 info->src.y1 - info->src.y0, &box);
+
+	r600_blitter_begin(ctx, R600_COPY_TEXTURE);
+	util_blitter_copy_texture(rctx->blitter, info->dst.res, info->dst.level,
+				  ~0, info->dst.x0, info->dst.y0, info->dst.layer,
+				  tmp, 0, 0, &box);
+	r600_blitter_end(ctx);
+
+	pipe_resource_reference(&tmp, NULL);
+}
+
 static void r600_resource_resolve(struct pipe_context *ctx,
 				  const struct pipe_resolve_info *info)
 {
@@ -313,6 +391,8 @@ static void r600_resource_resolve(struct pipe_context *ctx,
 	if ((info->mask & PIPE_MASK_ZS) ||
 	    util_format_is_pure_integer(info->src.res->format)) {
 		r600_copy_first_sample(ctx, info);
+	} else {
+		r600_color_resolve(ctx, info);
 	}
 }
 
diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c
index f3556de..76a019d 100644
--- a/src/gallium/drivers/r600/r600_pipe.c
+++ b/src/gallium/drivers/r600/r600_pipe.c
@@ -162,6 +162,9 @@ static void r600_destroy_context(struct pipe_context *context)
 	if (rctx->custom_dsa_flush) {
 		rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush);
 	}
+	if (rctx->custom_blend_resolve) {
+		rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_blend_resolve);
+	}
 	util_unreference_framebuffer_state(&rctx->framebuffer);
 
 	r600_context_fini(rctx);
@@ -254,6 +257,7 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void
 		if (evergreen_context_init(rctx))
 			goto fail;
 		rctx->custom_dsa_flush = evergreen_create_db_flush_dsa(rctx);
+		rctx->custom_blend_resolve = evergreen_create_resolve_blend(rctx);
 		rctx->has_vertex_cache = !(rctx->family == CHIP_CEDAR ||
 					   rctx->family == CHIP_PALM ||
 					   rctx->family == CHIP_SUMO ||
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 4cadab8..aeff528 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -326,6 +326,8 @@ struct r600_context {
 	boolean				has_vertex_cache;
 	unsigned			r6xx_num_clause_temp_gprs;
 	void				*custom_dsa_flush;
+	void				*custom_blend_resolve;
+
 	struct r600_screen		*screen;
 	struct radeon_winsys		*ws;
 	struct r600_pipe_state		*states[R600_PIPE_NSTATES];
@@ -465,6 +467,7 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
 void evergreen_fetch_shader(struct pipe_context *ctx, struct r600_vertex_element *ve);
 void *evergreen_create_db_flush_dsa(struct r600_context *rctx);
+void *evergreen_create_resolve_blend(struct r600_context *rctx);
 void evergreen_polygon_offset_update(struct r600_context *rctx);
 boolean evergreen_is_format_supported(struct pipe_screen *screen,
 				      enum pipe_format format,
-- 
1.7.9.5



More information about the mesa-dev mailing list