fix(agc): store only the bytes a synchronous draw changed in a linear color target #9202
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9202"
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-21T15:11:07Z.
What
A draw into a color target without a resident image is synchronous. It works in five steps:
For a linear target it read and stored the whole target, even when the draw's scissor covered a small part of it. The store also rewrote every byte with what was read before the draw, so a guest CPU store made to the target while the draw ran was lost.
The draw cannot write outside
State::scissor, the intersection of the screen, window, generic and viewport scissors, which lies inside every bound target. So, for a linear target without DCC whose scissor is smaller than the target, the synchronous draw now:bufferRowLengthset to the pitch;GuestMemory::WriteChangedagainst the bytes it read, as the GPU-tiled path already does, so only the bytes the draw changed are written.A scissor that covers the whole target, other tile modes and DCC targets take the old path.
Why
PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1) draws its PS1 games into three linear 3072x2048 R8G8B8A8 color targets of 24 MiB each. They have no host import, so every draw into them is synchronous. In the PS1 intro there are up to about 80 such draws per frame. A local trace of their scissors found almost all at (0,0) 320x224: each draw moved 24 MiB in and 24 MiB out for an area of 280 KiB.
On
mainevery draw into these targets is synchronous. #9879 creates their host import; in our runs with its branch (2026-10-23) the PS1 part made no synchronous draws on the RX 6700 XT, so once #9879 is merged this change no longer speeds up PPSA14363 there. It still applies to every target #9879 keeps synchronous, and the lost-store fix does not depend on any title. The two PRs merge cleanly in either order.Tested
Rechecked merged onto
main14c99b52ac(2026-10-26, AMD Windows driver 32.0.21045.16010): heada39a7d1f43setsAPS5_NO_RESIDENT_LINEAR=1in the test before its first draw, so its targets stay on the synchronous path this PR changes, also once #9879 gives linear color targets a host import.main'sDraw.cppthe new test fails in 3 of 3 rounds with the message below; with this change it passes 3 of 3.agc_buffer_pool, and three more tests that make synchronous draws with a partial scissor:agc_driver_cmask_fast_clear(a linear target with a padded pitch),agc_driver_srgb8_color_targetandagc_driver_packed_unorm4444_color_target.VUID-errors are 3 ofVUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605inagc_driver_srgb8_color_target. Plainmain14c99b52acreports the same 3 there (#6782 enablesindependentBlend). The other 14 GPU tests have none, and withmain'sDraw.cppthe new test has none either.New test:
agc_driver_linear_target_scissor_rows, on linear R32G32B32A32 targets with no host import, so their draws are synchronous. Four cases:SetFlushHook, at theStoreread site.In every case, pixels inside the scissor must hold their position, pixels outside keep their bytes, and both CPU stores survive.
maincecb540a63with only the test fails:main4777caca34(headc01f5cb9c8), after930b9640d7splitGraphics::Drawinto a prepare and a record step. The band fields moved into the file-scopeTargetBinding; nothing else changed. On that head, with AMD driver 32.0.21045.16010, the 12 tests below pass 3 of 3, and withmain'sDraw.cppthe new test fails with the message above.RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2 Release:
agc_driver_linear_target_resident, whose target is imported and resident:agc_driver_uint8x4_color_target_no_residentagc_driver_color1555_target,agc_driver_color565_targetagc_driver_packed_float_color_target,agc_driver_packed_unorm_color_target,agc_driver_packed_mip_tail_targetagc_driver_pixel32_ar_export,agc_driver_pixel_uint16_exportagc_driver_pixel_ancillary_word,agc_driver_pixel_fixed_point_positionagc_driver_linear_target_residentKhronos validation layer A/B (
VK_LOADER_DEBUG=layershows the layer inserted in all 12 test processes on both sides, with no "was not found" line), same 12 tests:mainwith only the new test: 11 of 12 pass (the new test fails as above), 0VUID-lines.VUID-lines.PPSA14363 (own dump), RX 6700 XT:
APS5_PROFILE_DRAW=1, warm shader cache, the same scripted input into the PS1 section.sceNpTrophy2GetTrophyInfo: trophy 19 is not in .../trophy00.ucp, was bypassed locally; #9115 fixes it.[draws]lines of the 10 s windows with at least 50 of them:maincecb540a63readTarget(read of the target)sync(upload, draw, read back, wait)writeBack(store to guest memory)prepare(per-draw image, see #9188)The 3300th guest flip (the
flipcounts of the[packets]lines) came after 84.4 s onmainand 70.8 s with this change. Assuming the title advances one frame per flip, both had reached the same content by then.This change is independent of #9188, which removes most of the remaining
preparetime. With both changes merged locally ontomaind34da5d694, one run ofmainand two of the change, same setup:mainRun 1's
syncphase was 1.6 to 3.1 ms per draw, against 0.35 to 1.1 ms in run 2, with the same build. Another lane on this PC may have been building during run 1.Gameplay, 2026-10-22:
main6ef5a1c4c9+ #9115 + #9373 on both sides.libSceAgcDriver.prxwas built with and without #9188 and #9202; nothing else differs. Two 600 s runs per side, alternating, with the same scripted input andAPS5_PROFILE_DRAW=1:No run stopped. The second run with both changes was slower at the Dock (107 to 147 presents per 10 s, against 124 to 196 in the first). These runs held only this PC's GPU lock, so other work on the PC may have slowed it. The title's progress is tracked in its bring-up discussion, #9615.
Other GPUs, from reviewers: @simnJS, GeForce RTX 4080 SUPER, driver 616.92, Windows 11 Pro 26200, on the earlier head
40e6e9247(before the one-row case):agc_driver_linear_target_scissor_rowspasses 3 of 3.main'sDraw.cppit fails 3 of 3 with the same partial-scissor message.@jotitadev, Ubuntu 26.04, NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3), on the earlier head
eab9f18d2onmain0c6a5bd59(the rebase toc01f5cb9c8only moved the band fields intoTargetBinding):agc_driver_linear_target_scissor_rowspasses 3 of 3 on both.main'sDraw.cppand only this PR's test it fails on both with the same partial-scissor message.Not tested: AMD GPUs other than the RX 6700 XT, AMD on Linux.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-10-21T16:28:14Z.
NVIDIA, Windows. GeForce RTX 4080 SUPER, driver 616.92 (32.0.16.1692), Windows 11 Pro 26200, Ryzen 9 7950X3D, WinLibs GCC 15.2.0 r7, Release.
Head
40e6e9247onmaincecb540a6.ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1,ctest --test-dir build -R "^(agc_driver_linear_target_scissor_rows|agc_driver_uint8x4_color_target_no_resident|agc_driver_color1555_target|agc_driver_color565_target|agc_driver_packed_float_color_target|agc_driver_packed_unorm_color_target|agc_driver_packed_mip_tail_target|agc_driver_pixel32_ar_export|agc_driver_pixel_uint16_export|agc_driver_pixel_ancillary_word|agc_driver_pixel_fixed_point_position|agc_driver_linear_target_resident)$" --output-on-failure --timeout 120 --repeat until-fail:3 -V.Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32appears in all 36 test runs. No test skipped.Draw.cpp+ PR testagc_driver_linear_target_scissor_rowspartial scissor: pixel (2, 2) outside the scissor holds byte 255 at 0, expected 17 (the CPU stored it while the draw ran)agc_driver_uint8x4_color_target_no_residentagc_driver_color1555_targetagc_driver_color565_targetagc_driver_packed_float_color_targetagc_driver_packed_unorm_color_targetagc_driver_packed_mip_tail_targetagc_driver_pixel32_ar_exportagc_driver_pixel_uint16_exportagc_driver_pixel_ancillary_wordagc_driver_pixel_fixed_point_positionagc_driver_linear_target_residentKhronos validation layer not run: the Vulkan SDK is not installed on this machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-21T21:56:33Z.
Review: COMMENTED
A Linux run on NVIDIA and lavapipe, with the red control, at the current head.
Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON, every execution test built. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. Headeab9f18d2applied ontomain0c6a5bd59(3-way, clean).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 60 --repeat until-fail:3.agc_driver_linear_target_scissor_rowsmainDraw.cpp+ only this PR's testThe red control fails the same way on both:
So on NVIDIA and on software Vulkan the whole-target store of a partial-scissor synchronous draw loses a concurrent guest CPU store, and this change fixes it; the test's position, out-of-scissor and both-CPU-store checks all hold with the PR.
(The earlier NVIDIA Windows run in the thread was on head
40e6e9247, which has since been force-pushed away; this is the current headeab9f18d2.)Not run: Windows, AMD, the Khronos validation layer (not installed on this host), any title, performance.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.