- Secondary colour
authorBen Skeggs <darktama@iinet.net.au>
Wed, 8 Jun 2005 15:05:19 +0000 (15:05 +0000)
committerBen Skeggs <darktama@iinet.net.au>
Wed, 8 Jun 2005 15:05:19 +0000 (15:05 +0000)
- Calculate tc_count in EmitArrays (enabled units != nr texcoords).

src/mesa/drivers/dri/r300/r300_fragprog.c
src/mesa/drivers/dri/r300/r300_ioctl.c
src/mesa/drivers/dri/r300/r300_maos.c
src/mesa/drivers/dri/r300/r300_reg.h
src/mesa/drivers/dri/r300/r300_state.c

index 599face..19dab8f 100644 (file)
@@ -941,24 +941,29 @@ void init_program(struct r300_fragment_program *rp)
        /* Work out what temps the Mesa inputs correspond to, this must match
         * what setup_rs_unit does, which shouldn't be a problem as rs_unit
         * configures itself based on the fragprog's InputsRead
+        *
+        * I'm using get_hw_temp() here now rather than doing this manually.
+        * This depends on get_hw_temp() allocating registers in order, starting
+        * at 0 (which it currently does).
         */
 
        /* Texcoords come first */
        for (i=0;i<rp->ctx->Const.MaxTextureUnits;i++) {
-               if (InputsRead & (FRAG_BIT_TEX0 << i)) {
-                       rp->hwreg_in_use |= (1<<fp_reg);
-                       rp->inputs[FRAG_ATTRIB_TEX0+i] = fp_reg++;
-               }
+               if (InputsRead & (FRAG_BIT_TEX0 << i))
+                       rp->inputs[FRAG_ATTRIB_TEX0+i] = get_hw_temp(rp);
        }
        InputsRead &= ~FRAG_BITS_TEX_ANY;
 
        /* Then primary colour */
-       if (InputsRead & FRAG_BIT_COL0) {
-               rp->hwreg_in_use |= (1<<fp_reg);
-               rp->inputs[FRAG_ATTRIB_COL0] = fp_reg++;
-       }
+       if (InputsRead & FRAG_BIT_COL0)
+               rp->inputs[FRAG_ATTRIB_COL0] = get_hw_temp(rp);
        InputsRead &= ~FRAG_BIT_COL0;
-       
+
+       /* Secondary color */
+       if (InputsRead & FRAG_BIT_COL1)
+               rp->inputs[FRAG_ATTRIB_COL1] = get_hw_temp(rp);
+       InputsRead &= ~FRAG_BIT_COL1;
+
        /* Anything else */
        if (InputsRead) {
                WARN_ONCE("Don't know how to handle inputs 0x%x\n", InputsRead);
index 6765651..6f8a712 100644 (file)
@@ -143,7 +143,7 @@ static void r300ClearBuffer(r300ContextPtr r300, int flags, int buffer)
 
        R300_STATECHANGE(r300, rc);
        /* The second constant is needed to get glxgears display anything .. */
-       r300->hw.rc.cmd[1] = R300_RS_CNTL_0_UNKNOWN_7 | R300_RS_CNTL_0_UNKNOWN_18;
+       r300->hw.rc.cmd[1] = (1 << R300_RS_CNTL_CI_CNT_SHIFT) | R300_RS_CNTL_0_UNKNOWN_18;
        r300->hw.rc.cmd[2] = 0;
        
        R300_STATECHANGE(r300, rr);
index d9a10b0..946bf09 100644 (file)
@@ -385,6 +385,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd)
        }
 #endif
 
+       r300->state.texture.tc_count = 0;
        for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
                if (inputs & (_TNL_BIT_TEX0 << i)) {
                        CONFIGURE_AOS(i_tex[i], AOS_FORMAT_FLOAT,
@@ -393,6 +394,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd)
                                                        count);
 
                        vic_1 |= R300_INPUT_CNTL_TC0 << i;
+                       r300->state.texture.tc_count++;
                }
        }
        
@@ -536,6 +538,8 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd)
                        r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT;
                if(inputs & _TNL_BIT_COLOR0)
                        r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_PRESENT;
+               if(inputs & _TNL_BIT_COLOR1)
+                       r300->hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT;
 
                for(i=0;i < ctx->Const.MaxTextureUnits;i++)
                        if(inputs & (_TNL_BIT_TEX0<<i))
