From 6befeb66070498427e139d3ff86bfd0bd15b5668 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 10 Mar 2020 12:46:02 +1000 Subject: [PATCH] gallium/util: split out zstencil clearing code. llvmpipe will want to reuse this for it's multisample clears. Reviewed-by: Roland Scheidegger Part-of: --- src/gallium/auxiliary/util/u_surface.c | 206 ++++++++++++++----------- src/gallium/auxiliary/util/u_surface.h | 6 + 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 @@ -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); } 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, -- 2.30.2