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 <[email protected]>
---
 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

Reply via email to