r300-gallium: Start swizzles.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 11 Mar 2009 03:43:11 +0000 (20:43 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 11 Mar 2009 22:23:08 +0000 (15:23 -0700)
src/gallium/drivers/r300/r300_state_shader.c
src/gallium/drivers/r300/r300_state_shader.h

index 7165efdc19b1f06585823379d6c92f13ffa21875..65d5c5a596efe8f898a6d0484a2e6b64606237c3 100644 (file)
@@ -68,6 +68,19 @@ static void r300_fs_declare(struct r300_fs_asm* assembler,
     assembler->temp_offset = assembler->color_count + assembler->tex_count;
 }
 
+/* XXX cover extended cases */
+static INLINE uint32_t r500_rgb_swiz(struct tgsi_src_register* reg)
+{
+    uint32_t temp = reg->SwizzleX | (reg->SwizzleY << 3) |
+        (reg->SwizzleZ << 6);
+    return temp;
+}
+
+static INLINE uint32_t r500_alpha_swiz(struct tgsi_src_register* reg)
+{
+    return reg->SwizzleZ;
+}
+
 static INLINE void r500_emit_mov(struct r500_fragment_shader* fs,
                                  struct r300_fs_asm* assembler,
                                  struct tgsi_full_src_register* src,
@@ -84,13 +97,13 @@ static INLINE void r500_emit_mov(struct r500_fragment_shader* fs,
     fs->instructions[i].inst2 =
         R500_ALPHA_ADDR0(0) | R500_ALPHA_ADDR1(0) | R500_ALPHA_ADDR1_CONST |
         R500_ALPHA_ADDR2(0) | R500_ALPHA_ADDR2_CONST;
-    fs->instructions[i].inst3 =
-        R500_ALU_RGB_SEL_A_SRC0 | R500_ALU_RGB_R_SWIZ_A_R |
-        R500_ALU_RGB_G_SWIZ_A_G | R500_ALU_RGB_B_SWIZ_A_B |
-        R500_ALU_RGB_SEL_B_SRC0 | R500_ALU_RGB_R_SWIZ_B_R |
-        R500_ALU_RGB_B_SWIZ_B_G | R500_ALU_RGB_G_SWIZ_B_B,
-    fs->instructions[i].inst4 =
-        R500_ALPHA_OP_CMP | R500_ALPHA_SWIZ_A_A | R500_ALPHA_SWIZ_B_A;
+    fs->instructions[i].inst3 = R500_ALU_RGB_SEL_A_SRC0 |
+        R500_SWIZ_RGB_A(r500_rgb_swiz(&src->SrcRegister)) |
+        R500_ALU_RGB_SEL_B_SRC0 |
+        R500_SWIZ_RGB_B(r500_rgb_swiz(&src->SrcRegister));
+    fs->instructions[i].inst4 = R500_ALPHA_OP_CMP |
+        R500_SWIZ_ALPHA_A(r500_alpha_swiz(&src->SrcRegister)) |
+        R500_SWIZ_ALPHA_B(r500_alpha_swiz(&src->SrcRegister));
     fs->instructions[i].inst5 =
         R500_ALU_RGBA_OP_CMP | R500_ALU_RGBA_R_SWIZ_0 |
         R500_ALU_RGBA_G_SWIZ_0 | R500_ALU_RGBA_B_SWIZ_0 |
index 333f0f5d050058cfa4d6d23998ed77c06537539c..410926a26a502ac0a40bc200dd13347f83b49e5f 100644 (file)
 #include "r300_reg.h"
 #include "r300_screen.h"
 
+/* Swizzle tools */
+#define R500_SWIZZLE_ZERO 4
+#define R500_SWIZZLE_HALF 5
+#define R500_SWIZZLE_ONE 6
+#define R500_SWIZ_RGB_ZERO ((4 << 0) | (4 << 3) | (4 << 6))
+#define R500_SWIZ_RGB_ONE ((6 << 0) | (6 << 3) | (6 << 6))
+#define R500_SWIZ_RGB_RGB ((0 << 0) | (1 << 3) | (2 << 6))
+#define R500_SWIZ_MOD_NEG 1
+#define R500_SWIZ_MOD_ABS 2
+#define R500_SWIZ_MOD_NEG_ABS 3
+/* Swizzles for inst2 */
+#define R500_SWIZ_TEX_STRQ(x) (x << 8)
+#define R500_SWIZ_TEX_RGBA(x) (x << 24)
+/* Swizzles for inst3 */
+#define R500_SWIZ_RGB_A(x) (x << 2)
+#define R500_SWIZ_RGB_B(x) (x << 15)
+/* Swizzles for inst4 */
+#define R500_SWIZ_ALPHA_A(x) (x << 14)
+#define R500_SWIZ_ALPHA_B(x) (x << 21)
+/* Swizzle for inst5 */
+#define R500_SWIZ_RGBA_C(x) (x << 14)
+#define R500_SWIZ_ALPHA_C(x) (x << 27)
+
 /* Temporary struct used to hold assembly state while putting together
  * fragment programs. */
 struct r300_fs_asm {