[pr-performance] Opt-in DARNER_LATE_FENCE=1 to avoid CPU stalls on in-flight cross-queue fence waits #93
Loading…
Reference in a new issue
No description provided.
Delete branch "hingeowl/Darner:vercetti/late-fence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds opt-in
DARNER_LATE_FENCE=1(off by default) to avoid CPU stalls on in-flight cross-queue fence waits when running on a single FIFO host queue.When a waiting queue encounters
Ask::Wait(fence, value)orJob::Wait(fence, value)whose signal is already queued in-flight on the host relay (Late::Signal),host::late_fence_met()allows the waiting queue to proceed behind the in-flight signal instead of stalling the sender thread for the GPU to drain. Guarded off automatically whentwo_queues::on()is active.Provenance
https://github.com/lobomfz/VIctory-xmemcommit9d72949c520646e44a1cdb1f451fd1b6f2de07f9(GPL-3.0-or-later), adapted to Darner'sFenceRefand guarded againsttwo_queues::on().main(b3a615f).Validation
cargo test --locked -p darner-gpu --lib queue::behindpassed.DARNER_RELAY=2, canonicalplay.rssettings,DARNER_LATE_FENCE=0vs1, same binary):DARNER_LATE_FENCE=0(R1 / R2)DARNER_LATE_FENCE=1(R1 / R2)7,982/7,9177,556/7,8411.77%drift20.5/21.9(21.9)20.9/22.2(22.2)+0.3 FPS49.0/46.2 ms(49.0)47.1/46.4 ms(47.1)-1.9 ms63.1/57.7 ms(63.1)60.1/58.9 ms(60.1)-3.0 ms34.1/31.5 ms(34.1)32.2/32.4 ms(32.4)-1.7 ms18.4 ms17.3 ms-1.1 ms65%/21,799 MB64%/21,891 MB-1.9 msmedian frame time,-3.0 msP95,-1.7 mssubmit, visually verified spotless withnonBlack=99.99%,magenta=0%).mainb3a615f:19.4 FPS,49.6 msmed,65.0 msP95,35.1 mssubmit,7,946draws.)I reproduced a stale upload on
08e3ed5b77365eb66880df5a72e88fae5c82e32fwith an RTX 4060 8 GB (621.40), Windows 11 build 26300, and Rust 1.98.1.The synthetic test submits a producer and a consumer through Darner's graphics and compute queues, which share one real D3D12 direct queue. The producer's
Write64BitValueBottomOfPipeXchanges the source from0x1bto0xb7when the relay publishes it. The consumer waits on the producer's emulated fence, snapshots the source withdefer_fill, and copies that upload buffer into a D3D12 readback.DARNER_LATE_FENCE0xb70x1b0xb70x1bEach row covers three runs with
DARNER_RELAY=1and three withDARNER_RELAY=2. In every run the producer's fence was 0 while publication was held. Both emulated fences later reached 1 and the CPU source became0xb7. In the first pair of rows the D3D12 fence itself holds the producer. That pair also reproduced with just the fixture inqueue.rs. In the second pair a test-only latch holds the relay after the GPU completed the producer and the relay took its pendingLate::Write. The test queues the producer's fence signal during that latch.late_fence_metcan accept the pending signal in both windows. FIFO orders the GPU copies. The CPU prelude had already captured the consumer's upload bytes before the relay published the producer's write. The demonstrated case needs the emulated wait to keep holding while a preceding bottom-of-pipe write is queued or in hand. This test covers a bottom-of-pipe value and CPU upload preparation. Gameplay, other CPU copy-back paths, and performance were outside its scope.To reproduce, apply the test patch at the commit above and run the test below in a fresh process for each switch combination. I used an isolated Darner home and cache. Common settings were
DARNER_ADAPTER=RTX 4060,DARNER_ASYNC_SUBMIT=1,DARNER_QUEUE_WAIT=1,DARNER_ASYNC_QUEUE=0,DARNER_LATE_WAIT=3,DARNER_LATE_WAIT_WRITES=1,DARNER_CARD_STEPS=0,DARNER_THIN=0,DARNER_JOIN_PARTS=1, andDARNER_SUBMIT_SPLIT=0. UseDARNER_RELAY=1or2,DARNER_LATE_FENCE=0or1, andDARNER_TEST_RELAY_LANDING=0for the GPU gate or1for the relay latch.Synthetic test patch
The stale value also occurs with a plain list readback as the producer's sole CPU publication. On
08e3ed5b77365eb66880df5a72e88fae5c82e32f, thedefer_read_backcase returned0x1bin all four opt-in runs and the expected0xb7in all four opt-out runs. These cover relay modes 1 and 2, both before the producer's GPU work finishes and after the relay takes the completed list. The original fixture covered bottom-of-pipe writes. First reproductionI tested the guard below on the same head. It keeps the emulated wait while the relay is settling and scans only as far as the matching pending signal. Earlier bottom-of-pipe writes, list or texture readbacks, declared copy-backs, or work via
card_stepskeep the wait held.submitrecords the plain-readback bit alongsidetexture_back_rangesunder the existing list lock. The predicate uses the stored bit underLINE.DARNER_LATE_FENCE=10xb70xb70x1bTwo additional opt-out runs passed. Ten of the opt-in runs used the separate sender (
DARNER_RELAY=2 DARNER_RELAY_COPY=1 DARNER_SUBMIT_SPLIT=1). The fixture confirmed that both submissions went through it. The ninequeue::behindunit tests andflight_texture_back_ranges_refuse_stale_shadow_holderpassed. So didcargo clippy --locked -p darner-gpu --all-targets --all-features -- -D warnings. Hardware was RTX 4060 8 GB, driver 621.40, Windows 11 build 26300, and Rust 1.98.1. This covers synthetic queue ordering. Frequency in gameplay and the effect on frame times remain unmeasured.Apply the fixture at
08e3ed5b77365eb66880df5a72e88fae5c82e32fto test the original behaviour, or apply both patches to test the guard. Use the settings in the first report. SetDARNER_TEST_FENCE_READBACK=1for the plain readback orDARNER_TEST_FENCE_GPU_ONLY=1for the GPU-only control. Leaving those switches off selects the bottom-of-pipe write.DARNER_TEST_RELAY_LANDING=0holds the D3D12 queue and1holds the relay before it publishes. Run each combination in its own process.Tested guard (candidate patch)
Synthetic fixture
Replay A/B on RTX 5070 Ti: DARNER_LATE_FENCE=1 in gameplay, no measurable gain
Measured
08e3ed5b77merged on top of release v2026.12.03.02, against the plain release, on a ~6.5 minute replay route (same save, recorded controller input) through a cutscene, a scene cut and a stretch of free play. The switch was on in both PR runs (first line of each log).DARNER_LATE_FENCE=1(2 runs)Crashes: none in any run (no device loss, no host GPU failure). Fps means are within the release's own run-to-run spread, so: no measurable difference on this route. With only 3 release runs, that spread is not well known yet; differences under ~2-3% can't be resolved here. This adds the gameplay frame-time side that the synthetic reports above left unmeasured; it says nothing about the stale-read case they show, since nothing on this route checks for it.
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11;
scripts\play-nvidia.ps1 -Build release(Series X, 1440p native, DLSS Quality, no frame generation, fullscreen, no fps cap). Each build had one unmeasured warm-up run first. The release base excludes its first measured run, which was still compiling shaders (about 3,300 compiles during the route).Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.