]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/vkms: Add support for DRM_FORMAT_R*
authorLouis Chauvet <louis.chauvet@bootlin.com>
Tue, 15 Apr 2025 13:55:39 +0000 (15:55 +0200)
committerLouis Chauvet <louis.chauvet@bootlin.com>
Wed, 28 May 2025 14:19:15 +0000 (16:19 +0200)
This add the support for:
- R1/R2/R4/R8

R1 format was tested with [1] and [2].

[1]: https://lore.kernel.org/r/20240313-new_rotation-v2-0-6230fd5cae59@bootlin.com
[2]: https://lore.kernel.org/igt-dev/20240306-b4-kms_tests-v1-0-8fe451efd2ac@bootlin.com/

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Acked-by: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20250415-yuv-v18-8-f2918f71ec4b@bootlin.com
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
drivers/gpu/drm/vkms/vkms_formats.c
drivers/gpu/drm/vkms/vkms_plane.c

index 9972780f3fa975ad8f5bcb71fa5c616071a8cf08..6d0227c6635adbedf28301672fb4b0a411c9e6df 100644 (file)
@@ -249,6 +249,16 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
        return out_pixel;
 }
 
+static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
+{
+       return argb_u16_from_u8888(255, gray, gray, gray);
+}
+
+static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray)
+{
+       return argb_u16_from_u16161616(0xFFFF, gray, gray, gray);
+}
+
 VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2,
                                                            const struct conversion_matrix *matrix)
 {
@@ -286,7 +296,7 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888);
  * The following functions are read_line function for each pixel format supported by VKMS.
  *
  * They read a line starting at the point @x_start,@y_start following the @direction. The result
- * is stored in @out_pixel and in the format ARGB16161616.
+ * is stored in @out_pixel and in a 64 bits format, see struct pixel_argb_u16.
  *
  * These functions are very repetitive, but the innermost pixel loops must be kept inside these
  * functions for performance reasons. Some benchmarking was done in [1] where having the innermost
@@ -295,6 +305,96 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888);
  * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33b3a3@riseup.net/
  */
 
+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[])
+{
+       struct pixel_argb_u16 *end = out_pixel + count;
+       int bits_per_pixel = drm_format_info_bpp(plane->frame_info->fb->format, 0);
+       u8 *src_pixels;
+       int rem_x, rem_y;
+
+       WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) != 1,
+                 "%s() only support formats with block_h == 1", __func__);
+
+       packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &rem_x, &rem_y);
+       int bit_offset = (8 - bits_per_pixel) - rem_x * bits_per_pixel;
+       int step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
+       int mask = (0x1 << bits_per_pixel) - 1;
+       int lum_per_level = 0xFFFF / mask;
+
+       if (direction == READ_LEFT_TO_RIGHT || direction == READ_RIGHT_TO_LEFT) {
+               int restart_bit_offset;
+               int step_bit_offset;
+
+               if (direction == READ_LEFT_TO_RIGHT) {
+                       restart_bit_offset = 8 - bits_per_pixel;
+                       step_bit_offset = -bits_per_pixel;
+               } else {
+                       restart_bit_offset = 0;
+                       step_bit_offset = bits_per_pixel;
+               }
+
+               while (out_pixel < end) {
+                       u8 val = ((*src_pixels) >> bit_offset) & mask;
+
+                       *out_pixel = argb_u16_from_grayu16((int)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 >> bit_offset) & mask;
+                       *out_pixel = argb_u16_from_grayu16((int)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);
+}
+
+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);
+}
+
+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);
+}
+
+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 step = get_block_step_bytes(plane->frame_info->fb, direction, 0);
+
+       packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels);
+
+       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[])
@@ -636,6 +736,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
index fbfbe424e558d781759c25a46e3b2b4ab082558c..e3fdd161d0f0a1d20c14a79dbe51c08c8486d12f 100644 (file)
@@ -31,6 +31,10 @@ static const u32 vkms_formats[] = {
        DRM_FORMAT_YVU420,
        DRM_FORMAT_YVU422,
        DRM_FORMAT_YVU444,
+       DRM_FORMAT_R1,
+       DRM_FORMAT_R2,
+       DRM_FORMAT_R4,
+       DRM_FORMAT_R8,
 };
 
 static struct drm_plane_state *