Repository navigation
fix(agc): reuse the GPU timing query pools instead of destroying one per batch - #25421
oneandonlydean merged 1 commit into
Conversation
…per batch Under APS5_PROFILE_GPU the recorder destroyed each batch's timestamp query pool when the batch completed and created a new one for the next batch; only the two-query pools of batch stamps went back to the spare list. GpuTimingEnabled() is fixed for the process, so every spare pool has the same size in either mode, and the full-size pools now go back to the spare list too. On MoltenVK 1.4.2, destroying the pool raced the Metal completion handler that still reads it, and agc_driver_profiled_dispatch_run crashed in MVKCommandEncoder::finishQueries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows compatibility check for
The dispatch and batch-completion logs identified the requested adapter. These are patched Windows-driver runs. Tested with Codex assistance. |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing in the inspected changes blocks merging; the two changed code paths consistently recycle timing query pools, and the spare list remains capped at 64.
What I ran
Reviewed head 7888d2ce7f6f734c5d3a3104446943af877a2b02 using repo_read.py to inspect the prepared diff and relevant source ranges. I did not run tests or build commands.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | Both changed files read |
| Runtime checks | not run | Author-reported results only |
Findings
Blocking
None.
Non-blocking
None.
Not verified
Runtime behavior, tests, builds, other operating systems, and physical-console behavior were not verified. The reported test results in the PR description were not run during this review. review/files.json was not available through the reader, so no excluded-file list was available; the manifest lists both changed files as included.
To get this to a good state
Nothing is required.
|
NVIDIA run on Linux: no regression in the GPU timing, profiled dispatch, recorder and reuse tests from the description. Setup: RTX 3070 8 GB, NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13 (kernel 6.12.115), GCC 13.3.0 Release, validation layer 1.4.335. Base is the merge-base 3b6291c, head is 7888d2c.
Every Vulkan test's log selects the RTX 3070 and shows the layer inserted, none reports it missing, and no log has a AI-assisted: yes |
|
Head Code.
Existing runs. Doorriiaann ran 84 tests on NVIDIA Linux with the layer, and 1tsethan ran 4 tests on an RTX 3070 Ti and a Ryzen iGPU on Windows without the layer. This run adds three things:
Of the 84 tests in the PR's list, only Probe 1: the suite with GPU timing on. I set
That Probe 2: pool reuse count. I added a local, uncommitted counter to the head's
Every reused pool was a full-size pool ( Negative control. None. The PR adds no test. On GPU.
Validation.
Host:
AI-assisted: yes |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Additional evidence from a title, Apple M5 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), Grand Theft Auto V (PPSA04264):
|
What
Under
APS5_PROFILE_GPU,Recorder::releasedestroyed each batch's timestamp query pool when the batch completed, andbeginTimingcreated a new one for the next batch; only the two-query pools of batch stamps went back tosparePools.GpuTimingEnabled()is a process-wide constant, so every spare pool has the same size in either mode: the full-size pools (MaxTimedRanges * 2queries) now go back to the spare list too, capped at 64 as before.This also avoids a crash on MoltenVK 1.4.2 (the Vulkan SDK 1.4.363.0 build). MoltenVK reads a query pool from a Metal command buffer completion handler without retaining it (
MVKCommandEncoder::finishQueries), and that handler can run after the batch's fence signals, so destroying the pool then, which Vulkan allows, made MoltenVK read freed memory.agc_driver_profiled_dispatch_rundied with SIGSEGV on a non-canonical address in that handler, on a Metal completion thread. MoltenVK fixed this on its main branch in KhronosGroup/MoltenVK#2839, which is not in a release yet.It is a workaround for the timing pools only: the occlusion sample pools a batch owns (
batch.samples,endedSamples) are still destroyed when it completes, and so is a timing pool when the spare list is full. The fragment adds a debt entry for that.Tested
macOS 27.3 (Apple M5 Pro), x86_64 Release under Rosetta 2,
main0538bc2 with #17425 and #11049 (needed to build on macOS),ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.agc_driver_profiled_dispatch_run_testsrun directly, MoltenVK:mainWith the validation layer loaded,
mainpasses 10 of 10: the layer changes the timing enough to hide the race, so the crash runs above are without it. A temporary SIGSEGV handler (not in this PR) showed the faulting frame asMVKCommandEncoder::finishQueriesblock, called from-[_MTLCommandBuffer didCompleteWithStartTime:endTime:error:]. On KosmicKrisp (Mesa, also on Metal) the test passes onmain.84 tests that exercise GPU timing, batch stamps or the recorder (
ctest -R 'agc_gpu_timing|profiled_dispatch|target_memo|draw_cache_reuse|image_table_reuse|address_draw_space_reuse|agc_recorder|agc_driver_recorder|prepared_shaders|host_report' -j4 -V), withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer,mainagainst this PR:mainagc_driver_recorderfailsagc_driver_recorder,agc_driver_prepared_shaders_abi_deferred_rectangle_pairs,agc_gpu_timing_complete,agc_gpu_timing_incompletefailVUID-(MoltenVK)VkDeviceCreateInfo-sType-unique, 18vkCreateDescriptorSetLayout-support-09582VUID-(KosmicKrisp)Every log shows the loader inserting the layer (110 times) and no
was not found but was requested by env var VK_INSTANCE_LAYERS. ThesType-uniqueerrors come from the recorder tests' own device (#21965).readGpuTimingreads a recycled pool the same way as before (noVK_QUERY_RESULT_WAIT_BIT, anything other thanVK_SUCCESSdropped), as the two-query pools already were. 64 spare full-size pools hold 64 × 1024 timestamps. No speed claim. Not run on Linux or Windows; there the change only affectsAPS5_PROFILE_GPUruns, which now reuse pools instead of creating one per batch.tools/check_conventions.py --base upstream/mainpasses.tools/debt_fold.py --checkpasses for this fragment (run with only this fragment; two fragments already onmainfail it on their own).tools/pr_overlap.pylists open PRs that touchRecorder.cpp; none of their diffs touchessparePools,beginTiming's pool choice orrelease.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code