Skip to content

d3d12: propagate explicit removal to fence notifications - #8454

Open
kyaemma wants to merge 2 commits into
ItsNotRexed:mainfrom
kyaemma:fix/removedevice-fence-notifications
Open

kyaemma wants to merge 2 commits into
ItsNotRexed:mainfrom
kyaemma:fix/removedevice-fence-notifications

Conversation

@kyaemma

@kyaemma kyaemma commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as: #8344 (comment)

Depends on: #8101, #3293, #4577 (integration/rebase coordination for overlapping code; no functional dependency for this HANDLE-notification fix).

Review follow-up f2ee288

Fixed the test defect reported by tupacfan04 and rideinstead in f2ee288: the first WARP CreateFence() is now an oracle operation after successful device setup, so failure returns 1 (FAIL) rather than 77 (SKIP). Only the test changes (2 additions / 2 deletions); the production implementation is unchanged by this follow-up. Fresh independent Luna and Claude Opus 5.5 reviews approve this limited correction.

Fresh validation on Windows 11 / MSVC 19.51 / RX 9070 XT, LEONIDA_VK_VALIDATION=1: all five requested targets rebuilt; 5/5 CTest Passed, no new warning lines in that build, zero Vulkan validation errors. Luna independently reran the final regression: exit 0. Isolated compiled branch-forcing probes give old fence-failure 77 / corrected fence-failure 1 / setup-failure 77; they simulate the branch, not an actual COM failure. The current corrected test linked in a separate executable against the original runtime from main 867d922f09b86583859796a174df89555fb32da8 still fails as expected: actual exit 1, WARP PASS, layer 0/0 and notification timeouts, validation errors 0. Its separately compiled original production object emitted the known pre-existing C4189; no new warning is attributed to this test edit. Hygiene checks remain clean.

Remaining runtime compatibility issue, confirmed during review: after explicit removal, native WARP Signal(1) returns S_OK, the original layer returns S_OK, and this PR's runtime returns E_FAIL. This HRESULT divergence is introduced by the original context-propagation change and is not fixed by the test-only follow-up. WARP CreateFence after removal returns DXGI_ERROR_DEVICE_REMOVED, while both layer versions succeed; that difference is pre-existing. These are open review/coordination items, not a claim of complete removal conformance or merge readiness.

Null-event blocking waits also remain excluded. Open #4577 rewrites those paths, but its current draft returns E_FAIL on logical device loss whereas the native checks report S_OK; it is not claimed as a complete resolution of that contract. No competing wait implementation is added here.

The public ECHOZwei / lohant27-netizen / gut0to / h0useadv validations refer to original head 2a87ecd6383f639c6f58be92bebf9499a4c33220, not this follow-up. Local results above refer to the corrected test. No remote CI success is claimed.

What and why

Explicit ID3D12Device5::RemoveDevice changes the removal reason while leaving the fence/dispatcher context healthy. With two unsignaled synthetic fences, native WARP reports UINT64_MAX and completes single/ALL/ANY HANDLE notifications; the layer retained 0/0 and left the notifications pending. This differs from the documented removal contract.

Propagate explicit removal through the existing context notification. The regression compares WARP and the layer: healthy initial state, single/ALL/ANY HANDLEs registered before and after removal, completed values, and idempotent repeated removal. Oracle failures are FAIL, not SKIP; only WARP setup unavailability skips.

Scope: #1440 introduced the reason-only stub. The inspected diffs of #8101/#3293 add diagnostics, without this propagation. #4577 rewrites blocking waits; this patch does not change or claim to fix null-event blocking waits. Those PRs may require integration/rebase work when merged.

Tested

Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0, RX 9070 XT / driver 32.0.32015.7029; native Microsoft WARP. Synthetic inputs only; no physical GPU failure or reset induced.

  • Test added alone on 6dda0630bd6fc0514baadb94fb98e36bd7d64c0b: WARP PASS, layer FAIL (0/0, pending events), exit 1.
  • Fixed version, including defensive context guard: regression PASS on WARP/layer; existing OOM and device-loss-result checks remain passing; 0 Vulkan validation errors. Luna independently reran it, exit 0.
  • Updated to main a86d7f95081461f4dfd976a4e6d977d37671a151, rebuilt all five targets, then with LEONIDA_VK_VALIDATION=1:
cmake --build <build> --config RelWithDebInfo --target vk_fence_dispatcher_sync_test d3d12_fence_timing_test d3d12_fence_events_test d3d12_fence_device_lost_counter_test d3d12_fence_waiter_test
ctest --test-dir <build> -C RelWithDebInfo --output-on-failure -R '^(vk_fence_dispatcher_sync|d3d12_fence_timing|d3d12_fence_events|d3d12_fence_device_lost_counter|d3d12_fence_waiter)$'

Result: 5/5 PASS, exit 0. git diff --check and python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_fence_device_lost_counter_test.cpp: exit 0. Broader baseline results are not claimed as a full rerun for this patch.

AI-assisted: yes — Codex (Sol orchestration/final review, Terra implementation, Luna independent validation) and Claude Opus 5.5 (independent discovery and cross-review). Luna approved the final diff; Claude's requested context guard is integrated.

Discord : kyaemma

Checklist

  • No game data, keys or decryption, including in the evidence above.
  • A new translator rule is in the contract table (not applicable: no translator changes).

@tupacfan04 tupacfan04 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.

The implementation change looks correct: mark_device_lost() sets the context lost and wakes the dispatcher, GetCompletedValue returns UINT64_MAX, and single/multiple SetEventOnCompletion complete immediately after removal; the test otherwise covers pre/post-removal single/ALL/ANY notifications, fence values, repeated removal and the native WARP oracle. One test defect:

runtime/test/d3d12_fence_device_lost_counter_test.cpp:127-131 groups device->CreateFence with the WARP setup checks:

if (FAILED(CreateDXGIFactory1(...)) ||
    FAILED(factory->EnumWarpAdapter(...)) ||
    FAILED(D3D12CreateDevice(...)) ||
    FAILED(device->CreateFence(...)))
    return 77;

main treats 77 as SKIP (CTest property SKIP_RETURN_CODE 77). If WARP and D3D12CreateDevice succeed but CreateFence fails, that is a fence-control failure, not WARP unavailability; the test skips before either remove_device_notifies call, so the explicit-removal/fence-notification behavior is never exercised. This contradicts the PR description's “Oracle failures are FAIL, not SKIP; only WARP setup unavailability skips.” The rest of the new control (event, signal, query, multiple-fence waits) correctly returns 1.

Fix: move CreateFence out of the return 77 block into the return 1 oracle-control block, or run the layer removal check independently when the oracle fails. Synthetic only; no game files. AI-assisted (OpenCode).

@ECHOZwei

Copy link
Copy Markdown

Tested 2a87ecd6383f639c6f58be92bebf9499a4c33220 merged onto origin/main 427a7ec71 (clean merge) on Windows 11 (MSVC 14.51 / Visual Studio Community 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1) on two GPUs (synthetic tests only; no game files): pass

  • Negative control (d3d12_vulkan_device.cpp at origin/main 427a7ec71, RTX 4080 SUPER, LEONIDA_VK_VALIDATION=1): d3d12_fence_device_lost_counter_test.exe fails as expected (exit 1: Leonida Vulkan RemoveDevice: reason=887a0005 fences=0/0 before=258 after=258 repeated=0: FAIL); with the PR merged, passes cleanly.
  • Built vk_fence_dispatcher_sync_test, d3d12_fence_timing_test, d3d12_fence_events_test, d3d12_fence_device_lost_counter_test, and d3d12_fence_waiter_test cleanly (0 new warnings).
  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01, validation on):
    • ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R ^(vk_fence_dispatcher_sync|d3d12_fence_timing|d3d12_fence_events|d3d12_fence_device_lost_counter|d3d12_fence_waiter)$: 5/5 passed (4.24s), 0 validation errors.
  • AMD Radeon(TM) Graphics iGPU (driver 25.10, LEONIDA_VK_DEVICE=AMD, validation on):
    • Same 5 tests: 5/5 passed (3.18s), 0 validation errors.
  • git diff --check and python -I scripts/check_no_game_data.py runtime/shims/d3d12_vulkan_device.cpp runtime/test/d3d12_fence_device_lost_counter_test.cpp: clean (exit 0).
  • Code review: minimal and clean; GetDeviceRemovedReason() checks both removed_ and state_.context->is_device_lost(), so threads woken by mark_device_lost() before removed_.store(true) still observe DXGI_ERROR_DEVICE_REMOVED.

AI-assisted.

@rideinstead

Copy link
Copy Markdown

TEST validation — Needs changes

Reviewer-flagged test defect (significant):

In native_warp_control() in runtime/test/d3d12_fence_device_lost_counter_test.cpp, device->CreateFence(...) is grouped inside the return 77 (SKIP) block alongside WARP setup:

if (FAILED(CreateDXGIFactory1(...)) ||
    FAILED(factory->EnumWarpAdapter(...)) ||
    FAILED(D3D12CreateDevice(...)) ||
    FAILED(device->CreateFence(...)))
    return 77;

If WARP and D3D12CreateDevice succeed but CreateFence fails, the test returns 77 → CTest treats it as SKIP, and remove_device_notifies() is never called. The explicit-removal/fence-notification behavior is never exercised. This contradicts the PR's own stated contract: "Oracle failures are FAIL, not SKIP; only WARP setup unavailability skips."

Fix needed: Move CreateFence out of the return 77 block into the return 1 oracle-control block (or run the layer removal check independently when the oracle fails).

Other notes:

  • CI has not run (0 checks on the PR)
  • D3D12 half is Windows-only (not runnable on Linux CI)
  • scripts/check_no_game_data.py passed on both changed files (exit 0)
  • AI-assisted; one review by tupacfan04 exists, second reviewer needed

Recommendation: Needs changes — fix the SKIP/FAIL contract defect before merge.

@lohant27-netizen

Copy link
Copy Markdown

Tested 2a87ecd63 on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 2a3b3b554 together with #8457, #8454, #8373, #8364 and #8340 (no conflicts between them): pass.

@gut0to gut0to 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.

Reviewed the removal and notification ordering, including repeated removal and notifications registered after removal. Built d3d12_fence_device_lost_counter_test with native MSVC and ran the WARP/Vulkan regression through CTest: d3d12_fence_device_lost_counter passed (1/1). The new test separately checks native WARP as the behavior oracle and the shim against the same expectations.

@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

The event-based paths look right: mark_device_lost() wakes the dispatcher, which drains every pending entry once, and enqueue checks device_lost_ under its mutex so late registrations fire immediately. But the blocking (null-event) waits are still uncovered:

  • runtime/shims/d3d12_com.cpp:1489: a SetEventOnCompletion(v, nullptr) already blocked in fence_.wait(value, UINT64_MAX) never returns, because after a logical RemoveDevice the Vulkan device is healthy and the semaphore is never signalled.
  • runtime/shims/d3d12_com.cpp:1994-2003: the null-event SetEventOnMultipleFenceCompletion has no is_device_lost() check, so it hangs even when called after removal.

Native result (RTX and WARP, ID3D12Device5::RemoveDevice): an in-flight blocking single wait and an in-flight blocking multi ALL wait both return S_OK, a post-removal null-event multi wait returns S_OK right away, and shared fences also read UINT64_MAX. Smaller differences: native Signal after removal returns S_OK (the shim returns E_FAIL), and CreateFence returns DXGI_ERROR_DEVICE_REMOVED (the shim succeeds).

Suggestion: bound the blocking waits in slices and re-check is_device_lost(), and add a threaded blocking-wait case to the test.

AI-assisted (Claude Code).

@h0useadv

Copy link
Copy Markdown

