fix(agc): start a new depth surface from the storage writes over its plane #5446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5446"
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 Nesyth on 2026-10-13T19:58:45Z.
What
A depth surface the driver creates for a depth target starts from
DB_DEPTH_CLEAR: theDepthSurfaceconstructor clears the new image and never reads guest memory. Storage writes made to the plane's memory before any surface existed at that address therefore do not reach it. At that time the view is an ordinary storage image, since a plane's own storage view (#4500) exists only once its surface does. The first depth test against the plane reads the clear value instead of what the kernel wrote.DepthSurfaceViewnow gives a surface it creates for a target without HTILE (DB_HTILE_DATA_BASE0), and without an earlier surface whose planes it takes over (#4683), the depth those writes left (Graphics/src/DepthSurface.cpp):StorageTexture::FindPending), then a cached one of exactly the plane's size (FindLive).UINT,UNORM,SINT,SNORMorSFLOAT) for a 16-bit plane (D16, D16S8) or an R32 format (SFLOAT,UINTorSINT) for a 32-bit one (D32, D32S8).Refresh). Its layer 0 is then copied into the surface's depth aspect through the plane's staging buffer: in the active recorder, which keeps the image alive until the copy has run, or else in a batch of its own that is submitted and waited for.DB_STENCIL_CLEAR.DB_DEPTH_CLEAR, as onmain:D16_UNORM_S8_UINT, #3846);DepthSurfaceViewfinds again for the same target. #5113 keeps such a surface up to date when a storage image over its plane is stored back.DepthSurfaceViewnow takesGuestMemory::GpuMutex()(recursive) before the surfaces' mutex, the same orderDepthSurfaceTextureuses, because the lookup andRefreshrun under the GPU mutex. Its only caller in the driver is the draw path.docs/dev/debt/libSceAgcDriver.mdrecords the rule. On the console the plane is the memory the kernel wrote, so there is nothing to seed; none of this is measured there.Ready or Not (PPSA18605) clears its shadow maps this way. Traced with temporary logging on my bring-up build (run 205): six 1024x1024 D16 planes were each written through a storage image, then bound as a depth target for the first time and created from
DB_DEPTH_CLEAR0.0 without HTILE. Onmainthe two operators in the main menu are black silhouettes, while the PS5 shows a red rim light on them. With this change they are lit (see Tested).Test: new
tests/execution/DepthSurfaceFromStorage.cpp(ctestagc_driver_depth_surface_from_storage). A compute kernel stores row 0 of a 64x32 plane whose memory holds 0.25, 32 values from 0 to 0.94, through a storage view. A full-screen draw at depth 0.5 withLESSthen tests against a new surface over the plane, whose clear value is 1.0. The draw passes 15 of the 2048 pixels when the surface took the storage image (the stored values above 0.5) and all 2048 when the surface started from its clear value:FindLive): 15 each;FindPendingfinds it; the case requiresFindLiveto miss it;NoteHtileDepthClear) after the storage write: 2048;EQUAL 0draw without the depth test then passes all 2048 pixels (the stencil plane kept its clear value).Not covered by a test:
FindPendingcomes first, so the one with pending results.ctest -R depth, 10 tests) still pass. It keeps an image that is still cached at the address from overwriting depth drawn after the image was written.Related, both merged:
main32e810db4, which has #5113, this PR's test fails its five new-surface cases ("2048 pixels passed, expected 15"). Earlier, onmain18c438b10, Ready or Not's menu operators stayed black with #5113 alone (run 702) and were lit with both (run 709).DepthSurfaceViewthat creates a surface, so that a new surface takes its planes from their last owner. TheTakeStoragecall now sits in that block and runs only when there is no such owner.Tested
Windows 11 Pro 10.0.22631, AMD Ryzen 7 7800X3D, AMD Radeon RX 7900 XTX, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, this head onmain32e810db4:ctest -R "^agc_" -j 2: 539 of 544 pass, with 4 skips. The failure,agc_driver_layered_volume_vertex_no_gpl("vertex draw: slice 1 texel (0, 0) channel 0 is 64, expected 255"), also fails onmain4ae78dc13without this change on this GPU.agc_driver_depth_surface_from_storage:main32e810db4without this change, it fails in the five new-surface cases ("a new D32 depth surface over a pending R32F storage write: 2048 pixels passed, expected 15", and the same for D16, the flushed image, the two-layer view and D32S8);target.htileAddress == 0): "a new D32 depth surface whose HTILE was cleared after a storage write: 15 pixels passed, expected 2048";FindLive: "a new D32 depth surface over a flushed R32F storage write: 2048 pixels passed, expected 15";FindLivealone, withoutFindPending: "a new D32 depth surface over a pending R32F storage write through a two-layer 2D array view: 2048 pixels passed, expected 15".tools/check_conventions.py --base origin/mainpasses.Ready or Not (PPSA18605), main menu, measured before this rebase on
main18c438b10, whichmaindacd78525differs from only inlibSceAgcDriver(#4949). The runtime'slibsheld the 127 modules built from18c438b10, withlibSceAgcDriverswapped per run, andapp.exeis the title relinked by that commit's relinker.APS5_HOST_IMPORT_MIB=10240, and the runtime'ssaved\ps5\engine.iniraises UE's render fence timeout (g.TimeoutForBlockOnRenderFence=1800000). The red light is measured on the 9 menu frames each run dumped (1280x720), in the 500x380 box around the operators, as the share of pixels with R >= 60 and R at least twice G and B:main(runs 700, 704, 706 and 708): 0.07-0.14%, mean R 14-16: black silhouettes.main+ this change (run 701): 2.9-4.7%, mean R 28-34: lit by the red rim light.main+ #5113 (run 702): 0.07-0.13%, mean R 16: black silhouettes.main+ this change + #5113 (run 709): 7.1-10.3%, mean R 30-37: lit.libSceAgcDriverbuilt onmaindacd78525(run 710): 3.2-12.0%, mean R 32-41: lit.Main menu, one dumped frame (1280x720) from each session. Top left:
main18c438b10(run 700). Top right:main+ this PR (run 701). Bottom left:main+ #5113 (run 702). Bottom right: the PS5, for reference. The two operators stand in front of a red light. On the PS5 it lights their outlines. Onmainand with #5113 alone they are black silhouettes; with this PR they get the same rim light.Linux: not run.
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)Imported from boykopovar/AnyPS5. Originally posted by KauaSantos702 on 2026-10-14T13:44:34Z.
NVIDIA run at this head (
284011b8b), adding a vendor to the AMD results in the body: noagc_*test fails.BUILD_TESTING=ONctest -R '^agc_' -j2: 484 tests, 483 passed, 0 failed, 1 skipped. The skipped test isagc_driver_stencil_ref_export, because the device lacksVK_EXT_shader_stencil_export; it is also skipped onmain.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T19:48:35Z.
Checked: the merged tree builds and
agc_driver_depth_surface_from_storagepasses on Linux; withDepthSurface.cppreverted it fails, so the test pins the change. The rest of the libSceAgcDriver scope is green exceptagc_driver_tessellation, which segfaults on main as well. Lock order (GpuMutexbefore the surfaces mutex), the recorder/batch copy path and the debt entry look right; thanks for the NVIDIA run, @KauaSantos702. Merging once the full Build is green.