Skip to content

Runtime: allow D3D12 fence signal retry after transient Vulkan failure - #3789

Open
pmilewsskiedu-gif wants to merge 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/d3d12-fence-signal-retry-20261122
Open

pmilewsskiedu-gif wants to merge 1 commit into
ItsNotRexed:mainfrom
pmilewsskiedu-gif:fix/d3d12-fence-signal-retry-20261122

Conversation

@pmilewsskiedu-gif

Copy link
Copy Markdown
Contributor

Claimed: #3574 (comment)

What and why

Fix a transient D3D12 fence-signal failure: Fence::claim(value) advanced its high-water mark before vkSignalSemaphore (CPU) or vkQueueSubmit (GPU) succeeded. On synthetic VK_ERROR_OUT_OF_HOST_MEMORY, the original call returned E_FAIL, but retrying the same value was discarded as S_OK, leaving the Vulkan timeline unsignaled.

Use a per-fence mutex transaction to check an ascending value, submit the backend signal, and commit the high-water mark only after success. This prevents unsafe CAS rollback if another queue's higher value is accepted. Existing duplicate/backward signal behavior stays unchanged. Three files +198/-12; no game data.

Base f847748. Commit a78a5a4.

Tested

  • RTX 4060 Ti, MSVC 19.44, Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1, Medal capture disabled.
  • New COM-level test intercepts vkSignalSemaphore/vkQueueSubmit with test-only one-shot VK_ERROR_OUT_OF_HOST_MEMORY before real driver. Tests E_FAIL, unchanged counter, same-value retry reaching target, duplicates, ascending values, cross-origin CPU/GPU recovery, and multi-queue concurrent signal/failed lower vs successful higher.
  • Exact upstream negative control: independently compiled unmodified d3d12_com.cpp linked into same test, exit 1 at missing second CPU vkSignalSemaphore; patched: exit 0, zero Vulkan validation errors.
  • Focused CTest 6/6 pass (multithread, queue wait, queue wait timeout, new retry, timing, events), zero failures. MSVC incremental build 10/10, git diff --check clean.
  • Synthetic OOM is not a physically observed NVIDIA OOM. Native WARP validates ordinary fence behavior but cannot inject Vulkan failure. No full suite or other GPU vendor coverage claimed.

Integration / limitations

#1161 owns CPU-behind-GPU queue signal ordering; #2951 owns held Wait-before-Signal execution. Both are open and edit adjacent/identical methods. This PR does not fix either. When integrating, avoid invoking held-queue releases or deferred callbacks under the per-fence mutex (Q1→Fence→Q2 / Q2→Fence deadlock). Retain only accepted queued values, dispatch callbacks outside queue/fence locks. Coordinate before combining; don't blindly merge.

Checklist

No upstream merge performed.

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Tested a78a5a4 (based on main f847748) on Windows 11 build 26300, MSVC 19.44, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, with two GPUs picked by LEONIDA_VK_DEVICE: pass. This adds a second vendor to the NVIDIA run in the description.

RTX 4070 SUPER (NVIDIA 616.64) Intel UHD 770 (101.7092)
d3d12_fence_signal_retry_test exit 0, fence signal retry: PASS exit 0, fence signal retry: PASS
the same under VK_LAYER_KHRONOS_validation exit 0, 0 messages exit 0, 0 messages
full ctest 141/141 (the new test included) 139/141: d3d12_descriptor and d3d12_subgroup, the same two as on main (#2948, #2934)

The multi-queue case passes on the UHD 770 too, although its Vulkan driver has a single queue. That is expected: the test builds its device with create_vulkan_device(info), and that caller-owned device keeps sharing the one queue. Only create_vulkan_device_standalone limits that GPU to one live queue (posted separately in #3574).

AI-assisted (Claude Code). No game files.

@Kam471 Kam471 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 a78a5a4b89f1e32687468aae5ce2ac6bc45ea6db on Windows 11, MSVC 19.44.35228, RTX 5070 Ti, Vulkan SDK 1.4.363.0.

  • Built d3d12_fence_signal_retry_test (11/11 steps); pinned LEONIDA_VK_DEVICE=RTX 5070 Ti.
  • d3d12_fence_signal_retry_test.exe -> exit 0, 44/44 EXPECT checks, real vkSignalSemaphore/vkQueueSubmit/timeline waits with synthetic OOM above the driver.
  • ctest ^d3d12_fence_signal_retry$ -> 1/1 passed, 0.14 s. With LEONIDA_VK_VALIDATION=1: PASS, 0 VUIDs; 50/50 repeat runs; related fence/queue ctest set 7/7.
  • Negative control: the same test on the unmodified base shim exits 1 at line 103 (the retry never reaches vkSignalSemaphore); this head exits 0.

Logic: a failed value is never committed, so highest_ stays at the last accepted value and the identical retry passes the ascending gate; one signal per value is admitted, and retries only happen after submit() returned false (d3d12_com.cpp:1106-1113). VK_ERROR_DEVICE_LOST is special-cased as lost and fails E_FAIL rather than spinning.

Two non-blocking notes: only VK_ERROR_OUT_OF_HOST_MEMORY is injected (no permanent/device-lost case), and the CPU vkSignalSemaphore device loss is not recorded (vulkan_backend.h:1374), unlike the GPU path, so a permanent CPU failure can look retryable and GetCompletedValue stays healthy. Classifying transient vs permanent results would make the intent explicit; neither is a regression here.

@kovaaper

Copy link
Copy Markdown
Contributor

Tested a78a5a4b89f1e32687468aae5ce2ac6bc45ea6db on Windows 11, NVIDIA GeForce RTX 3060 (driver 621.01), MSVC 19.44, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1.

Built d3d12_fence_signal_retry_test, d3d12_queue_wait_test, and d3d12_multithread_test from the PR head. Focused CTest: 3/3 passed (d3d12_fence_signal_retry, d3d12_queue_wait, d3d12_multithread). The retry test also ran directly: CPU/GPU synthetic OOM and identical-value retries, cross-origin recovery, and concurrent multi-queue case passed; 0 Vulkan validation errors. No game files were used. I did not run the full suite or reproduce a physical out-of-memory condition. Independent AI-assisted (Codex) test run.

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.

4 participants