perf(agc): wait only for CPU-completion labels before direct consumers #9858
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9858"
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?
Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-22T19:11:42Z.
What
CompletePendingCpuWritessynced the recorder when any completion was pending (Recorder::PendingCompletionLabels() != 0, whichAfterRecordedWorkalso counts) andPendingLabelInfound any pending label in the range.PendingLabelInalso matches labels the GPU stores in stream order. An address-based build calls it over the whole registered heaps (completeSpaceWrites), so nearly every such build found a label there and waited for the open batch under the GPU mutex.It now uses
CompletionLabelIn, the testVulkanDevice's other copied-writer checks make: a label whose store waits for a batch's CPU completion, or a queued one. A label the GPU stores needs no wait: a dispatch flushes queued label stores that overlap its reads, or all of them for a build that holds a lease (VulkanDevice::dispatch), and draws do the same (Draw.cpp), before they are recorded.Found on ASTRO's PLAYROOM (PPSA01325): with
APS5_PROFILE_DRAW=1, every GPU wait over 0.5 ms inside an indirect dispatch's build had the stackShaderResources::Complete→GuestBufferMemory::UploadFinish→completeSpaceWrites→CompletePendingCpuWrites→Recorder::SyncThrough→Recorder::Sync. In 12,181 of 12,181 of those syncs no copied writer overlapped the range, so the label test made them. That was about 905 ms per 10 s of GPU-mutex hold on queue 0x0.Tested
CachyOS (Linux 7.3.0), RTX 4090, NVIDIA 615.78.08.
agc_copied_direct_orderinggains a case: a label stored on the GPU (RecordStoreandNoteLabel) with an unrelated completion pending (AfterRecordedWork). A fresh direct consumer must not submit, and it reads the label's value once the dispatch's queued-store flush has run. WithPendingLabelInrestored it fails with "a fresh direct consumer waited for a label the GPU stores in order". The existing CPU completion label case still passes.ctest -E bda_device -j4): every test passes exceptagc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, which fail the same way onmainon this machine.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V, onmainand on this branch: the 62 tests that runagc_driver_recorder_testspass on both. Neither log reports the missing layer. Both logs have the same fourVUID-VkImageViewCreateInfo-usage-02275messages, fromagc_sampled_storage_base_level_usage(image view usage); the change adds none.APS5_TRACE_SECONDS=120:15and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, log not redirected,mainand this branch in the same session:maina6fc8a467db6b6e15718Both traces have
trace_dropped: queue worker 0x0's event buffer filled about 4 s into the window.totals_fullis false for every thread, so the summary numbers are complete; only the event timeline is short.main:This branch:
Traces:
aps5-trace-a6fc8a467d09-250704.json.gz(main) andaps5-trace-b6b6e15718eb-252018.json.gz(this branch), attached.aps5-trace-a6fc8a467d09-250704.json.gz
aps5-trace-b6b6e15718eb-252018.json.gz
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)Imported from boykopovar/AnyPS5. Originally posted by panicDa3m0n on 2026-10-23T08:10:28Z.
Review: COMMENTED
I read this at
b6b6e15718eb, one commit ona6fc8a467d09, and checked the reasoning against the code at that head and on currentmain(21554447d).The narrower test holds for the labels it drops.
AfterCompletions, which tables it per dword, withbehindCompletionset whenever the completion will store it (Recorder.cpp:3448-3457). It has no wide-label path, soCompletionLabelInsees all of them.behindCompletioninNoteWrittenBack(markBehindCompletion,Recorder.cpp:3498), so it is still waited for.NoteLabelentries, tabled up to 64 bytes or kept inwideLabelsabove that. A queued store of one lands before the commands that read it:VulkanDevice.cpp:4793);Draw.cpp:2683).VulkanDevicealready makes for copied writers (VulkanDevice.cpp:2292,2378,2662).The image callers.
CompletePendingCpuWritesis also called while image resources are built, before their uploads (ShaderResources.cpp4711, 4796, 5014, 5074 and 5108 on21554447d). A label the GPU orders over that memory still lands before the upload reads it:Texture.cpp:2721and3186on21554447d).ReadTextureSurface, through the flush hook (DccMetadata.cpp:769-772).FlushForAccessfirst records a queued label that overlaps the range (Recorder.cpp:1023-1028on21554447d). It then syncs through a pending write over the range (1035-1040), andNoteLabelnotes a label's range as one.#9445 makes the same change. #9445 (Zenodeon, opened 2026-10-21) changes the same condition in
CompletePendingCpuWritesfromPendingLabelIntoCompletionLabelIn. MarcZX10's review there asks only for a branch update and a fresh validation run. The two tests cover different sides:The maintainers may want to keep one of the two changes and both tests.
Against current
main.CompletePendingCpuWritesandCompletionLabelInare unchanged on21554447d.mainhas one caller more, for the FMASK/CMASK range, which also completes CPU writes before the GPU reads, so the change applies to it as well.CONTRIBUTING checks.
mainis the PR's parenta6fc8a467d09, with the same machine and scene. Both traces are attached.mainand on the branch with no newVUID-.PendingLabelInrestored. TheGPUs testedline is filled in.Observations on the numbers, not blockers.
gpu_busy_ms_per_presentgoes from 29.7 to 31.2 ms. That fits the GPU being fed more often once the build stops waiting.CountSync(4)) onmainand on the branch in the same session;I have #9712 open, which also touches
ShaderResources.cppandtests/Recorder.cpp. The overlap bot finds no shared lines with this PR, and neither change depends on the other.AI-assisted: I reviewed this with an AI assistant. The code references above were checked against the head and
mainnamed here.