drm/vkms: Reimplement line-per-line pixel conversion for plane reading
Louis Chauvet
maintainerPATCH v5 13/16 drm/vkms: Drop YUV formats TODO
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
VKMS has support for YUV formats now. Remove the task from the TODO list.
--- Documentation/gpu/vkms.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Documentation/gpu/vkms.rst +1 -2
@@ -122,8 +122,7 @@ There's lots of plane features we could add support for: - Scaling. -- Additional buffer formats, especially YUV formats for video like NV12. - Low/high bpp RGB formats would also be interesting. +- Additional buffer formats. Low/high bpp RGB formats would be interesting. - Async updates (currently only possible on cursor plane using the legacy cursor api).
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v5 14/16 drm/vkms: Create KUnit tests for YUV conversions
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors.
The code used to compute the expected result can be found in comment.
[Louis Chauvet:
- fix minor formating issues (whitespace, double line)
- change expected alpha from 0x0000 to 0xffff
- adapt to the new get_conversion_matrix usage
- apply the changes from Arthur
- move struct pixel_yuv_u8 to the test itself]
--- drivers/gpu/drm/vkms/Kconfig | 15 ++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_format_test.c | 230 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 4 + 7 files changed, 262 insertions(+), 2 deletions(-)
drivers/gpu/drm/vkms/Kconfig +15 -0
@@ -13,3 +13,18 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N".
drivers/gpu/drm/vkms/Makefile +1 -0
@@ -9,3 +9,4 @@ vkms-y := \ vkms_writeback.o obj-$(CONFIG_DRM_VKMS) += vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/
drivers/gpu/drm/vkms/tests/.kunitconfig new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=y
drivers/gpu/drm/vkms/tests/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_format_test.o
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +230 -0
230 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.c +5 -2
@@ -7,6 +7,8 @@#include <drm/drm_rect.h> #include <drm/drm_fixed.h> +#include <kunit/visibility.h> +#include "vkms_formats.h" /**
@@ -199,8 +201,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } -static struct pixel_argb_u16 argb_u16_from_yuv888 (u8 y,u8 cb,u8 cr, -struct conversion_matrix *matrix) +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr, +struct conversion_matrix *matrix) {u8 r, g, b;s64 fp_y, fp_cb, fp_cr;
@@ -234,6 +236,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,return argb_u16_from_u8888 (255 , r, g, b); } +EXPORT_SYMBOL_IF_KUNIT (argb_u16_from_yuv888);/* * The following functions are read_line function for each pixel format supported by VKMS.
drivers/gpu/drm/vkms/vkms_formats.h +4 -0
@@ -13,4 +13,8 @@ struct conversion_matrix * get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, enum drm_color_range range); +#if IS_ENABLED (CONFIG_KUNIT ) +struct pixel_argb_u16 argb_u16_from_yuv888 (u8 y,u8 cb,u8 cr,struct conversion_matrix *matrix); +#endif +#endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.43.0
Re: [PATCH v5 14/16] drm/vkms: Create KUnit tests for YUV conversions
Quoted 7 lines · Louis Chauvet
From: Arthur Grillo <[email protected]>
Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors.
The code used to compute the expected result can be found in comment.
Quoted 7 lines
Signed-off-by Arthur Grillo <[email protected]>[Louis Chauvet:
- fix minor formating issues (whitespace, double line)
- change expected alpha from0x0000to0xffff
- adapt to the newget_conversion_matrixusage
- apply the changes from Arthur
- move structpixel_yuv_u8to the test itself]
Again, a Co-developed-by tag might be more proper.
Quoted 16 lines
Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 15 ++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_format_test.c | 230 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 4 + 7 files changed, 262 insertions(+), 2 deletions(-)drivers/gpu/drm/vkms/Kconfig +0
-0
drivers/gpu/drm/vkms/Kconfig config DRM_VKMS · line 18
Quoted 6 lines
drivers/gpu/drm/vkms/Kconfig +3
-0@@ -13,3 +13,18 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS
"KUnit tests for VKMS"
Quoted 72 lines
drivers/gpu/drm/vkms/Kconfig +12
-0+ depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N".drivers/gpu/drm/vkms/Makefile +1
-0@@ -9,3 +9,4 @@ vkms-y := \ vkms_writeback.o obj-$(CONFIG_DRM_VKMS) += vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/drivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_format_test.odrivers/gpu/drm/vkms/tests/vkms_format_test.c new file +25
-0@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <kunit/test.h> + +#include <drm/drm_fixed.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_print.h> + +#include "../../drm_crtc_internal.h" + +#include "../vkms_drv.h" +#include "../vkms_formats.h" + +#define TEST_BUFF_SIZE 50 + +struct pixel_yuv_u8 { +u8 y, u, v; +}; + +struct yuv_u8_to_argb_u16_case { +enum drm_color_encoding encoding; +enum drm_color_range range; +size_t n_colors; +struct format_pair { +char *name;
drivers/gpu/drm/vkms/tests/vkms_format_test.c line 35
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +10
-0+struct pixel_yuv_u8 yuv; +struct pixel_argb_u16 argb; + } colors[TEST_BUFF_SIZE ]; +}; + +/* +* The YUV color representation were acquired via the colour python framework. +* Below are the function calls used for generating each case. +* +* for more information got to the docs:
s/for/For
drivers/gpu/drm/vkms/tests/vkms_format_test.c line 48
Quoted 13 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +13
-0+* https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html +*/ +static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] = { +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = False, +* out_int = True) +*/
I feel that this Python code is kind of poluting the test cases.
Quoted 219 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +182
-0+ { + .encoding = DRM_COLOR_YCBCR_BT601, + .range = DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors = 6, + .colors = { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = True, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT601, + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors = 6, + .colors = { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x51, 0x5a, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x91, 0x36, 0x22 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x29, 0xf0, 0x6e }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.709"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = False, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT709, + .range = DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors = 4, + .colors = { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x36, 0x63, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xb6, 0x1e, 0x0c }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x12, 0xff, 0x74 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.709"], +* in_bits = 16, +* int_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = True, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT709, + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors = 4, + .colors = { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x3f, 0x66, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x2a, 0x1a }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x20, 0xf0, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = False, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT2020, + .range = DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors = 4, + .colors = { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x43, 0x5c, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x24, 0x0b }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x0f, 0xff, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.2020"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = True, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT2020, + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors = 4, + .colors = { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4a, 0x61, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xa4, 0x2f, 0x19 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xf0, 0x77 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +}; + +static void vkms_format_test_yuv_u8_to_argb_u16 (struct kunit *test) +{ +const struct yuv_u8_to_argb_u16_case *param = test->param_value; +struct pixel_argb_u16 argb; + +for (size_t i =0 ; i < param->n_colors; i++) { +const struct format_pair *color = ¶m->colors[i]; + +struct conversion_matrix *matrix =get_conversion_matrix_to_argb_u16 + (DRM_FORMAT_NV12 , param->encoding, param->range); + + argb =argb_u16_from_yuv888 (color->yuv.y, color->yuv.u, color->yuv.v, matrix); + +KUNIT_EXPECT_LE_MSG (test,abs_diff (argb.a, color->argb.a),257 , +"On the A channel of the color %s expected 0x%04x, got 0x%04x" , + color->name, color->argb.a, argb.a); +KUNIT_EXPECT_LE_MSG (test,abs_diff (argb.r, color->argb.r),257 , +"On the R channel of the color %s expected 0x%04x, got 0x%04x" , + color->name, color->argb.r, argb.r); +KUNIT_EXPECT_LE_MSG (test,abs_diff (argb.g, color->argb.g),257 , +"On the G channel of the color %s expected 0x%04x, got 0x%04x" , + color->name, color->argb.g, argb.g); +KUNIT_EXPECT_LE_MSG (test,abs_diff (argb.b, color->argb.b),257 , +"On the B channel of the color %s expected 0x%04x, got 0x%04x" , + color->name, color->argb.b, argb.b); + } +} + +static void vkms_format_test_yuv_u8_to_argb_u16_case_desc (struct yuv_u8_to_argb_u16_case *t, +char *desc) +{ +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"%s - %s" , +drm_get_color_encoding_name (t->encoding),drm_get_color_range_name (t->range)); +} + +KUNIT_ARRAY_PARAM (yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_cases, + vkms_format_test_yuv_u8_to_argb_u16_case_desc +); + +static struct kunit_case vkms_format_test_cases[] = { +KUNIT_CASE_PARAM (vkms_format_test_yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_gen_params), + {} +}; + +static struct kunit_suite vkms_format_test_suite = { + .name ="vkms-format" , + .test_cases = vkms_format_test_cases, +}; + +kunit_test_suite (vkms_format_test_suite); + +MODULE_LICENSE ("GPL" );drivers/gpu/drm/vkms/vkms_formats.c +5
-2@@ -7,6 +7,8 @@#include <drm/drm_rect.h> #include <drm/drm_fixed.h> +#include <kunit/visibility.h> +#include "vkms_formats.h" /** @@ -199,8 +201,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } -static struct pixel_argb_u16 argb_u16_from_yuv888 (u8 y,u8 cb,u8 cr, -struct conversion_matrix *matrix) +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr, +struct conversion_matrix *matrix) {u8 r, g, b;s64 fp_y, fp_cb, fp_cr;@@ -234,6 +236,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,return argb_u16_from_u8888 (255 , r, g, b); } +EXPORT_SYMBOL_IF_KUNIT (argb_u16_from_yuv888);/* * The following functions are read_line function for each pixel format supported by VKMS. drivers/gpu/drm/vkms/vkms_formats.h +0
-0
drivers/gpu/drm/vkms/vkms_formats.h struct conversion_matrix * · line 16
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_formats.h +1
-0@@ -13,4 +13,8 @@ struct conversion_matrix * get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, enum drm_color_range range); +#if IS_ENABLED (CONFIG_KUNIT )
What about the CONFIG_DRM_EXPORT_FOR_TESTS?
Best Regards,
- Maíra
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_formats.h +3
-0+struct pixel_argb_u16 argb_u16_from_yuv888 (u8 y,u8 cb,u8 cr,struct conversion_matrix *matrix); +#endif +#endif /* _VKMS_FORMATS_H_ */
Louis Chauvet
maintainerRe: [PATCH v5 14/16] drm/vkms: Create KUnit tests for YUV conversions
Quoted 16 lines · Maíra Canal
Quoted 7 lines · Louis Chauvet
From: Arthur Grillo <[email protected]>
Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors.
The code used to compute the expected result can be found in comment.
Quoted 7 lines
Signed-off-by Arthur Grillo <[email protected]>[Louis Chauvet:
- fix minor formating issues (whitespace, double line)
- change expected alpha from0x0000to0xffff
- adapt to the newget_conversion_matrixusage
- apply the changes from Arthur
- move structpixel_yuv_u8to the test itself]
Quoted 1 line
Again, a Co-developed-by tag might be more proper.
For this patch, my contribution was very minimal (I only add a call to get_conversion_matrix_to_argb_u16), so I will not add the Co-developed-by.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 15 ++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_format_test.c | 230 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 4 + 7 files changed, 262 insertions(+), 2 deletions(-)drivers/gpu/drm/vkms/Kconfig +0
-0@@ -13,3 +13,18 @@ config DRM_VKMS a VKMS.
Quoted 6 lines
drivers/gpu/drm/vkms/Kconfig config DRM_VKMS · line 18
Quoted 4 lines
drivers/gpu/drm/vkms/Kconfig +3
-0If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS"KUnit tests for VKMS"
Fixed in v6.
Quoted 46 lines
Quoted 46 lines
drivers/gpu/drm/vkms/Kconfig +12
-0+ depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N".drivers/gpu/drm/vkms/Makefile +1
-0@@ -9,3 +9,4 @@ vkms-y := \ vkms_writeback.o obj-$(CONFIG_DRM_VKMS) += vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/drivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_format_test.odrivers/gpu/drm/vkms/tests/vkms_format_test.c new file +0
-0
[...]
Quoted 7 lines
Quoted 5 lines
+/*
+ * The YUV color representation were acquired via the colour python framework.
+ * Below are the function calls used for generating each case.
+ *
+ * for more information got to the docs:s/for/For
Fixed in v6.
Quoted 7 lines
Quoted 7 lines
+ * https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html
+ */drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +5
-0+static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] = { +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], +* in_bits = 16,
Quoted 8 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c line 48
Quoted 6 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +6
-0+* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = False, +* out_int = True) +*/ I feel that this Python code is kind of poluting the test cases.
This python code is needed to understand where the values come from. I think we should keep it for future reference (add more cases, test yuv 16 bits...)
Maybe we can change the array comment to
/*
* The yuv color representation were acquired via the colour python framework:
*
* colour.RGB_to_YCbCr(<rgb color in 16 bits form>,
* K=color.WEIGHTS_YCBCR["<format>"],
* [...],
* out_legal = <limited or full range>)
*
* The exact function call arguments are given for each element of this list. *
* [...]
*/
And above each test case:
/*
* format = "ITU-R BT.601"
* out_legal = False
*/
@Arthur, do you agree with those modifications?
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +13
-0+ { + .encoding = DRM_COLOR_YCBCR_BT601, + .range = DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors = 6, + .colors = { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + },
[...]
Quoted 40 lines
Quoted 40 lines
drivers/gpu/drm/vkms/vkms_formats.c +5
-2@@ -7,6 +7,8 @@#include <drm/drm_rect.h> #include <drm/drm_fixed.h> +#include <kunit/visibility.h> +#include "vkms_formats.h" /** @@ -199,8 +201,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } -static struct pixel_argb_u16 argb_u16_from_yuv888 (u8 y,u8 cb,u8 cr, -struct conversion_matrix *matrix) +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr, +struct conversion_matrix *matrix) {u8 r, g, b;s64 fp_y, fp_cb, fp_cr;@@ -234,6 +236,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,return argb_u16_from_u8888 (255 , r, g, b); } +EXPORT_SYMBOL_IF_KUNIT (argb_u16_from_yuv888);/* * The following functions are read_line function for each pixel format supported by VKMS. drivers/gpu/drm/vkms/vkms_formats.h +0
-0@@ -13,4 +13,8 @@ struct conversion_matrix * get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, enum drm_color_range range);
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_formats.h struct conversion_matrix * · line 16
Quoted 1 line
drivers/gpu/drm/vkms/vkms_formats.h +1
-0+#if IS_ENABLED (CONFIG_KUNIT )What about the
CONFIG_DRM_EXPORT_FOR_TESTS?
As the documentation for CONFIG_DRM_EXPORT_FOR_TESTS don't exists, I don't know what to use. Maybe Arthur knows what to do here? If needed I can apply the modifications for the next iteration.
Thanks for all your reviews,
Louis Chauvet
[...]
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Pekka Paalanen
Acked-byRe: [PATCH v5 14/16] drm/vkms: Create KUnit tests for YUV conversions
In reply to Maíra CanalQuoted 128 lines · On Mon, 25 Mar 2024 11:34:17 -0300 Maíra Canal <[email protected]> wrote:
Quoted 7 lines · Louis Chauvet
From: Arthur Grillo <[email protected]>
Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors.
The code used to compute the expected result can be found in comment.
Quoted 7 lines
Signed-off-by Arthur Grillo <[email protected]>[Louis Chauvet:
- fix minor formating issues (whitespace, double line)
- change expected alpha from0x0000to0xffff
- adapt to the newget_conversion_matrixusage
- apply the changes from Arthur
- move structpixel_yuv_u8to the test itself]Again, a Co-developed-by tag might be more proper.
Quoted 16 lines
Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 15 ++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_format_test.c | 230 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 4 + 7 files changed, 262 insertions(+), 2 deletions(-)drivers/gpu/drm/vkms/Kconfig +0
-0drivers/gpu/drm/vkms/Kconfig config DRM_VKMS · line 18
Quoted 6 lines
drivers/gpu/drm/vkms/Kconfig +3
-0@@ -13,3 +13,18 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS"KUnit tests for VKMS"
Quoted 72 lines
drivers/gpu/drm/vkms/Kconfig +12
-0+ depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N".drivers/gpu/drm/vkms/Makefile +1
-0@@ -9,3 +9,4 @@ vkms-y := \ vkms_writeback.o obj-$(CONFIG_DRM_VKMS) += vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/drivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/Makefile new file +3
-0@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_format_test.odrivers/gpu/drm/vkms/tests/vkms_format_test.c new file +25
-0@@ -0,0 +1,230 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <kunit/test.h> + +#include <drm/drm_fixed.h> +#include <drm/drm_fourcc.h> +#include <drm/drm_print.h> + +#include "../../drm_crtc_internal.h" + +#include "../vkms_drv.h" +#include "../vkms_formats.h" + +#define TEST_BUFF_SIZE 50 + +struct pixel_yuv_u8 { +u8 y, u, v; +}; + +struct yuv_u8_to_argb_u16_case { +enum drm_color_encoding encoding; +enum drm_color_range range; +size_t n_colors; +struct format_pair { +char *name;drivers/gpu/drm/vkms/tests/vkms_format_test.c line 35
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +10
-0+struct pixel_yuv_u8 yuv; +struct pixel_argb_u16 argb; + } colors[TEST_BUFF_SIZE ]; +}; + +/* +* The YUV color representation were acquired via the colour python framework. +* Below are the function calls used for generating each case. +* +* for more information got to the docs: s/for/For
Quoted 15 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c line 48
Quoted 13 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +13
-0+* https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.html +*/ +static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] = { +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = False, +* out_int = True) +*/ I feel that this Python code is kind of poluting the test cases.
I asked for the python code.
How would you verify that the expected values are actually correct without these comments?
You cannot trust that the test values are good if the tests pass. Both the test values and the tested code could be wrong simultaneously and agree on wrong results.
I love these comments that explicitly give the python snippets used to generate the test values. Well done!
Louis' suggestion of collecting the common python bits together is fine, too. As long as the comments clearly explain what python commands produced the test values, I'm happy.
Anyway,
Thanks,
pq
Quoted 47 lines
Quoted 47 lines
drivers/gpu/drm/vkms/tests/vkms_format_test.c new file +47
-0+ { + .encoding = DRM_COLOR_YCBCR_BT601, + .range = DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors = 6, + .colors = { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +/* +* colour.RGB_to_YCbCr(<rgb color in 16 bit form>, +* K=colour.WEIGHTS_YCBCR["ITU-R BT.601"], +* in_bits = 16, +* in_legal = False, +* in_int = True, +* out_bits = 8, +* out_legal = True, +* out_int = True) +*/ + { + .encoding = DRM_COLOR_YCBCR_BT601, + .range = DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors = 6, + .colors = { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x51, 0x5a, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x91, 0x36, 0x22 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x29, 0xf0, 0x6e }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(<rgb color in 16 bit form>, + * K=colour.WEIGHTS_YCBCR["ITU-R BT.709"], + * in_bits = 16, + * in_legal = False, + * in_int = True, + * out_bits = 8, + * out_legal = False, + * out_int = True) + */ + {
Louis Chauvet
maintainerPATCH v5 15/16 drm/vkms: Add how to run the Kunit tests
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
Now that we have KUnit tests, add instructions on how to run them.
--- Documentation/gpu/vkms.rst | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/gpu/vkms.rst +11 -0
@@ -89,6 +89,17 @@ You can also run subtests if you do not want to run the entire test:: sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device "sys:/sys/devices/platform/vkms" sudo IGT_DEVICE="sys:/sys/devices/platform/vkms" ./build/tests/kms_flip --run-subtest basic-plain-flip +Testing With KUnit +================== + +KUnit (Kernel unit testing framework) provides a common framework for unit tests +within the Linux kernel. +More information in ../dev-tools/kunit/index.rst . + +To run the VKMS KUnit tests:: + + tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/vkms/tests + TODO ====
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v5 16/16 drm/vkms: Add support for DRM_FORMAT_R*
In reply to Louis ChauvetThis add the support for:
- R1/R2/R4/R8
R1 format was tested with [1] and [2].
[1]: https://lore.kernel.org/r/[email protected]
[2]: https://lore.kernel.org/igt-dev/[email protected]/
--- drivers/gpu/drm/vkms/vkms_formats.c | 100 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 6 ++- 2 files changed, 105 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_formats.c +100 -0
@@ -201,6 +201,11 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } +static struct pixel_argb_u16 argb_u16_from_gray8 (u8 gray) +{ +return argb_u16_from_u8888 (255 , gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,struct conversion_matrix *matrix) {
@@ -269,6 +274,89 @@ static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, } } +static void Rx_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[],u8 bit_per_pixel,u8 lum_per_level) +{ +struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y); +int bit_offset = (int )rem_x * bit_per_pixel; +int step =get_step_next_block (plane->frame_info->fb, direction,0 ); +int mask = (0x1 << bit_per_pixel) -1 ; + +if (direction ==READ_LEFT_TO_RIGHT || direction ==READ_RIGHT_TO_LEFT ) { +int restart_bit_offset =0 ; +int step_bit_offset = bit_per_pixel; + +if (direction ==READ_RIGHT_TO_LEFT ) { + restart_bit_offset =8 - bit_per_pixel; + step_bit_offset = -bit_per_pixel; + } + +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset; + + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + + bit_offset += step_bit_offset; +if (bit_offset <0 ||8 <= bit_offset) { + bit_offset = restart_bit_offset; + src_pixels += step; + } + out_pixel +=1 ; + } + }else if (direction ==READ_TOP_TO_BOTTOM || direction ==READ_BOTTOM_TO_TOP ) { +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset; + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + src_pixels += step; + out_pixel +=1 ; + } + } +} + +static void R1_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,1 ,0xFF ); +} + +static void R2_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,2 ,0x55 ); +} + +static void R4_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,4 ,0x11 ); +} + +static void R8_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; +int step =get_step_next_block (plane->frame_info->fb, direction,0 ); + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y); + +while (out_pixel < end) { + *out_pixel =argb_u16_from_gray8 (*src_pixels); + src_pixels += step; + out_pixel +=1 ; + } +} +static void ARGB8888_read_line (const struct vkms_plane_state *plane,int x_start,int y_start,enum pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[])
@@ -582,6 +670,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 format)case DRM_FORMAT_YVU422 :case DRM_FORMAT_YVU444 :return &planar_yuv_read_line; +case DRM_FORMAT_R1 : +return &R1_read_line; +case DRM_FORMAT_R2 : +return &R2_read_line; +case DRM_FORMAT_R4 : +return &R4_read_line; +case DRM_FORMAT_R8 : +return &R8_read_line;default :/* * This is a bug in vkms_plane_atomic_check. All the supported
@@ -855,6 +951,10 @@ get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding,case DRM_FORMAT_ARGB16161616 :case DRM_FORMAT_XRGB16161616 :case DRM_FORMAT_RGB565 : +case DRM_FORMAT_R1 : +case DRM_FORMAT_R2 : +case DRM_FORMAT_R4 : +case DRM_FORMAT_R8 :/* * Those formats are supported, but they don't need a conversion matrix. Return * a valid pointer to avoid kernel panic in case this matrix is used/checked
drivers/gpu/drm/vkms/vkms_plane.c +5 -1
@@ -29,7 +29,11 @@ static const u32 vkms_formats[] = {DRM_FORMAT_YUV444 ,DRM_FORMAT_YVU420 ,DRM_FORMAT_YVU422 , -DRM_FORMAT_YVU444 +DRM_FORMAT_YVU444 , +DRM_FORMAT_R1 , +DRM_FORMAT_R2 , +DRM_FORMAT_R4 , +DRM_FORMAT_R8 }; static struct drm_plane_state *
Signature · 1 line
2.43.0
Re: [PATCH v5 16/16] drm/vkms: Add support for DRM_FORMAT_R*
Quoted 33 lines · On Wed, 13 Mar 2024 18:45:10 +0100 Louis Chauvet <[email protected]>…
This add the support for:
- R1/R2/R4/R8R1 format was tested with [1] and [2].
[1]: https://lore.kernel.org/r/[email protected]
[2]: https://lore.kernel.org/igt-dev/[email protected]/Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_formats.c | 100 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 6 ++- 2 files changed, 105 insertions(+), 1 deletion(-)drivers/gpu/drm/vkms/vkms_formats.c +5
-0@@ -201,6 +201,11 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } +static struct pixel_argb_u16 argb_u16_from_gray8 (u8 gray) +{ +return argb_u16_from_u8888 (255 , gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,struct conversion_matrix *matrix) {@@ -269,6 +274,89 @@ static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, } }
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 285
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_formats.c +9
-0+static void Rx_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[],u8 bit_per_pixel,u8 lum_per_level) +{ +struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y);
Maybe assert that rem_y = 0? Or block_h = 1.
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 286
Quoted 1 line
drivers/gpu/drm/vkms/vkms_formats.c +1
-0+int bit_offset = (int )rem_x * bit_per_pixel;
Why cast rem_x to int when it was defined to be int?
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 288
Quoted 2 lines
drivers/gpu/drm/vkms/vkms_formats.c +2
-0+int step =get_step_next_block (plane->frame_info->fb, direction,0 ); +int mask = (0x1 << bit_per_pixel) -1 ;
Since mask will interact with u8, it should be unsigned too.
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 300
Quoted 12 lines
drivers/gpu/drm/vkms/vkms_formats.c +12
-0+ +if (direction ==READ_LEFT_TO_RIGHT || direction ==READ_RIGHT_TO_LEFT ) { +int restart_bit_offset =0 ; +int step_bit_offset = bit_per_pixel; + +if (direction ==READ_RIGHT_TO_LEFT ) { + restart_bit_offset =8 - bit_per_pixel; + step_bit_offset = -bit_per_pixel; + } + +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset;
or shorter: (*src_pixels >> bit_offset) & mask
However, shouldn't the first pixel be on the high bits?
That how I would understand the comments in drm_fourcc.h.
Again a reason to avoid a solid color fill in IGT.
Quoted 41 lines
drivers/gpu/drm/vkms/vkms_formats.c +41
-0+ + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + + bit_offset += step_bit_offset; +if (bit_offset <0 ||8 <= bit_offset) { + bit_offset = restart_bit_offset; + src_pixels += step; + } + out_pixel +=1 ; + } + }else if (direction ==READ_TOP_TO_BOTTOM || direction ==READ_BOTTOM_TO_TOP ) { +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset; + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + src_pixels += step; + out_pixel +=1 ; + } + } +} + +static void R1_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,1 ,0xFF ); +} + +static void R2_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,2 ,0x55 ); +} + +static void R4_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,4 ,0x11 ); +} +
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 351
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_formats.c +10
-0+static void R8_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; +int step =get_step_next_block (plane->frame_info->fb, direction,0 ); + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y);
Assert on block size?
Quoted 27 lines
drivers/gpu/drm/vkms/vkms_formats.c +16
-0+ +while (out_pixel < end) { + *out_pixel =argb_u16_from_gray8 (*src_pixels); + src_pixels += step; + out_pixel +=1 ; + } +} +static void ARGB8888_read_line (const struct vkms_plane_state *plane,int x_start,int y_start,enum pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[])@@ -582,6 +670,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 format)case DRM_FORMAT_YVU422 :case DRM_FORMAT_YVU444 :return &planar_yuv_read_line; +case DRM_FORMAT_R1 : +return &R1_read_line; +case DRM_FORMAT_R2 : +return &R2_read_line; +case DRM_FORMAT_R4 : +return &R4_read_line; +case DRM_FORMAT_R8 : +return &R8_read_line;default :/* * This is a bug in vkms_plane_atomic_check. All the supported
drivers/gpu/drm/vkms/vkms_formats.c get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, · line 959
Quoted 9 lines
drivers/gpu/drm/vkms/vkms_formats.c +4
-0@@ -855,6 +951,10 @@ get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding,case DRM_FORMAT_ARGB16161616 :case DRM_FORMAT_XRGB16161616 :case DRM_FORMAT_RGB565 : +case DRM_FORMAT_R1 : +case DRM_FORMAT_R2 : +case DRM_FORMAT_R4 : +case DRM_FORMAT_R8 :/* * Those formats are supported, but they don't need a conversion matrix. Return
It is strange that you need to list irrelevant formats here.
Quoted 9 lines
drivers/gpu/drm/vkms/vkms_formats.c +0
-0* a valid pointer to avoid kernel panic in case this matrix is used/checked drivers/gpu/drm/vkms/vkms_plane.c +0
-0@@ -29,7 +29,11 @@ static const u32 vkms_formats[] = {DRM_FORMAT_YUV444 , DRM_FORMAT_YVU420,
drivers/gpu/drm/vkms/vkms_plane.c static const u32 vkms_formats[] = { · line 39
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_plane.c +5
-1DRM_FORMAT_YVU422 , -DRM_FORMAT_YVU444 +DRM_FORMAT_YVU444 , +DRM_FORMAT_R1 , +DRM_FORMAT_R2 , +DRM_FORMAT_R4 , +DRM_FORMAT_R8 }; static struct drm_plane_state *
Thanks,
pq
Louis Chauvet
maintainerRe: [PATCH v5 16/16] drm/vkms: Add support for DRM_FORMAT_R*
Quoted 37 lines · Pekka Paalanen
Quoted 34 lines · On Wed, 13 Mar 2024 18:45:10 +0100 Louis Chauvet <[email protected]>…
This add the support for:
- R1/R2/R4/R8R1 format was tested with [1] and [2].
[1]: https://lore.kernel.org/r/[email protected]
[2]: https://lore.kernel.org/igt-dev/[email protected]/Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_formats.c | 100 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 6 ++- 2 files changed, 105 insertions(+), 1 deletion(-)drivers/gpu/drm/vkms/vkms_formats.c +5
-0@@ -201,6 +201,11 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel)return out_pixel; } +static struct pixel_argb_u16 argb_u16_from_gray8 (u8 gray) +{ +return argb_u16_from_u8888 (255 , gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr,struct conversion_matrix *matrix) {@@ -269,6 +274,89 @@ static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, } }
Quoted 11 lines
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 285
Quoted 9 lines
drivers/gpu/drm/vkms/vkms_formats.c +9
-0+static void Rx_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[],u8 bit_per_pixel,u8 lum_per_level) +{ +struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y);Maybe assert that
rem_y= 0? Orblock_h= 1.
Done for the v6.
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 286
Quoted 1 line
drivers/gpu/drm/vkms/vkms_formats.c +1
-0+int bit_offset = (int )rem_x * bit_per_pixel;Why cast
rem_xto int when it was defined to be int?
Because it was not the case for my first implementation, and I miss this cast... Thanks.
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 288
Quoted 2 lines
drivers/gpu/drm/vkms/vkms_formats.c +2
-0+int step =get_step_next_block (plane->frame_info->fb, direction,0 ); +int mask = (0x1 << bit_per_pixel) -1 ;Since mask will interact with u8, it should be unsigned too.
Ok, I will change it for the v6.
Quoted 15 lines
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 300
Quoted 12 lines
drivers/gpu/drm/vkms/vkms_formats.c +12
-0+ +if (direction ==READ_LEFT_TO_RIGHT || direction ==READ_RIGHT_TO_LEFT ) { +int restart_bit_offset =0 ; +int step_bit_offset = bit_per_pixel; + +if (direction ==READ_RIGHT_TO_LEFT ) { + restart_bit_offset =8 - bit_per_pixel; + step_bit_offset = -bit_per_pixel; + } + +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset;or shorter: (
*src_pixels>>bit_offset) & mask
Quoted 1 line
However, shouldn't the first pixel be on the high bits?
Obviously yes... I missunderstood it... fixed in the v6 (and it will be fixed in the next iteration of my igt series).
Quoted 3 lines
That how I would understand the comments in
drm_fourcc.h.Again a reason to avoid a solid color fill in IGT.
Yes, but in this case I wrote the IGT test too... So "wrong + wrong = test SUCCESS" :)
There are some patterns in IGT, but they are only for "color". None of them are available for "black and white"/"gray" formats.
Quoted 45 lines
Quoted 45 lines
drivers/gpu/drm/vkms/vkms_formats.c +45
-0+ + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + + bit_offset += step_bit_offset; +if (bit_offset <0 ||8 <= bit_offset) { + bit_offset = restart_bit_offset; + src_pixels += step; + } + out_pixel +=1 ; + } + }else if (direction ==READ_TOP_TO_BOTTOM || direction ==READ_BOTTOM_TO_TOP ) { +while (out_pixel < end) { +u8 val = (*src_pixels & (mask << bit_offset)) >> bit_offset; + *out_pixel =argb_u16_from_gray8 (val * lum_per_level); + src_pixels += step; + out_pixel +=1 ; + } + } +} + +static void R1_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,1 ,0xFF ); +} + +static void R2_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,2 ,0x55 ); +} + +static void R4_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +Rx_read_line (plane, x_start, y_start, direction, count, out_pixel,4 ,0x11 ); +} + +static void R8_read_line (const struct vkms_plane_state *plane,int x_start, +int y_start,enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_formats.c static void black_to_argb_u16(const struct vkms_plane_state *plane, int x_start, · line 351
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_formats.c +6
-0+struct pixel_argb_u16 *end = out_pixel + count; +u8 *src_pixels; +int rem_x, rem_y; +int step =get_step_next_block (plane->frame_info->fb, direction,0 ); + +packed_pixels_addr (plane->frame_info, x_start, y_start,0 , &src_pixels, &rem_x, &rem_y);Assert on block size?
Fixed in v6.
Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/vkms/vkms_formats.c +16
-0+ +while (out_pixel < end) { + *out_pixel =argb_u16_from_gray8 (*src_pixels); + src_pixels += step; + out_pixel +=1 ; + } +} +static void ARGB8888_read_line (const struct vkms_plane_state *plane,int x_start,int y_start,enum pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[])@@ -582,6 +670,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 format)case DRM_FORMAT_YVU422 :case DRM_FORMAT_YVU444 :return &planar_yuv_read_line; +case DRM_FORMAT_R1 : +return &R1_read_line; +case DRM_FORMAT_R2 : +return &R2_read_line; +case DRM_FORMAT_R4 : +return &R4_read_line; +case DRM_FORMAT_R8 : +return &R8_read_line;default :/* * This is a bug in vkms_plane_atomic_check. All the supported @@ -855,6 +951,10 @@ get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding,case DRM_FORMAT_ARGB16161616 :case DRM_FORMAT_XRGB16161616 :case DRM_FORMAT_RGB565 :
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_formats.c get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, · line 959
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_formats.c +4
-0+case DRM_FORMAT_R1 : +case DRM_FORMAT_R2 : +case DRM_FORMAT_R4 : +case DRM_FORMAT_R8 :/* * Those formats are supported, but they don't need a conversion matrix. Return It is strange that you need to list irrelevant formats here.
It is not needed anymore.
Thanks for your review,
Louis Chauvet
Quoted 23 lines
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_formats.c +0
-0* a valid pointer to avoid kernel panic in case this matrix is used/checked drivers/gpu/drm/vkms/vkms_plane.c +0
-0@@ -29,7 +29,11 @@ static const u32 vkms_formats[] = {DRM_FORMAT_YUV444 , DRM_FORMAT_YVU420,drivers/gpu/drm/vkms/vkms_plane.c static const u32 vkms_formats[] = { · line 39
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_plane.c +5
-1DRM_FORMAT_YVU422 , -DRM_FORMAT_YVU444 +DRM_FORMAT_YVU444 , +DRM_FORMAT_R1 , +DRM_FORMAT_R2 , +DRM_FORMAT_R4 , +DRM_FORMAT_R8 }; static struct drm_plane_state *Thanks,
pq
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com