draw: make sure constant buffer data is aligned before passing to aos.c
authorKeith Whitwell <keith@tungstengraphics.com>
Thu, 29 May 2008 11:38:49 +0000 (12:38 +0100)
committerKeith Whitwell <keith@tungstengraphics.com>
Thu, 29 May 2008 11:38:49 +0000 (12:38 +0100)
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_context.h
src/gallium/auxiliary/draw/draw_private.h
src/gallium/auxiliary/draw/draw_vs.c
src/gallium/auxiliary/draw/draw_vs_aos.c
src/gallium/drivers/i915simple/i915_context.c
src/gallium/drivers/softpipe/sp_draw_arrays.c
src/mesa/state_tracker/st_draw.c

index bcec85c2ef88fbb26bfb76591a6bec4d52346d43..2f263cf06a9866c3226002687239485f0c6b2ab8 100644 (file)
@@ -217,10 +217,11 @@ draw_set_mapped_vertex_buffer(struct draw_context *draw,
 
 void
 draw_set_mapped_constant_buffer(struct draw_context *draw,
-                                const void *buffer)
+                                const void *buffer, 
+                                unsigned size )
 {
    draw->pt.user.constants = buffer;
-   draw_vs_set_constants( draw, (const float (*)[4])buffer );
+   draw_vs_set_constants( draw, (const float (*)[4])buffer, size );
 }
 
 
index 8dd03cb79eff855ada8d538fb6918dfe83645baa..b8f2bfa3327b96d9220b6f2b9ce4e61c7234bb06 100644 (file)
@@ -133,7 +133,8 @@ void draw_set_mapped_vertex_buffer(struct draw_context *draw,
                                    unsigned attr, const void *buffer);
 
 void draw_set_mapped_constant_buffer(struct draw_context *draw,
-                                     const void *buffer);
+                                     const void *buffer,
+                                     unsigned size );
 
 void draw_set_edgeflags( struct draw_context *draw,
                          const unsigned *edgeflag );
index 40f1d978f211fd422368b8c11d31bec93635e500..88a7224b6230955009a940f3167b846ab392c39a 100644 (file)
@@ -190,6 +190,12 @@ struct draw_context
       struct aos_machine *aos_machine; 
 
 
+      const float (*aligned_constants)[4];
+
+      const float (*aligned_constant_storage)[4];
+      unsigned const_storage_size;
+
+
       struct translate *fetch;
       struct translate_cache *fetch_cache;
       struct translate *emit;
@@ -225,7 +231,8 @@ void draw_vs_set_viewport( struct draw_context *,
                            const struct pipe_viewport_state * );
 
 void draw_vs_set_constants( struct draw_context *,
-                            const float (*constants)[4] );
+                            const float (*constants)[4],
+                            unsigned size );
 
 
 
index a8b6d0c90d2500c3c8c0aecd9e980621ee374643..ce35112fc109e5ffb97e41e7e5815ea508abb091 100644 (file)
 
 
 void draw_vs_set_constants( struct draw_context *draw,
-                            const float (*constants)[4] )
+                            const float (*constants)[4],
+                            unsigned size )
 {
+   if (((unsigned)constants) & 0xf) {
+      if (size > draw->vs.const_storage_size) {
+         if (draw->vs.aligned_constant_storage)
+            align_free(draw->vs.aligned_constant_storage);
+         draw->vs.aligned_constant_storage = align_malloc( size, 16 );
+      }
+      memcpy( draw->vs.aligned_constant_storage,
+              constants, 
+              size );
+      constants = draw->vs.aligned_constant_storage;
+   }
+      
+   draw->vs.aligned_constants = constants;
    draw_vs_aos_machine_constants( draw->vs.aos_machine, constants );
 }
 
@@ -159,6 +173,9 @@ draw_vs_destroy( struct draw_context *draw )
    if (draw->vs.aos_machine)
       draw_vs_aos_machine_destroy(draw->vs.aos_machine);
 
