fix(agc): store storage results pending under a multisampled color target before it takes the memory #13963
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13963"
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 hugodearaujo on 2026-10-31T14:09:14Z.
What
A multisampled color target whose samples live only on the host guards its guest memory: a CPU read of it throws "overlaps multisampled color target … whose samples are only on the host". A storage image can still have GPU results pending over that memory, produced before the target was drawn there. When the idle flush (
VulkanDevice::StoreIdleResults→StorageTexture::FlushAllPending("idle")) stores that image later, a watched surface takes the CPU path ofwriteBackLayers, which reads the guest bytes of the unitsoriginaldoes not hold (a GPU clear) withGuestMemory::ReadCommitted. That read crosses the target's guard and the title stops.This PR stores those results before the target takes the memory, as a single-sample target's refresh already does (
StorageTexture::Refresh→FlushPending):MultisampleTargetView(both overloads),MultisampleTargetOrderTarget,MaterializeMultisampleTargetClearandResolveMultisampleTargetcallStorageTexture::FlushPendingover the target's guarded color bytes (guardedColorBytes) before they taketargetsMutexand acquire (create, recreate or restamp) the target. The flush passesPublishScope::None, as the refresh does: the target takes no data from its color bytes in guest memory, so unit shadows over them are not published there (a reader that needs them publishes them, at the latest the idle flush). With nothing pending there,FlushPendingreturns from its pretest.Still refused: storage results recorded after the target's last draw by a writer that did not claim it. The target's next draw, resolve or materialization now runs the same write-back first, so it throws "a CPU read" there; an idle store still throws it too. Either way the results stay pending and the target stays guarded. A plain CPU read of the target's memory is still refused too.
Unknown use. Since
3b459ef4d6(oneandonlydean), an element the binding has no written flag for also claims the target, as the store-back already treats it as written. #13248 on its own still refuses it.8c0aafff03moves the guard test's unknown-use case and the debt entry to the new rule.Why: Assassin's Creed Mirage (PPSA13960 01.007.000) on
main+ #13248. In about 1 run in 8 the title stops at 50-80 s:A diagnostic build (local only) prints a backtrace where that refusal is thrown:
On every frame of that screen the build also logs a 4x target (0x10dc450000+0x480000 and 0x10e0720000+0x870000) stamped over pending storage results. Usually the compute clear's store claims the target (#13248) before the idle flush runs. On the failing frame a new 4x target, 0x10dc450000+0x870000, is drawn after the clear, and the idle flush runs before anything claims it. That flush stores the 1x image 0x10dc1d0000 through the CPU path, which reads the whole image.
Tested
Linux 7.2.11, RADV (Mesa 26.2.6), AMD Radeon RX 9070 XT, Release,
BUILD_TESTING=ON, onmain16345cad6a+ #1324811cfa16b5e(merge383588ed19), this change on top (37417cec46, then2fb6d79835:PublishScope::Nonefor the store, after review). The checks below were run on37417cec46. The "After review" item repeats them on2fb6d79835.agc_multisample_guest_access(agc_driver_recorder_tests --multisample-only, also in the full run), newmultisampleTargetOverPendingStorageTests. Setup: a watched 256x256 R64KBX surface without host imports (the idle store takes the CPU path as in the title) and a 4x 64x64 target over its last 64 KiB. Results come from a recorded clear +MarkWholeWritten.ClaimMultisampleTargetStore), still pending at the target's next draw: same checks.a CPU readand the results stay pending; the idle store after it is refused the same way, and the target stays guarded. Once the target is gone, they reach guest memory.an idle store after a multisampled target's draw over earlier storage results threw: AGC graphics: a CPU read of …+0x40000 overlaps multisampled color target …+0x10000 (4 samples), whose samples are only on the host.MultisampleTargetViewoverloads: the first case's refusal.an idle store after a multisampled target's next draw over a claiming store's results threw: … a CPU read ….storage results recorded before a multisampled target's draw did not reach guest memory.ctest -VwithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1: 55/56 on both. The one failure on both isagc_driver_native_multisample_depth(host importvkAllocateMemory (-1000072003), which also fails on plainmainhere). Neither log has aVUID-line orwas not found but was requested. Both logs have the same 25Undefined-Value-ShaderOutputNotConsumedwarnings.main+ #13248: 3 stops in 25 runs that got past startup, all on the refusal above. 2 of 14 were on the earlier base (3b32cc7b61+ #8223, 300 s / 110 s runs). 1 of 11 was on16345cad6a, with diagnostic logging only, 110 s runs.rc=139right aftersceKernelOpen /app0/streaminginstall.ini, a known intermittent crash with fresh run dirs, on both builds) are not counted.2fb6d79835,PublishScope::None), same machine:agc_multisample_guest_accesspasses. The negative control (265201ee2d) still fails at the first case witha CPU read, and each mutation, applied to2fb6d79835, still fails at its own check (the three above plus a CPU read that retires a host-only target:a CPU read of a resolved-only multisampled target's memory did not throw).37417cec46and2fb6d79835: 55/56 on both with identical per-test results (agc_driver_native_multisample_depthfails on both, as above). NoVUID-line, nowas not found but was requested, and 25Undefined-Value-ShaderOutputNotConsumedwarnings in each log.rc=139afterstreaminginstall.iniand are not counted). Each run reaches 142 s with 15-27 frames per 10 s after the menu, the same rate as37417cec46. By itself, 6 clean runs at the base's rate (3/25) mean little (p ≈ 0.46). With 37417cec46's 20 runs it is 0 in 26 (p ≈ 0.04).tools/check_conventions.py --base 383588ed19passes.main(headad007e4fe3:main6db6a3e927merged in, which has #13248):MultisampleTarget.cpp,main(#16483) starts the same five functions with aDccPublication. The store of earlier storage results stays first, before the publication's hold and the targets lock, as before. In the guard test, thestoresline keeps this PR'swritten.empty() || written[0]; the rest of the file ismain's.ctest -V -R 'multisample|fmask|cached_image|depth_storage|storage_flush|storage_cache|image_table|draw_cache|agc_driver_recorder$|agc_multisample_guest_access' -E agc_storage_write_back_scratchgives 92 tests onmainand on this change: 91 pass andagc_driver_image_table_vouched_lookupsskips on both (the device reports written imported pages).agc_multisample_guest_accessand the guard test's unknown-use cases pass. NoVUID-line and no "was not found but was requested".agc_driver_cached_image_multisample_guardfails atchecking a compute storage image of unknown use over part of a 4x target.tools/check_conventions.py --base 6db6a3e927passes.Runs by others.
8c0aafff03and its merge base4a467be387,agc_driver_recorder_tests, 3 runs each, Release. Ubuntu 26.04.1 with an RTX 4070 Ti (NVIDIA 615.71.09, GCC 15.2), and a Windows 11 VM with a GeForce GT 1030 (NVIDIA 582.78, WinLibs GCC 15.2 UCRT).agc_multisample_guest_accesspasses 3 of 3 on both sides on both machines, and no test differs between the base and the head. On Windows,agc_pipeline_cache_allocation_incomplete,_periodicand_same-sizefail 3 of 3 on both sides.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T14:23:05Z.
Review: DISMISSED
Reviewed — changes requested
At head
37417cec46307f537be995c8532b0e02ab231a42on base73f4f7e06e4f210a8c6570e335fd654dc0a86134, the new multisample claim path does not preserve the existing conservative behavior for storage-image bindings whoseimageWrittenmetadata is absent.What I ran
Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. The stack preview merged cleanly and confirmed #13248 is included in this head. I did not build or run C++ tests locally.
Results
Precheck output
Negative control
imageWrittenflags is treated as a possible write and claims an overlapping multisample targetbinding.imageWritten, as the existingDrawWriteRangestest doeswrittenis true whilestoredis false in this case.Findings
Blocking
At
ShaderResources.cpp:5091-5107, a missingimageWrittenentry makeswrittentrue butstoredfalse. Therefore this path neither callsclaimStoredMultisampleMemorynor recordsstoredWordsforrevalidateFull. An overlapping host-only multisample target can remain unclaimed, so the storage result is still rejected instead of following the new claim-and-store path. The repository already treats missing image-write metadata conservatively as a write inDrawWriteRanges.cpp:73-74.The smallest code correction is to make the claim metadata follow the same conservative result as
written:Please add an execution test with an empty
imageWrittenvector that exercises the overlapping-target claim and verifies the expected pending-store behavior.Non-blocking
None identified.
Sources
Not verified
No local build, C++ tests, or GPU runs. The detailed AMD validation and title-run results in the PR description are author-reported; I did not reproduce them. Hosted Windows was still running when checked.
To get this to a good state
Preserve the conservative missing-metadata behavior in the claim path and add the regression test described above. I will rerun the same precheck and inspect the updated diff and CI on the new head.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T00:11:17Z.
Review: APPROVED
Reviewed — approved
Before any of the five
acquirecallers creates, recreates or restamps a multisampled target, they now store storage results still pending over its color bytes. On a clean worktree this fixes the idle-store refusal that the new test reproduces, and the negative control fails with the title's message.What I ran
Head
95a0f94a7e64d31a7611f63d88f3cb542e684aba,main5cb015caaaaf83f8ee431414ee6a457b5b307d49, merged treea16594959d2244848969cf827c1e99c967154d46. Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pylibs(script)agc_multisample_guest_access(includes the newmultisampleTargetOverPendingStorageTests)agc_driver_cached_image_multisample_guard(newCheckStoredImagecases)agc_driver_image_sample_lod_clamp_shader_lanemain, so it comes frommain(the baseline096c4557is older thanmain)unwrap_self_..._test_new_output_inherits_the_destination_directory_groupos.chown→EINVALin the sandbox. This PR changes nothing undertools/or anything that test loads, so the failure is environmentalVUID-lines compared withmainVerbose output of the changed tests (merged tree)
lod_clamp failure, identical with main's production files
Negative control
storeEarlierStorageResultsa no-op, leaving the rest of the merged tree as it was.agc_multisample_guest_accessthen fails at the first case with the title's message:main(MultisampleTarget.{hpp,cpp},ShaderResources.{hpp,cpp}, which also removes #13248's claim path):agc_driver_cached_image_multisample_guardfails atchecking a compute storage image store over part of a 4x targetwitha cached image access ... overlaps multisampled color target. I couldn't build the recorder test in this state because it usesClaimMultisampleTargetStore.git status --porcelainis empty.Findings
Blocking
None.
Non-blocking
MultisampleTarget.cpp:971-973. The setup: a writer that did not claim the target records results after the target's last draw, and the target is then drawn, resolved or materialized again.storeEarlierStorageResultsnow runs the samewriteBackCPU path that the idle flush runs. That path reads guest bytes under the still-guarded target, so I expect the refusal to be thrown fromMultisampleTargetView/ResolveMultisampleTargetinstead of fromStoreIdleResults.Recorder.cpp:11254is followed directly byidleStore()).draw()that expects the same refusal, and check that the results stay pending afterwards. Also mention the draw-time refusal in the description's "Still refused" paragraph. I tried to probe this locally, but the review environment did not allow editing the test, so this point is from reading the code only.FlushPendingcallsFlushDepthPlanes(address, bytes)before its pretest (Texture.cpp:4516-4517). Every multisampled target's view, order target, clear materialization and resolve now pays for that call plus the pending-list pretest. The author's frame-rate numbers show no change in the title, so this is only for awareness.On the earlier review threads:
storedvswritten). I didn't apply the suggested change. On the merged tree I confirmed that theCheckStoredImage(..., {}, false)"of unknown use" cases (compute and draw) run and pass. Those cases require the refusal for an element without animageWrittenflag, which supports the author's answer.PublishScope::Nonepoint. It is addressed at this head (MultisampleTarget.cpp:972).Not verified
FlushPendingrunning outsidetargetsMutexbut under the draw'sGpuMutex: I checked it only by reading the code and by the tests, which call it withGpuMutexheld.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T22:28:45Z.
Review: APPROVED
Re-checked — approved
The only change since my last review is a merge of
main04a9eb4fa2(67c62dc509). At all fiveacquirecallers it keepsstoreEarlierStorageResults(...)right before #13021'sTargetsLock. The changed tests pass, and the negative control still fails with the title's message.What changed since my last review
The PR's three own commits are unchanged: delta.patch shows
88091bc014,37417cec46and2fb6d79835as identical.New commit:
67c62dc509, a merge ofmainwith one conflict inMultisampleTarget.cpp. #13021 replacedstd::lock_guardwithTargetsLock(alock_guardontargetsMutex()that also sets the thread-localtargetsMutexHeld).In the merged tree, every
acquire(context, …)call is preceded by the store, which runs outside the targets lock:MultisampleTargetOrderTargetMultisampleTargetViewoverloadsMaterializeMultisampleTargetClearResolveMultisampleTargetSee
MultisampleTarget.cpp:1377-1380and:1520-1523.grep "acquire(context"finds no other callers.storeEarlierStorageResultsis unchanged and still passesPublishScope::None(:964-966). This matches the author's comment of 2026-11-03.The description and checklist have no relevant edits.
What I ran
Head
67c62dc50922bda65302eccb021a2af62cf5f48b,main04a9eb4fa2877eb6e40bf2c83adf972e40d89b24, merged tree232e8b4969fa17be45f4ad28809f89111038ddc2. Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release,BUILD_TESTING=ON.git diff --checkcheck_conventions.pylibs(script)agc_driver_division, the denormal-mode tests,unwrap_self_…,vector_constant_factor_tininess) also fail on the baseline.agc_driver_cached_image_multisample_guardagc_multisample_guest_accessVUID-lines:agc_driver_image_gather_volume(VkSamplerCreateInfo-addressMode*), marked "test not run on main". That test did not run on the baseline1e658521, which is older thanmain. Several 3D-gather commits landed onmainafter the baseline (e.g.e92ec413c9,27d9dc2e4e,a3834314f8). This PR changes no sampler or gather code, so I don't count it against the PR.git status --porcelainafter restoringNegative control
With the body of
storeEarlierStorageResultsdisabled on the merged tree,agc_multisample_guest_accessfails at the first case with the title's message:After I restored the merged file and rebuilt, both tests pass again and the worktree matches the merged tree.
Previous findings
idleStore(). This does not block the PR.FlushDepthPlanes+ pretest cost for every multisampled target. Still open, for awareness only. The code is unchanged.New findings
Blocking
None.
Non-blocking
None.
Not verified
agc_driver_image_gather_volumeVUIDs also appear on currentmain. My attribution tomainrests on the baseline age, the gather commits that landed onmainafter the baseline, and the PR not touching sampler code.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:44:18Z.
Review: APPROVED
Re-checked — approved
The only new commit is
fc1dfc03ab, a test-only change. InmultisampleTargetOverPendingStorageTests, the third case now draws the target before the idle store. It requires that draw to be refused witha CPU readand requires the results to still be pending afterwards. The test passes, and a mutation aimed at the new assertion makes it fail.What changed since my last review
88091bc014,37417cec46and2fb6d79835are identical to what I reviewed. One new commit,fc1dfc03ab, adds 14 lines tocore/libs/prx/libSceAgcDriver/tests/Recorder.cppand changes no production code:refusedDrawhelper, which callsMultisampleTargetViewunderGpuMutexand captures the exception message;idleStore():refused(refusedDraw()), thenAnyPendingOverlaps(surface)(Recorder.cpp:11843-11845).a CPU read, and that the idle store still throws it too. This matches the code and the new test.What I ran
Head
fc1dfc03abea055730fffd1911244be66ddc809b,main1c8c0efc8c41314402e6966da5bef6ea3d639d10, merged treea5e67caec0be230350f597ab80fedd56d459807f. Debian 13 VM, Xeon Gold 6136, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19), Release,BUILD_TESTING=ON.git diff --checkcheck_conventions.pylibs(script)agc_driver_division, the denormal-mode tests,unwrap_self_…,vector_constant_factor_tininess) also fail on the baseline.agc_multisample_guest_accessagc_driver_recorderagc_driver_cached_image_multisample_guardVUID-lines in one test only:agc_driver_image_gather_volume(VkSamplerCreateInfo-addressMode*), marked "test not run on main". This is the same result as in my last review. The test did not exist on the baseline1e658521, which is older thanmain, and this PR touches no sampler or gather code, so I do not count it against the PR.git status --porcelainafter restoringNegative control
To check the new assertion on its own, I made
storeEarlierStorageResultsswallow its exception (try/catch around theFlushPendingcall). With that mutation, the first two cases still pass. The test then fails at the new check:So without the refusal, the draw goes through and the new assertion catches it. After I restored the merged file and rebuilt, both tests pass again and the worktree matches the merged tree.
Previous findings
Recorder.cpp:11843-11845), and the description now says so. The mutation above confirms the check works.FlushDepthPlanes+ pretest cost for every multisampled target. No longer applies as an open request. The author acknowledged the cost and reports no change in the title's frame rate (author-reported). It was for awareness only, and I accept leaving it.New findings
Blocking
None.
Non-blocking
None.
Not verified
fc1dfc03abare author-reported.agc_driver_image_gather_volumeon currentmainto confirm its VUIDs come from there.Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T15:48:35Z.
Review: COMMENTED
Ran
7d548223bdmerged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^(agc_driver_recorder$|agc_driver_cached_image_multisample_guard)' -V:mainRecorder.cppchanges callClaimMultisampleTargetStore, which this PR adds, so there's no run of the tests without the change.agc_driver_recorderstopping atvkQueueSubmit recorder: Vulkan result -4(device lost), which happens intermittently onmainon this iGPU too.agc_driver_cached_image_multisample_guardpasses in every run.was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T05:51:23Z.
Review: COMMENTED
Reviewed — comments
Changes are required before merge: the tests should check the cached revalidation path for the newly supported unknown-use storage image case.
What I ran
Reviewed head
8c0aafff03cf3537f5b1e25cb9a4a402acb42e67using the prepared diff and pinnedrepo_read.pyreader. No commands or tests were run by me; test results below are author reported.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/execution/CachedImageMultisampleGuard.cpp:517: the new unknown-use case (imageWrittenempty) is tested with an initial build, but unlike the explicit{true}case it does not revalidate an already cached binding after the target is drawn. Since cached revalidation separately reconstructs the stored resource metadata, adding that scenario would cover the new branch and guard against a regression there.Not verified
I did not run the test suite, validation layers, or the game. The author-reported checks are not independently verified. The full texts of
ShaderResources.cppandRecorder.cppwere excluded from the review folder; I read their relevant changed ranges and call context throughrepo_read.py. Other changed files were read from the review folder. Lockfiles, minified files,dist/,build/, and.svgfiles were excluded by the prepared review bundle;files.jsonwas not provided as a readable artifact.To get this to a good state
Nothing is required. Optionally add cached revalidation coverage for the unknown-use storage image case.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T15:11:01Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at
ad007e4fe322004713979a9266f1fa8a1016ba36has no verified blocking defects in the inspected code; the prepared description reports passing targeted checks on this head.What I ran
No commands were run. I inspected the prepared diff and relevant code through
repo_read.py; I did not independently run tests or build the project.Results
Findings
Blocking
None found in the code inspected.
Non-blocking
None.
Not verified
The prepared diff covers five changed files. I read the full included files
MultisampleTarget.cpp,CachedImageMultisampleGuard.cpp, anddocs/dev/debt/libSceAgcDriver.md, plus targeted ranges inShaderResources.cppandRecorder.cpp. The full text ofShaderResources.cppandRecorder.cppwas excluded from the review folder as too large; other ranges and callers in those files were not inspected. I did not independently verify reported builds, tests, or game runs.To get this to a good state
Nothing is required.