fix(gpu): track direct buffer states in HostList and restore COPY_DEST to COMMON in place_copy #194

Open
github-bot wants to merge 1 commit from github-bot/gh-194 into main AGit
Owner

@⁠BE29ZZ on GitHub · 2026-11-27 19:31 UTC · original
BE29ZZ:fix/hostlist-buffer-states → main · +836 −25 · 5 files · 1 commits · open

### Problem
\HostList::place_copy\ (\crates/victory-gpu/src/host/place.rs) runs \CopyBufferRegion\ directly into a destination \Shadow::buffer, implicitly promoting it from \COMMON\ to \COPY_DEST, and never transitions it back to \COMMON. Because D3D12 buffers only decay back to \COMMON\ at the end of \ExecuteCommandLists:

  1. Any later direct root SRV/CBV/UAV in the same list — or \card_before()'s \plan.check\ compute compare pass appended to the same \ExecuteCommandLists\ batch — triggers D3D12 Debug Layer Error ID 538 (\Resource state (0x400: COPY_DEST) (promoted from COMMON state) ... is invalid for use as a root shader resource) and can trigger device removal on strict NVIDIA/AMD drivers.
  2. Conversely, if a shadow buffer was already implicitly promoted to a read state earlier in the same list (or in an earlier list of the same \ExecuteCommandLists\ batch), \place_copy\ cannot legally implicitly promote it to \COPY_DEST\ without an explicit transition from its exact promoted read mask.
  3. In the same-buffer copy path (\ rom == to), reading as \COPY_SOURCE\ then writing as \COPY_DEST\ requires an explicit \COPY_SOURCE -> COPY_DEST\ transition and a trailing \COPY_DEST -> COMMON\ transition.

What changed

  • Per-list direct buffer state tracking (\crates/victory-gpu/src/host/buffers.rs):
    • Pure \Track\ state machine modeling D3D12 buffer implicit read-promotion masks, exclusive write states (\COPY_DEST, \UNORDERED_ACCESS), and
      eset_to_common.
    • Cross-list \LiveState\ / \LiveBuffers\ tracking across lists in the same \ExecuteCommandLists\ call (cleared at every \ExecuteCommandLists\ boundary where D3D12 decays buffers back to \COMMON).
  • In-place copies (\crates/victory-gpu/src/host/place.rs):
    • \HostList::place_copy\ and \HostList::place_source\ emit exact \StateBefore\ transitions when a buffer was previously promoted, handle same-buffer \COPY_SOURCE -> COPY_DEST -> COMMON, and restore copied shadow buffers to \COMMON\ afterwards.
    • Pre-allocates the \etween\ buffer before \ o.refresh\ / \wait_for_all\ so early failure leaves no partial side effects.
  • Submission & direct-bind integration (\crates/victory-gpu/src/host.rs, \draw.rs, \indirect.rs):
    • \HostList::prelude\ emits cross-list -> COMMON\ buffer handoff barriers when an earlier list in the same \ExecuteCommandLists\ batch left a buffer non-common.
    • \Host::card_before\ appends any required -> NON_PIXEL_SHADER_RESOURCE\ barrier to \plan.check's prologue barrier batch.
    • \draw.rs\ (vertex buffers, index buffers, direct root CBV/SRV/UAV) and \indirect.rs\ (\clamp_into, \open_batch) record direct buffer promotions on \HostList.
  • Tests:
    • 5 unit tests in \host::buffers::tests\ covering single-list, same-buffer, read-before-copy, cross-list prelude bridging, and direct root UAV -> \plan.check\ bridging.
    • Live GPU test \host::place::tests::place_copy_restores_buffer_to_common_and_runs_cleanly\ executing all paths and cross-list handoffs on real D3D12 hardware.
    • Ignored D3D12 Debug Layer regression test \host::place::tests::copies_in_place_leave_their_buffers_to_root_views\ (co-authored with @⁠MamaLeVrai), covering 5 cases in both PC memory (256 KiB) and card memory (8 MiB).

Prior independent D3D12 Debug Layer validation

On the identical Belobug implementation before repo takedown, @⁠MamaLeVrai validated with \VICTORY_D3D12_DEBUG=1 --features diagnostics\ on an RX 6950 XT (Windows 11 26300, release):

  • Base: 7 of 8 cases emitted D3D12 Debug Layer errors (including ID 538).
  • With this fix: 0 messages across all 8 cases (and \plan.check\ ran cleanly in every card-memory case).

