From 8dd678208e4dcd90e07dc271d11d73d87465e0fd Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 11 Jan 2008 16:08:53 -0700 Subject: Cell: basic batch buffer working --- src/mesa/pipe/cell/ppu/cell_batch.c | 27 ++++++++++++++++++++++++++- src/mesa/pipe/cell/ppu/cell_batch.h | 6 ++++++ src/mesa/pipe/cell/ppu/cell_flush.c | 19 ++++++++++++++----- src/mesa/pipe/cell/ppu/cell_state_surface.c | 20 +++++++++++++++++++- src/mesa/pipe/cell/ppu/cell_surface.c | 12 ++++++++++++ src/mesa/pipe/cell/ppu/cell_vbuf.c | 27 ++++++++++++++++++++++++++- 6 files changed, 103 insertions(+), 8 deletions(-) (limited to 'src/mesa/pipe/cell/ppu') diff --git a/src/mesa/pipe/cell/ppu/cell_batch.c b/src/mesa/pipe/cell/ppu/cell_batch.c index a71573cbf7..7eb1b50ddb 100644 --- a/src/mesa/pipe/cell/ppu/cell_batch.c +++ b/src/mesa/pipe/cell/ppu/cell_batch.c @@ -43,7 +43,7 @@ cell_batch_flush(struct cell_context *cell) assert(batch < CELL_NUM_BATCH_BUFFERS); - printf("cell_batch_dispatch: buf %u, size %u\n", batch, size); + /*printf("cell_batch_dispatch: buf %u, size %u\n", batch, size);*/ cmd_word = CELL_CMD_BATCH | (batch << 8) | (size << 16); @@ -83,3 +83,28 @@ cell_batch_append(struct cell_context *cell, const void *cmd, uint length) cell->batch_buffer_size[cell->cur_batch] = size + length; } + + +void * +cell_batch_alloc(struct cell_context *cell, uint bytes) +{ + void *pos; + uint size; + + assert(cell->cur_batch >= 0); + + size = cell->batch_buffer_size[cell->cur_batch]; + + if (size + bytes > CELL_BATCH_BUFFER_SIZE) { + cell_batch_flush(cell); + size = 0; + } + + assert(size + bytes <= CELL_BATCH_BUFFER_SIZE); + + pos = (void *) (cell->batch_buffer[cell->cur_batch] + size); + + cell->batch_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 02d7edf8b9..7a5c6392d7 100644 --- a/src/mesa/pipe/cell/ppu/cell_batch.h +++ b/src/mesa/pipe/cell/ppu/cell_batch.h @@ -30,11 +30,17 @@ #define CELL_BATCH_H +struct cell_context; + + extern void cell_batch_flush(struct cell_context *cell); extern void cell_batch_append(struct cell_context *cell, const void *cmd, uint length); +extern void * +cell_batch_alloc(struct cell_context *cell, uint bytes); + #endif /* CELL_BATCH_H */ diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c index 977c50da32..33cbe2a085 100644 --- a/src/mesa/pipe/cell/ppu/cell_flush.c +++ b/src/mesa/pipe/cell/ppu/cell_flush.c @@ -38,16 +38,25 @@ cell_flush(struct pipe_context *pipe, unsigned flags) struct cell_context *cell = cell_context(pipe); uint i; - cell_flush_prim_buffer(cell); + if (flags & PIPE_FLUSH_WAIT) { + uint *cmd = (uint *) cell_batch_alloc(cell, sizeof(uint)); + *cmd = CELL_CMD_FINISH; + } + + cell_batch_flush(cell); +#if 0 /* Send CMD_FINISH to all SPUs */ for (i = 0; i < cell->num_spus; i++) { send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FINISH); } +#endif - /* Wait for ack */ - for (i = 0; i < cell->num_spus; i++) { - uint k = wait_mbox_message(cell_global.spe_contexts[i]); - assert(k == CELL_CMD_FINISH); + if (flags & PIPE_FLUSH_WAIT) { + /* Wait for ack */ + for (i = 0; i < cell->num_spus; i++) { + uint k = wait_mbox_message(cell_global.spe_contexts[i]); + assert(k == CELL_CMD_FINISH); + } } } diff --git a/src/mesa/pipe/cell/ppu/cell_state_surface.c b/src/mesa/pipe/cell/ppu/cell_state_surface.c index cd8e5def31..ff8fdbd334 100644 --- a/src/mesa/pipe/cell/ppu/cell_state_surface.c +++ b/src/mesa/pipe/cell/ppu/cell_state_surface.c @@ -27,6 +27,7 @@ #include "pipe/p_inlines.h" +#include "cell_batch.h" #include "cell_context.h" #include "cell_state.h" #include "cell_spu.h" @@ -68,8 +69,10 @@ cell_set_framebuffer_state(struct pipe_context *pipe, if (zsurf && !zsurf->map) pipe_surface_map(zsurf); +#if 0 for (i = 0; i < cell->num_spus; i++) { struct cell_command_framebuffer *fb = &cell_global.command[i].fb; + fb->opcode = CELL_CMD_FRAMEBUFFER; fb->color_start = csurf->map; fb->color_format = csurf->format; fb->depth_start = zsurf ? zsurf->map : NULL; @@ -78,7 +81,22 @@ cell_set_framebuffer_state(struct pipe_context *pipe, fb->height = csurf->height; send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER); } - +#endif +#if 1 + { + struct cell_command_framebuffer *fb + = cell_batch_alloc(cell, sizeof(*fb)); + fb->opcode = CELL_CMD_FRAMEBUFFER; + fb->color_start = csurf->map; + fb->color_format = csurf->format; + fb->depth_start = zsurf ? zsurf->map : NULL; + fb->depth_format = zsurf ? zsurf->format : PIPE_FORMAT_NONE; + fb->width = csurf->width; + fb->height = csurf->height; + /*cell_batch_flush(cell);*/ + /*cell_flush(&cell->pipe, 0x0);*/ + } +#endif cell->dirty |= CELL_NEW_FRAMEBUFFER; } diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c index 03dd41583f..ea1c2bd644 100644 --- a/src/mesa/pipe/cell/ppu/cell_surface.c +++ b/src/mesa/pipe/cell/ppu/cell_surface.c @@ -37,6 +37,7 @@ #include "pipe/p_util.h" #include "pipe/cell/common.h" #include "cell_context.h" +#include "cell_batch.h" #include "cell_surface.h" #include "cell_spu.h" @@ -59,6 +60,7 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps, surfIndex = 0; } +#if 0 for (i = 0; i < cell->num_spus; i++) { #if 1 uint clr = clearValue; @@ -80,6 +82,16 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps, cell_global.command[i].clear.surface = surfIndex; send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_SURFACE); } +#else + { + struct cell_command_clear_surface *clr + = (struct cell_command_clear_surface *) + cell_batch_alloc(cell, sizeof(*clr)); + clr->opcode = CELL_CMD_CLEAR_SURFACE; + clr->surface = surfIndex; + clr->value = clearValue; + } +#endif /* XXX temporary */ cell_flush(&cell->pipe, 0x0); diff --git a/src/mesa/pipe/cell/ppu/cell_vbuf.c b/src/mesa/pipe/cell/ppu/cell_vbuf.c index 63c3b39ec7..d27d718dae 100644 --- a/src/mesa/pipe/cell/ppu/cell_vbuf.c +++ b/src/mesa/pipe/cell/ppu/cell_vbuf.c @@ -130,8 +130,10 @@ cell_vbuf_draw(struct vbuf_render *vbr, if (prim != PIPE_PRIM_TRIANGLES) return; /* only render tris for now */ +#if 0 for (i = 0; i < cell->num_spus; i++) { struct cell_command_render *render = &cell_global.command[i].render; + render->opcode = CELL_CMD_RENDER; render->prim_type = prim; render->num_verts = nr_vertices; render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */ @@ -147,9 +149,32 @@ cell_vbuf_draw(struct vbuf_render *vbr, ASSERT_ALIGN16(render->index_data); send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_RENDER); } +#else + { + struct cell_command_render *render + = (struct cell_command_render *) + cell_batch_alloc(cell, sizeof(*render)); + render->opcode = CELL_CMD_RENDER; + render->prim_type = prim; + render->num_verts = nr_vertices; + render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */ + render->vertex_data = vertices; + render->index_data = indices; + render->num_indexes = nr_indices; + render->xmin = xmin; + render->ymin = ymin; + render->xmax = xmax; + render->ymax = ymax; + + ASSERT_ALIGN16(render->vertex_data); + ASSERT_ALIGN16(render->index_data); + } +#endif +#if 01 /* XXX this is temporary */ - cell_flush(&cell->pipe, 0x0); + cell_flush(&cell->pipe, PIPE_FLUSH_WAIT); +#endif } -- cgit v1.2.3