Shader: check device removal before FMad readback #2450

Open
github-bot wants to merge 1 commit from github-bot/gh-2450 into main AGit
Owner

@⁠Damokles2 on GitHub · 2026-11-25 13:48 UTC · original
Damokles2:fix-shader-fmad-device-removal → main · +82 −11 · 1 files · 1 commits · open

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

  • pes7 requested a separate follow-up because the probe runs during production adapter initialization and #1734 covers the test harness. Request in #1734
  • #2041 addresses a separate sampler-heap binding issue in the same function. Its shader hunk applied cleanly during compatibility review. PR #2041
  • The device-removal follow-up was claimed in #1633. Coordination claim

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

**@⁠Damokles2** on GitHub · 2026-11-25 13:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2450) `Damokles2:fix-shader-fmad-device-removal` → `main` · +82 −11 · 1 files · 1 commits · open ### 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](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12fence-getcompletedvalue) · [Readback mapping contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12resource-map) ### 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](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12device-getdeviceremovedreason) ### 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. ```text 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](https://github.com/Damokles2/VIctory/actions/runs/45625862310) 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 - pes7 requested a separate follow-up because the probe runs during production adapter initialization and #1734 covers the test harness. [Request in #1734](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1734) - #2041 addresses a separate sampler-heap binding issue in the same function. Its shader hunk applied cleanly during compatibility review. [PR #2041](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2041) - The device-removal follow-up was claimed in #1633. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) AI-assisted development disclosure — OpenAI Codex assisted with investigation, implementation, regression testing, CI validation, and preparation of this PR.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:17 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:16 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 14:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2450#issuecomment-7165025672) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:58 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2450#issuecomment-7167481122) <!-- victory-triage v1 head=de9a0315887daf72fb4edf7a7d6dc6673ec32cf6 verdict=merge-candidate at=2026-11-25T15:58:31Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:55 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2450#issuecomment-7179249291) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2450/head:github-bot/gh-2450'
git switch 'github-bot/gh-2450'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2450'
git switch 'github-bot/gh-2450'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2450'
git switch 'github-bot/gh-2450'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2450'
git switch 'main'
git merge --squash 'github-bot/gh-2450'
git switch 'main'
git merge --ff-only 'github-bot/gh-2450'
git switch 'main'
git merge 'github-bot/gh-2450'
git push origin 'main'
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/Marvisak--VIctory!2450
No description provided.