GPU: fill table constant buffers that flights write on the card, not at submission #462

Open
iurysf wants to merge 1 commit from upstream-pr/462 into main
iurysf commented 2026-11-25 01:13:44 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by iurysf on 2026-11-25T01:13:44Z.


What'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:

  1. declares the refresh of the host copy for that range (as before), and
  2. records a copy on the card, from the host copy into a 1 MiB device-local buffer of the list's own (HostList::card_constants, 256-byte slots), with a UAV barrier before it and a transition to VERTEX_AND_CONSTANT_BUFFER after 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=0 restores 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.

pair B − A (ms/frame)
1 −32.7
2 −38.1
3 −47.6
4 −20.3

Arm medians over the measured lines: A 271.7 ms, B 221.5 ms.

  • Median paired difference: −35.4 ms/frame, 4 of 4 pairs in the same direction (mean −34.7 ms).
  • Table constant buffers whose fill waited for flights: 1.0/frame (A) → 0.2/frame (B).
  • The run took a PNG every 10 frames, which raises both arms' level the same way.

Image: four A→B turns, comparing the last PNG of A with the first PNG of B (7.1–7.6 s apart):

  • mean per-pixel difference 4.8–7.1/255, with 7.8–12.3% of pixels differing by more than 8/255;
  • the same interval inside one arm gives A→A 5.3/255 (8.8%) and B→B 5.0/255 (8.6%).

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_wrote runs on the hardware adapter and on WARP (VICTORY_D3D12_WARP=1):

  • a "flight" writes a pattern into a host copy on the card;
  • the next list fills two constant buffers (512 and 300 bytes) from it on the card;
  • a readback matches the pattern byte for byte, and the title memory, which still holds 0xAA, was never read.

Limits

  • Only with the late wait. Without VICTORY_RELAY/VICTORY_LATE_WAIT nothing is in the air at recording and nothing changes.
  • About a fifth of the waits remain (0.2/frame). A list recorded on a title thread before the writing flight was sent is submitted after it, so at recording the range is not yet known to be written. A follow-up (on our branch, being measured) also takes ranges flights wrote lately.
  • 1 MiB of card memory per host list, made on first use. When it is full, the list falls back to the old fill.
  • Cost on the GPU: each such view adds one small copy and two barriers. In the world that is about one a frame.

cargo clippy -p victory-gpu --all-targets -- -D warnings (with and without diagnostics) is clean; cargo test -p victory-gpu --features diagnostics --lib passes 120/120 (1 ignored) on a803c87 + this commit.