Tested 2a87ecd63 (base a86d7f950) on AMD Radeon RX 9070 XT (RDNA4), AMD Windows driver 32.0.32029.2010, Windows 11 Pro build 26300: pass, no new failures. Built with clang-cl 23.1.6 + lld-link against an xwin splat (MSVC 14.44, SDK 10.0.26100), RelWithDebInfo; synthetic, no game files.

  • d3d12_fence_device_lost_counter (with the new WARP-vs-layer removal checks): passes.
  • The other fence tests pass: d3d12_fence_events, d3d12_fence_timing, d3d12_fence_waiter, vk_fence_dispatcher_sync.
  • Full ctest -j8, failures rerun with -j1: 265/271; the failures are the ones main has on this GPU, plus d3d12_indirect_dispatch_count, which fails because this base predates its fix on main.

AI-assisted (Claude Code).

@kyaemma

kyaemma commented Nov 23, 2026

Copy link
Copy Markdown
Author

@tupacfan04 Thanks for catching this. You were right: the first CreateFence() failure was still grouped with WARP setup and could skip the oracle regression. Fixed in f2ee288: factory/adapter/device setup retains exit 77; the first fence creation now returns FAIL (1), like the later control operations.

Rebuilt all five fence targets and reran them on RX 9070 XT with Vulkan validation: 5/5 passed, no new warning lines or validation errors. Compiled branch-forcing probes also verify old fence-failure → 77, corrected fence-failure → 1, and setup-failure → 77. The follow-up changes only the test; Luna and a fresh Claude review approved it.

@kyaemma

kyaemma commented Nov 23, 2026

Copy link
Copy Markdown
Author

@rideinstead Thanks for independently identifying the same skip/fail defect. Addressed in f2ee288: CreateFence() now runs after successful WARP setup, and failure returns 1 instead of 77. I checked the remaining early returns: later oracle operations already fail with 1.

The five rebuilt targeted tests pass with validation on RX 9070 XT; an independent Luna run also passes with zero validation errors. The current corrected test, linked in an isolated executable against the original runtime, still fails as expected (actual exit 1, WARP PASS, layer counters 0/0 and notification timeouts). No runtime behavior was changed by this follow-up.

@kyaemma

kyaemma commented Nov 23, 2026

Copy link
Copy Markdown
Author

@ECHOZwei Thanks for the independent negative control and the RTX 4080 SUPER / AMD iGPU validation, including the clean five-target runs. I have retained those results against the exact commit you tested, 2a87ecd6383f639c6f58be92bebf9499a4c33220. Thanks also @lohant27-netizen and @gut0to for the additional RTX 5070 and native MSVC validation of that revision.

Follow-up f2ee288 addresses the reviewers' test classification feedback: initial WARP fence creation failure now fails instead of skipping. It preserves the production implementation. Our local RX 9070 XT validation of the follow-up is 5/5 targeted tests passed, with zero validation errors.

@kyaemma

kyaemma commented Nov 23, 2026

Copy link
Copy Markdown
Author

@Envyre Thanks for the native checks. I reproduced the two post-removal HRESULT differences with synthetic WARP/original-layer/PR-layer probes:

After RemoveDevice WARP Original layer PR runtime
Signal(1) S_OK, value stays UINT64_MAX S_OK, value becomes 1 E_FAIL, value stays UINT64_MAX
CreateFence DXGI_ERROR_DEVICE_REMOVED S_OK S_OK

So the Signal HRESULT divergence is introduced by the initial propagation change; creation-after-removal is pre-existing. I have highlighted both as open compatibility items in the description. They are not resolved by follow-up f2ee288, which only fixes the test's SKIP/FAIL classification.

The null-event cases were already explicitly excluded here because #4577 rewrites those same waits. Its current draft still maps logical loss to E_FAIL, so I do not claim it fully matches your native S_OK result either. I am keeping the reviewed test correction separate from that competing runtime work and leaving these concerns open for scope/integration review; the HANDLE regression alone does not establish complete removal conformance.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants