util: Merge util_format_read_4* functions.
[mesa.git] / src / gallium / auxiliary / util / u_tile.c
index ed76a7ef83d2ef450fe71a71e4451c18765ac170..5677074903090175bf8f74d913a6dbcc236bd586 100644 (file)
@@ -27,7 +27,7 @@
 
 /**
  * RGBA/float tile get/put functions.
- * Usable both by drivers and state trackers.
+ * Usable both by drivers and gallium frontends.
  */
 
 
@@ -354,93 +354,35 @@ x32_s8_get_tile_rgba(const unsigned *src,
    }
 }
 
-static void
-pipe_tile_raw_to_rgba(enum pipe_format format,
-                      const void *src,
-                      uint w, uint h,
-                      float *dst, unsigned dst_stride)
+void
+pipe_put_tile_rgba(struct pipe_transfer *pt,
+                   void *dst,
+                   uint x, uint y, uint w, uint h,
+                   enum pipe_format format, const void *p)
 {
-   switch (format) {
-   case PIPE_FORMAT_Z16_UNORM:
-      z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_Z32_UNORM:
-      z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-   case PIPE_FORMAT_Z24X8_UNORM:
-      s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_S8_UINT:
-      s8_get_tile_rgba((unsigned char *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_X24S8_UINT:
-      s8x24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-   case PIPE_FORMAT_X8Z24_UNORM:
-      z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_S8X24_UINT:
-      x24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_Z32_FLOAT:
-      z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-      z32f_x24s8_get_tile_rgba((float *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_X32_S8X24_UINT:
-      x32_s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   default:
-      util_format_read_4f(format,
-                          dst, dst_stride * sizeof(float),
-                          src, util_format_get_stride(format, w),
-                          0, 0, w, h);
-   }
-}
+   unsigned src_stride = w * 4;
 
-static void
-pipe_tile_raw_to_unsigned(enum pipe_format format,
-                          const void *src,
-                          uint w, uint h,
-                          unsigned *dst, unsigned dst_stride)
-{
-  util_format_read_4ui(format,
-                       dst, dst_stride * sizeof(float),
-                       src, util_format_get_stride(format, w),
-                       0, 0, w, h);
-}
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
+      return;
 
-static void
-pipe_tile_raw_to_signed(enum pipe_format format,
-                          void *src,
-                          uint w, uint h,
-                          int *dst, unsigned dst_stride)
-{
-  util_format_read_4i(format,
-                      dst, dst_stride * sizeof(float),
-                      src, util_format_get_stride(format, w),
-                      0, 0, w, h);
+   /* While we do generate RGBA tiles for z/s for softpipe's texture fetch
+    * path, we never have to store from "RGBA" to Z/S.
+    */
+   if (util_format_is_depth_or_stencil(format))
+      return;
+
+   util_format_write_4(format,
+                       p, src_stride * sizeof(float),
+                       dst, pt->stride,
+                       x, y, w, h);
 }
 
 void
 pipe_get_tile_rgba(struct pipe_transfer *pt,
                    const void *src,
                    uint x, uint y, uint w, uint h,
-                   float *p)
-{
-   pipe_get_tile_rgba_format(pt, src, x, y, w, h, pt->resource->format, p);
-}
-
-
-void
-pipe_get_tile_rgba_format(struct pipe_transfer *pt,
-                          const void *src,
-                          uint x, uint y, uint w, uint h,
-                          enum pipe_format format,
-                          float *p)
+                   enum pipe_format format,
+                   void *dst)
 {
    unsigned dst_stride = w * 4;
    void *packed;
@@ -460,186 +402,45 @@ pipe_get_tile_rgba_format(struct pipe_transfer *pt,
 
    pipe_get_tile_raw(pt, src, x, y, w, h, packed, 0);
 
-   pipe_tile_raw_to_rgba(format, packed, w, h, p, dst_stride);
-
-   FREE(packed);
-}
-
-
-void
-pipe_put_tile_rgba(struct pipe_transfer *pt,
-                   void *dst,
-                   uint x, uint y, uint w, uint h,
-                   const float *p)
-{
-   pipe_put_tile_rgba_format(pt, dst, x, y, w, h, pt->resource->format, p);
-}
-
-
-void
-pipe_put_tile_rgba_format(struct pipe_transfer *pt,
-                          void *dst,
-                          uint x, uint y, uint w, uint h,
-                          enum pipe_format format,
-                          const float *p)
-{
-   unsigned src_stride = w * 4;
-   void *packed;
-
-   if (u_clip_tile(x, y, &w, &h, &pt->box))
-      return;
-
-   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-
-   if (!packed)
-      return;
-
    switch (format) {
    case PIPE_FORMAT_Z16_UNORM:
-      /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
+      z16_get_tile_rgba((ushort *) packed, w, h, dst, dst_stride);
       break;
    case PIPE_FORMAT_Z32_UNORM:
-      /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+      z32_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
       break;
    case PIPE_FORMAT_Z24_UNORM_S8_UINT:
    case PIPE_FORMAT_Z24X8_UNORM:
-      /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+      s8z24_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
+      break;
+   case PIPE_FORMAT_S8_UINT:
+      s8_get_tile_rgba((unsigned char *) packed, w, h, dst, dst_stride);
+      break;
+   case PIPE_FORMAT_X24S8_UINT:
+      s8x24_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
       break;
    case PIPE_FORMAT_S8_UINT_Z24_UNORM:
    case PIPE_FORMAT_X8Z24_UNORM:
-      /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+      z24s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
+      break;
+   case PIPE_FORMAT_S8X24_UINT:
+      x24s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
       break;
    case PIPE_FORMAT_Z32_FLOAT:
-      /*z32f_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+      z32f_get_tile_rgba((float *) packed, w, h, dst, dst_stride);
       break;
    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-      /*z32f_s8x24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
+      z32f_x24s8_get_tile_rgba((float *) packed, w, h, dst, dst_stride);
+      break;
+   case PIPE_FORMAT_X32_S8X24_UINT:
+      x32_s8_get_tile_rgba((unsigned *) packed, w, h, dst, dst_stride);
       break;
    default:
-      util_format_write_4f(format,
-                           p, src_stride * sizeof(float),
-                           packed, util_format_get_stride(format, w),
-                           0, 0, w, h);
-   }
-
-   pipe_put_tile_raw(pt, dst, x, y, w, h, packed, 0);
-
-   FREE(packed);
-}
-
-void
-pipe_put_tile_i_format(struct pipe_transfer *pt,
-                       void *dst,
-                       uint x, uint y, uint w, uint h,
-                       enum pipe_format format,
-                       const int *p)
-{
-   unsigned src_stride = w * 4;
-   void *packed;
-
-   if (u_clip_tile(x, y, &w, &h, &pt->box))
-      return;
-
-   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-
-   if (!packed)
-      return;
-
-   util_format_write_4i(format,
-                        p, src_stride * sizeof(float),
-                        packed, util_format_get_stride(format, w),
-                        0, 0, w, h);
-
-   pipe_put_tile_raw(pt, dst, x, y, w, h, packed, 0);
-
-   FREE(packed);
-}
-
-void
-pipe_put_tile_ui_format(struct pipe_transfer *pt,
-                        void *dst,
-                        uint x, uint y, uint w, uint h,
-                        enum pipe_format format,
-                        const unsigned int *p)
-{
-   unsigned src_stride = w * 4;
-   void *packed;
-
-   if (u_clip_tile(x, y, &w, &h, &pt->box))
-      return;
-
-   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-
-   if (!packed)
-      return;
-
-   util_format_write_4ui(format,
-                         p, src_stride * sizeof(float),
+      util_format_read_4(format,
+                         dst, dst_stride * sizeof(float),
                          packed, util_format_get_stride(format, w),
                          0, 0, w, h);
-
-   pipe_put_tile_raw(pt, dst, x, y, w, h, packed, 0);
-
-   FREE(packed);
-}
-
-void
-pipe_get_tile_ui_format(struct pipe_transfer *pt,
-                        const void *src,
-                        uint x, uint y, uint w, uint h,
-                        enum pipe_format format,
-                        unsigned int *p)
-{
-   unsigned dst_stride = w * 4;
-   void *packed;
-
-   if (u_clip_tile(x, y, &w, &h, &pt->box)) {
-      return;
-   }
-
-   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-   if (!packed) {
-      return;
-   }
-
-   if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
-      assert((x & 1) == 0);
-   }
-
-   pipe_get_tile_raw(pt, src, x, y, w, h, packed, 0);
-
-   pipe_tile_raw_to_unsigned(format, packed, w, h, p, dst_stride);
-
-   FREE(packed);
-}
-
-
-void
-pipe_get_tile_i_format(struct pipe_transfer *pt,
-                       const void *src,
-                       uint x, uint y, uint w, uint h,
-                       enum pipe_format format,
-                       int *p)
-{
-   unsigned dst_stride = w * 4;
-   void *packed;
-
-   if (u_clip_tile(x, y, &w, &h, &pt->box)) {
-      return;
-   }
-
-   packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
-   if (!packed) {
-      return;
-   }
-
-   if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
-      assert((x & 1) == 0);
    }
 
-   pipe_get_tile_raw(pt, src, x, y, w, h, packed, 0);
-
-   pipe_tile_raw_to_signed(format, packed, w, h, p, dst_stride);
-
    FREE(packed);
 }