Skip to content

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 into
trustno1-coder:mainfrom
Robotniq:pr-hashes
Open

Robotniq wants to merge 1 commit into
trustno1-coder:mainfrom
Robotniq:pr-hashes

Conversation

@Robotniq

Copy link
Copy Markdown

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 CI: clear the four clippy -D warnings errors on main #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

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

🤖 Generated with Claude Code

https://claude.ai/code/session_017D5NZ3Fd7undwVFyu8fQN1

…ff by default); live card buffers in the log

Every card copy of a title buffer whose shader writes are declared had a
committed buffer of its own for the hashes of its 64 KiB pieces, 48 bytes
for most, and a small committed buffer costs the card far more than that
(about 36 KiB for 256 bytes on an RTX 3070 Ti, small_buffers_cost_the_card).
With the switch, hashes of up to 32 KiB take slots of shared 1 MiB buffers
by size class; a slot given back is taken again 10 s later at the earliest.
On 63b902f with the launcher as shipped, 5-minute run: card buffers alive
asked for 4 KiB or less 4,135 -> 977, fps 22.1 -> 22.3.

A line every 30 s counts the card buffers Host::uav_buffer made that are
alive, by the size asked for, until their last release (a COM object kept
as private data); no other line counts them alive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017D5NZ3Fd7undwVFyu8fQN1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant