perf(agc): copy contiguous rows of a drawn linear target store in one region #10656
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10656"
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 thuanquang on 2026-10-24T15:22:09Z.
What
StorageTexture::storeDrawnRectstores a drawn linear target's rectangles in two steps. It copies the image into a scratch buffer, then the scratch buffer into the host import, and also into the target's saved bytes when the target is outside the write watch. Each copy uses oneVkBufferCopyregion per span thatdrawnSpansreturns.drawnSpansreturns one span per row, so storing a full-width rectangle issued one region per row: about 2048 regions for a 3072x2048 target.In both copies, regions that are contiguous in both the source and the destination are now merged into one. Storing whole rows of a target without row padding becomes one region per import segment, split only where a 64 KiB block is kept for the CPU. The stored bytes, the stamps and the settle after the store are unchanged; only the number of regions changes.
Why
PPSA14363 (METAL GEAR SOLID - Master Collection Version, own dump): on the PS1 part's codec screen, the PS1 renderer redraws a whole 3072x2048 linear color target (found with a local diagnostic build).
StoreDrawnLinear("flip")stores it throughstoreDrawnRect; before this change, the store used one copy region per row. In the trace pair below, the queue worker submits one GPU batch per present, insideDriver.Packet.flip_flush, the stage that also runsStoreDrawnLinear("flip"). At about every second present that stage takes 0.1 ms or more, and the batch it submits then holds the store together with the rest of that frame's GPU work. Every leg has 598 to 600 such batches per 1199 presents, at p50 9.90 ms onmainand 7.54 ms with this change. The other batches take p50 1.05 ms on both arms, and their total differs by at most 0.013 ms per present between the arms.Trace pair:
mainagainst this head merged onto it, on the RX 6700 XT (AMD driver 32.0.21045.16010, shown as 26.10.1 in the summary lines; Windows 11, build 26300 in the summary lines). Four legs in two exclusive pairs (main, PR, main, PR), 2026-11-12 12:17-12:38 UTC.mainf57c971559a8dcacdb7b090ad5f4a82b7633ea96.a00f02a4d168f86d0a269052dfcae0177f38fe7a, this headfdea400fcemerged onto thatmain(evidence/10656-main-f57c). Both are full builds of clean trees.APS5_TRACE_SECONDS=95:20; the four windows start at presents 5537 to 5653. The measured legs dump no frames.envholds onlyAPS5_TRACE_SECONDS,APS5_PAD_INPUT_FILEandAPS5_NO_PAD_INPUT. No other game ran: before each leg the pair runner checks for running games, and the process list showed no game process when I checked it between and after the pairs. The caches were warm: both run folders had run the same route in six legs earlier that hour. Since the log is not kept, the shader cache hit counts quoted for the earlier pair are not available for this one.f57c971559a8a00f02a4d168f57c971559a8a00f02a4d168tools/performance_compare.py --require-matching-context,mainfirst: GPU busy per present -1.10 (legs 1/2), -1.04 (3/2) and -1.10 ms (3/4). Between legs of the same build it differs by 0.065 ms (main) and 0.064 ms (change). The mean frame is 16.683-16.684 ms in all four legs, at the 60 Hz cap, so the change frees GPU time without moving the frame time here.tools/trace_digest.py:Summary lines, legs 1-4
The traces, digests, summary lines and the pair's score are on my fork at https://github.com/thuanquang/AnyPS5/tree/evidence/10656-main5084-traces (folder
codec-95-20-main-f57c-head-fdea). The traces hold only timings and emulator scope and thread names; the digests and summary lines add the machine, the commits and the title.Earlier pair (2026-10-31, main
50843f45d9, previous head; the log was redirected)Trace pair:
mainagainst this change merged onto it, on the RX 6700 XT (AMD driver 32.0.21045.16010, shown as 26.10.1 in the summary lines; Windows 11 26200). Four legs in two exclusive pairs (main, PR, main, PR), 2026-10-31 19:54-20:18 UTC.main50843f45d95b60e5772f4396431f9a39b8709d72.ba38183755751d4f1ddd223d9d402b333fbe076b, this PR's previous headfe506b00d0merged onto thatmain(evidence/10656-main5084). The head named under Tested,fdea400fce, is976a71c337rebased ontomain2a3df01d6f(git range-diffshows only context lines moved; the conflict was two blocks added next to each other inTexture.hpp/Texture.cpp).976a71c337is the same change as one commit onmainf2d874c1fd:git diff 50843f45d9 ba38183755andgit diff f2d874c1fd 976a71c337add and remove the same 57 lines in the same order, and only the counter declaration sits at another line.storeDrawnRect,drawnSpansandStoreDrawnLinearare textually identical on bothmaincommits.APS5_TRACE_SECONDS=95:20; the four windows start at presents 5652 to 5659. I located the codec with frame dumps in an earlier shared run of the same route onmain319621ba2e; the measured legs dump no frames.envholds onlyAPS5_TRACE_SECONDS,APS5_PAD_INPUT_FILEandAPS5_NO_PAD_INPUT. The caches were warm: the shader disk cache reports 54 hits and 0 misses in every leg. One box of the performance form is not met: our launcher wrote the emulator's stdout and stderr to a file in all four legs, and the form asks not to redirect the log. Before each leg it waits until no build or other game is running and the CPU is idle; that check allows League of Legends and does not log it, so it may have been open.50843f45d95bba381837557550843f45d95bba3818375575tools/performance_compare.py --require-matching-context,mainfirst: GPU busy per present -1.142 (legs 1/2), -1.194 (3/2) and -1.205 ms (3/4). Between legs of the same build it differs by 0.052 ms (main) and 0.011 ms (change). The mean frame is 16.683 ms in all four legs, at the 60 Hz cap, so the change frees GPU time without changing the frame rate on this GPU.tools/trace_digest.py:Summary lines, legs 1-4
The traces, digests and summary lines are on my fork at https://github.com/thuanquang/AnyPS5/tree/evidence/10656-main5084-traces (folder
codec-95-20). The traces hold only timings and emulator scope and thread names; the digests and summary lines add the machine, the commits and the title.Open PRs on the same code. #10159's
Texture.cppmerges into this head's without a conflict. #8246'sTexture.cppandTexture.hppmerge without a textual conflict too, but as #8246 stands (head9377004c3c),writeBackLayerscallsstoreDrawnRectonly when no pre-draw snapshot exists, andPrepareLinearDrawtakes one for each linear target a recorded draw writes. Read from the code, not run: with #8246, a store like the codec's would no longer reach the code this PR changes. The merge order with #8246 is not agreed yet.Tested
Windows 11 26200, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON, on this headfdea400fce(main2a3df01d6f).New case in
agc_driver_linear_target_rectangle_bound: on a 64x256 RGBA32F linear target (rows contiguous, one import segment), it draws one seed pixel and waits for the device to go idle, which stores the target, then draws a full-width scissor over 128 rows and waits again. It checks every pixel: the band must hold the band draw's output, the seed pixel the seed draw's output, and every other pixel the initial bytes. Through a newStorageTexture::TakeDrawnStoreCounts, it also checks that the band's store used one copy region per destination: one when the target stays write-watched, two when it is outside the write watch (the import and the saved bytes). On this machine the band was outside the write watch at the store, so both merged copies ran (two regions). The write-watched branch, which has only the import copy, did not run here.976a71c337), with only the region merge reverted (appendback topush_back, the counter kept), 3 of 3:AGC graphics: a drawn linear target's store copied contiguous whole rows in more than one region per copy.ctest -Vunder the validation layer (below), and 3 of 3 inside the suite runs; on976a71c3373 of 3:linear target rectangle bound, full-width band of 128 rows, unwatched memory: 1 stores in 2 copy regions (expected 1 in 2), wrong drawn pixels 0, changed untouched pixels 0.ctest -R "^agc_driver_(linear_target|bda_)"(21 entries) withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: 21 of 21 in each of 3 runs, onmain2a3df01d6fand on this head. WithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationadded to the same two variables (one run each, withctest -V,VK_LOADER_DEBUG=layerandVK_LOADER_LAYERS_DISABLE=~implicit~):main: 21 of 21, layer inserted 24 times, no "was not found" line, 0VUID-lines;VUID-lines.On the earlier head
fe506b00d0(on #9685's headd6d8966bba,mainb930da950d):ctest -R "^(agc|shader)_"passed 1011 of 1014. The 3 failures are thesample_ordertests thatmainfails on this GPU.Runs by others in this thread, on other bases (supporting only):
fe506b00d0merged ontod4cb89300f: all 1,125agc_tests match thatmain.fe506b0merged onto73f4f7e: 0 new failures. Its test selection did not includeagc_driver_linear_target_rectangle_bound.Linux path, WSL2 Ubuntu 24.04 with lavapipe (Mesa 25.2.8), GCC 13, Release, on the earlier head
976a71c337: the new case passes 3 of 3 withAPS5_WRITE_WATCH_IMPORTS=unwatchand 1 of 1 with the default, each withlinear target rectangle bound, full-width band of 128 rows, unwatched memory: 1 stores in 2 copy regions (expected 1 in 2), wrong drawn pixels 0, changed untouched pixels 0. WSL2's kernel has no guest write watch, so the band is outside it in both modes.Not tested: the write-watched branch of the new case (its memory was outside the write watch on both machines), and macOS.
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)d4cb89300f); NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Ubuntu 26.04.1 (TechLevelZero CI, on73f4f7e, without the new case)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:30:28Z.
Review: CHANGES_REQUESTED
The implementation’s merge condition is appropriately limited to adjacent regions whose source and destination offsets are both contiguous, and the focused test checks the resulting region count and bytes. I also see the reported RX 6700 XT validation run, including 54/54 focused Vulkan validation checks with no VUID lines; those are author-reported results, not runs I reproduced. The hosted product jobs were skipped.
The performance evidence still does not meet the repository requirement for a
perfPR: the report compares the change against #9879 (5575dc3108), notmainagainst this PR, and the two trace files are not attached. The stated reason (commercial title content) explains the omission but does not replace the required captures. Please provide compliant pairedmain/PR summaries and attach traces, or remove the performance claim/title/label and keep this as a correctness/optimization change without a measured speed claim. The current checklist also saysDepends on: #9685, while the text says merge #9685 first; please ensure the dependency remains explicit and the complete diff is reviewed after #9685 lands.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T16:21:11Z.
Review: COMMENTED
The expanded body adds useful red/green evidence for the region-count change and reports the GPU-validation suite. The performance pair still needs a reproducible commit mapping before it can support this PR: the summaries compare #9879 head
5575dc3108with 500e4c227069 (described as the first version of this commit), while the current PR head is fe506b00d0 and its declared dependency is #9685 atd6d8966bba. Please rerun the paired trace on the same machine/scene using the current dependency stack as the base and this exact PR head as the candidate, then state both full commit IDs and include the resulting trace_digest summaries. Raw title traces need not be attached if that would disclose protected content; the summaries should identify the exact source commits and show the same scene/window. The local regression and validation-layer results are useful separately, but they do not resolve this attribution gap.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:27:34Z.
Review: COMMENTED
The updated description now supplies an attributable base/candidate pair (
5575dc3108c7andb12e6b60f9a0), confirms the candidate is exactly this PR’s diff on the declared stack, and includes trace-digest summaries and paired runs. That resolves the commit-mapping gap I raised. One repository-required item remains:CONTRIBUTING.mdsays a speed claim must attach the traces. The description says the captures are not attached because they come from a commercial title. Please attach the required captures, or remove the speed claim andperfclassification and retain the correctness/region-count evidence. I have not independently reproduced the Windows GPU runs.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:07:12Z.
Review: DISMISSED
Rechecked exact head
fe506b00d065f0dd7b7bbd2878c8c26f81dd8f7dand the follow-up evidence.Findings
Blocking — the attached capture pair does not satisfy the repository performance-report protocol. The new summary lines are useful and the four traces are now attached, but they show
APS5_TRACE_SUMMARY_EVERY=10andAPS5_TRACE_DIRin addition toAPS5_TRACE_SECONDS; they also showAPS5_DUMP_FRAMESandAPS5_DUMP_FRAMES_EVERY. The current performance form says not to set additional trace/profile switches because they affect timings, and asks for a matched capture onmainand with the change. The pair currently compares #9879 (5575dc3108c7) with that stack plus this PR (b12e6b60f9a0). Please recapture with only the required trace setting and the form's permitted environment, using the correct comparable main/integration base, or remove the performance claim andperfclassification if a compliant pair cannot be produced. Keep the exact commit IDs and paired summaries/traces/digests for any replacement captures.The Windows correctness evidence is useful: the author reports the focused tests and validation suite on the RX 6700 XT, with the three broad-suite failures matching main on that GPU. I did not independently run the GPU tests or captures; this workspace has no Vulkan device. The current PR remains stacked on #9685, so the integrated branch and any replacement performance baseline should preserve that dependency.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T02:25:45Z.
Review: DISMISSED
Reviewed — changes requested
The code change and reported test results are credible, but the performance captures do not follow the repository’s required capture procedure because the emulator logs were redirected.
What I ran
Reviewed head
fdea400fcefbee630eeb086e13df08a3840ec686. The PR API reports base17fec482248b110379dadb86b9a228e3cb1e79b7; local checks and the merge preview used currentmain32d5fb01e47da227a0b3f5c9bf25c3fa1d5c8614, against which the head merges cleanly.Environment: Debian 12, Python 3.11.2, Git 2.39.5, GCC 12.2.0.
I read all three changed files and the performance report form. The reported Windows and Linux focused runs, negative control, and traces are author-provided evidence; I did not run those tests or captures locally.
Results
main.main. No required checks are reported.Negative control
The author reports reverting only the region merge made the new test fail 3/3, while the changed version passed 3/3 on Windows and 1/1 under validation on the current head. I did not run this control.
Findings
Blocking
main/change captures with the log left unredirected and no other game running, then update the summary lines, traces, and digest. This is a report-evidence request; I found no blocking defect in the code diff.Non-blocking
guest_relative_sleep. The author reports observing that failure onmaintoo (12/200 baseline runs versus 6/100 candidate runs, and 0/100 with #18299). I could not independently reproduce those rates; this review does not attribute that failure to this PR.Sources
Not verified
To get this to a good state
Repeat the paired captures without redirecting emulator output or running another game, and update the performance evidence. I will re-check the exact new head and rerun the relevant no-build checks after that update.