perf(agc): store a write-back's changed bytes without a masked non-temporal store #8930
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8930"
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 JJenkx on 2026-10-21T06:36:48Z.
What
Choose the store for partially changed 16-byte write-back chunks by changed-byte density and host CPU vendor. A chunk with at most
ChangedByteStoreLimit()changed bytes uses ordinary byte stores; denser chunks useMASKMOVDQU. The limit is 16 onAuthenticAMDand 4 on other vendors. Fully changed chunks retain their vector store, untouched bytes remain untouched, andsfenceruns if a masked store was used. The changed-byte count uses SSE2psadbwwithout requiring POPCNT.The policy retains the measured Ryzen title behavior while keeping the reviewer's faster Intel masked-store path for dense chunks. The threshold is measured only on the Ryzen 9 7950X and the reviewer's Core i9-14900KF; other CPU generations remain unmeasured and are recorded as debt. Tests exercise limits 0, 4, 16 and the host-selected limit, both sides of the density cut-off, aligned/unaligned writes and a tail.
Tested
Current-main correctness refresh, 2026-10-25: head
eb0b59ccc212870e3cc66df1b2671cf6931d6a46is four linear commits on mainb90d009d9f73354cbea239a74a8f7e2dcd138772. Every added/removed line in the four changed files is preserved from old headef525ba0b82; the rebase only resolves additive debt context and retains main's swept-staging entry. Source clean, conventions and whitespace pass. Local merge-tree is clean against newer main49d1f9b07ec(not rebuilt).Built full
libsand all seven selected test executables on both pinned main and candidate, Linux GCC 16.2.1 Release, bundled SPIRV-Tools enabled. The same 11 focused CTest groups pass three consecutive times on each arm (33 passes each), zero skips and zero VUID errors. Required Vulkan and disabled shader caching are set. Every repetition of all ten GPU groups loads Khronos validation (36 actual layer insertions per arm); the PM4 group is CPU-only. Hardware: Ryzen 9 7950X, RX 6650 XT / RADV Mesa 26.2.4, Arch Linux 7.2.9.The candidate PM4 fixture covers limits 0, 4, 16 and the host-selected limit at densities around the cut-off, aligned/unaligned destinations and a tail. This host selects AMD limit 16; exercising limit 4 functionally is not an Intel-host timing result. The selected groups cover PM4, storage split/write-back blocks, partially resident snapshot/pending stores, storage flush ordering, no-window/overhang write-back (including the draw-pipeline variant), and the sampled-cache case without storage-image multisampling.
The first attempted comparison was rejected for seven skip stubs excluded by the inherited execution-source selector; a second configuration attempt incorrectly used Boolean
ONfor the source-name selector and ran no tests. Both attempts are preserved. The completed comparison explicitly selects the five required execution sources and has no skips.Current source patch, source-preservation proof, full build/configuration logs and verbose main/candidate tests. SHA-256:
1456a1e353a987886fbdb4b0c87832cd3970fb5a55ac1caf526a36fed6cc135e; downloaded copy verified.No new title/performance, Windows, Intel-host or full-suite result is claimed. The historical speed evidence below retains its original exact revisions and caveats; it is not a fresh measurement of this rebased head.
Historical performance and earlier correctness evidence
Linux 7.2.9 (Arch), Ryzen 9 7950X, Radeon RX 6650 XT, RADV Mesa 26.2.4.
Speed: Minecraft Dungeons II (PPSA16064) 01.000.000, same scene on both sides: the Accessibility menu, reached by one Cross press at 45 s. Captured with
APS5_TRACE_SECONDS=90:30and no other trace or profile switch. Both runtimes were seeded with the same shader cache and saves before every run. Runs alternated main, change, main, change in one session, with no build running. Summary lines of the first pair:main9f4ddf7cf9:This PR (
9f4ddf7cf9+ ef9f2785be):9f4ddf7cf99f4ddf7cf9All four traces report
dropped: noin thetools/trace_digest.pyheader, with the default event limit. Frame p50 is about 5 % lower in both pairs. An earlier pair agrees: main 2736.1 / 2803.2 ms against 2615.8 / 2577.7 ms. That pair is not in the table because the PR build there was stamped dirty (built before the commit). The scene is still CPU-bound by the write-backs andGuestBufferMemory::AcquireRegistered. This is a small part of the frame, not a fix for that scene.Disclosed deviations from the Performance report form, identical on both sides: the harness writes the title's stdout to a file, and
perf recordattached at 123 s, after the trace window ended at 120 s.Traces (
aps5-trace-*.json.gz, open in ui.perfetto.dev), summary lines,tools/trace_digest.pyoutput, both annotate excerpts and the test logs: 20261021-write-changed-byte-stores-PPSA16064.tar.gzCorrectness, historical (measured on the first head
ef9f2785beovermain9f4ddf7cf9, before the review revision; the final-head gate is under Revision below):agc_driver_pm4already checks thatWriteChangedwrites exactly the changed bytes, including partially changed chunks and a tail (testWriteChangedKeepsUntouchedBytes,testWriteChangedStoresExactlyTheChangedRuns), andtestWriteChangedChunksOfEveryDensitychecks chunks with exactly 3, 10, 13 and 16 changed bytes. Focused write-back tests onmainand on this PR:ctest -R 'agc_driver_pm4$|partially_resident|storage_flush|write_back|writeback|storage_texture|storage_image' -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1.VK_ADD_LAYER_PATH, andVK_LOADER_DEBUG=layershows it inserted in all 9 tests in both logs. Neither log reportswas not found but was requested by env var VK_INSTANCE_LAYERS.main9/9, this PR 9/9.VUID-errors: 0 in both.tools/check_conventions.py --base origin/mainpasses. The PR overlap tool lists #6185 on the same lines. #6186 is stacked on it and was not compared automatically because it conflicts. Both change the store mask but keep_mm_maskmoveu_si128; whichever lands second keeps the other's mask and this store.Historical revision (
ef525ba0b8, rebased onmainf3456a4152):agc_driver_pm4passes 3/3.testWriteChangedChunksOfEveryDensitynow writes chunks with 3, 4, 5, 10, 13 and 16 changed bytes through limits 0, 4 and 16 and the host's limit. It does so both aligned and one byte off with a 5-byte tail, and checks every guest byte, including the bytes outside the write. It fails when the masked store's mask is inverted.Final-head focused write-back gate, validation layer on:
ctest -R 'agc_driver_pm4$|partially_resident|storage_flush|write_back|writeback|storage_texture|storage_image' -V. This now matches 11 tests. It ran withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(layer loaded throughVK_ADD_LAYER_PATH),ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, on the RX 6650 XT (RADV Mesa 26.2.4), for three builds:mainf3456a4152;ef525ba0b8(on this AMD CPU the limit is 16, so byte stores at every density);ef525ba0b8withChangedByteStoreLimit()forced to 4, so every CPU takes the non-AMD path.All three: 11/11 passed,
VK_LOADER_DEBUG=layershows the Khronos layer inserted 12 times, and the log never sayswas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-errors: 0, 0 and 0. I did not instrument whether these GPU tests produce chunks with more than 4 changed bytes.MASKMOVDQUitself is covered byagc_driver_pm4at limits 0 and 4.Zen 4 microbenchmark (synthetic, 32 MiB, every chunk partly changed): with the
psadbwcount, the limit-4 path is within about 3 % of pure byte stores at 1 to 4 changed bytes and of pureMASKMOVDQUat 5 to 15.On AMD the revision takes the same stores as the measured head; the only addition is a predictable compare. A matched old-head / new-head pair in the title is diagnostic only: the game's log was redirected by my harness, and the four arms were not adjacent. Its p50 differences were +1.3 % and -19 %, which is run-to-run spread, not a measurement. A form-compliant capture with a visible terminal could not be made on this machine. No Intel run is mine: the Intel numbers above are the reviewer's. A rerun of this head on their machine would be the check for the non-AMD path.
Checklist
main; no other open PR implements the same functions (rebased onb90d009d9f7; headeb0b59ccc21; local merge clean against49d1f9b07ec)NotImplemented_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 JJenkx on 2026-10-22T12:33:34Z.
Note for reviewers: a teammate measured Demon's Souls (PPSA01341) with this PR and saw slower frames: p50 76.6 and 64.8 ms on
main, against 132.5 and 173.4 ms with this PR. They flagged it themselves as unconfirmed, because the trace windows started at very different points in the game.I tried to make it a controlled comparison on a Radeon RX 6650 XT, RADV Mesa 26.2.4:
9f4ddf7cf9. The PR side swaps in onlylibSceAgcDriver.prxfromef9f2785be.I couldn't get matched scenes. On this title the start-up path changes from run to run even with no input: the same 140–180 s window lands on the publisher logos, the "LANGUAGE SELECT" menu or the "On the first day" intro, depending on the run. One base run also stopped on
APS5_ADDRESS_COPY_MAX_MIBat 189 s, unrelated to this PR. Across the complete traces, frame p50 is 109–116 ms on base and 102–140 ms with this PR, but the scenes don't match, so it shows neither a regression nor a gain here.The traces also have no slice for
WriteChangedalone; it falls underDriver.Packet.flush_between_packets. So I couldn't compare the function's own cost either. The Minecraft Dungeons II measurement in the description is the only matched-scene result for this PR so far.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T13:10:07Z.
New commit
51cd838855: a 16-byte chunk with 10 or more changed bytes now takes_mm_maskmoveu_si128again, and fewer changed bytes take the byte stores. Thesfenceruns only when a masked store was issued.Why. I benchmarked the 16-byte loop directly, outside the emulator. It's the function's loop body verbatim, run single-threaded on one Ryzen 9 7950X core, best of 7. With byte stores, the cost depends on how many bytes of a chunk changed. A chunk with 15 changed bytes costs 15 scalar stores, which is slower than one masked store. Write-backs where most chunks are almost fully changed could therefore get slower with the previous head. This may be what showed up in the Demon's Souls runs in my last comment; I couldn't confirm that in the title.
32 MiB buffer with every 16-byte chunk partly changed, N distinct changed bytes per chunk, in ms:
With half of the chunks partly changed, the same pattern holds: at N = 15, base 12.54, previous head 13.81 and this head 13.63 ms. Reading an unrelated 32 MiB array right after each write-back showed no consistent difference between the variants, so I see no cache-pollution cost from the byte stores. Every variant leaves the destination byte-identical to the expected result. Source: 20261022-pr8930-writechanged-bench.cpp.
Test. The new
testWriteChangedChunksOnBothStorePathsinagc_driver_pm4writes chunks with exactly 3, 13, 10 and 16 changed bytes, so the threshold sits on a boundary chunk. It checks that every changed byte is stored and no unchanged byte is touched.ctest -R '^agc_driver_pm4'withANYPS5_REQUIRE_VULKAN=1: 14 passed, andagc_driver_pm4_replayand_replay_toolwere not run because the replay tool target wasn't built.tools/check_conventions.pypasses.The Minecraft Dungeons II numbers in the description were measured on the previous head. That title's partly changed chunks would now take the masked store only if 10 or more of their bytes changed. I'll remeasure it on this head before asking for review again.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T14:42:55Z.
Head is now
fb25202abd. I've reverted the 10-changed-byte threshold from51cd838855. The code is back to the measuredef9f2785be, and the only addition is the density test, nowtestWriteChangedChunksOfEveryDensity.Why. I measured the threshold in the title before asking for review again. Minecraft Dungeons II (PPSA16064), the same Accessibility-menu scene and method as the description: one Cross at 45 s,
APS5_TRACE_SECONDS=90:30, seeded cache, alternating base and candidate. Every run used the full library set built at9f4ddf7cf9; onlylibSceAgcDriver.prxdiffers. All eight traces reportdropped: no, and all 120 s screenshots show the Accessibility menu.9f4ddf7cf951cd8388559f4ddf7cf951cd8388559f4ddf7cf9ef9f2785be9f4ddf7cf9ef9f2785beWith the threshold the title is no faster than base. With byte stores for every partially changed chunk it's faster again (−1.6 % and −8.4 %), in line with the description's pairs from yesterday. So in this title, byte stores beat the masked store even for chunks where most bytes changed. My single-threaded benchmark predicted the opposite for chunks with 10 or more changed bytes. Timing a read of the destination right after the write didn't explain the difference, and I don't know what does. I'm going with the in-title measurement. The benchmark's case of chunks with 11–15 changed bytes, where it shows byte stores up to 1.6× slower than the masked store, remains a possible cost on some titles. I haven't measured it in one; the Demon's Souls runs above didn't have matched scenes.
agc_driver_pm4passes with the density test, andtools/check_conventions.pypasses.Traces with
SHA256SUMS, digests, screenshots and the three drivers' hashes: 20261022-pr8930-threshold-check-PPSA16064.tar.gz (sha256f35d8bcb890060d045b31d172d4fd3c8c030692b52e2573538b6d4ad45a290d0).AI-assisted: yes (Claude Code).