[Mesa-dev] [PATCH] r600g: fix linear and flat interpolation

Vadim Girlin vadimgirlin at gmail.com
Tue Jan 24 11:32:50 PST 2012


Signed-off-by: Vadim Girlin <vadimgirlin at gmail.com>
---

Tested on evergreen, fixes interpolation tests

Two tesselation tests turned to "WARN" - "tessellation polygon flat_first" and 
"tessellation quads flat_first", I think this patch uncovered some other
problem.

 src/gallium/drivers/r600/evergreen_state.c   |   17 +++++++++++------
 src/gallium/drivers/r600/r600_pipe.h         |    1 +
 src/gallium/drivers/r600/r600_state.c        |   21 ++++++++++++---------
 src/gallium/drivers/r600/r600_state_common.c |    5 +++--
 4 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index 6b91bab..b71a9bc 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -918,7 +918,7 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 	rstate->id = R600_PIPE_STATE_RASTERIZER;
 	if (state->flatshade_first)
 		prov_vtx = 0;
-	tmp = S_0286D4_FLAT_SHADE_ENA(state->flatshade);
+	tmp = S_0286D4_FLAT_SHADE_ENA(1);
 	if (state->sprite_coord_enable) {
 		tmp |= S_0286D4_PNT_SPRITE_ENA(1) |
 			S_0286D4_PNT_SPRITE_OVRD_X(2) |
@@ -994,9 +994,11 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL,
 			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
-			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip),
-			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(1) |
-			S_028810_ZCLIP_FAR_DISABLE(1), NULL, 0);
+			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip) |
+			S_028810_DX_LINEAR_ATTR_CLIP_ENA(1),
+			~(C_028810_PS_UCP_MODE & C_028810_ZCLIP_NEAR_DISABLE &
+			C_028810_ZCLIP_FAR_DISABLE &
+			C_028810_DX_LINEAR_ATTR_CLIP_ENA), NULL, 0);
 	return rstate;
 }
 
@@ -2316,8 +2318,9 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 			tmp = S_028644_SEMANTIC(sid);
 
 			if (rshader->input[i].name == TGSI_SEMANTIC_POSITION ||
-				rshader->input[i].interpolate == TGSI_INTERPOLATE_COLOR ||
-				rshader->input[i].interpolate == TGSI_INTERPOLATE_CONSTANT) {
+				rshader->input[i].interpolate == TGSI_INTERPOLATE_CONSTANT ||
+				(rshader->input[i].interpolate == TGSI_INTERPOLATE_COLOR &&
+					rctx->rasterizer && rctx->rasterizer->flatshade)) {
 				tmp |= S_028644_FLAT_SHADE(1);
 			}
 
@@ -2436,6 +2439,8 @@ void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader
 				0xFFFFFFFF, NULL, 0);
 
 	shader->sprite_coord_enable = rctx->sprite_coord_enable;
+	if (rctx->rasterizer)
+		shader->flatshade = rctx->rasterizer->flatshade;
 }
 
 void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader)
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index 65e84c1..5403d02 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -148,6 +148,7 @@ struct r600_pipe_shader {
 	struct r600_vertex_element	vertex_elements;
 	struct tgsi_token		*tokens;
 	unsigned	sprite_coord_enable;
+	unsigned	flatshade;
 	struct pipe_stream_output_info	so;
 };
 
diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c
index 8f4e9f2..2ab6659 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -969,7 +969,7 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 	rstate->id = R600_PIPE_STATE_RASTERIZER;
 	if (state->flatshade_first)
 		prov_vtx = 0;
-	tmp = S_0286D4_FLAT_SHADE_ENA(state->flatshade);
+	tmp = S_0286D4_FLAT_SHADE_ENA(1);
 	if (state->sprite_coord_enable) {
 		tmp |= S_0286D4_PNT_SPRITE_ENA(1) |
 			S_0286D4_PNT_SPRITE_OVRD_X(2) |
@@ -1037,9 +1037,11 @@ static void *r600_create_rs_state(struct pipe_context *ctx,
 	r600_pipe_state_add_reg(rstate, R_02820C_PA_SC_CLIPRECT_RULE, clip_rule, 0xFFFFFFFF, NULL, 0);
 	r600_pipe_state_add_reg(rstate, R_028810_PA_CL_CLIP_CNTL,
 			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(!state->depth_clip) |
-			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip),
-			S_028810_PS_UCP_MODE(3) | S_028810_ZCLIP_NEAR_DISABLE(1) |
-			S_028810_ZCLIP_FAR_DISABLE(1), NULL, 0);
+			S_028810_ZCLIP_FAR_DISABLE(!state->depth_clip) |
+			S_028810_DX_LINEAR_ATTR_CLIP_ENA(1),
+			~(C_028810_PS_UCP_MODE & C_028810_ZCLIP_NEAR_DISABLE &
+			C_028810_ZCLIP_FAR_DISABLE &
+			C_028810_DX_LINEAR_ATTR_CLIP_ENA), NULL, 0);
 	return rstate;
 }
 
@@ -2098,11 +2100,10 @@ void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shad
 
 		tmp = S_028644_SEMANTIC(sid);
 
-		if (rshader->input[i].name == TGSI_SEMANTIC_POSITION) {
-			tmp |= S_028644_FLAT_SHADE(1);
-		}
-		if (rshader->input[i].interpolate == TGSI_INTERPOLATE_COLOR ||
-		    rshader->input[i].interpolate == TGSI_INTERPOLATE_CONSTANT)
+		if (rshader->input[i].name == TGSI_SEMANTIC_POSITION ||
+			rshader->input[i].interpolate == TGSI_INTERPOLATE_CONSTANT ||
+			(rshader->input[i].interpolate == TGSI_INTERPOLATE_COLOR &&
+				rctx->rasterizer && rctx->rasterizer->flatshade))
 			tmp |= S_028644_FLAT_SHADE(1);
 
 		if (rshader->input[i].name == TGSI_SEMANTIC_GENERIC &&
@@ -2205,6 +2206,8 @@ void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shad
 				0xFFFFFFFF, NULL, 0);
 
 	shader->sprite_coord_enable = rctx->sprite_coord_enable;
+	if (rctx->rasterizer)
+		shader->flatshade = rctx->rasterizer->flatshade;
 }
 
 void r600_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader)
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 6a31309..bb39858 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -603,8 +603,9 @@ static void r600_update_derived_state(struct r600_pipe_context *rctx)
 		r600_update_alpha_ref(rctx);
 	}
 
-	if (rctx->ps_shader && rctx->sprite_coord_enable &&
-		(rctx->ps_shader->sprite_coord_enable != rctx->sprite_coord_enable)) {
+	if (rctx->ps_shader && ((rctx->sprite_coord_enable &&
+		(rctx->ps_shader->sprite_coord_enable != rctx->sprite_coord_enable)) ||
+		(rctx->rasterizer && rctx->rasterizer->flatshade != rctx->ps_shader->flatshade))) {
 
 		if (rctx->chip_class >= EVERGREEN)
 			evergreen_pipe_shader_ps(ctx, rctx->ps_shader);
-- 
1.7.7.6



More information about the mesa-dev mailing list