d3d12: preserve same-value retry after a failed fence signal (D3D-FENCE-SIGNAL-RETRY) #1455

Closed
PyZikYG wants to merge 1 commit from upstream-pr/1455 into main
PyZikYG commented 2026-11-25 00:32:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PyZikYG on 2026-11-25T00:32:11Z.


Claimed as D3D-FENCE-SIGNAL-RETRY.

Summary

A synchronous Vulkan failure in ID3D12Fence::Signal or ID3D12CommandQueue::Signal previously left the fence's highest accepted value advanced. Retrying the same value could return success without signalling anything, leaving a dependent queue held.

Publish the fence value after a successful CPU signal or admission to the command queue. Release retired references and run ready queue work after dropping the fence lock.

Verification

Injected transient failures in vkSignalSemaphore and vkQueueSubmit. Verified that the failed call leaves the fence value and waiting queue pending, and that retrying the same value releases the queue. Covered retries from the CPU, from the queue, and from the CPU after a queue submission fails.

AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5482776940 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1455). Originally posted by [PyZikYG](https://github.com/PyZikYG) on 2026-11-25T00:32:11Z. --- Claimed as [D3D-FENCE-SIGNAL-RETRY](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7148508370). ### Summary A synchronous Vulkan failure in `ID3D12Fence::Signal` or `ID3D12CommandQueue::Signal` previously left the fence's highest accepted value advanced. Retrying the same value could return success without signalling anything, leaving a dependent queue held. Publish the fence value after a successful CPU signal or admission to the command queue. Release retired references and run ready queue work after dropping the fence lock. ### Verification Injected transient failures in `vkSignalSemaphore` and `vkQueueSubmit`. Verified that the failed call leaves the fence value and waiting queue pending, and that retrying the same value releases the queue. Covered retries from the CPU, from the queue, and from the CPU after a queue submission fails. AI-assisted: yes.
whoalin1 commented 2026-11-25 06:22:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T06:22:55Z.


Independent verification on both of our GPUs (native Windows 11, validation on):

  • NVIDIA RTX 4070 SUPER: 24/24 pass — d3d12_fence_device_lost_counter (incl. the new injected-failure retry cases), all d3d12_fence_*, d3d12_queue_*, queue_proxy, vk_queue, vk_fence_dispatcher_sync, vk_sync_validation, vk_command_replay, vk_queue_constructor_oom.
  • AMD Radeon iGPU (gfx1036, LEONIDA_PC_TAIL_UBO=1): 23 pass + 1 by-design skip (d3d12_queue_handover_two_queues — single-queue family returns 77).

AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7154732126 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1455#issuecomment-7154732126). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T06:22:55Z. --- Independent verification on both of our GPUs (native Windows 11, validation on): - **NVIDIA RTX 4070 SUPER**: 24/24 pass — `d3d12_fence_device_lost_counter` (incl. the new injected-failure retry cases), all `d3d12_fence_*`, `d3d12_queue_*`, `queue_proxy`, `vk_queue`, `vk_fence_dispatcher_sync`, `vk_sync_validation`, `vk_command_replay`, `vk_queue_constructor_oom`. - **AMD Radeon iGPU** (gfx1036, `LEONIDA_PC_TAIL_UBO=1`): 23 pass + 1 by-design skip (`d3d12_queue_handover_two_queues` — single-queue family returns 77). AI-assisted verification.
MoonEyes commented 2026-11-28 18:00:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T18:00:13Z.


Hi @PyZikYG, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/src/vulkan_backend.h), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7243452736 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1455#issuecomment-7243452736). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T18:00:13Z. --- Hi @PyZikYG, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/src/vulkan_backend.h`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
enlight3d commented 2026-11-29 12:08:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T12:08:44Z.


Run on RTX 3090 (PR head only, because it conflicts with main)

  • Heads: PR head 7ce510d6e, main 8fb974878. The merge conflicts in runtime/src/vulkan_backend.h, so I tested the PR head as it is (detached at the head, not merged).
  • Configure: cmake -S runtime -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON -DSDL3_DIR=<SDL3 cmake folder>
  • Green: cmake --build build -j 8 --target d3d12_fence_device_lost_counter_test gta6rt, then ctest --test-dir build -R "^d3d12_fence_device_lost_counter$" --output-on-failure -j1: Passed (0.25 s).
  • Also run on the same build, one at a time (ctest -R ... -j1): 25 tests, 24 Passed and 1 Skipped: vk_command_replay, vk_queue, vk_queue_query_sync, vk_fence_dispatcher_sync, vk_fence_lost_by_counter, vk_queue_constructor_oom, all d3d12_queue_* (including the three handover tests, which run here), d3d12_fence_timing, d3d12_fence_events, d3d12_fence_waiter, queue_proxy. vk_sync_validation was Skipped (exit 77 in 0.02 s); I did not look into why.
  • Red (behavioural; the test builds either way, it needs no new API): same head with runtime/shims/d3d12_com.cpp, runtime/src/vulkan_backend.h and docs/d3d12_vulkan.md put back to the merge-base version (the test kept), rebuilt, same ctest command: Failed with "failed to retry a fence Signal or release a waiting queue" (the retried Signal of the same value is refused and the waiting queue stays held). That is the bug the PR describes. With the PR's change back, it passes.
  • Link: gta6rt.exe imports compared with a plain main build (dumpbin /imports, DLL!symbol): one entry differs, api-ms-win-crt-stdio-l1-1-0.dll!__stdio_common_vswscanf. It comes from the older base of this branch (runtime/src/base_reservation.h still calls a scanf function there; main no longer does), not from the PR: the PR diff contains no scanf. Nothing else is added, so no new imports from this PR.
  • Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.

The branch is 3835 commits behind main; could you merge main into it when you have a moment? Thanks.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255598782 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1455#issuecomment-7255598782). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T12:08:44Z. --- Run on RTX 3090 (PR head only, because it conflicts with main) - Heads: PR head 7ce510d6e, main 8fb974878. The merge conflicts in `runtime/src/vulkan_backend.h`, so I tested the PR head as it is (detached at the head, not merged). - Configure: `cmake -S runtime -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLEONIDA_REQUIRE_VULKAN=ON -DSDL3_DIR=<SDL3 cmake folder>` - Green: `cmake --build build -j 8 --target d3d12_fence_device_lost_counter_test gta6rt`, then `ctest --test-dir build -R "^d3d12_fence_device_lost_counter$" --output-on-failure -j1`: **Passed** (0.25 s). - Also run on the same build, one at a time (`ctest -R ... -j1`): 25 tests, 24 Passed and 1 Skipped: `vk_command_replay`, `vk_queue`, `vk_queue_query_sync`, `vk_fence_dispatcher_sync`, `vk_fence_lost_by_counter`, `vk_queue_constructor_oom`, all `d3d12_queue_*` (including the three handover tests, which run here), `d3d12_fence_timing`, `d3d12_fence_events`, `d3d12_fence_waiter`, `queue_proxy`. `vk_sync_validation` was Skipped (exit 77 in 0.02 s); I did not look into why. - Red (behavioural; the test builds either way, it needs no new API): same head with `runtime/shims/d3d12_com.cpp`, `runtime/src/vulkan_backend.h` and `docs/d3d12_vulkan.md` put back to the merge-base version (the test kept), rebuilt, same ctest command: **Failed** with "failed to retry a fence Signal or release a waiting queue" (the retried Signal of the same value is refused and the waiting queue stays held). That is the bug the PR describes. With the PR's change back, it passes. - Link: gta6rt.exe imports compared with a plain main build (`dumpbin /imports`, DLL!symbol): one entry differs, `api-ms-win-crt-stdio-l1-1-0.dll!__stdio_common_vswscanf`. It comes from the older base of this branch (`runtime/src/base_reservation.h` still calls a scanf function there; main no longer does), not from the PR: the PR diff contains no scanf. Nothing else is added, so no new imports from this PR. - Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44. The branch is 3835 commits behind main; could you merge main into it when you have a moment? Thanks.
aslan2142 commented 2026-12-01 16:35:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:35:57Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317872083 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1455#issuecomment-7317872083). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:35:57Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
ProjectLeonida/mandy!1455
No description provided.