Repository navigation
fix(shader): read a 2D MSAA T# through DIM 2D as its sample 0 - #7803
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
2a725c5 to
b216fe3
Compare
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, To pick it up: Head is |
jotitadev
left a comment
There was a problem hiding this comment.
Apple GPU / MoltenVK run. On Apple, agc_driver_sample_multisample_target is skipped as a whole, so the new sample-0 cases never run: MoltenVK doesn't expose shaderStorageImageMultisample, and the existing gate in main() 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 b216fe3, PR diff applied cleanly.
Tested: the tree is main a373e85 + 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 plain main (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 (branch jotitadev:fix/agc-tests-vulkan-loader-macos). Base on that tree: 40 ^agc failures with MoltenVK 1.4.2 and 26 with MoltenVK main + #2704, plus agc_driver_pooled_buffer_range and agc_performance_overlay, which only run because of the loader patch.
- With the PR, unchanged:
agc_driver_sample_multisample_targetreportsmultisampled target sampling not tested: storage image multisampling unavailable(skip).agc_shader_memorypasses 3 of 3. - With the
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. - With
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. - Full
^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.
|
@thuanquang ran it in the title on Linux / NVIDIA. Setup:
Result: the game gets past the read that
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). |
b216fe3 to
cbe3805
Compare
cbe3805 to
09c3d71
Compare
|
@jotitadev thanks for the MoltenVK runs. The gate now sits below the sample-0 and BGRA8 checks ( @mrfelek thanks for running it in the title. I've added your result to the description. |
09c3d71 to
5b78947
Compare
5b78947 to
9ac1a20
Compare
jotitadev
left a comment
There was a problem hiding this comment.
Adds NVIDIA and lavapipe (native Linux). Worth noting lavapipe runs agc_driver_sample_multisample_target in full here, where on Apple through MoltenVK the whole test skips (no shaderStorageImageMultisample), so this is a red→green on 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=1 and ANYPS5_REQUIRE_VULKAN=1, device selected with VK_ICD_FILENAMES, serial CTest, on main a6dcea927 (this PR applies cleanly on it; head 9ac1a20ce).
agc_driver_sample_multisample_target |
NVIDIA RTX 3070 (595.99.02) | lavapipe (Mesa 26.0.3, LLVM 21.1.8) |
|---|---|---|
main a6dcea927 + the PR's test only (ShaderResources.cpp and ResourceMaterializer.cpp reverted) |
fail | fail |
| this PR | pass | pass |
With the two production files reverted and the test kept, both devices exit non-zero in ShaderRecompiler::Recompile with:
image descriptor is incompatible with the static runtime image interface: descriptor format 71 decodes to {class 1, dim 6, ...}; modes: {class 1, dim 3, ...} ...
That is the DIM 6 (2D MSAA) T# that main cannot 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 ^agc suite is unchanged from main on both devices: NVIDIA 859/862, lavapipe 861/862, i.e. main + the one agc_uncounted_passes this PR adds. The only remaining failures are the pre-existing ones main already has here (sample_order family on NVIDIA, multisample_retirement on 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.
9ac1a20 to
0ad8aa3
Compare
0ad8aa3 to
e0f6ea8
Compare
A DIM 2D image_load or image_sample of a 2D MSAA T# returns sample 0 on RDNA2 (RX 6700 XT, measured through HIP; bilinear blends sample-0 texels). The recompiler now reads such a direct sampled access as a 2D image, and the driver binds a one-sample copy of the target's sample 0, refreshed by a fragment pass before each binding. Peace Walker (PPSA18216) stops on this read at the end of its opening movie. Co-Authored-By: Claude <noreply@anthropic.com>
e0f6ea8 to
0a3ea21
Compare
|
@thuanquang another title with this refusal, which this PR doesn't reach yet: Ghost of Tsushima Director's Cut (PPSA02225), Linux, RTX 4070 Ti (615.71.09), warm, 20 GiB. The stop. A GoT stack on That's a 2-sample 2D MSAA T# (TYPE 14, format 22) read through DIM 2D, the case this PR handles. The same stop appears without the PR. Why the PR's path doesn't take it. A local diagnostic in
One table entry, I can't measure what RDNA returns for gather or the other ops behind AI-assisted: yes (Claude Code) |
|
@milescoviello Thanks, that pins it down. This PR stays at the reads it has hardware data for: a non-table DIM 2D
So I'd keep this PR as it is and do both as a follow-up once the ops are known, and I'll ask you to run that branch on GoT. |
|
@thuanquang agreed: keep this PR as it is, and do the table elements and the other ops as a follow-up. I'm running GoT now with the shader cache off and AI-assisted: yes (Claude Code) |
|
@thuanquang here are the ops. The IR dump never fired for that shader in a warm run, so I tagged two local diagnostics with the shader being prepared or materialized. One prints each 2D MSAA T# read through a non-MSAA dimension. The other prints each op that clears Reads of 2D MSAA T#s through a non-MSAA dimension (T#s What clears
None had a mip, packed or by-element read. Four of the shaders clear it with none of these, so their reads keep A correction to my earlier comment about the shader that stops, AI-assisted: yes (Claude Code) |
|
Re-checked the interdiff: the first-sample copy now binds the source at its real layout, the 8/16-bit T# modes and the 16_UINT depth-bits refusal are pinned in |
|
@milescoviello thanks for the op list and the correction on Measured on an RX 6700 XT (gfx1031) through HIP, for a 2-sample 2D MSAA T# (format 22, 16x16, SW_64KB_Z_X and SW_64KB_R_X, wrap addressing, X channel) read through DIM 2D:
Still refused on the branch: the two DIM 3D shaders ( |
|
@thuanquang thank you for measuring those two so quickly. I'm building GoT's stack with your two commits now (cold cache, then a full run), and I'll post where it stops and how the frames around those targets look. If AI-assisted: yes (Claude Code) |
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 fix(agc): key shader modules by the pipeline library mode #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_atomicsfix(shader): release the LDS lock with an exchange and drop fences inside it #6976,agc_driver_lds_lock_budgetAGC: AMD device-backed LDS lock-budget case returns half of expected sum #7344,agc_driver_layered_volume_vertex_no_gplAMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #4768);agc_trimmed_import, the new test from perf(agc): keep a host import across a split of its guest range #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 AMD Windows: GPL-mode cache failures (alpha/wave32 pass after local driver update) #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+ fix(libc): give the scripting heap hooks blocks from libc's own heap #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+ fix(agc): draw line lists and strips into a multisampled target with MSAA_ENABLE clear #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 fix(shader): store through DIM 2D image_store to a cube T#'s BASE_ARRAY face #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