[Mesa-dev] [PATCH 05/13] radeonsi: allocate si_state_rasterizer::pm4_poly_offset only when needed

Marek Olšák maraeo at gmail.com
Sat Jun 10 16:39:43 UTC 2017


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

Each element has over 700 bytes.
---
 src/gallium/drivers/radeonsi/si_state.c | 14 +++++++++++++-
 src/gallium/drivers/radeonsi/si_state.h |  2 +-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
index 27a88a8..f4d6ae1 100644
--- a/src/gallium/drivers/radeonsi/si_state.c
+++ b/src/gallium/drivers/radeonsi/si_state.c
@@ -863,20 +863,29 @@ static void *si_create_rs_state(struct pipe_context *ctx,
 		S_028814_CULL_BACK((state->cull_face & PIPE_FACE_BACK) ? 1 : 0) |
 		S_028814_FACE(!state->front_ccw) |
 		S_028814_POLY_OFFSET_FRONT_ENABLE(util_get_offset(state, state->fill_front)) |
 		S_028814_POLY_OFFSET_BACK_ENABLE(util_get_offset(state, state->fill_back)) |
 		S_028814_POLY_OFFSET_PARA_ENABLE(state->offset_point || state->offset_line) |
 		S_028814_POLY_MODE(state->fill_front != PIPE_POLYGON_MODE_FILL ||
 				   state->fill_back != PIPE_POLYGON_MODE_FILL) |
 		S_028814_POLYMODE_FRONT_PTYPE(si_translate_fill(state->fill_front)) |
 		S_028814_POLYMODE_BACK_PTYPE(si_translate_fill(state->fill_back)));
 
+	if (!rs->uses_poly_offset)
+		return rs;
+
+	rs->pm4_poly_offset = CALLOC(3, sizeof(struct si_pm4_state));
+	if (!rs->pm4_poly_offset) {
+		FREE(rs);
+		return NULL;
+	}
+
 	/* Precalculate polygon offset states for 16-bit, 24-bit, and 32-bit zbuffers. */
 	for (i = 0; i < 3; i++) {
 		struct si_pm4_state *pm4 = &rs->pm4_poly_offset[i];
 		float offset_units = state->offset_units;
 		float offset_scale = state->offset_scale * 16.0f;
 		uint32_t pa_su_poly_offset_db_fmt_cntl = 0;
 
 		if (!state->offset_units_unscaled) {
 			switch (i) {
 			case 0: /* 16-bit zbuffer */
@@ -958,24 +967,27 @@ static void si_bind_rs_state(struct pipe_context *ctx, void *state)
 	    old_rs->poly_smooth != rs->poly_smooth ||
 	    old_rs->line_smooth != rs->line_smooth ||
 	    old_rs->clamp_fragment_color != rs->clamp_fragment_color ||
 	    old_rs->force_persample_interp != rs->force_persample_interp)
 		sctx->do_update_shaders = true;
 }
 
 static void si_delete_rs_state(struct pipe_context *ctx, void *state)
 {
 	struct si_context *sctx = (struct si_context *)ctx;
+	struct si_state_rasterizer *rs = (struct si_state_rasterizer *)state;
 
 	if (sctx->queued.named.rasterizer == state)
 		si_pm4_bind_state(sctx, poly_offset, NULL);
-	si_pm4_delete_state(sctx, rasterizer, (struct si_state_rasterizer *)state);
+
+	FREE(rs->pm4_poly_offset);
+	si_pm4_delete_state(sctx, rasterizer, rs);
 }
 
 /*
  * infeered state between dsa and stencil ref
  */
 static void si_emit_stencil_ref(struct si_context *sctx, struct r600_atom *atom)
 {
 	struct radeon_winsys_cs *cs = sctx->b.gfx.cs;
 	struct pipe_stencil_ref *ref = &sctx->stencil_ref.state;
 	struct si_dsa_stencil_ref_part *dsa = &sctx->stencil_ref.dsa_part;
diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h
index dabe9b9..8de8675 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -53,21 +53,21 @@ struct si_state_blend {
 	/* Set 0xf or 0x0 (4 bits) per render target if the following is
 	 * true. ANDed with spi_shader_col_format.
 	 */
 	unsigned		blend_enable_4bit;
 	unsigned		need_src_alpha_4bit;
 };
 
 struct si_state_rasterizer {
 	struct si_pm4_state	pm4;
 	/* poly offset states for 16-bit, 24-bit, and 32-bit zbuffers */
-	struct si_pm4_state	pm4_poly_offset[3];
+	struct si_pm4_state	*pm4_poly_offset;
 	unsigned		pa_sc_line_stipple;
 	unsigned		pa_cl_clip_cntl;
 	unsigned		sprite_coord_enable:8;
 	unsigned		clip_plane_enable:8;
 	unsigned		flatshade:1;
 	unsigned		two_side:1;
 	unsigned		multisample_enable:1;
 	unsigned		force_persample_interp:1;
 	unsigned		line_stipple_enable:1;
 	unsigned		poly_stipple_enable:1;
-- 
2.7.4



More information about the mesa-dev mailing list