+ struct vc4_resource_slice *slice = &rsc->slices[level];
+ if (rsc->tiled) {
+ uint32_t utile_w = vc4_utile_width(rsc->cpp);
+ uint32_t utile_h = vc4_utile_height(rsc->cpp);
+
+ /* No direct mappings of tiled, since we need to manually
+ * tile/untile.
+ */
+ if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
+ return NULL;
+
+ if (format == PIPE_FORMAT_ETC1_RGB8) {
+ /* ETC1 is arranged as 64-bit blocks, where each block
+ * is 4x4 pixels. Texture tiling operates on the
+ * 64-bit block the way it would an uncompressed
+ * pixels.
+ */
+ assert(!(ptrans->box.x & 3));
+ assert(!(ptrans->box.y & 3));
+ ptrans->box.x >>= 2;
+ ptrans->box.y >>= 2;
+ ptrans->box.width = (ptrans->box.width + 3) >> 2;
+ ptrans->box.height = (ptrans->box.height + 3) >> 2;
+ }
+
+ /* We need to align the box to utile boundaries, since that's
+ * what load/store operates on. This may cause us to need to
+ * read out the original contents in that border area. Right
+ * now we just read out the entire contents, including the
+ * middle area that will just get overwritten.
+ */
+ uint32_t box_start_x = ptrans->box.x & (utile_w - 1);
+ uint32_t box_start_y = ptrans->box.y & (utile_h - 1);
+ bool needs_load = (usage & PIPE_TRANSFER_READ) != 0;
+
+ if (box_start_x) {
+ ptrans->box.width += box_start_x;
+ ptrans->box.x -= box_start_x;
+ needs_load = true;
+ }
+ if (box_start_y) {
+ ptrans->box.height += box_start_y;
+ ptrans->box.y -= box_start_y;
+ needs_load = true;
+ }
+ if (ptrans->box.width & (utile_w - 1)) {
+ /* We only need to force a load if our border region
+ * we're extending into is actually part of the
+ * texture.
+ */
+ uint32_t slice_width = u_minify(prsc->width0, level);
+ if (ptrans->box.x + ptrans->box.width != slice_width)
+ needs_load = true;
+ ptrans->box.width = align(ptrans->box.width, utile_w);
+ }
+ if (ptrans->box.height & (utile_h - 1)) {
+ uint32_t slice_height = u_minify(prsc->height0, level);
+ if (ptrans->box.y + ptrans->box.height != slice_height)
+ needs_load = true;
+ ptrans->box.height = align(ptrans->box.height, utile_h);
+ }
+
+ ptrans->stride = ptrans->box.width * rsc->cpp;
+ ptrans->layer_stride = ptrans->stride * ptrans->box.height;
+
+ trans->map = malloc(ptrans->layer_stride * ptrans->box.depth);
+
+ if (needs_load) {
+ vc4_load_tiled_image(trans->map, ptrans->stride,
+ buf + slice->offset +
+ ptrans->box.z * rsc->cube_map_stride,
+ slice->stride,
+ slice->tiling, rsc->cpp,
+ &ptrans->box);
+ }
+ return (trans->map +
+ box_start_x * rsc->cpp +
+ box_start_y * ptrans->stride);
+ } else {
+ ptrans->stride = slice->stride;
+ ptrans->layer_stride = ptrans->stride;
+
+ return buf + slice->offset +
+ ptrans->box.y / util_format_get_blockheight(format) * ptrans->stride +
+ ptrans->box.x / util_format_get_blockwidth(format) * rsc->cpp +
+ ptrans->box.z * rsc->cube_map_stride;
+ }
+