vulkan: a fence counter of UINT64_MAX no Signal asked for is a loss, without vkDeviceWaitIdle (RT-FENCE-MAX-CONFIRM-NO-STALL) #2365
Closed
leonida/mandy
HasiKe wants to merge 0 commits from
fence-max-no-stall into main
pull from: fence-max-no-stall
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!2365
Loading…
Reference in a new issue
No description provided.
Delete branch "fence-max-no-stall"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Item: RT-FENCE-MAX-CONFIRM-NO-STALL (claim and analysis in #1608)
What and why
VulkanFence::completed(runtime/src/vulkan_backend.h) handles the NVIDIA case where a lost device first shows as a timeline counter of UINT64_MAX. It confirmed that withvkDeviceWaitIdleunder the submit lock.In a cold world-load boot on an RTX 2070 SUPER (NVIDIA 616.56), that call blocked for 270 s:
submit-lock: held 270089 ms by thread 17780, t=200.490..470.579 s. I resolved the runtime's own submit-lock stack dump against the build's PDB:Pump::run→take_landed→VulkanFence::completed→vkDeviceWaitIdle.Pump::release_loop→Fence::Signal→VulkanQueue::release_held→QueueHolds::pump_ready→execute_now→SubmitMutex::lock, in the middle of submitting a held batch.VulkanFence::completedreader, and a compile worker.Nothing could submit for 4.5 minutes, so the title froze. The loss, and the
LEONIDA_DEVICE_FAULTreport, came 270 s after the fault, so that report describes the device after the wait.QueueHolds::submitted_value(semaphore)already knows the highest value anyone asked of the fence: its initial value (add_fence), CPU Signals (signaled) and submitted Signals. This PR uses that:vkDeviceWaitIdleand no submit lock.Behaviour change, for @quartz-heron-58 (author of 35e38baee)
Case 3 of
vk_fence_lost_by_counterwas "UINT64_MAX on a device that is not lost records no loss whenvkDeviceWaitIdlesucceeds". It is now "UINT64_MAX on a fence a Signal asked that value of records no loss". Two open questions from me:vkDeviceWaitIdle"is also what a driver needs to have returned beforevkGetDeviceFaultInfoEXTanswers". With this change, a loss found this way no longer goes through aVK_ERROR_DEVICE_LOSTresult, so theLEONIDA_DEVICE_FAULTreport is not triggered from here. If you want the report kept, I can add avkDeviceWaitIdleafter the loss is marked, only with the fault diagnostics on. It then stalls only diagnostic runs, and by then the context is already lost.Tests
vk_fence_lost_by_counter, rewritten:vkDeviceWaitIdle.vkDeviceWaitIdle.Results:
mainfbf100b1bthe new test fails (exit 1). With this change it passes.xbox_presentandd3d12_set_descriptor_heaps. Both also fail on unmodifiedmainfbf100b1bon this machine.xbox_presentis the known one (#2259).vk_fence_*,d3d12_fence_*,list_value_wait_budget,xbox_list_value_fallback,wait_registration_*.The 270 s stall itself came from one boot in about five, so I have not shown in a game boot that it is gone. I'll run more cold world-load boots with this change and report there.
Environment: RTX 2070 SUPER, NVIDIA 616.56, Windows 11 Pro 26300, MSVC (VS 18) RelWithDebInfo via
scripts/build_runtime.ps1 -FetchSdl3. No game files in the change or the test.AI-assisted (Claude Code).
One game boot with this PR. AI-assisted (Claude Code).
Runtime:
mainfbf100b1b(which has #2195) plus this PR. Recipe: RTX 2070 SUPER, NVIDIA 616.56, a cold boot (no caches),LEONIDA_ASYNC_PIPELINES=1,LEONIDA_COMPILE_GATE=0,LEONIDA_DEVICE_FAULT=2, the watchdog kicked, 660 s.Result:
the device was lost (a fence's counter read UINT64_MAX, a value no Signal asked for).VK_ERROR_DEVICE_LOST from vkQueueSubmit (present), and the fault report is taken at t=304.8 s. The report sayssubmit lock held by thread 2680 for 0 ms.submit-lock: heldordevice-stallline anywhere in the log. The boot this PR comes from had the lock held for 270 s at this point.nvlddmkm153 came at 16:46:49. The boot started at 16:41:43, so the driver reset and the reported loss fall in the same second, rather than 270 s apart._MS_VS_TransformD_c5fd36bb_Wrapped~153+%PS_DeferredTextured_942fcba4_Wrapped~30.lib_cs_01468, command 16. That is the same shape as the GPU-hang boots in #1608, now without the wait in front of it.This is one boot. The 270 s stall needs the same timing to come back, so this does not show the stall can never happen. It does show that the changed branch is taken in a real loss, and that the report then comes promptly and points at the hang.
Answers to the two questions, as author of 35e38ba (AI-assisted, Claude Code):
Case 3 was not a measured driver case. What I measured (RTX 4080, NVIDIA 621.24) was only the lost case: vkGetSemaphoreCounterValue succeeding with UINT64_MAX, and vkWaitSemaphores succeeding on it, before any call had returned VK_ERROR_DEVICE_LOST. I never saw UINT64_MAX on a healthy device with no Signal for it. Case 3 was a synthetic guard (interposed driver table) so that the value alone was not taken as proof. Deciding from what was asked of the fence covers the same concern, so I have no objection to dropping the vkDeviceWaitIdle. The window lixonik describes (the Vulkan signal done, the bookkeeping not yet updated) is the one place where the new rule can call a healthy device lost, so that needs closing.
The sentence about vkGetDeviceFaultInfoEXT comes from the same machine: there the driver did not answer the fault query until some call had returned VK_ERROR_DEVICE_LOST. I measured that with vkDeviceWaitIdle as the call; I did not test whether a later vkQueueSubmit returning the error serves equally. Your boot above suggests it does on 616.56 (the report follows the next submission). The case not covered is a loss found here when nothing submits afterwards, for example a title that stops on reading the value. A vkDeviceWaitIdle only with the fault diagnostics on, after the loss is marked, would keep the report for that case and stalls nothing in ordinary runs, so yes, I would keep it in that form.
Not checked by me: this PR's head in a game run.
Thanks to both of you. Pushed in
69b1338f2, on top of a merge ofmaind5634defe. AI-assisted (Claude Code).@lixonik's window (P2):
QueueHolds::asking(semaphore, value)now records the value before each of the three calls that can signal a D3D12 fence's semaphore:VulkanFence::signal(vkSignalSemaphore);vkQueueSubmitinVulkanQueuethat signals the fence;vkSignalSemaphore(d3d12_com.cpp).completed()decides fromasked_value, the larger of that record and the existingsignaled()one. A reader that sees UINT64_MAX while such a call is still returning therefore finds the value already announced.vkSignalSemaphore/submit-signal sites in the backend (the fence dispatcher's wakeup semaphore and the queues' progress timelines) are not D3D12 fences;completed()never reads them.vk_fence_lost_by_counter: a Signal(UINT64_MAX) announced but not yet recorded (submitted_valuestillUINT64_MAX - 1) reads as the value, with no loss and novkDeviceWaitIdle.@quartz-heron-58's point 2:
context.device_fault()),completed()still callsvkDeviceWaitIdleunder the submit lock, but only after it has marked the loss, and only the first time.Tests:
xbox_presentandd3d12_set_descriptor_heaps, the same two that fail on unmodifiedmainhere.vk_fence_lost_by_counterpasses with all six cases.Approving 69b1338f2.
Merged into current main (d1dff7949): only
vulkan_backend.hauto-merges, no conflicts. Cross-built with clang-cl 19 + xwin and run under Wine 11.22 on llvmpipe: all 27 fence and queue tests pass (ctest -R "fence|queue_query|presenter_sync|wait_registration"), includingvk_fence_lost_by_counter,d3d12_fence_device_lost_counter,d3d12_fence_timing(held CPU signals) andvk_presenter_sync.Read the diff with lixonik's P2 in mind. Every path that can signal a D3D12 fence's semaphore now announces its value first:
VulkanFence::signal, the fence-signallingvkQueueSubmitinVulkanQueue, and the COM fence callback. The two othervkSignalSemaphore/signal sites are the dispatcher's wakeup semaphore and the sparse-bind progress ticket, whichcompleted()never reads.asked_is cleared withfences_inremove_fence. Deciding from what was asked instead of avkDeviceWaitIdleunder the submit lock removes the multi-minute stall HasiKe measured, and the wait is kept only for fault diagnostics on an already-lost context.The updated test uses
asking(), so it can't run against main's code as a before/after check; the lixonik and HasiKe runs above cover the real-driver side. AI-assisted (Claude Code, Claude Opus 5.5).#2365 | head 69b1338f2e97df44fd3e573f8c26888a76c1bcd7 (merged cleanly with main 48bae6cade49aea69f63eb8871572dcd6931cd4b — no conflicts on current
main) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(list_value_wait_budget|vk_fence_lost_by_counter|xbox_list_value_fallback)$" --output-on-failure(LEONIDA_VK_VALIDATION=1) | red on main: buildingvk_fence_lost_by_counter_testagainstmain'sruntime/src/vulkan_backend.hfailsvk_fence_lost_by_counteratline 90: driver::idle_calls.load() == 0(VulkanFence::completedcallsvkDeviceWaitIdleundersubmit_mutex_) | green on PR+main:3/3CTests (list_value_wait_budget,vk_fence_lost_by_counter— all 6 cases includingsubmit_mutex_contention and in-flightQueueHolds::asking(UINT64_MAX),xbox_list_value_fallback) pass in1.59 son RTX 3090 with0Khronos validation errors (check_no_game_data.py0violations; minor non-blocking note inVulkanFence::completed:first = !context_.is_device_lost()beforemark_device_lost(...)is a non-atomic check-then-set — returning the winning exchange bool frommark_device_lostavoids two concurrentUINT64_MAXreaders both entering theLEONIDA_DEVICE_FAULTvkDeviceWaitIdlebranch) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesClosing 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.