- struct swr_resource *res = swr_resource(transfer->resource);
- /* if we're mapping the depth/stencil, copy out stencil */
- if (res->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT
- && res->has_stencil) {
- for (unsigned i = 0; i < res->alignedWidth * res->alignedHeight; i++) {
- res->secondary.pBaseAddress[i] = res->swr.pBaseAddress[4 * i + 3];
- }
- } else if (res->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
- && res->has_stencil) {
- for (unsigned i = 0; i < res->alignedWidth * res->alignedHeight; i++) {
- res->secondary.pBaseAddress[i] = res->swr.pBaseAddress[8 * i + 4];
+ struct swr_resource *spr = swr_resource(transfer->resource);
+ if (!spr->has_depth || !spr->has_stencil)
+ return;
+
+ size_t zbase, sbase;
+ struct pipe_box box = *flush_box;
+ box.x += transfer->box.x;
+ box.y += transfer->box.y;
+ box.z += transfer->box.z;
+ for (int z = box.z; z < box.z + box.depth; z++) {
+ zbase = (z * spr->swr.qpitch + box.y) * spr->swr.pitch +
+ spr->mip_offsets[transfer->level];
+ sbase = (z * spr->secondary.qpitch + box.y) * spr->secondary.pitch +
+ spr->secondary_mip_offsets[transfer->level];
+ for (int y = box.y; y < box.y + box.height; y++) {
+ if (spr->base.format == PIPE_FORMAT_Z24_UNORM_S8_UINT) {
+ for (int x = box.x; x < box.x + box.width; x++)
+ ((uint8_t*)(spr->secondary.xpBaseAddress))[sbase + x] =
+ ((uint8_t*)(spr->swr.xpBaseAddress))[zbase + 4 * x + 3];
+ } else if (spr->base.format == PIPE_FORMAT_Z32_FLOAT_S8X24_UINT) {
+ for (int x = box.x; x < box.x + box.width; x++)
+ ((uint8_t*)(spr->secondary.xpBaseAddress))[sbase + x] =
+ ((uint8_t*)(spr->swr.xpBaseAddress))[zbase + 8 * x + 4];
+ }
+ zbase += spr->swr.pitch;
+ sbase += spr->secondary.pitch;