index 7b9fd1c..2dd3cb6 100644 (file)
@@ -502,7 +502,7 @@ I am fairly certain that they are correct unless stated otherwise in comments.
 #define R300_RS_CNTL_0                      0x4300
 #       define R300_RS_CNTL_TC_CNT_SHIFT         2
 #       define R300_RS_CNTL_TC_CNT_MASK          (7 << 2)
-#       define R300_RS_CNTL_0_UNKNOWN_7          (1 << 7) /* Number of color interpolators used (shifted by 7) */
+#              define R300_RS_CNTL_CI_CNT_SHIFT         7 /* number of color interpolators used */
 #       define R300_RS_CNTL_0_UNKNOWN_18         (1 << 18)
 /* Guess: RS_CNTL_1 holds the index of the highest used RS_ROUTE_n register. */
 #define R300_RS_CNTL_1                      0x4304
@@ -562,6 +562,11 @@ I am fairly certain that they are correct unless stated otherwise in comments.
 #       define R300_RS_ROUTE_0_COLOR             (1 << 14)
 #       define R300_RS_ROUTE_0_COLOR_DEST_SHIFT  17
 #       define R300_RS_ROUTE_0_COLOR_DEST_MASK   (31 << 17) /* GUESS */
+/* As above, but for secondary color */
+#              define R300_RS_ROUTE_1_COLOR1            (1 << 14)
+#              define R300_RS_ROUTE_1_COLOR1_DEST_SHIFT 17
+#              define R300_RS_ROUTE_1_COLOR1_DEST_MASK  (31 << 17)
+#              define R300_RS_ROUTE_1_UNKNOWN11         (1 << 11)
 /* END */
 
 /* BEGIN: Scissors and cliprects
index 4cadfd3..7241815 100644 (file)
@@ -1030,8 +1030,6 @@ void r300_setup_textures(GLcontext *ctx)
        R300_STATECHANGE(r300, tex.unknown4);
        R300_STATECHANGE(r300, tex.border_color);
        
-       r300->state.texture.tc_count=0;
-
        r300->hw.txe.cmd[R300_TXE_ENABLE]=0x0;
 
        mtu = r300->radeon.glCtx->Const.MaxTextureUnits;
@@ -1053,7 +1051,6 @@ void r300_setup_textures(GLcontext *ctx)
                if(TMU_ENABLED(ctx, i)) {
                        t=r300->state.texture.unit[i].texobj;
                        //fprintf(stderr, "format=%08x\n", r300->state.texture.unit[i].format);
-                       r300->state.texture.tc_count++;
                        
                        if(t == NULL){
                                fprintf(stderr, "Texture unit %d enabled, but corresponding texobj is NULL, using default object.\n", i);
@@ -1102,7 +1099,6 @@ void r300_setup_textures(GLcontext *ctx)
 void r300_setup_rs_unit(GLcontext *ctx)
 {
        r300ContextPtr r300 = R300_CONTEXT(ctx);
-       int i, vp_reg, fp_reg, in_texcoords;
        /* I'm still unsure if these are needed */
        GLuint interp_magic[8] = {
                0x00,
@@ -1116,7 +1112,10 @@ void r300_setup_rs_unit(GLcontext *ctx)
        };
        GLuint OutputsWritten;
        GLuint InputsRead;
-       
+       int vp_reg, fp_reg, high_rr;
+       int in_texcoords, col_interp_nr;
+       int i;
+
        if(hw_tcl_on)
                OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten;
        else
@@ -1128,13 +1127,14 @@ void r300_setup_rs_unit(GLcontext *ctx)
                fprintf(stderr, "No ctx->FragmentProgram._Current!!\n");
                return; /* This should only ever happen once.. */
        }
-       /* This needs to be rewritten - it is a hack at best */
+
        R300_STATECHANGE(r300, ri);
        R300_STATECHANGE(r300, rc);
        R300_STATECHANGE(r300, rr);
        
-       vp_reg = fp_reg = in_texcoords = 0;
+       vp_reg = fp_reg = in_texcoords = col_interp_nr = high_rr = 0;
        r300->hw.rr.cmd[R300_RR_ROUTE_0] = 0;
