Mesa (master): r300/compiler: Use consistent src swizzles for transcendent instructions

Tom Stellard tstellar at kemper.freedesktop.org
Sun Oct 2 15:47:48 PDT 2011


Module: Mesa
Branch: master
Commit: b5ecf5ba466c3e1872dc9281b01f4e59ca1a388b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b5ecf5ba466c3e1872dc9281b01f4e59ca1a388b

Author: Tom Stellard <tstellar at gmail.com>
Date:   Sat Oct  1 21:06:12 2011 -0700

r300/compiler: Use consistent src swizzles for transcendent instructions

Source swizzles for transcendent instructions were being stored in the X
channel regardless of what channel the instruction was writing.
This was causing problems for some helper functions that were expecting
source swizzles to occupy channels corresponding to the instruction's
writemask.  This commit makes transcendent instructions follow the same
convention as normal instructions for representing source swizzles.

Previous behavior:
LG2 temp[0].y, input[0].x___;

Current behavior:
LG2 temp[0].y, input[0]._x__;

---

 src/gallium/drivers/r300/compiler/r3xx_vertprog.c  |   10 ++++++----
 .../drivers/r300/compiler/radeon_compiler_util.c   |   18 ++++++++++++++++++
 .../drivers/r300/compiler/radeon_compiler_util.h   |    1 +
 src/gallium/drivers/r300/compiler/radeon_opcodes.c |    2 +-
 .../drivers/r300/compiler/radeon_pair_translate.c  |    8 +++++++-
 5 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
index 654f9a0..a8d8ebc 100644
--- a/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
+++ b/src/gallium/drivers/r300/compiler/r3xx_vertprog.c
@@ -163,11 +163,13 @@ static unsigned long t_src_scalar(struct r300_vertex_program_code *vp,
 	/* src->Negate uses the RC_MASK_ flags from program_instruction.h,
 	 * which equal our VSF_FLAGS_ values, so it's safe to just pass it here.
 	 */
+	unsigned int swz = rc_get_scalar_src_swz(src->Swizzle);
+
 	return PVS_SRC_OPERAND(t_src_index(vp, src),
-			       t_swizzle(GET_SWZ(src->Swizzle, 0)),
-			       t_swizzle(GET_SWZ(src->Swizzle, 0)),
-			       t_swizzle(GET_SWZ(src->Swizzle, 0)),
-			       t_swizzle(GET_SWZ(src->Swizzle, 0)),
+			       t_swizzle(swz),
+			       t_swizzle(swz),
+			       t_swizzle(swz),
+			       t_swizzle(swz),
 			       t_src_class(src->File),
 			       src->Negate ? RC_MASK_XYZW : RC_MASK_NONE) |
 	       (src->RelAddr << 4) | (src->Abs << 3);
diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler_util.c b/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
index 33dbe0e..36a6341 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler_util.c
@@ -734,3 +734,21 @@ float rc_get_constant_value(
 	return base *
 		c->Program.Constants.Constants[index].u.Immediate[swz];
 }
+
+/**
+ * This function returns the component value (RC_SWIZZLE_*) of the first used
+ * channel in the swizzle.  This is only useful for scalar instructions that are
+ * known to use only one channel of the swizzle.
+ */
+unsigned int rc_get_scalar_src_swz(unsigned int swizzle)
+{
+	unsigned int swz, chan;
+	for (chan = 0; chan < 4; chan++) {
+		swz = GET_SWZ(swizzle, chan);
+		if (swz != RC_SWIZZLE_UNUSED) {
+			break;
+		}
+	}
+	assert(swz != RC_SWIZZLE_UNUSED);
+	return swz;
+}
diff --git a/src/gallium/drivers/r300/compiler/radeon_compiler_util.h b/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
index 58bdb3c..ae5288e 100644
--- a/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
+++ b/src/gallium/drivers/r300/compiler/radeon_compiler_util.h
@@ -98,5 +98,6 @@ float rc_get_constant_value(
 	unsigned int negate,
 	unsigned int chan);
 
+unsigned int rc_get_scalar_src_swz(unsigned int swizzle);
 
 #endif /* RADEON_PROGRAM_UTIL_H */
diff --git a/src/gallium/drivers/r300/compiler/radeon_opcodes.c b/src/gallium/drivers/r300/compiler/radeon_opcodes.c
index 527db9a..3b49ad7 100644
--- a/src/gallium/drivers/r300/compiler/radeon_opcodes.c
+++ b/src/gallium/drivers/r300/compiler/radeon_opcodes.c
@@ -463,7 +463,7 @@ void rc_compute_sources_for_writemask(
 			srcmasks[src] |= writemask;
 	} else if (opcode->IsStandardScalar) {
 		for(unsigned int src = 0; src < opcode->NumSrcRegs; ++src)
-			srcmasks[src] |= RC_MASK_X;
+			srcmasks[src] |= writemask;
 	} else {
 		switch(opcode->Opcode) {
 		case RC_OPCODE_ARL:
diff --git a/src/gallium/drivers/r300/compiler/radeon_pair_translate.c b/src/gallium/drivers/r300/compiler/radeon_pair_translate.c
index 3d9cf3b..7d9c8d1 100644
--- a/src/gallium/drivers/r300/compiler/radeon_pair_translate.c
+++ b/src/gallium/drivers/r300/compiler/radeon_pair_translate.c
@@ -247,7 +247,13 @@ static void set_pair_instruction(struct r300_fragment_program_compiler *c,
 		if (needalpha) {
 			unsigned int srcrgb = 0;
 			unsigned int srcalpha = 0;
-			unsigned int swz = GET_SWZ(inst->SrcReg[i].Swizzle, istranscendent ? 0 : 3);
+			unsigned int swz;
+			if (istranscendent) {
+				swz = rc_get_scalar_src_swz(inst->SrcReg[i].Swizzle);
+			} else {
+				swz = GET_SWZ(inst->SrcReg[i].Swizzle, 3);
+			}
+
 			if (swz < 3)
 				srcrgb = 1;
 			else if (swz < 4)



More information about the mesa-commit mailing list