From f44602765670a4ccf284dd71e2b1af5ac9200d03 Mon Sep 17 00:00:00 2001 From: Ben Skeggs Date: Tue, 15 Feb 2005 19:07:35 +0000 Subject: [PATCH] Share routing code between immd/vb. Fix breakage of vertex programs in vb mode. --- src/mesa/drivers/dri/r300/r300_context.h | 8 -- src/mesa/drivers/dri/r300/r300_maos.c | 164 +++++++++++++--------- src/mesa/drivers/dri/r300/r300_maos.h | 2 +- src/mesa/drivers/dri/r300/r300_render.c | 9 +- src/mesa/drivers/dri/r300/r300_state.c | 44 +++--- src/mesa/drivers/dri/r300/r300_texstate.c | 2 +- 6 files changed, 128 insertions(+), 101 deletions(-) diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index b6a80ae005f..eb76a1ca05a 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -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 { diff --git a/src/mesa/drivers/dri/r300/r300_maos.c b/src/mesa/drivers/dri/r300/r300_maos.c index a6c15e5220a..27cb4afa1c9 100644 --- a/src/mesa/drivers/dri/r300/r300_maos.c +++ b/src/mesa/drivers/dri/r300/r300_maos.c @@ -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;iConst.MaxTextureUnits;i++) { + if (rmesa->current_vp->inputs[VERT_ATTRIB_TEX0+i] != -1) + inputs |= _TNL_BIT_TEX0<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; diff --git a/src/mesa/drivers/dri/r300/r300_maos.h b/src/mesa/drivers/dri/r300/r300_maos.h index 6f6cce2f461..ec827a39b39 100644 --- a/src/mesa/drivers/dri/r300/r300_maos.h +++ b/src/mesa/drivers/dri/r300/r300_maos.h @@ -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 diff --git a/src/mesa/drivers/dri/r300/r300_render.c b/src/mesa/drivers/dri/r300/r300_render.c index 8f9d8929824..862fabbc142 100644 --- a/src/mesa/drivers/dri/r300/r300_render.c +++ b/src/mesa/drivers/dri/r300/r300_render.c @@ -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)); diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index d0f49b75f0b..94324b339d1 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -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+1state.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+1state.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); diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c index 8499ef89ab4..09466806713 100644 --- a/src/mesa/drivers/dri/r300/r300_texstate.c +++ b/src/mesa/drivers/dri/r300/r300_texstate.c @@ -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}, -- 2.30.2