All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Navare, Manasi D" <manasi.d.navare@intel.com>
To: "Nikula, Jani" <jani.nikula@intel.com>,
	"Hogander, Jouni" <jouni.hogander@intel.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>
Cc: "Hogander, Jouni" <jouni.hogander@intel.com>,
	Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>,
	"Kahola, Mika" <mika.kahola@intel.com>
Subject: RE: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
Date: Tue, 26 Apr 2022 18:27:13 +0000	[thread overview]
Message-ID: <a9dc7383696d4fd380f6925da6a5380e@intel.com> (raw)
In-Reply-To: <87levst171.fsf@intel.com>

Yes I agree that this data parsed from EDID/Display ID should be stored in structs defined in drm_display_info.
Like for the VRR range that we parse from EDID, we store that in a struct monitor_range in drm_display_info.

Manasi

-----Original Message-----
From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Jani Nikula
Sent: Tuesday, April 26, 2022 6:38 AM
To: Hogander, Jouni <jouni.hogander@intel.com>; dri-devel@lists.freedesktop.org
Cc: Hogander, Jouni <jouni.hogander@intel.com>; Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>; Kahola, Mika <mika.kahola@intel.com>
Subject: Re: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata

On Tue, 26 Apr 2022, Jouni Högander <jouni.hogander@intel.com> wrote:
> Split luminance min/max calculation using static hdr metadata from 
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext
> _caps
> into drm/drm_edid.c.

IMO all of this should be computed at EDID parsing time once and stored in the metadata. Maybe in drm_parse_hdr_metadata_block().

Over time we've added a bunch of functions to do this type of stuff, and all drivers call them at slightly different times and different ways, and it just grows complicated.

(Also, I think basically everything that comes out of the EDID or DisplayID should be stored in connector->display_info instead of being spread around like we currently do. But that's for another patch series, another time.)

BR,
Jani.

>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_edid.h     |  4 +++
>  2 files changed, 59 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c 
> index 7a8482b75071..1cb886debbbe 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -4005,6 +4005,61 @@ drm_display_mode_from_cea_vic(struct drm_device 
> *dev,  }  EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
>  
> +/**
> + * drm_luminance_range_from_static_hdr_metadata() - luminance range 
> +from static hdr
> + * metadata
> + * @connector: connector we're calculating for
> + * @min: Calculated min value
> + * @max: Calculated max value
> + *
> + * Calculates backlight min and max as described in CTA-861-G
> + *
> + * Returns: True when calculation succeeds.
> + */
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max)
> +{
> +	struct hdr_sink_metadata *hdr_metadata = &connector->hdr_sink_metadata;
> +	static const u8 pre_computed_values[] = {
> +		50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
> +		71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
> +	u32 min_cll, max_cll, q, r;
> +
> +	if (!(hdr_metadata->hdmi_type1.metadata_type &
> +	      BIT(HDMI_STATIC_METADATA_TYPE1)))
> +		return false;
> +
> +	max_cll = hdr_metadata->hdmi_type1.max_cll;
> +	min_cll = hdr_metadata->hdmi_type1.min_cll;
> +
> +	/* From the specification (CTA-861-G), for calculating the maximum
> +	 * luminance we need to use:
> +	 *	Luminance = 50*2**(CV/32)
> +	 * Where CV is a one-byte value.
> +	 * For calculating this expression we may need float point precision;
> +	 * to avoid this complexity level, we take advantage that CV is divided
> +	 * by a constant. From the Euclids division algorithm, we know that CV
> +	 * can be written as: CV = 32*q + r. Next, we replace CV in the
> +	 * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
> +	 * need to pre-compute the value of r/32. For pre-computing the values
> +	 * We just used the following Ruby line:
> +	 *	(0...32).each {|cv| puts (50*2**(cv/32.0)).round}
> +	 * The results of the above expressions can be verified at
> +	 * pre_computed_values.
> +	 */
> +	q = max_cll >> 5;
> +	r = max_cll % 32;
> +	*max = (1 << q) * pre_computed_values[r];
> +
> +	/* min luminance: maxLum * (CV/255)^2 / 100 */
> +	q = DIV_ROUND_CLOSEST(min_cll, 255);
> +	*min = *max * DIV_ROUND_CLOSEST((q * q), 100);
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_luminance_range_from_static_hdr_metadata);
> +
>  static int
>  do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)  
> { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 
> c3204a58fb09..63e441c84d72 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -406,6 +406,10 @@ drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
>  				   const struct drm_display_mode *mode,
>  				   enum hdmi_quantization_range rgb_quant_range);
>  
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max);
> +
>  /**
>   * drm_eld_mnl - Get ELD monitor name length in bytes.
>   * @eld: pointer to an eld memory structure with mnl set

--
Jani Nikula, Intel Open Source Graphics Center

  reply	other threads:[~2022-04-26 18:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
2022-04-26 13:37   ` Jani Nikula
2022-04-26 18:27     ` Navare, Manasi D [this message]
2022-04-26 12:30 ` [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function Jouni Högander
2022-04-26 12:30 ` [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata Jouni Högander
2022-04-27 18:57 ` [PATCH 0/3] HDR aux backlight range calculation Lyude Paul
2022-04-29 23:34 ` Lyude Paul
2022-05-02  5:25   ` Hogander, Jouni

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=a9dc7383696d4fd380f6925da6a5380e@intel.com \
    --to=manasi.d.navare@intel.com \
    --cc=Rodrigo.Siqueira@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=jouni.hogander@intel.com \
    --cc=mika.kahola@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.