pass vertex size to shaders so that callee can decide on the size
authorZack Rusin <zack@tungstengraphics.com>
Mon, 14 Apr 2008 16:27:24 +0000 (12:27 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Mon, 14 Apr 2008 16:27:24 +0000 (12:27 -0400)
of the vertices and not always have to use the maximum vertex
allocation size for them

src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c
src/gallium/auxiliary/draw/draw_vertex_cache.c
src/gallium/auxiliary/draw/draw_vertex_shader.c
src/gallium/auxiliary/draw/draw_vs_exec.c
src/gallium/auxiliary/draw/draw_vs_sse.c

index 3042d26..c8cb96c 100644 (file)
@@ -78,6 +78,7 @@ struct vertex_header {
 
 /* XXX This is too large */
 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
+#define MAX_VERTEX_ALLOCATION ((MAX_VERTEX_SIZE + 0x0f) & ~0x0f)
 
 
 
@@ -152,7 +153,8 @@ struct draw_vertex_shader {
                    struct draw_context *draw,
                    const unsigned *elts,
                    unsigned count,
-                   void *out );
+                   void *out,
+                   unsigned vertex_size);
 
 
    void (*delete)( struct draw_vertex_shader * );
@@ -450,9 +452,8 @@ dot4(const float *a, const float *b)
 }
 
 static INLINE struct vertex_header *
-draw_header_from_block(char *block, int num)
+draw_header_from_block(char *block, int size, int num)
 {
-   static const unsigned size = (MAX_VERTEX_SIZE + 0x0f) & ~0x0f;
    return (struct vertex_header*)(block + num * size);
 }
 
index 427128f..3fa6dcc 100644 (file)
@@ -157,7 +157,8 @@ static void fetch_pipeline_run( struct draw_pt_middle_end *middle,
    /* Shade
     */
    shader->prepare(shader, draw);
-   if (shader->run(shader, draw, fetch_elts, fetch_count, pipeline_verts)) {
+   if (shader->run(shader, draw, fetch_elts, fetch_count, pipeline_verts,
+                   fpme->pipeline_vertex_size)) {
       /* Run the pipeline */
       draw_pt_run_pipeline( fpme->draw,
                             fpme->prim,
index 9256dec..730c18b 100644 (file)
@@ -74,6 +74,7 @@ static struct vertex_header *get_vertex( struct draw_context *draw,
         /*debug_printf("HIT %d %d\n", slot, i);*/
         assert(draw->vcache.idx[slot].out < draw->vs.queue_nr);
         return draw_header_from_block(draw->vs.vertex_cache,
+                                       MAX_VERTEX_ALLOCATION,
                                        draw->vcache.idx[slot].out);
       }
 
@@ -101,7 +102,8 @@ static struct vertex_header *get_vertex( struct draw_context *draw,
        */
       assert(draw->vs.queue_nr < VS_QUEUE_LENGTH);
 
-      header = draw_header_from_block(draw->vs.vertex_cache, out);
+      header = draw_header_from_block(draw->vs.vertex_cache, MAX_VERTEX_ALLOCATION,
+                                      out);
       draw->vs.elts[out] = i;
       header->clipmask = 0;
       header->edgeflag = draw_get_edgeflag(draw, i);
@@ -113,6 +115,7 @@ static struct vertex_header *get_vertex( struct draw_context *draw,
        */
 
       return draw_header_from_block(draw->vs.vertex_cache,
+                                    MAX_VERTEX_ALLOCATION,
                                     draw->vcache.idx[slot].out);
    }
 }
@@ -148,7 +151,8 @@ void draw_vertex_cache_reset_vertex_ids( struct draw_context *draw )
 
    for (i = 0; i < draw->vs.post_nr; i++) {
       struct vertex_header * header =
-         draw_header_from_block(draw->vs.vertex_cache, i);
+         draw_header_from_block(draw->vs.vertex_cache,
+                                MAX_VERTEX_ALLOCATION, i);
       header->vertex_id = UNDEFINED_VERTEX_ID;
    }
 }
index 452d017..8572a6d 100644 (file)
@@ -60,7 +60,8 @@ draw_vertex_shader_queue_flush(struct draw_context *draw)
       unsigned elts[MAX_SHADER_VERTICES];
       int j, n = MIN2(MAX_SHADER_VERTICES, draw->vs.queue_nr  - i);
       struct vertex_header *dests =
-         draw_header_from_block(draw->vs.vertex_cache, i);
+         draw_header_from_block(draw->vs.vertex_cache,
+                                MAX_VERTEX_ALLOCATION, i);
 
       for (j = 0; j < n; j++) {
          elts[j] = draw->vs.elts[i + j];
@@ -73,7 +74,7 @@ draw_vertex_shader_queue_flush(struct draw_context *draw)
       assert(n > 0);
       assert(n <= MAX_SHADER_VERTICES);
 
-      shader->run(shader, draw, elts, n, dests);
+      shader->run(shader, draw, elts, n, dests, MAX_VERTEX_ALLOCATION);
    }
 
    draw->vs.post_nr = draw->vs.queue_nr;
index 27cf060..5c88c2e 100644 (file)
@@ -69,7 +69,8 @@ vs_exec_run( struct draw_vertex_shader *shader,
             struct draw_context *draw,
             const unsigned *elts, 
             unsigned count,
-            void *vOut )
+            void *vOut,
+             unsigned vertex_size)
 {
    struct tgsi_exec_machine *machine = &draw->machine;
    unsigned int i, j;
@@ -107,7 +108,7 @@ vs_exec_run( struct draw_vertex_shader *shader,
          unsigned slot;
          float x, y, z, w;
          struct vertex_header *out =
-            draw_header_from_block(vOut, i + j);
+            draw_header_from_block(vOut, vertex_size, i + j);
 
          /* Handle attr[0] (position) specially:
           *
index 92b9947..ee0a310 100644 (file)
@@ -83,7 +83,8 @@ vs_sse_run( struct draw_vertex_shader *base,
            struct draw_context *draw, 
            const unsigned *elts, 
            unsigned count,
-           void *vOut )
+           void *vOut,
+            unsigned vertex_size )
 {
    struct draw_sse_vertex_shader *shader = (struct draw_sse_vertex_shader *)base;
    struct tgsi_exec_machine *machine = &draw->machine;
@@ -136,7 +137,7 @@ vs_sse_run( struct draw_vertex_shader *base,
          unsigned slot;
          float x, y, z, w;
          struct vertex_header *out =
-            draw_header_from_block(vOut, i + j);
+            draw_header_from_block(vOut, vertex_size, i + j);
 
          x = out->clip[0] = machine->Outputs[0].xyzw[0].f[j];
          y = out->clip[1] = machine->Outputs[0].xyzw[1].f[j];