Skip to content

Frame pacer: keep the 30 fps grid half a vsync before the latch (VK_GOOGLE_display_timing), no more 50 / 16.7 ms judder - #183

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:pace-vsync-phase
Nov 4, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:pace-vsync-phase

Conversation

@Propinbo

@Propinbo Propinbo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Problem

With a frame limit (30 fps) the framepace_on() grid in nvnQueuePresentTexture has no tie to the display. Its phase
is wherever the last long frame (load, menu, map, hitch) left it, and then it stays there for minutes. When that puts
queueBuffer within about 1.5 ms before SurfaceFlinger's latch, sub-millisecond jitter makes frames alternately make
and miss the latch: they reach the screen as 50.0 / 16.7 ms (60 Hz) or 41.7 / 25.0 ms (120 Hz) instead of 33.3 ms. The
mean stays 30 fps, so FPS counters look fine, but it is visible judder.

On a Samsung SM-X730 (Immortalis-G925 MC12, r49p1) at 60 Hz, 7 of 24 baseline windows had bursts (up to 1,398
consecutive alternating intervals in one segment). The cause was checked with a phase-sweep experiment (temporary
instrumentation moving the grid 0.5 ms every 150 presents): at 60 Hz, 150-frame blocks with a queue lead of 0.4-1.4 ms
before the vsync had burst share 0.11-0.47, any other lead 0.00-0.01. Content, Native vs Recompiled, shader compiles
and GPU load are not needed to explain it.

Change

  • vulkan/device.c: on Android, enable VK_GOOGLE_display_timing when the device advertises it (it is Android's own
    swapchain layer, not a vendor feature). Presents chain VkPresentTimesInfoGOOGLE with desiredPresentTime = 0, so
    scheduling is as before. After each present, keep the newest actualPresentTime, the refresh period (re-queried about
    once a second) and the median of the last 9 hand-over -> queueBuffer delays. backend_vsync_offset() returns the
    shift that would put the next queueBuffer half a vsync before a vsync. It returns false (pacing exactly as today)
    without valid, recent (2 s) timings, when the timings do not fit the vsync grid, or when the frame grid is not a
    whole number of vsyncs (no limit, 40 fps on 60 Hz).
  • objects.c (grid branch of framepace_on() only): at a grid restart (after a long frame, a hitch anyway) the grid is
    moved by the full shift; otherwise by 0.25 ms per frame once it is more than 0.5 ms off. Steering is capped at one
    vsync per correction and then left alone until the next restart.
  • vulkan/async.c, nvn.h: the PRESENT request carries the hand-over time; one declaration.
  • LARECOMP_PACE_VSYNC=0 leaves the extension off and the pacer as before. No RT_ON_RESET hook is needed: a reboot of
    the game is a long frame, which restarts the grid, and the timing state ages out after 2 s.

Not touched: desiredPresentTime scheduling, Choreographer, setFrameRate, present mode, swapchain image count, ADPF,
the g_vsync_count path, other platforms (stub returns false).

Testing

Device: Samsung SM-X730, Dimensity 9400+, Immortalis-G925 MC12 (Vulkan driver r49p1), Android with the game at 1.9.0
Great Plateau start, Native and Recompiled, 30 fps cap, scratch save. Compared against unchanged v0.2.10-beta APK.

Check Result
actualPresentTime vs SurfaceFlinger actual present (60 and 120 Hz) equal for 1800/1800 frames at each rate; refresh 16.66 / 8.33 ms
60 Hz, worst 150-frame block of the 50 / 16.7 share (baseline pacing 0.11-0.47 in the bad zone) 0.013; longest off-grid run 2 (Recompiled: 0.013, run 1)
Queue lead within half a vsync +-25% 100% of frames at 60 and 120 Hz
LARECOMP_PACE_VSYNC=0 reproduces the baseline zone (block 0.433)
FPS / p99 / >100 ms, 4 cells (Native, Recompiled x cold, warm shader cache), 120 s each FPS 29.93-29.97 (baseline cells 29.93-29.98), p99 <= 33.5 ms in every cell, >100 ms count 1-2 (baseline 1-3)
Long session, Native, 4 x 300 s with 3 menus and a game re-boot, 37,379 frames 29.84 FPS, 159 intervals >50 ms (baseline long session 232), 3 >100 ms (baseline 3), longest alternating run 4; graceful teardown, no crash
Existing host tests (GPU timing history, shader cache, Vulkan startup, Vulkan compatibility) 8 / 17 / 33 / 16 assertions pass, same as without the patch (the upload-cache harness fails to compile with or without it)

Everything above was seen in game on the device; captures were reviewed, no visual change.

Limitations (please read)

  • 120 Hz is improved, not clean. The patch removes the phase peak at 120 Hz, but a phase-independent background of
    41.7 / 25 ms intervals stays: mean 150-frame block share 0.175 (max 0.253; baseline pacing 0.228 / 0.480 in the same
    sweep). I attribute it to the compositor side (late-shown frames were queued and GPU-ready on time), not proven on
    other devices. My own bar for 120 Hz (no block above 0.16) was therefore not met; I did not relax it.
  • 60 FPS in-world and movie playback were not checked (60 FPS mode: launcher and title screen stable, process alive).
  • One device and one GPU vendor. Other SoCs and 90 Hz panels are untested; the fallback path (no extension, no valid
    timings) is the existing pacing.
  • Sweeps and the long session ran on USB power (not battery); short cells ran on battery. The baseline comparison is one
    cell per mode and cache state, so the >50 ms reductions are supportive, not statistically established.
  • The 20-minute long session is crash-free testing of that length, not proof of absence of crashes.
  • No automated regression test: the behavior depends on SurfaceFlinger's latch; moving the arithmetic into a header for
    a host test seemed out of proportion. Happy to do it if you prefer.

