[Mesa-dev] [PATCH 15/30] r600g: add primitive input support for gs

Dave Airlie airlied at gmail.com
Tue Feb 4 00:53:32 CET 2014


From: Dave Airlie <airlied at redhat.com>

only enable prim id if gs uses it

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/gallium/drivers/r600/evergreen_state.c | 6 +++++-
 src/gallium/drivers/r600/evergreend.h      | 4 ++++
 src/gallium/drivers/r600/r600_shader.c     | 9 +++++++++
 src/gallium/drivers/r600/r600_shader.h     | 1 +
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
index e6aa122..c206c08 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -2725,7 +2725,7 @@ static void evergreen_emit_shader_stages(struct r600_context *rctx, struct r600_
 	struct radeon_winsys_cs *cs = rctx->b.rings.gfx.cs;
 	struct r600_shader_stages_state *state = (struct r600_shader_stages_state*)a;
 
-	uint32_t v = 0, v2 = 0;
+	uint32_t v = 0, v2 = 0, primid = 0;
 
 	if (state->geom_enable) {
 		v = S_028B54_ES_EN(V_028B54_ES_STAGE_REAL) |
@@ -2734,10 +2734,14 @@ static void evergreen_emit_shader_stages(struct r600_context *rctx, struct r600_
 
 		v2 = S_028A40_MODE(V_028A40_GS_SCENARIO_G) |
 			S_028A40_CUT_MODE(V_028A40_GS_CUT_128);
+
+		if (rctx->gs_shader->current->shader.gs_prim_id_input)
+			primid = 1;
 	}
 
 	r600_write_context_reg(cs, R_028B54_VGT_SHADER_STAGES_EN, v);
 	r600_write_context_reg(cs, R_028A40_VGT_GS_MODE, v2);
+	r600_write_context_reg(cs, R_028A84_VGT_PRIMITIVEID_EN, primid);
 }
 
 static void evergreen_emit_gs_rings(struct r600_context *rctx, struct r600_atom *a)
diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
index 73b37c2..986fd16 100644
--- a/src/gallium/drivers/r600/evergreend.h
+++ b/src/gallium/drivers/r600/evergreend.h
@@ -1983,6 +1983,10 @@
 #define R_028A58_ES_PER_GS                           0x00028A58
 #define R_028A5C_GS_PER_VS                           0x00028A5C
 
+#define R_028A84_VGT_PRIMITIVEID_EN                  0x028A84
+#define   S_028A84_PRIMITIVEID_EN(x)                   (((x) & 0x1) << 0)
+#define   G_028A84_PRIMITIVEID_EN(x)                   (((x) >> 0) & 0x1)
+#define   C_028A84_PRIMITIVEID_EN                      0xFFFFFFFE
 #define R_028A94_VGT_MULTI_PRIM_IB_RESET_EN          0x00028A94
 #define   S_028A94_RESET_EN(x)                         (((x) & 0x1) << 0)
 #define   G_028A94_RESET_EN(x)                         (((x) >> 0) & 0x1)
diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c
index e24b64d..fd11f61 100644
--- a/src/gallium/drivers/r600/r600_shader.c
+++ b/src/gallium/drivers/r600/r600_shader.c
@@ -590,6 +590,8 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
 			/* FIXME probably skip inputs if they aren't passed in the ring */
 			ctx->shader->input[i].ring_offset = ctx->next_ring_offset;
 			ctx->next_ring_offset += 16;
+			if (ctx->shader->input[i].name == TGSI_SEMANTIC_PRIMID)
+				ctx->shader->gs_prim_id_input = true;
 		}
 		for (j = 1; j < count; ++j) {
 			ctx->shader->input[i + j] = ctx->shader->input[i];
@@ -872,6 +874,13 @@ static int tgsi_split_gs_inputs(struct r600_shader_ctx *ctx)
 	for (i = 0; i < inst->Instruction.NumSrcRegs; i++) {
 		struct tgsi_full_src_register *src = &inst->Src[i];
 
+		if (src->Register.File == TGSI_FILE_INPUT) {
+			if (ctx->shader->input[src->Register.Index].name == TGSI_SEMANTIC_PRIMID) {
+				/* primitive id is in R0.z */
+				ctx->src[i].sel = 0;
+				ctx->src[i].swizzle[0] = 2;
+			}
+		}
 		if (src->Register.File == TGSI_FILE_INPUT && src->Register.Dimension) {
 			int treg = r600_get_temp(ctx);
 			int index = src->Register.Index;
diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h
index 0bf8b51..d31c65f 100644
--- a/src/gallium/drivers/r600/r600_shader.h
+++ b/src/gallium/drivers/r600/r600_shader.h
@@ -64,6 +64,7 @@ struct r600_shader {
 	boolean			vs_out_point_size;
 	boolean			has_txq_cube_array_z_comp;
 	boolean			uses_tex_buffers;
+	boolean                 gs_prim_id_input;
 
 	/* geometry shader properties */
 	unsigned		gs_input_prim;
-- 
1.8.3.1



More information about the mesa-dev mailing list