Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Yuling Li <Yuling.Li@amd.com>
To: <igt-dev@lists.freedesktop.org>
Cc: <vitaly.prosyak@amd.com>, Yuling Li <Yuling.Li@amd.com>
Subject: [PATCH i-g-t] tests/kms_plane_cursor: add native cursor test with multiple overlays
Date: Fri, 20 Nov 2026 15:30:49 +0800	[thread overview]
Message-ID: <20261120073049.91138-1-Yuling.Li@amd.com> (raw)

Exercise native cursor visibility while three overlay planes are
switched between quadrant positions.

This reproduces incorrect cursor suppression when a split overlay
is mistaken for a split partner that covers the lower pipe.
The issue exposed by this test was fixed in Linux kernel.

Signed-off-by: Yuling Li <Yuling.Li@amd.com>
---
 tests/kms_plane_cursor.c | 233 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 228 insertions(+), 5 deletions(-)

diff --git a/tests/kms_plane_cursor.c b/tests/kms_plane_cursor.c
index 4b69f1a17..48e5a1c13 100644
--- a/tests/kms_plane_cursor.c
+++ b/tests/kms_plane_cursor.c
@@ -24,7 +24,7 @@
  * TEST: kms plane cursor
  * Category: Display
  * Description: Tests cursor interactions with primary and overlay planes.
- * Driver requirement: i915, xe
+ * Driver requirement: i915, xe, amdgpu
  * Mega feature: General Display Features
  */
 
@@ -37,6 +37,10 @@
  * SUBTEST: primary
  * Description: Tests atomic cursor positioning on primary plane
  *
+ * SUBTEST: multi-overlay
+ * Description: Tests native cursor positioning with three overlays arranged in
+ *              quadrants while switching their positions
+ *
  * SUBTEST: viewport
  * Description: Tests atomic cursor positioning on primary plane and overlay plane
  *              with buffer larger than viewport used for display
@@ -47,13 +51,14 @@
  *
  * Some assumptions made:
  * - Cursor planes can be placed on top of overlay planes
- * - DRM index indicates z-ordering, higher index = higher z-order
+ * - Overlay z-order follows zpos, with plane ID used to break ties
  */
 
 enum {
 	TEST_PRIMARY = 0,
 	TEST_OVERLAY = 1 << 0,
 	TEST_VIEWPORT = 1 << 1,
+	TEST_MPO = 1 << 2,
 };
 
 typedef struct {
@@ -73,6 +78,7 @@ typedef struct data {
 	igt_display_t display;
 	igt_plane_t *primary;
 	igt_plane_t *overlay;
+	igt_plane_t *overlays[3];
 	igt_plane_t *cursor;
 	igt_output_t *output;
 	igt_crtc_t *crtc;
@@ -81,6 +87,7 @@ typedef struct data {
 	igt_fb_t ref_fb;
 	igt_fb_t pfb;
 	igt_fb_t ofb;
+	igt_fb_t mpo_fbs[3];
 	igt_fb_t cfb;
 	int drm_fd;
 	rect_t rect;
@@ -88,6 +95,49 @@ typedef struct data {
 	uint64_t max_curh;
 } data_t;
 
+enum quadrant {
+	TOP_LEFT,
+	TOP_RIGHT,
+	BOTTOM_LEFT,
+	BOTTOM_RIGHT,
+	QUADRANT_COUNT,
+};
+
+static const enum quadrant mpo_slots[3][3] = {
+	{ TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT },
+	{ BOTTOM_RIGHT, BOTTOM_LEFT, TOP_RIGHT },
+	{ BOTTOM_LEFT, TOP_RIGHT, BOTTOM_RIGHT },
+};
+
+static const double mpo_colors[3][3] = {
+	{ 0.25, 0.25, 0.25 },
+	{ 0.50, 0.50, 0.50 },
+	{ 0.75, 0.75, 0.75 },
+};
+
+static int plane_zpos_cmp(const void *left, const void *right)
+{
+	igt_plane_t *plane_left = *(igt_plane_t * const *)left;
+	igt_plane_t *plane_right = *(igt_plane_t * const *)right;
+	uint64_t zpos_left = 0, zpos_right = 0;
+
+	if (igt_plane_has_prop(plane_left, IGT_PLANE_ZPOS) &&
+	    igt_plane_has_prop(plane_right, IGT_PLANE_ZPOS)) {
+		zpos_left = igt_plane_get_prop(plane_left, IGT_PLANE_ZPOS);
+		zpos_right = igt_plane_get_prop(plane_right, IGT_PLANE_ZPOS);
+	}
+
+	if (zpos_left < zpos_right)
+		return -1;
+	if (zpos_left > zpos_right)
+		return 1;
+	if (plane_left->drm_plane->plane_id < plane_right->drm_plane->plane_id)
+		return -1;
+	if (plane_left->drm_plane->plane_id > plane_right->drm_plane->plane_id)
+		return 1;
+	return 0;
+}
+
 /* Common test setup. */
 static void test_init(data_t *data, igt_crtc_t *crtc, igt_output_t *output,
 		      unsigned int flags)
@@ -99,9 +149,20 @@ static void test_init(data_t *data, igt_crtc_t *crtc, igt_output_t *output,
 
 	data->primary = igt_crtc_get_plane_type(data->crtc,
 						DRM_PLANE_TYPE_PRIMARY);
-	if (flags & TEST_OVERLAY)
+	data->overlay = NULL;
+	memset(data->overlays, 0, sizeof(data->overlays));
+	if (flags & TEST_MPO) {
+		for (int i = 0; i < ARRAY_SIZE(data->overlays); i++)
+			data->overlays[i] =
+				igt_crtc_get_plane_type_index(data->crtc,
+							      DRM_PLANE_TYPE_OVERLAY,
+							      i);
+		qsort(data->overlays, ARRAY_SIZE(data->overlays),
+		      sizeof(data->overlays[0]), plane_zpos_cmp);
+	} else if (flags & TEST_OVERLAY) {
 		data->overlay = igt_crtc_get_plane_type(data->crtc,
 							DRM_PLANE_TYPE_OVERLAY);
+	}
 	data->cursor = igt_crtc_get_plane_type(data->crtc,
 					       DRM_PLANE_TYPE_CURSOR);
 
@@ -127,10 +188,40 @@ static void test_fini(data_t *data)
 	igt_plane_set_fb(data->primary, NULL);
 	if (data->overlay)
 		igt_plane_set_fb(data->overlay, NULL);
+	for (int i = 0; i < ARRAY_SIZE(data->overlays); i++)
+		if (data->overlays[i])
+			igt_plane_set_fb(data->overlays[i], NULL);
 	igt_plane_set_fb(data->cursor, NULL);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 }
 
+static rect_t quadrant_rect(const data_t *data, enum quadrant quadrant)
+{
+	int split_x = (data->mode->hdisplay + 1) / 2;
+	int split_y = (data->mode->vdisplay + 1) / 2;
+	rect_t rect = {
+		.x = quadrant == TOP_RIGHT || quadrant == BOTTOM_RIGHT ?
+		     split_x : 0,
+		.y = quadrant == BOTTOM_LEFT || quadrant == BOTTOM_RIGHT ?
+		     split_y : 0,
+	};
+
+	rect.w = rect.x ? data->mode->hdisplay - split_x : split_x;
+	rect.h = rect.y ? data->mode->vdisplay - split_y : split_y;
+	return rect;
+}
+
+static pos_t quadrant_cursor_pos(const data_t *data, int size,
+				 enum quadrant quadrant)
+{
+	rect_t rect = quadrant_rect(data, quadrant);
+
+	return (pos_t) {
+		.x = rect.x + (rect.w - size) / 2,
+		.y = rect.y + (rect.h - size) / 2,
+	};
+}
+
 /*
  * Draws white and gray (if overlay FB is given) on the primary FB.
  * Draws a magenta square where the cursor should be over top both planes.
@@ -239,10 +330,117 @@ static void test_cursor_spots(data_t *data, int size, unsigned int flags)
 	}
 }
 
+static void set_mpo_overlays(data_t *data, int phase)
+{
+	for (int i = 0; i < ARRAY_SIZE(data->overlays); i++) {
+		rect_t rect = quadrant_rect(data, mpo_slots[phase][i]);
+
+		igt_plane_set_fb(data->overlays[i], &data->mpo_fbs[i]);
+		igt_plane_set_position(data->overlays[i], rect.x, rect.y);
+		igt_plane_set_size(data->overlays[i], rect.w, rect.h);
+		igt_fb_set_position(&data->mpo_fbs[i], data->overlays[i], 0, 0);
+		igt_fb_set_size(&data->mpo_fbs[i], data->overlays[i],
+				rect.w, rect.h);
+	}
+}
+
+static void disable_mpo_planes(data_t *data)
+{
+	for (int i = 0; i < ARRAY_SIZE(data->overlays); i++)
+		igt_plane_set_fb(data->overlays[i], NULL);
+	igt_plane_set_fb(data->cursor, NULL);
+}
+
+static void draw_mpo_reference(data_t *data, int phase, pos_t cursor_pos,
+			       int cursor_size)
+{
+	cairo_t *cr = igt_get_cairo_ctx(data->drm_fd, &data->ref_fb);
+
+	igt_paint_color(cr, 0, 0, data->ref_fb.width, data->ref_fb.height,
+			1.0, 1.0, 1.0);
+
+	for (int i = 0; i < ARRAY_SIZE(data->overlays); i++) {
+		rect_t rect = quadrant_rect(data, mpo_slots[phase][i]);
+
+		igt_paint_color(cr, rect.x, rect.y, rect.w, rect.h,
+				mpo_colors[i][0], mpo_colors[i][1],
+				mpo_colors[i][2]);
+	}
+
+	igt_paint_color(cr, cursor_pos.x, cursor_pos.y,
+			cursor_size, cursor_size, 1.0, 0.0, 1.0);
+	igt_put_cairo_ctx(cr);
+}
+
+static void test_cursor_mpo(data_t *data, int size)
+{
+	igt_crc_t references[3][QUADRANT_COUNT];
+	igt_crc_t test_crc;
+	const enum quadrant positions[] = {
+		BOTTOM_RIGHT,
+		TOP_LEFT,
+		TOP_RIGHT,
+		BOTTOM_LEFT,
+	};
+
+	igt_pipe_crc_start(data->pipe_crc);
+
+	/*
+	 * Capture every software-composited reference before enabling the
+	 * overlays. This leaves the hardware pass free to switch overlay
+	 * topology while the native cursor remains enabled.
+	 */
+	for (int phase = 0; phase < ARRAY_SIZE(mpo_slots); phase++) {
+		for (int i = 0; i < ARRAY_SIZE(positions); i++) {
+			pos_t cursor_pos =
+				quadrant_cursor_pos(data, size, positions[i]);
+
+			draw_mpo_reference(data, phase, cursor_pos, size);
+			igt_plane_set_fb(data->primary, &data->ref_fb);
+			disable_mpo_planes(data);
+			igt_display_commit_atomic(&data->display, 0, NULL);
+			igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc,
+						 &references[phase][i]);
+		}
+	}
+
+	igt_plane_set_fb(data->primary, &data->pfb);
+
+	for (int phase = 0; phase < ARRAY_SIZE(mpo_slots); phase++) {
+		set_mpo_overlays(data, phase);
+
+		for (int i = 0; i < ARRAY_SIZE(positions); i++) {
+			pos_t cursor_pos =
+				quadrant_cursor_pos(data, size, positions[i]);
+
+			/*
+			 * The first commit for each phase switches overlay
+			 * positions with the cursor on the bottom-right pipe.
+			 * Subsequent commits only move the cursor.
+			 */
+			igt_plane_set_fb(data->cursor, &data->cfb);
+			igt_plane_set_position(data->cursor,
+					       cursor_pos.x, cursor_pos.y);
+			igt_display_commit_atomic(&data->display, 0, NULL);
+
+			if (is_amdgpu_device(data->drm_fd))
+				igt_wait_for_vblank_count(data->crtc, 1);
+
+			igt_pipe_crc_get_current(data->drm_fd, data->pipe_crc,
+						 &test_crc);
+			igt_assert_crc_equal(&references[phase][i], &test_crc);
+		}
+	}
+
+	igt_pipe_crc_stop(data->pipe_crc);
+}
+
 static void test_cleanup(data_t *data)
 {
 	igt_remove_fb(data->drm_fd, &data->cfb);
 	igt_remove_fb(data->drm_fd, &data->ofb);
+	for (int i = 0; i < ARRAY_SIZE(data->mpo_fbs); i++)
+		igt_remove_fb(data->drm_fd, &data->mpo_fbs[i]);
 	igt_remove_fb(data->drm_fd, &data->pfb);
 	igt_remove_fb(data->drm_fd, &data->ref_fb);
 }
@@ -257,6 +455,9 @@ static void test_cursor(data_t *data, int size, unsigned int flags)
 	sw = data->mode->hdisplay;
 	sh = data->mode->vdisplay;
 
+	igt_skip_on((flags & TEST_MPO) &&
+		    (size > sw / 2 || size > sh / 2));
+
 	test_cleanup(data);
 
 	igt_create_fb(data->drm_fd, sw, sh, DRM_FORMAT_XRGB8888,
@@ -265,7 +466,19 @@ static void test_cursor(data_t *data, int size, unsigned int flags)
 	igt_create_color_fb(data->drm_fd, sw, sh, DRM_FORMAT_XRGB8888,
 			    DRM_FORMAT_MOD_LINEAR, 1.0, 1.0, 1.0, &data->pfb);
 
-	if (flags & TEST_OVERLAY) {
+	if (flags & TEST_MPO) {
+		int width = (sw + 1) / 2;
+		int height = (sh + 1) / 2;
+
+		for (int i = 0; i < ARRAY_SIZE(data->mpo_fbs); i++)
+			igt_create_color_fb(data->drm_fd, width, height,
+					    DRM_FORMAT_XRGB8888,
+					    DRM_FORMAT_MOD_LINEAR,
+					    mpo_colors[i][0],
+					    mpo_colors[i][1],
+					    mpo_colors[i][2],
+					    &data->mpo_fbs[i]);
+	} else if (flags & TEST_OVERLAY) {
 		int width = (flags & TEST_VIEWPORT) ? data->rect.w + pad : data->rect.w;
 		int height = (flags & TEST_VIEWPORT) ? data->rect.h + pad : data->rect.h;
 
@@ -281,7 +494,10 @@ static void test_cursor(data_t *data, int size, unsigned int flags)
 			    data->crtc);
 	igt_display_commit2(&data->display, COMMIT_ATOMIC);
 
-	test_cursor_spots(data, size, flags);
+	if (flags & TEST_MPO)
+		test_cursor_mpo(data, size);
+	else
+		test_cursor_spots(data, size, flags);
 }
 
 int igt_main()
@@ -304,6 +520,9 @@ int igt_main()
 		{ "viewport", TEST_PRIMARY | TEST_OVERLAY | TEST_VIEWPORT,
 		  "Tests atomic cursor positioning on primary plane and overlay plane "
 		  "with buffer larger than viewport used for display" },
+		{ "multi-overlay", TEST_PRIMARY | TEST_MPO,
+		  "Tests native cursor positioning while switching three overlay "
+		  "planes between quadrant positions" },
 	};
 
 	igt_fixture() {
@@ -334,6 +553,10 @@ int igt_main()
 							     DRM_PLANE_TYPE_OVERLAY))
 					continue;
 
+				if ((tests[i].flags & TEST_MPO) &&
+				    igt_crtc_count_plane_type(crtc, DRM_PLANE_TYPE_OVERLAY) < 3)
+					continue;
+
 				igt_display_reset(display);
 
 				igt_output_set_crtc(output,
-- 
2.34.1


             reply	other threads:[~2026-11-20 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  7:30 Yuling Li [this message]
2026-11-20 14:38 ` ✓ Xe.CI.BAT: success for tests/kms_plane_cursor: add native cursor test with multiple overlays Patchwork
2026-11-20 14:48 ` ✓ i915.CI.BAT: " 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=20261120073049.91138-1-Yuling.Li@amd.com \
    --to=yuling.li@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=vitaly.prosyak@amd.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