GPU: revalidate bound depth state after compute reads #4549

Closed
github-bot wants to merge 14 commits from github-bot/gh-4548 into main AGit
Owner

@⁠d8ahazard on GitHub · 2026-11-30 22:17 UTC · original
d8ahazard:codex/depth-state-transition → main · +1185 −852 · 35 files · 14 commits · closed without merging

What it changes

An intervening compute SRV, copy, or internal pass can change a bound depth texture's state without changing the DSV. The next graphics draw currently skips its transition when its desired state equals State::last_depth_state, even though that cache no longer describes the resource. This leaves a read-only depth draw using a texture in shader-read state and produces D3D12 message 538.

Always revalidate the computed depth state through the command list's existing tracker, which already deduplicates actual no-op transitions. Preserve the combined DEPTH_READ | SHADER_RESOURCE state for a draw that also samples its depth texture. Depth preparation is factored into a private method so the regression exercises the production path.

The opt-in native regression uses authored 4×4 resources and shaders. It covers read-only depth → compute SRV → the same read-only depth, simultaneous depth/SRV reads, and a writable-depth control. It checks the actual compute result, 16 rasterized samples, depth readback, device completion, and the debug InfoQueue. A separate legacy-gate control reproduces the validation error while recording and never submits the invalid command list. The test-only victory-core dependency keeps its output outside the repository.

How it was tested

  • GPU/profile: Windows, NVIDIA RTX PRO 5000 Blackwell; Series X, native 2560×1440, DLAA, 2× DLSS frame generation. The game's RT passes without a structure builder remain omitted.

  • Before: the legacy desired-state gate reproduces D3D12 error 538 while recording; that invalid command list is never submitted.

  • After: the corrected native controls return the expected GPU values with zero error-level debug messages.

  • Shader wave sizes: not applicable; no shader or translator change.

  • Native D3D12 regression and legacy control pass with the device LUID matched to its DXGI hardware adapter. All three corrected controls return the expected GPU values with zero error-level debug messages.

  • cargo check --workspace --all-targets --all-features --locked passes.

  • All 14 draw::tests pass.

  • Staged asset policy passes for all five changed files; git diff --cached --check passes.

  • An optimized local integration build completed a 15-minute in-world smoke check at native 1440p with DLAA and 2× DLSS frame generation, including character appearance and wardrobe operations, and remained responsive. The clean PR source was separately validated with the native regression.

Strict workspace Clippy remains blocked by inherited Lowered::loop_caps / Shadow::ranged dead-code errors and the existing seed % 3 test lint in host.rs. Whole-tree policy reports the unchanged 560-character run in victory-shader/src/native.rs. These are outside this change; no lint or policy is suppressed. The full touched-crate/workspace test suites were not rerun; the selected draw tests and native regression are the completed test coverage.

Checked for overlap

  • Searched open pull requests for the issue and touched files. #3572 proposes the same authoritative-tracker approach, and #4016 includes a broader depth/state repair. This focused alternative adds the self-contained native regression and fresh validation. If another production fix lands first, the regression can be retained independently.
