r300: fix register-negate branch merge regression
authorMaciej Cencora <m.cencora@gmail.com>
Mon, 20 Apr 2009 13:31:44 +0000 (07:31 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 20 Apr 2009 13:31:44 +0000 (07:31 -0600)
src/mesa/drivers/dri/r300/r300_fragprog_swizzle.c
src/mesa/drivers/dri/r300/radeon_program_alu.c
src/mesa/drivers/dri/r300/radeon_program_pair.c

index 191853ac1f2848d28f5220333a571938114613ac..6f0d733d46344f21001ff1646d630a98dabc1310 100644 (file)
@@ -122,7 +122,7 @@ GLboolean r300FPIsNativeSwizzle(GLuint opcode, struct prog_src_register reg)
                if (GET_SWZ(reg.Swizzle, j) != SWIZZLE_NIL)
                        relevant |= 1 << j;
 
-       if ((reg.Negate & relevant) && (reg.Negate & relevant) != relevant)
+       if ((reg.Negate & relevant) && ((reg.Negate & relevant) != relevant))
                return GL_FALSE;
 
        if (!lookup_native_swizzle(reg.Swizzle))
@@ -144,7 +144,6 @@ void r300FPBuildSwizzle(struct nqssadce_state *s, struct prog_dst_register dst,
                const struct swizzle_data *best_swizzle = 0;
                GLuint best_matchcount = 0;
                GLuint best_matchmask = 0;
-               GLboolean rgbnegate;
                int i, comp;
 
                for(i = 0; i < num_native_swizzles; ++i) {
@@ -158,6 +157,11 @@ void r300FPBuildSwizzle(struct nqssadce_state *s, struct prog_dst_register dst,
                                if (swz == SWIZZLE_NIL)
                                        continue;
                                if (swz == GET_SWZ(sd->hash, comp)) {
+                                       /* check if the negate bit of current component
+                                        * is the same for already matched components */
+                                       if (matchmask && (!!(src.Negate & matchmask) != !!(src.Negate & (1 << comp))))
+                                               continue;
+
                                        matchcount++;
                                        matchmask |= 1 << comp;
                                }
@@ -171,13 +175,6 @@ void r300FPBuildSwizzle(struct nqssadce_state *s, struct prog_dst_register dst,
                        }
                }
 
-               if ((src.Negate & best_matchmask) != 0) {
-                       best_matchmask &= src.Negate;
-                       rgbnegate = !src.Negate;
-               } else {
-                       rgbnegate = src.Negate;
-               }
-
                struct prog_instruction *inst;
 
                _mesa_insert_instructions(s->Program, s->IP, 1);
@@ -186,6 +183,7 @@ void r300FPBuildSwizzle(struct nqssadce_state *s, struct prog_dst_register dst,
                inst->DstReg = dst;
                inst->DstReg.WriteMask &= (best_matchmask | WRITEMASK_W);
                inst->SrcReg[0] = src;
+               inst->SrcReg[0].Negate = (best_matchmask & src.Negate) ? NEGATE_XYZW : NEGATE_NONE;
                /* Note: We rely on NqSSA/DCE to set unused swizzle components to NIL */
 
                dst.WriteMask &= ~inst->DstReg.WriteMask;
index ebc5c913b25c8e263dab6dbd3a2a26253e135b5f..8283723bad795f09dc939391f7748d875a010396 100644 (file)
@@ -81,19 +81,6 @@ static struct prog_instruction *emit3(struct gl_program* p,
        return fpi;
 }
 
-static void set_swizzle(struct prog_src_register *SrcReg, int coordinate, int swz)
-{
-       SrcReg->Swizzle &= ~(7 << (3*coordinate));
-       SrcReg->Swizzle |= swz << (3*coordinate);
-}
-
-static void set_negate_base(struct prog_src_register *SrcReg, int coordinate, int negate)
-{
-       /* XXX note sure about this negation logic here */
-       SrcReg->Negate &= ~(1 << coordinate);
-       SrcReg->Negate |= (negate << coordinate);
-}
-
 static struct prog_dst_register dstreg(int file, int index)
 {
        struct prog_dst_register dst;
@@ -197,17 +184,9 @@ static void transform_DPH(struct radeon_transform_context* t,
        struct prog_instruction* inst)
 {
        struct prog_src_register src0 = inst->SrcReg[0];
-       if (src0.Negate) {
-               if (src0.Abs) {
-                       int tempreg = radeonFindFreeTemporary(t);
-                       emit1(t->Program, OPCODE_MOV, 0, dstreg(PROGRAM_TEMPORARY, tempreg), src0);
-                       src0 = srcreg(src0.File, src0.Index);
-               } else {
-                       src0.Negate ^= NEGATE_XYZW;
-               }
-       }
-       set_swizzle(&src0, 3, SWIZZLE_ONE);
-       set_negate_base(&src0, 3, 0);
+       src0.Negate &= ~NEGATE_W;
+       src0.Swizzle &= ~(7 << (3 * 3));
+       src0.Swizzle |= SWIZZLE_ONE << (3 * 3);
        emit2(t->Program, OPCODE_DP4, inst->SaturateMode, inst->DstReg, src0, inst->SrcReg[1]);
 }
 
index ecc82ff8a81db441a9c3f06d952e1fe5ab49bd83..4aa2319a454ff1eeeba8aca4a0af8068df3f43f8 100644 (file)
@@ -721,7 +721,6 @@ static GLboolean fill_instruction_into_pair(struct pair_state *s, struct radeon_
                if (pairinst->NeedRGB && !pairinst->IsTranscendent) {
                        GLboolean srcrgb = GL_FALSE;
                        GLboolean srcalpha = GL_FALSE;
-                       GLuint negatebase = 0;
                        int j;
                        for(j = 0; j < 3; ++j) {
                                GLuint swz = GET_SWZ(inst->SrcReg[i].Swizzle, j);
@@ -729,8 +728,6 @@ static GLboolean fill_instruction_into_pair(struct pair_state *s, struct radeon_
                                        srcrgb = GL_TRUE;
                                else if (swz < 4)
                                        srcalpha = GL_TRUE;
-                               if (swz != SWIZZLE_NIL && GET_BIT(inst->SrcReg[i].Negate, j))
-                                       negatebase = 1;
                        }
                        source = alloc_pair_source(s, pair, inst->SrcReg[i], srcrgb, srcalpha);
                        if (source < 0)
@@ -738,12 +735,11 @@ static GLboolean fill_instruction_into_pair(struct pair_state *s, struct radeon_
                        pair->RGB.Arg[i].Source = source;
                        pair->RGB.Arg[i].Swizzle = inst->SrcReg[i].Swizzle & 0x1ff;
                        pair->RGB.Arg[i].Abs = inst->SrcReg[i].Abs;
-                       pair->RGB.Arg[i].Negate = (negatebase & ~pair->RGB.Arg[i].Abs) ^ inst->SrcReg[i].Negate;
+                       pair->RGB.Arg[i].Negate = !!(inst->SrcReg[i].Negate & (NEGATE_X | NEGATE_Y | NEGATE_Z));
                }
                if (pairinst->NeedAlpha) {
                        GLboolean srcrgb = GL_FALSE;
                        GLboolean srcalpha = GL_FALSE;
-                       GLuint negatebase = GET_BIT(inst->SrcReg[i].Negate, pairinst->IsTranscendent ? 0 : 3);
                        GLuint swz = GET_SWZ(inst->SrcReg[i].Swizzle, pairinst->IsTranscendent ? 0 : 3);
                        if (swz < 3)
                                srcrgb = GL_TRUE;
@@ -755,7 +751,7 @@ static GLboolean fill_instruction_into_pair(struct pair_state *s, struct radeon_
                        pair->Alpha.Arg[i].Source = source;
                        pair->Alpha.Arg[i].Swizzle = swz;
                        pair->Alpha.Arg[i].Abs = inst->SrcReg[i].Abs;
-                       pair->Alpha.Arg[i].Negate = (negatebase & ~pair->RGB.Arg[i].Abs) ^ inst->SrcReg[i].Negate;
+                       pair->Alpha.Arg[i].Negate = !!(inst->SrcReg[i].Negate & NEGATE_W);
                }
        }