feat(agc): draw partial writes of multisampled 4_4_4_4 targets into a temporary target #11557
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11557"
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 JAB-dev on 2026-10-26T19:21:56Z.
What
Arcade Game Zone (PPSA19015) stops at its LOADING screen on current main, 14 to 16 seconds after the start, on two refusals of the 2-sample 4_4_4_4 partial write. Such writes are now drawn through the render pipeline into a temporary target and merged afterwards, so both refusals go away.
Current main, first stop:
AGC graphics: partial writes of a multisampled 4_4_4_4 unorm color target run the pixel shader once per sample, so a shader the guest runs once per pixel cannot read the ancillary word or, unless every sample sits at the pixel centre, centroid, sample-located or pull-model barycentrics, Z, 1/W or a position at the centroid or a sample: they would follow the invocation's sample (SPI_PS_INPUT_ENA 0x402, SPI_PS_INPUT_ADDR 0x402, SPI_BARYC_CNTL 0x1000000, sample 1 location 0xc4)With that relaxed, the second stop:
ShaderRecompiler::Recompile: a partial write of a packed color target merges inside the pixel shader after early depth and stencil tests, which a shader that kills pixels under late tests of a draw writing depth or stencil, exports depth, stencil or coverage, or runs with a quad sample mask cannot useA partial write of a 2-, 4- or 8-sample 4_4_4_4 UNORM target merged inside the pixel shader: it ran once per sample under a pixel interlock with forced early tests, so the merge could not follow a shader that kills pixels after the depth test or whose inputs follow the sample. The draw now runs at the guest's shading rate into a temporary R32_UINT target of the same size and sample count, with the draw's own depth, stencil, kill and coverage state, cleared to a marker no packed word has. A compute pass then replaces the written bits of the samples the draw wrote, inside its scissor. A pixel the depth test rejects or the shader kills never reaches the temporary, and the last fragment to pass wins, whatever the order of fragments inside the draw. A color logic operation, blending and a device that puts the guest's samples in order still throw.
One-sample partial writes keep their in-shader merge and its refusals. The recompiler's multisample merge variant is no longer reached by the driver; it is still exercised by the recompiler tests in
agc_driver_graphics, and removing it changes the request serializer and cache versions, so it is left for its own PR.After this change Arcade Game Zone stops at its next step,
native multisample stencil or depth format import is not implemented, which the open native multisample depth work covers.Tested
Windows 11, NVIDIA RTX 4070 SUPER, driver 610.88.
agc_driver_packed_unorm4444_multisample_partial_write: 2, 4 and 8 samples, a merge, a full write over it and two merges back to back, each sample checked against its location in the triangles. New cases at 2, 4 and 8 samples: a checkerboard kill under late tests, a merge inside an offset scissor smaller than the target (the pixels outside keep their word), a shader that reads POS_Z over a sloped depth (every sample of a pixel must hold the same word, and running the shader per sample fails it). At 2 samples with a depth target: a second merge at the same depth that must land only where the first draw killed (a killed pixel writes no depth). Merging every sample, written or not, fails the test.agc_driver_graphics: the 2-sample target decodes as staged at the guest's shading rate for every input the old merge refused (centroid and sample barycentrics, pull model, ancillary, Z, 1/W, positions at a sample, SAMPLE_COVERAGE), LINEAR_SAMPLE, and a color logic operation throws. The test's sample-count gate checks the R32_UINT staging image as well as the R16_UINT target.agc_drivertests that touch draws, targets, multisampling and pipelines, andcheck_conventions.py.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V, same machine and GPU): 32 focused tests give the same VUID sets on main and on this change. The multisample partial write test gainsVUID-VkGraphicsPipelineCreateInfo-renderPass-06053, which main already reports for every test that draws with a depth target (this test draws with one now). The message is identical to main's for the multisampled pass order test:has fragment state and a depth format (VK_FORMAT_D32_SFLOAT) or stencil format (VK_FORMAT_UNDEFINED) and an invalid pDepthStencilState structure.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)mainagain on top of this one once it lands🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T22:04:47Z.
Review: CHANGES_REQUESTED
I reviewed the implementation and the reported overlap against current
main3ae0fb5601542063bd2748ea10aa70598672eed2. Both branches merge cleanly intomainindependently, but a three-way merge of #11557 with open #9335 conflicts inExecution/src/Driver/Draw/DrawRegisterKey.cpp,Graphics/include/State.hpp,Graphics/src/State.cpp, anddocs/dev/debt/shader.md. The description acknowledges the overlap but saysDepends on: noneand only that the second PR to land rebases.CONTRIBUTING.mdrequires authors to agree which overlapping change lands first and declare the required order withDepends on. Please coordinate the order with #9335’s author and update the checklist to name the dependency if one must land first. I’m holding approval on that integration requirement; this is not a finding against the reported GPU results.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T03:54:47Z.
Review: COMMENTED
Linux run of head
c249f30fe: the build breaks on Linux/GCC. With that fixed, the new staged path passes on NVIDIA and lavapipe.Linux build
Merged onto
maincb45ae2dd(no conflicts),libSceAgcDriverstops compiling:The check sits under
#if defined(__linux__) && defined(__x86_64__) && defined(__GLIBCXX__), so it doesn't fire on Windows, and thelinuxCI job doesn't run on this PR. The three newColorTargetfields (staged,stagedMask,stagedFormat) makeState8 bytes larger throughState::color. The recipe codec andCanonicalPipelineStatestill carry onlyformat,exportIndex,componentMappingandpartialWriteMaskper color. A staged target'sformatis alreadyR32_UINT, so that looks enough, but you're in a better position to confirm it. For the runs below I only changed the number to848.Tested
Ubuntu 26.04, GCC 15.2.0, Release,
ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1, device chosen withVK_ICD_FILENAMES,-j1. This PR merged ontomaincb45ae2dd, plus thesizeof(State)change above.Focused tests,
--repeat until-fail:3:agc_driver_packed_unorm4444_multisample_partial_write,agc_driver_packed_unorm4444_partial_write,agc_driver_packed_unorm4444_color_target,agc_driver_packed_unorm_color_targetandagc_driver_graphicspass 3/3 on both devices. The multisample test runs every case on both, with no skip:ctest -R "^agc"without display/flip/lds_atomics64,--timeout 30:maincb45ae2ddNo new failures. On
main, NVIDIA's one failure isagc_driver_sgpr_pattern_fill_keys, which passed on later runs. lavapipe failsagc_driver_multisample_retirementonmainand with this PR.I couldn't run a negative control. Both updated test files use the new
ColorTarget::staged/stagedMask/stagedFormatandStagedMergeTarget, so they don't build againstmain's driver sources.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.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T05:37:49Z.
Review: APPROVED
Reviewed — approved
The staged R32_UINT draw plus compute merge builds on Linux/GCC, passes its focused tests with validation layers on an RTX 4070 Ti SUPER with no new
VUID-lines, and a mutation of the merge kernel makes the new test fail. I found nothing blocking.What I ran
Head
173ce1f14d939714d6c4c54a2c090b1ecfb672cd, merged with--no-ffontomain52c09d567d2fa453494dd720fcf53a98149468e4(no conflicts), in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja, Intel Core i9-14900KF, NVIDIA GeForce RTX 4070 Ti SUPER (driver 615.78.08).Results
maingit diff --checkcheck_conventions.pyAll conventions checks passed.libs), merged treesizeof(State) == 920guard inPipelineJournal.cppholds with GCC 16.2.1, so the build break jotitadev reported onc249f30feis fixed at this headmain, validation onVUID-linesmain, 0 on the merged treewas not found but was requested by env var VK_INSTANCE_LAYERSInsert instance layer "VK_LAYER_KHRONOS_validation"in bothagc_driver_graphics4.91 s; the multisample partial write test 0.97 sThe description says the multisample test gains
VUID-VkGraphicsPipelineCreateInfo-renderPass-06053on Windows. On this Linux host and driver neither side logs anyVUID-line, so I could not reproduce it.Multisample partial write test, merged tree
ctest summaries
Negative control
I put the PR's
tests/execution/PackedUnorm4444MultisamplePartialWrite.cppon top ofmain's production files. It does not compile becauseColorTargethas nostaged,stagedMaskorstagedFormatthere. That shows the test depends on the new code, but it says nothing about behaviour.On the merged tree I changed
PackedMerge.compso it merges every sample, written or not (if (false && word == unwritten) continue;). The test then fails on its first check:After restoring the shader, the test passes again. This confirms the description's claim that merging unwritten samples fails the test.
Findings
Blocking
None.
Non-blocking
StagedMerges::Acquireadds a device-local multisampled R32_UINT image for every new extent and sample count, and keeps it until the device is torn down. An 8-sample 1920×1080 temporary is about 66 MB. A title with dynamic resolution or several such targets would keep accumulating them. The debt entry documents this ("kept per size and sample count"). The comparable copy cache inSampleOrder.cppis bounded to 4 entries with LRU eviction; the same pattern would fit here. Recorded batches already hold the temporaries they use throughrecorder->Keep(write.temporary), so evicting one is safe.RecordedDrawnow sits aboveStagedWrite. In Draw.cpp:2066-2078, the new struct was inserted between the "What recordDraw records from…" comment andstruct RecordedDraw. MovingStagedWriteabove the comment fixes it.Requirecannot fail, and the recorded image handle can be stale. In Draw.cpp:2834-2836,MultisampleTargetViewcapturesbinding.multisampleImagefirst.MultisampleTargetStorageViewthen runsStorage, which already throws with a clear message when the form cannot be stored. Otherwise it callsmakeStorable, which on the first storage access retires the image and replaces it.Require(MultisampleTargetStorable(...))added after review therefore always passes:Storagehas either thrown or made the image storable.record.multisampleImages(which feeds the pass'spassAttachments) gets the retired handle. The harm is limited because the staged draw forces a new pass and the merge closes it.MultisampleTargetStorageViewbeforeMultisampleTargetView(..., &binding.multisampleImage), asmain's order did, and drop the redundantRequire.CONFLICTINGagainstmainand this PR merges cleanly. The description proposes that this PR lands first and #9335 rebases on it, which matchesDepends on: noneunder CONTRIBUTING.md. The agreement itself still has to come from #9335's author.Not verified
renderPass-06053message the description mentions.agc_suite. I ran only the five focused tests above.SampleOrdercopies, and I did not test it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:54:52Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
173ce1f14d939714d6c4c54a2c090b1ecfb672cd. The reported Windows/validation runs and the Linux size-guard correction address the prior technical test concern. The current-main merge preview is clean. The remaining blocker is the shared edit with open #9335: your proposed order is #11557 first, but #9335’s author has not confirmed it, and this PR still recordsDepends on: none. The current overlap requires an agreement on which lands first and the second PR’s rebase/retained hunks; please record the agreed order in both checklists. I am holding approval for that repository integration requirement, not questioning the reported GPU results. I did not run a local GPU suite.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:02:24Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
Since my last review the branch was rebuilt as one feature commit plus two merges of
main, and the merged tree no longer compiles with Linux/GCC.mainand this PR each raised thesizeof(State)guard from 920 to 928, and git keeps that line without a conflict. The real size is now 936. When I patch the guard by hand, the code builds and the focused tests pass on lavapipe with validation on.What changed since my last review
173ce1f14d, the separate "update the Linux State size guard" commit, is gone. Its change from 920 to 928 is now inside7ef4e4a696.7ef4e4a696followsmain's rename ofExportTargetMergetoExportTargetMerges(it now returns a vector). It also takesmain's wording for the "another merged color target" refusal, addsother.stagedto that refusal, and updates the two debt entries to match. The tests useExportTargetMerges(...).empty()/.size() == 1uin place ofmask == 0u.main(3fde7f528a,734d8d19d7). The description now records the agreed order with #9335.What I ran
Head
734d8d19d75fe80f1b5608c0a6c27aaffaee6d80, merged with--no-ffontomainaeae1aebe7dd76d37e620f1c57e211ad6e13f337, in a clean worktree. Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pyAll conventions checks passed.PipelineJournal.cpp:44: static assertion failed ... the comparison reduces to '(936 == 928)'was not found but was requestedline, and 0VUID-linessample 0 of pixel (0, 0) holds 0xf69c, neither the merged word, ...Build error (merged tree, unmodified)
Focused tests with the guard patched
agc_driver_graphicstook 39.5 s under-j8with validation on lavapipe. TechLevelZero's NVIDIA runs report this test over 30 s onmainas well, so I am not counting it against this PR.Previous findings
StagedMerge.cpp:90Acquirestill only adds entries, and only device teardown (StagedMerge.cpp:273) removes them.RecordedDrawdoc comment sits aboveStagedWrite: Still open (non-blocking). The comment is atDraw.cpp:2209,struct StagedWriteat 2213 andstruct RecordedDrawat 2221.Requireand a possibly stalemultisampleImagehandle: Still open (non-blocking).Draw.cpp:2983-2985still callsMultisampleTargetView(..., &binding.multisampleImage)beforeMultisampleTargetStorageView, thenRequire(MultisampleTargetStorable(...)).mainon top of this PR. That comes from the author's description, and I did not check it on #9335.New findings
Blocking
sizeof(State)guard). The guard is atPipelineJournal.cpp:44. At the merge base69bfe76785it read 920.mainraised it to 928 in372d688b87for its ownStategrowth, and this PR raised it from 920 to 928 for the three stagedColorTargetfields. Both sides changed the line identically, so git merged it silently. With both growths,Stateis 936 bytes, andlibSceAgcDriverfails to compile on Linux x86_64 with libstdc++, which is what thelinuxCI job uses. The test results reported on734d8d19d7were all on trees that did not have both growths, or on Windows, where the guard is compiled out. Fix: merge currentmainagain, set the guard to the size measured on the merged tree (936 againstaeae1aebe7), and check that the recipe codec still needs no new field. My earlier review accepted that point for the staged fields. I did not check whatmainadded.Non-blocking
None beyond the three still-open items above.
Not verified
mainin this run: the bot's comparison was skipped because the build failed. I ran the five focused tests on the patched merged tree with the layer active and saw noVUID-lines, but I did not runmainagain.main: the tests useColorTarget::stagedandStagedMergeTarget, so they do not compile againstmain. I used the merge-kernel mutation above instead.To get this to a good state
main, update thesizeof(State)guard to the size GCC reports on the merged tree, and confirm a Linux/GCC build oflibs.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:42:22Z.
Review: APPROVED
Re-checked — approved
The new commit
f8112e0de6changes the Linuxsizeof(State)guard from 928 to 936, and3ffeb212b0merges currentmainagain. The merged tree now builds with GCC, which fixes my one blocking finding. The focused tests pass on lavapipe with validation on, and the merge-kernel mutation still makes the multisample test fail.What changed since my last review
f8112e0de6(new): a one-line change atPipelineJournal.cpp:44,sizeof(State) == 928→936. Nothing else in the commit.3ffeb212b0: a merge of currentmain. The range-diff shows the feature commit7ef4e4a696is unchanged.What I ran
Head
f8112e0de6628a9fb48a10c7a8d652661a1f42dc, merged with--no-ffontomain9090972b7e91fd266819cbd77a8b058e177b5682(merged treece0cc84f8f4d25d691fffb36568e048b81efbf88), in a clean worktree. Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pyAll conventions checks passed.libsand the selected tests, from the bot's run)mainmain(bot's run, 757 tests)VUID-lineswas not found but was requestedline, 0VUID-linesFocused run
Mutation
agc_driver_graphicsandagc_driver_pipeline_journaltook more than 30 s with validation on under-j8. TechLevelZero's NVIDIA runs report both over 30 s onmainas well, so I am not counting them against this PR.Previous findings
sizeof(State)guard): Resolved (blocking).PipelineJournal.cpp:44now reads 936, and the merged tree compiles with GCC 14 on x86_64 Linux with libstdc++.main's own guard change,372d688b87, edits only that line. Whethermain's ownStategrowth needs a recipe field is a question formain, not for this PR.StagedMerge.cpp:90Acquireonly adds entries. Only device teardown at line 273 removes them.RecordedDrawdoc comment sits aboveStagedWrite: Still open (non-blocking). The comment is atDraw.cpp:2209,struct StagedWriteis at 2213 andstruct RecordedDrawat 2221.Requireand a possibly stalemultisampleImagehandle: Still open (non-blocking). SeeDraw.cpp:2983-2985.New findings
Blocking
None.
Non-blocking
None.
Not verified
R16_UINTstorage targets and skips them. I also did not check other GPU vendors, Windows, or the title PPSA19015. The author's Windows/NVIDIA runs and the other contributors' runs are author-reported or third-party.main: the tests useColorTarget::stagedandStagedMergeTarget, so they do not compile againstmain. I used the merge-kernel mutation instead.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T09:17:19Z.
Review: APPROVED
Re-checked — approved
The only change since my last review is
1b12e6f302, a merge of currentmainthat resolves a conflict inlibSceAgcDriver/CMakeLists.txt. The resolution is correct, and the merged tree builds with GCC. The focused tests pass on lavapipe with validation on. The one newVUID-line in the bot's run comes from code onmain, not from this PR.What changed since my last review
1b12e6f302: a merge oforigin/mainwith a conflict incore/libs/prx/libSceAgcDriver/CMakeLists.txt. The range-diff shows7ef4e4a696andf8112e0de6unchanged.What I ran
Head
1b12e6f30246623db99280731c3690e9f004bd52, merged with--no-ffontomain4f41f4c375f5abb487dbd184fbc150f31994d762(merged tree3e6306140a9b8ffff933ba17e9b433d018fb3435), in a clean worktree. Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pyAll conventions checks passed.CMakeLists.txtagainstmainPackedMerge.compSPIR-V rule,StagedMerge.cppand${agcPackedMergeShaderHeader}inagcDriverSources.main's newStagingCopyBackandTextureDetileWordsentries are keptlibsand selected tests, bot's run)mainVUID-lines,agc_driver_native_depth_uniform_planes; see belowVUID-lines, nowas not found but was requestedlineFocused run
The new
VUID-vkCmdDispatch-groupCountX-00386comes frommain. The bot marks it(test not run on main):main's baselined1ae628bc2has noagc_driver_native_depth_uniform_planes.mainadded that test after the baseline, through the uniform-depth branch merged infec9ceae93. The error isgroupCountX (69144) exceeds device limit maxComputeWorkGroupCount[0] (65535). This PR changes neitherDepthSurface.cpp, nor the test, nor the detiler. Its only new dispatch,StagedMerge.cpp:122, uses(width + 7) / 8by(height + 7) / 8groups for the scissor area, so it cannot reach 69144 groups in X. I tried to confirm this by rebuilding with the PR's production files taken frommain. The sandbox could not reconfigure CMake, so that rebuild did not happen. The conclusion therefore rests on the code, not on a run. The worktree was restored,git status --porcelainis empty, and the build directory was not changed.Previous findings
sizeof(State)guard): Resolved earlier. The merged tree still builds with GCC 14.Graphics/src/StagedMerge.cpp:90:Acquireonly adds entries. No code changed.RecordedDrawdoc comment sits aboveStagedWrite: Still open (non-blocking). The comment is atGraphics/src/Draw.cpp:2218-2221andstruct StagedWriteat 2223. Only the line numbers moved, frommain's changes.Requireand a possibly stalemultisampleImagehandle: Still open (non-blocking). SeeGraphics/src/Draw.cpp:2990-2993.New findings
Blocking
None.
Non-blocking
None.
Not verified
VUID-line also appears without this PR. The sandbox could not regenerate the build, so this rests on the code reasoning above.PackedMerge.compand the test are unchanged since my last review, where the mutation made the test fail.R16_UINTstorage targets. Other GPU vendors, Windows, and title PPSA19015 were not run here; those results are reported by the author or by other contributors.