Skip to content

perf(agc): disambiguate direct GPU writes from copied write-backs in indirect draws - #3471

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Kikoarl:perf/agc-copied-writes-overlap
Oct 13, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Kikoarl:perf/agc-copied-writes-overlap

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What

Building on #2792: a recorded dispatch or draw in copiedWriters or DrawCopiedWriters forces 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 copiedWriters can 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, checking WritesOverlap(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::CopiedWriterOverlaps and Draw's indirect draw check now use this instead of whole-writer WritesOverlap. Duplicate any_of scans across copiedWriters and DrawCopiedWriters in FillBuffer, CopyBuffer and decideIndirect are unified through CopiedWriterOverlaps.

Tested

  • Linux x86_64, CachyOS (Kernel 7.2.9), Intel Core i7-13700T, NVIDIA GeForce RTX 5060 Ti 8GB (NVIDIA 615.78.08, Vulkan 1.4, Subgroup 32), Clang/GCC, Release:
    • ctest -R "^agc_driver_": 295 of 295 passed (100%, 46.99 s).
    • Indirect draw & copied writer tests: copied_writer_copy, prepared_shaders_indirect, draw_cache_reuse_off passed.
    • PPSA21567 (Astro Bot) live execution on Linux native (Wayland, 1920x1080):
      • Runs cleanly on the discrete GPU (ANYPS5_GPU=NVIDIA), compiling and caching >1,280 shaders with 0 GPU deadlocks or assertion failures.
      • Eliminates false-positive CPU fallbacks (cpuReason = 2) on indirect draws in Linux Vulkan just as observed on Windows.
  • Linux x86_64, 13th Gen Intel(R) Core(TM) i7-13700T, Mesa Intel Graphics (RPL-S, ANV driver Mesa 25.1-devel), Clang 18, Release:
    • ctest -R copied_writer_copy: passed (0.04 s).
    • python3 tools/check_conventions.py: all checks passed.
  • PPSA21567 (Astro Bot), Windows 11, Ryzen 7 7800X3D + RTX 5080:
    • In scenes with intensive compute passes producing indirect draw parameters alongside unrelated copied buffers, eliminates ~55–62 false-positive CPU fallbacks (cpuReason = 2) and GPU-mutex waits per 10 s.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions github-actions Bot added the agc libSceAgc* label Oct 11, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Could you add frame times for main against main plus this PR alone, on the scene you measured? The count of cpuReason = 2 fallbacks 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 copiedWriters with one copied region and one direct region, and an indirect draw whose arguments overlap only the direct one.

@Kikoarl
Kikoarl force-pushed the perf/agc-copied-writes-overlap branch from fd293be to 112d0a9 Compare October 12, 2026 00:07
@Kikoarl

Kikoarl commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Added the unit test and isolated frame times for main vs main + this PR alone:

Unit Test (copiedWriterIndirectOverlapTests in tests/Graphics.cpp)

Covers the exact scenario:

  1. Allocates a writer (ShaderResources) with one copied region (unregistered, requiring CPU write-back) and one direct region (host-imported).
  2. Lists it in DrawCopiedWriters().
  3. An indirect draw whose arguments overlap only the direct region:
    • On main: writer->WritesOverlap(directAddress, 16) returned true, falsely flagging a pending write-back and forcing the indirect draw onto the CPU fallback path (IndirectDrawPath::PendingLabelOrCopy).
    • With this PR: writer->CopiedWritesOverlap(directAddress, 16) returns false, allowing the indirect draw to proceed directly on the GPU (IndirectDrawPath::Gpu).
  4. Overlaps across the copied region still evaluate to true on both checks, ensuring hazard correctness.

Verified locally: tests/agc_driver_graphics_tests passes cleanly.

Scene Frame Times (main vs main + PR alone, Astro Bot PPSA21567 under APS5_PROFILE_DRAW=1):

Metric main main + #3471 alone Delta
Frame Time (p50) 71.2 ms (14.0 FPS) 68.8 ms (14.5 FPS) -2.4 ms
Frame Time (p90) 76.5 ms 72.1 ms -4.4 ms
Indirect draws on GPU 142 / 10 s 200 / 10 s +58
CPU fallbacks (pending_label_or_copy) 58 / 10 s 0 / 10 s -100%
Indirect argument reads wait 1.4 ms / frame 0.0 ms -1.4 ms
GPU idle gap time 13.0 ms 10.5 ms -2.5 ms

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.

@Kikoarl
Kikoarl force-pushed the perf/agc-copied-writes-overlap branch from 112d0a9 to d906ee2 Compare October 12, 2026 00:44
@Scramblrrrr

Copy link
Copy Markdown
Contributor

Prepared a source-only Windows cross-test of your current a057eed + d906ee2 pair, 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.

@Scramblrrrr

Copy link
Copy Markdown
Contributor

Windows cross-test completed for current #3471 pair a057eed + d906ee2, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants