drm/vkms: Reimplement line-per-line pixel conversion for plane reading
Louis Chauvet
maintainerv3 cover drm/vkms: Reimplement line-per-line pixel conversion for plane reading
This patchset is the second version of [1]. It is almost a complete rewrite to use a line-by-line algorithm for the composition. It can be divided in three parts:
- PATCH 1 to 4: no functional change is intended, only some formatting and documenting
(PATCH 2 is taken from [2])
- PATCH 5: main patch for this series, it reintroduce the line-by-line algorithm
- PATCH 6 to 9: taken from Arthur's series [2], with sometimes adaptation to use the pixel-by-pixel algorithm.
The PATCH 5 aims to restore the line-by-line pixel reading algorithm. It was introduced in 8ba1648567e2 ("drm: vkms: Refactor the plane composer to accept new formats") but removed in 8ba1648567e2 ("drm: vkms: Refactor the plane composer to accept new formats") in a over-simplification effort. At this time, nobody noticed the performance impact of this commit. After the first iteration of my series, poeple notice performance impact, and it was the case. Pekka suggested to reimplement the line-by-line algorithm.
Expiriments on my side shown great improvement for the line-by-line algorithm, and the performances are the same as the original line-by-line algorithm. I targeted my effort to make the code working for all the rotations and translations. The usage of helpers from drm_rect_* avoid reimplementing existing logic.
The only "complex" part remaining is the clipping of the coordinate to avoid reading/writing outside of src/dst. Thus I added a lot of comments to help when someone will want to add some features (framebuffer resizing for example).
The YUV part is not mandatory for this series, but as my first effort was to help the integration of YUV, I decided to rebase Arthur's series on mine to help. I took [3], [4], [5] and [6] and adapted them to use the line-by-line reading. If I did something wrong here, please let me know.
My series was mainly tested with:
- kms_plane (for color conversions)
- kms_rotation_crc (for rotations of planes)
- kms_cursor_crc (for translations)
The benchmark used to measure the improvment was done with:
- kms_fb_stress
[1]: https://lore.kernel.org/r/[email protected]
[2]: https://lore.kernel.org/all/[email protected]/
[3]: https://lore.kernel.org/all/[email protected]/
[4]: https://lore.kernel.org/all/[email protected]/
[5]: https://lore.kernel.org/all/[email protected]/
[6]: https://lore.kernel.org/all/[email protected]/
To: Rodrigo Siqueira <[email protected]>
To: Melissa Wen <[email protected]>
To: Maíra Canal <[email protected]>
To: Haneen Mohammed <[email protected]>
To: Daniel Vetter <[email protected]>
To: Maarten Lankhorst <[email protected]>
To: Maxime Ripard <[email protected]>
To: Thomas Zimmermann <[email protected]>
To: David Airlie <[email protected]>
To: [email protected]
To: Jonathan Corbet <[email protected]>
To: [email protected]
Note: after my changes, those tests seems to pass, so [7] may need updating (I did not check, it was maybe already the case):
- kms_cursor_legacy@flip-vs-cursor-atomic
- kms_pipe_crc_basic@nonblocking-crc
- kms_pipe_crc_basic@nonblocking-crc-frame-sequence
- kms_writeback@writeback-pixel-formats
- kms_writeback@writeback-invalid-parameters
- kms_flip@flip-vs-absolute-wf_vblank-interruptible
And those tests pass, I did not investigate why the runners fails:
- kms_flip@flip-vs-expired-vblank-interruptible
- kms_flip@flip-vs-expired-vblank
- kms_flip@plain-flip-fb-recreate
- kms_flip@plain-flip-fb-recreate-interruptible
- kms_flip@plain-flip-ts-check-interruptible
- kms_cursor_legacy@cursorA-vs-flipA-toggle
- kms_pipe_crc_basic@nonblocking-crc
- kms_prop_blob@invalid-get-prop
- kms_flip@flip-vs-absolute-wf_vblank-interruptible
- kms_invalid_mode@zero-hdisplay
- kms_invalid_mode@bad-vtotal
- kms_cursor_crc.* (everything is SUCCEED or SKIP, but no fails)
[7]: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Correction of remaining git-rebase artefacts
- Added Pekka in copy of this patch
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Rebased the series on top of drm-misc/drm-misc-net
- Extract the typedef for pixel_read/pixel_write
- Introduce the line-by-line algorithm per pixel format
- Add some documentation for existing and new code
- Port the series [1] to use line-by-line algorithm
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Arthur Grillo (5):
drm/vkms: Use drm_frame directly
drm/vkms: Add YUV support
drm/vkms: Add range and encoding properties to pixel_read function drm/vkms: Drop YUV formats TODO
drm/vkms: Create KUnit tests for YUV conversions
Louis Chauvet (4):
drm/vkms: Code formatting
drm/vkms: write/update the documentation for pixel conversion and pixel write functions drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions drm/vkms: Re-introduce line-per-line composition algorithm
Documentation/gpu/vkms.rst | 3 +- 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 | 155 +++++++ drivers/gpu/drm/vkms/vkms_composer.c | 233 ++++++++--- drivers/gpu/drm/vkms/vkms_crtc.c | 6 +- drivers/gpu/drm/vkms/vkms_drv.c | 3 +- drivers/gpu/drm/vkms/vkms_drv.h | 55 ++- drivers/gpu/drm/vkms/vkms_formats.c | 565 +++++++++++++++++++++----- drivers/gpu/drm/vkms/vkms_formats.h | 13 +- drivers/gpu/drm/vkms/vkms_plane.c | 50 ++- drivers/gpu/drm/vkms/vkms_writeback.c | 14 +- 13 files changed, 915 insertions(+), 190 deletions(-)
---
base-commit: c079e2e113f2ec2803ba859bbb442a6ab82c96bd
change-id: 20240201-yuv-1337d90d9576
Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
Louis Chauvet
maintainerPATCH v3 1/9 drm/vkms: Code formatting
Few no-op changes to remove double spaces and fix wrong alignments.
--- drivers/gpu/drm/vkms/vkms_composer.c | 10 +++++----- drivers/gpu/drm/vkms/vkms_crtc.c | 6 ++---- drivers/gpu/drm/vkms/vkms_drv.c | 3 +-- drivers/gpu/drm/vkms/vkms_plane.c | 9 ++++----- 4 files changed, 12 insertions(+), 16 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +5 -5
@@ -96,7 +96,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)s64 a_fp =drm_int2fixp (a);s64 b_fp =drm_int2fixp (b); -s64 delta =drm_fixp_mul (b_fp - a_fp, t); +s64 delta =drm_fixp_mul (b_fp - a_fp, t);return drm_fixp2int (a_fp + delta); }
@@ -302,8 +302,8 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb,void vkms_composer_worker (struct work_struct *work) {struct vkms_crtc_state *crtc_state =container_of (work, - struct vkms_crtc_state, - composer_work); + struct vkms_crtc_state, + composer_work);struct drm_crtc *crtc = crtc_state->base.crtc;struct vkms_writeback_job *active_wb = crtc_state->active_writeback;struct vkms_output *out =drm_crtc_to_vkms_output (crtc);
@@ -328,7 +328,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->gamma_lut.base = (struct drm_color_lut *)crtc->state->gamma_lut->data; crtc_state->gamma_lut.lut_length = crtc->state->gamma_lut->length /sizeof (struct drm_color_lut ); - max_lut_index_fp =drm_int2fixp (crtc_state->gamma_lut.lut_length -1 ); + max_lut_index_fp =drm_int2fixp (crtc_state->gamma_lut.lut_length -1 ); crtc_state->gamma_lut.channel_value2index_ratio =drm_fixp_div (max_lut_index_fp, u16_max_fp);
@@ -367,7 +367,7 @@ void vkms_composer_worker(struct work_struct *work)drm_crtc_add_crc_entry (crtc, true, frame_start++, &crc32); } -static const char *const pipe_crc_sources[] = {"auto" }; +static const char *const pipe_crc_sources[] = {"auto" };const char *const *vkms_get_crc_sources (struct drm_crtc *crtc,size_t *count)
drivers/gpu/drm/vkms/vkms_crtc.c +2 -4
@@ -191,8 +191,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc,return ret;drm_for_each_plane_mask (plane, crtc->dev, crtc_state->plane_mask) { - plane_state =drm_atomic_get_existing_plane_state (crtc_state->state, - plane); + plane_state =drm_atomic_get_existing_plane_state (crtc_state->state, plane);WARN_ON (!plane_state);if (!plane_state->visible)
@@ -208,8 +207,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, i =0 ;drm_for_each_plane_mask (plane, crtc->dev, crtc_state->plane_mask) { - plane_state =drm_atomic_get_existing_plane_state (crtc_state->state, - plane); + plane_state =drm_atomic_get_existing_plane_state (crtc_state->state, plane);if (!plane_state->visible)continue ;
drivers/gpu/drm/vkms/vkms_drv.c +1 -2
@@ -81,8 +81,7 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)drm_atomic_helper_wait_for_flip_done (dev, old_state);for_each_old_crtc_in_state (old_state, crtc, old_crtc_state, i) { -struct vkms_crtc_state *vkms_state = -to_vkms_crtc_state (old_crtc_state); +struct vkms_crtc_state *vkms_state =to_vkms_crtc_state (old_crtc_state);flush_work (&vkms_state->composer_work); }
drivers/gpu/drm/vkms/vkms_plane.c +4 -5
@@ -112,15 +112,14 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, frame_info = vkms_plane_state->frame_info;memcpy (&frame_info->src, &new_state->src,sizeof (struct drm_rect ));memcpy (&frame_info->dst, &new_state->dst,sizeof (struct drm_rect )); -memcpy (&frame_info->rotated, &new_state->dst,sizeof (struct drm_rect )); frame_info->fb = fb;memcpy (&frame_info->map, &shadow_plane_state->data,sizeof (frame_info->map));drm_framebuffer_get (frame_info->fb); frame_info->rotation =drm_rotation_simplify (new_state->rotation,DRM_MODE_ROTATE_0 | -DRM_MODE_ROTATE_90 | -DRM_MODE_ROTATE_270 | -DRM_MODE_REFLECT_X | -DRM_MODE_REFLECT_Y ); +DRM_MODE_ROTATE_90 | +DRM_MODE_ROTATE_270 | +DRM_MODE_REFLECT_X | +DRM_MODE_REFLECT_Y );drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated),drm_rect_height (&frame_info->rotated), frame_info->rotation);
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v3 2/9 drm/vkms: Use drm_frame directly
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
Remove intermidiary variables and access the variables directly from drm_frame. These changes should be noop.
--- drivers/gpu/drm/vkms/vkms_drv.h | 3 --- drivers/gpu/drm/vkms/vkms_formats.c | 12 +++++++----- drivers/gpu/drm/vkms/vkms_plane.c | 3 --- drivers/gpu/drm/vkms/vkms_writeback.c | 5 ----- 4 files changed, 7 insertions(+), 16 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.h +0 -3
@@ -31,9 +31,6 @@ struct vkms_frame_info {struct drm_rect rotated;struct iosys_map map[DRM_FORMAT_MAX_PLANES ];unsigned int rotation; -unsigned int offset; -unsigned int pitch; -unsigned int cpp; };struct pixel_argb_u16 {
drivers/gpu/drm/vkms/vkms_formats.c +7 -5
@@ -11,8 +11,10 @@static size_t pixel_offset (const struct vkms_frame_info *frame_info,int x,int y) { -return frame_info->offset + (y * frame_info->pitch) - + (x * frame_info->cpp); +struct drm_framebuffer *fb = frame_info->fb; + +return fb->offsets[0 ] + (y * fb->pitches[0 ]) + + (x * fb->format->cpp[0 ]); }/*
@@ -131,12 +133,12 @@ void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_stateu8 *src_pixels =get_packed_src_addr (frame_info, y);int limit =min_t (size_t,drm_rect_width (&frame_info->dst), stage_buffer->n_pixels); -for (size_t x =0 ; x < limit; x++, src_pixels += frame_info->cpp) { +for (size_t x =0 ; x < limit; x++, src_pixels += frame_info->fb->format->cpp[0 ]) {int x_pos =get_x_position (frame_info, limit, x);if (drm_rotation_90_or_270 (frame_info->rotation)) src_pixels =get_packed_src_addr (frame_info, x + frame_info->rotated.y1) - + frame_info->cpp * y; + + frame_info->fb->format->cpp[0 ] * y; plane->pixel_read (src_pixels, &out_pixels[x_pos]); }
@@ -223,7 +225,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb,struct pixel_argb_u16 *in_pixels = src_buffer->pixels;int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), src_buffer->n_pixels); -for (size_t x =0 ; x < x_limit; x++, dst_pixels += frame_info->cpp) +for (size_t x =0 ; x < x_limit; x++, dst_pixels += frame_info->fb->format->cpp[0 ]) wb->pixel_write (dst_pixels, &in_pixels[x]); }
drivers/gpu/drm/vkms/vkms_plane.c +0 -3
@@ -124,9 +124,6 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated),drm_rect_height (&frame_info->rotated), frame_info->rotation); - frame_info->offset = fb->offsets[0 ]; - frame_info->pitch = fb->pitches[0 ]; - frame_info->cpp = fb->format->cpp[0 ]; vkms_plane_state->pixel_read =get_pixel_conversion_function (fmt); }
drivers/gpu/drm/vkms/vkms_writeback.c +0 -5
@@ -149,11 +149,6 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, crtc_state->active_writeback = active_wb; crtc_state->wb_pending = true;spin_unlock_irq (&output->composer_lock); - - wb_frame_info->offset = fb->offsets[0 ]; - wb_frame_info->pitch = fb->pitches[0 ]; - wb_frame_info->cpp = fb->format->cpp[0 ]; -drm_writeback_queue_job (wb_conn, connector_state); active_wb->pixel_write =get_pixel_write_function (wb_format);drm_rect_init (&wb_frame_info->src,0 ,0 , crtc_width, crtc_height);
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v3 3/9 drm/vkms: write/update the documentation for pixel conversion and pixel write functions
In reply to Louis ChauvetAdd some documentation on pixel conversion functions. Update of outdated comments for pixel_write functions.
--- drivers/gpu/drm/vkms/vkms_composer.c | 4 +++ drivers/gpu/drm/vkms/vkms_drv.h | 13 ++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 58 ++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 9 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +4 -0
@@ -189,6 +189,10 @@ static void blend(struct vkms_writeback_job *wb,size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; +/* +* The planes are composed line-by-line. It is a necessary complexity to avoid poor +* blending performance. +*/ for (size_t y =0 ; y < crtc_y_limit; y++) {fill_background (&background_color, output_buffer);
drivers/gpu/drm/vkms/vkms_drv.h +13 -0
@@ -25,6 +25,17 @@#define VKMS_LUT_SIZE 256 +/** +* struct vkms_frame_info - structure to store the state of a frame +* +* @fb: backing drm framebuffer +* @src: source rectangle of this frame in the source framebuffer +* @dst: destination rectangle in the crtc buffer +* @map: see drm_shadow_plane_state@data +* @rotation: rotation applied to the source. +* +* @src and @dst should have the same size modulo the rotation. +*/ struct vkms_frame_info {struct drm_framebuffer *fb;struct drm_rect src, dst;
@@ -52,6 +63,8 @@ struct vkms_writeback_job {* vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation +* @pixel_read: function to read a pixel in this plane. The creator of a vkms_plane_state must +* ensure that this pointer is valid */ struct vkms_plane_state {struct drm_shadow_plane_state base;
drivers/gpu/drm/vkms/vkms_formats.c +49 -9
103 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 3/9] drm/vkms: write/update the documentation for pixel conversion and pixel write functions
Quoted 15 lines · Louis Chauvet
Add some documentation on pixel conversion functions. Update of outdated comments for
pixel_writefunctions.Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 4 +++ drivers/gpu/drm/vkms/vkms_drv.h | 13 ++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 58 ++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 9 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +0
-0
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 194
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_composer.c +3
-0@@ -189,6 +189,10 @@ static void blend(struct vkms_writeback_job *wb,size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; +/* +* The planes are composed line-by-line. It is a necessary complexity to avoid poor +* blending performance.
At this moment in the series, you have not yet reintroduced the line-by-line algorithm yet. Maybe it's better to add this comment when you do.
Also, I think it's good to give more context, like:
"The planes are composed line-by-line, instead of pixel-by-pixel"
Best Regards,
~Arthur Grillo
Quoted 150 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-0+*/ for (size_t y =0 ; y < crtc_y_limit; y++) {fill_background (&background_color, output_buffer);drivers/gpu/drm/vkms/vkms_drv.h +13
-0@@ -25,6 +25,17 @@#define VKMS_LUT_SIZE 256 +/** +* struct vkms_frame_info - structure to store the state of a frame +* +* @fb: backing drm framebuffer +* @src: source rectangle of this frame in the source framebuffer +* @dst: destination rectangle in the crtc buffer +* @map: see drm_shadow_plane_state@data +* @rotation: rotation applied to the source. +* +* @src and @dst should have the same size modulo the rotation. +*/ struct vkms_frame_info {struct drm_framebuffer *fb;struct drm_rect src, dst;@@ -52,6 +63,8 @@ struct vkms_writeback_job {* vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation +* @pixel_read: function to read a pixel in this plane. The creator of a vkms_plane_state must +* ensure that this pointer is valid */ struct vkms_plane_state {struct drm_shadow_plane_state base;drivers/gpu/drm/vkms/vkms_formats.c +49
-9@@ -9,6 +9,17 @@#include "vkms_formats.h" +/** +* packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y +* in the first plane +* +* @frame_info: Buffer metadata +* @x: The x coordinate of the wanted pixel in the buffer +* @y: The y coordinate of the wanted pixel in the buffer +* +* The caller must be aware that this offset is not always a pointer to a pixel. If individual +* pixel values are needed, they have to be extracted from the resulting block. +*/ static size_t pixel_offset (const struct vkms_frame_info *frame_info,int x,int y) {struct drm_framebuffer *fb = frame_info->fb;@@ -17,12 +28,13 @@ static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int + (x * fb->format->cpp[0 ]); } -/* -* packed_pixels_addr - Get the pointer to pixel of a given pair of coordinates +/** +* packed_pixels_addr() - Get the pointer to the block containing the pixel at the given +* coordinates * * @frame_info: Buffer metadata -* @x: The x(width) coordinate of the 2D buffer -* @y: The y(Heigth) coordinate of the 2D buffer +* @x: The x(width) coordinate inside the plane +* @y: The y(height) coordinate inside the plane * * Takes the information stored in the frame_info, a pair of coordinates, and * returns the address of the first color channel. @@ -53,6 +65,13 @@ static int get_x_position(const struct vkms_frame_info *frame_info, int limit, ireturn x; } +/* +* The following functions take pixel data from the buffer and convert them to the format +* ARGB16161616 in out_pixel. +* +* They are used in the `vkms_compose_row` function to handle multiple formats. +*/ +static void ARGB8888_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) {/* @@ -145,12 +164,11 @@ void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state }/* -* The following functions take an line of argb_u16 pixels from the -* src_buffer, convert them to a specific format, and store them in the -* destination. +* The following functions take one argb_u16 pixel and convert it to a specific format. The +* result is stored in @dst_pixels. * -* They are used in the `compose_active_planes` to convert and store a line -* from the src_buffer to the writeback buffer. +* They are used in the `vkms_writeback_row` to convert and store a pixel from the src_buffer to +* the writeback buffer. */ static void argb_u16_to_ARGB8888 (u8 *dst_pixels,struct pixel_argb_u16 *in_pixel) {@@ -216,6 +234,14 @@ static void argb_u16_to_RGB565(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel) *pixels =cpu_to_le16 (r <<11 | g <<5 | b); } +/** +* Generic loop for all supported writeback format. It is executed just after the blending to +* write a line in the writeback buffer. +* +* @wb: Job where to insert the final image +* @src_buffer: Line to write +* @y: Row to write in the writeback buffer +*/ void vkms_writeback_row (struct vkms_writeback_job *wb,const struct line_buffer *src_buffer,int y) {@@ -229,6 +255,13 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, wb->pixel_write (dst_pixels, &in_pixels[x]); } +/** +* Retrieve the correct read_pixel function for a specific format. +* The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the +* pointer is valid before using it in a vkms_plane_state. +* +* @format: 4cc of the format +*/ void *get_pixel_conversion_function (u32 format) {switch (format) {@@ -247,6 +280,13 @@ void *get_pixel_conversion_function(u32 format) } } +/** +* Retrieve the correct write_pixel function for a specific format. +* The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the +* pointer is valid before using it in a vkms_writeback_job. +* +* @format: 4cc of the format +*/ void *get_pixel_write_function (u32 format) {switch (format) {
Louis Chauvet
maintainerRe: [PATCH v3 3/9] drm/vkms: write/update the documentation for pixel conversion and pixel write functions
Quoted 21 lines · Arthur Grillo
Quoted 18 lines · Louis Chauvet
Add some documentation on pixel conversion functions. Update of outdated comments for
pixel_writefunctions.Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 4 +++ drivers/gpu/drm/vkms/vkms_drv.h | 13 ++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 58 ++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 9 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +0
-0@@ -189,6 +189,10 @@ static void blend(struct vkms_writeback_job *wb,size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay;
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 194
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_composer.c +3
-0+/* +* The planes are composed line-by-line. It is a necessary complexity to avoid poor +* blending performance. At this moment in the series, you have not yet reintroduced the line-by-line algorithm yet. Maybe it's better to add this comment when you do.
Is it better with this:
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The function vkms_compose_row is used to read a line, pixel-by-pixel, into the staging
* buffer.
*/
Quoted 2 lines
Also, I think it's good to give more context, like:
"The planes are composed line-by-line, instead of pixel-by-pixel"
And after PATCHv3 5/9:
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The function pixel_read_line callback is used to read a line, using an efficient
* algorithm for a specific format, into the staging buffer.
*/
Kind regards,
Louis Chauvet
Quoted 2 lines
Best Regards,
~Arthur Grillo
[...]
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 3/9] drm/vkms: write/update the documentation for pixel conversion and pixel write functions
Quoted 45 lines · Louis Chauvet
Quoted 21 lines · Arthur Grillo
Quoted 18 lines · Louis Chauvet
Add some documentation on pixel conversion functions. Update of outdated comments for
pixel_writefunctions.Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 4 +++ drivers/gpu/drm/vkms/vkms_drv.h | 13 ++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 58 ++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 9 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +0
-0@@ -189,6 +189,10 @@ static void blend(struct vkms_writeback_job *wb,size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay;Quoted 7 lines
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 194
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_composer.c +3
-0+/* +* The planes are composed line-by-line. It is a necessary complexity to avoid poor +* blending performance. At this moment in the series, you have not yet reintroduced the line-by-line algorithm yet. Maybe it's better to add this comment when you do.
Is it better with this:
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The functionvkms_compose_rowis used to read a line, pixel-by-pixel, into the staging
* buffer.
*/Quoted 2 lines
Also, I think it's good to give more context, like:
"The planes are composed line-by-line, instead of pixel-by-pixel"And after PATCHv3 5/9:
Quoted 8 lines
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The functionpixel_read_linecallback is used to read a line, using an efficient
* algorithm for a specific format, into the staging buffer.
*/
Hi,
This looks good to me.
Best Regards,
~Arthur Grillo
Quoted 8 lines
Kind regards,
Louis ChauvetQuoted 2 lines
Best Regards,
~Arthur Grillo[...]
Re: [PATCH v3 3/9] drm/vkms: write/update the documentation for pixel conversion and pixel write functions
Quoted 46 lines · On Tue, 27 Feb 2024 15:47:08 -0300 Arthur Grillo <[email protected]>…
Quoted 45 lines · Louis Chauvet
Quoted 21 lines · Arthur Grillo
Quoted 18 lines · Louis Chauvet
Add some documentation on pixel conversion functions. Update of outdated comments for
pixel_writefunctions.Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 4 +++ drivers/gpu/drm/vkms/vkms_drv.h | 13 ++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 58 ++++++++++++++++++++++++++++++------ 3 files changed, 66 insertions(+), 9 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +0
-0@@ -189,6 +189,10 @@ static void blend(struct vkms_writeback_job *wb,size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay;Quoted 7 lines
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 194
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_composer.c +3
-0+/* +* The planes are composed line-by-line. It is a necessary complexity to avoid poor +* blending performance. At this moment in the series, you have not yet reintroduced the line-by-line algorithm yet. Maybe it's better to add this comment when you do.
Is it better with this:
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The functionvkms_compose_rowis used to read a line, pixel-by-pixel, into the staging
* buffer.
*/Quoted 2 lines
Also, I think it's good to give more context, like:
"The planes are composed line-by-line, instead of pixel-by-pixel"And after PATCHv3 5/9:
Quoted 8 lines
Quoted 8 lines
/*
* The planes are composed line-by-line to avoid heavy memory usage. It is a necessary
* complexity to avoid poor blending performance.
*
* The functionpixel_read_linecallback is used to read a line, using an efficient
* algorithm for a specific format, into the staging buffer.
*/
Hi,
there are a few reasons for the line-by-line algorithm, and the optimizations at large:
VKMS uses temporary stage and output buffers so that blending functions can operate on just one high-precision pixel format, struct pixel_argb_u16. We can make pixel-format-specific read and write functions completely orthogonal from the blending operations and FB format combinations. This avoids a combinatorial explosion of needed functions for { input pixel formats × blending operations × output pixel formats }.
We can use a temporary stage and output buffer whose size is one line and not whole FB or CRTC framebuffer. This is the memory savings.
Using a temporary output buffer also avoids repeated read-decode-blend-encode-write cycles into the final destination buffer, as we don't need to decode/encode the pixel format.
Finally, doing elementary operations (read, blend, write) line-by-line is much more efficient than pixel-by-pixel, because it allows making the inner-most loop very tight. It avoids repeatedly computing a result that does not change, like which function to call for a specific pixel format or blending equation.
Thanks,
pq
Louis Chauvet
maintainerPATCH v3 4/9 drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions
In reply to Louis ChauvetIntroduce two typedefs: pixel_read_t and pixel_write_t. It allows the compiler to check if the passed functions take the correct arguments. Such typedefs will help ensuring consistency across the code base in case of update of these prototypes.
Introduce a check around the get_pixel_*_functions to avoid using a nullptr as a function.
Document for those typedefs.
--- drivers/gpu/drm/vkms/vkms_drv.h | 23 +++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_formats.c | 8 ++++---- drivers/gpu/drm/vkms/vkms_formats.h | 4 ++-- drivers/gpu/drm/vkms/vkms_plane.c | 9 ++++++++- drivers/gpu/drm/vkms/vkms_writeback.c | 9 ++++++++- 5 files changed, 43 insertions(+), 10 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.h +21 -2
@@ -53,12 +53,31 @@ struct line_buffer {struct pixel_argb_u16 *pixels; }; +/** +* typedef pixel_write_t - These functions are used to read a pixel from a +* `struct pixel_argb_u16*`, convert it in a specific format and write it in the @dst_pixels +* buffer. +* +* @dst_pixel: destination address to write the pixel +* @in_pixel: pixel to write +*/ +typedef void (*pixel_write_t )(u8 *dst_pixels,struct pixel_argb_u16 *in_pixel); +struct vkms_writeback_job {struct iosys_map data[DRM_FORMAT_MAX_PLANES ];struct vkms_frame_info wb_frame_info; -void (*pixel_write)(u8 *dst_pixels,struct pixel_argb_u16 *in_pixel); +pixel_write_t pixel_write; }; +/** +* typedef pixel_read_t - These functions are used to read a pixel in the source frame, +* convert it to `struct pixel_argb_u16` and write it to @out_pixel. +* +* @src_pixels: Pointer to the pixel to read +* @out_pixel: Pointer to write the converted pixel +*/ +typedef void (*pixel_read_t )(u8 *src_pixels,struct pixel_argb_u16 *out_pixel); +/** * vkms_plane_state - Driver specific plane state * @base: base plane state
@@ -69,7 +88,7 @@ struct vkms_writeback_job {struct vkms_plane_state {struct drm_shadow_plane_state base;struct vkms_frame_info *frame_info; -void (*pixel_read)(u8 *src_buffer,struct pixel_argb_u16 *out_pixel); +pixel_read_t pixel_read; };struct vkms_plane {
drivers/gpu/drm/vkms/vkms_formats.c +4 -4
@@ -262,7 +262,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb,* * @format: 4cc of the format */ -void *get_pixel_conversion_function (u32 format) +pixel_read_t get_pixel_read_function (u32 format) {switch (format) {case DRM_FORMAT_ARGB8888 :
@@ -276,7 +276,7 @@ void *get_pixel_conversion_function(u32 format)case DRM_FORMAT_RGB565 :return &RGB565_to_argb_u16;default : -return NULL ; +return (pixel_read_t )NULL ; } }
@@ -287,7 +287,7 @@ void *get_pixel_conversion_function(u32 format)* * @format: 4cc of the format */ -void *get_pixel_write_function (u32 format) +pixel_write_t get_pixel_write_function (u32 format) {switch (format) {case DRM_FORMAT_ARGB8888 :
@@ -301,6 +301,6 @@ void *get_pixel_write_function(u32 format)case DRM_FORMAT_RGB565 :return &argb_u16_to_RGB565;default : -return NULL ; +return (pixel_write_t )NULL ; } }
drivers/gpu/drm/vkms/vkms_formats.h +2 -2
@@ -5,8 +5,8 @@#include "vkms_drv.h" -void *get_pixel_conversion_function (u32 format); +pixel_read_t get_pixel_read_function (u32 format); -void *get_pixel_write_function (u32 format); +pixel_write_t get_pixel_write_function (u32 format);#endif /* _VKMS_FORMATS_H_ */
drivers/gpu/drm/vkms/vkms_plane.c +8 -1
@@ -106,6 +106,13 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,return ; fmt = fb->format->format; +pixel_read_t pixel_read =get_pixel_read_function (fmt); + +if (!pixel_read) { +DRM_WARN ("Pixel format is not supported by VKMS planes. State is inchanged\n" ); +return ; + } + vkms_plane_state =to_vkms_plane_state (new_state); shadow_plane_state = &vkms_plane_state->base;
@@ -124,7 +131,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated),drm_rect_height (&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read =get_pixel_conversion_function (fmt); + vkms_plane_state->pixel_read = pixel_read; } static int vkms_plane_atomic_check(struct drm_plane *plane,
drivers/gpu/drm/vkms/vkms_writeback.c +8 -1
@@ -140,6 +140,13 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,if (!conn_state)return ; +pixel_write_t pixel_write =get_pixel_write_function (wb_format); + +if (!pixel_write) { +DRM_WARN ("Pixel format is not supported by VKMS writeback. State is inchanged\n" ); +return ; + } +vkms_set_composer (&vkmsdev->output, true); active_wb = conn_state->writeback_job->priv;
@@ -150,7 +157,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, crtc_state->wb_pending = true;spin_unlock_irq (&output->composer_lock);drm_writeback_queue_job (wb_conn, connector_state); - active_wb->pixel_write =get_pixel_write_function (wb_format); + active_wb->pixel_write = pixel_write;drm_rect_init (&wb_frame_info->src,0 ,0 , crtc_width, crtc_height);drm_rect_init (&wb_frame_info->dst,0 ,0 , crtc_width, crtc_height); }
Signature · 1 line
2.43.0
Re: [PATCH v3 4/9] drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions
Quoted 124 lines · Louis Chauvet
Introduce two typedefs:
pixel_read_tandpixel_write_t. It allows the compiler to check if the passed functions take the correct arguments. Such typedefs will help ensuring consistency across the code base in case of update of these prototypes.Introduce a check around the get_pixel_*_functions to avoid using a nullptr as a function.
Document for those typedefs.
Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.h | 23 +++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_formats.c | 8 ++++---- drivers/gpu/drm/vkms/vkms_formats.h | 4 ++-- drivers/gpu/drm/vkms/vkms_plane.c | 9 ++++++++- drivers/gpu/drm/vkms/vkms_writeback.c | 9 ++++++++- 5 files changed, 43 insertions(+), 10 deletions(-)drivers/gpu/drm/vkms/vkms_drv.h +21
-2@@ -53,12 +53,31 @@ struct line_buffer {struct pixel_argb_u16 *pixels; }; +/** +* typedef pixel_write_t - These functions are used to read a pixel from a +* `struct pixel_argb_u16*`, convert it in a specific format and write it in the @dst_pixels +* buffer. +* +* @dst_pixel: destination address to write the pixel +* @in_pixel: pixel to write +*/ +typedef void (*pixel_write_t )(u8 *dst_pixels,struct pixel_argb_u16 *in_pixel); +struct vkms_writeback_job {struct iosys_map data[DRM_FORMAT_MAX_PLANES ];struct vkms_frame_info wb_frame_info; -void (*pixel_write)(u8 *dst_pixels,struct pixel_argb_u16 *in_pixel); +pixel_write_t pixel_write; }; +/** +* typedef pixel_read_t - These functions are used to read a pixel in the source frame, +* convert it to `struct pixel_argb_u16` and write it to @out_pixel. +* +* @src_pixels: Pointer to the pixel to read +* @out_pixel: Pointer to write the converted pixel +*/ +typedef void (*pixel_read_t )(u8 *src_pixels,struct pixel_argb_u16 *out_pixel); +/** * vkms_plane_state - Driver specific plane state * @base: base plane state @@ -69,7 +88,7 @@ struct vkms_writeback_job {struct vkms_plane_state {struct drm_shadow_plane_state base;struct vkms_frame_info *frame_info; -void (*pixel_read)(u8 *src_buffer,struct pixel_argb_u16 *out_pixel); +pixel_read_t pixel_read; };struct vkms_plane {drivers/gpu/drm/vkms/vkms_formats.c +4
-4@@ -262,7 +262,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb,* * @format: 4cc of the format */ -void *get_pixel_conversion_function (u32 format) +pixel_read_t get_pixel_read_function (u32 format) {switch (format) {case DRM_FORMAT_ARGB8888 :@@ -276,7 +276,7 @@ void *get_pixel_conversion_function(u32 format)case DRM_FORMAT_RGB565 :return &RGB565_to_argb_u16;default : -return NULL ; +return (pixel_read_t )NULL ; } }@@ -287,7 +287,7 @@ void *get_pixel_conversion_function(u32 format)* * @format: 4cc of the format */ -void *get_pixel_write_function (u32 format) +pixel_write_t get_pixel_write_function (u32 format) {switch (format) {case DRM_FORMAT_ARGB8888 :@@ -301,6 +301,6 @@ void *get_pixel_write_function(u32 format)case DRM_FORMAT_RGB565 :return &argb_u16_to_RGB565;default : -return NULL ; +return (pixel_write_t )NULL ; } }drivers/gpu/drm/vkms/vkms_formats.h +2
-2@@ -5,8 +5,8 @@#include "vkms_drv.h" -void *get_pixel_conversion_function (u32 format); +pixel_read_t get_pixel_read_function (u32 format); -void *get_pixel_write_function (u32 format); +pixel_write_t get_pixel_write_function (u32 format);#endif /* _VKMS_FORMATS_H_ */ drivers/gpu/drm/vkms/vkms_plane.c +0
-0
drivers/gpu/drm/vkms/vkms_plane.c static void vkms_plane_atomic_update(struct drm_plane *plane, · line 112
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_plane.c +4
-0@@ -106,6 +106,13 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,return ; fmt = fb->format->format; +pixel_read_t pixel_read =get_pixel_read_function (fmt); + +if (!pixel_read) { +DRM_WARN ("Pixel format is not supported by VKMS planes. State is inchanged\n" );
s/inchanged/unchanged/
Quoted 20 lines
drivers/gpu/drm/vkms/vkms_plane.c +4
-1+return ; + } + vkms_plane_state =to_vkms_plane_state (new_state); shadow_plane_state = &vkms_plane_state->base;@@ -124,7 +131,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated),drm_rect_height (&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read =get_pixel_conversion_function (fmt); + vkms_plane_state->pixel_read = pixel_read; } static int vkms_plane_atomic_check(struct drm_plane *plane,drivers/gpu/drm/vkms/vkms_writeback.c +0
-0
drivers/gpu/drm/vkms/vkms_writeback.c static void vkms_wb_atomic_commit(struct drm_connector *conn, · line 146
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_writeback.c +4
-0@@ -140,6 +140,13 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,if (!conn_state)return ; +pixel_write_t pixel_write =get_pixel_write_function (wb_format); + +if (!pixel_write) { +DRM_WARN ("Pixel format is not supported by VKMS writeback. State is inchanged\n" );
Same here
Best Regards,
~Arthur Grillo
Quoted 16 lines
drivers/gpu/drm/vkms/vkms_writeback.c +4
-1+return ; + } +vkms_set_composer (&vkmsdev->output, true); active_wb = conn_state->writeback_job->priv;@@ -150,7 +157,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, crtc_state->wb_pending = true;spin_unlock_irq (&output->composer_lock);drm_writeback_queue_job (wb_conn, connector_state); - active_wb->pixel_write =get_pixel_write_function (wb_format); + active_wb->pixel_write = pixel_write;drm_rect_init (&wb_frame_info->src,0 ,0 , crtc_width, crtc_height);drm_rect_init (&wb_frame_info->dst,0 ,0 , crtc_width, crtc_height); }
Louis Chauvet
maintainerRe: [PATCH v3 4/9] drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions
[...]
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_plane.c +0
-0@@ -106,6 +106,13 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,return ;
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_plane.c static void vkms_plane_atomic_update(struct drm_plane *plane, · line 112
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_plane.c +4
-0fmt = fb->format->format; +pixel_read_t pixel_read =get_pixel_read_function (fmt); + +if (!pixel_read) { +DRM_WARN ("Pixel format is not supported by VKMS planes. State is inchanged\n" );s/inchanged/unchanged/
Thanks for this correction. See my answer to [1], I changed the message a bit.
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Kind regards,
Louis Chauvet
Quoted 49 lines
Quoted 20 lines
drivers/gpu/drm/vkms/vkms_plane.c +4
-1+return ; + } + vkms_plane_state =to_vkms_plane_state (new_state); shadow_plane_state = &vkms_plane_state->base;@@ -124,7 +131,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated),drm_rect_height (&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read =get_pixel_conversion_function (fmt); + vkms_plane_state->pixel_read = pixel_read; } static int vkms_plane_atomic_check(struct drm_plane *plane,drivers/gpu/drm/vkms/vkms_writeback.c +0
-0drivers/gpu/drm/vkms/vkms_writeback.c static void vkms_wb_atomic_commit(struct drm_connector *conn, · line 146
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_writeback.c +4
-0@@ -140,6 +140,13 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,if (!conn_state)return ; +pixel_write_t pixel_write =get_pixel_write_function (wb_format); + +if (!pixel_write) { +DRM_WARN ("Pixel format is not supported by VKMS writeback. State is inchanged\n" );Same here
Best Regards,
~Arthur GrilloQuoted 16 lines
drivers/gpu/drm/vkms/vkms_writeback.c +4
-1+return ; + } +vkms_set_composer (&vkmsdev->output, true); active_wb = conn_state->writeback_job->priv;@@ -150,7 +157,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, crtc_state->wb_pending = true;spin_unlock_irq (&output->composer_lock);drm_writeback_queue_job (wb_conn, connector_state); - active_wb->pixel_write =get_pixel_write_function (wb_format); + active_wb->pixel_write = pixel_write;drm_rect_init (&wb_frame_info->src,0 ,0 , crtc_width, crtc_height);drm_rect_init (&wb_frame_info->dst,0 ,0 , crtc_width, crtc_height); }
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Louis Chauvet
maintainerPATCH v3 5/9 drm/vkms: Re-introduce line-per-line composition algorithm
In reply to Louis ChauvetRe-introduce a line-by-line composition algorithm for each pixel format. This allows more performance by not requiring an indirection per pixel read. This patch is focused on readability of the code.
Line-by-line composition was introduced by [1] but rewritten back to pixel-by-pixel algorithm in [2]. At this time, nobody noticed the impact on performance, and it was merged.
This patch is almost a revert of [2], but in addition efforts have been made to increase readability and maintainability of the rotation handling. The blend function is now divided in two parts:
- Transformation of coordinates from the output referential to the source referential
- Line conversion and blending
Most of the complexity of the rotation management is avoided by using drm_rect_* helpers. The remaining complexity is around the clipping, to avoid reading/writing outside source/destination buffers.
The pixel conversion is now done line-by-line, so the read_pixel_t was replaced with read_pixel_line_t callback. This way the indirection is only required once per line and per plane, instead of once per pixel and per plane.
The read_line_t callbacks are very similar for most pixel format, but it is required to avoid performance impact. Some helpers were created to avoid code repetition:
- get_step_1x1: get the step in byte to reach next pixel block in a certain direction
- *_to_argb_u16: helpers to perform colors conversion. They should be inlined by the compiler, and they are used to avoid repetition between multiple variants of the same format (argb/xrgb and maybe in the future for formats like bgr formats).
This new algorithm was tested with:
- kms_plane (for color conversions)
- kms_rotation_crc (for rotations of planes)
- kms_cursor_crc (for translations of planes)
The performance gain was mesured with:
- kms_fb_stress
[1]: commit 8ba1648567e2 ("drm: vkms: Refactor the plane composer to accept
new formats")
https://lore.kernel.org/all/[email protected]/
[2]: commit 322d716a3e8a ("drm/vkms: isolate pixel conversion
functionality")
https://lore.kernel.org/all/[email protected]/--- drivers/gpu/drm/vkms/vkms_composer.c | 219 +++++++++++++++++++++++------- drivers/gpu/drm/vkms/vkms_drv.h | 24 +++- drivers/gpu/drm/vkms/vkms_formats.c | 253 ++++++++++++++++++++++------------- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- drivers/gpu/drm/vkms/vkms_plane.c | 8 +- 5 files changed, 349 insertions(+), 157 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +167 -52
@@ -24,9 +24,10 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)/** * pre_mul_alpha_blend - alpha blending equation -* @frame_info: Source framebuffer's metadata * @stage_buffer: The line with the pixels from src_plane * @output_buffer: A line buffer that receives all the blends output +* @x_start: The start offset to avoid useless copy +* @count: The number of byte to copy * * Using the information from the `frame_info`, this blends only the * necessary pixels from the `stage_buffer` to the `output_buffer`
@@ -37,51 +38,23 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)* drm_plane_create_blend_mode_property(). Also, this formula assumes a * completely opaque background. */ -static void pre_mul_alpha_blend (struct vkms_frame_info *frame_info, -struct line_buffer *stage_buffer, -struct line_buffer *output_buffer) +static void pre_mul_alpha_blend ( +struct line_buffer *stage_buffer, +struct line_buffer *output_buffer, +int x_start, +int pixel_count) { -int x_dst = frame_info->dst.x1; -struct pixel_argb_u16 *out = output_buffer->pixels + x_dst; -struct pixel_argb_u16 *in = stage_buffer->pixels; -int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), - stage_buffer->n_pixels); - -for (int x =0 ; x < x_limit; x++) { - out[x].a = (u16 )0xffff ; - out[x].r =pre_mul_blend_channel (in[x].r, out[x].r, in[x].a); - out[x].g =pre_mul_blend_channel (in[x].g, out[x].g, in[x].a); - out[x].b =pre_mul_blend_channel (in[x].b, out[x].b, in[x].a); +struct pixel_argb_u16 *out = &output_buffer->pixels[x_start]; +struct pixel_argb_u16 *in = &stage_buffer->pixels[x_start]; + +for (int i =0 ; i < pixel_count; i++) { + out[i].a = (u16 )0xffff ; + out[i].r =pre_mul_blend_channel (in[i].r, out[i].r, in[i].a); + out[i].g =pre_mul_blend_channel (in[i].g, out[i].g, in[i].a); + out[i].b =pre_mul_blend_channel (in[i].b, out[i].b, in[i].a); } } -static int get_y_pos (struct vkms_frame_info *frame_info,int y) -{ -if (frame_info->rotation &DRM_MODE_REFLECT_Y ) -return drm_rect_height (&frame_info->rotated) - y -1 ; - -switch (frame_info->rotation &DRM_MODE_ROTATE_MASK ) { -case DRM_MODE_ROTATE_90 : -return frame_info->rotated.x2 - y -1 ; -case DRM_MODE_ROTATE_270 : -return y + frame_info->rotated.x1; -default : -return y; - } -} - -static bool check_limit (struct vkms_frame_info *frame_info,int pos) -{ -if (drm_rotation_90_or_270 (frame_info->rotation)) { -if (pos >=0 && pos <drm_rect_width (&frame_info->rotated)) -return true; - }else { -if (pos >= frame_info->rotated.y1 && pos < frame_info->rotated.y2) -return true; - } - -return false; -}static void fill_background (const struct pixel_argb_u16 *background_color,struct line_buffer *output_buffer)
@@ -163,6 +136,37 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +/** +* direction_for_rotation() - Helper to get the correct reading direction for a specific rotation +* +* @rotation: rotation to analyze +*/ +enum pixel_read_direction direction_for_rotation (unsigned int rotation) +{ +if (rotation &DRM_MODE_ROTATE_0 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_LEFT ; +else +return READ_RIGHT ; + }else if (rotation &DRM_MODE_ROTATE_90 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_UP ; +else +return READ_DOWN ; + }else if (rotation &DRM_MODE_ROTATE_180 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_RIGHT ; +else +return READ_LEFT ; + }else if (rotation &DRM_MODE_ROTATE_270 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_DOWN ; +else +return READ_UP ; + } +return READ_RIGHT ; +} +/** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata
@@ -183,11 +187,11 @@ static void blend(struct vkms_writeback_job *wb, {struct vkms_plane_state **plane = crtc_state->active_planes;u32 n_active_planes = crtc_state->num_active_planes; -int y_pos;const struct pixel_argb_u16 background_color = { .a =0xffff };size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; +size_t crtc_x_limit = crtc_state->base.crtc->mode.hdisplay;/* * The planes are composed line-by-line. It is a necessary complexity to avoid poor
@@ -198,22 +202,133 @@ static void blend(struct vkms_writeback_job *wb,/* The active planes are composed associatively in z-order. */ for (size_t i =0 ; i < n_active_planes; i++) { - y_pos =get_y_pos (plane[i]->frame_info, y); +struct vkms_plane_state *current_plane = plane[i]; -if (!check_limit (plane[i]->frame_info, y_pos)) +/* Avoid rendering useless lines */ +if (y < current_plane->frame_info->dst.y1 || + y >= current_plane->frame_info->dst.y2) {continue ; - -vkms_compose_row (stage_buffer, plane[i], y_pos); -pre_mul_alpha_blend (plane[i]->frame_info, stage_buffer, - output_buffer); + } + +/* +* src_px is the line to copy. The initial coordinates are inside the +* destination framebuffer, and then drm_rect_* helpers are used to +* compute the correct position into the source framebuffer. +*/ +struct drm_rect src_px =DRM_RECT_INIT ( + current_plane->frame_info->dst.x1, y, +drm_rect_width (¤t_plane->frame_info->dst),1 ); +struct drm_rect tmp_src; + +drm_rect_fp_to_int (&tmp_src, ¤t_plane->frame_info->src); + +/* +* [1]: Clamping src_px to the crtc_x_limit to avoid writing outside of the +* destination buffer +*/ + src_px.x2 =min_t (int, src_px.x2, (int )crtc_x_limit); + +/* +* Transform the coordinate x/y from the crtc to coordinates into +* coordinates for the src buffer. +* +* - Cancel the offset of the dst buffer. +* - Invert the rotation. This assumes that +* dst = drm_rect_rotate(src, rotation) (dst and src have the +* same size, but can be rotated). +* - Apply the offset of the source rectangle to the coordinate. +*/ +drm_rect_translate (&src_px, -current_plane->frame_info->dst.x1, + -current_plane->frame_info->dst.y1); +drm_rect_rotate_inv (&src_px, +drm_rect_width (&tmp_src), +drm_rect_height (&tmp_src), + current_plane->frame_info->rotation); +drm_rect_translate (&src_px, tmp_src.x1, tmp_src.y1); + +/* Get the correct reading direction in the source buffer. */ + +enum pixel_read_direction direction = +direction_for_rotation (current_plane->frame_info->rotation); + +int x_start = src_px.x1; +int y_start = src_px.y1; +int pixel_count; +/* [2]: Compute and clamp the number of pixel to read */ +if (direction ==READ_RIGHT || direction ==READ_LEFT ) { +/* +* In horizontal reading, the src_px width is the number of pixel to +* read +*/ + pixel_count =drm_rect_width (&src_px); +if (x_start <0 ) { + pixel_count += x_start; + x_start =0 ; + } +if (x_start + pixel_count > current_plane->frame_info->fb->width) { + pixel_count = + (int )current_plane->frame_info->fb->width - x_start; + } + }else { +/* +* In vertical reading, the src_px height is the number of pixel to +* read +*/ + pixel_count =drm_rect_height (&src_px); +if (y_start <0 ) { + pixel_count += y_start; + y_start =0 ; + } +if (y_start + pixel_count > current_plane->frame_info->fb->height) { + pixel_count = + (int )current_plane->frame_info->fb->width - y_start; + } + } + +if (pixel_count <=0 ) { +/* Nothing to read, so avoid multiple function calls for nothing */ +continue ; + } + +/* +* Modify the starting point to take in account the rotation +* +* src_px is the top-left corner, so when reading READ_LEFT or READ_TOP, it +* must be changed to the top-right/bottom-left corner. +*/ +if (direction ==READ_LEFT ) { +// x_start is now the right point + x_start += pixel_count -1 ; + }else if (direction ==READ_UP ) { +// y_start is now the bottom point + y_start += pixel_count -1 ; + } + +/* +* Perform the conversion and the blending +* +* Here we know that the read line (x_start, y_start, pixel_count) is +* inside the source buffer [2] and we don't write outside the stage +* buffer [1] +*/ + current_plane->pixel_read_line ( + current_plane->frame_info, + x_start, + y_start, + direction, + pixel_count, + &stage_buffer->pixels[current_plane->frame_info->dst.x1]); + +pre_mul_alpha_blend (stage_buffer, output_buffer, + current_plane->frame_info->dst.x1, + pixel_count); }apply_lut (crtc_state, output_buffer); *crc32 =crc32_le (*crc32, (void *)output_buffer->pixels, row_size); -if (wb) -vkms_writeback_row (wb, output_buffer, y_pos); +vkms_writeback_row (wb, output_buffer, y); } }
@@ -224,7 +339,7 @@ static int check_format_funcs(struct vkms_crtc_state *crtc_state,u32 n_active_planes = crtc_state->num_active_planes;for (size_t i =0 ; i < n_active_planes; i++) -if (!planes[i]->pixel_read) +if (!planes[i]->pixel_read_line)return -1 ;if (active_wb && !active_wb->pixel_write)
drivers/gpu/drm/vkms/vkms_drv.h +17 -7
@@ -39,7 +39,6 @@struct vkms_frame_info {struct drm_framebuffer *fb;struct drm_rect src, dst; -struct drm_rect rotated;struct iosys_map map[DRM_FORMAT_MAX_PLANES ];unsigned int rotation; };
@@ -69,14 +68,26 @@ struct vkms_writeback_job {pixel_write_t pixel_write; }; +enum pixel_read_direction { +READ_UP , +READ_DOWN , +READ_LEFT , +READ_RIGHT +}; +/** -* typedef pixel_read_t - These functions are used to read a pixel in the source frame, +* typedef pixel_read_line_t - These functions are used to read a pixel line in the source frame, * convert it to `struct pixel_argb_u16` and write it to @out_pixel. * -* @src_pixels: Pointer to the pixel to read -* @out_pixel: Pointer to write the converted pixel +* @frame_info: Frame used as source for the pixel value +* @y: Y (height) coordinate in the source buffer +* @x_start: X (width) coordinate of the first pixel to copy +* @x_end: X (width) coordinate of the last pixel to copy +* @out_pixel: Pointer where to write the pixel value. Pixels will be written between x_start and +* x_end. */ -typedef void (*pixel_read_t )(u8 *src_pixels,struct pixel_argb_u16 *out_pixel); +typedef void (*pixel_read_line_t )(struct vkms_frame_info *frame_info,int x_start,int y_start,enum +pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[]);/** * vkms_plane_state - Driver specific plane state
@@ -88,7 +99,7 @@ typedef void (*pixel_read_t)(u8 *src_pixels, struct pixel_argb_u16 *out_pixel);struct vkms_plane_state {struct drm_shadow_plane_state base;struct vkms_frame_info *frame_info; -pixel_read_t pixel_read; +pixel_read_line_t pixel_read_line; };struct vkms_plane {
@@ -193,7 +204,6 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,/* Composer Support */ void vkms_composer_worker (struct work_struct *work);void vkms_set_composer (struct vkms_output *out,bool enabled); -void vkms_compose_row (struct line_buffer *stage_buffer,struct vkms_plane_state *plane,int y);void vkms_writeback_row (struct vkms_writeback_job *wb,const struct line_buffer *src_buffer,int y);/* Writeback */
drivers/gpu/drm/vkms/vkms_formats.c +161 -92
342 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.h +1 -1
@@ -5,7 +5,7 @@#include "vkms_drv.h" -pixel_read_t get_pixel_read_function (u32 format); +pixel_read_line_t get_pixel_read_line_function (u32 format);pixel_write_t get_pixel_write_function (u32 format);
drivers/gpu/drm/vkms/vkms_plane.c +3 -5
@@ -106,9 +106,9 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,return ; fmt = fb->format->format; -pixel_read_t pixel_read =get_pixel_read_function (fmt); +pixel_read_line_t pixel_read_line =get_pixel_read_line_function (fmt); -if (!pixel_read) { +if (!pixel_read_line) {DRM_WARN ("Pixel format is not supported by VKMS planes. State is inchanged\n" );return ; }
@@ -128,10 +128,8 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y); -drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated), -drm_rect_height (&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read = pixel_read; + vkms_plane_state->pixel_read_line = pixel_read_line; } static int vkms_plane_atomic_check(struct drm_plane *plane,
Signature · 1 line
2.43.0
Re: [PATCH v3 5/9] drm/vkms: Re-introduce line-per-line composition algorithm
Quoted 199 lines · Louis Chauvet
Re-introduce a line-by-line composition algorithm for each pixel format. This allows more performance by not requiring an indirection per pixel read. This patch is focused on readability of the code.
Line-by-line composition was introduced by [1] but rewritten back to pixel-by-pixel algorithm in [2]. At this time, nobody noticed the impact on performance, and it was merged.
This patch is almost a revert of [2], but in addition efforts have been made to increase readability and maintainability of the rotation handling. The blend function is now divided in two parts:
- Transformation of coordinates from the output referential to the source referential
- Line conversion and blendingMost of the complexity of the rotation management is avoided by using drm_rect_* helpers. The remaining complexity is around the clipping, to avoid reading/writing outside source/destination buffers.
The pixel conversion is now done line-by-line, so the
read_pixel_twas replaced withread_pixel_line_tcallback. This way the indirection is only required once per line and per plane, instead of once per pixel and per plane.The
read_line_tcallbacks are very similar for most pixel format, but it is required to avoid performance impact. Some helpers were created to avoid code repetition:
-get_step_1x1: get the step in byte to reach next pixel block in a certain direction
-*_to_argb_u16: helpers to perform colors conversion. They should be inlined by the compiler, and they are used to avoid repetition between multiple variants of the same format (argb/xrgb and maybe in the future for formats like bgr formats).This new algorithm was tested with:
-kms_plane(for color conversions)
-kms_rotation_crc(for rotations of planes)
-kms_cursor_crc(for translations of planes)
The performance gain was mesured with:
-kms_fb_stress[1]: commit
8ba1648567e2("drm: vkms: Refactor the plane composer to acceptnew formats") https://lore.kernel.org/all/[email protected]/ [2]: commit 322d716a3e8a ("drm/vkms: isolate pixel conversion functionality") https://lore.kernel.org/all/[email protected]/Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 219 +++++++++++++++++++++++------- drivers/gpu/drm/vkms/vkms_drv.h | 24 +++- drivers/gpu/drm/vkms/vkms_formats.c | 253 ++++++++++++++++++++++------------- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- drivers/gpu/drm/vkms/vkms_plane.c | 8 +- 5 files changed, 349 insertions(+), 157 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +50
-45@@ -24,9 +24,10 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)/** * pre_mul_alpha_blend - alpha blending equation -* @frame_info: Source framebuffer's metadata * @stage_buffer: The line with the pixels from src_plane * @output_buffer: A line buffer that receives all the blends output +* @x_start: The start offset to avoid useless copy +* @count: The number of byte to copy * * Using the information from the `frame_info`, this blends only the * necessary pixels from the `stage_buffer` to the `output_buffer` @@ -37,51 +38,23 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)* drm_plane_create_blend_mode_property(). Also, this formula assumes a * completely opaque background. */ -static void pre_mul_alpha_blend (struct vkms_frame_info *frame_info, -struct line_buffer *stage_buffer, -struct line_buffer *output_buffer) +static void pre_mul_alpha_blend ( +struct line_buffer *stage_buffer, +struct line_buffer *output_buffer, +int x_start, +int pixel_count) { -int x_dst = frame_info->dst.x1; -struct pixel_argb_u16 *out = output_buffer->pixels + x_dst; -struct pixel_argb_u16 *in = stage_buffer->pixels; -int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), - stage_buffer->n_pixels); - -for (int x =0 ; x < x_limit; x++) { - out[x].a = (u16 )0xffff ; - out[x].r =pre_mul_blend_channel (in[x].r, out[x].r, in[x].a); - out[x].g =pre_mul_blend_channel (in[x].g, out[x].g, in[x].a); - out[x].b =pre_mul_blend_channel (in[x].b, out[x].b, in[x].a); +struct pixel_argb_u16 *out = &output_buffer->pixels[x_start]; +struct pixel_argb_u16 *in = &stage_buffer->pixels[x_start]; + +for (int i =0 ; i < pixel_count; i++) { + out[i].a = (u16 )0xffff ; + out[i].r =pre_mul_blend_channel (in[i].r, out[i].r, in[i].a); + out[i].g =pre_mul_blend_channel (in[i].g, out[i].g, in[i].a); + out[i].b =pre_mul_blend_channel (in[i].b, out[i].b, in[i].a); } } -static int get_y_pos (struct vkms_frame_info *frame_info,int y) -{ -if (frame_info->rotation &DRM_MODE_REFLECT_Y ) -return drm_rect_height (&frame_info->rotated) - y -1 ; - -switch (frame_info->rotation &DRM_MODE_ROTATE_MASK ) { -case DRM_MODE_ROTATE_90 : -return frame_info->rotated.x2 - y -1 ; -case DRM_MODE_ROTATE_270 : -return y + frame_info->rotated.x1; -default : -return y; - } -} - -static bool check_limit (struct vkms_frame_info *frame_info,int pos) -{ -if (drm_rotation_90_or_270 (frame_info->rotation)) { -if (pos >=0 && pos <drm_rect_width (&frame_info->rotated)) -return true; - }else { -if (pos >= frame_info->rotated.y1 && pos < frame_info->rotated.y2) -return true; - } - -return false; -}static void fill_background (const struct pixel_argb_u16 *background_color,struct line_buffer *output_buffer)@@ -163,6 +136,37 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +/** +* direction_for_rotation() - Helper to get the correct reading direction for a specific rotation +* +* @rotation: rotation to analyze +*/ +enum pixel_read_direction direction_for_rotation (unsigned int rotation) +{ +if (rotation &DRM_MODE_ROTATE_0 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_LEFT ; +else +return READ_RIGHT ; + }else if (rotation &DRM_MODE_ROTATE_90 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_UP ; +else +return READ_DOWN ; + }else if (rotation &DRM_MODE_ROTATE_180 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_RIGHT ; +else +return READ_LEFT ; + }else if (rotation &DRM_MODE_ROTATE_270 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_DOWN ; +else +return READ_UP ; + } +return READ_RIGHT ; +} +/** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata @@ -183,11 +187,11 @@ static void blend(struct vkms_writeback_job *wb, {struct vkms_plane_state **plane = crtc_state->active_planes;u32 n_active_planes = crtc_state->num_active_planes; -int y_pos;const struct pixel_argb_u16 background_color = { .a =0xffff };size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; +size_t crtc_x_limit = crtc_state->base.crtc->mode.hdisplay;/* * The planes are composed line-by-line. It is a necessary complexity to avoid poor @@ -198,22 +202,133 @@ static void blend(struct vkms_writeback_job *wb,/* The active planes are composed associatively in z-order. */ for (size_t i =0 ; i < n_active_planes; i++) { - y_pos =get_y_pos (plane[i]->frame_info, y); +struct vkms_plane_state *current_plane = plane[i]; -if (!check_limit (plane[i]->frame_info, y_pos)) +/* Avoid rendering useless lines */ + if (y < current_plane->frame_info->dst.y1 ||
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 214
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_composer.c +5
-4+ y >= current_plane->frame_info->dst.y2) {continue ; - -vkms_compose_row (stage_buffer, plane[i], y_pos); -pre_mul_alpha_blend (plane[i]->frame_info, stage_buffer, - output_buffer); + } + +/* +* src_px is the line to copy. The initial coordinates are inside the
So maybe is better to rename to src_line?
Best Regards,
~Arthur Grillo
Quoted 585 lines
drivers/gpu/drm/vkms/vkms_composer.c +112
-3+* destination framebuffer, and then drm_rect_* helpers are used to +* compute the correct position into the source framebuffer. +*/ +struct drm_rect src_px =DRM_RECT_INIT ( + current_plane->frame_info->dst.x1, y, +drm_rect_width (¤t_plane->frame_info->dst),1 ); +struct drm_rect tmp_src; + +drm_rect_fp_to_int (&tmp_src, ¤t_plane->frame_info->src); + +/* +* [1]: Clamping src_px to the crtc_x_limit to avoid writing outside of the +* destination buffer +*/ + src_px.x2 =min_t (int, src_px.x2, (int )crtc_x_limit); + +/* +* Transform the coordinate x/y from the crtc to coordinates into +* coordinates for the src buffer. +* +* - Cancel the offset of the dst buffer. +* - Invert the rotation. This assumes that +* dst = drm_rect_rotate(src, rotation) (dst and src have the +* same size, but can be rotated). +* - Apply the offset of the source rectangle to the coordinate. +*/ +drm_rect_translate (&src_px, -current_plane->frame_info->dst.x1, + -current_plane->frame_info->dst.y1); +drm_rect_rotate_inv (&src_px, +drm_rect_width (&tmp_src), +drm_rect_height (&tmp_src), + current_plane->frame_info->rotation); +drm_rect_translate (&src_px, tmp_src.x1, tmp_src.y1); + +/* Get the correct reading direction in the source buffer. */ + +enum pixel_read_direction direction = +direction_for_rotation (current_plane->frame_info->rotation); + +int x_start = src_px.x1; +int y_start = src_px.y1; +int pixel_count; +/* [2]: Compute and clamp the number of pixel to read */ +if (direction ==READ_RIGHT || direction ==READ_LEFT ) { +/* +* In horizontal reading, the src_px width is the number of pixel to +* read +*/ + pixel_count =drm_rect_width (&src_px); +if (x_start <0 ) { + pixel_count += x_start; + x_start =0 ; + } +if (x_start + pixel_count > current_plane->frame_info->fb->width) { + pixel_count = + (int )current_plane->frame_info->fb->width - x_start; + } + }else { +/* +* In vertical reading, the src_px height is the number of pixel to +* read +*/ + pixel_count =drm_rect_height (&src_px); +if (y_start <0 ) { + pixel_count += y_start; + y_start =0 ; + } +if (y_start + pixel_count > current_plane->frame_info->fb->height) { + pixel_count = + (int )current_plane->frame_info->fb->width - y_start; + } + } + +if (pixel_count <=0 ) { +/* Nothing to read, so avoid multiple function calls for nothing */ +continue ; + } + +/* +* Modify the starting point to take in account the rotation +* +* src_px is the top-left corner, so when reading READ_LEFT or READ_TOP, it +* must be changed to the top-right/bottom-left corner. +*/ +if (direction ==READ_LEFT ) { +// x_start is now the right point + x_start += pixel_count -1 ; + }else if (direction ==READ_UP ) { +// y_start is now the bottom point + y_start += pixel_count -1 ; + } + +/* +* Perform the conversion and the blending +* +* Here we know that the read line (x_start, y_start, pixel_count) is +* inside the source buffer [2] and we don't write outside the stage +* buffer [1] +*/ + current_plane->pixel_read_line ( + current_plane->frame_info, + x_start, + y_start, + direction, + pixel_count, + &stage_buffer->pixels[current_plane->frame_info->dst.x1]); + +pre_mul_alpha_blend (stage_buffer, output_buffer, + current_plane->frame_info->dst.x1, + pixel_count); }apply_lut (crtc_state, output_buffer); *crc32 =crc32_le (*crc32, (void *)output_buffer->pixels, row_size); -if (wb) -vkms_writeback_row (wb, output_buffer, y_pos); +vkms_writeback_row (wb, output_buffer, y); } }@@ -224,7 +339,7 @@ static int check_format_funcs(struct vkms_crtc_state *crtc_state,u32 n_active_planes = crtc_state->num_active_planes;for (size_t i =0 ; i < n_active_planes; i++) -if (!planes[i]->pixel_read) +if (!planes[i]->pixel_read_line)return -1 ;if (active_wb && !active_wb->pixel_write)drivers/gpu/drm/vkms/vkms_drv.h +17
-7@@ -39,7 +39,6 @@struct vkms_frame_info {struct drm_framebuffer *fb;struct drm_rect src, dst; -struct drm_rect rotated;struct iosys_map map[DRM_FORMAT_MAX_PLANES ];unsigned int rotation; };@@ -69,14 +68,26 @@ struct vkms_writeback_job {pixel_write_t pixel_write; }; +enum pixel_read_direction { +READ_UP , +READ_DOWN , +READ_LEFT , +READ_RIGHT +}; +/** -* typedef pixel_read_t - These functions are used to read a pixel in the source frame, +* typedef pixel_read_line_t - These functions are used to read a pixel line in the source frame, * convert it to `struct pixel_argb_u16` and write it to @out_pixel. * -* @src_pixels: Pointer to the pixel to read -* @out_pixel: Pointer to write the converted pixel +* @frame_info: Frame used as source for the pixel value +* @y: Y (height) coordinate in the source buffer +* @x_start: X (width) coordinate of the first pixel to copy +* @x_end: X (width) coordinate of the last pixel to copy +* @out_pixel: Pointer where to write the pixel value. Pixels will be written between x_start and +* x_end. */ -typedef void (*pixel_read_t )(u8 *src_pixels,struct pixel_argb_u16 *out_pixel); +typedef void (*pixel_read_line_t )(struct vkms_frame_info *frame_info,int x_start,int y_start,enum +pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[]);/** * vkms_plane_state - Driver specific plane state @@ -88,7 +99,7 @@ typedef void (*pixel_read_t)(u8 *src_pixels, struct pixel_argb_u16 *out_pixel);struct vkms_plane_state {struct drm_shadow_plane_state base;struct vkms_frame_info *frame_info; -pixel_read_t pixel_read; +pixel_read_line_t pixel_read_line; };struct vkms_plane {@@ -193,7 +204,6 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,/* Composer Support */ void vkms_composer_worker (struct work_struct *work);void vkms_set_composer (struct vkms_output *out,bool enabled); -void vkms_compose_row (struct line_buffer *stage_buffer,struct vkms_plane_state *plane,int y);void vkms_writeback_row (struct vkms_writeback_job *wb,const struct line_buffer *src_buffer,int y);/* Writeback */ drivers/gpu/drm/vkms/vkms_formats.c +161
-92@@ -11,21 +11,29 @@/** * packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y -* in the first plane * * @frame_info: Buffer metadata * @x: The x coordinate of the wanted pixel in the buffer * @y: The y coordinate of the wanted pixel in the buffer +* @plane_index: The index of the plane to use * * The caller must be aware that this offset is not always a pointer to a pixel. If individual * pixel values are needed, they have to be extracted from the resulting block. */ -static size_t pixel_offset (const struct vkms_frame_info *frame_info,int x,int y) +static size_t packed_pixels_offset (const struct vkms_frame_info *frame_info,int x,int y, +size_t plane_index) {struct drm_framebuffer *fb = frame_info->fb; - -return fb->offsets[0 ] + (y * fb->pitches[0 ]) - + (x * fb->format->cpp[0 ]); +const struct drm_format_info *format = frame_info->fb->format; +/* Directly using x and y to multiply pitches and format->ccp is not sufficient because +* in some formats a block can represent multiple pixels. +* +* Dividing x and y by the block size allows to extract the correct offset of the block +* containing the pixel. +*/ +return fb->offsets[plane_index] + + (y /drm_format_info_block_width (format, plane_index)) * fb->pitches[plane_index] + + (x /drm_format_info_block_height (format, plane_index)) * format->char_per_block[plane_index]; }/** @@ -35,44 +43,56 @@ static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int* @frame_info: Buffer metadata * @x: The x(width) coordinate inside the plane * @y: The y(height) coordinate inside the plane +* @plane_index: The index of the plane * -* Takes the information stored in the frame_info, a pair of coordinates, and -* returns the address of the first color channel. -* This function assumes the channels are packed together, i.e. a color channel -* comes immediately after another in the memory. And therefore, this function -* doesn't work for YUV with chroma subsampling (e.g. YUV420 and NV21). +* Takes the information stored in the frame_info, a pair of coordinates, and returns the address +* of the block containing this pixel. +* The caller must be aware that this pointer is sometimes not directly a pixel, it needs some +* additional work to extract pixel color from this block. */ static void *packed_pixels_addr (const struct vkms_frame_info *frame_info, -int x,int y) +int x,int y,size_t plane_index) { -size_t offset =pixel_offset (frame_info, x, y); - -return (u8 *)frame_info->map[0 ].vaddr + offset; +return (u8 *)frame_info->map[0 ].vaddr +packed_pixels_offset (frame_info, x, y, plane_index); } -static void *get_packed_src_addr (const struct vkms_frame_info *frame_info,int y) +/** +* get_step_1x1() - Common helper to compute the correct step value between each pixel to read in a +* certain direction. +* This must be used only with format where blockh == blockw == 1. +* In the case when direction is not a valid pixel_read_direction, the returned step is 0, so you +* must not rely on this result to create a loop variant. +* +* @fb Framebuffer to iter on +* @direction Direction of the reading +*/ +static int get_step_1x1 (struct drm_framebuffer *fb,enum pixel_read_direction direction, +int plane_index) { -int x_src = frame_info->src.x1 >>16 ; -int y_src = y - frame_info->rotated.y1 + (frame_info->src.y1 >>16 ); - -return packed_pixels_addr (frame_info, x_src, y_src); +switch (direction) { +default : +DRM_ERROR ("Invalid direction for pixel reading: %d\n" , direction); +return 0 ; +case READ_RIGHT : +return fb->format->char_per_block[plane_index]; +case READ_LEFT : +return -fb->format->char_per_block[plane_index]; +case READ_DOWN : +return (int )fb->pitches[plane_index]; +case READ_UP : +return -(int )fb->pitches[plane_index]; + } } -static int get_x_position (const struct vkms_frame_info *frame_info,int limit,int x) -{ -if (frame_info->rotation & (DRM_MODE_REFLECT_X |DRM_MODE_ROTATE_270 )) -return limit - x -1 ; -return x; -}/* -* The following functions take pixel data from the buffer and convert them to the format +* The following functions take pixel data (a, r, g, b, pixel, ...), convert them to the format * ARGB16161616 in out_pixel. * -* They are used in the `vkms_compose_row` function to handle multiple formats. +* They are used in the `read_line`s functions to avoid duplicate work for some pixel formats. */ -static void ARGB8888_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) +static void ARGB8888_to_argb_u16 (struct pixel_argb_u16 *out_pixel,int a,int r,int g,int b) {/* * The 257 is the "conversion ratio". This number is obtained by the @@ -80,48 +100,26 @@ static void ARGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixe* the best color value in a pixel format with more possibilities. * A similar idea applies to others RGB color conversions. */ - out_pixel->a = (u16 )src_pixels[3 ] *257 ; - out_pixel->r = (u16 )src_pixels[2 ] *257 ; - out_pixel->g = (u16 )src_pixels[1 ] *257 ; - out_pixel->b = (u16 )src_pixels[0 ] *257 ; -} - -static void XRGB8888_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) -{ - out_pixel->a = (u16 )0xffff ; - out_pixel->r = (u16 )src_pixels[2 ] *257 ; - out_pixel->g = (u16 )src_pixels[1 ] *257 ; - out_pixel->b = (u16 )src_pixels[0 ] *257 ; + out_pixel->a = (u16 )a *257 ; + out_pixel->r = (u16 )r *257 ; + out_pixel->g = (u16 )g *257 ; + out_pixel->b = (u16 )b *257 ; } -static void ARGB16161616_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) +static void ARGB16161616_to_argb_u16 (struct pixel_argb_u16 *out_pixel,int a,int r,int g,int b) { -u16 *pixels = (u16 *)src_pixels; - - out_pixel->a =le16_to_cpu (pixels[3 ]); - out_pixel->r =le16_to_cpu (pixels[2 ]); - out_pixel->g =le16_to_cpu (pixels[1 ]); - out_pixel->b =le16_to_cpu (pixels[0 ]); -} - -static void XRGB16161616_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) -{ -u16 *pixels = (u16 *)src_pixels; - - out_pixel->a = (u16 )0xffff ; - out_pixel->r =le16_to_cpu (pixels[2 ]); - out_pixel->g =le16_to_cpu (pixels[1 ]); - out_pixel->b =le16_to_cpu (pixels[0 ]); + out_pixel->a =le16_to_cpu (a); + out_pixel->r =le16_to_cpu (r); + out_pixel->g =le16_to_cpu (g); + out_pixel->b =le16_to_cpu (b); } -static void RGB565_to_argb_u16 (u8 *src_pixels,struct pixel_argb_u16 *out_pixel) +static void RGB565_to_argb_u16 (struct pixel_argb_u16 *out_pixel,const u16 *pixel) { -u16 *pixels = (u16 *)src_pixels; -s64 fp_rb_ratio =drm_fixp_div (drm_int2fixp (65535 ),drm_int2fixp (31 ));s64 fp_g_ratio =drm_fixp_div (drm_int2fixp (65535 ),drm_int2fixp (63 )); -u16 rgb_565 =le16_to_cpu (*pixels); +u16 rgb_565 =le16_to_cpu (*pixel);s64 fp_r =drm_int2fixp ((rgb_565 >>11 ) &0x1f );s64 fp_g =drm_int2fixp ((rgb_565 >>5 ) &0x3f );s64 fp_b =drm_int2fixp (rgb_565 &0x1f );@@ -132,34 +130,105 @@ static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel) out_pixel->b =drm_fixp2int_round (drm_fixp_mul (fp_b, fp_rb_ratio)); } -/** -* vkms_compose_row - compose a single row of a plane -* @stage_buffer: output line with the composed pixels -* @plane: state of the plane that is being composed -* @y: y coordinate of the row +/* +* The following functions are read_line function for each pixel format supported by VKMS. * -* This function composes a single row of a plane. It gets the source pixels -* through the y coordinate (see get_packed_src_addr()) and goes linearly -* through the source pixel, reading the pixels and converting it to -* ARGB16161616 (see the pixel_read() callback). For rotate-90 and rotate-270, -* the source pixels are not traversed linearly. The source pixels are queried -* on each iteration in order to traverse the pixels vertically. +* 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. +* +* Those function are very similar, but it is required for performance reason. In the past, some +* experiment were done, and with a generic loop the performance are very reduced [1]. +* +* [1]: https://lore.kernel.org/dri-devel/[email protected]/ */ -void vkms_compose_row (struct line_buffer *stage_buffer,struct vkms_plane_state *plane,int y) + +static void ARGB8888_read_line (struct vkms_frame_info *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +u8 *src_pixels =packed_pixels_addr (frame_info, x_start, y_start,0 ); + +int step =get_step_1x1 (frame_info->fb, direction,0 ); + +while (count) { +u8 *px = (u8 *)src_pixels; + +ARGB8888_to_argb_u16 (out_pixel, px[3 ], px[2 ], px[1 ], px[0 ]); + out_pixel +=1 ; + src_pixels += step; + count--; + } +} + +static void XRGB8888_read_line (struct vkms_frame_info *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +u8 *src_pixels =packed_pixels_addr (frame_info, x_start, y_start,0 ); + +int step =get_step_1x1 (frame_info->fb, direction,0 ); + +while (count) { +u8 *px = (u8 *)src_pixels; + +ARGB8888_to_argb_u16 (out_pixel,255 , px[2 ], px[1 ], px[0 ]); + out_pixel +=1 ; + src_pixels += step; + count--; + } +} + +static void ARGB16161616_read_line (struct vkms_frame_info *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +u8 *src_pixels =packed_pixels_addr (frame_info, x_start, y_start,0 ); + +int step =get_step_1x1 (frame_info->fb, direction,0 ); + +while (count) { +u16 *px = (u16 *)src_pixels; + +ARGB16161616_to_argb_u16 (out_pixel, px[3 ], px[2 ], px[1 ], px[0 ]); + out_pixel +=1 ; + src_pixels += step; + count--; + } +} + +static void XRGB16161616_read_line (struct vkms_frame_info *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) +{ +u8 *src_pixels =packed_pixels_addr (frame_info, x_start, y_start,0 ); + +int step =get_step_1x1 (frame_info->fb, direction,0 ); + +while (count) { +u16 *px = (u16 *)src_pixels; + +ARGB16161616_to_argb_u16 (out_pixel,0xFFFF , px[2 ], px[1 ], px[0 ]); + out_pixel +=1 ; + src_pixels += step; + count--; + } +} + +static void RGB565_read_line (struct vkms_frame_info *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count, +struct pixel_argb_u16 out_pixel[]) { -struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; -struct vkms_frame_info *frame_info = plane->frame_info; -u8 *src_pixels =get_packed_src_addr (frame_info, y); -int limit =min_t (size_t,drm_rect_width (&frame_info->dst), stage_buffer->n_pixels); +u8 *src_pixels =packed_pixels_addr (frame_info, x_start, y_start,0 ); -for (size_t x =0 ; x < limit; x++, src_pixels += frame_info->fb->format->cpp[0 ]) { -int x_pos =get_x_position (frame_info, limit, x); +int step =get_step_1x1 (frame_info->fb, direction,0 ); -if (drm_rotation_90_or_270 (frame_info->rotation)) - src_pixels =get_packed_src_addr (frame_info, x + frame_info->rotated.y1) - + frame_info->fb->format->cpp[0 ] * y; +while (count) { +u16 *px = (u16 *)src_pixels; - plane->pixel_read (src_pixels, &out_pixels[x_pos]); +RGB565_to_argb_u16 (out_pixel, px); + out_pixel +=1 ; + src_pixels += step; + count--; } }@@ -247,7 +316,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, {struct vkms_frame_info *frame_info = &wb->wb_frame_info;int x_dst = frame_info->dst.x1; -u8 *dst_pixels =packed_pixels_addr (frame_info, x_dst, y); +u8 *dst_pixels =packed_pixels_addr (frame_info, x_dst, y,0 );struct pixel_argb_u16 *in_pixels = src_buffer->pixels;int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), src_buffer->n_pixels);@@ -256,27 +325,27 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, }/** -* Retrieve the correct read_pixel function for a specific format. +* Retrieve the correct read_line function for a specific format. * The returned pointer is NULL for unsupported pixel formats. The caller must ensure that the * pointer is valid before using it in a vkms_plane_state. * * @format: 4cc of the format */ -pixel_read_t get_pixel_read_function (u32 format) +pixel_read_line_t get_pixel_read_line_function (u32 format) {switch (format) {case DRM_FORMAT_ARGB8888 : -return &ARGB8888_to_argb_u16; +return &ARGB8888_read_line;case DRM_FORMAT_XRGB8888 : -return &XRGB8888_to_argb_u16; +return &XRGB8888_read_line;case DRM_FORMAT_ARGB16161616 : -return &ARGB16161616_to_argb_u16; +return &ARGB16161616_read_line;case DRM_FORMAT_XRGB16161616 : -return &XRGB16161616_to_argb_u16; +return &XRGB16161616_read_line;case DRM_FORMAT_RGB565 : -return &RGB565_to_argb_u16; +return &RGB565_read_line;default : -return (pixel_read_t )NULL ; +return (pixel_read_line_t )NULL ; } }drivers/gpu/drm/vkms/vkms_formats.h +1
-1@@ -5,7 +5,7 @@#include "vkms_drv.h" -pixel_read_t get_pixel_read_function (u32 format); +pixel_read_line_t get_pixel_read_line_function (u32 format);pixel_write_t get_pixel_write_function (u32 format);drivers/gpu/drm/vkms/vkms_plane.c +3
-5@@ -106,9 +106,9 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,return ; fmt = fb->format->format; -pixel_read_t pixel_read =get_pixel_read_function (fmt); +pixel_read_line_t pixel_read_line =get_pixel_read_line_function (fmt); -if (!pixel_read) { +if (!pixel_read_line) {DRM_WARN ("Pixel format is not supported by VKMS planes. State is inchanged\n" );return ; }@@ -128,10 +128,8 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y); -drm_rect_rotate (&frame_info->rotated,drm_rect_width (&frame_info->rotated), -drm_rect_height (&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read = pixel_read; + vkms_plane_state->pixel_read_line = pixel_read_line; } static int vkms_plane_atomic_check(struct drm_plane *plane,
Louis Chauvet
maintainerRe: [PATCH v3 5/9] drm/vkms: Re-introduce line-per-line composition algorithm
Quoted 199 lines · Arthur Grillo
Quoted 196 lines · Louis Chauvet
Re-introduce a line-by-line composition algorithm for each pixel format. This allows more performance by not requiring an indirection per pixel read. This patch is focused on readability of the code.
Line-by-line composition was introduced by [1] but rewritten back to pixel-by-pixel algorithm in [2]. At this time, nobody noticed the impact on performance, and it was merged.
This patch is almost a revert of [2], but in addition efforts have been made to increase readability and maintainability of the rotation handling. The blend function is now divided in two parts:
- Transformation of coordinates from the output referential to the source referential
- Line conversion and blendingMost of the complexity of the rotation management is avoided by using drm_rect_* helpers. The remaining complexity is around the clipping, to avoid reading/writing outside source/destination buffers.
The pixel conversion is now done line-by-line, so the
read_pixel_twas replaced withread_pixel_line_tcallback. This way the indirection is only required once per line and per plane, instead of once per pixel and per plane.The
read_line_tcallbacks are very similar for most pixel format, but it is required to avoid performance impact. Some helpers were created to avoid code repetition:
-get_step_1x1: get the step in byte to reach next pixel block in a certain direction
-*_to_argb_u16: helpers to perform colors conversion. They should be inlined by the compiler, and they are used to avoid repetition between multiple variants of the same format (argb/xrgb and maybe in the future for formats like bgr formats).This new algorithm was tested with:
-kms_plane(for color conversions)
-kms_rotation_crc(for rotations of planes)
-kms_cursor_crc(for translations of planes)
The performance gain was mesured with:
-kms_fb_stress[1]: commit
8ba1648567e2("drm: vkms: Refactor the plane composer to acceptnew formats") https://lore.kernel.org/all/[email protected]/ [2]: commit 322d716a3e8a ("drm/vkms: isolate pixel conversion functionality") https://lore.kernel.org/all/[email protected]/Signed-off-by Louis Chauvet <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 219 +++++++++++++++++++++++------- drivers/gpu/drm/vkms/vkms_drv.h | 24 +++- drivers/gpu/drm/vkms/vkms_formats.c | 253 ++++++++++++++++++++++------------- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- drivers/gpu/drm/vkms/vkms_plane.c | 8 +- 5 files changed, 349 insertions(+), 157 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +48
-44@@ -24,9 +24,10 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)/** * pre_mul_alpha_blend - alpha blending equation -* @frame_info: Source framebuffer's metadata * @stage_buffer: The line with the pixels from src_plane * @output_buffer: A line buffer that receives all the blends output +* @x_start: The start offset to avoid useless copy +* @count: The number of byte to copy * * Using the information from the `frame_info`, this blends only the * necessary pixels from the `stage_buffer` to the `output_buffer` @@ -37,51 +38,23 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha)* drm_plane_create_blend_mode_property(). Also, this formula assumes a * completely opaque background. */ -static void pre_mul_alpha_blend (struct vkms_frame_info *frame_info, -struct line_buffer *stage_buffer, -struct line_buffer *output_buffer) +static void pre_mul_alpha_blend ( +struct line_buffer *stage_buffer, +struct line_buffer *output_buffer, +int x_start, +int pixel_count) { -int x_dst = frame_info->dst.x1; -struct pixel_argb_u16 *out = output_buffer->pixels + x_dst; -struct pixel_argb_u16 *in = stage_buffer->pixels; -int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), - stage_buffer->n_pixels); - -for (int x =0 ; x < x_limit; x++) { - out[x].a = (u16 )0xffff ; - out[x].r =pre_mul_blend_channel (in[x].r, out[x].r, in[x].a); - out[x].g =pre_mul_blend_channel (in[x].g, out[x].g, in[x].a); - out[x].b =pre_mul_blend_channel (in[x].b, out[x].b, in[x].a); +struct pixel_argb_u16 *out = &output_buffer->pixels[x_start]; +struct pixel_argb_u16 *in = &stage_buffer->pixels[x_start]; + +for (int i =0 ; i < pixel_count; i++) { + out[i].a = (u16 )0xffff ; + out[i].r =pre_mul_blend_channel (in[i].r, out[i].r, in[i].a); + out[i].g =pre_mul_blend_channel (in[i].g, out[i].g, in[i].a); + out[i].b =pre_mul_blend_channel (in[i].b, out[i].b, in[i].a); } } -static int get_y_pos (struct vkms_frame_info *frame_info,int y) -{ -if (frame_info->rotation &DRM_MODE_REFLECT_Y ) -return drm_rect_height (&frame_info->rotated) - y -1 ; - -switch (frame_info->rotation &DRM_MODE_ROTATE_MASK ) { -case DRM_MODE_ROTATE_90 : -return frame_info->rotated.x2 - y -1 ; -case DRM_MODE_ROTATE_270 : -return y + frame_info->rotated.x1; -default : -return y; - } -} - -static bool check_limit (struct vkms_frame_info *frame_info,int pos) -{ -if (drm_rotation_90_or_270 (frame_info->rotation)) { -if (pos >=0 && pos <drm_rect_width (&frame_info->rotated)) -return true; - }else { -if (pos >= frame_info->rotated.y1 && pos < frame_info->rotated.y2) -return true; - } - -return false; -}static void fill_background (const struct pixel_argb_u16 *background_color,struct line_buffer *output_buffer)@@ -163,6 +136,37 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +/** +* direction_for_rotation() - Helper to get the correct reading direction for a specific rotation +* +* @rotation: rotation to analyze +*/ +enum pixel_read_direction direction_for_rotation (unsigned int rotation) +{ +if (rotation &DRM_MODE_ROTATE_0 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_LEFT ; +else +return READ_RIGHT ; + }else if (rotation &DRM_MODE_ROTATE_90 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_UP ; +else +return READ_DOWN ; + }else if (rotation &DRM_MODE_ROTATE_180 ) { +if (rotation &DRM_MODE_REFLECT_X ) +return READ_RIGHT ; +else +return READ_LEFT ; + }else if (rotation &DRM_MODE_ROTATE_270 ) { +if (rotation &DRM_MODE_REFLECT_Y ) +return READ_DOWN ; +else +return READ_UP ; + } +return READ_RIGHT ; +} +/** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata @@ -183,11 +187,11 @@ static void blend(struct vkms_writeback_job *wb, {struct vkms_plane_state **plane = crtc_state->active_planes;u32 n_active_planes = crtc_state->num_active_planes; -int y_pos;const struct pixel_argb_u16 background_color = { .a =0xffff };size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; +size_t crtc_x_limit = crtc_state->base.crtc->mode.hdisplay;/* * The planes are composed line-by-line. It is a necessary complexity to avoid poor @@ -198,22 +202,133 @@ static void blend(struct vkms_writeback_job *wb,/* The active planes are composed associatively in z-order. */ for (size_t i =0 ; i < n_active_planes; i++) { - y_pos =get_y_pos (plane[i]->frame_info, y); +struct vkms_plane_state *current_plane = plane[i];
Quoted 15 lines
drivers/gpu/drm/vkms/vkms_composer.c static void blend(struct vkms_writeback_job *wb, · line 214
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_composer.c +7
-5-if (!check_limit (plane[i]->frame_info, y_pos)) +/* Avoid rendering useless lines */ +if (y < current_plane->frame_info->dst.y1 || + y >= current_plane->frame_info->dst.y2) {continue ; - -vkms_compose_row (stage_buffer, plane[i], y_pos); -pre_mul_alpha_blend (plane[i]->frame_info, stage_buffer, - output_buffer); + } + +/* +* src_px is the line to copy. The initial coordinates are inside the So maybe is better to rename to
src_line?
Good idea!
Kind regards,
Louis Chauvet
[...]
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Louis Chauvet
maintainerPATCH v3 6/9 drm/vkms: Add YUV support
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
Add support to the YUV formats bellow:
- NV12
- NV16
- NV24
- NV21
- NV61
- NV42
- YUV420
- YUV422
- YUV444
- YVU420
- YVU422
- YVU444
The conversion matrices of each encoding and range were obtained by rounding the values of the original conversion matrices multiplied by 2^8. This is done to avoid the use of fixed point operations.
[Louis Chauvet: Adapted Arthur's work and implemented the read_line_t callbacks for yuv formats]
--- drivers/gpu/drm/vkms/vkms_composer.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 6 +- drivers/gpu/drm/vkms/vkms_formats.c | 289 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_formats.h | 4 + drivers/gpu/drm/vkms/vkms_plane.c | 14 +- 5 files changed, 295 insertions(+), 20 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +1 -1
@@ -312,7 +312,7 @@ static void blend(struct vkms_writeback_job *wb,* buffer [1] */ current_plane->pixel_read_line( - current_plane->frame_info, + current_plane, x_start, y_start, direction,
drivers/gpu/drm/vkms/vkms_drv.h +4 -2
@@ -75,6 +75,8 @@ enum pixel_read_direction { READ_RIGHT }; +struct vkms_plane_state ; +/** * typedef pixel_read_line_t - These functions are used to read a pixel line in the source frame, * convert it to `struct pixel_argb_u16` and write it to @out_pixel.
@@ -86,8 +88,8 @@ enum pixel_read_direction {* @out_pixel: Pointer where to write the pixel value. Pixels will be written between x_start and * x_end. */ -typedef void (*pixel_read_line_t )(struct vkms_frame_info *frame_info,int x_start,int y_start,enum -pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[]); +typedef void (*pixel_read_line_t )(struct vkms_plane_state *frame_info,int x_start,int y_start, +enum pixel_read_direction direction,int count,struct pixel_argb_u16 out_pixel[]);/** * vkms_plane_state - Driver specific plane state
drivers/gpu/drm/vkms/vkms_formats.c +273 -16
369 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.h +4 -0
@@ -9,4 +9,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format);pixel_write_t get_pixel_write_function (u32 format); +struct pixel_yuv_u8 { +u8 y, u, v; +}; +#endif /* _VKMS_FORMATS_H_ */
drivers/gpu/drm/vkms/vkms_plane.c +13 -1
@@ -17,7 +17,19 @@ static const u32 vkms_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_XRGB16161616 ,DRM_FORMAT_ARGB16161616 , -DRM_FORMAT_RGB565 +DRM_FORMAT_RGB565 , +DRM_FORMAT_NV12 , +DRM_FORMAT_NV16 , +DRM_FORMAT_NV24 , +DRM_FORMAT_NV21 , +DRM_FORMAT_NV61 , +DRM_FORMAT_NV42 , +DRM_FORMAT_YUV420 , +DRM_FORMAT_YUV422 , +DRM_FORMAT_YUV444 , +DRM_FORMAT_YVU420 , +DRM_FORMAT_YVU422 , +DRM_FORMAT_YVU444 }; static struct drm_plane_state *
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v3 7/9 drm/vkms: Add range and encoding properties to pixel_read function
In reply to Louis ChauvetFrom: Arthur Grillo <[email protected]>
Create range and encoding properties. This should be noop, as none of the conversion functions need those properties.
--- drivers/gpu/drm/vkms/vkms_plane.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/vkms/vkms_plane.c +9 -0
@@ -228,5 +228,14 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,drm_plane_create_rotation_property (&plane->base,DRM_MODE_ROTATE_0 ,DRM_MODE_ROTATE_MASK |DRM_MODE_REFLECT_MASK ); +drm_plane_create_color_properties (&plane->base, +BIT (DRM_COLOR_YCBCR_BT601 ) | +BIT (DRM_COLOR_YCBCR_BT709 ) | +BIT (DRM_COLOR_YCBCR_BT2020 ), +BIT (DRM_COLOR_YCBCR_LIMITED_RANGE ) | +BIT (DRM_COLOR_YCBCR_FULL_RANGE ), +DRM_COLOR_YCBCR_BT601 , +DRM_COLOR_YCBCR_FULL_RANGE ); +return plane; }
Signature · 1 line
2.43.0
Louis Chauvet
maintainerPATCH v3 8/9 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 v3 9/9 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.
--- 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 | 155 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.c | 9 +- drivers/gpu/drm/vkms/vkms_formats.h | 5 + 6 files changed, 175 insertions(+), 2 deletions(-)
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 +155 -0
155 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.c +7 -2
@@ -7,6 +7,8 @@#include <drm/drm_rect.h> #include <drm/drm_fixed.h> +#include <kunit/visibility.h> +#include "vkms_formats.h" /**
@@ -175,8 +177,10 @@ static void ycbcr2rgb(const s16 m[3][3], u8 y, u8 cb, u8 cr, u8 y_offset, u8 *r, *b =clamp (b_16,0 ,0xffff ) >>8 ; } -static void yuv_u8_to_argb_u16 (struct pixel_argb_u16 *argb_u16,const struct pixel_yuv_u8 *yuv_u8, -enum drm_color_encoding encoding,enum drm_color_range range) +VISIBLE_IF_KUNIT void yuv_u8_to_argb_u16(struct pixel_argb_u16 *argb_u16, +const struct pixel_yuv_u8 *yuv_u8, +enum drm_color_encoding encoding, +enum drm_color_range range) {static const s16 bt601_full[3 ][3 ] = { {256 ,0 ,359 },
@@ -237,6 +241,7 @@ static void yuv_u8_to_argb_u16(struct pixel_argb_u16 *argb_u16, const struct pix argb_u16->g = g *257 ; argb_u16->b = b *257 ; } +EXPORT_SYMBOL_IF_KUNIT (yuv_u8_to_argb_u16);/* * The following functions are read_line function for each pixel format supported by VKMS.
drivers/gpu/drm/vkms/vkms_formats.h +5 -0
@@ -13,4 +13,9 @@ struct pixel_yuv_u8 { u8 y, u, v; }; +#if IS_ENABLED (CONFIG_KUNIT ) +void yuv_u8_to_argb_u16 (struct pixel_argb_u16 *argb_u16,const struct pixel_yuv_u8 *yuv_u8, +enum drm_color_encoding encoding,enum drm_color_range range); +#endif +#endif /* _VKMS_FORMATS_H_ */
Signature · 1 line
2.43.0
Quoted 10 lines · On Mon, 26 Feb 2024 09:46:30 +0100 Louis Chauvet <[email protected]>…
This patchset is the second version of [1]. It is almost a complete rewrite to use a line-by-line algorithm for the composition. It can be divided in three parts:
- PATCH 1 to 4: no functional change is intended, only some formatting and documenting
(PATCH 2 is taken from [2])
- PATCH 5: main patch for this series, it reintroduce the line-by-line algorithm
- PATCH 6 to 9: taken from Arthur's series [2], with sometimes adaptation to use the pixel-by-pixel algorithm.
Hi Louis,
I'll skip v3 because I was still reviewing v2 while you posted this. I'm done on v2 now.
Thanks,
pq