Local verification on \main\ (\cef07e) — Windows 11 x64, NVIDIA GeForce RTX 3060, Rust 1.98.1

  • Clippy (default and --all-features): 0 warnings/errors in modified code.
  • \cargo test -p victory-gpu --lib --locked -- host::buffers:: host::place::tests::place_copy_restores: 6 passed, 0 failed.
  • \cargo test -p victory-gpu --lib --all-features --locked -- host::buffers:: host::place::tests::place_copy_restores: 6 passed, 0 failed.
  • \VICTORY_INDIRECT_REST=1 cargo test -p victory-gpu --lib --locked -- --test-threads=1: 426 passed, 0 failed (36 ignored).
  • \cargo test -p xtask --locked: 6 passed, 0 failed (
    epository_passes_policy\ clean).

Not tested with \VICTORY_D3D12_DEBUG=1\ locally (Graphics Tools optional feature not installed on this PC) or in the title itself (no game files here).

AI-assisted; no game data.

**@⁠BE29ZZ** on GitHub · 2026-11-27 19:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194) `BE29ZZ:fix/hostlist-buffer-states` → `main` · +836 −25 · 5 files · 1 commits · open ### Problem \HostList::place_copy\ (\crates/victory-gpu/src/host/place.rs\) runs \CopyBufferRegion\ directly into a destination \Shadow::buffer\, implicitly promoting it from \COMMON\ to \COPY_DEST\, and never transitions it back to \COMMON\. Because D3D12 buffers only decay back to \COMMON\ at the end of \ExecuteCommandLists\: 1. Any later direct root SRV/CBV/UAV in the same list — or \card_before()\'s \plan.check\ compute compare pass appended to the same \ExecuteCommandLists\ batch — triggers **D3D12 Debug Layer Error ID 538** (\Resource state (0x400: COPY_DEST) (promoted from COMMON state) ... is invalid for use as a root shader resource\) and can trigger device removal on strict NVIDIA/AMD drivers. 2. Conversely, if a shadow buffer was already implicitly promoted to a read state earlier in the same list (or in an earlier list of the same \ExecuteCommandLists\ batch), \place_copy\ cannot legally implicitly promote it to \COPY_DEST\ without an explicit transition from its exact promoted read mask. 3. In the same-buffer copy path (\ rom == to\), reading as \COPY_SOURCE\ then writing as \COPY_DEST\ requires an explicit \COPY_SOURCE -> COPY_DEST\ transition and a trailing \COPY_DEST -> COMMON\ transition. ### What changed - **Per-list direct buffer state tracking (\crates/victory-gpu/src/host/buffers.rs\):** - Pure \Track\ state machine modeling D3D12 buffer implicit read-promotion masks, exclusive write states (\COPY_DEST\, \UNORDERED_ACCESS\), and \ eset_to_common\. - Cross-list \LiveState\ / \LiveBuffers\ tracking across lists in the same \ExecuteCommandLists\ call (cleared at every \ExecuteCommandLists\ boundary where D3D12 decays buffers back to \COMMON\). - **In-place copies (\crates/victory-gpu/src/host/place.rs\):** - \HostList::place_copy\ and \HostList::place_source\ emit exact \StateBefore\ transitions when a buffer was previously promoted, handle same-buffer \COPY_SOURCE -> COPY_DEST -> COMMON\, and restore copied shadow buffers to \COMMON\ afterwards. - Pre-allocates the \etween\ buffer before \ o.refresh\ / \wait_for_all\ so early failure leaves no partial side effects. - **Submission & direct-bind integration (\crates/victory-gpu/src/host.rs\, \draw.rs\, \indirect.rs\):** - \HostList::prelude\ emits cross-list \-> COMMON\ buffer handoff barriers when an earlier list in the same \ExecuteCommandLists\ batch left a buffer non-common. - \Host::card_before\ appends any required \-> NON_PIXEL_SHADER_RESOURCE\ barrier to \plan.check\'s prologue barrier batch. - \draw.rs\ (vertex buffers, index buffers, direct root CBV/SRV/UAV) and \indirect.rs\ (\clamp_into\, \open_batch\) record direct buffer promotions on \HostList\. - **Tests:** - 5 unit tests in \host::buffers::tests\ covering single-list, same-buffer, read-before-copy, cross-list prelude bridging, and direct root UAV -> \plan.check\ bridging. - Live GPU test \host::place::tests::place_copy_restores_buffer_to_common_and_runs_cleanly\ executing all paths and cross-list handoffs on real D3D12 hardware. - Ignored D3D12 Debug Layer regression test \host::place::tests::copies_in_place_leave_their_buffers_to_root_views\ (co-authored with @⁠MamaLeVrai), covering 5 cases in both PC memory (256 KiB) and card memory (8 MiB). ### Prior independent D3D12 Debug Layer validation On the identical Belobug implementation before repo takedown, @⁠MamaLeVrai validated with \VICTORY_D3D12_DEBUG=1 --features diagnostics\ on an RX 6950 XT (Windows 11 26300, release): - **Base:** **7 of 8** cases emitted D3D12 Debug Layer errors (including ID 538). - **With this fix:** **0 messages across all 8 cases** (and \plan.check\ ran cleanly in every card-memory case). ### Local verification on \main\ (\cef07e\) — Windows 11 x64, NVIDIA GeForce RTX 3060, Rust 1.98.1 - Clippy (default and \--all-features\): **0 warnings/errors** in modified code. - \cargo test -p victory-gpu --lib --locked -- host::buffers:: host::place::tests::place_copy_restores\: **6 passed, 0 failed**. - \cargo test -p victory-gpu --lib --all-features --locked -- host::buffers:: host::place::tests::place_copy_restores\: **6 passed, 0 failed**. - \VICTORY_INDIRECT_REST=1 cargo test -p victory-gpu --lib --locked -- --test-threads=1\: **426 passed, 0 failed** (36 ignored). - \cargo test -p xtask --locked\: **6 passed, 0 failed** (\ epository_passes_policy\ clean). Not tested with \VICTORY_D3D12_DEBUG=1\ locally (Graphics Tools optional feature not installed on this PC) or in the title itself (no game files here). AI-assisted; no game data.
HostList::place_copy implicitly promoted destination shadow buffers from COMMON to COPY_DEST without transitioning them back to COMMON. Within a single ExecuteCommandLists call, any subsequent root SRV/CBV/UAV (or card_before's plan.check compare dispatch) accessing that buffer triggered D3D12 Debug Layer error ID 538 (invalid resource state COPY_DEST for root view) and risked GPU device loss on strict drivers. Conversely, a buffer promoted to a read state earlier in the same list (or an earlier list of the same ExecuteCommandLists batch) could not legally implicitly promote to COPY_DEST.

- Add per-HostList direct buffer state tracking (crates/victory-gpu/src/host/buffers.rs) modeling D3D12 implicit read-promotion masks, exclusive write states, and cross-list ExecuteCommandLists batch decay.
- Update HostList::place_copy and HostList::place_source (crates/victory-gpu/src/host/place.rs) to emit exact pre-transitions from promoted states, handle same-buffer COPY_SOURCE -> COPY_DEST -> COMMON cleanly, and restore copied shadow buffers to COMMON afterwards.
- Wire cross-list prelude -> COMMON handoffs and card_before/plan.check barriers in Host::execute (crates/victory-gpu/src/host.rs), plus direct buffer state recording in draw.rs (vertex, index, direct root CBV/SRV/UAV) and indirect.rs (clamp_into, open_batch).
- Add 5 unit tests in host::buffers::tests, an RTX 3060 GPU test in host::place::tests, and an ignored D3D12 debug-layer regression test covering all 5 copy/read/compare cases in both host and card memory.

Co-authored-by: MamaLeVrai <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:35:25 +00:00
Author
Owner

@⁠1tsethan on GitHub · 2026-11-27 23:01 UTC · original

Independent Windows validation of PR #194.

Tested commit: 55e08da430c2ae45f03d3498ccbe1b0a17dfdc11.

cargo test --locked -p victory-gpu host::buffers -- --nocapture --test-threads=1

Exit: 0.

  • test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 457 filtered out; finished in 0.00s

Coverage here is the buffer-state unit suite. The Windows debug layer is not installed, so this is not debug-layer or gameplay validation.

Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result.

**@⁠1tsethan** on GitHub · 2026-11-27 23:01 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194#issuecomment-7229805019) Independent Windows validation of PR #194. Tested commit: `55e08da430c2ae45f03d3498ccbe1b0a17dfdc11`. `cargo test --locked -p victory-gpu host::buffers -- --nocapture --test-threads=1` Exit: **0**. - test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 457 filtered out; finished in 0.00s Coverage here is the buffer-state unit suite. The Windows debug layer is not installed, so this is not debug-layer or gameplay validation. Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result. <!-- victory-native-validation-20261128 -->
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 05:23 UTC · original

Independent debug-layer check of this PR's place_copy part, on current main (63b902f).

Setup: RTX 5070 Ti, diagnostics build, VICTORY_D3D12_DEBUG=1, run as the tests ask (VICTORY_RELAY=2 VICTORY_RELAY_COPY=1, each test in a process of its own).

The existing ignored tests of copies in place already hit these errors, but cannot see them. Every landing moves the debug layer's messages into the log (Host::log_messages), so copy_draw_copy_draw's check at its end finds nothing, and the three copies_stand_where_the_list_has_them_* tests do not look at all. I counted the errors moved into the log with a test-only counter in log_messages:

Test main Restores only
copy_draw_copy_draw 11 (8 × 538, 3 × 527) 0
..._on_the_card 1,139 0
..._mixed 1,030 0
..._in_pc_memory 966 0

"Restores only" means just the COMMON restores in place_copy and place_source. In all four tests, what the draws read and what title memory and the card hold are unchanged.

So on today's main, the restore part alone clears these four. Your tracker also covers a host copy read through a root view before the copy, which the restores alone would report once as 527.

This PR conflicts with main now. If a smaller step would help meanwhile, the patch I measured is kibagami-nc/VIctory-NVIDIA@5bda8ffaa8 (+42/-9): the restores, the test counter, and asserts in the four tests. I won't open it as a separate PR unless you'd rather I did.

**@⁠kibagami-nc** on GitHub · 2026-11-28 05:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194#issuecomment-7234636917) Independent debug-layer check of this PR's `place_copy` part, on current `main` (`63b902f`). Setup: RTX 5070 Ti, diagnostics build, `VICTORY_D3D12_DEBUG=1`, run as the tests ask (`VICTORY_RELAY=2 VICTORY_RELAY_COPY=1`, each test in a process of its own). The existing ignored tests of copies in place already hit these errors, but cannot see them. Every landing moves the debug layer's messages into the log (`Host::log_messages`), so `copy_draw_copy_draw`'s check at its end finds nothing, and the three `copies_stand_where_the_list_has_them_*` tests do not look at all. I counted the errors moved into the log with a test-only counter in `log_messages`: | Test | `main` | Restores only | |---|---:|---:| | `copy_draw_copy_draw` | 11 (8 × 538, 3 × 527) | 0 | | `..._on_the_card` | 1,139 | 0 | | `..._mixed` | 1,030 | 0 | | `..._in_pc_memory` | 966 | 0 | "Restores only" means just the `COMMON` restores in `place_copy` and `place_source`. In all four tests, what the draws read and what title memory and the card hold are unchanged. So on today's `main`, the restore part alone clears these four. Your tracker also covers a host copy read through a root view before the copy, which the restores alone would report once as 527. This PR conflicts with `main` now. If a smaller step would help meanwhile, the patch I measured is kibagami-nc/VIctory-NVIDIA@5bda8ffaa87c77cf077e551840a22ed80f0e0f35 (+42/-9): the restores, the test counter, and asserts in the four tests. I won't open it as a separate PR unless you'd rather I did.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
  • crates/victory-gpu/src/host/place.rs
  • crates/victory-gpu/src/indirect.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/194/head:github-bot/gh-194'
git switch 'github-bot/gh-194'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-194'
git switch 'github-bot/gh-194'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-194'
git switch 'github-bot/gh-194'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-194'
git switch 'main'
git merge --squash 'github-bot/gh-194'
git switch 'main'
git merge --ff-only 'github-bot/gh-194'
git switch 'main'
git merge 'github-bot/gh-194'
git push origin 'main'
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!194
No description provided.