From nobody Mon Feb 9 07:44:05 2026 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B20A829A5 for ; Fri, 22 Nov 2024 16:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292715; cv=none; b=pTB7MO5peUk40FakjuoD0q848BHEWt8iXPorQpha5j/l/9MQqPrEvvCMP8pf95I8uQpDrGav5hkXl5pUcVM6vwjGI2yHLFqEWl391Cyd3ePZY/4yysZ7uWeIRtHwchSp11OJpxVywzB5+HVItmx2svzfXB9qL8uRgvdnoln2g1U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292715; c=relaxed/simple; bh=kvBuXYPDgNffAIVnvaafBaanKc2jQF6V8JhgmRV44/I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tw0ykZQ8kr3S2+35yIvfFQ9JIMA4CmbzruIdHVueY85J34jurK2NxzFd5mdj3sqvQq1PjZfh/erbT6wF9UzG7KQhx1GZFZGw9yNPxQBgS98z+b+WxIh1cZnEEc4EFG+e2i+UI1AzPgHkKOdTyLtDXreu5YH7QFLJ1/31jhpiXSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=mHYw6goM; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="mHYw6goM" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8B231E0007; Fri, 22 Nov 2024 16:25:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292705; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yrph+lbrmkDjH3XLZYWrCy0AJRMEXLYnrJDeKfCnYw0=; b=mHYw6goMMboI06Tyjqparj+e4/1DXCzkIzKE8fII49onb17Y4F6dKIe13e6pIx6aXaPyg8 bGSovXd2YEBwq16M7LubSn6ox8QgiB1UqeD4g4A6sTk+xUrid5FeMZ5JNTyWZPK5ihY1R1 G/xYOg7lzoXulNT98rAanLVOdjPa5wAuCeSo9XZeu0ZMeaX27Gx1NNIdA1nzqdJSZerVGJ UC6BjErlGxvpAANTSysOKIHiiBtEmsY4MF/DRvXXQn4fz9u/+XvvFMqr8Zu1rN2HWWi1Cd /GTQiNBPtF7Aq6lEpyRd6JUvbILw24r5qV4edAHwukpYI0hBJb1/5CFrPPJ2zA== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:25:00 +0100 Subject: [PATCH v3 1/3] drm/vkms: Re-introduce line-by-line algorithm for writeback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241122-writeback_line_by_line-v3-1-085d5810f6e3@bootlin.com> References: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> In-Reply-To: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=11596; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=kvBuXYPDgNffAIVnvaafBaanKc2jQF6V8JhgmRV44/I=; b=kA0DAAgBIK0uxlsQLOIByyZiAGdAsF2h4PW7X5QyKrlhxTuFa27f8fbwyZ0I4jWAblYU44ToB okCMwQAAQgAHRYhBE+PuD++eDwxDFBZBCCtLsZbECziBQJnQLBdAAoJECCtLsZbECziNgYQAMuH AonLShQXfr/lx7G//NDW63oxl3Ii7NU7XhS7kioxvOgdNhi07BcXsiQOFD8qNb/01w1RqqCeGEu TxrVehHwVpYEA3TX+v5SnTIawLpIoruRjyyYqHTDvEoqQQ4lftBo//ZraxY8VWgbg1btuye3eOE LGBizdFOOQnY+QyIuht8yjPX4qnZzbKB+VnT+Swyvlh6UASWoZdy+Rso2JvzwKxi3uKUtpa5+7V ioU4RXQt5EqGcHvOpkPqW6T7rAiYKtd1MMVCTWrkhJKFjVgPIm5tQfzsJbGNknuuVozgvxtHBxT wHKsHnZQ5QZr2nCekDyaB2tcuoQagZiTkG1dtJ/5YfMkfWb6pYD1OZgUvVKerlOrlATabAmwSB+ u2ax0M8KbIq/Vtml1Iu7GyFknRCgaJXHgs8sqUbj1ZuX52Jsi8KWesTHyrKTAU2MNgsgs0dbXXL rDGpgmd5/dyrZP9MLA8zqYJG/ra6Ie+Pis01lWWi2DMgnU+qzArWmiVAcdbk9jbIBvt8+6/OGO2 dQLEq2f6wQ1PFLRXFxFaqAZTiOh3UvFxkY1qM1ope5W8YmL6PufJEI5Gc+bVSASvx0m6W3sjiRz owL3N56Kl6rQI6RAcbe56H5XRXhoBZ2S33vbvTMBtVU0l/PcAdeGPU7hDTE8WxbO37PURuc5OEC U0jLe X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Re-introduce a line-by-line writeback algorithm for each pixel format. This allows more performance by not requiring an indirection per pixel write. Line-by-line writeback 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 with some effort to avoid code duplication. Now only the loop is repeated, but it is required to have good performances. The performance gain is around 5 to 10%. [1]: https://lore.kernel.org/all/20211005201637.58563-7-igormtorrente@gmail= .com/ [2]: https://lore.kernel.org/all/20230515135204.115393-4-mcanal@igalia.com/ Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 17 +++++ drivers/gpu/drm/vkms/vkms_drv.h | 17 +++-- drivers/gpu/drm/vkms/vkms_formats.c | 119 +++++++++++++++++++++++++++---= ---- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- drivers/gpu/drm/vkms/vkms_writeback.c | 2 +- 5 files changed, 125 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index b20ac170572622b34ba76b1a9c5dd626ca5da6fa..6d58ba47c2a401a1235d04e8eb2= 1cf95904d8fc2 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -176,6 +176,23 @@ static enum pixel_read_direction direction_for_rotatio= n(unsigned int rotation) return READ_LEFT_TO_RIGHT; } =20 +/** + * vkms_writeback_row() - Write a line to the writeback buffer + * + * @wb: Job where to insert the final image + * @src_buffer: Line to write + * @y: Row to write in the writeback buffer + */ +static void vkms_writeback_row(struct vkms_writeback_job *wb, + const struct line_buffer *src_buffer, size_t y_start) +{ + struct vkms_frame_info *frame_info =3D &wb->wb_frame_info; + int x_start =3D frame_info->dst.x1; + int count =3D min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer-= >n_pixels); + + wb->pixel_write(wb, src_buffer->pixels, count, x_start, y_start); +} + /** * clamp_line_coordinates() - Compute and clamp the coordinate to read and= write during the blend * process. diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index ae721d998c7d381b9e4105c41dec90b7b0ce2dc0..c806055151cd909beb454df1a25= 6d97464b6614f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -52,20 +52,26 @@ struct line_buffer { struct pixel_argb_u16 *pixels; }; =20 +struct vkms_writeback_job; /** - * typedef pixel_write_t - These functions are used to read a pixel from a + * typedef pixel_write_line_t - These functions are used to read a pixel f= rom a * &struct pixel_argb_u16, convert it in a specific format and write it in= the @out_pixel * buffer. * - * @out_pixel: destination address to write the pixel - * @in_pixel: pixel to write + * @wb: the writeback job to write the output of the conversion + * @in_pixels: Source buffer containing the line to convert + * @count: The width of a line + * @x_start: The x (width) coordinate in the destination plane + * @y_start: The y (height) coordinate in the destination plane */ -typedef void (*pixel_write_t)(u8 *out_pixel, const struct pixel_argb_u16 *= in_pixel); +typedef void (*pixel_write_line_t)(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *in_pixels, int count, int x_start, + int y_start); =20 struct vkms_writeback_job { struct iosys_map data[DRM_FORMAT_MAX_PLANES]; struct vkms_frame_info wb_frame_info; - pixel_write_t pixel_write; + pixel_write_line_t pixel_write; }; =20 /** @@ -290,7 +296,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_writeback_row(struct vkms_writeback_job *wb, const struct line_b= uffer *src_buffer, int y); =20 /* Writeback */ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev); diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index c895126e9136bff7820ac7dfc1a3b6418c9ca2b1..f6d0b71a05084a7f57dc8f0600b= a2a2b654c4ec0 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -589,7 +589,7 @@ static void planar_yuv_read_line(const struct vkms_plan= e_state *plane, int x_sta * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. * The result is stored in @out_pixel. * - * They are used in vkms_writeback_row() to convert and store a pixel from= the src_buffer to + * They are used in the `write_line` functions to convert and store a pixe= l from the src_buffer to * the writeback buffer. */ static void argb_u16_to_ARGB8888(u8 *out_pixel, const struct pixel_argb_u1= 6 *in_pixel) @@ -656,28 +656,97 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const s= truct pixel_argb_u16 *in_pi *pixel =3D cpu_to_le16(r << 11 | g << 5 | b); } =20 -/** - * vkms_writeback_row() - Generic loop for all supported writeback format.= It is executed just - * after the blending to write a line in the writeback buffer. +/* + * The following functions are write_line function for each pixel format s= upported by VKMS. + * + * They write a full line at index y. They must read data from the line sr= c_pixels. + * + * The caller must ensure that count is not larger than the framebuffer an= d the src_pixels. + * + * Those function are very similar, but it is required for performance rea= son. In the past, some + * experiment were done, and with a generic loop the performance are very = reduced [1]. * - * @wb: Job where to insert the final image - * @src_buffer: Line to write - * @y: Row to write in the writeback buffer + * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ -void vkms_writeback_row(struct vkms_writeback_job *wb, - const struct line_buffer *src_buffer, int y) + +static void ARGB8888_write_line(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *src_pixels, int count, int x_start, + int y_start) { - struct vkms_frame_info *frame_info =3D &wb->wb_frame_info; - int x_dst =3D frame_info->dst.x1; u8 *dst_pixels; - int rem_x, rem_y; =20 - packed_pixels_addr(frame_info, x_dst, y, 0, &dst_pixels, &rem_x, &rem_y); - struct pixel_argb_u16 *in_pixels =3D src_buffer->pixels; - int x_limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), src_buffe= r->n_pixels); + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); + + while (count) { + argb_u16_to_ARGB8888(dst_pixels, src_pixels); + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; + src_pixels +=3D 1; + count--; + } +} + +static void XRGB8888_write_line(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *src_pixels, int count, int x_start, + int y_start) +{ + u8 *dst_pixels; + + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); + + while (count) { + argb_u16_to_XRGB8888(dst_pixels, src_pixels); + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; + src_pixels +=3D 1; + count--; + } +} + +static void ARGB16161616_write_line(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *src_pixels, int count, int x_start, + int y_start) +{ + u8 *dst_pixels; + + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); =20 - for (size_t x =3D 0; x < x_limit; x++, dst_pixels +=3D frame_info->fb->fo= rmat->cpp[0]) - wb->pixel_write(dst_pixels, &in_pixels[x]); + while (count) { + argb_u16_to_ARGB16161616(dst_pixels, src_pixels); + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; + src_pixels +=3D 1; + count--; + } +} + +static void XRGB16161616_write_line(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *src_pixels, int count, int x_start, + int y_start) +{ + u8 *dst_pixels; + + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); + + while (count) { + argb_u16_to_XRGB16161616(dst_pixels, src_pixels); + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; + src_pixels +=3D 1; + count--; + } +} + +static void RGB565_write_line(struct vkms_writeback_job *wb, + struct pixel_argb_u16 *src_pixels, int count, int x_start, + int y_start) +{ + u8 *dst_pixels; + + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); + + while (count) { + argb_u16_to_RGB565(dst_pixels, src_pixels); + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; + src_pixels +=3D 1; + count--; + } } =20 /** @@ -939,25 +1008,27 @@ void get_conversion_matrix_to_argb_u16(u32 format, EXPORT_SYMBOL(get_conversion_matrix_to_argb_u16); =20 /** - * get_pixel_write_function() - Retrieve the correct write_pixel function = for a specific format. + * get_pixel_write_line_function() - Retrieve the correct write_line funct= ion 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: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) */ -pixel_write_t get_pixel_write_function(u32 format) +pixel_write_line_t get_pixel_write_line_function(u32 format) { switch (format) { case DRM_FORMAT_ARGB8888: - return &argb_u16_to_ARGB8888; + return &ARGB8888_write_line; case DRM_FORMAT_XRGB8888: - return &argb_u16_to_XRGB8888; + return &XRGB8888_write_line; case DRM_FORMAT_ARGB16161616: - return &argb_u16_to_ARGB16161616; + return &ARGB16161616_write_line; case DRM_FORMAT_XRGB16161616: - return &argb_u16_to_XRGB16161616; + return &XRGB16161616_write_line; case DRM_FORMAT_RGB565: - return &argb_u16_to_RGB565; + return &RGB565_write_line; default: /* * This is a bug in vkms_writeback_atomic_check. All the supported diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index eeb208cdd6b1be9676b4706e0e3cbb2ad7efe067..852ab9a4cee5a8684592200f81f= 66afaf4873101 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -7,7 +7,7 @@ =20 pixel_read_line_t get_pixel_read_line_function(u32 format); =20 -pixel_write_t get_pixel_write_function(u32 format); +pixel_write_line_t get_pixel_write_line_function(u32 format); =20 void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding= encoding, enum drm_color_range range, diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/v= kms_writeback.c index 79918b44fedd7ae2451d1d530fc6d5aabf2d99a3..0b31628e1b532367cc79cd7432a= a070661f41a57 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -150,7 +150,7 @@ static void vkms_wb_atomic_commit(struct drm_connector = *conn, crtc_state->wb_pending =3D true; spin_unlock_irq(&output->composer_lock); drm_writeback_queue_job(wb_conn, connector_state); - active_wb->pixel_write =3D get_pixel_write_function(wb_format); + active_wb->pixel_write =3D get_pixel_write_line_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); } --=20 2.47.0 From nobody Mon Feb 9 07:44:05 2026 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0B4E1A0B08 for ; Fri, 22 Nov 2024 16:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292716; cv=none; b=RPT2DpoWzILKILRh7XP/G3rMU9mwnZrJIr9cI+A3LG17zXBV/fcMuMUV/21aZW6frK518eVddL3kxSTqI7DW1or9TR05soLHN0SpkZL1p0LYtQhQ97jYq+yNieeoGBQW6LQrAsF5t/bR+VPqaOtbeCByGUyBjqbFBrPtPEl3lQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292716; c=relaxed/simple; bh=RoqCewqT3TKP7Wxmp1Mjkb0PcZ0QIg4QsOF4CrLNhpU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JOdv59a6jmehMk9USL5a2eVytNuerEddWdqazJFe2WVE6ml+Ocyv50sZQeBCoLO/tBS5v0oTGA+08IMl9syUDTRlLlpLU1K9SvdwrLDlXGGNzQRxcDKfT+L+9h8PxGKIDY5lTwSNMF0my6ByrMFoYg5i76u/1dS+dObTNf1jpjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=UQ2WTsKl; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="UQ2WTsKl" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8F971E0003; Fri, 22 Nov 2024 16:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292706; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5utM+I0xu1pJxGdU34PkZq3EfroSNhCwpZdApnApPr8=; b=UQ2WTsKlocKhCCwTpHxuYJfyeR+eM3hnzBuxCgvVClD1dxx1o1HBZ0sjK7Ow/Vc+X9zusL jU2JThv738KNc+EyFYMTAssPOLtueI1VISk+ISUZLCycCV9woxMDppNDb2XNowFIw+MMKA JF8LgNXqbba4rHQoZTTO/XSapC4Bvh0Y+pUliaX0xzVXrRz+nwA4PqZqUl4fXN3AYwJ9VH sAx+fy6DavT1l13i0c/Ek1RG3mXzbnm4zEIzxFdt6c1yTxMNX51Bwj51RyrNt/1GCGzqsn vyaKadvvEAH357o9d3ubA+btPfnRZqLT+v75Qj0W4lWXS0QARr0VPeA10S94bA== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:25:01 +0100 Subject: [PATCH v3 2/3] drm/vkms: Add a macro for write_line functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241122-writeback_line_by_line-v3-2-085d5810f6e3@bootlin.com> References: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> In-Reply-To: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4631; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=RoqCewqT3TKP7Wxmp1Mjkb0PcZ0QIg4QsOF4CrLNhpU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQLBeACDzwdeoBJbvpctDZylawm/HIGbJFpIhB wiT0YTZUMSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CwXgAKCRAgrS7GWxAs 4m4PD/4voNKH3JH8lHhjExaoTKBR2+H4WnUu8oaNV+e2NsLNnz2+SmjOfWm7ekMpD0T4eCpYvl7 FSI0ap7y4HJ2zU8XVQA0lYr1NlxoOu4pp/pbO4bJyWT+hXg8zyDW8MF6wDL3AYDJeRmdWP3037L DyKOrVBg6RDxaRKe4+sSQd1CUs9dc5zuCEz8ds2Ovs01g/6iGjU8Yw9mX209oxBfIexoOrTzbkE i7xFvsDVWOGxnoduOoa7cKbl6oldf27ucwugpOnpctZMLoqSx7YK4lyKwwYaxIdEUW7TsI+1TTX mxceuOOX7WAChRQx/QHKCzxJq/cxBVkr5g3BpABj1EVYIrWLNLp9xJkjbCzOyq+1YwQQpuUVHcS UfRIXYKQFxxRxH64KAMiek2OpDJoOWGsmRzbOGXrOYzZu2pZTzF+3l1rB0kT3+o2pjls2Rsr4aG JKEVaL4CkBOApoH7popUBdgNjsguETowSfP8DB2hQLh0XEQItQG4Nz4bJb+4xZIn4oiJ9VdOscT jtbJ+drvanXyo/6R1MkcYikvCc9z7BoG3YRJzWOLOG5LGkqp+3urT6R73FxGPZB/HFZ0JdkKQjs He05uPSK9EbsxyND6Aw1C5gR/XZnzbHD4NziSCawnqmFybMpJkxeMqOFRjx9lkfL+/ukV/UDNHb 8UJnkv/NSK9EeHA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The write_line functions are very similar and force code duplication. This patch add a macro to avoid code repetition. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 105 ++++++++++----------------------= ---- 1 file changed, 28 insertions(+), 77 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index f6d0b71a05084a7f57dc8f0600ba2a2b654c4ec0..6a50a86291e50edab2058cf7d40= c7efc8fcb4c12 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -656,6 +656,29 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const st= ruct pixel_argb_u16 *in_pi *pixel =3D cpu_to_le16(r << 11 | g << 5 | b); } =20 +/** + * WRITE_LINE() - Generic generator for write_line functions + * + * This generator can only be used for format with only one plane and bloc= k_w =3D=3D block_h =3D=3D 1 + * + * @function_name: Name to use for the generated function + * @conversion_function: Function to use for the conversion from argb_u16 = to the required format. + */ +#define WRITE_LINE(function_name, conversion_function) \ +static void function_name(struct vkms_writeback_job *wb, \ + struct pixel_argb_u16 *src_pixels, int count, int x_start, \ + int y_start) \ +{ \ + u8 *dst_pixels; \ + \ + packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); \ + \ + for (; count > 0; src_pixels++, count--) { \ + (conversion_function)(dst_pixels, src_pixels); \ + dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; \ + } \ +} + /* * The following functions are write_line function for each pixel format s= upported by VKMS. * @@ -669,85 +692,13 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const s= truct pixel_argb_u16 *in_pi * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ =20 -static void ARGB8888_write_line(struct vkms_writeback_job *wb, - struct pixel_argb_u16 *src_pixels, int count, int x_start, - int y_start) -{ - u8 *dst_pixels; +WRITE_LINE(ARGB8888_write_line, argb_u16_to_ARGB8888) +WRITE_LINE(XRGB8888_write_line, argb_u16_to_XRGB8888) =20 - packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); +WRITE_LINE(ARGB16161616_write_line, argb_u16_to_ARGB16161616) +WRITE_LINE(XRGB16161616_write_line, argb_u16_to_XRGB16161616) =20 - while (count) { - argb_u16_to_ARGB8888(dst_pixels, src_pixels); - dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; - src_pixels +=3D 1; - count--; - } -} - -static void XRGB8888_write_line(struct vkms_writeback_job *wb, - struct pixel_argb_u16 *src_pixels, int count, int x_start, - int y_start) -{ - u8 *dst_pixels; - - packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); - - while (count) { - argb_u16_to_XRGB8888(dst_pixels, src_pixels); - dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; - src_pixels +=3D 1; - count--; - } -} - -static void ARGB16161616_write_line(struct vkms_writeback_job *wb, - struct pixel_argb_u16 *src_pixels, int count, int x_start, - int y_start) -{ - u8 *dst_pixels; - - packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); - - while (count) { - argb_u16_to_ARGB16161616(dst_pixels, src_pixels); - dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; - src_pixels +=3D 1; - count--; - } -} - -static void XRGB16161616_write_line(struct vkms_writeback_job *wb, - struct pixel_argb_u16 *src_pixels, int count, int x_start, - int y_start) -{ - u8 *dst_pixels; - - packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); - - while (count) { - argb_u16_to_XRGB16161616(dst_pixels, src_pixels); - dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; - src_pixels +=3D 1; - count--; - } -} - -static void RGB565_write_line(struct vkms_writeback_job *wb, - struct pixel_argb_u16 *src_pixels, int count, int x_start, - int y_start) -{ - u8 *dst_pixels; - - packed_pixels_addr_1x1(&wb->wb_frame_info, x_start, y_start, 0, &dst_pixe= ls); - - while (count) { - argb_u16_to_RGB565(dst_pixels, src_pixels); - dst_pixels +=3D wb->wb_frame_info.fb->format->char_per_block[0]; - src_pixels +=3D 1; - count--; - } -} +WRITE_LINE(RGB565_write_line, argb_u16_to_RGB565) =20 /** * get_pixel_read_line_function() - Retrieve the correct read_line functio= n for a specific --=20 2.47.0 From nobody Mon Feb 9 07:44:05 2026 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65B621DEFFD for ; Fri, 22 Nov 2024 16:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292717; cv=none; b=VgWWAA+b6ndhMet3UFOE62wVx0ZBP7t3DgzfFHQZ3hLW1wC4/G/xmksAM4dpXyiiMIqFNzoHfk+hbhbr1RVhGwmNHSNNVo7a0es//kKY0k6J1UU5ZJI29JBAWH4OUNU2kBFJaytZvLZzNM8ktq9vJcCdWIIYshzAAVkNr1XzVek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292717; c=relaxed/simple; bh=UoxOHiMTNSZuKXnSQuqgBjDi8qYlisedSJdTUWJ8t7k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kAoy/9AyAG6azSqJmpMJkUG5PZvR6ffCpzVsl+Kl0Ki2W0cXisHcdCxbwaI5aBMNShdI6jlnl1mV+En0UiemFhT5fmIoh0nre516clVizfkMfdAUxvA8HsO/Od0ytktq8ZplQ83Bqg0fzUYKAi8FM80WvCaP+IbDGG82W3rZhT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Pg/9AsI3; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Pg/9AsI3" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8C611E0008; Fri, 22 Nov 2024 16:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292707; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4+cxTF9KCJO78YUV+0ZHhBWyFhLzGz4nnDy5LMx5b6s=; b=Pg/9AsI3WIp0tF98BPvN4L7upd3O+X7DoubntwCwOmpcDVM3clHX2iM4mZd/DUSAPcbV34 3jmgilU3DnEyabD4NGHdcS1BMxXb/nikqLpRtC69J7HoDO8wt3OWlj6YOD4vV6cd/Kx7Ne R9Hnvbht5CvLs6vbz5OUBYSBz5IF+Gt2Y67nCnvgOuiXmKF4teevHVNkdqAGejflxiByM0 LMuBeaJLOGluwEuDpEi+Nb8d29Nf6EPKxp+m0rIwy/m3hsFxe9TkLlEowaRwt0KMQ7SDWm 4FMbvWHgPYV6WNUnvEaWpow6O5JskjqNRUjo2w9ssMdQFVwpSSFftwDujindLg== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:25:02 +0100 Subject: [PATCH v3 3/3] drm/vkms: Add support for XRGB2101010 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241122-writeback_line_by_line-v3-3-085d5810f6e3@bootlin.com> References: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> In-Reply-To: <20241122-writeback_line_by_line-v3-0-085d5810f6e3@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2493; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=UoxOHiMTNSZuKXnSQuqgBjDi8qYlisedSJdTUWJ8t7k=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQLBeEgU50nN/Jsq9saN6JiwszSPcxZECtubdO WvEhQD9nfWJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CwXgAKCRAgrS7GWxAs 4jn3EAC/ztIduKbgnP6ONI9LAQmfqHBsju5aJlvQ5lZpWSIt764Ky2t9qSDaKRi541wJ3axPjux zYIeQ7oTx3cRLg30YK6IkaauV7RBlwzcp4ybJKk+1Z/GUVkV4RfL58NdEuDw0cQc4arRl0nQd3R wJPt6S78SnJsnJE95IZuzCQMmcI/zY83bIzmr2HUcb4+dFRczy6DVmh1VFMmj1RkaFsyyQ6UQID Vsy8RC79MorPCdClpC6GM3j6Yz4DFTNBtNWI5dngrQwpIkv7tOCqcrFanR/NpPVqCHIVVZhVvRn 9+LyBDVcUIBpjb6LgXbCYfNZNve1QM9o1QkKPzD3NqFIE50j/IdHrOEs8gQvwQMHhBf+6WD0CCt 9f4cmNUwknKKiaM4oBE9kXu+6CYloMZo/X/yiyqEZ/LCZ29JUSlrBl7dkeyeQyZtXgAiVvI7R0t Strpq15GjTATAMIZPYEZV1W9oTayNVmi8/uxYMDRXHTid2XJR/5w4DCGM7/voUl4/F2PPJlDFK3 /QcDsGvgNoFYnuVjrAtrkwXdS1JJCpzGgOWRpvai8hJbHU0z4PXGN7C+FASJZTyTXuOVRE/zp7R iieQ6YFAwAjSSU2mtGJRbW3OmMB1zKMBhsKo5psIABS598mMVtgSAoZ655gT5iftTnY0giuViGu c1+RREemk3A5m2Q== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Thanks to the WRITE_LINE macro, adding the format XRGB210101010 is trivial. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 12 ++++++++++++ drivers/gpu/drm/vkms/vkms_writeback.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 6a50a86291e50edab2058cf7d40c7efc8fcb4c12..2177310580ae19382d5fc2f095d= 6b49984033b61 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -656,6 +656,14 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const st= ruct pixel_argb_u16 *in_pi *pixel =3D cpu_to_le16(r << 11 | g << 5 | b); } =20 +static void argb_u16_to_XRGB2101010(u8 *out_pixel, const struct pixel_argb= _u16 *in_pixel) +{ + out_pixel[0] =3D (u8)(in_pixel->b & 0xFF); + out_pixel[1] =3D (u8)((in_pixel->b >> 8) & 0x03) | (u8)((in_pixel->g << 2= ) & 0xFC); + out_pixel[2] =3D (u8)((in_pixel->g >> 6) & 0x0F) | (u8)((in_pixel->r << 4= ) & 0xF0); + out_pixel[3] =3D (u8)((in_pixel->r >> 4) & 0x3F); +} + /** * WRITE_LINE() - Generic generator for write_line functions * @@ -700,6 +708,8 @@ WRITE_LINE(XRGB16161616_write_line, argb_u16_to_XRGB161= 61616) =20 WRITE_LINE(RGB565_write_line, argb_u16_to_RGB565) =20 +WRITE_LINE(XRGB2101010_write_line, argb_u16_to_XRGB2101010) + /** * get_pixel_read_line_function() - Retrieve the correct read_line functio= n for a specific * format. The returned pointer is NULL for unsupported pixel formats. The= caller must ensure that @@ -980,6 +990,8 @@ pixel_write_line_t get_pixel_write_line_function(u32 fo= rmat) return &XRGB16161616_write_line; case DRM_FORMAT_RGB565: return &RGB565_write_line; + case DRM_FORMAT_XRGB2101010: + return &XRGB2101010_write_line; default: /* * This is a bug in vkms_writeback_atomic_check. All the supported diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/v= kms_writeback.c index 0b31628e1b532367cc79cd7432aa070661f41a57..f25468bf4cd7b92535288695761= 11e7a3745a42f 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -19,7 +19,8 @@ static const u32 vkms_wb_formats[] =3D { DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB16161616, DRM_FORMAT_ARGB16161616, - DRM_FORMAT_RGB565 + DRM_FORMAT_RGB565, + DRM_FORMAT_XRGB2101010, }; =20 static const struct drm_connector_funcs vkms_wb_connector_funcs =3D { --=20 2.47.0