Notes for review

  • The pattern was seen on a cool device (thermal status 0) at a 30.0 fps mean, so it is not a throttling effect.
  • No game files, saves, logs or generated code are included.

(Test summary only; raw logs stay with me and can be attached on request.)

🤖 Generated with Claude Code

…OOGLE_display_timing)

With a frame limit the present grid had no tie to the display: its phase stayed wherever the last long frame left it, and near the compositor's latch frames went out as 50 / 16.7 ms (60 Hz) or 41.7 / 25 ms (120 Hz) for minutes. On Android the vsync period and past present times come from VK_GOOGLE_display_timing; the pacer now keeps each frame queued half a vsync before one. No timings, no whole-vsync grid, or LARECOMP_PACE_VSYNC=0: pacing as before.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Propinbo

Propinbo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: the remaining 41.7 / 25 ms intervals at 120 Hz come from the display HAL, not from the pacing

The PR's limitations list a ~0.17 share of 41.7 / 25 ms intervals at 120 Hz that does not depend on the grid's phase. I traced it on the same device (Samsung SM-X730, Dimensity 9400+ / Mali-G925, Android 16, 120 Hz, Native, 30 fps cap). Capture: one 180 s window with Perfetto FrameTimeline + atrace gfx.

  • The Vulkan SurfaceView has no per-layer FrameTimeline frames, so I followed each game frame via the layer's BufferTX counter (transaction arrival / latch), VSYNC-sf and the display frame that showed it.
  • The frames take the same path in all three interval classes (33.3 / 41.7 / 25 ms, n = 4709 / 230 / 231): queued 3.8–3.9 ms before a vsync, in SurfaceFlinger 0.4–0.5 ms later, latched at the first SF wakeup after arrival every time. The app side and the latch are on time.
  • Only latch → screen differs: 15.2 ms normally, 7.6 ms for the 25 ms frames. 90% of display frames are Late Present / Display HAL, exactly one vsync (8.5 ms) after SurfaceFlinger's expected present. The rest are on time. A 25 ms interval is a frame the HAL happened to show on time, and the 41.7 ms after it (206 of 231 cases) is the return to the usual latency.
  • ANativeWindow_setFrameRate(30, FIXED_SOURCE) (interleaved, 2+2 windows of 180 s) makes it worse: block share 0.20–0.25 vs 0.13–0.15 without it. desiredPresentTime or a different queue lead can't help, since the latch already happens at the first possible wakeup.

So this background is outside the app and needs no change in this PR. Only one device and HWC vendor was checked, with refresh forced to 120 Hz and USB power. Other panels and adaptive refresh were not tested.

Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 2, 2026
@mamcjr
mamcjr merged commit e4d8ca0 into mamcjr:main Nov 4, 2026
@mamcjr

mamcjr commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Merged, thank you! I measured it on my POCO F7 Ultra (Adreno 830, Turnip, 30 fps, in the world) by SurfaceFlinger's actual present times (dumpsys SurfaceFlinger --latency, ~2,475 frames per run):

60 Hz 120 Hz
main 6.1% of frames off 33 ms (17 / 50) 2.3% (25 / 42)
this PR 0.2% 10.3-12.4% (two runs)

So at 60 Hz it does exactly what you described, a clear win. At 120 Hz it made things worse here, as you suspected. I added a follow-up (cdb85c6) that keeps the steering to refresh periods of 12 ms and up (60 Hz) for now; with it, 120 Hz measured 3.5%, like main. If you find what goes wrong at 120 Hz (maybe the 4 ms half-vsync lead is too tight for the jitter there), I'd be glad to lift it.

You're in the README's contributors now, for this and #210.

mamcjr added a commit that referenced this pull request Nov 4, 2026
…he judder on a POCO F7 Ultra (#183)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mamcjr added a commit that referenced this pull request Nov 4, 2026
Moab-tk added a commit to Moab-tk/BOTWRecompAndroid-S23 that referenced this pull request Nov 5, 2026
… tamanhos inteiros

Junção da v0.3.1-beta de mamcjr (0.3.0 e 0.3.1): quedas com Magnésis, Stasis e câmera do Slate, botão de flechas,
álbum, mapa com dois toques, giroscópio como a tela do Switch, 40/45 FPS, folga de ADPF, correções da tela larga,
variáveis do driver, memória por arquivo compartilhado (Mali/Xclipse) e som depois do segundo plano (SDL refeita).

Conflitos resolvidos:
- Ritmo: os quadros regulares do S23 (present_lock) continuam o padrão; o ajuste de fase do original (mamcjr#183) vale
  quando eles estão desligados (LARECOMP_VSYNC_STEER=1/0 força). Os dois liam os mesmos tempos do painel, que o
  driver entrega uma vez só.
- A extensão de tempo de apresentação é ligada uma vez só (o original a punha depois das duas de mapa, que saem
  juntas pela contagem n_ext -= 2).
- O pedido de 40/45 FPS à janela não apaga mais o pedido de 60 Hz dos quadros regulares.
- Configurações: linha de 2048 com o fim de linha CRLF do original.

Novidades S23:
- Mira pelo dedo (experimental, desligada): com os ícones, o arco na mão e o sensor de movimento ligado, o arrasto
  gira a mira como o celular girando, sem o limite de velocidade do direcional.
- Dica na sensibilidade do arrasto: acima de uns 400% só os arrastos lentos mudam (limite do jogo).
- Escala da cena em múltiplos de 0,08 (do TOTK S23): metades das imagens sempre inteiras (LARECOMP_SCALE_SNAP=0).
- versionCode 49 (0.3.1-s23-b12)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants