}
}
+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,
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) &&
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);
}