make draw's vertex_info struct smaller/quicker to compare with memcmp()

This commit is contained in:
Keith Whitwell
2008-09-10 11:39:43 +01:00
parent 0370d6b359
commit 53d4706c6c
9 changed files with 59 additions and 29 deletions
+2 -2
View File
@@ -231,9 +231,9 @@ vbuf_set_prim( struct vbuf_stage *vbuf, uint prim )
unsigned emit_sz = 0;
unsigned src_buffer = 0;
unsigned output_format;
unsigned src_offset = (vbuf->vinfo->src_index[i] * 4 * sizeof(float) );
unsigned src_offset = (vbuf->vinfo->attrib[i].src_index * 4 * sizeof(float) );
switch (vbuf->vinfo->emit[i]) {
switch (vbuf->vinfo->attrib[i].emit) {
case EMIT_4F:
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
emit_sz = 4 * sizeof(float);
+2 -2
View File
@@ -84,11 +84,11 @@ void draw_pt_emit_prepare( struct pt_emit *emit,
unsigned emit_sz = 0;
unsigned src_buffer = 0;
unsigned output_format;
unsigned src_offset = (vinfo->src_index[i] * 4 * sizeof(float) );
unsigned src_offset = (vinfo->attrib[i].src_index * 4 * sizeof(float) );
switch (vinfo->emit[i]) {
switch (vinfo->attrib[i].emit) {
case EMIT_4F:
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
emit_sz = 4 * sizeof(float);
@@ -121,7 +121,7 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
memset(&key, 0, sizeof(key));
for (i = 0; i < vinfo->num_attribs; i++) {
const struct pipe_vertex_element *src = &draw->pt.vertex_element[vinfo->src_index[i]];
const struct pipe_vertex_element *src = &draw->pt.vertex_element[vinfo->attrib[i].src_index];
unsigned emit_sz = 0;
unsigned input_format = src->src_format;
@@ -129,7 +129,7 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
unsigned input_offset = src->src_offset;
unsigned output_format;
switch (vinfo->emit[i]) {
switch (vinfo->attrib[i].emit) {
case EMIT_4F:
output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
emit_sz = 4 * sizeof(float);
@@ -133,7 +133,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
for (i = 0; i < vinfo->num_attribs; i++) {
unsigned emit_sz = 0;
switch (vinfo->emit[i]) {
switch (vinfo->attrib[i].emit) {
case EMIT_4F:
emit_sz = 4 * sizeof(float);
break;
@@ -161,8 +161,8 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
* numbers, not to positions in the hw vertex description --
* that's handled by the output_offset field.
*/
fse->key.element[i].out.format = vinfo->emit[i];
fse->key.element[i].out.vs_output = vinfo->src_index[i];
fse->key.element[i].out.format = vinfo->attrib[i].emit;
fse->key.element[i].out.vs_output = vinfo->attrib[i].src_index;
fse->key.element[i].out.offset = dst_offset;
dst_offset += emit_sz;
+3 -3
View File
@@ -49,7 +49,7 @@ draw_compute_vertex_size(struct vertex_info *vinfo)
vinfo->size = 0;
for (i = 0; i < vinfo->num_attribs; i++) {
switch (vinfo->emit[i]) {
switch (vinfo->attrib[i].emit) {
case EMIT_OMIT:
break;
case EMIT_4UB:
@@ -81,8 +81,8 @@ draw_dump_emitted_vertex(const struct vertex_info *vinfo, const uint8_t *data)
unsigned i, j;
for (i = 0; i < vinfo->num_attribs; i++) {
j = vinfo->src_index[i];
switch (vinfo->emit[i]) {
j = vinfo->attrib[i].src_index;
switch (vinfo->attrib[i].emit) {
case EMIT_OMIT:
debug_printf("EMIT_OMIT:");
break;
+37 -7
View File
@@ -75,12 +75,41 @@ struct vertex_info
{
uint num_attribs;
uint hwfmt[4]; /**< hardware format info for this format */
enum interp_mode interp_mode[PIPE_MAX_SHADER_INPUTS];
enum attrib_emit emit[PIPE_MAX_SHADER_INPUTS]; /**< EMIT_x */
uint src_index[PIPE_MAX_SHADER_INPUTS]; /**< map to post-xform attribs */
uint size; /**< total vertex size in dwords */
/* Keep this small and at the end of the struct to allow quick
* memcmp() comparisons.
*/
struct {
ubyte interp_mode:4; /**< INTERP_x */
ubyte emit:4; /**< EMIT_x */
ubyte src_index; /**< map to post-xform attribs */
} attrib[PIPE_MAX_SHADER_INPUTS];
};
static inline int
draw_vinfo_size( const struct vertex_info *a )
{
return ((const char *)&a->attrib[a->num_attribs] -
(const char *)a);
}
static inline int
draw_vinfo_compare( const struct vertex_info *a,
const struct vertex_info *b )
{
unsigned sizea = draw_vinfo_size( a );
return memcmp( a, b, sizea );
}
static inline void
draw_vinfo_copy( struct vertex_info *dst,
const struct vertex_info *src )
{
unsigned size = draw_vinfo_size( src );
memcpy( dst, src, size );
}
/**
@@ -91,14 +120,15 @@ struct vertex_info
*/
static INLINE uint
draw_emit_vertex_attr(struct vertex_info *vinfo,
enum attrib_emit emit, enum interp_mode interp,
enum attrib_emit emit,
enum interp_mode interp, /* only used by softpipe??? */
uint src_index)
{
const uint n = vinfo->num_attribs;
assert(n < PIPE_MAX_SHADER_INPUTS);
vinfo->emit[n] = emit;
vinfo->interp_mode[n] = interp;
vinfo->src_index[n] = src_index;
vinfo->attrib[n].emit = emit;
vinfo->attrib[n].interp_mode = interp;
vinfo->attrib[n].src_index = src_index;
vinfo->num_attribs++;
return n;
}
@@ -77,9 +77,9 @@ emit_hw_vertex( struct i915_context *i915,
assert(!i915->dirty);
for (i = 0; i < vinfo->num_attribs; i++) {
const uint j = vinfo->src_index[i];
const uint j = vinfo->attrib[i].src_index;
const float *attrib = vertex->data[j];
switch (vinfo->emit[i]) {
switch (vinfo->attrib[i].emit) {
case EMIT_1F:
OUT_BATCH( fui(attrib[0]) );
count++;
@@ -88,12 +88,12 @@ static void calculate_vertex_layout( struct i915_context *i915 )
if (needW) {
draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src);
vinfo.hwfmt[0] |= S4_VFMT_XYZW;
vinfo.emit[0] = EMIT_4F;
vinfo.attrib[0].emit = EMIT_4F;
}
else {
draw_emit_vertex_attr(&vinfo, EMIT_3F, INTERP_LINEAR, src);
vinfo.hwfmt[0] |= S4_VFMT_XYZ;
vinfo.emit[0] = EMIT_3F;
vinfo.attrib[0].emit = EMIT_3F;
}
/* hardware point size */
+6 -6
View File
@@ -773,10 +773,10 @@ static void setup_tri_coefficients( struct setup_context *setup )
/* setup interpolation for all the remaining attributes:
*/
for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
const uint vertSlot = vinfo->src_index[fragSlot];
const uint vertSlot = vinfo->attrib[fragSlot].src_index;
uint j;
switch (vinfo->interp_mode[fragSlot]) {
switch (vinfo->attrib[fragSlot].interp_mode) {
case INTERP_CONSTANT:
for (j = 0; j < NUM_CHANNELS; j++)
const_coeff(setup, &setup->coef[fragSlot], vertSlot, j);
@@ -1084,10 +1084,10 @@ setup_line_coefficients(struct setup_context *setup,
/* setup interpolation for all the remaining attributes:
*/
for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
const uint vertSlot = vinfo->src_index[fragSlot];
const uint vertSlot = vinfo->attrib[fragSlot].src_index;
uint j;
switch (vinfo->interp_mode[fragSlot]) {
switch (vinfo->attrib[fragSlot].interp_mode) {
case INTERP_CONSTANT:
for (j = 0; j < NUM_CHANNELS; j++)
const_coeff(setup, &setup->coef[fragSlot], vertSlot, j);
@@ -1331,10 +1331,10 @@ setup_point( struct setup_context *setup,
const_coeff(setup, &setup->posCoef, 0, 3);
for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) {
const uint vertSlot = vinfo->src_index[fragSlot];
const uint vertSlot = vinfo->attrib[fragSlot].src_index;
uint j;
switch (vinfo->interp_mode[fragSlot]) {
switch (vinfo->attrib[fragSlot].interp_mode) {
case INTERP_CONSTANT:
/* fall-through */
case INTERP_LINEAR: