From: Jeevan B <jeevan.b@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: animesh.manna@intel.com, dibin.moolakadan.subrahmanian@intel.com,
mohammed.thasleem@intel.com, ramanaidu.naladala@intel.com,
Jeevan B <jeevan.b@intel.com>
Subject: [PATCH i-g-t v2 1/2] lib/igt_fb: Add IGT_FORMAT_MOD_PREFERRED helper modifier
Date: Wed, 13 May 2026 11:45:01 +0530 [thread overview]
Message-ID: <20260513061503.645278-2-jeevan.b@intel.com> (raw)
In-Reply-To: <20260513061503.645278-1-jeevan.b@intel.com>
lib/igt_fb: Add IGT_FORMAT_MOD_PREFERRED helper modifier
Add IGT_FORMAT_MOD_PREFERRED as an internal FB modifier sentinel so tests
can request preferred tiling without hardcoding driver rules.
Resolve it in igt_fb_resolve_modifier() (never pass it to kernel) by
checking support for the requested format in this order:
X_TILED -> 4_TILED -> LINEAR.
v2:
- Switch from gen/driver policy to capability-based selection
- Drop Y_TILED preference
Signed-off-by: Jeevan B <jeevan.b@intel.com>
---
lib/igt_fb.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++-
lib/igt_fb.h | 19 ++++++++++++++
2 files changed, 89 insertions(+), 1 deletion(-)
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index fa9220953..454a59859 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -790,6 +790,67 @@ static int fb_num_planes(const struct igt_fb *fb)
return num_planes;
}
+/**
+ * igt_fb_resolve_modifier:
+ * @fd: DRM device fd
+ * @modifier: Requested modifier, may be IGT_FORMAT_MOD_PREFERRED
+ *
+ * Resolve the IGT_FORMAT_MOD_PREFERRED sentinel to an actual framebuffer
+ * modifier by checking device capabilities. Tries modifiers in order of
+ * preference: X-tile (compatibility), 4-tile (modern), then LINEAR (fallback).
+ * Returns the first supported modifier.
+ *
+ * This approach avoids hardcoded driver/generation checks and instead
+ * validates actual device capabilities.
+ *
+ * Returns: The resolved DRM format modifier that is supported by the device.
+ */
+static bool igt_fb_modifier_is_supported(int fd, uint32_t format,
+ uint64_t modifier)
+{
+ igt_display_t display;
+ bool supported = false;
+
+ if (modifier == DRM_FORMAT_MOD_LINEAR)
+ return true; /* LINEAR is always supported */
+
+ igt_display_require(&display, fd);
+ supported = igt_display_has_format_mod(&display, format, modifier);
+ igt_display_fini(&display);
+
+ return supported;
+}
+
+static uint64_t igt_fb_resolve_modifier(int fd, uint32_t format,
+ uint64_t modifier)
+{
+ uint64_t preferred_modifiers[] = {
+ I915_FORMAT_MOD_X_TILED, /* X-tile: good compatibility */
+ I915_FORMAT_MOD_4_TILED, /* 4-tile: modern, potentially better */
+ DRM_FORMAT_MOD_LINEAR /* Linear: always fallback */
+ };
+ uint64_t resolved = DRM_FORMAT_MOD_LINEAR;
+
+ if (modifier != IGT_FORMAT_MOD_PREFERRED)
+ return modifier;
+
+ /* Try preferred modifiers in order, independent of driver checks. */
+ for (int i = 0; i < ARRAY_SIZE(preferred_modifiers); i++) {
+ if (igt_fb_modifier_is_supported(fd, format,
+ preferred_modifiers[i])) {
+ resolved = preferred_modifiers[i];
+ igt_debug("Found supported modifier: %s(0x%" PRIx64 ")\n",
+ igt_fb_modifier_name(resolved), resolved);
+ break;
+ }
+ }
+
+ igt_debug("Resolved IGT_FORMAT_MOD_PREFERRED to %s(0x%" PRIx64 ")\n",
+ igt_fb_modifier_name(resolved), resolved);
+
+ return resolved;
+}
+
void igt_init_fb(struct igt_fb *fb, int fd, int width, int height,
uint32_t drm_format, uint64_t modifier,
enum igt_color_encoding color_encoding,
@@ -803,7 +864,13 @@ void igt_init_fb(struct igt_fb *fb, int fd, int width, int height,
fb->width = width;
fb->height = height;
- fb->modifier = modifier;
+ fb->modifier = igt_fb_resolve_modifier(fd, drm_format, modifier);
+ /* Log the chosen modifier for debugging. */
+ if (modifier == IGT_FORMAT_MOD_PREFERRED) {
+ igt_debug("Created framebuffer: %dx%d, format=%s, modifier=%s(0x%" PRIx64 ")\n",
+ width, height, igt_format_str(drm_format),
+ igt_fb_modifier_name(fb->modifier), fb->modifier);
+ }
fb->drm_format = drm_format;
fb->fd = fd;
fb->num_planes = fb_num_planes(fb);
@@ -5266,6 +5333,8 @@ void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
const char *igt_fb_modifier_name(uint64_t modifier)
{
switch (modifier) {
+ case IGT_FORMAT_MOD_PREFERRED:
+ return "preferred";
case DRM_FORMAT_MOD_LINEAR:
return "linear";
case I915_FORMAT_MOD_X_TILED:
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 8e5907dab..27aa9e161 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -50,6 +50,25 @@ typedef struct _igt_crc igt_crc_t;
*/
#define IGT_FORMAT_FLOAT fourcc_code('I', 'G', 'F', 'x')
+/**
+ * IGT_FORMAT_MOD_PREFERRED:
+ *
+ * Modifier used by tests to request the best tiling format for the
+ * current device. The actual modifier is selected inside igt_init_fb()
+ * based on device capabilities, so tests don't need to handle driver or
+ * generation-specific details.
+ *
+ * Default selection rules (capability-based):
+ * - If X_TILED is supported for the requested format, use X_TILED
+ * - Else if 4_TILED is supported for the requested format, use 4_TILED
+ * - Else use LINEAR
+ *
+ * Note: This is a special placeholder value and must never be sent to
+ * the kernel. Modifier selection is logged in IGT debug output.
+ */
+#define IGT_FORMAT_MOD_PREFERRED UINT64_C(0xfffffffffffffffe)
+
+
#define IGT_FORMAT_FMT "%c%c%c%c(0x%08x)"
#define IGT_FORMAT_ARGS(f) ((f) >> 0) & 0xff, ((f) >> 8) & 0xff, \
((f) >> 16) & 0xff, ((f) >> 24) & 0xff, (f)
--
2.43.0
next prev parent reply other threads:[~2026-05-13 6:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-13 6:15 [PATCH i-g-t v2 0/2] RFC: Add preferred FB modifier helper Jeevan B
2026-05-13 6:15 ` Jeevan B [this message]
2026-05-13 6:15 ` [PATCH i-g-t v2 2/2] HAX: kms_cursor_legacy: Use IGT_FORMAT_MOD_PREFERRED for cursor FBs Jeevan B
2026-05-13 8:35 ` Jani Nikula
2026-05-13 8:50 ` B, Jeevan
2026-05-13 10:12 ` Jani Nikula
2026-05-13 7:15 ` ✗ i915.CI.BAT: failure for RFC: Add preferred FB modifier helper (rev3) Patchwork
2026-05-13 7:34 ` ✗ Xe.CI.BAT: " Patchwork
2026-05-14 4:39 ` ✗ Xe.CI.FULL: " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2026-05-12 6:20 [PATCH i-g-t v2 0/2] RFC: Add preferred FB modifier helper Jeevan B
2026-05-12 6:20 ` [PATCH i-g-t v2 1/2] lib/igt_fb: Add IGT_FORMAT_MOD_PREFERRED helper modifier Jeevan B
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513061503.645278-2-jeevan.b@intel.com \
--to=jeevan.b@intel.com \
--cc=animesh.manna@intel.com \
--cc=dibin.moolakadan.subrahmanian@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=mohammed.thasleem@intel.com \
--cc=ramanaidu.naladala@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox