Cell: use global color_shuffle to remove a switch stmnt
authorBrian <brian.paul@tungstengraphics.com>
Fri, 1 Feb 2008 23:25:42 +0000 (16:25 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 1 Feb 2008 23:25:42 +0000 (16:25 -0700)
src/mesa/pipe/cell/spu/Makefile
src/mesa/pipe/cell/spu/spu_colorpack.h
src/mesa/pipe/cell/spu/spu_main.c
src/mesa/pipe/cell/spu/spu_main.h
src/mesa/pipe/cell/spu/spu_tri.c

index 2d031bfbc61202a1af0f59e9291cc95f6801bec0..91a631b6992b96c27ab5008a937e1f05355e88ff 100644 (file)
@@ -8,6 +8,8 @@ TOP = ../../../../..
 include $(TOP)/configs/linux-cell
 
 
+OPT_FLAGS=-g
+OPT_FLAGS=-O3
 PROG = g3d
 
 PROG_SPU = $(PROG)_spu
index 56709bd9f3883a093491248bb928c96de804e044..9977a6ece0eeec5837a026b7f255b380f877b8cf 100644 (file)
@@ -57,4 +57,13 @@ spu_pack_B8G8R8A8(vector float rgba)
 }
 
 
+static INLINE unsigned int
+spu_pack_color_shuffle(vector float rgba, vector unsigned char shuffle)
+{
+  vector unsigned int out = spu_convtu(rgba, 32);
+  out = spu_shuffle(out, out, shuffle);
+  return spu_extract(out, 0);
+}
+
+
 #endif /* SPU_COLORPACK_H */
index 8e3987f6ef53099fcb445d431d1e53f832faeb64..ba4d180cc0cbb598027923e6b7a4b747257c4f20 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <stdio.h>
 #include <libmisc.h>
+#include <vec_literal.h>
 
 #include "spu_main.h"
 #include "spu_render.h"
@@ -217,6 +218,17 @@ cmd_state_framebuffer(const struct cell_command_framebuffer *cmd)
       spu.fb.zsize = 2;
    else
       spu.fb.zsize = 0;
+
+   if (spu.fb.color_format == PIPE_FORMAT_A8R8G8B8_UNORM)
+      spu.color_shuffle = VEC_LITERAL(vector unsigned char,
+                                      12, 0, 4, 8, 0, 0, 0, 0, 
+                                      0, 0, 0, 0, 0, 0, 0, 0);
+   else if (spu.fb.color_format == PIPE_FORMAT_B8G8R8A8_UNORM)
+      spu.color_shuffle = VEC_LITERAL(vector unsigned char,
+                                      8, 4, 0, 12, 0, 0, 0, 0, 
+                                      0, 0, 0, 0, 0, 0, 0, 0);
+   else
+      ASSERT(0);
 }
 
 
index cce5e708021e33d619b380546763cd437615a9f1..7a12715b0bcfac13ae890bed2a93e5c210b80476 100644 (file)
@@ -107,6 +107,9 @@ struct spu_global
    ubyte ctile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
    ubyte ztile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
 
+
+   /** for converting RGBA to PIPE_FORMAT_x colors */
+   vector unsigned char color_shuffle;
 } ALIGN16_ATTRIB;
 
 
index c82ca51000e1aca85b946f3d38be087adde92066..165e41a7819b56157fe2ec4068bfe71a3f1cf784 100644 (file)
@@ -249,28 +249,6 @@ eval_z(float x, float y)
 }
 
 
