From 2197fac47cb1f87387820678357cc67c9a2536b9 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 19 Apr 2010 18:14:04 +0200 Subject: draw: Implement index bias. --- src/gallium/auxiliary/draw/draw_context.c | 4 ++ src/gallium/auxiliary/draw/draw_context.h | 2 + src/gallium/auxiliary/draw/draw_private.h | 1 + src/gallium/auxiliary/draw/draw_pt.c | 6 +- src/gallium/auxiliary/draw/draw_pt.h | 1 + .../auxiliary/draw/draw_pt_varray_tmp_linear.h | 3 + src/gallium/auxiliary/draw/draw_pt_vcache.c | 17 +++-- src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h | 77 +++++++++++----------- 8 files changed, 65 insertions(+), 46 deletions(-) (limited to 'src/gallium/auxiliary/draw') diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c index 99f4e6dd2a..b6c558ba9b 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -427,12 +427,14 @@ void draw_set_render( struct draw_context *draw, void draw_set_mapped_element_buffer_range( struct draw_context *draw, unsigned eltSize, + int eltBias, unsigned min_index, unsigned max_index, const void *elements ) { draw->pt.user.elts = elements; draw->pt.user.eltSize = eltSize; + draw->pt.user.eltBias = eltBias; draw->pt.user.min_index = min_index; draw->pt.user.max_index = max_index; } @@ -441,10 +443,12 @@ draw_set_mapped_element_buffer_range( struct draw_context *draw, void draw_set_mapped_element_buffer( struct draw_context *draw, unsigned eltSize, + int eltBias, const void *elements ) { draw->pt.user.elts = elements; draw->pt.user.eltSize = eltSize; + draw->pt.user.eltBias = eltBias; draw->pt.user.min_index = 0; draw->pt.user.max_index = 0xffffffff; } diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h index 1af4961716..cfa0ad88d0 100644 --- a/src/gallium/auxiliary/draw/draw_context.h +++ b/src/gallium/auxiliary/draw/draw_context.h @@ -139,12 +139,14 @@ void draw_set_vertex_elements(struct draw_context *draw, void draw_set_mapped_element_buffer_range( struct draw_context *draw, unsigned eltSize, + int eltBias, unsigned min_index, unsigned max_index, const void *elements ); void draw_set_mapped_element_buffer( struct draw_context *draw, unsigned eltSize, + int eltBias, const void *elements ); void draw_set_mapped_vertex_buffer(struct draw_context *draw, diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h index da64102d9d..33b0c196d4 100644 --- a/src/gallium/auxiliary/draw/draw_private.h +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -148,6 +148,7 @@ struct draw_context const void *elts; /** bytes per index (0, 1, 2 or 4) */ unsigned eltSize; + int eltBias; unsigned min_index; unsigned max_index; diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c index 43f6c5650a..aa1f7064a3 100644 --- a/src/gallium/auxiliary/draw/draw_pt.c +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -111,6 +111,7 @@ draw_pt_arrays(struct draw_context *draw, frontend->run(frontend, draw_pt_elt_func(draw), draw_pt_elt_ptr(draw, start), + draw->pt.user.eltBias, count); frontend->finish( frontend ); @@ -222,8 +223,11 @@ draw_print_arrays(struct draw_context *draw, uint prim, int start, uint count) break; default: assert(0); + return; } - debug_printf("Element[%u + %u] -> Vertex %u:\n", start, i, ii); + ii += draw->pt.user.eltBias; + debug_printf("Element[%u + %u] + %i -> Vertex %u:\n", start, i, + draw->pt.user.eltBias, ii); } else { /* non-indexed arrays */ diff --git a/src/gallium/auxiliary/draw/draw_pt.h b/src/gallium/auxiliary/draw/draw_pt.h index c2797a759e..3e3ea320cc 100644 --- a/src/gallium/auxiliary/draw/draw_pt.h +++ b/src/gallium/auxiliary/draw/draw_pt.h @@ -67,6 +67,7 @@ struct draw_pt_front_end { void (*run)( struct draw_pt_front_end *, pt_elt_func elt_func, const void *elt_ptr, + int elt_bias, unsigned count ); void (*finish)( struct draw_pt_front_end * ); diff --git a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h index f0aec5feba..a292346be9 100644 --- a/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h +++ b/src/gallium/auxiliary/draw/draw_pt_varray_tmp_linear.h @@ -6,6 +6,7 @@ static unsigned trim( unsigned count, unsigned first, unsigned incr ) static void FUNC(struct draw_pt_front_end *frontend, pt_elt_func get_elt, const void *elts, + int elt_bias, unsigned count) { struct varray_frontend *varray = (struct varray_frontend *)frontend; @@ -14,6 +15,8 @@ static void FUNC(struct draw_pt_front_end *frontend, unsigned j; unsigned first, incr; + assert(elt_bias == 0); + draw_pt_split_prim(varray->input_prim, &first, &incr); /* Sanitize primitive length: diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c index 757c487454..a513188b91 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache.c +++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c @@ -329,6 +329,7 @@ static INLINE void vcache_check_run( struct draw_pt_front_end *frontend, pt_elt_func get_elt, const void *elts, + int elt_bias, unsigned draw_count ) { struct vcache_frontend *vcache = (struct vcache_frontend *)frontend; @@ -362,8 +363,9 @@ vcache_check_run( struct draw_pt_front_end *frontend, } - if (min_index == 0 && - index_size == 2) + if (elt_bias <= 0 && + min_index == (unsigned)-elt_bias && + index_size == 2) { transformed_elts = (const ushort *)elts; } @@ -373,7 +375,8 @@ vcache_check_run( struct draw_pt_front_end *frontend, if (!storage) goto fail; - if (min_index == 0) { + if (elt_bias <= 0 && + min_index == (unsigned)-elt_bias) { switch(index_size) { case 1: translate_ubyte_elts( (const ubyte *)elts, @@ -404,21 +407,21 @@ vcache_check_run( struct draw_pt_front_end *frontend, case 1: rebase_ubyte_elts( (const ubyte *)elts, draw_count, - 0 - (int)min_index, + elt_bias - (int)min_index, storage ); break; case 2: rebase_ushort_elts( (const ushort *)elts, draw_count, - 0 - (int)min_index, + elt_bias - (int)min_index, storage ); break; case 4: rebase_uint_elts( (const uint *)elts, draw_count, - 0 - (int)min_index, + elt_bias - (int)min_index, storage ); break; @@ -447,7 +450,7 @@ vcache_check_run( struct draw_pt_front_end *frontend, fetch_count, draw_count); fail: - vcache_run( frontend, get_elt, elts, draw_count ); + vcache_run( frontend, get_elt, elts, elt_bias, draw_count ); } diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h index 7cba8547f1..eedd31b7f8 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h @@ -3,6 +3,7 @@ static void FUNC( struct draw_pt_front_end *frontend, pt_elt_func get_elt, const void *elts, + int elt_bias, unsigned count ) { struct vcache_frontend *vcache = (struct vcache_frontend *)frontend; @@ -20,7 +21,7 @@ static void FUNC( struct draw_pt_front_end *frontend, case PIPE_PRIM_POINTS: for (i = 0; i < count; i ++) { POINT( vcache, - get_elt(elts, i + 0) ); + get_elt(elts, i + 0) + elt_bias ); } break; @@ -28,8 +29,8 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 0; i+1 < count; i += 2) { LINE( vcache, DRAW_PIPE_RESET_STIPPLE, - get_elt(elts, i + 0), - get_elt(elts, i + 1)); + get_elt(elts, i + 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias); } break; @@ -40,14 +41,14 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 1; i < count; i++, flags = 0) { LINE( vcache, flags, - get_elt(elts, i - 1), - get_elt(elts, i )); + get_elt(elts, i - 1) + elt_bias, + get_elt(elts, i ) + elt_bias); } LINE( vcache, flags, - get_elt(elts, i - 1), - get_elt(elts, 0 )); + get_elt(elts, i - 1) + elt_bias, + get_elt(elts, 0 ) + elt_bias); } break; @@ -56,8 +57,8 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 1; i < count; i++, flags = 0) { LINE( vcache, flags, - get_elt(elts, i - 1), - get_elt(elts, i )); + get_elt(elts, i - 1) + elt_bias, + get_elt(elts, i ) + elt_bias); } break; @@ -65,9 +66,9 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 0; i+2 < count; i += 3) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2 )); + get_elt(elts, i + 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2 ) + elt_bias); } break; @@ -76,18 +77,18 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 0; i+2 < count; i++) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, i + 0), - get_elt(elts, i + 1 + (i&1)), - get_elt(elts, i + 2 - (i&1))); + get_elt(elts, i + 0) + elt_bias, + get_elt(elts, i + 1 + (i&1) + elt_bias), + get_elt(elts, i + 2 - (i&1) + elt_bias)); } } else { for (i = 0; i+2 < count; i++) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, i + 0 + (i&1)), - get_elt(elts, i + 1 - (i&1)), - get_elt(elts, i + 2 )); + get_elt(elts, i + 0 + (i&1) + elt_bias), + get_elt(elts, i + 1 - (i&1) + elt_bias), + get_elt(elts, i + 2 ) + elt_bias); } } break; @@ -98,18 +99,18 @@ static void FUNC( struct draw_pt_front_end *frontend, for (i = 0; i+2 < count; i++) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, i + 1), - get_elt(elts, i + 2), - get_elt(elts, 0 )); + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2) + elt_bias, + get_elt(elts, 0 ) + elt_bias); } } else { for (i = 0; i+2 < count; i++) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2 )); + get_elt(elts, 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2 ) + elt_bias); } } } @@ -119,20 +120,20 @@ static void FUNC( struct draw_pt_front_end *frontend, case PIPE_PRIM_QUADS: for (i = 0; i+3 < count; i += 4) { QUAD( vcache, - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2), - get_elt(elts, i + 3) ); + get_elt(elts, i + 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2) + elt_bias, + get_elt(elts, i + 3) + elt_bias ); } break; case PIPE_PRIM_QUAD_STRIP: for (i = 0; i+3 < count; i += 2) { QUAD( vcache, - get_elt(elts, i + 2), - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 3) ); + get_elt(elts, i + 2) + elt_bias, + get_elt(elts, i + 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 3) + elt_bias ); } break; @@ -165,16 +166,16 @@ static void FUNC( struct draw_pt_front_end *frontend, if (flatfirst) { TRIANGLE( vcache, flags, - get_elt(elts, 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2) ); + get_elt(elts, 0) + elt_bias, + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2) + elt_bias ); } else { TRIANGLE( vcache, flags, - get_elt(elts, i + 1), - get_elt(elts, i + 2), - get_elt(elts, 0)); + get_elt(elts, i + 1) + elt_bias, + get_elt(elts, i + 2) + elt_bias, + get_elt(elts, 0) + elt_bias); } } } -- cgit v1.2.3 From f1d3f42c47ee0d3c5f13f5b30e6b113d6b542f64 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 20 Apr 2010 10:19:42 +0200 Subject: draw: Fix typo resulting from bad regular expression in index bias addition. --- src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gallium/auxiliary/draw') diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h index eedd31b7f8..f7a63de3ba 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h @@ -78,16 +78,16 @@ static void FUNC( struct draw_pt_front_end *frontend, TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, get_elt(elts, i + 0) + elt_bias, - get_elt(elts, i + 1 + (i&1) + elt_bias), - get_elt(elts, i + 2 - (i&1) + elt_bias)); + get_elt(elts, i + 1 + (i&1)) + elt_bias, + get_elt(elts, i + 2 - (i&1)) + elt_bias); } } else { for (i = 0; i+2 < count; i++) { TRIANGLE( vcache, DRAW_PIPE_RESET_STIPPLE | DRAW_PIPE_EDGE_FLAG_ALL, - get_elt(elts, i + 0 + (i&1) + elt_bias), - get_elt(elts, i + 1 - (i&1) + elt_bias), + get_elt(elts, i + 0 + (i&1)) + elt_bias, + get_elt(elts, i + 1 - (i&1)) + elt_bias, get_elt(elts, i + 2 ) + elt_bias); } } -- cgit v1.2.3 From 4e8154e8666ec9375936bbe3fa2ca925ff9be5df Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 20 Apr 2010 10:32:06 +0200 Subject: draw: Fix cache elt_bias implementation. --- src/gallium/auxiliary/draw/draw_pt_vcache.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/gallium/auxiliary/draw') diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c index a513188b91..28dc514888 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache.c +++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c @@ -347,7 +347,7 @@ vcache_check_run( struct draw_pt_front_end *frontend, vcache->fetch_max, draw_count); - if (max_index >= DRAW_PIPE_MAX_VERTICES || + if (elt_bias + max_index >= DRAW_PIPE_MAX_VERTICES || fetch_count >= UNDEFINED_VERTEX_ID || fetch_count > draw_count) { if (0) debug_printf("fail\n"); @@ -363,6 +363,9 @@ vcache_check_run( struct draw_pt_front_end *frontend, } + assert((elt_bias >= 0 && min_index + elt_bias >= min_index) || + (elt_bias < 0 && min_index + elt_bias < min_index)); + if (elt_bias <= 0 && min_index == (unsigned)-elt_bias && index_size == 2) @@ -407,21 +410,21 @@ vcache_check_run( struct draw_pt_front_end *frontend, case 1: rebase_ubyte_elts( (const ubyte *)elts, draw_count, - elt_bias - (int)min_index, + -elt_bias - (int)min_index, storage ); break; case 2: rebase_ushort_elts( (const ushort *)elts, draw_count, - elt_bias - (int)min_index, + -elt_bias - (int)min_index, storage ); break; case 4: rebase_uint_elts( (const uint *)elts, draw_count, - elt_bias - (int)min_index, + -elt_bias - (int)min_index, storage ); break; @@ -436,7 +439,7 @@ vcache_check_run( struct draw_pt_front_end *frontend, if (fetch_count < UNDEFINED_VERTEX_ID) ok = vcache->middle->run_linear_elts( vcache->middle, - min_index, /* start */ + min_index + elt_bias, /* start */ fetch_count, transformed_elts, draw_count ); -- cgit v1.2.3 From 3dcdca433a5d6cde1c0b4d69ff0aa3a5eee26473 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Tue, 20 Apr 2010 11:06:05 +0200 Subject: draw: No need to rebase for elt_bias. As we are rebasing to min_index + elt_bias, and the vertex buffer has no elt_bias. I still don't know how to exercise this code. I hope this is now right. --- src/gallium/auxiliary/draw/draw_pt_vcache.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/gallium/auxiliary/draw') diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache.c b/src/gallium/auxiliary/draw/draw_pt_vcache.c index 28dc514888..37ffbac4f9 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache.c +++ b/src/gallium/auxiliary/draw/draw_pt_vcache.c @@ -366,8 +366,7 @@ vcache_check_run( struct draw_pt_front_end *frontend, assert((elt_bias >= 0 && min_index + elt_bias >= min_index) || (elt_bias < 0 && min_index + elt_bias < min_index)); - if (elt_bias <= 0 && - min_index == (unsigned)-elt_bias && + if (min_index == 0 && index_size == 2) { transformed_elts = (const ushort *)elts; @@ -378,8 +377,7 @@ vcache_check_run( struct draw_pt_front_end *frontend, if (!storage) goto fail; - if (elt_bias <= 0 && - min_index == (unsigned)-elt_bias) { + if (min_index == 0) { switch(index_size) { case 1: translate_ubyte_elts( (const ubyte *)elts, @@ -410,21 +408,21 @@ vcache_check_run( struct draw_pt_front_end *frontend, case 1: rebase_ubyte_elts( (const ubyte *)elts, draw_count, - -elt_bias - (int)min_index, + 0 - (int)min_index, storage ); break; case 2: rebase_ushort_elts( (const ushort *)elts, draw_count, - -elt_bias - (int)min_index, + 0 - (int)min_index, storage ); break; case 4: rebase_uint_elts( (const uint *)elts, draw_count, - -elt_bias - (int)min_index, + 0 - (int)min_index, storage ); break; -- cgit v1.2.3