gallium: optimizations to flatshade, two-side prim stages

This commit is contained in:
Brian 2008-01-25 08:15:04 -07:00
parent 48355538a6
commit a148cc51fb
2 changed files with 36 additions and 23 deletions

View file

@ -76,12 +76,25 @@ static INLINE void copy_colors( struct draw_stage *stage,
{ {
const struct flat_stage *flat = flat_stage(stage); const struct flat_stage *flat = flat_stage(stage);
uint i; uint i;
/* Look for constant/flat attribs and duplicate from src to dst vertex */
/* skip attrib[0] which is vert pos */
for (i = 0; i < flat->num_color_attribs; i++) { for (i = 0; i < flat->num_color_attribs; i++) {
const uint attr = flat->color_attribs[i]; const uint attr = flat->color_attribs[i];
memcpy(dst->data[attr], src->data[attr], sizeof(src->data[0])); COPY_4FV(dst->data[attr], src->data[attr]);
}
}
/** Copy all the color attributes from src vertex to dst0 & dst1 vertices */
static INLINE void copy_colors2( struct draw_stage *stage,
struct vertex_header *dst0,
struct vertex_header *dst1,
const struct vertex_header *src )
{
const struct flat_stage *flat = flat_stage(stage);
uint i;
for (i = 0; i < flat->num_color_attribs; i++) {
const uint attr = flat->color_attribs[i];
COPY_4FV(dst0->data[attr], src->data[attr]);
COPY_4FV(dst1->data[attr], src->data[attr]);
} }
} }
@ -101,8 +114,7 @@ static void flatshade_tri( struct draw_stage *stage,
tmp.v[1] = dup_vert(stage, header->v[1], 1); tmp.v[1] = dup_vert(stage, header->v[1], 1);
tmp.v[2] = header->v[2]; tmp.v[2] = header->v[2];
copy_colors(stage, tmp.v[0], tmp.v[2]); copy_colors2(stage, tmp.v[0], tmp.v[1], tmp.v[2]);
copy_colors(stage, tmp.v[1], tmp.v[2]);
stage->next->tri( stage->next, &tmp ); stage->next->tri( stage->next, &tmp );
} }

View file

@ -75,6 +75,12 @@ static void twoside_begin( struct draw_stage *stage )
} }
} }
if (!twoside->attrib_back0)
twoside->attrib_front0 = 0;
if (!twoside->attrib_back1)
twoside->attrib_front1 = 0;
/* /*
* We'll multiply the primitive's determinant by this sign to determine * We'll multiply the primitive's determinant by this sign to determine
* if the triangle is back-facing (negative). * if the triangle is back-facing (negative).
@ -86,28 +92,23 @@ static void twoside_begin( struct draw_stage *stage )
} }
static INLINE void copy_attrib( unsigned attr_dst,
unsigned attr_src,
struct vertex_header *v )
{
COPY_4FV(v->data[attr_dst], v->data[attr_src]);
}
/** /**
* Copy back color(s) to front color(s). * Copy back color(s) to front color(s).
*/ */
static struct vertex_header *copy_bfc( struct twoside_stage *twoside, static INLINE struct vertex_header *
const struct vertex_header *v, copy_bfc( struct twoside_stage *twoside,
unsigned idx ) const struct vertex_header *v,
unsigned idx )
{ {
struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx ); struct vertex_header *tmp = dup_vert( &twoside->stage, v, idx );
if (twoside->attrib_front0 && twoside->attrib_back0) { if (twoside->attrib_back0) {
copy_attrib(twoside->attrib_front0, twoside->attrib_back0, tmp); COPY_4FV(tmp->data[twoside->attrib_front0],
tmp->data[twoside->attrib_back0]);
} }
if (twoside->attrib_front1 && twoside->attrib_back1) { if (twoside->attrib_back1) {
copy_attrib(twoside->attrib_front1, twoside->attrib_back1, tmp); COPY_4FV(tmp->data[twoside->attrib_front1],
tmp->data[twoside->attrib_back1]);
} }
return tmp; return tmp;