dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: "Jouni Högander" <jouni.hogander@intel.com>,
	dri-devel@lists.freedesktop.org
Cc: "Rodrigo Siqueira" <Rodrigo.Siqueira@amd.com>,
	"Roman Li" <roman.li@amd.com>,
	"Manasi Navare" <manasi.d.navare@intel.com>,
	"Mika Kahola" <mika.kahola@intel.com>,
	"Jouni Högander" <jouni.hogander@intel.com>
Subject: Re: [PATCH v2 2/4] drm: New function to get luminance range based on static hdr metadata
Date: Thu, 23 Jun 2022 11:50:50 +0300	[thread overview]
Message-ID: <87edzfrcet.fsf@intel.com> (raw)
In-Reply-To: <20220620072019.2710652-3-jouni.hogander@intel.com>

On Mon, 20 Jun 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 and use it during edid parsing. Calculated range is
> stored into connector->display_info->luminance_range.
>
> v2: Calculate range during edid parsing
>
> Cc: Roman Li <roman.li@amd.com>
> 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>
> Cc: Manasi Navare <manasi.d.navare@intel.com>
> Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 50 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 49 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 2bdaf1e34a9d..3b367100290f 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -5014,6 +5014,49 @@ static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
>  	mode->clock = clock;
>  }
>  
> +static void drm_calculate_luminance_range(struct drm_connector *connector)
> +{
> +	struct hdr_static_metadata *hdr_metadata = &connector->hdr_sink_metadata.hdmi_type1;
> +	struct drm_luminance_range_info *luminance_range =
> +		&connector->display_info.luminance_range;
> +	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};

Nitpick, newline before };

> +	u32 max_avg, min_cll, max, min, q, r;
> +
> +	if (!(hdr_metadata->metadata_type & BIT(HDMI_STATIC_METADATA_TYPE1)))
> +		return;
> +
> +	max_avg = hdr_metadata->max_fall;
> +	min_cll = hdr_metadata->min_cll;
> +
> +	/* From the specification (CTA-861-G), for calculating the maximum

Nitpick, newline after /*.

> +	 * 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_avg >> 5;
> +	r = max_avg % 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);
> +
> +	luminance_range->min_luminance = min;
> +	luminance_range->max_luminance = max;

I'll just trust this; not going to start verifying.

Acked-by: Jani Nikula <jani.nikula@intel.com>

> +}
> +
>  static uint8_t eotf_supported(const u8 *edid_ext)
>  {
>  	return edid_ext[2] &
> @@ -5045,8 +5088,12 @@ drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
>  		connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
>  	if (len >= 5)
>  		connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
> -	if (len >= 6)
> +	if (len >= 6) {
>  		connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
> +
> +		/* Calculate only when all values are available */
> +		drm_calculate_luminance_range(connector);
> +	}
>  }
>  
>  static void
> @@ -5951,6 +5998,7 @@ drm_reset_display_info(struct drm_connector *connector)
>  
>  	info->non_desktop = 0;
>  	memset(&info->monitor_range, 0, sizeof(info->monitor_range));
> +	memset(&info->luminance_range, 0, sizeof(info->luminance_range));
>  
>  	info->mso_stream_count = 0;
>  	info->mso_pixel_overlap = 0;

-- 
Jani Nikula, Intel Open Source Graphics Center

  reply	other threads:[~2022-06-23  8:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  7:20 [PATCH v2 0/4] HDR aux backlight range calculation Jouni Högander
2022-06-20  7:20 ` [PATCH v2 1/4] drm/display: Add drm_luminance_range_info Jouni Högander
2022-06-23  8:44   ` Jani Nikula
2022-06-20  7:20 ` [PATCH v2 2/4] drm: New function to get luminance range based on static hdr metadata Jouni Högander
2022-06-23  8:50   ` Jani Nikula [this message]
2022-06-20  7:20 ` [PATCH v2 3/4] drm/amdgpu_dm: Rely on split out luminance calculation function Jouni Högander
2022-06-20  7:20 ` [PATCH v2 4/4] drm/i915: Use luminance range calculated during edid parsing Jouni Högander
2022-06-23  8:43   ` Jani Nikula

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=87edzfrcet.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=Rodrigo.Siqueira@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jouni.hogander@intel.com \
    --cc=manasi.d.navare@intel.com \
    --cc=mika.kahola@intel.com \
    --cc=roman.li@amd.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