**@⁠d8ahazard** on GitHub · 2026-11-30 22:17 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4548) `d8ahazard:codex/depth-state-transition` → `main` · +1185 −852 · 35 files · 14 commits · closed without merging ## What it changes An intervening compute SRV, copy, or internal pass can change a bound depth texture's state without changing the DSV. The next graphics draw currently skips its transition when its desired state equals `State::last_depth_state`, even though that cache no longer describes the resource. This leaves a read-only depth draw using a texture in shader-read state and produces D3D12 message 538. Always revalidate the computed depth state through the command list's existing tracker, which already deduplicates actual no-op transitions. Preserve the combined `DEPTH_READ | SHADER_RESOURCE` state for a draw that also samples its depth texture. Depth preparation is factored into a private method so the regression exercises the production path. The opt-in native regression uses authored 4×4 resources and shaders. It covers read-only depth → compute SRV → the same read-only depth, simultaneous depth/SRV reads, and a writable-depth control. It checks the actual compute result, 16 rasterized samples, depth readback, device completion, and the debug InfoQueue. A separate legacy-gate control reproduces the validation error while recording and never submits the invalid command list. The test-only `victory-core` dependency keeps its output outside the repository. ## How it was tested - GPU/profile: Windows, NVIDIA RTX PRO 5000 Blackwell; Series X, native 2560×1440, DLAA, 2× DLSS frame generation. The game's RT passes without a structure builder remain omitted. - Before: the legacy desired-state gate reproduces D3D12 error 538 while recording; that invalid command list is never submitted. - After: the corrected native controls return the expected GPU values with zero error-level debug messages. - Shader wave sizes: not applicable; no shader or translator change. - Native D3D12 regression and legacy control pass with the device LUID matched to its DXGI hardware adapter. All three corrected controls return the expected GPU values with zero error-level debug messages. - `cargo check --workspace --all-targets --all-features --locked` passes. - All 14 `draw::tests` pass. - Staged asset policy passes for all five changed files; `git diff --cached --check` passes. - An optimized local integration build completed a 15-minute in-world smoke check at native 1440p with DLAA and 2× DLSS frame generation, including character appearance and wardrobe operations, and remained responsive. The clean PR source was separately validated with the native regression. Strict workspace Clippy remains blocked by inherited `Lowered::loop_caps` / `Shadow::ranged` dead-code errors and the existing `seed % 3` test lint in `host.rs`. Whole-tree policy reports the unchanged 560-character run in `victory-shader/src/native.rs`. These are outside this change; no lint or policy is suppressed. The full touched-crate/workspace test suites were not rerun; the selected draw tests and native regression are the completed test coverage. ## Checked for overlap - [x] Searched open pull requests for the issue and touched files. #3572 proposes the same authoritative-tracker approach, and #4016 includes a broader depth/state repair. This focused alternative adds the self-contained native regression and fresh validation. If another production fix lands first, the regression can be retained independently.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 22:19:14 +00:00
Author
Owner

@⁠IRennie74 on GitHub · 2026-11-30 22:39 UTC · original

This and #4512 change the same lines in State::prepare_targets (the last_depth_state gate), so only one of them can go in as is. #4512 also fixes mirror_light (colour moved to 0xC0, not 0x80), which this PR does not touch and which would be worth carrying over.

With the gate gone, State::last_depth_state (draw.rs:676 on main) is only ever written outside tests: the gate was its one read in the library, and the remaining reads are in #[cfg(test)] code. That should give a new field is never read warning in the non-test build, which -D warnings turns into an error. It is hidden for now by the dead-code errors already on main. Either drop the field (and its resets at the reset/set_* sites) or keep it as the cache below.

On cost: dropping the gate means one ensure_state per draw with a depth target (a host_copy lookup plus the list's states mutex) even when nothing changed. That runs on the list-recording threads, not the submitting thread. Still, on a 6-core CPU (Ryzen 5 5600X, RTX 3060) the submit head waits about 6 ms a frame for lists still being recorded, at 4,500-5,000 draws a frame. The extra cost is probably small next to the rest of a draw. A cheaper equivalent would keep the gate and clear last_depth_state wherever a dispatch, copy or internal pass on the same list can move self.depth, as #4512 already does for dispatches.

**@⁠IRennie74** on GitHub · 2026-11-30 22:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4548#issuecomment-7294131263) This and #4512 change the same lines in `State::prepare_targets` (the `last_depth_state` gate), so only one of them can go in as is. #4512 also fixes `mirror_light` (`colour` moved to 0xC0, not 0x80), which this PR does not touch and which would be worth carrying over. With the gate gone, `State::last_depth_state` (draw.rs:676 on main) is only ever written outside tests: the gate was its one read in the library, and the remaining reads are in `#[cfg(test)]` code. That should give a new `field is never read` warning in the non-test build, which `-D warnings` turns into an error. It is hidden for now by the dead-code errors already on main. Either drop the field (and its resets at the `reset`/`set_*` sites) or keep it as the cache below. On cost: dropping the gate means one `ensure_state` per draw with a depth target (a `host_copy` lookup plus the list's `states` mutex) even when nothing changed. That runs on the list-recording threads, not the submitting thread. Still, on a 6-core CPU (Ryzen 5 5600X, RTX 3060) the submit head waits about 6 ms a frame for lists still being recorded, at 4,500-5,000 draws a frame. The extra cost is probably small next to the rest of a draw. A cheaper equivalent would keep the gate and clear `last_depth_state` wherever a dispatch, copy or internal pass on the same list can move `self.depth`, as #4512 already does for dispatches.
github-bot closed this pull request 2026-12-01 18:43:07 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:37 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:37 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4548#issuecomment-7321247826) 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!4549
No description provided.