Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1875067lqe; Tue, 9 Apr 2024 03:07:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHo/3LLASH22bOwPA3cR03Irk69w/s2bIgqRQWNMJGiioeundDh14EuId3BvKz2ejJKXJ/nl2A/L33KuXwczPF6YOeEVd4Pp7TxOTkFA== X-Google-Smtp-Source: AGHT+IHcPKtRCvnnz0vzqW/f4Y2zhuHo9iFdPKbcm760QvBntCXnw0SDnrXWr6mBCc7ad96u4sNq X-Received: by 2002:a50:9e48:0:b0:56e:2332:c282 with SMTP id z66-20020a509e48000000b0056e2332c282mr7898251ede.14.1712657240976; Tue, 09 Apr 2024 03:07:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712657240; cv=pass; d=google.com; s=arc-20160816; b=DYKzwDEdOv2NnBQfrxSxg9191OHfv+F10RDKkBEBM2feneHV++++c2HL9I6Q+B8Y7a 8WkXRjk3f+9xXzGCAXkzqZfjHX02VJTFU/T7rP2HHX/y1s1hcoTNDMLrISAXDJ+MngN7 xbJ3mzD8Z7yZWvdRXQ+w2XOcYuPmMDEfxfbPBbUG7MONNAPao9qZyRelQO40+CD8tymy 6ejE/g0zzsJRgL6laXZvXN9J7OwbARH7+zlQDZi2W+19KILrKxCRjOtUiKs1LbV7aPzb gCS2vqcNhlRhSRCaCCRevSCDoZQtiRfEBjnRqGAg1J55gR41Csfb9stp5w6WJ5RHDm1r It5Q== 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=5H49i2PxxNai/K6ycWDJvpcrRnWv61IRnD8Osqq+4FI=; fh=45eQo3ZJsZ9kxlKtiBlNFdEPxIxcGnXy8eMk/mnf88Q=; b=r0EzvZweZi/bz3UYT0vWpaHvneIJTG5fuQWcBO+OlDM3RB2O5gOJH9OrsP0HRjxV0p ce2syGJ55bL+7wNWkYs/yfy1JpZOmac365qlGAN9X783co/IMeRy7kabb31IT0QGVY3n FBjDdRcNobgVFBpMRcG32Ab8o1e7wV/CkbL7XRW4k3P0QVYK1imYTf6ESjSG2HLaHBzs 1sL5eNQ2p1xki+icZNUn39Q0KBmBSdX8Mcyq2ojKk/sLY/PSVjmfAffIL3p3/evx9h4s u8jRiAS3jvAf3Gp8RIVWJH7ymPrbmixB98LOyNk1E+z8Fl4N+lKyD7AKguOyHCZi7cAC Eusg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=bSzAwssn; 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-136630-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136630-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s23-20020a50ab17000000b0056c24dfd782si4511205edc.687.2024.04.09.03.07.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 03:07:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136630-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=bSzAwssn; 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-136630-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136630-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 830011F224E6 for ; Tue, 9 Apr 2024 10:07:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1EF58173B; Tue, 9 Apr 2024 10:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="bSzAwssn" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 25D9B80639 for ; Tue, 9 Apr 2024 10:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657173; cv=none; b=CSpfUc0JHZOal7rtexI9PVc38wBFlgfhiZ7ygZ1o+pKS9UF60DstxXj8VepJTC9y0wx1i1xF7rH8Zqim3PI+mVSqkB8Cy8Gx9KyqLind98KrT4ZnpfL4IYMsfSMNbaCq0Y3Fv9GCketUHAxc6dFq55kPAd14OqSS6Ue26WyVMZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712657173; c=relaxed/simple; bh=C/bEWMA9mORMCnBTmv1XrGDUaZhRfn9JeFYgeh+Esz4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HxRTqYZkHETcAxN74hcqwFSXxAXlzdBaoTDu7glNr9zl9PLZcd8nLnRsiqRifOFxZiGJvZrc4wSyFl7MB9dYzd87TxorIMr949TTfGGRDDEnj3JUn8UnKxARd3HUo84f0DnWzD37xtXgR4auS+5ZNzQlqTtv3cDOeAj32mAZUKE= 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=bSzAwssn; arc=none smtp.client-ip=217.70.183.194 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 9E98340008; Tue, 9 Apr 2024 10:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1712657169; 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=5H49i2PxxNai/K6ycWDJvpcrRnWv61IRnD8Osqq+4FI=; b=bSzAwssnXzyBF0E55bS86BWdB2MXEYOQmSSqGGOb3+L47AOCqwL5Z9zVadFKvYjyogzGO7 jHdkFFzkTHqul7QHQylswkcJgUbr6d+Jcm5jeAIqBIDFPRIsYIHmv4DdfXZfLVoG6lOXVE XJKgbM2PUumap28qFWcgoS05jmY+xtJe6WtkAxuCYNzPJx3GSgDiit+Fi7ixyAWHLso51g G2X0eA8Cs9WM4NRJxfoT777PcsyXhImL+Qjui3G+ozxqYzNlw7BJOdtJ5NgURYzvXMhS+S +X5avQTwMyf8W5cpQ2c5xDh/p0Ai5bOXON1R1k3uMhWFol/kFGuQiMMn77m3hg== Date: Tue, 9 Apr 2024 12:06:06 +0200 From: Louis Chauvet To: Pekka Paalanen Cc: Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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: Pekka Paalanen , Rodrigo Siqueira , Melissa Wen , =?iso-8859-1?Q?Ma=EDra?= Canal , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , arthurgrillo@riseup.net, Jonathan Corbet , 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> <20240327162307.4b9b6e45.pekka.paalanen@collabora.com> <20240409105857.67bc4ce4.pekka.paalanen@collabora.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: <20240409105857.67bc4ce4.pekka.paalanen@collabora.com> X-GND-Sasl: louis.chauvet@bootlin.com Le 09/04/24 - 10:58, Pekka Paalanen a ?crit : > On Mon, 8 Apr 2024 09:50:19 +0200 > Louis Chauvet wrote: > > > Le 27/03/24 - 16:23, Pekka Paalanen a ?crit : > > > On Wed, 13 Mar 2024 18:45:05 +0100 > > > 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. > > > > > > You mean fixed-point, not floating-point (floats). > > > > > > > > > > > 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. > > > > > > Sounds good! > > > > > > > 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] > > > > 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 > > ... > > > > > +static struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 cb, u8 cr, > > > > + struct conversion_matrix *matrix) > > > > > > If you are using the "swap the matrix columns" trick, then you cannot > > > call these cb, cr nor even u,v, because they might be the opposite. > > > They are simply the first and second chroma channel, and their meaning > > > depends on the given matrix. > > > > I will rename them for v6, channel_1 and channel_2. > > > > > > +{ > > > > + u8 r, g, b; > > > > + s64 fp_y, fp_cb, fp_cr; > > > > + s64 fp_r, fp_g, fp_b; > > > > + > > > > + fp_y = y - matrix->y_offset; > > > > + fp_cb = cb - 128; > > > > + fp_cr = cr - 128; > > > > > > This looks like an incorrect way to convert u8 to fixed-point, but... > > > > > > > + > > > > + fp_y = drm_int2fixp(fp_y); > > > > + fp_cb = drm_int2fixp(fp_cb); > > > > + fp_cr = drm_int2fixp(fp_cr); > > > > > > I find it confusing to re-purpose variables like this. > > > > > > I'd do just > > > > > > fp_c1 = drm_int2fixp((int)c1 - 128); > > > > I agree with this remark, I will change it for the v6. > > > > > If the function arguments were int to begin with, then the cast would > > > be obviously unnecessary. > > > > For this I'm less sure. The name of the function and the usage is > > explicit: we want to use u8 as input. As we manipulate pointers in > > read_line, I don't know how it will works if the pointer is dereferenced > > to a int instead of a u8. > > Dereference operator acts on its input type. What happens to the result > is irrelevant. > > If we have > > u8 *p = ...; > > void foo(int x); > > then you can call > > foo(*v); > > if that was your question. Dereference acts on u8* which results in u8. > Then it gets implicitly cast to int. Thanks for the clear explaination! > However, you have a semantic reason to keep the argument as u8, and > that is fine. So I will keep u8 for the v6. > > > So, what you have in fp variables at this point is fractional numbers > > > in the 8-bit integer scale. However, because the target format is > > > 16-bit, you should not show the extra precision away here. Instead, > > > multiply by 257 to bring the values to 16-bit scale, and do the RGB > > > clamping to 16-bit, not 8-bit. > > > > > > > + > > > > + fp_r = drm_fixp_mul(matrix->matrix[0][0], fp_y) + > > > > + drm_fixp_mul(matrix->matrix[0][1], fp_cb) + > > > > + drm_fixp_mul(matrix->matrix[0][2], fp_cr); > > > > + fp_g = drm_fixp_mul(matrix->matrix[1][0], fp_y) + > > > > + drm_fixp_mul(matrix->matrix[1][1], fp_cb) + > > > > + drm_fixp_mul(matrix->matrix[1][2], fp_cr); > > > > + fp_b = drm_fixp_mul(matrix->matrix[2][0], fp_y) + > > > > + drm_fixp_mul(matrix->matrix[2][1], fp_cb) + > > > > + drm_fixp_mul(matrix->matrix[2][2], fp_cr); > > > > + > > > > + fp_r = drm_fixp2int_round(fp_r); > > > > + fp_g = drm_fixp2int_round(fp_g); > > > > + fp_b = drm_fixp2int_round(fp_b); > > > > + > > > > + r = clamp(fp_r, 0, 0xff); > > > > + g = clamp(fp_g, 0, 0xff); > > > > + b = clamp(fp_b, 0, 0xff); > > > > + > > > > + return argb_u16_from_u8888(255, r, g, b); > > > > > > Going through argb_u16_from_u8888() will throw away precision. > > > > I tried to fix it in the v6, IGT tests pass. If something is wrong in the > > v6, please let me know. > > > > > > +} > > > > + > > > > /* > > > > * The following functions are read_line function for each pixel format supported by VKMS. > > > > * > > > > @@ -293,6 +367,79 @@ static void RGB565_read_line(const struct vkms_plane_state *plane, int x_start, > > > > } > > > > } > > > > > > > > +/* > > > > + * This callback can be used for yuv and yvu formats, given a properly modified conversion matrix > > > > + * (column inversion) > > > > > > Would be nice to explain what semi_planar_yuv means, so that the > > > documentation for these functions would show how they differ rather > > > than all saying exactly the same thing. > > > > /* This callback can be used for YUV format where each color component is > > * stored in a different plane (often called planar formats). It will > > * handle correctly subsampling. > > > > /* > > * 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 > > * corectly handle subsampling. > > * > > * 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 simple column swap is > > * needed) > > */ > > Sounds good. I'd just drop the "It will handle correctly subsampling." > because all code is supposed to be correct by default. Will do for the v6. Thanks, Louis Chauvet > If there is a function that intentionally overlooks something, that > certainly should be documented. > > > Thanks, > pq -- Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com