Skip to content

Commit cb500b4

Browse files
Harry Wentlandemersion
authored andcommitted
drm/vkms: Add kunit tests for linear and sRGB LUTs
Two tests are added to VKMS LUT handling: - linear - inv_srgb 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> Reviewed-by: Daniel Stone <daniels@collabora.com> Signed-off-by: Simon Ser <contact@emersion.fr> Link: https://patch.msgid.link/20251115000237.3561250-18-alex.hung@amd.com
1 parent 9b5c7e8 commit cb500b4

3 files changed

Lines changed: 55 additions & 13 deletions

File tree

drivers/gpu/drm/vkms/tests/vkms_color_test.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <drm/drm_mode.h>
77
#include "../vkms_composer.h"
88
#include "../vkms_drv.h"
9+
#include "../vkms_luts.h"
910

1011
#define TEST_LUT_SIZE 16
1112

@@ -99,6 +100,19 @@ static void vkms_color_test_get_lut_index(struct kunit *test)
99100
lut_index = get_lut_index(&test_linear_lut, test_linear_array[i].red);
100101
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(lut_index), i);
101102
}
103+
104+
KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_eotf, 0x0)), 0x0);
105+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x0)), 0x0);
106+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x101)), 0x1);
107+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0x202)), 0x2);
108+
109+
KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0);
110+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x0)), 0x0);
111+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x101)), 0x1);
112+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_inv_eotf, 0x202)), 0x2);
113+
114+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xfefe)), 0xfe);
115+
KUNIT_EXPECT_EQ(test, drm_fixp2int_ceil(get_lut_index(&srgb_eotf, 0xffff)), 0xff);
102116
}
103117

104118
static void vkms_color_test_lerp(struct kunit *test)
@@ -112,9 +126,33 @@ static void vkms_color_test_lerp(struct kunit *test)
112126
}
113127
}
114128

129+
static void vkms_color_test_linear(struct kunit *test)
130+
{
131+
for (int i = 0; i < LUT_SIZE; i++) {
132+
int linear = apply_lut_to_channel_value(&linear_eotf, i * 0x101, LUT_RED);
133+
134+
KUNIT_EXPECT_EQ(test, DIV_ROUND_CLOSEST(linear, 0x101), i);
135+
}
136+
}
137+
138+
static void vkms_color_srgb_inv_srgb(struct kunit *test)
139+
{
140+
u16 srgb, final;
141+
142+
for (int i = 0; i < LUT_SIZE; i++) {
143+
srgb = apply_lut_to_channel_value(&srgb_eotf, i * 0x101, LUT_RED);
144+
final = apply_lut_to_channel_value(&srgb_inv_eotf, srgb, LUT_RED);
145+
146+
KUNIT_EXPECT_GE(test, final / 0x101, i - 1);
147+
KUNIT_EXPECT_LE(test, final / 0x101, i + 1);
148+
}
149+
}
150+
115151
static struct kunit_case vkms_color_test_cases[] = {
116152
KUNIT_CASE(vkms_color_test_get_lut_index),
117153
KUNIT_CASE(vkms_color_test_lerp),
154+
KUNIT_CASE(vkms_color_test_linear),
155+
KUNIT_CASE(vkms_color_srgb_inv_srgb),
118156
{}
119157
};
120158

drivers/gpu/drm/vkms/vkms_composer.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,8 @@ VISIBLE_IF_KUNIT s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel
8282
}
8383
EXPORT_SYMBOL_IF_KUNIT(get_lut_index);
8484

85-
/*
86-
* This enum is related to the positions of the variables inside
87-
* `struct drm_color_lut`, so the order of both needs to be the same.
88-
*/
89-
enum lut_channel {
90-
LUT_RED = 0,
91-
LUT_GREEN,
92-
LUT_BLUE,
93-
LUT_RESERVED
94-
};
95-
96-
static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value,
97-
enum lut_channel channel)
85+
VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value,
86+
enum lut_channel channel)
9887
{
9988
s64 lut_index = get_lut_index(lut, channel_value);
10089
u16 *floor_lut_value, *ceil_lut_value;
@@ -119,6 +108,8 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan
119108
return lerp_u16(floor_channel_value, ceil_channel_value,
120109
lut_index & DRM_FIXED_DECIMAL_MASK);
121110
}
111+
EXPORT_SYMBOL_IF_KUNIT(apply_lut_to_channel_value);
112+
122113

123114
static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer)
124115
{

drivers/gpu/drm/vkms/vkms_composer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,22 @@
66
#include <kunit/visibility.h>
77
#include "vkms_drv.h"
88

9+
/*
10+
* This enum is related to the positions of the variables inside
11+
* `struct drm_color_lut`, so the order of both needs to be the same.
12+
*/
13+
enum lut_channel {
14+
LUT_RED = 0,
15+
LUT_GREEN,
16+
LUT_BLUE,
17+
LUT_RESERVED
18+
};
19+
920
#if IS_ENABLED(CONFIG_KUNIT)
1021
u16 lerp_u16(u16 a, u16 b, s64 t);
1122
s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value);
23+
u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value,
24+
enum lut_channel channel);
1225
#endif
1326

1427
#endif /* _VKMS_COMPOSER_H_ */

0 commit comments

Comments
 (0)