From: Alex Hung <alex.hung@amd.com>
To: <dri-devel@lists.freedesktop.org>, <amd-gfx@lists.freedesktop.org>
Cc: <wayland-devel@lists.freedesktop.org>, <harry.wentland@amd.com>,
<alex.hung@amd.com>, <leo.liu@amd.com>,
<ville.syrjala@linux.intel.com>, <pekka.paalanen@collabora.com>,
<contact@emersion.fr>, <mwen@igalia.com>, <jadahl@redhat.com>,
<sebastian.wick@redhat.com>, <shashank.sharma@amd.com>,
<agoins@nvidia.com>, <joshua@froggi.es>, <mdaenzer@redhat.com>,
<aleixpol@kde.org>, <xaver.hugl@gmail.com>,
<victoria@system76.com>, <daniel@ffwll.ch>,
<uma.shankar@intel.com>, <quic_naseer@quicinc.com>,
<quic_cbraga@quicinc.com>, <quic_abhinavk@quicinc.com>,
<marcan@marcan.st>, <Liviu.Dudau@arm.com>,
<sashamcintosh@google.com>, <chaitanya.kumar.borah@intel.com>,
<louis.chauvet@bootlin.com>, <mcanal@igalia.com>,
<nfraprado@collabora.com>, <arthurgrillo@riseup.net>,
Daniel Stone <daniels@collabora.com>
Subject: [PATCH V12 02/49] drm/vkms: Add kunit tests for VKMS LUT handling
Date: Wed, 29 Oct 2025 21:42:07 -0600 [thread overview]
Message-ID: <20251030034349.2309829-3-alex.hung@amd.com> (raw)
In-Reply-To: <20251030034349.2309829-1-alex.hung@amd.com>
From: Harry Wentland <harry.wentland@amd.com>
Debugging LUT math is much easier when we can unit test
it. Add kunit functionality to VKMS and add tests for
- get_lut_index
- lerp_u16
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
Cc: Arthur Grillo <arthurgrillo@riseup.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
---
v12:
- Reorder header files (Louis Chauvet)
- Add header file "vkms_drv.h" to vkms_composer.h to avoid compile errors (kernel test robot)
v11:
- Refactor vkms_color_test_lerp() to parametized tests (Maíra Canal)
- Sort include file alphabetically (Maíra Canal)
v8:
- Update config names (Louis Chauvet)
v7:
- Fix checkpatch warnings and errors (Louis Chauvet)
- Change SPDX-License-Identifier: GPL-2.0+ from /* */ to //
- Fix checkpatch errors and warnings (new line at EOF, redundant spaces, and long lines)
- Add static to const struct vkms_color_lut test_linear_lut
- Add "MODULE_DESCRIPTION" (Jeff Johnson)
v6:
- Eliminate need to include test as .c file (Louis Chauvet)
v5:
- Bring back static for lerp_u16 and get_lut_index (Arthur)
v4:
- Test the critical points of the lerp function (Pekka)
v3:
- Use include way of testing static functions (Arthur)
drivers/gpu/drm/vkms/tests/Makefile | 2 +-
drivers/gpu/drm/vkms/tests/vkms_color_test.c | 130 +++++++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.c | 9 +-
drivers/gpu/drm/vkms/vkms_composer.h | 14 ++
4 files changed, 151 insertions(+), 4 deletions(-)
create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_test.c
create mode 100644 drivers/gpu/drm/vkms/vkms_composer.h
diff --git a/drivers/gpu/drm/vkms/tests/Makefile b/drivers/gpu/drm/vkms/tests/Makefile
index 5750f0bd9d40..a834d182b022 100644
--- a/drivers/gpu/drm/vkms/tests/Makefile
+++ b/drivers/gpu/drm/vkms/tests/Makefile
@@ -4,4 +4,4 @@ vkms-kunit-tests-y := \
vkms_config_test.o \
vkms_format_test.o
-obj-$(CONFIG_DRM_VKMS_KUNIT_TEST) += vkms-kunit-tests.o
+obj-$(CONFIG_DRM_VKMS_KUNIT_TEST) += vkms-kunit-tests.o vkms_config_test.o vkms_color_test.o
diff --git a/drivers/gpu/drm/vkms/tests/vkms_color_test.c b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
new file mode 100644
index 000000000000..582fae1f3220
--- /dev/null
+++ b/drivers/gpu/drm/vkms/tests/vkms_color_test.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <kunit/test.h>
+
+#include <drm/drm_fixed.h>
+#include <drm/drm_mode.h>
+#include "../vkms_composer.h"
+#include "../vkms_drv.h"
+
+#define TEST_LUT_SIZE 16
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static struct drm_color_lut test_linear_array[TEST_LUT_SIZE] = {
+ { 0x0, 0x0, 0x0, 0 },
+ { 0x1111, 0x1111, 0x1111, 0 },
+ { 0x2222, 0x2222, 0x2222, 0 },
+ { 0x3333, 0x3333, 0x3333, 0 },
+ { 0x4444, 0x4444, 0x4444, 0 },
+ { 0x5555, 0x5555, 0x5555, 0 },
+ { 0x6666, 0x6666, 0x6666, 0 },
+ { 0x7777, 0x7777, 0x7777, 0 },
+ { 0x8888, 0x8888, 0x8888, 0 },
+ { 0x9999, 0x9999, 0x9999, 0 },
+ { 0xaaaa, 0xaaaa, 0xaaaa, 0 },
+ { 0xbbbb, 0xbbbb, 0xbbbb, 0 },
+ { 0xcccc, 0xcccc, 0xcccc, 0 },
+ { 0xdddd, 0xdddd, 0xdddd, 0 },
+ { 0xeeee, 0xeeee, 0xeeee, 0 },
+ { 0xffff, 0xffff, 0xffff, 0 },
+};
+
+/* lerp test parameters */
+struct vkms_color_test_lerp_params {
+ s64 t;
+ __u16 a;
+ __u16 b;
+ __u16 expected;
+};
+
+/* lerp test cases */
+static const struct vkms_color_test_lerp_params color_test_lerp_cases[] = {
+ /* Half-way round down */
+ { 0x80000000 - 1, 0x0, 0x10, 0x8 },
+ { 0x80000000 - 1, 0x1, 0x10, 0x8 }, /* Odd a */
+ { 0x80000000 - 1, 0x1, 0xf, 0x8 }, /* Odd b */
+ { 0x80000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x80000000 - 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/
+ /* Half-way round up */
+ { 0x80000000, 0x0, 0x10, 0x8 },
+ { 0x80000000, 0x1, 0x10, 0x9 }, /* Odd a */
+ { 0x80000000, 0x1, 0xf, 0x8 }, /* Odd b */
+ { 0x80000000, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x80000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/
+ /* t = 0.0 */
+ { 0x0, 0x0, 0x10, 0x0 },
+ { 0x0, 0x1, 0x10, 0x1 }, /* Odd a */
+ { 0x0, 0x1, 0xf, 0x1 }, /* Odd b */
+ { 0x0, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x0, 0x10, 0x11, 0x10 }, /* b = a + 1*/
+ /* t = 1.0 */
+ { 0x100000000, 0x0, 0x10, 0x10 },
+ { 0x100000000, 0x1, 0x10, 0x10 }, /* Odd a */
+ { 0x100000000, 0x1, 0xf, 0xf }, /* Odd b */
+ { 0x100000000, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x100000000, 0x10, 0x11, 0x11 }, /* b = a + 1*/
+ /* t = 0.0 + 1 */
+ { 0x0 + 1, 0x0, 0x10, 0x0 },
+ { 0x0 + 1, 0x1, 0x10, 0x1 }, /* Odd a */
+ { 0x0 + 1, 0x1, 0xf, 0x1 }, /* Odd b */
+ { 0x0 + 1, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x0 + 1, 0x10, 0x11, 0x10 }, /* b = a + 1*/
+ /* t = 1.0 - 1 */
+ { 0x100000000 - 1, 0x0, 0x10, 0x10 },
+ { 0x100000000 - 1, 0x1, 0x10, 0x10 }, /* Odd a */
+ { 0x100000000 - 1, 0x1, 0xf, 0xf }, /* Odd b */
+ { 0x100000000 - 1, 0x10, 0x10, 0x10 }, /* b = a */
+ { 0x100000000 - 1, 0x10, 0x11, 0x11 }, /* b = a + 1*/
+ /* t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) */
+ { 0x80000000 - 1, 0x0, 0x1, 0x0 },
+ { 0x80000000, 0x0, 0x1, 0x1 },
+};
+
+static const struct vkms_color_lut test_linear_lut = {
+ .base = test_linear_array,
+ .lut_length = TEST_LUT_SIZE,
+ .channel_value2index_ratio = 0xf000fll
+};
+
+
+static void vkms_color_test_get_lut_index(struct kunit *test)
+{
+ s64 lut_index;
+ int i;
+
+ lut_index = get_lut_index(&test_linear_lut, test_linear_array[0].red);
+ KUNIT_EXPECT_EQ(test, drm_fixp2int(lut_index), 0);
+
+ for (i = 0; i < TEST_LUT_SIZE; i++) {
+ lut_index = get_lut_index(&test_linear_lut, test_linear_array[i].red);
+ KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(lut_index), i);
+ }
+}
+
+static void vkms_color_test_lerp(struct kunit *test)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(color_test_lerp_cases); i++) {
+ const struct vkms_color_test_lerp_params *params = &color_test_lerp_cases[i];
+
+ KUNIT_EXPECT_EQ(test, lerp_u16(params->a, params->b, params->t), params->expected);
+ }
+}
+
+static struct kunit_case vkms_color_test_cases[] = {
+ KUNIT_CASE(vkms_color_test_get_lut_index),
+ KUNIT_CASE(vkms_color_test_lerp),
+ {}
+};
+
+static struct kunit_suite vkms_color_test_suite = {
+ .name = "vkms-color",
+ .test_cases = vkms_color_test_cases,
+};
+
+kunit_test_suite(vkms_color_test_suite);
+
+MODULE_DESCRIPTION("Kunit test for VKMS LUT handling");
+MODULE_LICENSE("GPL");
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index fa269d279e25..a0ca28a253d2 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -10,8 +10,9 @@
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_vblank.h>
#include <linux/minmax.h>
+#include <kunit/visibility.h>
-#include "vkms_drv.h"
+#include "vkms_composer.h"
static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)
{
@@ -60,7 +61,7 @@ static void fill_background(const struct pixel_argb_u16 *background_color,
}
// lerp(a, b, t) = a + (b - a) * t
-static u16 lerp_u16(u16 a, u16 b, s64 t)
+VISIBLE_IF_KUNIT u16 lerp_u16(u16 a, u16 b, s64 t)
{
s64 a_fp = drm_int2fixp(a);
s64 b_fp = drm_int2fixp(b);
@@ -69,13 +70,15 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)
return drm_fixp2int_round(a_fp + delta);
}
+EXPORT_SYMBOL_IF_KUNIT(lerp_u16);
-static s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value)
+VISIBLE_IF_KUNIT s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value)
{
s64 color_channel_fp = drm_int2fixp(channel_value);
return drm_fixp_mul(color_channel_fp, lut->channel_value2index_ratio);
}
+EXPORT_SYMBOL_IF_KUNIT(get_lut_index);
/*
* This enum is related to the positions of the variables inside
diff --git a/drivers/gpu/drm/vkms/vkms_composer.h b/drivers/gpu/drm/vkms/vkms_composer.h
new file mode 100644
index 000000000000..45f5e6a4986e
--- /dev/null
+++ b/drivers/gpu/drm/vkms/vkms_composer.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef _VKMS_COMPOSER_H_
+#define _VKMS_COMPOSER_H_
+
+#include <kunit/visibility.h>
+#include "vkms_drv.h"
+
+#if IS_ENABLED(CONFIG_KUNIT)
+u16 lerp_u16(u16 a, u16 b, s64 t);
+s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value);
+#endif
+
+#endif /* _VKMS_COMPOSER_H_ */
--
2.43.0
next prev parent reply other threads:[~2025-10-30 3:45 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 3:42 [PATCH V12 00/49] Color Pipeline API w/ VKMS Alex Hung
2025-10-30 3:42 ` [PATCH V12 01/49] drm: Add helper for conversion from signed-magnitude Alex Hung
2025-10-30 3:42 ` Alex Hung [this message]
2025-10-30 14:50 ` [PATCH V12 02/49] drm/vkms: Add kunit tests for VKMS LUT handling Louis Chauvet
2025-10-31 0:01 ` Alex Hung
2025-10-30 3:42 ` [PATCH V12 03/49] drm/doc/rfc: Describe why prescriptive color pipeline is needed Alex Hung
2025-10-30 3:42 ` [PATCH V12 04/49] drm/colorop: Introduce new drm_colorop mode object Alex Hung
2025-10-30 3:42 ` [PATCH V12 05/49] drm/colorop: Add TYPE property Alex Hung
2025-10-30 3:42 ` [PATCH V12 06/49] drm/colorop: Add 1D Curve subtype Alex Hung
2025-10-30 3:42 ` [PATCH V12 07/49] drm/colorop: Add BYPASS property Alex Hung
2025-10-30 3:42 ` [PATCH V12 08/49] drm/colorop: Add NEXT property Alex Hung
2025-10-30 3:42 ` [PATCH V12 09/49] drm/colorop: Add atomic state print for drm_colorop Alex Hung
2025-10-30 3:42 ` [PATCH V12 10/49] drm/plane: Add COLOR PIPELINE property Alex Hung
2025-10-30 3:42 ` [PATCH V12 11/49] drm/colorop: Introduce DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE Alex Hung
2025-10-30 3:42 ` [PATCH V12 12/49] Documentation/gpu: document drm_colorop Alex Hung
2025-10-30 3:42 ` [PATCH V12 13/49] drm/colorop: Add destroy functions for color pipeline Alex Hung
2025-10-30 3:42 ` [PATCH V12 14/49] drm/vkms: Add enumerated 1D curve colorop Alex Hung
2025-10-30 14:50 ` Louis Chauvet
2025-10-31 0:04 ` Alex Hung
2025-10-31 10:15 ` Louis Chauvet
2025-10-31 22:28 ` Alex Hung
2025-10-30 3:42 ` [PATCH V12 15/49] drm/vkms: Add kunit tests for linear and sRGB LUTs Alex Hung
2025-10-30 3:42 ` [PATCH V12 16/49] drm/colorop: Add 3x4 CTM type Alex Hung
2025-10-30 3:42 ` [PATCH V12 17/49] drm/vkms: Use s32 for internal color pipeline precision Alex Hung
2025-10-30 3:42 ` [PATCH V12 18/49] drm/vkms: add 3x4 matrix in color pipeline Alex Hung
2025-10-30 3:42 ` [PATCH V12 19/49] drm/tests: Add a few tests around drm_fixed.h Alex Hung
2025-10-30 3:42 ` [PATCH V12 20/49] drm/vkms: Add tests for CTM handling Alex Hung
2025-10-30 3:42 ` [PATCH V12 21/49] drm/colorop: pass plane_color_pipeline client cap to atomic check Alex Hung
2025-10-30 3:42 ` [PATCH V12 22/49] drm/colorop: define a new macro for_each_new_colorop_in_state Alex Hung
2025-10-30 3:42 ` [PATCH V12 23/49] drm/amd/display: Ignore deprecated props when plane_color_pipeline set Alex Hung
2025-10-30 3:42 ` [PATCH V12 24/49] drm/amd/display: Add bypass COLOR PIPELINE Alex Hung
2025-10-30 3:42 ` [PATCH V12 25/49] drm/amd/display: Skip color pipeline initialization for cursor plane Alex Hung
2025-10-30 3:42 ` [PATCH V12 26/49] drm/amd/display: Add support for sRGB EOTF in DEGAM block Alex Hung
2025-10-30 3:42 ` [PATCH V12 27/49] drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block Alex Hung
2025-10-30 3:42 ` [PATCH V12 28/49] drm/amd/display: Add support for sRGB EOTF in BLND block Alex Hung
2025-10-30 3:42 ` [PATCH V12 29/49] drm/colorop: Add PQ 125 EOTF and its inverse Alex Hung
2025-10-30 3:42 ` [PATCH V12 30/49] drm/amd/display: Enable support for PQ 125 EOTF and Inverse Alex Hung
2025-10-30 3:42 ` [PATCH V12 31/49] drm/colorop: add BT2020/BT709 OETF and Inverse OETF Alex Hung
2025-10-30 3:42 ` [PATCH V12 32/49] drm/amd/display: Add support for BT.709 and BT.2020 TFs Alex Hung
2025-10-30 3:42 ` [PATCH V12 33/49] drm: Add Enhanced LUT precision structure Alex Hung
2025-10-30 3:42 ` [PATCH V12 34/49] drm: Add helper to extract lut from struct drm_color_lut32 Alex Hung
2025-10-30 3:42 ` [PATCH V12 35/49] drm/colorop: Add 1D Curve Custom LUT type Alex Hung
2025-10-30 3:42 ` [PATCH V12 36/49] drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT Alex Hung
2025-10-30 3:42 ` [PATCH V12 37/49] drm/amd/display: add 3x4 matrix colorop Alex Hung
2025-10-30 3:42 ` [PATCH V12 38/49] drm/colorop: Add multiplier type Alex Hung
2025-10-30 3:42 ` [PATCH V12 39/49] drm/amd/display: add multiplier colorop Alex Hung
2025-10-30 3:42 ` [PATCH V12 40/49] drm/amd/display: Swap matrix and multiplier Alex Hung
2025-10-30 3:42 ` [PATCH V12 41/49] drm/colorop: Define LUT_1D interpolation Alex Hung
2025-10-30 3:42 ` [PATCH V12 42/49] drm/colorop: allow non-bypass colorops Alex Hung
2025-10-30 3:42 ` [PATCH V12 43/49] drm/colorop: Add 3D LUT support to color pipeline Alex Hung
2025-10-30 3:42 ` [PATCH V12 44/49] drm/amd/display: add 3D LUT colorop Alex Hung
2025-10-30 3:42 ` [PATCH V12 45/49] drm/amd/display: Add AMD color pipeline doc Alex Hung
2025-10-30 3:42 ` [PATCH V12 46/49] drm/amd/display: Ensure 3D LUT for color pipeline Alex Hung
2025-11-13 19:40 ` Harry Wentland
2025-10-30 3:42 ` [PATCH V12 47/49] drm/amd/display: Disable CRTC degamma when color pipeline is enabled Alex Hung
2025-11-13 19:46 ` Harry Wentland
2025-10-30 3:42 ` [PATCH V12 48/49] drm/colorop: Add DRM_COLOROP_1D_CURVE_GAMMA22 to 1D Curve Alex Hung
2025-11-13 19:47 ` Harry Wentland
2025-10-30 3:42 ` [PATCH V12 49/49] drm/amd/display: Enable support for Gamma 2.2 Alex Hung
2025-11-13 19:50 ` Harry Wentland
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=20251030034349.2309829-3-alex.hung@amd.com \
--to=alex.hung@amd.com \
--cc=Liviu.Dudau@arm.com \
--cc=agoins@nvidia.com \
--cc=aleixpol@kde.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=arthurgrillo@riseup.net \
--cc=chaitanya.kumar.borah@intel.com \
--cc=contact@emersion.fr \
--cc=daniel@ffwll.ch \
--cc=daniels@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=jadahl@redhat.com \
--cc=joshua@froggi.es \
--cc=leo.liu@amd.com \
--cc=louis.chauvet@bootlin.com \
--cc=marcan@marcan.st \
--cc=mcanal@igalia.com \
--cc=mdaenzer@redhat.com \
--cc=mwen@igalia.com \
--cc=nfraprado@collabora.com \
--cc=pekka.paalanen@collabora.com \
--cc=quic_abhinavk@quicinc.com \
--cc=quic_cbraga@quicinc.com \
--cc=quic_naseer@quicinc.com \
--cc=sashamcintosh@google.com \
--cc=sebastian.wick@redhat.com \
--cc=shashank.sharma@amd.com \
--cc=uma.shankar@intel.com \
--cc=victoria@system76.com \
--cc=ville.syrjala@linux.intel.com \
--cc=wayland-devel@lists.freedesktop.org \
--cc=xaver.hugl@gmail.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