Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: "Nautiyal, Ankit K" <ankit.k.nautiyal@intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH 01/12] drm/i915: Fix limited range csc matrix
Date: Thu, 6 Apr 2023 14:10:10 +0300	[thread overview]
Message-ID: <ZC6okmAsug2LGYBO@intel.com> (raw)
In-Reply-To: <eeceb998-0bc6-53c3-a6c8-54b5e660f961@intel.com>

On Thu, Apr 06, 2023 at 04:26:48PM +0530, Nautiyal, Ankit K wrote:
> Hi Ville,
> 
> HDMI1.4b indeed says max value for 16bpc as 60160 (0xeb00)
> And black level of 4096.
> 
> Got me thinking that we might need to consider bpc for getting the 
> Coeffs and the offsets.
> IIUC for CSC Full range to Limited range:
> out = in * gain  + offset
> 
> Gain :
> So for 8 bpc, as you have mentioned
> multiplier or gain will be: (235-16) / 255 = 0.8588 ~0.86
> offset will be 16, as range is from 16-235
> 
> 16 bpc
> Multiplier: (60160-4096)/65535 = 0.8555 ~0.86
> Offset for 16bit: should be 4096
> 
> So it seems Multiplier of 0.86 should be alright for different bpc, but 
> offset would vary.

It's all still in the pipe's internal precision. So any 16 vs. 4096
distinction doesn't exist.

> 
> Also CSC Postoff programming for the offset doesn’t seem very clear to me.
> For CSC BT709 RGB Full range->YCbCr Limited Range, we use offset of {16, 
> 128, 128} for Y, Cb, Cr, and we write 0x800, 0x100, 0x100 for these values.

Y is the middle channel. We write 0x800,0x100,0x800

> 
> But below for Limited range Post offset 16,  we seem to be shifting by 
> (12 - 8) i.e 4. Am I missing something?
> 
> 
> Regards,
> 
> Ankit
> 
> On 3/29/2023 7:19 PM, Ville Syrjala wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Our current limited range matrix is a bit off. I think it
> > was originally calculated with rounding, as if we wanted
> > the normal pixel replication type of behaviour.
> > That is, since the 8bpc max value is 0xeb we assumed the
> > 16bpc max value should be 0xebeb, but what the HDMI spec
> > actually says it should be is 0xeb00.
> >
> > So to get what we want we make the formula
> >   out = in * (235-16) << (12-8) / in_max + 16 << (12-8),
> > with 12 being precision of the csc, 8 being the precision
> > of the constants we used.
> >
> > The hardware takes its coefficients as floating point
> > values, but the (235−16)/255 = ~.86, so exponent 0
> > is what we want anyway, so it works out perfectly without
> > having to hardcode it in hex or start playing with floats.
> >
> > In terms of raw numbers we are feeding the hardware the
> > post offset changes from 0x101 to 0x100, and the coefficient
> > changes from 0xdc0 to 0xdb0 (~.860->~.855). So this should
> > make everything come out just a tad darker.
> >
> > I already used better constants in lut_limited_range() earlier
> > so the output of the two paths should be closer now.
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/i915/display/intel_color.c | 5 ++---
> >   1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_color.c b/drivers/gpu/drm/i915/display/intel_color.c
> > index 36aac88143ac..3c3e2f5a5cde 100644
> > --- a/drivers/gpu/drm/i915/display/intel_color.c
> > +++ b/drivers/gpu/drm/i915/display/intel_color.c
> > @@ -116,10 +116,9 @@ struct intel_color_funcs {
> >   #define ILK_CSC_COEFF_FP(coeff, fbits)	\
> >   	(clamp_val(((coeff) >> (32 - (fbits) - 3)) + 4, 0, 0xfff) & 0xff8)
> >   
> > -#define ILK_CSC_COEFF_LIMITED_RANGE 0x0dc0
> >   #define ILK_CSC_COEFF_1_0 0x7800
> > -
> > -#define ILK_CSC_POSTOFF_LIMITED_RANGE (16 * (1 << 12) / 255)
> > +#define ILK_CSC_COEFF_LIMITED_RANGE ((235 - 16) << (12 - 8)) /* exponent 0 */
> > +#define ILK_CSC_POSTOFF_LIMITED_RANGE (16 << (12 - 8))
> >   
> >   /* Nop pre/post offsets */
> >   static const u16 ilk_csc_off_zero[3] = {};

-- 
Ville Syrjälä
Intel

  reply	other threads:[~2023-04-06 11:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 13:49 [Intel-gfx] [PATCH 00/12] drm/i915: Add CSC state readout/check Ville Syrjala
2023-03-29 13:49 ` [Intel-gfx] [PATCH 01/12] drm/i915: Fix limited range csc matrix Ville Syrjala
2023-04-06 10:56   ` Nautiyal, Ankit K
2023-04-06 11:10     ` Ville Syrjälä [this message]
2023-04-06 11:54       ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 02/12] drm/i915: Introduce intel_csc_matrix struct Ville Syrjala
2023-04-06  9:00   ` Nautiyal, Ankit K
2023-04-11  5:07     ` Ville Syrjälä
2023-04-11  5:35       ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 03/12] drm/i915: Split chv_load_cgm_csc() into pieces Ville Syrjala
2023-04-06  9:03   ` Nautiyal, Ankit K
2023-04-06  9:17     ` Nautiyal, Ankit K
2023-04-06 10:45     ` Ville Syrjälä
2023-03-29 13:49 ` [Intel-gfx] [PATCH 04/12] drm/i915: Start using struct intel_csc_matrix for chv cgm csc Ville Syrjala
2023-04-06  9:05   ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 05/12] drm/i915: Store ilk+ csc matrices in the crtc state Ville Syrjala
2023-04-06  9:12   ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 06/12] drm/i915: Utilize crtc_state->csc on chv Ville Syrjala
2023-04-06  9:21   ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 07/12] drm/i915: Sprinke a few sanity check WARNS during csc assignment Ville Syrjala
2023-04-06  9:24   ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 08/12] drm/i915: Add hardware csc readout for ilk+ Ville Syrjala
2023-04-06  9:30   ` Nautiyal, Ankit K
2023-03-29 13:49 ` [Intel-gfx] [PATCH 09/12] drm/i915: Implement chv cgm csc readout Ville Syrjala
2023-04-06  9:31   ` Nautiyal, Ankit K
2023-03-29 13:50 ` [Intel-gfx] [PATCH 10/12] drm/i915: Include the csc matrices in the crtc state dump Ville Syrjala
2023-04-06  9:49   ` Nautiyal, Ankit K
2023-03-29 13:50 ` [Intel-gfx] [PATCH 11/12] drm/i915: Hook up csc into state checker Ville Syrjala
2023-04-06  9:53   ` Nautiyal, Ankit K
2023-03-29 13:50 ` [Intel-gfx] [PATCH 12/12] drm/i915: Do state check for color management changes Ville Syrjala
2023-03-29 18:50 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915: Add CSC state readout/check Patchwork
2023-03-29 18:50 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2023-03-29 18:59 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-03-30 11:06 ` [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=ZC6okmAsug2LGYBO@intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=ankit.k.nautiyal@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /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