Card copies' hashes in shared 1 MiB buffers (VICTORY_PACK_HASHES=1, off by default); live card buffers in the log #945

Open
Robotniq wants to merge 1 commit from upstream-pr/945 into main
Robotniq commented 2026-11-28 09:38:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Robotniq on 2026-11-28T09:38:17Z.


What was wrong

Every card copy of a title buffer that shaders are declared to write gets a committed buffer of its own for the hashes of its 64 KiB pieces (Shadow::card_make_before, made with Host::uav_buffer(card_hash_bytes(size))): (size / 64 KiB + 2) * 16 bytes, 48 bytes for most copies. With VICTORY_CARD_BUFFERS_MIN_KB=64, which both launchers set, there are thousands of them: on main at 63b902f with the launcher as shipped, about 3,150 were alive near the end of a 5-minute run on my 8 GB card (see the table below).

On this card a committed buffer takes far more than it asks for. The ignored test in this branch makes some and reads DXGI's CurrentUsage: 2,000 buffers of 256 bytes raised it by 73 MB, about 36 KiB each. As a check, 20 buffers of 1 MiB read as about 947 KiB each, so these readings are approximate. If a 48-byte buffer costs what a 256-byte one does, the hashes held about 110 MB of the card.

No line of the log shows this. "host copies in the card's memory: ... their bytes from before" counts the 48 bytes (it says 0 MB), and "made so far: ... card buffers" counts what was made since the start, not what is alive.

What changes

  • VICTORY_PACK_HASHES=1 (off by default; unset, every copy keeps a buffer of its own, as now). Hashes of up to 32 KiB lie in slots of shared 1 MiB buffers, one set per size class (256 B, 512 B ... 32 KiB); larger ones keep their own buffer. A slot goes back when its copy goes and is taken again 10 s later at the earliest. A copy that gets a slot has all its pieces hashed into it first, as with a new buffer. Shadow::card_sides now gives the hashes' address on the card (Option<u64>) instead of a buffer, and the two SetComputeRootUnorderedAccessView(2, ...) calls take it as it is. The hashes are only reached through that root view, and the barrier before the compare is a UAV barrier on no resource, so no barrier names a shared buffer (the reasoning of VICTORY_BUDGET_PACK's slots). The shared buffers stay until the end of the run.
  • A line every 30 s, from the sweep: the card buffers Host::uav_buffer made that are alive, by the size asked for (4 KiB or less, over 4 KiB up to 64 KiB, larger), each with the bytes asked for rounded up to a multiple of 64 KiB (so more than the ~36 KiB measured above for the small ones). A buffer is counted until its last release, through a COM object kept as its private data, the way book.rs learns when its objects go. No switch: it costs a box and one SetPrivateDataInterface call per buffer made.
  • small_buffers_cost_the_card, an ignored test for the cost above (cargo test -p victory-gpu small_buffers_cost_the_card -- --ignored --nocapture). small_buffers_cost in host/place.rs measures buffers of 64 KiB; this one measures 256 bytes against 1 MiB.

With the switch unset, nothing changes but the new line.

Measured

RTX 3070 Ti 8 GB, i7-13700F, 32 GB RAM, Windows 11, driver 621.40. Series S profile, DLSS Quality, the title's ray tracing off (its 43 ray-tracing pipelines left out with VICTORY_SKIP_PIPELINES), VICTORY_CARD_ROOM_FOR_TARGETS_MB=1600, VICTORY_TEXTURE_ROOM_PERCENT=85, diagnostics build through play-foxhound.ps1 -Build diag. The same save each time, keys sent by a script, 300 s from when the world starts. fps is the median of the frame-rate lines after the first minute and moves about ±1 between runs.

On main at 63b902f with this branch, the launcher as shipped (memory stack on, VICTORY_INDIRECT_CARD_BUDGET at its default), one run each after a warm-up run; the two runs' switch lists differ only in this switch:

unset VICTORY_PACK_HASHES=1
card buffers alive asked for 4 KiB or less, near the end 4,135 977
fps, median after the first minute 22.1 22.3
peak in use 6,788 MB 6,791 MB
error lines Streamline's presentCommon() line, which every run has the same
  • The 977 left are the host lists' 256-byte card budgets (about one per host list); VICTORY_INDIRECT_CARD_BUDGET=0 removes those, and this change does not touch them.
  • About 110 MB of the card back by the estimate above (3,158 buffers); one run's peak moves by ±300 MB from run to run, so it does not show there.
  • The fps difference (0.2) is inside the run-to-run noise.

