perf(agc): upload sampled textures across existing imports #17255
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17255"
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 PrivacyOnion on 2026-11-08T16:26:20Z.
What
P1 review correction on 2026-11-09: imported uploads can reuse the same tiled scratch range within one recorder batch. Add
VK_ACCESS_TRANSFER_WRITE_BITto the existing barrier's destination mask so successive copies have a write-after-write memory dependency. This changes the imported upload path for both single-import and multi-import surfaces. No CPU wait, submission or scratch allocation is added. The regression now uploads two distinct arrays of the same size before sampling either, proves they reused the same scratch without a submission, and verifies both arrays after the uploads.Extend #16286's sampled-texture upload path to surfaces covered by several existing host imports. The current single-import lookup misses a GPU-written sampled surface whenever it crosses an import boundary, then waits for the writes and snapshots the entire tiled surface on the CPU.
Build an ordered, all-or-nothing copy plan under the import lock. Copy each covered span into the existing tiled upload scratch buffer behind the same GPU-write barrier, then use the existing detile and image upload. Include the import's actual buffer offset. A gap, stale registry, disabled host imports, empty range or address overflow produces no plan and retains the CPU path. No import, joined allocation or import-budget increase is created. Cache invalidation and retirement remain those of #16286.
The title that exposed this is Sniper Ghost Warrior Contracts 2, PPSA03131, 01.004.000: its 1920x1080 RGBA8 texture array has 13 layers and a 115,015,680-byte guest surface split across two existing imports. #16286 alone cannot take its GPU path. The implementation has no title ID, address, format-specific exception or relaxed validation.
This is stacked on #16286. Its prerequisite patch is a separate commit credited to JJenkx; the remaining commits add multi-import coverage and tests. #6197 creates joined storage imports; this change consumes existing imports only. #9884 removes a copy within the CPU snapshot path and retains the read/wait. Neither implements this multi-import GPU sampling path.
Tested
P1 correction validation on 2026-11-09, rebased on main
0f7eb1e23d535cc696553f5cfed14bb05c703530, fixed PR headd823c087eafb2679c8f2706179c246e844e03abf. Windows 11 build 26200, WinLibs GCC 15.2.0 Release, NVIDIA RTX 5070 driver 616.64. Both test executables and their runtime dependencies were rebuilt together for each checkout.The new consecutive-upload fixture reproduces 8
SYNC-HAZARD-WRITE-AFTER-WRITEvalidation errors with the original imported barrier, even though the sampled texels are correct. With synchronization validation and the new CTest failure regex, the original barrier fails the test. The one-mask correction removes all eight errors.Same focused selection and same physical GPU on main and the correction, using
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_GPU=RTX 5070,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LAYER_ENABLES=VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXTandVK_LOADER_LAYERS_DISABLE=~implicit~, withctest --test-dir C:/Users/playl/AppData/Local/Temp/ap5p15 -R '^(agc_sampled_import_pieces|agc_recorder_upload_scratch|agc_copied_direct_ordering|agc_driver_staged_clear_sampled_read.*)$' -V --no-tests=error.VUID-errors, zero synchronization hazards, zero missing requested validation-layer messages and no skipped tests. The new test also fails automatically onSYNC-HAZARDorVUID-output.The historical FPS captures below predate this synchronization correction. The previous +31.7% result is not validated for this corrected head and is withdrawn as a claim about this head. No new FPS benchmark or title-unlock claim is made for the P1 correction.
Overlap refresh for the P1 correction:
python tools/pr_overlap.py --branch perf/sampled-texture-imports --repo boykopovar/AnyPS5 --jobs 4examined 1,971 open PRs. It reports 99 heads, including this PR's own previous public head. Four other heads have shared-line intersections (#4448, #10064, #15674 and the declared prerequisite #16286). Another 94 cannot merge into the scan's current main base, so the tool exits 2 and fails closed. Of the reported heads, 74 exactly match immutable heads from the prior source audit. The remaining 25 new or changed heads were compared across the shared files and the import lookup, sampled lookup and upload-constructor regions. Only #16286 and this PR's own previous head change the sampled upload regions in that refreshed group. No second multi-import uploader or competing scratch-barrier correction was found. This supersedes the historical scan below and is not a clean automatic overlap result.The remainder records the earlier pre-correction validation and performance captures with their original commit IDs.
Windows 11 build 26200, WinLibs GCC 15.2.0, Release; Ryzen 5 5600, 16 GiB RAM, NVIDIA RTX 5070, driver 616.64. PR main base:
d0d11564cac8b513bdad3c61c2cb352884fffcaa. Capture and pure-main GPU-test base:828e44310ec98912f041d0e51b8adc809848741b; the intervening main change is LibreSSL3 BIO methods and changes none of AGC, the shader recompiler, libc or libkernel.Focused GPU validation, same physical GPU, with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_LAYERS_DISABLE=~implicit~, usingctest --test-dir C:/Users/playl/AppData/Local/Temp/ap5p15 -R <pattern> -V:^(agc_sampled_import_pieces|agc_copied_direct_ordering|agc_driver_staged_clear_sampled_read.*)$. Pure main runs the same four existing tests without the new test name.VUID-errors, zero missing-validation-layer messages and no skipped tests. The new multi-import GPU test actually runs on the RTX 5070.The new test samples real GPU-written texels from three array layers spanning four independent imports. It checks layer origins and centers, aligned and half-import source offsets, repeated GPU writes invalidating cached textures, and that a fully covered lookup does not submit/wait. A gapped import set has pending GPU writes and must fall back without producing a partial copy plan; empty and overflowing ranges produce no copies. All checked values come from GPU sampling.
Performance protocol: owned title relinked with
--windows --no-patches, offline, dummy audio, default graphics settings, 3840x2160. Same machine, savedata seed, timed controller sequence and stationary initial tutorial position. The scene ran before the retained captures to warm the caches. Capture order A1, B1, A2, B2; onlyAPS5_TRACE_SECONDS=240:40and its output directory are set for tracing. No other profiling/trace switch, frame dumps, log redirection, compiler or focused GPU test runs during the measured windows. Startup/controller actions finish before the measured window.Pure main stops on the tutorial's independent dual-source MIN blend, so it cannot supply gameplay FPS there. Both measured builds therefore use the identical common prerequisite set: main + #17187 (tutorial entry), #17157 (moved draw-recipe bindings) and #16286. A is
07b65274c87c6949afe3e20c1f7f997c1e1a3cb0; B is9fd2b22bc6942fc3424e8feb551f0750c53acd45. Both are clean committed trees. Their production difference is only this PR's five multi-import implementation files; their staged library sets differ only inlibSceAgcDriver.prx. The benchmark integration commits are published on the fork'sperf/bench-sampled-import-piecesbranch. #17187/#17157 are common benchmark prerequisites, not changes carried in this PR.Historical pre-correction captures measured 7.49 -> 9.86 mean FPS (+31.7%) in this stationary tutorial scene. These numbers do not establish a speed gain for the corrected head.
tools/performance_compare.py --require-matching-contextaccepts both A/B pairs. Event buffers fill in these captures: frame intervals and summary phase totals are retained (totals_full=false), while slice-based inventories describe retained events only. No claim about missing event slices is made. The attached digests retain this warning.Summary lines:
A1:
B1:
A2:
B2:
Download all four timing traces, their complete trace_digest reports, summaries and both comparisons. The archive contains no game files, savedata or memory dumps.
tools/trace_digest.pysummary for every retained trace:A1: seconds 240:40 from present 10488: 283 presents, frame p50 133.7 / p90 175.1 / p99 240.3 / max 294.0 ms, GPU busy 25.9 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit 07b65274c87c, dropped: yes
B1: seconds 240:40 from present 6669: 370 presents, frame p50 103.7 / p90 124.1 / p99 168.4 / max 286.4 ms, GPU busy 26.6 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit 9fd2b22bc694, dropped: yes
A2: seconds 240:40 from present 7598: 317 presents, frame p50 118.3 / p90 126.8 / p99 181.1 / max 2049.1 ms, GPU busy 24.7 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit 07b65274c87c, dropped: yes
B2: seconds 240:40 from present 7348: 420 presents, frame p50 95.1 / p90 100.5 / p99 108.3 / max 126.3 ms, GPU busy 24.3 ms per present
NVIDIA GeForce RTX 5070, NVIDIA 616.64, Windows 10.0.26200, 3840x2160, commit 9fd2b22bc694, dropped: yes
A separate diagnostic run counted hundreds of uploads from existing imports and zero CPU snapshot reads over recorded GPU writes; it rendered the tutorial correctly. That diagnostic uses profiling and is not the FPS evidence above. A preliminary attempt affected by concurrent compilation was stopped without a trace and excluded.
Historical overlap audit:
python tools/pr_overlap.py --branch perf/sampled-texture-imports --repo boykopovar/AnyPS5reports shared-line intersections with #4448, #9508, #10064, #15674, #15710 and the declared prerequisite #16286. The neighboring changes concern import-unwatching policy, image-table addresses, committed 3D slabs, import-lookup caching and shared array views. Their merge order can require a mechanical rebase; they do not implement multi-import sampled uploads. The scan fails closed for 73 older branches that conflict with main. All 79 reported heads were compared against their merge bases across the shared files and the affected import lookup, sampled lookup and snapshot-constructor regions. No second multi-import sampled upload implementation was found. This is an audited non-clean scan, not a claimed green overlap check.python tools/check_conventions.py --base upstream/mainpasses. The required--base origin/mainrun reports existing upstream findings because the fork's origin/main is behind; the actual PR base passes.git diff --checkpasses. No new third-party dependency or repository report is added.Historical GitHub Windows build/test, conventions, library-portability, eligibility, intake, labels and report checks passed for the pre-correction head
57f86b349782b0654af42e26105a36b921d2f111. Linux was skipped. A manual full-workflow dispatch was refused with HTTP 403 because this account lacks repository administration rights. The local physical-GPU results above are completed; no full Linux CI result is claimed.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)Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-08T20:45:19Z.
Review: DISMISSED
[P1] Synchronize writes when the imported upload reuses tiled scratch —
Texture.cpp:704.UploadScratchBuffer(Tiled, …)returns the same buffer for a second upload in the same recorder batch when its capacity is sufficient. Both uploads write from offset zero. The imported path’s barrier makes earlier writes visible to transfer reads, but its destination access mask omitsVK_ACCESS_TRANSFER_WRITE_BIT. A second imported upload can therefore issue overlapping writes to the same scratch range without the required write-after-write dependency. Please include the destination transfer write in the barrier and add a synchronization-validation case that uploads two distinct imported textures of the same size in one batch, then verifies both. I verified the reuse path and barrier on this head by source inspection. Vulkan synchronization rules.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T23:10:14Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the review evidence supports the multi-import upload and scratch synchronization behavior, though approval is not justified because not every reviewed file was read.
What I ran
Reviewed head
afc5589f6ff47e948b2f8850382916b750392a05using the prepared review bundle andrepo_read.py. No tests or build were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No source-level defect was identified in the inspected logic. The full text of
GuestBufferMemory.cpp,ShaderResources.cpp,Texture.cpp, andtests/Recorder.cppwas available through the reader; only the relevant ranges were read. The full test source and remaining portions of the diff were not reviewed. Files listed as changed in the review manifest:Graphics/include/GuestBufferMemory.hpp,Graphics/include/Texture.hpp,Graphics/src/GuestBufferMemory.cpp,Graphics/src/ShaderResources.cpp,Graphics/src/Texture.cpp,tests/Recorder.cpp,tests/cmake/agc_driver_recorder_tests.cmake, andtests/shaders/SampleImportOrigin.comp. The four files listed as too large for the review folder were read only through targeted reader ranges; no files were excluded by rule according to the manifest excerpt available.To get this to a good state
Nothing is required.