Repository navigation
perf(agc): count the finisher's pending writes in a fixed table - #235
Merged
utkuhalis merged 1 commit intoDec 5, 2026
Merged
Conversation
The draw finisher kept a hash map entry per 1 MiB block that a pending draw writes, and copied each draw's write ranges to uncount them later. The worker allocated both for every draw and the finisher freed them, about 13% of the worker's busy time and 9% of the finisher's in a GTA V scene. Count the blocks in a fixed table of 4096 slots instead: blocks that share a slot only send a query to the walk over the pending jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thanks, nice to see the per-draw allocations go. I checked that uncounting from
The A/B is fair and the doc line matches the code. We'll merge once CI is green. |
Collaborator
|
Merged, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
With
APS5_DRAW_PIPELINE, the draw finisher counts the 1 MiB blocks that its pending jobs write, so that a pending-overlap query can answer "no overlap" without walking the jobs (APS5_NO_PENDING_WRITE_BLOCKSturns this off). The counts were kept in anstd::unordered_mapwith one node per block, and every job also copied its write ranges intocountedWritesso they could be uncounted later. The queue worker allocated both for every draw and the finisher thread freed them. On macOS under Rosetta, freeing memory allocated by another thread is slow. In a GTA V scene this was about 13% of the queue worker's busy time and 9% of the finisher's.This PR keeps the counts in a fixed table of 4096 slots indexed by the block number, and uncounts from the job's own
writes, which stay unchanged while the job is pending. No memory is allocated per draw. Two blocks 4 GiB apart share a slot, so a shared slot can only make the counts say "maybe", and the query then walks the pending jobs as before. The answers are unchanged.docs/dev/ENVIRONMENT.mddescribes the table underAPS5_NO_PENDING_WRITE_BLOCKS.Tested
macOS 27.2 (Darwin 27.2.0), Apple M5 Pro, MoltenVK 1.4.2. The binaries are x86_64 under Rosetta.
Tests: I ran the 179
agc_drivertests that run with the draw finisher or the draw pipeline, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, onmainand on this branch.agc_driver_pending_write_blocks,_verifyand_offpass.main. They are thecolor_memo_*andtarget_memo_*tests,draw_allocations_draw_pipelineand_plan_verify,draw_recapture_on_change_finisher, thepipelined_flush_read_order*tests and thestorage_write_back_overhang_*tests.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, using the Khronos validation layer vulkan-sdk-1.4.363.1 built from source for x86_64. In both logs the loader inserts the layer 195 times and never reports it as not found. The results are the same 135 passes and 44 failures, and the only validation error isVUID-vkCreateDescriptorSetLayout-support-09582, 4 times in each log, so this PR adds none.Performance: GTA V (PPSA04263, 01.011.001), in the bank scene of the prologue, in Performance mode (not the title's default graphics mode). Each run covers 70 s from arrival in the scene, without input, with
APS5_TRACE_SUMMARY_EVERY=10. The builds were run alternately, A, B, A, B.GTA V does not run on
main's driver library alone. Both builds are themainof 2026-12-04 plus the same unmerged local changes, with the A build lacking only this commit:Both builds ran with
APS5_DRAW_PIPELINE=1 APS5_PIPELINE_DISPATCH=1 APS5_PIPELINE_DISPATCH_MISSES=1 APS5_ASYNC_DRAW_COMPILE=1 APS5_ASYNC_PIPELINE_WORDS=1 APS5_NO_ADAPTIVE_STAGING=1.Without this PR the mean is 14.93 FPS, and with it 15.49 FPS, about 4% more. Both B runs are above both A runs, but the gap is small compared with the run-to-run spread of the A runs. In a Metal System Trace of the same scene,
countPendingWritesanduncountPendingWritesleave the profile, and the queue worker, the finisher and the committer are on the CPU about 20% fewer samples.tools/trace_digest.pyof A2 and B2A2:
B2:
The four
aps5-summary.jsonlfiles are available on request.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