Earlier, on my own tree (based on 0cef07e with the fxceless/victory-fork tree of 27 November merged in and changes of my own), the same switch took the count from 3,214 to 1 with VICTORY_INDIRECT_CARD_BUDGET=0, fps 25.4 and 24.9 (one pair), and every later run that day had it on with no device loss. A review of the change by another AI model (GPT, through Codex) found no lifetime problem: when fences complete normally, a slot cannot be taken again while a submission that wrote it is in flight.

Tests

  • cargo clippy --workspace --all-targets --locked -- -D warnings, plain and with --all-features: no warning from this change. On 63b902f clippy already stops on three warnings of main's own (clippy::let_and_return in victory-shader/src/emit/mod.rs, clippy::manual_is_multiple_of in victory-gpu/src/shadow.rs and, with --all-features, in victory-gpu/src/descriptor.rs), the ones #705 clears.
  • cargo test --workspace --locked: all pass, no failure (victory-gpu: 453 passed, 37 ignored).
  • small_buffers_cost_the_card by hand on the RTX 3070 Ti: the 73 MB and 947 KiB above.

Not tested

  • Other cards and drivers, AMD and Intel included: what a small committed buffer costs may differ.
  • Series X, frame generation, the title's ray tracing on.
  • A session longer than the 5-minute test with it on.
  • A fence wait that fails: then only the 10 s keeps a slot from being taken again.

Notes

  • BudgetSlot gives its slots back through retire. I kept the 10 s wait because that is what ran; I can switch to retire if you prefer.
  • If #890 goes in, cards under 10 GiB keep the 16 MiB floor and have few card copies, so this would matter mostly where VICTORY_CARD_BUFFERS_MIN_KB=64 still holds.
  • #884 and #682 also change Host::uav_buffer. Whichever lands second moves the one count_uav call to where the card buffer is made.

Measured with AI assistance (Claude Code); the runs were made on my machine.

🤖 Generated with Claude Code

https://claude.ai/code/session_017D5NZ3Fd7undwVFyu8fQN1

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5538808398 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/945). Originally posted by [Robotniq](https://github.com/Robotniq) on 2026-11-28T09:38:17Z. --- ## What was wrong Every card copy of a title buffer that shaders are declared to write gets a committed buffer of its own for the hashes of its 64 KiB pieces (`Shadow::card_make_before`, made with `Host::uav_buffer(card_hash_bytes(size))`): `(size / 64 KiB + 2) * 16` bytes, 48 bytes for most copies. With `VICTORY_CARD_BUFFERS_MIN_KB=64`, which both launchers set, there are thousands of them: on `main` at 63b902f with the launcher as shipped, about 3,150 were alive near the end of a 5-minute run on my 8 GB card (see the table below). On this card a committed buffer takes far more than it asks for. The ignored test in this branch makes some and reads DXGI's `CurrentUsage`: 2,000 buffers of 256 bytes raised it by 73 MB, about 36 KiB each. As a check, 20 buffers of 1 MiB read as about 947 KiB each, so these readings are approximate. If a 48-byte buffer costs what a 256-byte one does, the hashes held about 110 MB of the card. No line of the log shows this. "host copies in the card's memory: ... their bytes from before" counts the 48 bytes (it says 0 MB), and "made so far: ... card buffers" counts what was made since the start, not what is alive. ## What changes - `VICTORY_PACK_HASHES=1` (off by default; unset, every copy keeps a buffer of its own, as now). Hashes of up to 32 KiB lie in slots of shared 1 MiB buffers, one set per size class (256 B, 512 B ... 32 KiB); larger ones keep their own buffer. A slot goes back when its copy goes and is taken again 10 s later at the earliest. A copy that gets a slot has all its pieces hashed into it first, as with a new buffer. `Shadow::card_sides` now gives the hashes' address on the card (`Option<u64>`) instead of a buffer, and the two `SetComputeRootUnorderedAccessView(2, ...)` calls take it as it is. The hashes are only reached through that root view, and the barrier before the compare is a UAV barrier on no resource, so no barrier names a shared buffer (the reasoning of `VICTORY_BUDGET_PACK`'s slots). The shared buffers stay until the end of the run. - A line every 30 s, from the sweep: the card buffers `Host::uav_buffer` made that are alive, by the size asked for (4 KiB or less, over 4 KiB up to 64 KiB, larger), each with the bytes asked for rounded up to a multiple of 64 KiB (so more than the ~36 KiB measured above for the small ones). A buffer is counted until its last release, through a COM object kept as its private data, the way `book.rs` learns when its objects go. No switch: it costs a box and one `SetPrivateDataInterface` call per buffer made. - `small_buffers_cost_the_card`, an ignored test for the cost above (`cargo test -p victory-gpu small_buffers_cost_the_card -- --ignored --nocapture`). `small_buffers_cost` in `host/place.rs` measures buffers of 64 KiB; this one measures 256 bytes against 1 MiB. With the switch unset, nothing changes but the new line. ## Measured RTX 3070 Ti 8 GB, i7-13700F, 32 GB RAM, Windows 11, driver 621.40. Series S profile, DLSS Quality, the title's ray tracing off (its 43 ray-tracing pipelines left out with `VICTORY_SKIP_PIPELINES`), `VICTORY_CARD_ROOM_FOR_TARGETS_MB=1600`, `VICTORY_TEXTURE_ROOM_PERCENT=85`, diagnostics build through `play-foxhound.ps1 -Build diag`. The same save each time, keys sent by a script, 300 s from when the world starts. fps is the median of the frame-rate lines after the first minute and moves about ±1 between runs. On `main` at 63b902f with this branch, the launcher as shipped (memory stack on, `VICTORY_INDIRECT_CARD_BUDGET` at its default), one run each after a warm-up run; the two runs' switch lists differ only in this switch: | | unset | `VICTORY_PACK_HASHES=1` | |---|---:|---:| | card buffers alive asked for 4 KiB or less, near the end | 4,135 | 977 | | fps, median after the first minute | 22.1 | 22.3 | | peak in use | 6,788 MB | 6,791 MB | | error lines | Streamline's `presentCommon()` line, which every run has | the same | - The 977 left are the host lists' 256-byte card budgets (about one per host list); `VICTORY_INDIRECT_CARD_BUDGET=0` removes those, and this change does not touch them. - About 110 MB of the card back by the estimate above (3,158 buffers); one run's peak moves by ±300 MB from run to run, so it does not show there. - The fps difference (0.2) is inside the run-to-run noise. Earlier, on my own tree (based on 0cef07e with the fxceless/victory-fork tree of 27 November merged in and changes of my own), the same switch took the count from 3,214 to 1 with `VICTORY_INDIRECT_CARD_BUDGET=0`, fps 25.4 and 24.9 (one pair), and every later run that day had it on with no device loss. A review of the change by another AI model (GPT, through Codex) found no lifetime problem: when fences complete normally, a slot cannot be taken again while a submission that wrote it is in flight. ## Tests - `cargo clippy --workspace --all-targets --locked -- -D warnings`, plain and with `--all-features`: no warning from this change. On 63b902f clippy already stops on three warnings of main's own (`clippy::let_and_return` in `victory-shader/src/emit/mod.rs`, `clippy::manual_is_multiple_of` in `victory-gpu/src/shadow.rs` and, with `--all-features`, in `victory-gpu/src/descriptor.rs`), the ones #705 clears. - `cargo test --workspace --locked`: all pass, no failure (`victory-gpu`: 453 passed, 37 ignored). - `small_buffers_cost_the_card` by hand on the RTX 3070 Ti: the 73 MB and 947 KiB above. ## Not tested - Other cards and drivers, AMD and Intel included: what a small committed buffer costs may differ. - Series X, frame generation, the title's ray tracing on. - A session longer than the 5-minute test with it on. - A fence wait that fails: then only the 10 s keeps a slot from being taken again. ## Notes - `BudgetSlot` gives its slots back through `retire`. I kept the 10 s wait because that is what ran; I can switch to `retire` if you prefer. - If #890 goes in, cards under 10 GiB keep the 16 MiB floor and have few card copies, so this would matter mostly where `VICTORY_CARD_BUFFERS_MIN_KB=64` still holds. - #884 and #682 also change `Host::uav_buffer`. Whichever lands second moves the one `count_uav` call to where the card buffer is made. Measured with AI assistance (Claude Code); the runs were made on my machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017D5NZ3Fd7undwVFyu8fQN1
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/945:upstream-pr/945'
git switch 'upstream-pr/945'

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/945'
git switch 'upstream-pr/945'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/945'
git switch 'upstream-pr/945'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/945'
git switch 'main'
git merge --squash 'upstream-pr/945'
git switch 'main'
git merge --ff-only 'upstream-pr/945'
git switch 'main'
git merge 'upstream-pr/945'
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
trustno1-coder/VIctory-NVIDIA!945
No description provided.