From: Rob Clark Date: Fri, 25 Oct 2013 19:22:06 +0000 (-0400) Subject: gallium/auxiliary/indices: add start param X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=28f3f8d413f6bf29f051d54479d9ae90bb16a55e;p=mesa.git gallium/auxiliary/indices: add start param Add 'start' parameter to generator/translator. Signed-off-by: Rob Clark Reviewed-by: Brian Paul --- diff --git a/src/gallium/auxiliary/indices/u_indices.c b/src/gallium/auxiliary/indices/u_indices.c index 72c46f7d230..30b54b9fb6a 100644 --- a/src/gallium/auxiliary/indices/u_indices.c +++ b/src/gallium/auxiliary/indices/u_indices.c @@ -26,17 +26,19 @@ #include "u_indices_priv.h" static void translate_memcpy_ushort( const void *in, + unsigned start, unsigned nr, void *out ) { - memcpy(out, in, nr*sizeof(short)); + memcpy(out, &((short *)in)[start], nr*sizeof(short)); } static void translate_memcpy_uint( const void *in, + unsigned start, unsigned nr, void *out ) { - memcpy(out, in, nr*sizeof(int)); + memcpy(out, &((int *)in)[start], nr*sizeof(int)); } diff --git a/src/gallium/auxiliary/indices/u_indices.h b/src/gallium/auxiliary/indices/u_indices.h index be522c67252..331d0fd0042 100644 --- a/src/gallium/auxiliary/indices/u_indices.h +++ b/src/gallium/auxiliary/indices/u_indices.h @@ -31,11 +31,30 @@ #define PV_LAST 1 #define PV_COUNT 2 +/** + * Index translator function (for glDrawElements() case) + * + * \param in the input index buffer + * \param start the index of the first vertex (pipe_draw_info::start) + * \param nr the number of vertices (pipe_draw_info::count) + * \param out output buffer big enough or nr vertices (of + * @out_index_size bytes each) + */ typedef void (*u_translate_func)( const void *in, + unsigned start, unsigned nr, void *out ); -typedef void (*u_generate_func)( unsigned nr, +/** + * Index generator function (for glDrawArrays() case) + * + * \param start the index of the first vertex (pipe_draw_info::start) + * \param nr the number of vertices (pipe_draw_info::count) + * \param out output buffer big enough or nr vertices (of + * @out_index_size bytes each) + */ +typedef void (*u_generate_func)( unsigned start, + unsigned nr, void *out ); diff --git a/src/gallium/auxiliary/indices/u_indices_gen.py b/src/gallium/auxiliary/indices/u_indices_gen.py index af63d099302..2714df87cfb 100644 --- a/src/gallium/auxiliary/indices/u_indices_gen.py +++ b/src/gallium/auxiliary/indices/u_indices_gen.py @@ -153,6 +153,7 @@ def preamble(intype, outtype, inpv, outpv, prim): print 'static void ' + name( intype, outtype, inpv, outpv, prim ) + '(' if intype != GENERATE: print ' const void * _in,' + print ' unsigned start,' print ' unsigned nr,' print ' void *_out )' print '{' @@ -168,28 +169,28 @@ def postamble(): def points(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='points') - print ' for (i = 0; i < nr; i++) { ' + print ' for (i = start; i < (nr+start); i++) { ' do_point( intype, outtype, 'out+i', 'i' ); print ' }' postamble() def lines(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='lines') - print ' for (i = 0; i < nr; i+=2) { ' + print ' for (i = start; i < (nr+start); i+=2) { ' do_line( intype, outtype, 'out+i', 'i', 'i+1', inpv, outpv ); print ' }' postamble() def linestrip(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='linestrip') - print ' for (j = i = 0; j < nr; j+=2, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=2, i++) { ' do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv ); print ' }' postamble() def lineloop(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='lineloop') - print ' for (j = i = 0; j < nr - 2; j+=2, i++) { ' + print ' for (i = start, j = 0; j < nr - 2; j+=2, i++) { ' do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv ); print ' }' do_line( intype, outtype, 'out+j', 'i', '0', inpv, outpv ); @@ -197,7 +198,7 @@ def lineloop(intype, outtype, inpv, outpv): def tris(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='tris') - print ' for (i = 0; i < nr; i+=3) { ' + print ' for (i = start; i < (nr+start); i+=3) { ' do_tri( intype, outtype, 'out+i', 'i', 'i+1', 'i+2', inpv, outpv ); print ' }' postamble() @@ -205,7 +206,7 @@ def tris(intype, outtype, inpv, outpv): def tristrip(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='tristrip') - print ' for (j = i = 0; j < nr; j+=3, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=3, i++) { ' if inpv == FIRST: do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv ); else: @@ -216,7 +217,7 @@ def tristrip(intype, outtype, inpv, outpv): def trifan(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='trifan') - print ' for (j = i = 0; j < nr; j+=3, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=3, i++) { ' do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv ); print ' }' postamble() @@ -225,7 +226,7 @@ def trifan(intype, outtype, inpv, outpv): def polygon(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='polygon') - print ' for (j = i = 0; j < nr; j+=3, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=3, i++) { ' if inpv == FIRST: do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv ); else: @@ -236,7 +237,7 @@ def polygon(intype, outtype, inpv, outpv): def quads(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='quads') - print ' for (j = i = 0; j < nr; j+=6, i+=4) { ' + print ' for (i = start, j = 0; j < nr; j+=6, i+=4) { ' do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv ); print ' }' postamble() @@ -244,7 +245,7 @@ def quads(intype, outtype, inpv, outpv): def quadstrip(intype, outtype, inpv, outpv): preamble(intype, outtype, inpv, outpv, prim='quadstrip') - print ' for (j = i = 0; j < nr; j+=6, i+=2) { ' + print ' for (i = start, j = 0; j < nr; j+=6, i+=2) { ' do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv ); print ' }' postamble() diff --git a/src/gallium/auxiliary/indices/u_unfilled_gen.py b/src/gallium/auxiliary/indices/u_unfilled_gen.py index 085c47a114a..88649724521 100644 --- a/src/gallium/auxiliary/indices/u_unfilled_gen.py +++ b/src/gallium/auxiliary/indices/u_unfilled_gen.py @@ -127,6 +127,7 @@ def preamble(intype, outtype, prim): print 'static void ' + name( intype, outtype, prim ) + '(' if intype != GENERATE: print ' const void * _in,' + print ' unsigned start,' print ' unsigned nr,' print ' void *_out )' print '{' @@ -142,7 +143,7 @@ def postamble(): def tris(intype, outtype): preamble(intype, outtype, prim='tris') - print ' for (j = i = 0; j < nr; j+=6, i+=3) { ' + print ' for (i = start, j = 0; j < nr; j+=6, i+=3) { ' do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' ); print ' }' postamble() @@ -150,7 +151,7 @@ def tris(intype, outtype): def tristrip(intype, outtype): preamble(intype, outtype, prim='tristrip') - print ' for (j = i = 0; j < nr; j+=6, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=6, i++) { ' do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' ); print ' }' postamble() @@ -158,7 +159,7 @@ def tristrip(intype, outtype): def trifan(intype, outtype): preamble(intype, outtype, prim='trifan') - print ' for (j = i = 0; j < nr; j+=6, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=6, i++) { ' do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' ); print ' }' postamble() @@ -167,7 +168,7 @@ def trifan(intype, outtype): def polygon(intype, outtype): preamble(intype, outtype, prim='polygon') - print ' for (j = i = 0; j < nr; j+=2, i++) { ' + print ' for (i = start, j = 0; j < nr; j+=2, i++) { ' line( intype, outtype, 'out+j', 'i', '(i+1)%(nr/2)' ) print ' }' postamble() @@ -175,7 +176,7 @@ def polygon(intype, outtype): def quads(intype, outtype): preamble(intype, outtype, prim='quads') - print ' for (j = i = 0; j < nr; j+=8, i+=4) { ' + print ' for (i = start, j = 0; j < nr; j+=8, i+=4) { ' do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' ); print ' }' postamble() @@ -183,7 +184,7 @@ def quads(intype, outtype): def quadstrip(intype, outtype): preamble(intype, outtype, prim='quadstrip') - print ' for (j = i = 0; j < nr; j+=8, i+=2) { ' + print ' for (i = start, j = 0; j < nr; j+=8, i+=2) { ' do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' ); print ' }' postamble() diff --git a/src/gallium/auxiliary/indices/u_unfilled_indices.c b/src/gallium/auxiliary/indices/u_unfilled_indices.c index 25c61d97bdf..7a74c39135e 100644 --- a/src/gallium/auxiliary/indices/u_unfilled_indices.c +++ b/src/gallium/auxiliary/indices/u_unfilled_indices.c @@ -27,6 +27,7 @@ static void translate_ubyte_ushort( const void *in, + unsigned start, unsigned nr, void *out ) { @@ -34,40 +35,44 @@ static void translate_ubyte_ushort( const void *in, ushort *out_us = (ushort *)out; unsigned i; for (i = 0; i < nr; i++) - out_us[i] = (ushort) in_ub[i]; + out_us[i] = (ushort) in_ub[i+start]; } static void translate_memcpy_ushort( const void *in, + unsigned start, unsigned nr, void *out ) { - memcpy(out, in, nr*sizeof(short)); + memcpy(out, &((short *)in)[start], nr*sizeof(short)); } static void translate_memcpy_uint( const void *in, + unsigned start, unsigned nr, void *out ) { - memcpy(out, in, nr*sizeof(int)); + memcpy(out, &((int *)in)[start], nr*sizeof(int)); } -static void generate_linear_ushort( unsigned nr, +static void generate_linear_ushort( unsigned start, + unsigned nr, void *out ) { ushort *out_us = (ushort *)out; unsigned i; for (i = 0; i < nr; i++) - out_us[i] = (ushort) i; + out_us[i] = (ushort)(i + start); } -static void generate_linear_uint( unsigned nr, +static void generate_linear_uint( unsigned start, + unsigned nr, void *out ) { unsigned *out_ui = (unsigned *)out; unsigned i; for (i = 0; i < nr; i++) - out_ui[i] = i; + out_ui[i] = i + start; } diff --git a/src/gallium/drivers/svga/svga_draw_arrays.c b/src/gallium/drivers/svga/svga_draw_arrays.c index 5f03483390f..89a5dc1da77 100644 --- a/src/gallium/drivers/svga/svga_draw_arrays.c +++ b/src/gallium/drivers/svga/svga_draw_arrays.c @@ -58,7 +58,7 @@ generate_indices(struct svga_hwtnl *hwtnl, if (dst_map == NULL) goto fail; - generate(nr, dst_map); + generate(0, nr, dst_map); pipe_buffer_unmap(pipe, transfer); diff --git a/src/gallium/drivers/svga/svga_draw_elements.c b/src/gallium/drivers/svga/svga_draw_elements.c index b68dad0c3bb..fb5f1c91b29 100644 --- a/src/gallium/drivers/svga/svga_draw_elements.c +++ b/src/gallium/drivers/svga/svga_draw_elements.c @@ -61,7 +61,7 @@ translate_indices(struct svga_hwtnl *hwtnl, struct pipe_resource *src, if (dst_map == NULL) goto fail; - translate((const char *) src_map + offset, nr, dst_map); + translate((const char *) src_map + offset, 0, nr, dst_map); pipe_buffer_unmap(pipe, src_transfer); pipe_buffer_unmap(pipe, dst_transfer);