AI-assisted (Claude Code); measured on real hardware in the game's world.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594834282 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/462). Originally posted by [iurysf](https://github.com/iurysf) on 2026-11-25T01:13:44Z. --- ### What'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: 1. declares the refresh of the host copy for that range (as before), and 2. records a copy on the card, from the host copy into a 1 MiB device-local buffer of the list's own (`HostList::card_constants`, 256-byte slots), with a UAV barrier before it and a transition to `VERTEX_AND_CONSTANT_BUFFER` after 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=0` restores 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`. | pair | B − A (ms/frame) | |---|---| | 1 | −32.7 | | 2 | −38.1 | | 3 | −47.6 | | 4 | −20.3 | Arm medians over the measured lines: A 271.7 ms, B 221.5 ms. - Median paired difference: **−35.4 ms/frame**, 4 of 4 pairs in the same direction (mean −34.7 ms). - Table constant buffers whose fill waited for flights: 1.0/frame (A) → 0.2/frame (B). - The run took a PNG every 10 frames, which raises both arms' level the same way. **Image:** four A→B turns, comparing the last PNG of A with the first PNG of B (7.1–7.6 s apart): - mean per-pixel difference 4.8–7.1/255, with 7.8–12.3% of pixels differing by more than 8/255; - the same interval inside one arm gives A→A 5.3/255 (8.8%) and B→B 5.0/255 (8.6%). 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_wrote` runs on the hardware adapter and on WARP (`VICTORY_D3D12_WARP=1`): - a "flight" writes a pattern into a host copy on the card; - the next list fills two constant buffers (512 and 300 bytes) from it on the card; - a readback matches the pattern byte for byte, and the title memory, which still holds 0xAA, was never read. ### Limits - **Only with the late wait.** Without `VICTORY_RELAY`/`VICTORY_LATE_WAIT` nothing is in the air at recording and nothing changes. - **About a fifth of the waits remain (0.2/frame).** A list recorded on a title thread before the writing flight was sent is submitted after it, so at recording the range is not yet known to be written. A follow-up (on our branch, being measured) also takes ranges flights wrote lately. - **1 MiB of card memory per host list,** made on first use. When it is full, the list falls back to the old fill. - **Cost on the GPU:** each such view adds one small copy and two barriers. In the world that is about one a frame. `cargo clippy -p victory-gpu --all-targets -- -D warnings` (with and without `diagnostics`) is clean; `cargo test -p victory-gpu --features diagnostics --lib` passes 120/120 (1 ignored) on a803c87 + this commit. AI-assisted (Claude Code); measured on real hardware in the game's world.
Peppacodes commented 2026-11-25 05:08:59 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Peppacodes on 2026-11-25T04:26:36Z.


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_write is false when it is recorded.

Setup

  • diag build with diagnostics of fork main c96b4f2 + #220 + this PR (b39d4aa, cherry-picked cleanly), plus #28's watchdog hook and 64 MB pipeline-worker stacks.
  • Series X profile, 1080p, main's defaults (relay, card buffers) + VICTORY_INDIRECT_WINDOW=1.
  • One binary, a fresh copy of the same save per run, standing in the first room. Median of the last 20 frame lines (about 2 min), 5 min after entering the world.
run VICTORY_FILL_ON_CARD ms/frame settles/frame reason waited/frame
74 0 156.5 1.1 fill 1.0 24.0 ms
75 1 156.0 1.1 fill 1.0 21.7 ms
76 0 149.5 1.0 fill 1.0 26.3 ms
77 1 150.8 1.0 fill 1.0 27.2 ms
  • With the switch on, the fills your log names are the same as with it off. All are len=480 in the 174 MB buffer (copy=...+0xae00000), at 0x...fd00 (most), 0x...ec00 and 0x...f2e0. That is the case in your Limits section (0.2/frame on the 4070); on this PC it is every one.
  • Most of them are 256-byte aligned. Binding those straight from the host copy (what #144 does) removed this wait in an earlier A/B on the same PC, because it does not depend on what is in the air at recording. A settle for a title buffer copy in the same buffer then took its place, with the same wait (19-28 ms/frame), as dkdknight found in #107.
  • So here, your follow-up that also takes ranges flights wrote lately is the part that would matter. Happy to run it when it is up.
  • I am trying the same idea for that title buffer copy (a copy between the two host copies on the card, behind the flights) and will report what I find.

AI-assisted (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7152846930 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/462#issuecomment-7152846930). Originally posted by [Peppacodes](https://github.com/Peppacodes) on 2026-11-25T04:26:36Z. --- **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_write` is false when it is recorded. **Setup** - `diag` build with diagnostics of fork main `c96b4f2` + #220 + this PR (`b39d4aa`, cherry-picked cleanly), plus #28's watchdog hook and 64 MB pipeline-worker stacks. - Series X profile, 1080p, main's defaults (relay, card buffers) + `VICTORY_INDIRECT_WINDOW=1`. - One binary, a fresh copy of the same save per run, standing in the first room. Median of the last 20 frame lines (about 2 min), 5 min after entering the world. | run | `VICTORY_FILL_ON_CARD` | ms/frame | settles/frame | reason | waited/frame | |---|---|---|---|---|---| | 74 | 0 | 156.5 | 1.1 | fill 1.0 | 24.0 ms | | 75 | 1 | 156.0 | 1.1 | fill 1.0 | 21.7 ms | | 76 | 0 | 149.5 | 1.0 | fill 1.0 | 26.3 ms | | 77 | 1 | 150.8 | 1.0 | fill 1.0 | 27.2 ms | - With the switch on, the fills your log names are the same as with it off. All are `len=480` in the 174 MB buffer (`copy=...+0xae00000`), at `0x...fd00` (most), `0x...ec00` and `0x...f2e0`. That is the case in your Limits section (0.2/frame on the 4070); on this PC it is every one. - Most of them are 256-byte aligned. Binding those straight from the host copy (what #144 does) removed this wait in an earlier A/B on the same PC, because it does not depend on what is in the air at recording. A settle for a title buffer copy in the same buffer then took its place, with the same wait (19-28 ms/frame), as dkdknight found in #107. - So here, your follow-up that also takes ranges flights wrote lately is the part that would matter. Happy to run it when it is up. - I am trying the same idea for that title buffer copy (a copy between the two host copies on the card, behind the flights) and will report what I find. AI-assisted (Claude Code).
Peppacodes commented 2026-11-25 06:06:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Peppacodes on 2026-11-25T05:10:11Z.


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.

  • A "written lately" rule is very broad in this title. I tried one locally: a table constant buffer went on the card if its host copy was declared written in the last 64 submissions (about 2 frames), with #144 binding the aligned ones first. The 174 MB buffer is declared every frame, so 12,008 table constant buffers a frame took the card path (6 MB). The read settles went to 0, but the frame went from 141-143 ms to 227 ms. Settles were "256 lists in the air" 0.8 + "title memory changed under shader writes" 0.7 (53 ms waited), and the relay's fetch wait doubled.
  • The title buffer copy that takes over after the fills, named by a log: 20 KiB from the 174 MB buffer (another offset each frame) into one whole 20 KiB buffer, once a frame. Doing such copies on the card behind the flights (with the destination declared GPU-written, copied back by the relay) just moved the wait. The CPU fills that read the destinations in later submissions waited instead: 4.5-5 settles a frame, 212 ms a frame.
  • So the waiting reads here form a chain: compute writes the big buffer, the title copies from it into small buffers, and constant buffers read those. Deciding at recording either misses it (this PR as is) or catches far too much. What I want to try next is deciding at submission, when the flights in the air are known: only the 1-5 reads a frame that would wait go to the card, as copies in the list's prelude.

AI-assisted (Claude Code).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153513454 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/462#issuecomment-7153513454). Originally posted by [Peppacodes](https://github.com/Peppacodes) on 2026-11-25T05:10:11Z. --- 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. - **A "written lately" rule is very broad in this title.** I tried one locally: a table constant buffer went on the card if its host copy was declared written in the last 64 submissions (about 2 frames), with #144 binding the aligned ones first. The 174 MB buffer is declared every frame, so **12,008 table constant buffers a frame** took the card path (6 MB). The read settles went to 0, but the frame went from 141-143 ms to **227 ms**. Settles were "256 lists in the air" 0.8 + "title memory changed under shader writes" 0.7 (53 ms waited), and the relay's fetch wait doubled. - **The title buffer copy that takes over** after the fills, named by a log: 20 KiB from the 174 MB buffer (another offset each frame) into one whole 20 KiB buffer, once a frame. Doing such copies on the card behind the flights (with the destination declared GPU-written, copied back by the relay) just moved the wait. The CPU fills that read the destinations in later submissions waited instead: 4.5-5 settles a frame, 212 ms a frame. - So the waiting reads here form a chain: compute writes the big buffer, the title copies from it into small buffers, and constant buffers read those. Deciding at recording either misses it (this PR as is) or catches far too much. What I want to try next is deciding at submission, when the flights in the air are known: only the 1-5 reads a frame that would wait go to the card, as copies in the list's prelude. AI-assisted (Claude Code).
kennymaakay commented 2026-11-25 06:06:42 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by kennymaakay on 2026-11-25T06:05:01Z.


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 the c96b4f2 texture 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/frame

So 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).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154423344 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/462#issuecomment-7154423344). Originally posted by [kennymaakay](https://github.com/kennymaakay) on 2026-11-25T06:05:01Z. --- 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 the c96b4f2 texture 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/frame So 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 commented 2026-11-25 08:09:00 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Garu667 on 2026-11-25T07:34:11Z.


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 8dd30ab with VICTORY_CARD_ROOM_FOR_BUFFERS=1, prologue cell:

  • Cause (logged at the blocked_by fill check): every frame, one Step::Fill of a descriptor-table constant buffer (32–480 bytes) lies inside a title buffer whose range 0x218c0000..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.
  • Aligned views bound on the card copy only: 456 → 348 ms/frame (−24 %), no device loss, no visible fault.
  • Unaligned ones copied on the card too: the fill waits disappear entirely. The remaining ~220 ms/frame settle then comes from a title buffer copy (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=1 partly recovers it.

(Measured and written with Claude Code, Claude Opus 5.5.)

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156007535 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/462#issuecomment-7156007535). Originally posted by [Garu667](https://github.com/Garu667) on 2026-11-25T07:34:11Z. --- 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 8dd30ab with `VICTORY_CARD_ROOM_FOR_BUFFERS=1`, prologue cell: - **Cause** (logged at the `blocked_by` fill check): every frame, one `Step::Fill` of a descriptor-table constant buffer (32–480 bytes) lies inside a title buffer whose range `0x218c0000..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. - **Aligned views bound on the card copy only:** 456 → **348 ms/frame** (−24 %), no device loss, no visible fault. - **Unaligned ones copied on the card too:** the fill waits disappear entirely. The remaining ~220 ms/frame settle then comes from a **title buffer copy** (`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=1` partly recovers it. *(Measured and written with Claude Code, Claude Opus 5.5.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/462:upstream-pr/462'
git switch 'upstream-pr/462'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/462'
git switch 'upstream-pr/462'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/462'
git switch 'upstream-pr/462'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/462'
git switch 'main'
git merge --squash 'upstream-pr/462'
git switch 'main'
git merge --ff-only 'upstream-pr/462'
git switch 'main'
git merge 'upstream-pr/462'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!462
No description provided.