Card copies: read each hash buffer once per recording, so none is bound as an SRV in COPY_DEST (#4543, #4642) #4678

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

@⁠davemathews12 on GitHub · 2026-12-01 01:32 UTC · original
davemathews12:fix/card-hash-before-snapshot → main · +13 −2 · 1 files · 1 commits · closed without merging

Refs #4544, Refs #4643

What it changes

The card-copy sync (host.rs, the list that brings copies in the card's memory up to date) decides twice whether a copy has its hash buffer (before):

  1. after the copies: own.is_none() && before.is_some() && !ranges.is_empty() pushes the copy's COPY_DEST -> NON_PIXEL_SHADER_RESOURCE transition;
  2. in the hash pass: shadow.card_before_gpu() decides whether the copy is bound as a root SRV (SetComputeRootShaderResourceView(1, shadow.buffer_gpu())).

The sending thread records this list while the submitting thread prepares the next submission, and card_take_prepared is where before is made (card_make_before), as the comment there says. A before made between the two reads leaves the copy in COPY_DEST and binds it as a root SRV. That is the debug-layer message in #4544 ("Resource state (0x400: COPY_DEST) (promoted from COMMON state) … is invalid for use as a root shader resource … Missing State: 0x40"), and the root-SRV messages in #4643's GBV run (3 of them). NVIDIA and AMD tolerate it; the Arc driver removes the device.

The fix reads before once per copy, before own.record and the copy loop, and the hash pass uses that snapshot. before is a OnceLock (set once, never cleared), so every later read agrees whenever the snapshot saw it, and the transition is always pushed for a copy that is hashed. A copy that gets its before after the snapshot isn't hashed in this list. The submission that made it has it in whole and hashes all of it, as before.

What it doesn't change: #4643's other messages (CopyBufferRegion reading a buffer in COPY_DEST where COPY_SOURCE was required, 116–249 of them) come from another path, which this doesn't touch.

How it was tested

  • GPU and profile: none. I have no Windows machine, and this has not been run in the game. The race is found by reading the code, not reproduced.
  • Before: n/a. After: n/a.
  • For shader changes, the wave sizes tested: n/a (no shader change).
  • cargo test passed for the crates it touches: not run (the code is Windows-only). cargo clippy -p victory-gpu --tests --target x86_64-pc-windows-msvc: no errors and no new warnings, cross-checked from Linux. cargo xtask policy --staged passes.

Asking Arc owners (@⁠marcelloveyugioh-wq, @⁠gilmarcs): with VICTORY_D3D12_DEBUG=1 and card buffers on, does the "invalid for use as a root shader resource" message still appear with this change?

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches (#4544, #4643, "hash pass barrier", "COPY_DEST NON_PIXEL", "card copy hash state"). None changes this transition. Related: #945 (card copies' hashes in shared buffers, off by default, different code path).

🤖 Generated with Claude Code

**@⁠davemathews12** on GitHub · 2026-12-01 01:32 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4677) `davemathews12:fix/card-hash-before-snapshot` → `main` · +13 −2 · 1 files · 1 commits · closed without merging Refs #4544, Refs #4643 ## What it changes The card-copy sync (`host.rs`, the list that brings copies in the card's memory up to date) decides **twice** whether a copy has its hash buffer (`before`): 1. after the copies: `own.is_none() && before.is_some() && !ranges.is_empty()` pushes the copy's `COPY_DEST -> NON_PIXEL_SHADER_RESOURCE` transition; 2. in the hash pass: `shadow.card_before_gpu()` decides whether the copy is bound as a root SRV (`SetComputeRootShaderResourceView(1, shadow.buffer_gpu())`). The sending thread records this list while the submitting thread prepares the next submission, and `card_take_prepared` is where `before` is made (`card_make_before`), as the comment there says. A `before` made between the two reads leaves the copy in `COPY_DEST` and binds it as a root SRV. That is the debug-layer message in #4544 ("Resource state (0x400: COPY_DEST) (promoted from COMMON state) … is invalid for use as a root shader resource … Missing State: 0x40"), and the root-SRV messages in #4643's GBV run (3 of them). NVIDIA and AMD tolerate it; the Arc driver removes the device. The fix reads `before` once per copy, before `own.record` and the copy loop, and the hash pass uses that snapshot. `before` is a `OnceLock` (set once, never cleared), so every later read agrees whenever the snapshot saw it, and the transition is always pushed for a copy that is hashed. A copy that gets its `before` after the snapshot isn't hashed in this list. The submission that made it has it in `whole` and hashes all of it, as before. What it doesn't change: #4643's other messages (`CopyBufferRegion` reading a buffer in `COPY_DEST` where `COPY_SOURCE` was required, 116–249 of them) come from another path, which this doesn't touch. ## How it was tested - GPU and profile: none. I have no Windows machine, and this has **not been run in the game**. The race is found by reading the code, not reproduced. - Before: n/a. After: n/a. - For shader changes, the wave sizes tested: n/a (no shader change). - `cargo test` passed for the crates it touches: not run (the code is Windows-only). `cargo clippy -p victory-gpu --tests --target x86_64-pc-windows-msvc`: no errors and no new warnings, cross-checked from Linux. `cargo xtask policy --staged` passes. Asking Arc owners (@⁠marcelloveyugioh-wq, @⁠gilmarcs): with `VICTORY_D3D12_DEBUG=1` and card buffers on, does the "invalid for use as a root shader resource" message still appear with this change? ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches (#4544, #4643, "hash pass barrier", "COPY_DEST NON_PIXEL", "card copy hash state"). None changes this transition. Related: #945 (card copies' hashes in shared buffers, off by default, different code path). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The recording of a card-copy sync decided twice whether a copy has its
hash buffer (`before`): once for its COPY_DEST -> NON_PIXEL_SHADER_RESOURCE
transition after the copies, once for its hash pass. The submitting thread
makes `before` for the next submission (`card_take_prepared`) while the
sending thread records this one, so a `before` made between the two reads
left the copy in COPY_DEST and bound it as a root SRV. Intel's driver
removes the device for that; the debug layer reports "Resource state
(0x400: COPY_DEST) ... is invalid for use as a root shader resource".

`before` is now read once per copy before anything decides on it. It is
only ever set once, so every later read agrees when this one saw it; a
copy that gets one later is hashed whole by the submission that made it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 01:35:55 +00:00
Author
Owner

@⁠marcelloveyugioh-wq on GitHub · 2026-12-01 05:54 UTC · original

Tested #4678 on the Arc B580 (driver 32.0.101.9175). The message still appears, so this change doesn't fix it.

Setup: PR head c17489a, built with cargo build --profile diag -p victory --features diagnostics. Started with scripts\play-nvidia.ps1 -Build diag -SeriesS -Dlss off -NoMenu -More 'VICTORY_D3D12_DEBUG=1,VICTORY_LIBRARY_MAP=0'. Card buffers were on (no VICTORY_CARD_BUFFERS), TdrDelay 60, fresh cache and data dirs.

Result:

  • 3114 × Using SetComputeRootShaderResourceView … Resource state (0x400: D3D12_RESOURCE_STATE_COPY_DEST) (promoted from COMMON state) … is invalid for use as a root shader resource … Missing State: 0x40. All of them are COPY_DEST, the same as before the change.
  • The first one came ~7.5 min in (during the intro). They kept coming for ~2 min until the device was removed: relay: the device was lost before fence value 347232 was reached … 0x887A0006; debug layer: … DXGI_ERROR_DEVICE_HUNG.
  • At removal: the submitting thread was preparing a submission (nothing of ours was running on the card), of 27 lists, for 979.3 ms.

A guess, not verified: the message is reported at ExecuteCommandLists and says the state was promoted from COMMON. So the buffer seems to be promoted to COPY_DEST by a copy in an earlier list of the same ExecuteCommandLists call, and then bound as a root SRV in a later list of that call. Implicit promotion persists across lists within one call. The compare pass after the lists binds r.shadow.buffer / key.buf_gpu as root SRVs (host.rs ~8612–8666 at this commit), and I couldn't find a COPY_DEST → NON_PIXEL_SHADER_RESOURCE transition before it for copies that the title's own buffer copies wrote in that submission. If that compare list goes into the same ExecuteCommandLists as the lists that copied into the card copy, it would produce exactly this message, independent of the before race fixed here.

The full log (17 MB) is available if useful.

**@⁠marcelloveyugioh-wq** on GitHub · 2026-12-01 05:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4677#issuecomment-7302258365) Tested #4678 on the Arc B580 (driver 32.0.101.9175). The message **still appears**, so this change doesn't fix it. **Setup:** PR head `c17489a`, built with `cargo build --profile diag -p victory --features diagnostics`. Started with `scripts\play-nvidia.ps1 -Build diag -SeriesS -Dlss off -NoMenu -More 'VICTORY_D3D12_DEBUG=1,VICTORY_LIBRARY_MAP=0'`. Card buffers were on (no `VICTORY_CARD_BUFFERS`), TdrDelay 60, fresh cache and data dirs. **Result:** - 3114 × `Using SetComputeRootShaderResourceView … Resource state (0x400: D3D12_RESOURCE_STATE_COPY_DEST) (promoted from COMMON state) … is invalid for use as a root shader resource … Missing State: 0x40`. All of them are `COPY_DEST`, the same as before the change. - The first one came ~7.5 min in (during the intro). They kept coming for ~2 min until the device was removed: `relay: the device was lost before fence value 347232 was reached … 0x887A0006; debug layer: … DXGI_ERROR_DEVICE_HUNG`. - At removal: `the submitting thread was preparing a submission (nothing of ours was running on the card), of 27 lists, for 979.3 ms`. **A guess, not verified:** the message is reported at `ExecuteCommandLists` and says the state was *promoted from COMMON*. So the buffer seems to be promoted to `COPY_DEST` by a copy in an earlier list of the same `ExecuteCommandLists` call, and then bound as a root SRV in a later list of that call. Implicit promotion persists across lists within one call. The compare pass after the lists binds `r.shadow.buffer` / `key.buf_gpu` as root SRVs (host.rs ~8612–8666 at this commit), and I couldn't find a `COPY_DEST → NON_PIXEL_SHADER_RESOURCE` transition before it for copies that the title's own buffer copies wrote in that submission. If that compare list goes into the same `ExecuteCommandLists` as the lists that copied into the card copy, it would produce exactly this message, independent of the `before` race fixed here. The full log (17 MB) is available if useful.
github-bot closed this pull request 2026-12-01 12:37:47 +00:00
Author
Owner

@⁠davemathews12 on GitHub · 2026-12-01 12:37 UTC · original

Closing: #3881 (JSa25) made the same change first, and I missed it when I searched. marcelloveyugioh-wq's Arc run shows this change doesn't stop the messages anyway: the compare is sent in the same ExecuteCommandLists call as the title's lists, so a copy they promoted to COPY_DEST is still in it. That fix was merged as #1 and lost in the foxhound merge (4db42779). It's back in the new PR from fix/compare-own-execute. Thanks @⁠marcelloveyugioh-wq for the test.

**@⁠davemathews12** on GitHub · 2026-12-01 12:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4677#issuecomment-7311405874) Closing: #3881 (JSa25) made the same change first, and I missed it when I searched. marcelloveyugioh-wq's Arc run shows this change doesn't stop the messages anyway: the compare is sent in the same ExecuteCommandLists call as the title's lists, so a copy they promoted to COPY_DEST is still in it. That fix was merged as #1 and lost in the foxhound merge (4db42779). It's back in the new PR from fix/compare-own-execute. Thanks @⁠marcelloveyugioh-wq for the test.

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