AGC: a comparison-sampled R32F surface stays a CPU snapshot, compared against guest memory under the GPU mutex after every GPU write #1133
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 fisherjoey on 2026-10-07T13:24:18Z.
Summary
cachedTexturenever views a storage image for adepthComparelookup (source.reset()atGraphics/src/ShaderResources.cpp:315, and the!depthComparecondition at :339 onmaine79c971f). A shadow map rendered on the GPU into host-imported memory is therefore served as a CPU snapshot uploaded into a D32_SFLOAT image. After each GPU write-back into the range, the snapshot's hit rule (equalsCommitted) flushes the pending results, waits for that GPU work through the flush hook, and compares the whole surface with guest memory, all under the GPU mutex.A plain view would not serve the sampler on this GPU anyway. Driver 595.91.07 reports no depth-comparison sampling on R32_SFLOAT or R16_UNORM (
vkGetPhysicalDeviceFormatProperties2); D32_SFLOAT and D16_UNORM support it.Evidence
Demon's Souls (PPSA01341 v1.07), PS Studios movie. Every compare is the same surface:
0x2c25b0000+0x1000000, 1024x1024, fmt 22 (R32_SFLOAT), 4 layers (shadow cascades), on queues 0x30 and 0x40. That is about 10 compares a second, eachequalin 1.3-8 ms (one took 53 ms). In about 1000 compares, one differed.Per 10 s: queue 0x30 holds the GPU mutex 950-1163 ms, and an estimated 0.5-0.7 s of that is these compares. Queue 0 waits 1974-2170 ms for the mutex, 994-1127 ms of it behind queue 0x30. Direct dispatches on queue 0 spend 78-99 us each waiting for the lock.
Proposed fix
Give such surfaces a depth image that follows their storage image on the GPU:
vkCmdCopyImageToBufferfrom the storage image into a device buffer, thenvkCmdCopyBufferToImageinto the depth aspect.APS5_DEPTH_COPY_MIN_KIB).APS5_NO_DEPTH_COPY=1restores the snapshot path.Measured, per 10 s of the movie:
[hooksync]on queue 0x30The attract movie went from 384-407 to 429-439 presents per 10 s (41.8-45.0 fps). The PS Studios movie stayed at 255 presents. It is limited by how the queue 0 worker thread gets scheduled, which I'll file separately.
agc_driver_graphicsandguest_agc_driver_resourcespass.About the 1 MiB floor: without it, a 48x24 R16_UNORM surface also got a copy, and both runs with that build hit the intermittent boot-time crash that looks like #479 (a compute shader reading a garbage descriptor). With the floor, 0 of 2 runs crashed. That is a small sample.
Another route would be to treat R32F as not natively comparable on devices that lack the format feature, and let the shader-side compare from #668 sample a plain view. That would skip the copy but adds ALU work per tap. I have not tried it.
Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07. Measured on
mainatc1241ad0with #157, #861, #864 and #1051, plus the path fix from #1047.I can send a PR for this if the approach looks right.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T18:01:18Z.
The fix described above is ready on a branch, rebased on current
main(cea1ef13): https://github.com/fisherjoey/AnyPS5/compare/main...fisherjoey:AnyPS5:fix/depth-compare-copyOne commit. It keeps
APS5_NO_DEPTH_COPYandAPS5_DEPTH_COPY_MIN_KIB(default 1024) and adds a TechnicalDebt line for the 1 MiB floor and the 3D exclusion. A new GPU test,agc_driver_depth_compare_copy, writes a 512x512 R32F surface with a compute store, compare-samples it, rewrites it and samples it again.agc_driverandguest_agc_driverpass (160 of 160, same two exclusions).I'll open the PR if the approach looks right.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T08:26:29Z.
Please open it as a PR, with before/after numbers for this change alone on the same scene.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:52:53Z.
This is an excellent analysis of the depth surface comparison performance issue. Based on my review of recent PRs related to the AGC driver and shader recompiler, I can provide some context:
The proposed fix of giving such surfaces a depth image that follows their storage image on the GPU seems reasonable. The measured improvements (queue 0x30 mutex held time reduced from 950-1163 ms to 195 ms per 10 s) are significant and would likely improve performance for many titles that use shadow mapping.
Some observations based on similar issues I've seen:
I'd suggest implementing this fix, as it addresses a real performance bottleneck that affects many titles. The fact that the attract movie fps improved from 384-407 to 429-439 presents per 10 s demonstrates the practical benefit.