drm/amd/display: don't overwrite regamma LUT with empty data
Subsystems (3)
v3 cover drm/amd/display: don't overwrite regamma LUT with empty data
Hi,
Xaver first reported flickering when changing GAMMA_LUT often in KDE with an HDR-enabled display:
https://gitlab.freedesktop.org/drm/amd/-/issues/4444
This issue is reproducible on Fedora 42 from [1], with integrated and/or external monitors. I was able to reproduce it on DCN3.01, but other users also reported similar issue with DCN3 and DCN4 families. Besides that, when setting Night Light mode and changing a Display setting, such as Overscan, colors on the screen look like gamma LUT was lost (and it was).
After further investigation, the root cause of all these problems appears to be the way DM updates the DC stream's color state at atomic_check, allowing test-only commit settings to override non-blocking commit settings before it is committed in commit_tail. Xaver explained that KWin always performs a test commit without the LUT, then another with the LUT, and finally a non-test-only commit with the same LUT value still set. This sequence makes the issue more likely to occur, as the commit_tail of a non-blocking commit can delay until a subsequent test-only commit without the LUT "removes" the gamma LUT set by the non-blocking commit at atomic_check from the DC stream's state.
This series resolves all reported issues by moving DC stream color changes from atomic_check to atomic_setup_commit, preventing test-only commit CRTC color properties from being programmed into commit_tail. I see this change in line with the kernel-doc on amdgpu_dm_atomic_check(), which says: "It is important not to modify the existing DC state. Otherwise, atomic_check may unexpectedly commit hardware changes."
Adding here a shortened trace that exemplifies this bad sequence with some custom printk to track color settings in drm_atomic_state:
[ +0.000046] DRM: non block commit call: begin [ +0.000003] amdgpu 0000:04:00.0: [drm:drm_atomic_check_only [drm]] checking 00000000183d1556 <-- non-blocking commit [ +0.000053] amdgpu: AMD DM: atomic_check: CHECK color mgmt: color change: 1, AMD regamma Tf update: 0, needs modeset: 0 for drm_atomic_state: 00000000183d1556 [ +0.000005] amdgpu: program atomic regamma? 1 for drm_atomic_state: 00000000183d1556 [ +0.000003] amdgpu: AMD DM: set_atomic_regamma: PROGRAM regamma [ +0.000699] amdgpu 0000:04:00.0: [drm:drm_atomic_nonblocking_commit [drm]] committing 00000000183d1556 nonblocking [ +0.000076] DRM: non block commit call: end [ +0.000002] amdgpu 0000:04:00.0: [drm:drm_atomic_get_connector_state [drm]] Added [CONNECTOR:93:eDP-1] 00000000c74c75cc state to 00000000bce01e59 <-- test-only commit [[ +0.000046] amdgpu 0000:04:00.0: [drm:drm_atomic_get_crtc_state [drm]] Added [CRTC:79:crtc-0] 000000004fe38ea2 state to 00000000bce01e59 [ +0.000048] amdgpu 0000:04:00.0: [drm:drm_atomic_get_plane_state [drm]] Added [PLANE:76:plane-6] 00000000a3ba0680 state to 00000000bce01e59 [ -0.000252] amdgpu 0000:04:00.0: [drm:amdgpu_dm_atomic_commit_tail [amdgpu]] amdgpu_crtc id:0 crtc_state_flags: enable:1, active:1, planes_changed:1, mode_changed:0,active_changed:0,connectors_changed:0 [ +0.000045] amdgpu 0000:04:00.0: [drm:drm_atomic_get_plane_state [drm]] Added [PLANE:58:plane-3] 0000000007ae0fe5 state to 00000000bce01e59 [ +0.000073] DRM: color mgmt changed for DEGAMMA? 0 [ +0.000054] DRM: color mgmt changed for CTM? 0 [ +0.000314] DRM: color mgmt changed for REGAMMA? 1 [ +0.000004] DRM: TEST ONLY call: begin [ +0.000003] amdgpu 0000:04:00.0: [drm:drm_atomic_check_only [drm]] checking 00000000bce01e59 <-- test-only commit [ +0.000055] amdgpu: AMD DM: atomic check: CHECK color mgmt: color change: 1, AMD regamma Tf update: 0, needs modeset: 0 for drm_atomic_state: 00000000bce01e59 [ +0.000005] amdgpu: program atomic regamma? 0 for drm_atomic_state 00000000bce01e59 [ +0.000003] amdgpu: AMD DM: set atomic regamma: REMOVE regamma [ +0.000247] amdgpu 0000:04:00.0: [drm:amdgpu_dm_atomic_commit_tail [amdgpu]] [HDCP_DM] pipe_ctx dispname=ANX7530 U [ +0.000441] amdgpu 0000:04:00.0: [drm:amdgpu_dm_atomic_commit_tail [amdgpu]] crtc:0, pflip_stat:AMDGPU_FLIP_SUBMITTED [ +0.000731] amdgpu: AMD DM: commit planes: color mgmt changed, out tf type: 2 for drm_atomic_commit 00000000183d1556 <-- non-blocking commit taking out TF = BYPASS [ +0.000570] DC: set_output_transfer_func? enable: 0, out_tf:1 [ +0.000005] DC: set_output_transfer_func: begin [ +0.000004] DC: set_output_transfer_func: configure output gamma: 2 <-- BYPASS [ +0.000004] DC: set_output_gamma: begin [ +0.000002] DC: set_output_gamma: DISABLE OGAM [ +0.000107] amdgpu 0000:04:00.0: [drm:drm_atomic_state_default_clear [drm]] Clearing atomic state 00000000183d1556 [ +0.000053] DRM: TEST ONLY call: end [ +0.000008] amdgpu 0000:04:00.0: [drm:drm_atomic_state_default_clear [drm]] Clearing atomic state 00000000bce01e59 [ +0.000012] amdgpu 0000:04:00.0: [drm:__drm_atomic_state_free [drm]] Freeing atomic state 00000000bce01e59 [ +0.000085] amdgpu 0000:04:00.0: [drm:__drm_atomic_state_free [drm]] Freeing atomic state 00000000183d1556
I hope this trace can illustrate the situation.
[1] https://bodhi.fedoraproject.org/updates/FEDORA-2025-b58c14c454
v1: https://lore.kernel.org/amd-gfx/[email protected]/
- complete redesign targeting DM instead of DC
v2: https://lore.kernel.org/amd-gfx/[email protected]/
- switch from pr_info to drm_dbg_atomic
- nest amdgpu_dm_check_crtc_color_mgmt in amdgpu_dm_update_crtc_color_mgmt (Harry)
- use kvfree instead of dc_release_transfer_func since out_tf and stream->out_transfer_func isn't refcounted.
- add Harry r-b, but the 2nd patch changed a lot so should be double checked.
PS: maybe we should do a follow-up refactor in the amdgpu_dm_atomic_check() and move other DC state changes from atomic_check to atomic_setup_commit.
Best Regards,
Melissa
Melissa Wen (2):
drm/amd/display: update color on atomic commit time drm/amd/display: change dc stream color settings only in atomic commit
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 38 +++++++- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 86 ++++++++++++++----- 3 files changed, 101 insertions(+), 25 deletions(-)
Signature · 1 line
2.47.2
PATCH v3 1/2 drm/amd/display: update color on atomic commit time
Use atomic_commit_setup to change the DC stream state. It's a preparation to remove from atomic_check changes in CRTC color components of DC stream state and prevent DC to commit TEST_ONLY changes.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +35 -1
@@ -233,6 +233,7 @@ static int amdgpu_dm_encoder_init(struct drm_device *dev,static int amdgpu_dm_connector_get_modes (struct drm_connector *connector); +static int amdgpu_dm_atomic_setup_commit (struct drm_atomic_state *state);static void amdgpu_dm_atomic_commit_tail (struct drm_atomic_state *state); static int amdgpu_dm_atomic_check(struct drm_device *dev,
@@ -3641,7 +3642,7 @@ static const struct drm_mode_config_funcs amdgpu_dm_mode_funcs = {static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = { .atomic_commit_tail = amdgpu_dm_atomic_commit_tail, - .atomic_commit_setup = drm_dp_mst_atomic_setup_commit, + .atomic_commit_setup = amdgpu_dm_atomic_setup_commit, };static void update_connector_ext_caps (struct amdgpu_dm_connector *aconnector)
@@ -10272,6 +10273,39 @@ static void amdgpu_dm_update_hdcp(struct drm_atomic_state *state) } } +static int amdgpu_dm_atomic_setup_commit (struct drm_atomic_state *state) +{ +struct drm_crtc *crtc; +struct drm_crtc_state *old_crtc_state, *new_crtc_state; +struct dm_crtc_state *dm_old_crtc_state, *dm_new_crtc_state; +int i, ret; + + ret =drm_dp_mst_atomic_setup_commit (state); +if (ret) +return ret; + +for_each_oldnew_crtc_in_state (state, crtc, old_crtc_state, new_crtc_state, i) { + dm_old_crtc_state =to_dm_crtc_state (old_crtc_state); + dm_new_crtc_state =to_dm_crtc_state (new_crtc_state); +/* +* Color management settings. We also update color properties +* when a modeset is needed, to ensure it gets reprogrammed. +*/ +if (dm_new_crtc_state->base.active && dm_new_crtc_state->stream && + (dm_new_crtc_state->base.color_mgmt_changed || + dm_old_crtc_state->regamma_tf != dm_new_crtc_state->regamma_tf || +drm_atomic_crtc_needs_modeset (new_crtc_state))) { + ret =amdgpu_dm_update_crtc_color_mgmt (dm_new_crtc_state); +if (ret) { +drm_dbg_atomic (state->dev,"Failed to update color state\n" ); +return ret; + } + } + } + +return 0 ; +} +/** * amdgpu_dm_atomic_commit_tail() - AMDgpu DM's commit tail implementation. * @state: The atomic state to commit
Signature · 1 line
2.47.2
PATCH v3 2/2 drm/amd/display: change dc stream color settings only in atomic commit
In reply to Melissa WenDon't update DC stream color components during atomic check. The driver will continue validating the new CRTC color state but will not change DC stream color components. The DC stream color state will only be programmed at commit time in the atomic_setup_commit stage.
It fixes gamma LUT loss reported by KDE users when changing brightness quickly or changing Display settings (such as overscan) with nightlight on and HDR. As KWin can do a test commit with color settings different from those that should be applied in a non-test-only commit, if the driver changes DC stream color state in atomic check, this state can be eventually HW programmed in commit tail, instead of the respective state set by the non-blocking commit.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 86 ++++++++++++++----- 3 files changed, 66 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
@@ -11118,7 +11118,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm,if (dm_new_crtc_state->base.color_mgmt_changed || dm_old_crtc_state->regamma_tf != dm_new_crtc_state->regamma_tf ||drm_atomic_crtc_needs_modeset (new_crtc_state)) { - ret =amdgpu_dm_update_crtc_color_mgmt (dm_new_crtc_state); + ret =amdgpu_dm_check_crtc_color_mgmt (dm_new_crtc_state, true);if (ret) goto fail; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2 -0
@@ -1041,6 +1041,8 @@ void amdgpu_dm_init_color_mod(void);int amdgpu_dm_create_color_properties (struct amdgpu_device *adev);int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state);int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc); +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, +bool check_only);int amdgpu_dm_update_plane_color_mgmt (struct dm_crtc_state *crtc,struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +63 -23
144 lines not on this page · raw message
Signature · 1 line
2.47.2
Re: [PATCH v3 2/2] drm/amd/display: change dc stream color settings only in atomic commit
Quoted 190 lines · Melissa Wen
Don't update DC stream color components during atomic check. The driver will continue validating the new CRTC color state but will not change DC stream color components. The DC stream color state will only be programmed at commit time in the
atomic_setup_commitstage.It fixes gamma LUT loss reported by KDE users when changing brightness quickly or changing Display settings (such as overscan) with nightlight on and HDR. As KWin can do a test commit with color settings different from those that should be applied in a non-test-only commit, if the driver changes DC stream color state in atomic check, this state can be eventually HW programmed in commit tail, instead of the respective state set by the non-blocking commit.
Reported-by Xaver Hugl <[email protected]>Reviewed-by Harry Wentland <[email protected]> #v2Signed-off-by Melissa Wen <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 86 ++++++++++++++----- 3 files changed, 66 insertions(+), 24 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -11118,7 +11118,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm,if (dm_new_crtc_state->base.color_mgmt_changed || dm_old_crtc_state->regamma_tf != dm_new_crtc_state->regamma_tf ||drm_atomic_crtc_needs_modeset (new_crtc_state)) { - ret =amdgpu_dm_update_crtc_color_mgmt (dm_new_crtc_state); + ret =amdgpu_dm_check_crtc_color_mgmt (dm_new_crtc_state, true);if (ret) goto fail; }drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2
-0@@ -1041,6 +1041,8 @@ void amdgpu_dm_init_color_mod(void);int amdgpu_dm_create_color_properties (struct amdgpu_device *adev);int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state);int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc); +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, +bool check_only);int amdgpu_dm_update_plane_color_mgmt (struct dm_crtc_state *crtc,struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state);drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +53
-23@@ -566,12 +566,11 @@ static int __set_output_tf(struct dc_transfer_func *func,return res ?0 : -ENOMEM ; } -static int amdgpu_dm_set_atomic_regamma (struct dc_stream_state *stream, +static int amdgpu_dm_set_atomic_regamma (struct dc_transfer_func *out_tf,const struct drm_color_lut *regamma_lut,uint32_t regamma_size,bool has_rom,enum dc_transfer_func_predefined tf) { -struct dc_transfer_func *out_tf = &stream->out_transfer_func;int ret =0 ;if (regamma_size || tf !=TRANSFER_FUNCTION_LINEAR ) {@@ -885,33 +884,33 @@ int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state) }/** -* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* amdgpu_dm_check_crtc_color_mgmt: Check if DRM color props are programmable by DC. * @crtc: amdgpu_dm crtc state +* @check_only: only check color state without update dc stream * -* With no plane level color management properties we're free to use any -* of the HW blocks as long as the CRTC CTM always comes before the -* CRTC RGM and after the CRTC DGM. -* -* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. -* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. -* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* This function just verifies CRTC LUT sizes, if there is enough space for +* output transfer function and if its parameters can be calculated by AMD +* color module. It also adjusts some settings for programming CRTC degamma at +* plane stage, using plane DGM block. * * The RGM block is typically more fully featured and accurate across * all ASICs - DCE can't support a custom non-linear CRTC DGM. * * For supporting both plane level color management and CRTC level color -* management at once we have to either restrict the usage of CRTC properties -* or blend adjustments together. +* management at once we have to either restrict the usage of some CRTC +* properties or blend adjustments together. * * Returns: -* 0 on success. Error code if setup fails. +* 0 on success. Error code if validation fails. */ -int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) + +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, +bool check_only) {struct dc_stream_state *stream = crtc->stream;struct amdgpu_device *adev =drm_to_adev (crtc->base.state->dev);bool has_rom = adev->asic_type <=CHIP_RAVEN ; -struct drm_color_ctm *ctm =NULL ; +struct dc_transfer_func *out_tf;const struct drm_color_lut *degamma_lut, *regamma_lut;uint32_t degamma_size, regamma_size;bool has_regamma, has_degamma;@@ -940,6 +939,14 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) crtc->cm_has_degamma = false; crtc->cm_is_degamma_srgb = false; +if (check_only) { + out_tf =kvzalloc (sizeof (*out_tf),GFP_KERNEL ); +if (!out_tf) +return -ENOMEM ; + }else { + out_tf = &stream->out_transfer_func; + } +/* Setup regamma and degamma. */ if (is_legacy) {/* @@ -954,8 +961,8 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* inverse color ramp in legacy userspace. */ crtc->cm_is_degamma_srgb = true; - stream->out_transfer_func.type =TF_TYPE_DISTRIBUTED_POINTS ; - stream->out_transfer_func.tf =TRANSFER_FUNCTION_SRGB ; + out_tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + out_tf->tf =TRANSFER_FUNCTION_SRGB ;/* * Note: although we pass has_rom as parameter here, we never * actually use ROM because the color module only takes the ROM @@ -963,16 +970,12 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* * See more in mod_color_calculate_regamma_params() */ - r =__set_legacy_tf (&stream->out_transfer_func, regamma_lut, + r =__set_legacy_tf (out_tf, regamma_lut, regamma_size, has_rom); -if (r) -return r; }else { regamma_size = has_regamma ? regamma_size :0 ; - r =amdgpu_dm_set_atomic_regamma (stream, regamma_lut, + r =amdgpu_dm_set_atomic_regamma (out_tf, regamma_lut, regamma_size, has_rom, tf); -if (r) -return r; }/* @@ -981,6 +984,43 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* have to place the CTM in the OCSC in that case. */ crtc->cm_has_degamma = has_degamma; +if (check_only) +kvfree (out_tf); + +return r; +} + +/** +* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* @crtc: amdgpu_dm crtc state +* +* With no plane level color management properties we're free to use any +* of the HW blocks as long as the CRTC CTM always comes before the +* CRTC RGM and after the CRTC DGM. +* +* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. +* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. +* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* +* The RGM block is typically more fully featured and accurate across +* all ASICs - DCE can't support a custom non-linear CRTC DGM. +* +* For supporting both plane level color management and CRTC level color +* management at once we have to either restrict the usage of CRTC properties +* or blend adjustments together. +* +* Returns: +* 0 on success. Error code if setup fails.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) · line 1023
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+*/ +int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) +{ +struct dc_stream_state *stream = crtc->stream; +struct drm_color_ctm *ctm =NULL ; +int ret; + + ret =amdgpu_dm_check_crtc_color_mgmt (crtc, false); +if (ret) +return ret;
Thanks. I like it.
Harry
Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +0
-0/* Setup CRTC CTM. */ if (crtc->base.ctm) {
Re: [PATCH v3 2/2] drm/amd/display: change dc stream color settings only in atomic commit
Quoted 7 lines · Harry Wentland
Quoted 5 lines · Melissa Wen
Don't update DC stream color components during atomic check. The driver will continue validating the new CRTC color state but will not change DC stream color components. The DC stream color state will only be programmed at commit time in the
atomic_setup_commitstage.
Quoted 7 lines
Quoted 7 lines
It fixes gamma LUT loss reported by KDE users when changing brightness quickly or changing Display settings (such as overscan) with nightlight on and HDR. As KWin can do a test commit with color settings different from those that should be applied in a non-test-only commit, if the driver changes DC stream color state in atomic check, this state can be eventually HW programmed in commit tail, instead of the respective state set by the non-blocking commit.
Hello,
I'm not sure if this series was already applied somewhere. I don't see it in asdn.
Can someone double check?
Thanks,
Melissa
Quoted 197 lines
Quoted 178 lines
Reported-by Xaver Hugl <[email protected]>Reviewed-by Harry Wentland <[email protected]> #v2Signed-off-by Melissa Wen <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 86 ++++++++++++++----- 3 files changed, 66 insertions(+), 24 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1
-1@@ -11118,7 +11118,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm,if (dm_new_crtc_state->base.color_mgmt_changed || dm_old_crtc_state->regamma_tf != dm_new_crtc_state->regamma_tf ||drm_atomic_crtc_needs_modeset (new_crtc_state)) { - ret =amdgpu_dm_update_crtc_color_mgmt (dm_new_crtc_state); + ret =amdgpu_dm_check_crtc_color_mgmt (dm_new_crtc_state, true);if (ret) goto fail; }drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2
-0@@ -1041,6 +1041,8 @@ void amdgpu_dm_init_color_mod(void);int amdgpu_dm_create_color_properties (struct amdgpu_device *adev);int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state);int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc); +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, +bool check_only);int amdgpu_dm_update_plane_color_mgmt (struct dm_crtc_state *crtc,struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state);drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +53
-23@@ -566,12 +566,11 @@ static int __set_output_tf(struct dc_transfer_func *func,return res ?0 : -ENOMEM ; } -static int amdgpu_dm_set_atomic_regamma (struct dc_stream_state *stream, +static int amdgpu_dm_set_atomic_regamma (struct dc_transfer_func *out_tf,const struct drm_color_lut *regamma_lut,uint32_t regamma_size,bool has_rom,enum dc_transfer_func_predefined tf) { -struct dc_transfer_func *out_tf = &stream->out_transfer_func;int ret =0 ;if (regamma_size || tf !=TRANSFER_FUNCTION_LINEAR ) {@@ -885,33 +884,33 @@ int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state) }/** -* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* amdgpu_dm_check_crtc_color_mgmt: Check if DRM color props are programmable by DC. * @crtc: amdgpu_dm crtc state +* @check_only: only check color state without update dc stream * -* With no plane level color management properties we're free to use any -* of the HW blocks as long as the CRTC CTM always comes before the -* CRTC RGM and after the CRTC DGM. -* -* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. -* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. -* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* This function just verifies CRTC LUT sizes, if there is enough space for +* output transfer function and if its parameters can be calculated by AMD +* color module. It also adjusts some settings for programming CRTC degamma at +* plane stage, using plane DGM block. * * The RGM block is typically more fully featured and accurate across * all ASICs - DCE can't support a custom non-linear CRTC DGM. * * For supporting both plane level color management and CRTC level color -* management at once we have to either restrict the usage of CRTC properties -* or blend adjustments together. +* management at once we have to either restrict the usage of some CRTC +* properties or blend adjustments together. * * Returns: -* 0 on success. Error code if setup fails. +* 0 on success. Error code if validation fails. */ -int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) + +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, +bool check_only) {struct dc_stream_state *stream = crtc->stream;struct amdgpu_device *adev =drm_to_adev (crtc->base.state->dev);bool has_rom = adev->asic_type <=CHIP_RAVEN ; -struct drm_color_ctm *ctm =NULL ; +struct dc_transfer_func *out_tf;const struct drm_color_lut *degamma_lut, *regamma_lut;uint32_t degamma_size, regamma_size;bool has_regamma, has_degamma;@@ -940,6 +939,14 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) crtc->cm_has_degamma = false; crtc->cm_is_degamma_srgb = false; +if (check_only) { + out_tf =kvzalloc (sizeof (*out_tf),GFP_KERNEL ); +if (!out_tf) +return -ENOMEM ; + }else { + out_tf = &stream->out_transfer_func; + } +/* Setup regamma and degamma. */ if (is_legacy) {/* @@ -954,8 +961,8 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* inverse color ramp in legacy userspace. */ crtc->cm_is_degamma_srgb = true; - stream->out_transfer_func.type =TF_TYPE_DISTRIBUTED_POINTS ; - stream->out_transfer_func.tf =TRANSFER_FUNCTION_SRGB ; + out_tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + out_tf->tf =TRANSFER_FUNCTION_SRGB ;/* * Note: although we pass has_rom as parameter here, we never * actually use ROM because the color module only takes the ROM @@ -963,16 +970,12 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* * See more in mod_color_calculate_regamma_params() */ - r =__set_legacy_tf (&stream->out_transfer_func, regamma_lut, + r =__set_legacy_tf (out_tf, regamma_lut, regamma_size, has_rom); -if (r) -return r; }else { regamma_size = has_regamma ? regamma_size :0 ; - r =amdgpu_dm_set_atomic_regamma (stream, regamma_lut, + r =amdgpu_dm_set_atomic_regamma (out_tf, regamma_lut, regamma_size, has_rom, tf); -if (r) -return r; }/* @@ -981,6 +984,43 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* have to place the CTM in the OCSC in that case. */ crtc->cm_has_degamma = has_degamma; +if (check_only) +kvfree (out_tf); + +return r; +} + +/** +* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* @crtc: amdgpu_dm crtc state +* +* With no plane level color management properties we're free to use any +* of the HW blocks as long as the CRTC CTM always comes before the +* CRTC RGM and after the CRTC DGM. +* +* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. +* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. +* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* +* The RGM block is typically more fully featured and accurate across +* all ASICs - DCE can't support a custom non-linear CRTC DGM. +* +* For supporting both plane level color management and CRTC level color +* management at once we have to either restrict the usage of CRTC properties +* or blend adjustments together. +* +* Returns: +* 0 on success. Error code if setup fails. drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) · line 1023
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+*/ +int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) +{ +struct dc_stream_state *stream = crtc->stream; +struct drm_color_ctm *ctm =NULL ; +int ret; + + ret =amdgpu_dm_check_crtc_color_mgmt (crtc, false); +if (ret) +return ret;Thanks. I like it.
Reviewed-by Harry Wentland <[email protected]>Harry
Quoted 3 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +0
-0/* Setup CRTC CTM. */ if (crtc->base.ctm) {
Re: [PATCH v3 2/2] drm/amd/display: change dc stream color settings only in atomic commit
Quoted 17 lines · Melissa Wen
Quoted 7 lines · Harry Wentland
Quoted 5 lines · Melissa Wen
Don't update DC stream color components during atomic check. The driver will continue validating the new CRTC color state but will not change DC stream color components. The DC stream color state will only be programmed at commit time in the
atomic_setup_commitstage.Quoted 7 lines
Quoted 7 lines
It fixes gamma LUT loss reported by KDE users when changing brightness quickly or changing Display settings (such as overscan) with nightlight on and HDR. As KWin can do a test commit with color settings different from those that should be applied in a non-test-only commit, if the driver changes DC stream color state in atomic check, this state can be eventually HW programmed in commit tail, instead of the respective state set by the non-blocking commit.
Quoted 4 lines
Hello,
I'm not sure if this series was already applied somewhere. I don't see it in asdn.
Applied. It should land soon after going through our CI pipeline.
Harry
Quoted 198 lines
Can someone double check?
Thanks,
Melissa
Quoted 191 lines
Quoted 173 lines
Reported-by Xaver Hugl <[email protected]>Reviewed-by Harry Wentland <[email protected]> #v2Signed-off-by Melissa Wen <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 2 +-.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h| 2 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 86 ++++++++++++++-----3 files changed, 66 insertions(+), 24 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-0@@ -11118,7 +11118,7 @@ static int dm_update_crtc_state(struct amdgpu_display_manager *dm,if (
dm_new_crtc_state->base.color_mgmt_changed||dm_old_crtc_state->regamma_tf!=dm_new_crtc_state->regamma_tf||drm_atomic_crtc_needs_modeset(new_crtc_state)) {
- ret =amdgpu_dm_update_crtc_color_mgmt(dm_new_crtc_state); + ret =amdgpu_dm_check_crtc_color_mgmt(dm_new_crtc_state, true); if (ret)
goto fail;
}drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +2
-0@@ -1041,6 +1041,8 @@ void amdgpu_dm_init_color_mod(void); int amdgpu_dm_create_color_properties(struct amdgpu_device *adev); int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state); int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc); +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, + bool check_only); int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, struct drm_plane_state *plane_state, struct dc_plane_state *dc_plane_state);drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +52
-22@@ -566,12 +566,11 @@ static int __set_output_tf(struct dc_transfer_func *func, return res ? 0 : -ENOMEM; } -static int amdgpu_dm_set_atomic_regamma(struct dc_stream_state *stream, +static int amdgpu_dm_set_atomic_regamma (struct dc_transfer_func *out_tf, const struct drm_color_lut *regamma_lut, uint32_t regamma_size, bool has_rom, enum dc_transfer_func_predefined tf) { - struct dc_transfer_func *out_tf = &stream->out_transfer_func; int ret = 0; if (regamma_size || tf != TRANSFER_FUNCTION_LINEAR) {@@ -885,33 +884,33 @@ int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state) } /** -* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* amdgpu_dm_check_crtc_color_mgmt: Check if DRM color props are programmable by DC. * @crtc: amdgpu_dm crtc state +* @check_only: only check color state without update dc stream * -* With no plane level color management properties we're free to use any -* of the HW blocks as long as the CRTC CTM always comes before the -* CRTC RGM and after the CRTC DGM. -* -* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. -* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. -* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* This function just verifies CRTC LUT sizes, if there is enough space for +* output transfer function and if its parameters can be calculated by AMD +* color module. It also adjusts some settings for programming CRTC degamma at +* plane stage, using plane DGM block. * * The RGM block is typically more fully featured and accurate across * all ASICs - DCE can't support a custom non-linear CRTC DGM. * * For supporting both plane level color management and CRTC level color -* management at once we have to either restrict the usage of CRTC properties -* or blend adjustments together. +* management at once we have to either restrict the usage of some CRTC +* properties or blend adjustments together. * * Returns: -* 0 on success. Error code if setup fails. +* 0 on success. Error code if validation fails. */ -int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) + +int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc, + bool check_only) { struct dc_stream_state *stream = crtc->stream; struct amdgpu_device *adev = drm_to_adev(crtc->base.state->dev); bool has_rom = adev->asic_type <= CHIP_RAVEN; - struct drm_color_ctm *ctm = NULL; + struct dc_transfer_func *out_tf; const struct drm_color_lut *degamma_lut, *regamma_lut; uint32_t degamma_size, regamma_size; bool has_regamma, has_degamma;@@ -940,6 +939,14 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) crtc->cm_has_degamma = false; crtc->cm_is_degamma_srgb = false; + if (check_only) { + out_tf = kvzalloc(sizeof(*out_tf), GFP_KERNEL); + if (!out_tf) + return -ENOMEM; + } else { + out_tf = &stream->out_transfer_func; + } + /* Setup regamma and degamma. */ if (is_legacy) { /*@@ -954,8 +961,8 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* inverse color ramp in legacy userspace. */ crtc->cm_is_degamma_srgb = true; - stream->out_transfer_func.type = TF_TYPE_DISTRIBUTED_POINTS; - stream->out_transfer_func.tf = TRANSFER_FUNCTION_SRGB; + out_tf->type = TF_TYPE_DISTRIBUTED_POINTS; + out_tf->tf = TRANSFER_FUNCTION_SRGB; /** Note: although we pass has_rom as parameter here, we never * actually use ROM because the color module only takes the ROM @@ -963,16 +970,12 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* * See more in mod_color_calculate_regamma_params() */ - r = __set_legacy_tf(&stream->out_transfer_func, regamma_lut, + r = __set_legacy_tf(out_tf, regamma_lut, regamma_size, has_rom); - if (r) - return r; } else { regamma_size = has_regamma ? regamma_size : 0; - r = amdgpu_dm_set_atomic_regamma(stream, regamma_lut, + r = amdgpu_dm_set_atomic_regamma(out_tf, regamma_lut, regamma_size, has_rom, tf); - if (r) - return r; } /*@@ -981,6 +984,43 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)* have to place the CTM in the OCSC in that case. */ crtc->cm_has_degamma = has_degamma; + if (check_only) + kvfree(out_tf); + + return r; +} + +/** +* amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. +* @crtc: amdgpu_dm crtc state +* +* With no plane level color management properties we're free to use any +* of the HW blocks as long as the CRTC CTM always comes before the +* CRTC RGM and after the CRTC DGM. +* +* - The CRTC RGM block will be placed in the RGM LUT block if it is non-linear. +* - The CRTC DGM block will be placed in the DGM LUT block if it is non-linear. +* - The CRTC CTM will be placed in the gamut remap block if it is non-linear. +* +* The RGM block is typically more fully featured and accurate across +* all ASICs - DCE can't support a custom non-linear CRTC DGM. +* +* For supporting both plane level color management and CRTC level color +* management at once we have to either restrict the usage of CRTC properties +* or blend adjustments together. +* +* Returns: +* 0 on success. Error code if setup fails. drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc) · line 1023
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+*/ +int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) +{ + struct dc_stream_state *stream = crtc->stream; + struct drm_color_ctm *ctm = NULL; + int ret; + + ret = amdgpu_dm_check_crtc_color_mgmt(crtc, false); + if (ret) + return ret;Thanks. I like it.
Reviewed-by Harry Wentland <[email protected]>Harry
Quoted 2 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +0
-0/* Setup CRTC CTM. */ if (crtc->base.ctm) {