Share routing code between immd/vb. Fix breakage of vertex programs in vb mode.
authorBen Skeggs <darktama@iinet.net.au>
Tue, 15 Feb 2005 19:07:35 +0000 (19:07 +0000)
committerBen Skeggs <darktama@iinet.net.au>
Tue, 15 Feb 2005 19:07:35 +0000 (19:07 +0000)
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_maos.c
src/mesa/drivers/dri/r300/r300_maos.h
src/mesa/drivers/dri/r300/r300_render.c
src/mesa/drivers/dri/r300/r300_state.c
src/mesa/drivers/dri/r300/r300_texstate.c

index b6a80ae005f190016eee21200a6782225e9caef8..eb76a1ca05a8ea0845e4f9c35265c103d0af497a 100644 (file)
@@ -116,14 +116,6 @@ struct r300_dma_region {
     int aos_size;       /* number of components (1-4) */
     int aos_format;     /* format of components */
     int aos_reg;        /* VAP register assignment */
-
-/* Left here so immediate mode still works unmodified */
-       int element_size;
-       int stride;
-       int offset;
-       int ncomponents;
-       int reg;
-       int format;
 };
 
 struct r300_dma {
index a6c15e5220a7b88057de342bd73f010a5226c8ae..27cb4afa1c9e93244c95e55b4c41a8c3cc62c5f4 100644 (file)
@@ -208,11 +208,11 @@ static void emit_vector(GLcontext * ctx,
        }
 
 }
-
-/* Emit any changed arrays to new GART memory, re-emit a packet to
- * update the arrays.
+                               
+/* Emit vertex data to GART memory (unless immediate mode)
+ * Route inputs to the vertex processor
  */
-void r300EmitArrays(GLcontext * ctx, GLuint inputs)
+void r300EmitArrays(GLcontext * ctx, GLboolean immd)
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        r300ContextPtr r300 = rmesa;
@@ -223,88 +223,126 @@ void r300EmitArrays(GLcontext * ctx, GLuint inputs)
        GLuint vic_1 = 0;       /* R300_VAP_INPUT_CNTL_1 */
        GLuint aa_vap_reg = 0; /* VAP register assignment */
        GLuint i;
+       GLuint inputs = 0;
+
+#define CONFIGURE_AOS(f, v, sz, cn) { \
+               if (RADEON_DEBUG & DEBUG_STATE) \
+                       fprintf(stderr, "Enabling "#v "\n"); \
+               if (++nr >= R300_MAX_AOS_ARRAYS) { \
+                       fprintf(stderr, "Aieee! AOS array count exceeded!\n"); \
+                       exit(-1); \
+               } \
+               \
+               if (rmesa->current_vp == NULL) \
+                       rmesa->state.aos[nr-1].aos_reg = aa_vap_reg++; \
+               rmesa->state.aos[nr-1].aos_format = f; \
+               if (immd) { \
+                       rmesa->state.aos[nr-1].aos_size = 4; \
+                       rmesa->state.aos[nr-1].aos_stride = 4; \
+                       rmesa->state.aos[nr-1].aos_offset = 0; \
+               } else { \
+                       emit_vector(ctx, \
+                                               &rmesa->state.aos[nr-1], \
+                                               v->data, \
+                                               sz, \
+                                               v->stride, \
+                                               cn); \
+               } \
+}
+
+       if (rmesa->current_vp != NULL) {
+               if (rmesa->current_vp->inputs[VERT_ATTRIB_POS] != -1) {
+                       inputs |= _TNL_BIT_POS;
+                       rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_POS];
+               }
+               if (rmesa->current_vp->inputs[VERT_ATTRIB_NORMAL] != -1) {
+                       inputs |= _TNL_BIT_NORMAL;
+                       rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_NORMAL];
+               }
+               if (rmesa->current_vp->inputs[VERT_ATTRIB_COLOR0] != -1) {
+                       inputs |= _TNL_BIT_COLOR0;
+                       rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_COLOR0];
+               }
+               if (rmesa->current_vp->inputs[VERT_ATTRIB_COLOR1] != -1) {
+                       inputs |= _TNL_BIT_COLOR1;
+                       rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_COLOR1];
+               }
+               if (rmesa->current_vp->inputs[VERT_ATTRIB_FOG] != -1) {
+                       inputs |= _TNL_BIT_FOG;
+                       rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_FOG];
+               }
+               for (i=0;i<ctx->Const.MaxTextureUnits;i++) {
+                       if (rmesa->current_vp->inputs[VERT_ATTRIB_TEX0+i] != -1)
+                               inputs |= _TNL_BIT_TEX0<<i;
+                               rmesa->state.aos[nr++].aos_reg = rmesa->current_vp->inputs[VERT_ATTRIB_TEX0+i];
+               }
+               nr = 0;
+       } else {
+               inputs = TNL_CONTEXT(ctx)->render_inputs;
+       }
+       rmesa->state.render_inputs = inputs;
 
-/*FIXME: handle vertex program input */
        if (inputs & _TNL_BIT_POS) {
-               if (RADEON_DEBUG & DEBUG_ALL)
-                       fprintf(stderr, "[%d] _TNL_BIT_POS: sz=%d, st=%d, c=%d\n",
-                               nr, VB->ObjPtr->size, VB->ObjPtr->stride, count);
-               emit_vector(ctx, &rmesa->state.aos[nr++],
-                                       (char *)VB->ObjPtr->data,
-                                       VB->ObjPtr->size,
-                                       VB->ObjPtr->stride, count);
+               CONFIGURE_AOS(  AOS_FORMAT_FLOAT,
+                                               VB->ObjPtr,
+                                               immd ? 4 : VB->ObjPtr->size,
+                                               count);
 
                vic_1 |= R300_INPUT_CNTL_POS;
-               rmesa->state.aos[nr-1].aos_reg    = aa_vap_reg++;
-               rmesa->state.aos[nr-1].aos_format = AOS_FORMAT_FLOAT;
        }
 
        if (inputs & _TNL_BIT_NORMAL) {
-               if (RADEON_DEBUG & DEBUG_ALL)
-                       fprintf(stderr, "[%d] _TNL_BIT_NORMAL: sz=%d, st=%d, c=%d\n",
-                               nr, VB->NormalPtr->size, VB->NormalPtr->stride, count);
-               emit_vector(ctx, &rmesa->state.aos[nr++],
-                               (char *)VB->NormalPtr->data,
-                               VB->NormalPtr->size,
-                               VB->NormalPtr->stride, count);
+               CONFIGURE_AOS(  AOS_FORMAT_FLOAT,
+                                               VB->NormalPtr,
+                                               immd ? 4 : VB->NormalPtr->size,
+                                               count);
 
                vic_1 |= R300_INPUT_CNTL_NORMAL;
-               rmesa->state.aos[nr-1].aos_reg    = aa_vap_reg++;
-               rmesa->state.aos[nr-1].aos_format = AOS_FORMAT_FLOAT;
        }
 
-       if (inputs & VERT_BIT_COLOR0) {
+       if (inputs & _TNL_BIT_COLOR0) {
                int emitsize;
-               if (RADEON_DEBUG & DEBUG_ALL)
-                       fprintf(stderr, "[%d] _TNL_BIT_COLOR0: sz=%d, st=%d, c=%d\n",
-                               nr, VB->ColorPtr[0]->size, VB->ColorPtr[0]->stride, count);
-
-               if (VB->ColorPtr[0]->size == 4 &&
-                   (VB->ColorPtr[0]->stride != 0 ||
-                    VB->ColorPtr[0]->data[0][3] != 1.0)) {
-                       emitsize = 4;
-               } else {
-                       emitsize = 3;
+
+               if (!immd) {
+                       if (VB->ColorPtr[0]->size == 4 &&
+                           (VB->ColorPtr[0]->stride != 0 ||
+                            VB->ColorPtr[0]->data[0][3] != 1.0)) {
+                               emitsize = 4;
+                       } else {
+                               emitsize = 3;
+                       }
                }
 
-               emit_vector(ctx,
-                           &(rmesa->state.aos[nr++]),
-                           (char *)VB->ColorPtr[0]->data,
-                           emitsize, VB->ColorPtr[0]->stride, count);
-//                         emitsize, VB->ColorPtr[0]->stride, count);
+               CONFIGURE_AOS(  AOS_FORMAT_FLOAT_COLOR,
+                                               VB->ColorPtr[0],
+                                               immd ? 4 : emitsize,
+                                               count);
 
                vic_1 |= R300_INPUT_CNTL_COLOR;
-               rmesa->state.aos[nr-1].aos_reg    = aa_vap_reg++;
-               rmesa->state.aos[nr-1].aos_format = AOS_FORMAT_FLOAT_COLOR;
        }
 
-       if (inputs & VERT_BIT_COLOR1) {
-               if (RADEON_DEBUG & DEBUG_ALL)
-                       fprintf(stderr, "[%d] _TNL_BIT_COLOR1: sz=%d, st=%d, c=%d\n",
-                               nr, VB->SecondaryColorPtr[0]->size, VB->SecondaryColorPtr[0]->stride, count);
-
-               emit_vector(ctx,
-                           &rmesa->state.aos[nr++],
-                           (char *)VB->SecondaryColorPtr[0]->data,
-                           VB->SecondaryColorPtr[0]->size, VB->SecondaryColorPtr[0]->stride, count);
-               rmesa->state.aos[nr-1].aos_reg    = aa_vap_reg++;
-               rmesa->state.aos[nr-1].aos_format = AOS_FORMAT_FLOAT_COLOR;
+       if (inputs & _TNL_BIT_COLOR1) {
+               CONFIGURE_AOS(  AOS_FORMAT_FLOAT_COLOR,
+                                               VB->SecondaryColorPtr[0],
+                                               immd ? 4 : VB->SecondaryColorPtr[0]->size,
+                                               count);
+       }
+
+       if (inputs & _TNL_BIT_FOG) {
+               CONFIGURE_AOS(  AOS_FORMAT_FLOAT,
+                                               VB->FogCoordPtr,
+                                               immd ? 4 : VB->FogCoordPtr->size,
+                                               count);
        }
 
        for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
                if (inputs & (_TNL_BIT_TEX0 << i)) {
-                       if (RADEON_DEBUG & DEBUG_ALL)
-                               fprintf(stderr, "[%d] _TNL_BIT_TEX%02d: sz=%d, st=%d, c=%d\n",
-                                       nr, i, VB->TexCoordPtr[i]->size, VB->TexCoordPtr[i]->stride, count);
-                       emit_vector(ctx,
-                                   &(rmesa->state.aos[nr++]),
-                                   (char *)VB->TexCoordPtr[i]->data,
-                                   VB->TexCoordPtr[i]->size,
-                                   VB->TexCoordPtr[i]->stride, count);
+                       CONFIGURE_AOS(  AOS_FORMAT_FLOAT,
+                                                       VB->TexCoordPtr[i],
+                                                       immd ? 4 : VB->TexCoordPtr[i]->size,
+                                                       count);
 
                        vic_1 |= R300_INPUT_CNTL_TC0 << i;
-                       rmesa->state.aos[nr-1].aos_reg    = aa_vap_reg++;
-                       rmesa->state.aos[nr-1].aos_format = AOS_FORMAT_FLOAT;
                }
        }
 
@@ -398,7 +436,7 @@ drm_radeon_cmd_header_t *cmd = NULL;
        ((drm_r300_cmd_header_t*)r300->hw.vir[1].cmd)->unchecked_state.count = (nr+1)>>1;
 
        /* Set up input_cntl */
-
+       /* I don't think this is needed for vertex buffers, but it doesn't hurt anything */
        R300_STATECHANGE(r300, vic);
        r300->hw.vic.cmd[R300_VIC_CNTL_0]=0x5555;  /* Hard coded value, no idea what it means */
        r300->hw.vic.cmd[R300_VIC_CNTL_1]=vic_1;
index 6f6cce2f46141ad25b6d5c24d40277d8c24f419b..ec827a39b397bdb75a1581203bccc9e2e5a507fb 100644 (file)
@@ -40,7 +40,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "r300_context.h"
 
-extern void r300EmitArrays(GLcontext * ctx, GLuint inputs);
+extern void r300EmitArrays(GLcontext * ctx, GLboolean immd);
 extern void r300ReleaseArrays(GLcontext * ctx);
 
 #endif
index 8f9d89298248179bf7264b40d844b29b3efa5f8c..862fabbc142ff12b4541c7608667a35c70624823 100644 (file)
@@ -485,9 +485,12 @@ static GLboolean r300_run_immediate_render(GLcontext *ctx,
    efloat(1.0);
    #endif
    
+/* Setup INPUT_ROUTE and INPUT_CNTL */
+       r300EmitArrays(ctx, GL_TRUE);
+
 /* Why do we need this for immediate mode?? Vertex processor needs it to know proper regs */
-//   r300EmitLOAD_VBPNTR(rmesa, 0);
-   
+//     r300EmitLOAD_VBPNTR(rmesa, 0);
+
    for(i=0; i < VB->PrimitiveCount; i++){
        GLuint prim = VB->Primitive[i].mode;
        GLuint start = VB->Primitive[i].start;
@@ -542,7 +545,7 @@ static GLboolean r300_run_vb_render(GLcontext *ctx,
 
    
        r300ReleaseArrays(ctx);
-       r300EmitArrays(ctx, rmesa->state.render_inputs);
+       r300EmitArrays(ctx, GL_FALSE);
        
 //     LOCK_HARDWARE(&(rmesa->radeon));
 
index d0f49b75f0b1b2d49f7008372bccea4de2a936b3..94324b339d1782dad0d9e1320a6b389bbc6dc80e 100644 (file)
@@ -1017,18 +1017,11 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
        #define CONFIGURE_AOS(v, o, r, f) \
                {\
                if (RADEON_DEBUG & DEBUG_STATE)fprintf(stderr, "Enabling "#r "\n"); \
-               if(immediate){ \
-                       r300->state.aos[count].element_size=4; \
-                       r300->state.aos[count].stride=4; \
-                       r300->state.aos[count].ncomponents=4; \
-                       } else { \
-                       r300->state.aos[count].element_size=v->size; \
-                       r300->state.aos[count].stride=v->size; \
-                       r300->state.aos[count].ncomponents=v->size; \
-                       } \
-               r300->state.aos[count].offset=o; \
-               r300->state.aos[count].reg=reg; \
-               r300->state.aos[count].format=(f); \
+               r300->state.aos[count].aos_size=4; \
+               r300->state.aos[count].aos_stride=4; \
+               r300->state.aos[count].aos_offset=o; \
+               r300->state.aos[count].aos_reg=reg; \
+               r300->state.aos[count].aos_format=(f); \
                r300->state.vap_reg.r=reg; \
                count++; \
                reg++; \
@@ -1123,12 +1116,12 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
        /* setup INPUT_ROUTE */
        R300_STATECHANGE(r300, vir[0]);
        for(i=0;i+1<count;i+=2){
-               dw=(r300->state.aos[i].ncomponents-1)
-               | ((r300->state.aos[i].reg)<<8)
-               | (r300->state.aos[i].format<<14)
-               | (((r300->state.aos[i+1].ncomponents-1)
-               | ((r300->state.aos[i+1].reg)<<8)
-               | (r300->state.aos[i+1].format<<14))<<16);
+               dw=(r300->state.aos[i].aos_size-1)
+               | ((r300->state.aos[i].aos_reg)<<8)
+               | (r300->state.aos[i].aos_format<<14)
+               | (((r300->state.aos[i+1].aos_size-1)
+               | ((r300->state.aos[i+1].aos_reg)<<8)
+               | (r300->state.aos[i+1].aos_format<<14))<<16);
 
                if(i+2==count){
                        dw|=(1<<(13+16));
@@ -1136,9 +1129,9 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
                r300->hw.vir[0].cmd[R300_VIR_CNTL_0+(i>>1)]=dw;
                }
        if(count & 1){
-               dw=(r300->state.aos[count-1].ncomponents-1)
-               | (r300->state.aos[count-1].format<<14)
-               | ((r300->state.aos[count-1].reg)<<8)
+               dw=(r300->state.aos[count-1].aos_size-1)
+               | (r300->state.aos[count-1].aos_format<<14)
+               | ((r300->state.aos[count-1].aos_reg)<<8)
                | (1<<13);
                r300->hw.vir[0].cmd[R300_VIR_CNTL_0+(count>>1)]=dw;
                //fprintf(stderr, "vir0 dw=%08x\n", dw);
@@ -1163,13 +1156,13 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
 
        for(i=0;i+1<count;i+=2){
                /* do i first.. */
-               mask=(1<<(r300->state.aos[i].ncomponents*3))-1;
+               mask=(1<<(r300->state.aos[i].aos_size*3))-1;
                dw=(ALL_COMPONENTS & mask)
                | (ALL_DEFAULT & ~mask)
                | R300_INPUT_ROUTE_ENABLE;
 
                /* i+1 */
-               mask=(1<<(r300->state.aos[i+1].ncomponents*3))-1;
+               mask=(1<<(r300->state.aos[i+1].aos_size*3))-1;
                dw|=(
                (ALL_COMPONENTS & mask)
                | (ALL_DEFAULT & ~mask)
@@ -1179,7 +1172,7 @@ void r300_setup_routing(GLcontext *ctx, GLboolean immediate)
                r300->hw.vir[1].cmd[R300_VIR_CNTL_0+(i>>1)]=dw;
                }
        if(count & 1){
-               mask=(1<<(r300->state.aos[count-1].ncomponents*3))-1;
+               mask=(1<<(r300->state.aos[count-1].aos_size*3))-1;
                dw=(ALL_COMPONENTS & mask)
                | (ALL_DEFAULT & ~mask)
                | R300_INPUT_ROUTE_ENABLE;
@@ -1833,7 +1826,8 @@ void r300ResetHwState(r300ContextPtr r300)
 
        r300UpdateTextureState(ctx);
        
-       r300_setup_routing(ctx, GL_TRUE);
+//     r300_setup_routing(ctx, GL_TRUE);
+       r300EmitArrays(ctx, GL_TRUE); /* Just do the routing */
        r300_setup_textures(ctx);
        r300_setup_rs_unit(ctx);
 
index 8499ef89ab4af58d1b0a4b7ee5f1a93c8ac8f837..09466806713cc1750855114d7f2b64fff9f55a0d 100644 (file)
@@ -119,7 +119,7 @@ static const struct {
            {0xffffff16,  0},
            {0xffffff17, 0},
            };
-#elif
+#else
            {R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8), 0},
            {0xffffff01, 0},
            {0xffffff02, 0},