[Mesa-dev] [PATCH 1/2] softpipe: add integer support

Dave Airlie airlied at gmail.com
Sat Oct 8 10:07:05 PDT 2011


From: Dave Airlie <airlied at redhat.com>

This adds support to the clear and tile caches for integer storage
and clearing, avoiding any floating paths.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/gallium/drivers/softpipe/sp_clear.c          |    7 +-
 src/gallium/drivers/softpipe/sp_tex_tile_cache.c |   32 ++++-
 src/gallium/drivers/softpipe/sp_tex_tile_cache.h |    2 +
 src/gallium/drivers/softpipe/sp_tile_cache.c     |  142 +++++++++++++++++-----
 src/gallium/drivers/softpipe/sp_tile_cache.h     |    7 +-
 5 files changed, 146 insertions(+), 44 deletions(-)

diff --git a/src/gallium/drivers/softpipe/sp_clear.c b/src/gallium/drivers/softpipe/sp_clear.c
index bfb16be..3cb3b72 100644
--- a/src/gallium/drivers/softpipe/sp_clear.c
+++ b/src/gallium/drivers/softpipe/sp_clear.c
@@ -68,17 +68,16 @@ softpipe_clear(struct pipe_context *pipe, unsigned buffers,
       for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
          struct pipe_surface *ps = softpipe->framebuffer.cbufs[i];
 
-         util_pack_color(color->f, ps->format, &uc);
-         sp_tile_cache_clear(softpipe->cbuf_cache[i], color->f, uc.ui);
+         sp_tile_cache_clear(softpipe->cbuf_cache[i], color, 0);
       }
    }
 
    if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
-      static const float zero[4] = { 0.0F, 0.0F, 0.0F, 0.0F };
+      static const union pipe_color_union zero;
       struct pipe_surface *ps = softpipe->framebuffer.zsbuf;
 
       cv = util_pack_z_stencil(ps->format, depth, stencil);
-      sp_tile_cache_clear(softpipe->zsbuf_cache, zero, cv);
+      sp_tile_cache_clear(softpipe->zsbuf_cache, &zero, cv);
    }
 
    softpipe->dirty_render_cache = TRUE;
diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
index e589ee7..2e665c9 100644
--- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c
@@ -35,6 +35,7 @@
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_tile.h"
+#include "util/u_format.h"
 #include "util/u_math.h"
 #include "sp_context.h"
 #include "sp_texture.h"
@@ -228,7 +229,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
                         union tex_tile_address addr )
 {
    struct softpipe_tex_cached_tile *tile;
-   
+
    tile = tc->entries + tex_cache_pos( addr );
 
    if (addr.value != tile->addr.value) {
@@ -290,15 +291,34 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
       /* Get tile from the transfer (view into texture), explicitly passing
        * the image format.
        */
-      pipe_get_tile_rgba_format(tc->pipe,
+      if (util_format_is_pure_uint(tc->format)) {
+         pipe_get_tile_ui_format(tc->pipe,
+                                 tc->tex_trans,
+                                 addr.bits.x * TILE_SIZE,
+                                 addr.bits.y * TILE_SIZE,
+                                 TILE_SIZE,
+                                 TILE_SIZE,
+                                 tc->format,
+                                 (unsigned *) tile->data.colorui);
+      } else if (util_format_is_pure_sint(tc->format)) {
+         pipe_get_tile_i_format(tc->pipe,
                                 tc->tex_trans,
-                                addr.bits.x * TILE_SIZE, 
+                                addr.bits.x * TILE_SIZE,
                                 addr.bits.y * TILE_SIZE,
                                 TILE_SIZE,
-                                TILE_SIZE,
+                                 TILE_SIZE,
                                 tc->format,
-                                (float *) tile->data.color);
-
+                                (int *) tile->data.colori);
+      } else {
+         pipe_get_tile_rgba_format(tc->pipe,
+                                   tc->tex_trans,
+                                   addr.bits.x * TILE_SIZE,
+                                   addr.bits.y * TILE_SIZE,
+                                   TILE_SIZE,
+                                   TILE_SIZE,
+                                   tc->format,
+                                   (float *) tile->data.color);
+      }
       tile->addr = addr;
    }
 
diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h
index 9bced37..4098aa1 100644
--- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.h
+++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.h
@@ -68,6 +68,8 @@ struct softpipe_tex_cached_tile
    union tex_tile_address addr;
    union {
       float color[TILE_SIZE][TILE_SIZE][4];
+      unsigned int colorui[TILE_SIZE][TILE_SIZE][4];
+      int colori[TILE_SIZE][TILE_SIZE][4];
    } data;
 };
 
diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c
index d3d9eb9..ad6b015 100644
--- a/src/gallium/drivers/softpipe/sp_tile_cache.c
+++ b/src/gallium/drivers/softpipe/sp_tile_cache.c
@@ -219,22 +219,43 @@ sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc)
 static void
 clear_tile_rgba(struct softpipe_cached_tile *tile,
                 enum pipe_format format,
-                const float clear_value[4])
+                const union pipe_color_union *clear_value)
 {
-   if (clear_value[0] == 0.0 &&
-       clear_value[1] == 0.0 &&
-       clear_value[2] == 0.0 &&
-       clear_value[3] == 0.0) {
+   if (clear_value->f[0] == 0.0 &&
+       clear_value->f[1] == 0.0 &&
+       clear_value->f[2] == 0.0 &&
+       clear_value->f[3] == 0.0) {
       memset(tile->data.color, 0, sizeof(tile->data.color));
    }
    else {
       uint i, j;
-      for (i = 0; i < TILE_SIZE; i++) {
-         for (j = 0; j < TILE_SIZE; j++) {
-            tile->data.color[i][j][0] = clear_value[0];
-            tile->data.color[i][j][1] = clear_value[1];
-            tile->data.color[i][j][2] = clear_value[2];
-            tile->data.color[i][j][3] = clear_value[3];
+
+      if (util_format_is_pure_uint(format)) {
+         for (i = 0; i < TILE_SIZE; i++) {
+            for (j = 0; j < TILE_SIZE; j++) {
+               tile->data.colorui128[i][j][0] = clear_value->ui[0];
+               tile->data.colorui128[i][j][1] = clear_value->ui[1];
+               tile->data.colorui128[i][j][2] = clear_value->ui[2];
+               tile->data.colorui128[i][j][3] = clear_value->ui[3];
+            }
+         }
+      } else if (util_format_is_pure_sint(format)) {
+         for (i = 0; i < TILE_SIZE; i++) {
+            for (j = 0; j < TILE_SIZE; j++) {
+               tile->data.colori128[i][j][0] = clear_value->i[0];
+               tile->data.colori128[i][j][1] = clear_value->i[1];
+               tile->data.colori128[i][j][2] = clear_value->i[2];
+               tile->data.colori128[i][j][3] = clear_value->i[3];
+            }
+         }
+      } else {
+         for (i = 0; i < TILE_SIZE; i++) {
+            for (j = 0; j < TILE_SIZE; j++) {
+               tile->data.color[i][j][0] = clear_value->f[0];
+               tile->data.color[i][j][1] = clear_value->f[1];
+               tile->data.color[i][j][2] = clear_value->f[2];
+               tile->data.color[i][j][3] = clear_value->f[3];
+            }
          }
       }
    }
@@ -305,7 +326,7 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc)
    if (tc->depth_stencil) {
       clear_tile(tc->tile, pt->resource->format, tc->clear_val);
    } else {
-      clear_tile_rgba(tc->tile, pt->resource->format, tc->clear_color);
+      clear_tile_rgba(tc->tile, pt->resource->format, &tc->clear_color);
    }
 
    /* push the tile to all positions marked as clear */
@@ -322,9 +343,21 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc)
                                  tc->tile->data.any, 0/*STRIDE*/);
             }
             else {
-               pipe_put_tile_rgba(tc->pipe, pt,
-                                  x, y, TILE_SIZE, TILE_SIZE,
-                                  (float *) tc->tile->data.color);
+               if (util_format_is_pure_uint(tc->surface->format)) {
+                  pipe_put_tile_ui_format(tc->pipe, pt,
+                                          x, y, TILE_SIZE, TILE_SIZE,
+                                          pt->resource->format,
+                                          (unsigned *) tc->tile->data.colorui128);
+               } else if (util_format_is_pure_sint(tc->surface->format)) {
+                  pipe_put_tile_i_format(tc->pipe, pt,
+                                         x, y, TILE_SIZE, TILE_SIZE,
+                                         pt->resource->format,
+                                         (int *) tc->tile->data.colori128);
+               } else {
+                  pipe_put_tile_rgba(tc->pipe, pt,
+                                     x, y, TILE_SIZE, TILE_SIZE,
+                                     (float *) tc->tile->data.color);
+               }
             }
             numCleared++;
          }
@@ -351,12 +384,28 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos)
                            tc->entries[pos]->data.depth32, 0/*STRIDE*/);
       }
       else {
-         pipe_put_tile_rgba_format(tc->pipe, tc->transfer,
+         if (util_format_is_pure_uint(tc->surface->format)) {
+            pipe_put_tile_ui_format(tc->pipe, tc->transfer,
+                                    tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                    tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                    TILE_SIZE, TILE_SIZE,
+                                    tc->surface->format,
+                                    (unsigned *) tc->entries[pos]->data.colorui128);
+         } else if (util_format_is_pure_sint(tc->surface->format)) {
+            pipe_put_tile_i_format(tc->pipe, tc->transfer,
                                    tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                    tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                    TILE_SIZE, TILE_SIZE,
                                    tc->surface->format,
-                                   (float *) tc->entries[pos]->data.color);
+                                   (int *) tc->entries[pos]->data.colori128);
+         } else {
+            pipe_put_tile_rgba_format(tc->pipe, tc->transfer,
+                                      tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                      tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                      TILE_SIZE, TILE_SIZE,
+                                      tc->surface->format,
+                                      (float *) tc->entries[pos]->data.color);
+         }
       }
       tc->tile_addrs[pos].bits.invalid = 1;  /* mark as empty */
    }
@@ -439,7 +488,6 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
                     union tile_address addr )
 {
    struct pipe_transfer *pt = tc->transfer;
-   
    /* cache pos/entry: */
    const int pos = CACHE_POS(addr.bits.x,
                              addr.bits.y);
@@ -463,12 +511,28 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
                               tile->data.depth32, 0/*STRIDE*/);
          }
          else {
-            pipe_put_tile_rgba_format(tc->pipe, pt,
+            if (util_format_is_pure_uint(tc->surface->format)) {
+               pipe_put_tile_ui_format(tc->pipe, pt,
+                                      tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                      tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                      TILE_SIZE, TILE_SIZE,
+                                      tc->surface->format,
+                                      (unsigned *) tile->data.colorui128);
+            } else if (util_format_is_pure_sint(tc->surface->format)) {
+               pipe_put_tile_i_format(tc->pipe, pt,
                                       tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                       tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                       TILE_SIZE, TILE_SIZE,
                                       tc->surface->format,
-                                      (float *) tile->data.color);
+                                      (int *) tile->data.colori128);
+            } else {
+               pipe_put_tile_rgba_format(tc->pipe, pt,
+                                         tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                         tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                         TILE_SIZE, TILE_SIZE,
+                                         tc->surface->format,
+                                         (float *) tile->data.color);
+            }
          }
       }
 
@@ -480,7 +544,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
             clear_tile(tile, pt->resource->format, tc->clear_val);
          }
          else {
-            clear_tile_rgba(tile, pt->resource->format, tc->clear_color);
+            clear_tile_rgba(tile, pt->resource->format, &tc->clear_color);
          }
          clear_clear_flag(tc->clear_flags, addr);
       }
@@ -494,12 +558,28 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
                               tile->data.depth32, 0/*STRIDE*/);
          }
          else {
-            pipe_get_tile_rgba_format(tc->pipe, pt,
-                                      tc->tile_addrs[pos].bits.x * TILE_SIZE,
-                                      tc->tile_addrs[pos].bits.y * TILE_SIZE,
-                                      TILE_SIZE, TILE_SIZE,
-                                      tc->surface->format,
-                                      (float *) tile->data.color);
+            if (util_format_is_pure_uint(tc->surface->format)) {
+               pipe_get_tile_ui_format(tc->pipe, pt,
+                                         tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                         tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                         TILE_SIZE, TILE_SIZE,
+                                         tc->surface->format,
+                                         (unsigned *) tile->data.colorui128);
+            } else if (util_format_is_pure_sint(tc->surface->format)) {
+               pipe_get_tile_i_format(tc->pipe, pt,
+                                         tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                         tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                         TILE_SIZE, TILE_SIZE,
+                                         tc->surface->format,
+                                         (int *) tile->data.colori128);
+            } else {
+               pipe_get_tile_rgba_format(tc->pipe, pt,
+                                         tc->tile_addrs[pos].bits.x * TILE_SIZE,
+                                         tc->tile_addrs[pos].bits.y * TILE_SIZE,
+                                         TILE_SIZE, TILE_SIZE,
+                                         tc->surface->format,
+                                         (float *) tile->data.color);
+            }
          }
       }
    }
@@ -519,15 +599,13 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
  * Save the color and set a 'clearflag' for each tile of the screen.
  */
 void
-sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float *rgba,
+sp_tile_cache_clear(struct softpipe_tile_cache *tc,
+                    const union pipe_color_union *color,
                     uint clearValue)
 {
    uint pos;
 
-   tc->clear_color[0] = rgba[0];
-   tc->clear_color[1] = rgba[1];
-   tc->clear_color[2] = rgba[2];
-   tc->clear_color[3] = rgba[3];
+   tc->clear_color = *color;
 
    tc->clear_val = clearValue;
 
diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h
index 68140b1..88d527c 100644
--- a/src/gallium/drivers/softpipe/sp_tile_cache.h
+++ b/src/gallium/drivers/softpipe/sp_tile_cache.h
@@ -68,6 +68,8 @@ struct softpipe_cached_tile
       uint depth32[TILE_SIZE][TILE_SIZE];
       ushort depth16[TILE_SIZE][TILE_SIZE];
       ubyte stencil8[TILE_SIZE][TILE_SIZE];
+      uint colorui128[TILE_SIZE][TILE_SIZE][4];
+      int colori128[TILE_SIZE][TILE_SIZE][4];
       ubyte any[1];
    } data;
 };
@@ -85,7 +87,7 @@ struct softpipe_tile_cache
    union tile_address tile_addrs[NUM_ENTRIES];
    struct softpipe_cached_tile *entries[NUM_ENTRIES];
    uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
-   float clear_color[4];  /**< for color bufs */
+   union pipe_color_union clear_color; /**< for color bufs */
    uint clear_val;        /**< for z+stencil */
    boolean depth_stencil; /**< Is the surface a depth/stencil format? */
 
@@ -119,7 +121,8 @@ extern void
 sp_flush_tile_cache(struct softpipe_tile_cache *tc);
 
 extern void
-sp_tile_cache_clear(struct softpipe_tile_cache *tc, const float *rgba,
+sp_tile_cache_clear(struct softpipe_tile_cache *tc,
+                    const union pipe_color_union *color,
                     uint clearValue);
 
 extern struct softpipe_cached_tile *
-- 
1.7.6.2



More information about the mesa-dev mailing list