r5xx: Dump shader constants when dumping program assembly.
[mesa.git] / src / mesa / drivers / dri / r300 / r500_fragprog.c
index 2315830a59c5acf4fbac3a80fc392bbf3070d43e..f8321fd12366b5dfec063619977637b0b2e0d480 100644 (file)
 
 /* Writemasks */
 #define R500_WRITEMASK_G 0x2
+#define R500_WRITEMASK_RGB 0x7
 #define R500_WRITEMASK_A 0x8
 #define R500_WRITEMASK_AR 0x9
 #define R500_WRITEMASK_AG 0xA
@@ -720,8 +721,8 @@ static GLboolean parse_program(struct r500_fragment_program *fp)
                                counter++;
                                /* Second instruction */
                                fp->inst[counter].inst0 = R500_INST_TYPE_ALU | (R500_WRITEMASK_AB << 11);
-                               fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0));
-                               fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0)) | R500_ALPHA_ADDR1(src[1]);
+                               fp->inst[counter].inst1 = R500_RGB_ADDR0(get_temp(fp, 0)) | R500_RGB_ADDR1(src[1]);
+                               fp->inst[counter].inst2 = R500_ALPHA_ADDR0(get_temp(fp, 0));
                                /* Select [z, z, z, y] */
                                temp_swiz = 2 | (2 << 3) | (2 << 6);
                                fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
@@ -746,8 +747,8 @@ static GLboolean parse_program(struct r500_fragment_program *fp)
                                        | MAKE_SWIZ_RGB_B(R500_SWIZ_RGB_ONE);
                                fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
                                        | R500_ALPHA_ADDRD(get_temp(fp, 1))
-                                       | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_B
-                                       | R500_ALPHA_SEL_B_SRC0 | R500_ALPHA_SWIZ_B_A;
+                                       | R500_ALPHA_SEL_A_SRC0 | R500_ALPHA_SWIZ_A_A
+                                       | R500_ALPHA_SEL_B_SRC0 | R500_ALPHA_SWIZ_B_B;
                                fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
                                        | R500_ALU_RGBA_ADDRD(get_temp(fp, 1))
                                        | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
@@ -788,7 +789,7 @@ static GLboolean parse_program(struct r500_fragment_program *fp)
                                        | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
                                counter++;
                                /* Final instruction */
-                               emit_mov(fp, counter, fpi, get_temp(fp, 0), 1672, dest);
+                               emit_mov(fp, counter, fpi, get_temp(fp, 0), SWIZZLE_NOOP, dest);
                                break;
                        case OPCODE_LRP:
                                /* src0 * src1 + INV(src0) * src2
@@ -1151,6 +1152,65 @@ static GLboolean parse_program(struct r500_fragment_program *fp)
                                /* TODO: The rarer negation masks! */
                                emit_mov(fp, counter, fpi, make_src(fp, fpi->SrcReg[0]), fpi->SrcReg[0].Swizzle, dest);
                                break;
