gpu(draw): keep depth-read and mirror shader-read states valid for D3D12 #4512

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

@⁠gnostic-snakes on GitHub · 2026-11-30 21:39 UTC · original
gnostic-snakes:fix/d3d12-depth-read-and-mirror-state → main · +983 −861 · 32 files · 14 commits · closed without merging

Fixes two D3D12 debug layer message 538 resource-state mismatches observed during a 40-minute diagnostics run with VICTORY_D3D12_DEBUG=1:

1. DrawInstanced: depth buffer left in

**@⁠gnostic-snakes** on GitHub · 2026-11-30 21:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4511) `gnostic-snakes:fix/d3d12-depth-read-and-mirror-state` → `main` · +983 −861 · 32 files · 14 commits · closed without merging Fixes two D3D12 debug layer message 538 resource-state mismatches observed during a 40-minute diagnostics run with VICTORY_D3D12_DEBUG=1: ### 1. DrawInstanced: depth buffer left in
Fixes two D3D12 debug layer message 538 state mismatches observed in a
40-minute diagnostics run with VICTORY_D3D12_DEBUG=1:

1. DrawInstanced missing DEPTH_READ (0x20) on depth targets left in
   NON_PIXEL|PIXEL_SHADER_RESOURCE (0xC0) (1,123,479 occurrences):
   - Always call list::ensure_state for self.depth in State::prepare_for
     instead of gating on State::last_depth_state (HostList::transition
     already skips no-op barriers, while compute dispatches or other
     passes on the same list can move self.depth to 0xC0 without
     clearing last_depth_state).
   - Set TESTED_DEPTH before early_textures in State::bind, and clear
     targets_synced and last_depth_state on compute dispatches so bound
     targets are re-synced on the next graphics draw.

2. SetGraphicsRootDescriptorTable missing NON_PIXEL_SHADER_RESOURCE
   (0x40) after State::mirror_light (267 occurrences):
   - Transition colour to SHADER_RESOURCE (0xC0) instead of
     PIXEL_SHADER_RESOURCE (0x80), matching the all-stage
     DATA_STATIC_WHILE_SET_AT_EXECUTE graphics root descriptor tables.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 21:40:39 +00:00
Author
Owner

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

Overlaps with #4549, which removes the same last_depth_state gate in prepare_targets (and adds a native regression for it), so the two will conflict. The mirror_light change here (0x80 -> 0xC0) is not in #4549 and is worth keeping whichever goes in.

Two points on this version:

  • With the gate removed, State::last_depth_state is written (here, in the compute branch, and at the resets) but never read outside #[cfg(test)] code. That should become a field is never read warning under -D warnings, currently hidden behind main's existing dead-code errors. Either keep the gate and rely on the new last_depth_state = 0 after a dispatch (that alone fixes the dispatch case), or drop the field.
  • self.targets_synced = false after every dispatch re-runs ensure_state for every bound target on the next draw. That is correct, just more work per compute-to-draw switch on the recording threads. It is worth choosing one approach (cache plus invalidation, or always ask the tracker) for both depth and targets.
**@⁠IRennie74** on GitHub · 2026-11-30 22:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4511#issuecomment-7294126703) Overlaps with #4549, which removes the same `last_depth_state` gate in `prepare_targets` (and adds a native regression for it), so the two will conflict. The `mirror_light` change here (0x80 -> 0xC0) is not in #4549 and is worth keeping whichever goes in. Two points on this version: - With the gate removed, `State::last_depth_state` is written (here, in the compute branch, and at the resets) but never read outside `#[cfg(test)]` code. That should become a `field is never read` warning under `-D warnings`, currently hidden behind main's existing dead-code errors. Either keep the gate and rely on the new `last_depth_state = 0` after a dispatch (that alone fixes the dispatch case), or drop the field. - `self.targets_synced = false` after every dispatch re-runs `ensure_state` for every bound target on the next draw. That is correct, just more work per compute-to-draw switch on the recording threads. It is worth choosing one approach (cache plus invalidation, or always ask the tracker) for both depth and targets.
Author
Owner

@⁠gnostic-snakes on GitHub · 2026-11-30 23:13 UTC · original

Verified live with a 17-minute gameplay run (diag build with VICTORY_D3D12_DEBUG=1):

D3D12 id=538 validation error Before After
DrawInstanced missing DEPTH_READ (0x20) 1,123,479 0
SetGraphicsRootDescriptorTable
**@⁠gnostic-snakes** on GitHub · 2026-11-30 23:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4511#issuecomment-7294871248) Verified live with a 17-minute gameplay run (diag build with VICTORY_D3D12_DEBUG=1): | D3D12 id=538 validation error | Before | After | |---|---|---| | DrawInstanced missing DEPTH_READ (0x20) | 1,123,479 | **0** | | SetGraphicsRootDescriptorTable
github-bot closed this pull request 2026-12-01 18:43:13 +00:00
Author
Owner

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