/* Emit any changed arrays to new GART memory, re-emit a packet to
* update the arrays.
*/
-void r200EmitArrays( GLcontext *ctx, GLuint inputs )
+void r200EmitArrays( GLcontext *ctx, GLubyte *vimap_rev )
{
r200ContextPtr rmesa = R200_CONTEXT( ctx );
struct vertex_buffer *VB = &TNL_CONTEXT( ctx )->vb;
GLuint nr = 0;
GLuint vfmt0 = 0, vfmt1 = 0;
GLuint count = VB->Count;
- GLuint i;
- GLuint generic_in_mapped = 0;
- struct r200_vertex_program *vp = NULL;
-
- /* this looks way more complicated than necessary... */
- if (ctx->VertexProgram._Enabled) {
- vp = rmesa->curr_vp_hw;
- generic_in_mapped = vp->gen_inputs_mapped;
- }
-
- if (inputs & VERT_BIT_POS) {
- if (!rmesa->tcl.obj.buf)
- emit_vector( ctx,
- &rmesa->tcl.obj,
- (char *)VB->ObjPtr->data,
- VB->ObjPtr->size,
- VB->ObjPtr->stride,
- count);
-
- switch( VB->ObjPtr->size ) {
- case 4: vfmt0 |= R200_VTX_W0;
- case 3: vfmt0 |= R200_VTX_Z0;
- case 2:
- default:
- break;
- }
- component[nr++] = &rmesa->tcl.obj;
- }
- else if (generic_in_mapped & (1 << 0)) {
- int geninput = vp->rev_inputs[0] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_W0 | R200_VTX_Z0;
- }
-
- if (inputs & VERT_BIT_WEIGHT) {
- if (!rmesa->tcl.weight.buf)
- emit_vector( ctx,
- &rmesa->tcl.weight,
- (char *)VB->AttribPtr[VERT_ATTRIB_WEIGHT]->data,
- VB->AttribPtr[VERT_ATTRIB_WEIGHT]->size,
- VB->AttribPtr[VERT_ATTRIB_WEIGHT]->stride,
- count);
-
- assert(VB->AttribPtr[VERT_ATTRIB_WEIGHT]->size <= 4);
- vfmt0 |= VB->AttribPtr[VERT_ATTRIB_WEIGHT]->size << R200_VTX_WEIGHT_COUNT_SHIFT;
- component[nr++] = &rmesa->tcl.weight;
- }
-
- if (inputs & VERT_BIT_NORMAL) {
- if (!rmesa->tcl.norm.buf)
- emit_vector( ctx,
- &(rmesa->tcl.norm),
- (char *)VB->NormalPtr->data,
- 3,
- VB->NormalPtr->stride,
- count);
-
- vfmt0 |= R200_VTX_N0;
- component[nr++] = &rmesa->tcl.norm;
- }
-
- if (inputs & VERT_BIT_FOG) {
- if (!rmesa->tcl.fog.buf) {
- if (ctx->VertexProgram._Enabled)
- emit_vector( ctx,
- &(rmesa->tcl.fog),
- (char *)VB->FogCoordPtr->data,
+ GLuint i, emitsize;
+
+ for ( i = 0; i < 15; i++ ) {
+ GLubyte attrib = vimap_rev[i];
+ if (attrib != 255) {
+ switch (i) {
+ case 0:
+ emitsize = (VB->AttribPtr[attrib]->size);
+ switch (emitsize) {
+ case 4:
+ vfmt0 |= R200_VTX_W0;
+ /* fallthrough */
+ case 3:
+ vfmt0 |= R200_VTX_Z0;
+ break;
+ case 2:
+ break;
+ default: assert(0);
+ }
+ break;
+ case 1:
+ assert(attrib == VERT_ATTRIB_WEIGHT);
+ emitsize = (VB->AttribPtr[attrib]->size);
+ vfmt0 |= emitsize << R200_VTX_WEIGHT_COUNT_SHIFT;
+ break;
+ case 2:
+ assert(attrib == VERT_ATTRIB_NORMAL);
+ emitsize = 3;
+ vfmt0 |= R200_VTX_N0;
+ break;
+ case 3:
+ /* special handling to fix up fog. Will get us into trouble with vbos...*/
+ assert(attrib == VERT_ATTRIB_FOG);
+ if (!rmesa->tcl.vertex_data[i].buf) {
+ if (ctx->VertexProgram._Enabled)
+ emit_vector( ctx,
+ &(rmesa->tcl.vertex_data[attrib]),
+ (char *)VB->AttribPtr[attrib]->data,
1,
- VB->FogCoordPtr->stride,
+ VB->AttribPtr[attrib]->stride,
count);
- else
- emit_vecfog( ctx,
- &(rmesa->tcl.fog),
- (char *)VB->FogCoordPtr->data,
- VB->FogCoordPtr->stride,
+ else
+ emit_vecfog( ctx,
+ &(rmesa->tcl.vertex_data[attrib]),
+ (char *)VB->AttribPtr[attrib]->data,
+ VB->AttribPtr[attrib]->stride,
count);
- }
-
- vfmt0 |= R200_VTX_DISCRETE_FOG;
- component[nr++] = &rmesa->tcl.fog;
- }
-
- if (inputs & VERT_BIT_COLOR0) {
- int emitsize;
-
- if (VB->ColorPtr[0]->size == 4 &&
- (VB->ColorPtr[0]->stride != 0 ||
- VB->ColorPtr[0]->data[0][3] != 1.0)) {
- vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_0_SHIFT;
- emitsize = 4;
- }
- else {
- vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_0_SHIFT;
- emitsize = 3;
- }
-
- if (!rmesa->tcl.rgba.buf)
- emit_vector( ctx,
- &(rmesa->tcl.rgba),
- (char *)VB->ColorPtr[0]->data,
- emitsize,
- VB->ColorPtr[0]->stride,
- count);
-
- component[nr++] = &rmesa->tcl.rgba;
- }
-/* vfmt0 |= R200_VTX_PK_RGBA << R200_VTX_COLOR_0_SHIFT;
- emit_ubyte_rgba( ctx, &rmesa->tcl.rgba,
- (char *)VB->ColorPtr[0]->data, 4,
- VB->ColorPtr[0]->stride, count);*/
- else if (generic_in_mapped & (1 << 2)) {
- int geninput = vp->rev_inputs[2] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_0_SHIFT;
- }
-
-
- if (inputs & VERT_BIT_COLOR1) {
- if (!rmesa->tcl.spec.buf) {
- emit_vector( ctx,
- &rmesa->tcl.spec,
- (char *)VB->SecondaryColorPtr[0]->data,
- 3,
- VB->SecondaryColorPtr[0]->stride,
- count);
- }
-
- /* How does this work?
- */
- vfmt0 |= R200_VTX_FP_RGB << R200_VTX_COLOR_1_SHIFT;
- component[nr++] = &rmesa->tcl.spec;
- }
- else if (generic_in_mapped & (1 << 3)) {
- int geninput = vp->rev_inputs[3] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_1_SHIFT;
- }
-
- if (generic_in_mapped & (1 << 4)) {
- int geninput = vp->rev_inputs[4] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_2_SHIFT;
- }
-
- if (generic_in_mapped & (1 << 5)) {
- int geninput = vp->rev_inputs[5] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_FP_RGBA << R200_VTX_COLOR_3_SHIFT;
- }
-
- for ( i = 0 ; i < 6 ; i++ ) {
- if (inputs & (VERT_BIT_TEX0 << i)) {
- if (!rmesa->tcl.tex[i].buf)
- emit_vector( ctx,
- &(rmesa->tcl.tex[i]),
- (char *)VB->TexCoordPtr[i]->data,
- VB->TexCoordPtr[i]->size,
- VB->TexCoordPtr[i]->stride,
- count );
-
- vfmt1 |= VB->TexCoordPtr[i]->size << (i * 3);
- component[nr++] = &rmesa->tcl.tex[i];
- }
- else if (generic_in_mapped & (1 << (i + 6))) {
- int geninput = vp->rev_inputs[i + 6] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt1 |= 4 << (R200_VTX_TEX0_COMP_CNT_SHIFT + (i * 3));
- }
- }
-
- if (generic_in_mapped & (1 << 13)) {
- int geninput = vp->rev_inputs[13] - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->data,
- 4,
- VB->AttribPtr[geninput + VERT_ATTRIB_GENERIC0]->stride,
- count );
- }
- component[nr++] = &rmesa->tcl.generic[geninput];
- vfmt0 |= R200_VTX_XY1 | R200_VTX_Z1 | R200_VTX_W1;
- }
-
-/* doesn't work. Wrong order with mixed generic & conventional! */
-/*
- if (ctx->VertexProgram._Enabled) {
- int *vp_inputs = rmesa->curr_vp_hw->inputs;
- for ( i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++ ) {
- if (inputs & (1 << i)) {
- int geninput = i - VERT_ATTRIB_GENERIC0;
- if (!rmesa->tcl.generic[geninput].buf) {
- emit_vector( ctx,
- &(rmesa->tcl.generic[geninput]),
- (char *)VB->AttribPtr[i]->data,
- 4,
- VB->AttribPtr[i]->stride,
- count );
}
- component[nr++] = &rmesa->tcl.generic[geninput];
- switch (vp_inputs[i]) {
- case 0:
- vfmt0 |= R200_VTX_W0 | R200_VTX_Z0;
- break;
+ vfmt0 |= R200_VTX_DISCRETE_FOG;
+ goto after_emit;
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ if (VB->AttribPtr[attrib]->size == 4 &&
+ (VB->AttribPtr[attrib]->stride != 0 ||
+ VB->AttribPtr[attrib]->data[0][3] != 1.0)) emitsize = 4;
+ else emitsize = 3;
+ if (emitsize == 4)
+ vfmt0 |= R200_VTX_FP_RGBA << (R200_VTX_COLOR_0_SHIFT + (i - 4) * 2);
+ else {
+ vfmt0 |= R200_VTX_FP_RGB << (R200_VTX_COLOR_0_SHIFT + (i - 4) * 2);
+ }
+ break;
+ case 8:
+ case 9:
+ case 10:
+ case 11:
+ case 12:
+ case 13:
+ emitsize = VB->AttribPtr[attrib]->size;
+ vfmt1 |= emitsize << (R200_VTX_TEX0_COMP_CNT_SHIFT + (i - 8) * 3);
+ break;
+ case 14:
+ emitsize = VB->AttribPtr[attrib]->size >= 2 ? VB->AttribPtr[attrib]->size : 2;
+ switch (emitsize) {
case 2:
+ vfmt0 |= R200_VTX_XY1;
+ /* fallthrough */
case 3:
+ vfmt0 |= R200_VTX_Z1;
+ /* fallthrough */
case 4:
- case 5:
- vfmt0 |= R200_VTX_FP_RGBA << (R200_VTX_COLOR_0_SHIFT + (vp_inputs[i] - 2) * 2);
- break;
- case 6:
- case 7:
- case 8:
- case 9:
- case 10:
- case 11:
- vfmt1 |= 4 << (R200_VTX_TEX0_COMP_CNT_SHIFT + (vp_inputs[i] - 6) * 3);
- break;
- case 13:
- vfmt0 |= R200_VTX_XY1 | R200_VTX_Z1 | R200_VTX_W1;
- break;
- case 1:
- case 12:
- default:
- assert(0);
+ vfmt0 |= R200_VTX_W1;
+ break;
}
+ default:
+ assert(0);
+ }
+ if (!rmesa->tcl.vertex_data[i].buf) {
+ emit_vector( ctx,
+ &(rmesa->tcl.vertex_data[i]),
+ (char *)VB->AttribPtr[attrib]->data,
+ emitsize,
+ VB->AttribPtr[attrib]->stride,
+ count );
}
+after_emit:
+ assert(nr < 12);
+ component[nr++] = &rmesa->tcl.vertex_data[i];
}
}
-*/
if (vfmt0 != rmesa->hw.vtx.cmd[VTX_VTXFMT_0] ||
vfmt1 != rmesa->hw.vtx.cmd[VTX_VTXFMT_1]) {
void r200ReleaseArrays( GLcontext *ctx, GLuint newinputs )
{
- GLuint unit;
r200ContextPtr rmesa = R200_CONTEXT( ctx );
-/* if (R200_DEBUG & DEBUG_VERTS) */
-/* _tnl_print_vert_flags( __FUNCTION__, newinputs ); */
-
- if (newinputs & VERT_BIT_POS)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.obj, __FUNCTION__ );
-
- if (newinputs & VERT_BIT_WEIGHT)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.weight, __FUNCTION__ );
-
- if (newinputs & VERT_BIT_NORMAL)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.norm, __FUNCTION__ );
-
- if (newinputs & VERT_BIT_FOG)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.fog, __FUNCTION__ );
-
- if (newinputs & VERT_BIT_COLOR0)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.rgba, __FUNCTION__ );
-
- if (newinputs & VERT_BIT_COLOR1)
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.spec, __FUNCTION__ );
-
- for (unit = 0 ; unit < ctx->Const.MaxTextureUnits; unit++) {
- if (newinputs & VERT_BIT_TEX(unit))
- r200ReleaseDmaRegion( rmesa, &rmesa->tcl.tex[unit], __FUNCTION__ );
- }
-
- if (ctx->VertexProgram._Enabled) {
- int i;
- for (i = VERT_ATTRIB_GENERIC0; i < VERT_ATTRIB_MAX; i++) {
- if (newinputs & (1 << i))
- r200ReleaseDmaRegion( rmesa,
- &rmesa->tcl.generic[i - VERT_ATTRIB_GENERIC0], __FUNCTION__ );
- }
+ /* only do it for changed inputs ? */
+ int i;
+ for (i = 0; i < 15; i++) {
+ if (newinputs & (1 << i))
+ r200ReleaseDmaRegion( rmesa,
+ &rmesa->tcl.vertex_data[i], __FUNCTION__ );
}
-
}
r200ContextPtr rmesa = R200_CONTEXT(ctx);
TNLcontext *tnl = TNL_CONTEXT(ctx);
struct vertex_buffer *VB = &tnl->vb;
- GLuint inputs = 0;
GLuint i;
+ GLubyte *vimap_rev;
+/* use hw fixed order for simplicity, pos 0, weight 1, normal 2, fog 3,
+ color0 - color3 4-7, texcoord0 - texcoord5 8-13, pos 1 14. Must not use
+ more than 12 of those at the same time. */
+ GLubyte map_rev_fixed[15] = {255, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255};
+
/* TODO: separate this from the swtnl pipeline
*/
r200ValidateState( ctx );
if (!ctx->VertexProgram._Enabled) {
- inputs = VERT_BIT_POS | VERT_BIT_COLOR0;
/* NOTE: inputs != tnl->render_inputs - these are the untransformed
* inputs.
*/
+ map_rev_fixed[0] = VERT_ATTRIB_POS;
+ /* technically there is no reason we always need VA_COLOR0. In theory
+ could disable it depending on lighting, color materials, texturing... */
+ map_rev_fixed[4] = VERT_ATTRIB_COLOR0;
+
if (ctx->Light.Enabled) {
- inputs |= VERT_BIT_NORMAL;
+ map_rev_fixed[2] = VERT_ATTRIB_NORMAL;
}
+ /* this also enables VA_COLOR1 when using separate specular
+ lighting model, which is unnecessary.
+ FIXME: OTOH, we're missing the case where a ATI_fragment_shader accesses
+ the secondary color (if lighting is disabled). The chip seems
+ misconfigured for that though elsewhere (tcl output, might lock up) */
if (ctx->_TriangleCaps & DD_SEPARATE_SPECULAR) {
- inputs |= VERT_BIT_COLOR1;
+ map_rev_fixed[5] = VERT_ATTRIB_COLOR1;
}
if ( (ctx->Fog.FogCoordinateSource == GL_FOG_COORD) && ctx->Fog.Enabled ) {
- inputs |= VERT_BIT_FOG;
+ map_rev_fixed[3] = VERT_ATTRIB_FOG;
}
for (i = 0 ; i < ctx->Const.MaxTextureUnits; i++) {
if (ctx->Texture.Unit[i]._ReallyEnabled) {
if (rmesa->TexGenNeedNormals[i]) {
- inputs |= VERT_BIT_NORMAL;
+ map_rev_fixed[2] = VERT_ATTRIB_NORMAL;
}
- inputs |= VERT_BIT_TEX(i);
+ map_rev_fixed[8 + i] = VERT_ATTRIB_TEX0 + i;
}
}
+ vimap_rev = &map_rev_fixed[0];
}
else {
/* vtx_tcl_output_vtxfmt_0/1 need to match configuration of "fragment
We only need to change compsel. */
GLuint out_compsel = 0;
GLuint vp_out = rmesa->curr_vp_hw->mesa_program.Base.OutputsWritten;
-#if 0
- /* can't handle other inputs, generic attribs etc. currently - should never arrive here */
- assert ((rmesa->curr_vp_hw->mesa_program.Base.InputsRead &
- ~(VERT_BIT_POS | VERT_BIT_NORMAL | VERT_BIT_COLOR0 | VERT_BIT_COLOR1 |
- VERT_BIT_FOG | VERT_BIT_TEX0 | VERT_BIT_TEX1 | VERT_BIT_TEX2 |
- VERT_BIT_TEX3 | VERT_BIT_TEX4 | VERT_BIT_TEX5)) == 0);
-#endif
- inputs |= rmesa->curr_vp_hw->mesa_program.Base.InputsRead;
+
+ vimap_rev = &rmesa->curr_vp_hw->inputmap_rev[0];
assert(vp_out & (1 << VERT_RESULT_HPOS));
out_compsel = R200_OUTPUT_XYZW;
if (vp_out & (1 << VERT_RESULT_COL0)) {
/* Do the actual work:
*/
r200ReleaseArrays( ctx, ~0 /* stage->changed_inputs */ );
- r200EmitArrays( ctx, inputs );
+ r200EmitArrays( ctx, vimap_rev );
rmesa->tcl.Elts = VB->Elts;