HDR aux backlight range calculation
Subsystems (6)
cover HDR aux backlight range calculation
This patch set splits out static hdr metadata backlight range parsing from gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c into gpu/drm/drm-edid.c as a new function. This new function is then used in admgpu_dm.c and intel_dp_aux_backlight.c
Jouni Högander (3):
drm: New function to get luminance range based on static hdr metadata drm/amdgpu_dm: Use split out luminance calculation function drm/i915: Use luminance range from static hdr metadata
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++---------- drivers/gpu/drm/drm_edid.c | 55 +++++++++++++++++++ .../drm/i915/display/intel_dp_aux_backlight.c | 9 ++- include/drm/drm_edid.h | 4 ++ 4 files changed, 70 insertions(+), 33 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 drm: New function to get luminance range based on static hdr metadata
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.
--- drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 4 +++ 2 files changed, 59 insertions(+)
drivers/gpu/drm/drm_edid.c +55 -0
@@ -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) {
include/drm/drm_edid.h +4 -0
@@ -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
Signature · 1 line
2.25.1
Re: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
Quoted 3 lines · Jouni Högander
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.
Quoted 93 lines
Cc Rodrigo Siqueira <[email protected]>Cc Harry Wentland <[email protected]>Cc Lyude Paul <[email protected]>Cc Mika Kahola <[email protected]>Cc Jani Nikula <[email protected]>Signed-off-by Jouni Högander <[email protected]>--- drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 4 +++ 2 files changed, 59 insertions(+)drivers/gpu/drm/drm_edid.c +55
-0@@ -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) {include/drm/drm_edid.h +4
-0@@ -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
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
RE: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
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 <[email protected]> On Behalf Of Jani Nikula
Sent: Tuesday, April 26, 2022 6:38 AM
To: Hogander, Jouni <[email protected]>; [email protected]
Cc: Hogander, Jouni <[email protected]>; Rodrigo Siqueira <[email protected]>; Kahola, Mika <[email protected]>
Subject: Re: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
Quoted 4 lines · Jouni Högander
Split luminance min/max calculation using static hdr metadata from drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext
_caps
intodrm/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.
Quoted 82 lines
Cc Rodrigo Siqueira <[email protected]>Cc Harry Wentland <[email protected]>Cc Lyude Paul <[email protected]>Cc Mika Kahola <[email protected]>Cc Jani Nikula <[email protected]>Signed-off-by Jouni Högander <[email protected]>--- drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 4 +++ 2 files changed, 59 insertions(+)drivers/gpu/drm/drm_edid.c +56
-0@@ -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.hb/include/drm/drm_edid.hindexc3204a58fb09..63e441c84d72100644
include/drm/drm_edid.h drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame, · line 415
Quoted 10 lines
include/drm/drm_edid.h +4
-0@@ -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
PATCH 2/3 drm/amdgpu_dm: Use split out luminance calculation function
In reply to Jouni HöganderLuminance range was split out into drm_edid.c to share the calculation function. Use this new interface for caps->aux_max_input_signal and caps->aux_min_input_signal.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -31
@@ -2836,15 +2836,11 @@ static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = {static void update_connector_ext_caps (struct amdgpu_dm_connector *aconnector) { -u32 max_cll, min_cll, max, min, q, r;struct amdgpu_dm_backlight_caps *caps;struct amdgpu_display_manager *dm;struct drm_connector *conn_base;struct amdgpu_device *adev;struct dc_link *link =NULL ; -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 };int i;if (!aconnector || !aconnector->dc_link)
@@ -2866,8 +2862,6 @@ static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector) caps = &dm->backlight_caps[i]; caps->ext_caps = &aconnector->dc_link->dpcd_sink_ext_caps; caps->aux_support = false; - max_cll = conn_base->hdr_sink_metadata.hdmi_type1.max_cll; - min_cll = conn_base->hdr_sink_metadata.hdmi_type1.min_cll;if (caps->ext_caps->bits.oled ==1 /*|| caps->ext_caps->bits.sdr_aux_backlight_control == 1 ||
@@ -2879,31 +2873,10 @@ static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)else if (amdgpu_backlight ==1 ) caps->aux_support = true; -/* 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 ); - - caps->aux_max_input_signal = max; - caps->aux_min_input_signal = min; +if (!drm_luminance_range_from_static_hdr_metadata (conn_base, + &caps->aux_min_input_signal, + &caps->aux_max_input_signal)) +DRM_ERROR ("No backligt range in static hdr metadata\n" ); } void amdgpu_dm_update_connector_after_detect(
Signature · 1 line
2.25.1
PATCH 3/3 drm/i915: Use luminance range from static hdr metadata
In reply to Jouni HöganderInstead of using fixed 0 - 512 range use drm_luminance_range_from_static_hdr_metadata to obtain panel range. If that fails fall back to static 0 - 512.
--- drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c +7 -2
@@ -293,8 +293,13 @@ intel_dp_aux_hdr_setup_backlight(struct intel_connector *connector, enum pipe pi } } - panel->backlight.max =512 ; - panel->backlight.min =0 ; +if (!drm_luminance_range_from_static_hdr_metadata (&connector->base, + &panel->backlight.min, + &panel->backlight.max)) { +drm_err (&i915->drm,"No backlight range data in static hdr metadata, using fixed 0,512\n" ); + panel->backlight.max =512 ; + panel->backlight.min =0 ; + } panel->backlight.level =intel_dp_aux_hdr_get_backlight (connector, pipe); panel->backlight.enabled = panel->backlight.level !=0 ;
Signature · 1 line
2.25.1
Hey! I will try to test this out ASAP on all of the HDR backlight machines I have (so, many :) at some point this week, will let you know when
Quoted 23 lines · Jouni Högander
This patch set splits out static hdr metadata backlight range parsing from
gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.cintogpu/drm/drm-edid.cas a new function. This new function is then used inadmgpu_dm.candintel_dp_aux_backlight.cCc Maarten Lankhorst <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Harry Wentland <[email protected]>Cc Lyude Paul <[email protected]>Cc Mika Kahola <[email protected]>Cc Jani Nikula <[email protected]>Jouni Högander (3):
drm: New function to get luminance range based on static hdr metadata drm/amdgpu_dm: Use split out luminance calculation function drm/i915: Use luminance range from static hdr metadata.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++---------- drivers/gpu/drm/drm_edid.c | 55 +++++++++++++++++++
.../drm/i915/display/intel_dp_aux_backlight.c| 9 ++- include/drm/drm_edid.h | 4 ++4 files changed, 70 insertions(+), 33 deletions(-)
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat
Cool! Tested this on three different laptops, and it seems to work great on all of them. so, this series is:
Would review, but I basically have the same comments as jani
Quoted 23 lines · Jouni Högander
This patch set splits out static hdr metadata backlight range parsing from
gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.cintogpu/drm/drm-edid.cas a new function. This new function is then used inadmgpu_dm.candintel_dp_aux_backlight.cCc Maarten Lankhorst <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Harry Wentland <[email protected]>Cc Lyude Paul <[email protected]>Cc Mika Kahola <[email protected]>Cc Jani Nikula <[email protected]>Jouni Högander (3):
drm: New function to get luminance range based on static hdr metadata drm/amdgpu_dm: Use split out luminance calculation function drm/i915: Use luminance range from static hdr metadata.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++---------- drivers/gpu/drm/drm_edid.c | 55 +++++++++++++++++++
.../drm/i915/display/intel_dp_aux_backlight.c| 9 ++- include/drm/drm_edid.h | 4 ++4 files changed, 70 insertions(+), 33 deletions(-)
Signature · 3 lines
Cheers, Lyude Paul (she/her) Software Engineer at Red Hat
Quoted 5 lines · Lyude Paul
Cool! Tested this on three different laptops, and it seems to work great on
all of them. so, this series is:Tested-by Lyude Paul <[email protected]>
Thank you all for review/testing support. I will come back with updated patch set later.
Quoted 31 lines
Would review, but I basically have the same comments as jani
Quoted 27 lines · Jouni Högander
This patch set splits out static hdr metadata backlight range parsing
fromgpu/drm/amd/display/amdgpu_dm/amdgpu_dm.cinto gpu/drm/drm-edid.cas
a new function. This new function is then used inadmgpu_dm.candintel_dp_aux_backlight.cCc Maarten Lankhorst <[email protected]>Cc Rodrigo Siqueira <[email protected]>Cc Harry Wentland <[email protected]>Cc Lyude Paul <[email protected]>Cc Mika Kahola <[email protected]>Cc Jani Nikula <[email protected]>Jouni Högander (3):
drm: New function to get luminance range based on static hdr
metadata
drm/amdgpu_dm: Use split out luminance calculation function drm/i915: Use luminance range from static hdr metadata.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++---------- drivers/gpu/drm/drm_edid.c | 55 +++++++++++++++++++ .../drm/i915/display/intel_dp_aux_backlight.c | 9 ++- include/drm/drm_edid.h | 4 ++ 4 files changed, 70 insertions(+), 33 deletions(-)