summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorSisinty Sasmita Patra <[email protected]>2015-01-03 11:16:08 -0800
committerJason Ekstrand <[email protected]>2015-01-26 17:29:34 -0800
commitb52959c6022509514deb672e53c710069eed0237 (patch)
treeba9708263b9b30d2bffdd3e7114a0aaa26fe57f9 /src/mesa
parent009be40b7d9e882ce95f6f76523f8f6d1c21238c (diff)
i965/tiled_memcpy: Add tiled-to-linear paths
This commit addes tiled copy functions for coping from tiled memory to linear memory. These are very similar to the existing linear-to-tiled paths. v2: Jason Ekstrand <[email protected]> - New commit message - Various whitespace fixes - Added ptrdiff_t casts as done in commit 225a09790 v3: Jason Ekstrand <[email protected]> - Fixed a comment Signed-off-by: Jason Ekstrand <[email protected]> Reviewed-by: Chad Versace <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/dri/i965/intel_tiled_memcpy.c272
-rw-r--r--src/mesa/drivers/dri/i965/intel_tiled_memcpy.h9
2 files changed, 281 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
index a7692a3b0eb..284374f012e 100644
--- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
+++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.c
@@ -234,6 +234,109 @@ linear_to_ytiled(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
}
/**
+ * Copy texture data from X tile layout to linear.
+ *
+ * \copydoc tile_copy_fn
+ */
+static inline void
+xtiled_to_linear(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
+ uint32_t y0, uint32_t y1,
+ char *dst, const char *src,
+ uint32_t dst_pitch,
+ uint32_t swizzle_bit,
+ mem_copy_fn mem_copy)
+{
+ /* The copy destination offset for each range copied is the sum of
+ * an X offset 'x0' or 'xo' and a Y offset 'yo.'
+ */
+ uint32_t xo, yo;
+
+ dst += y0 * dst_pitch;
+
+ for (yo = y0 * xtile_width; yo < y1 * xtile_width; yo += xtile_width) {
+ /* Bits 9 and 10 of the copy destination offset control swizzling.
+ * Only 'yo' contributes to those bits in the total offset,
+ * so calculate 'swizzle' just once per row.
+ * Move bits 9 and 10 three and four places respectively down
+ * to bit 6 and xor them.
+ */
+ uint32_t swizzle = ((yo >> 3) ^ (yo >> 4)) & swizzle_bit;
+
+ mem_copy(dst + x0, src + ((x0 + yo) ^ swizzle), x1 - x0);
+
+ for (xo = x1; xo < x2; xo += xtile_span) {
+ mem_copy(dst + xo, src + ((xo + yo) ^ swizzle), xtile_span);
+ }
+
+ mem_copy(dst + x2, src + ((xo + yo) ^ swizzle), x3 - x2);
+
+ dst += dst_pitch;
+ }
+}
+
+ /**
+ * Copy texture data from Y tile layout to linear.
+ *
+ * \copydoc tile_copy_fn
+ */
+static inline void
+ytiled_to_linear(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
+ uint32_t y0, uint32_t y1,
+ char *dst, const char *src,
+ uint32_t dst_pitch,
+ uint32_t swizzle_bit,
+ mem_copy_fn mem_copy)
+{
+ /* Y tiles consist of columns that are 'ytile_span' wide (and the same height
+ * as the tile). Thus the destination offset for (x,y) is the sum of:
+ * (x % column_width) // position within column
+ * (x / column_width) * bytes_per_column // column number * bytes per column
+ * y * column_width
+ *
+ * The copy destination offset for each range copied is the sum of
+ * an X offset 'xo0' or 'xo' and a Y offset 'yo.'
+ */
+ const uint32_t column_width = ytile_span;
+ const uint32_t bytes_per_column = column_width * ytile_height;
+
+ uint32_t xo0 = (x0 % ytile_span) + (x0 / ytile_span) * bytes_per_column;
+ uint32_t xo1 = (x1 % ytile_span) + (x1 / ytile_span) * bytes_per_column;
+
+ /* Bit 9 of the destination offset control swizzling.
+ * Only the X offset contributes to bit 9 of the total offset,
+ * so swizzle can be calculated in advance for these X positions.
+ * Move bit 9 three places down to bit 6.
+ */
+ uint32_t swizzle0 = (xo0 >> 3) & swizzle_bit;
+ uint32_t swizzle1 = (xo1 >> 3) & swizzle_bit;
+
+ uint32_t x, yo;
+
+ dst += y0 * dst_pitch;
+
+ for (yo = y0 * column_width; yo < y1 * column_width; yo += column_width) {
+ uint32_t xo = xo1;
+ uint32_t swizzle = swizzle1;
+
+ mem_copy(dst + x0, src + ((xo0 + yo) ^ swizzle0), x1 - x0);
+
+ /* Step by spans/columns. As it happens, the swizzle bit flips
+ * at each step so we don't need to calculate it explicitly.
+ */
+ for (x = x1; x < x2; x += ytile_span) {
+ mem_copy(dst + x, src + ((xo + yo) ^ swizzle), ytile_span);
+ xo += bytes_per_column;
+ swizzle ^= swizzle_bit;
+ }
+
+ mem_copy(dst + x2, src + ((xo + yo) ^ swizzle), x3 - x2);
+
+ dst += dst_pitch;
+ }
+}
+
+
+/**
* Copy texture data from linear to X tile layout, faster.
*
* Same as \ref linear_to_xtiled but faster, because it passes constant
@@ -305,6 +408,77 @@ linear_to_ytiled_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
dst, src, src_pitch, swizzle_bit, mem_copy);
}
+/**
+ * Copy texture data from X tile layout to linear, faster.
+ *
+ * Same as \ref xtile_to_linear but faster, because it passes constant
+ * parameters for common cases, allowing the compiler to inline code
+ * optimized for those cases.
+ *
+ * \copydoc tile_copy_fn
+ */
+static FLATTEN void
+xtiled_to_linear_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
+ uint32_t y0, uint32_t y1,
+ char *dst, const char *src,
+ uint32_t dst_pitch,
+ uint32_t swizzle_bit,
+ mem_copy_fn mem_copy)
+{
+ if (x0 == 0 && x3 == xtile_width && y0 == 0 && y1 == xtile_height) {
+ if (mem_copy == memcpy)
+ return xtiled_to_linear(0, 0, xtile_width, xtile_width, 0, xtile_height,
+ dst, src, dst_pitch, swizzle_bit, memcpy);
+ else if (mem_copy == rgba8_copy)
+ return xtiled_to_linear(0, 0, xtile_width, xtile_width, 0, xtile_height,
+ dst, src, dst_pitch, swizzle_bit, rgba8_copy);
+ } else {
+ if (mem_copy == memcpy)
+ return xtiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, memcpy);
+ else if (mem_copy == rgba8_copy)
+ return xtiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, rgba8_copy);
+ }
+ xtiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, mem_copy);
+}
+
+/**
+ * Copy texture data from Y tile layout to linear, faster.
+ *
+ * Same as \ref ytile_to_linear but faster, because it passes constant
+ * parameters for common cases, allowing the compiler to inline code
+ * optimized for those cases.
+ *
+ * \copydoc tile_copy_fn
+ */
+static FLATTEN void
+ytiled_to_linear_faster(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
+ uint32_t y0, uint32_t y1,
+ char *dst, const char *src,
+ uint32_t dst_pitch,
+ uint32_t swizzle_bit,
+ mem_copy_fn mem_copy)
+{
+ if (x0 == 0 && x3 == ytile_width && y0 == 0 && y1 == ytile_height) {
+ if (mem_copy == memcpy)
+ return ytiled_to_linear(0, 0, ytile_width, ytile_width, 0, ytile_height,
+ dst, src, dst_pitch, swizzle_bit, memcpy);
+ else if (mem_copy == rgba8_copy)
+ return ytiled_to_linear(0, 0, ytile_width, ytile_width, 0, ytile_height,
+ dst, src, dst_pitch, swizzle_bit, rgba8_copy);
+ } else {
+ if (mem_copy == memcpy)
+ return ytiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, memcpy);
+ else if (mem_copy == rgba8_copy)
+ return ytiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, rgba8_copy);
+ }
+ ytiled_to_linear(x0, x1, x2, x3, y0, y1,
+ dst, src, dst_pitch, swizzle_bit, mem_copy);
+}
/**
* Copy from linear to tiled texture.
@@ -397,10 +571,108 @@ linear_to_tiled(uint32_t xt1, uint32_t xt2,
}
}
+/**
+ * Copy from tiled to linear texture.
+ *
+ * Divide the region given by X range [xt1, xt2) and Y range [yt1, yt2) into
+ * pieces that do not cross tile boundaries and copy each piece with a tile
+ * copy function (\ref tile_copy_fn).
+ * The X range is in bytes, i.e. pixels * bytes-per-pixel.
+ * The Y range is in pixels (i.e. unitless).
+ * 'dst' is the start of the texture and 'src' is the corresponding
+ * address to copy from, though copying begins at (xt1, yt1).
+ */
+void
+tiled_to_linear(uint32_t xt1, uint32_t xt2,
+ uint32_t yt1, uint32_t yt2,
+ char *dst, const char *src,
+ uint32_t dst_pitch, uint32_t src_pitch,
+ bool has_swizzling,
+ uint32_t tiling,
+ mem_copy_fn mem_copy)
+{
+ tile_copy_fn tile_copy;
+ uint32_t xt0, xt3;
+ uint32_t yt0, yt3;
+ uint32_t xt, yt;
+ uint32_t tw, th, span;
+ uint32_t swizzle_bit = has_swizzling ? 1<<6 : 0;
+
+ if (tiling == I915_TILING_X) {
+ tw = xtile_width;
+ th = xtile_height;
+ span = xtile_span;
+ tile_copy = xtiled_to_linear_faster;
+ } else if (tiling == I915_TILING_Y) {
+ tw = ytile_width;
+ th = ytile_height;
+ span = ytile_span;
+ tile_copy = ytiled_to_linear_faster;
+ } else {
+ unreachable("unsupported tiling");
+ }
+
+ /* Round out to tile boundaries. */
+ xt0 = ALIGN_DOWN(xt1, tw);
+ xt3 = ALIGN_UP (xt2, tw);
+ yt0 = ALIGN_DOWN(yt1, th);
+ yt3 = ALIGN_UP (yt2, th);
+
+ /* Loop over all tiles to which we have something to copy.
+ * 'xt' and 'yt' are the origin of the destination tile, whether copying
+ * copying a full or partial tile.
+ * tile_copy() copies one tile or partial tile.
+ * Looping x inside y is the faster memory access pattern.
+ */
+ for (yt = yt0; yt < yt3; yt += th) {
+ for (xt = xt0; xt < xt3; xt += tw) {
+ /* The area to update is [x0,x3) x [y0,y1).
+ * May not want the whole tile, hence the min and max.
+ */
+ uint32_t x0 = MAX2(xt1, xt);
+ uint32_t y0 = MAX2(yt1, yt);
+ uint32_t x3 = MIN2(xt2, xt + tw);
+ uint32_t y1 = MIN2(yt2, yt + th);
+
+ /* [x0,x3) is split into [x0,x1), [x1,x2), [x2,x3) such that
+ * the middle interval is the longest span-aligned part.
+ * The sub-ranges could be empty.
+ */
+ uint32_t x1, x2;
+ x1 = ALIGN_UP(x0, span);
+ if (x1 > x3)
+ x1 = x2 = x3;
+ else
+ x2 = ALIGN_DOWN(x3, span);
+
+ assert(x0 <= x1 && x1 <= x2 && x2 <= x3);
+ assert(x1 - x0 < span && x3 - x2 < span);
+ assert(x3 - x0 <= tw);
+ assert((x2 - x1) % span == 0);
+
+ /* Translate by (xt,yt) for single-tile copier. */
+ tile_copy(x0-xt, x1-xt, x2-xt, x3-xt,
+ y0-yt, y1-yt,
+ dst + (ptrdiff_t) xt + (ptrdiff_t) yt * dst_pitch,
+ src + (ptrdiff_t) xt * th + (ptrdiff_t) yt * src_pitch,
+ dst_pitch,
+ swizzle_bit,
+ mem_copy);
+ }
+ }
+}
+
/**
* Determine which copy function to use for the given format combination
*
+ * The only two possible copy functions which are ever returned are a
+ * direct memcpy and a RGBA <-> BGRA copy function. Since RGBA -> BGRA and
+ * BGRA -> RGBA are exactly the same operation (and memcpy is obviously
+ * symmetric), it doesn't matter whether the copy is from the tiled image
+ * to the untiled or vice versa. The copy function required is the same in
+ * either case so this function can be used.
+ *
* \param[in] tiledFormat The format of the tiled image
* \param[in] format The GL format of the client data
* \param[in] type The GL type of the client data
diff --git a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
index ed7dabb792e..f64a32a2808 100644
--- a/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
+++ b/src/mesa/drivers/dri/i965/intel_tiled_memcpy.h
@@ -46,6 +46,15 @@ linear_to_tiled(uint32_t xt1, uint32_t xt2,
uint32_t tiling,
mem_copy_fn mem_copy);
+void
+tiled_to_linear(uint32_t xt1, uint32_t xt2,
+ uint32_t yt1, uint32_t yt2,
+ char *dst, const char *src,
+ uint32_t dst_pitch, uint32_t src_pitch,
+ bool has_swizzling,
+ uint32_t tiling,
+ mem_copy_fn mem_copy);
+
bool intel_get_memcpy(mesa_format tiledFormat, GLenum format,
GLenum type, mem_copy_fn* mem_copy, uint32_t* cpp);