Skip to content

Commit e129a80

Browse files
committed
drm: apple: Set swap timestamps to sane values for Adaptive Sync
Setting these timestamps to a dummy value worked fine for enabling a fixed 120 Hz mode on the MacBook Pros, however doing so causes Adaptive Sync displays to simply switch between full and minimum refresh rates. Setting these timestamps based on the swap pacing seems to fix this, and makes the display's refresh rate match the incoming swap rate. Note that the names and values are best-guess only. These seem to work fine for driving VRR displays, but may still be incorrect. Signed-off-by: James Calligeros <[email protected]>
1 parent fa3d853 commit e129a80

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,15 @@ int DCP_FW_NAME(iomfb_modeset)(struct apple_dcp *dcp,
13011301
return 0;
13021302
}
13031303

1304+
/*
1305+
* DCP timestamps are expressed in system timer ticks. Approximate
1306+
* this by converting from ktime nanoseconds to 24 MHz ticks.
1307+
*/
1308+
static u64 ns_to_mach(u64 ns)
1309+
{
1310+
return ns * 3 / 125;
1311+
}
1312+
13041313
void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, struct drm_atomic_state *state)
13051314
{
13061315
struct drm_plane *plane;
@@ -1417,12 +1426,13 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru
14171426

14181427
if (has_surface && dcp->use_timestamps) {
14191428
/*
1420-
* Fake timstamps to get 120hz refresh rate. It looks
1421-
* like the actual value does not matter, as long as it is non zero.
1429+
* TODO: ascertain with certainty what these timestamps
1430+
* are. These names are guesses based on what macOS populates
1431+
* them with. These values seem to work well with VRR.
14221432
*/
1423-
req->swap.ts1 = 120;
1424-
req->swap.ts2 = 120;
1425-
req->swap.ts3 = 120;
1433+
req->swap.presentation_time = ns_to_mach(ktime_get_ns());
1434+
req->swap.last_pres_time = ns_to_mach(ktime_to_ns(dcp->swap_start));
1435+
req->swap.submit_time = req->swap.presentation_time;
14261436
}
14271437

14281438
/* These fields should be set together */

drivers/gpu/drm/apple/iomfb_template.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include "version_utils.h"
1919

2020
struct DCP_FW_NAME(dcp_swap) {
21-
u64 ts1;
22-
u64 ts2;
21+
u64 presentation_time;
22+
u64 last_pres_time;
2323

2424
u64 unk_10;
2525
u64 unk_18;
2626
u64 ts64_unk;
2727
u64 unk_28;
28-
u64 ts3;
28+
u64 submit_time;
2929
u64 unk_38;
3030

3131
u64 flags1;

0 commit comments

Comments
 (0)