From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 4183419F13B; Thu, 31 Oct 2024 18:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; cv=none; b=uzlztOxoudAFqCtPzoBC1pofetVUfAWEK8Ss0h8KgbR2OIfbsI/jHVoUrHFpTtiPdW87uTZER8Mqtug7wSaOno3YaIlF6f0/OepEDOflvynFuRGER1tbOdFPtjNfIqBYE6e6cfyQGeUzdDI97ZguATNSD6cff8WOGPWzQYf84Y8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; c=relaxed/simple; bh=/CnKcRoy2zzniLdXoudcf5h1SXIo8EK5hX/PNiu16Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=j2dgbr2ZlRq4Q9TCztHQSnPQyLbpjezKFiZthc+zvC5sjzROYcfVYg7rmyQ4aPxhjeGShzYmDLNLxK9LYefoDAG6D5VbLXxdVnrZYiFa2gmoiD4ft+qXXm85m9ysBamcqWqsFw4E0ZTcb3vTzB+ZVVDyECpchtnK4b4/aB+ptEQ= 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=NdJqkCjs; arc=none smtp.client-ip=217.70.183.200 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="NdJqkCjs" Received: by mail.gandi.net (Postfix) with ESMTPSA id D0A652000C; Thu, 31 Oct 2024 18:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397971; 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=bqUdHNzvsNs0NM53sXaQxXz2E0n3SnQyNT/O9oJLiLs=; b=NdJqkCjsGcVsB5JdfjHQbd8iJm1RgsbmQkVswRQxMYBrjQrcWfsoAZIW49+NqDR4yvtBFW F83cVgrVfNgPk9OdhdV1JEjqjltKIZxYmYfubCLMOwtAUdVjrTck1nUc5NlcT3gicCETE7 mbjqn4uJbczRuYXblYrYs84AELMl6DJWOWF9/6H2ts0a7LDrMcF9nEP7hkt/KKOMrbN8bn 8hn7P57051eLPDoRZ7iq4S1JmEig5MEX3JRzAnOrtOIg6n2e4p8FFEzmGOPZd4cpbp8Xas GB5oyNdsm2L/BXUM/U+GET+Sihr7dHhSXp+iN01P4XBVjM1wjjX9cfmVeSgCUQ== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:01 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-1-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=18710; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=gMgum11zQDjELLviyW4+/LCQ02/qwVenadipsHpvrMY=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cNNktcgt3RtGsEyPZTIh1y6vtK4WX78ofK6 PAVHuV/xZiJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDQAKCRAgrS7GWxAs 4q0MD/42Z4PlTZ0Gi6985dkZ6pIl/qE2095T6HRSYVqPrqvJPbkYCpcrnBytI6lzaN+Ux+nv7SJ M3RWBkXdfHX4mtl6c9zVoUlc5DrDsY8qBM+ec45biPDZKLqDuu6npR4J7auy+eD9lGc8oKdhzs4 GA+pLrGRlX1CvwJaw8Elo0DZYATMrW3HHQ8lZwwQ8BwnCcYkZZPNNTWYSFPm/yTw2Xy56/oIqJQ 82mNhM7WYhg9ublVEt9LdJ+3Xm7XXKrL0GkZjVoUNi7RBGtE9LiMAZ+AOHxasxhqfvM/AlkSi9N 07vWfJ1/lHv3Nyj+0qSHOs681ljG+ldICYjN8790s5P9B41WBaj3yU8RAdpSh65aD+UJqv9dzYV /v67YpnqXSHg+YK0XpsbRlII3aWq36DlOgJywgzjrPxskbkxrSYDi6W5SOsCaJjm5u5A/qxY1mF BhzP0k2JyV9XLNu3qVlmy7n/b1lNRVgj1FOUJltNgenke4b4uhU4qJNgkrf4L2wKP5NI6xV1z3M g7QianlHLN1P64ToitLJaPT3VR+r+TTniSw7dIf6rBWO/nsQk477IxkWb3s76/ThOIqRrLeHISu fhXtXRQAi6P8Fndrfr+8QQT3oQdtgzGL/BFhvMO2TcEUCS9LpiZRyVsh31rdSilB6g9/x2up6FP ickb26DrnIIGPpw== 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 067a4797f7a0..337ca3f39cd2 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 0f6678420a11..27865261f384 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 8d2bef95ff79..d583855cb320 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 5a028ee96c91..d4e375913122 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 642631BC9FB; Thu, 31 Oct 2024 18:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397981; cv=none; b=SrkMpr9VhQicX1nV3WFO/k0eBpHIKh00NnLhk8khiax1xCKM+rFWGk2sQuYn5vWN2RC4XJodfe7BdrrlIWIBuSAfI6Rmynqlpo9OlPNlXAhGdf3aNT1XYXl10NBBeTtDCqUM0aWHX10MZtuJL6IS5zIHSspKildqBKpdcPX4NhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397981; c=relaxed/simple; bh=gkogr80zC9IT6ygCMxlP62nYp/y4G1vFYorCtQOD8gE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H+Hkr2CaMXefR4VkvrNt+ZbmvyfFt5ukyeIl63oF6VvrXIS4GRbrDsO4N3F58znemD0f3arkJByRxjSt+7mOXuILd60LCYkk6Q/HdpBbH8MM8Z0IRT8gsZfHVwzKiU+FDeWnCxhiy+COwKBAlh7O/DFwrpaUoHy3uToNHUi4HmM= 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=jlRIbD0k; arc=none smtp.client-ip=217.70.183.200 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="jlRIbD0k" Received: by mail.gandi.net (Postfix) with ESMTPSA id 2FA0220008; Thu, 31 Oct 2024 18:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397972; 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=LZZXCAOt96HKPNadssGl+s0w7QDIgwJlOE/lg2YiDu4=; b=jlRIbD0kwP6r8oFTiga7Pr8I3OkMIKAE1XLHqvFA+2nnFUPAmrRrcejX0mObsFkWc9xrjZ Z1VAGUo9qngDwZq0d2SGfY/PYPe86/UQzeIGdoCRNHp6SYaWa1HlTnINGVSpFmnqF0os9F j/TGAkZygsAXr4IQ2dDcJYlDGjWpWgzYO8r8LBjrTetUoephf2C9eElDQ0iR8IiWkcCy90 4CWmtxVRQaTTsiSy8OtL9y2xSoSJQlGYtps/Z9SHRb1HdEzK5uJ/8Zh3eepgQy06ZrVm8l FGcNHGXgDyhbNUzsmh6kkDQxY7o/06TPVghdl2Uurq9ricpCL5BkfJMA5WYigw== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:02 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-2-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1253; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=VB/TChUFVIfTCJz1NYTIIebS+nzvAngxAg3Yry+8p1o=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cNBzYvzdbEW+ukdVx3vI8o0dy2hxpvtBt5b acKMa2/GD6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDQAKCRAgrS7GWxAs 4hkpD/47cr62P6N7DyPlN+SqvwNwKOTNrofNbtuz+ngN43gdpj8q6M7zynzIqIXO0GL2DnKLUcW q34/iKYIkZ4B+yVVzsMIQw3l/g2CTRGXNgORU9RGxKnZSz+/B8DcPl2NrDVy1wjhb9NIUQ3E3b2 G7mJBYpqqfR5qgiiu6ca6cZKIuTkMgx9khImtBEtnu+3k8/wRPCk7F3iwfFNSufNDhSz6qq2vNe XHPkHBaTv3MtmSOCpQ405klhswJepoK0Avr45uH0dRuOz0tC5NritQJI8tQWMEBVLHDkWIoQsj6 YNsd4Xd8miAvRU2qkxnrDc5iVIKQ0sftnrAGzqNUzokAQU2fI9H9TxApV9Pz4ypwAiWj/fuege+ uvEQbOReFlkS+0ZvLj4Q/aO7lFa9BYa+2tsA8PgS2tEh0nG5XBrSBSJ0xTI8ctMTf9YfMAFaxqY ZQDDKNCHf+bgtNJhC+Nqff/xABanfbJjO2wTL0Y+Eddzvcpt5/I1qmOnUDx554iwEdOix6oTeeJ 9OBltfdOlir+6J9dPYE8inlauXjtHCVpAzc9CEbfXDlkiSzVYS8qceoZjjwMtVUsISg6gGdP0zq IbnDRo5QfiiyRep7rDk9n37lOafnDlCJ4VVTbA16F5w4BuXJYKB3gYTQRHOtymYi34qf6il5v7o Lq0+iUX8jPZ3Rpw== 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 d4e375913122..8f764a108b00 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 57FAE1C57A0; Thu, 31 Oct 2024 18:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397983; cv=none; b=bkE9ihBTHSuHLCMZ8PzoAbMEa0m+18dss/XaxjFiVXncO9I3UT7hYUW1Y4fDw33PlypWsCD+M3/FFBW5bRtr5rrwAQV7b9TT0OUCWdhUFbka9XvXVb3Z9lDw5kEDfW61aBtXWw9yo8ZlBRgZPTPjxq3SHdlOl2PBvCwORZUuhhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397983; c=relaxed/simple; bh=OY3WebhRv0aeGADgqvUb4/UTEnKrmR0RzKDlWJXZa2E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dbtbF9DGJkmSN/HPVRZnctgnC7g59r9KJwmLUFRD3R06hGmXfPWpwxSbd6Z04j6c11SGGsB0jhqrZJJHsV63bPpJ3BA5cKRHanEoTviooCSMuR6staRxVVtTAiYAJB15cqDrNmLOMSujaXPy0c+PU9VHthmNF5Mu46iaMmBWTAY= 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=DPQD5qUk; arc=none smtp.client-ip=217.70.183.200 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="DPQD5qUk" Received: by mail.gandi.net (Postfix) with ESMTPSA id 831F22000B; Thu, 31 Oct 2024 18:06:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397973; 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=hsQ2CTA2pljllkiENrEWMPdAOoEF3CDQQvjJFAj8G3E=; b=DPQD5qUkYkmp/uTYcGSpBlp7CYk0GB6U5ar80NulIzYl9Y49YCPnhcRuDrknHevkSUVm1L 9VO4T0DBrYCHrtO/gtFq6XAG95mb9mSiQbAWaRE55jvXBfUEE4++AXZbtCP6XW0NyPR7pJ Ieb7g4P485uhxVZwTlSHFam9SsF4RJeB1Tlj6NpjzWMPbuKwCWsNXuG4Tj6FzphJ+o9msk LgraFgyO98FwJ5PT2V6aOJmtFD4nRhYRyrggt0Gkcj5QoTXuHHBDcdIkV6NWx3aU9JWGkS 2rhAPJmz9I7UQBdHpb5CQixRD+wmwhi6e4R6CZYRmzwl/KpNBjYuOIxsMW3O/g== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:03 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-3-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=881; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=P2BW0rn/HzAIDwl58Rwi6B7V7fHRrzFFCT1b251G+Ng=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cNTg7Vuqg944sB2+yE/4NQDuaF8i/v33e2M TxAZd53WzuJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDQAKCRAgrS7GWxAs 4i+4D/9+eY7dnehTONtd/+40Vi4PhyrB8h7laI5EeVBfEFG1vvcV/Q5W5VdtDTKPn+hEb+JZmkR NVe7SmjHHjApdudPYlEB+6wMgE/igdXbuu0qXL9vGhFfDASuD3lIxVeRCghZjLho0ZGeyDb1TSu O34LB2lpUpAUmgnoCqeHl4+Nl5Vt4adS7NlxG814SY4lra1o1N8T5UtSUSqo9g3ndbWfTm/MJqx 4W+rkJSUZxf72V23MAM5mT+6XTCtP92D1vYN+H9yPI0xSspyfEmyblGLH/Q8W7OI+sgVVKbH4WI N756sKHtglDAT0uVcTgGOcDp9UQD6n3OcFhWmtILXhPkCE+mhbJIDTRLaFRW4prlwJXOV8c1Gkr xgeqpDpE5mnijB3zCnWh6Z3UXnT8FHVAaL4F7xMX7jiN2DyFoWaAdFqyP0opMcpp8F7FpZxHQF7 yNVxkhqRzvLSOtXRWriIQazObUw9CHyId9g/qYwFlcgDe4bW1GMTK/c4u5h9Y6h4qdGZNoVDsDA ziTsbTIgWQK+6m1mh21/weiwzJuB4fztM9m1OBPt53MhQlo+Q+kGGzhvy3Tw7cfUiKvdMknRhk3 R2neb1AP4t8Cwb3wPRLNErieXXE2cq+IocgLhul74Lr5Il7i7IHAUyzGEAL4cXx8OG/S7OTYjVU EyireR2ErzDnkXw== 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 ba04ac7c2167..13b866c3617c 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 5297C1C9B98; Thu, 31 Oct 2024 18:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397984; cv=none; b=k7Hjp0m60PCs5PDAZraEep7sdK2NEysZRXT0nci9K7VGQ5jhWeWZJayWkDanuClLytmsry95tmu4rZ7w+9P7/LF/Mbtbh/8ASDlfzSimsayO6DlGlBK8zfKFZ+y1+kWqMlGg52WbnUWXvheDBnTqAg8apV+UJHC28HD85cNPqLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397984; c=relaxed/simple; bh=7tjRMSUn1ff+jaTKfg3LLB4Z1WdxYK0a7+YdSZB50Ws=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mYQ28rhvSXnEImAZP1UP9TOlCXzHcJ4w4O3pYjSigePWUth3kyHsi0FpyCx48LPjsmfC2nbdROILKcE7mMxZIBCS0RFyDBJIrfeK0oFQTuFgxfC72AtL14stUPSWEbWxFLlzB9O9i9mCrKiN2xf5aWmAo76LDDPMQ0c0M8Y0HMY= 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=AmTC2Nb5; arc=none smtp.client-ip=217.70.183.200 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="AmTC2Nb5" Received: by mail.gandi.net (Postfix) with ESMTPSA id C853F2000D; Thu, 31 Oct 2024 18:06:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397975; 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=WnxB3DYHE4hlot0SiDmuaPnWv/Qs3ZnmMdNCEu0LXW8=; b=AmTC2Nb5X/r7SKiLz0cluzgtNgcCtelTLxq+FfKqJe2ZQdwXI5WBU9wVu+QjOqOpWt1z03 SUBfqt3By3meI/Kq3dwBqll2/SsmJfGfjLTvVpwPWDCOUxeZgxeo1LatPfpZcNYeBY4JwE qtyqWn09SCfQGjSxpXY8eOJ6y2HXRLnKUZjUiGKv68UIACOjckvrPzHM/LRjitd03gZsSY tB0lxlqXOBbrLAmR8SBx1R0uwNLEpMrKngFrWNMuOuKbPk5rxg3GFOxSLntu2UsYaNM7Z1 DYMEKmVqJjpBwjg3RXFMGx2OBnX9xJ71ZcOCQsq73BMG++vriZc5ZCtsmARdww== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:04 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-4-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1008; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=7tjRMSUn1ff+jaTKfg3LLB4Z1WdxYK0a7+YdSZB50Ws=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cO4JrWkuXTajcS3TwlAWUM/tx0YtbPwUmWt HmGXz61ywSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDgAKCRAgrS7GWxAs 4oBeEADC0xzD/sfcbN2nWw4+6Y6jG0Wla6EVNCMEhkPF0j5rwx7F1GSoDTa1kGuSTdtbe9iMD1/ ZdSSxfIzTmMZvO0BrF1lCZ7uXApFFYoi3xat5GTVpaQQhk9Dz4yEHgVFIY6nsgQ9ekcCg+GGW0s +7myo1+dFhU127Gnteouyz5SGvpmzV1aHNEKBIRqGeEY/AGPAn4OU/U51uiowTzlfoSPdNK+Nwr aopFW+Lleee06NVUcIEeQlMx77R1G8NbB+yfxwcs7GeFm0eWHtMxv1mrXww/wax4GfT1zYymD8W K/7Cwo/DiU+bOm+qsSOsqgz0vf/bKsrlgqnOYqxN5tGXjRPCADelbUR/qJfH8qG5Tgkw3p6+Ic2 y+hatDGm5l38NzvB9uEBftzTePHXR/DzxyhtCA2YWTU5fP8sRFKcjM+ReE1f2GDS6dOteecC0Nx hDqQWMDsCZXzcQwWKzcW/IVQWb66dyQw+sUvLgLqVJg6mjTQZb43qJwuJg0g8SEA66kUTj16/xD FKQJzxcCeE79Hg8tqs11zCVjYZnFelzgRBvksWCqmrZJSijT9EX+3i4A6MNdqaUxCTsY+LLrPm4 lEgOAfkGXz4E0mN/waShmRqMOIo3eJlpJCDTqGQGytnxHbax7MvDrADBLqL+2MogY7fODHwjWeX WkW6jmSSWBYI+ew== 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 3969dc548cff..509aa4325391 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 DEB6819E7D0; Thu, 31 Oct 2024 18:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397981; cv=none; b=dD9C6yqfhqdR939fxyp8ARMmwxGXKB2VUGJZ3eWVEBawFrjlkSgL71L09z6PGcuV3B7UlZ9gPWXXms6SWxnkzWEo+soKgpikxT/qnljv/0f+Z8322uSg1LqPg4ol26/+MeYL67nYXqMy0guvPCih0D8HWbbMFxiexR1COgkk35Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397981; c=relaxed/simple; bh=bKa+5ChJXxkbbGZrOcz2cZ9+0ctUM/r3kl1i6iZsMoA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iv+mDs7NsBnva/GDfX/lRJHQP3hA2yXJJDc5hVITH69fTDF1SyU/aJkKwwRmeeTdFgku8ccju+gRlDi0Ax8G0O9A/G9kwP5npUY+Nmq8L2Xl8TaQUb2UbbZNClPUoHfyla7kNnlEC/PkjEh7nsc5YwyTzcxzZzj5hOV0gL08/d8= 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=j5yo97u/; arc=none smtp.client-ip=217.70.183.200 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="j5yo97u/" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1E6CB2000E; Thu, 31 Oct 2024 18:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397976; 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=AmhgWt61HTP8ifG1twSSJwLRHokIu6F/ialvnMeQqfQ=; b=j5yo97u/6Vv5Sr6tpyfn4mapIsE/6ikg/oD3JF63w1NePvH64P6ng8Bt9R+CytWkn639SJ ewhbtAbVQwue9iy5Da7uASXRkEpS8IK1mX4gLTwL5rGG1kBUMIU92zx3y/m7JrjAb4gG+f bwVAIinhB2Nh8KQMiYzKSxul8zplaVLKIbj4cFhfPfzR4AR8habZhiGVozm6s34H/0PyP6 qGw2U6VDPqASovDTvVexRMC2QxAofNkr3xM78xIwbGZgn4DyrKYEJQ23HfkUE1/tqZdrWR 8qhzXFu4VQKu1cCMU+NP0Nd7an+Sx/zQ0zzfRQm3Ps6XMtY1qANMgAFmuY7DRA== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:05 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-5-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=15493; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=hHnml+kWAuA0fCqxKFKz0iqBNTn5Q5jlo/NsZD9DAO0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cOQO9WKE7hmlFdsAMsZT6vruLk1eUkihI8L 6KybjrU+FGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDgAKCRAgrS7GWxAs 4vrvD/9sRdEkLsNNIKMihSFv2SyB6gjTfTcOX9J3BZVeoRl9KFxlHcaEkP6FitvpoNIPBR6IGGk H3wEiqFCcp8CgxqOO7iJF33eo1fajvVL+S9xK2wZFqZgrr7XRVhfKu3X9FDtw8trYDmt8kSbxiV KfmsFJPB8qmhiOaEHp7EuvRdQluQv1LxZpLTpYnyxu/jk1Zf1Z0mlGU+yufugP3RKpBIrUxYPbR AK0s5Nf2675E+1200Unz/JNmQ2ak6aFspibZrSlkhI0+6zz5ZnbgDC3BJHn0Ztp69uWhNsblOQf 9JnBY9QI/TKTcF5YJ78QNRaVJzwSxBQY3hp7zQEaHnY1GQnNC1yZT8bqirmv1s/0jH3HGwvZV/+ jvCP35VvtAwvKIO+sNef3syLdIauSJzWgwhA0w76ou0eoIAK4FjqAMkwqUrFVxLwPYhRsITTFOd 2BmAAWOSAtlaW/lW0FMO5rlpmXv3zroEoNzrvgSge6r+YgIwNNDt1UGYjf8epVhP3G5yLhEugut wlqgPbyijCCgmyKWkeDn7kX469OPnum3MLeJarW0OYc+EedNyGcTLejqLoi7sRlFelfd8X4BVuK jXPxAR2Qt3wPLwqc6C4AQdjtOiqu27s8es85HDZ8tyJSSHJ4PzuG192857msRfoUKwdk1BNcNlE lKAfeh2rwjBayiA== 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 9def079f685b..d4665e913de7 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 1b28a6a32948..8d3e46dde635 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 000000000000..70e378228cbd --- /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 000000000000..2d1df668569e --- /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 000000000000..4f565ecb591c --- /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 27865261f384..90adcc924c31 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 d583855cb320..b4fe62ab9c65 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 61C6A1BC097; Thu, 31 Oct 2024 18:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; cv=none; b=VRIsnsC2TZj8qV/FQw8Fnll+4GD9LZ3ClGMryMc+hIwwlpqV0/YZSLGOXFiNv0+LBTxXIpRoPc2qS+QARSwQnbMA5MxlwgsO2RprIhIJItgEvgcW4I0kVlI/c19x8i6+GWwnrDpI1GaqcsMH8P1LZta6PY4CTrFOlMUK/Nwp5zk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397982; c=relaxed/simple; bh=L2eAww3XB8bl9Sxnoiq/z6nn2Apw5rKlRY7sfjjDvWY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AMRR4R8KPHx0wxrC+fbK32TNoarSvDuY20b/vBMUCUYLTInA2u3ViJigBY/Yn9fQPARK6akGTmUB8DwRxowE2Lf4dcp/Q5XqOhuWqg03RxQ+JvbsMToy2FBlUV39DQJg5oc+OMHk6Hy/ViDru6hF43VkxwYGU0Ky3f4tRSoPhHA= 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=faiK9yf7; arc=none smtp.client-ip=217.70.183.200 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="faiK9yf7" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7E7182000F; Thu, 31 Oct 2024 18:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397977; 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=4dr23WBAY8ZlBbMVkhnAU+t1UPEWAWhnUCz8S7CEndk=; b=faiK9yf7SG5VWhqxjI7OQYfTJCjTC/kXWbTKyR85Z9wRBPDHGFGatRmW1p6pfD+NpH7hQH qJvECZm+zTdJO9j/OOUZcJpz7G+PQBY/sZMgjxCvkGjwEZuYAJop9bHoxPyoiUAhSJpMSj PpDBAYJDLBJkmUtifD5ofUVk46CCHy38rS71lVKGD53E4lgr4jskE2tfVA7440m9tEHWrS 91itqMj3gHjpazHbvibxm21eqdoKWcpHRnXZ33nlTvOVEYGuYVjH+NTMrIDRwtrkYHu2ME c2zV+Uy/80wekas0CgOlMs9+dc0PjEEcA2aO9hM2j2OS9r8AZhevuOSEUANsLg== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:06 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-6-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1115; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=cnp5oJy7nuzGGG9ERF9CFtbtr9GkJcMMWvS4L3S4Vps=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cOFnJu/bZQoRm8WNJWKPZ7P7plt4DDDTlM8 j66b+RPbOGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDgAKCRAgrS7GWxAs 4rjhD/9wfcZde53S6DmfNyReBfKsHbeMUDS8S1lrLiocRSH5sVv+v55ZHLE0Mc2saY8LYQtJQ96 TPk2LlZMpuIoCVz5W58wUrRK4zvK8RmY/vC7I+OKGrsl4lN18ytbHTojjtWlBW0Rf0Kvn2GMIpV xNBbC89FUpabOywT40Nr91bjdk23FFkmacwBYNAjnOnFHaubB8ldtNx0uYU2BFDWactuxc08qso O6PMGQiNUA7dnPYFyA1HsD9PnR39jQ0itseWGpOZ5q6dZfyksL3N16/+dJGer3jloVy1tXD1ikr m9cOAb37TsDRXl51RJBVHuMRwi7h8VJgT9t/ERi0w+l+KeGxXVJV4xuRBUAfMi6zbwOwXajxFIE QJ5qX38IZWM7Obfgod0IZ/7w1Z7hJifCy9iNb+FOSpTLGThKLWKbTQtPBlvW5V4Eyjh6I7YzGhr YwuByOtPMIjdk6GbbyYl1WqodB2bU+2bskr1FHHCOjMqhg48JA0IOJKTxXlnq+HOcC6lMPOwK9v q3c+B0irndOdxOwF3b6hv4L3Je9H0lwqir09GGEE2yRYAp99L0gjyQkC6eJg9Snlwl/WObxl8FA 2oNFXOZ4PyeC4imMKun6PhwgcVLwhX7QAoY9nz83YPlmUp4fdoyUMWlVtlStQu0ZB/nacUPhKOB gG1dkbcug/N/GkQ== 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 13b866c3617c..5ef5ef2e6a21 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.46.2 From nobody Sun Nov 24 22:56:53 2024 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 03D3C1C463F; Thu, 31 Oct 2024 18:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397985; cv=none; b=LLsV0empd1eNISs/y8/w5ksrmhAXBKHGPY03eFDNn74d2LQkfL3zpSPtp2m0+D2+yXDINnBe/TW7ePUKZMzlJGe7usLftNK60Jb7Gnk70fqozhe4QTOb23FqzP7DzTAg1HkIOz7OnG91LnDyXBTAaO8/erKfYybr0K5PeTAE9X0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730397985; c=relaxed/simple; bh=6P9xgPCLCn1gF47vP1Q/qpB7fXcZkuf7C7x8fmcRBzQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FeO5fC/RQhv9h8FlW0KMNPb9whmYM/zfCGk49rURoGykxb1n2zMdtfB169iRpGMzlJueeCz0dZjDfuzRhKalAZhHgsNVm1xITrOv2Ufs68C2fKhXlrSh0nExWk6KvsoldA3GgB+cUSh+kh8OUAQe/7CyvsNo8tcAgAJc4+zL15s= 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=DmRPKB6H; arc=none smtp.client-ip=217.70.183.200 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="DmRPKB6H" Received: by mail.gandi.net (Postfix) with ESMTPSA id D27A120011; Thu, 31 Oct 2024 18:06:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1730397979; 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=o4Wn/46pVuuaTENAL8EOOI2/SmJ1WAof8XzHSYEsemM=; b=DmRPKB6HIga9I8eQcU5I/3LLbAxC+8brWGgG/Od8P/wMszB6O9g57flE58ZYpsRBnca+ZY INy78ekCs1Keli9uH78rZxhAUsXa1sKJfuBLuWs1VlkBWePEMNDWUsMNxeWYzGfp94+IAS rn9Uep0ADNWxLYVuXsB/UUmwxZOYseu+YPdVz7jDs/CxSd/sRzI+ar8DgDlx6QHelfW5zF vYs7pP3KT09G+WwZf/3b5SBg92zfCNPqwqBkgBl6alwOpdbrpz+TXwpaxNX0+1bB66wGA5 SPBK3raoKRKec+z3VRrQSEyYcK+QDjSCVUZWqx7REMEi1eiAtN9lypSSG5A4+g== From: Louis Chauvet Date: Thu, 31 Oct 2024 19:06:07 +0100 Subject: [PATCH v13 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: <20241031-yuv-v13-7-c67a337301ae@bootlin.com> References: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> In-Reply-To: <20241031-yuv-v13-0-c67a337301ae@bootlin.com> To: Louis Chauvet , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Rodrigo Siqueira , =?utf-8?q?Ma=C3=ADra_Canal?= , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: thomas.petazzoni@bootlin.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, 20241031-yuv-v13-0-bd5463126faa@bootlin.com, Pekka Paalanen X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=6382; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=6P9xgPCLCn1gF47vP1Q/qpB7fXcZkuf7C7x8fmcRBzQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnI8cP4dvN76fN6xEFIWCu8xg/bjkbtaiO2qslL lpHgNXjWiCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZyPHDwAKCRAgrS7GWxAs 4pCTEAC65VaSi2wZd6K8QhpGEv+Pen4ly3ebwzJm8y8X7GyJlYkdgTshvbR6/THXmc9enl0BflT J0sLGrSA6WnFZgEuxfcPUzXYTxBdyjFvH3YCbYa+0EF5brYP+/ZYxivgn22P3Z/DCRkB3RHSTaF lkIzeCkoNiKMXcfEarPf8XlYgqQ3ieAj0xaS7DiqliGOUXj5thq++1hIYZ42kjzlFrnASVJQMlW RUvvSscwFJ4VeyjhweoQPOOv62A7SQmdRsQe0x8rt1QC6KMX0YUUuU534LXtPB86HXHLawC1cLc xWjasjZXUGcsdVldhjelw/pgLqluHzw8tdDKrxyEFmOOD5fm6Oi1PHDXulF9hR11Js/96oPKo7O G7JUX7ZJk7nFSvnml7LcblX+/20e0Wyv8wX7LhKZyXvj29hc/kqbYalUGxkG7h4befDygWfv1WQ rgGYDcEpUQF7WmIxgQw6hYyaLY9u4uvzGWP2T3E+YCA02Hfj/oNmu6++euii4DrplDSfpkd5hzs DmzOlV8HAz0O9gUTLFEr65Sw3iYzXA6UhZm6OL7Mv9TudwNQ9ZIayJrIIhVqv5cSvR5VxzzFTiI 0h4eeiTRzMtm06SrgvKof8Mkcu9HcQV2pDh+Y5i8o95b9Z2uZzigO0JxwdbHe5qK4gOx7ZZ7lzE TuVdDbml2DJ2QaA== 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 90adcc924c31..3db7fe1ae844 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 8f764a108b00..67f891e7ac58 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.46.2