From: Louis Chauvet <louis.chauvet@bootlin.com>
To: Pekka Paalanen <pekka.paalanen@collabora.com>
Cc: "Rodrigo Siqueira" <rodrigosiqueiramelo@gmail.com>,
"Melissa Wen" <melissa.srw@gmail.com>,
"Maíra Canal" <mairacanal@riseup.net>,
"Haneen Mohammed" <hamohammed.sa@gmail.com>,
"Daniel Vetter" <daniel@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
arthurgrillo@riseup.net, "Jonathan Corbet" <corbet@lwn.net>,
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
Date: Tue, 9 Apr 2024 12:06:06 +0200 [thread overview]
Message-ID: <ZhUTDiN8dX_K4S-b@localhost.localdomain> (raw)
In-Reply-To: <20240409105857.67bc4ce4.pekka.paalanen@collabora.com>
Le 09/04/24 - 10:58, Pekka Paalanen a écrit :
> On Mon, 8 Apr 2024 09:50:19 +0200
> Louis Chauvet <louis.chauvet@bootlin.com> wrote:
>
> > Le 27/03/24 - 16:23, Pekka Paalanen a écrit :
> > > On Wed, 13 Mar 2024 18:45:05 +0100
> > > Louis Chauvet <louis.chauvet@bootlin.com> wrote:
> > >
> > > > From: Arthur Grillo <arthurgrillo@riseup.net>
> > > >
> > > > 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 <arthurgrillo@riseup.net>
> > > > [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 <louis.chauvet@bootlin.com>
> > > > ---
> > > > 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
next prev parent reply other threads:[~2024-04-09 10:06 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-13 17:44 [PATCH v5 00/16] drm/vkms: Reimplement line-per-line pixel conversion for plane reading Louis Chauvet
2024-03-13 17:44 ` [PATCH v5 01/16] drm/vkms: Code formatting Louis Chauvet
2024-03-25 12:03 ` Pekka Paalanen
2024-03-25 13:13 ` Maíra Canal
2024-03-13 17:44 ` [PATCH v5 02/16] drm/vkms: Use drm_frame directly Louis Chauvet
2024-03-25 12:04 ` Pekka Paalanen
2024-03-25 13:20 ` Maíra Canal
2024-03-26 15:56 ` Louis Chauvet
2024-03-13 17:44 ` [PATCH v5 03/16] drm/vkms: write/update the documentation for pixel conversion and pixel write functions Louis Chauvet
2024-03-13 19:02 ` Randy Dunlap
2024-03-25 13:32 ` Maíra Canal
2024-03-26 15:56 ` Louis Chauvet
2024-03-13 17:44 ` [PATCH v5 04/16] drm/vkms: Add typedef and documentation for pixel_read and pixel_write functions Louis Chauvet
2024-03-25 12:04 ` Pekka Paalanen
2024-03-26 15:56 ` Louis Chauvet
2024-03-25 13:56 ` Maíra Canal
2024-03-26 15:56 ` Louis Chauvet
2024-03-27 15:03 ` Maíra Canal
2024-03-13 17:44 ` [PATCH v5 05/16] drm/vkms: Add dummy pixel_read/pixel_write callbacks to avoid NULL pointers Louis Chauvet
2024-03-13 19:08 ` Randy Dunlap
2024-03-25 12:05 ` Pekka Paalanen
2024-03-26 15:56 ` Louis Chauvet
2024-03-25 13:59 ` Maíra Canal
2024-03-26 15:56 ` Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 06/16] drm/vkms: Use const for input pointers in pixel_read an pixel_write functions Louis Chauvet
2024-03-25 12:05 ` Pekka Paalanen
2024-03-25 14:00 ` Maíra Canal
2024-03-13 17:45 ` [PATCH v5 07/16] drm/vkms: Update pixels accessor to support packed and multi-plane formats Louis Chauvet
2024-03-25 12:40 ` Pekka Paalanen
2024-03-26 15:56 ` Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 08/16] drm/vkms: Avoid computing blending limits inside pre_mul_alpha_blend Louis Chauvet
2024-03-25 12:41 ` Pekka Paalanen
2024-03-26 15:57 ` Louis Chauvet
2024-03-27 11:48 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 09/16] drm/vkms: Introduce pixel_read_direction enum Louis Chauvet
2024-03-25 13:11 ` Pekka Paalanen
2024-03-26 15:57 ` Louis Chauvet
2024-03-27 12:16 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
2024-04-09 7:35 ` Pekka Paalanen
2024-04-09 10:06 ` Louis Chauvet
2024-03-25 14:07 ` Maíra Canal
2024-03-26 15:57 ` Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 10/16] drm/vkms: Re-introduce line-per-line composition algorithm Louis Chauvet
2024-03-25 14:15 ` Maíra Canal
2024-03-25 14:56 ` Pekka Paalanen
2024-03-26 15:57 ` Louis Chauvet
2024-03-25 15:43 ` Pekka Paalanen
2024-03-26 15:57 ` Louis Chauvet
2024-03-27 12:29 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 11/16] drm/vkms: Add YUV support Louis Chauvet
2024-03-13 19:20 ` Randy Dunlap
2024-03-14 14:41 ` Louis Chauvet
2024-03-25 14:26 ` Maíra Canal
2024-03-26 15:57 ` Louis Chauvet
2024-03-27 12:59 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
2024-03-27 12:11 ` Philipp Zabel
2024-04-08 7:50 ` Louis Chauvet
2024-03-27 14:23 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
2024-04-09 7:58 ` Pekka Paalanen
2024-04-09 10:06 ` Louis Chauvet [this message]
2024-03-13 17:45 ` [PATCH v5 12/16] drm/vkms: Add range and encoding properties to the plane Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 13/16] drm/vkms: Drop YUV formats TODO Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 14/16] drm/vkms: Create KUnit tests for YUV conversions Louis Chauvet
2024-03-25 14:34 ` Maíra Canal
2024-03-26 15:57 ` Louis Chauvet
2024-03-28 13:26 ` Pekka Paalanen
2024-03-13 17:45 ` [PATCH v5 15/16] drm/vkms: Add how to run the Kunit tests Louis Chauvet
2024-03-13 17:45 ` [PATCH v5 16/16] drm/vkms: Add support for DRM_FORMAT_R* Louis Chauvet
2024-03-28 14:00 ` Pekka Paalanen
2024-04-08 7:50 ` Louis Chauvet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZhUTDiN8dX_K4S-b@localhost.localdomain \
--to=louis.chauvet@bootlin.com \
--cc=airlied@gmail.com \
--cc=arthurgrillo@riseup.net \
--cc=corbet@lwn.net \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=hamohammed.sa@gmail.com \
--cc=jeremie.dautheribes@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mairacanal@riseup.net \
--cc=marcheu@google.com \
--cc=melissa.srw@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=mripard@kernel.org \
--cc=nicolejadeyee@google.com \
--cc=pekka.paalanen@collabora.com \
--cc=rodrigosiqueiramelo@gmail.com \
--cc=seanpaul@google.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox