Add new formats support to vkms
v7 cover Add new formats support to vkms
Summary
=======
This series of patches refactor some vkms components in order to introduce new formats to the planes and writeback connector.
Now in the blend function, the plane's pixels are converted to ARGB16161616 and then blended together.
The CRC is calculated based on the ARGB1616161616 buffer. And if required, this buffer is copied/converted to the writeback buffer format.
And to handle the pixel conversion, new functions were added to convert from a specific format to ARGB16161616 (the reciprocal is also true).
Tests
=====
This patch series was tested using the following igt tests:
-t ".*kms_plane.*"
-t ".*kms_writeback.*"
-t ".*kms_cursor_crc*"
-t ".*kms_flip.*"
New tests passing
-------------------
- pipe-A-cursor-size-change
- pipe-A-cursor-alpha-transparent
Performance
-----------
It's running slightly faster than the current implementation.
Results running the IGT[1] test igt@kms_cursor_crc@pipe-a-cursor-512x512-onscreen ten times:
| Frametime | |:--------------------------------------------:| | Implementation | Current | This commit | |:---------------:|:---------:|:--------------:| | frametime range | 9~22 ms | 10~22 ms | | Average | 11.4 ms | 12.32 ms |
Memory consumption
==================
It consumes less memory than the current implementation in the common case (more detail in the commit message).
| Memory consumption (output dimensions) | |:--------------------------------------:| | Current | This patch | |:------------------:|:-----------------:| | Width * Heigth | 2 * Width |
[1] IGT commit id: bc3f6833a12221a46659535dac06ebb312490eb4
XRGB to ARGB behavior
=====================
During the development, I decided to always fill the alpha channel of the output pixel whenever the conversion from a format without an alpha channel to ARGB16161616 is necessary. Therefore, I ignore the value received from the XRGB and overwrite the value with 0xFFFF.
Primary plane and CRTC size
===========================
This patch series reworks the blend function to accept a primary plane with a different size and position from CRTC.
Because now we need to fill the background, we had a loss in performance with this change
Alpha channel output for XRGB formats
=====================================
There's still an open question about which value the writeback alpha channel should be for XRGB formats.
The current igt test implementation is expecting the channel to not be change. But it's not entirely clear if this should be the behavior followed by vkms (or any other driver).
Open issue: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues/118
---
Igor Torrente (9):
drm: vkms: Replace hardcoded value of vkms_composer.map to
DRM_FORMAT_MAX_PLANES
drm: vkms: Rename vkms_composer to vkms_frame_info
drm: drm_atomic_helper: Add a new helper to deal with the writeback
connector validation
drm: vkms: get the reference to drm_framebuffer instead if coping it
drm: vkms: Add fb information to vkms_writeback_job
drm: vkms: Refactor the plane composer to accept new formats
drm: vkms: Supports to the case where primary plane doesn't match the
CRTC
drm: vkms: Adds XRGB_16161616 and ARGB_1616161616 formats
drm: vkms: Add support to the RGB565 format
Documentation/gpu/vkms.rst | 7 +- drivers/gpu/drm/drm_atomic_helper.c | 39 ++++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 314 ++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 33 ++- drivers/gpu/drm/vkms/vkms_formats.c | 302 +++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 50 ++-- drivers/gpu/drm/vkms/vkms_writeback.c | 39 +++- include/drm/drm_atomic_helper.h | 3 + 10 files changed, 580 insertions(+), 220 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_formats.c create mode 100644 drivers/gpu/drm/vkms/vkms_formats.h
Signature · 1 line
2.30.2
PATCH v7 1/9 drm: vkms: Replace hardcoded value of `vkms_composer.map` to DRM_FORMAT_MAX_PLANES
The map vector at vkms_composer uses a hardcoded value to define its size.
If someday the maximum number of planes increases, this hardcoded value can be a problem.
This value is being replaced with the DRM_FORMAT_MAX_PLANES macro.
--- drivers/gpu/drm/vkms/vkms_drv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
@@ -31,7 +31,7 @@ struct vkms_writeback_job {struct vkms_composer {struct drm_framebuffer fb;struct drm_rect src, dst; -struct iosys_map map[4 ]; +struct iosys_map map[DRM_FORMAT_MAX_PLANES ];unsigned int offset;unsigned int pitch;unsigned int cpp;
Signature · 1 line
2.30.2
PATCH v7 2/9 drm: vkms: Rename `vkms_composer` to `vkms_frame_info`
In reply to Igor TorrenteChanges the name of this struct to a more meaningful name. A name that represents better what this struct is about.
Composer is the code that do the compositing of the planes. This struct contains information on the frame used in the output composition. Thus, vkms_frame_info is a better name to represent this.
V5: Fix a commit message typo(Melissa Wen).
V6: Fix wrong iosys_map_is_null verification at compose_plane
(Melissa Wen).
--- drivers/gpu/drm/vkms/vkms_composer.c | 87 ++++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 6 +- drivers/gpu/drm/vkms/vkms_plane.c | 38 ++++++------ 3 files changed, 66 insertions(+), 65 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +44 -43
@@ -11,11 +11,11 @@#include "vkms_drv.h" static u32 get_pixel_from_buffer (int x,int y,const u8 *buffer, -const struct vkms_composer *composer) +const struct vkms_frame_info *frame_info) {u32 pixel; -int src_offset = composer->offset + (y * composer->pitch) - + (x * composer->cpp); +int src_offset = frame_info->offset + (y * frame_info->pitch) + + (x * frame_info->cpp); pixel = *(u32 *)&buffer[src_offset];
@@ -26,24 +26,24 @@ static u32 get_pixel_from_buffer(int x, int y, const u8 *buffer,* compute_crc - Compute CRC value on output frame * * @vaddr: address to final framebuffer -* @composer: framebuffer's metadata +* @frame_info: framebuffer's metadata * * returns CRC value computed using crc32 on the visible portion of * the final framebuffer at vaddr_out */ static uint32_t compute_crc (const u8 *vaddr, -const struct vkms_composer *composer) +const struct vkms_frame_info *frame_info) {int x, y;u32 crc =0 , pixel =0 ; -int x_src = composer->src.x1 >>16 ; -int y_src = composer->src.y1 >>16 ; -int h_src =drm_rect_height (&composer->src) >>16 ; -int w_src =drm_rect_width (&composer->src) >>16 ; +int x_src = frame_info->src.x1 >>16 ; +int y_src = frame_info->src.y1 >>16 ; +int h_src =drm_rect_height (&frame_info->src) >>16 ; +int w_src =drm_rect_width (&frame_info->src) >>16 ;for (y = y_src; y < y_src + h_src; ++y) {for (x = x_src; x < x_src + w_src; ++x) { - pixel =get_pixel_from_buffer (x, y, vaddr, composer); + pixel =get_pixel_from_buffer (x, y, vaddr, frame_info); crc =crc32_le (crc, (void *)&pixel,sizeof (u32)); } }
@@ -98,8 +98,8 @@ static void x_blend(const u8 *xrgb_src, u8 *xrgb_dst)* blend - blend value at vaddr_src with value at vaddr_dst * @vaddr_dst: destination address * @vaddr_src: source address -* @dst_composer: destination framebuffer's metadata -* @src_composer: source framebuffer's metadata +* @dst_frame_info: destination framebuffer's metadata +* @src_frame_info: source framebuffer's metadata * @pixel_blend: blending equation based on plane format * * Blend the vaddr_src value with the vaddr_dst value using a pixel blend
@@ -111,33 +111,33 @@ static void x_blend(const u8 *xrgb_src, u8 *xrgb_dst)* pixel color values */ static void blend (void *vaddr_dst,void *vaddr_src, -struct vkms_composer *dst_composer, -struct vkms_composer *src_composer, +struct vkms_frame_info *dst_frame_info, +struct vkms_frame_info *src_frame_info,void (*pixel_blend)(const u8 *,u8 *)) {int i, j, j_dst, i_dst;int offset_src, offset_dst;u8 *pixel_dst, *pixel_src; -int x_src = src_composer->src.x1 >>16 ; -int y_src = src_composer->src.y1 >>16 ; +int x_src = src_frame_info->src.x1 >>16 ; +int y_src = src_frame_info->src.y1 >>16 ; -int x_dst = src_composer->dst.x1; -int y_dst = src_composer->dst.y1; -int h_dst =drm_rect_height (&src_composer->dst); -int w_dst =drm_rect_width (&src_composer->dst); +int x_dst = src_frame_info->dst.x1; +int y_dst = src_frame_info->dst.y1; +int h_dst =drm_rect_height (&src_frame_info->dst); +int w_dst =drm_rect_width (&src_frame_info->dst);int y_limit = y_src + h_dst;int x_limit = x_src + w_dst;for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {for (j = x_src, j_dst = x_dst; j < x_limit; ++j) { - offset_dst = dst_composer->offset - + (i_dst * dst_composer->pitch) - + (j_dst++ * dst_composer->cpp); - offset_src = src_composer->offset - + (i * src_composer->pitch) - + (j * src_composer->cpp); + offset_dst = dst_frame_info->offset + + (i_dst * dst_frame_info->pitch) + + (j_dst++ * dst_frame_info->cpp); + offset_src = src_frame_info->offset + + (i * src_frame_info->pitch) + + (j * src_frame_info->cpp); pixel_src = (u8 *)(vaddr_src + offset_src); pixel_dst = (u8 *)(vaddr_dst + offset_dst);
@@ -149,32 +149,33 @@ static void blend(void *vaddr_dst, void *vaddr_src, } } -static void compose_plane (struct vkms_composer *primary_composer, -struct vkms_composer *plane_composer, +static void compose_plane (struct vkms_frame_info *primary_plane_info, +struct vkms_frame_info *plane_frame_info,void *vaddr_out) { -struct drm_framebuffer *fb = &plane_composer->fb; +struct drm_framebuffer *fb = &plane_frame_info->fb;void *vaddr;void (*pixel_blend)(const u8 *p_src,u8 *p_dst); -if (WARN_ON (iosys_map_is_null (&plane_composer->map[0 ]))) +if (WARN_ON (iosys_map_is_null (&plane_frame_info->map[0 ])))return ; - vaddr = plane_composer->map[0 ].vaddr; + vaddr = plane_frame_info->map[0 ].vaddr;if (fb->format->format ==DRM_FORMAT_ARGB8888 ) pixel_blend = &alpha_blend;else pixel_blend = &x_blend; -blend (vaddr_out, vaddr, primary_composer, plane_composer, pixel_blend); +blend (vaddr_out, vaddr, primary_plane_info, + plane_frame_info, pixel_blend); }static int compose_active_planes (void **vaddr_out, -struct vkms_composer *primary_composer, +struct vkms_frame_info *primary_plane_info,struct vkms_crtc_state *crtc_state) { -struct drm_framebuffer *fb = &primary_composer->fb; +struct drm_framebuffer *fb = &primary_plane_info->fb;struct drm_gem_object *gem_obj =drm_gem_fb_get_obj (fb,0 );const void *vaddr;int i;
@@ -187,10 +188,10 @@ static int compose_active_planes(void **vaddr_out, } } -if (WARN_ON (iosys_map_is_null (&primary_composer->map[0 ]))) +if (WARN_ON (iosys_map_is_null (&primary_plane_info->map[0 ])))return -EINVAL ; - vaddr = primary_composer->map[0 ].vaddr; + vaddr = primary_plane_info->map[0 ].vaddr;memcpy (*vaddr_out, vaddr, gem_obj->size);
@@ -199,8 +200,8 @@ static int compose_active_planes(void **vaddr_out,* ((primary <- overlay) <- cursor) */ for (i =1 ; i < crtc_state->num_active_planes; i++) -compose_plane (primary_composer, - crtc_state->active_planes[i]->composer, +compose_plane (primary_plane_info, + crtc_state->active_planes[i]->frame_info, *vaddr_out);return 0 ;
@@ -222,7 +223,7 @@ void vkms_composer_worker(struct work_struct *work) composer_work);struct drm_crtc *crtc = crtc_state->base.crtc;struct vkms_output *out =drm_crtc_to_vkms_output (crtc); -struct vkms_composer *primary_composer =NULL ; +struct vkms_frame_info *primary_plane_info =NULL ;struct vkms_plane_state *act_plane =NULL ;bool crc_pending, wb_pending;void *vaddr_out =NULL ;
@@ -250,16 +251,16 @@ void vkms_composer_worker(struct work_struct *work)if (crtc_state->num_active_planes >=1 ) { act_plane = crtc_state->active_planes[0 ];if (act_plane->base.base.plane->type ==DRM_PLANE_TYPE_PRIMARY ) - primary_composer = act_plane->composer; + primary_plane_info = act_plane->frame_info; } -if (!primary_composer) +if (!primary_plane_info)return ;if (wb_pending) vaddr_out = crtc_state->active_writeback->data[0 ].vaddr; - ret =compose_active_planes (&vaddr_out, primary_composer, + ret =compose_active_planes (&vaddr_out, primary_plane_info, crtc_state);if (ret) {if (ret == -EINVAL && !wb_pending)
@@ -267,7 +268,7 @@ void vkms_composer_worker(struct work_struct *work)return ; } - crc32 =compute_crc (vaddr_out, primary_composer); + crc32 =compute_crc (vaddr_out, primary_plane_info);if (wb_pending) {drm_writeback_signal_completion (&out->wb_connector,0 );
drivers/gpu/drm/vkms/vkms_drv.h +3 -3
@@ -28,7 +28,7 @@ struct vkms_writeback_job {struct iosys_map data[DRM_FORMAT_MAX_PLANES ]; }; -struct vkms_composer { +struct vkms_frame_info {struct drm_framebuffer fb;struct drm_rect src, dst;struct iosys_map map[DRM_FORMAT_MAX_PLANES ];
@@ -40,11 +40,11 @@ struct vkms_composer {/** * vkms_plane_state - Driver specific plane state * @base: base plane state -* @composer: data required for composing computation +* @frame_info: data required for composing computation */ struct vkms_plane_state {struct drm_shadow_plane_state base; -struct vkms_composer *composer; +struct vkms_frame_info *frame_info; };struct vkms_plane {
drivers/gpu/drm/vkms/vkms_plane.c +19 -19
@@ -23,20 +23,20 @@ static struct drm_plane_state * vkms_plane_duplicate_state(struct drm_plane *plane) {struct vkms_plane_state *vkms_state; -struct vkms_composer *composer; +struct vkms_frame_info *frame_info; vkms_state =kzalloc (sizeof (*vkms_state),GFP_KERNEL );if (!vkms_state)return NULL ; - composer =kzalloc (sizeof (*composer),GFP_KERNEL ); -if (!composer) { -DRM_DEBUG_KMS ("Couldn't allocate composer\n" ); + frame_info =kzalloc (sizeof (*frame_info),GFP_KERNEL ); +if (!frame_info) { +DRM_DEBUG_KMS ("Couldn't allocate frame_info\n" );kfree (vkms_state);return NULL ; } - vkms_state->composer = composer; + vkms_state->frame_info = frame_info;__drm_gem_duplicate_shadow_plane_state (plane, &vkms_state->base);
@@ -53,12 +53,12 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,/* dropping the reference we acquired in * vkms_primary_plane_update() */ -if (drm_framebuffer_read_refcount (&vkms_state->composer->fb)) -drm_framebuffer_put (&vkms_state->composer->fb); +if (drm_framebuffer_read_refcount (&vkms_state->frame_info->fb)) +drm_framebuffer_put (&vkms_state->frame_info->fb); } -kfree (vkms_state->composer); - vkms_state->composer =NULL ; +kfree (vkms_state->frame_info); + vkms_state->frame_info =NULL ;__drm_gem_destroy_shadow_plane_state (&vkms_state->base);kfree (vkms_state);
@@ -98,7 +98,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,struct vkms_plane_state *vkms_plane_state;struct drm_shadow_plane_state *shadow_plane_state;struct drm_framebuffer *fb = new_state->fb; -struct vkms_composer *composer; +struct vkms_frame_info *frame_info;if (!new_state->crtc || !fb)return ;
@@ -106,15 +106,15 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, vkms_plane_state =to_vkms_plane_state (new_state); shadow_plane_state = &vkms_plane_state->base; - composer = vkms_plane_state->composer; -memcpy (&composer->src, &new_state->src,sizeof (struct drm_rect )); -memcpy (&composer->dst, &new_state->dst,sizeof (struct drm_rect )); -memcpy (&composer->fb, fb,sizeof (struct drm_framebuffer )); -memcpy (&composer->map, &shadow_plane_state->data,sizeof (composer->map)); -drm_framebuffer_get (&composer->fb); - composer->offset = fb->offsets[0 ]; - composer->pitch = fb->pitches[0 ]; - composer->cpp = fb->format->cpp[0 ]; + 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->fb, fb,sizeof (struct drm_framebuffer )); +memcpy (&frame_info->map, &shadow_plane_state->data,sizeof (frame_info->map)); +drm_framebuffer_get (&frame_info->fb); + frame_info->offset = fb->offsets[0 ]; + frame_info->pitch = fb->pitches[0 ]; + frame_info->cpp = fb->format->cpp[0 ]; } static int vkms_plane_atomic_check(struct drm_plane *plane,
Signature · 1 line
2.30.2
PATCH v7 3/9 drm: drm_atomic_helper: Add a new helper to deal with the writeback connector validation
In reply to Igor TorrenteAdd a helper function to validate the connector configuration received in the encoder atomic_check by the drivers.
So the drivers don't need to do these common validations themselves.
V2: Move the format verification to a new helper at the drm_atomic_helper.c
(Thomas Zimmermann).
V3: Format check improvements (Leandro Ribeiro).
Minor improvements(Thomas Zimmermann).
V5: Fix some grammar issues in the commit message (André Almeida).
--- drivers/gpu/drm/drm_atomic_helper.c | 39 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_writeback.c | 9 +++---- include/drm/drm_atomic_helper.h | 3 +++ 3 files changed, 46 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +39 -0
@@ -785,6 +785,45 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, }EXPORT_SYMBOL (drm_atomic_helper_check_modeset); +/** +* drm_atomic_helper_check_wb_connector_state() - Check writeback encoder state +* @encoder: encoder state to check +* @conn_state: connector state to check +* +* Checks if the writeback connector state is valid, and returns an error if it +* isn't. +* +* RETURNS: +* Zero for success or -errno +*/ +int +drm_atomic_helper_check_wb_encoder_state (struct drm_encoder *encoder, +struct drm_connector_state *conn_state) +{ +struct drm_writeback_job *wb_job = conn_state->writeback_job; +struct drm_property_blob *pixel_format_blob; +struct drm_framebuffer *fb; +size_t i, nformats; +u32 *formats; + +if (!wb_job || !wb_job->fb) +return 0 ; + + pixel_format_blob = wb_job->connector->pixel_formats_blob_ptr; + nformats = pixel_format_blob->length /sizeof (u32); + formats = pixel_format_blob->data; + fb = wb_job->fb; + +for (i =0 ; i < nformats; i++) +if (fb->format->format == formats[i]) +return 0 ; + +drm_dbg_kms (encoder->dev,"Invalid pixel format %p4cc\n" , &fb->format->format); + +return -EINVAL ; +} +EXPORT_SYMBOL (drm_atomic_helper_check_wb_encoder_state); +/** * drm_atomic_helper_check_plane_state() - Check plane state for validity * @plane_state: plane state to check
drivers/gpu/drm/vkms/vkms_writeback.c +4 -5
@@ -31,6 +31,7 @@ static int vkms_wb_encoder_atomic_check(struct drm_encoder *encoder, {struct drm_framebuffer *fb;const struct drm_display_mode *mode = &crtc_state->mode; +int ret;if (!conn_state->writeback_job || !conn_state->writeback_job->fb)return 0 ;
@@ -42,11 +43,9 @@ static int vkms_wb_encoder_atomic_check(struct drm_encoder *encoder,return -EINVAL ; } -if (fb->format->format != vkms_wb_formats[0 ]) { -DRM_DEBUG_KMS ("Invalid pixel format %p4cc\n" , - &fb->format->format); -return -EINVAL ; - } + ret =drm_atomic_helper_check_wb_encoder_state (encoder, conn_state); +if (ret <0 ) +return ret;return 0 ; }
include/drm/drm_atomic_helper.h +3 -0
@@ -49,6 +49,9 @@ struct drm_private_state;int drm_atomic_helper_check_modeset (struct drm_device *dev,struct drm_atomic_state *state); +int +drm_atomic_helper_check_wb_encoder_state (struct drm_encoder *encoder, +struct drm_connector_state *conn_state); int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, const struct drm_crtc_state *crtc_state, int min_scale,
Signature · 1 line
2.30.2
PATCH v7 4/9 drm: vkms: get the reference to `drm_framebuffer` instead if coping it
In reply to Igor TorrenteInstead of coping drm_framebuffer - which can cause problems - we just get the reference and add the ref count.
--- drivers/gpu/drm/vkms/vkms_composer.c | 4 ++-- drivers/gpu/drm/vkms/vkms_drv.h | 2 +- drivers/gpu/drm/vkms/vkms_plane.c | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +2 -2
@@ -153,7 +153,7 @@ static void compose_plane(struct vkms_frame_info *primary_plane_info,struct vkms_frame_info *plane_frame_info, void *vaddr_out) { - struct drm_framebuffer *fb = &plane_frame_info->fb; + struct drm_framebuffer *fb = plane_frame_info->fb;void *vaddr;void (*pixel_blend)(const u8 *p_src,u8 *p_dst);
@@ -175,7 +175,7 @@ static int compose_active_planes(void **vaddr_out,struct vkms_frame_info *primary_plane_info, struct vkms_crtc_state *crtc_state) { - struct drm_framebuffer *fb = &primary_plane_info->fb; + struct drm_framebuffer *fb = primary_plane_info->fb;struct drm_gem_object *gem_obj =drm_gem_fb_get_obj (fb,0 );const void *vaddr;int i;
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
@@ -29,7 +29,7 @@ struct vkms_writeback_job { };struct vkms_frame_info { -struct drm_framebuffer fb; +struct drm_framebuffer *fb;struct drm_rect src, dst;struct iosys_map map[DRM_FORMAT_MAX_PLANES ];unsigned int offset;
drivers/gpu/drm/vkms/vkms_plane.c +5 -5
@@ -49,12 +49,12 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,struct vkms_plane_state *vkms_state =to_vkms_plane_state (old_state);struct drm_crtc *crtc = vkms_state->base.base.crtc; -if (crtc) { +if (crtc && vkms_state->frame_info->fb) {/* dropping the reference we acquired in * vkms_primary_plane_update() */ -if (drm_framebuffer_read_refcount (&vkms_state->frame_info->fb)) -drm_framebuffer_put (&vkms_state->frame_info->fb); +if (drm_framebuffer_read_refcount (vkms_state->frame_info->fb)) +drm_framebuffer_put (vkms_state->frame_info->fb); }kfree (vkms_state->frame_info);
@@ -109,9 +109,9 @@ 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->fb, fb,sizeof (struct drm_framebuffer )); + frame_info->fb = fb;memcpy (&frame_info->map, &shadow_plane_state->data,sizeof (frame_info->map)); -drm_framebuffer_get (&frame_info->fb); +drm_framebuffer_get (frame_info->fb); frame_info->offset = fb->offsets[0 ]; frame_info->pitch = fb->pitches[0 ]; frame_info->cpp = fb->format->cpp[0 ];
Signature · 1 line
2.30.2
PATCH v7 5/9 drm: vkms: Add fb information to `vkms_writeback_job`
In reply to Igor TorrenteThis commit is the groundwork to introduce new formats to the planes and writeback buffer. As part of it, a new buffer metadata field is added to vkms_writeback_job, this metadata is represented by the vkms_frame_info struct.
Also adds two new function pointers (line_to_frame_func and frame_to_line_func) are defined to handle format conversion from/to internal format.
A new internal format(struct pixel_argb_u16) is introduced to deal with all possible inputs. It consists of 16 bits fields that represent each of the channels.
These things will allow us, in the future, to have different compositing and wb format types.
V2: Change the code to get the drm_framebuffer reference and not copy its
contents (Thomas Zimmermann).
V3: Drop the refcount in the wb code (Thomas Zimmermann).
V5: Add {wb,plane}_format_transform_func to vkms_writeback_job
and vkms_plane_state (Pekka Paalanen)
V6: Improvements to some struct/struct members names (Pekka Paalanen).
Splits this patch in two (Pekka Paalanen).
V7: Replace line_to_frame_func and frame_to_line_func typedefs
with the function signature and void* (Melissa Wen).
--- drivers/gpu/drm/vkms/vkms_drv.h | 23 ++++++++++++++++++----- drivers/gpu/drm/vkms/vkms_writeback.c | 20 +++++++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.h +18 -5
@@ -23,11 +23,6 @@#define NUM_OVERLAY_PLANES 8 -struct vkms_writeback_job { -struct iosys_map map[DRM_FORMAT_MAX_PLANES ]; -struct iosys_map data[DRM_FORMAT_MAX_PLANES ]; -}; -struct vkms_frame_info {struct drm_framebuffer *fb;struct drm_rect src, dst;
@@ -37,6 +32,22 @@ struct vkms_frame_info {unsigned int cpp; }; +struct pixel_argb_u16 { +u16 a, r, g, b; +}; + +struct line_buffer { +size_t n_pixels; +struct pixel_argb_u16 *pixels; +}; + +struct vkms_writeback_job { +struct iosys_map data[DRM_FORMAT_MAX_PLANES ]; +struct vkms_frame_info wb_frame_info; +void (*wb_write)(struct vkms_frame_info *frame_info, +const struct line_buffer *buffer,int y); +}; +/** * vkms_plane_state - Driver specific plane state * @base: base plane state
@@ -45,6 +56,8 @@ struct vkms_frame_info {struct vkms_plane_state {struct drm_shadow_plane_state base;struct vkms_frame_info *frame_info; +void (*plane_read)(struct line_buffer *buffer, +const struct vkms_frame_info *frame_info,int y); };struct vkms_plane {
drivers/gpu/drm/vkms/vkms_writeback.c +17 -3
@@ -75,12 +75,15 @@ static int vkms_wb_prepare_job(struct drm_writeback_connector *wb_connector,if (!vkmsjob)return -ENOMEM ; - ret =drm_gem_fb_vmap (job->fb, vkmsjob->map, vkmsjob->data); + ret =drm_gem_fb_vmap (job->fb, vkmsjob->wb_frame_info.map, vkmsjob->data);if (ret) {DRM_ERROR ("vmap failed: %d\n" , ret); goto err_kfree; } + vkmsjob->wb_frame_info.fb = job->fb; +drm_framebuffer_get (vkmsjob->wb_frame_info.fb); + job->priv = vkmsjob;return 0 ;
@@ -99,7 +102,9 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,if (!job->fb)return ; -drm_gem_fb_vunmap (job->fb, vkmsjob->map); +drm_gem_fb_vunmap (job->fb, vkmsjob->wb_frame_info.map); + +drm_framebuffer_put (vkmsjob->wb_frame_info.fb); vkmsdev =drm_device_to_vkms_device (job->fb->dev);vkms_set_composer (&vkmsdev->output, false);
@@ -116,14 +121,23 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,struct drm_writeback_connector *wb_conn = &output->wb_connector;struct drm_connector_state *conn_state = wb_conn->base.state;struct vkms_crtc_state *crtc_state = output->composer_state; +struct drm_framebuffer *fb = connector_state->writeback_job->fb; +struct vkms_writeback_job *active_wb; +struct vkms_frame_info *wb_frame_info;if (!conn_state)return ;vkms_set_composer (&vkmsdev->output, true); + active_wb = conn_state->writeback_job->priv; + wb_frame_info = &active_wb->wb_frame_info; +spin_lock_irq (&output->composer_lock); - crtc_state->active_writeback = conn_state->writeback_job->priv; + crtc_state->active_writeback = active_wb; + wb_frame_info->offset = fb->offsets[0 ]; + wb_frame_info->pitch = fb->pitches[0 ]; + wb_frame_info->cpp = fb->format->cpp[0 ]; crtc_state->wb_pending = true;spin_unlock_irq (&output->composer_lock);drm_writeback_queue_job (wb_conn, connector_state);
Signature · 1 line
2.30.2
PATCH v7 6/9 drm: vkms: Refactor the plane composer to accept new formats
In reply to Igor TorrenteCurrently the blend function only accepts XRGB_8888 and ARGB_8888 as a color input.
This patch refactors all the functions related to the plane composition to overcome this limitation.
The pixels blend is done using the new internal format. And new handlers are being added to convert a specific format to/from this internal format.
So the blend operation depends on these handlers to convert to this common format. The blended result, if necessary, is converted to the writeback buffer format.
This patch introduces three major differences to the blend function. 1 - All the planes are blended at once.
2 - The blend calculus is done as per line instead of per pixel. 3 - It is responsible to calculates the CRC and writing the writeback buffer(if necessary).
These changes allow us to allocate way less memory in the intermediate buffer to compute these operations. Because now we don't need to have the entire intermediate image lines at once, just one line is enough.
| Memory consumption (output dimensions) | |:--------------------------------------:| | Current | This patch | |:------------------:|:-----------------:| | Width * Heigth | 2 * Width |
Beyond memory, we also have a minor performance benefit from all these changes. Results running the IGT[1] test igt@kms_cursor_crc@pipe-a-cursor-512x512-onscreen ten times:
| Frametime | |:------------------------------------------:| | Implementation | Current | This commit | |:---------------:|:---------:|:------------:| | frametime range | 9~22 ms | 5~17 ms | | Average | 11.4 ms | 7.8 ms |
[1] IGT commit id: bc3f6833a12221a46659535dac06ebb312490eb4
V2: Improves the performance drastically, by performing the operations
per-line and not per-pixel(Pekka Paalanen).
Minor improvements(Pekka Paalanen).
V3: Changes the code to blend the planes all at once. This improves
performance, memory consumption, and removes much of the weirdness of the V2(Pekka Paalanen and me).
Minor improvements(Pekka Paalanen and me).
V4: Rebase the code and adapt it to the new NUM_OVERLAY_PLANES constant.
V5: Minor checkpatch fixes and the removal of TO-DO item(Melissa Wen).
Several security/robustness improvents(Pekka Paalanen). Removes check_planes_x_bounds function and allows partial partly off-screen(Pekka Paalanen).
V6: Fix a mismatch of some variable sizes (Pekka Paalanen).
Several minor improvements (Pekka Paalanen).
--- Documentation/gpu/vkms.rst | 4 - drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 322 ++++++++++++-------------- drivers/gpu/drm/vkms/vkms_formats.c | 155 +++++++++++++ drivers/gpu/drm/vkms/vkms_formats.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 3 + drivers/gpu/drm/vkms/vkms_writeback.c | 3 + 7 files changed, 318 insertions(+), 182 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_formats.c create mode 100644 drivers/gpu/drm/vkms/vkms_formats.h
Documentation/gpu/vkms.rst +0 -4
@@ -118,10 +118,6 @@ Add Plane Features There's lots of plane features we could add support for: -- Clearing primary plane: clear primary plane before plane composition (at the - start) for correctness of pixel blend ops. It also guarantees alpha channel - is cleared in the target buffer for stable crc. [Good to get started] - - ARGB format on primary plane: blend the primary plane into background with translucent alpha.
drivers/gpu/drm/vkms/Makefile +1 -0
@@ -3,6 +3,7 @@ vkms-y := \ vkms_drv.o \ vkms_plane.o \ vkms_output.o \ + vkms_formats.o \ vkms_crtc.o \ vkms_composer.o \ vkms_writeback.o
drivers/gpu/drm/vkms/vkms_composer.c +144 -178
396 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.c new file +155 -0
155 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_formats.h new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#ifndef _VKMS_FORMATS_H_ +#define _VKMS_FORMATS_H_ + +#include "vkms_drv.h" + +void *get_frame_to_line_function (u32 format); + +void *get_line_to_frame_function (u32 format); + +#endif /* _VKMS_FORMATS_H_ */
drivers/gpu/drm/vkms/vkms_plane.c +3 -0
@@ -9,6 +9,7 @@#include <drm/drm_gem_framebuffer_helper.h> #include "vkms_drv.h" +#include "vkms_formats.h" static const u32 vkms_formats[] = {DRM_FORMAT_XRGB8888 ,
@@ -99,6 +100,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane,struct drm_shadow_plane_state *shadow_plane_state;struct drm_framebuffer *fb = new_state->fb;struct vkms_frame_info *frame_info; +u32 fmt = fb->format->format;if (!new_state->crtc || !fb)return ;
@@ -115,6 +117,7 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, frame_info->offset = fb->offsets[0 ]; frame_info->pitch = fb->pitches[0 ]; frame_info->cpp = fb->format->cpp[0 ]; + vkms_plane_state->plane_read =get_frame_to_line_function (fmt); } static int vkms_plane_atomic_check(struct drm_plane *plane,
drivers/gpu/drm/vkms/vkms_writeback.c +3 -0
@@ -12,6 +12,7 @@#include <drm/drm_gem_shmem_helper.h> #include "vkms_drv.h" +#include "vkms_formats.h" static const u32 vkms_wb_formats[] = {DRM_FORMAT_XRGB8888 ,
@@ -124,6 +125,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,struct drm_framebuffer *fb = connector_state->writeback_job->fb;struct vkms_writeback_job *active_wb;struct vkms_frame_info *wb_frame_info; +u32 wb_format = fb->format->format;if (!conn_state)return ;
@@ -141,6 +143,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->wb_write =get_line_to_frame_function (wb_format); }static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
Signature · 1 line
2.30.2
PATCH v7 7/9 drm: vkms: Supports to the case where primary plane doesn't match the CRTC
In reply to Igor TorrenteWe will remove the current assumption that the primary plane has the same size and position as CRTC and that the primary plane is the bottom-most in zpos order, or is even enabled. At least as far as the blending machinery is concerned.
For that we will add CRTC dimension information to vkms_crtc_state and add a opaque black backgound color.
Because now we need to fill the background, we had a loss in performance with this change. Results running the IGT[1] test igt@kms_cursor_crc@pipe-a-cursor-512x512-onscreen ten times:
| Frametime | |:--------------------------------------------:| | Implementation | Previous | This commit | |:---------------:|:---------:|:--------------:| | frametime range | 5~18 ms | 10~22 ms | | Average | 8.47 ms | 12.32 ms |
[1] IGT commit id: bc3f6833a12221a46659535dac06ebb312490eb4
V6: Improve the commit description (Pekka Paalanen).
Update some comments (Pekka Paalanen).
Remove some fields from vkms_crtc_state and move where some variables are set (Pekka Paalanen).
--- Documentation/gpu/vkms.rst | 3 +- drivers/gpu/drm/vkms/vkms_composer.c | 59 +++++++++++++-------------- drivers/gpu/drm/vkms/vkms_writeback.c | 4 ++ 3 files changed, 33 insertions(+), 33 deletions(-)
Documentation/gpu/vkms.rst +1 -2
@@ -121,8 +121,7 @@ There's lots of plane features we could add support for: - ARGB format on primary plane: blend the primary plane into background with translucent alpha. -- Support when the primary plane isn't exactly matching the output size: blend - the primary plane into the black background. +- Add background color KMS property[Good to get started]. - Full alpha blending on all planes.
drivers/gpu/drm/vkms/vkms_composer.c +28 -31
104 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_writeback.c +4 -0
@@ -123,6 +123,8 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,struct drm_connector_state *conn_state = wb_conn->base.state;struct vkms_crtc_state *crtc_state = output->composer_state;struct drm_framebuffer *fb = connector_state->writeback_job->fb; +u16 crtc_height = crtc_state->base.crtc->mode.vdisplay; +u16 crtc_width = crtc_state->base.crtc->mode.hdisplay;struct vkms_writeback_job *active_wb;struct vkms_frame_info *wb_frame_info;u32 wb_format = fb->format->format;
@@ -144,6 +146,8 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,spin_unlock_irq (&output->composer_lock);drm_writeback_queue_job (wb_conn, connector_state); active_wb->wb_write =get_line_to_frame_function (wb_format); +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); }static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
Signature · 1 line
2.30.2
PATCH v7 8/9 drm: vkms: Adds XRGB_16161616 and ARGB_1616161616 formats
In reply to Igor TorrenteThis will be useful to write tests that depends on these formats.
ARGB and XRGB follows the a similar implementation of the former formats. Just adjusting for 16 bits per channel.
V3: Adapt the handlers to the new format introduced in patch 7 V3.
V5: Minor improvements
Added le16_to_cpu/cpu_to_le16 to the 16 bits color read/writes.
--- drivers/gpu/drm/vkms/vkms_formats.c | 77 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 5 +- drivers/gpu/drm/vkms/vkms_writeback.c | 2 + 3 files changed, 83 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_formats.c +77 -0
@@ -78,6 +78,41 @@ static void XRGB8888_to_argb_u16(struct line_buffer *stage_buffer, } } +static void ARGB16161616_to_argb_u16 (struct line_buffer *stage_buffer, +const struct vkms_frame_info *frame_info, +int y) +{ +struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; +u16 *src_pixels =get_packed_src_addr (frame_info, y); +int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), + stage_buffer->n_pixels); + +for (size_t x =0 ; x < x_limit; x++, src_pixels +=4 ) { + out_pixels[x].a =le16_to_cpu (src_pixels[3 ]); + out_pixels[x].r =le16_to_cpu (src_pixels[2 ]); + out_pixels[x].g =le16_to_cpu (src_pixels[1 ]); + out_pixels[x].b =le16_to_cpu (src_pixels[0 ]); + } +} + +static void XRGB16161616_to_argb_u16 (struct line_buffer *stage_buffer, +const struct vkms_frame_info *frame_info, +int y) +{ +struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; +u16 *src_pixels =get_packed_src_addr (frame_info, y); +int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), + stage_buffer->n_pixels); + +for (size_t x =0 ; x < x_limit; x++, src_pixels +=4 ) { + out_pixels[x].a = (u16 )0xffff ; + out_pixels[x].r =le16_to_cpu (src_pixels[2 ]); + out_pixels[x].g =le16_to_cpu (src_pixels[1 ]); + out_pixels[x].b =le16_to_cpu (src_pixels[0 ]); + } +} + +/* * 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
@@ -130,6 +165,40 @@ static void argb_u16_to_XRGB8888(struct vkms_frame_info *frame_info, } } +static void argb_u16_to_ARGB16161616 (struct vkms_frame_info *frame_info, +const struct line_buffer *src_buffer,int y) +{ +int x_dst = frame_info->dst.x1; +u16 *dst_pixels =packed_pixels_addr (frame_info, x_dst, y); +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 +=4 ) { + dst_pixels[3 ] =cpu_to_le16 (in_pixels[x].a); + dst_pixels[2 ] =cpu_to_le16 (in_pixels[x].r); + dst_pixels[1 ] =cpu_to_le16 (in_pixels[x].g); + dst_pixels[0 ] =cpu_to_le16 (in_pixels[x].b); + } +} + +static void argb_u16_to_XRGB16161616 (struct vkms_frame_info *frame_info, +const struct line_buffer *src_buffer,int y) +{ +int x_dst = frame_info->dst.x1; +u16 *dst_pixels =packed_pixels_addr (frame_info, x_dst, y); +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 +=4 ) { + dst_pixels[3 ] =0xffff ; + dst_pixels[2 ] =cpu_to_le16 (in_pixels[x].r); + dst_pixels[1 ] =cpu_to_le16 (in_pixels[x].g); + dst_pixels[0 ] =cpu_to_le16 (in_pixels[x].b); + } +} +void *get_frame_to_line_function (u32 format) {switch (format) {
@@ -137,6 +206,10 @@ void *get_frame_to_line_function(u32 format)return &ARGB8888_to_argb_u16;case DRM_FORMAT_XRGB8888 :return &XRGB8888_to_argb_u16; +case DRM_FORMAT_ARGB16161616 : +return &ARGB16161616_to_argb_u16; +case DRM_FORMAT_XRGB16161616 : +return &XRGB16161616_to_argb_u16;default :return NULL ; }
@@ -149,6 +222,10 @@ void *get_line_to_frame_function(u32 format)return &argb_u16_to_ARGB8888;case DRM_FORMAT_XRGB8888 :return &argb_u16_to_XRGB8888; +case DRM_FORMAT_ARGB16161616 : +return &argb_u16_to_ARGB16161616; +case DRM_FORMAT_XRGB16161616 : +return &argb_u16_to_XRGB16161616;default :return NULL ; }
drivers/gpu/drm/vkms/vkms_plane.c +4 -1
@@ -13,11 +13,14 @@static const u32 vkms_formats[] = {DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB16161616 };static const u32 vkms_plane_formats[] = {DRM_FORMAT_ARGB8888 , -DRM_FORMAT_XRGB8888 +DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB16161616 , +DRM_FORMAT_ARGB16161616 }; static struct drm_plane_state *
drivers/gpu/drm/vkms/vkms_writeback.c +2 -0
@@ -16,6 +16,8 @@static const u32 vkms_wb_formats[] = {DRM_FORMAT_XRGB8888 , +DRM_FORMAT_XRGB16161616 , +DRM_FORMAT_ARGB16161616 };static const struct drm_connector_funcs vkms_wb_connector_funcs = {
Signature · 1 line
2.30.2
PATCH v7 9/9 drm: vkms: Add support to the RGB565 format
In reply to Igor TorrenteThis commit also adds new helper macros to deal with fixed-point arithmetic.
It was done to improve the precision of the conversion to ARGB16161616 since the "conversion ratio" is not an integer.
V3: Adapt the handlers to the new format introduced in patch 7 V3.
V5: Minor improvements
V6: Minor improvements (Pekka Paalanen)
--- drivers/gpu/drm/vkms/vkms_formats.c | 70 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 6 ++- drivers/gpu/drm/vkms/vkms_writeback.c | 3 +- 3 files changed, 76 insertions(+), 3 deletions(-)
drivers/gpu/drm/vkms/vkms_formats.c +70 -0
@@ -5,6 +5,23 @@#include "vkms_formats.h" +/* The following macros help doing fixed point arithmetic. */ +/* +* With Fixed-Point scale 15 we have 17 and 15 bits of integer and fractional +* parts respectively. +* | 0000 0000 0000 0000 0.000 0000 0000 0000 | +* 31 0 +*/ +#define SHIFT 15 + +#define INT_TO_FIXED (a) ((a) << SHIFT) +#define FIXED_MUL (a, b) ((s32)(((s64)(a) * (b)) >> SHIFT)) +#define FIXED_DIV (a, b) ((s32)(((s64)(a) << SHIFT) / (b))) +/* This macro converts a fixed point number to int, and round half up it */ +#define FIXED_TO_INT_ROUND (a) (((a) + (1 << (SHIFT - 1))) >> SHIFT) +#define INT_TO_FIXED_DIV (a, b) (FIXED_DIV(INT_TO_FIXED(a), INT_TO_FIXED(b))) +#define INT_TO_FIXED_DIV (a, b) (FIXED_DIV(INT_TO_FIXED(a), INT_TO_FIXED(b))) +static size_t pixel_offset (const struct vkms_frame_info *frame_info,int x,int y) {return frame_info->offset + (y * frame_info->pitch)
@@ -112,6 +129,30 @@ static void XRGB16161616_to_argb_u16(struct line_buffer *stage_buffer, } } +static void RGB565_to_argb_u16 (struct line_buffer *stage_buffer, +const struct vkms_frame_info *frame_info,int y) +{ +struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; +u16 *src_pixels =get_packed_src_addr (frame_info, y); +int x_limit =min_t (size_t,drm_rect_width (&frame_info->dst), + stage_buffer->n_pixels); + +s32 fp_rb_ratio =INT_TO_FIXED_DIV (65535 ,31 ); +s32 fp_g_ratio =INT_TO_FIXED_DIV (65535 ,63 ); + +for (size_t x =0 ; x < x_limit; x++, src_pixels++) { +u16 rgb_565 =le16_to_cpu (*src_pixels); +s32 fp_r =INT_TO_FIXED ((rgb_565 >>11 ) &0x1f ); +s32 fp_g =INT_TO_FIXED ((rgb_565 >>5 ) &0x3f ); +s32 fp_b =INT_TO_FIXED (rgb_565 &0x1f ); + + out_pixels[x].a = (u16 )0xffff ; + out_pixels[x].r =FIXED_TO_INT_ROUND (FIXED_MUL (fp_r, fp_rb_ratio)); + out_pixels[x].g =FIXED_TO_INT_ROUND (FIXED_MUL (fp_g, fp_g_ratio)); + out_pixels[x].b =FIXED_TO_INT_ROUND (FIXED_MUL (fp_b, fp_rb_ratio)); + } +} +/* * The following functions take an line of argb_u16 pixels from the
@@ -199,6 +240,31 @@ static void argb_u16_to_XRGB16161616(struct vkms_frame_info *frame_info, } } +static void argb_u16_to_RGB565 (struct vkms_frame_info *frame_info, +const struct line_buffer *src_buffer,int y) +{ +int x_dst = frame_info->dst.x1; +u16 *dst_pixels =packed_pixels_addr (frame_info, x_dst, y); +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); + +s32 fp_rb_ratio =INT_TO_FIXED_DIV (65535 ,31 ); +s32 fp_g_ratio =INT_TO_FIXED_DIV (65535 ,63 ); + +for (size_t x =0 ; x < x_limit; x++, dst_pixels++) { +s32 fp_r =INT_TO_FIXED (in_pixels[x].r); +s32 fp_g =INT_TO_FIXED (in_pixels[x].g); +s32 fp_b =INT_TO_FIXED (in_pixels[x].b); + +u16 r =FIXED_TO_INT_ROUND (FIXED_DIV (fp_r, fp_rb_ratio)); +u16 g =FIXED_TO_INT_ROUND (FIXED_DIV (fp_g, fp_g_ratio)); +u16 b =FIXED_TO_INT_ROUND (FIXED_DIV (fp_b, fp_rb_ratio)); + + *dst_pixels =cpu_to_le16 (r <<11 | g <<5 | b); + } +} +void *get_frame_to_line_function (u32 format) {switch (format) {
@@ -210,6 +276,8 @@ void *get_frame_to_line_function(u32 format)return &ARGB16161616_to_argb_u16;case DRM_FORMAT_XRGB16161616 :return &XRGB16161616_to_argb_u16; +case DRM_FORMAT_RGB565 : +return &RGB565_to_argb_u16;default :return NULL ; }
@@ -226,6 +294,8 @@ void *get_line_to_frame_function(u32 format)return &argb_u16_to_ARGB16161616;case DRM_FORMAT_XRGB16161616 :return &argb_u16_to_XRGB16161616; +case DRM_FORMAT_RGB565 : +return &argb_u16_to_RGB565;default :return NULL ; }
drivers/gpu/drm/vkms/vkms_plane.c +4 -2
@@ -13,14 +13,16 @@static const u32 vkms_formats[] = {DRM_FORMAT_XRGB8888 , -DRM_FORMAT_XRGB16161616 +DRM_FORMAT_XRGB16161616 , +DRM_FORMAT_RGB565 };static const u32 vkms_plane_formats[] = {DRM_FORMAT_ARGB8888 ,DRM_FORMAT_XRGB8888 ,DRM_FORMAT_XRGB16161616 , -DRM_FORMAT_ARGB16161616 +DRM_FORMAT_ARGB16161616 , +DRM_FORMAT_RGB565 }; static struct drm_plane_state *
drivers/gpu/drm/vkms/vkms_writeback.c +2 -1
@@ -17,7 +17,8 @@static const u32 vkms_wb_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_XRGB16161616 , -DRM_FORMAT_ARGB16161616 +DRM_FORMAT_ARGB16161616 , +DRM_FORMAT_RGB565 };static const struct drm_connector_funcs vkms_wb_connector_funcs = {
Signature · 1 line
2.30.2
Quoted 5 lines · Igor Torrente
Summary
=======
This series of patches refactor some vkms components in order to introduce new formats to the planes and writeback connector.
Quoted 9 lines
Now in the blend function, the plane's pixels are converted to ARGB16161616 and then blended together.
The CRC is calculated based on the ARGB1616161616 buffer. And if required, this buffer is copied/converted to the writeback buffer format.
And to handle the pixel conversion, new functions were added to convert from a specific format to ARGB16161616 (the reciprocal is also true).
Hi Igor,
Thanks for this great work!
I just applied to drm-misc-next (I did some minor code-style fixes when applying too).
Best Regards,
Melissa
Quoted 95 lines
Tests
=====
This patch series was tested using the following igt tests:(quoted diff) +0
-4-t ".*kms_plane.*" -t ".*kms_writeback.*" -t ".*kms_cursor_crc*" -t ".*kms_flip.*"New tests passing
-------------------
- pipe-A-cursor-size-change
- pipe-A-cursor-alpha-transparentPerformance
-----------
It's running slightly faster than the current implementation.Results running the IGT[1] test
igt@kms_cursor_crc@pipe-a-cursor-512x512-onscreenten times:| Frametime | |:--------------------------------------------:| | Implementation | Current | This commit | |:---------------:|:---------:|:--------------:| | frametime range | 9~22 ms | 10~22 ms | | Average | 11.4 ms | 12.32 ms |Memory consumption
==================
It consumes less memory than the current implementation in the common case (more detail in the commit message).| Memory consumption (output dimensions) | |:--------------------------------------:| | Current | This patch | |:------------------:|:-----------------:| | Width * Heigth | 2 * Width |[1] IGT commit id:
bc3f6833a12221a46659535dac06ebb312490eb4XRGB to ARGB behavior
=====================
During the development, I decided to always fill the alpha channel of the output pixel whenever the conversion from a format without an alpha channel to ARGB16161616 is necessary. Therefore, I ignore the value received from the XRGB and overwrite the value with0xFFFF.Primary plane and CRTC size
===========================
This patch series reworks the blend function to accept a primary plane with a different size and position from CRTC.
Because now we need to fill the background, we had a loss in performance with this changeAlpha channel output for XRGB formats
=====================================
There's still an open question about which value the writeback alpha channel should be for XRGB formats.
The current igt test implementation is expecting the channel to not be change. But it's not entirely clear if this should be the behavior followed by vkms (or any other driver).Open issue: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues/118
---
Igor Torrente (9):
drm: vkms: Replace hardcoded value ofvkms_composer.mapto
DRM_FORMAT_MAX_PLANES
drm: vkms: Renamevkms_composertovkms_frame_info
drm:drm_atomic_helper: Add a new helper to deal with the writeback
connector validation
drm: vkms: get the reference todrm_framebufferinstead if coping it
drm: vkms: Add fb information tovkms_writeback_job
drm: vkms: Refactor the plane composer to accept new formats
drm: vkms: Supports to the case where primary plane doesn't match the
CRTC
drm: vkms: AddsXRGB_16161616andARGB_1616161616formats
drm: vkms: Add support to the RGB565 formatDocumentation/gpu/vkms.rst | 7 +- drivers/gpu/drm/drm_atomic_helper.c | 39 ++++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 314 ++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 33 ++- drivers/gpu/drm/vkms/vkms_formats.c | 302 +++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_formats.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 50 ++-- drivers/gpu/drm/vkms/vkms_writeback.c | 39 +++- include/drm/drm_atomic_helper.h | 3 + 10 files changed, 580 insertions(+), 220 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_formats.c create mode 100644 drivers/gpu/drm/vkms/vkms_formats.hSignature · 1 line
2.30.2