fix(agc): rasterize into one-sample targets as one sample when MSAA_ENABLE is clear #6196
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6196"
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 SandstromPL on 2026-10-15T01:54:17Z.
What
Rebased onto
mainf474fb776, which contains #5882 and #5907. The PR has three commits: the change for draw C, a one-line update of a #5907 test case (see #5907 below), and the same rule for a one-sample depth target, which mrfelek hit next (see "Third commit" below). It does not need #6014.mainrefuses three draws of METAL GEAR SOLID: Peace Walker's (PPSA18216) first presentation one after the other. mrfelek listed them and posted their registers. #5915 handles draw A, and #6014 (on #5882) handles draw B. This PR handles draw C, the third.With #5915, #5882 and #6014, mrfelek's run gets past draws A and B and stops at draw C with this message:
His local print at that draw gave a 1-sample color target, a 4-sample rasterizer and no depth target.
Draw C's registers:
PA_SC_AA_CONFIGPA_SC_MODE_CNTL_0MSAA_ENABLEclear)DB_Z_INFODB_EQAADB_DEPTH_CONTROLCB_COLOR0_INFOCB_COLOR0_ATTRIB#5882 rasterizes a draw without
MSAA_ENABLEwith every sample at the pixel center. Draw C's only target has one sample, which is taken to keep the coverage of sample 0:VK_AMD_mixed_attachment_samplesgives a color target with fewer samples than the rasterizer. RADV exposes it on AMD GPUs, and #5907 uses the same rule withMSAA_ENABLEset.With both, draw C covers exactly the pixels whose center it covers, so it is now drawn as a one-sample draw.
shadPS4 gives the same result. It rasterizes with the largest sample count of the bound depth and color targets (L416-L417, L477-L480). It reads
PA_SC_AA_CONFIGonly for aSAMPLE_COVERAGEinput (L174-L177), which this PR refuses. mrfelek's local change, which ignoresPA_SC_AA_CONFIGwhileMSAA_ENABLEis clear, also let draw C through.Neither RADV nor radeonsi programs a multisampled
PA_SC_AA_CONFIGwithMSAA_ENABLEclear:MSAA_ENABLE(L1065-L1067).So, as for #5882, what the console does is inferred, not measured.
These throw on this path:
PS_ITER_SAMPLE. The console could run the pixel program once for each of the 4 samples.ANCILLARYorSAMPLE_COVERAGEpixel input. Under a 4x configuration the console may give a different sample index or coverage than a one-sample draw does.Sample- and centroid-interpolated inputs are accepted, unlike in #5907: with every sample at the pixel center they read the center value, as in a one-sample draw.
The new debt entry records the rule, the analogy and that it is not measured on hardware.
Third commit: a one-sample depth target. With
mainc9e6c45de, this PR's previous heada3cbea1ff, #6014, #6842, #6237 and #7072, mrfelek's run draws the title and the Kant quote, and the first draw of the opening movie stops with:His probe in
DecodeStatelogged:PA_SC_MODE_CNTL_0.MSAA_ENABLEThis is draw C's case with a one-sample depth target instead of a one-sample color target. #5907's sample-0 path (
rasterizesSampleZeroOnly) needsMSAA_ENABLE, so it throws there. Onmainwithout #6014 the same state throws earlier, at #5882'smultisampled targets rasterized without MSAA_ENABLE are unsupported for points, lines, a depth target or alpha-to-coverage.The third commit draws a one-sample depth target under a multisampled
PA_SC_AA_CONFIGwithMSAA_ENABLEclear, with no color target or only one-sample color targets, as a one-sample draw at the pixel center:mainalone, and with #6014 that block sees one sample and is skipped. #5907's sample-0 path now runs only while the rasterizer still has more than one sample.perSampleShading; here that flag is computed after the block from the collapsed sample count, so it is already false.These throw on this path, with a new message (
a one-sample depth target under a multisampled rasterizer without MSAA_ENABLE is unsupported ...):DB_EQAAZ interpolation or overrasterization (INTERPOLATE_COMP_Z,INTERPOLATE_SRC_Z,OVERRASTERIZATION_AMOUNT,ENABLE_POSTZ_OVERRASTERIZATION, mask 0x0f0c0000), the bits #6014 refuses with a multisampled depth target.PS_ITER_SAMPLEand anANCILLARYorSAMPLE_COVERAGEpixel input, when the pixel program runs, for the reasons given for draw C. A depth-only draw that skips its pixel program is drawn with the null program, which uses neither, so leftover bits inPA_SC_MODE_CNTL_1andSPI_PS_INPUT_ENA/SPI_PS_INPUT_ADDRdon't refuse it.a color target's sample count differs from the rasterizer's).The debt entry now covers the depth target and these refusals. The first commit's test case that required a one-sample depth target to throw is replaced by the depth cases under Tested.
This is the depth counterpart of draw C, so it is in this PR rather than a new one: the title already covers one-sample targets, and the commit replaces this PR's own test case and rewrites its debt entry, so a separate PR would depend on this one and change the same lines.
Tested
Ubuntu 24.04, GCC 13.3, Release with
BUILD_TESTING=ON. Locally, the libusb lines were removed fromCMakeLists.txt, because the libusb submodule isn't checked out here. The first commit was tested on #5882's heade10ec3904(basemainfa539dd9b); the runs after the rebase and for the third commit are listed under Other checks.agc_driver_graphics(tests/Graphics.cpp) gainsmsaaEnableClearOneSampleTargetTests. It uses draw C's posted registers. Draw C's sample locations weren't posted, so the test uses draw B's, the standard 4x pattern of the same frame. The depth cases build mrfelek's reported state from draw C's registers, which already have a one-sampleDB_Z_INFO: depth test and write on (DB_DEPTH_CONTROL0x16) and, for the depth-only cases,CB_TARGET_MASK0. His draw's registers weren't posted, so these cases are not a dump of that draw.PA_SC_AA_CONFIG0.PA_SC_AA_CONFIGANCILLARYinputPS_ITER_SAMPLE,ANCILLARY,SAMPLE_COVERAGE, a sample-mask exportPA_SC_AA_CONFIG0.PS_ITER_SAMPLEwithANCILLARYandSAMPLE_COVERAGEinputs, pixel program skippedANCILLARY,SAMPLE_COVERAGEorPS_ITER_SAMPLEwith the pixel program running, a sample-mask export, alpha-to-coverage, a line list,DB_EQAA0x00050002, 0x00090002, 0x01010002 or 0x08010002With #5882 alone, the new test fails at draw C with the message above. With the first commit it passes, 5 runs out of 5. Removing any one of its refusals, or either of its two assignments, makes it fail.
For the third commit: with the second commit's
State.cppand the new tests, the test fails at the first depth case with #5882'smultisampled targets rasterized without MSAA_ENABLE are unsupported for points, lines, a depth target or alpha-to-coverage, the stop onmainalone. Each of 13 single changes to the new code makes it fail: removing one of the six refusal terms, removing the skipped-program exception or making it always true, removing one of the four assignments, or removing theresult.samples > 1guard on #5907's sample-0 path (which then throwsthe depth target's sample count differs from the rasterizer's).Other checks:
cteston the RTX 3050 Ti, first commit: 1,199 of 1,203 pass, 12 of them skipping themselves:agc_driver_stencil_ref_exporton this GPU, and the VideoOut flip tests, which need a display.patched_librariesandguest_usbdare Not Run because the libusb submodule isn't checked out. Two more failed in that run; both are intermittent here:agc_driver_preparation_scope_settle("the link did not wait for the vertex shader's registration preparation") fails 7 runs out of 30 with this commit, and 9 out of 30 with #5882 alone.guest_host_standard_errortimed out underctest -j10and passed 10 runs out of 10 on its own.mainwith #5915, #5882, #6014 and the first commit: fullctestgives 1,214 of 1,216, with the same 12 skips and the same 2 Not Run, andagc_driver_graphicsruns all three new test functions.mainf474fb776,agc_driver_graphicspasses 3 runs out of 3 on the RTX 3050 Ti and on lavapipe. It also passes with #5915 and #6014 merged in. Withmain'sState.cppit fails witha color target's sample count differs from the rasterizer's.3dadf7712, same base):agc_driver_graphicspasses 3 runs out of 3 on the RTX 3050 Ti and 1 out of 1 on lavapipe (Mesa 25.2.8). Fullcteston the RTX 3050 Ti: 1,288 of 1,291 pass, 12 of them skipping themselves as above, andpatched_librariesandguest_usbdare Not Run. The one failure,agc_driver_store_over_untracked("the result did not reach a block the CPU left alone"), is #6383, whose test fix #6385 landed onmainafter this branch's base: it fails the same way with the second commit'sState.cpp(14 runs out of 15), and with #6385 applied it passes 15 out of 15.main66702f1cf(which now has #5915), this branch and #6014 (4ef2af62e) merge cleanly, andagc_driver_graphicspasses on the RTX 3050 Ti. In the mergedState.cppthe depth block runs before #6014's relaxed block, which then sees one sample and is skipped. mrfelek's stack (currentmain, this branch, #6014, #6842, #6237 and #7072) also merges cleanly; that is a textual check only.e10ec3904clearssampleLocationGridin its block, which runs first. So a draw C whose 4x pattern varies between pixels ends with no grid, and its one-sample pipeline needs no sample locations. The depth block clears the grid itself, because #5882's block is skipped once the draw is one-sample; the varying-pattern depth case checks that.24528f4e5) handles one-sample targets, including a one-sample depth target, under a multisampled rasterizer withMSAA_ENABLEset, at sample 0's location. The two rules don't overlap.singleScancase inmultisampleTestsclearsMSAA_ENABLEon its 2x rasterizer over a one-sample color target, and expected the color sample-count refusal.samples1, one one-sample color target, and no custom sample locations.result.samples > 1to #5907'sif (depthKeepsSampleZero). WithMSAA_ENABLEset the sample count is unchanged at that point, so #5907's path runs as before.mainf474fb776. The branch merges cleanly into currentmain66702f1cf, and together with #6014. #5915 has since merged.docs/dev/debt/libSceAgcDriver.md. TheState.cppandtests/Graphics.cppchanges of the two merge cleanly.State.cppwith #6530 (milescoviello,6972f7a38). #6530 adds asampleCoverageSupportedRequiredirectly aboveif (depthKeepsSampleZero) {, the line this PR turns intoif (depthKeepsSampleZero && result.samples > 1) {. The resolution keeps #6530'sRequirefollowed by the guardedif. The first two commits merge cleanly with #6530.tools/check_conventions.pyfrommainpasses with this title and body.@mrfelek, thanks for the runs. With #5915, #5882, #6014 and this PR, the first presentation gets past draw C. Your next run reached the opening movie and stopped on the depth case the third commit handles, and your in-game run uses this commit.
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)3dadf7712, with #6014, #6237, #6842, #7072 and #7200, plus three local workarounds outside this PR's code)ctestfor the first and third commits,agc_driver_graphicsafter the rebase); lavapipe, Mesa 25.2.8 (agc_driver_graphics). The new checks are host-side decode tests🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-15T08:24:45Z.
Peace Walker (PPSA18216): draw C passes; the next stop is a 2D read of a 2D MSAA T#, and a plain 2D read gives strips
System: Linux, RTX 3080 Ti (NVIDIA 615.71.09)
Build:
maind92a8dad3plus #5915, #5882, #6014 and this PR (cfa1a78ec), plus a local probe (see below). All four PRs merge cleanly. Started through the launcher hand-over from #5268.Draws A, B and C pass
Draw C no longer throws
a color target's sample count differs from the rasterizer's. The first presentation then stops in a pixel shader:The T# type nibble is
0xe(Color2DMsaa, type 14). The shader does a plain 2Dimage_sampleon it.A plain 2D read gives strips (local probe)
A local probe reads a 2D MSAA T# as 2D. With the probe on, the first layer passes and the logo comes up:
Both images are below. The reference is a PS5 stream, cropped to the game area.
This is a probe, not a fix. It shows that a plain 2D read is the wrong target, but not which sample or layout the hardware returns, which is the question SandstromPL raised.
On the measurement question
Agreed, that's the open part. We looked at
tools/hw-oraclefor it: it runs single-lane RDNA arithmetic and checks float behaviour, so it can't render an MSAA target or read its memory layout. It also needs ROCm and an AMD GPU, and this machine has an NVIDIA card. So we don't have a way to measure this here.Launcher hand-over (#6000)
With #6000 (
e7219e4bc) onmain, the hand-over stopped withProcessShutdown. Reverting it made the launcher start the game again. That's still the only change that fixed it here.AI-assisted; the runs are from my machine.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-15T08:32:25Z.
@mrfelek Thanks for the run! Good to see draws A, B and C all through, and that the four PRs merge onto
maintogether.Agreed, the next stop is separate. It is a 2D MSAA T# (dim 6) read through a pixel shader whose static interface accepts only
Dim2DandDim1D. No open PR handles it. To implement it, someone would need to measure what RDNA returns when a non-MSAA image instruction reads an MSAA resource: sample 0, fragment 0, or something else. That takestools/hw-oracleon an AMD GPU, which I don't have, so I've left it for now.AI-assisted.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:31Z.
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.
main)core/libs/prx/libSceAgcDriver/Graphics/src/State.cppL1132-1133Some 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.
core/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-16T19:24:09Z.
Rebased onto
mainf474fb776, which now has #5882 and #5907. #5907 added asingleScancase tomultisampleTeststhat clearsMSAA_ENABLEon its 2x rasterizer over a one-sample color target, and expected the color sample-count refusal. That's draw C's state, so with this PR it decodes. The second commit makes the case require a one-sample draw with the standard location instead. @simonbronk, it's your test, so please say if you'd rather pin it differently.agc_driver_graphicspasses 3 of 3 on an RTX 3050 Ti and on lavapipe. It also passes with #5915 and #6014 merged in, and fails withmain'sState.cpp.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-17T07:44:50Z.
@SandstromPL fine with me. The
singleScancase only pinned that the draw was refused, and with this PR it is draw C's state, so requiring a one-sample draw at the standard location is the right expectation.Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-17T14:21:37Z.
Peace Walker (PPSA18216): with
a3cbea1ffthe next stop is a depth-only draw, MSAA_ENABLE clear, 4-sample rasterizer, one-sample depth targetSystem: Linux, RTX 3080 Ti (NVIDIA 615.71.09)
Build:
mainc9e6c45deplus this PR (a3cbea1ff), #6014, #6842, #6237 and #7072. Local changes: an AvPlayer change the game's movies need, and the change below.The launcher hands over to
mgspw.elf, the title and the Kant quote draw, and the opening movie's first draw stops on the depth refusal:A probe in
DecodeStatelogs the state of that draw:PA_SC_MODE_CNTL_0.MSAA_ENABLE(0x292 bit 0)depthKeepsSampleZerois true, butrasterizesSampleZeroOnlyreturns false straight away because MSAA_ENABLE is clear, so theRequirethrows. That's the depth-target counterpart of draw C's color case. The color loop already handles a one-sample color target under a multisampled rasterizer with MSAA_ENABLE clear: one sample at the pixel center.Locally I made the depth case do the same, before the
rasterizesSampleZeroOnlybranch:With it the refusal is gone and the draw renders.
I didn't add the color path's refusals here:
PS_ITER_SAMPLE, a sample-index or coverage input, and a sample-mask export. They probably belong on the depth case too. I'll leave whether and how to cover it to you, since it's your PR's area.AI-assisted; the runs are from my machine.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-17T16:58:58Z.
@mrfelek, thanks for the run and for tracing it to
rasterizesSampleZeroOnly. The depth case is now in this PR as a third commit,3dadf7712. A one-sample depth target under a multisampledPA_SC_AA_CONFIGwithMSAA_ENABLEclear is now drawn as one sample at the pixel center, by the same rule as draw C. This covers a draw with no color target or with only one-sample color targets.It no longer relies on #6014's relaxation. The new block runs before #5882's multisampled-target block, so on
mainalone your state is drawn instead of stopping at... a depth target .... With #6014, that block sees one sample and is skipped.perSampleShadingis computed after the new block from the collapsed sample count, so it doesn't need clearing.The color path's refusals are mirrored. These still throw, with
a one-sample depth target under a multisampled rasterizer without MSAA_ENABLE is unsupported ...:DB_EQAAZ interpolation or overrasterization (0x0f0c0000, the bits #6014 refuses with a depth target)PS_ITER_SAMPLE, or anANCILLARYorSAMPLE_COVERAGEinput, when the pixel program runs. A depth-only draw that skips its pixel program gets the null program, so leftover bits there don't refuse it.A 4x color target next to the one-sample depth target still fails the color sample-count check.
Could you rerun Peace Walker with this head instead of your local change, keeping the rest of your stack, and post the next stop? This head, #6014, #6842, #6237 and #7072 merge cleanly on current
main. If the movie draw stops on the new message, please post that draw's0x293,0x1b3,0x1b4,0x203,0x201and0x2dcvalues and its primitive type. They would show which refusal fired.AI-assisted: yes (Claude Code)