perf(agc): back the GDS with anonymous shared memory on integrated GPUs and keep its DMA_DATA on the GPU #13159
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13159"
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 Gonic0 on 2026-10-30T04:34:13Z.
What
Builds on #9385. Until it merges, this branch carries its commits (merged at
ec471877d3); only the top commit,57190a6629, is new here.The GDS is a 64 KiB private anonymous guest mapping (
Pm4::GdsAddress). On MoltenVK the GPU cannot import that mapping: registered for the GPU as an experiment, its host import failed atvkAllocateMemory(-2) (APS5_TRACE_HOST_IMPORT=1). So DMA_DATA through the GDS stays on the CPU and waits for the GPU:GuestMemory::Read, whose flush hook waits for the recorded batches writing it (syncThroughUnlocked, which no performance timer covers).This change, on top of #9385:
VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) withVK_EXT_external_memory_host, the Vulkan device requests an importable GDS when it is created (Pm4::RequestImportableGds).GdsAddressthen backs the GDS with anonymous shared memory:shm_open(SHM_ANON), 64 KiB, mapped shared with CPU read and write, zeroed, and the descriptor closed. This is not direct memory, so the title's direct memory pool andsceKernelAvailableDirectMemorySizeare unchanged, and the object has no name a title could open. Its host import succeeds on MoltenVK.Pm4::GdsImportable()reports the backing actually obtained. If the shared mapping fails, if the request was not made, or if the GDS was first used before the device made it, the GDS keeps the private mapping and everything behaves as with #9385 alone.APS5_NO_SHARED_GDS=1forces that.preparePacketMemory, a GDS destination first tries the GPU copy behind a pending source (copyBehindPendingSource, withdecodeCopydecoding GDS to memory and memory to GDS), then #9385's idle-GDS path, then the existing store path (ResolveStore, which #9385 extends to GDS destinations, thenWriteLabelOnGpu), which records the store on the GPU behind the queued work instead of draining. A GDS to memory copy behind pending GDS writes is recorded on the GPU the same way. With a private GDS, as on any discrete GPU,decodeCopyreturns nothing for the GDS and the store path is skipped for it, so those devices take #9385's paths unchanged.gdsWritesPendingalso counts the GPU writes this change records into the GDS (VulkanDevice::StoresPendingOver), so #9385's idle path does not take a GDS that a recorded copy or store still writes. In the test below, removing that check did not fail: the idle path's CPU write still landed after the recorded copy. The check keeps such a fill on the GPU instead of on that path.DecodeMemoryCopyandResolveStoreare unchanged by this commit. On an integrated GPU the shaders' GDS bindings (ShaderResources,AddWritable(gds, GdsBytes, true)) now find the import and use it in place.Devices that are neither integrated nor discrete (
CPU,VIRTUAL_GPU,OTHER) keep the private GDS. I ran only an integrated GPU (Apple M5 Pro).Tested
Apple M5 Pro, macOS 27.2, MoltenVK from Vulkan SDK 1.4.363, x86-64 Release under Rosetta 2.
mainalone does not build on macOS. I ran everything in a tree with the open macOS port PRs onmain39fc186c97with #9385 merged, and this commit applied; it applies unchanged there.agc_driver_gds_dma_fill(#9385's test), extended:APS5_NO_SHARED_GDSis not set.agc_driver_gds_dma_fill_privateruns the same test withAPS5_NO_SHARED_GDS=1: same values, #9385's drain, no GPU copy or store over the GDS.Negative controls, each of which fails
agc_driver_gds_dma_fill:decodeCopywithout the GDS cases: the copy out of the shared GDS is not recorded on the GPU;gdsWritesPendingwithoutStoresPendingOverdoes not fail the test, as said above.With
VK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, these 44 CTest entries pass:agc_driver,agc_driver_gds_dma_fill,agc_driver_gds_dma_fill_private,agc_driver_gds_append_consume,agc_atomic_gds_size,agc_dma_data_tests,agc_driver_pipelined_dma,agc_driver_pipelined_dma_draw_pipeline,agc_driver_pm4,agc_guarded_memory_loadsand the 34agc_storage_,agc_driver_storage_andagc_driver_linear_target_entries. The only validation message isVUID-VkDeviceCreateInfo-pProperties-04451, from the tests' own device creation on MoltenVK.PPSA21564 01.007.000, the logos before the intro. Per frame there is one 4-byte DATA → GDS fill on queue 0x40 behind GDS writes, which drained for 3 to 6 ms on that queue (the graphics queue waits on it), and about 15 four-byte GDS → memory copies read on the CPU. The base is the tree with #9385 and without this commit (
99fffc44a1, its revert); the change isc4562034f0. Alternating, no profiling switches,APS5_TRACE_FRAMES=150:240, four pairs:FPS is 480 presents over the time between dumped frames 5 and 13; the load average is the one-minute value after each run. The host was not idle: a browser and the desktop stayed open, and the first pair ran while the load was still falling from earlier runs. Round 2 is the only one where this change was slower. Rounds 3 to 8 give 28.9 to 33.1 FPS for the base against 33.0 to 36.3 with this change, frame p50 28.7 to 32.6 ms against 25.2 to 29.1 ms. An earlier set on a busier host (load 7 to 10) moved the frame p50 from 41.6 to 43.1 ms to 36.4 to 37.2 ms, with flat FPS. No run reported an unexpected copy path, and the dumped frames show the logos intact.
Base (
99fffc44a1, round 5):This change (
c4562034f0, round 6):Traces: base, this change
Not tested on Linux, Windows, a discrete GPU or a software Vulkan driver.
Overlap
preparePacketMemory; it should land first.GdsBindingBytes; whichever lands second sizes the shared mapping here to that.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