aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2020-03-10 12:46:02 +1000
committerMarge Bot <[email protected]>2020-05-06 06:20:37 +0000
commit6befeb66070498427e139d3ff86bfd0bd15b5668 (patch)
tree7a1cf230d9a4d88fcb43556e62a55ea12c02bb38 /src/gallium
parentbcbe5b3d268b325c1138ddc29785b6b002c38af9 (diff)
gallium/util: split out zstencil clearing code.
llvmpipe will want to reuse this for it's multisample clears. Reviewed-by: Roland Scheidegger <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4122>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/auxiliary/util/u_surface.c206
-rw-r--r--src/gallium/auxiliary/util/u_surface.h6
2 files changed, 123 insertions, 89 deletions
diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c
index 527e6662f0b..fffa1493ae0 100644
--- a/src/gallium/auxiliary/util/u_surface.c
+++ b/src/gallium/auxiliary/util/u_surface.c
@@ -428,6 +428,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,
enum pipe_format format,
@@ -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);
}
diff --git a/src/gallium/auxiliary/util/u_surface.h b/src/gallium/auxiliary/util/u_surface.h
index f6149563e81..61a8d512f4c 100644
--- a/src/gallium/auxiliary/util/u_surface.h
+++ b/src/gallium/auxiliary/util/u_surface.h
@@ -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,