Shader: check device removal before FMad readback #2448
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2450"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Damokles2 on 2026-11-25T13:48:03Z.
Problem
fuses_fmad()checks for device removal inside its fence polling loop. D3D12 documents thatGetCompletedValue()returnsUINT64_MAXafter 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 contractFix
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 contractRegression 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.The patched Windows-MSVC run validated
de9a0315887daf72fb4edf7a7d6dc6673ec32cf6.dxbctests — 2 passed, 0 failed.git diff --check— passed.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.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:55:25Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: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).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:05Z.
Review: APPROVED
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — device removal checked before FMad readback.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:16:32Z.
Correct:
GetCompletedValuereturnsu64::MAXon a removed device, which satisfied the< 1wait and letMaprun 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. Extractingread_fmad_after_waitmakes all four paths unit-testable without a device; the test matrix covers MAX-immediate, mid-poll removal, and both healthy outcomes.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:58:37Z.
Automated triage for the maintainers.
Merge candidate, low priority. In
crates/victory-shader/src/emit/host.rsfuses_fmad, a device removed by the time the fence reads complete (it then reportsu64::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.rsat 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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:55:24Z.
Code review and RTX 5090 + WARP + DXIL verification at head
de9a0315887dmerged cleanly ontomain(63bcca43c6a0):crates/victory-shader/src/emit/host.rs:720-751):read_fmad_after_waitand checkingdevice_status()(GetDeviceRemovedReason()) after the fence wait completes and beforereadback.Map(...)cleanly closes the D3D12 device-removal window whereID3D12Fence::GetCompletedValue()returnsu64::MAX, breaks the wait loop, and would otherwise read zeros from the readback buffer and misclassify FMAD support.#2922(emit/host.rs:691-694sampler heap binding): ~25 lines apart, zero merge conflict and complementary.dxil.dll10.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 warningsemit::host emit::tests emit::lower::tests: 55/55 passed on both RTX 5090 and WARPemit::semantics_tests::hosts_that_do_not_fuse_are_named: passed (WARP = Ok(false), RTX 5090 hardware fuses FMad =true).LGTM.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T02:49:25Z.
Review: APPROVED
Reviewed at
de9a0315887daf72fb4edf7a7d6dc6673ec32cf6— APPROVE.Verification
cargo xtask policy(191 files ok),cargo clippy -p victory-shader --all-targets --all-features -- -D warnings, andrustfmt --edition 2024 --check(zero new formatting diffs) all passed.read_fmad_after_wait(crates/victory-shader/src/emit/host.rs:735-751) re-checksGetDeviceRemovedReason()after exiting the fence wait loop—catching the D3D12u64::MAXdevice-removal sentinel cleanly beforereadback.Map, matchingHost::draw(host.rs:1327-1329) with pairedMap/Unmapcleanup.emit::host::fmad_wait_tests(4/4), and verified zero regressions on both hardware (VICTORY_WARP=0) and WARP (VICTORY_WARP=1) acrossemit::host::tests(1/1),emit::valu_tests::v_fma_(1/1), andemit::semantics_tests::hosts_that_do_not_fuse_are_named(confirmingtrueon hardware andfalseon WARP).Non-blocking notes
Host::dispatch(host.rs:2061) still lacks the same post-waitGetDeviceRemovedReason()check.fmad_wait_testswherecompleted_value()returns1and the post-waitdevice_status()returnsErr(DXGI_ERROR_DEVICE_REMOVED)would assert zero readback calls for the post-loop check specifically.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.