vulkan: read the retirement records under their own lock (RT-RETIRE-TICKET-LOCK) #2402
Closed
leonida/mandy
wavehs wants to merge 0 commits from
retire-ticket-lock into main
pull from: retire-ticket-lock
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!2402
Loading…
Reference in a new issue
No description provided.
Delete branch "retire-ticket-lock"
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.
Claimed in the coordination issue as: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7201897573
(follow-up to DadaCap's finding: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7201692029)
Depends on: none.
What and why
VulkanContext::completed_retire_ticket()andwait_retire_ticket()readretire_tickets_undersubmit_mutex_, so a caller that only asks what retired waits behind whoever holds that lock — a queue submission, or avkDeviceWaitIdleunder it. That is the hop DadaCap described: the held-work releaser inside a gateSignaland the progress watch both want the completed ticket and neither needs to submit.retire_tickets_now has its own innermostretire_mutex_:record_submit_lockedandretire_queue_idle_lockedtakesubmit_mutex_ -> retire_mutex_;completed_retire_ticketandwait_retire_tickettakeretire_mutex_alone; thewait_submitted_lockedsnapshot takes it under thesubmit_mutex_its caller already holds;retire_mutex_beforesubmit_mutex_, so the order is unchanged everywhere else;poll_retirement_lockedtry-locksretire_mutex_on purpose: a query already in progress watches the same timelines, and waiting for it while holding the submit lock is what this change removes.Queue teardown is still safe: it marks the queue's entries idle under
retire_mutex_(viaretire_queue_idle_locked) before destroying the timeline semaphore, so an in-flight query either finishes first or is skipped because the entry is idle.Test
New CPU-only ctest
retire_ticket_lock(runtime/test/retire_ticket_lock_test.cpp): one thread holdscontext.submit_mutex()for 500 ms, the main thread callscompleted_retire_ticket()and must get ticket 0 in under 200 ms.Tested
macOS 27.2.1 arm64 (Apple clang, CMake/Ninja, RelWithDebInfo), portable runtime build, no GPU and no game files:
ctestafter a full build: 114/114 passed (63-66 s).retire_ticketsandreplay_pipeline_compile_unlockare in that run;submit_mutexis Windows-only and is not part of the portable set.python3 -I tests/test_ctest_registration.py-> 6 tests, OK.python3 -I scripts/check_no_game_data.pyon the four changed files -> exit 0.python3 -m compileall -q make_game.py tools tests-> OK.Not built here: the Windows runtime (MSVC) and the title. The change is portable C++17 and the new target links
Vulkan::Headers Threads::Threadslike its neighbours, but the Windows build should confirm it.AI-assisted.
Native Windows 11 x64, MSVC 19.44 Release:
gta6rt.exebuilt at PR head35eb7b4a40. All four focused CPU tests passed, including the Windows-onlysubmit_mutex, plusretire_ticket_lock,retire_ticketsandreplay_pipeline_compile_unlock.I also checked the change with two outstanding submissions on an RTX 4090 (driver 616.64). The same synthetic probe ran three times on the PR and three times on its parent
2d43417d49. Each submission waited for its own host gate value and signaled a real Vulkan timeline. The reader ran on a separate thread while the main thread heldcontext.submit_mutex(). I waited for the GPU counter to reach each released value independently.All three runs agreed on each revision. On the parent, each reader remained blocked throughout the 400 ms observation window. This covers both the query and wait paths with live semaphore values. The stock
vk_queue_testalso passed on the PR: copy-to-direct and direct-to-compute readbacks had zero bad bytes. The queue test and all six probe runs recorded zero Vulkan validation errors. The probe uses synthetic submissions and measures this lock dependency only.Independently checked head
35eb7b4a4on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK1.4.363.0, WSLllvm-mc 21.1.8, no game files.Local build & runtime verification:
retire_ticket_lock_test,retire_tickets_test, andd3d12_m4_compute_test(zero new warnings in PR files).retire_ticket_lock_test: 5/5 consecutive runs PASS (completed_retire_ticket returned 0ms after a submit lock was held).retire_tickets_test: PASS (out-of-order queue completion kept the retirement prefix safe).d3d12_m4_compute_test(LEONIDA_VK_VALIDATION=1): 1924/1924 words matched (error 0) on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02), 0 validation errors.Static lock & lifetime findings on
35eb7b4a4:retire_tickets_accesses holdretire_mutex_, and every nested path acquiressubmit_mutex_beforeretire_mutex_(no AB-BA inversion found).Nis published before its retirement record exists (runtime/src/vulkan_backend.h:2058-2064, 1992-2013; callerd3d12_vulkan_device.cpp:5051-5064):Nviafetch_addbefore acquiringretire_mutex_to insert the retirement record. IfN-1has already retired, a concurrent waiter can readN, snapshot an emptyretire_tickets_list, skipvkWaitSemaphores, and returnN-1while submissionNis still outstanding on the GPU (the old sharedsubmit_mutex_prevented this window; console-heap teardown ignores the returned prefix before destroying its buffer).Nunderretire_mutex_after installing its record (and add a test holdingN's timeline unsignaled to provewait_retire_ticket(N)cannot return early).retire_mutex_(runtime/src/vulkan_backend.h:2024-2033, 2631-2645, 2661-2665, 1993-2012):retire_mutex_before destroying the semaphore even though a counter query already insideretire_mutex_can still be reading it. (Separately, on successful idle,wait_retire_ticketcopies raw semaphore handles and waits outside the lock, which is an inherited teardown lifetime window.) Synchronizing failed teardown with in-flight queries and pinning timelines across waits closes both.try_lockin the progress sample can feed a false hang exit (runtime/src/vulkan_backend.h:2240-2248, 2281-2286, 2336-2353):retire_mutex_try-lock returns0withVK_SUCCESS, which the watchdog treats as pending unretired work after any submission; repeated misses can tripLEONIDA_HANG_EXIT_Son an idle GPU. Representing an unavailable sample explicitly so it does not advance the hang timer avoids false triggers.AI-assisted.
Single-variable A/B game-run check on Linux + Wine 11.22 + NVIDIA RTX 3070 Ti 8 GB (Profile M), per #2464. Both arms started from the exact same byte-for-byte warm cache and overlay snapshot (cloned post-cold-baseline), with identical recipe and hands-free input script (
0env differences apart from the per-run capture folder;runtime_sha256differs as expected). Numbers independently checked from raw logs and resource samples by a second agent (codex/gpt-6-luna) and cross-verified before posting.PROVISIONAL (n=1 per side).Reading:
n=1per side, PROVISIONAL): Throughmenu -> story load -> world loadon RTX 3070 Ti 8 GB (NVIDIA 620.73.04, Linux + Wine 11.22), PR #2402 introduced 0 deadlocks, 0 releaser stalls, 0 list-value gate timeouts, and 0 device losses, with comparable frame rates (peak86.57vs85.15frames/s; story-load windows5.50–8.15vs5.06–8.98frames/s) and the same clean-mainmissing-shader world-entry end class (160.18 sB vs174.33 sA).playpast world entry (cleanmainshaders stop at world entry beforeplay; long-run soak inplaystill needs a run past world entry).AI-assisted: Antigravity (Gemini 4 Neon) + Codex (
gpt-6-lunaindependent verification); no game data.#2402 | head 35eb7b4a4071897c5337ba67c428918b15c08ed1 (merged cleanly with main 829530dbd0196aa817dbec74aaafc79407b94b57 — no conflicts on current
main) |ctest --test-dir runtime/build -C RelWithDebInfo -R "^(retire_ticket_lock|retire_tickets|submit_mutex|replay_pipeline_compile_unlock|vk_queue|d3d12_bindless_churn|d3d12_compute)$" --output-on-failure(LEONIDA_VK_VALIDATION=1) | red on main: buildingretire_ticket_lock_testagainstmain'sruntime/src/vulkan_backend.hfailsretire_ticket_lockatline 55: waited < 200(completed_retire_ticket returned 515ms after a submit lock was held) | green on PR+main:7/7CTests (retire_ticket_lock—0ms after a submit lock was held,retire_tickets,submit_mutex,replay_pipeline_compile_unlock,vk_queue,d3d12_bindless_churnexercisingrelease_retired(context.completed_retire_ticket())across 96 direct+compute frames with0vkDeviceWaitIdle, andd3d12_compute) pass in45.97 son RTX 3090 with0Khronos validation errors (10/10test_ctest_registration.py+test_text_write_line_endings.pyOK,check_no_game_data.py0violations;timbot103's static note on movingsubmitted_ticket_.fetch_addinsideretire_mutex_inrecord_submit_lockedstill applies at head35eb7b4a40) | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yesNative Windows 11 + AMD Radeon RX 7900 XTX 24 GB A/B game-run check (
main791899f65vsmain+#240235eb7b4a4), per#2464.retire_ticket_lock_testpassed (completed_retire_ticketreturned in0 mswhile the submit lock was held).first-run UI/menu, unattended): 0 faults, 0VK_ERROR_DEVICE_LOST, 0 regressions; GPU direct latency0.64 msavg (5.0 msmax,5.5%busy) vsmain0.74 msavg (5.8 msmax,6.5%busy), VRAM identical (4,982 MiB).Independent check on Windows (not the author), at
35eb7b4a4.retire_ticket_lock_testand ran it: passed —completed_retire_ticket returned 0ms after a submit lock was held (ticket 0).Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.
AI-assisted: yes (opencode).
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.