From: Melissa Wen <mwen@igalia.com>
To: Harry Wentland <harry.wentland@amd.com>
Cc: Sebastian Wick <sebastian.wick@redhat.com>,
Pekka Paalanen <pekka.paalanen@collabora.com>,
kernel-dev@igalia.com, Shashank Sharma <Shashank.Sharma@amd.com>,
sunpeng.li@amd.com, Simon Ser <contact@emersion.fr>,
Xinhui.Pan@amd.com, Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>,
Xaver Hugl <xaver.hugl@gmail.com>,
dri-devel@lists.freedesktop.org,
Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>,
Alex Hung <alex.hung@amd.com>,
amd-gfx@lists.freedesktop.org, daniel@ffwll.ch,
Alex Deucher <alexander.deucher@amd.com>,
airlied@gmail.com, christian.koenig@amd.com,
Joshua Ashton <joshua@froggi.es>,
sungjoon.kim@amd.com
Subject: Re: [PATCH 21/36] drm/amd/display: add CRTC 3D LUT support
Date: Tue, 6 Jun 2023 16:03:47 -0100 [thread overview]
Message-ID: <20230606170347.libjx7jemm6466cl@mail.igalia.com> (raw)
In-Reply-To: <61fe8337-ef01-0ca9-cfd3-4d2029aee5ec@amd.com>
[-- Attachment #1: Type: text/plain, Size: 10865 bytes --]
O 06/01, Harry Wentland wrote:
>
>
> On 5/23/23 18:15, Melissa Wen wrote:
> > Wire up DC 3D LUT to DM CRTC color management (post-blending). On AMD
> > display HW, we have to set a shaper LUT to delinearize or normalize the
> > color space before applying a 3D LUT (since we have a reduced number of
> > LUT entries). Therefore, we map DC shaper LUT to DM CRTC color mgmt in
> > the next patch.
> >
> > Signed-off-by: Melissa Wen <mwen@igalia.com>
> > ---
> > .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 6 +
> > .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 17 ++
> > .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 158 +++++++++++++++++-
> > 3 files changed, 180 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> > index 0be62fe436b0..a6dd982d7e77 100644
> > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> > @@ -9976,6 +9976,12 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
> > goto fail;
> > }
> >
> > + ret = amdgpu_dm_verify_lut3d_size(adev, new_crtc_state);
> > + if (ret) {
> > + drm_dbg_driver(dev, "amdgpu_dm_verify_lut_sizes() failed\n");
> > + goto fail;
> > + }
> > +
> > if (!new_crtc_state->enable)
> > continue;
> >
> > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> > index e5f9db5a43f4..eebe12c353ad 100644
> > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> > @@ -797,6 +797,21 @@ struct dm_crtc_state {
> >
> > int abm_level;
> >
> > + /* AMD driver-private CRTC color management
> > + *
> > + * DRM provides CRTC degamma/ctm/gamma color mgmt features, but AMD HW
> > + * has a larger set of post-blending color calibration. Here, DC MPC
> > + * color caps are wired up to DM CRTC state:
> > + */
> > + /**
> > + * @lut3d:
> > + *
> > + * Post-blending 3D Lookup table for converting pixel data. When
> > + * supported by HW (DCN 3+), it is positioned just before post-blending
> > + * regamma and always assumes a preceding shaper LUT. The blob (if not
> > + * NULL) is an array of &struct drm_color_lut.
> > + */
> > + struct drm_property_blob *lut3d;
> > /**
> > * @regamma_tf:
> > *
> > @@ -868,6 +883,8 @@ void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);
> > /* 3D LUT max size is 17x17x17 */
> > #define MAX_COLOR_3DLUT_ENTRIES 4913
> > #define MAX_COLOR_3DLUT_BITDEPTH 12
> > +int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
> > + const struct drm_crtc_state *crtc_state);
> > /* 1D LUT size */
> > #define MAX_COLOR_LUT_ENTRIES 4096
> > /* Legacy gamm LUT users such as X doesn't like large LUT sizes */
> > diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> > index 161807e19886..cef8d0d7f37b 100644
> > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
> > @@ -364,6 +364,96 @@ static int __set_input_tf(struct dc_transfer_func *func,
> > return res ? 0 : -ENOMEM;
> > }
> >
> > +static void __to_dc_lut3d_color(struct dc_rgb *rgb,
> > + const struct drm_color_lut lut,
> > + int bit_precision)
> > +{
> > + rgb->red = drm_color_lut_extract(lut.red, bit_precision);
> > + rgb->green = drm_color_lut_extract(lut.green, bit_precision);
> > + rgb->blue = drm_color_lut_extract(lut.blue, bit_precision);
> > +}
> > +
> > +static void __drm_3dlut_to_dc_3dlut(const struct drm_color_lut *lut,
> > + uint32_t lut3d_size,
> > + struct tetrahedral_params *params,
> > + bool use_tetrahedral_9,
> > + int bit_depth)
> > +{
> > + struct dc_rgb *lut0;
> > + struct dc_rgb *lut1;
> > + struct dc_rgb *lut2;
> > + struct dc_rgb *lut3;
> > + int lut_i, i;
> > +
> > +
> > + if (use_tetrahedral_9) {
> > + lut0 = params->tetrahedral_9.lut0;
> > + lut1 = params->tetrahedral_9.lut1;
> > + lut2 = params->tetrahedral_9.lut2;
> > + lut3 = params->tetrahedral_9.lut3;
> > + } else {
> > + lut0 = params->tetrahedral_17.lut0;
> > + lut1 = params->tetrahedral_17.lut1;
> > + lut2 = params->tetrahedral_17.lut2;
> > + lut3 = params->tetrahedral_17.lut3;
> > + }
> > +
> > + for (lut_i = 0, i = 0; i < lut3d_size - 4; lut_i++, i += 4) {
> > + /* We should consider the 3dlut RGB values are distributed
> > + * along four arrays lut0-3 where the first sizes 1229 and the
> > + * other 1228. The bit depth supported for 3dlut channel is
> > + * 12-bit, but DC also supports 10-bit.
> > + *
> > + * TODO: improve color pipeline API to enable the userspace set
> > + * bit depth and 3D LUT size/stride, as specified by VA-API.
> > + */
> > + __to_dc_lut3d_color(&lut0[lut_i], lut[i], bit_depth);
> > + __to_dc_lut3d_color(&lut1[lut_i], lut[i + 1], bit_depth);
> > + __to_dc_lut3d_color(&lut2[lut_i], lut[i + 2], bit_depth);
> > + __to_dc_lut3d_color(&lut3[lut_i], lut[i + 3], bit_depth);
> > + }
> > + /* lut0 has 1229 points (lut_size/4 + 1) */
> > + __to_dc_lut3d_color(&lut0[lut_i], lut[i], bit_depth);
> > +}
> > +
> > +/* amdgpu_dm_atomic_lut3d - set DRM 3D LUT to DC stream
> > + * @drm_lut3d: DRM CRTC (user) 3D LUT
> > + * @drm_lut3d_size: size of 3D LUT
> > + * @lut3d: DC 3D LUT
> > + *
> > + * Map DRM CRTC 3D LUT to DC 3D LUT and all necessary bits to program it
> > + * on DCN MPC accordingly.
> > + */
> > +static void amdgpu_dm_atomic_lut3d(const struct drm_color_lut *drm_lut,
> > + uint32_t drm_lut3d_size,
> > + struct dc_3dlut *lut)
> > +{
> > + if (!drm_lut3d_size) {
> > + lut->state.bits.initialized = 0;
> > + } else {
> > + /* Stride and bit depth are not programmable by API yet.
> > + * Therefore, only supports 17x17x17 3D LUT (12-bit).
> > + */
> > + lut->lut_3d.use_tetrahedral_9 = false;
> > + lut->lut_3d.use_12bits = true;
> > + lut->state.bits.initialized = 1;
> > + __drm_3dlut_to_dc_3dlut(drm_lut, drm_lut3d_size, &lut->lut_3d,
> > + lut->lut_3d.use_tetrahedral_9,
> > + MAX_COLOR_3DLUT_BITDEPTH);
> > + }
> > +}
> > +
> > +static int amdgpu_dm_atomic_shaper_lut(struct dc_transfer_func *func_shaper)
> > +{
> > + /* We don't get DRM shaper LUT yet. We assume the input color space is already
> > + * delinearized, so we don't need a shaper LUT and we can just BYPASS
> > + */
>
> This assumption won't be true for all compositors. This comment will
> be misleading when someone looks at this in the future. I'm thinking we
> might not want to merge patches 16-22 since we have no way to exercise
> this code.
Oh, in the end it was a temporary comment that is overwritten in the
next patch. I'll remove it to avoid misunderstanding.
>
> We'll definitely want MPC 3DLUT support in the future, with the driver-agnostic
> API. So these patches still have value.
I'm okay on remove MPC shaper+3D LUT handling from DM if you think it's
a cleaner approach. I just need to detach shaper and 3D LUT helpers from
these patches and attach to DPP shaper+3D LUT, since we reuse the
helpers for plane shaper+3D LUT support.
>
> Harry
>
> > + func_shaper->type = TF_TYPE_BYPASS;
> > + func_shaper->tf = TRANSFER_FUNCTION_LINEAR;
> > +
> > + return 0;
> > +}
> > +
> > /* amdgpu_dm_atomic_shaper_lut3d - set DRM CRTC shaper LUT and 3D LUT to DC
> > * interface
> > * @dc: Display Core control structure
> > @@ -404,6 +494,57 @@ static int amdgpu_dm_atomic_shaper_lut3d(struct dc *dc,
> > stream->func_shaper = func_shaper;
> > stream->lut3d_func = lut3d_func;
> >
> > + if (!acquire)
> > + return 0;
> > +
> > + amdgpu_dm_atomic_lut3d(drm_lut3d, drm_lut3d_size, lut3d_func);
> > +
> > + return amdgpu_dm_atomic_shaper_lut(func_shaper);
> > +}
> > +
> > +/**
> > + * amdgpu_dm_lut3d_size - get expected size according to hw color caps
> > + * @adev: amdgpu device
> > + * @lut_size: default size
> > + *
> > + * Return:
> > + * lut_size if DC 3D LUT is supported, zero otherwise.
> > + */
> > +static uint32_t amdgpu_dm_get_lut3d_size(struct amdgpu_device *adev,
> > + uint32_t lut_size)
> > +{
> > + return adev->dm.dc->caps.color.mpc.num_3dluts ? lut_size : 0;
> > +}
> > +
> > +/**
> > + * amdgpu_dm_verify_lut3d_size - verifies if 3D LUT is supported and if DRM 3D
> > + * LUT matches the hw supported size
> > + * @adev: amdgpu device
> > + * @crtc_state: the DRM CRTC state
> > + *
> > + * Verifies if post-blending (MPC) 3D LUT is supported by the HW (DCN 3.0 or
> > + * newer) and if the DRM 3D LUT matches the supported size.
> > + *
> > + * Returns:
> > + * 0 on success. -EINVAL if lut size are invalid.
> > + */
> > +int amdgpu_dm_verify_lut3d_size(struct amdgpu_device *adev,
> > + const struct drm_crtc_state *crtc_state)
> > +{
> > + const struct drm_color_lut *lut3d = NULL;
> > + struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc_state);
> > + uint32_t exp_size, size;
> > +
> > + exp_size = amdgpu_dm_get_lut3d_size(adev, MAX_COLOR_3DLUT_ENTRIES);
> > +
> > + lut3d = __extract_blob_lut(acrtc_state->lut3d, &size);
> > +
> > + if (lut3d && size != exp_size) {
> > + drm_dbg(&adev->ddev, "Invalid 3D LUT size. Should be %u but got %u.\n",
> > + exp_size, size);
> > + return -EINVAL;
> > + }
> > +
> > return 0;
> > }
> >
> > @@ -478,6 +619,14 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc,
> > bool has_regamma, has_degamma;
> > bool is_legacy;
> > int r;
> > + const struct drm_color_lut *lut3d;
> > + uint32_t lut3d_size;
> > +
> > + r = amdgpu_dm_verify_lut3d_size(adev, &crtc->base);
> > + if (r)
> > + return r;
> > +
> > + lut3d = __extract_blob_lut(crtc->lut3d, &lut3d_size);
> >
> > r = amdgpu_dm_verify_lut_sizes(&crtc->base);
> > if (r)
> > @@ -526,10 +675,17 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc,
> > if (r)
> > return r;
> > } else {
> > + /* We are not exposing CRTC 3D LUT properties yet, so DC 3D LUT
> > + * programming is expected to be set to bypass mode, since
> > + * there is no user-blob.
> > + */
> > + lut3d_size = lut3d != NULL ? lut3d_size : 0;
> > r = amdgpu_dm_atomic_shaper_lut3d(adev->dm.dc, ctx, stream,
> > - NULL, 0, NULL, 0);
> > + NULL, 0,
> > + lut3d, lut3d_size);
> > if (r)
> > return r;
> > +
> > /* Note: OGAM is disabled if 3D LUT is successfully programmed.
> > * See params and set_output_gamma in
> > * dcn30_set_output_transfer_func()
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-06-06 17:04 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-23 22:14 [PATCH 00/36] drm/amd/display: add AMD driver-specific properties for color mgmt Melissa Wen
2023-05-23 22:14 ` [PATCH 01/36] drm/drm_mode_object: increase max objects to accommodate new color props Melissa Wen
2023-05-23 22:21 ` Simon Ser
2023-05-23 22:14 ` [PATCH 02/36] drm/drm_property: make replace_property_blob_from_id a DRM helper Melissa Wen
2023-05-25 14:48 ` Liviu Dudau
2023-05-23 22:14 ` [PATCH 03/36] drm/drm_plane: track color mgmt changes per plane Melissa Wen
2023-05-23 22:14 ` [PATCH 04/36] drm/amd/display: fix segment distribution for linear LUTs Melissa Wen
2023-05-23 22:14 ` [PATCH 05/36] drm/amd/display: fix the delta clamping for shaper LUT Melissa Wen
2023-05-23 22:14 ` [PATCH 06/36] drm/amd/display: add CRTC driver-specific property for gamma TF Melissa Wen
2023-05-24 8:24 ` Pekka Paalanen
2023-05-25 15:32 ` Harry Wentland
2023-05-25 19:43 ` kernel test robot
2023-06-01 19:17 ` Harry Wentland
2023-06-06 16:18 ` Joshua Ashton
2023-06-06 16:26 ` Sebastian Wick
2023-06-06 16:57 ` Melissa Wen
2023-06-06 20:03 ` Harry Wentland
2023-06-06 17:14 ` Melissa Wen
2023-05-23 22:14 ` [PATCH 07/36] drm/amd/display: add plane driver-specific properties for degamma LUT Melissa Wen
2023-06-01 19:24 ` Harry Wentland
2023-06-06 17:15 ` Melissa Wen
2023-06-10 5:34 ` Joshua Ashton
2023-05-23 22:14 ` [PATCH 08/36] drm/amd/display: add plane degamma TF driver-specific property Melissa Wen
2023-05-26 2:57 ` kernel test robot
2023-05-23 22:14 ` [PATCH 09/36] drm/amd/display: add plane HDR multiplier " Melissa Wen
2023-06-01 19:33 ` Harry Wentland
2023-05-23 22:14 ` [PATCH 10/36] drm/amd/display: add plane 3D LUT driver-specific properties Melissa Wen
2023-05-23 22:14 ` [PATCH 11/36] drm/amd/display: add plane shaper " Melissa Wen
2023-05-23 22:14 ` [PATCH 12/36] drm/amd/display: add plane shaper TF driver-private property Melissa Wen
2023-05-23 22:14 ` [PATCH 13/36] drm/amd/display: add plane blend LUT and TF driver-specific properties Melissa Wen
2023-05-23 22:14 ` [PATCH 14/36] drm/amd/display: add comments to describe DM crtc color mgmt behavior Melissa Wen
2023-05-23 22:14 ` [PATCH 15/36] drm/amd/display: encapsulate atomic regamma operation Melissa Wen
2023-05-23 22:15 ` [PATCH 16/36] drm/amd/display: update lut3d and shaper lut to stream Melissa Wen
2023-05-23 22:15 ` [PATCH 17/36] drm/amd/display: copy 3D LUT settings from crtc state to stream_update Melissa Wen
2023-05-23 22:15 ` [PATCH 18/36] drm/amd/display: allow BYPASS 3D LUT but keep shaper LUT settings Melissa Wen
2023-05-23 22:15 ` [PATCH 19/36] drm/amd/display: handle MPC 3D LUT resources for a given context Melissa Wen
2023-05-23 22:15 ` [PATCH 20/36] drm/amd/display: dynamically acquire 3DLUT resources for color changes Melissa Wen
2023-05-23 22:15 ` [PATCH 21/36] drm/amd/display: add CRTC 3D LUT support Melissa Wen
2023-05-25 1:13 ` kernel test robot
2023-06-01 20:19 ` Harry Wentland
2023-06-06 17:03 ` Melissa Wen [this message]
2023-05-23 22:15 ` [PATCH 22/36] drm/amd/display: add CRTC shaper " Melissa Wen
2023-05-23 22:15 ` [PATCH 23/36] drm/amd/display: add CRTC regamma TF support Melissa Wen
2023-05-23 22:15 ` [PATCH 24/36] drm/amd/display: set sdr_ref_white_level to 80 for out_transfer_func Melissa Wen
2023-05-23 22:15 ` [PATCH 25/36] drm/amd/display: add CRTC shaper TF support Melissa Wen
2023-05-23 22:15 ` [PATCH 26/36] drm/amd/display: mark plane as needing reset if plane color mgmt changes Melissa Wen
2023-05-23 22:15 ` [PATCH 27/36] drm/amd/display: decouple steps for mapping CRTC degamma to DC plane Melissa Wen
2023-05-23 22:15 ` [PATCH 28/36] drm/amd/display: add support for plane degamma TF and LUT properties Melissa Wen
2023-05-23 22:15 ` [PATCH 29/36] drm/amd/display: reject atomic commit if setting both plane and CRTC degamma Melissa Wen
2023-05-23 22:15 ` [PATCH 30/36] drm/amd/display: add dc_fixpt_from_s3132 helper Melissa Wen
2023-05-23 22:15 ` [PATCH 31/36] drm/adm/display: add HDR multiplier support Melissa Wen
2023-05-23 22:15 ` [PATCH 32/36] drm/amd/display: program DPP shaper and 3D LUT if updated Melissa Wen
2023-05-23 22:15 ` [PATCH 33/36] drm/amd/display: add plane shaper/3D LUT and shaper TF support Melissa Wen
2023-05-23 22:15 ` [PATCH 34/36] drm/amd/display: handle empty LUTs in __set_input_tf Melissa Wen
2023-05-23 22:15 ` [PATCH 35/36] drm/amd/display: add DRM plane blend LUT and TF support Melissa Wen
2023-05-23 22:15 ` [PATCH 36/36] drm/amd/display: allow newer DC hardware to use degamma ROM for PQ/HLG Melissa Wen
2023-06-02 15:10 ` Harry Wentland
2023-05-29 22:55 ` [PATCH 00/36] drm/amd/display: add AMD driver-specific properties for color mgmt Dmitry Baryshkov
2023-05-30 7:22 ` Pekka Paalanen
2023-06-02 15:18 ` Harry Wentland
2023-06-06 17:22 ` Melissa Wen
2023-06-06 17:29 ` Melissa Wen
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=20230606170347.libjx7jemm6466cl@mail.igalia.com \
--to=mwen@igalia.com \
--cc=Rodrigo.Siqueira@amd.com \
--cc=Shashank.Sharma@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alex.hung@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=contact@emersion.fr \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=harry.wentland@amd.com \
--cc=joshua@froggi.es \
--cc=kernel-dev@igalia.com \
--cc=nicholas.kazlauskas@amd.com \
--cc=pekka.paalanen@collabora.com \
--cc=sebastian.wick@redhat.com \
--cc=sungjoon.kim@amd.com \
--cc=sunpeng.li@amd.com \
--cc=xaver.hugl@gmail.com \
/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