perf(agc): bind the changed copy-back's buffers through push descriptors #15792
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15792"
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 imellag on 2026-11-04T15:18:38Z.
What
#6185 copies a staged region back through
StagingCopyBack.comp, which reaches its three buffers through buffer device addresses. To have those addresses, every staging buffer and every shadow copy is now created withVK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT(gpuCopyUsage).On MoltenVK both halves of that cost time. MoltenVK keeps every buffer created with that usage in one device-wide list (
MVKDevice::_gpuAddressableBuffers). In every encoder whose pipeline uses physical storage buffer addresses, it callsuseResourceon every buffer in that list (MVKCommandEncoderState.mm,encodeGPUAddressableBuffers). So the staging buffers make the list longer, and the kernel adds one more such encoder after each staged dispatch.Stray (PPSA02100) stages about 2 GB per 10 s through these regions. It went from 11.4 to 9.7 fps between
maina4eca2a056and1e658521a0.APS5_NO_CHANGED_COPY_BACK=1alone restores 11.3 fps. With the variable set, though, 2 of 5 runs stopped at about 33 s on a queue 0x20WAIT_REG_MEMthat timed out, which is the rollback #6185 fixes. Local variants (not in this PR) split the cost:main)APS5_CHANGED_COPY_ALWAYS=1(kernel without its read of the import)The kernel is the larger half, and the bytes it reads aren't what costs; the address flag is the rest.
This PR binds the kernel's buffers as descriptors where the device has
VK_KHR_push_descriptor, as #12120's depth pass does:StagingCopyBackBound.compapplies the same per-byte rule tostd430storage buffers. Each buffer is bound at its offset rounded down tominStorageBufferOffsetAlignment, and the dwords before the range are skipped through a base index in the push constants.Recorder::RecordBoundChangedCopypushes the four descriptors and dispatches. It splits a range onmaxComputeWorkGroupCountas before, and onmaxStorageBufferRangetoo.APS5_TRACE_COPY_BACKis bound the same way.main. A device with push descriptors but without buffer device addresses now gets the changed copy-back too; onmainit copied whole ranges.APS5_NO_CHANGED_COPY_BACKandAPS5_CHANGED_COPY_ALWAYSkeep their meaning.Tested
macOS 27.2, Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2.
maindoesn't build on macOS on its own, so both sides use the support branchsupport/macos-boot-1103merged withmainb11c7bf84f, plus #15700, #15755 and #15756 for the build. The change side is that tree + these two commits.New
agc_bound_changed_copy(agc_driver_recorder_tests --bound-changed-copy-only): 70001 dwords at buffer offsets 4, 0x1008 and 0x10c, so every binding needs a base index. It checks every stored word against the per-byte rule, the count of words where both sides changed the same byte, and guard words before and after the target range. It passes. Its device enablesVK_KHR_push_descriptorwhen the device has it; the context of the other recorder tests keepspushDescriptorsoff as before.The test runs the same check three times, on copies of the device's context (
b004620164, after @frankea's review): with the device's limits (one dispatch), withmaxComputeWorkGroupCount[0]set to 16 (1024 dwords per dispatch, 69 dispatches, a short last one), and withmaxStorageBufferRangeset to the offset alignment plus 1001 dwords (1001 dwords per dispatch, so each chunk's aligned binding and first dword differ from the previous one). Every word, the guards and the counter summed over all dispatches match in all three. Onmainmerged atb30dcca60e, withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:agc_bound_changed_copy,agc_changed_copy,agc_bda_stagingandagc_bda_staging_boundpass, noVUID-lines, nowas not found but was requested by env var VK_INSTANCE_LAYERS. That tree needs #16591, #17767 and theBasicString.cppstd::mintype to build on macOS; they are not part of this PR.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R '^(agc_changed_copy|agc_bound_changed_copy|agc_bda_staging|agc_read_written_staging|agc_copied_write_back|agc_copied_direct_ordering|agc_sparse_run_import_copied|agc_adaptive_staging|agc_draw_inputs_copied|agc_driver_copied_writer_.*|agc_driver_storage_flush_ordering|agc_driver_vertex_target_range_copied)$' -V:VUID-VkDeviceCreateInfo-pProperties-04451only (the device created withoutVK_KHR_portability_subset, #13942), once per test. Neither haswas not found but was requested by env var VK_INSTANCE_LAYERS.Stray,
main1e658521a0+ the support branch + #11551 + #9356 (needed to reach gameplay on MoltenVK), 3840x2160,APS5_PROFILE_DRAW=1, the same scene, the two sides alternated. The copy-back code is the same at1e658521a0andb11c7bf84f.tools/trace_digest.pyof the summaries, gameplay intervals only:Base (
1b81580dc875):This change (
4e408effcaba):WAIT_REG_MEMtimeout; no sample was taken, and the read trap deadlocks of #15729 and #15742 stop the game the same way). This change: 11.25 and 11.30 fps.The
aps5-summary.jsonllines of interval 13 above, base (cbd-B-1) then this change (cbd-C-2):The summary files of every run above, of the Lana and GoW runs below and of the variants in the table under What are attached as the release
perf-bound-changed-copy-back-20261104, with a README.Lana (PPSA19450) and God of War Ragnarök (PPSA28997) on the same trees, two rounds each: Lana 31.40 and 31.66 fps on the base, 31.67 and 31.53 with this change; GoW 54.23 and 54.49 fps, 54.36 and 53.69.
tools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.py --branch perf/agc-changed-copy-back-descriptorsfinds no overlapping lines among the PRs it could merge. It could not compare 73 PRs that conflict withmain; of the 54 that shareGuestBufferMemory.cpporRecorder.cpp, two touch the changed copy-back:APS5_GPU_HEAP) givesRecordChangedCopya heap pipeline;RecordBoundChangedCopywould need the same there if both land.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)