+                       case OPCODE_XPD:
+                               /* src0 * src1 - src1 * src0
+                                * 1) MUL temp.xyz, src0.yzx, src1.zxy
+                                * 2) MAD src0.zxy, src1.yzx, -temp.xyz */
+                               src[0] = make_src(fp, fpi->SrcReg[0]);
+                               src[1] = make_src(fp, fpi->SrcReg[1]);
+                               fp->inst[counter].inst0 = R500_INST_TYPE_ALU | R500_INST_TEX_SEM_WAIT
+                                       | (R500_WRITEMASK_RGB << 11);
+                               fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+                                       | R500_RGB_ADDR1(src[1]);
+                               fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+                                       | R500_ALPHA_ADDR1(src[1]);
+                               /* Select [y, z, x] */
+                               temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
+                               temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
+                               fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+                                       | MAKE_SWIZ_RGB_A(temp_swiz);
+                               /* Select [z, x, y] */
+                               temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
+                               temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
+                               fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
+                                       | MAKE_SWIZ_RGB_B(temp_swiz);
+                               fp->inst[counter].inst4 = R500_ALPHA_OP_MAD
+                                       | R500_ALPHA_ADDRD(get_temp(fp, 0))
+                                       | R500_ALPHA_SEL_A_SRC0 | MAKE_SWIZ_ALPHA_A(make_alpha_swizzle(fpi->SrcReg[0]))
+                                       | R500_ALPHA_SEL_B_SRC1 | MAKE_SWIZ_ALPHA_B(make_alpha_swizzle(fpi->SrcReg[1]));
+                               fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+                                       | R500_ALU_RGBA_ADDRD(get_temp(fp, 0))
+                                       | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_ZERO)
+                                       | MAKE_SWIZ_ALPHA_C(R500_SWIZZLE_ZERO);
+                               counter++;
+                               emit_alu(fp, counter, fpi);
+                               fp->inst[counter].inst1 = R500_RGB_ADDR0(src[0])
+                                       | R500_RGB_ADDR1(src[1])
+                                       | R500_RGB_ADDR2(get_temp(fp, 0));
+                               fp->inst[counter].inst2 = R500_ALPHA_ADDR0(src[0])
+                                       | R500_ALPHA_ADDR1(src[1])
+                                       | R500_ALPHA_ADDR2(get_temp(fp, 0));
+                               /* Select [z, x, y] */
+                               temp_swiz = make_rgb_swizzle(fpi->SrcReg[0]);
+                               temp_swiz = (GET_SWZ(temp_swiz, 2) << 0) | (GET_SWZ(temp_swiz, 0) << 3) | (GET_SWZ(temp_swiz, 1) << 6);
+                               fp->inst[counter].inst3 = R500_ALU_RGB_SEL_A_SRC0
+                                       | MAKE_SWIZ_RGB_A(temp_swiz);
+                               /* Select [y, z, x] */
+                               temp_swiz = make_rgb_swizzle(fpi->SrcReg[1]);
+                               temp_swiz = (GET_SWZ(temp_swiz, 1) << 0) | (GET_SWZ(temp_swiz, 2) << 3) | (GET_SWZ(temp_swiz, 0) << 6);
+                               fp->inst[counter].inst3 |= R500_ALU_RGB_SEL_B_SRC1
+                                       | MAKE_SWIZ_RGB_B(temp_swiz);
+                               fp->inst[counter].inst4 |= R500_ALPHA_OP_MAD
+                                       | R500_ALPHA_ADDRD(dest)
+                                       | R500_ALPHA_SWIZ_A_1
+                                       | R500_ALPHA_SWIZ_B_1;
+                               fp->inst[counter].inst5 = R500_ALU_RGBA_OP_MAD
+                                       | R500_ALU_RGBA_ADDRD(dest)
+                                       | R500_ALU_RGBA_SEL_C_SRC2
+                                       | MAKE_SWIZ_RGBA_C(R500_SWIZ_RGB_RGB)
+                                       | R500_ALU_RGBA_MOD_C_NEG
+                                       | R500_ALU_RGBA_A_SWIZ_0;
+                               break;
                        case OPCODE_KIL:
                        case OPCODE_TEX:
                        case OPCODE_TXB:
@@ -1435,7 +1495,7 @@ static char *toswiz(int swiz_val) {
 
 static char *toop(int op_val)
 {
-  char *str;
+  char *str = NULL;
   switch (op_val) {
   case 0: str = "MAD"; break;
   case 1: str = "DP3"; break;
@@ -1518,12 +1578,24 @@ static char *to_texop(int val)
 
 static void dump_program(struct r500_fragment_program *fp)
 {
-  int pc = 0;
+
+  fprintf(stderr, "R500 Fragment Program:\n--------\n");
+
   int n;
   uint32_t inst;
   uint32_t inst0;
   char *str = NULL;
 
+  if (fp->const_nr) {
+    fprintf(stderr, "--------\nConstants:\n");
+    for (n = 0; n < fp->const_nr; n++) {
+      fprintf(stderr, "Constant %d: %f %f\n\t %f %f\n", n,
+        fp->constant[n][0], fp->constant[n][1], fp->constant[n][2],
+        fp->constant[n][3]);
+    }
+    fprintf(stderr, "--------\n");
+  }
+
   for (n = 0; n < fp->inst_end+1; n++) {
     inst0 = inst = fp->inst[n].inst0;
     fprintf(stderr,"%d\t0:CMN_INST   0x%08x:", n, inst);