From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Shankar, Uma" <uma.shankar@intel.com>
Cc: "intel-gfx@lists.freedesktop.org"
<intel-gfx@lists.freedesktop.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>
Subject: Re: [Intel-gfx] [PATCH v2 3/7] drm/i915: Fix CHV CGM CSC coefficient sign handling
Date: Fri, 26 May 2023 16:48:15 +0300 [thread overview]
Message-ID: <ZHC4nyUkQpCxTxHj@intel.com> (raw)
In-Reply-To: <DM4PR11MB636031F61EE8864E316FB1C3F4469@DM4PR11MB6360.namprd11.prod.outlook.com>
On Thu, May 25, 2023 at 08:55:08PM +0000, Shankar, Uma wrote:
>
>
> > -----Original Message-----
> > From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Ville Syrjala
> > Sent: Thursday, April 13, 2023 10:19 PM
> > To: intel-gfx@lists.freedesktop.org
> > Cc: dri-devel@lists.freedesktop.org
> > Subject: [PATCH v2 3/7] drm/i915: Fix CHV CGM CSC coefficient sign handling
> >
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > The CHV CGM CSC coefficients are in s4.12 two's complement format. Fix the CTM-
> > >CGM conversion to handle that correctly instead of pretending that the hw
> > coefficients are also in some sign-magnitude format.
>
> Spec is slightly confusing when it says:
> "CGM CSC : Input pixels to the CGM CSC are 14 bits. (u.14 format). Coefficients are 16 bits (s3.12)."
> Also here:
> "Programmable parameters :
> c0[15 :0], c1[15 :0], c2[15 :0], c3[15 :0], c4[15 :0], c5[15 :0], c6[15 :0], c7[15 :0], c8[15 :0] ; // signed matrix coefficients (s3.12)"
Yeah, the spec just uses a weird notation where it doesn't count the msb
in the bits.
>
> But the coefficients are 16bits, can you help understand how were you able to crack this 😊
The 16bit coefficient already made me suspect they screwed up
the notation. Testing specific values on real hardware
confirmed that.
>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> > drivers/gpu/drm/i915/display/intel_color.c | 46 ++++++++++++++--------
> > 1 file changed, 29 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_color.c
> > b/drivers/gpu/drm/i915/display/intel_color.c
> > index 4fc16cac052d..63141f4ed372 100644
> > --- a/drivers/gpu/drm/i915/display/intel_color.c
> > +++ b/drivers/gpu/drm/i915/display/intel_color.c
> > @@ -568,29 +568,41 @@ static void icl_load_csc_matrix(const struct
> > intel_crtc_state *crtc_state)
> > icl_update_output_csc(crtc, &crtc_state->output_csc); }
> >
> > +static u16 ctm_to_twos_complement(u64 coeff, int int_bits, int
> > +frac_bits) {
> > + s64 c = CTM_COEFF_ABS(coeff);
> > +
> > + /* leave an extra bit for rounding */
> > + c >>= 32 - frac_bits - 1;
> > +
> > + /* round and drop the extra bit */
> > + c = (c + 1) >> 1;
> > +
> > + if (CTM_COEFF_NEGATIVE(coeff))
> > + c = -c;
> > +
> > + c = clamp(c, -(s64)BIT(int_bits + frac_bits - 1),
> > + (s64)(BIT(int_bits + frac_bits - 1) - 1));
> > +
> > + return c & (BIT(int_bits + frac_bits) - 1); }
> > +
> > +/*
> > + * CHV Color Gamut Mapping (CGM) CSC
> > + * |r| | c0 c1 c2 | |r|
> > + * |g| = | c3 c4 c5 | x |g|
> > + * |b| | c6 c7 c8 | |b|
> > + *
> > + * Coefficients are two's complement s4.12.
> > + */
> > static void chv_cgm_csc_convert_ctm(const struct intel_crtc_state *crtc_state,
> > struct intel_csc_matrix *csc)
> > {
> > const struct drm_color_ctm *ctm = crtc_state->hw.ctm->data;
> > int i;
> >
> > - for (i = 0; i < 9; i++) {
> > - u64 abs_coeff = ((1ULL << 63) - 1) & ctm->matrix[i];
> > -
> > - /* Round coefficient. */
> > - abs_coeff += 1 << (32 - 13);
> > - /* Clamp to hardware limits. */
> > - abs_coeff = clamp_val(abs_coeff, 0, CTM_COEFF_8_0 - 1);
> > -
> > - csc->coeff[i] = 0;
> > -
> > - /* Write coefficients in S3.12 format. */
> > - if (ctm->matrix[i] & (1ULL << 63))
> > - csc->coeff[i] |= 1 << 15;
> > -
> > - csc->coeff[i] |= ((abs_coeff >> 32) & 7) << 12;
> > - csc->coeff[i] |= (abs_coeff >> 20) & 0xfff;
> > - }
> > + for (i = 0; i < 9; i++)
> > + csc->coeff[i] = ctm_to_twos_complement(ctm->matrix[i], 4, 12);
> > }
> >
> > static void chv_load_cgm_csc(struct intel_crtc *crtc,
> > --
> > 2.39.2
>
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2023-05-26 13:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 16:49 [Intel-gfx] [PATCH v2 0/7] drm/i915: CTM stuff mostly Ville Syrjala
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 1/7] drm/uapi: Document CTM matrix better Ville Syrjala
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 2/7] drm/i915: Expose crtc CTM property on ilk/snb Ville Syrjala
2023-05-25 20:13 ` Shankar, Uma
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 3/7] drm/i915: Fix CHV CGM CSC coefficient sign handling Ville Syrjala
2023-05-25 20:55 ` Shankar, Uma
2023-05-25 21:27 ` Shankar, Uma
2023-05-26 13:48 ` Ville Syrjälä [this message]
2023-05-29 5:13 ` Shankar, Uma
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 4/7] drm/i915: Always enable CGM CSC on CHV Ville Syrjala
2023-05-25 20:58 ` Shankar, Uma
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 5/7] drm/i915: Implement CTM property support for VLV Ville Syrjala
2023-05-25 21:23 ` Shankar, Uma
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 6/7] drm/i915: No 10bit gamma on desktop gen3 parts Ville Syrjala
2023-05-25 21:25 ` Shankar, Uma
2023-05-26 10:59 ` Jani Nikula
2023-05-26 13:51 ` Ville Syrjälä
2023-04-13 16:49 ` [Intel-gfx] [PATCH v2 7/7] drm/i915: Do state check for color management changes Ville Syrjala
2023-04-13 18:28 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: CTM stuff mostly (rev3) Patchwork
2023-04-13 18:28 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-04-13 18:49 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-04-15 12:56 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: CTM stuff mostly (rev4) Patchwork
2023-04-15 13:09 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-04-15 20:11 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: CTM stuff mostly (rev5) Patchwork
2023-04-15 20:11 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-04-15 20:23 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-04-15 21:33 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
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=ZHC4nyUkQpCxTxHj@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=uma.shankar@intel.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