Cell: added cell_batch_alloc_aligned()
authorBrian <brian.paul@tungstengraphics.com>
Tue, 5 Feb 2008 21:21:01 +0000 (14:21 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 5 Feb 2008 22:08:06 +0000 (15:08 -0700)
src/mesa/pipe/cell/ppu/cell_batch.c
src/mesa/pipe/cell/ppu/cell_batch.h

index 2fb4971..f45e5f2 100644 (file)
@@ -157,7 +157,7 @@ cell_batch_append(struct cell_context *cell, const void *data, uint bytes)
       size = 0;
    }
 
-   assert(size + bytes <= CELL_BUFFER_SIZE);
+   ASSERT(size + bytes <= CELL_BUFFER_SIZE);
 
    memcpy(cell->buffer[cell->cur_batch] + size, data, bytes);
 
@@ -168,13 +168,21 @@ cell_batch_append(struct cell_context *cell, const void *data, uint bytes)
 void *
 cell_batch_alloc(struct cell_context *cell, uint bytes)
 {
+   return cell_batch_alloc_aligned(cell, bytes, 1);
+}
+
+
+void *
+cell_batch_alloc_aligned(struct cell_context *cell, uint bytes,
+                         uint alignment)
+{
    void *pos;
-   uint size;
+   uint size, padbytes;
 
    ASSERT(bytes % 8 == 0);
    ASSERT(bytes <= CELL_BUFFER_SIZE);
-
-   assert(cell->cur_batch >= 0);
+   ASSERT(alignment > 0);
+   ASSERT(cell->cur_batch >= 0);
 
 #ifdef ASSERT
    {
@@ -188,12 +196,18 @@ cell_batch_alloc(struct cell_context *cell, uint bytes)
 
    size = cell->buffer_size[cell->cur_batch];
 
-   if (size + bytes > CELL_BUFFER_SIZE) {
+   padbytes = (alignment - (size % alignment)) % alignment;
+
+   if (padbytes + size + bytes > CELL_BUFFER_SIZE) {
       cell_batch_flush(cell);
       size = 0;
    }
+   else {
+      size += padbytes;
+   }
 
-   assert(size + bytes <= CELL_BUFFER_SIZE);
+   ASSERT(size % alignment == 0);
+   ASSERT(size + bytes <= CELL_BUFFER_SIZE);
 
    pos = (void *) (cell->buffer[cell->cur_batch] + size);
 
index f4f3731..a6eee0a 100644 (file)
@@ -50,5 +50,9 @@ cell_batch_append(struct cell_context *cell, const void *data, uint bytes);
 extern void *
 cell_batch_alloc(struct cell_context *cell, uint bytes);
 
+extern void *
+cell_batch_alloc_aligned(struct cell_context *cell, uint bytes,
+                         uint alignment);
+
 
 #endif /* CELL_BATCH_H */