+ * Set the layout mode for all tiles in a particular image.
+ */
+static INLINE void
+llvmpipe_set_texture_image_layout(struct llvmpipe_resource *lpr,
+ unsigned face_slice, unsigned level,
+ unsigned width_t, unsigned height_t,
+ enum lp_texture_layout layout)
+{
+ const unsigned start = face_slice * lpr->tiles_per_image[level];
+ unsigned i;
+
+ for (i = 0; i < width_t * height_t; i++) {
+ lpr->layout[level][start + i] = layout;
+ }
+}
+
+
+/**
+ * Allocate storage for a linear or tile texture image (all cube
+ * faces and all 3D slices.
+ */
+static void
+alloc_image_data(struct llvmpipe_resource *lpr, unsigned level,
+ enum lp_texture_layout layout)
+{
+ uint alignment = MAX2(16, util_cpu_caps.cacheline);
+
+ if (lpr->dt)
+ assert(level == 0);
+
+ if (layout == LP_TEX_LAYOUT_TILED) {
+ /* tiled data is stored in regular memory */
+ uint buffer_size = tex_image_size(lpr, level, layout);
+ lpr->tiled[level].data = align_malloc(buffer_size, alignment);
+ if (lpr->tiled[level].data) {
+ memset(lpr->tiled[level].data, 0, buffer_size);
+ }
+ }
+ else {
+ assert(layout == LP_TEX_LAYOUT_LINEAR);
+ 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;
+
+ lpr->linear[0].data =
+ winsys->displaytarget_map(winsys, lpr->dt,
+ PIPE_TRANSFER_READ_WRITE);
+ }
+ else {
+ /* not a display target - allocate regular memory */
+ uint buffer_size = tex_image_size(lpr, level, LP_TEX_LAYOUT_LINEAR);
+ lpr->linear[level].data = align_malloc(buffer_size, alignment);
+ if (lpr->linear[level].data) {
+ memset(lpr->linear[level].data, 0, buffer_size);
+ }
+ }
+ }
+}
+
+
+
+/**
+ * Return pointer to texture image data (either linear or tiled layout)
+ * for a particular cube face or 3D texture slice.
+ *
+ * \param face_slice the cube face or 3D slice of interest