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

Closed
github-bot wants to merge 1 commit from github-bot/gh-3592 into main AGit
Owner

@⁠fl4rion on GitHub · 2026-11-30 01:25 UTC · original
fl4rion:card-hash-pool → main · +196 −13 · 2 files · 1 commits · closed without merging

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.

**@⁠fl4rion** on GitHub · 2026-11-30 01:25 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3592) `fl4rion:card-hash-pool` → `main` · +196 −13 · 2 files · 1 commits · closed without merging ## 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.
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. For most copies that is a few hundred bytes.
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.
Each one cost a driver allocation, a wait for its residency, and at least
64 KiB of the card's memory.

When a new area streams in, thousands of copies get their hashes at once.
In an RTX 5070 Ti play log, 3,686 copies were made as the world came in, and
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 some 240 MB of the card's memory for well under 1 MB of data,
while textures waited for room on the card.

Now the hashes are slices of shared 4 MiB buffers:
- slices come in power-of-two size classes from 256 bytes, cut from the
  newest shared buffer, so one allocation and one residency wait serve
  4 MiB of hashes;
- a slice goes back to its class's free list when its copy is dropped.
  That is after the card ran the last submission that used it (the
  submission's plan holds the copy), as the buffer's own release was;
- what a new shared buffer leaves of the previous one goes to the free
  lists in the largest slices it holds;
- the passes that hash and compare already take the hashes as a root view
  by GPU address, so they take the slice's address as they took the
  buffer's. Slices start on 256-byte boundaries.
Hashes too large for a shared buffer (a copy of 16 GiB or more, which the
card copies' size limit never allows) would still get a buffer of their own.

Same play route, before and after (submitting thread, "first whole copies"
on the card copies' line, ms a frame): before, up to 871.5 in the stretch
where the world came in; after, 0.0 in every line of the next runs, and at
most 0.1 in later runs of 503 lines.

Bench (`shadow::hash_pool_tests::bench_hash_places`, ignored, release,
RTX 5070 Ti): the hashes' places of 2,000 copies of 1 MiB, three rounds.
A buffer each: 697, 871 and 1,461 ms (518, 1,686 and 10,488 ms in another
run; it grows with every round). Shared slices: 0.69, 0.12 and 0.08 ms, from
one shared buffer.

Tests: `hash_classes` (the size classes), `hash_slices_lie_apart_and_come_back`
(slices taken together don't overlap, and one given back is the next of its
size taken).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:26:20 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:50 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3592#issuecomment-7321657778) 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.
github-bot closed this pull request 2026-12-01 18:58:15 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3592
No description provided.