Skip to content

Commit c6a29aa

Browse files
committed
drm/amd/display: Optimize custom brightness curve
JIRA: https://issues.redhat.com/browse/RHEL-75958 commit d5df87e3fccecde67866f587e187e67b503a0be9 Author: Mario Limonciello <mario.limonciello@amd.com> Date: Mon Mar 24 12:57:25 2025 -0500 drm/amd/display: Optimize custom brightness curve commit 03b979e upstream. [Why] When BIOS includes a lot of custom brightness data points, walking the entire list can be time consuming. This is most noticed when dragging a power slider. The "higher" values are "slower" to drag around. [How] Move custom brightness calculation loop into a static function. Before starting the loop check the "half way" data point to see how it compares to the input. If greater than the half way data point use that as the starting point instead. Reviewed-by: Alex Hung <alex.hung@amd.com> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Roman Li <roman.li@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: José Expósito <jexposit@redhat.com>
1 parent e42de47 commit c6a29aa

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,41 +4655,54 @@ static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps,
46554655
return 1;
46564656
}
46574657

4658-
static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *caps,
4659-
uint32_t brightness)
4658+
static void convert_custom_brightness(const struct amdgpu_dm_backlight_caps *caps,
4659+
uint32_t *brightness)
46604660
{
4661-
unsigned int min, max;
46624661
u8 prev_signal = 0, prev_lum = 0;
4662+
int i = 0;
46634663

4664-
if (!get_brightness_range(caps, &min, &max))
4665-
return brightness;
4666-
4667-
for (int i = 0; i < caps->data_points; i++) {
4668-
u8 signal, lum;
4664+
if (amdgpu_dc_debug_mask & DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE)
4665+
return;
46694666

4670-
if (amdgpu_dc_debug_mask & DC_DISABLE_CUSTOM_BRIGHTNESS_CURVE)
4671-
break;
4667+
if (!caps->data_points)
4668+
return;
46724669

4673-
signal = caps->luminance_data[i].input_signal;
4674-
lum = caps->luminance_data[i].luminance;
4670+
/* choose start to run less interpolation steps */
4671+
if (caps->luminance_data[caps->data_points/2].input_signal > *brightness)
4672+
i = caps->data_points/2;
4673+
do {
4674+
u8 signal = caps->luminance_data[i].input_signal;
4675+
u8 lum = caps->luminance_data[i].luminance;
46754676

46764677
/*
46774678
* brightness == signal: luminance is percent numerator
46784679
* brightness < signal: interpolate between previous and current luminance numerator
46794680
* brightness > signal: find next data point
46804681
*/
4681-
if (brightness < signal)
4682-
lum = prev_lum + DIV_ROUND_CLOSEST((lum - prev_lum) *
4683-
(brightness - prev_signal),
4684-
signal - prev_signal);
4685-
else if (brightness > signal) {
4682+
if (*brightness > signal) {
46864683
prev_signal = signal;
46874684
prev_lum = lum;
4685+
i++;
46884686
continue;
46894687
}
4690-
brightness = DIV_ROUND_CLOSEST(lum * brightness, 101);
4691-
break;
4692-
}
4688+
if (*brightness < signal)
4689+
lum = prev_lum + DIV_ROUND_CLOSEST((lum - prev_lum) *
4690+
(*brightness - prev_signal),
4691+
signal - prev_signal);
4692+
*brightness = DIV_ROUND_CLOSEST(lum * *brightness, 101);
4693+
return;
4694+
} while (i < caps->data_points);
4695+
}
4696+
4697+
static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *caps,
4698+
uint32_t brightness)
4699+
{
4700+
unsigned int min, max;
4701+
4702+
if (!get_brightness_range(caps, &min, &max))
4703+
return brightness;
4704+
4705+
convert_custom_brightness(caps, &brightness);
46934706

46944707
// Rescale 0..255 to min..max
46954708
return min + DIV_ROUND_CLOSEST((max - min) * brightness,

0 commit comments

Comments
 (0)