Skip to content

Shader: check device removal before FMad readback - #2450

Open
Damokles2 wants to merge 1 commit into
Marvisak:mainfrom
Damokles2:fix-shader-fmad-device-removal
Open

Damokles2 wants to merge 1 commit into
Marvisak:mainfrom
Damokles2:fix-shader-fmad-device-removal

Conversation

@Damokles2

Copy link
Copy Markdown
Contributor

Problem

fuses_fmad() checks for device removal inside its fence polling loop. D3D12 documents that GetCompletedValue() returns UINT64_MAX after removal. That value satisfies the loop's completion condition, so execution can reach readback without establishing that the GPU copy completed. Fence contract · Readback mapping contract

Fix

Check GetDeviceRemovedReason() immediately after the fence wait and before readback. The change preserves existing error conversion, polling behavior, resource lifetimes, FMad classification, and adapter initialization policy. A small private helper lets CPU-only tests exercise the same wait-to-readback decision used by the production probe. Device removal status contract

Regression and validation

The test-only baseline had three passing tests and one expected failure in immediate_removal_skips_readback. Readback was invoked once when zero calls were expected.

assertion `left == right` failed: unexpected readback count
  left: 1
 right: 0

The patched Windows-MSVC run validated de9a0315887daf72fb4edf7a7d6dc6673ec32cf6.

  • FMad regression — 4 passed, 0 failed.
  • Existing CPU-only dxbc tests — 2 passed, 0 failed.
  • Strict Clippy — passed with default and all features.
  • git diff --check — passed.
  • Rustfmt — no new formatting differences relative to upstream.

The single fork-only run passed on its first attempt and took 3 minutes 36 seconds on the runner. Windows-MSVC validation

The regression uses simulated fence and device-status responses. Native D3D12 device removal, GPU execution, and full workspace runtime coverage were outside its scope. The guard handles removal observed at the end of the wait. Device removal can still occur after the status check.

References and coordination

AI-assisted development disclosure — OpenAI Codex assisted with investigation, implementation, regression testing, CI validation, and preparation of this PR.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Checking for device removal before FMad readback cleanly avoids reading garbage after a removed device.
  • cargo test -p victory-shader hosts_that_do_not_fuse_are_named: 1/1 passed on RTX 5090, 1/1 passed on WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — device removal checked before FMad readback.

@kotekompotek

Copy link
Copy Markdown

Correct: GetCompletedValue returns u64::MAX on a removed device, which satisfied the < 1 wait and let Map run on dead readback — the FMad verdict then read garbage or failed as its own error, hiding the removal. The post-wait status check closes it. Extracting read_fmad_after_wait makes all four paths unit-testable without a device; the test matrix covers MAX-immediate, mid-poll removal, and both healthy outcomes.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate, low priority. In crates/victory-shader/src/emit/host.rs fuses_fmad, a device removed by the time the fence reads complete (it then reports u64::MAX, which ends the wait) now returns the "device removed" error instead of mapping the readback; the wait-then-readback order is moved into a small helper with CPU-only tests. The only caller, crates/victory-gpu/src/host.rs at adapter setup, uses the result just to pick a log line, so the visible effect is a correct message in that case. CI: passing.


Generated by Claude Code

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP + DXIL verification at head de9a0315887d merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-shader/src/emit/host.rs:720-751):
    • Extracting read_fmad_after_wait and checking device_status() (GetDeviceRemovedReason()) after the fence wait completes and before readback.Map(...) cleanly closes the D3D12 device-removal window where ID3D12Fence::GetCompletedValue() returns u64::MAX, breaks the wait loop, and would otherwise read zeros from the readback buffer and misclassify FMAD support.
    • Checked interaction with #2922 (emit/host.rs:691-694 sampler heap binding): ~25 lines apart, zero merge conflict and complementary.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-shader --all-targets -- -D warnings (default + --all-features): 0 warnings
    • emit::host emit::tests emit::lower::tests: 55/55 passed on both RTX 5090 and WARP
    • emit::semantics_tests::hosts_that_do_not_fuse_are_named: passed (WARP = Ok(false), RTX 5090 hardware fuses FMad = true).

LGTM.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants