[PATCH i-g-t 2/4] lib/intel_blt: Add helpers for calculating stride and aligned height
Zbigniew Kempczyński
zbigniew.kempczynski at intel.com
Wed Jan 31 10:51:46 UTC 2024
Tiled surfaces have stride / aligned height constraints. Currently
blt library has limitation and doesn't work properly when surface
stride is not valid for specific tiling.
As an example lets say we want to copy from linear to xmajor
33 x 33 x 32bpp surface. Xmajor surface expects stride aligned to
512 bytes and height to 8 rows so this surface will occupy 512B x 40
(128 x 40 x 32 bpp).
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Karolina Drobnik <karolina.drobnik at intel.com>
---
lib/intel_blt.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/lib/intel_blt.c b/lib/intel_blt.c
index 951c364d5f..77017f4432 100644
--- a/lib/intel_blt.c
+++ b/lib/intel_blt.c
@@ -521,6 +521,58 @@ static int __block_tiling(enum blt_tiling_type tiling)
return 0;
}
+/**
+ * blt_get_min_stride
+ * @width: width in pixels
+ * @bpp: bits per pixel
+ * @tiling: tiling
+ *
+ * Function returns minimum posibble stride in bytes for width, bpp and tiling.
+ *
+ * Returns:
+ * minimum possible stride in bytes.
+ */
+static uint32_t blt_get_min_stride(uint32_t width, uint32_t bpp,
+ enum blt_tiling_type tiling)
+{
+ switch (tiling) {
+ case T_LINEAR:
+ return width * bpp / 8;
+ case T_XMAJOR:
+ case T_TILE64:
+ return ALIGN(width * bpp / 8, 512);
+ default:
+ return ALIGN(width * bpp / 8, 128);
+ }
+}
+
+/**
+ * blt_get_aligned_height
+ * @height: height in pixels
+ * @tiling: tiling
+ *
+ * Function returns aligned height for specific tiling. Height returned is
+ * important from memory allocation perspective, because each tiling has
+ * specific memory constraints.
+ *
+ * Returns:
+ * height (rows) expected for specific tiling
+ */
+static uint32_t blt_get_aligned_height(uint32_t height,
+ enum blt_tiling_type tiling)
+{
+ switch (tiling) {
+ case T_LINEAR:
+ return height;
+ case T_XMAJOR:
+ return ALIGN(height, 8);
+ case T_TILE64:
+ return ALIGN(height, 128);
+ default:
+ return ALIGN(height, 32);
+ }
+}
+
static int __special_mode(const struct blt_copy_data *blt)
{
if (blt->src.handle == blt->dst.handle &&
--
2.34.1
More information about the igt-dev
mailing list