Skip to content

Repair GPU lifetimes, state transitions and external-pass bindings - #4016

Open
deama wants to merge 1 commit into
trustno1-coder:mainfrom
deama:codex/gpu-stability-fixes
Open

deama wants to merge 1 commit into
trustno1-coder:mainfrom
deama:codex/gpu-stability-fixes

Conversation

@deama

@deama deama commented Nov 30, 2026

Copy link
Copy Markdown

What it changes

Several command sequences could leave stale shader inputs or invalid D3D12 resource states, and a failed fence wait could authorize CPU landing/recycling before GPU completion. This PR bundles the verified correctness repairs from that investigation, with synthetic regressions and explicit software-only validation support.

The most recent reproducer concerns external passes: a callback can bind its own pipeline and static depth SRV, then report failure. Previously run_external restored the title's cached state only on success. The next title dispatch could therefore run with the external pass's bindings after depth had changed, producing SDK message 1003 (DATA_STATIC_WHILE_SET_AT_EXECUTE). The real handoff/binding path reproduces that error on WARP; after this change, it runs the intended title shader and returns the expected value without validation errors.

This is a correctness/stability PR. It makes no FPS-gain claim and does not reduce resolution, scene detail, shader calculations or rendering passes. Unproven performance experiments, local launch profiles, checkpoint tooling and machine-specific investigation notes are not included.

1. Recording ownership across command-list cuts

  • Introduce State::next_part for a new host recording, distinct from restoring bindings on the same recording.
  • Invalidate recording-local constant tables, root-view caches and tails when a list is cut at a wait/value boundary. A COM reference alone does not stop a prior part's scratch bytes from being recycled.
  • Preserve dynamic/shared descriptor ownership through the final part.
  • The regression deliberately recycles the preceding scratch and checks that the later shader still reads its original constant, rather than the poison value.

2. Fence completion checks and regression coverage

  • Preserve the strict HRESULT/wait/completion checks that have now landed in the latest upstream: UINT64_MAX means removal, and only a real completed value at least equal to the target authorizes landing/recycling.
  • Factor the wait-result check into a tested helper, including proof that a failed wait does not query the driver again.
  • Cover failed waits, signalled-but-unfinished work, removed devices and successful completion. Software replay also rejects removal before continuing. The safeguards already in the new base are not presented as new fixes by this PR.

3. Depth and placed-copy state transitions

  • Remove reliance on the draw-local depth-state cache when other operations can change the same resource. Revalidate through the command list's authoritative tracker.
  • Preserve compatible depth-read and shader-read bits; do not collapse a valid read combination into an incompatible state.
  • Restore placed-copy destinations and sources for subsequent uses. Source restoration accounts for accumulated CBV/SRV/COPY_SOURCE read promotions instead of assuming COPY_SOURCE was the only read state.
  • For overlapping same-resource copies, transition both the original and intermediate buffers when their source/destination roles reverse.
  • Regressions cover a shader read between depth draws, combined-read copy sources followed by overwrites, and constant copies consuming earlier copy results.

4. Bounded snapshot allocation

  • Do not round a request just over 2 GiB up to a rejected 4 GiB CPU-visible buffer. Large snapshot capacities grow in checked 64 KiB steps.
  • Reject a size that cannot be represented safely; do not silently fall through to a submission using mutable, unsnapshotted bytes.
  • Bound the existing optional CPU-mapped VRAM staging path to 64 MiB per buffer. Larger snapshots keep their full CPU-upload fallback data, and an oversized fallback cannot absorb later small mapped-VRAM requests from the spare pool.
  • Derive the upload address ceiling from the shader directory's MEMORY_PAGES, excluding its null-sink page. This does not enlarge upstream's shader directory. A local wider-directory build exposed the drift; the regression exercises a synthetic larger ceiling with virtual reservation only, while production retains upstream's actual limit.

5. Mutable depth and external-pass recovery

  • Mark the ambient helper's depth SRV as both descriptor-volatile and data-volatile. Descriptor volatility alone still implies static SRV data under root signature 1.1.
  • Always restore title bindings after an external callback, irrespective of its completion result. Failure does not imply that no bindings changed.
  • The ambient test checks the compiled contract and updated-depth reads. The external-pass test independently reproduces SDK 1003 before software submission, then verifies the repaired dispatch's actual output.

6. Fail-closed diagnostics

  • Add the gpu-validation feature for the debug layer, explicit WARP selection and light/fault-only DRED without full per-draw profiling overhead.
  • VICTORY_D3D12_ERROR_ABORT=1 requires an available debug layer and stops further submission after an API error.
  • VICTORY_D3D12_ERROR_BREAK=1, paired with VICTORY_FATAL_BREAKPOINT=1, reports the SDK message and original calling stack and terminates at the offending recording call. Agility 614 raises a DXGI diagnostic exception (0x87a) for this mode; bounded kernel reads protect the exception reporter from invalid message pointers.
  • Add explicit replay --warp selection with no hardware fallback, debug-layer preflight and removed-device handling.
  • Include an optional private Agility test-staging helper and a validation runbook. No OS, driver, BIOS, clock, pagefile or TDR-registry settings are changed by these features.
  • Make the loader's existing free-region test race-free: check the unmappable null region rather than assuming a released address has not already been reused by another parallel test. The release result itself is checked.

How it was tested

Clean PR branch

  • 32 targeted checks passed on the updated branch: 20 individually selected GPU/state/fence/replay/allocation checks plus all 12 upload tests. This includes the new upstream clear-state/compare-kernel cases affected by integration. Hardware-shaped tests used Microsoft WARP, matching Agility 614 SDK layers and strict validation, in separate supervised processes.
  • 76 loader library tests passed. The first parallel run exposed the existing released-address assertion race described above; the repaired test suite passed.
  • 89 application unit tests passed; one intentional process-termination probe remains ignored by the ordinary harness.
  • The separate software-only fatal-break probe passed: expected exit 0x887a0005, synthetic SDK message and original stack captured, with no GPU commands submitted.
  • The diagnostics unit-test build and the all-target/all-feature workspace check compile, including the feature-gated replay code.
  • cargo build --release --locked -p victory --features gpu-validation succeeds on this clean branch.
  • The PR change set passes staged asset policy and whitespace checks. No game assets, executable bytes, shader dumps, captures, crash dumps or vendor binaries are introduced. The whole-tree upstream policy blocker is called out below.

Hardware integration evidence and its limits

  • Rig: RTX 4080 16 GB, 64 GB host RAM, Windows 10, PCIe 4.0 x4; Series X profile, 2560x1440 / DLSS Balanced, frame generation off, RT structure builder off.
  • The integrated development checkout completed a 300-second strict-validation run, visiting the balcony, street and balcony again, with zero D3D12 errors and zero relevant Windows driver/reset events. It was hidden and muted; the final scene retained foliage, distant scenery, water and character lighting.
  • That hardware run used the broader development checkout based on 41adb551, before this clean PR extraction and the later upstream update. The extracted PR branch on c71899d9 has fresh software validation, not a separate fresh hardware playthrough. The tests establish the repaired defects; they do not prove which command caused earlier machine-level timeouts or establish permanent driver stability.
  • No shader algorithm or wave-size changes are made; 32/64-lane shader equivalence is not claimed or needed for this patch.

CI status

cargo clippy --workspace --all-targets --locked -- -D warnings is blocked by existing upstream dead-code errors for Lowered::loop_caps in tests and Shadow::ranged. I reproduced those on an untouched c71899d9 checkout. The non-strict all-target/all-feature check completed; an existing seed % 3 test lint also remains. This PR does not disable or relax CI lints. The earlier 41adb551 blockers were fixed upstream; they are not the current blocker list.

Whole-tree cargo xtask policy also reports a pre-existing 560-character hex/base64 run in crates/victory-shader/src/native.rs on untouched c71899d9. This PR does not change that file or suppress the policy. The staged PR files pass policy; the inherited whole-tree failure still needs upstream attention.

The full hardware-sensitive GPU/workspace suite was not run on the user's physical adapter. The selected WARP checks, loader/application suites and intentional-exit probe above are the completed validation, not a claim of fully green CI. Reproduction instructions are in docs/gpu-stability-validation.md.

Checked for overlap

  • Searched open PRs for the failures and touched areas, and inspected relevant PR descriptions/files.
Related PR Relationship
#3729 Same 4 GiB send-allocation rounding problem. This bundle adds checked representability/failure handling and separate mapped-VRAM bounds. The overlapping sizing changes should be coordinated rather than merged twice. Related reports: #3024 and #2945.
#3572 Overlapping authoritative depth-state revalidation approach. This bundle also retains compatible read-state combinations and has fresh WARP regression coverage. Coordinate the shared draw.rs changes if either lands first.
#3976, #3979 Adjacent placed-twin format-family fixes in list.rs; this PR addresses binding restoration and copy-state lifetimes, not those cross-format copy policies.
#3740 Related device-removal reporting work. This PR primarily prevents invalid completion values/failed waits from authorizing landing or recycling.
#3939 Exposes existing narrow-barrier choices in the menu; this PR changes the underlying correctness paths without changing that menu or enabling experimental barrier modes.
#2160 Changes ambient compilation/root-signature construction for Proton. Its separate signature builder would also need to preserve the mutable-depth contract if merged with this PR.

The final base is c71899d9. The updated upstream code is merged, including its new defaults; this PR does not override them. Conflict resolutions retain the new HostList barrier-helper API, allocation-search backoff, CPU-mirror export and fence-wait scope while preserving these repairs. Clear-state tests were adapted to the removed draw-local depth cache, and the upstream compare-kernel fixture was updated for its new disabled-capture arguments/UAV bindings. The checks above were rerun after integration. The larger performance/development history is preserved separately and is not part of this PR.

Review focus

Please focus on recording ownership across cuts, completion-before-recycling, the combined-read barrier before-states, and restoring bindings after partial/failed external work. The allocation and ambient-signature overlaps above are called out explicitly for coordination.

Signed: GPT 6.0 astra

@github-actions github-actions Bot added the pr-fix Pull request: fixes a bug label Nov 30, 2026
@github-actions github-actions Bot changed the title [pr-fix] Repair GPU lifetimes, state transitions and external-pass bindings Repair GPU lifetimes, state transitions and external-pass bindings Nov 30, 2026
@deama

deama commented Nov 30, 2026

Copy link
Copy Markdown
Author

@trustno1-coder, could you review this stability bundle, or route it to the appropriate repository maintainer?

The main review points are recording ownership across list cuts, copy/depth state transitions, snapshot allocation bounds, and restoring title bindings after an unsuccessful external pass. The description includes the exact software regression evidence, the limits of the earlier hardware validation, and overlaps with #3729 and #3572. It also identifies the current upstream Clippy and whole-tree asset-policy blockers separately from this PR's passing checks.

GitHub does not allow this contributing account to assign formal review requests, so I am requesting maintainer review here.

Signed: GPT 6.0 astra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant