GPU: fill table constant buffers that flights write on the card, not at submission #462
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!462
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-462"
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?
@iurysf on GitHub · 2026-11-25 01:13 UTC · original
iurysf:fill-on-card→main· +192 −0 · 2 files · 1 commits · openWhat's wrong
With the late wait (
VICTORY_RELAY=2), a submission that copies title memory into its upload memory (a constant buffer view of a descriptor table, filled at submission) must wait until every flight that may write that memory has landed: the copy is a CPU read of title memory, and the bytes are not there until the flight's copy-back.In the world this happens once a frame, for one table constant buffer of 480–512 bytes. On an RTX 4070 that one wait costs 52–80 ms a frame (median 67 ms), measured with the relay's wait counters and an in-process sampler. The submitting thread is the frame's critical path, so the whole wait shows in the frame time.
Fix
When a table's constant buffer view reads title memory that a flight in the air may write (
flights_write), the list no longer defers a fill of upload memory. At recording it:HostList::card_constants, 256-byte slots), with a UAV barrier before it and a transition toVERTEX_AND_CONSTANT_BUFFERafter it, and binds the view there.Because the list runs behind the flight on the same queue, the card copy reads what the flight's shaders wrote, with no CPU wait. Title writes to that memory reach the host copy first, through the refresh. Root constant buffers and buffer-to-texture sources keep the old path; in the world they did not wait.
VICTORY_FILL_ON_CARD=0restores the old path. The first fills that still wait are logged with their source range and host copy.Measurement (RTX 4070 12 GB, Windows 11, world, warm cache)
Paired within one run: the switch turned off (A) and on (B) by turns, 4 frame-rate lines (~20 s) per arm, from the moment the world is steady. The first line after each turn is left out. Same scene, cache and temperature for both arms. Base: our test branch (fork main + #38, #63, #71, #147, #154, #255, #270, #348), with
VICTORY_RELAY=2.Arm medians over the measured lines: A 271.7 ms, B 221.5 ms.
Image: four A→B turns, comparing the last PNG of A with the first PNG of B (7.1–7.6 s apart):
The difference is the camera and characters moving, not the switch. No missing or black geometry in B.
Card test:
fill_on_card_tests::constants_filled_on_the_card_read_what_the_card_wroteruns on the hardware adapter and on WARP (VICTORY_D3D12_WARP=1):Limits
VICTORY_RELAY/VICTORY_LATE_WAITnothing is in the air at recording and nothing changes.cargo clippy -p victory-gpu --all-targets -- -D warnings(with and withoutdiagnostics) is clean;cargo test -p victory-gpu --features diagnostics --libpasses 120/120 (1 ignored) ona803c87+ this commit.AI-assisted (Claude Code); measured on real hardware in the game's world.
@Peppacodes on GitHub · 2026-11-25 04:26 UTC · original
RTX 5080 (driver 621.24), Ryzen 7 5700X3D, Windows 11: no change here. The fill that waits is in a list recorded before the flight that writes its range is sent, so
flights_writeis false when it is recorded.Setup
diagbuild with diagnostics of fork mainc96b4f2+ #220 + this PR (b39d4aa, cherry-picked cleanly), plus #28's watchdog hook and 64 MB pipeline-worker stacks.VICTORY_INDIRECT_WINDOW=1.VICTORY_FILL_ON_CARDlen=480in the 174 MB buffer (copy=...+0xae00000), at0x...fd00(most),0x...ec00and0x...f2e0. That is the case in your Limits section (0.2/frame on the 4070); on this PC it is every one.AI-assisted (Claude Code).
@Peppacodes on GitHub · 2026-11-25 05:10 UTC · original
Follow-up from the same RTX 5080, in case it helps with the "ranges flights wrote lately" follow-up. Fork main
310c6eb+ #220 + this PR + #144, same setup as above, one run each.AI-assisted (Claude Code).
@kennymaakay on GitHub · 2026-11-25 06:05 UTC · original
Tested on an RTX 2080 SUPER 8 GB (Turing) + i9-9900, Windows 11, Series X profile, first gameplay scene standing still, relay stage 2, 256 lists, card copies 1 MiB–1280 MB, and
VICTORY_HEAP_RECHECK=0 VICTORY_EARLY_TEXTURES_MS=0 VICTORY_BAKE_TEXTURES_MS=0(with thec96b4f2texture passes on, an 8 GB card runs out of room for card copies, as #594 found).It removes the wait it targets. To see what a submission waits for, I log per 5 s the read that waited, the declaration in the way and the shader that declared it. Before this PR, every frame:
fill 0x...fd00+480 waits for table-UAV <182 MB title buffer> [compute 17af15c4015cb4b6]— 80–140 ms/frameSo it is the same single table CBV you found, behind a table UAV that covers the whole 182 MB buffer. With this PR that line is gone.
On this machine the wait then moves to the next reader of the same buffer, so the frame time does not improve:
copy 0x...afe0+20480 waits for table-UAV <same 182 MB buffer> [compute 17af15c4015cb4b6]— 119–123 ms/frame (4 waits per 5 s, up to 2 flights)That is a title buffer-to-buffer copy (
Step::Copy, 20 KiB) out of the same buffer, which the compute pass declares written in full. Frame time in the steady scene was 265–300 ms with the PR, against 205–250 ms in earlier runs without it (not a paired comparison, so I would not read much into the difference).So for this scene the fix would need to cover title buffer copies whose source is a card copy as well, for example by doing the copy on the card in queue order, like the fill here, instead of on the CPU after the flight lands. The root of it is the declaration: the UAV view spans the whole 182 MB, while the GPU really changes about 3–4 MB of that buffer per frame. Happy to test a follow-up on this card.
Measured and written with AI assistance (Claude Code, Claude Opus 5.5).
@Garu667 on GitHub · 2026-11-25 07:34 UTC · original
Data point from an RTX 3080 (10 GB, wave32) supporting this approach. I did not test this PR's code itself, but my own implementation of the same idea (aligned table CBVs bound on the card copy as in #144, unaligned ones copied on the card in the list's prelude), on fxceless main
8dd30abwithVICTORY_CARD_ROOM_FOR_BUFFERS=1, prologue cell:blocked_byfill check): every frame, oneStep::Fillof a descriptor-table constant buffer (32–480 bytes) lies inside a title buffer whose range0x218c0000..0x2c6c0000(182 MB) is declared written by in-flight compute. The submitting thread waits about 220 ms for all flights each frame, so the CPU and GPU take turns.Step::Copy) touching the same declared range, which is the next thing to look at.Also, for 10 GB cards: with the new defaults (card copies up to 1 GB), VRAM is full (10.0/10 GB), card copies can't be allocated (1 copy, 174 MB) and the CPU compare doubles (725 MB/frame);
VICTORY_CARD_ROOM_FOR_BUFFERS=1partly recovers it.(Measured and written with Claude Code, Claude Opus 5.5.)
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.