Module: Mesa
Branch: lp-surface-tiling
Commit: 92fe9952161cc06f6edc58778e9e5a8b9ea447dc
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=92fe9952161cc06f6edc58778e9e5a8b9ea447dc

Author: Brian Paul <[email protected]>
Date:   Wed Mar 24 10:15:19 2010 -0600

llvmpipe: add tiled/linear conversion for 16-bit Z images

---

 src/gallium/drivers/llvmpipe/lp_tile_image.c |  136 +++++++++++++++++++++-----
 1 files changed, 110 insertions(+), 26 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_tile_image.c 
b/src/gallium/drivers/llvmpipe/lp_tile_image.c
index f893eca..b5a3236 100644
--- a/src/gallium/drivers/llvmpipe/lp_tile_image.c
+++ b/src/gallium/drivers/llvmpipe/lp_tile_image.c
@@ -61,6 +61,26 @@ untile_4_4_uint32(const uint32_t *src, uint32_t *dst, 
unsigned dst_stride)
 
 
 /**
+ * Untile a 4x4 block of 16-bit words (all contiguous) to linear layout
+ * at dst, with dst_stride words between rows.
+ */
+static void
+untile_4_4_uint16(const uint16_t *src, uint16_t *dst, unsigned dst_stride)
+{
+   uint16_t *d0 = dst;
+   uint16_t *d1 = d0 + dst_stride;
+   uint16_t *d2 = d1 + dst_stride;
+   uint16_t *d3 = d2 + dst_stride;
+
+   d0[0] = src[0];   d0[1] = src[1];   d0[2] = src[4];   d0[3] = src[5];
+   d1[0] = src[2];   d1[1] = src[3];   d1[2] = src[6];   d1[3] = src[7];
+   d2[0] = src[8];   d2[1] = src[9];   d2[2] = src[12];  d2[3] = src[13];
+   d3[0] = src[10];  d3[1] = src[11];  d3[2] = src[14];  d3[3] = src[15];
+}
+
+
+
+/**
  * Convert a 4x4 rect of 32-bit words from a linear layout into tiled
  * layout (in which all 16 words are contiguous).
  */
