summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/cell
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe/cell')
-rw-r--r--src/mesa/pipe/cell/common.h23
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.c6
-rw-r--r--src/mesa/pipe/cell/ppu/cell_context.h3
-rw-r--r--src/mesa/pipe/cell/ppu/cell_flush.c6
-rw-r--r--src/mesa/pipe/cell/ppu/cell_spu.c150
-rw-r--r--src/mesa/pipe/cell/ppu/cell_spu.h41
-rw-r--r--src/mesa/pipe/cell/ppu/cell_state.h3
-rw-r--r--src/mesa/pipe/cell/ppu/cell_state_sampler.c32
-rw-r--r--src/mesa/pipe/cell/ppu/cell_surface.c83
-rw-r--r--src/mesa/pipe/cell/ppu/cell_surface.h16
-rw-r--r--src/mesa/pipe/cell/spu/main.c77
-rw-r--r--src/mesa/pipe/cell/spu/main.h61
-rw-r--r--src/mesa/pipe/cell/spu/tri.c873
-rw-r--r--src/mesa/pipe/cell/spu/tri.h50
14 files changed, 1184 insertions, 240 deletions
diff --git a/src/mesa/pipe/cell/common.h b/src/mesa/pipe/cell/common.h
index da7de78803..f7f1e2eb41 100644
--- a/src/mesa/pipe/cell/common.h
+++ b/src/mesa/pipe/cell/common.h
@@ -33,11 +33,11 @@
#ifndef CELL_COMMON_H
#define CELL_COMMON_H
+#include "pipe/p_compiler.h"
#include "pipe/p_util.h"
-#define ALIGN16 __attribute__( (aligned( 16 )) )
-
+/** for sanity checking */
#define ASSERT_ALIGN16(ptr) \
assert((((unsigned long) (ptr)) & 0xf) == 0);
@@ -49,7 +49,7 @@
#define CELL_CMD_EXIT 1
#define CELL_CMD_FRAMEBUFFER 2
#define CELL_CMD_CLEAR_TILES 3
-#define CELL_CMD_INVERT_TILES 4
+#define CELL_CMD_TRIANGLE 4
#define CELL_CMD_FINISH 5
@@ -61,7 +61,7 @@ struct cell_command_framebuffer
void *start;
int width, height;
unsigned format;
-} ALIGN16;
+} ALIGN16_ATTRIB;
/**
@@ -70,7 +70,14 @@ struct cell_command_framebuffer
struct cell_command_clear_tiles
{
uint value;
-} ALIGN16;
+} ALIGN16_ATTRIB;
+
+
+struct cell_command_triangle
+{
+ float vert[3][4];
+ float color[3][4];
+} ALIGN16_ATTRIB;
/** XXX unions don't seem to work */
@@ -78,15 +85,17 @@ struct cell_command
{
struct cell_command_framebuffer fb;
struct cell_command_clear_tiles clear;
-} ALIGN16;
+ struct cell_command_triangle tri;
+} ALIGN16_ATTRIB;
+/** This is the object passed to spe_create_thread() */
struct cell_init_info
{
unsigned id;
unsigned num_spus;
struct cell_command *cmd;
-} ALIGN16;
+} ALIGN16_ATTRIB;
diff --git a/src/mesa/pipe/cell/ppu/cell_context.c b/src/mesa/pipe/cell/ppu/cell_context.c
index 68543ecf30..966f355bb3 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.c
+++ b/src/mesa/pipe/cell/ppu/cell_context.c
@@ -208,18 +208,12 @@ cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
cell->pipe.set_blend_color = cell_set_blend_color;
cell->pipe.set_clip_state = cell_set_clip_state;
- cell->pipe.set_clear_color_state = cell_set_clear_color_state;
cell->pipe.set_constant_buffer = cell_set_constant_buffer;
-#if 0
- cell->pipe.set_feedback_state = cell_set_feedback_state;
-#endif
cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
- cell->pipe.set_sampler_units = cell_set_sampler_units;
cell->pipe.set_scissor_state = cell_set_scissor_state;
- cell->pipe.set_texture_state = cell_set_texture_state;
cell->pipe.set_viewport_state = cell_set_viewport_state;
cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
diff --git a/src/mesa/pipe/cell/ppu/cell_context.h b/src/mesa/pipe/cell/ppu/cell_context.h
index a64692081d..96f000eef4 100644
--- a/src/mesa/pipe/cell/ppu/cell_context.h
+++ b/src/mesa/pipe/cell/ppu/cell_context.h
@@ -47,10 +47,8 @@ struct cell_context
const struct pipe_rasterizer_state *rasterizer;
struct pipe_blend_color blend_color;
- struct pipe_clear_color_state clear_color;
struct pipe_clip_state clip;
struct pipe_constant_buffer constants[2];
- struct pipe_feedback_state feedback;
struct pipe_framebuffer_state framebuffer;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
@@ -58,7 +56,6 @@ struct cell_context
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
- uint sampler_units[PIPE_MAX_SAMPLERS];
uint dirty;
/** The primitive drawing context */
diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c
index e844d13f06..b1ff0e51cd 100644
--- a/src/mesa/pipe/cell/ppu/cell_flush.c
+++ b/src/mesa/pipe/cell/ppu/cell_flush.c
@@ -26,8 +26,6 @@
**************************************************************************/
-#include <cbe_mfc.h>
-
#include "cell_context.h"
#include "cell_flush.h"
#include "cell_spu.h"
@@ -43,12 +41,12 @@ cell_flush(struct pipe_context *pipe, unsigned flags)
/* Send CMD_FINISH to all SPUs */
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_FINISH);
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FINISH);
}
/* Wait for ack */
for (i = 0; i < cell->num_spus; i++) {
- uint k = wait_mbox_message(control_ps_area[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_spu.c b/src/mesa/pipe/cell/ppu/cell_spu.c
index ed56250ff1..55a0d5038b 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.c
+++ b/src/mesa/pipe/cell/ppu/cell_spu.c
@@ -26,7 +26,7 @@
**************************************************************************/
-#include <cbe_mfc.h>
+#include <pthread.h>
#include "cell_spu.h"
#include "pipe/p_format.h"
@@ -40,29 +40,16 @@ helpful headers:
*/
-/**
- * SPU/SPE handles, etc
- */
-speid_t speid[MAX_SPUS];
-spe_spu_control_area_t *control_ps_area[MAX_SPUS];
-
-
-/**
- * Data sent to SPUs
- */
-struct cell_init_info inits[MAX_SPUS] ALIGN16;
-struct cell_command command[MAX_SPUS] ALIGN16;
+struct cell_global_info cell_global;
/**
* Write a 1-word message to the given SPE mailbox.
*/
void
-send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg)
+send_mbox_message(spe_context_ptr_t ctx, unsigned int msg)
{
- while (_spe_in_mbox_status(ca) < 1)
- ;
- _spe_in_mbox_write(ca, msg);
+ spe_in_mbox_write(ctx, &msg, 1, SPE_MBOX_ALL_BLOCKING);
}
@@ -70,13 +57,37 @@ send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg)
* Wait for a 1-word message to arrive in given mailbox.
*/
uint
-wait_mbox_message(spe_spu_control_area_t *ca)
+wait_mbox_message(spe_context_ptr_t ctx)
+{
+ do {
+ unsigned data;
+ int count = spe_out_mbox_read(ctx, &data, 1);
+
+ if (count == 1) {
+ return data;
+ }
+
+ if (count < 0) {
+ /* error */ ;
+ }
+ } while (1);
+}
+
+
+static void *cell_thread_function(void *arg)
{
- uint k;
- while (_spe_out_mbox_status(ca) < 1)
- ;
- k = _spe_out_mbox_read(ca);
- return k;
+ struct cell_init_info *init = (struct cell_init_info *) arg;
+ unsigned entry = SPE_DEFAULT_ENTRY;
+
+ ASSERT_ALIGN16(init);
+
+ if (spe_context_run(cell_global.spe_contexts[init->id], &entry, 0,
+ init, NULL, NULL) < 0) {
+ fprintf(stderr, "spe_context_run() failed\n");
+ exit(1);
+ }
+
+ pthread_exit(NULL);
}
@@ -88,30 +99,32 @@ cell_start_spus(uint num_spus)
{
uint i;
- assert((sizeof(struct cell_command) & 0xf) == 0);
- ASSERT_ALIGN16(&command[0]);
- ASSERT_ALIGN16(&command[1]);
+ assert(num_spus <= MAX_SPUS);
- assert((sizeof(struct cell_init_info) & 0xf) == 0);
- ASSERT_ALIGN16(&inits[0]);
- ASSERT_ALIGN16(&inits[1]);
+ ASSERT_ALIGN16(&cell_global.command[0]);
+ ASSERT_ALIGN16(&cell_global.command[1]);
- /* XXX do we need to create a gid with spe_create_group()? */
+ ASSERT_ALIGN16(&cell_global.inits[0]);
+ ASSERT_ALIGN16(&cell_global.inits[1]);
for (i = 0; i < num_spus; i++) {
- inits[i].id = i;
- inits[i].num_spus = num_spus;
- inits[i].cmd = &command[i];
-
- speid[i] = spe_create_thread(0, /* gid */
- &g3d_spu, /* spe program handle */
- &inits[i], /* argp */
- NULL, /* envp */
- -1, /* mask */
- SPE_MAP_PS/*0*/ ); /* flags */
-
- control_ps_area[i] = spe_get_ps_area(speid[i], SPE_CONTROL_AREA);
- assert(control_ps_area[i]);
+ cell_global.inits[i].id = i;
+ cell_global.inits[i].num_spus = num_spus;
+ cell_global.inits[i].cmd = &cell_global.command[i];
+
+ cell_global.spe_contexts[i] = spe_context_create(0, NULL);
+ if (!cell_global.spe_contexts[i]) {
+ fprintf(stderr, "spe_context_create() failed\n");
+ exit(1);
+ }
+
+ if (spe_program_load(cell_global.spe_contexts[i], &g3d_spu)) {
+ fprintf(stderr, "spe_program_load() failed\n");
+ exit(1);
+ }
+
+ pthread_create(&cell_global.spe_threads[i], NULL, &cell_thread_function,
+ &cell_global.inits[i]);
}
}
@@ -124,14 +137,15 @@ finish_all(uint num_spus)
uint i;
for (i = 0; i < num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_FINISH);
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FINISH);
}
for (i = 0; i < num_spus; i++) {
/* wait for mbox message */
unsigned k;
- while (_spe_out_mbox_status(control_ps_area[i]) < 1)
+
+ while (spe_out_mbox_read(cell_global.spe_contexts[i], &k, 1) < 1)
;
- k = _spe_out_mbox_read(control_ps_area[i]);
+
assert(k == CELL_CMD_FINISH);
}
}
@@ -150,16 +164,16 @@ test_spus(struct cell_context *cell)
sleep(2);
for (i = 0; i < cell->num_spus; i++) {
- command[i].fb.start = surf->map;
- command[i].fb.width = surf->width;
- command[i].fb.height = surf->height;
- command[i].fb.format = PIPE_FORMAT_A8R8G8B8_UNORM;
- send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER);
+ cell_global.command[i].fb.start = surf->map;
+ cell_global.command[i].fb.width = surf->width;
+ cell_global.command[i].fb.height = surf->height;
+ cell_global.command[i].fb.format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER);
}
for (i = 0; i < cell->num_spus; i++) {
- command[i].clear.value = 0xff880044; /* XXX */
- send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES);
+ cell_global.command[i].clear.value = 0xff880044; /* XXX */
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_TILES);
}
finish_all(cell->num_spus);
@@ -171,21 +185,7 @@ test_spus(struct cell_context *cell)
}
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_INVERT_TILES);
- }
-
- finish_all(cell->num_spus);
-
- {
- uint *b = (uint*) surf->map;
- printf("PPU: Inverted results: 0x%x 0x%x 0x%x 0x%x\n",
- b[0], b[1000], b[2000], b[3000]);
- }
-
-
-
- for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_EXIT);
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_EXIT);
}
}
@@ -196,10 +196,11 @@ test_spus(struct cell_context *cell)
void
wait_spus(uint num_spus)
{
- int i, status;
+ uint i;
+ void *value;
for (i = 0; i < num_spus; i++) {
- spe_wait( speid[i], &status, 1 );
+ pthread_join(cell_global.spe_threads[i], &value);
}
}
@@ -210,14 +211,11 @@ wait_spus(uint num_spus)
void
cell_spu_exit(struct cell_context *cell)
{
- uint i;
- int status;
+ unsigned i;
for (i = 0; i < cell->num_spus; i++) {
- send_mbox_message(control_ps_area[i], CELL_CMD_EXIT);
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_EXIT);
}
- for (i = 0; i < cell->num_spus; i++) {
- spe_wait( speid[i], &status, 1 );
- }
+ wait_spus(cell->num_spus);
}
diff --git a/src/mesa/pipe/cell/ppu/cell_spu.h b/src/mesa/pipe/cell/ppu/cell_spu.h
index dcbc72573f..612cb45c59 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.h
+++ b/src/mesa/pipe/cell/ppu/cell_spu.h
@@ -29,35 +29,46 @@
#define CELL_SPU
-#include <libspe.h>
+#include <libspe2.h>
#include <libmisc.h>
#include "pipe/cell/common.h"
#include "cell_context.h"
-#define MAX_SPUS 7
+#define MAX_SPUS 8
/**
- * SPU/SPE handles, etc
+ * Global vars, for now anyway.
*/
-extern spe_program_handle_t g3d_spu;
-extern speid_t speid[MAX_SPUS];
-extern spe_spu_control_area_t *control_ps_area[MAX_SPUS];
+struct cell_global_info
+{
+ /**
+ * SPU/SPE handles, etc
+ */
+ spe_context_ptr_t spe_contexts[MAX_SPUS];
+ pthread_t spe_threads[MAX_SPUS];
+ /**
+ * Data sent to SPUs
+ */
+ struct cell_init_info inits[MAX_SPUS];
+ struct cell_command command[MAX_SPUS];
+};
-/**
- * Data sent to SPUs
- */
-extern struct cell_init_info inits[MAX_SPUS] ALIGN16;
-extern struct cell_command command[MAX_SPUS] ALIGN16;
+extern struct cell_global_info cell_global;
-void
-send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg);
-uint
-wait_mbox_message(spe_spu_control_area_t *ca);
+/** This is the handle for the actual SPE code */
+extern spe_program_handle_t g3d_spu;
+
+
+extern void
+send_mbox_message(spe_context_ptr_t ctx, unsigned int msg);
+
+extern uint
+wait_mbox_message(spe_context_ptr_t ctx);
void
diff --git a/src/mesa/pipe/cell/ppu/cell_state.h b/src/mesa/pipe/cell/ppu/cell_state.h
index 033767d29b..4bad45950b 100644
--- a/src/mesa/pipe/cell/ppu/cell_state.h
+++ b/src/mesa/pipe/cell/ppu/cell_state.h
@@ -93,9 +93,6 @@ void cell_set_constant_buffer(struct pipe_context *pipe,
void cell_set_polygon_stipple( struct pipe_context *,
const struct pipe_poly_stipple * );
-void cell_set_sampler_units( struct pipe_context *,
- uint numSamplers, const uint *units );
-
void cell_set_scissor_state( struct pipe_context *,
const struct pipe_scissor_state * );
diff --git a/src/mesa/pipe/cell/ppu/cell_state_sampler.c b/src/mesa/pipe/cell/ppu/cell_state_sampler.c
index c2a180ed30..1e7d4f08b8 100644
--- a/src/mesa/pipe/cell/ppu/cell_state_sampler.c
+++ b/src/mesa/pipe/cell/ppu/cell_state_sampler.c
@@ -66,35 +66,3 @@ cell_delete_sampler_state(struct pipe_context *pipe,
{
FREE( sampler );
}
-
-
-void
-cell_set_texture_state(struct pipe_context *pipe,
- unsigned unit,
- struct pipe_texture *texture)
-{
- struct cell_context *cell = cell_context(pipe);
-
- assert(unit < PIPE_MAX_SAMPLERS);
-
-#if 0
- cell->texture[unit] = cell_texture(texture); /* ptr, not struct */
- cell_tile_cache_set_texture(cell->tex_cache[unit], texture);
-#endif
-
- cell->dirty |= CELL_NEW_TEXTURE;
-}
-
-
-void
-cell_set_sampler_units(struct pipe_context *pipe,
- uint num_samplers, const uint *units )
-{
- struct cell_context *cell = cell_context(pipe);
- uint i;
- for (i = 0; i < num_samplers; i++)
- cell->sampler_units[i] = units[i];
- cell->dirty |= CELL_NEW_SAMPLER;
-}
-
-
diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c
index 1692960244..185eeb26e8 100644
--- a/src/mesa/pipe/cell/ppu/cell_surface.c
+++ b/src/mesa/pipe/cell/ppu/cell_surface.c
@@ -41,28 +41,6 @@
#include "cell_spu.h"
-
-struct pipe_surface *
-cell_create_surface(int width, int height)
-{
-#if 0
- /* XXX total hack */
- struct pipe_surface *ps = CALLOC_STRUCT(pipe_surface);
-
- printf("cell_create_surface\n");
-
- ps->width = width;
- ps->height = height;
-
- ps->region = CALLOC_STRUCT(pipe_region);
- ps->region->map = align_malloc(width * height * 4, 16);
- return ps;
-#endif
- return NULL;
-}
-
-
-
void
cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
unsigned clearValue)
@@ -70,37 +48,54 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
struct cell_context *cell = cell_context(pipe);
uint i;
- printf("%s 0x%08x\n", __FUNCTION__, clearValue);
-
- {
- char s[100];
- pf_sprint_name(s, ps->format);
- printf("format = %s\n", s);
- }
-
if (!ps->map)
pipe_surface_map(ps);
for (i = 0; i < cell->num_spus; i++) {
- command[i].fb.start = ps->map;
- command[i].fb.width = ps->width;
- command[i].fb.height = ps->height;
- command[i].fb.format = ps->format;
- send_mbox_message(control_ps_area[i], CELL_CMD_FRAMEBUFFER);
+ struct cell_command_framebuffer *fb = &cell_global.command[i].fb;
+ fb->start = ps->map;
+ fb->width = ps->width;
+ fb->height = ps->height;
+ fb->format = ps->format;
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_FRAMEBUFFER);
}
for (i = 0; i < cell->num_spus; i++) {
- command[i].clear.value = clearValue | (i << 21);
- send_mbox_message(control_ps_area[i], CELL_CMD_CLEAR_TILES);
+ /* XXX clear color varies per-SPU for debugging */
+ cell_global.command[i].clear.value = clearValue | (i << 21);
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_CLEAR_TILES);
}
-}
+#if 1
+ /* XXX Draw a test triangle over the cleared surface */
+ for (i = 0; i < cell->num_spus; i++) {
+ /* Same triangle data for all SPUs */
+ struct cell_command_triangle *tri = &cell_global.command[i].tri;
+ tri->vert[0][0] = 20.0;
+ tri->vert[0][1] = ps->height - 20;
-void
-cell_set_clear_color_state(struct pipe_context *pipe,
- const struct pipe_clear_color_state *clear)
-{
- struct cell_context *cell = cell_context(pipe);
+ tri->vert[1][0] = ps->width - 20.0;
+ tri->vert[1][1] = ps->height - 20;
- cell->clear_color = *clear; /* struct copy */
+ tri->vert[2][0] = ps->width / 2;
+ tri->vert[2][1] = 20.0;
+
+ tri->color[0][0] = 1.0;
+ tri->color[0][1] = 0.0;
+ tri->color[0][2] = 0.0;
+ tri->color[0][3] = 0.0;
+
+ tri->color[1][0] = 0.0;
+ tri->color[1][1] = 1.0;
+ tri->color[1][2] = 0.0;
+ tri->color[1][3] = 0.0;
+
+ tri->color[2][0] = 0.0;
+ tri->color[2][1] = 0.0;
+ tri->color[2][2] = 1.0;
+ tri->color[2][3] = 0.0;
+
+ send_mbox_message(cell_global.spe_contexts[i], CELL_CMD_TRIANGLE);
+ }
+#endif
}
diff --git a/src/mesa/pipe/cell/ppu/cell_surface.h b/src/mesa/pipe/cell/ppu/cell_surface.h
index 8b42ba02d5..4c69c4c89f 100644
--- a/src/mesa/pipe/cell/ppu/cell_surface.h
+++ b/src/mesa/pipe/cell/ppu/cell_surface.h
@@ -26,24 +26,18 @@
**************************************************************************/
-#ifndef CELL_SURFACE
-#define CELL_SURFACE
+#ifndef CELL_SURFACE_H
+#define CELL_SURFACE_H
-#include "pipe/p_state.h"
+struct pipe_context;
+struct pipe_surface;
-extern struct pipe_surface *
-cell_create_surface(int width, int height);
-
extern void
cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
unsigned clearValue);
-extern void
-cell_set_clear_color_state(struct pipe_context *pipe,
- const struct pipe_clear_color_state *clear);
-
-#endif /* CELL_SURFACE */
+#endif /* CELL_SURFACE_H */
diff --git a/src/mesa/pipe/cell/spu/main.c b/src/mesa/pipe/cell/spu/main.c
index 226d81b4ca..cc5eddb0f5 100644
--- a/src/mesa/pipe/cell/spu/main.c
+++ b/src/mesa/pipe/cell/spu/main.c
@@ -34,6 +34,7 @@
#include <libmisc.h>
#include <spu_mfcio.h>
+#include "main.h"
#include "tri.h"
#include "pipe/cell/common.h"
@@ -43,21 +44,15 @@ helpful headers:
/opt/ibm/cell-sdk/prototype/sysroot/usr/include/libmisc.h
*/
-static struct cell_init_info init;
+volatile struct cell_init_info init;
-struct framebuffer {
- void *start;
- uint width, height;
- uint width_tiles, height_tiles; /**< width and height in tiles */
-};
-static struct framebuffer fb;
+struct framebuffer fb;
+int DefaultTag;
-static int DefaultTag = 1;
-
-static inline void
+void
wait_on_mask(unsigned tag)
{
mfc_write_tag_mask( tag );
@@ -66,7 +61,7 @@ wait_on_mask(unsigned tag)
-static void
+void
get_tile(const struct framebuffer *fb, uint tx, uint ty, uint *tile)
{
uint offset = ty * fb->width_tiles + tx;
@@ -89,7 +84,7 @@ get_tile(const struct framebuffer *fb, uint tx, uint ty, uint *tile)
0 /* rid */);
}
-static void
+void
put_tile(const struct framebuffer *fb, uint tx, uint ty, const uint *tile)
{
uint offset = ty * fb->width_tiles + tx;
@@ -119,7 +114,7 @@ clear_tiles(const struct cell_command_clear_tiles *clear)
{
uint num_tiles = fb.width_tiles * fb.height_tiles;
uint i;
- uint tile[TILE_SIZE * TILE_SIZE] ALIGN16;
+ uint tile[TILE_SIZE * TILE_SIZE] ALIGN16_ATTRIB;
for (i = 0; i < TILE_SIZE * TILE_SIZE; i++)
tile[i] = clear->value;
@@ -136,32 +131,29 @@ clear_tiles(const struct cell_command_clear_tiles *clear)
}
-/** Invert all pixels in all tiles */
static void
-invert_tiles(void)
+triangle(const struct cell_command_triangle *tri)
{
uint num_tiles = fb.width_tiles * fb.height_tiles;
- uint i, j;
- uint tile[TILE_SIZE * TILE_SIZE] ALIGN16;
+ struct prim_header prim;
+ uint i;
+
+ COPY_4V(prim.v[0].data[0], tri->vert[0]);
+ COPY_4V(prim.v[1].data[0], tri->vert[1]);
+ COPY_4V(prim.v[2].data[0], tri->vert[2]);
+
+ COPY_4V(prim.v[0].data[1], tri->color[0]);
+ COPY_4V(prim.v[1].data[1], tri->color[1]);
+ COPY_4V(prim.v[2].data[1], tri->color[2]);
for (i = init.id; i < num_tiles; i += init.num_spus) {
uint tx = i % fb.width_tiles;
uint ty = i / fb.width_tiles;
-
- get_tile(&fb, tx, ty, tile);
- wait_on_mask(1 << DefaultTag);
-
- for (j = 0; j < TILE_SIZE * TILE_SIZE; j++) {
- tile[j] = ~tile[j];
- }
-
- put_tile(&fb, tx, ty, tile);
+ draw_triangle(&prim, tx, ty);
}
}
-struct cell_command cmd ALIGN16;
-
/**
* Temporary/simple main loop for SPEs: Get a command, execute it, repeat.
@@ -169,7 +161,9 @@ struct cell_command cmd ALIGN16;
static void
main_loop(void)
{
+ struct cell_command cmd;
int exitFlag = 0;
+
printf("SPU %u: Enter main loop\n", init.id);
assert((sizeof(struct cell_command) & 0xf) == 0);
@@ -207,17 +201,19 @@ main_loop(void)
cmd.fb.start);
fb.width = cmd.fb.width;
fb.height = cmd.fb.height;
- fb.width_tiles = fb.width / TILE_SIZE;
- fb.height_tiles = fb.height / TILE_SIZE;
+ fb.width_tiles = (fb.width + TILE_SIZE - 1) / TILE_SIZE;
+ fb.height_tiles = (fb.height + TILE_SIZE - 1) / TILE_SIZE;
+ printf("SPU %u: %u x %u tiles\n",
+ init.id, fb.width_tiles, fb.height_tiles);
fb.start = cmd.fb.start;
break;
case CELL_CMD_CLEAR_TILES:
printf("SPU %u: CLEAR to 0x%08x\n", init.id, cmd.clear.value);
clear_tiles(&cmd.clear);
break;
- case CELL_CMD_INVERT_TILES:
- printf("SPU %u: INVERT_TILES\n", init.id);
- invert_tiles();
+ case CELL_CMD_TRIANGLE:
+ printf("SPU %u: TRIANGLE\n", init.id);
+ triangle(&cmd.tri);
break;
case CELL_CMD_FINISH:
printf("SPU %u: FINISH\n", init.id);
@@ -238,15 +234,21 @@ main_loop(void)
+/**
+ * SPE entrypoint.
+ * Note: example programs declare params as 'unsigned long long' but
+ * that doesn't work.
+ */
int
-main(unsigned long long speid,
- unsigned long long argp,
- unsigned long long envp)
+main(unsigned long speid, unsigned long argp)
{
int tag = 0;
(void) speid;
- (void) envp;
+
+ DefaultTag = 1;
+
+ printf("SPU: main() speid=%lu\n", speid);
mfc_get(&init, /* dest */
(unsigned int) argp, /* src */
@@ -256,6 +258,7 @@ main(unsigned long long speid,
0 /* rid */);
wait_on_mask( 1 << tag );
+
main_loop();
return 0;
diff --git a/src/mesa/pipe/cell/spu/main.h b/src/mesa/pipe/cell/spu/main.h
new file mode 100644
index 0000000000..8c2796387f
--- /dev/null
+++ b/src/mesa/pipe/cell/spu/main.h
@@ -0,0 +1,61 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef MAIN_H
+#define MAIN_H
+
+
+#include <libmisc.h>
+#include <spu_mfcio.h>
+#include "pipe/cell/common.h"
+
+
+extern volatile struct cell_init_info init;
+
+struct framebuffer {
+ void *start;
+ uint width, height;
+ uint width_tiles, height_tiles; /**< width and height in tiles */
+};
+
+extern struct framebuffer fb;
+
+
+extern int DefaultTag;
+
+
+void
+wait_on_mask(unsigned tag);
+
+void
+get_tile(const struct framebuffer *fb, uint tx, uint ty, uint *tile);
+
+void
+put_tile(const struct framebuffer *fb, uint tx, uint ty, const uint *tile);
+
+
+#endif /* MAIN_H */
diff --git a/src/mesa/pipe/cell/spu/tri.c b/src/mesa/pipe/cell/spu/tri.c
index 949c3b4c8e..90452f14ba 100644
--- a/src/mesa/pipe/cell/spu/tri.c
+++ b/src/mesa/pipe/cell/spu/tri.c
@@ -1,9 +1,880 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+/**
+ * Triangle rendering within a tile.
+ */
+
+
+#if 0
+#include "sp_context.h"
+#include "sp_headers.h"
+#include "sp_quad.h"
+#include "sp_prim_setup.h"
+#include "pipe/draw/draw_private.h"
+#include "pipe/draw/draw_vertex.h"
+#include "pipe/p_util.h"
+#endif
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_util.h"
+#include "main.h"
#include "tri.h"
+/*
+#include <vmx2spu.h>
+#include <spu_internals.h>
+*/
+
+
+#if 1
+
+/* XXX fix this */
+#undef CEILF
+#define CEILF(X) ((float) (int) ((X) + 0.99999))
+
+
+#define QUAD_TOP_LEFT 0
+#define QUAD_TOP_RIGHT 1
+#define QUAD_BOTTOM_LEFT 2
+#define QUAD_BOTTOM_RIGHT 3
+#define MASK_TOP_LEFT (1 << QUAD_TOP_LEFT)
+#define MASK_TOP_RIGHT (1 << QUAD_TOP_RIGHT)
+#define MASK_BOTTOM_LEFT (1 << QUAD_BOTTOM_LEFT)
+#define MASK_BOTTOM_RIGHT (1 << QUAD_BOTTOM_RIGHT)
+#define MASK_ALL 0xf
+
+#define PIPE_MAX_SHADER_INPUTS 8 /* XXX temp */
+
+static int cliprect_minx, cliprect_maxx, cliprect_miny, cliprect_maxy;
+
+static uint tile[TILE_SIZE][TILE_SIZE] ALIGN16_ATTRIB;
+
+#endif
+
+
+#define DEBUG_VERTS 0
+
+/**
+ * Triangle edge info
+ */
+struct edge {
+ float dx; /**< X(v1) - X(v0), used only during setup */
+ float dy; /**< Y(v1) - Y(v0), used only during setup */
+ float dxdy; /**< dx/dy */
+ float sx, sy; /**< first sample point coord */
+ int lines; /**< number of lines on this edge */
+};
+
+
+struct interp_coef
+{
+ float a0[4];
+ float dadx[4];
+ float dady[4];
+};
+
+/**
+ * Triangle setup info (derived from draw_stage).
+ * Also used for line drawing (taking some liberties).
+ */
+struct setup_stage {
+#if 0
+ struct draw_stage stage; /**< This must be first (base class) */
+
+ struct softpipe_context *softpipe;
+#endif
+
+ /* Vertices are just an array of floats making up each attribute in
+ * turn. Currently fixed at 4 floats, but should change in time.
+ * Codegen will help cope with this.
+ */
+ const struct vertex_header *vmax;
+ const struct vertex_header *vmid;
+ const struct vertex_header *vmin;
+ const struct vertex_header *vprovoke;
+
+ struct edge ebot;
+ struct edge etop;
+ struct edge emaj;
+
+ float oneoverarea;
+
+#if 0
+ struct tgsi_interp_coef coef[PIPE_MAX_SHADER_INPUTS];
+#else
+ struct interp_coef coef[PIPE_MAX_SHADER_INPUTS];
+#endif
+
+#if 0
+ struct quad_header quad;
+#endif
+#if 1
+ uint color;
+#endif
+
+ struct {
+ int left[2]; /**< [0] = row0, [1] = row1 */
+ int right[2];
+ int y;
+ unsigned y_flags;
+ unsigned mask; /**< mask of MASK_BOTTOM/TOP_LEFT/RIGHT bits */
+ } span;
+};
+
+
+#if 0
+/**
+ * Basically a cast wrapper.
+ */
+static INLINE struct setup_stage *setup_stage( struct draw_stage *stage )
+{
+ return (struct setup_stage *)stage;
+}
+#endif
+
+#if 0
+/**
+ * Clip setup->quad against the scissor/surface bounds.
+ */
+static INLINE void
+quad_clip(struct setup_stage *setup)
+{
+ const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect;
+ const int minx = (int) cliprect->minx;
+ const int maxx = (int) cliprect->maxx;
+ const int miny = (int) cliprect->miny;
+ const int maxy = (int) cliprect->maxy;
+
+ if (setup->quad.x0 >= maxx ||
+ setup->quad.y0 >= maxy ||
+ setup->quad.x0 + 1 < minx ||
+ setup->quad.y0 + 1 < miny) {
+ /* totally clipped */
+ setup->quad.mask = 0x0;
+ return;
+ }
+ if (setup->quad.x0 < minx)
+ setup->quad.mask &= (MASK_BOTTOM_RIGHT | MASK_TOP_RIGHT);
+ if (setup->quad.y0 < miny)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_BOTTOM_RIGHT);
+ if (setup->quad.x0 == maxx - 1)
+ setup->quad.mask &= (MASK_BOTTOM_LEFT | MASK_TOP_LEFT);
+ if (setup->quad.y0 == maxy - 1)
+ setup->quad.mask &= (MASK_TOP_LEFT | MASK_TOP_RIGHT);
+}
+#endif
+
+#if 0
+/**
+ * Emit a quad (pass to next stage) with clipping.
+ */
+static INLINE void
+clip_emit_quad(struct setup_stage *setup)
+{
+ quad_clip(setup);
+ if (setup->quad.mask) {
+ struct softpipe_context *sp = setup->softpipe;
+ sp->quad.first->run(sp->quad.first, &setup->quad);
+ }
+}
+#endif
+
+/**
+ * Evaluate attribute coefficients (plane equations) to compute
+ * attribute values for the four fragments in a quad.
+ * Eg: four colors will be compute.
+ */
+static INLINE void
+eval_coeff( struct setup_stage *setup, uint slot,
+ float x, float y, float result[4][4])
+{
+ uint i;
+ const float *dadx = setup->coef[slot].dadx;
+ const float *dady = setup->coef[slot].dady;
+
+ /* loop over XYZW comps */
+ for (i = 0; i < 4; i++) {
+ result[QUAD_TOP_LEFT][i] = setup->coef[slot].a0[i] + x * dadx[i] + y * dady[i];
+ result[QUAD_TOP_RIGHT][i] = result[0][i] + dadx[i];
+ result[QUAD_BOTTOM_LEFT][i] = result[0][i] + dady[i];
+ result[QUAD_BOTTOM_RIGHT][i] = result[0][i] + dadx[i] + dady[i];
+ }
+}
+
+
+static INLINE uint
+pack_color(const float color[4])
+{
+ uint r = (uint) (color[0] * 255.0);
+ uint g = (uint) (color[1] * 255.0);
+ uint b = (uint) (color[2] * 255.0);
+ uint a = (uint) (color[3] * 255.0);
+ uint icolor = (b << 24) | (g << 16) | (r << 8) | a;
+ return icolor;
+}
+
+
+/**
+ * Emit a quad (pass to next stage). No clipping is done.
+ */
+static INLINE void
+emit_quad( struct setup_stage *setup, int x, int y, unsigned mask )
+{
+#if 0
+ struct softpipe_context *sp = setup->softpipe;
+ setup->quad.x0 = x;
+ setup->quad.y0 = y;
+ setup->quad.mask = mask;
+ sp->quad.first->run(sp->quad.first, &setup->quad);
+#else
+ /* Cell: "write" quad fragments to the tile by setting prim color */
+ int ix = x - cliprect_minx;
+ int iy = y - cliprect_miny;
+ float colors[4][4];
+
+ eval_coeff(setup, 1, (float) x, (float) y, colors);
+
+ if (mask & MASK_TOP_LEFT)
+ tile[iy][ix] = pack_color(colors[QUAD_TOP_LEFT]);
+ if (mask & MASK_TOP_RIGHT)
+ tile[iy][ix+1] = pack_color(colors[QUAD_TOP_RIGHT]);
+ if (mask & MASK_BOTTOM_LEFT)
+ tile[iy+1][ix] = pack_color(colors[QUAD_BOTTOM_LEFT]);
+ if (mask & MASK_BOTTOM_RIGHT)
+ tile[iy+1][ix+1] = pack_color(colors[QUAD_BOTTOM_RIGHT]);
+#endif
+}
+
+
+/**
+ * Given an X or Y coordinate, return the block/quad coordinate that it
+ * belongs to.
+ */
+static INLINE int block( int x )
+{
+ return x & ~1;
+}
+
+
+/**
+ * Compute mask which indicates which pixels in the 2x2 quad are actually inside
+ * the triangle's bounds.
+ *
+ * this is pretty nasty... may need to rework flush_spans again to
+ * fix it, if possible.
+ */
+static unsigned calculate_mask( struct setup_stage *setup, int x )
+{
+ unsigned mask = 0x0;
+
+ if (x >= setup->span.left[0] && x < setup->span.right[0])
+ mask |= MASK_TOP_LEFT;
+
+ if (x >= setup->span.left[1] && x < setup->span.right[1])
+ mask |= MASK_BOTTOM_LEFT;
+
+ if (x+1 >= setup->span.left[0] && x+1 < setup->span.right[0])
+ mask |= MASK_TOP_RIGHT;
+
+ if (x+1 >= setup->span.left[1] && x+1 < setup->span.right[1])
+ mask |= MASK_BOTTOM_RIGHT;
+
+ return mask;
+}
+
+
+/**
+ * Render a horizontal span of quads
+ */
+static void flush_spans( struct setup_stage *setup )
+{
+ int minleft, maxright;
+ int x;
+
+ switch (setup->span.y_flags) {
+ case 0x3:
+ /* both odd and even lines written (both quad rows) */
+ minleft = MIN2(setup->span.left[0], setup->span.left[1]);
+ maxright = MAX2(setup->span.right[0], setup->span.right[1]);
+ break;
+
+ case 0x1:
+ /* only even line written (quad top row) */
+ minleft = setup->span.left[0];
+ maxright = setup->span.right[0];
+ break;
+
+ case 0x2:
+ /* only odd line written (quad bottom row) */
+ minleft = setup->span.left[1];
+ maxright = setup->span.right[1];
+ break;
+
+ default:
+ return;
+ }
+
+ /* XXX this loop could be moved into the above switch cases and
+ * calculate_mask() could be simplified a bit...
+ */
+ for (x = block(minleft); x <= block(maxright); x += 2) {
+ emit_quad( setup, x, setup->span.y,
+ calculate_mask( setup, x ) );
+ }
+
+ setup->span.y = 0;
+ setup->span.y_flags = 0;
+ setup->span.right[0] = 0;
+ setup->span.right[1] = 0;
+}
+
+#if DEBUG_VERTS
+static void print_vertex(const struct setup_stage *setup,
+ const struct vertex_header *v)
+{
+ int i;
+ fprintf(stderr, "Vertex: (%p)\n", v);
+ for (i = 0; i < setup->quad.nr_attrs; i++) {
+ fprintf(stderr, " %d: %f %f %f %f\n", i,
+ v->data[i][0], v->data[i][1], v->data[i][2], v->data[i][3]);
+ }
+}
+#endif
+
+static boolean setup_sort_vertices( struct setup_stage *setup,
+ const struct prim_header *prim )
+{
+#if 0
+ const struct vertex_header *v0 = prim->v[0];
+ const struct vertex_header *v1 = prim->v[1];
+ const struct vertex_header *v2 = prim->v[2];
+#else
+ const struct vertex_header *v0 = &prim->v[0];
+ const struct vertex_header *v1 = &prim->v[1];
+ const struct vertex_header *v2 = &prim->v[2];
+#endif
+
+#if DEBUG_VERTS
+ fprintf(stderr, "Triangle:\n");
+ print_vertex(setup, v0);
+ print_vertex(setup, v1);
+ print_vertex(setup, v2);
+#endif
+
+ setup->vprovoke = v2;
+
+ /* determine bottom to top order of vertices */
+ {
+ float y0 = v0->data[0][1];
+ float y1 = v1->data[0][1];
+ float y2 = v2->data[0][1];
+ if (y0 <= y1) {
+ if (y1 <= y2) {
+ /* y0<=y1<=y2 */
+ setup->vmin = v0;
+ setup->vmid = v1;
+ setup->vmax = v2;
+ }
+ else if (y2 <= y0) {
+ /* y2<=y0<=y1 */
+ setup->vmin = v2;
+ setup->vmid = v0;
+ setup->vmax = v1;
+ }
+ else {
+ /* y0<=y2<=y1 */
+ setup->vmin = v0;
+ setup->vmid = v2;
+ setup->vmax = v1;
+ }
+ }
+ else {
+ if (y0 <= y2) {
+ /* y1<=y0<=y2 */
+ setup->vmin = v1;
+ setup->vmid = v0;
+ setup->vmax = v2;
+ }
+ else if (y2 <= y1) {
+ /* y2<=y1<=y0 */
+ setup->vmin = v2;
+ setup->vmid = v1;
+ setup->vmax = v0;
+ }
+ else {
+ /* y1<=y2<=y0 */
+ setup->vmin = v1;
+ setup->vmid = v2;
+ setup->vmax = v0;
+ }
+ }
+ }
+
+ setup->ebot.dx = setup->vmid->data[0][0] - setup->vmin->data[0][0];
+ setup->ebot.dy = setup->vmid->data[0][1] - setup->vmin->data[0][1];
+ setup->emaj.dx = setup->vmax->data[0][0] - setup->vmin->data[0][0];
+ setup->emaj.dy = setup->vmax->data[0][1] - setup->vmin->data[0][1];
+ setup->etop.dx = setup->vmax->data[0][0] - setup->vmid->data[0][0];
+ setup->etop.dy = setup->vmax->data[0][1] - setup->vmid->data[0][1];
+
+ /*
+ * Compute triangle's area. Use 1/area to compute partial
+ * derivatives of attributes later.
+ *
+ * The area will be the same as prim->det, but the sign may be
+ * different depending on how the vertices get sorted above.
+ *
+ * To determine whether the primitive is front or back facing we
+ * use the prim->det value because its sign is correct.
+ */
+ {
+ const float area = (setup->emaj.dx * setup->ebot.dy -
+ setup->ebot.dx * setup->emaj.dy);
+
+ setup->oneoverarea = 1.0f / area;
+ /*
+ _mesa_printf("%s one-over-area %f area %f det %f\n",
+ __FUNCTION__, setup->oneoverarea, area, prim->det );
+ */
+ }
+
+#if 0
+ /* We need to know if this is a front or back-facing triangle for:
+ * - the GLSL gl_FrontFacing fragment attribute (bool)
+ * - two-sided stencil test
+ */
+ setup->quad.facing = (prim->det > 0.0) ^ (setup->softpipe->rasterizer->front_winding == PIPE_WINDING_CW);
+#endif
+
+ return TRUE;
+}
+
+
+#if 0
+/**
+ * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
+ * The value value comes from vertex->data[slot][i].
+ * The result will be put into setup->coef[slot].a0[i].
+ * \param slot which attribute slot
+ * \param i which component of the slot (0..3)
+ */
+static void const_coeff( struct setup_stage *setup,
+ unsigned slot,
+ unsigned i )
+{
+ assert(slot < PIPE_MAX_SHADER_INPUTS);
+ assert(i <= 3);
+
+ setup->coef[slot].dadx[i] = 0;
+ setup->coef[slot].dady[i] = 0;
+
+ /* need provoking vertex info!
+ */
+ setup->coef[slot].a0[i] = setup->vprovoke->data[slot][i];
+}
+#endif
+
+
+/**
+ * Compute a0, dadx and dady for a linearly interpolated coefficient,
+ * for a triangle.
+ */
+static void tri_linear_coeff( struct setup_stage *setup,
+ unsigned slot )
+{
+ uint i;
+ for (i = 0; i < 4; i++) {
+ float botda = setup->vmid->data[slot][i] - setup->vmin->data[slot][i];
+ float majda = setup->vmax->data[slot][i] - setup->vmin->data[slot][i];
+ float a = setup->ebot.dy * majda - botda * setup->emaj.dy;
+ float b = setup->emaj.dx * botda - majda * setup->ebot.dx;
+
+ assert(slot < PIPE_MAX_SHADER_INPUTS);
+
+ setup->coef[slot].dadx[i] = a * setup->oneoverarea;
+ setup->coef[slot].dady[i] = b * setup->oneoverarea;
+
+ /* calculate a0 as the value which would be sampled for the
+ * fragment at (0,0), taking into account that we want to sample at
+ * pixel centers, in other words (0.5, 0.5).
+ *
+ * this is neat but unfortunately not a good way to do things for
+ * triangles with very large values of dadx or dady as it will
+ * result in the subtraction and re-addition from a0 of a very
+ * large number, which means we'll end up loosing a lot of the
+ * fractional bits and precision from a0. the way to fix this is
+ * to define a0 as the sample at a pixel center somewhere near vmin
+ * instead - i'll switch to this later.
+ */
+ setup->coef[slot].a0[i] = (setup->vmin->data[slot][i] -
+ (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5f) +
+ setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5f)));
+ }
+
+ /*
+ _mesa_printf("attr[%d].%c: %f dx:%f dy:%f\n",
+ slot, "xyzw"[i],
+ setup->coef[slot].a0[i],
+ setup->coef[slot].dadx[i],
+ setup->coef[slot].dady[i]);
+ */
+}
+
+
+#if 0
+/**
+ * Compute a0, dadx and dady for a perspective-corrected interpolant,
+ * for a triangle.
+ * We basically multiply the vertex value by 1/w before computing
+ * the plane coefficients (a0, dadx, dady).
+ * Later, when we compute the value at a particular fragment position we'll
+ * divide the interpolated value by the interpolated W at that fragment.
+ */
+static void tri_persp_coeff( struct setup_stage *setup,
+ unsigned slot,
+ unsigned i )
+{
+ /* premultiply by 1/w:
+ */
+ float mina = setup->vmin->data[slot][i] * setup->vmin->data[0][3];
+ float mida = setup->vmid->data[slot][i] * setup->vmid->data[0][3];
+ float maxa = setup->vmax->data[slot][i] * setup->vmax->data[0][3];
+
+ float botda = mida - mina;
+ float majda = maxa - mina;
+ float a = setup->ebot.dy * majda - botda * setup->emaj.dy;
+ float b = setup->emaj.dx * botda - majda * setup->ebot.dx;
+
+ /*
+ printf("tri persp %d,%d: %f %f %f\n", slot, i,
+ setup->vmin->data[slot][i],
+ setup->vmid->data[slot][i],
+ setup->vmax->data[slot][i]
+ );
+ */
+
+ assert(slot < PIPE_MAX_SHADER_INPUTS);
+ assert(i <= 3);
+
+ setup->coef[slot].dadx[i] = a * setup->oneoverarea;
+ setup->coef[slot].dady[i] = b * setup->oneoverarea;
+ setup->coef[slot].a0[i] = (mina -
+ (setup->coef[slot].dadx[i] * (setup->vmin->data[0][0] - 0.5f) +
+ setup->coef[slot].dady[i] * (setup->vmin->data[0][1] - 0.5f)));
+}
+#endif
+
+
+/**
+ * Compute the setup->coef[] array dadx, dady, a0 values.
+ * Must be called after setup->vmin,vmid,vmax,vprovoke are initialized.
+ */
+static void setup_tri_coefficients( struct setup_stage *setup )
+{
+#if 0
+ const enum interp_mode *interp = setup->softpipe->vertex_info.interp_mode;
+ unsigned slot, j;
+
+ /* z and w are done by linear interpolation:
+ */
+ tri_linear_coeff(setup, 0, 2);
+ tri_linear_coeff(setup, 0, 3);
+
+ /* setup interpolation for all the remaining attributes:
+ */
+ for (slot = 1; slot < setup->quad.nr_attrs; slot++) {
+ switch (interp[slot]) {
+ case INTERP_CONSTANT:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ const_coeff(setup, slot, j);
+ break;
+
+ case INTERP_LINEAR:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ tri_linear_coeff(setup, slot, j);
+ break;
+
+ case INTERP_PERSPECTIVE:
+ for (j = 0; j < NUM_CHANNELS; j++)
+ tri_persp_coeff(setup, slot, j);
+ break;
+
+ default:
+ /* invalid interp mode */
+ assert(0);
+ }
+ }
+#else
+ tri_linear_coeff(setup, 1); /* slot 1 = color */
+#endif
+}
+
+
+static void setup_tri_edges( struct setup_stage *setup )
+{
+ float vmin_x = setup->vmin->data[0][0] + 0.5f;
+ float vmid_x = setup->vmid->data[0][0] + 0.5f;
+
+ float vmin_y = setup->vmin->data[0][1] - 0.5f;
+ float vmid_y = setup->vmid->data[0][1] - 0.5f;
+ float vmax_y = setup->vmax->data[0][1] - 0.5f;
+
+ setup->emaj.sy = CEILF(vmin_y);
+ setup->emaj.lines = (int) CEILF(vmax_y - setup->emaj.sy);
+ setup->emaj.dxdy = setup->emaj.dx / setup->emaj.dy;
+ setup->emaj.sx = vmin_x + (setup->emaj.sy - vmin_y) * setup->emaj.dxdy;
+
+ setup->etop.sy = CEILF(vmid_y);
+ setup->etop.lines = (int) CEILF(vmax_y - setup->etop.sy);
+ setup->etop.dxdy = setup->etop.dx / setup->etop.dy;
+ setup->etop.sx = vmid_x + (setup->etop.sy - vmid_y) * setup->etop.dxdy;
+
+ setup->ebot.sy = CEILF(vmin_y);
+ setup->ebot.lines = (int) CEILF(vmid_y - setup->ebot.sy);
+ setup->ebot.dxdy = setup->ebot.dx / setup->ebot.dy;
+ setup->ebot.sx = vmin_x + (setup->ebot.sy - vmin_y) * setup->ebot.dxdy;
+}
+
+
+/**
+ * Render the upper or lower half of a triangle.
+ * Scissoring/cliprect is applied here too.
+ */
+static void subtriangle( struct setup_stage *setup,
+ struct edge *eleft,
+ struct edge *eright,
+ unsigned lines )
+{
+#if 0
+ const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect;
+ const int minx = (int) cliprect->minx;
+ const int maxx = (int) cliprect->maxx;
+ const int miny = (int) cliprect->miny;
+ const int maxy = (int) cliprect->maxy;
+#else
+ const int minx = cliprect_minx;
+ const int maxx = cliprect_maxx;
+ const int miny = cliprect_miny;
+ const int maxy = cliprect_maxy;
+#endif
+ int y, start_y, finish_y;
+ int sy = (int)eleft->sy;
+
+ assert((int)eleft->sy == (int) eright->sy);
+
+ /* clip top/bottom */
+ start_y = sy;
+ finish_y = sy + lines;
+
+ if (start_y < miny)
+ start_y = miny;
+
+ if (finish_y > maxy)
+ finish_y = maxy;
+
+ start_y -= sy;
+ finish_y -= sy;
+
+ /*
+ _mesa_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y);
+ */
+
+ for (y = start_y; y < finish_y; y++) {
+
+ /* avoid accumulating adds as floats don't have the precision to
+ * accurately iterate large triangle edges that way. luckily we
+ * can just multiply these days.
+ *
+ * this is all drowned out by the attribute interpolation anyway.
+ */
+ int left = (int)(eleft->sx + y * eleft->dxdy);
+ int right = (int)(eright->sx + y * eright->dxdy);
+
+ /* clip left/right */
+ if (left < minx)
+ left = minx;
+ if (right > maxx)
+ right = maxx;
+
+ if (left < right) {
+ int _y = sy + y;
+ if (block(_y) != setup->span.y) {
+ flush_spans(setup);
+ setup->span.y = block(_y);
+ }
+
+ setup->span.left[_y&1] = left;
+ setup->span.right[_y&1] = right;
+ setup->span.y_flags |= 1<<(_y&1);
+ }
+ }
+
+
+ /* save the values so that emaj can be restarted:
+ */
+ eleft->sx += lines * eleft->dxdy;
+ eright->sx += lines * eright->dxdy;
+ eleft->sy += lines;
+ eright->sy += lines;
+}
+
+
+/**
+ * Do setup for triangle rasterization, then render the triangle.
+ */
+static void setup_tri(
+#if 0
+ struct draw_stage *stage,
+#endif
+ struct prim_header *prim )
+{
+#if 0
+ struct setup_stage *setup = setup_stage( stage );
+#else
+ struct setup_stage ss;
+ struct setup_stage *setup = &ss;
+ ss.color = prim->color;
+#endif
+
+ /*
+ _mesa_printf("%s\n", __FUNCTION__ );
+ */
+
+ setup_sort_vertices( setup, prim );
+ setup_tri_coefficients( setup );
+ setup_tri_edges( setup );
+
+#if 0
+ setup->quad.prim = PRIM_TRI;
+#endif
+
+ setup->span.y = 0;
+ setup->span.y_flags = 0;
+ setup->span.right[0] = 0;
+ setup->span.right[1] = 0;
+ /* setup->span.z_mode = tri_z_mode( setup->ctx ); */
+
+ /* init_constant_attribs( setup ); */
+
+ if (setup->oneoverarea < 0.0) {
+ /* emaj on left:
+ */
+ subtriangle( setup, &setup->emaj, &setup->ebot, setup->ebot.lines );
+ subtriangle( setup, &setup->emaj, &setup->etop, setup->etop.lines );
+ }
+ else {
+ /* emaj on right:
+ */
+ subtriangle( setup, &setup->ebot, &setup->emaj, setup->ebot.lines );
+ subtriangle( setup, &setup->etop, &setup->emaj, setup->etop.lines );
+ }
+
+ flush_spans( setup );
+}
+
+
+
+
+#if 0
+static void setup_begin( struct draw_stage *stage )
+{
+ struct setup_stage *setup = setup_stage(stage);
+ struct softpipe_context *sp = setup->softpipe;
+
+ setup->quad.nr_attrs = setup->softpipe->nr_frag_attrs;
+
+ sp->quad.first->begin(sp->quad.first);
+}
+#endif
+
+#if 0
+static void setup_end( struct draw_stage *stage )
+{
+}
+#endif
+
+
+#if 0
+static void reset_stipple_counter( struct draw_stage *stage )
+{
+ struct setup_stage *setup = setup_stage(stage);
+ setup->softpipe->line_stipple_counter = 0;
+}
+#endif
+
+#if 0
+static void render_destroy( struct draw_stage *stage )
+{
+ FREE( stage );
+}
+#endif
+
+
+#if 0
+/**
+ * Create a new primitive setup/render stage.
+ */
+struct draw_stage *sp_draw_render_stage( struct softpipe_context *softpipe )
+{
+ struct setup_stage *setup = CALLOC_STRUCT(setup_stage);
+
+ setup->softpipe = softpipe;
+ setup->stage.draw = softpipe->draw;
+ setup->stage.begin = setup_begin;
+ setup->stage.point = setup_point;
+ setup->stage.line = setup_line;
+ setup->stage.tri = setup_tri;
+ setup->stage.end = setup_end;
+ setup->stage.reset_stipple_counter = reset_stipple_counter;
+ setup->stage.destroy = render_destroy;
+
+ setup->quad.coef = setup->coef;
+
+ return &setup->stage;
+}
+#endif
+
+
void
-draw_triangle(int v1, int v2, int v3)
+draw_triangle(struct prim_header *tri, uint tx, uint ty)
{
+ /* set clipping bounds to tile bounds */
+ cliprect_minx = tx * TILE_SIZE;
+ cliprect_miny = ty * TILE_SIZE;
+ cliprect_maxx = (tx + 1) * TILE_SIZE;
+ cliprect_maxy = (ty + 1) * TILE_SIZE;
+
+ get_tile(&fb, tx, ty, (uint *) tile);
+ wait_on_mask(1 << DefaultTag);
+ setup_tri(tri);
+ put_tile(&fb, tx, ty, (uint *) tile);
+ wait_on_mask(1 << DefaultTag);
}
diff --git a/src/mesa/pipe/cell/spu/tri.h b/src/mesa/pipe/cell/spu/tri.h
index 6a915de60d..dc66ad0f47 100644
--- a/src/mesa/pipe/cell/spu/tri.h
+++ b/src/mesa/pipe/cell/spu/tri.h
@@ -1,4 +1,52 @@
+/**************************************************************************
+ *
+ * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef TRI_H
+#define TRI_H
+
+
+/**
+ * Simplified types taken from other parts of Gallium
+ */
+
+struct vertex_header {
+ float data[2][4]; /* pos and color */
+};
+
+
+struct prim_header {
+ struct vertex_header v[3];
+ uint color;
+};
extern void
-draw_triangle(int v1, int v2, int v3);
+draw_triangle(struct prim_header *tri, uint tx, uint ty);
+
+
+#endif /* TRI_H */