From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [PATCH i-g-t v2 16/25] lib/kms: Introduce igt_format_mods iterators
Date: Wed, 13 May 2026 06:17:24 +0300 [thread overview]
Message-ID: <20260513031724.27229-1-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20260512122143.11013-17-ville.syrjala@linux.intel.com>
From: Ville Syrjälä <ville.syrjala@linux.intel.com>
Add three new iterators:
- for_each_format_and_modifier()
- for_each_format_with_modifier()
- for_each_modifier_with_format()
Each one takes a igt_format_mods structure, and iterates it
accordingly.
Convert igt_format_mods_has_format_and_modifier() to use
for_each_format_and_modifier() as the first step.
v2: Fix _modifier type in igt_format_mods_has_format_and_modifier()
Make the macros a bit more type safe
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
lib/igt_aux.h | 3 +++
lib/igt_kms.c | 8 ++++----
lib/igt_kms.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 56761a3b3eaa..30530a4040ce 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -250,6 +250,9 @@ void igt_debug_interactive_mode_check(const char *var, const char *expected);
__cmp(x, y, op), \
__cmp_once(x, y, igt_unique(igt_tokencat(prefix, __x)), igt_unique(igt_tokencat(prefix, __y)), op))
+#define assert_type(x, type) \
+ (void)({_Static_assert(__builtin_types_compatible_p(typeof(x), type), #x " must be " #type);})
+
#define min(x, y) __careful_cmp(x, y, <, min)
#define max(x, y) __careful_cmp(x, y, >, max)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index b90d34e61359..75f7ca2d64e0 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -6288,11 +6288,11 @@ static void igt_fill_plane_format_mod(igt_display_t *display, igt_plane_t *plane
static bool igt_format_mods_has_format_and_modifier(const struct igt_format_mods *format_mods,
uint32_t format, uint64_t modifier)
{
- int i;
+ uint64_t _modifier;
+ uint32_t _format;
- for (i = 0; i < format_mods->count; i++) {
- if (format_mods->formats[i] == format &&
- format_mods->modifiers[i] == modifier)
+ for_each_format_and_modifier(format_mods, _format, _modifier) {
+ if (_format == format && _modifier == modifier)
return true;
}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index e02c5dd25d16..2f4526407aa2 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -828,6 +828,50 @@ igt_output_crtc_t *__igt_output_crtc_populate(igt_display_t *display,
for_each_if (((format) = (plane)->drm_plane->formats[__i], \
1))
+/**
+ * for_each_format_and_modifier:
+ * @format_mods: a pointer to an #igt_format_mod structure
+ * @format: format iterator
+ * @modifier: modifier iterator
+ *
+ * This for loop iterates over all format+modifier combinations.
+ */
+#define for_each_format_and_modifier(format_mods, format, modifier) \
+ for (int igt_unique(__i) = 0; igt_unique(__i) < (format_mods)->count; igt_unique(__i)++) \
+ for_each_if ((assert_type((format), uint32_t), \
+ assert_type((modifier), uint64_t), \
+ (format) = (format_mods)->formats[igt_unique(__i)], \
+ (modifier) = (format_mods)->modifiers[igt_unique(__i)], \
+ 1))
+
+/**
+ * for_each_format_with_modifier:
+ * @format_mods: a pointer to an #igt_format_mod structure
+ * @modifier: specified modifier
+ * @format: format iterator
+ *
+ * This for loop iterates over all formats supporting @modifier.
+ */
+#define for_each_format_with_modifier(format_mods, format, modifier) \
+ for (int igt_unique(__i) = 0; igt_unique(__i) < (format_mods)->count; igt_unique(__i)++) \
+ for_each_if ((assert_type((format), uint32_t), \
+ (format) = (format_mods)->formats[igt_unique(__i)], \
+ (modifier) == (format_mods)->modifiers[igt_unique(__i)]))
+
+/**
+ * for_each_modifier_with_format:
+ * @format_mods: a pointer to an #igt_format_mod structure
+ * @format: specified format
+ * @modifier: modifier iterator
+ *
+ * This for loop iterates over all modifiers supporting @format.
+ */
+#define for_each_modifier_with_format(format_mods, format, modifier) \
+ for (int igt_unique(__i) = 0; igt_unique(__i) < (format_mods)->count; igt_unique(__i)++) \
+ for_each_if ((assert_type((modifier), uint64_t), \
+ (modifier) = (format_mods)->modifiers[igt_unique(__i)], \
+ (format) == (format_mods)->formats[igt_unique(__i)]))
+
#define IGT_FIXED(i,f) ((i) << 16 | (f))
/**
--
2.52.0
next prev parent reply other threads:[~2026-05-13 3:17 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 12:21 [PATCH i-g-t 00/25] lib/kms: Clean up format+mod stuff Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 01/25] tests/kms_async_flips: Use correct format_mod list Ville Syrjala
2026-05-13 5:12 ` B, Jeevan
2026-05-12 12:21 ` [PATCH i-g-t 02/25] test/kms: Introduce a few extra format/modifier variables Ville Syrjala
2026-05-13 5:17 ` B, Jeevan
2026-05-12 12:21 ` [PATCH i-g-t 03/25] lib/kms: Introduce struct igt_format_mods Ville Syrjala
2026-05-13 5:23 ` B, Jeevan
2026-05-12 12:21 ` [PATCH i-g-t 04/25] lib/kms: Pass struct igt_format_mods to igt_parse_format_mod_blob() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 05/25] lib/kms: Extract format_mods_alloc() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 06/25] lib/kms: Extract fill_plane_default_format_mods() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 07/25] lib/kms: Extract igt_format_mods_has_format_with_modifier() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 08/25] lib/kms: Pass target format_mods to igt_add_display_format_mod() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 09/25] lib/kms: Extract format_mods_union() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 10/25] lib/kms: Extract display_format_mods_union() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 11/25] lib/kms: Move and rename igt_count_display_format_mod() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 12/25] lib/kms: Make igt_fill_display_format_mod() more flexible Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 13/25] lib/kms: Add display->format_mods_async Ville Syrjala
2026-05-14 4:35 ` Reddy Guddati, Santhosh
2026-05-12 12:21 ` [PATCH i-g-t 14/25] lib/kms: Fill plane->format_mods_async for planes without IN_FORMATS Ville Syrjala
2026-05-14 4:59 ` Reddy Guddati, Santhosh
2026-05-12 12:21 ` [PATCH i-g-t 15/25] lib/kms: Encourage drivers to expose IN_FORMATS_ASYNC Ville Syrjala
2026-05-14 5:15 ` Reddy Guddati, Santhosh
2026-05-12 12:21 ` [PATCH i-g-t 16/25] lib/kms: Introduce igt_format_mods iterators Ville Syrjala
2026-05-13 3:17 ` Ville Syrjala [this message]
2026-05-12 12:21 ` [PATCH i-g-t 17/25] lib/kms: Add helpers to query igt_format_mods Ville Syrjala
2026-05-13 3:17 ` [PATCH i-g-t v2 " Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 18/25] tests/chamelium/kms_chamelium_frames: Use for_each_format_and_modifier() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 19/25] tests/kms_plane: Use igt_format_mods_has_modifier() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 20/25] tests/kms_plane: Use for_each_format_and_modifier() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 21/25] tests/kms_async_flips: Remove the IN_FORMAT_ASYNC check Ville Syrjala
2026-05-14 5:18 ` Reddy Guddati, Santhosh
2026-05-12 12:21 ` [PATCH i-g-t 22/25] tests/kms_async_flips: Use igt_format_mods_has_modifier() Ville Syrjala
2026-05-14 4:27 ` Reddy Guddati, Santhosh
2026-05-12 12:21 ` [PATCH i-g-t 23/25] tests/kms_async_flips: Use for_each_format_and_modifier() and for_each_modifier_with_format() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 24/25] tests/intel/kms_flip_tiling: Use for_each_modifier_with_format() Ville Syrjala
2026-05-12 12:21 ` [PATCH i-g-t 25/25] tests/chamelium/kms_chamelium_frames: Use for_each_format_with_modifier() Ville Syrjala
2026-05-12 22:00 ` ✗ i915.CI.BAT: failure for lib/kms: Clean up format+mod stuff Patchwork
2026-05-13 0:10 ` ✗ Xe.CI.BAT: " Patchwork
2026-05-13 4:25 ` ✓ i915.CI.BAT: success for lib/kms: Clean up format+mod stuff (rev3) Patchwork
2026-05-13 4:34 ` ✓ Xe.CI.BAT: " Patchwork
2026-05-13 17:00 ` ✗ Xe.CI.FULL: failure for lib/kms: Clean up format+mod stuff Patchwork
2026-05-14 0:12 ` ✗ Xe.CI.FULL: failure for lib/kms: Clean up format+mod stuff (rev3) Patchwork
2026-05-14 2:27 ` ✗ i915.CI.Full: " Patchwork
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=20260513031724.27229-1-ville.syrjala@linux.intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.