draw: Pass-through pipe_buffer::max_index to translate.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 26 Apr 2010 13:55:16 +0000 (14:55 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 26 Apr 2010 15:05:06 +0000 (16:05 +0100)
max_index must be observed to prevent crashes due to bad index data.

I've been using this patch for some time without regressions.

Some places, where we use internal vertex buffer, it is not entirely
clear what max_index should be, so passing just ~0 to avoid regressions
for now.

src/gallium/auxiliary/draw/draw_pipe_vbuf.c
src/gallium/auxiliary/draw/draw_pt_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch.c
src/gallium/auxiliary/draw/draw_pt_fetch_emit.c
src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c
src/gallium/auxiliary/draw/draw_vs.h
src/gallium/auxiliary/draw/draw_vs_varient.c

index ee2b8116032ad1c498a57ac77a1ac645b0d408d8..abbf6247ab824897a222811af2632740ebe5f97b 100644 (file)
@@ -137,7 +137,7 @@ emit_vertex( struct vbuf_stage *vbuf,
        */
       /* Note: we really do want data[0] here, not data[pos]: 
        */
-      vbuf->translate->set_buffer(vbuf->translate, 0, vertex->data[0], 0);
+      vbuf->translate->set_buffer(vbuf->translate, 0, vertex->data[0], 0, ~0);
       vbuf->translate->run(vbuf->translate, 0, 1, 0, vbuf->vertex_ptr);
 
       if (0) draw_dump_emitted_vertex(vbuf->vinfo, (uint8_t *)vbuf->vertex_ptr);
@@ -271,7 +271,7 @@ vbuf_start_prim( struct vbuf_stage *vbuf, uint prim )
       translate_key_sanitize(&hw_key);
       vbuf->translate = translate_cache_find(vbuf->cache, &hw_key);
 
-      vbuf->translate->set_buffer(vbuf->translate, 1, &vbuf->point_size, 0);
+      vbuf->translate->set_buffer(vbuf->translate, 1, &vbuf->point_size, 0, ~0);
    }
 
    vbuf->point_size = vbuf->stage.draw->rasterizer->point_size;
index a7917f54b048257be04dcbe1aa6cda69d6bcff2d..ad48fa39a4f0ad751058b9b91f07e50bc07cb080 100644 (file)
@@ -171,12 +171,14 @@ void draw_pt_emit( struct pt_emit *emit,
    translate->set_buffer(translate, 
                         0, 
                         vertex_data,
-                        stride );
+                        stride,
+                        ~0);
 
    translate->set_buffer(translate, 
                         1, 
                         &draw->rasterizer->point_size,
-                        0);
+                        0,
+                        ~0);
 
    translate->run( translate,
                   0, 
@@ -232,11 +234,11 @@ void draw_pt_emit_linear(struct pt_emit *emit,
       goto fail;
 
    translate->set_buffer(translate, 0,
-                        vertex_data, stride);
+                        vertex_data, stride, count - 1);
 
    translate->set_buffer(translate, 1,
                         &draw->rasterizer->point_size,
-                        0);
+                        0, ~0);
 
    translate->run(translate,
                   0,
index 252be5053e4c75bdb260ad43d128326761f00d7b..a1347221b5db6a53f11f06802a4653f8701e827b 100644 (file)
@@ -149,7 +149,8 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch,
         fetch->translate->set_buffer(fetch->translate,
                                      draw->pt.nr_vertex_buffers,
                                      &vh,
-                                     0);
+                                     0,
+                                     ~0);
       }
    }
 
@@ -172,7 +173,8 @@ void draw_pt_fetch_run( struct pt_fetch *fetch,
                            i, 
                            ((char *)draw->pt.user.vbuffer[i] + 
                             draw->pt.vertex_buffer[i].buffer_offset),
-                           draw->pt.vertex_buffer[i].stride );
+                           draw->pt.vertex_buffer[i].stride,
+                           draw->pt.vertex_buffer[i].max_index);
    }
 
    translate->run_elts( translate,
@@ -198,7 +200,8 @@ void draw_pt_fetch_run_linear( struct pt_fetch *fetch,
                            i,
                            ((char *)draw->pt.user.vbuffer[i] +
                             draw->pt.vertex_buffer[i].buffer_offset),
-                           draw->pt.vertex_buffer[i].stride );
+                           draw->pt.vertex_buffer[i].stride,
+                           draw->pt.vertex_buffer[i].max_index);
    }
 
    translate->run( translate,
index 1994ddf2bcc45c0e7d81fdcab75e3d9d02b04dea..d7735bf1ac9dcf0642eb08cd473bae520439205b 100644 (file)
@@ -168,7 +168,8 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
       feme->translate->set_buffer(feme->translate, 
                                  draw->pt.nr_vertex_buffers, 
                                  &feme->point_size,
-                                 0);
+                                 0,
+                                 ~0);
    }
    
    feme->point_size = draw->rasterizer->point_size;
@@ -178,7 +179,8 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle,
                                   i, 
                                   ((char *)draw->pt.user.vbuffer[i] + 
                                    draw->pt.vertex_buffer[i].buffer_offset),
-                                  draw->pt.vertex_buffer[i].stride );
+                                  draw->pt.vertex_buffer[i].stride,
+                                  draw->pt.vertex_buffer[i].max_index);
    }
 
    *max_vertices = (draw->render->max_vertex_buffer_bytes / 
index 389e2b105e56aa962c4730d995f48f49c94e232e..cbb5b6c960535e6320b61a67f003a1035b61a120 100644 (file)
@@ -167,7 +167,8 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
                                i, 
                                ((const ubyte *) draw->pt.user.vbuffer[i] + 
                                 draw->pt.vertex_buffer[i].buffer_offset),
-                              draw->pt.vertex_buffer[i].stride );
+                              draw->pt.vertex_buffer[i].stride,
+                              draw->pt.vertex_buffer[i].max_index );
    }
 
    *max_vertices = (draw->render->max_vertex_buffer_bytes / 
index f49332352b0ef63478d1b5e2f30300800a7f87f0..efead42335fc6c7bc8a98a42f48cf82697718c9a 100644 (file)
@@ -80,7 +80,8 @@ struct draw_vs_varient {
    void (*set_buffer)( struct draw_vs_varient *,
                       unsigned i,
                       const void *ptr,
-                      unsigned stride );
+                      unsigned stride,
+                      unsigned max_stride );
 
    void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader,
                                   unsigned start,
index 5ed706cb4ff01d15079ab958301b2a3ddb579382..0abd827b61586e5e80401bfa1b60ca8a7a1ae08f 100644 (file)
@@ -66,14 +66,16 @@ struct draw_vs_varient_generic {
 static void vsvg_set_buffer( struct draw_vs_varient *varient,
                              unsigned buffer,
                              const void *ptr,
-                             unsigned stride )
+                             unsigned stride,
+                             unsigned max_index )
 {
    struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
 
    vsvg->fetch->set_buffer(vsvg->fetch, 
                            buffer, 
                            ptr, 
-                           stride);
+                           stride,
+                           max_index );
 }
 
 
@@ -172,12 +174,14 @@ static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient,
    vsvg->emit->set_buffer( vsvg->emit,
                            0, 
                            temp_buffer,
-                           temp_vertex_stride );
+                           temp_vertex_stride,
+                           ~0 );
 
    vsvg->emit->set_buffer( vsvg->emit, 
                            1,
                            &vsvg->draw->rasterizer->point_size,
-                           0);
+                           0,
+                           ~0 );
 
    vsvg->emit->run( vsvg->emit,
                     0, count,
@@ -232,12 +236,14 @@ static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient,
    vsvg->emit->set_buffer( vsvg->emit,
                            0, 
                            temp_buffer,
-                           temp_vertex_stride );
+                           temp_vertex_stride,
+                           ~0 );
    
    vsvg->emit->set_buffer( vsvg->emit, 
                            1,
                            &vsvg->draw->rasterizer->point_size,
-                           0);
+                           0,
+                           ~0 );
    
    vsvg->emit->run( vsvg->emit,
                     0, count,