- img = &lpr->linear_img;
- offset = lpr->linear_mip_offsets[level];
-
- if (face_slice > 0)
- offset += face_slice * tex_image_face_size(lpr, level);
-
- return (ubyte *) img->data + offset;
-}
-
-
-/**
- * Allocate storage for a linear image
- * (all cube faces and all 3D slices, all levels).
- */
-static void
-alloc_image_data(struct llvmpipe_resource *lpr)
-{
- uint alignment = MAX2(16, util_cpu_caps.cacheline);
- uint level;
- uint offset = 0;
-
- if (lpr->dt) {
- /* we get the linear memory from the winsys, and it has
- * already been zeroed
- */
- struct llvmpipe_screen *screen = llvmpipe_screen(lpr->base.screen);
- struct sw_winsys *winsys = screen->winsys;
-
- assert(lpr->base.last_level == 0);
-
- lpr->linear_img.data =
- winsys->displaytarget_map(winsys, lpr->dt,
- PIPE_TRANSFER_READ_WRITE);
- }
- else {
- /* not a display target - allocate regular memory */
- /*
- * Offset calculation for start of a specific mip/layer is always
- * offset = lpr->linear_mip_offsets[level] + lpr->img_stride[level] * layer
- */
- for (level = 0; level <= lpr->base.last_level; level++) {
- uint buffer_size = tex_image_size(lpr, level);
- lpr->linear_mip_offsets[level] = offset;
- offset += align(buffer_size, alignment);
- }
- lpr->linear_img.data = align_malloc(offset, alignment);
- if (lpr->linear_img.data) {
- memset(lpr->linear_img.data, 0, offset);
- }
- }
-}
-
-
-
-/**
- * Return pointer to texture image data
- * for a particular cube face or 3D texture slice.
- *
- * \param face_slice the cube face or 3D slice of interest
- * \param usage one of LP_TEX_USAGE_READ/WRITE_ALL/READ_WRITE
- */
-void *
-llvmpipe_get_texture_image(struct llvmpipe_resource *lpr,
- unsigned face_slice, unsigned level,
- enum lp_texture_usage usage)
-{
- struct llvmpipe_texture_image *target_img;
- void *target_data;
- unsigned target_offset;
- unsigned *target_off_ptr;
-
- assert(usage == LP_TEX_USAGE_READ ||
- usage == LP_TEX_USAGE_READ_WRITE ||
- usage == LP_TEX_USAGE_WRITE_ALL);
-
- if (lpr->dt) {
- assert(lpr->linear_img.data);
- }
-
- target_img = &lpr->linear_img;
- target_off_ptr = lpr->linear_mip_offsets;
- target_data = target_img->data;
-
- if (!target_data) {
- /* allocate memory for the target image now */
- alloc_image_data(lpr);
- target_data = target_img->data;
- }
-
- target_offset = target_off_ptr[level];
-
- if (face_slice > 0) {
- target_offset += face_slice * tex_image_face_size(lpr, level);
- }
-
- if (target_data) {
- target_data = (uint8_t *) target_data + target_offset;
- }
-
- return target_data;
-}
-
-
-/**
- * Return pointer to start of a texture image (1D, 2D, 3D, CUBE).
- * This is typically used when we're about to sample from a texture.
- */
-void *
-llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
- unsigned level,
- enum lp_texture_usage usage)
-{
- const int slices = lpr->num_slices_faces[level];
- int slice;
- void *map = NULL;
-
- assert(slices > 0);
-
- for (slice = slices - 1; slice >= 0; slice--) {
- map = llvmpipe_get_texture_image(lpr, slice, level, usage);
- }
-
- return map;
-}
-
-
-/**
- * Get pointer to a linear image (not the tile!) at tile (x,y).
- * \return pointer to start of image/face (not the tile)
- */
-ubyte *
-llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
- unsigned face_slice, unsigned level,
- enum lp_texture_usage usage,
- unsigned x, unsigned y)
-{
- struct llvmpipe_texture_image *linear_img = &lpr->linear_img;
- uint8_t *linear_image;
-