gpu profile: read MoltenVK's late timestamps again instead of dropping them; vk_gpu_profile runs alone (RT-GPU-PROFILE-NOT-READY) #2942
Closed
github-bot
wants to merge 2 commits from
github-bot/gh-2942 into main
AGit
pull from: github-bot/gh-2942
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
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
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
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.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2942
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2942"
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?
@Tauwni on GitHub · 2026-12-01 20:07 UTC · original
Tauwni:fix/gpu-profile-not-ready-wait→main· +77 −8 · 4 files · 2 commits · closed without mergingClaimed in the coordination issue as: RT-GPU-PROFILE-NOT-READY (#2570)
What and why
LEONIDA_GPU_PROFILE(runtime/src/vulkan_gpu_profile.h) reads a submission's timestamps once, without waiting, when the fence dispatcher sees the submission's timeline-semaphore value. On an Apple M3 with MoltenVK 1.4.2,vkGetQueryPoolResultscan still answerVK_NOT_READYat that point. Every timestamp of that submission was then dropped (unread), andvk_gpu_profilefailed onentries.size() == 3.MEASURED with a temporary
fprintfof the return code:rc=1 used=7, which isVK_NOT_READYfor all 7 timestamps of the test's submission. The real profile loses whole submissions on MoltenVK the same way, not only the test.#2758 made the test skip its checks when a paravirtual GPU resolves no timestamps, on the guess that it was the CI VM. The same thing happens on real Apple hardware, and the cause is this read.
Changes:
runtime/src/vulkan_gpu_profile.hresolve(): onVK_NOT_READY, read again every 1 ms for up to about 50 ms.VK_QUERY_RESULT_WAIT_BIT:FenceWaitDispatcheralso runs pending callbacks for a submission that may not have finished, when the context is marked lost (worker_threw, a failedvkQueueWaitIdle) or the queue is stopping. A wait there could block the resolve thread and shutdown'sjoin(). READ IN CODE (vulkan_backend.h,FenceWaitDispatcher).mutex_is taken, on the profile's own resolve thread, so it never blocks submits.runtime/CMakeLists.txt:vk_gpu_profilegetsRUN_SERIAL TRUE. Its check thatcs heavytakes over twicecs lightper call times the GPU, which a parallel ctest shares.runtime/README.md'sLEONIDA_GPU_PROFILErow and the test's comment now say this. The header's "read on the fence thread" is corrected to the profile's resolve thread.Tested
All MEASURED on an Apple M3 (Mac15,13), macOS 27.0, MoltenVK 1.4.2 (Homebrew), Release build,
main93ffc4821(the branch is now rebased on99a29d10e, no conflict).Red/green, only
vulkan_gpu_profile.hswapped. Same build,vk_gpu_profile_testrun 150 times on its own while a parallel ctest of all the other tests loops beside it:vulkan_gpu_profile.hentries.size() == 3)mainFull
ctest -j8, 159 tests:main:vk_gpu_profilefailed in 3 of 56 runs (two without timestamps, one on the heavy/light ratio).Other checks:
tests/test_ctest_registration.py,tests/test_runtime_paths.pyandtests/test_docs_*.pypass.python -I scripts/check_no_game_data.pyis clean.This is a flake, not a deterministic failure, so there is no single test that is always red on
main. The red side is the 6/150 above.Not run by the author at first: Windows, Linux, AMD/NVIDIA, the paravirtual macOS runner. (Updated after review: since then, Linux on RTX 4070 SUPER and RADV by merzleckeier (comment), and Windows 10 on an AMD RX 9060 XT at
93b95ef87; the paravirtual macOS runner is still not run.) On a driver that never answersVK_NOT_READYafter the semaphore, the change adds nothing but one comparison.GPUs tested: Apple M3 (8-core GPU), MoltenVK 1.4.2, macOS 27.0
AI-assisted: yes — Claude Opus 5.5 (Claude Code) wrote and measured the change. A separate read-only Claude Opus 5.5 reviewer agent audited the diff before this PR. Its findings were applied:
WAIT_BIT;Not checked by a second human yet.
Follow-up, not in this PR (also posted as
finding:in #2570):runtime/src/vulkan_gpu_labels.h:162reads its label timestamps once after the fence, with no retry, and may drop them the same way on MoltenVK.Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Residual cost (added after review)
VK_NOT_READYfor the whole budget costs ~50 ms per submission on the profile's single resolve thread (51 reads, 1 ms sleeps), so at worst ~20 submissions/s are resolved and the queue grows. ~52.7 ms MEASURED on Linux by merzleckeier (comment).VK_NOT_READYcould delayjoin()by ~50 ms per record in that batch. READ IN CODE.LEONIDA_GPU_PROFILE=1), so acceptable. Skipping the retry once the resolver is stopping would be a small follow-up.93b95ef87:vk_gpu_profile_testhas a deterministic sub-case for the retry:VK_NOT_READYtwice, thenVK_SUCCESS, 3 reads, noWAIT_BIT. It is red with the retry disabled and green with it.@merzleckeier on GitHub · 2026-12-01 20:40 UTC · original
Native Linux check of the bounded timestamp retry on
28df9fe5merged into66c79286f. The unmodifiedctest -V -R ^vk_gpu_profile$passed 12/12 with zero validation errors and no skips, three runs per tree on each of RTX 4070 SUPER and Radeon RADV (Ryzen 7800X3D). The generated CTest configuration also showedRUN_SERIALonly with the PR.I then wrapped the first submission’s query function and ran each case three times per adapter and tree. The compute and graphics work still ran on the selected GPU.
VK_NOT_READYresults lost the submission on main after one call. The PR read all seven real timestamps and reported three entries on attempt 4 in all six runs.VK_NOT_READYgave one unread submission on both trees. The PR stopped after 51 calls, 52.724–52.843 ms after the first call, against one on main.VK_ERROR_DEVICE_LOSTstopped after one call on both trees. Every recorded query used the 64-bit flag with the wait bit clear.The latter two cases intentionally fail the fixture’s existing three-entry assertion. This measures the retry mechanics with injected statuses on Linux. A natural MoltenVK delay and physical device loss were outside this check.
MEASURED with OpenAI Codex and a separate read-only review.
@KelboLive on GitHub · 2026-12-01 21:28 UTC · original · reviewed
Correct and safe: the retry only runs on
VK_NOT_READY, stays on the dedicated resolve thread outsidemutex_, cannot outlive or overlap the recording's pool (the pool is recycled only afterresolve()returns), and is a no-op on drivers that answer immediately. On this card the wholevk_gpu_profiletest passes withunread 0and 7 timestamps, andRUN_SERIAL TRUEis actually in the generatedCTestTestfile.cmake.One gap before merge: the new guard is untested. Replacing
tries < 50withtries < 0still passesvk_gpu_profileon NVIDIA, because both the syntheticFakeTsand the real device returnVK_SUCCESSfirst time. Please add a deterministic sub-case invk_gpu_profile_test.cpp— aget_resultsthat returnsVK_NOT_READYtwice, thenSUCCESS— assertingunread == 0and that the stamps are counted. Without it, only the out-of-tree MoltenVK run and merzleckeier's injection exercise the retry.Two small things:
runtime/README.md:462still says "the read on the fence thread" while the header now says "the profile's resolve thread" — make them agree. Andnowis sampled before the retry (:253) but used forbusy_ns/last_done(:292-295), so busy time is stamped slightly early; moving the sample after the loop removes the skew.Worth stating the residual cost: ~50 ms per stubborn record on the single resolve thread, so if a driver answered
NOT_READYfor the whole budget, throughput drops to ~20/s and queued recordings (each holding a query pool) would accumulate — fine for an opt-in diagnostic, but it should be known.Note:
runtime/is being deprecated in favour of the Rust runtimes, so please confirm with the maintainers that this diagnostic tool is still wanted before investing further.@Tauwni on GitHub · 2026-12-02 00:10 UTC · original
@KelboLive thanks for the careful read. Pushed
93b95ef87; point by point:Untested retry: added.
vk_gpu_profile_test.cpphas a new sub-case with a fakevkGetQueryPoolResultsthat answersVK_NOT_READYtwice, thenVK_SUCCESS. It asserts 3 reads,VK_QUERY_RESULT_WAIT_BITnever set,submissions == 1,unread == 0,stamps == 3and the 0.1 ms pipeline time. MEASURED on Windows 10 / RX 9060 XT (driver 32.0.23033.1002),ctest -R "^vk_gpu_profile$":93b95ef87: passes 3/3 and printslate-timestamp retry unit check: OK (3 reads);tries < 50→tries < 0, local only): fails 3/3 atline 473: FakeLate::calls() == 3 && !FakeLate::waited().So the guard is now exercised in-tree. The sub-case sleeps about 2 ms: READ IN CODE (
vulkan_gpu_profile.h:269, 2 × 1 ms).README vs header: fixed.
runtime/README.mdnow says "the read on the profile's resolve thread", as the header does.nowbefore the retry: kept on purpose.nowstands for when the completion was seen, asLEONIDA_GPU_LATENCYmeasures it. Sampled after the loop, up to ~50 ms of our own sleep would go intobusy_nsand pushlast_donelater, which adds skew rather than removing it. READ IN CODE (vulkan_gpu_profile.h:255sample,:268-271retry,:296-297busy_ns/last_done). There is now a one-line comment saying so above the sample.Residual cost: stated in the description, under "Residual cost":
join()could wait that long per record.Other checks at
93b95ef87, MEASURED:tests/test_ctest_registration.pyand the 13tests/test_docs_*.pypass (14 files,scripts/run_standalone_tests.py), andcheck_no_game_data.pypasses on the three changed files (1 run). On this AMD card, the real-device part reads all 7 timestamps (MEASURED, 3/3), so it shows no regression only. Whether the retry fired there was not measured. The MoltenVK run of the new head is pending, on an Apple M3.Deprecation: agreed.
docs/testing.mdsays the C++runtime/is deprecated in favour ofd3d12/and the Rust Vulkan runtime, andruntime.ymlno longer runs on pull requests. A relatedruntime/PR, #2680, was closed for that reason. Maintainers: is this fix to an opt-in diagnostic still wanted? If not, I'll close it.Verdict: NOT READY until a maintainer confirms
runtime/changes are still wanted. The review points are addressed, and the retry has a red/green test on this machine.Checked by a separate reviewer agent on the same machine (numbers recomputed from the raw logs, ctest rerun 1/1); not by a second human yet. AI-assisted: yes (Claude Code).
@Tauwni on GitHub · 2026-12-02 00:21 UTC · original
Mac check of
93b95ef87:vk_gpu_profilepasses on an Apple M3 with MoltenVK 1.4.2.MEASURED, Release build, head checked to be
93b95ef87:ctest -R "^vk_gpu_profile$", alone, 3 runslate-timestamp retry unit check: OK (3 reads)andqueue: 1 submissions, 7 timestampsvk_gpu_profile_test150 times whilectest -j7 -E "^vk_gpu_profile$"loops alongsideFor comparison, in an earlier run of the same harness, the build with
main's version of the header had 6 of 150 runs with no timestamps.READ IN CODE: the test fails unless the queue has 1 submission, 7 timestamps, 0 unread and 0 dropped, so each pass also means 0 unread.
Only
vk_gpu_profilewas run at this head.Not checked by a second agent or human yet.
AI-assisted: yes (Claude Code)
@aslan2142 on GitHub · 2026-12-02 00:44 UTC · original
Thank you for the careful work and verification on MoltenVK timestamp handling and standalone test execution. The legacy C++/Vulkan runtime/ directory is now frozen and deprecated as active development focuses on the d3d12/ and clean-room Rust vulkan/ tracks, so we are closing open legacy runtime/ PRs. We really appreciate the effort that went into this.
Pull request closed