All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stylon Wang <stylon.wang@amd.com>
To: igt-dev@lists.freedesktop.org
Cc: anson.jacob@amd.com, Bhawanpreet.Lakha@amd.com,
	Ahmad.Othman@amd.com, Hayden.Goodfellow@amd.com
Subject: [igt-dev] [PATCH i-g-t 05/11] tests/amdgpu/amd_plane: Create mpo panning test
Date: Tue, 30 Nov 2021 16:34:57 +0800	[thread overview]
Message-ID: <20211130083503.10221-6-stylon.wang@amd.com> (raw)
In-Reply-To: <20211130083503.10221-1-stylon.wang@amd.com>

From: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>

[Why]
Moving the MPO window is a common usecase (video window being moved).
This test creates a MPO window and moves it horizontally, vertically and
diagonally

[How]
Create common video resolution windows and move them across the
displays. Test pass is determined by getting a crc of window location
using a single plane, then recreating this scenario using overlay.

Test panes from Start->End1, Start->End2 and Start->End3

                  CRTC#1
    Start
    +--------+--------+--------+
    |Primary |  -->   |Primary | End1
    +--------+        +--------+
    |  |      \      Overlay   |
    |  v        *              |
    +--------+    \   +--------+
    |Primary |        |Primary | End2
    +--------+--------+--------+
     End3

Signed-off-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
---
 tests/amdgpu/amd_plane.c | 261 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 261 insertions(+)

diff --git a/tests/amdgpu/amd_plane.c b/tests/amdgpu/amd_plane.c
index 5666b9e7..09fcf3eb 100644
--- a/tests/amdgpu/amd_plane.c
+++ b/tests/amdgpu/amd_plane.c
@@ -26,6 +26,13 @@
 
 /* Maximum pipes on any AMD ASIC. */
 #define MAX_PIPES 6
+#define DISPLAYS_TO_TEST 2
+
+/* (De)gamma LUT. */
+typedef struct lut {
+	struct drm_color_lut *data;
+	uint32_t size;
+} lut_t;
 
 /* Common test data. */
 typedef struct data {
@@ -79,6 +86,63 @@ static const drmModeModeInfo test_mode_2 = {
 	.vscan = 0,
 };
 
+static const drmModeModeInfo test_mode_3 = {
+	.name = "3840x2160 Test",
+	.vrefresh = 60,
+	.clock = 594000,
+	.hdisplay = 3840,
+	.hsync_start = 4016,
+	.hsync_end = 4104,
+	.htotal = 4400,
+	.vdisplay = 2160,
+	.vsync_start = 2168,
+	.vsync_end = 2178,
+	.vtotal = 2250,
+	.type = DRM_MODE_TYPE_DRIVER,
+	.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
+	.hskew = 0,
+	.vscan = 0,
+};
+
+static void lut_init(lut_t *lut, uint32_t size)
+{
+	igt_assert(size > 0);
+	lut->size = size;
+	lut->data = malloc(size * sizeof(struct drm_color_lut));
+	igt_assert(lut);
+}
+static void lut_gen(lut_t *lut)
+{
+	uint32_t i;
+	/* 10% threshold */
+	uint32_t threshold = (256 * 10) / 100;
+
+	for (i = 0; i < threshold; ++i) {
+		uint32_t v = 0;
+		lut->data[i].red = v;
+		lut->data[i].blue = v;
+		lut->data[i].green = v;
+	}
+	for (i = threshold; i < lut->size; ++i) {
+		uint32_t v = 0xffff;
+		lut->data[i].red = v;
+		lut->data[i].blue = v;
+		lut->data[i].green = v;
+	}
+}
+static void lut_free(lut_t *lut)
+{
+	if (lut->data) {
+		free(lut->data);
+		lut->data = NULL;
+	}
+	lut->size = 0;
+}
+
+enum test {
+	MPO_SINGLE_PAN
+};
+
 static void test_init(data_t *data)
 {
 	igt_display_t *display = &data->display;
@@ -174,10 +238,205 @@ static void draw_color_alpha(igt_fb_t *fb, int x, int y, int w, int h,
 		             double r, double g, double b, double a)
 {
 	cairo_t *cr = igt_get_cairo_ctx(fb->fd, fb);
+	cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
 	igt_paint_color_alpha(cr, x, y, w, h, r, g, b, a);
 	igt_put_cairo_ctx(cr);
 }
 
+struct fbc {
+	igt_fb_t ref_primary;
+	igt_fb_t test_primary;
+	igt_fb_t test_overlay;
+	igt_crc_t ref_crc;
+};
+
+/* Sets the regamma LUT. */
+static void set_regamma_lut(data_t *data, lut_t const *lut, int n)
+{
+	size_t size = lut ? sizeof(lut->data) * lut->size : 0;
+	const void *ptr = lut ? lut->data : NULL;
+	igt_pipe_obj_replace_prop_blob(data->pipe[n], IGT_CRTC_GAMMA_LUT, ptr,
+				       size);
+}
+
+/*
+ * Compares the result of white backgroud with white window with and without MPO
+ *
+ * Reference crc:
+ * Draws a White background of size (pw,ph).
+ *
+ * Test crc:
+ * Draws a White Overlay of size (pw,ph) then creates a cutout of size (p,w) at location (x,y)
+ * Draws a White Primary plane of size (p,w) at location (x,y) (under the overlay)
+ *
+ * NOTE: The reason for using White+White is to speed up the crc (reuse the ref crc for all cases vs taking
+ * a ref crc per flip)
+ */
+static void test_plane(data_t *data, int n, int x, int y, int w, int h, int pw, int ph, struct fbc *fbc){
+
+	igt_crc_t test_crc;
+	igt_display_t *display = &data->display;
+
+	/* Reference: */
+
+	igt_plane_set_fb(data->primary[n], &fbc[n].ref_primary);
+
+	igt_plane_set_position(data->primary[n], 0, 0);
+	igt_plane_set_size(data->primary[n], pw, ph);
+
+	igt_display_commit_atomic(display, 0, 0);
+
+	/* Test: */
+	/* Draw a white overlay with a cutout */
+	draw_color_alpha(&fbc[n].test_overlay, 0, 0, pw, ph, 1.0, 1.0, 1.0, 1.00);
+	draw_color_alpha(&fbc[n].test_overlay, x, y, w, h, 0.0, 0.0, 0.0, 0.0);
+
+	igt_plane_set_fb(data->primary[n], &fbc[n].test_primary);
+	igt_plane_set_fb(data->overlay[n], &fbc[n].test_overlay);
+
+	/* Move the overlay to cover the cutout */
+	igt_plane_set_position(data->primary[n], x, y);
+	igt_plane_set_size(data->primary[n], w, h);
+
+	igt_display_commit_atomic(display, 0, 0);
+	igt_pipe_crc_collect_crc(data->pipe_crc[n], &test_crc);
+	igt_plane_set_fb(data->overlay[n], NULL);
+
+	igt_assert_crc_equal(&fbc[n].ref_crc, &test_crc);
+
+	/* Set window to white, this is to avoid flashing between black/white after each flip */
+	draw_color_alpha(&fbc[n].ref_primary, 0, 0, pw, ph, 1.0, 1.0, 1.0, 1.00);
+	igt_plane_set_fb(data->primary[n], &fbc[n].ref_primary);
+	igt_plane_set_position(data->primary[n], 0, 0);
+	igt_plane_set_size(data->primary[n], pw, ph);
+	igt_display_commit_atomic(display, 0, 0);
+
+
+}
+/*
+ * MPO_SINGLE_PAN: This test moves the window (w,h) horizontally, vertically and diagonally
+ * Horizontal: from top-left (0,0) to top-right (pw-w,0)
+ * Vertical: from top-left (0,0) to bottom-left (0,ph-h)
+ * Diagonal: from top-left (0,0) to bottom-right (pw-w, ph-h)
+ */
+static void test_panning_1_display(data_t *data, int display_count, int w, int h, struct fbc *fb)
+{
+	/* x and y movements */
+	int dir[3][2]= {
+		{0,1}, /* Only Y */
+		{1,0}, /* Only X */
+		{1,1}, /* Both X and Y */
+
+	};
+
+	/* # of iterations to use to move from one side to the other */
+	int it = 3;
+
+	for (int n = 0; n < display_count; n++) {
+
+		int pw = data->w[n];
+		int ph = data->h[n];
+		int dx = (pw-w)/it;
+		int dy = (ph-h)/it;
+
+		for (int i = 0; i < ARRAY_SIZE(dir); i++){
+			for (int j = 0; j <= it; j++){
+
+				int x = dx*j*dir[i][0];
+				int y = dy*j*dir[i][1];
+
+				/* No need to pan a overley that is bigger than the display */
+				if (pw <= w && ph <= h)
+					break;
+
+				test_plane(data, n, x, y, w, h, pw, ph, fb);
+
+			}
+		}
+	}
+
+	return;
+
+
+}
+
+
+/*
+ * Setup and runner for panning test. Creates common video sizes and pans them across the display
+ */
+static void test_display_mpo(data_t *data, enum test test, uint32_t format, int display_count)
+{
+
+	igt_display_t *display = &data->display;
+	uint32_t regamma_lut_size;
+	lut_t lut;
+	struct fbc fb[4];
+	int videos[][2]= {
+		{426, 240},
+		{640, 360},
+		{854, 480},
+		{1280, 720},
+		{1920, 1080},
+		{2560, 1440},
+		{3840, 2160},
+	};
+
+	test_init(data);
+
+	regamma_lut_size = igt_pipe_obj_get_prop(data->pipe[0], IGT_CRTC_GAMMA_LUT_SIZE);
+	igt_assert_lt(0, regamma_lut_size);
+	lut_init(&lut, regamma_lut_size);
+	lut_gen(&lut);
+
+	for (int n = 0; n < display_count;  n++) {
+		int w = data->w[n];
+		int h = data->h[n];
+
+		if (w == 0) {
+			force_output_mode(data, data->output[n], &test_mode_3);
+			w = data->w[n] = test_mode_3.hdisplay;
+			h = data->h[n] = test_mode_3.vdisplay;
+		}
+
+		igt_output_set_pipe(data->output[n], data->pipe_id[n]);
+
+		igt_create_fb(data->fd, w, h, DRM_FORMAT_XRGB8888, 0, &fb[n].ref_primary);
+		igt_create_color_fb(data->fd, w, h, DRM_FORMAT_XRGB8888, 0, 1.0, 1.0, 1.0, &fb[n].ref_primary);
+		igt_create_fb(data->fd, w, h, DRM_FORMAT_ARGB8888, 0, &fb[n].test_overlay);
+
+		igt_plane_set_fb(data->primary[n], &fb[n].ref_primary);
+
+		if (format == DRM_FORMAT_NV12)
+			set_regamma_lut(data, &lut,  n);
+	}
+
+	igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, 0);
+
+	for (int n = 0; n < display_count; n++)
+		igt_pipe_crc_collect_crc(data->pipe_crc[n], &fb[n].ref_crc);
+
+	for (int i = 0; i < ARRAY_SIZE(videos); ++i) {
+
+		for (int n = 0; n < display_count; n++)
+			igt_create_color_fb(data->fd, videos[i][0], videos[i][1],
+					    format, 0, 1.0, 1.0, 1.0, &fb[n].test_primary);
+
+		if (test == MPO_SINGLE_PAN)
+			test_panning_1_display(data, display_count, videos[i][0], videos[i][1], fb);
+
+		for (int n = 0; n < display_count; n++)
+			igt_remove_fb(data->fd, &fb[n].test_primary);
+	}
+
+	test_fini(data);
+
+	lut_free(&lut);
+
+	for (int n = 0; n < display_count; n++) {
+		igt_remove_fb(data->fd, &fb[n].ref_primary);
+		igt_remove_fb(data->fd, &fb[n].test_overlay);
+	}
+}
 /*
  * Compares a white 4K reference FB against a white 4K primary FB and a
  * white 4K overlay with an RGBA (0, 0, 0, 0) cutout in the center.
@@ -395,6 +654,8 @@ igt_main
 	igt_subtest("mpo-swizzle-toggle") test_mpo_swizzle_toggle(&data);
 	igt_subtest("mpo-swizzle-toggle-multihead")
 		test_mpo_swizzle_toggle_multihead(&data);
+	igt_subtest("mpo-pan-rgb") test_display_mpo(&data, MPO_SINGLE_PAN, DRM_FORMAT_XRGB8888, DISPLAYS_TO_TEST);
+	igt_subtest("mpo-pan-nv12") test_display_mpo(&data, MPO_SINGLE_PAN, DRM_FORMAT_NV12, DISPLAYS_TO_TEST);
 
 	igt_fixture
 	{
-- 
2.33.1

  parent reply	other threads:[~2021-11-30  8:35 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30  8:34 [igt-dev] [PATCH i-g-t 00/11] Create tests for multi-plane overlay Stylon Wang
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 01/11] tests/amdgpu/amd_plane: Introduced 4K MPO test Stylon Wang
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 02/11] tests/amdgpu/amd_plane: Add MPO swizzle mode toggle test Stylon Wang
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 03/11] tests/amdgpu/amd_plane: fixes for test-4k-mpo Stylon Wang
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 04/11] tests/amdgpu/amd_plane: Switch mpo-swizzle-toggle to single-head Stylon Wang
2021-11-30  8:34 ` Stylon Wang [this message]
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 06/11] tests/amdgpu/amd_plane: Create mpo swap between 2 displays test Stylon Wang
2021-11-30  8:34 ` [igt-dev] [PATCH i-g-t 07/11] tests/amdgpu/amd_plane: Create mpo scaling tests Stylon Wang
2021-11-30  8:35 ` [igt-dev] [PATCH i-g-t 08/11] tests/amdgpu/amd_plane: Add MPO scale and pan subtest single display option Stylon Wang
2021-11-30  8:35 ` [igt-dev] [PATCH i-g-t 09/11] tests/amdgpu/amd_plane: Add full screen scaling test case Stylon Wang
2021-11-30  8:35 ` [igt-dev] [PATCH i-g-t 10/11] tests/amdgpu/amd_plane: Ensure pipes are enabled before accessing Stylon Wang
2021-11-30  8:35 ` [igt-dev] [PATCH i-g-t 11/11] tests/amdgpu/amd_plane: Add P010 format to MPO tests and add test descriptions Stylon Wang
2021-11-30 11:10 ` [igt-dev] ✗ Fi.CI.BUILD: failure for Create tests for multi-plane overlay Patchwork
2021-12-01  6:54 ` [igt-dev] [PATCH i-g-t v2 00/11] " Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 01/11] tests/amdgpu/amd_plane: Introduced 4K MPO test Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 02/11] tests/amdgpu/amd_plane: Add MPO swizzle mode toggle test Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 03/11] tests/amdgpu/amd_plane: fixes for test-4k-mpo Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 04/11] tests/amdgpu/amd_plane: Switch mpo-swizzle-toggle to single-head Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 05/11] tests/amdgpu/amd_plane: Create mpo panning test Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 06/11] tests/amdgpu/amd_plane: Create mpo swap between 2 displays test Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 07/11] tests/amdgpu/amd_plane: Create mpo scaling tests Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 08/11] tests/amdgpu/amd_plane: Add MPO scale and pan subtest single display option Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 09/11] tests/amdgpu/amd_plane: Add full screen scaling test case Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 10/11] tests/amdgpu/amd_plane: Ensure pipes are enabled before accessing Stylon Wang
2021-12-01  6:54   ` [igt-dev] [PATCH i-g-t v2 11/11] tests/amdgpu/amd_plane: Add P010 format to MPO tests and add test descriptions Stylon Wang
2021-12-01 22:09 ` [igt-dev] [PATCH i-g-t 00/11] Create tests for multi-plane overlay Rodrigo Siqueira Jordao

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=20211130083503.10221-6-stylon.wang@amd.com \
    --to=stylon.wang@amd.com \
    --cc=Ahmad.Othman@amd.com \
    --cc=Bhawanpreet.Lakha@amd.com \
    --cc=Hayden.Goodfellow@amd.com \
    --cc=anson.jacob@amd.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.