Bug 481467

Summary: Set refresh rate not applied when screen turn on after idle
Product: [Plasma] KScreen Reporter: Bernhard <micraft.b>
Component: commonAssignee: kscreen-bugs-null <kscreen-bugs-null>
Status: RESOLVED UPSTREAM    
Severity: normal CC: xaver.hugl
Priority: NOR Keywords: qt6
Version First Reported In: 5.93.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Bernhard 2024-02-17 14:35:44 UTC
SUMMARY
When I set my monitor to 120Hz and reboot, it still shows 120Hz after reboot kscreen-doctor and the kcm, but my monitor reports 144Hz. VRR is set to automatic (and does not seem to be used for the desktop).
Reproducible every time on this setup.

STEPS TO REPRODUCE
1. Set screen to lower than max refresh rate
2. Reboot system
3. Screen receives max refresh rate

OBSERVED RESULT
The monitor receives a different refresh than is set. Changing the Adaptive Sync mode does not seem correct the refresh rate. To get back to 120Hz, I need to set it to something else first, pressing Apply twice. `kscreen-doctor -o` ouput remains exactly identical (as checked by diff)

EXPECTED RESULT
The monitor should receive the refresh rate I set.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 5.93.0
KDE Frameworks Version: 5.249.0
Qt Version: 6.7.0 beta3
Kernel Version: 6.6.16-1-lts (64-bit)
Graphics Platform: Wayland
Processors: 24 × AMD Ryzen 9 5900X 12-Core Processor
Memory: 62.7 GiB of RAM
Graphics Processor: AMD Radeon RX 6600 XT

ADDITIONAL INFORMATION
We're talking Output 1 here.
$ kscreen-doctor -o
Output: 1 DP-2
	enabled
	connected
	priority 1
	DisplayPort
	Modes:  0:3840x2160@60!  1:3840x2160@144  2:3840x2160@120*  3:3840x2160@120  4:3840x2160@96  5:3840x2160@72  6:3840x2160@60  7:3840x2160@60  8:3840x2160@60  9:3840x2160@50  10:3840x2160@48  11:3840x2160@24  12:3840x2160@24  13:2560x1440@144  14:2560x1440@120  15:2560x1440@60  16:1920x1200@60  17:1920x1080@144  18:1920x1080@120  19:1920x1080@120  20:1920x1080@60  21:1920x1080@60  22:1920x1080@60  23:1920x1080@24  24:1920x1080@24  25:1600x1200@60  26:1680x1050@60  27:1280x1024@60  28:1440x900@60  29:1280x800@60  30:1280x720@120  31:1280x720@120  32:1280x720@100  33:1280x720@60  34:1280x720@60  35:1280x720@50  36:1024x768@75  37:1024x768@60  38:800x600@75  39:800x600@60  40:720x576@50  41:720x576@50  42:720x480@60  43:720x480@60  44:720x480@60  45:720x480@60  46:640x480@75  47:640x480@60  48:640x480@60  49:1600x1200@60  50:1280x1024@60  51:1024x768@60  52:2560x1600@60  53:1920x1200@60  54:1280x800@60  55:3840x2160@60  56:3200x1800@60  57:2880x1620@60  58:2560x1440@60  59:1920x1080@60  60:1600x900@60  61:1368x768@60  62:1280x720@60
	Geometry: 1280,0 3840x2160
	Scale: 1
	Rotation: 1
	Overscan: 0
	Vrr: Automatic
	RgbRange: unknown
	HDR: disabled
	Wide Color Gamut: disabled
	ICC profile: none
Output: 2 DP-3
	enabled
	connected
	priority 2
	DisplayPort
	Modes:  0:2560x1440@60*!  1:1920x1200@60  2:2048x1080@60  3:2048x1080@24  4:1920x1080@60  5:1920x1080@60  6:1920x1080@60  7:1920x1080@50  8:1600x1200@60  9:1680x1050@60  10:1280x1024@75  11:1280x1024@60  12:1440x900@60  13:1280x800@60  14:1152x864@75  15:1280x720@60  16:1280x720@60  17:1280x720@60  18:1280x720@50  19:1024x768@75  20:1024x768@60  21:800x600@75  22:800x600@60  23:720x576@50  24:720x576@50  25:720x480@60  26:720x480@60  27:720x480@60  28:720x480@60  29:640x480@75  30:640x480@60  31:640x480@60  32:640x480@60  33:720x400@70  34:1600x1200@60  35:1280x1024@60  36:1024x768@60  37:1920x1200@60  38:1280x800@60  39:1920x1080@60  40:1600x900@60  41:1368x768@60  42:1280x720@60
	Geometry: 0,0 1280x2276
	Scale: 1.125
	Rotation: 2
	Overscan: 0
	Vrr: incapable
	RgbRange: unknown
	HDR: incapable
	Wide Color Gamut: incapable
	ICC profile: none


$ kscreen-doctor -i
Environment:
  * KSCREEN_BACKEND           : [not set]
  * KSCREEN_BACKEND_INPROCESS : [not set]
  * KSCREEN_LOGGING           : [not set]
