fix(agc): retire a multisampled color target a write-only storage image overwrites #10049
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10049"
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 frankea on 2026-10-23T06:30:03Z.
What
A multisampled color target keeps its samples on the host, so every guest access to its memory throws, and only an unmap or allocation removal that covers the target retires it (debt entry "Multisampled color targets"). A title that pools render target memory and reuses a resolved target's range for a compute shader's output stopped on that guard, even though the shader overwrites the memory and never reads it.
DescriptorBindinggainsimageRead, anElementFlagslikemain's other element flags, one entry per image element, from the resource tracker's per-image read flag (any image access other than a store, atomics included). Image table elements are marked read. The shader disk cache keeps it (format 69;mainis at 68), and the binding grows frommain's 864 bytes to 920. This is the image counterpart ofbufferRead(2fb7a77ac), and the recompiler already useswritten && !readthe same way for storage images inResourceMaterializer.WrittenStorageBytes, the same whole-block ranges main uses to retire covered depth surfaces) cover the target's whole color range. The target is then retired with the unmap rule (retireCovered, shared withretireUnmapped), at the end of the resource build or of a successfulRevalidate. Retiring last means every other access of the same dispatch or draw has already passed its own guard: a sampled read of the same memory still throws.main's guards: since #9186 an overlapping range that is not host-only (a target made from a texture no draw rendered to) is retired on access and a host-only one is refused, since #8223 unless the title wrote over it or bound another target over it after its last use (canRetire), and since9d6332386a one-fragment target's FMASK is guarded as a range of its own. This PR's exemption is checked first: a range whose target's color plane the store covers is passed and left for the retirement at the end of the build, host-only or not. FMASK ranges have no color plane and are not exempt, so a store over a one-fragment target's FMASK is still refused withmain's FMASK message.imageRead, likeimageWritten, andmain's compact key for large image tables hashes it with the other flag vectors. The key's labeller (LabelShaderKey, used by theAPS5_PROFILE_DRAWmiss counts), the churn profiler's key walk (chargeShaderKey) and theKeyMisstest count all 11 flag vectors.Why: Gran Turismo 7 (PPSA01317) reuses the memory of the 4-sample EQAA target it draws while loading the World Map. After the CB resolve, compute shader 0x1258c1fd00 (8x8 threads, wave64) stores to three images from the table at user data words 2-3: 1920x1080 at 0x1238ba0000 (the target's base,
0x1238ba00 0xc4200000 0x010dc1df 0x91b00fac 0 0x00700000 0 0, 0xff0000 bytes), 1920x1080 at 0x1239b90000, and a one-channel image at 0x123ab80000. Each thread stores either zeros or texels it loads from three other images; it loads nothing from the three it stores to (replayed offline withagc_shader_replay --asm). The resource set was built before the target existed, so the run stopped inRevalidate:compute shader 0x1258c1fd00: AGC graphics: a cached image access of 0x1238ba0000+0xff0000 overlaps multisampled color target 0x1238ba0000+0x200000 (4 samples), whose samples are only on the host: guest access to it is not implemented.Tested
maina4ef806cd7(merge73b8218e12, head9b94901b30; conflicts inShaderResources.cpp,Recompiler.hppandShaderDiskCache.cpp/.hpp, resolved as described in the comments:imageReadis anElementFlags,DescriptorBinding920 bytes, format 69;9b94901b30makeschargeShaderKeycount 11 flag vectors). The binding size was measured on the box's libstdc++ (MinGW GCC 15.2.0): 864 onmain, 920 here. RTX 4090 (NVIDIA 616.92, Windows 11 build 26200),maina4ef806cd7and9b94901b30built in the same tree:--repeat until-fail:3: on both, the same 276 pass three times, the same 4 skip and the same 4 fail with the same messages:agc_driver_msaa_dcc_clear_2/4/8(a same-value CPU color store did not invalidate multisampled DCC residency) andagc_driver_native_depth_publication(a native depth publication overwrote a byte the guest stored).agc_driver_cached_image_multisample_guardpasses on both and runs 9 checks on this head against 5 onmain(the four newCheckOverwrittenTargetcases: written 128x128, read and written 128x128, written 64x64, written 128x128 beside a sampled read).VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V) on the same 284: the same results on both, 1400Insert instance layerlines on each side, noVUID-line and nowas not found but was requested by env var VK_INSTANCE_LAYERS, and the same warnings (27Undefined-Value-ShaderOutputNotConsumed-DynamicRendering, 1Undefined-Value-ShaderOutputNotConsumed).ctest -R agc, 1575 entries: 1553 pass, 15 skip and 7 fail on both, the same tests: the 4 above plusagc_driver_image_plane_address_on_line(67.50 vs 60, the NVIDIA LOD blend) andagc_driver_image_sample_lod_clamp/agc_driver_image_sample_lod_clamp_shader_lane(2 vs 1).main3cb1cd29ecand7383be1a19(6f8593891f,f5b27d4d89) ran only on an Apple M5 Max under Rosetta 2 and MoltenVK, as described in the 11/06 comment, and the one ontomain4138defef7(18bda85904) only in CI. The RTX 4090 run above is the 4090 rerun promised on 11/06.mainee9a9a66c(d500cd1ed;mainhad taken disk cache format 50, the number this branch used, so the merge kept it without a conflict and70150798atakes 52) and ontomainb1b5353cf(headbff3f2a07;main's #6628 guarded-range generation now also counts this PR's retirement inretireCovered), RTX 4090 (NVIDIA 616.92, Windows 11), each test run three times: the 207 ctest entries of the focused set's executables pass 207/207 onbff3f2a07, and 207/207 under the validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V): 895Insert instance layerlines, noVUID-line, and the same warnings asmainin every test.mainb1b5353cf: 207/207 in both runs. The first merge (70150798a,mainee9a9a66c) gave the same result.mainbb04a4f1e(head3974b1292; theShaderDiskCacheconflict resolved tomain'sRecompileResultsize 552, this PR'sDescriptorBindingsize 696 and format 50), RTX 4090, each test run three times: the 196 ctest entries of the focused set's executables pass 196/196, and 196/196 under the validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V), with 875Insert instance layerlines and noVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS.mainbb04a4f1egives the same in both runs.agc_host_import_cut_lifetime(#10746) passes on both now.mainca6e29e83(head6d3bc5e2a; theShaderResources.cppand debt-file conflicts resolved as described in the comments): of the 183 ctest entries of the focused set's executables, 182 pass, and the same 182 under the validation layer (same settings as below), where the loader inserted the layer and the log has noVUID-line orwas not found but was requested by env var VK_INSTANCE_LAYERS. The one failure,agc_host_import_cut_lifetime(the larger side of an unmap of 1440 KiB at the start of the import's first 2 MiB run left the write watch), fails the same way onmainca6e29e83, which otherwise gives the same results in both runs.mainf894ba69dplus the pull requests the title needs before this stop (#7978, #7243, #7256, #7550, #8564, #9020, #9335, #9068, #9700, #9721, #9743, #9806, a local form of #9988) and local diagnostics. In runs um-4 and um-5, compute shader 0x1258c1fd00's store retires the EQAA target (its color and FMASK ranges, logged by a local print) and the World Map's main pass draws on. Both runs then stop on a line list drawn into a multisampled target withoutMSAA_ENABLE, whichmaindraws since #8871; the integration branch predates it.Windows 11 (build 26200), NVIDIA GeForce RTX 4090 (driver 616.92), MinGW GCC Release build with
BUILD_TESTING=ON, all on one machine.agc_driver_cached_image_multisample_guard(CheckOverwrittenTarget): a compute set built before a 4-sample 64x64 target appears at its memory, with one storage image element. A write-only 128x128 element (64 KiB, the target's whole guarded range) revalidates, retires the target, and a fresh build over a new target retires it too. A read-and-written element, a write-only 64x64 element (16 KiB of it) and a write-only element beside a sampled read of the same memory all still throw, inRevalidateand in a fresh build, and leave the target guarded.agc_shader_disk_cacheround-tripsimageRead;agc_driver_graphicschecks that the content key changes with the lastimageReadbit;agc_driver_key_missbuilds keys with 11 flag vectors.agc_shader_disk_cache,agc_driver_key_missand the storage testsdepth_storage,depth_storage_dispatch,depth_storage_reuse,storage_cache_budget,storage_flush_ordering,image_table_reuseanddraw_cache_reuse.177b85aa8onmain0db47b263): 82/82 passed, each test run three times (ctest --repeat until-fail:3).CachedImageMultisampleGuard.cpp, run before the branch moved tomain0db47b263(951e93436 onmain9a030c2d5, the same change with cache format 45): the first new case fails withmain's refusal,AGC graphics: a cached image access of 0x200000000+0x10000 overlaps multisampled color target 0x200000000+0x10000 (4 samples), whose samples are only on the host: guest access to it is not implemented.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0),ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1withctest -V, onmain0db47b263(115/115, a set that includes these 82) and on this PR (82/82). Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line. Both have the same 16Undefined-Value-ShaderOutputNotConsumed-DynamicRenderingwarnings, from tests inmain.main379b1dca3(head17b8f6682): the one code conflict, inDescriptorBindingBuilder.cpp, keeps this PR'simageRead.push_back(true)beside #8792'simageAtomic.push_back(element.atomic). The disk cache format moves to 48 in its own commit, sincemain's 46 line merged cleanly and theimageReadbits would otherwise have shipped under it. RTX 4090: the 85 ctest entries the same targets now select pass 85/85, three times each, and 85/85 under the validation layer with noVUID-line (the same 16 warnings, from tests inmain).main9c85790c9passes the union of this run's sets, 109/109, under the same layer settings with noVUID-line.main5b85225ef(807ec18eb) and the FMASK exclusion (8ea73d837), RTX 4090, each test run three times. The set is 178 ctest entries of 28 targets: the 27 above plusagc_driver_recorder_tests, which now checks inagc_multisample_guest_accessthat a write-only store over every byte of a one-fragment target's guarded FMASK is refused.8ea73d837reranagc_multisample_guest_accessandagc_driver_cached_image_multisample_guard: 2/2.main5b85225ef: 177/178. The one failure on both isagc_host_import_cut_lifetime(the larger side of an unmap of 1440 KiB at the start of the import's first 2 MiB run left the write watch), #10746, which fails onmainon every run here.overwrittenTargetreturns false):agc_driver_cached_image_multisample_guardfails withmain's refusal,a cached image access of 0x200000000+0x10000 overlaps multisampled color target 0x200000000+0x10000 (4 samples), whose samples are only on the host.agc_multisample_guest_accessfails witha write-only storage store over every guarded byte of a host-drawn one-fragment target's FMASK did not throw.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V) on the 178 entries, onmain5b85225efand on b4612f900: each log has 790Insert instance layerlines, noVUID-line and nowas not found but was requested by env var VK_INSTANCE_LAYERS; both fail only #10746's entry.sizeof(DescriptorBinding) == 920assert applies (main's 864 plus oneElementFlags, 56 bytes with libstdc++, the size the 4090 box's MinGW libstdc++ also gives).tools/check_conventions.py --base origin/mainpasses on9b94901b30.Checklist
main; no other open PR implements the same functions.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)RequireNoMultisampleTargetand changes the same storage-image call inShaderResources.cpp: #15941 goes first, then this PR mergesmainand takes both parameters,DepthReadCause cause = DepthReadCause::Accessbeforeoverwritten, with the storage-image call passingDepthReadCause::Reuseand its covered bytes.mainalready draws)Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:49:37Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
This pull request does not merge cleanly into
main(5cb015caaa): headbff3f2a078conflicts incore/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppPlease rebase it onto current
main. I will review the change once it merges cleanly.Pull request closed