gallium/auxiliary/indices: add start param

Add 'start' parameter to generator/translator.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Rob Clark 2013-10-25 15:22:06 -04:00
parent 5127436a4a
commit 28f3f8d413
7 changed files with 56 additions and 28 deletions

View file

@ -26,17 +26,19 @@
#include "u_indices_priv.h" #include "u_indices_priv.h"
static void translate_memcpy_ushort( const void *in, static void translate_memcpy_ushort( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ) void *out )
{ {
memcpy(out, in, nr*sizeof(short)); memcpy(out, &((short *)in)[start], nr*sizeof(short));
} }
static void translate_memcpy_uint( const void *in, static void translate_memcpy_uint( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ) void *out )
{ {
memcpy(out, in, nr*sizeof(int)); memcpy(out, &((int *)in)[start], nr*sizeof(int));
} }

View file

@ -31,11 +31,30 @@
#define PV_LAST 1 #define PV_LAST 1
#define PV_COUNT 2 #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, typedef void (*u_translate_func)( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ); 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 ); void *out );

View file

@ -153,6 +153,7 @@ def preamble(intype, outtype, inpv, outpv, prim):
print 'static void ' + name( intype, outtype, inpv, outpv, prim ) + '(' print 'static void ' + name( intype, outtype, inpv, outpv, prim ) + '('
if intype != GENERATE: if intype != GENERATE:
print ' const void * _in,' print ' const void * _in,'
print ' unsigned start,'
print ' unsigned nr,' print ' unsigned nr,'
print ' void *_out )' print ' void *_out )'
print '{' print '{'
@ -168,28 +169,28 @@ def postamble():
def points(intype, outtype, inpv, outpv): def points(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='points') 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' ); do_point( intype, outtype, 'out+i', 'i' );
print ' }' print ' }'
postamble() postamble()
def lines(intype, outtype, inpv, outpv): def lines(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='lines') 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 ); do_line( intype, outtype, 'out+i', 'i', 'i+1', inpv, outpv );
print ' }' print ' }'
postamble() postamble()
def linestrip(intype, outtype, inpv, outpv): def linestrip(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='linestrip') 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 ); do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print ' }' print ' }'
postamble() postamble()
def lineloop(intype, outtype, inpv, outpv): def lineloop(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='lineloop') 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 ); do_line( intype, outtype, 'out+j', 'i', 'i+1', inpv, outpv );
print ' }' print ' }'
do_line( intype, outtype, 'out+j', 'i', '0', inpv, outpv ); 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): def tris(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='tris') 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 ); do_tri( intype, outtype, 'out+i', 'i', 'i+1', 'i+2', inpv, outpv );
print ' }' print ' }'
postamble() postamble()
@ -205,7 +206,7 @@ def tris(intype, outtype, inpv, outpv):
def tristrip(intype, outtype, inpv, outpv): def tristrip(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='tristrip') 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: if inpv == FIRST:
do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv ); do_tri( intype, outtype, 'out+j', 'i', 'i+1+(i&1)', 'i+2-(i&1)', inpv, outpv );
else: else:
@ -216,7 +217,7 @@ def tristrip(intype, outtype, inpv, outpv):
def trifan(intype, outtype, inpv, outpv): def trifan(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='trifan') 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 ); do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv );
print ' }' print ' }'
postamble() postamble()
@ -225,7 +226,7 @@ def trifan(intype, outtype, inpv, outpv):
def polygon(intype, outtype, inpv, outpv): def polygon(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='polygon') 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: if inpv == FIRST:
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv ); do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2', inpv, outpv );
else: else:
@ -236,7 +237,7 @@ def polygon(intype, outtype, inpv, outpv):
def quads(intype, outtype, inpv, outpv): def quads(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='quads') 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 ); do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3', inpv, outpv );
print ' }' print ' }'
postamble() postamble()
@ -244,7 +245,7 @@ def quads(intype, outtype, inpv, outpv):
def quadstrip(intype, outtype, inpv, outpv): def quadstrip(intype, outtype, inpv, outpv):
preamble(intype, outtype, inpv, outpv, prim='quadstrip') 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 ); do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3', inpv, outpv );
print ' }' print ' }'
postamble() postamble()

