summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2008-02-05 14:21:01 -0700
committerBrian <brian.paul@tungstengraphics.com>2008-02-05 15:08:06 -0700
commitb0974420f4dab55d398f4015cf71a62fa643f713 (patch)
tree88bfd9ac5aee590a0258a13c17ecc7be945a0baa
parentc9f98142b6a47825c49aea72a79c1be62c2b7d89 (diff)
Cell: added cell_batch_alloc_aligned()
-rw-r--r--src/mesa/pipe/cell/ppu/cell_batch.c26
-rw-r--r--src/mesa/pipe/cell/ppu/cell_batch.h4
2 files changed, 24 insertions, 6 deletions
diff --git a/src/mesa/pipe/cell/ppu/cell_batch.c b/src/mesa/pipe/cell/ppu/cell_batch.c
index 2fb49711b2..f45e5f25b6 100644
--- a/src/mesa/pipe/cell/ppu/cell_batch.c
+++ b/src/mesa/pipe/cell/ppu/cell_batch.c
@@ -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);
diff --git a/src/mesa/pipe/cell/ppu/cell_batch.h b/src/mesa/pipe/cell/ppu/cell_batch.h
index f4f37314a4..a6eee0a8b1 100644
--- a/src/mesa/pipe/cell/ppu/cell_batch.h
+++ b/src/mesa/pipe/cell/ppu/cell_batch.h
@@ -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 */