+   if (draw->vs.aligned_constant_storage)
+      align_free(draw->vs.aligned_constant_storage);
+
    tgsi_exec_machine_free_data(&draw->vs.machine);
 
 }
index b5e4e1e7b1a37640b3a75378cb439b256c4805fd..55cabb6df9a9fdbb630e95912958fef578d1e979 100644 (file)
@@ -1957,7 +1957,7 @@ static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient,
    struct aos_machine *machine = vaos->draw->vs.aos_machine;
 
    machine->internal[IMM_PSIZE][0] = vaos->draw->rasterizer->point_size;
-   machine->constants = (const float (*)[4])vaos->draw->pt.user.constants;
+   machine->constants = vaos->draw->vs.aligned_constants;
    machine->immediates = vaos->base.vs->immediates;
    machine->attrib = vaos->attrib;
 
@@ -1976,7 +1976,7 @@ static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient,
    struct aos_machine *machine = vaos->draw->vs.aos_machine;
 
    machine->internal[IMM_PSIZE][0] = vaos->draw->rasterizer->point_size;
-   machine->constants = (const float (*)[4])vaos->draw->pt.user.constants;
+   machine->constants = vaos->draw->vs.aligned_constants;
    machine->immediates = vaos->base.vs->immediates;
    machine->attrib = vaos->attrib;
 
index 4bef21619c23650e2340d129e3afac4a4328756a..c609d16a5af95cb940d38aad938686fa6241ceae 100644 (file)
@@ -86,7 +86,9 @@ i915_draw_elements( struct pipe_context *pipe,
 
 
    draw_set_mapped_constant_buffer(draw,
-                                i915->current.constants[PIPE_SHADER_VERTEX]);
+                                   i915->current.constants[PIPE_SHADER_VERTEX],
+                                   ( i915->current.num_user_constants[PIPE_SHADER_VERTEX] * 
+                                     4 * sizeof(float) ));
 
    /* draw! */
    draw_arrays(i915->draw, prim, start, count);
index dbecf6865f498c669564b646ac1c55ea0624a81d..d4d5fa744fbdadb56aae2aabb882fc75d58d240b 100644 (file)
@@ -54,7 +54,8 @@ softpipe_map_constant_buffers(struct softpipe_context *sp)
    }
 
    draw_set_mapped_constant_buffer(sp->draw,
-                                   sp->mapped_constants[PIPE_SHADER_VERTEX]);
+                                   sp->mapped_constants[PIPE_SHADER_VERTEX],
+                                   sp->constants[i].size);
 }
 
 static void
@@ -68,7 +69,7 @@ softpipe_unmap_constant_buffers(struct softpipe_context *sp)
     */
    draw_flush(sp->draw);
 
-   draw_set_mapped_constant_buffer(sp->draw, NULL);
+   draw_set_mapped_constant_buffer(sp->draw, NULL, 0);
 
    for (i = 0; i < 2; i++) {
       if (sp->constants[i].size)
index 551860452ae3b108ef0acc1aa6c0c9ff4e6d4e02..5300848ef6a3b0ad890ff0ca67a721079d1332d7 100644 (file)
@@ -596,9 +596,10 @@ st_feedback_draw_vbo(GLcontext *ctx,
 
    /* map constant buffers */
    mapped_constants = pipe_buffer_map(pipe,
-                               st->state.constants[PIPE_SHADER_VERTEX].buffer,
-                               PIPE_BUFFER_USAGE_CPU_READ);
-   draw_set_mapped_constant_buffer(st->draw, mapped_constants);
+                                      st->state.constants[PIPE_SHADER_VERTEX].buffer,
+                                      PIPE_BUFFER_USAGE_CPU_READ);
+   draw_set_mapped_constant_buffer(st->draw, mapped_constants,
+                                   st->state.constants[PIPE_SHADER_VERTEX].buffer->size);
 
 
    /* draw here */