When no CRC is armed and both sides use the same 32-bit format, copy the frame straight into the writeback buffer.
Signed-off-by: Oarora Etimis <[email protected]> --- drivers/gpu/drm/vkms/vkms_composer.c | 63 ++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 5 +++ drivers/gpu/drm/vkms/vkms_formats.c | 26 +++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 4e2dd568bc3e..7ecd8b459ed2 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -581,6 +581,49 @@ static bool compose_direct(const struct vkms_crtc_state *crtc_state) return true; } +/** + * writeback_direct() - Can the frame skip the line buffer? + * @crtc_state: the state to compose + * @wb: the writeback job, or NULL + * + * True when nothing needs 16-bit pixels: no CRC, no LUT, no colour pipeline, + * same 32-bit format on both sides. + * + * Returns: true if the frame can be copied straight into the writeback buffer. + */ +static bool writeback_direct(const struct vkms_crtc_state *crtc_state, + const struct vkms_writeback_job *wb, + const struct vkms_plane_state *plane) +{ + const struct vkms_output *output; + const struct drm_format_info *format; + + if (!wb) + return false; + + /* The CRC is computed over the 16-bit line buffer. */ + output = drm_crtc_to_vkms_output(crtc_state->base.crtc); + if (READ_ONCE(output->crc_enabled)) + return false; + + /* The gamma LUT is applied to the 16-bit line buffer. */ + if (crtc_state->gamma_lut.y) + return false; + + /* The copy walks source rows, so the plane cannot be rotated. */ + if (plane->frame_info.rotation != DRM_MODE_ROTATE_0) + return false; + + if (plane->frame_info.src.x1 || plane->frame_info.src.y1) + return false; + + format = plane->frame_info.fb->format; + if (format != wb->wb_frame_info.fb->format) + return false; + + return format->cpp[0] == 4; +} + /** * blend - blend the pixels from all planes and compute crc * @wb: The writeback frame buffer metadata @@ -597,7 +640,8 @@ static bool compose_direct(const struct vkms_crtc_state *crtc_state) static void blend(struct vkms_writeback_job *wb, struct vkms_crtc_state *crtc_state, u32 *crc32, struct line_buffer *stage_buffer, - struct line_buffer *output_buffer, size_t row_size) + struct line_buffer *output_buffer, size_t row_size, + bool direct) { struct vkms_plane_state **plane = crtc_state->active_planes; u32 n_active_planes = crtc_state->num_active_planes; @@ -612,7 +656,6 @@ static void blend(struct vkms_writeback_job *wb, int crtc_y_limit = crtc_state->base.mode.vdisplay; int crtc_x_limit = crtc_state->base.mode.hdisplay; - bool direct = compose_direct(crtc_state); /* * The planes are composed line-by-line to avoid heavy memory usage. It is a necessary @@ -674,6 +717,7 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb, { size_t line_width, pixel_size = sizeof(struct pixel_argb_u16); struct line_buffer output_buffer, stage_buffer; + bool direct; int ret = 0; /* @@ -690,6 +734,15 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb, if (WARN_ON(check_format_funcs(crtc_state, active_wb))) return -EINVAL; + direct = compose_direct(crtc_state); + + if (direct && writeback_direct(crtc_state, active_wb, crtc_state->active_planes[0])) { + for (int y = 0; y < crtc_state->base.mode.vdisplay; y++) + vkms_writeback_row_direct(active_wb, crtc_state->active_planes[0], y); + + return 0; + } + line_width = crtc_state->base.mode.hdisplay; stage_buffer.n_pixels = line_width; output_buffer.n_pixels = line_width; @@ -708,7 +761,7 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb, } blend(active_wb, crtc_state, crc32, &stage_buffer, - &output_buffer, line_width * pixel_size); + &output_buffer, line_width * pixel_size, direct); kvfree(output_buffer.pixels); free_stage_buffer: @@ -858,6 +911,10 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) ret = vkms_crc_parse_source(src_name, &enabled); + spin_lock_irq(&out->lock); + WRITE_ONCE(out->crc_enabled, enabled); + spin_unlock_irq(&out->lock); + vkms_set_composer(out, enabled); return ret; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index b7eb7033fb4b..69f12cecd2f9 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -220,6 +220,8 @@ struct vkms_crtc_state { * @lock: Lock used to protect concurrent access to the composer * @composer_enabled: Protected by @lock, true when the VKMS composer is active (crc needed or * writeback) + * @crc_enabled: true while the CRC source is enabled. Written under @lock, read with + * READ_ONCE() from the composer worker * @composer_state: Protected by @lock, current state of this VKMS output * @composer_lock: Lock used internally to protect @composer_state members */ @@ -231,6 +233,7 @@ struct vkms_output { spinlock_t lock; bool composer_enabled; + bool crc_enabled; struct vkms_crtc_state *composer_state; spinlock_t composer_lock; @@ -325,6 +328,8 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, void vkms_composer_worker(struct work_struct *work); void vkms_set_composer(struct vkms_output *out, bool enabled); void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y); +void vkms_writeback_row_direct(struct vkms_writeback_job *wb, + const struct vkms_plane_state *plane, int y); /* Writeback */ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_output *vkms_out); diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index 7f1f29b589e8..8bbd517092a5 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include <linux/kernel.h> +#include <linux/unaligned.h> #include <linux/minmax.h> #include <drm/drm_blend.h> @@ -681,6 +682,31 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, wb->pixel_write(dst_pixels, &in_pixels[x]); } +/** + * vkms_writeback_row_direct() - Copy a composed line into the writeback buffer + * @wb: the writeback job + * @plane: the plane the line comes from + * @y: line to write + * + * Only used when writeback_direct() returned true. + */ +void vkms_writeback_row_direct(struct vkms_writeback_job *wb, + const struct vkms_plane_state *plane, int y) +{ + const struct vkms_frame_info *src_info = &plane->frame_info; + struct vkms_frame_info *dst_info = &wb->wb_frame_info; + u8 *src_pixels, *dst_pixels; + int rem_x, rem_y; + int x_limit = drm_rect_width(&dst_info->dst); + + packed_pixels_addr(src_info, src_info->dst.x1, y, 0, &src_pixels, &rem_x, &rem_y); + packed_pixels_addr(dst_info, dst_info->dst.x1, y, 0, &dst_pixels, &rem_x, &rem_y); + + /* compose_direct() guarantees no alpha, so byte 3 is padding. */ + for (int x = 0; x < x_limit; x++, src_pixels += 4, dst_pixels += 4) + put_unaligned_le32(get_unaligned_le32(src_pixels) | 0xff000000, dst_pixels); +} + /** * get_pixel_read_line_function() - Retrieve the correct read_line function for a specific * format. The returned pointer is NULL for unsupported pixel formats. The caller must ensure that -- 2.56.1
