drm/vkms: Add gamma 2.2 and 2.4 1D curve colorops
cover drm/vkms: Add gamma 2.2 and 2.4 1D curve colorops
This series implements two LUTs that are typically used for SDR content and falls into the context of pre- and post-blend pipelines.
It depends on the first commit of
https://lore.kernel.org/dri-devel/[email protected]/
and is implemented in the following Weston MR:
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/2157
In that MR the curves are further tested to match the corresponding Weston GL implementations.
Robert Mader (4):
drm/vkms: Fix inverse lut naming scheme in script drm/vkms: Make LUT test reusable
drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA22 drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA24
.../gpu/drm/vkms/scripts/color-curve-lut.py | 40 +- drivers/gpu/drm/vkms/tests/vkms_color_test.c | 41 +- drivers/gpu/drm/vkms/vkms_colorop.c | 6 +- drivers/gpu/drm/vkms/vkms_composer.c | 26 + drivers/gpu/drm/vkms/vkms_luts.c | 5798 +++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 4 + 6 files changed, 5893 insertions(+), 22 deletions(-)
Signature · 1 line
2.56.1
PATCH 1/4 drm/vkms: Fix inverse lut naming scheme in script
We went with in srgb_inv instead of inv_srgb in commit 3c7c3c12dfc7 ("drm/vkms: replace uniform sRGB LUT and its inverse with optimal ones") thus adopt the script to reflect that.
--- .../gpu/drm/vkms/scripts/color-curve-lut.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/gpu/drm/vkms/scripts/color-curve-lut.py +11 -11
@@ -371,7 +371,7 @@ class Functions: return pow(x, 2.2) @staticmethod - def inv_pow22(x): + def pow22_inv(x): return pow(x, 1.0 / 2.2) @staticmethod
@@ -381,7 +381,7 @@ class Functions: return pow(((x + 0.055) / 1.055), 2.4) @staticmethod - def inv_srgb(x): + def srgb_inv(x): if x <= 0.0031308: return 12.92 * x return 1.055 * pow(x, (1.0 / 2.4)) - 0.055
@@ -397,7 +397,7 @@ class Functions: return pow(max(aux - c1, 0.0) / (c2 - c3 * aux), m1_inv) @staticmethod - def inv_pq(x): + def pq_inv(x): m1 = 0.1593017578125 m2 = 78.84375 c1 = 0.8359375
@@ -414,7 +414,7 @@ class Functions: return a * (pow(x, 0.45)) - (a - 1.0) @staticmethod - def inv_bt2020_oetf(x): + def bt2020_oetf_inv(x): a = 1.0993 if x < 0.081: return x / 4.5
@@ -472,7 +472,7 @@ def print_help_and_quit(function_table): print("Possible function names are:") for func in function_table.keys(): print(f" {func}") - print(f" inv_{func}") + print(f" {func}_inv") sys.exit(1)
@@ -491,8 +491,8 @@ def parse_cli_params(args, function_table): plot = True func_str = args[1] - use_inverse = func_str.startswith("inv_") - base_func_str = func_str[4:] if use_inverse else func_str + use_inverse = func_str.endswith("_inv") + base_func_str = func_str[:-4] if use_inverse else func_str func_pair = function_table.get(base_func_str) if func_pair is None:
@@ -517,10 +517,10 @@ def parse_cli_params(args, function_table): def main(args): function_table = { - "srgb": (Functions.srgb, Functions.inv_srgb), - "pow22": (Functions.pow22, Functions.inv_pow22), - "pq": (Functions.pq, Functions.inv_pq), - "bt2020_oetf": (Functions.bt2020_oetf, Functions.inv_bt2020_oetf), + "srgb": (Functions.srgb, Functions.srgb_inv), + "pow22": (Functions.pow22, Functions.pow22_inv), + "pq": (Functions.pq, Functions.pq_inv), + "bt2020_oetf": (Functions.bt2020_oetf, Functions.bt2020_oetf_inv), } func_str, func_pair, lut_size, plot = parse_cli_params(args, function_table)
Signature · 1 line
2.56.1
PATCH 3/4 drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA22
In reply to Robert MaderAnd its inverse, using the pow22 function from the script with the suggested sizes from the top comment.
The Gamma 2.2 EOTF is what Wayland compositors like Weston implicitly assume for SDR content and thus important for the colorop transition.
--- drivers/gpu/drm/vkms/tests/vkms_color_test.c | 6 + drivers/gpu/drm/vkms/vkms_colorop.c | 4 +- drivers/gpu/drm/vkms/vkms_composer.c | 13 + drivers/gpu/drm/vkms/vkms_luts.c | 4944 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 2 + 5 files changed, 4968 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/tests/vkms_color_test.c +6 -0
@@ -151,6 +151,11 @@ static void vkms_color_srgb_inv_srgb(struct kunit *test)vkms_color_test_inv_lut (test, &srgb_eotf, &srgb_inv_eotf,11 ,0 ); } +static void vkms_color_gamma22_inv_gamma22 (struct kunit *test) +{ +vkms_color_test_inv_lut (test, &gamma22_eotf, &gamma22_inv_eotf,304 ,2 ); +} +#define FIXPT_HALF (DRM_FIXED_ONE >> 1)#define FIXPT_QUARTER (DRM_FIXED_ONE >> 2)
@@ -401,6 +406,7 @@ static struct kunit_case vkms_color_test_cases[] = {KUNIT_CASE (vkms_color_test_lerp),KUNIT_CASE (vkms_color_test_linear),KUNIT_CASE (vkms_color_srgb_inv_srgb), +KUNIT_CASE (vkms_color_gamma22_inv_gamma22),KUNIT_CASE (vkms_color_ctm_3x4_50_desat), KUNIT_CASE(vkms_color_ctm_3x4_bt709), {}
drivers/gpu/drm/vkms/vkms_colorop.c +3 -1
@@ -10,7 +10,9 @@static const u64 supported_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) | -BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ); +BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA22 ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA22_INV );static const u64 supported_fm = BIT(DRM_COLOROP_FM_YCBCR601_FULL_RGB) |
drivers/gpu/drm/vkms/vkms_composer.c +13 -0
@@ -264,6 +264,19 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colo pixel->g =apply_lut_to_channel_value (&srgb_eotf, pixel->g,LUT_GREEN ); pixel->b =apply_lut_to_channel_value (&srgb_eotf, pixel->b,LUT_BLUE );break ; +case DRM_COLOROP_1D_CURVE_GAMMA22 : + pixel->r =apply_lut_to_channel_value (&gamma22_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&gamma22_eotf, pixel->g,LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&gamma22_eotf, pixel->b,LUT_BLUE ); +break ; +case DRM_COLOROP_1D_CURVE_GAMMA22_INV : + pixel->r =apply_lut_to_channel_value (&gamma22_inv_eotf, pixel->r, +LUT_RED ); + pixel->g =apply_lut_to_channel_value (&gamma22_inv_eotf, pixel->g, +LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&gamma22_inv_eotf, pixel->b, +LUT_BLUE ); +break ;default : drm_WARN_ONCE(dev, true, "unknown colorop 1D curve type %d\n",
drivers/gpu/drm/vkms/vkms_luts.c +4944 -0
2,953 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.56.1
Part of the diff is not shown here. View the raw message.
PATCH 2/4 drm/vkms: Make LUT test reusable
In reply to Robert MaderFactor out the logic so we can reuse it for other LUTs and, While on it, add an average error which will become useful in follow-up commits.
--- drivers/gpu/drm/vkms/tests/vkms_color_test.c | 29 +++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-)
drivers/gpu/drm/vkms/tests/vkms_color_test.c +22 -7
@@ -120,20 +120,35 @@ static void vkms_color_test_linear(struct kunit *test) } } -static void vkms_color_srgb_inv_srgb (struct kunit *test) +static void vkms_color_test_inv_lut (struct kunit *test, +const struct vkms_color_lut *lut, +const struct vkms_color_lut *inv_lut, +u16 tolerance_max, +u16 tolerance_avg) { -u16 srgb, final; -u16 tolerance =11 ; +u16 sum =0 ; +u16 count =0 ; +u16 tmp, final;u32 x;for (u32 i =0 ; i <=4095 ; i++) { x = i *U16_MAX /4095 ; - srgb =apply_lut_to_channel_value (&srgb_eotf, x,LUT_RED ); - final =apply_lut_to_channel_value (&srgb_inv_eotf, srgb,LUT_RED ); + tmp =apply_lut_to_channel_value (lut, x,LUT_RED ); + final =apply_lut_to_channel_value (inv_lut, tmp,LUT_RED ); + +KUNIT_EXPECT_GE (test, final, (int )x - tolerance_max); +KUNIT_EXPECT_LE (test, final, (int )x + tolerance_max); -KUNIT_EXPECT_GE (test, final, (int )x - tolerance); -KUNIT_EXPECT_LE (test, final, (int )x + tolerance); + sum +=abs ((int )x - final); + count++; } + +KUNIT_EXPECT_LE (test, sum / count, tolerance_avg); +} + +static void vkms_color_srgb_inv_srgb (struct kunit *test) +{ +vkms_color_test_inv_lut (test, &srgb_eotf, &srgb_inv_eotf,11 ,0 ); }#define FIXPT_HALF (DRM_FIXED_ONE >> 1)
Signature · 1 line
2.56.1
PATCH 4/4 drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA24
In reply to Robert MaderAnd its inverse, using the pow22 function from the script. The sizes where determined to match the max error of the already existing functions, rounded to up to the next decimal value.
The Gamma 2.4 EOTF is typically used for SDR video content.
See
https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/539
for more context.
--- .../gpu/drm/vkms/scripts/color-curve-lut.py | 18 +- drivers/gpu/drm/vkms/tests/vkms_color_test.c | 6 + drivers/gpu/drm/vkms/vkms_colorop.c | 4 +- drivers/gpu/drm/vkms/vkms_composer.c | 13 + drivers/gpu/drm/vkms/vkms_luts.c | 854 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 2 + 6 files changed, 893 insertions(+), 4 deletions(-)
drivers/gpu/drm/vkms/scripts/color-curve-lut.py +15 -3
@@ -61,6 +61,8 @@ Function LUT size Max error ---------------------------------------------- pow 2.2 270 9.320331e-06 inverse pow 2.2 370 1.056258e-05 +pow 2.4 270 9.537672e-06 +inverse pow 2.4 460 1.071102e-05 piece-wise sRGB 260 9.298192e-06 inv piece-wise sRGB 330 1.001394e-05 PQ 380 9.159226e-06
@@ -69,9 +71,10 @@ BT.2020 OETF 270 9.762646e-06 inv BT.2020 OETF 240 9.924004e-06 ---------------------------------------------- -Note: inverse pow 2.2 and inverse piece-wise sRGB LUTs stopped improving with -fewer taps than inverse PQ, but their max_error didn't drop below 10^-5, even -with very large LUTs. This can be attributed to quantization error. +Note: inverse pow 2.2, inverse pow 2.4 and inverse piece-wise sRGB LUTs stopped +improving with fewer taps than inverse PQ, but their max_error didn't drop +below 10^-5, even with very large LUTs. This can be attributed to quantization +error. """ import sys
@@ -374,6 +377,14 @@ class Functions: def pow22_inv(x): return pow(x, 1.0 / 2.2) + @staticmethod + def pow24(x): + return pow(x, 2.4) + + @staticmethod + def pow24_inv(x): + return pow(x, 1.0 / 2.4) + @staticmethod def srgb(x): if x <= 0.04045:
@@ -519,6 +530,7 @@ def main(args): function_table = { "srgb": (Functions.srgb, Functions.srgb_inv), "pow22": (Functions.pow22, Functions.pow22_inv), + "pow24": (Functions.pow24, Functions.pow24_inv), "pq": (Functions.pq, Functions.pq_inv), "bt2020_oetf": (Functions.bt2020_oetf, Functions.bt2020_oetf_inv), }
drivers/gpu/drm/vkms/tests/vkms_color_test.c +6 -0
@@ -156,6 +156,11 @@ static void vkms_color_gamma22_inv_gamma22(struct kunit *test)vkms_color_test_inv_lut (test, &gamma22_eotf, &gamma22_inv_eotf,304 ,2 ); } +static void vkms_color_gamma24_inv_gamma24 (struct kunit *test) +{ +vkms_color_test_inv_lut (test, &gamma24_eotf, &gamma24_inv_eotf,389 ,3 ); +} +#define FIXPT_HALF (DRM_FIXED_ONE >> 1)#define FIXPT_QUARTER (DRM_FIXED_ONE >> 2)
@@ -407,6 +412,7 @@ static struct kunit_case vkms_color_test_cases[] = {KUNIT_CASE (vkms_color_test_linear),KUNIT_CASE (vkms_color_srgb_inv_srgb),KUNIT_CASE (vkms_color_gamma22_inv_gamma22), +KUNIT_CASE (vkms_color_gamma24_inv_gamma24),KUNIT_CASE (vkms_color_ctm_3x4_50_desat), KUNIT_CASE(vkms_color_ctm_3x4_bt709), {}
drivers/gpu/drm/vkms/vkms_colorop.c +3 -1
@@ -12,7 +12,9 @@ static const u64 supported_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) |BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) |BIT (DRM_COLOROP_1D_CURVE_GAMMA22 ) | -BIT (DRM_COLOROP_1D_CURVE_GAMMA22_INV ); +BIT (DRM_COLOROP_1D_CURVE_GAMMA22_INV ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA24 ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA24_INV );static const u64 supported_fm = BIT(DRM_COLOROP_FM_YCBCR601_FULL_RGB) |
drivers/gpu/drm/vkms/vkms_composer.c +13 -0
@@ -277,6 +277,19 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colo pixel->b =apply_lut_to_channel_value (&gamma22_inv_eotf, pixel->b,LUT_BLUE );break ; +case DRM_COLOROP_1D_CURVE_GAMMA24 : + pixel->r =apply_lut_to_channel_value (&gamma24_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&gamma24_eotf, pixel->g,LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&gamma24_eotf, pixel->b,LUT_BLUE ); +break ; +case DRM_COLOROP_1D_CURVE_GAMMA24_INV : + pixel->r =apply_lut_to_channel_value (&gamma24_inv_eotf, pixel->r, +LUT_RED ); + pixel->g =apply_lut_to_channel_value (&gamma24_inv_eotf, pixel->g, +LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&gamma24_inv_eotf, pixel->b, +LUT_BLUE ); +break ;default : drm_WARN_ONCE(dev, true, "unknown colorop 1D curve type %d\n",
drivers/gpu/drm/vkms/vkms_luts.c +854 -0
857 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_luts.h +2 -0
@@ -7,5 +7,7 @@ extern const struct vkms_color_lut srgb_eotf;extern const struct vkms_color_lut srgb_inv_eotf;extern const struct vkms_color_lut gamma22_eotf;extern const struct vkms_color_lut gamma22_inv_eotf; +extern const struct vkms_color_lut gamma24_eotf; +extern const struct vkms_color_lut gamma24_inv_eotf;#endif /* _VKMS_LUTS_H_ */
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v1 2/4] drm/vkms: Make LUT test reusable
In reply to Robert MaderThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/vkms: u16 sum overflow in vkms_color_test_inv_lut() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/vkms: u16 sum overflow in vkms_color_test_inv_lut() --
commit 88ce71701c6dbe07fa8ad17d5f1c90963dd032aa
Author: Robert Mader <[email protected]>
drm/vkms: Make LUT test reusable
This commit factors the inverse LUT test logic out of vkms_color_srgb_inv_srgb() into a reusable vkms_color_test_inv_lut() helper and adds an average error tolerance check.
Quoted 29 lines
drivers/gpu/drm/vkms/tests/vkms_color_test.c +11
-5@@ -120,20 +120,35 @@ static void vkms_color_test_linear(struct kunit *test) } } -static void vkms_color_srgb_inv_srgb (struct kunit *test) +static void vkms_color_test_inv_lut (struct kunit *test, +const struct vkms_color_lut *lut, +const struct vkms_color_lut *inv_lut, +u16 tolerance_max, +u16 tolerance_avg) { -u16 srgb, final; -u16 tolerance =11 ; +u16 sum =0 ; +u16 count =0 ; +u16 tmp, final;u32 x;for (u32 i =0 ; i <=4095 ; i++) { x = i *U16_MAX /4095 ; - srgb =apply_lut_to_channel_value (&srgb_eotf, x,LUT_RED ); - final =apply_lut_to_channel_value (&srgb_inv_eotf, srgb,LUT_RED ); + tmp =apply_lut_to_channel_value (lut, x,LUT_RED ); + final =apply_lut_to_channel_value (inv_lut, tmp,LUT_RED ); +
drivers/gpu/drm/vkms/tests/vkms_color_test.c static void vkms_color_test_linear(struct kunit *test) · line 146
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_test.c +6
-2+KUNIT_EXPECT_GE (test, final, (int )x - tolerance_max); +KUNIT_EXPECT_LE (test, final, (int )x + tolerance_max); -KUNIT_EXPECT_GE (test, final, (int )x - tolerance); -KUNIT_EXPECT_LE (test, final, (int )x + tolerance); + sum +=abs ((int )x - final); + count++; } + +KUNIT_EXPECT_LE (test, sum / count, tolerance_avg);
[Severity: Medium]
Can sum overflow here?
sum is a u16 accumulating errors across 4096 samples, so it wraps modulo 65536 as soon as the average error reaches 16 (and the true total can reach 4096 * U16_MAX). This caps sum / count at 15 and lets a regressed LUT falsely pass KUNIT_EXPECT_LE(test, sum / count, tolerance_avg).
Using u32 for sum would avoid the overflow.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v1 3/4] drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA22
In reply to Robert MaderThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/vkms: u16 sum overflow in vkms_color_test_inv_lut() masks test failures - [Medium] drm/vkms…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/vkms: u16 sum overflow in vkms_color_test_inv_lut() masks test failures
- [Medium] drm/vkms: gamma22_inv_eotf uses 4096-entry inv_pow22 LUT instead of 370
- [Low] drm/vkms: globally export KUnit-only gamma22 LUTs via EXPORT_SYMBOL()
--
commit 59d26d74c99ba688971258bafc7bd1586364f0e8
Author: Robert Mader <[email protected]>
drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA22
This commit adds Gamma 2.2 EOTF and inverse EOTF 1D curve colorop support to VKMS by defining non-uniform LUTs in vkms_luts.c, wiring them into vkms_colorop.c and vkms_composer.c, and adding a KUnit round-trip test.
drivers/gpu/drm/vkms/tests/vkms_color_test.c static void vkms_color_srgb_inv_srgb(struct kunit *test) · line 158
Quoted 13 lines
drivers/gpu/drm/vkms/tests/vkms_color_test.c +5
-0@@ -151,6 +151,11 @@ static void vkms_color_srgb_inv_srgb(struct kunit *test)vkms_color_test_inv_lut (test, &srgb_eotf, &srgb_inv_eotf,11 ,0 ); } +static void vkms_color_gamma22_inv_gamma22 (struct kunit *test) +{ +vkms_color_test_inv_lut (test, &gamma22_eotf, &gamma22_inv_eotf,304 ,2 ); +} +
[Severity: Medium]
Can sum overflow in vkms_color_test_inv_lut() with tolerance_max set to 304?
drivers/gpu/drm/vkms/tests/vkms_color_test.c:vkms_color_test_inv_lut() {
u16 sum = 0;
u16 count = 0;
...
for (u32 i = 0; i <= 4095; i++) {
...
sum += abs((int)x - final);
count++;
}
KUNIT_EXPECT_LE(test, sum / count, tolerance_avg);
}Because sum is a u16, it wraps modulo 65536 once the average error over 4096 samples reaches 16. A broken LUT with an average error of 16 to 18 would wrap sum / count back to 0..2 and falsely pass the average tolerance check. Widening sum to u32 or u64 prevents the wraparound.
[ ... ]
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_luts.c +0
-0@@ -706,3 +706,4947 @@ const struct vkms_color_lut srgb_inv_eotf = { .lut_length = ARRAY_SIZE(srgb_inv_y) };EXPORT_SYMBOL (srgb_inv_eotf);
[ ... ]
drivers/gpu/drm/vkms/vkms_luts.c const struct vkms_color_lut srgb_inv_eotf = { · line 1028
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_luts.c +6
-0+const struct vkms_color_lut gamma22_eotf = { + .x = pow22_x, + .y = pow22_y, + .lut_length =ARRAY_SIZE (pow22_y) +}; +EXPORT_SYMBOL (gamma22_eotf);
[Severity: Low]
Should gamma22_eotf and gamma22_inv_eotf use EXPORT_SYMBOL_IF_KUNIT() instead of EXPORT_SYMBOL()?
vkms_luts.o and vkms_composer.o link into vkms.o, so the only external user is vkms_color_test.c, which already imports EXPORTED_FOR_KUNIT_TESTING. Using EXPORT_SYMBOL_IF_KUNIT() avoids exposing these unprefixed internal structs in the global symbol table when CONFIG_KUNIT is disabled.
[ ... ]
Quoted 1 line
+static u16 inv_pow22_x[] = {
[ ... ]
drivers/gpu/drm/vkms/vkms_luts.c const struct vkms_color_lut srgb_inv_eotf = { · line 5651
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_luts.c +8
-0+static_assert (ARRAY_SIZE (inv_pow22_x) ==ARRAY_SIZE (inv_pow22_y), +"pow22_inv x and y must have the same number of entries" ); + +const struct vkms_color_lut gamma22_inv_eotf = { + .x = inv_pow22_x, + .y = inv_pow22_y, + .lut_length =ARRAY_SIZE (inv_pow22_y) +};
[Severity: Medium]
Were inv_pow22_x and inv_pow22_y meant to have 370 entries instead of 4096?
The commit message says the tables use the suggested sizes from color-curve-lut.py, which recommends 370 entries for inverse pow 2.2. The mismatch between the inv_pow22 names and the "pow22_inv" static_assert message also suggests stale 4096-entry output was pasted here.
Embedding 4096 entries adds ~37 KiB of redundant static data to vkms.ko (mostly repeating identical quantized values across 0xf240..0xffff), pushes the table past a 32 KiB L1 data cache, and increases the per-channel binary search in apply_non_uniform_lut() from 9 to 12 iterations.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v1 4/4] drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA24
In reply to Robert MaderThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/vkms: undeclared DRM_COLOROP_1D_CURVE_GAMMA24 constants break build - [Medium] drm/vkms: u16 sum…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/vkms: undeclared DRM_COLOROP_1D_CURVE_GAMMA24 constants break build
- [Medium] drm/vkms: u16 sum overflow in vkms_color_test_inv_lut()
- [Low] drm/vkms: commit message references pow22 instead of pow24
- [Low] drm/vkms: unconditional EXPORT_SYMBOL() for test-only Gamma 2.4 LUTs
--
commit 4fadd67a1786c5a41648858b25f1d109b7e89b77
Author: Robert Mader <[email protected]>
drm/vkms: Add support for DRM_COLOROP_1D_CURVE_GAMMA24
This commit adds Gamma 2.4 and inverse Gamma 2.4 LUTs, wires them into VKMS 1D curve colorops, updates the LUT generation script, and adds a KUnit round-trip test.
Quoted 1 line
And its inverse, using the pow22 function from the script.
[Severity: Low]
Should this say pow24 instead of pow22? The patch adds pow24 and pow24_inv to color-curve-lut.py and uses them to generate the Gamma 2.4 LUTs.
[ ... ]
drivers/gpu/drm/vkms/tests/vkms_color_test.c static void vkms_color_gamma22_inv_gamma22(struct kunit *test) · line 162
Quoted 12 lines
drivers/gpu/drm/vkms/tests/vkms_color_test.c +4
-0@@ -156,6 +156,11 @@ static void vkms_color_gamma22_inv_gamma22(struct kunit *test)vkms_color_test_inv_lut (test, &gamma22_eotf, &gamma22_inv_eotf,304 ,2 ); } +static void vkms_color_gamma24_inv_gamma24 (struct kunit *test) +{ +vkms_color_test_inv_lut (test, &gamma24_eotf, &gamma24_inv_eotf,389 ,3 ); +}
[Severity: Medium]
Can the u16 sum accumulator in vkms_color_test_inv_lut() overflow here?
drivers/gpu/drm/vkms/tests/vkms_color_test.c:vkms_color_test_inv_lut() {
u16 sum = 0;
...
for (u32 i = 0; i <= 4095; i++) {
...
sum += abs((int)x - final);
count++;
}
KUNIT_EXPECT_LE(test, sum / count, tolerance_avg);
}With 4096 samples and tolerance_max set to 389, sum wraps modulo 65536 as soon as the mean error reaches 16. A regressed LUT with a mean error between 16 and 19 wraps sum / count back to 0..3 and silently passes the tolerance_avg check. Changing sum to u32 avoids the wraparound.
[ ... ]
drivers/gpu/drm/vkms/vkms_colorop.c static const u64 supported_tfs = · line 17
Quoted 12 lines
drivers/gpu/drm/vkms/vkms_colorop.c +3
-1@@ -12,7 +12,9 @@ static const u64 supported_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) |BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) |BIT (DRM_COLOROP_1D_CURVE_GAMMA22 ) | -BIT (DRM_COLOROP_1D_CURVE_GAMMA22_INV ); +BIT (DRM_COLOROP_1D_CURVE_GAMMA22_INV ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA24 ) | +BIT (DRM_COLOROP_1D_CURVE_GAMMA24_INV );
[Severity: High]
Are DRM_COLOROP_1D_CURVE_GAMMA24 and DRM_COLOROP_1D_CURVE_GAMMA24_INV declared anywhere in the tree?
enum drm_colorop_curve_1d_type in include/drm/drm_colorop.h and colorop_curve_1d_type_names[] in drivers/gpu/drm/drm_colorop.c both stop at DRM_COLOROP_1D_CURVE_GAMMA22_INV, so this and the matching switch cases in apply_colorop() fail to compile when CONFIG_DRM_VKMS is enabled.
A prerequisite DRM core patch defining both enum values and their property name strings is needed first.
[ ... ]
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_luts.c +0
-0@@ -5650,3 +5650,857 @@ const struct vkms_color_lut gamma22_inv_eotf = {
[ ... ]
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_luts.c +6
-0+const struct vkms_color_lut gamma24_eotf = { + .x = pow24_x, + .y = pow24_y, + .lut_length =ARRAY_SIZE (pow24_y) +}; +EXPORT_SYMBOL (gamma24_eotf);
[ ... ]
drivers/gpu/drm/vkms/vkms_luts.c const struct vkms_color_lut gamma22_inv_eotf = { · line 6506
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_luts.c +6
-0+const struct vkms_color_lut gamma24_inv_eotf = { + .x = pow24_inv_x, + .y = pow24_inv_y, + .lut_length =ARRAY_SIZE (pow24_inv_y) +}; +EXPORT_SYMBOL (gamma24_inv_eotf);
[Severity: Low]
Should gamma24_eotf and gamma24_inv_eotf use EXPORT_SYMBOL_IF_KUNIT() instead of EXPORT_SYMBOL()?
Their only external user is vkms_color_test.c, which already imports the EXPORTED_FOR_KUNIT_TESTING namespace. Unconditionally exporting generic, unprefixed names into the global kernel symbol table risks symbol collisions across modules when KUnit is disabled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4