<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=UTF-8" http-equiv="Content-Type"></head><body ><div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;"><div><br></div><div><br></div><div id="Zm-_Id_-Sgn" data-sigid="3241918000000049003" data-zbluepencil-ignore="true"><div>~Faith Ekstrand<br></div></div><div><br></div><div class="zmail_extra_hr" style="border-top: 1px solid rgb(204, 204, 204); height: 0px; margin-top: 10px; margin-bottom: 10px; line-height: 0px;"><br></div><div class="zmail_extra" data-zbluepencil-ignore="true"><div><br></div><div id="Zm-_Id_-Sgn1">---- On Sat, 01 Mar 2025 16:01:30 -0600 <b>Alyssa Rosenzweig <alyssa@rosenzweig.io></b> wrote ---<br></div><div><br></div><blockquote style="margin: 0px;" id="blockquote_zmail"><div>Apple GPUs support various non-linear image layouts. Add modifiers for <br>these layouts. Mesa requires these modifiers to share non-linear buffers <br>across processes, but no other userspace or kernel support is <br>required/expected. <br> <br>These layouts are notably not used for interchange across hardware <br>blocks (e.g. with the display controller). There are other layouts for <br>that but we don't support them either in userspace or kernelspace yet <br>(even downstream), so we don't add modifiers here. <br> <br>Signed-off-by: Alyssa Rosenzweig <<a target="_blank" href="mailto:alyssa@rosenzweig.io">alyssa@rosenzweig.io</a>> <br>--- <br>Changes in v3: <br>- Condense comments for clarity and concision. <br>- Add text explaining strides and planes with justification. <br>- Add table giving tile sizes for GPU tiled images. <br>- Tighten up wording. <br>- Link to v2: <a target="_blank" href="https://lore.kernel.org/r/20250225-apple-twiddled-modifiers-v2-1-cf69729e87f6@rosenzweig.io">https://lore.kernel.org/r/20250225-apple-twiddled-modifiers-v2-1-cf69729e87f6@rosenzweig.io</a> <br> <br>Changes in v2: <br>- Rename "Twiddled" to "GPU-tiled" to match what I now believe is the canonical name. <br>- Add modifiers for the actual "Twiddled" layouts. <br>- Clarify that the body of compressed images are laid out like their <br> uncompressed counterparts. <br>- Link to v1: <a target="_blank" href="https://lore.kernel.org/r/20250218-apple-twiddled-modifiers-v1-1-8551bab4321f@rosenzweig.io">https://lore.kernel.org/r/20250218-apple-twiddled-modifiers-v1-1-8551bab4321f@rosenzweig.io</a> <br>--- <br> include/uapi/drm/drm_fourcc.h | 63 +++++++++++++++++++++++++++++++++++++++++++ <br> 1 file changed, 63 insertions(+) <br> <br>diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h <br>index e41a3cec6a9ed18760f3b0c88ba437c9aba3dd4f..2e21f71c500ec96b55abb04967f20630963f59f8 100644 <br>--- a/include/uapi/drm/drm_fourcc.h <br>+++ b/include/uapi/drm/drm_fourcc.h <br>@@ -422,6 +422,7 @@ extern "C" { <br> #define DRM_FORMAT_MOD_VENDOR_ALLWINNER 0x09 <br> #define DRM_FORMAT_MOD_VENDOR_AMLOGIC 0x0a <br> #define DRM_FORMAT_MOD_VENDOR_MTK 0x0b <br>+#define DRM_FORMAT_MOD_VENDOR_APPLE 0x0c <br> <br> /* add more to the end as needed */ <br> <br>@@ -1494,6 +1495,68 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier) <br> /* alias for the most common tiling format */ <br> #define DRM_FORMAT_MOD_MTK_16L_32S_TILE DRM_FORMAT_MOD_MTK(MTK_FMT_MOD_TILE_16L32S) <br> <br>+/* <br>+ * Apple GPU layouts. <br>+ * <br>+ * Apple GPUs support nonlinear tilings with optional lossless compression. <br>+ * <br>+ * Compressed images pad the body to 128-bytes and are immediately followed by a <br>+ * metadata section. The metadata section rounds the image dimensions to <br>+ * powers-of-two and contains 8 bytes for each 16x16 compression subtile. <br>+ * Subtiles are interleaved (Morton order). <br>+ * <br>+ * All images are 16-byte aligned. <br>+ * <br>+ * These layouts fundamentally do not have meaningful strides. No matter how we <br>+ * specify strides for these layouts, userspace unaware of Apple image layouts <br>+ * will be unable to use correctly the specified stride for any purpose. <br>+ * Userspace aware of the image layouts do not use strides. The most "correct" <br>+ * convention would be setting the image stride to 0. Unfortunately, some <br>+ * software assumes the stride is at least (width * bytes per pixel). We <br>+ * therefore require that stride equals (width * bytes per pixel). Since the <br>+ * stride is arbitrary here, we pick the simplest convention. <br>+ * <br>+ * Although containing two sections, compressed image layouts are treated in <br>+ * software as a single plane. This is modelled after AFBC, a similar <br>+ * scheme. Attempting to separate the sections to be "explicit" in DRM would <br>+ * only generate more confusion, as software does not treat the image this way. <br>+ * <br>+ * For detailed information on the hardware image layouts, see <br>+ * <a target="_blank" href="https://docs.mesa3d.org/drivers/asahi.html#image-layouts">https://docs.mesa3d.org/drivers/asahi.html#image-layouts</a> <br>+ */ <br>+ <br>+/* <br>+ * Apple GPU-tiled layouts. <br>+ * <br>+ * GPU-tiled images are divided into 16KiB tiles: <br>+ * <br>+ * Bytes per pixel Tile size <br>+ * --------------- --------- <br>+ * 1 128x128 <br>+ * 2 128x64 <br>+ * 4 64x64 <br>+ * 8 64x32 <br>+ * 16 32x32 <br>+ * <br>+ * Tiles are raster-order. Pixels within a tile are interleaved (Morton order). </div></blockquote></div><div><br></div><div>"raster-order. Tiles are tightly packed with no padding on the right-hand edge except that which is required to make full tiles."? I think that would make the stride stuff more clear.<br></div><div><br></div><div>Either way,<br></div><div><br></div><div>Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com></div><div class="zmail_extra" data-zbluepencil-ignore="true"><blockquote style="margin: 0px;" id="blockquote_zmail"><div><br>+ * <br>+ * GPU-tiled is the preferred layout (compressed if possible). <br>+ */ <br>+#define DRM_FORMAT_MOD_APPLE_GPU_TILED fourcc_mod_code(APPLE, 1) <br>+#define DRM_FORMAT_MOD_APPLE_GPU_TILED_COMPRESSED fourcc_mod_code(APPLE, 2) <br>+ <br>+/* <br>+ * Apple twiddled layouts. <br>+ * <br>+ * Twiddled images are padded to power-of-two dimensions. Pixels are interleaved <br>+ * (Morton order). <br>+ * <br>+ * Twiddled layouts are useful for sparse images due to limitation of the <br>+ * hardware PBE unit. <br>+ */ <br>+#define DRM_FORMAT_MOD_APPLE_TWIDDLED fourcc_mod_code(APPLE, 3) <br>+#define DRM_FORMAT_MOD_APPLE_TWIDDLED_COMPRESSED fourcc_mod_code(APPLE, 4) <br>+ <br> /* <br> * AMD modifiers <br> * <br> <br>--- <br>base-commit: 0ed1356af8f629ae807963b7db4e501e3b580bc2 <br>change-id: 20250218-apple-twiddled-modifiers-fde1a6f4300c <br> <br>Best regards, <br>-- <br>Alyssa Rosenzweig <<a target="_blank" href="mailto:alyssa@rosenzweig.io">alyssa@rosenzweig.io</a>> <br> <br></div></blockquote></div><div><br></div></div><br></body></html>