util: fix util_clear_render_target and util_clear_depth_stencil layer handling

These functions must clear all bound layers, not just the first.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Roland Scheidegger
2013-06-07 21:10:59 +02:00
parent 201d7a352b
commit b47d13f425

View File

@@ -307,6 +307,7 @@ no_src_map:
* cpp > 4 looks like a gross hack at best... * cpp > 4 looks like a gross hack at best...
* Plus can't use these transfer fallbacks when clearing * Plus can't use these transfer fallbacks when clearing
* multisampled surfaces for instance. * multisampled surfaces for instance.
* Clears all bound layers.
*/ */
void void
util_clear_render_target(struct pipe_context *pipe, util_clear_render_target(struct pipe_context *pipe,
@@ -316,8 +317,9 @@ util_clear_render_target(struct pipe_context *pipe,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
struct pipe_transfer *dst_trans; struct pipe_transfer *dst_trans;
void *dst_map; ubyte *dst_map;
union util_color uc; union util_color uc;
unsigned max_layer, layer;
assert(dst->texture); assert(dst->texture);
if (!dst->texture) if (!dst->texture)
@@ -332,6 +334,7 @@ util_clear_render_target(struct pipe_context *pipe,
unsigned pixstride = util_format_get_blocksize(dst->format); unsigned pixstride = util_format_get_blocksize(dst->format);
dx = (dst->u.buf.first_element + dstx) * pixstride; dx = (dst->u.buf.first_element + dstx) * pixstride;
w = width * pixstride; w = width * pixstride;
max_layer = 0;
dst_map = pipe_transfer_map(pipe, dst_map = pipe_transfer_map(pipe,
dst->texture, dst->texture,
0, 0, 0, 0,
@@ -340,14 +343,13 @@ util_clear_render_target(struct pipe_context *pipe,
&dst_trans); &dst_trans);
} }
else { else {
/* XXX: should handle multiple layers */ max_layer = dst->u.tex.last_layer - dst->u.tex.first_layer;
dst_map = pipe_transfer_map(pipe, dst_map = pipe_transfer_map_3d(pipe,
dst->texture, dst->texture,
dst->u.tex.level, dst->u.tex.level,
dst->u.tex.first_layer, PIPE_TRANSFER_WRITE,
PIPE_TRANSFER_WRITE, dstx, dsty, dst->u.tex.first_layer,
dstx, dsty, width, height, &dst_trans); width, height, max_layer, &dst_trans);
} }
assert(dst_map); assert(dst_map);
@@ -373,9 +375,13 @@ util_clear_render_target(struct pipe_context *pipe,
else { else {
util_pack_color(color->f, dst->format, &uc); util_pack_color(color->f, dst->format, &uc);
} }
util_fill_rect(dst_map, dst->format,
dst_trans->stride, for (layer = 0; layer <= max_layer; layer++) {
0, 0, width, height, &uc); util_fill_rect(dst_map, dst->format,
dst_trans->stride,
0, 0, width, height, &uc);
dst_map += dst_trans->layer_stride;
}
pipe->transfer_unmap(pipe, dst_trans); pipe->transfer_unmap(pipe, dst_trans);
} }
@@ -386,6 +392,7 @@ util_clear_render_target(struct pipe_context *pipe,
* sw fallback doesn't look terribly useful here. * sw fallback doesn't look terribly useful here.
* Plus can't use these transfer fallbacks when clearing * Plus can't use these transfer fallbacks when clearing
* multisampled surfaces for instance. * multisampled surfaces for instance.
* Clears all bound layers.
*/ */
void void
util_clear_depth_stencil(struct pipe_context *pipe, util_clear_depth_stencil(struct pipe_context *pipe,
@@ -400,6 +407,7 @@ util_clear_depth_stencil(struct pipe_context *pipe,
struct pipe_transfer *dst_trans; struct pipe_transfer *dst_trans;
ubyte *dst_map; ubyte *dst_map;
boolean need_rmw = FALSE; boolean need_rmw = FALSE;
unsigned max_layer, layer;
if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) && if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) &&
((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) && ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
@@ -409,102 +417,110 @@ util_clear_depth_stencil(struct pipe_context *pipe,
assert(dst->texture); assert(dst->texture);
if (!dst->texture) if (!dst->texture)
return; return;
dst_map = pipe_transfer_map(pipe,
dst->texture, max_layer = dst->u.tex.last_layer - dst->u.tex.first_layer;
dst->u.tex.level, dst_map = pipe_transfer_map_3d(pipe,
dst->u.tex.first_layer, dst->texture,
(need_rmw ? PIPE_TRANSFER_READ_WRITE : dst->u.tex.level,
PIPE_TRANSFER_WRITE), (need_rmw ? PIPE_TRANSFER_READ_WRITE :
dstx, dsty, width, height, &dst_trans); PIPE_TRANSFER_WRITE),
dstx, dsty, dst->u.tex.first_layer,
width, height, max_layer + 1, &dst_trans);
assert(dst_map); assert(dst_map);
if (dst_map) { if (dst_map) {
unsigned dst_stride = dst_trans->stride; unsigned dst_stride = dst_trans->stride;
uint64_t zstencil = util_pack64_z_stencil(format, uint64_t zstencil = util_pack64_z_stencil(format,
depth, stencil); depth, stencil);
ubyte *dst_layer = dst_map;
unsigned i, j; unsigned i, j;
assert(dst_trans->stride > 0); assert(dst_trans->stride > 0);
switch (util_format_get_blocksize(format)) { for (layer = 0; layer <= max_layer; layer++) {
case 1: dst_map = dst_layer;
assert(format == PIPE_FORMAT_S8_UINT);
if(dst_stride == width) switch (util_format_get_blocksize(format)) {
memset(dst_map, (uint8_t) zstencil, height * width); case 1:
else { assert(format == PIPE_FORMAT_S8_UINT);
for (i = 0; i < height; i++) { if(dst_stride == width)
memset(dst_map, (uint8_t) zstencil, width); memset(dst_map, (uint8_t) zstencil, height * 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++) {
uint32_t *row = (uint32_t *)dst_map;
for (j = 0; j < width; j++)
*row++ = (uint32_t) zstencil;
dst_map += dst_stride;
}
}
else {
uint32_t dst_mask;
if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT)
dst_mask = 0x00ffffff;
else { else {
assert(format == PIPE_FORMAT_S8_UINT_Z24_UNORM); for (i = 0; i < height; i++) {
dst_mask = 0xffffff00; memset(dst_map, (uint8_t) zstencil, width);
} dst_map += dst_stride;
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;
break; case 2:
case 8: assert(format == PIPE_FORMAT_Z16_UNORM);
if (!need_rmw) {
for (i = 0; i < height; i++) { for (i = 0; i < height; i++) {
uint64_t *row = (uint64_t *)dst_map; uint16_t *row = (uint16_t *)dst_map;
for (j = 0; j < width; j++) for (j = 0; j < width; j++)
*row++ = zstencil; *row++ = (uint16_t) zstencil;
dst_map += dst_stride; 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;
case 4:
if (!need_rmw) {
for (i = 0; i < height; i++) {
uint32_t *row = (uint32_t *)dst_map;
for (j = 0; j < width; j++)
*row++ = (uint32_t) zstencil;
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;
} }
break; dst_layer += dst_trans->layer_stride;
default:
assert(0);
break;
} }
pipe->transfer_unmap(pipe, dst_trans); pipe->transfer_unmap(pipe, dst_trans);