Repository navigation
GPU: cheaper indirect draws: no barrier per draw, one budget charge per group, budget in card memory - #220
GPU: cheaper indirect draws: no barrier per draw, one budget charge per group, budget in card memory#220venglov wants to merge 9 commits into
Conversation
Every indirect execution was followed by a move of the list's clamped arguments back to the common state, and the next clamp moved them from common to unordered access. Drivers may treat a barrier into or out of the common state as a full wait, so even the window path (VICTORY_INDIRECT_WINDOW=1), whose draws skip the clamp, still recorded one barrier between every two draws. The list now remembers that its scratch buffer was left readable as indirect arguments: executions read it with no barrier of their own, the next clamp moves it straight back to unordered access, and it returns to common once, when the list closes or a bigger buffer replaces it. The waits for earlier shader writes around the clamp are unchanged. Tests: two windows of executions with no barrier between them, on WARP and through a host list; the tracked state across clamps, growth and reset; the existing clamp tests follow the new states. With VICTORY_D3D12_DEBUG=1 in a diagnostics build, the host-list tests also check that the debug layer reports nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc11cccc57
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // SAFETY: the list has run; a mapped buffer. | ||
| let hits = unsafe { (hits_ptr as *const u32).read_volatile() }; | ||
| assert_eq!(hits, expected, "every record of both windows runs once"); | ||
| assert_eq!(host.log_messages(), None, "the debug layer found an error"); |
There was a problem hiding this comment.
Preserve debug-layer errors before checking the queue
With diagnostics and VICTORY_D3D12_DEBUG=1, this assertion runs after host.execute, but Host::submit already calls self.log_messages() at host.rs:4144, discarding its result and clearing the info queue. Nonfatal resource-state errors from recording or submission are therefore consumed before this assertion can inspect them, allowing the test to pass despite the barrier errors it is intended to reject. The new assertion in host_list_reuses_and_grows_scratch_across_submissions has the same problem. Preserve and assert the submission's diagnostic result, or inspect the messages before that drain.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right: Host::submit drains the queue into the log, so those asserts couldn't see errors raised while recording. Fixed in 23daba3: both host-list tests now read the messages after list.close() and before host.execute. Barrier before-state errors are reported at record time, so they're caught there. A control test on the CI-only debug-layer branch records a wrong barrier into a HostList the same way and checks that the read sees it.
A frame's worth (3,200) of one-record indirect draws of our own, clamped one at a time and in windows of 32, recorded with the old barriers (back to the common state after every execution) and the new ones, timed with GPU timestamps around the list. Ignored by default; any machine with a GPU runs it in seconds, no title files needed: cargo test -p victory-gpu --release --lib indirect::bench -- --ignored --nocapture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Flyander
left a comment
There was a problem hiding this comment.
I ran the ignored release benchmark on a Windows 11 D3D12 RTX 5070 Ti. Median of 9 frames, 3,200 one-record draws per frame:
| Old barriers | New barriers | Change | |
|---|---|---|---|
| Clamped one at a time, GPU | 18.98 ms | 19.04 ms | +0.3% |
| Clamped one at a time, submit-to-done | 19.20 ms | 19.24 ms | +0.2% |
| Windows of 32, GPU | 49.82 ms | 46.43 ms | -6.8% |
| Windows of 32, CPU recording | 1.68 ms | 0.56 ms | -66.7% |
| Windows of 32, submit-to-done | 50.16 ms | 46.54 ms | -7.2% |
The run confirms the no-window path is neutral and the batched-window path improves on this NVIDIA card. These are synthetic draws; I have not measured the title scene. The command was cargo test --locked -p victory-gpu --release --lib --target-dir E:\Dev\victory-fork-target indirect::bench -- --ignored --nocapture.
The clamp charged the list's budget record by record: an atomic read and a compare-and-swap loop per record on one word, every thread of a window racing for it, so a group of n records took n rounds and about n*n/2 atomics. The word is CPU-visible memory (zeroed on the CPU at submission), so on a card of its own each of them crosses the bus. On an RTX 5070 Ti the benchmark's windows of 32 took 46-50 ms for 3,200 draws where draws clamped one at a time took 19 ms (fxceless#220). Now the records' costs go to group-shared memory, one thread charges their sum with one compare-and-swap (retried only if another group got there first), simulating the same saturation record by record in lane order, and every thread reads whether its record fitted. The mesh diagnostics (largest group count asked, groups asked in all) are summed in the group and added once. What a record costs and when it runs empty are unchanged; which records of a group fit is now their lane order instead of the order the GPU served the race. Test: a group with 300 left of the budget keeps its first draw (100), empties the second (250, which takes the rest) and the ones after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s clamp - The clamp's charge per group walks the group's own records (one, for a record clamped alone) instead of all 64 slots. - The host-list tests read the debug layer's messages after closing the list and before the submission, which moves them to the log (review). - The benchmark lives in its own file and records five cases: what main records, one record at a time and in windows of 32; what this tree records, both ways; and windows with the new barriers but main's clamp, to tell the two changes apart. main's clamp is kept in the benchmark to measure against. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the RTX 5070 Ti run. It showed something the software adapter couldn't: on the card, windows of 32 took 46–50 ms where draws clamped one at a time took 19 ms, even though windows record far fewer clamp passes and barriers. The only work that grows with a window is in the clamp. Each record charged the list's budget with an atomic read and a compare-and-swap loop on one word, all 64 threads racing for it. That's a round per record and about n²/2 atomics per window. The word is a New commits:
On the software adapter (run, three repetitions):
As expected, the per-group charge doesn't matter there. The card is where it should. If you can run the updated benchmark on the same 5070 Ti, its fourth and fifth lines will show how much of the windows' cost was the budget atomics: Full CI on 23daba3 passes ( |
Two more cases, one record at a time and windows of 32, with this tree's clamp and the budget words in a device-local buffer instead of CPU-mapped memory: whether the clamp's atomics crossing the bus are what a draw clamped alone still costs on a card. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The clamp charges the list's budget with atomics: at least an atomic read and a compare-and-swap in a row for every clamp, so for every indirect execution clamped on its own. The budget was in memory the CPU maps (zeroed on the CPU at submission), so on a card of its own each of those crosses the bus. Now the words live in a device-local buffer of the list. The list zeroes it before its first clamp (WriteBufferImmediate, as a copy), the clamps charge it as before, and when the list closes the clamp's notes on mesh records are copied to the mapped words, where the next submission reads them for the frame line as before. VICTORY_INDIRECT_CARD_BUDGET=0 keeps the old place, for an A/B; lists without ID3D12GraphicsCommandList2 keep it too. Test: a recording whose clamps spend the whole budget, then one with a small record after the reset, which runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested in game on Windows 11 D3D12, RTX 5070 (driver 621.14): fork main + #175 + this PR at World frames only (samples over 1,000 draws), one run each:
The frame time stayed the same while each frame carried about 23% more draws, so more indirect work gets through per frame. Here the CPU side (~420 ms preparing) still sets the pace, so the barrier savings don't show up as fps yet. No hangs or device removals in the full run, and the AI-assisted (Claude Code); no game files attached. |
|
I tested Each arm issued 3,827 single-record indirect mesh dispatches, one group per dispatch, with a 12-byte signature and 32 bytes between source records. The budget remained in CPU-visible memory and lookahead was off. The warm-up for each arm checked 3,827 mesh invocations, 3,827 emitted primitives, nonzero pixel invocations and the expected budget charge. Nine timed rounds rotated the arm order. Times below are GPU timestamps around the complete synthetic command list.
The full change saved 2.067 ms per list (10.5%) on this workload and was faster in all nine paired rounds. The barrier-only median moved by 0.033 ms. This gives the clamp change a measurable result on the RTX 5070 with one requested record per call. Game frame time still needs a separate comparison. For a local correctness check, the original and new HLSL produced the same indirect arguments and budget counters for 14 single-record WARP cases, including oversized mesh counts, zero work and exact/insufficient remaining budget. The benchmark’s original clamp compiled byte-for-byte identically to the original production shader. To reproduce, check out the linked commit on a Windows machine with native mesh-shader and mesh pipeline-statistics support. Set cargo test --locked --release -p victory-gpu --lib indirect::bench::bench_indirect_mesh_singletons -- --exact --ignored --nocapture --test-threads=1AI-assisted. All benchmark shaders and inputs are synthetic. |
|
One more change, for the default path: d5c15cb moves the budget word into the card's memory. Even a record clamped alone makes two atomics in a row on that word (read, then compare-and-swap). In mapped memory, both cross PCIe on every clamped draw, which may be a good part of the ~6 µs a draw in the one-at-a-time line on the 5070 Ti. The list now zeroes a device-local copy before its first clamp ( The benchmark gained two lines with the budget in card memory: "one at a time, card" and "windows of 32, card". If someone reruns it on a card, the lines comparing "this" with "card" show what that saves. On the software adapter it's neutral, as it should be there (run). CI on d5c15cb passes ( |
|
Follow-up to the synthetic mesh benchmark. I also compared two plain release builds on the same RTX 5070, one with the four-file delta from The last 30 seconds had median reported frame times of 209.1 ms on the control and 232.2 ms with #220 (4.78 and 4.31 FPS). For a closer workload comparison, I paired reports from 30–90 seconds after world entry with at least 3,500 draws/frame, zero pipelines building, timestamps within 10 seconds, and draw counts within 3%. Only three pairs qualified. The candidate was 9.3, 13.0 and 18.3 ms slower in those pairs. Median draws/frame were 4,967 and 5,019, with 347 and 345 dropped. One run per build. The runs reached the world threshold at different times. We saw the synthetic single-record GPU improvement, but this checkpoint did not show a frame-rate improvement. AI-assisted. |
… all An execution may ask for thousands of records with a count buffer that counts a few: the clamp runs a group per 64 asked. Before the charge per group, the threads past the count returned at once; with it, the first thread of every group read the budget word, and for mesh records added the group's notes to it, records or none. In memory the CPU maps that is up to three atomics across the bus per empty group (on an RTX 5070 an in-game A/B of 32c6229 ran slower, fxceless#220). Now a group without records makes no atomic; the group's barriers stay in uniform control flow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you, both runs are useful, and the in-game one matters more. Synthetic. The single-record result (19.68 → 17.61 ms, barriers alone neutral) fits the budget being the cost: even one record makes an atomic read and a compare-and-swap on a word in CPU-mapped memory. In-game, slower. One run per build is thin, but all three matched pairs going the same way is enough to take seriously. The single-record benchmark can't show one regression I found in
7e239bf makes a group without records make no atomic. Your build also didn't have d5c15cb, which moves the budget into the card's memory ( If you have time for one more pair on the same checkpoint, 7e239bf against |
|
RTX 3070 8 GB (Ampere, driver 610.88), Ryzen 7 5700X3D, Windows 11 26200. Tested Benchmark ( On this card, the barriers matter little (-8.7%). The per-group charge is what turns windows from slower than one at a time (10.5 µs) into 0.31 µs a draw. The card budget takes another 10-14% off. In game. The base is fork
I'll run AI-assisted (Claude Code); runs on my machine with my own copy, counts and timings only. |
|
Thank you, this is the in-game result the PR needed. 201–206 → 130–145 ms a frame, with the card's share going from about 110 ms to 28–46 ms, also says where the windows' cost was: the per-group charge, not the barriers. I've put your tables in the description. Two notes for your next runs:
|
|
The benchmark and an in-game A/B on an RTX 5080 (driver 621.24, Ryzen 7 5700X3D, Windows 11 26200), at Benchmark
As on the 3070, the budget atomics were almost all of the windows' cost on this card. The barriers take 9.5 % off, and the per-group charge takes off another 97.9 %. In gameSetup:
Run 50 drew the first room's walls on both sides, which no run without this PR did here. Runs 52 and 54 didn't. The walls vary from run to run, so I'm not claiming anything for #168. AI-assisted (Claude Code). Benchmark and runs on my own machine; nothing from the title attached. |
…lamps With fxceless#220 a draw served from a window costs a fraction of one clamped alone (0.2-0.3 us against 4-7 us on RTX 3070 and 5080, and 12-45 % more frames in game with VICTORY_INDIRECT_WINDOW=1), so windows are worth turning on by default. Before that, whether anything writes a record between its window's clamp and its draw needs answering in game (fxceless#107: keeping 16 windows per list broke drawing). With VICTORY_INDIRECT_WINDOW_CHECK=1 every window draw first clamps its record again, by the window's rules, into a buffer of its own with a budget of its own, and a one-thread compare checks it against the window's copy on the card. At the list's next submission the counts go to the log ("window check", every 10,000 checks) and a warning names the first differing record of a run (as the window had it, as it is now). Off by default; costs a clamp and a compare per window draw. Test: through a host list, a record nothing wrote compares equal, and one the card writes after the window's clamp is found and named. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @Peppacodes. The RTX 5080 numbers settle the windows' cost: 32.6 ms → 0.63 ms for 3,200 draws in the benchmark, and 12–22 % shorter frames in game with So the gain is in windows, and the open question is whether windows can be trusted by default (#107: keeping 16 windows per list broke drawing, and one RTX 4090 run with windows on
If anyone with windows on can run a few minutes of gameplay with the check and post the last Also: #220 merges cleanly onto the new
With those two aside, #220 merged onto |
…c, draw-table slots left to their draws, no failing write-watch calls; card fetches inside their flights (off by default) - Descriptor sync: a multiply-and-fold fingerprint of a record in place of BLAKE3 (35 to 42 ms a frame over 250,000 to 300,000 records), and slots that draws read through tables lately are left to their draws (VICTORY_HEAP_SYNC_TABLES=1 mirrors them too): the pass over the heap went from 70-220 ms a frame to about 3. - Write watch: no kernel asking for memory the guards already hold as view memory (pull request #670 by Jonirulah). - Card copies' flagged pieces can come down inside their own flights (pull request #648 by Jonirulah; VICTORY_CARD_FETCH_INFLIGHT=1, off by default). One game run with it on: no device loss, the copy-back thread's fetch wait 181 -> 0 ms a frame, the card busier; no frame-time gain claimed. - Logging: the heap pass's texture part and buffer slots; indirect compute dispatches over 65,535 groups. - README: what was measured, and that pull request #220 with VICTORY_INDIRECT_WINDOW=1 lost the device twice here and is not in. One five-minute game run of this tree's source on an RTX 4070: no device loss; the frame is still 250 to 380 ms (the card is the limit). This merged tree was built; its test suites were not run. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
A second RTX 3070 (slower CPU), Series S: faster in light scenes, slower in heavy ones One run with the switch against one without, same exe and settings otherwise, both about 24 minutes from the first
One run each, and the heavy scenes differ a little between runs, so the direction is firmer than the sizes. It Setup: RTX 3070 8 GB (driver 621.24, 32-lane waves), Ryzen 5 3600, 32 GB, Windows 11, Series S mode (PR #188), 1920x1080, |
|
Turing data point: RTX 2080 SUPER 8 GB (i9-9900, Windows 11, PCIe 3.0), PR head
So this card tracks the 3070 closely: windows -96.9 % against
On Turing almost all of the per-draw cost is the compute pass between two draws itself (4.18 µs); the two UAV waits add about 0.1 µs. On the 5070 Ti in #696 it was the other way round (0.47 µs without the waits, 4.22 with them). So on this generation removing barriers alone ( Rough synthetic bound for this card: about 5,100 clamped executions a frame × ~6 µs ≈ 30 ms a frame of clamp alone, before any loss of overlap with the real draws. For reference, in game this machine runs at about 190 ms a frame of card work, card-bound (with the c96b4f2 texture passes off, see #594). I haven't run this PR in game yet; that A/B is next. (Measured and written with Claude Code, Claude Opus 5.5.) |
…queue for fetches, indirect draw windows made safer, a profiler; all behind switches - VICTORY_ASYNC_SUBMIT=1: submissions are prepared and sent by a thread of the layer, in order, instead of by the title's render thread; the queue's line stays open while its head is prepared. - VICTORY_QUEUE2=1: fetches of what shaders wrote to copies in the card's memory go to a copy queue, with the fix for a piece fetched beside a later flight (fetched again when that flight lands). - Pull request #220 (cheaper indirect draws) is in, its windows off by default; a draw record of 2^23 vertices an instance or more runs empty (its window checker found one list drawing 90 such records). - Fills of upload memory and read-only title buffer copies no longer wait for flights; each is checked against what the flights then wrote, and the first mismatch turns the waiting back on (VICTORY_FILL_WAIT=1). - Up to 512 idle host lists and the texture staging buffers are reused. - VICTORY_MERGE_GAP / VICTORY_MERGE_RUNS (off / 512 by default; the gap form is not exact, see its comment). - VICTORY_PROFILE=1 (diagnostics builds): a sampling profiler inside the layer. - README: what was measured, the history of the device losses with windows, and what is still open (frame rate dips; cause not known). Measured on an RTX 4070 in the first room: about 3.5-4 frames a second before, 6-7 with all the switches, defaults about 4.5-5. Five runs with windows on since the fix, no device loss. This merged tree was built; its whole test suite was not run (the tests around flights, queues, indirect draws and the copy queue were, on the development tree). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
In-game A/B on the same RTX 2080 SUPER 8 GB (i9-9900, Windows 11), following the benchmarks above. PR head
Not covered: one run each; I did not compare the picture closely between the two runs and have not run (Measured and written with Claude Code, Claude Opus 5.5.) |
|
Results on an RTX 3070 8 GB + i9-9900X, Windows 11, Series S profile. This is a port of this PR's budget part onto a #780 ( The same warm build, three runs back to back. Each is the median over world frames 60-160, with
These are single runs with small windows (9-11 status lines), so the medians are noisy, but the GPU drop with windows is large. There were no device losses on this card. WARP tests: 14 passed with all switch combinations, including a lane-order test across the 32-lane boundary. (AI-assisted: ported with Codex, reviewed and measured with Claude Code. No game data.) |
…her codes 0x104/0x105/0x106 - fxceless#646 (USER_DISPATCH_THREADS), fxceless#834 (USER_GROUP_BASE) and our USER_VIEW_SLOT each took 0x104; here they are 0x104, 0x106, 0x105. - record_clamp_with takes the scratch buffer's state as record_clamp_as does since fxceless#220, and bound_split tracks it like clamp_into. - The split read asked.x, which since fxceless#220 is the mesh records' count (a scalar, 0 for dispatches): every full dispatch got 65,535 more groups and twice the charge. It reads the record's x now, as the second record's store does. warp_split_runs_every_group_of_a_wide_ dispatch_once passes again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016TFkzoCQk3ZUibQWPNRBXE
…, small buffers on the card, parallel page merge, absent blocks asked outside the guards' lock, PR fxceless#853 alias guard, GPU_UPLOAD windows, legacy multiply and wide scalar loads); view guard back on in play-lod.ps1 Written by AI agents from this session's leads, reviewed and built here; measured separately. Switches: - VICTORY_INDIRECT_CARD_BUDGET (on; =0 as before): the clamp's per-list budget counter in card memory, zeroed by the clamp shader's own entry, instead of a system-memory buffer with 1-4 atomics per clamp over PCIe (after fxceless/victory-fork PR fxceless#220). - VICTORY_CARD_BUFFERS_MIN_KB (off): card copies for title buffers under 1 MiB, floor 64 KiB (after PR fxceless#200). - VICTORY_MERGE_THREADS (4; =1 as before): merge_under_writes reads contiguous stale pages in one call and compares them on scoped threads; changed_runs skips equal bytes 64 at a time; merging stays in order on the submitting thread. - VICTORY_GUARD_ABSENT_BITS (on; =0 as before): absent blocks still uncommitted are dropped from a range's runs before the guards' lock is taken (nothing marked clean, unlike parking). - PR fxceless#853 (Peppacodes et al.) ported: a write through one view no longer opens the other views of the page; they are noted written and guarded again together (plus clean_bit cleared for the alias). - VICTORY_UPLOAD_WINDOWS_MB / VICTORY_UPLOAD_WINDOWS_ROOM_MB (off): windows in GPU_UPLOAD (ReBAR) heaps, written by the CPU straight into card memory. - VICTORY_LEGACY_MUL=1|2, VICTORY_SMEM_WIDE=1 (off): plain multiplies for exact legacy-multiply cases, scalar buffer loads 4 dwords at a time. - play-lod.ps1: VICTORY_VIEW_GUARD=0 removed (walls of the cell were missing without it: same shot, screenshots). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The clamp charged the list's budget record by record: an atomic read and a compare-and-swap loop per record on one word, every thread of a window racing for it, so a group of n records took n rounds and about n*n/2 atomics. The word is CPU-visible memory (zeroed on the CPU at submission), so on a card of its own each of them crosses the bus. On an RTX 5070 Ti the benchmark's windows of 32 took 46-50 ms for 3,200 draws where draws clamped one at a time took 19 ms (fxceless#220). Now the records' costs go to group-shared memory, one thread charges their sum with one compare-and-swap (retried only if another group got there first), simulating the same saturation record by record in lane order, and every thread reads whether its record fitted. The mesh diagnostics (largest group count asked, groups asked in all) are summed in the group and added once. What a record costs and when it runs empty are unchanged; which records of a group fit is now their lane order instead of the order the GPU served the race. Test: a group with 300 left of the budget keeps its first draw (100), empties the second (250, which takes the rest) and the ones after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 3db5a0e)
… all An execution may ask for thousands of records with a count buffer that counts a few: the clamp runs a group per 64 asked. Before the charge per group, the threads past the count returned at once; with it, the first thread of every group read the budget word, and for mesh records added the group's notes to it, records or none. In memory the CPU maps that is up to three atomics across the bus per empty group (on an RTX 5070 an in-game A/B of 32c6229 ran slower, fxceless#220). Now a group without records makes no atomic; the group's barriers stay in uniform control flow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 7e239bf)
…with fxceless#220's clamp, 159 -> ~121 ms/frame in the world
|
RTX 5080 16 GB, 617.14, Windows 11 Pro 25H2 build 26200.9974, Ryzen 9 5900X, 32 GB RAM. I used a diagnostics switch to toggle draw windows on and off within an Over three 30-second display segments at 2542 × 1396, off/on/off gave 2.985 / 3.446 / 3.813 displayed FPS and 393.94 / 629.10 / 358.66 ms P99. In the overlapping 4,800–5,300 draws-per-frame band, median host-reported GPU time was 179.45 ms across six initial off samples and 78.40 ms across five on samples. The final off segment drew fewer objects, and the captured viewpoints differed. A performance overlay was also visible in the enabled capture. The GPU time decrease is a useful lead. The test does not establish an FPS gain at matched workload. No driver error or device removal was logged and the run ended deliberately. Test method and frame timing. Testing and reporting assisted by OpenAI Codex. |
…with fxceless#220's clamp, 159 -> ~121 ms/frame in the world (cherry picked from commit f8bc690)
…fer indirect windows, a profiler; one implementation where both sides had one Where both sides did the same thing one implementation was kept: - Fetches of what shaders wrote, on a copy queue: upstream's lane (VICTORY_QUEUE2 bit 1, with its refetch) replaces this fork's (5afe21a, VICTORY_RELAY_COPY_QUEUE), on correctness. Ours had the hole upstream fixed: a piece fetched while a later flight writes it comes down half written, and when that flight leaves the piece as it was its compare flags nothing, so title memory keeps the half-written bytes. Upstream's WARP test, adapted to our fetch on integration 3833fff, fails that way (title memory holds 0xdead0001, the half-way value, where 0x600d0002 is due); the merged tree passes it, and fails it again with VICTORY_QUEUE2_REFETCH=0. The lane is on by default here (upstream: off), as our copy queue was (gameplay frame 213 -> 170 ms when it went in); VICTORY_QUEUE2=0, or VICTORY_RELAY_COPY_QUEUE=0 with VICTORY_QUEUE2 unset, fetches on the direct queue. The progress watch of aca0259 watches the lane's fetch as it watched our copy queue's. - The indirect scratch buffer left readable between draws: upstream's tracking (HostList::indirect_state, set at the clamp, back to common when the list closes or the buffer is replaced) replaces ours (scratch_read, set after each execution): the same barriers, and no caller has to report its execution. The ring of 485a070 stays the default where the host takes enhanced barriers (VICTORY_INDIRECT_RING=0: the scratch buffer). - The clamp program: upstream's (pull request fxceless#220: one budget charge per group, the budget in the card's memory, a draw record of 2^23 vertices an instance or more runs empty) with integration's split dispatch (6d59c48: kind 3, four records of base and counts) and its counters of compute records, now gathered per group as upstream gathers the mesh ones; the card's copy of the budget carries all five words back, so the frame line's budget (6831678) and group counts are read as before. The window check (VICTORY_INDIRECT_WINDOW_CHECK=1) works with the ring (the compare reads the ring behind a barrier of the enhanced kind). Windows stay on by default here (measured in the second pass), now with that fix; upstream lost the device three times with windows on before it. - Texture staging buffers: this fork's pool (f5f458e: classes of an eighth of a power of two, 1 GiB, every size; the opening cutscenes' heap pass 187 -> 65 ms) stays, upstream's (powers of two up to 8 MiB, 256 MB) is left out; upstream's VICTORY_STAGING_POOL=0 turns ours off too. - The relay's merge of fetched pieces stays one piece at a time, each gathering the ranges to leave out as they stand (13494e5); upstream's check of read-ahead fills (shaders_write) is called from it per piece. Upstream's alone, as shipped: VICTORY_ASYNC_SUBMIT (off), fills of upload memory and read-only title buffer copies no longer waiting for flights (the first one that read bytes a flight then changed turns the waits back on; VICTORY_FILL_WAIT=1 waits from the start), up to 512 idle host lists, VICTORY_MERGE_GAP / VICTORY_MERGE_RUNS, VICTORY_PROFILE (diagnostics). Both sides' diagnostics of waits for flights are kept. With VICTORY_ASYNC_SUBMIT a page remap first lets what the queues hold and may run go (queue::before_sync), so it is prepared from title memory as it stood when submitted; the land-before-remap of 915add2 follows. Not timed in a game run here (the general test of the merged build does). Checked on the software adapter (diagnostics): the queue tests with VICTORY_QUEUE2 at 0, 1 and 3; the indirect tests on the ring and on the scratch buffer (window check, executions with no barrier of their own, the budget, the split dispatch); the profiler's tests.
Refs #107, #10.
Problem
#107 measured about 3,200 one-record indirect draws a frame at roughly 12 µs each, about 40 of 63 ms of GPU time on an RTX 5080.
VICTORY_INDIRECT_WINDOW=1, which clamps a run of records in one pass, didn't move it. Two reasons, both in our own clamp path:indirect::done, which moves the clamped-arguments buffer back toCOMMON; the next clamp then moved it fromCOMMON. A barrier into or out ofCOMMONmay be a full wait for the driver.shared_buffer, custom heapL0), so on a card of its own each atomic crosses PCIe. On an RTX 5070 Ti, windows of 32 took 46–50 ms for 3,200 draws, where draws clamped one at a time took 19 ms (benchmark below).Change
cc11ccc).HostListremembers that a clamp left its scratch buffer inINDIRECT_ARGUMENT. Executions read it with no barrier of their own, the next clamp moves it straight back toUNORDERED_ACCESS, and it returns toCOMMONonce, when the list closes or a bigger buffer replaces it.indirect::doneis gone.f873394, off by default). WithVICTORY_INDIRECT_WINDOW_CHECK=1, every draw served from a window first clamps its record again (own buffer, own budget) and a compare on the card checks it against the window's copy. Counts are logged aswindow check, plus a warning naming the first record that differed.3db5a0e,23daba3). Record costs go to group-shared memory, and one thread charges the group's sum with a single compare-and-swap (retried only if another group got there first). It simulates the same saturation record by record, in lane order, and each thread reads whether its record fit. The mesh diagnostics are summed in the group and added once. What a record costs and when it runs empty are unchanged; which records of a group fit is now lane order instead of whoever won the race.d5c15cb). Even one record clamped alone makes two atomics in a row on the budget word (a read, then a compare-and-swap), and in CPU-mapped memory both cross PCIe, on the default path too. The word is now a device-local buffer of the list. The list zeroes it before its first clamp (WriteBufferImmediate, as a copy) instead of the CPU zeroing it at submission. When the list closes, the clamp's notes on mesh records are copied to the mapped words, where the next submission reads them for the frame line as before.VICTORY_INDIRECT_CARD_BUDGET=0keeps the old place, for in-game A/B runs.Barrier calls per indirect execution:
Why it is safe
INDIRECT_ARGUMENT, which orders its writes after all earlier executions' argument reads.copy_buffer_region→defer_copy), so nothing recorded between two window draws writes the scratch buffer.Measured
In-game, RTX 3070 8 GB (by @VibeClauding,
d5c15cb, card-bound cell scene,VICTORY_RELAY=2, frame lines from minutes 3–5, one run each; report):VICTORY_INDIRECT_WINDOWThe picture was intact in the dumped frames, with no device removal. Afterwards the frame is bound by preparing and copy-back, not the card.
In-game, RTX 5080 (by @Peppacodes,
32c6229/7e239bf, first room,VICTORY_RELAY=2 VICTORY_LATE_WAIT=3, medians of 20 frame lines; report): with windows on, 157–177 ms a frame against 202 ms formainwith windows off and 218 ms formainwith windows on. The card wait fell from 84 to 22–30 ms. With windows off at7e239bf: 211 ms against 202 ms, within this machine's run-to-run spread (up to 9 %), with the card wait down from 84 to 64 ms. No errors or device loss in six runs.Other in-game runs:
32c6229, windows off, one run each): 232.2 ms against 209.1 ms onmain, so slower. One cause found since: every clamp group touched the budget, including groups past a count buffer's count. Fixed in7e239bf; a rerun has been asked for.a4a745e, CPU-bound at about 550 ms a frame): same frame time, about 23 % more draws a frame, no hangs.Benchmark
indirect::bench(ignored by default, no title files needed): 3,200 one-record indirect draws of our own, records 32 bytes apart, one at a time and in windows of 32. It runs them asmainrecords them and as this branch does, plus windows with the new barriers butmain's clamp, and both modes with the budget in card memory. GPU time comes from timestamps around the list.d5c15cb, @VibeClauding)a4a745e, @Flyander)mainmainmain's clampOn an RTX 5080 (by @Peppacodes): one at a time 14.1 ms on
main, 14.0–14.2 with this, 10.7–10.9 with the budget in card memory; windows of 32 32.6 ms onmain, 0.63 ms with this, 0.52 ms with the budget in card memory.Synthetic single-record mesh draws on an RTX 5070 (by @ryotdev,
32c6229): 19.68 ms → 17.61 ms (−10.5 %) with the new clamp; the barriers alone were neutral.What this shows:
VICTORY_INDIRECT_WINDOW=1.VICTORY_INDIRECT_WINDOW_CHECK=1(f873394) checks every window draw against a fresh clamp of its record on the card and logs any that differ, to settle whether windows can be trusted in a scene. Turning it on by default should wait for GPU: keep indirect argument windows within the named buffers #204 (window bounds) and a check that window draws match fresh clamps; the 16-window breakage on RTX 5080 on 4e17478: 8.5 fps in the lit cutscene; 40 of 63 ms GPU time is 3,227 indirect draws a frame (~12 µs each) #107 likely came from several windows sharing one scratch region, which a single window cannot do (comment).Tests
HostListandHost::execute, recorded twice across a reset.VICTORY_D3D12_DEBUG=1, diagnostics), the host-list tests check that nothing was reported after closing each list. A control that records a wrong barrier into aHostListis caught by the same check (run).windows-latestpasses forf873394: clippy in both configurations, andcargo test --workspace(victory-gpu115 passed, 2 ignored; merged ontomainc96b4f2, 117 passed with only that main's owndepth_boundstest failing on the software adapter, as it does without this PR). Under the debug layer all 12indirect::tests pass with nothing reported (run).AI-assisted (Claude Code). Tests and benchmark ran on GitHub's Windows runners; hardware and in-game numbers are from the testers credited above.
🤖 Generated with Claude Code