-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This patch ports the existing Gallium Cell code to use libspe2 instead
of libspe.  libspe is deprecated in SDK 2.1 and is removed from SDK 3.0.
 If there are no NAKs, I'll commit this code later today.

Signed-off-by: Ian Romanick <[EMAIL PROTECTED]>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHXtTzX1gOwKyEAw8RAhgoAKCDLpfUZ0rslwO0w6qQQ2L1uRvx+QCfcb2K
Bs5Vcp1amMe6GEdAMMECXQo=
=jMuo
-----END PGP SIGNATURE-----
diff --git a/configs/linux-cell b/configs/linux-cell
index f2c1dd2..e01c319 100644
--- a/configs/linux-cell
+++ b/configs/linux-cell
@@ -25,7 +25,7 @@ MKDEP_OPTIONS = -fdepend -Y
 
 
 GL_LIB_DEPS = $(EXTRA_LIB_PATH) -lX11 -lXext -lm -lpthread \
-	-L$(SDK)/lib -m32 -Wl,-m,elf32ppc -R$(SDK)/lib -lspe
+	-L$(SDK)/lib -m32 -Wl,-m,elf32ppc -R$(SDK)/lib -lspe2
 
 
 
diff --git a/src/mesa/pipe/cell/ppu/cell_flush.c b/src/mesa/pipe/cell/ppu/cell_flush.c
index e844d13..39b72c4 100644
--- a/src/mesa/pipe/cell/ppu/cell_flush.c
+++ b/src/mesa/pipe/cell/ppu/cell_flush.c
@@ -43,12 +43,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(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(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 ed56250..64fa89f 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.c
+++ b/src/mesa/pipe/cell/ppu/cell_spu.c
@@ -27,6 +27,7 @@
 
 
 #include <cbe_mfc.h>
+#include <pthread.h>
 
 #include "cell_spu.h"
 #include "pipe/p_format.h"
@@ -43,9 +44,8 @@ helpful headers:
 /**
  * SPU/SPE handles, etc
  */
-speid_t speid[MAX_SPUS];
-spe_spu_control_area_t *control_ps_area[MAX_SPUS];
-
+spe_context_ptr_t spe_contexts[MAX_SPUS];
+pthread_t spe_threads[MAX_SPUS];
 
 /**
  * Data sent to SPUs
@@ -58,11 +58,9 @@ struct cell_command command[MAX_SPUS] ALIGN16;
  * 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 +68,30 @@ 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;
+   
+   spe_context_run(spe_contexts[init->id], &entry, 0, init, NULL, NULL);
+   pthread_exit(NULL);
 }
 
 
@@ -96,22 +111,17 @@ cell_start_spus(uint num_spus)
    ASSERT_ALIGN16(&inits[0]);
    ASSERT_ALIGN16(&inits[1]);
 
-   /* XXX do we need to create a gid with spe_create_group()? */
-
    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 */
+      spe_contexts[i] = spe_context_create(0, NULL);
 
-      control_ps_area[i] = spe_get_ps_area(speid[i], SPE_CONTROL_AREA);
-      assert(control_ps_area[i]);
+      spe_program_load(spe_contexts[i], &g3d_spu);
+      
+      pthread_create(&spe_threads[i], NULL, cell_thread_function,
+		     & inits[i]);
    }
 }
 
@@ -124,14 +134,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(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(spe_contexts[i], &k, 1) < 1)
          ;
-      k = _spe_out_mbox_read(control_ps_area[i]);
+
       assert(k == CELL_CMD_FINISH);
    }
 }
@@ -154,12 +165,12 @@ test_spus(struct cell_context *cell)
       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);
+      send_mbox_message(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);
+      send_mbox_message(spe_contexts[i], CELL_CMD_CLEAR_TILES);
    }
 
    finish_all(cell->num_spus);
@@ -171,7 +182,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);
+      send_mbox_message(spe_contexts[i], CELL_CMD_INVERT_TILES);
    }
 
    finish_all(cell->num_spus);
@@ -185,7 +196,7 @@ test_spus(struct cell_context *cell)
 
 
    for (i = 0; i < cell->num_spus; i++) {
-      send_mbox_message(control_ps_area[i], CELL_CMD_EXIT);
+      send_mbox_message(spe_contexts[i], CELL_CMD_EXIT);
    }
 }
 
@@ -196,10 +207,11 @@ test_spus(struct cell_context *cell)
 void
 wait_spus(uint num_spus)
 {
-   int i, status;
+   unsigned i;
+   void *value;
 
    for (i = 0; i < num_spus; i++) {
-      spe_wait( speid[i], &status, 1 );
+      pthread_join(spe_threads[i], &value);
    }
 }
 
@@ -210,14 +222,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(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 dcbc725..80a8899 100644
--- a/src/mesa/pipe/cell/ppu/cell_spu.h
+++ b/src/mesa/pipe/cell/ppu/cell_spu.h
@@ -29,7 +29,7 @@
 #define CELL_SPU
 
 
-#include <libspe.h>
+#include <libspe2.h>
 #include <libmisc.h>
 #include "pipe/cell/common.h"
 
@@ -42,8 +42,8 @@
  * SPU/SPE handles, etc
  */
 extern spe_program_handle_t g3d_spu;
-extern speid_t speid[MAX_SPUS];
-extern spe_spu_control_area_t *control_ps_area[MAX_SPUS];
+extern spe_context_ptr_t spe_contexts[MAX_SPUS];
+extern pthread_t spe_threads[MAX_SPUS];
 
 
 /**
@@ -53,11 +53,11 @@ extern struct cell_init_info inits[MAX_SPUS] ALIGN16;
 extern struct cell_command command[MAX_SPUS] ALIGN16;
 
 
-void
-send_mbox_message(spe_spu_control_area_t *ca, unsigned int msg);
+extern void
+send_mbox_message(spe_context_ptr_t ctx, unsigned int msg);
 
-uint
-wait_mbox_message(spe_spu_control_area_t *ca);
+extern uint
+wait_mbox_message(spe_context_ptr_t ctx);
 
 
 void
diff --git a/src/mesa/pipe/cell/ppu/cell_surface.c b/src/mesa/pipe/cell/ppu/cell_surface.c
index 1692960..af42a54 100644
--- a/src/mesa/pipe/cell/ppu/cell_surface.c
+++ b/src/mesa/pipe/cell/ppu/cell_surface.c
@@ -86,12 +86,12 @@ cell_clear_surface(struct pipe_context *pipe, struct pipe_surface *ps,
       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);
+      send_mbox_message(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);
+      send_mbox_message(spe_contexts[i], CELL_CMD_CLEAR_TILES);
    }
 }
 
-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to