fix(shader): read a 2D MSAA T# through DIM 2D as its sample 0 #7803
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7803"
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-19T08:10:52Z.
What
METAL GEAR SOLID: Peace Walker (PPSA18216) stops at the opening movie's last copy (#5268). A pixel shader reads its 4-sample 1440x816 RGBA8 target through a plain DIM 2D
image_sample, and the recompiler refuses the T#:What RDNA returns for a DIM 2D read of a 2D MSAA T# was the open question (@mrfelek, @SandstromPL). On an RX 6700 XT (gfx1031), through HIP, it is sample 0 (measurement on #5268):
image_sample(implicit LOD),image_sample_lzandimage_loadwithout a mip, through a T# built like the title's (format 22), return sample 0 in 1024 of 1024 lanes on a 256x256 surface spanning 16 64 KiB blocks, where a TYPE 9 (2D) T# over the same memory matched sample 0 in only 60.image_sample_lat LOD 0 to 3, through an S# with MAX_LOD 15.99 and each mip filter, returns sample 0 in 256 of 256 lanes of a 16x16 surface through a T# built the same way. With a point mip filter, the same S# at LOD 1 and 2 reads another level of a 3-level TYPE 9 T# over the same memory, so the LOD takes effect.image_load_mipDIM 2D with mip N returns sample N.image_sample,image_sample_lzandimage_loadat 2, 4 and 8 samples, for formats 22, 29, 56, 60, 64, 71 and 77 in SW_64KB_R_X and the 32-bit formats in SW_64KB_Z_X. Itsimage_sample_lrows used an all-zero S#, which clamps the LOD to 0 (correction).image_sample_lat LOD 1, 2 and 3 through an S# with MAX_LOD 15.99, with a control showing that S# reads mip 1 of a TYPE 9 T#, for those texels and for 32_FLOAT and 8_8_8_8_UNORM (the title's format) in SW_64KB_R_X.image_sample_lfor formats 29, 60, 64, 71 and 77 and for the 32-bit formats in SW_64KB_Z_X, and implicit-LODimage_sampleeverywhere. 64- and 128-bit texels in SW_64KB_Z_X, and SW_64KB_S_X and SW_64KB_D_X, do not address samples on this GPU (every sample index reads the same texel), so they are not covered.This change reads it that way:
ResourceMaterializer.cpp): a 2D MSAA T# decodes as Dim2D when the access is a direct sampled image read only throughimage_loadwithout a mip andimage_sample,_lzor_l(the readscubeFaceCompatibletracks, taken for sampled images only), without a depth compare, R128, FMASK or depth-bits format. The shader then uses the existing 2D runtime mode, so sampling, filtering and LOD stay native. Storage, atomics, image tables, depth compares, gathers, bias, gradients, offsets andimage_load_mipkeep the existing refusal. The gate has no element-size check: the 8- and 16-bit run covers the narrower texels.MultisampleTargetFirstSample). After the usualSampled()checks (CMASK/HTILE, fast clears, pending storage writes, barrier), a fragment pass (FirstSampleCopy,texelFetchof sample 0 into a one-sample attachment of the target's format) refreshes the copy before each such binding. The pass reads the target's sampled view in the layout that view reports (Texture::Layout()), and creates its shader modules throughCreateShaderModule, the path #6436 made for every module the driver creates. Float, UNORM, SNORM and sRGB formats go through a float pass; UINT and SINT formats go throughusampler2DMSandisampler2DMSpasses, which copy the bits. It works for a live target, a red/blue-swapped one, and a texture no draw rendered to (createFilled). A Vulkan resolve would not do: it averages float and UNORM samples. A multisampled depth surface read this way throws.The debt entries state the gaps first. The reads are measured on gfx1031, not the console's gfx1013. Implicit LOD above 0, explicit LOD above 0 for texels over 16 bits other than formats 22 and 56 in SW_64KB_R_X, and other formats and swizzle modes are not measured. 64- and 128-bit SW_64KB_Z_X texels are not covered. Float, UNORM, SNORM and sRGB values pass through a shader and a color attachment, which Vulkan does not require to keep exact.
Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002 and 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1. Rebased ontomain9d6adeb550: this head (0a3ea213e1) is one commit on it; the one conflict was intests/ShaderMemory.cpp, wheremainadded averifyArrayVolumeStoreMode()call inmain()on the line where this change addsverifyMultisamplePlaneReadMode(); both calls are kept, and the rest of the patch is unchanged. On this head, with AMD driver 32.0.21045.16010, the six focused tests below pass 3 of 3, and a validation layer run of the six (same environment as the validation layer run below) passes with noVUID-error and nowas not found but was requestedline. The full AGC suite on this head (ctest -R ^agc_ -j 1): 902 of 905 pass; the three failures,agc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, fail onmainon this machine as well (seen onmaind6eafa54d). The rebase before it, onto001d132f47(heade0f6ea8ed6), had one conflict inMultisampleTarget.cpp, where #8847 (sRGB twin formats) addedView(VkFormat)andServes(), madeResolvePass()per format and destroys the twin view inrelease(), next to this change'sFirstSample()and its tworelease()lines; both are kept, and with AMD driver 32.0.21045.16010 the six focused tests below passed 3 of 3 on it. The rebase before that, onto8b3a6ba88d(head0ad8aa3278), had one conflict:mainaddedimageCoordinates()inResourceMaterializer.cppwhere this change addsmultisamplePlaneRead(), and both are kept.main's new GCN-only address-count check runs before this change's sample-0 rule, so GCN shaders behave as onmain. On that head, with AMD driver 32.0.21045.16010, the six focused tests below passed 3 of 3; withmain'sResourceMaterializer.cppon it,agc_shader_memoryfailed withdescriptor format 56 decodes to {class 1, dim 6, ...}as below. Before that, the rebase onto2f161d4f33(head9ac1a20ce4) had one conflict:mainadded its SampleOrder shader block incore/libs/prx/libSceAgcDriver/CMakeLists.txtwhere this change adds the FirstSample block, and both are kept. On that head the six focused tests below passed 3 of 3, and the validation layer run (A:main2f161d4f33with #9115's libSceNpTrophy2-only commit, which none of these tests load; B:9ac1a20ce4) has noVUID-line and nowas not found but was requestedon either side; A has five of the six, sinceagc_uncounted_passescomes with this change. Before that, the rebase onto7ab4b2e56had one conflict too: #7966 added adepth1Dcheck on the lines where this change addsfirstSample, and both checks are kept.agc_shader_memory, newverifyMultisamplePlaneReadMode: a sampled Dim2D access to the title's T# selects the float 2D runtime mode, and 2D MSAA T#s with 8- and 16-bit texels select the 2D mode of their numeric class (4x 8_UNORM and 4x 16_SINT in SW_64KB_R_X, 2x 8_UINT and 8x 16_FLOAT in SW_64KB_Z_X). A 4x 16_UINT SW_64KB_Z_X T#, which is read as depth bits, an access outside the measured set (cubeFaceCompatiblefalse), a depth compare and a storage access are refused.agc_driver_sample_multisample_target, newCheckFirstSampleReads: DIM 2Dimage_load,image_sample_lzandimage_sample_lat LOD 1 through the 4x target's TYPE 14 T# return each pixel's sample 0, bit for bit, as the target's DIM 2D_MSAAimage_loadreads it. It checks every pixel of:sampledImageIntegerSampleCountsincludes 4 samples (Vulkan requires only 1); elsewhere the test printsDIM 2D reads of 4x 8_8_8_8_UINT and 8_8_8_8_SINT targets not tested: sampledImageIntegerSampleCounts lacks VK_SAMPLE_COUNT_4_BITand goes on. The RX 6700 XT runs them.main7f596df48with only this PR's tests:agc_shader_memoryfails withdescriptor format 56 decodes to {class 1, dim 6, ...}, the title's refusal, andagc_driver_sample_multisample_targetwith the same refusal for its RGBA16F target (format 71).agc_shader_memorypasses, and the GPU test fails one step later, at the driver:guest texture dimension disagrees with the shader's declared image shape (shape 1, dimension 6).7f596df48, and after rebasing ontomainfb0dc118f.5b7894778(onmain7ab4b2e56):agc_shader_memory,agc_driver_sample_multisample_target,agc_driver_native_msaa_vertex_input,agc_driver_graphics,agc_uncounted_passesandagc_sample_dumpspass 3 of 3.aae3228a5(onmainb85d972f4):agc_shader_memory,agc_driver_sample_multisample_target,agc_driver_native_msaa_vertex_input,agc_driver_graphics,agc_uncounted_passesandagc_sample_dumpspass 3 of 3, and once more after the controls below were restored and rebuilt.aae3228a5, each built and run on its own, then restored:agc_driver_sample_multisample_targetfails witha DIM 2D image_load of pixel (9, 11) read 00000000 00000000 00000000 00000000, sample 0 is 00000012 000000be 00000042 00000081 from a drawn 4x 8_8_8_8_UINT target;a DIM 2D image_load of pixel (0, 0) read ffffff81 ffffffbe ffffffff 00000012, sample 0 is 00000012 ffffffff ffffffbe ffffff81 from 8_8_8_8_SINT color memory no draw rendered to;VUID-vkCmdDraw-format-07753(the view's numeric type must match the shader's sampled type), reported 10 times, the layer's default limit for one message, and 2Undefined-Value-ShaderFragmentOutputMismatchwarnings;GetFormatInfo(format).byteSize >= 4u):agc_shader_memoryfails at the 8_UNORM row withdescriptor format 1 decodes to {class 1, dim 6, ...};agc_shader_memoryfails witha 2D read of a 16_UINT SW_64KB_Z_X 2D MSAA T#, read as depth bits, was accepted;e7ab9e7c1onmainfb0dc118f), the fullctest --parallel 4 --timeout 120: 1605 tests, 9 fail, none of which reads a multisampled texture:mainhas here (agc_driver_lds_mixed_width_atomics#6976,agc_driver_lds_lock_budget#7344,agc_driver_layered_volume_vertex_no_gpl#4768);agc_trimmed_import, the new test from #6499, which fails the same way onmainon this machine;agc_driver_draw_cache_reuse_offandagc_driver_stencil_replay_no_gpl, which lose the device under their usual names and pass from renamed copies (AMD's per-executable pipeline cache, as in #4768);guest_nanosleep_timer_self_test, a timing test, which timed out while other builds were running;log_macrosandlog_macros_timestamps, which fail only in this local build because ccache's base directory turns__FILE__into a relative path with backslashes.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V, same RX 6700 XT, onmain7ab4b2e56and on5b7894778, this change rebased onto it.agc_shader_memory,agc_driver_sample_multisample_target,agc_driver_native_msaa_vertex_input,agc_driver_graphicsandagc_sample_dumpspass on both, and the newagc_uncounted_passespasses on5b7894778(6 of 6). Neither log has awas not found but was requestedline or aVUID-error. The same environment reports the float-pass control above, so the layer was loaded.python tools/check_conventions.py --base origin/mainwith this title and body passes.main+ #6842 + this PR atb216fe3a3): Peace Walker gets past the readmainrefuses, startsmgspwand reaches the title screen, with noimage descriptor is incompatiblein the log and no abort in 9 minutes on the title screen and its attract movies. Whether the picture at the copy matches a resolve was not compared.maincecb540a6+ this PR9ac1a20ce+ #8871593f4ab86, without local changes): Peace Walker plays through New Game into the beach tutorial at about 60 FPS, with no driver error in the log.b216fe3a3with the storage-multisampling gate moved below the sample-0 checks locally): the sample-0 and BGRA8 checks pass, and fail with the recompiler change reverted. MoltenVK has noshaderStorageImageMultisample. The gate has sat there since09c3d719f, so devices without storage multisampling run those checks and skip only the fill, store and swizzle cases. The UINT and SINT cases are newer than that run.7ecc1293fof headb216fe3a3): the full suite has no failures from this PR.9ac1a20ceonmaina6dcea927(@jotitadev):agc_driver_sample_multisample_targetfails on both withShaderResources.cppandResourceMaterializer.cppreverted (image descriptor is incompatible with the static runtime image interface, the DIM 6 T#) and passes with this PR; lavapipe runs the multisampled storage-image path that MoltenVK skips.agc_uncounted_passespasses on both, and the rest of the^agcsuite matchesmain(NVIDIA 859/862, lavapipe 861/862, only failuresmainalready has there).From the reviews of this change:
Recorder::RecordUncounted. When the recorder counts occlusion over a whole batch (the fallback without segment queries), it ends that query around the copy and starts a new one, and the batch's sample count sums them.agc_uncounted_passeschecks it: two counted 64-sample draws around one uncounted draw give 128. Without the pause, it reads 192.agc_driver_sample_multisample_targetalso checks that:image_sample_lat LOD 1 uses an S# that allows it (MAX_LOD 15.99, point mip filter); the copy has a single level.FirstSampleCopy::Recordtakes the source view's layout instead of assuming GENERAL; the UINT and SINT passes are tested and the reads are compared bit for bit; 8- and 16-bit texels are measured and pinned inagc_shader_memory; both debt entries state the gap first and stay under 1000 characters.cubeFaceCompatible, which #6799 extended to mip-less stores (the gate still takes sampled reads only); and the GPU test reads through compute dispatches only, without bilinear filtering.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 blawesom on 2026-10-19T09:25:35Z.
Rebase handoff — rebased onto current
maincleanly (authorship unchanged).Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
7ecc1293f.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T09:39:35Z.
Review: COMMENTED
Apple GPU / MoltenVK run. On Apple,
agc_driver_sample_multisample_targetis skipped as a whole, so the new sample-0 cases never run: MoltenVK doesn't exposeshaderStorageImageMultisample, and the existing gate inmain()returns before the first draw. The new cases don't seem to need storage multisampling. With the gate moved after them (local, test-only), they pass on both drivers, and they fail with the PR's driver and recompiler changes reverted.Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704. Head b216fe3a3, PR diff applied cleanly.
Tested: the tree is
maina373e85e5+ mugurc's macOS series (ci/macos-series-2) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plainmain(it doesn't build on macOS yet). Applied together in the same build: #7666, #7811, #7799 and #7803, plus a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branchjotitadev:fix/agc-tests-vulkan-loader-macos). Base on that tree: 40^agcfailures with MoltenVK 1.4.2 and 26 with MoltenVK main + #2704, plusagc_driver_pooled_buffer_rangeandagc_performance_overlay, which only run because of the loader patch.agc_driver_sample_multisample_targetreportsmultisampled target sampling not tested: storage image multisampling unavailable(skip).agc_shader_memorypasses 3 of 3.storageImageMultisamplecheck moved below thestd::puts("DIM 2D image_load, image_sample_lz and image_sample_l reads ...")line, the draw,LoadSamplesand the first twoCheckFirstSampleReadscalls (the drawn 4x target, and zeroed memory no draw rendered to) run and pass on both drivers. Then the test skips at the moved gate. I also copied the BGRA8 block (DecodeSwappedTarget,CheckSwappedSamplesand itsCheckFirstSampleReadsthrough an RGBA8 descriptor, format 56 as in the title) above the gate. All three first-sample checks pass, 3 runs of 3 on each driver. So theFirstSampleCopypass works on Metal, including the check that sample 0 differs from the average.ResourceMaterializer.cppreverted (test kept, gate moved), the test fails on both drivers with the refusal from the description, here for the test's format-71 target:image descriptor is incompatible with the static runtime image interface: descriptor format 71 decodes to {class 1, dim 6, ...}.agc_shader_memoryfails the same way for format 56.^agcsuite with the stack (gate moved): the base failures on each driver, nothing new and nothing gone.Moving the gate below the first-sample checks (and the BGRA8 block with them) would let devices without storage multisampling, such as MoltenVK, cover this path. The store cases further down still need the gate.
GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-19T11:33:17Z.
@thuanquang ran it in the title on Linux / NVIDIA.
Setup:
mainf71a31193+ #6842 (Peace Walker still needs it) + this PR at b216fe3a3, both merged cleanly. No local changes, noAPS5_PROBE_*switch, so none of my resolve code.Result: the game gets past the read that
mainrefuses.stagedat.pdtand samples the 1440x816 4-sample targets at0x2754d0000(your T#) and0x277fc0000.mgspwand reaches the title screen.image descriptor is incompatibledoesn't appear anywhere in the log, and nothing aborted in 9 minutes on the title screen and its attract movies.What I haven't checked: whether the picture at that moment matches my resolve's. My frame dumps from both processes went to the same file names, so the frames around the read were overwritten. If you need that comparison, I can rerun with frames saved around the read in both builds.
AI-assisted; the runs are from my machine(s).
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T19:23:02Z.
@jotitadev thanks for the MoltenVK runs. The gate now sits below the sample-0 and BGRA8 checks (
09c3d719f), so devices withoutshaderStorageImageMultisamplerun them and skip only the fill, store and swizzle cases. On the RX 6700 XT the test passes, and with the gate forced on, the sample-0 and BGRA8 checks run and pass before the skip.@mrfelek thanks for running it in the title. I've added your result to the description.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T01:30:46Z.
Review: COMMENTED
Adds NVIDIA and lavapipe (native Linux). Worth noting lavapipe runs
agc_driver_sample_multisample_targetin full here, where on Apple through MoltenVK the whole test skips (noshaderStorageImageMultisample), so this is ared→greenon a device that actually executes the multisampled storage-image path.Tested
Ubuntu 26.04, GCC 15.2.0, Release,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1, device selected withVK_ICD_FILENAMES, serial CTest, onmaina6dcea927(this PR applies cleanly on it; head9ac1a20ce).agc_driver_sample_multisample_targetmaina6dcea927+ the PR's test only (ShaderResources.cppandResourceMaterializer.cppreverted)With the two production files reverted and the test kept, both devices exit non-zero in
ShaderRecompiler::Recompilewith:That is the DIM 6 (2D MSAA) T# that
maincannot match to any of the DIM 3 (2D) runtime modes; with the full PR the recompiler reads it through DIM 2D as sample 0 and both devices pass.agc_uncounted_passes, the test this PR adds, also passes on both.The rest of the guarded
^agcsuite is unchanged frommainon both devices: NVIDIA 859/862, lavapipe 861/862, i.e.main+ the oneagc_uncounted_passesthis PR adds. The only remaining failures are the pre-existing onesmainalready has here (sample_orderfamily on NVIDIA,multisample_retirementon lavapipe).GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.