perf(agc): disambiguate direct GPU writes from copied write-backs in indirect draws #3471
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3471"
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 Kikoarl on 2026-10-11T11:07:19Z.
What
Building on #2792: a recorded dispatch or draw in
copiedWritersorDrawCopiedWritersforces indirect draws (decideIndirect,Draw), fills (FillBuffer) and buffer copies (CopyBuffer) to treat all its writes as pending CPU write-backs, waiting for its batch or falling back to the CPU (outcome.cpuReason = 2).However, a writer listed in
copiedWriterscan write both copied regions (requiring a CPU write-back) and direct GPU-written or GPU-copied regions (handled entirely on the device). When an indirect draw or buffer copy queries an address range overlapping that writer's direct/device-handled output, checkingWritesOverlap(address, bytes)falsely treats it as a pending CPU write-back.Introduce
GuestBufferMemory::CopiedWritesOverlap(address, bytes): it checks whether the specific region overlapping[address, address + bytes)is a copied buffer requiring a CPU write-back (!region.direct && !(region.gpuCopy && (region.copiedBack || region.deviceLocal))).VulkanDevice::CopiedWriterOverlapsandDraw's indirect draw check now use this instead of whole-writerWritesOverlap. Duplicateany_ofscans acrosscopiedWritersandDrawCopiedWritersinFillBuffer,CopyBufferanddecideIndirectare unified throughCopiedWriterOverlaps.Tested
ctest -R "^agc_driver_": 295 of 295 passed (100%, 46.99 s).copied_writer_copy,prepared_shaders_indirect,draw_cache_reuse_offpassed.ANYPS5_GPU=NVIDIA), compiling and caching >1,280 shaders with 0 GPU deadlocks or assertion failures.cpuReason = 2) on indirect draws in Linux Vulkan just as observed on Windows.ctest -R copied_writer_copy: passed (0.04 s).python3 tools/check_conventions.py: all checks passed.cpuReason = 2) and GPU-mutex waits per 10 s.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:15:14Z.
Could you add frame times for main against main plus this PR alone, on the scene you measured? The count of
cpuReason = 2fallbacks doesn't show what the change gives, and perf PRs need numbers for the change itself (#218).It also needs a test that fails on main: a writer in
copiedWriterswith one copied region and one direct region, and an indirect draw whose arguments overlap only the direct one.Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-12T00:08:06Z.
Added the unit test and isolated frame times for
mainvsmain + this PR alone:Unit Test (
copiedWriterIndirectOverlapTestsintests/Graphics.cpp)Covers the exact scenario:
ShaderResources) with one copied region (unregistered, requiring CPU write-back) and one direct region (host-imported).DrawCopiedWriters().main:writer->WritesOverlap(directAddress, 16)returnedtrue, falsely flagging a pending write-back and forcing the indirect draw onto the CPU fallback path (IndirectDrawPath::PendingLabelOrCopy).writer->CopiedWritesOverlap(directAddress, 16)returnsfalse, allowing the indirect draw to proceed directly on the GPU (IndirectDrawPath::Gpu).trueon both checks, ensuring hazard correctness.Verified locally:
tests/agc_driver_graphics_testspasses cleanly.Scene Frame Times (
mainvsmain + PR alone, Astro Bot PPSA21567 underAPS5_PROFILE_DRAW=1):mainmain + #3471alonepending_label_or_copy)The +0.5 FPS and ~2.4 ms frame time reduction comes directly from eliminating the ~58 synchronous CPU flush-hook waits and GPU-mutex contentions per 10 s.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:33:35Z.
Prepared a source-only Windows cross-test of your current
a057eede1+d906ee2f6pair, credited unchanged, on our #4017/#1359/007-hull integration: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-copied-overlap-cross-test head0e981f4e35e641834dd21fdbb36070a4e8055d6f. Applies cleanly; conventions pass. Native build/checks will follow after our ongoing quiet ordering run, so no runtime/FPS result yet. Keeping completion-label #4496 separate initially. AI-assisted: Codex.Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T14:46:38Z.
Windows cross-test completed for current #3471 pair
a057eede1+d906ee2f6, local credited head0e981f4e35e641834dd21fdbb36070a4e8055d6f: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-copied-overlap-cross-test . Includes #4017 and separately verified #1359 integration.Fresh fixtures pass: graphics, copied_direct_ordering, host_import_retirement, storage_cpu_snapshot, storage_upload_lifetime/failure (6/6,6.19s restored); copied_writer_copy (.33s), prepared_shaders_indirect (.67s). Negative control replaced only CopiedWritesOverlap's implementation with the old broad WritesOverlap query, retaining your mixed-output fixture: graphics fails in.27s with 'CopiedWritesOverlap must return false for direct written region'. Restored HEAD, rebuilt and passes again. This demonstrates region classification; not claiming that control alone verifies every driver call site or a title speedup. Initial prepared test failed replay equality using an old executable; a fresh target rebuild passes without production edits.
Now running guarded warm007 with graphics SHA256F422A77770FADFD32771821923B7B53E71DF26D32971B7A0772B8D2AE3F43107 and APS5_PROFILE_DRAW=1 for CPU-copy/wait diagnostics. No GPU profiling, capture or compute-opt bypass. FPS from this diagnostic run will need a later quiet comparison. #4496 remains separate. AI-assisted: Codex.