All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oarora Etimis <oaroraetimis@gmail.com>
To: Louis Chauvet <louis.chauvet@bootlin.com>,
	 Haneen Mohammed <hamohammed.sa@gmail.com>,
	Simona Vetter <simona@ffwll.ch>,
	 Melissa Wen <melissa.srw@gmail.com>,
	 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	 David Airlie <airlied@gmail.com>, Alex Hung <alex.hung@amd.com>,
	 Robert Mader <robert.mader@collabora.com>,
	 Harry Wentland <harry.wentland@amd.com>,
	Simon Ser <contact@emersion.fr>,
	 Daniel Stone <daniels@collabora.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH 7/7] drm/vkms: add KUnit coverage for the 3D LUT and multiplier colorops
Date: Sat, 28 Nov 2026 18:15:25 +0100	[thread overview]
Message-ID: <20261128-colorop-v1-7-dd79919f822b@gmail.com> (raw)
In-Reply-To: <20261128-colorop-v1-0-dd79919f822b@gmail.com>

The 3D LUT test uses a 2x2x2 identity LUT with inputs that reach all six
tetrahedra, and checks that values outside [0, 1] saturate. The
multiplier test covers gains of 1.0, 0.5, 2.0 and -0.5.

Signed-off-by: Oarora Etimis <oaroraetimis@gmail.com>
---
 drivers/gpu/drm/vkms/tests/vkms_color_test.c | 105 +++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
index 0d68de6462d9..15f71a977ed9 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_color_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -205,6 +205,108 @@ static void vkms_color_test_lut32_single_entry(struct kunit *test)
 						     0xffff, LUT_RED));
 }
 
+/*
+ * A 2x2x2 identity LUT: every corner maps the axis index to the same
+ * value, so any input has to come back unchanged. The entries are ordered
+ * with red as the fastest moving index, as the uapi documents.
+ */
+static const struct drm_color_lut32 test_lut3d_identity[] = {
+	{ 0x00000000, 0x00000000, 0x00000000, 0 },
+	{ 0xffffffff, 0x00000000, 0x00000000, 0 },
+	{ 0x00000000, 0xffffffff, 0x00000000, 0 },
+	{ 0xffffffff, 0xffffffff, 0x00000000, 0 },
+	{ 0x00000000, 0x00000000, 0xffffffff, 0 },
+	{ 0xffffffff, 0x00000000, 0xffffffff, 0 },
+	{ 0x00000000, 0xffffffff, 0xffffffff, 0 },
+	{ 0xffffffff, 0xffffffff, 0xffffffff, 0 },
+};
+
+static void vkms_color_test_lut3d_identity(struct kunit *test)
+{
+	static const struct {
+		u16 r, g, b;
+	} cases[] = {
+		{ 0x0000, 0x0000, 0x0000 },
+		{ 0xffff, 0xffff, 0xffff },
+		{ 0x8000, 0x8000, 0x8000 },
+		{ 0xffff, 0x0000, 0x0000 },
+		{ 0x0000, 0xffff, 0x0000 },
+		{ 0x0000, 0x0000, 0xffff },
+		{ 0x8000, 0x4000, 0x1000 },
+		/* One input per tetrahedron the lists above do not reach. */
+		{ 0x9000, 0x1000, 0x5000 },
+		{ 0x5000, 0x1000, 0x9000 },
+		{ 0x1000, 0x9000, 0x5000 },
+		{ 0x1000, 0x5000, 0x9000 },
+	};
+
+	for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
+		struct pixel_argb_s32 pixel = {
+			.r = cases[i].r,
+			.g = cases[i].g,
+			.b = cases[i].b,
+			.a = 0xffff,
+		};
+
+		apply_3dlut_to_pixel(&pixel, test_lut3d_identity, 2);
+
+		KUNIT_EXPECT_EQ(test, cases[i].r, pixel.r);
+		KUNIT_EXPECT_EQ(test, cases[i].g, pixel.g);
+		KUNIT_EXPECT_EQ(test, cases[i].b, pixel.b);
+		KUNIT_EXPECT_EQ(test, 0xffff, pixel.a);
+	}
+}
+
+/* A value outside [0, 1] saturates at the LUT input instead of wrapping. */
+static void vkms_color_test_lut3d_clamp(struct kunit *test)
+{
+	struct pixel_argb_s32 pixel = {
+		.r = -1,
+		.g = 0x10000,
+		.b = 0xffff,
+		.a = 0xffff,
+	};
+
+	apply_3dlut_to_pixel(&pixel, test_lut3d_identity, 2);
+
+	KUNIT_EXPECT_EQ(test, 0x0000, pixel.r);
+	KUNIT_EXPECT_EQ(test, 0xffff, pixel.g);
+	KUNIT_EXPECT_EQ(test, 0xffff, pixel.b);
+}
+
+static void vkms_color_test_multiplier(struct kunit *test)
+{
+	struct pixel_argb_s32 pixel;
+
+	/* 1.0 leaves the pixel unchanged. */
+	pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+	apply_multiplier_to_pixel(&pixel, 1ULL << 32);
+	KUNIT_EXPECT_EQ(test, 0x8000, pixel.r);
+	KUNIT_EXPECT_EQ(test, 0x4000, pixel.g);
+	KUNIT_EXPECT_EQ(test, 0x2000, pixel.b);
+
+	/* 0.5 halves every channel. */
+	pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+	apply_multiplier_to_pixel(&pixel, 1ULL << 31);
+	KUNIT_EXPECT_EQ(test, 0x4000, pixel.r);
+	KUNIT_EXPECT_EQ(test, 0x2000, pixel.g);
+	KUNIT_EXPECT_EQ(test, 0x1000, pixel.b);
+
+	/* 2.0 doubles every channel. */
+	pixel = (struct pixel_argb_s32){ .r = 0x4000, .g = 0x2000, .b = 0x1000 };
+	apply_multiplier_to_pixel(&pixel, 1ULL << 33);
+	KUNIT_EXPECT_EQ(test, 0x8000, pixel.r);
+	KUNIT_EXPECT_EQ(test, 0x4000, pixel.g);
+	KUNIT_EXPECT_EQ(test, 0x2000, pixel.b);
+
+	/* A negative gain flips the sign; the composer clamps it at the end. */
+	pixel = (struct pixel_argb_s32){ .r = 0x8000, .g = 0x4000, .b = 0x2000 };
+	apply_multiplier_to_pixel(&pixel, (1ULL << 63) | (1ULL << 31));
+	KUNIT_EXPECT_EQ(test, -0x4000, pixel.r);
+	KUNIT_EXPECT_EQ(test, -0x2000, pixel.g);
+	KUNIT_EXPECT_EQ(test, -0x1000, pixel.b);
+}
+
 static void vkms_color_srgb_inv_srgb(struct kunit *test)
 {
 	u16 srgb, final;
@@ -474,6 +576,9 @@ static struct kunit_case vkms_color_test_cases[] = {
 	KUNIT_CASE(vkms_color_test_lut32_three_points),
 	KUNIT_CASE(vkms_color_test_lut32_single_entry),
 	KUNIT_CASE(vkms_color_test_lut32_descending),
+	KUNIT_CASE(vkms_color_test_lut3d_identity),
+	KUNIT_CASE(vkms_color_test_lut3d_clamp),
+	KUNIT_CASE(vkms_color_test_multiplier),
 	KUNIT_CASE(vkms_color_srgb_inv_srgb),
 	KUNIT_CASE(vkms_color_ctm_3x4_50_desat),
 	KUNIT_CASE(vkms_color_ctm_3x4_bt709),

-- 
2.56.1


  parent reply	other threads:[~2026-11-28 17:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 17:15 [PATCH 0/7] drm/vkms: complete the plane color pipeline Oarora Etimis
2026-11-28 17:15 ` [PATCH 1/7] drm/vkms: add the colorops of a plane that is being enabled Oarora Etimis
2026-11-28 17:15 ` [PATCH 2/7] drm/vkms: free the colorop whose initialization failed Oarora Etimis
2026-11-28 17:27   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 3/7] drm/vkms: use the colorop states of the state being composed Oarora Etimis
2026-11-28 17:31   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 4/7] drm/vkms: add a programmable 1D LUT colorop Oarora Etimis
2026-11-28 17:25   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 5/7] drm/vkms: add a 3D " Oarora Etimis
2026-11-28 17:34   ` sashiko-bot
2026-11-28 17:15 ` [PATCH 6/7] drm/vkms: add a multiplier colorop Oarora Etimis
2026-11-28 17:31   ` sashiko-bot
2026-11-28 17:15 ` Oarora Etimis [this message]
2026-11-29 12:37 ` [PATCH 0/7] drm/vkms: complete the plane color pipeline Louis Chauvet

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=20261128-colorop-v1-7-dd79919f822b@gmail.com \
    --to=oaroraetimis@gmail.com \
    --cc=airlied@gmail.com \
    --cc=alex.hung@amd.com \
    --cc=contact@emersion.fr \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hamohammed.sa@gmail.com \
    --cc=harry.wentland@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=louis.chauvet@bootlin.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=melissa.srw@gmail.com \
    --cc=mripard@kernel.org \
    --cc=robert.mader@collabora.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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.