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

Open
BE29ZZ wants to merge 1 commit from upstream-pr/194 into main
BE29ZZ commented 2026-11-27 19:31:19 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by BE29ZZ on 2026-11-27T19:31:19Z.


### 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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532080802 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194). Originally posted by [BE29ZZ](https://github.com/BE29ZZ) on 2026-11-27T19:31:19Z. --- ### 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.
1tsethan commented 2026-11-27 23:01:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 1tsethan on 2026-11-27T23:01:09Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229805019 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194#issuecomment-7229805019). Originally posted by [1tsethan](https://github.com/1tsethan) on 2026-11-27T23:01:09Z. --- 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 -->
kibagami-nc commented 2026-11-28 05:23:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T05:23:13Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7234636917 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/194#issuecomment-7234636917). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T05:23:13Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/194:upstream-pr/194'
git switch 'upstream-pr/194'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/194'
git switch 'upstream-pr/194'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/194'
git switch 'upstream-pr/194'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/194'
git switch 'main'
git merge --squash 'upstream-pr/194'
git switch 'main'
git merge --ff-only 'upstream-pr/194'
git switch 'main'
git merge 'upstream-pr/194'
git push origin 'main'
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!194
No description provided.