Submission split: card_record reads each copy's before hashes once (port of Biskwit/VIctory-reloaded 4d3eae2) #3881

Closed
github-bot wants to merge 2 commits from github-bot/gh-3881 into main AGit
Owner

@⁠JSa25 on GitHub · 2026-11-30 10:12 UTC · original
JSa25:pr/split-befores → main · +64 −35 · 3 files · 2 commits · closed without merging

Fixes #

What it changes

With VICTORY_SUBMIT_SPLIT=1, one thread prepares the next submission while the sending thread records and sends the one before it. The preparing side's card_take makes a copy's "before" hash buffer (Shadow::card_make_before; Card::before is a lock-free OnceLock) without CARD_WORK, as the comment at its call site says. The sending thread holds CARD_WORK while it records. (The comment inside card_make_before, "the sole current caller already holds CARD_WORK", is out of date.)

card_record asked whether a copy has its "before" buffer several times while recording one sync list:

  • for the sends' transitions (send::Own::record, card_has_before());
  • for the fallback path's transition from COPY_DEST to NON_PIXEL_SHADER_RESOURCE;
  • again for the hash passes (card_before_gpu()).

If the other thread makes the buffer between those reads, the first read says "none", so no barrier to a read state is recorded. A later read says "there", so a hash pass is recorded over a copy still in COPY_DEST or UNORDERED_ACCESS.

This change looks at each copy's buffer once, right after the sync list is taken (befores), and gives that one answer to the sends, the transitions and the hash passes. A copy whose buffer appears later is hashed whole by the take that made it, which is behind this list on the queue. send::Own::record takes the answers as a new befores parameter. The compare lists recorded later in card_record (from declared and looked) are not changed.

This is a port of Biskwit/VIctory-reloaded 4d3eae2 (GPL-3.0-or-later, like this repository), adapted to main. We found the race by reading the code. We have not caught it in a log.

Why now: #3809 turns VICTORY_SUBMIT_SPLIT=1 on by default, and then this window exists in every run. With the split off, both sides run on one thread and nothing changes.

How it was tested

  • GPU and profile: RTX 5090, Ryzen 9 9950X3D, Series X, 2560x1440 with DLSS Quality, frame generation off, ray tracing off, VICTORY_SUBMIT_SPLIT=1.
  • Before / after: no change in speed is expected or claimed; it adds one Vec<Option<u64>> per sync list. We did not A/B it for fps.
  • In game: five runs of the opening cell route on main 41adb551 plus this change (and other local switches) had no device loss. One of them, with an unrelated experimental shader switch also on, ended about 10 s into the world on "a host command list did not close (0x80070057)". That error was not in our 21 earlier logs, the command was not identified (no D3D12 debug layer installed), and it has not happened again in the run since.
  • For shader changes, the wave sizes tested: not a shader change.
  • cargo test passed for the crates it touches:
    • cargo test --release --locked -p victory-gpu --lib -- --test-threads=1 on this branch: 921 passed, 1 failed. On unchanged main 41adb551 the result is identical: the same 921 passed and the same 1 failed.
    • The one failure is main's own: shader_cache::tests::every_switch_of_the_translator_is_in_the_key, which reports "VICTORY_SCALAR_SPLITS is not read by the translator any more".
    • Run in parallel, both this branch and main fail 1 to 4 more tests from run to run (card_steps, menu, pool, resource). Each passes alone; see #3668.
  • cargo check --release --locked -p victory: passes.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches ("befores", "card_before", "SUBMIT_SPLIT", "submit split").
    • Related: #3809 (split on by default).
    • #2587 rewrites allocation and grouping in card_before/card_record/send::take. It touches the same functions, and this change is small enough to rebase either way.
    • #2433 and #3103 are other submit-split fixes in different code.

AI use: Claude Code (Claude Opus 5.5) prepared this branch, ran the tests and wrote this text. Posted with the account owner's approval.

**@⁠JSa25** on GitHub · 2026-11-30 10:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881) `JSa25:pr/split-befores` → `main` · +64 −35 · 3 files · 2 commits · closed without merging Fixes # ## What it changes With `VICTORY_SUBMIT_SPLIT=1`, one thread prepares the next submission while the sending thread records and sends the one before it. The preparing side's `card_take` makes a copy's "before" hash buffer (`Shadow::card_make_before`; `Card::before` is a lock-free `OnceLock`) without `CARD_WORK`, as the comment at its call site says. The sending thread holds `CARD_WORK` while it records. (The comment inside `card_make_before`, "the sole current caller already holds `CARD_WORK`", is out of date.) `card_record` asked whether a copy has its "before" buffer several times while recording one sync list: - for the sends' transitions (`send::Own::record`, `card_has_before()`); - for the fallback path's transition from `COPY_DEST` to `NON_PIXEL_SHADER_RESOURCE`; - again for the hash passes (`card_before_gpu()`). If the other thread makes the buffer between those reads, the first read says "none", so no barrier to a read state is recorded. A later read says "there", so a hash pass is recorded over a copy still in `COPY_DEST` or `UNORDERED_ACCESS`. This change looks at each copy's buffer once, right after the sync list is taken (`befores`), and gives that one answer to the sends, the transitions and the hash passes. A copy whose buffer appears later is hashed whole by the take that made it, which is behind this list on the queue. `send::Own::record` takes the answers as a new `befores` parameter. The compare lists recorded later in `card_record` (from `declared` and `looked`) are not changed. This is a port of Biskwit/VIctory-reloaded 4d3eae2 (GPL-3.0-or-later, like this repository), adapted to main. We found the race by reading the code. We have not caught it in a log. Why now: #3809 turns `VICTORY_SUBMIT_SPLIT=1` on by default, and then this window exists in every run. With the split off, both sides run on one thread and nothing changes. ## How it was tested - **GPU and profile:** RTX 5090, Ryzen 9 9950X3D, Series X, 2560x1440 with DLSS Quality, frame generation off, ray tracing off, `VICTORY_SUBMIT_SPLIT=1`. - **Before / after:** no change in speed is expected or claimed; it adds one `Vec<Option<u64>>` per sync list. We did not A/B it for fps. - **In game:** five runs of the opening cell route on main 41adb551 plus this change (and other local switches) had no device loss. One of them, with an unrelated experimental shader switch also on, ended about 10 s into the world on "a host command list did not close (0x80070057)". That error was not in our 21 earlier logs, the command was not identified (no D3D12 debug layer installed), and it has not happened again in the run since. - **For shader changes, the wave sizes tested:** not a shader change. - **`cargo test` passed for the crates it touches:** - `cargo test --release --locked -p victory-gpu --lib -- --test-threads=1` on this branch: 921 passed, 1 failed. On unchanged main 41adb551 the result is identical: the same 921 passed and the same 1 failed. - The one failure is main's own: `shader_cache::tests::every_switch_of_the_translator_is_in_the_key`, which reports "VICTORY_SCALAR_SPLITS is not read by the translator any more". - Run in parallel, both this branch and main fail 1 to 4 more tests from run to run (`card_steps`, `menu`, `pool`, `resource`). Each passes alone; see #3668. - **`cargo check --release --locked -p victory`:** passes. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches ("befores", "card_before", "SUBMIT_SPLIT", "submit split"). - Related: #3809 (split on by default). - #2587 rewrites allocation and grouping in `card_before`/`card_record`/`send::take`. It touches the same functions, and this change is small enough to rebase either way. - #2433 and #3103 are other submit-split fixes in different code. AI use: Claude Code (Claude Opus 5.5) prepared this branch, ran the tests and wrote this text. Posted with the account owner's approval.
With VICTORY_SUBMIT_SPLIT=1 the next submission's card_take can make a
copy's "before" hash buffer (Card::before, a lock-free OnceLock) while
card_record records the sync list of the one before it. card_record asked
for that buffer separately for the sends' transitions
(send::Own::record), for the fallback path's transition to a read state and
for the hash passes, so a pass could be recorded over a copy still in
COPY_DEST or UNORDERED_ACCESS with no barrier to a read state.

The buffers are now looked at once, right after the sync list is taken,
and that one answer goes to the sends, the transitions and the hash
passes. A copy whose buffer appears later is hashed whole by the take
that made it, which is behind this list on the queue. The compare lists
recorded later in card_record are unchanged.

Port of Biskwit/VIctory-reloaded 4d3eae2 (GPL-3.0-or-later).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 10:13:36 +00:00
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 10:23 UTC · original

I found a second ordering case after the sync-list snapshot at ba9fd3b. With split submission, A's take can fail the first hash-buffer allocation. B's take can retry and publish the buffer before the sender records A. B's whole fill still runs behind A on the queue. A can therefore select a declared compare or lazy compare using hashes it cannot yet rely on, even with a consistent sync snapshot.

