+static void
+v3d_texture_subdata(struct pipe_context *pctx,
+ struct pipe_resource *prsc,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ const void *data,
+ unsigned stride,
+ unsigned layer_stride)
+{
+ struct v3d_resource *rsc = v3d_resource(prsc);
+ struct v3d_resource_slice *slice = &rsc->slices[level];
+
+ /* For a direct mapping, we can just take the u_transfer path. */
+ if (!rsc->tiled) {
+ return u_default_texture_subdata(pctx, prsc, level, usage, box,
+ data, stride, layer_stride);
+ }
+
+ /* Otherwise, map and store the texture data directly into the tiled
+ * texture. Note that gallium's texture_subdata may be called with
+ * obvious usage flags missing!
+ */
+ v3d_map_usage_prep(pctx, prsc, usage | (PIPE_TRANSFER_WRITE |
+ PIPE_TRANSFER_DISCARD_RANGE));
+
+ void *buf;
+ if (usage & PIPE_TRANSFER_UNSYNCHRONIZED)
+ buf = v3d_bo_map_unsynchronized(rsc->bo);
+ else
+ buf = v3d_bo_map(rsc->bo);
+
+ for (int i = 0; i < box->depth; i++) {
+ v3d_store_tiled_image(buf +
+ v3d_layer_offset(&rsc->base,
+ level,
+ box->z + i),
+ slice->stride,
+ (void *)data + layer_stride * i,
+ stride,
+ slice->tiling, rsc->cpp, slice->padded_height,
+ box);
+ }
+}
+