Card copies: their piece hashes are slices of shared buffers, not a buffer each #3592

Closed
fl4rion wants to merge 1 commit from upstream-pr/3592 into main
fl4rion commented 2026-11-30 01:25:06 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fl4rion on 2026-11-30T01:25:06Z.


What it changes

A title buffer's copy in the card's memory keeps a 128-bit hash of each 64 KiB piece on the card, so that the compare after a submission can find the pieces its shaders wrote. That is a few hundred bytes for most copies. But each copy's hashes were a committed buffer of their own, made on the submitting thread the first time shaders were declared to write the copy: a driver allocation, a residency wait and at least 64 KiB of VRAM each.

When an area streams in, thousands of copies get their hashes at once. In an RTX 5070 Ti play log (3,686 copies made as the world came in), the card copies' summary line put up to 871 ms of a frame on the submitting thread under "first whole copies", which is this allocation. The hashes also held about 240 MB of VRAM for well under 1 MB of data, while textures were waiting for room on the card.

  • Hashes are slices of shared 4 MiB buffers, in power-of-two size classes from 256 bytes, cut from the newest shared buffer: one allocation and one residency wait per 4 MiB of hashes. What a new shared buffer leaves of the previous one goes to the free lists in the largest slices it holds.
  • A slice goes back to its class's free list when its copy (Shadow) is dropped. That is after the card ran the last submission that used it, because the submission's CardPlan holds the copies it used (_synced) until the submission has run. It's the same point at which the per-copy buffer used to be released, so no timed delay is needed.
  • The hash and compare passes already take the hashes by GPU address as a root view (card_before_gpu); they now get the slice's address. Slices start on 256-byte boundaries. card_sides() still returns the resource, but callers only check whether it is there.
  • Hashes larger than a shared buffer (a 16 GiB copy, which the card-copy size limit never allows) would still get a buffer of their own, so nothing that worked before can fail now.
  • No switch: the results are the same, only the allocations change.

How it was tested

  • GPU: RTX 5070 Ti.
  • Before / after, in play (measured on our fork's tree, where this same change landed): "first whole copies" on the submitting thread had peaks of 871.5 ms a frame as the world streamed in. With the change it read 0.0 ms in every line of the following runs, and at most 0.1 ms in later runs (503 five-second lines).
  • Bench shadow::hash_pool_tests::bench_hash_places (ignored; release build), the hashes' places of 2,000 copies of 1 MiB, three rounds: a buffer each 697 / 871 / 1,461 ms (518 / 1,686 / 10,488 ms in another run, growing every round); shared slices 0.69 / 0.12 / 0.08 ms, from one shared buffer.
  • On main with this change: an HLE/API probe title on both the Series X and Series S profiles, 3 runs each, gave the same results as main, with no new mismatches and no crashes. That ran alongside #3586, which the probe needs to finish.
  • New tests: hash_classes, and hash_slices_lie_apart_and_come_back (slices taken together don't overlap; one given back is the next of its size taken).
  • cargo test -p victory-gpu --lib: 923 passed, 1 failed. The failure, shader_cache::tests::every_switch_of_the_translator_is_in_the_key, fails on main as well. cargo build --release -p victory and clippy: nothing new.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #945 by @Robotniq, which first put these hashes in shared slots (1 MiB buffers, behind VICTORY_PACK_HASHES=1, off by default, with a 10 s delay before a slot is reused), and which has its own measurements of the VRAM cost. This PR covers the same goal, with these differences:

    • it is on by default, with no switch;
    • slots are reused when the copy is dropped, which is tied to the submission having run, instead of after a timed wait;
    • it adds the measured submitting-thread stall above;
    • it applies cleanly to current main, where #945 is now in conflict.

    #945's live-card-buffer log line is not part of this PR. If the maintainers prefer #945, I'm glad to close this one in its favour.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5557329159 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3592). Originally posted by [fl4rion](https://github.com/fl4rion) on 2026-11-30T01:25:06Z. --- ## What it changes A title buffer's copy in the card's memory keeps a 128-bit hash of each 64 KiB piece on the card, so that the compare after a submission can find the pieces its shaders wrote. That is a few hundred bytes for most copies. But each copy's hashes were a committed buffer of their own, made on the submitting thread the first time shaders were declared to write the copy: a driver allocation, a residency wait and at least 64 KiB of VRAM each. When an area streams in, thousands of copies get their hashes at once. In an RTX 5070 Ti play log (3,686 copies made as the world came in), the card copies' summary line put up to **871 ms of a frame** on the submitting thread under "first whole copies", which is this allocation. The hashes also held about **240 MB of VRAM** for well under 1 MB of data, while textures were waiting for room on the card. - Hashes are slices of shared 4 MiB buffers, in power-of-two size classes from 256 bytes, cut from the newest shared buffer: one allocation and one residency wait per 4 MiB of hashes. What a new shared buffer leaves of the previous one goes to the free lists in the largest slices it holds. - A slice goes back to its class's free list when its copy (`Shadow`) is dropped. That is after the card ran the last submission that used it, because the submission's `CardPlan` holds the copies it used (`_synced`) until the submission has run. It's the same point at which the per-copy buffer used to be released, so no timed delay is needed. - The hash and compare passes already take the hashes by GPU address as a root view (`card_before_gpu`); they now get the slice's address. Slices start on 256-byte boundaries. `card_sides()` still returns the resource, but callers only check whether it is there. - Hashes larger than a shared buffer (a 16 GiB copy, which the card-copy size limit never allows) would still get a buffer of their own, so nothing that worked before can fail now. - No switch: the results are the same, only the allocations change. ## How it was tested - GPU: RTX 5070 Ti. - Before / after, in play (measured on our fork's tree, where this same change landed): "first whole copies" on the submitting thread had peaks of 871.5 ms a frame as the world streamed in. With the change it read 0.0 ms in every line of the following runs, and at most 0.1 ms in later runs (503 five-second lines). - Bench `shadow::hash_pool_tests::bench_hash_places` (ignored; release build), the hashes' places of 2,000 copies of 1 MiB, three rounds: a buffer each 697 / 871 / 1,461 ms (518 / 1,686 / 10,488 ms in another run, growing every round); shared slices 0.69 / 0.12 / 0.08 ms, from one shared buffer. - On main with this change: an HLE/API probe title on both the Series X and Series S profiles, 3 runs each, gave the same results as main, with no new mismatches and no crashes. That ran alongside #3586, which the probe needs to finish. - New tests: `hash_classes`, and `hash_slices_lie_apart_and_come_back` (slices taken together don't overlap; one given back is the next of its size taken). - `cargo test -p victory-gpu --lib`: 923 passed, 1 failed. The failure, `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`, fails on main as well. `cargo build --release -p victory` and clippy: nothing new. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #945 by @Robotniq, which first put these hashes in shared slots (1 MiB buffers, behind `VICTORY_PACK_HASHES=1`, off by default, with a 10 s delay before a slot is reused), and which has its own measurements of the VRAM cost. This PR covers the same goal, with these differences: - it is on by default, with no switch; - slots are reused when the copy is dropped, which is tied to the submission having run, instead of after a timed wait; - it adds the measured submitting-thread stall above; - it applies cleanly to current main, where #945 is now in conflict. #945's live-card-buffer log line is not part of this PR. If the maintainers prefer #945, I'm glad to close this one in its favour.
trustno1-coder commented 2026-12-01 18:50:41 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:50:41Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321657778 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3592#issuecomment-7321657778). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:50:41Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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!3592
No description provided.