The follow-up stores the filling submission's existing sent_as alongside the GPU address in the OnceLock. The sync pass, declared ranges, looked ranges, lazy sweep and compute compare all check it. A uses the existing conservative copy-back and B can fill and use its buffer in queue order. This keeps the PR's single sync snapshot.

The new regression forces the first reservation to fail and the second to allocate a real D3D12 buffer. It failed on this PR head because the earlier submission could see that buffer. It passed with the patch on an RTX 4060 and WARP. The focused diagnostics suite passed 15 tests. This is a synthetic allocation-order test.

Companion commit

**@⁠tyr0nsur** on GitHub · 2026-11-30 10:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7275515048) I found a second ordering case after the sync-list snapshot at `ba9fd3b`. With split submission, A's take can fail the first hash-buffer allocation. B's take can retry and publish the buffer before the sender records A. B's whole fill still runs behind A on the queue. A can therefore select a declared compare or lazy compare using hashes it cannot yet rely on, even with a consistent sync snapshot. The follow-up stores the filling submission's existing `sent_as` alongside the GPU address in the `OnceLock`. The sync pass, declared ranges, looked ranges, lazy sweep and compute compare all check it. A uses the existing conservative copy-back and B can fill and use its buffer in queue order. This keeps the PR's single sync snapshot. The new regression forces the first reservation to fail and the second to allocate a real D3D12 buffer. It failed on this PR head because the earlier submission could see that buffer. It passed with the patch on an RTX 4060 and WARP. The focused diagnostics suite passed 15 tests. This is a synthetic allocation-order test. [Companion commit](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/a36da0b5fc796234c8b15c4da6d0c2b45d4b5953)
Author
Owner

@⁠akimfomin on GitHub · 2026-11-30 10:37 UTC · original

@⁠tyr0nsur I carried your a36da0b5 follow-up and @⁠JSa25’s snapshot onto the pinned Lab control, preserving its coalesced copy plan and borrowed declared/looked iterators. The exact generated allocation-order regression executed on our Windows RTX 4070 Ti SUPER. Submission 10 rejected the allocation first filled by submission 11, and 11 and 12 both saw the expected address. Five send-plan tests also passed. A full-RT walk is running on the combined port. I’ll keep the split setting opt-in while collecting gameplay evidence.

**@⁠akimfomin** on GitHub · 2026-11-30 10:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7275853492) @⁠tyr0nsur I carried your `a36da0b5` follow-up and @⁠JSa25’s snapshot onto the pinned Lab control, preserving its coalesced copy plan and borrowed `declared`/`looked` iterators. The exact generated allocation-order regression executed on our Windows RTX 4070 Ti SUPER. Submission 10 rejected the allocation first filled by submission 11, and 11 and 12 both saw the expected address. Five send-plan tests also passed. A full-RT walk is running on the combined port. I’ll keep the split setting opt-in while collecting gameplay evidence.
When an earlier allocation fails, let that submission retain its conservative copy-back even if the split prepare thread has published a later buffer. Gate both sync and compare passes on the number of the first whole fill.

Co-authored-by: Claude Opus 5.5 <[email protected]>
github-bot force-pushed github-bot/gh-3881 from a36da0b5fc to 59c79f3981 2026-11-30 15:23:45 +00:00 Compare
Author
Owner

@⁠JSa25 on GitHub · 2026-11-30 15:16 UTC · original

Thanks @⁠tyr0nsur. I reviewed it and pulled your commit in as it is, with your authorship kept (59c79f39 after the rebase). The numbering holds: with the relay on, both take paths number from QUEUE_ORDER, and without it every take is 0, so nothing changes there.

I also rebased the branch onto c71899d9, since main had moved. send::Own::record now runs on the scratch guard and copy_runs, and host.rs uses looked.iter(&declared). It shows as mergeable again. Two notes from that:

  • Main's lib tests don't compile at c71899d9. The compare-prelude UAV test (990be53f) calls card_pass with 5 arguments since #3838 added capture. With , [0, 0, 0] added to its two calls, which is not part of this PR, cargo test --release --locked -p victory-gpu --lib -- --test-threads=1 gives:

    • this branch: 1115 passed, 2 failed;
    • main: 1114 passed, the same 2 failed (shader_cache::tests::every_switch_of_the_translator_is_in_the_key and list::thin::tests::bindings_record_no_work).

    The extra pass is your later_hash_allocation_is_hidden_from_an_earlier_submission, which ran on an RTX 5090 rather than skipping.

  • One ungated read is left, and it's harmless. The new compare prelude's UAV barrier list takes card_sides()'s before for compared ranges. compared is twin && fits, and every twin is now the gated card_before_gpu(sent_as), so this only adds barriers for buffers this submission may use.

Thanks also @⁠akimfomin for running the regression on the Lab branch.

**@⁠JSa25** on GitHub · 2026-11-30 15:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7282735551) Thanks @⁠tyr0nsur. I reviewed it and pulled your commit in as it is, with your authorship kept (59c79f39 after the rebase). The numbering holds: with the relay on, both take paths number from `QUEUE_ORDER`, and without it every take is 0, so nothing changes there. I also rebased the branch onto c71899d9, since main had moved. `send::Own::record` now runs on the scratch guard and `copy_runs`, and `host.rs` uses `looked.iter(&declared)`. It shows as mergeable again. Two notes from that: - **Main's lib tests don't compile at c71899d9.** The compare-prelude UAV test (990be53f) calls `card_pass` with 5 arguments since #3838 added `capture`. With `, [0, 0, 0]` added to its two calls, which is not part of this PR, `cargo test --release --locked -p victory-gpu --lib -- --test-threads=1` gives: - this branch: 1115 passed, 2 failed; - main: 1114 passed, the same 2 failed (`shader_cache::tests::every_switch_of_the_translator_is_in_the_key` and `list::thin::tests::bindings_record_no_work`). The extra pass is your `later_hash_allocation_is_hidden_from_an_earlier_submission`, which ran on an RTX 5090 rather than skipping. - **One ungated read is left, and it's harmless.** The new compare prelude's UAV barrier list takes `card_sides()`'s `before` for `compared` ranges. `compared` is `twin && fits`, and every `twin` is now the gated `card_before_gpu(sent_as)`, so this only adds barriers for buffers this submission may use. Thanks also @⁠akimfomin for running the regression on the Lab branch.
Author
Owner

@⁠mstrmoos on GitHub · 2026-11-30 19:22 UTC · original

Picked onto our branch with #3753, #3756, #3760, #3881, #3832, #3858 and four that have since merged (#3818, #3850, #3874, #3871). #3760 needed a hand merge on top of the others.

All of victory-gpu's and victory-shader's tests passed. On the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, the frame median went from 40.4 to 39.1 ms for the whole set. I didn't measure the PRs one by one, so this is evidence of no regression rather than this PR's own gain. Screenshots looked clean.

**@⁠mstrmoos** on GitHub · 2026-11-30 19:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7289290812) Picked onto our branch with #3753, #3756, #3760, #3881, #3832, #3858 and four that have since merged (#3818, #3850, #3874, #3871). #3760 needed a hand merge on top of the others. All of victory-gpu's and victory-shader's tests passed. On the RTX 5080 16 GB, Ryzen 7 9800X3D, Windows 11, Series X profile, same save and 90 s bench route each run, the frame median went from 40.4 to 39.1 ms for the whole set. I didn't measure the PRs one by one, so this is evidence of no regression rather than this PR's own gain. Screenshots looked clean.
Author
Owner

@⁠Zeyphers on GitHub · 2026-11-30 20:20 UTC · original

Merged onto main 84bd61e2 and benched on an RTX 2080 Super 8 GB and Ryzen 7 5800X (Series S, DLSS Quality, standing scene, 180 s): 9.4 fps median vs 9.2–9.7 baseline, so no measurable change on this CPU-bound rig. Two baseline runs differed by about 0.5 fps, so that's the noise. Only one run per PR, in a standing scene, not a walk.

**@⁠Zeyphers** on GitHub · 2026-11-30 20:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7290751986) Merged onto main `84bd61e2` and benched on an RTX 2080 Super 8 GB and Ryzen 7 5800X (Series S, DLSS Quality, standing scene, 180 s): 9.4 fps median vs 9.2–9.7 baseline, so no measurable change on this CPU-bound rig. Two baseline runs differed by about 0.5 fps, so that's the noise. Only one run per PR, in a standing scene, not a walk.
github-bot closed this pull request 2026-12-01 18:51:04 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:48 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:48 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3881#issuecomment-7321568182) 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

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