From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 BE10018452E for ; Fri, 22 Nov 2024 16:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292119; cv=none; b=Ud3uZcVFAjn9paNwsv15Dt6q3ezzIdozoYhzn2Nf9rvC+JyCQytr4A3hNlzwwUgvC5T8g6r9Pu7YDNqM/L7FlE9+ffE7B8UnOU8NtK7Mfh68/MJK+vePFUR9cjDLn7MfmIPQU44uONhcGxhhixC4vAgxir0vDCVjHfRgDTncp9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292119; c=relaxed/simple; bh=xXvj+crpyp9sfQgjGWcgkb4EGOJwO9WuwNz2TVJhiqc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YUgZj7az1Vdf7oVAzWHWfwmbcKK1gYX/dihcL9fs1FjOPyFcHZQElrKz4ZCtTrJTZnp67o9PaEV8MJc5X8vDT6Sdma2AfVQekT0LFFM/L5Vv+ORehAqyE3K7gaBVaOIpaPdkJd/aa/6lZcQusAOp07zEPajYV15IvVJEegVP1PM= 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=ph6Mgh4D; arc=none smtp.client-ip=217.70.183.197 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="ph6Mgh4D" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2030E1C0004; Fri, 22 Nov 2024 16:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292108; 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=wp31ywIXD1K5mMtQQFNYiTSeygR6X7Jueg+AoYzX29o=; b=ph6Mgh4DJuwbNNOy+oIAOpVsF70MwZkiKAfUnmRv/lz9EA6cKE1BIl9l8zepBAir/3mcZa n/KeNpX2tP44WkN2TVVo50UxqB9vHhK6FWg80OHLN0CqzpbKAGFqGHTu9QVUvtMZpeQ0P7 I9YyL+LXAbFoR171Cw0GjmcBNmmuExSaV9mZhEl6v7IKxo4imDuU2nAlwV7irvVkWUMFw2 XhHe85caD//CVSdVruJESKHIUWLmeKFiJ8ChaGDbh1BWfs2iLudbPmt69KNl7646gi7wE3 8fO6kSZRno0Tv0pWCPcV4fiiaGxs1EG23EDIeWAt/4EFEw2eu2mpeAiOIbj4mQ== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:01 +0100 Subject: [PATCH v14 1/7] drm/vkms: Add YUV support 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-yuv-v14-1-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=18934; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=x+PpGq/NazLPIBNQiPNlHKbW2GeWAhOXfFOTKwe+f0c=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4GuLC9DthePmhqpuVan4yx1shRhQ49dKTtN opkx1yBf++JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuBgAKCRAgrS7GWxAs 4kQaD/474quXcVmtE5I5CgOM1NO2Jvy4pvauna+IzKfvdrFmh12q+aagbM9RucWp8tIp9B8SOri qb4Di8AsLfWA7cCeSKFH3pVMUzTlz7tWskX+qyxMdB5fvL3seJQzSOXLDt+Y3qUnQRs+zgJrwW/ Dad7kM1fhi0jPOzbZHGPfq89JEjS/i2VGum1RzCXb0B7YffLE5W0y9Rk4nPDqR9wVod7hN//nt4 ctpRy1lUlFY9+4hYb9O2G7d0RuZQJMvMkHwsmzDxfyfS2jsDBi6vhdXJujY8q/o2s8qcrzYlI9B SKwedKfa2jiHRjAErvKsBPeoI9ZGLuhSDmvgtiI/RP1h2yTtOOl+kCoiSbLrvg5dyukkfuBAA2z vpZQJMHb1J4vjflQoTGAlkBBf1UqKOrMrEz85VIZoUuKYS4a5jrspUv2NwioL2ZBQs4RTzMyEgZ l22l1ANc7iL3QxIETMBEWMgdz+gSth9+GDXV0dWdoJBSQGR34zjNlLN0rlDLpqikt6811ajNLez EHSkp3YjG8n5KNEln4Nusk6ttAAy8gNChEl4wCF97GeW9kCC6Bnim77B75CW0OmTAXIyBKh7lLO QGJ4zn43IuwQ8Maaz7YNymGKxNi+XZLAtXnfvkmFbzKgKfVJa75/uH5ONdVVES9LaHTEhC1lULs 48mybN1hLw14yJw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Add support to the YUV formats bellow: - NV12/NV16/NV24 - NV21/NV61/NV42 - YUV420/YUV422/YUV444 - YVU420/YVU422/YVU444 The conversion from yuv to rgb is done with fixed-point arithmetic, using 32.32 fixed-point numbers and the drm_fixed helpers. To do the conversion, a specific matrix must be used for each color range (DRM_COLOR_*_RANGE) and encoding (DRM_COLOR_*). This matrix is stored in the `conversion_matrix` struct, along with the specific y_offset needed. This matrix is queried only once, in `vkms_plane_atomic_update` and stored in a `vkms_plane_state`. Those conversion matrices of each encoding and range were obtained by rounding the values of the original conversion matrices multiplied by 2^32. This is done to avoid the use of floating point operations. The same reading function is used for YUV and YVU formats. As the only difference between those two category of formats is the order of field, a simple swap in conversion matrix columns allows using the same function. Signed-off-by: Arthur Grillo [Louis Chauvet: - Adapted Arthur's work - Implemented the read_line_t callbacks for yuv - add struct conversion_matrix - store the whole conversion_matrix in the plane state - remove struct pixel_yuv_u8 - update the commit message - Merge the modifications from Arthur] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 18 ++ drivers/gpu/drm/vkms/vkms_formats.c | 354 ++++++++++++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_formats.h | 4 + drivers/gpu/drm/vkms/vkms_plane.c | 16 +- 4 files changed, 391 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 00541eff3d1b0aa4b374fb94c8fe34932df31509..ae721d998c7d381b9e4105c41de= c90b7b0ce2dc0 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -100,17 +100,35 @@ typedef void (*pixel_read_line_t)(const struct vkms_p= lane_state *plane, int x_st int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]); =20 +/** + * struct conversion_matrix - Matrix to use for a specific encoding and ra= nge + * + * @matrix: Conversion matrix from yuv to rgb. The matrix is stored in a r= ow-major manner and is + * used to compute rgb values from yuv values: + * [[r],[g],[b]] =3D @matrix * [[y],[u],[v]] + * OR for yvu formats: + * [[r],[g],[b]] =3D @matrix * [[y],[v],[u]] + * The values of the matrix are signed fixed-point values with 32 bits fr= actional part. + * @y_offset: Offset to apply on the y value. + */ +struct conversion_matrix { + s64 matrix[3][3]; + int y_offset; +}; + /** * struct vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation * @pixel_read_line: function to read a pixel line in this plane. The crea= tor of a * struct vkms_plane_state must ensure that this pointer is valid + * @conversion_matrix: matrix used for yuv formats to convert to rgb */ struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; pixel_read_line_t pixel_read_line; + struct conversion_matrix conversion_matrix; }; =20 struct vkms_plane { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 39b1d7c97d454dfa1420990d35e455ed47e57c0c..1f3ce4f334be9560e62c9a7fd93= 3fa0ed6640e8f 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -140,6 +140,51 @@ static void packed_pixels_addr_1x1(const struct vkms_f= rame_info *frame_info, *addr =3D (u8 *)frame_info->map[0].vaddr + offset; } =20 +/** + * get_subsampling() - Get the subsampling divisor value on a specific dir= ection + * + * @format: format to extarct the subsampling from + * @direction: direction of the subsampling requested + */ +static int get_subsampling(const struct drm_format_info *format, + enum pixel_read_direction direction) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + case READ_TOP_TO_BOTTOM: + return format->vsub; + case READ_RIGHT_TO_LEFT: + case READ_LEFT_TO_RIGHT: + return format->hsub; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 1; +} + +/** + * get_subsampling_offset() - An offset for keeping the chroma siting cons= istent regardless of + * x_start and y_start values + * + * @direction: direction of the reading to properly compute this offset + * @x_start: x coordinate of the starting point of the readed line + * @y_start: y coordinate of the starting point of the readed line + */ +static int get_subsampling_offset(enum pixel_read_direction direction, int= x_start, int y_start) +{ + switch (direction) { + case READ_BOTTOM_TO_TOP: + return -y_start - 1; + case READ_TOP_TO_BOTTOM: + return y_start; + case READ_RIGHT_TO_LEFT: + return -x_start - 1; + case READ_LEFT_TO_RIGHT: + return x_start; + } + WARN_ONCE(true, "Invalid direction for pixel reading: %d\n", direction); + return 0; +} + /* * The following functions take pixel data (a, r, g, b, pixel, ...) and co= nvert them to * &struct pixel_argb_u16 @@ -202,6 +247,38 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 c= hannel_2, + const struct conversion_matrix *matrix) +{ + u16 r, g, b; + s64 fp_y, fp_channel_1, fp_channel_2; + s64 fp_r, fp_g, fp_b; + + fp_y =3D drm_int2fixp(((int)y - matrix->y_offset) * 257); + fp_channel_1 =3D drm_int2fixp(((int)channel_1 - 128) * 257); + fp_channel_2 =3D drm_int2fixp(((int)channel_2 - 128) * 257); + + fp_r =3D drm_fixp_mul(matrix->matrix[0][0], fp_y) + + drm_fixp_mul(matrix->matrix[0][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[0][2], fp_channel_2); + fp_g =3D drm_fixp_mul(matrix->matrix[1][0], fp_y) + + drm_fixp_mul(matrix->matrix[1][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[1][2], fp_channel_2); + fp_b =3D drm_fixp_mul(matrix->matrix[2][0], fp_y) + + drm_fixp_mul(matrix->matrix[2][1], fp_channel_1) + + drm_fixp_mul(matrix->matrix[2][2], fp_channel_2); + + fp_r =3D drm_fixp2int_round(fp_r); + fp_g =3D drm_fixp2int_round(fp_g); + fp_b =3D drm_fixp2int_round(fp_b); + + r =3D clamp(fp_r, 0, 0xffff); + g =3D clamp(fp_g, 0, 0xffff); + b =3D clamp(fp_b, 0, 0xffff); + + return argb_u16_from_u16161616(0xffff, r, g, b); +} + /* * The following functions are read_line function for each pixel format su= pported by VKMS. * @@ -311,6 +388,92 @@ static void RGB565_read_line(const struct vkms_plane_s= tate *plane, int x_start, } } =20 +/* + * This callback can be used for YUV formats where U and V values are + * stored in the same plane (often called semi-planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void semi_planar_yuv_read_line(const struct vkms_plane_state *plane= , int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *uv_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &uv_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_uv =3D get_block_step_bytes(plane->frame_info->fb, direction, 1); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(y_plane[0], uv_plane[0], uv_plane[1], + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) + uv_plane +=3D step_uv; + } +} + +/* + * This callback can be used for YUV format where each color component is + * stored in a different plane (often called planar formats). It will + * correctly handle subsampling as described in the drm_format_info of the= plane. + * + * The conversion matrix stored in the @plane is used to: + * - Apply the correct color range and encoding + * - Convert YUV and YVU with the same function (a column swap is needed w= hen setting up + * plane->conversion_matrix) + */ +static void planar_yuv_read_line(const struct vkms_plane_state *plane, int= x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + u8 *y_plane; + u8 *channel_1_plane; + u8 *channel_2_plane; + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, + &y_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 1, + &channel_1_plane); + packed_pixels_addr_1x1(plane->frame_info, + x_start / plane->frame_info->fb->format->hsub, + y_start / plane->frame_info->fb->format->vsub, 2, + &channel_2_plane); + int step_y =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int step_channel_1 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 1); + int step_channel_2 =3D get_block_step_bytes(plane->frame_info->fb, direct= ion, 2); + int subsampling =3D get_subsampling(plane->frame_info->fb->format, direct= ion); + int subsampling_offset =3D get_subsampling_offset(direction, x_start, y_s= tart); + const struct conversion_matrix *conversion_matrix =3D &plane->conversion_= matrix; + + for (int i =3D 0; i < count; i++) { + *out_pixel =3D argb_u16_from_yuv888(*y_plane, *channel_1_plane, *channel= _2_plane, + conversion_matrix); + out_pixel +=3D 1; + y_plane +=3D step_y; + if ((i + subsampling_offset + 1) % subsampling =3D=3D 0) { + channel_1_plane +=3D step_channel_1; + channel_2_plane +=3D step_channel_2; + } + } +} + /* * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. * The result is stored in @out_pixel. @@ -426,6 +589,20 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) return &XRGB16161616_read_line; case DRM_FORMAT_RGB565: return &RGB565_read_line; + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV24: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + return &semi_planar_yuv_read_line; + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + return &planar_yuv_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported @@ -439,6 +616,183 @@ pixel_read_line_t get_pixel_read_line_function(u32 fo= rmat) } } =20 +/* + * Those matrices were generated using the colour python framework + * + * Below are the function calls used to generate each matrix, go to + * https://colour.readthedocs.io/en/develop/generated/colour.matrix_YCbCr.= html + * for more info: + * + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix no_operation =3D { + .matrix =3D { + { 4294967296, 0, 0, }, + { 0, 4294967296, 0, }, + { 0, 0, 4294967296, }, + }, + .y_offset =3D 0, +}; + +static const struct conversion_matrix yuv_bt601_full =3D { + .matrix =3D { + { 4294967296, 0, 6021544149 }, + { 4294967296, -1478054095, -3067191994 }, + { 4294967296, 7610682049, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt601_limited =3D { + .matrix =3D { + { 5020601039, 0, 6881764740 }, + { 5020601039, -1689204679, -3505362278 }, + { 5020601039, 8697922339, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_full =3D { + .matrix =3D { + { 4294967296, 0, 6763714498 }, + { 4294967296, -804551626, -2010578443 }, + { 4294967296, 7969741314, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709= "], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt709_limited =3D { + .matrix =3D { + { 5020601039, 0, 7729959424 }, + { 5020601039, -919487572, -2297803934 }, + { 5020601039, 9108275786, 0 }, + }, + .y_offset =3D 16, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D False, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_full =3D { + .matrix =3D { + { 4294967296, 0, 6333358775 }, + { 4294967296, -706750298, -2453942994 }, + { 4294967296, 8080551471, 0 }, + }, + .y_offset =3D 0, +}; + +/* + * numpy.around(colour.matrix_YCbCr(K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.202= 0"], + * is_legal =3D True, + * bits =3D 8) * 2**32).astype(int) + */ +static const struct conversion_matrix yuv_bt2020_limited =3D { + .matrix =3D { + { 5020601039, 0, 7238124312 }, + { 5020601039, -807714626, -2804506279 }, + { 5020601039, 9234915964, 0 }, + }, + .y_offset =3D 16, +}; + +/** + * swap_uv_columns() - Swap u and v column of a given matrix + * + * @matrix: Matrix in which column are swapped + */ +static void swap_uv_columns(struct conversion_matrix *matrix) +{ + swap(matrix->matrix[0][2], matrix->matrix[0][1]); + swap(matrix->matrix[1][2], matrix->matrix[1][1]); + swap(matrix->matrix[2][2], matrix->matrix[2][1]); +} + +/** + * get_conversion_matrix_to_argb_u16() - Retrieve the correct yuv to rgb c= onversion matrix for a + * given encoding and range. + * + * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) + * @encoding: DRM_COLOR_* value for which to obtain a conversion matrix + * @range: DRM_COLOR_*_RANGE value for which to obtain a conversion matrix + * @matrix: Pointer to store the value into + */ +void get_conversion_matrix_to_argb_u16(u32 format, + enum drm_color_encoding encoding, + enum drm_color_range range, + struct conversion_matrix *matrix) +{ + const struct conversion_matrix *matrix_to_copy; + bool limited_range; + + switch (range) { + case DRM_COLOR_YCBCR_LIMITED_RANGE: + limited_range =3D true; + break; + case DRM_COLOR_YCBCR_FULL_RANGE: + limited_range =3D false; + break; + case DRM_COLOR_RANGE_MAX: + limited_range =3D false; + WARN_ONCE(true, "The requested range is not supported."); + break; + } + + switch (encoding) { + case DRM_COLOR_YCBCR_BT601: + matrix_to_copy =3D limited_range ? &yuv_bt601_limited : + &yuv_bt601_full; + break; + case DRM_COLOR_YCBCR_BT709: + matrix_to_copy =3D limited_range ? &yuv_bt709_limited : + &yuv_bt709_full; + break; + case DRM_COLOR_YCBCR_BT2020: + matrix_to_copy =3D limited_range ? &yuv_bt2020_limited : + &yuv_bt2020_full; + break; + case DRM_COLOR_ENCODING_MAX: + matrix_to_copy =3D &no_operation; + WARN_ONCE(true, "The requested encoding is not supported."); + break; + } + + memcpy(matrix, matrix_to_copy, sizeof(*matrix_to_copy)); + + switch (format) { + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YVU444: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV61: + case DRM_FORMAT_NV42: + swap_uv_columns(matrix); + break; + default: + break; + } +} +EXPORT_SYMBOL(get_conversion_matrix_to_argb_u16); + /** * get_pixel_write_function() - 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 diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index 8d2bef95ff7974a5c852dbaf3bf3f45c3ac32047..d583855cb32027d16b73d2a5b5a= 0644b13191d08 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -9,4 +9,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format); =20 pixel_write_t get_pixel_write_function(u32 format); =20 +void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding= encoding, + enum drm_color_range range, + struct conversion_matrix *matrix); + #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index e2fce471870f1899f2ccb66b339ce8c4332cc287..10e032e146f093d0fd99a82c7b5= 8d62a0d987fd7 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -17,7 +17,19 @@ static const u32 vkms_formats[] =3D { 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, }; =20 static struct drm_plane_state * @@ -118,6 +130,8 @@ static void vkms_plane_atomic_update(struct drm_plane *= plane, frame_info->rotation =3D new_state->rotation; =20 vkms_plane_state->pixel_read_line =3D get_pixel_read_line_function(fmt); + get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, new_sta= te->color_range, + &vkms_plane_state->conversion_matrix); } =20 static int vkms_plane_atomic_check(struct drm_plane *plane, --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 475C41DEFF4 for ; Fri, 22 Nov 2024 16:15:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292118; cv=none; b=bFeBsObkv0hq62SMa/zKcMhr/reK6vEXrlaTE1lEsojYySa3ru0CSw+eO0QWLiewWqVCfk/e32f/Gej2Db5lOpiM1i4L4/ECmLQ4YztSiUnBUMSzvEhAA/gza3debIiD6wVemwf5xnZYYxXOj0IBLR7h5sTwr+TsakP6vPImdy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292118; c=relaxed/simple; bh=5+1bxkH/6jvM+bSYJwMzoEEdlhRHb3TLK4V00AuCHaQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZJle3nZWVHxQljyoE1IpEOCnhrjYemIrMuXYxSNpm/ogiqV+s2pdfRCvR9Ss0Z7IigtW0cGz/62cQshXoxjIs7/7LS/oMLO9S340Eb+7jUhVdeHbph23n1vy4yaU08rZusVFME5xO4OaeygcmOzcpqHt1PNf32kFTjKZbYDKq0I= 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=TzJ0wrK6; arc=none smtp.client-ip=217.70.183.197 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="TzJ0wrK6" Received: by mail.gandi.net (Postfix) with ESMTPSA id 333C61C0003; Fri, 22 Nov 2024 16:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292109; 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=+pwLDbgu9jtYV4f1M50fqXd9jWC2o3HSRBRiNLxp+j4=; b=TzJ0wrK6XmrRm3xGQDt9lgl0Yxh/jQfnuNaJCoTBltvu+C0eoKLKGoZx1B+nHR0mxizAri yXmwySkLzCPWwzlx492l55Y1A+K/MJlS7QU+oS3Y+ApwtA7V61lyUTNvnNrFKAMYsQfC68 X1xgxT6fdEhuWv2Ch4Q2+B4h6QDCE1+XgIAZ1suAbiqIpvho81hSyPl73k3LLp2Zefc13E kxp/NizTiUp+QXfUUsorIgWSwqGVVbLN/PB6lN61WNmiwgR89fh/wS3jGmVcBOXrROCMje P6Ab9CF6rpb4iaY7/T+6AGBp9e/XVtJXczjFVSCPcPHUmy3V4ld20rNR4F3EGQ== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:02 +0100 Subject: [PATCH v14 2/7] drm/vkms: Add range and encoding properties to the plane 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-yuv-v14-2-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1309; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=3qxUodTpFhGEQUZhya3OvUZpOZdhecRKqdRQipLiUwM=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4HddvcCxD1JVvtGNXQIdg92GB/lL0+bPGxI PactfCnFM6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuBwAKCRAgrS7GWxAs 4qi6D/9Pq1Gwe3AULloaYgUUWkL35YnHFCLjXE7TldWGRaM7cbjzFCFnlnlhFOAif6NGstI6wRc iKx7kui82YyJmIZzolzXn/3aqqpY0dHnavHa9QsLSRa0Doq80QhzK8NcrTD6O9LyVKtgp9PnO8A SdPHrPRz+8kICVkKU9sTAephIO4xiZAGuYpEef6t0WLQnB/dSvc1ee1zLpURSI0ONCAfVNV5G0m 1w4IvA/1NeWGPd4dBHNjxQU0lmpxFi5rKl+Tpaj2WNCACEVsyNdQvHFEoD3iekmcXrmbCGT/IDK uyOVgh1tg04qCi1bd4PL8nWQAvNEPIjlxV+xQjouudVF9C54ESIW1F2o/nQlcip/r/jgWx0nSyH HZd2Na25+hPhR9NnEZ7nZ9nmjMMY9nIz4NtSy5Sr56uewe8GpYReVtUEM3YYJ1XbEpj/wrL/JUP ooqWvqCq8N/1engWdnkEdnzsK5NXQ9MjUxdGtWACewq4sEtD/q1UnTK3Q6nGEgeXV65I572QIMp TOAjbVfyykrcNM5/F90xseeSJt1aSmAbN+/qm7vEV6fFU4ESHKyL5eF1y9gh2ePQz1LhtTrebUk 52kWX3gbarppOMizNxmIm855y5xXc4cDLldVRxjLqqLitwX0pXYz46dS94sDuTwpGUozDJcYsSg RYdTaqwYAOV57lQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Now that the driver internally handles these quantization ranges and YUV encoding matrices, expose the UAPI for setting them. Signed-off-by: Arthur Grillo [Louis Chauvet: retained only relevant parts, updated the commit message] Acked-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_plane.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index 10e032e146f093d0fd99a82c7b58d62a0d987fd7..e6ca8f2db32d92068ddba7eed92= cfae0d28cd45f 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -218,5 +218,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); =20 + 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; } --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 635BC1DF25B for ; Fri, 22 Nov 2024 16:15:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; cv=none; b=kLZGuI4pT645TASRgdAKkn2L75Om0nXS2CkhJc07gQsFQ2XvEqQexAnXqzamXlQMlUU0T1mbv9y5XnqsOwg9Fs0vWHOJNnG7X1hbMmJ3HzmXuBACgX26iBLszBbtX5+Gu+I/lFxUWpJIbo3yx8/+N3WSrrgb9M3ECWDj67wp3lA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; c=relaxed/simple; bh=KCcQhPVz6PUxTkptUubEsPv0X3QW8k3JN+SJqqNicp0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eI8y07GhaYdy4ZD7eGhu2qfeMarKuqlb3/LDVHVfe3TFE6JCuk8P2bFLtIjXE0jHPfiDdyOk4sAOOwIDbr1AgPqN2gBbScXe74x58mTVSklEP+PxnWhu+rd/Rru9qy1dTyZv9mu+Yn9xjbfkKdrPRV2II2vDk3leTQeMTzt5kD8= 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=e9QHAu4v; arc=none smtp.client-ip=217.70.183.197 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="e9QHAu4v" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4DEEE1C0006; Fri, 22 Nov 2024 16:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292110; 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=LyuZSeQhWN8yZC/+93Agwlt6oIM4sNXPX8BuSmxPT1g=; b=e9QHAu4v5qpnH3/4lofPsTsiGR54lTrJosUcvFmA560TtHxRWVRC9Ap5u8fA3jkzjECjPP YToqXZqmHBWz0PeSEmkAe4GpSvtKP9CGDHiJOWUyHuShkb7X72qBcmOYwgMzza4cBZDxcU s/V5+AzIN6DzMYtGSk89tQMfOeXLNRbSokIcSuzaiKVlPCBpZo7nyeybElUuCDdi4RJnXt 83d+hIYo7UtKwE5+DkqETIPJ2oYvorQU8ccxxCOtcyce5PJ4EtYWYHV/g9fMc+uBqSR7uG AdhM5HOWEiwVmlIsvgoQEPWwCS2GITAeEoCYFVO0n+TzTwcyWvatgtBKpeg5aw== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:03 +0100 Subject: [PATCH v14 3/7] drm/vkms: Drop YUV formats TODO 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-yuv-v14-3-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=937; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=iDZ/HJ7Gex8d9aGNH0HIIVbXcYQeibofjLc/H+dZBcg=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4HBuIoq//YMeeIKyGPMkM33ZY+HjZpEJQh3 Bu/kYVjKMiJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuBwAKCRAgrS7GWxAs 4lLgD/9x98VeLVlBYLzvcYfknylz/UYiYin/M4eKw0u3Id4wtMbCotQ97fejaUdKl5Fs3vOglBb eIS4U0dvS+4wR9C9OCszH8HjgNFa7G3dfwApP493zme1wQZFvf8G5PAeN/ETG5H3SBhuj1pc7qK 9GLvtYDtxDcbAJLooSQHfGnfUa9AheIz2HaSWWuzioUtSXTXJgLZ/2z+nWReX3SRuFrabmjJA5N hFCn+g6CvWL94y7acnimmEa16UEkFwi0O2yTDQKRzXg7U19UXZ4TQ9SrKhIGEK42X1bVt3YYOHx ItQhzXqGn7eamWQP3DwvZycWHFDh2QdtvfIIDxvzTufVpEzAGU9s3WkAyBDf6G2fU8IPTg/AyeQ vsOLlkbMhJdzRaJh/bv8vxVL1WgWq9IvM44PbQDpxJ3yIxSeH4XXlcmAq3tdVExK9CTv8qAhGTE fmd645/Kl6+YPG/2R7aeBrhOgxkOXrBC9oR/pao6Z1GZZEGxgisFAbevBOyeap58NZMluMBOi/Y liGBT/VCq5zzrgsQ/UFlnTLUEm/fJdG4z9JcltROzNEnfTbkN0jEJCH2rTxvxtW3p9ZiIAVpyo9 QKeJuFTppy3oSlVwTBwuKCe9U/CrDEGEDe0enVnpFBH58WRlTliKrCP250MOPcCPLEcdYImVsgs l+1CkE7P0l4N0bw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo VKMS has support for YUV formats now. Remove the task from the TODO list. Signed-off-by: Arthur Grillo Signed-off-by: Louis Chauvet --- Documentation/gpu/vkms.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index ba04ac7c2167a9d484c54c69a09a2fb8f2d9c0aa..13b866c3617cd44043406252d3c= aa912c931772f 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -122,8 +122,7 @@ There's lots of plane features we could add support for: =20 - Scaling. =20 -- 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. =20 - Async updates (currently only possible on cursor plane using the legacy cursor api). --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 A35831DF26F for ; Fri, 22 Nov 2024 16:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; cv=none; b=FQTH2lKiB0w6+6iIpU3r9YnBNYztWm30Kj9Ch3a7JAayPlqOwERwrp3HQAPn+J1Rz7q/L+rh0tAcVPzNocmnDnmiLkZzAhG/1u9LK01QZitrD9jgdNKeSeigTl2ZAA+vCw0u1jGZQoRgdwxGU/NvqZafEHdFg+dU12BJ59O8FCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; c=relaxed/simple; bh=axL606VOP+Vzkxig7OQTFfHk5EC8HgjRmS6iK/9rLyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RuGyqUxFCKqe8J5nAbuuF9ZPyw0UFYWat2mVRuwW86/Fp6JbDnGRUBAlgv8ru3bN1dEsI/qUDMzcWh+RM0x8jxtHRDU7DKUPdQChTRniXdJvC6QhCUcv/jC2d5c4Tf40yiBHLetXujcROWyMRGMDksNsQQRCSvNcABu2dg4abKs= 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=UnIVGG6P; arc=none smtp.client-ip=217.70.183.197 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="UnIVGG6P" Received: by mail.gandi.net (Postfix) with ESMTPSA id 57C7C1C0005; Fri, 22 Nov 2024 16:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292111; 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=7ROA9s97zr/TnBShjvPt9n/VC1Dc0gzXiBJZ5MkzKUk=; b=UnIVGG6PtfNfoD2S85gfD15bbQddp5DcxMxLSjc+jo42ZoF7rDgDZZ+UKCJwBBeIO5qa0b cp9SKt+S2HCeJOmhqtpQvA3a+JsaFDwAgY+x/LNZ0pRHfJ358ouzEoNOD1H/Yn20iibCee SxjjGrj6UTNygOaSjJhngKOlD5EUfld3MqdFkD239bUz1+IXfHKRlcLM2uU4EkqPGGA42V QrtkPRLdWm6kDosZ9ejVkocccsgkneGUnB54QgSCeHpu/dgPZqAgXOuNxS7ZecSZRdn7j6 Gk3EJLMrGxB5sNRdKk803tKprG9uhwF27L91Hv7vo8TFKgc6VRtGB/VJfHuusA== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:04 +0100 Subject: [PATCH v14 4/7] drm: Export symbols to use in tests 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-yuv-v14-4-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1064; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=axL606VOP+Vzkxig7OQTFfHk5EC8HgjRmS6iK/9rLyk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4HXt7kZyL9h/sZ3lKLwtcJhjG6CeuXVv49x fiQQp9OE0WJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuBwAKCRAgrS7GWxAs 4p3OD/40fJ6Kxjor7dbrBzKuRdnky8GURp/WOHla6m/iz7pHGwbKMKOUqaXODZk3BvtItDPYsOT D8/vJlZvdjQ1zEs215Hp4fWh3aPYUgU+Xdot3NQMQ6asW7vioyV50efOOO/5z+20UQ+OScGQm7/ cLNnHV9cbOAWlPZWXSU86o4NeiqakGcUuqqMEOXUKakD861zE1R3WN75yun8qX6T9Z8QQAoqYz4 O1nwBqSjIBtsIeF4IdnRG1zaioa39wpVlKyO6Cv0HSfKNCZvgIholyk+ec61JA1TejQh+9OQ0Aa 3i9GhQ0ALkXSKcjS3TOqVnCuWt1lv5moFQsqZpEjWWXkE5yq/lSF9Rswz7/tW7sAjdAa6FhAQ5W 92BbA/WBdF+u4PRsqM/hg5svwl4/aO4puotlM1ajtnZEijvnn5qxhQ/9aXzA5lu8OiZ3ZLiTwzA FGHPg4auCnpgFxB2DbALdOlP1BpKrcP8rPwGWROnf8DToMPDZkq99KTxfQiFi8TLSrrdF4ol5pV b8VAUOU0JZZt8jhiAoFJtgg73XXcQLyTgQVGmJEfXrnbVngiwWbIa60lHx51yabXtng39n1X4Ej MoVNVtgnj8tEQgoeCzNRsmi1CF5FxtcwlhtojHxWZo8mtMM+WXoI0dLQV0DJuzPv3TlkSjiHOXM w5yyDUKcmU2hvpQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The functions drm_get_color_encoding_name and drm_get_color_range_name are useful for clarifying test results. Therefore, export them so they can be used in tests built as modules. --- drivers/gpu/drm/drm_color_mgmt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_m= gmt.c index 3969dc548cff605cbdd3d56dceafb2ca00a5c886..509aa4325391340f8cfc50bd0fc= 277c48c889d3d 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -494,6 +494,7 @@ const char *drm_get_color_encoding_name(enum drm_color_= encoding encoding) =20 return color_encoding_name[encoding]; } +EXPORT_SYMBOL(drm_get_color_encoding_name); =20 /** * drm_get_color_range_name - return a string for color range @@ -509,6 +510,7 @@ const char *drm_get_color_range_name(enum drm_color_ran= ge range) =20 return color_range_name[range]; } +EXPORT_SYMBOL(drm_get_color_range_name); =20 /** * drm_plane_create_color_properties - color encoding related plane proper= ties --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 9742E1DF974 for ; Fri, 22 Nov 2024 16:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292123; cv=none; b=Rv0hl4RxDgZCkIGPiFL0EOIiPO3FmxDC2HtHy6EbQGB6Ql3oODjmgXpL4XfCY9T9VycCcgTn8fqy/rt/xgszzHqnerO1fStcvrckxNnhlWeB8evpMg1jHSz1Ilz5xrwlQPpg71CfjFGh/PL+FuCeFfqRBCD4Bv6Cu6jmrHgJqOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292123; c=relaxed/simple; bh=lanzwa7uQd2dq1WnL5/RSe7oqA47QKCr+LG82Ajh5t8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rvAhUFZ9Nijtgbk6d8Y1MAdZqlOmrmkr8tWfj3J1QOokDcr4nHF9wfvtSMvacBrIOKBs5dE+t5+RuM2xr0p6YeaS7SbYU92hA+Vj+U4NuqhsRceEsIpoN35i3kEKtUxRcqb5QwYt5L65m46zRMoYLwAt0sW92caMVydA08Od7HQ= 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=RanWX7N4; arc=none smtp.client-ip=217.70.183.197 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="RanWX7N4" Received: by mail.gandi.net (Postfix) with ESMTPSA id 62F0B1C000B; Fri, 22 Nov 2024 16:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292112; 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=KjrcxqxWYEGsMln6iyAVr49KF9gr9HWs0h5gPvFthYE=; b=RanWX7N4/RYGtPhAscVYBO/mL7jYXRm8rsr17pR2Ms/rstfiuk/Bn2BdLNRRCaYFWm5dnz ZB0/mZISAaTHy+Lw6p1uQnpZiiTUPa1LK+cRr7JrCC1ttaM5uoHldl2w6eTw7kwMjSHfLT IdO3SeApxNwZnDwGhuUjdsPbe9t5DY2JJ45sxj/ApOX21td6mzcMXo7R5EmdDfzH6wYvi6 wZ7CuZYp72xdeOt++T08ws3sTbGO5wGbY1aTKKV9FqgaTNTsuQNz8ndz4mFQmaMrrfdvlz Xh88HKgPiMFNbJpwQ9J+dt2+YOeTy+Dj9YD0zUi9WghzuUs9Sl034BRA/J7fVw== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:05 +0100 Subject: [PATCH v14 5/7] drm/vkms: Create KUnit tests for YUV conversions 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-yuv-v14-5-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=15885; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=lTwttDRftCz+MGppk5OGuAtu/rZkMajBmioh9zqJii8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4IL9THXgxwS36XSkuDIkHdWGcbF1HuDVk2K Z7OU4qgzSCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuCAAKCRAgrS7GWxAs 4vNoEADNExA85iLKVcVExOZj+lt80pAhzuCbvgXe+D7Eszdn1b+X8R+sMG9ZeDfCGcl28IKkvG9 Sc2dTeP0mAZloiFRTbtlsmc15Gjp3MWmjE9qDj1A6q9bCb+yPTZl1BUq9zk/HHTS9ZF+mzlJFhI ReqKPPFivAEjm9WakTIDq6TFM+tpSMnFzYtGGygycYehmja/pd3llUDsEAnVJ39OvZkXxreVk/V DpJ2GbjcWhmz63I0TaZxvkpQn3bEK83wQF8lfvZx4BsfllrpdsO1ezcWTNe6x+6YQgDIAvXRwDg lK7RWV597koVA8l/eAlxk/KKsdCH4k1O450r0Zc5alGfEsC/ToqE+fwJdq02H3hEcFFPel4Pn6V J6FN97a3s90FKgnPiTYN/LGO8Z68VwBMuW/mxCYJEUBmvzkcEXfZWGlLgmKnFfiaq8HAW3231E+ 46knC5llnKdfe0qOIcTjWUxD/P7OyW6ZAYmwvFPnRqcghNMzmrDMaO3Lvx3X86udyUy3K70x1o+ bI3z6JpSKSoK7KWyfW/Vnx141utC1AVxE4Kwl5hWxDzEM0Bx5AOBTRsownsMQvg3kK8wTWiRcRT ksdy7HlsFoYlWbzNn00h/ON/sCVYySsap+yS8ps/l8661QEMcnQtP3+vK4k80GI8K/WHUeDzzJZ OVNfGCmkGBJ/wyQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Create KUnit tests to test the conversion between YUV and RGB. Test each conversion and range combination with some common colors. The code used to compute the expected result can be found in comment. [Louis Chauvet: - fix minor formating issues (whitespace, double line) - change expected alpha from 0x0000 to 0xffff - adapt to the new get_conversion_matrix usage - apply the changes from Arthur - move struct pixel_yuv_u8 to the test itself] Signed-off-by: Arthur Grillo Acked-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/Kconfig | 15 ++ 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 | 270 ++++++++++++++++++++++= ++++ drivers/gpu/drm/vkms/vkms_formats.c | 7 +- drivers/gpu/drm/vkms/vkms_formats.h | 5 + 7 files changed, 303 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/Kconfig b/drivers/gpu/drm/vkms/Kconfig index 9def079f685bd30e1df3e4082e4818e402395391..d4665e913de7702fbd5c0f04787= 6dad9715c690a 100644 --- a/drivers/gpu/drm/vkms/Kconfig +++ b/drivers/gpu/drm/vkms/Kconfig @@ -14,3 +14,18 @@ config DRM_VKMS a VKMS. =20 If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "KUnit tests for VKMS." if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N". diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index 1b28a6a32948b557867dda51d2ccfdea687a2b62..8d3e46dde6350558a0aab4254df= 0dfe863f9c6ce 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -9,3 +9,4 @@ vkms-y :=3D \ vkms_writeback.o =20 obj-$(CONFIG_DRM_VKMS) +=3D vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) +=3D tests/ diff --git a/drivers/gpu/drm/vkms/tests/.kunitconfig b/drivers/gpu/drm/vkms= /tests/.kunitconfig new file mode 100644 index 0000000000000000000000000000000000000000..70e378228cbdaa025f01641f207= a93a6c01f0853 --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/.kunitconfig @@ -0,0 +1,4 @@ +CONFIG_KUNIT=3Dy +CONFIG_DRM=3Dy +CONFIG_DRM_VKMS=3Dy +CONFIG_DRM_VKMS_KUNIT_TESTS=3Dy diff --git a/drivers/gpu/drm/vkms/tests/Makefile b/drivers/gpu/drm/vkms/tes= ts/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..2d1df668569e4f243ed9a06c1e1= 6e595c131c4f6 --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) +=3D vkms_format_test.o diff --git a/drivers/gpu/drm/vkms/tests/vkms_format_test.c b/drivers/gpu/dr= m/vkms/tests/vkms_format_test.c new file mode 100644 index 0000000000000000000000000000000000000000..4f565ecb591c34b08d9df577860= 488702200a384 --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/vkms_format_test.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include +#include + +#include "../../drm_crtc_internal.h" + +#include "../vkms_formats.h" + +#define TEST_BUFF_SIZE 50 + +MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); + +struct pixel_yuv_u8 { + u8 y, u, v; +}; + +/* + * struct yuv_u8_to_argb_u16_case - Reference values to test the color + * conversions in VKMS between YUV to ARGB + * + * @encoding: Encoding used to convert RGB to YUV + * @range: Range used to convert RGB to YUV + * @n_colors: Count of test colors in this case + * @format_pair.name: Name used for this color conversion, used to + * clarify the test results + * @format_pair.rgb: RGB color tested + * @format_pair.yuv: Same color as @format_pair.rgb, but converted to + * YUV using @encoding and @range. + */ +struct yuv_u8_to_argb_u16_case { + enum drm_color_encoding encoding; + enum drm_color_range range; + size_t n_colors; + struct format_pair { + char *name; + struct pixel_yuv_u8 yuv; + struct pixel_argb_u16 argb; + } colors[TEST_BUFF_SIZE]; +}; + +/* + * The YUV color representation were acquired via the colour python framew= ork. + * Below are the function calls used for generating each case. + * + * For more information got to the docs: + * https://colour.readthedocs.io/en/master/generated/colour.RGB_to_YCbCr.h= tml + */ +static struct yuv_u8_to_argb_u16_case yuv_u8_to_argb_u16_cases[] =3D { + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + * + * Test cases for conversion between YUV BT601 full range and RGB + * using the ITU-R BT.601 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT601, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 6, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4c, 0x55, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x96, 0x2c, 0x15 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xff, 0x6b }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.601"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + * Test cases for conversion between YUV BT601 limited range and RGB + * using the ITU-R BT.601 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT601, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 6, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x51, 0x5a, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0x91, 0x36, 0x22 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x29, 0xf0, 0x6e }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + * Test cases for conversion between YUV BT709 full range and RGB + * using the ITU-R BT.709 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT709, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x36, 0x63, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xb6, 0x1e, 0x0c }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x12, 0xff, 0x74 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.709"], + * in_bits =3D 16, + * int_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + * Test cases for conversion between YUV BT709 limited range and RGB + * using the ITU-R BT.709 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT709, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x3f, 0x66, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x2a, 0x1a }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x20, 0xf0, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.2020"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D False, + * out_int =3D True) + * Test cases for conversion between YUV BT2020 full range and RGB + * using the ITU-R BT.2020 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT2020, + .range =3D DRM_COLOR_YCBCR_FULL_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xff, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x80, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x00, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x43, 0x5c, 0xff }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xad, 0x24, 0x0b }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x0f, 0xff, 0x76 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, + /* + * colour.RGB_to_YCbCr(, + * K=3Dcolour.WEIGHTS_YCBCR["ITU-R BT.2020"], + * in_bits =3D 16, + * in_legal =3D False, + * in_int =3D True, + * out_bits =3D 8, + * out_legal =3D True, + * out_int =3D True) + * Test cases for conversion between YUV BT2020 limited range and RGB + * using the ITU-R BT.709 weights. + */ + { + .encoding =3D DRM_COLOR_YCBCR_BT2020, + .range =3D DRM_COLOR_YCBCR_LIMITED_RANGE, + .n_colors =3D 4, + .colors =3D { + { "white", { 0xeb, 0x80, 0x80 }, { 0xffff, 0xffff, 0xffff, 0xffff }}, + { "gray", { 0x7e, 0x80, 0x80 }, { 0xffff, 0x8080, 0x8080, 0x8080 }}, + { "black", { 0x10, 0x80, 0x80 }, { 0xffff, 0x0000, 0x0000, 0x0000 }}, + { "red", { 0x4a, 0x61, 0xf0 }, { 0xffff, 0xffff, 0x0000, 0x0000 }}, + { "green", { 0xa4, 0x2f, 0x19 }, { 0xffff, 0x0000, 0xffff, 0x0000 }}, + { "blue", { 0x1d, 0xf0, 0x77 }, { 0xffff, 0x0000, 0x0000, 0xffff }}, + }, + }, +}; + +/* + * vkms_format_test_yuv_u8_to_argb_u16 - Testing the conversion between YUV + * colors to ARGB colors in VKMS + * + * This test will use the functions get_conversion_matrix_to_argb_u16 and + * argb_u16_from_yuv888 to convert YUV colors (stored in + * yuv_u8_to_argb_u16_cases) into ARGB colors. + * + * As there is a different range between YUV input (8 bits) and RGB output= (16 + * bits), the values are not checked exactly but ensured that they are wit= hin + * the uncertainty range. + */ +static void vkms_format_test_yuv_u8_to_argb_u16(struct kunit *test) +{ + const struct yuv_u8_to_argb_u16_case *param =3D test->param_value; + struct pixel_argb_u16 argb; + + for (size_t i =3D 0; i < param->n_colors; i++) { + const struct format_pair *color =3D ¶m->colors[i]; + struct conversion_matrix matrix; + + get_conversion_matrix_to_argb_u16 + (DRM_FORMAT_NV12, param->encoding, param->range, &matrix); + + argb =3D argb_u16_from_yuv888(color->yuv.y, color->yuv.u, color->yuv.v, = &matrix); + + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.a, color->argb.a), 257, + "On the A channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.a, argb.a); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.r, color->argb.r), 257, + "On the R channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.r, argb.r); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.g, color->argb.g), 257, + "On the G channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.g, argb.g); + KUNIT_EXPECT_LE_MSG(test, abs_diff(argb.b, color->argb.b), 257, + "On the B channel of the color %s expected 0x%04x, got 0x%04x", + color->name, color->argb.b, argb.b); + } +} + +static void vkms_format_test_yuv_u8_to_argb_u16_case_desc(struct yuv_u8_to= _argb_u16_case *t, + char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%s - %s", + drm_get_color_encoding_name(t->encoding), drm_get_color_range_name(t->r= ange)); +} + +KUNIT_ARRAY_PARAM(yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_cases, + vkms_format_test_yuv_u8_to_argb_u16_case_desc +); + +static struct kunit_case vkms_format_test_cases[] =3D { + KUNIT_CASE_PARAM(vkms_format_test_yuv_u8_to_argb_u16, yuv_u8_to_argb_u16_= gen_params), + {} +}; + +static struct kunit_suite vkms_format_test_suite =3D { + .name =3D "vkms-format", + .test_cases =3D vkms_format_test_cases, +}; + +kunit_test_suite(vkms_format_test_suite); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Kunit test for vkms format conversion"); diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 1f3ce4f334be9560e62c9a7fd933fa0ed6640e8f..0b867444999105262c855a24bf0= 3bc66d9ebea1b 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -7,6 +7,8 @@ #include #include =20 +#include + #include "vkms_formats.h" =20 /** @@ -247,8 +249,8 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const= __le16 *pixel) return out_pixel; } =20 -static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 c= hannel_2, - const struct conversion_matrix *matrix) +VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 chann= el_1, u8 channel_2, + const struct conversion_matrix *matrix) { u16 r, g, b; s64 fp_y, fp_channel_1, fp_channel_2; @@ -278,6 +280,7 @@ static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y,= u8 channel_1, u8 channel =20 return argb_u16_from_u16161616(0xffff, r, g, b); } +EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); =20 /* * The following functions are read_line function for each pixel format su= pported by VKMS. diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkm= s_formats.h index d583855cb32027d16b73d2a5b5a0644b13191d08..b4fe62ab9c65d465925d29911f2= 6612193a80799 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -13,4 +13,9 @@ void get_conversion_matrix_to_argb_u16(u32 format, enum d= rm_color_encoding encod enum drm_color_range range, struct conversion_matrix *matrix); =20 +#if IS_ENABLED(CONFIG_KUNIT) +struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_= 2, + const struct conversion_matrix *matrix); +#endif + #endif /* _VKMS_FORMATS_H_ */ --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 253F71DED76 for ; Fri, 22 Nov 2024 16:15:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292117; cv=none; b=qB+eSmh0vw/koFTTTJ9HrGVGcBYyDqGmOCwcZrZyjphtZM8oiJtsKtWcZlqON7DcnsiyzrQS7hVqHo03XhqkqjfE0s1kSXgtwmSf9V/tFMIk3+25xdIodcOZdokBapfwSHX3BPPUwf2tKk0RwzOxbLq5fSxPgcr2HjMl/UXdp+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292117; c=relaxed/simple; bh=UVavjxKhGJ9/Mx+njM6iq8QUM0yoeq/APHA6FGXHkJg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gU3/7yoUSrqZJU33fFPYwi69pGoSbcH9tYnPPyoUEtjVXpxA511lIJLB3Wh2nbCID/AwY1Ijl8jfO15wbNlfg40ycrlG5ETJNAmIHPDzjZZwPTmZuzC7O2TkFJP+MzTcLakwsYxR1JTAPQHxZYuZVcHsqxBEtC9ziFqND8l2pZI= 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=SkVNJBJX; arc=none smtp.client-ip=217.70.183.197 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="SkVNJBJX" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8DF0A1C000F; Fri, 22 Nov 2024 16:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292113; 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=PfHoqEBmoVIVQo1Iw5eRxgKBa4FOCahU3iIkG6Ku/Eo=; b=SkVNJBJXxKYgIOc9BwWh6Xjl5oit/A94GpPF5zdXIWsEki+OwfLHPwusXqk8qG+DwpU87T FddI6Q1AHwd908TX9Gd5tj+koHeILJmxB9e0RpfjPpCqGLylIRIIx6sIRQn4iV6KDsDNH0 nEQ8WbbCO/twKPJylTkoY0z0XXx1Eqi4BOBX825TVI+2gFZpbW24ZMlEQOUGow/2c3+y4w B41Rg24Il3D3TNJAV69g8CjcevwIUejpAY2tUk+NBfJ2KaaxWaogaCxDi6z2UcqW7mdMFK aj8zepM8h+IQj20ci3ljWEMa4eN5sSiuvg8aUD/Frb1KfxYijenwbPTBqLMJkA== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:06 +0100 Subject: [PATCH v14 6/7] drm/vkms: Add how to run the Kunit tests 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-yuv-v14-6-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1171; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=KcZXKbnDJcUNaO/ryK3mrQAB5uKi2etnbYIX4nCF2Hk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4Iv/OP2lDMDsNSQsMOUoHjXv/gzq0HVDkz9 TiaJefBG7OJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuCAAKCRAgrS7GWxAs 4pcPD/9zvbPt0PRgMxyU9gNTqj23mnbl5cQ+bwA6Ejill6Iqk2wBN3m0OCvwQ0vshvxvKX20LsT pY8oklqWMkaod2/KxEUD6Ht1AFQRxoQQ2Y33PmcsYXIkHOkadPAj7RtsL7wL8a2CZUD1qcnzvpC myFdbjesALlgpJkFUAzO2CUGGgDP1eCDhvEgUDCRUZ8Um3mpP+iSxOF25DTo3p6+IsUrWpholnj Sa6GLFyHcil7dry1XtWUiU4i6pe6S5jT3g/jsyoxg80iZctsVf5DvxFLN50KkbJjGgzj8PJICNo O7wKiEQiOWDscDxMTk63SBA/cs1f6Wrbnyd9wXz69GBtuvmTvKAXwSFTwP0oytbPxjtTPWBgn4P j/+gBC/eJmBKhEGwH4dn3q1PpVgNDEqkNZsZUutudUC0sU2NdFNqKJAlu/+imO2kbZsUfZqxHMK rMk6csPY0Dn4jPwBZ2vvgVS/6vdJFkZoqItXz97XhxewIOoaeZOzLRdsoZ9VCeLbEA2BEKAhx8Q MQ88qaX6S7FLaF1wggFokgKEoyxHwHRJI3bYekIXVrYGSL1nX0C99ByC6cHuoi0RT245iWzsAMT 8JxihdFKVraz5YvJmSqS9kIA8rePbAa5YN09BlzATchfRXYjK2HOTcAgaWxw14zIzCK7cQAKY8P nuo+ZyDkzw15QLA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com From: Arthur Grillo Now that we have KUnit tests, add instructions on how to run them. Signed-off-by: Arthur Grillo Signed-off-by: Louis Chauvet --- Documentation/gpu/vkms.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index 13b866c3617cd44043406252d3caa912c931772f..5ef5ef2e6a210382a070eaf3552= bbce75b04ff0c 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -89,6 +89,17 @@ You can also run subtests if you do not want to run the = entire test:: sudo ./build/tests/kms_flip --run-subtest basic-plain-flip --device "sys= :/sys/devices/platform/vkms" sudo IGT_DEVICE=3D"sys:/sys/devices/platform/vkms" ./build/tests/kms_fli= p --run-subtest basic-plain-flip =20 +Testing With KUnit +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +KUnit (Kernel unit testing framework) provides a common framework for unit= tests +within the Linux kernel. +More information in ../dev-tools/kunit/index.rst . + +To run the VKMS KUnit tests:: + + tools/testing/kunit/kunit.py run --kunitconfig=3Ddrivers/gpu/drm/vkms/te= sts + TODO =3D=3D=3D=3D =20 --=20 2.47.0 From nobody Sun Nov 24 05:48:39 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 635671DF258 for ; Fri, 22 Nov 2024 16:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; cv=none; b=jMW0hgv7dyz69MnBQJpq9mYBndN5EyFtXpzRDsEDStrTKyW03DrI0/cSf+PvZtOstbSFgCW6qHKtIQOkRILVzbARPwTAO9lJXupVh+tCkosZjSlCapVmyz5JRzb2zmydalJHbz6nWqT9bwOLE+cspS7qwwjZ8Qqhywue+hDp/JQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732292120; c=relaxed/simple; bh=nNEd7ScqpP2u8LOKBJlSl+nk9HqJjsqERZrBxXBPTzk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NerQmQCfASDJZLzl/jTPuAYwr39AokA3/7OAuj9yZqikTSd7nUqm3PdPwwF1XWaHlB6+2Pf7Kq6d5N0VMpxA2Kcqty5lBcCT6DcJJSD/b8Vp+tou1M59ROW7q3RSr2xCJ435ZFQgn6k6YwlkLWViIPrbV8J4Hyz0F/17wFhQx/A= 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=mZhdzTY4; arc=none smtp.client-ip=217.70.183.197 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="mZhdzTY4" Received: by mail.gandi.net (Postfix) with ESMTPSA id AA5471C000E; Fri, 22 Nov 2024 16:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732292114; 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=tEX5KIYM9MGflL3kKigU/rlvGYRABpADnL5AEt6CCt4=; b=mZhdzTY4BsMeEBS8IZhX7nUAKfzk2spYzmaTuhTMqNe2iFFU09NjfJA3En0/Hn1uynoloe FyGGMgcGI9CUzyboWYhzQTGs8durPzjyGPV/0DcLxCX6neybMT3Y4lL0c1G3OudzNfci99 Nx5hIqbov8HY7Pdmo5b8HVEhcxVSYTrJPoo256rVjuj7fuFB2eC4dViL2L3DWP6LeX2gaC 38ELomd4piypl9h7HzrSQveLSdJUW1iUQBZCcNREKu6QSc+4bIf1eXFtaUgSYpYHc4EJAv po5616SmnUWye1EPIEsgEu4AnOQ8r4EITMArWf14lOOZqW7W0v0dafqP/K4JzA== From: Louis Chauvet Date: Fri, 22 Nov 2024 17:15:07 +0100 Subject: [PATCH v14 7/7] drm/vkms: Add support for DRM_FORMAT_R* 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-yuv-v14-7-e66d83d28d0c@bootlin.com> References: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> In-Reply-To: <20241122-yuv-v14-0-e66d83d28d0c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=6494; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=nNEd7ScqpP2u8LOKBJlSl+nk9HqJjsqERZrBxXBPTzk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQK4IFfPn0B2W772RleqAdPtJ9DER/GqVvo0QB x0ukqE6dLGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0CuCAAKCRAgrS7GWxAs 4vbjEAC13yENEnBWEYPznmMXxOb1PdgAdgCFXkw5nrQ+PAe6uSFrqblEanzTMh59NAmIelNYCn+ YA1yyITGFiMYRkGDeL3o1v5ePlkqzkdqKf+ZQXFu8h9gftysrp1Deb2wmZFdRvtUJcspEHplfnz Mvx/xneml4F2M4keASSGUWLs/mYjUrJguVtUxQ0PS8iVJanfZKB4WkFReoRwihUh0aE1g6iAWf2 YByDs5s2XwqP7QZSAchgqq+OJ1UyOrNFs7PRgAHinGBy+MnAn/DOfdCTfAjhCupc+8QQSlbW83U 4/h0nflidvzJ/rmG/ta1OdoTpKlCGyzwV0cIhEclSV/GHQRjswp853eWfZi4JLtSSS8yWZ9NJKp 2KczI5osl4aqaW79z90TED7krv5RPS0lcfG6oWoMSfp+Eb10mnmSDqbu3nvQcseTvYVZ+0V/crf x7A8ofxwd7M9umMEVgquREe+Knq8LscnKTK0d6/omlIbtieT3DwOOPuEMXYy7ezsZ0CJ6b09t9m /VbsSCYQvuRfYuvdz00kBVeOBg3FOdlkAjfw0ge0PViTCXVvfWbEoJWUrskupdXI9XvB6u8JhbL GXd2U6DxlELet+EQUffKxn04tRNPIBSfx7ggwlJfiC5z93M9TFhTd5nFOaBhGL4dfq9XQoMFgdp yFATvSLRq8wvRPg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com This add the support for: - R1/R2/R4/R8 R1 format was tested with [1] and [2]. [1]: https://lore.kernel.org/r/20240313-new_rotation-v2-0-6230fd5cae59@boot= lin.com [2]: https://lore.kernel.org/igt-dev/20240306-b4-kms_tests-v1-0-8fe451efd2a= c@bootlin.com/ Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 110 ++++++++++++++++++++++++++++++++= +++- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 0b867444999105262c855a24bf03bc66d9ebea1b..2edf1ceccd37ad3a2f9f6d2dcf2= 044c98d9e10f0 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -249,6 +249,16 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray) +{ + return argb_u16_from_u8888(255, gray, gray, gray); +} + +static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray) +{ + return argb_u16_from_u16161616(0xFFFF, gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 chann= el_1, u8 channel_2, const struct conversion_matrix *matrix) { @@ -286,7 +296,7 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * The following functions are read_line function for each pixel format su= pported by VKMS. * * They read a line starting at the point @x_start,@y_start following the = @direction. The result - * is stored in @out_pixel and in the format ARGB16161616. + * is stored in @out_pixel and in a 64 bits format, see struct pixel_argb_= u16. * * These functions are very repetitive, but the innermost pixel loops must= be kept inside these * functions for performance reasons. Some benchmarking was done in [1] wh= ere having the innermost @@ -295,6 +305,96 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ =20 +static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + int bits_per_pixel =3D drm_format_info_bpp(plane->frame_info->fb->format,= 0); + u8 *src_pixels; + int rem_x, rem_y; + + WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) = !=3D 1, + "%s() only support formats with block_h =3D=3D 1", __func__); + + packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &= rem_x, &rem_y); + int bit_offset =3D (8 - bits_per_pixel) - rem_x * bits_per_pixel; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int mask =3D (0x1 << bits_per_pixel) - 1; + int lum_per_level =3D 0xFFFF / mask; + + if (direction =3D=3D READ_LEFT_TO_RIGHT || direction =3D=3D READ_RIGHT_TO= _LEFT) { + int restart_bit_offset; + int step_bit_offset; + + if (direction =3D=3D READ_LEFT_TO_RIGHT) { + restart_bit_offset =3D 8 - bits_per_pixel; + step_bit_offset =3D -bits_per_pixel; + } else { + restart_bit_offset =3D 0; + step_bit_offset =3D bits_per_pixel; + } + + while (out_pixel < end) { + u8 val =3D ((*src_pixels) >> bit_offset) & mask; + + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + + bit_offset +=3D step_bit_offset; + if (bit_offset < 0 || 8 <=3D bit_offset) { + bit_offset =3D restart_bit_offset; + src_pixels +=3D step; + } + out_pixel +=3D 1; + } + } else if (direction =3D=3D READ_TOP_TO_BOTTOM || direction =3D=3D READ_B= OTTOM_TO_TOP) { + while (out_pixel < end) { + u8 val =3D (*src_pixels >> bit_offset) & mask; + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + src_pixels +=3D step; + out_pixel +=3D 1; + } + } +} + +static void R1_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R2_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R4_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R8_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end =3D out_pixel + count; + u8 *src_pixels; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + while (out_pixel < end) { + *out_pixel =3D argb_u16_from_gray8(*src_pixels); + src_pixels +=3D step; + out_pixel +=3D 1; + } +} + static void ARGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]) @@ -606,6 +706,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) case DRM_FORMAT_YVU422: case DRM_FORMAT_YVU444: return &planar_yuv_read_line; + case DRM_FORMAT_R1: + return &R1_read_line; + case DRM_FORMAT_R2: + return &R2_read_line; + case DRM_FORMAT_R4: + return &R4_read_line; + case DRM_FORMAT_R8: + return &R8_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_= plane.c index e6ca8f2db32d92068ddba7eed92cfae0d28cd45f..81941914af87fcefb180dc393f2= ec311f1a1d3fa 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -30,6 +30,10 @@ static const u32 vkms_formats[] =3D { DRM_FORMAT_YVU420, DRM_FORMAT_YVU422, DRM_FORMAT_YVU444, + DRM_FORMAT_R1, + DRM_FORMAT_R2, + DRM_FORMAT_R4, + DRM_FORMAT_R8, }; =20 static struct drm_plane_state * --=20 2.47.0