On 10/25/2013 01:53 PM, Rob Clark wrote:
From: Rob Clark <[email protected]>

Add 'start' parameter to generator/translator.

Signed-off-by: Rob Clark <[email protected]>
---
  src/gallium/auxiliary/indices/u_indices.c          |  6 ++++--
  src/gallium/auxiliary/indices/u_indices.h          |  4 +++-
  src/gallium/auxiliary/indices/u_indices_gen.py     | 21 +++++++++++----------
  src/gallium/auxiliary/indices/u_unfilled_gen.py    | 13 +++++++------
  src/gallium/auxiliary/indices/u_unfilled_indices.c | 19 ++++++++++++-------
  src/gallium/drivers/svga/svga_draw_arrays.c        |  3 ++-
  src/gallium/drivers/svga/svga_draw_elements.c      |  1 +
  7 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/src/gallium/auxiliary/indices/u_indices.c 
b/src/gallium/auxiliary/indices/u_indices.c
index 72c46f7..30b54b9 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 be522c6..922bfe6 100644
--- a/src/gallium/auxiliary/indices/u_indices.h
+++ b/src/gallium/auxiliary/indices/u_indices.h
@@ -32,10 +32,12 @@
  #define PV_COUNT      2

  typedef void (*u_translate_func)( const void *in,
+                                  unsigned start,
                                    unsigned nr,
                                    void *out );

-typedef void (*u_generate_func)( unsigned nr,
+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 af63d09..2714df8 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 085c47a..8864972 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 25c61d9..7a74c39 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 7adefd0..c62c767 100644
--- a/src/gallium/drivers/svga/svga_draw_arrays.c
+++ b/src/gallium/drivers/svga/svga_draw_arrays.c
@@ -61,7 +61,8 @@ static enum pipe_error generate_indices( struct svga_hwtnl 
*hwtnl,
     if (dst_map == NULL)
        goto fail;

-   generate( nr,
+   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 c52ca2d..ff858cf 100644
--- a/src/gallium/drivers/svga/svga_draw_elements.c
+++ b/src/gallium/drivers/svga/svga_draw_elements.c
@@ -68,6 +68,7 @@ translate_indices( struct svga_hwtnl *hwtnl,
        goto fail;

     translate( (const char *)src_map + offset,
+              0,
                nr,
                dst_map );



I know all this code is light on comments, but maybe you could add a comment somewhere describing 'start'.

Otherwise, Reviewed-by: Brian Paul <[email protected]>

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to