feat(agc): sample multisampled depth through a shadow image #7318
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7318"
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 MarcZX10 on 2026-10-17T23:17:01Z.
What
Multisampled depth attachments currently add
VK_IMAGE_USAGE_SAMPLED_BITto the native image when a device supports it. Create a separate same-format, same-sample-count shadow image with sampled and transfer-destination usage instead, and copy the native depth samples into it before each per-use read that needs a refresh. This keeps sampled usage off the depth attachment and copies every sample without resolving it. If a device cannot create that shadow-image usage combination but can sample the original attachment as before, retain the direct path as a fallback.The native multisample depth regression now resolves the cached sampled view again after each raster write and checks the readback, so stale shadow contents fail the test across the supported D16/D32 and 2x/4x/8x cases.
This is the separate shadow-image prerequisite requested in the review of #5499. It does not implement the DB depth-copy draw; #5499 can build on this after it merges.
Tested
Rebased onto current
mainat5229b5b82; current headff332e7efdb05563ca03265d3511810c9f445a52.Linux x86-64, GCC 12.2.0, Release,
BUILD_TESTING=ON: configured and builtagc_driver_native_multisample_depth_tests. GCC 12 stops on an unrelated dependent-template parse error inSrtDescriptorEvaluation.cpp; for the local build only, I applied thetemplatedisambiguator in that file and restored it afterward. The changed AGC source and regression test compiled successfully on the rebased head.The regression now writes the first native multisample depth target, binds a second target, then samples the first while it is no longer the active draw target. It checks the depth readback. The shadow image is also allocated on first sampling, avoiding the extra image for eligible surfaces that are never sampled.
ctest --test-dir /tmp/AnyPS5-7318-review --output-on-failure -R '^agc_driver_native_multisample_depth$' --timeout 120aborts before Vulkan device selection and assertions at the project CPU-feature guard: this Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA. No local GPU runtime or title test is claimed. Conventions andgit diff --checkpass.Manual overlap review: #6146 changes the out-of-place depth-expand path; #6557 expands HTILE eligibility coverage in the same test fixture; neither implements shadow refresh. #7256 adds layered single-sample depth views and is a separate behavior, though both changes touch
DepthSurface.cppand will need manual integration if both merge. The overlap tool also cannot compare older conflicting PR bases, so its warning is not treated as proof of no overlap.Checklist
main; no other open PR implements the shadow-image pathNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T23:33:15Z.
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/tests/execution/NativeMultisampleDepth.cppL664Some 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/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/tests/execution/NativeMultisampleDepth.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppcore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:40:22Z.
Overlap note after comparing #7256: the features are separate—#7256 adds single-sample layered depth views, while this PR adds a sampled shadow for native multisampled depth. The layered-depth path explicitly rejects multisampled layers, so I found no shared behavior or prerequisite. However, both change
DepthSurfaceconstruction/usage setup, and a merge preview of the two heads reports a content conflict inDepthSurface.cpp; they will need a manual integration if both remain active. This PR does not include or depend on #7256.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T00:57:11Z.
Thanks for splitting the shadow out of #5499. I ran the PR's own test on a device, and the shadow path returns stale depth.
Run: RTX 4090, Linux, main
a8581d3331+ this PR at ea335672612,NativeMultisampleDepthadded toANYPS5_AGC_EXECUTION_TESTS.useSampleShadow = false(direct path)refreshSampleShadowremoved (always copy)Every failure is
native depth sampled fetch lost a raster sample or its component mapping(NativeMultisampleDepth.cpp:710).With the copy forced every time, all four pass. So the copy and its barriers are fine, and the problem is the skip at DepthSurface.cpp:590:
It treats the shadow as current when it isn't. Two things in the code look like they cause it:
written == 0: the member starts at 0 (DepthSurface.cpp:751), and :1341 only bumps it for!created || inherits.sampleShadowWrittenalso starts at 0, and :606 stores 0 after a drawn copy. For such a surface,0 == 0reads as "already copied", both before the shadow is first filled and after every drawn refresh.written. Onlydrawn(found == drawnDepth, :1469) covers them, anddrawnDepthis reset byClearDepthSurfaces(:1414) and moves when another depth target is bound. A raster write made before that reset is never copied.Could you:
writtencan also hold.drawnis false). The current cases keep the target asdrawnDepththroughout, so thewrittenbranch never runs.agc_driver_native_*results from a device. Linux CI runs them on llvmpipe, which isn't enough for this path on its own.Not blocking, but worth looking at in the same pass:
Sampled()would avoid that.drawnDepth, each sampling use copies the whole MSAA image (about 33 MB at 1080p 4x D32). A number for the worst case on a title that samples MSAA depth would help.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T01:37:30Z.
Thanks for the detailed reproduction; it exposed a real stale-shadow path. I pushed
ff332e7efon top of currentmain.The fix creates the shadow only on first sampling, gives every bound native surface a nonzero write generation, and advances the previous surface generation when another depth target becomes active. That makes a later sample of the no-longer-active target refresh its shadow. The regression now rasterizes one target, binds a second target, then samples and checks the first target\x27s depth readback.
The exact rebased head builds
agc_driver_native_multisample_depth_testson Linux after a temporary, restored GCC 12templatedisambiguator in unrelatedSrtDescriptorEvaluation.cpp. CTest stops before device selection/assertions at this Xeon E5-1620 v2 CPU feature guard, so I cannot provide the requested physical-GPU results from this host. The PR\x27s Linux/Windows test jobs are skipped by workflow gating. If a GPU-capable reviewer is available, could you rerun the four native depth groups on this head and report the selected device and results? I have not claimed a runtime pass.I also changed shadow allocation to first sample, addressing the unused-shadow memory cost. The copy remains per use while the surface is the active draw target for correctness; I do not have a title measurement for that cost yet.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T17:38:21Z.
I ran head ff332e7ef on an Apple GPU. The new regression still catches a stale shadow, and the cause isn't device-specific. There's also a second failure, in
agc_driver_graphics. CI skipped linux/windows on this head, so I don't think anyone has run it on a device yet.Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Method: main
81cb86339+ @mugurc'sci/macos-series-2(fa6d8ae0b, which has the MoltenVK device bring-up) + the open fixes it uses as stand-ins, then this PR merged on top (clean,DepthSurface.cppauto-merged). Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363), and MoltenVK main with SPIRV-Cross #2704.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1.useSampleShadow = falserefreshSampleShadowremovedBoth drivers give the same results. The failure is the same one as in the earlier run:
native depth sampled fetch lost a raster sample or its component mapping. The shadow copy itself works here, since always copying passes. The problem is the skip.Where it goes stale. It fails in the second loop pass (offset 0.25). Every sample reads 0.0625, the depth from the offset-0 raster, where 0.3125 is expected. In that pass:
DepthSurfaceView(context, target)bumpswritten.CachedSampledTextureat the top of the loop runs before the raster. It refreshes the shadow and setssampleShadowWritten = written.writtenafter it.CachedSampledTextureand the fetch skip the copy.The first pass only works because binding
otherTargetbumpswrittenagain. With the lookup at the top of the loop removed, all four pass.A one-line fix. In
DepthSurfaceTexture, the single-sample path passesfound == drawnDepthtoSampled, but the multisample path callsfound->Sampled(words, resource, components)without it. So a sample of the bound target never forces a refresh:With that change, all five
agc_driver_native_*depth*tests pass 3/3 on both drivers.Second failure:
agc_driver_graphics. It fails on every run with the PR and passes without it:That's
tests/DepthSurfaceReuse.cpp:339(TestMultisampleDepthOwnership, mocked Vulkan). It still expectsVK_IMAGE_USAGE_SAMPLED_BITon the attachment when the format supports sampled MSAA. With this PR, that's exactly the case where the attachment no longer gets it. So it should fail on any device. It probably needs to check the shadow image's usage instead, or that the attachment does not get sampled usage.Full
^agc|^shadersuite with the PR and the one-line change (MoltenVK 1.4.2,-j1 --timeout 30, flip/display/lds_atomics64 excluded): the 46 failures of the tree without the PR, plusagc_driver_graphics.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 MarcZX10 on 2026-10-18T18:42:06Z.
I checked your report against the current head
ff332e7ef: the multisample path atDepthSurface.cpp:1454callsfound->Sampled(words, resource, components)withoutfound == drawnDepth, while the single-sample path at :1472 passes that flag. The mocked ownership test atDepthSurfaceReuse.cpp:339also still expectsVK_IMAGE_USAGE_SAMPLED_BITon the native attachment, which conflicts with the shadow-image design.The reproduced stale-shadow failure is therefore actionable. Please pass
found == drawnDepththrough the multisample path and update the ownership test to assert the native attachment stays unsampled while checking the shadow image's sampled usage. The reported four-group results on the M2 Max make this a strong validation case; please rerun those after the fix, includingagc_driver_graphics.I have not pushed a change to your branch. My local GCC 12 test build is currently blocked earlier by an unrelated
SrtDescriptorEvaluation.cppdependent-template parse error already tracked by open fixes #6306/#6738.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:43:45Z.
Fixed in
132dbd1f0: the multisample lookup now passes whether the owner is the currently bound depth target, matching the single-sample path and forcing shadow refresh for the drawn target. UpdatedTestMultisampleDepthOwnershipto assert sampled usage remains off the native attachment when the sampled shadow path is available.Validation:
agc_driver_graphics_testsbuilt and the isolated--depth-surface-reusefixture passed. This host normally exits at the CPU-feature guard, so I temporarily bypassed only that guard for the fixture run; GCC 12 also required a temporary dependent-template disambiguator in unrelatedSrtDescriptorEvaluation.cpp. Both temporary edits were restored and are not in the commit. No GPU execution result is available from this host.check_conventions.py --base upstream/mainpasses; GitHub eligibility, conventions, labels, and report checks pass; platform build/test jobs are skipped by workflow gating.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T21:51:42Z.
Thanks for the rework. Review and CI both pass on 132dbd1f0f, but the PR now conflicts with main after #6635 (MSAA array descriptor shape) merged, in
Graphics/src/DepthSurface.cppandtests/execution/NativeMultisampleDepth.cpp.It isn't a mechanical conflict, so it needs your rebase rather than ours. #6635 adds
multisampleViewTypeto the sampled-depth texture key (the key grows from 12 to 13 words), picks the view type from it for multisampled targets, and passes it toSampled(..., multisampleViewType). This PR moves the texture-cache lookup after the shadow refresh, builds theTextureover the shadow image and callsSampled(..., found == drawnDepth). Both rewrite the key and lookup order, the view-type choice, theTexturecreation and theSampled()arguments. So the rebase has to decide two things: does the array view sit over the shadow image, and does the cache key cover both the view type and the shadow? The test hunk overlaps the same way (#6635's array-texture checks vs this PR's shadow-view checks).Could you rebase onto current main, keep #6635's array view for multisampled targets and keep both sets of test checks? After that we'll re-review the delta and run full CI.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T22:29:53Z.
Rebased this branch onto current main and resolved the #6635 overlap while preserving the array view type in the sample-view cache key and in texture creation, refreshing the bound depth shadow before cache reuse, and retaining both the existing array-view regression coverage and the new depth-surface reuse checks.\n\nValidation: the
agc_driver_graphics_teststarget builds successfully with Ninja. I attempted to run it, but this Linux host exits at the emulator CPU capability guard before any tests execute (Xeon E5-1620 v2 lacks AVX2, BMI1/2, LZCNT, MOVBE, and FMA). Hosted full build jobs are skipped by repository policy, and I cannot manually dispatch the workflow because GitHub returns HTTP 403 requiring admin rights. The branch passes the repository conventions and diff checks.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:27:48Z.
Review: COMMENTED
A device run of the rebased head
91be80b44, since the host you rebased on stops at the CPU guard and hosted CI hasn't run on it. Everything passes on an RTX 3070 and on lavapipe, and the new regression is what catches the stale shadow I hit onff332e7ef.Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON, every execution test built. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged ontomain84c1a4d9a(clean, so #6635 is in).ANYPS5_NO_SHADER_CACHE=1,-j1 --timeout 30.Tests:
agc_driver_native_multisample_depth,_depth_retirement,_depth_clears,_depth_clear_refusals,_depth_bda_clear,agc_driver_native_msaa_vertex_inputandagc_driver_graphics(which hasTestMultisampleDepthOwnership).91be80b44depth_bda_clearskips, as onmain)mainagc_driver_graphicsfailsrefreshSampleShadowremoved (always copy)useSampleShadow = false(direct path)drawnDepth->written = ++depthWritesremoved fromDepthSurfaceViewmultisample_depth,depth_clears,depth_clear_refusalsfaildepth_bda_clearskip.agc_driver_graphicsonmainfails witha native MSAA depth attachment must keep sampled usage off when the shadow path is available. That is the updated ownership check, so it is expected. With the PR it passes.native depth sampled fetch lost a raster sample or its component mapping, the same three tests and message as the stale shadow onff332e7ef. So the new "bind another target, then sample the first" case does guard that bump. The 6 native tests pass onmainbecausemainsamples the attachment directly and has no shadow to go stale.2D_ARRAYchecks from #6635 in the same loop pass on both devices, so the array view over the shadow image comes back from the cache unchanged across the raster writes.Full
^agcsuite with the PR (731 tests, without display/flip/lds_atomics64): the same result asmainon both devices. lavapipe 731/731 with the same 50 skips. RTX 3070 730/731 with the same skip, and the one failure isagc_driver_bda_device, which fails onmainhere too (#7584: a fence timeout,Vulkan result 2, in this run, and device lost,-4, onmain).Not run: Windows, AMD, any title, and the memory or copy cost of the shadow.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), 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 MarcZX10 on 2026-10-19T16:52:23Z.
Thanks for running the rebased head on both the RTX 3070 and lavapipe. The full reported suite passes on both, and the new regression catches the stale shadow image from the earlier head. I’ll record this as current-head device validation, with the tested merged-main composition including #6635.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T18:51:27Z.
Read the diff against the earlier findings (stale shadow after switching attachments,
drawnDepthpropagation, ownership test): all are addressed on this head. The new regression (bind another target, then sample the first) is covered by @jotitadev's RTX 3070 + lavapipe run, including the mutation that fails without the generation bump, and the^agcsuite matchesmain. Full Linux/Windows build went through the merge queue; merged.