Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3432953lqp; Tue, 26 Mar 2024 09:02:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUinoSOf+ISrlQ1HI23l2bRxphGNe6IvKkV75BTwIRcdaWeTYTo6Wi0iy1LPo2WrNDmSIFuhPnd71BecaToY6VJ/cppUrrabs7YsIy+5w== X-Google-Smtp-Source: AGHT+IF2yB3d8NI2W3xEcFelJTBTnVgw/aW7t1CQeHYwAkvJi4EMk3jTeWVFlgfkC0Rg+MmxQlLL X-Received: by 2002:a05:6a21:3414:b0:1a3:6ee9:305 with SMTP id yn20-20020a056a21341400b001a36ee90305mr110528pzb.2.1711468922341; Tue, 26 Mar 2024 09:02:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711468922; cv=pass; d=google.com; s=arc-20160816; b=U1JBZ8WQzRAewPa3I4kXUM4cZB07MmfcWa3YhOXrOMtaCUsZmRG4iqnf1mkeMx97tA GtVQlREQ+SfXKjVAewyifX0sEfzoDqK5JxYyKadeZWwk5JOqzaSsbsZlBIVEgiruqlRE Bga7FytbmvpUoE+7UvrBRLiHrzAY6TaaFg+qc6CAkcZ+Dk2rOf0Em0cfxSGP38VoWsh2 d2uVURqm+S1x1+eJPHHW2UWH/besKNwGsgeFYHSSYtBVCfikDCGOktuL8C29IJ2UrUsO IGxLGwpEv8yE3BosHKWjHvZJhJEh+kgsSHMLEAed3bU903BXamd5Ur8rEfRozSettHwh ADHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=cj4+K3Q18OP+zaHpsf73IF0YvyFrPci37KR5EMxaAhE=; fh=cwUBeHQ3ezus3RwQuH9AHNS4lDJrjXpRlC9h9x2ursM=; b=en05qsUiSjfThT8grXo3FOa+INd28AO/2ymzYgpTQVLWXDunOdpessgEMfxnoiKnzF 48laTFnmfdkgjp7eX5IIyuAsZ5DFAa4NFqWYArw9h53glxDNtaOUbuchrOgDs5ajgcYD a46D6mGZkuQgIRnPuO4ra1nO4sjYapt/DiZLwIazJWqpPIPo0y5gwn5Edk8XGU5fkPHi yp1/kp8uDH4W/D6yqOvkv+hbQ677tsjOrzmq7OTt648pmR13NMBaL6mazDBEu/NW9NqT WlMfT53YulGJL2DZGRTyoHOpJ126+6x+7bheEVjRBl+XrL3SR5eSZVcXmiK922Dpv4NG Kh5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="ek9x/s5q"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-119404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i7-20020a63e447000000b005e2b17c97efsi9675704pgk.28.2024.03.26.09.02.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 09:02:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="ek9x/s5q"; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-119404-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 87E5E29BB30 for ; Tue, 26 Mar 2024 15:58:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A73513C8ED; Tue, 26 Mar 2024 15:57:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ek9x/s5q" 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 13C7213C9A2 for ; Tue, 26 Mar 2024 15:57:06 +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=1711468629; cv=none; b=Nuyg4EavxgcG3sIb3i/fyiy018ogO33736v+SDKmiY4PO7Q9Ku4o4N516IxgDo1emgXDJ+3WyOjr7s4lKtQU//0p5zDr090zpRjR9Hq+nCPnwpPAMHH219U+AjcO8o2OA4km1j6SwHluE3nlb0RDFYkN1xXnuGQIYZtsseXZNt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711468629; c=relaxed/simple; bh=EwSDtBfSERf1SulivXMAtF1ySXj2XlLbikNLrpoiy8s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Hs1oqKys9SDni4d6Im+eCpP3TCxPRk8s35sHnx3XL4A4oJQ/PuVJZZV9lPnjuI8N0hiSOPwoljhP9LDk259RvPOSag3uJrULyp8+mAVP6OV2j78kPRFJLjbeLKG2vI7GOUE23NAYSy0wpxgcpwNCHZ4xBoOnwOOZQodtZMBmLig= 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=ek9x/s5q; 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 Received: by mail.gandi.net (Postfix) with ESMTPSA id 951FF1C0007; Tue, 26 Mar 2024 15:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1711468625; 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=cj4+K3Q18OP+zaHpsf73IF0YvyFrPci37KR5EMxaAhE=; b=ek9x/s5qL9OQw/9nadbUES4SLfBNBN+WazdAm0CYzaUm+RTsU1OjBkDvO0A6S2yE/n91Q1 IJWaixWIAwRnN8k2m9H0rJLKEl07270X4T6wvpY1x6ji/dLGEMijzeXS4wZCnZI98aBUeC TyoGlgfV9YkrcyJgeYkjYVNR3vw+8eaVZ0QHbGKGkS4to+hdA+1w1XCLUxOfpFdzlyb+zi DX+FzJNOQ0OmGtS0xNJLzKBo9bI1dtdonfZfnrkCSi3LFy3DXRpCckTvPAlCWjmiIGX3HL iUq1uJBPZvcI6RH2qZBEHGN1a5HIW8tGYV1PVuyozs489bgiZfp+MUUqCXqDGw== Date: Tue, 26 Mar 2024 16:57:03 +0100 From: Louis Chauvet To: =?iso-8859-1?Q?Ma=EDra?= Canal Cc: Rodrigo Siqueira , Melissa Wen , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, 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 Subject: Re: [PATCH v5 11/16] drm/vkms: Add YUV support Message-ID: Mail-Followup-To: =?iso-8859-1?Q?Ma=EDra?= Canal , Rodrigo Siqueira , Melissa Wen , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, 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 References: <20240313-yuv-v5-0-e610cbd03f52@bootlin.com> <20240313-yuv-v5-11-e610cbd03f52@bootlin.com> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GND-Sasl: louis.chauvet@bootlin.com Le 25/03/24 - 11:26, Ma?ra Canal a ?crit : > On 3/13/24 14:45, Louis Chauvet wrote: > > 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 floats 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 > > - remove struct pixel_yuv_u8 > > - update the commit message > > - Merge the modifications from Arthur] > > A Co-developed-by tag would be more appropriate. I am not the main author of this part, I only applied a few simple suggestions, the complex part was done by Arthur. I will wait for Arthur's confirmation to change it to Co-developed by if he agrees. > > Signed-off-by: Louis Chauvet > > --- > > drivers/gpu/drm/vkms/vkms_drv.h | 22 ++ > > drivers/gpu/drm/vkms/vkms_formats.c | 431 ++++++++++++++++++++++++++++++++++++ > > drivers/gpu/drm/vkms/vkms_formats.h | 4 + > > drivers/gpu/drm/vkms/vkms_plane.c | 17 +- > > 4 files changed, 473 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h > > index 23e1d247468d..f3116084de5a 100644 > > --- a/drivers/gpu/drm/vkms/vkms_drv.h > > +++ b/drivers/gpu/drm/vkms/vkms_drv.h > > @@ -99,6 +99,27 @@ typedef void (*pixel_read_line_t)(const struct vkms_plane_state *plane, int x_st > > int y_start, enum pixel_read_direction direction, int count, > > struct pixel_argb_u16 out_pixel[]); > > > > +/** > > + * CONVERSION_MATRIX_FLOAT_DEPTH - Number of digits after the point for conversion matrix values > > + */ > > +#define CONVERSION_MATRIX_FLOAT_DEPTH 32 > > + > > +/** > > + * struct conversion_matrix - Matrix to use for a specific encoding and range > > + * > > + * @matrix: Conversion matrix from yuv to rgb. The matrix is stored in a row-major manner and is > > + * used to compute rgb values from yuv values: > > + * [[r],[g],[b]] = @matrix * [[y],[u],[v]] > > + * OR for yvu formats: > > + * [[r],[g],[b]] = @matrix * [[y],[v],[u]] > > + * The values of the matrix are fixed floats, 32.CONVERSION_MATRIX_FLOAT_DEPTH > + * @y_offest: Offset to apply on the y value. > > s/y_offest/y_offset Fixed in v6. > > + */ > > +struct conversion_matrix { > > + s64 matrix[3][3]; > > + s64 y_offset; > > +}; > > + > > /** > > * vkms_plane_state - Driver specific plane state > > * @base: base plane state > > @@ -110,6 +131,7 @@ 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; > > Add @conversion_matrix on the kernel-doc from the struct > vkms_plane_state. Fixed in v6. > > }; > > > > struct vkms_plane { > > diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c > > index 1449a0e6c706..edbf4b321b91 100644 > > --- a/drivers/gpu/drm/vkms/vkms_formats.c > > +++ b/drivers/gpu/drm/vkms/vkms_formats.c > > @@ -105,6 +105,44 @@ static int get_step_next_block(struct drm_framebuffer *fb, enum pixel_read_direc > > return 0; > > } > > > > +/** > > + * get_subsampling() - Get the subsampling divisor value on a specific direction > > Where are the arguments? Fixed in v6. > > + */ > > +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 consistent regardless of > > + * x_start and y_start values > > Same. Fixed in v6. > > + */ > > +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, ...), convert them to the format > > * ARGB16161616 in out_pixel. > > @@ -161,6 +199,42 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel) > > return out_pixel; > > } > > > > [...] > > > > > +/** > > + * get_conversion_matrix_to_argb_u16() - Retrieve the correct yuv to rgb conversion matrix for a > > + * given encoding and range. > > + * > > + * If the matrix is not found, return a null pointer. In all other cases, it return a simple > > + * diagonal matrix, which act as a "no-op". > > + * > > + * @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 > > A bit odd to see the arguments after the description. Fixed in v6. > > + */ > > +struct conversion_matrix * > > +get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, > > + enum drm_color_range range) > > +{ > > + static struct conversion_matrix no_operation = { > > + .matrix = { > > + { 4294967296, 0, 0, }, > > + { 0, 4294967296, 0, }, > > + { 0, 0, 4294967296, }, > > + }, > > + .y_offset = 0, > > + }; [...] > > + > > + /* Breaking in this switch means that the color format+encoding+range is not supported */ > > s/color format+encoding+range/color format + encoding + range Fixed in v6. > > + switch (format) { > > + case DRM_FORMAT_NV12: > > + case DRM_FORMAT_NV16: > > + case DRM_FORMAT_NV24: > > + case DRM_FORMAT_YUV420: > > + case DRM_FORMAT_YUV422: > > + case DRM_FORMAT_YUV444: > > + switch (encoding) { > > + case DRM_COLOR_YCBCR_BT601: > > + switch (range) { > > + case DRM_COLOR_YCBCR_LIMITED_RANGE: > > + return &yuv_bt601_limited; > > + case DRM_COLOR_YCBCR_FULL_RANGE: [...] > > diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h > > index 8d2bef95ff79..e1d324764b17 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); > > > > pixel_write_t get_pixel_write_function(u32 format); > > > > +struct conversion_matrix * > > +get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, > > + enum drm_color_range range); > > + > > #endif /* _VKMS_FORMATS_H_ */ > > diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c > > index 8875bed76410..987dd2b686a8 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[] = { > > 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 > > Let's add a comma by the end of this entry, to avoid deleting this line > when adding a new format. Fixed in v6. > > }; > > > > static struct drm_plane_state * > > @@ -117,12 +129,15 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, > > drm_framebuffer_get(frame_info->fb); > > frame_info->rotation = drm_rotation_simplify(new_state->rotation, DRM_MODE_ROTATE_0 | > > DRM_MODE_ROTATE_90 | > > + DRM_MODE_ROTATE_180 | > > Why do we need to add DRM_MODE_ROTATE_180 here? Isn't the same as > reflecting both along the X and Y axis? Oops, I had no intention of putting that change here. I will move it to another patch. I don't understand why DRM_MODE_ROTATE_180 isn't in this list. If I read the drm_rotation_simplify documentation, it explains that this argument should contain all supported rotations and reflections, and ROT_180 is supported by VKMS. Perhaps this call is unnecessary because all combinations are supported by vkms? Thanks, Louis Chauvet > Best Regards, > - Ma?ra > > > DRM_MODE_ROTATE_270 | > > DRM_MODE_REFLECT_X | > > DRM_MODE_REFLECT_Y); > > > > > > vkms_plane_state->pixel_read_line = get_pixel_read_line_function(fmt); > > + vkms_plane_state->conversion_matrix = get_conversion_matrix_to_argb_u16 > > + (fmt, new_state->color_encoding, new_state->color_range); > > } > > > > static int vkms_plane_atomic_check(struct drm_plane *plane, > > -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com