-static INLINE void
-pack_colors(uint uicolors[4], const float4 fcolors[4])
-{
-   switch (spu.fb.color_format) {
-   case PIPE_FORMAT_A8R8G8B8_UNORM:
-      uicolors[0] = spu_pack_A8R8G8B8(fcolors[0].v);
-      uicolors[1] = spu_pack_A8R8G8B8(fcolors[1].v);
-      uicolors[2] = spu_pack_A8R8G8B8(fcolors[2].v);
-      uicolors[3] = spu_pack_A8R8G8B8(fcolors[3].v);
-      break;
-   case PIPE_FORMAT_B8G8R8A8_UNORM:
-      uicolors[0] = spu_pack_B8G8R8A8(fcolors[0].v);
-      uicolors[1] = spu_pack_B8G8R8A8(fcolors[1].v);
-      uicolors[2] = spu_pack_B8G8R8A8(fcolors[2].v);
-      uicolors[3] = spu_pack_B8G8R8A8(fcolors[3].v);
-      break;
-   default:
-      ASSERT(0);
-   }
-}
-
-
 static INLINE mask_t
 do_depth_test(int x, int y, mask_t quadmask)
 {
@@ -321,38 +299,44 @@ emit_quad( int x, int y, mask_t mask )
    if (spu_extract(spu_orx(mask), 0)) {
       const int ix = x - setup.cliprect_minx;
       const int iy = y - setup.cliprect_miny;
-      uint colors[4];  /* indexed by QUAD_x */
+
+      if (spu.cur_ctile_status == TILE_STATUS_CLEAR) {
+         /* now, _really_ clear the tile */
+         clear_c_tile(&spu.ctile);
+      }
+      spu.cur_ctile_status = TILE_STATUS_DIRTY;
 
       if (spu.texture.start) {
+         /* texture mapping */
          float4 texcoords[4];
-         uint i;
          eval_coeff(2, (float) x, (float) y, texcoords);
-         for (i = 0; i < 4; i++) {
-            colors[i] = sample_texture(texcoords[i]);
-         }
+
+         if (spu_extract(mask, 0))
+            spu.ctile.ui[iy][ix] = sample_texture(texcoords[0]);
+         if (spu_extract(mask, 1))
+            spu.ctile.ui[iy][ix+1] = sample_texture(texcoords[1]);
+         if (spu_extract(mask, 2))
+            spu.ctile.ui[iy+1][ix] = sample_texture(texcoords[2]);
+         if (spu_extract(mask, 3))
+            spu.ctile.ui[iy+1][ix+1] = sample_texture(texcoords[3]);
       }
       else {
-         float4 fcolors[4];
-         eval_coeff(1, (float) x, (float) y, fcolors);
-         pack_colors(colors, fcolors);
+         /* simple shading */
+         const vector unsigned char shuffle = spu.color_shuffle;
+         float4 colors[4];
+         eval_coeff(1, (float) x, (float) y, colors);
+
+         if (spu_extract(mask, 0))
+            spu.ctile.ui[iy][ix] = spu_pack_color_shuffle(colors[0].v, shuffle);
+         if (spu_extract(mask, 1))
+            spu.ctile.ui[iy][ix+1] = spu_pack_color_shuffle(colors[1].v, shuffle);
+         if (spu_extract(mask, 2))
+            spu.ctile.ui[iy+1][ix] = spu_pack_color_shuffle(colors[2].v, shuffle);
+         if (spu_extract(mask, 3))
+            spu.ctile.ui[iy+1][ix+1] = spu_pack_color_shuffle(colors[3].v, shuffle);
       }
 
-      if (spu.cur_ctile_status == TILE_STATUS_CLEAR) {
-         /* now, _really_ clear the tile */
-         clear_c_tile(&spu.ctile);
-      }
-      spu.cur_ctile_status = TILE_STATUS_DIRTY;
-
-#if 1
-      if (spu_extract(mask, 0))
-         spu.ctile.ui[iy][ix] = colors[QUAD_TOP_LEFT];
-      if (spu_extract(mask, 1))
-         spu.ctile.ui[iy][ix+1] = colors[QUAD_TOP_RIGHT];
-      if (spu_extract(mask, 2))
-         spu.ctile.ui[iy+1][ix] = colors[QUAD_BOTTOM_LEFT];
-      if (spu_extract(mask, 3))
-         spu.ctile.ui[iy+1][ix+1] = colors[QUAD_BOTTOM_RIGHT];
-#else
+#if 0
       /* SIMD_Z with swizzled color buffer (someday) */
       vector unsigned int uicolors = *((vector unsigned int *) &colors);
       spu.ctile.ui4[iy/2][ix/2] = spu_sel(spu.ctile.ui4[iy/2][ix/2], uicolors, mask);