gallium/util: split out zstencil clearing code.
authorDave Airlie <airlied@redhat.com>
Tue, 10 Mar 2020 02:46:02 +0000 (12:46 +1000)
committerMarge Bot <eric+marge@anholt.net>
Wed, 6 May 2020 06:20:37 +0000 (06:20 +0000)
llvmpipe will want to reuse this for it's multisample clears.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>

src/gallium/auxiliary/util/u_surface.c
src/gallium/auxiliary/util/u_surface.h

index 527e6662f0b243da0d15c9e19082a779f03a487e..fffa1493ae0d98b034647add2bc20a6adfe74ac0 100644 (file)
@@ -427,6 +427,119 @@ util_clear_render_target(struct pipe_context *pipe,
    }
 }
 
+static void
+util_fill_zs_rect(ubyte *dst_map,
+                  enum pipe_format format,
+                  bool need_rmw,
+                  unsigned clear_flags,
+                  unsigned dst_stride,
+                  unsigned width,
+                  unsigned height,
+                  uint64_t zstencil)
+{
+   unsigned i, j;
+   switch (util_format_get_blocksize(format)) {
+   case 1:
+      assert(format == PIPE_FORMAT_S8_UINT);
+      if(dst_stride == width)
+         memset(dst_map, (uint8_t) zstencil, height * width);
+      else {
+         for (i = 0; i < height; i++) {
+            memset(dst_map, (uint8_t) zstencil, width);
+            dst_map += dst_stride;
+         }
+      }
+      break;
+   case 2:
+      assert(format == PIPE_FORMAT_Z16_UNORM);
+      for (i = 0; i < height; i++) {
+         uint16_t *row = (uint16_t *)dst_map;
+         for (j = 0; j < width; j++)
+            *row++ = (uint16_t) zstencil;
+         dst_map += dst_stride;
+      }
+      break;
+   case 4:
+      if (!need_rmw) {
+         for (i = 0; i < height; i++) {
+            util_memset32(dst_map, (uint32_t)zstencil, width);
+            dst_map += dst_stride;
+         }
+      }
+      else {
+         uint32_t dst_mask;
+         if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT)
+            dst_mask = 0x00ffffff;
+         else {
+            assert(format == PIPE_FORMAT_S8_UINT_Z24_UNORM);
+            dst_mask = 0xffffff00;
+         }
+         if (clear_flags & PIPE_CLEAR_DEPTH)
+            dst_mask = ~dst_mask;
+         for (i = 0; i < height; i++) {
+            uint32_t *row = (uint32_t *)dst_map;
+            for (j = 0; j < width; j++) {
+               uint32_t tmp = *row & dst_mask;
+               *row++ = tmp | ((uint32_t) zstencil & ~dst_mask);
+            }
+            dst_map += dst_stride;
+         }
+      }
+      break;
+   case 8:
+      if (!need_rmw) {
+         for (i = 0; i < height; i++) {
+            uint64_t *row = (uint64_t *)dst_map;
+            for (j = 0; j < width; j++)
+               *row++ = zstencil;
+            dst_map += dst_stride;
+         }
+      }
+      else {
+         uint64_t src_mask;
+
+         if (clear_flags & PIPE_CLEAR_DEPTH)
+            src_mask = 0x00000000ffffffffull;
+         else
+            src_mask = 0x000000ff00000000ull;
+
+         for (i = 0; i < height; i++) {
+            uint64_t *row = (uint64_t *)dst_map;
+            for (j = 0; j < width; j++) {
+               uint64_t tmp = *row & ~src_mask;
+               *row++ = tmp | (zstencil & src_mask);
+            }
+            dst_map += dst_stride;
+         }
+      }
+      break;
+   default:
+      assert(0);
+      break;
+   }
+}
+
+void
+util_fill_zs_box(ubyte *dst,
+                 enum pipe_format format,
+                 bool need_rmw,
+                 unsigned clear_flags,
+                 unsigned stride,
+                 unsigned layer_stride,
+                 unsigned width,
+                 unsigned height,
+                 unsigned depth,
+                 uint64_t zstencil)
+{
+   unsigned layer;
+
+   for (layer = 0; layer < depth; layer++) {
+      util_fill_zs_rect(dst, format, need_rmw, clear_flags, stride,
+                        width, height, zstencil);
+      dst += layer_stride;
+   }
+}
+
 static void
 util_clear_depth_stencil_texture(struct pipe_context *pipe,
                                  struct pipe_resource *texture,
@@ -439,9 +552,6 @@ util_clear_depth_stencil_texture(struct pipe_context *pipe,
    struct pipe_transfer *dst_trans;
    ubyte *dst_map;
    boolean need_rmw = FALSE;
-   unsigned dst_stride;
-   ubyte *dst_layer;
-   unsigned i, j, layer;
 
    if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) &&
        ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
@@ -459,94 +569,12 @@ util_clear_depth_stencil_texture(struct pipe_context *pipe,
    if (!dst_map)
       return;
 
-   dst_stride = dst_trans->stride;
-   dst_layer = dst_map;
    assert(dst_trans->stride > 0);
 
-   for (layer = 0; layer < depth; layer++) {
-      dst_map = dst_layer;
-
-      switch (util_format_get_blocksize(format)) {
-      case 1:
-         assert(format == PIPE_FORMAT_S8_UINT);
-         if(dst_stride == width)
-            memset(dst_map, (uint8_t) zstencil, height * width);
-         else {
-            for (i = 0; i < height; i++) {
-               memset(dst_map, (uint8_t) zstencil, width);
-               dst_map += dst_stride;
-            }
-         }
-         break;
-      case 2:
-         assert(format == PIPE_FORMAT_Z16_UNORM);
-         for (i = 0; i < height; i++) {
-            uint16_t *row = (uint16_t *)dst_map;
-            for (j = 0; j < width; j++)
-               *row++ = (uint16_t) zstencil;
-            dst_map += dst_stride;
-            }
-         break;
-      case 4:
-         if (!need_rmw) {
-            for (i = 0; i < height; i++) {
-               util_memset32(dst_map, (uint32_t)zstencil, width);
-               dst_map += dst_stride;
-            }
-         }
-         else {
-            uint32_t dst_mask;
-            if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT)
-               dst_mask = 0x00ffffff;
-            else {
-               assert(format == PIPE_FORMAT_S8_UINT_Z24_UNORM);
-               dst_mask = 0xffffff00;
-            }
-            if (clear_flags & PIPE_CLEAR_DEPTH)
-               dst_mask = ~dst_mask;
-            for (i = 0; i < height; i++) {
-               uint32_t *row = (uint32_t *)dst_map;
-               for (j = 0; j < width; j++) {
-                  uint32_t tmp = *row & dst_mask;
-                  *row++ = tmp | ((uint32_t) zstencil & ~dst_mask);
-               }
-               dst_map += dst_stride;
-            }
-         }
-         break;
-      case 8:
-         if (!need_rmw) {
-            for (i = 0; i < height; i++) {
-               uint64_t *row = (uint64_t *)dst_map;
-               for (j = 0; j < width; j++)
-                  *row++ = zstencil;
-               dst_map += dst_stride;
-            }
-         }
-         else {
-            uint64_t src_mask;
-
-            if (clear_flags & PIPE_CLEAR_DEPTH)
-               src_mask = 0x00000000ffffffffull;
-            else
-               src_mask = 0x000000ff00000000ull;
-
-            for (i = 0; i < height; i++) {
-               uint64_t *row = (uint64_t *)dst_map;
-               for (j = 0; j < width; j++) {
-                  uint64_t tmp = *row & ~src_mask;
-                  *row++ = tmp | (zstencil & src_mask);
-               }
-               dst_map += dst_stride;
-            }
-         }
-         break;
-      default:
-         assert(0);
-         break;
-      }
-      dst_layer += dst_trans->layer_stride;
-   }
+   util_fill_zs_box(dst_map, format, need_rmw, clear_flags,
+                    dst_trans->stride,
+                    dst_trans->layer_stride, width, height,
+                    depth, zstencil);
 
    pipe->transfer_unmap(pipe, dst_trans);
 }
index f6149563e81b49c61eef7222cd803e126c316a79..61a8d512f4c4f3d6122662d96abb0a3f06e8e34b 100644 (file)
@@ -66,6 +66,12 @@ util_fill_box(ubyte * dst, enum pipe_format format,
               unsigned width, unsigned height, unsigned depth,
               union util_color *uc);
 
+extern void
+util_fill_zs_box(ubyte *dst, enum pipe_format format,
+                 bool need_rmw, unsigned clear_flags, unsigned stride,
+                 unsigned layer_stride, unsigned width,
+                 unsigned height, unsigned depth,
+                 uint64_t zstencil);
 
 extern void
 util_resource_copy_region(struct pipe_context *pipe,