+       r300->hw.rr.cmd[R300_RR_ROUTE_1] = 0;
 
        for (i=0;i<ctx->Const.MaxTextureUnits;i++) {
                if (OutputsWritten & (hw_tcl_on ? (1 << (VERT_RESULT_TEX0+i)) : (_TNL_BIT_TEX0<<i)))
@@ -1151,7 +1151,8 @@ void r300_setup_rs_unit(GLcontext *ctx)
                                        | R300_RS_ROUTE_ENABLE
                                        | i /* source INTERP */
                                        | (fp_reg << R300_RS_ROUTE_DEST_SHIFT);
-                       
+                       high_rr = fp_reg;
+
                        if (OutputsWritten & (hw_tcl_on ? (1 << (VERT_RESULT_TEX0+i)) : (_TNL_BIT_TEX0<<i))) {
                                vp_reg++;
                        } else {
@@ -1168,25 +1169,34 @@ void r300_setup_rs_unit(GLcontext *ctx)
        if (InputsRead & FRAG_BIT_COL0) {
                if (!(OutputsWritten & (hw_tcl_on ? (1<<VERT_RESULT_COL0) : _TNL_BIT_COLOR0)))
                        fprintf(stderr, "fragprog wants col0, vp doesn't provide it\n");
+
                r300->hw.rr.cmd[R300_RR_ROUTE_0] |= 0
                                | R300_RS_ROUTE_0_COLOR
-                               | (fp_reg << R300_RS_ROUTE_0_COLOR_DEST_SHIFT);
+                               | (fp_reg++ << R300_RS_ROUTE_0_COLOR_DEST_SHIFT);
                InputsRead &= ~FRAG_BIT_COL0;
+               col_interp_nr++;
        }
-
+       
+       if (InputsRead & FRAG_BIT_COL1) {
+               if (!(OutputsWritten & (hw_tcl_on ? (1<<VERT_RESULT_COL1) : _TNL_BIT_COLOR1)))
+                       fprintf(stderr, "fragprog wants col1, vp doesn't provide it\n");
+
+               r300->hw.rr.cmd[R300_RR_ROUTE_1] |= R300_RS_ROUTE_1_UNKNOWN11
+                               | R300_RS_ROUTE_1_COLOR1
+                               | (fp_reg++ << R300_RS_ROUTE_1_COLOR1_DEST_SHIFT);
+               InputsRead &= ~FRAG_BIT_COL1;
+               if (high_rr < 1) high_rr = 1;
+               col_interp_nr++;
+       }
+       
        r300->hw.rc.cmd[1] = 0
                        | (in_texcoords << R300_RS_CNTL_TC_CNT_SHIFT)
-                       | R300_RS_CNTL_0_UNKNOWN_7
+                       | (col_interp_nr << R300_RS_CNTL_CI_CNT_SHIFT)
                        | R300_RS_CNTL_0_UNKNOWN_18;
-       
 
-       if (r300->state.texture.tc_count > 0) {
-                       r300->hw.rr.cmd[R300_RR_CMD_0] = cmducs(R300_RS_ROUTE_0, fp_reg);
-                       r300->hw.rc.cmd[2] = 0xC0 | (fp_reg-1); /* index of highest RS_ROUTE used*/
-       } else {
-                       r300->hw.rr.cmd[R300_RR_CMD_0] = cmducs(R300_RS_ROUTE_0, 1);
-                       r300->hw.rc.cmd[2] = 0x0;
-       }
+       assert(high_rr >= 0);
+       r300->hw.rr.cmd[R300_RR_CMD_0] = cmducs(R300_RS_ROUTE_0, high_rr+1);
+       r300->hw.rc.cmd[2] = 0xC0 | high_rr;
 
        if (InputsRead)
                WARN_ONCE("Don't know how to satisfy InputsRead=0x%08x\n", InputsRead);
@@ -1388,7 +1398,16 @@ void r300GenerateSimpleVertexShader(r300ContextPtr r300)
                VSF_TMP(0)
                )
        o_reg += 2;
-
+       
+       if (r300->state.render_inputs & _TNL_BIT_COLOR1) {
+               WRITE_OP(
+                       EASY_VSF_OP(MUL, o_reg++, ALL, RESULT),
+                       VSF_REG(r300->state.vap_reg.i_color[1]),
+                       VSF_ATTR_UNITY(r300->state.vap_reg.i_color[1]),
+                       VSF_UNITY(r300->state.vap_reg.i_color[1])
+               )
+       }
+       
        /* Pass through texture coordinates, if any */
        for(i=0;i < r300->radeon.glCtx->Const.MaxTextureUnits;i++)
                if(r300->state.render_inputs & (_TNL_BIT_TEX0<<i)){