summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2008-01-27 12:01:47 -0700
committerBrian <brian.paul@tungstengraphics.com>2008-01-28 11:31:57 -0700
commit2194675196260c0a5d44242d698b85c86f84074b (patch)
tree3f7a068a9b8de1bdeff24144f184eb1ca7813ab9
parent16ed55c6412d2bdc5bff78e99114490223fb4afe (diff)
Cell: generalize the batch buffer code for vertex buffers...
-rw-r--r--src/mesa/pipe/cell/common.h8
-rw-r--r--src/mesa/pipe/cell/ppu/cell_batch.c84
-rw-r--r--src/mesa/pipe/cell/ppu/cell_batch.h3
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.c5
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.h10
-rw-r--r--src/mesa/pipe/cell/ppu/cell_spu.c4
-rw-r--r--src/mesa/pipe/cell/spu/spu_main.c22
7 files changed, 79 insertions, 57 deletions
diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h
index 0b63ed39be..ce9c381907 100644
--- a/src/mesa/pipe/cell/common.h
+++ b/src/mesa/pipe/cell/common.h
@@ -81,8 +81,8 @@
#define CELL_CMD_STATE_VERTEX_INFO 13
-#define CELL_NUM_BATCH_BUFFERS 3
-#define CELL_BATCH_BUFFER_SIZE 1024 /**< 16KB would be the max */
+#define CELL_NUM_BUFFERS 4
+#define CELL_BUFFER_SIZE (4*1024) /**< 16KB would be the max */
#define CELL_BUFFER_STATUS_FREE 10
#define CELL_BUFFER_STATUS_USED 20
@@ -147,7 +147,9 @@ struct cell_init_info
unsigned id;
unsigned num_spus;
struct cell_command *cmd;
- ubyte *batch_buffers[CELL_NUM_BATCH_BUFFERS];
+
+ /** Buffers for command batches, vertex/index data */
+ ubyte *buffers[CELL_NUM_BUFFERS];
uint *buffer_status; /**< points at cell_context->buffer_status */
} ALIGN16_ATTRIB;
diff --git a/src/mesa/pipe/cell/ppu/cell_batch.c b/src/mesa/pipe/cell/ppu/cell_batch.c
index c894ef8608..178caa74e1 100644
--- a/src/mesa/pipe/cell/ppu/cell_batch.c
+++ b/src/mesa/pipe/cell/ppu/cell_batch.c
@@ -31,12 +31,46 @@
#include "cell_spu.h"
+
+uint
+cell_get_empty_buffer(struct cell_context *cell)
+{
+ uint buf = 0;
+
+ /* Find a buffer that's marked as free by all SPUs */
+ while (1) {
+ uint spu, num_free = 0;
+
+ for (spu = 0; spu < cell->num_spus; spu++) {
+ if (cell->buffer_status[spu][buf][0] == CELL_BUFFER_STATUS_FREE) {
+ num_free++;
+
+ if (num_free == cell->num_spus) {
+ /* found a free buffer, now mark status as used */
+ for (spu = 0; spu < cell->num_spus; spu++) {
+ cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED;
+ }
+ return buf;
+ }
+ }
+ else {
+ break;
+ }
+ }
+
+ /* try next buf */
+ buf = (buf + 1) % CELL_NUM_BUFFERS;
+ }
+}
+
+
+
void
cell_batch_flush(struct cell_context *cell)
{
static boolean flushing = FALSE;
uint batch = cell->cur_batch;
- const uint size = cell->batch_buffer_size[batch];
+ const uint size = cell->buffer_size[batch];
uint spu, cmd_word;
assert(!flushing);
@@ -46,7 +80,7 @@ cell_batch_flush(struct cell_context *cell)
flushing = TRUE;
- assert(batch < CELL_NUM_BATCH_BUFFERS);
+ assert(batch < CELL_NUM_BUFFERS);
/*
printf("cell_batch_dispatch: buf %u at %p, size %u\n",
@@ -68,28 +102,9 @@ cell_batch_flush(struct cell_context *cell)
* array indicating that the PPU can re-use the buffer.
*/
+ batch = cell_get_empty_buffer(cell);
- /* Find a buffer that's marked as free by all SPUs */
- while (1) {
- uint num_free = 0;
-
- batch = (batch + 1) % CELL_NUM_BATCH_BUFFERS;
-
- for (spu = 0; spu < cell->num_spus; spu++) {
- if (cell->buffer_status[spu][batch][0] == CELL_BUFFER_STATUS_FREE)
- num_free++;
- }
-
- if (num_free == cell->num_spus) {
- /* found a free buffer, now mark status as used */
- for (spu = 0; spu < cell->num_spus; spu++) {
- cell->buffer_status[spu][batch][0] = CELL_BUFFER_STATUS_USED;
- }
- break;
- }
- }
-
- cell->batch_buffer_size[batch] = 0; /* empty */
+ cell->buffer_size[batch] = 0; /* empty */
cell->cur_batch = batch;
flushing = FALSE;
@@ -99,8 +114,7 @@ cell_batch_flush(struct cell_context *cell)
uint
cell_batch_free_space(const struct cell_context *cell)
{
- uint free = CELL_BATCH_BUFFER_SIZE
- - cell->batch_buffer_size[cell->cur_batch];
+ uint free = CELL_BUFFER_SIZE - cell->buffer_size[cell->cur_batch];
return free;
}
@@ -117,18 +131,18 @@ cell_batch_append(struct cell_context *cell, const void *cmd, uint length)
assert(length % 4 == 0);
assert(cell->cur_batch >= 0);
- size = cell->batch_buffer_size[cell->cur_batch];
+ size = cell->buffer_size[cell->cur_batch];
- if (size + length > CELL_BATCH_BUFFER_SIZE) {
+ if (size + length > CELL_BUFFER_SIZE) {
cell_batch_flush(cell);
size = 0;
}
- assert(size + length <= CELL_BATCH_BUFFER_SIZE);
+ assert(size + length <= CELL_BUFFER_SIZE);
- memcpy(cell->batch_buffer[cell->cur_batch] + size, cmd, length);
+ memcpy(cell->buffer[cell->cur_batch] + size, cmd, length);
- cell->batch_buffer_size[cell->cur_batch] = size + length;
+ cell->buffer_size[cell->cur_batch] = size + length;
}
@@ -142,18 +156,18 @@ cell_batch_alloc(struct cell_context *cell, uint bytes)
assert(cell->cur_batch >= 0);
- size = cell->batch_buffer_size[cell->cur_batch];
+ size = cell->buffer_size[cell->cur_batch];
- if (size + bytes > CELL_BATCH_BUFFER_SIZE) {
+ if (size + bytes > CELL_BUFFER_SIZE) {
cell_batch_flush(cell);
size = 0;
}
- assert(size + bytes <= CELL_BATCH_BUFFER_SIZE);
+ assert(size + bytes <= CELL_BUFFER_SIZE);
- pos = (void *) (cell->batch_buffer[cell->cur_batch] + size);
+ pos = (void *) (cell->buffer[cell->cur_batch] + size);
- cell->batch_buffer_size[cell->cur_batch] = size + bytes;
+ cell->buffer_size[cell->cur_batch] = size + bytes;
return pos;
}
diff --git a/src/mesa/pipe/cell/ppu/cell_batch.h b/src/mesa/pipe/cell/ppu/cell_batch.h
index c4ba7feb3d..b4c96f465a 100644
--- a/src/mesa/pipe/cell/ppu/cell_batch.h
+++ b/src/mesa/pipe/cell/ppu/cell_batch.h
@@ -35,6 +35,9 @@
struct cell_context;
+extern uint
+cell_get_empty_buffer(struct cell_context *cell);
+
extern void
cell_batch_flush(struct cell_context *cell);
diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c
index 8cb0c48f40..e8020a49bc 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.c
+++ b/src/mesa/pipe/cell/ppu/cell_context.c
@@ -254,8 +254,9 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
cell_start_spus(cell);
- for (buf = 0; buf < CELL_NUM_BATCH_BUFFERS; buf++) {
- cell->batch_buffer_size[buf] = 0;
+ /* init command, vertex/index buffer info */
+ for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) {
+ cell->buffer_size[buf] = 0;
/* init batch buffer status values,
* mark 0th buffer as used, rest as free.
diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h
index 3bd88bfd5b..de65fb5e9a 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.h
+++ b/src/mesa/pipe/cell/ppu/cell_context.h
@@ -102,12 +102,14 @@ struct cell_context
uint num_spus;
- uint batch_buffer_size[CELL_NUM_BATCH_BUFFERS];
- ubyte batch_buffer[CELL_NUM_BATCH_BUFFERS][CELL_BATCH_BUFFER_SIZE] ALIGN16_ATTRIB;
- int cur_batch; /**< which batch buffer is being filled */
+ /** Buffers for command batches, vertex/index data */
+ uint buffer_size[CELL_NUM_BUFFERS];
+ ubyte buffer[CELL_NUM_BUFFERS][CELL_BUFFER_SIZE] ALIGN16_ATTRIB;
+
+ int cur_batch; /**< which buffer is being filled w/ commands */
/** [4] to ensure 16-byte alignment for each status word */
- uint buffer_status[CELL_MAX_SPUS][CELL_NUM_BATCH_BUFFERS][4] ALIGN16_ATTRIB;
+ uint buffer_status[CELL_MAX_SPUS][CELL_NUM_BUFFERS][4] ALIGN16_ATTRIB;
};
diff --git a/src/mesa/pipe/cell/ppu/cell_spu.c b/src/mesa/pipe/cell/ppu/cell_spu.c
index 4627bc8d1f..7c83a47e57 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.c
+++ b/src/mesa/pipe/cell/ppu/cell_spu.c
@@ -111,8 +111,8 @@ cell_start_spus(struct cell_context *cell)
cell_global.inits[i].id = i;
cell_global.inits[i].num_spus = cell->num_spus;
cell_global.inits[i].cmd = &cell_global.command[i];
- for (j = 0; j < CELL_NUM_BATCH_BUFFERS; j++) {
- cell_global.inits[i].batch_buffers[j] = cell->batch_buffer[j];
+ for (j = 0; j < CELL_NUM_BUFFERS; j++) {
+ cell_global.inits[i].buffers[j] = cell->buffer[j];
}
cell_global.inits[i].buffer_status = &cell->buffer_status[0][0][0];
diff --git a/src/mesa/pipe/cell/spu/spu_main.c b/src/mesa/pipe/cell/spu/spu_main.c
index 0c83900a18..2097683b82 100644
--- a/src/mesa/pipe/cell/spu/spu_main.c
+++ b/src/mesa/pipe/cell/spu/spu_main.c
@@ -473,22 +473,22 @@ cmd_finish(void)
/**
- * Tell the PPU that this SPU has finished copying a batch buffer to
+ * Tell the PPU that this SPU has finished copying a buffer to
* local store and that it may be reused by the PPU.
* This is done by writting a 16-byte batch-buffer-status block back into
- * main memory (in cell_contex->buffer_status[]).
+ * main memory (in cell_context->buffer_status[]).
*/
static void
-release_batch_buffer(uint buffer)
+release_buffer(uint buffer)
{
/* Evidently, using less than a 16-byte status doesn't work reliably */
static const uint status[4] ALIGN16_ATTRIB
= {CELL_BUFFER_STATUS_FREE, 0, 0, 0};
- const uint index = 4 * (spu.init.id * CELL_NUM_BATCH_BUFFERS + buffer);
+ const uint index = 4 * (spu.init.id * CELL_NUM_BUFFERS + buffer);
uint *dst = spu.init.buffer_status + index;
- ASSERT(buffer < CELL_NUM_BATCH_BUFFERS);
+ ASSERT(buffer < CELL_NUM_BUFFERS);
/*
printf("SPU %u: Set batch status buf=%u, index %u, at %p to FREE\n",
@@ -513,24 +513,24 @@ cmd_batch(uint opcode)
{
const uint buf = (opcode >> 8) & 0xff;
uint size = (opcode >> 16);
- uint buffer[CELL_BATCH_BUFFER_SIZE / 4] ALIGN16_ATTRIB;
+ uint buffer[CELL_BUFFER_SIZE / 4] ALIGN16_ATTRIB;
const uint usize = size / sizeof(uint);
uint pos;
if (Debug)
printf("SPU %u: BATCH buffer %u, len %u, from %p\n",
- spu.init.id, buf, size, spu.init.batch_buffers[buf]);
+ spu.init.id, buf, size, spu.init.buffers[buf]);
ASSERT((opcode & CELL_CMD_OPCODE_MASK) == CELL_CMD_BATCH);
- ASSERT_ALIGN16(spu.init.batch_buffers[buf]);
+ ASSERT_ALIGN16(spu.init.buffers[buf]);
size = ROUNDUP16(size);
- ASSERT_ALIGN16(spu.init.batch_buffers[buf]);
+ ASSERT_ALIGN16(spu.init.buffers[buf]);
mfc_get(buffer, /* dest */
- (unsigned int) spu.init.batch_buffers[buf], /* src */
+ (unsigned int) spu.init.buffers[buf], /* src */
size,
TAG_BATCH_BUFFER,
0, /* tid */
@@ -538,7 +538,7 @@ cmd_batch(uint opcode)
wait_on_mask(1 << TAG_BATCH_BUFFER);
/* Tell PPU we're done copying the buffer to local store */
- release_batch_buffer(buf);
+ release_buffer(buf);
for (pos = 0; pos < usize; /* no incr */) {
switch (buffer[pos]) {