fix(agc): retire an unwritten native multisample depth surface on guest access #6727
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6727"
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 simonbronk on 2026-10-16T07:48:28Z.
What
Part of #6570. A guest read over the depth or HTILE range of a resident native multisample depth surface throws
sample-preserving guest publication of native multisample depth is not implemented. That includes a surface the host never wrote after its import. In that case its samples are still the clear value the import took from the guest HTILE, so the guest bytes already describe the surface and nothing needs publishing.Each native depth surface now records whether the host wrote it after the import. These count as host writes:
NoteDepthSurfaceWrite, called fromDraw.cpp);CopyAspectFrom);Host clears that follow a proven guest HTILE clear do not count: they keep the host equal to what the guest memory describes.
RequireNoResidentDepthRead_nid_no_patchretires an unwritten surface instead of throwing: it clears the surface'sactiveflag and removes its guards. A later bind imports it again from the guest memory.A surface the host wrote still throws the same refusal. Publishing it needs the layout and readback foundations in #6588 and #6601 and stays the follow-up in #6570.
The debt entry says what counts as a host write, and that a draw without depth or stencil writes leaving the console's Z planes and HTILE unchanged is inferred, not measured.
This depends on #6557 (its commit is the first one here). Both edit the same debt entry, and the title needs both.
The title's case, measured with local prints:
ITERATE_256).GREATER_OR_EQUALdepth tests, no depth or stencil writes and no color target.buffer_load_dwordx4withidxen, 96-byte records) and stores into it.Details are in #6570.
Tested
Windows 11 Pro 26200, Onimusha: Way of the Sword (PPSA27836),
APS5_NO_HOST_IMPORT=1(#6374). The build wasmain5d9dcc42d+ #5907 + #5884 + #5915 + #6557 + this PR.main4eb91eacd.depth export, shader coverage or ordered fragment execution is unsupported (register 0x203 = 0x00000045)(DB_SHADER_CONTROL).agc_driver_native_multisample_depthhas a new case per format and sample count: D16 and D32 at 2, 4 and 8 samples, 6 cases on each GPU. Each case checks that:The existing cases now note a host write before their refusal checks, since they rasterize into the surface directly. With retirement replaced by the old refusal, the new case fails.
ctest -R "agc|shader|video_out" -j 8on both GPUs:agc_driver_gpu_indirect_arguments_misaligned_writer_ahead(frommain) does not build with WinLibs GCC (#6452).python tools/check_conventions.py --base upstream/main: passed.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 oneandonlydean on 2026-10-20T12:51:12Z.
Thanks. The first commit on this branch (the ITERATE_256 HTILE import) is already on
main, and the branch now conflicts withmainintests/execution/NativeMultisampleDepth.cppand the libSceAgcDriver debt file. Could you rebase onto currentmainso the PR carries only "retire an unwritten native multisample depth surface on guest access"? I'll review it on the rebased head.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-20T22:02:04Z.
@oneandonlydean rebased onto current
main(bcdb03375). The PR now carries only "retire an unwritten native multisample depth surface on guest access" (8328c2fd3).main's84e3b73f1added adepthWrittenparameter toDepthSurfaceView. I kept it at bothDraw.cppcall sites and added this PR'sNoteDepthSurfaceWritenext to them, so the plane mirroring and the host-write mark are independent.main, already over the 1,000 warning). The content is unchanged.Tested on Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release,
ctest -R "agc|shader|video_out":agc_driver_storage_read_during_idle_storefailed once under-j 8; it passes 5/5 alone on this head and 3/3 onmain.agc_driver_tessellationfails 3/3 onmainas well.agc_driver_native_multisample_depthpasses on both.agc_driver_image_array_window_past_layer_limitdoesn't build with MinGW onmain(alignas(65536), #8310 fixes it), so it was excluded.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T23:38:12Z.
@simonbronk Thanks for the rebase. The conflict resolution against
84e3b73f1looks right (both call sites keepdepthWritten), and the retire-on-read logic matches main's release retirement. Two small requests:NoteDepthSurfaceWritetakessurfacesMutexand walks every depth surface on every depth- or stencil-writing draw, including single-sample draws in titles that never create a resident depth guard. Could it return early when there are no guards? Guards are only created together with a fresh surface (whosehostWrittenstarts false), so this is exact:NoteDepthSurfaceWritedirectly. The fixture already does a realdevice->Draw(state, draw, initial)withdepthWrite = true. Could you add a guest-readTargetRefuses(...)right after it, and if it's easy, a depth-test-only draw followed by a read that retires? A missed mark there would silently drop the host's depth instead of throwing, so it's the path most worth pinning.Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-22T09:11:47Z.
@oneandonlydean both done, on a rebase onto
maind6eafa54d(one conflict inDepthSurface.hpp, wheremainaddedDepthPlaneStoreCounts; I kept both).NoteDepthSurfaceWritenow returns at once for a single-sample target or whenanyDepthGuard()is false, as you suggested.CheckDrawFeedbacknow covers theDraw.cppmarking throughdevice->Draw:TargetRefuses(... "sample-preserving guest publication"), and the surface stays resident;depthWrite = false). A guest read of it then returns its guest bytes and retires it.The direct
NoteDepthSurfaceWritecalls stay only in the fixtures that don't draw.Tested: only partly, and I'd ask you to run the full CI on this head.
maind6eafa54d.check_conventions.py --base origin/mainpasses; its only warning is the debt entry's length, which was already over 1,000 characters onmain.agc_driver_native_multisample_depthcould not be exercised there. That VM's kernel has no asynchronoususerfaultfdwrite protection ("write watch unavailable"), so every native depth import is refused with "requires watched accessible guest memory". The test fails the same way onmaind6eafa54dand on this head (lavapipe,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, Khronos validation), so neither run tells anything about the change. The onlyVUID-in both logs is the sameVUID-VkDeviceCreateInfo-pNext-pNext, from Ubuntu's 1.3.275 layer not knowing a newer structure.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T12:42:27Z.
@simonbronk a merge-order note: #9533, with #9717 and #9742 stacked on it, passes the draw's
stencilTesttoDepthSurfaceViewat the two calls inDraw.cppwhere this PR addsNoteDepthSurfaceWriteafter the view. Both also reword the native multisampled depth sampling entry in the debt file. Composed, each call keeps the extra argument and your write note, and the entry keeps both changes. #9533 goes after this PR and rebases over it.