View file

@ -127,6 +127,7 @@ def preamble(intype, outtype, prim):
print 'static void ' + name( intype, outtype, prim ) + '(' print 'static void ' + name( intype, outtype, prim ) + '('
if intype != GENERATE: if intype != GENERATE:
print ' const void * _in,' print ' const void * _in,'
print ' unsigned start,'
print ' unsigned nr,' print ' unsigned nr,'
print ' void *_out )' print ' void *_out )'
print '{' print '{'
@ -142,7 +143,7 @@ def postamble():
def tris(intype, outtype): def tris(intype, outtype):
preamble(intype, outtype, prim='tris') 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' ); do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
print ' }' print ' }'
postamble() postamble()
@ -150,7 +151,7 @@ def tris(intype, outtype):
def tristrip(intype, outtype): def tristrip(intype, outtype):
preamble(intype, outtype, prim='tristrip') 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)*/' ); do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
print ' }' print ' }'
postamble() postamble()
@ -158,7 +159,7 @@ def tristrip(intype, outtype):
def trifan(intype, outtype): def trifan(intype, outtype):
preamble(intype, outtype, prim='trifan') 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' ); do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
print ' }' print ' }'
postamble() postamble()
@ -167,7 +168,7 @@ def trifan(intype, outtype):
def polygon(intype, outtype): def polygon(intype, outtype):
preamble(intype, outtype, prim='polygon') 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)' ) line( intype, outtype, 'out+j', 'i', '(i+1)%(nr/2)' )
print ' }' print ' }'
postamble() postamble()
@ -175,7 +176,7 @@ def polygon(intype, outtype):
def quads(intype, outtype): def quads(intype, outtype):
preamble(intype, outtype, prim='quads') 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' ); do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
print ' }' print ' }'
postamble() postamble()
@ -183,7 +184,7 @@ def quads(intype, outtype):
def quadstrip(intype, outtype): def quadstrip(intype, outtype):
preamble(intype, outtype, prim='quadstrip') 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' ); do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
print ' }' print ' }'
postamble() postamble()

View file

@ -27,6 +27,7 @@
static void translate_ubyte_ushort( const void *in, static void translate_ubyte_ushort( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ) void *out )
{ {
@ -34,40 +35,44 @@ static void translate_ubyte_ushort( const void *in,
ushort *out_us = (ushort *)out; ushort *out_us = (ushort *)out;
unsigned i; unsigned i;
for (i = 0; i < nr; 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, static void translate_memcpy_ushort( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ) void *out )
{ {
memcpy(out, in, nr*sizeof(short)); memcpy(out, &((short *)in)[start], nr*sizeof(short));
} }
static void translate_memcpy_uint( const void *in, static void translate_memcpy_uint( const void *in,
unsigned start,
unsigned nr, unsigned nr,
void *out ) 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 ) void *out )
{ {
ushort *out_us = (ushort *)out; ushort *out_us = (ushort *)out;
unsigned i; unsigned i;
for (i = 0; i < nr; 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 ) void *out )
{ {
unsigned *out_ui = (unsigned *)out; unsigned *out_ui = (unsigned *)out;
unsigned i; unsigned i;
for (i = 0; i < nr; i++) for (i = 0; i < nr; i++)
out_ui[i] = i; out_ui[i] = i + start;
} }

View file

@ -58,7 +58,7 @@ generate_indices(struct svga_hwtnl *hwtnl,
if (dst_map == NULL) if (dst_map == NULL)
goto fail; goto fail;
generate(nr, dst_map); generate(0, nr, dst_map);
pipe_buffer_unmap(pipe, transfer); pipe_buffer_unmap(pipe, transfer);

View file

@ -61,7 +61,7 @@ translate_indices(struct svga_hwtnl *hwtnl, struct pipe_resource *src,
if (dst_map == NULL) if (dst_map == NULL)
goto fail; 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, src_transfer);
pipe_buffer_unmap(pipe, dst_transfer); pipe_buffer_unmap(pipe, dst_transfer);