[Mesa-dev] [PATCH 3/8] radeonsi: implement set_min_samples

Marek Olšák maraeo at gmail.com
Wed May 7 07:00:31 PDT 2014


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

This is how per-sample shading is enabled.
---
 src/gallium/drivers/radeonsi/si_pipe.c  |  2 ++
 src/gallium/drivers/radeonsi/si_pipe.h  |  4 ++++
 src/gallium/drivers/radeonsi/si_state.c | 30 ++++++++++++++++++++++++++++--
 src/gallium/drivers/radeonsi/si_state.h |  1 +
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 22cd5b9..9fc1ea6 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -106,6 +106,8 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen, void *
 	/* Initialize cache_flush. */
 	sctx->cache_flush = si_atom_cache_flush;
 	sctx->atoms.cache_flush = &sctx->cache_flush;
+	sctx->msaa_config = si_atom_msaa_config;
+	sctx->atoms.msaa_config = &sctx->msaa_config;
 
 	sctx->atoms.streamout_begin = &sctx->b.streamout.begin_atom;
 	sctx->atoms.streamout_enable = &sctx->b.streamout.enable_atom;
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index a74bbcf..c3b7fb6 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -110,6 +110,7 @@ struct si_context {
 			struct r600_atom *streamout_begin;
 			struct r600_atom *streamout_enable; /* must be after streamout_begin */
 			struct r600_atom *framebuffer;
+			struct r600_atom *msaa_config;
 		};
 		struct r600_atom *array[0];
 	} atoms;
@@ -132,6 +133,9 @@ struct si_context {
 	struct r600_resource		*border_color_table;
 	unsigned			border_color_offset;
 
+	struct r600_atom		msaa_config;
+	int				ps_iter_samples;
+
 	unsigned default_ps_gprs, default_vs_gprs;
 
 	/* Below are variables from the old r600_context.
diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index 38a2acc..fd9de05 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -1921,8 +1921,9 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
 	sctx->framebuffer.atom.num_dw = state->nr_cbufs*15 + (8 - state->nr_cbufs)*3;
 	sctx->framebuffer.atom.num_dw += state->zsbuf ? 23 : 4;
 	sctx->framebuffer.atom.num_dw += 3; /* WINDOW_SCISSOR_BR */
-	sctx->framebuffer.atom.num_dw += 28; /* MSAA */
+	sctx->framebuffer.atom.num_dw += 18; /* MSAA sample locations */
 	sctx->framebuffer.atom.dirty = true;
+	sctx->msaa_config.dirty = true;
 }
 
 static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom *atom)
@@ -2026,7 +2027,30 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
 			       S_028208_BR_X(state->width) | S_028208_BR_Y(state->height));
 
 	cayman_emit_msaa_sample_locs(cs, sctx->framebuffer.nr_samples);
-	cayman_emit_msaa_config(cs, sctx->framebuffer.nr_samples, 1);
+}
+
+static void si_emit_msaa_config(struct r600_common_context *rctx, struct r600_atom *atom)
+{
+	struct si_context *sctx = (struct si_context *)rctx;
+	struct radeon_winsys_cs *cs = sctx->b.rings.gfx.cs;
+
+	cayman_emit_msaa_config(cs, sctx->framebuffer.nr_samples,
+				sctx->ps_iter_samples);
+}
+
+const struct r600_atom si_atom_msaa_config = { si_emit_msaa_config, 10 }; /* number of CS dwords */
+
+static void si_set_min_samples(struct pipe_context *ctx, unsigned min_samples)
+{
+	struct si_context *sctx = (struct si_context *)ctx;
+
+	if (sctx->ps_iter_samples == min_samples)
+		return;
+
+	sctx->ps_iter_samples = min_samples;
+
+	if (sctx->framebuffer.nr_samples > 1)
+		sctx->msaa_config.dirty = true;
 }
 
 /*
@@ -3026,6 +3050,8 @@ void si_init_state_functions(struct si_context *sctx)
 
 	sctx->b.b.texture_barrier = si_texture_barrier;
 	sctx->b.b.set_polygon_stipple = si_set_polygon_stipple;
+	sctx->b.b.set_min_samples = si_set_min_samples;
+
 	sctx->b.dma_copy = si_dma_copy;
 	sctx->b.set_occlusion_query_state = si_set_occlusion_query_state;
 	sctx->b.need_gfx_cs_space = si_need_gfx_cs_space;
diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h
index 0e0e480..e0fd2ff 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -239,6 +239,7 @@ unsigned si_tile_mode_index(struct r600_texture *rtex, unsigned level, bool sten
 
 /* si_state_draw.c */
 extern const struct r600_atom si_atom_cache_flush;
+extern const struct r600_atom si_atom_msaa_config;
 void si_emit_cache_flush(struct r600_common_context *sctx, struct r600_atom *atom);
 void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo);
 
-- 
1.9.1



More information about the mesa-dev mailing list