Repository navigation
Conversation
The game waits for its frame's fence right after presenting it, so the next frame's CPU work never overlapped that frame's GPU work: a frame cost CPU + GPU. Past 16.7 ms it fell to 30 fps with the GPU idle a third of the time, and macOS clocked the idle GPU down, which kept it there (M3 Max, Match at 5120x2880: 30 fps at ~420 MHz; the M1 report: Match at 2880x1800 30-40 fps with the GPU ~45% busy). nvnSyncWait now waits for the GPU work of the fence waited on before the newest one. The newest list is still translated and submitted first, so the game's command memory is free; readbacks finish during translation and uniform data is copied at translation. LARECOMP_GPU_LAG_CHECK=1 (a debug check of the vertex / index memory the GPU reads in place) shows the same in-flight change rate with and without the lag. M3 Max, Match: 5120x2880 27.6 -> 60 fps (clock 426 -> 860 MHz), 3840x2160 30 -> 60, 7680x4320 23.5 -> 49; 1x and Dynamic unchanged at 60. Default on with Metal; LARECOMP_GPU_LAG=0 restores the old wait. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ck covers storage buffers With the GPU a frame behind, the game reads its frame's timing counters right after a fence wait that only guarantees the frame before, so a counter got the GPU's time only some frames and the host clock the rest: noisy input to the game's own 30 fps decision. With the lag on they keep the host clock (as LARECOMP_MTL_COUNTER=cpu), and pace.c alone picks the 30 fps mode from frame times, as it already does on CPU-bound machines. nvn_gpu_lag() holds the LARECOMP_GPU_LAG switch for both. LARECOMP_GPU_LAG_CHECK=1 now also hashes the storage buffers bound to shaders that use gmem (compute and graphics), counted separately. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the GPU runs a frame behind (#67) With the lag, the game rewrites some small buffers for frame N + 2 while frame N may still be on the GPU: a ping-pong pair of 8-byte storage buffers a compute shader reads (two animating floats) changed in flight 17% of the time with the lag, never without (LARECOMP_GPU_LAG_CHECK). A buffer of at most 256 bytes bound to a stage's driver table, that the shader only reads, is now copied at translation after the driver constants (c0), and its table address points past the heap, where the shader's gmem loads read the copy (shader.h GSNAP). The translator traces every gmem store to the table row its address comes from (a dataflow over the code, BRX jump tables read from the compiler constants); a shader with a store it can't trace takes no snapshots. Buffers that GPU work still in flight may store to are left in place (256-byte granules, marked per generation of submissions, cleared once those complete). Metal only, with the lag; LARECOMP_GSNAP=0 turns it off. The lag check now covers the compute uniform buffers read through gmem too and counts snapshots apart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… too (#67) A per-shader-row diff of the lag check, lag on vs off, found a second ping-pong set the game rewrites for frame N + 2 while frame N may still be on the GPU: the same compute shader's four 3104-byte storage buffers, changed in flight in ~4% of its dispatches with the lag, never without. Snapshots now cover read-only buffers up to 4 KB (up to ~60 KB copied a frame in the sweep); with that, no buffer that no GPU store reaches changes in flight more with the lag than without. LARECOMP_GPU_LAG_CHECK=1 now also hashes the guest memory of snapshotted buffers, and LARECOMP_GSNAP=2 takes snapshots without the lag. With the lag off, a snapshotted buffer changing in flight is either the game rewriting it or a GPU store the store tracing missed; in a 39-room sweep none of them overlapped a GPU store still in flight. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Both ping-pong sets the lag check found are compute inputs. Draws keep the 256-byte limit: fragment shaders reading kilobytes of constant data with per-pixel offsets are a cost not worth taking without a race found there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
translate.c: both new functions kept (beta_5's BRX jump-table labels for the GLSL path, this branch's gmem store tracing for the MSL path). Co-Authored-By: Claude Opus 5.5 <[email protected]>
peiikai
force-pushed
the
mac-match-overlap
branch
from
October 20, 2026 21:38
bf53f53 to
74f20a5
Compare
The reference translator (REF=HEAD) now defines the thread-local maxwell_cb1_size as well, so linking both side by side failed with a multiple definition on Windows CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
peiikai
marked this pull request as draft
October 20, 2026 22:34
Owner
Author
|
Shelved until Beta 6. The second race fix (b42c04b) cut the black flickers down but a longer play-test at 5120x1440 still showed them, so there is at least one more GPU/CPU race with the frame lag on. Not merging for Beta 5; Dynamic resolution covers the M1 Match case for now. To be investigated more deeply for Beta 6. |
This was referenced Oct 23, 2026
Owner
Author
|
Superseded by #333 (the Metal CPU/GPU overlap with the race fixes), so closing this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the Match-resolution 30 fps lock on Apple GPUs (#67).
Cause
The game waits for its frame's fence right after presenting it, so frame N+1's CPU work never overlapped frame N's GPU work: a frame cost CPU + GPU. Once that passed 16.7 ms the game fell to 30 fps with the GPU idle about a third of the time, and macOS read the idle GPU as one to clock down (DVFS), which kept it there: a lower clock made the GPU part longer, so the frame never fit 60 again.
Fix
nvnSyncWaitnow waits for the GPU work of the fence waited on before the newest one, so the GPU may run one frame behind the game. The newest list is still translated and submitted first (the game's command memory is free), readbacks finish during translation and uniform data is copied at translation.Follow-ups from review (second commit):
LARECOMP_MTL_COUNTER=cpu). The game reads them right after a wait that only guarantees the frame before, so they got the GPU's time only some frames: noisy input to the game's 30 fps decision. Nowpace.calone picks the 30 fps mode from frame times, as it already does on CPU-bound machines (GPU fence waits count as busy there).LARECOMP_GPU_LAG_CHECK=1also covers the storage buffers bound to shaders that use gmem (compute and graphics), counted separately.Small buffers read through gmem (third commit): with the lag, the game rewrites some small buffers for frame N+2 while frame N may still be on the GPU (found by the lag check: a ping-pong pair of 8-byte storage buffers a compute shader reads, changed in flight 17% of the time with the lag and never without). Now a buffer of at most 256 bytes bound to a shader stage's driver table, that the shader only reads, is copied at translation after the driver constants (c0), and its table address points past the heap, where the shader's gmem loads read that copy (
shader.hGSNAP). It's general, not by address:LARECOMP_GSNAP=0turns it off. The cost is a copy of a few bytes per draw / dispatch that has such buffers, plus the store tracing once per shader at translation. The Vulkan path is unchanged (its lag is off by default); the same table rewrite would fit its GLSL gmem path too.Review follow-up (fourth and fifth commits):
LARECOMP_GPU_LAG_CHECK=1now hashes the guest memory of snapshotted buffers too, andLARECOMP_GSNAP=2takes snapshots without the lag. With the lag off, a snapshotted buffer that changes in flight is either the game rewriting it or a GPU store the tracing missed. 39-room sweep: 235 of ~240,000 snapshotted ranges changed; none of them overlapped a GPU store still in flight (one was stored by a later dispatch in the same command buffer, after the read). No missed GPU store found.Play-test: with f3a2ba3 (before the 3104-byte fix) the user saw brief full-screen black flickers walking near Field_09H at 5120x1440 (1x, MetalFX);
LARECOMP_GPU_LAG=0stopped them. With b42c04b they didn't show in a short watched session. A per-frame check of the presented images in scripted runs (hidden and one visible) never caught a black frame on either build, so the link to the 3104-byte race is from the play-test, not a reproduction.Merged with current beta_5 (merge commit;
translate.ckeeps both beta_5's BRX jump-table labels for GLSL and this branch's store tracing for MSL).Numbers
M3 Max, Match at 5120x2880: 30 -> 60 fps, GPU clock 425 -> 665-860 MHz. 3840x2160 30 -> 60, 7680x4320 23.5 -> 49; 1x and Dynamic unchanged at 60. Play-tested in a combined build: Match holds a steady 60.
With the snapshots (M3 Max, 130 s runs, one copy at a time with the GPU to itself): Match 5120x2880 60.0 fps (GPU ~640-1060 MHz), 1x 2560x1440 60.0; the render thread's CPU time per frame 2.5-3.0 ms vs 2.2-2.7 ms with
LARECOMP_GSNAP=0. Some later runs had multi-second stalls in both modes (snapshots on and off alike, including at the title screen), from something else on the machine at the time.Safety
A separate review found the lag safe for a test build. What the GPU reads in place from guest memory while a frame is in flight is vertex / index memory and storage / uniform buffers through gmem;
LARECOMP_GPU_LAG_CHECK=1hashes those ranges at translation and again when their command buffer completes (ranges read through snapshots are counted apart). 39-room warp sweep (tools/perf_sweep.py, Match), lag on vsLARECOMP_GPU_LAG=0:Vertex / index memory is at the known baseline (~0.3%). The buffer changes left are buffers the GPU writes itself (they change without the lag too). Before the snapshots, the 8-byte pair changed in flight 17% of the time with the lag. Screenshots with snapshots on and off match (Field and a dungeon room, apart from moving objects).
Switch
Default on with Metal;
LARECOMP_GPU_LAG=0restores the old wait (each fence wait waits for its own frame). Vulkan is unchanged (off unlessLARECOMP_GPU_LAG=1).🤖 Generated with Claude Code