@@ -81,6 +101,26 @@ tile_4_4_uint32(const uint32_t *src, uint32_t *dst, 
unsigned src_stride)
 
 
 /**
+ * Convert a 4x4 rect of 16-bit words from a linear layout into tiled
+ * layout (in which all 16 words are contiguous).
+ */
+static void
+tile_4_4_uint16(const uint16_t *src, uint16_t *dst, unsigned src_stride)
+{
+   const uint16_t *s0 = src;
+   const uint16_t *s1 = s0 + src_stride;
+   const uint16_t *s2 = s1 + src_stride;
+   const uint16_t *s3 = s2 + src_stride;
+
+   dst[0] = s0[0];   dst[1] = s0[1];   dst[4] = s0[2];   dst[5] = s0[3];
+   dst[2] = s1[0];   dst[3] = s1[1];   dst[6] = s1[2];   dst[7] = s1[3];
+   dst[8] = s2[0];   dst[9] = s2[1];   dst[12] = s2[2];  dst[13] = s2[3];
+   dst[10] = s3[0];  dst[11] = s3[1];  dst[14] = s3[2];  dst[15] = s3[3];
+}
+
+
+
+/**
  * Convert a tiled image into a linear image.
  * \param src_stride  source row stride in bytes (bytes per row of tiles)
  * \param dst_stride  dest row stride in bytes
@@ -94,25 +134,47 @@ lp_tiled_to_linear(const void *src, void *dst,
     * color surfaces.
     */
    if (util_format_is_depth_or_stencil(format)) {
+      const uint bpp = util_format_get_blocksize(format);
       const uint src_stride = dst_stride * TILE_VECTOR_WIDTH;
-      const uint bpp = 4;
       const uint tile_w = TILE_VECTOR_WIDTH, tile_h = TILE_VECTOR_HEIGHT;
       const uint tiles_per_row = src_stride / (tile_w * tile_h * bpp);
-      const uint32_t *src32 = (const uint32_t *) src;
-      uint32_t *dst32 = (uint32_t *) dst;
-      uint i, j;
 
       dst_stride /= bpp;   /* convert from bytes to words */
 
-      for (j = 0; j < height; j += tile_h) {
-         for (i = 0; i < width; i += tile_w) {
-            /* compute offsets in 32-bit words */
-            uint src_offset =
-               (j / tile_h * tiles_per_row + i / tile_w) * (tile_w * tile_h);
-            uint dst_offset = j * dst_stride + i;
-            untile_4_4_uint32(src32 + src_offset,
-                              dst32 + dst_offset,
-                              dst_stride);
+      if (bpp == 4) {
+         const uint32_t *src32 = (const uint32_t *) src;
+         uint32_t *dst32 = (uint32_t *) dst;
+         uint i, j;
+
+         for (j = 0; j < height; j += tile_h) {
+            for (i = 0; i < width; i += tile_w) {
+               /* compute offsets in 32-bit words */
+               uint src_offset =
+                  (j / tile_h * tiles_per_row + i / tile_w) * (tile_w * 
tile_h);
+               uint dst_offset = j * dst_stride + i;
+               untile_4_4_uint32(src32 + src_offset,
+                                 dst32 + dst_offset,
+                                 dst_stride);
+            }
+         }
+      }
+      else {
+         const uint16_t *src16 = (const uint16_t *) src;
+         uint16_t *dst16 = (uint16_t *) dst;
+         uint i, j;
+
+         assert(bpp == 2);
+
+         for (j = 0; j < height; j += tile_h) {
+            for (i = 0; i < width; i += tile_w) {
+               /* compute offsets in 16-bit words */
+               uint src_offset =
+                  (j / tile_h * tiles_per_row + i / tile_w) * (tile_w * 
tile_h);
+               uint dst_offset = j * dst_stride + i;
+               untile_4_4_uint16(src16 + src_offset,
+                                 dst16 + dst_offset,
+                                 dst_stride);
+            }
          }
       }
    }
@@ -153,25 +215,47 @@ lp_linear_to_tiled(const void *src, void *dst,
                    enum pipe_format format, unsigned src_stride)
 {
    if (util_format_is_depth_or_stencil(format)) {
+      const uint bpp = util_format_get_blocksize(format);
       const uint dst_stride = src_stride * TILE_VECTOR_WIDTH;
-      const uint bpp = 4;
       const uint tile_w = TILE_VECTOR_WIDTH, tile_h = TILE_VECTOR_HEIGHT;
       const uint tiles_per_row = dst_stride / (tile_w * tile_h * bpp);
-      const uint32_t *src32 = (const uint32_t *) src;
-      uint32_t *dst32 = (uint32_t *) dst;
-      uint i, j;
 
       src_stride /= bpp;   /* convert from bytes to words */
 
-      for (j = 0; j < height; j += tile_h) {
-         for (i = 0; i < width; i += tile_w) {
-            /* compute offsets in 32-bit words */
-            uint src_offset = j * src_stride + i;
-            uint dst_offset =
-               (j / tile_h * tiles_per_row + i / tile_w) * (tile_w * tile_h);
-            tile_4_4_uint32(src32 + src_offset,
-                            dst32 + dst_offset,
-                            src_stride);
+      if (bpp == 4) {
+         const uint32_t *src32 = (const uint32_t *) src;
+         uint32_t *dst32 = (uint32_t *) dst;
+         uint i, j;
+
+         for (j = 0; j < height; j += tile_h) {
+            for (i = 0; i < width; i += tile_w) {
+               /* compute offsets in 32-bit words */
+               uint src_offset = j * src_stride + i;
+               uint dst_offset = (j / tile_h * tiles_per_row + i / tile_w)
+                  * (tile_w * tile_h);
+               tile_4_4_uint32(src32 + src_offset,
+                               dst32 + dst_offset,
+                               src_stride);
+            }
+         }
+      }
+      else {
+         const uint16_t *src16 = (const uint16_t *) src;
+         uint16_t *dst16 = (uint16_t *) dst;
+         uint i, j;
+
+         assert(bpp == 2);
+
+         for (j = 0; j < height; j += tile_h) {
+            for (i = 0; i < width; i += tile_w) {
+               /* compute offsets in 16-bit words */
+               uint src_offset = j * src_stride + i;
+               uint dst_offset = (j / tile_h * tiles_per_row + i / tile_w)
+                  * (tile_w * tile_h);
+               tile_4_4_uint16(src16 + src_offset,
+                               dst16 + dst_offset,
+                               src_stride);
+            }
          }
       }
    }

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to