From: Chenyu Chen <chen-yu.chen@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Harry Wentland <harry.wentland@amd.com>,
Leo Li <sunpeng.li@amd.com>,
Aurabindo Pillai <aurabindo.pillai@amd.com>,
Roman Li <roman.li@amd.com>, Wayne Lin <wayne.lin@amd.com>,
Tom Chung <chiahsuan.chung@amd.com>,
"Fangzhi Zuo" <jerry.zuo@amd.com>,
Dan Wheeler <daniel.wheeler@amd.com>, Ray Wu <Ray.Wu@amd.com>,
Ivan Lipski <ivan.lipski@amd.com>, Alex Hung <alex.hung@amd.com>,
James Lin <PingLei.Lin@amd.com>,
Chenyu Chen <Chen-Yu.Chen@amd.com>,
Alan Liu <haoping.liu@amd.com>,
Chenyu Chen <chen-yu.chen@amd.com>
Subject: [PATCH 01/27] drm/amd/display: Avoid per-entry long division in __drm_lut32_to_dc_gamma
Date: Wed, 25 Nov 2026 14:54:50 +0800 [thread overview]
Message-ID: <20261125065631.3889665-2-chen-yu.chen@amd.com> (raw)
In-Reply-To: <20261125065631.3889665-1-chen-yu.chen@amd.com>
From: Alan Liu <haoping.liu@amd.com>
[Why]
__drm_lut32_to_dc_gamma() converts each entry of a 4096-entry 32-bit LUT
with dc_fixpt_from_fraction(v, 0xFFFFFFFF). That helper does a 64-bit
division followed by a 32-iteration bit-by-bit long division, so one LUT
costs 12288 such calls.
When a plane with a 32-bit LUT colorop is recreated in atomic check (for
example on every plane size change), this conversion accounts for ~97%
of amdgpu_dm_update_plane_color_mgmt() time, and it runs for TEST_ONLY
commits as well.
[How]
The denominator is constant, so the result has a closed form:
v * 2^32 / (2^32 - 1) = v + v / (2^32 - 1). The fractional term is below
1 and rounds up exactly when v >= 2^31, so the result is v + (v >= 2^31).
This is bit-exact with the previous dc_fixpt_from_fraction() result for
all 2^32 inputs (checked exhaustively in userspace), so there is no
functional change.
With this change __drm_lut32_to_dc_gamma() takes >99% less time, and
amdgpu_dm_update_plane_color_mgmt() takes ~95% less time per recreated
plane. KUnit amdgpu_dm_color results are unchanged.
Cc: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alan Liu <haoping.liu@amd.com>
Signed-off-by: Chenyu Chen <chen-yu.chen@amd.com>
---
.../amd/display/amdgpu_dm/amdgpu_dm_color.c | 21 ++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
index 45cea72111c7..e09a8a686ec9 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
@@ -534,6 +534,21 @@ void __drm_lut_to_dc_gamma(const struct drm_color_lut *lut,
}
EXPORT_IF_KUNIT(__drm_lut_to_dc_gamma);
+/*
+ * Convert a 32-bit DRM LUT value to S31.32 fixed point, i.e. v / 0xFFFFFFFF.
+ *
+ * Bit-exact replacement for dc_fixpt_from_fraction(v, MAX_DRM_LUT32_VALUE),
+ * which does a 64-bit division plus a 32-iteration long division per value.
+ * With d = 2^32 - 1: v * 2^32 / d = v + v / d, and v / d is in [0, 1], so
+ * the rounded result is v + 1 when v / d >= 1/2, i.e. when v >= 2^31.
+ */
+static inline struct fixed31_32 __drm_lut32_value_to_fixpt(u32 v)
+{
+ struct fixed31_32 res = { .value = (long long)v + (v >= 0x80000000u) };
+
+ return res;
+}
+
/**
* __drm_lut32_to_dc_gamma - convert the drm_color_lut to dc_gamma.
* @lut: DRM lookup table for color conversion
@@ -547,9 +562,9 @@ void __drm_lut32_to_dc_gamma(const struct drm_color_lut32 *lut, struct dc_gamma
int i;
for (i = 0; i < MAX_COLOR_LUT_ENTRIES; i++) {
- gamma->entries.red[i] = dc_fixpt_from_fraction(lut[i].red, MAX_DRM_LUT32_VALUE);
- gamma->entries.green[i] = dc_fixpt_from_fraction(lut[i].green, MAX_DRM_LUT32_VALUE);
- gamma->entries.blue[i] = dc_fixpt_from_fraction(lut[i].blue, MAX_DRM_LUT32_VALUE);
+ gamma->entries.red[i] = __drm_lut32_value_to_fixpt(lut[i].red);
+ gamma->entries.green[i] = __drm_lut32_value_to_fixpt(lut[i].green);
+ gamma->entries.blue[i] = __drm_lut32_value_to_fixpt(lut[i].blue);
}
}
EXPORT_IF_KUNIT(__drm_lut32_to_dc_gamma);
--
2.43.0
next prev parent reply other threads:[~2026-11-25 6:55 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 6:54 [PATCH 00/27] DC Patches Nov 30 2026 Chenyu Chen
2026-11-25 6:54 ` Chenyu Chen [this message]
2026-11-25 6:54 ` [PATCH 02/27] drm/amd/display: Capture more diagnostic register state Chenyu Chen
2026-11-25 6:54 ` [PATCH 03/27] drm/amd/display: Add debug option to force DP link rate Chenyu Chen
2026-11-25 6:54 ` [PATCH 04/27] drm/amd/display: Reject Replay activation on an inactive link Chenyu Chen
2026-11-25 6:54 ` [PATCH 05/27] drm/amd/display: Decouple PROGRAM_CURSOR_UPDATE_NOW from dc and pipe_ctx Chenyu Chen
2026-11-25 6:54 ` [PATCH 06/27] drm/amd/display: Add DPMS-v2 init Chenyu Chen
2026-11-25 6:54 ` [PATCH 07/27] drm/amd/display: Expose per-CRTC pstate method in connector debugfs Chenyu Chen
2026-11-25 6:54 ` [PATCH 08/27] drm/amd/display: Add DPMS-v2 tx init Chenyu Chen
2026-11-25 6:54 ` [PATCH 09/27] drm/amd/display: Derive DCN6 DSCCLK range from DISPCLK Chenyu Chen
2026-11-25 6:54 ` [PATCH 10/27] drm/amd/display: Carry the stream and plane update bits in update_flags Chenyu Chen
2026-11-25 6:55 ` [PATCH 11/27] drm/amd/display: Add the vsync flip to the DC2 seamless update Chenyu Chen
2026-11-25 6:55 ` [PATCH 12/27] drm/amd/display: Preserve bandwidth floors in overrides Chenyu Chen
2026-11-25 6:55 ` [PATCH 13/27] drm/amd/display: Set HDMI bypass earlier Chenyu Chen
2026-11-25 6:55 ` [PATCH 14/27] drm/amd/display: Add DMUB timer reference clock to ref_clocks Chenyu Chen
2026-11-25 6:55 ` [PATCH 15/27] drm/amd/display: Guard connector I2C transfer without DDC pin Chenyu Chen
2026-11-28 9:43 ` Eren Özen
2026-11-25 6:55 ` [PATCH 16/27] drm/amd/display: Refactor ABM_SET_PIPE and ABM_SET_IMMEDIATE_DISABLE Chenyu Chen
2026-11-25 6:55 ` [PATCH 17/27] drm/amd/display: Implement link_set_dpms_off_v2 Chenyu Chen
2026-11-25 6:55 ` [PATCH 18/27] drm/amd/display: Add the immediate flip to the DC2 seamless update Chenyu Chen
2026-11-25 6:55 ` [PATCH 19/27] drm/amd/display: Test amdgpu_dm_dmub alt-ch apertures Chenyu Chen
2026-11-25 6:55 ` [PATCH 20/27] drm/amd/display: Test amdgpu_dm_dmub SET_CONFIG sync wait Chenyu Chen
2026-11-25 6:55 ` [PATCH 21/27] drm/amd/display: Test amdgpu_dm_dmub AUX transfer timeout Chenyu Chen
2026-11-25 6:55 ` [PATCH 22/27] drm/amd/display: Test amdgpu_dm_dmub fused IO replies Chenyu Chen
2026-11-25 6:55 ` [PATCH 23/27] drm/amd/display: Use Z8 enter plus exit for vblank reserve Chenyu Chen
2026-11-25 6:55 ` [PATCH 24/27] drm/amd/display: Fix two streams sharing one OTG Chenyu Chen
2026-11-25 6:55 ` [PATCH 25/27] drm/amd/display: Count planes, not pipes, in the surface check Chenyu Chen
2026-11-25 6:55 ` [PATCH 26/27] drm/amd/display: [FW Promotion] Release 0.1.86.0 Chenyu Chen
2026-11-25 6:55 ` [PATCH 27/27] drm/amd/display: Promote DC to 3.2.409 Chenyu Chen
2026-11-27 5:44 ` [PATCH 00/27] DC Patches Nov 30 2026 Chung, ChiaHsuan (Tom)
2026-11-30 14:10 ` Wheeler, Daniel
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=20261125065631.3889665-2-chen-yu.chen@amd.com \
--to=chen-yu.chen@amd.com \
--cc=PingLei.Lin@amd.com \
--cc=Ray.Wu@amd.com \
--cc=alex.hung@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=aurabindo.pillai@amd.com \
--cc=chiahsuan.chung@amd.com \
--cc=daniel.wheeler@amd.com \
--cc=haoping.liu@amd.com \
--cc=harry.wentland@amd.com \
--cc=ivan.lipski@amd.com \
--cc=jerry.zuo@amd.com \
--cc=roman.li@amd.com \
--cc=sunpeng.li@amd.com \
--cc=wayne.lin@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 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.