Logging to                : [logging disabled]
Preferred KScreen backend : KSC_KWayland.so
Available KScreen backends:
  * KSC_Fake.so: /usr/lib/qt6/plugins/kf6/kscreen/KSC_Fake.so
  * KSC_KWayland.so: /usr/lib/qt6/plugins/kf6/kscreen/KSC_KWayland.so
  * KSC_QScreen.so: /usr/lib/qt6/plugins/kf6/kscreen/KSC_QScreen.so
  * KSC_XRandR.so: /usr/lib/qt6/plugins/kf6/kscreen/KSC_XRandR.so
Comment 1 Bernhard 2024-02-17 15:28:15 UTC
Okay this issue has made a liar out of me. It's not reproducible every time, and it might be related to some other issues I've been having with bad cables on my second monitor. I'll report back when I know more.
Comment 2 Bernhard 2024-02-18 06:05:21 UTC
It definitely still happens now that I don't have any other (obvious) problems, but I can't tell what triggers it.
Comment 3 Bernhard 2024-02-18 14:53:59 UTC
Also I thought this might be a seperate issue, but I suspect it's not:

My other display (output 2) often doesn't receive a signal after idle/suspend, but still shows as enabled. It only works again after either physically or in the KCM turning it off and on again.
Comment 4 Zamundaaa 2024-02-19 15:53:53 UTC
Please check the ~/.config/kwinoutputconfig.json file for your output config. What does the "refreshRate" key say for your screen, after changing the setting, and after rebooting?
Comment 5 Bernhard 2024-02-19 16:40:56 UTC
(In reply to Zamundaaa from comment #4)
> Please check the ~/.config/kwinoutputconfig.json file for your output
> config. What does the "refreshRate" key say for your screen, after changing
> the setting, and after rebooting?

Sorry, rebooting was a red herring.  It happens every time the screen turns off, like just from being idle and waiting. I'm testing now by setting "When locked, turn of screen = 5s" in Energy Saving, then locking. It happens about 80% of the time.

In any case, there is only one entry for the 4k VRR screen:
            {
                "autoRotation": "InTabletMode",
                "connectorName": "DP-2",
                "edidHash": "778c61b12a29b15f7932a423b63aa9a2",
                "edidIdentifier": "GBT 17152 16843009 41 2021 0",
                "highDynamicRange": false,
                "iccProfilePath": "",
                "mode": {
                    "height": 2160,
                    "refreshRate": 120018,
                    "width": 3840
                },
                "overscan": 0,
                "rgbRange": "Automatic",
                "scale": 1,
                "sdrBrightness": 400,
                "sdrGamutWideness": 0,
                "transform": "Normal",
                "vrrPolicy": "Automatic",
                "wideColorGamut": false
            },
Comment 6 Zamundaaa 2024-02-19 22:59:30 UTC
Okay, that looks correct. Does it change after the screen turns off and on again?
Comment 7 Bernhard 2024-02-19 23:01:21 UTC
(In reply to Zamundaaa from comment #6)
> Okay, that looks correct. Does it change after the screen turns off and on
> again?

No, it does not, it always says 120Hz. The file is in fact identical when diffed.
Comment 8 Zamundaaa 2024-02-19 23:17:01 UTC
Interesting, that means KWin's internal state considers the mode to be 120Hz... What does drm_info say? It should have a "MODE_ID" field where it states the exact refresh rate that the driver is actually trying to drive.
Comment 9 Bernhard 2024-02-19 23:22:56 UTC
(In reply to Zamundaaa from comment #8)
> Interesting, that means KWin's internal state considers the mode to be
> 120Hz... What does drm_info say? It should have a "MODE_ID" field where it
> states the exact refresh rate that the driver is actually trying to drive.

Oof, that one also states says 120Hz when my monitor reports 144Hz

├───CRTCs
│   ├───CRTC 0
│   │   ├───Object ID: 85
│   │   ├───Legacy info
│   │   │   ├───Mode: 3840x2160@120.02 driver phsync pvsync
│   │   │   └───Gamma size: 256
│   │   └───Properties
│   │       ├───"ACTIVE" (atomic): range [0, 1] = 1
│   │       ├───"MODE_ID" (atomic): blob = 150
│   │       │   └───3840x2160@120.02 driver phsync pvsync
│   │       ├───"OUT_FENCE_PTR" (atomic): range [0, UINT64_MAX] = 0
│   │       ├───"VRR_ENABLED": range [0, 1] = 0
│   │       ├───"DEGAMMA_LUT": blob = 0
│   │       ├───"DEGAMMA_LUT_SIZE" (immutable): range [0, UINT32_MAX] = 4096
│   │       ├───"CTM": blob = 0
│   │       ├───"GAMMA_LUT": blob = 0
│   │       └───"GAMMA_LUT_SIZE" (immutable): range [0, UINT32_MAX] = 4096
Comment 10 Zamundaaa 2024-02-19 23:34:43 UTC
Then this could either be a bug in your monitor's firmware, or a bug in the driver. Please make a bug report at https://gitlab.freedesktop.org/drm/amd/-/issues about this.