Repository navigation
fix(agc): keep stencil planes coherent with guest memory - #12210
Conversation
|
@XairRrR thanks, the stencil plane store and reload read correctly to me. One change before merge: the new debt text in docs/dev/debt/libSceAgcDriver.md names the game next to PPSA05684. Debt docs can carry the title ID but not game names, so please keep PPSA05684 and drop the name. |
|
Some 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.
|
|
Thanks. Dropped the game name in 366ddec: the debt text names PPSA05684 only. The stencil part had also taken the depth-plane entry past the 1000-character limit, so it is now an entry of its own, "Stencil planes in guest memory", right after it. AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
I found a data-loss path in the new stencil tracking. retire() calls retireStencil(), which clears stencilStale and removes its range without storing the pending plane. RetireDepthSurfaces retires a surface when either its depth or stencil address overlaps; a write that overlaps only the depth plane therefore retires the surface and drops pending stencil results even though the write did not replace the stencil bytes. The same drop can occur through retireStoringStale when the depth side is clean. Please preserve/flush the stale stencil plane when retiring for an unrelated depth-range write, and add a regression that writes the depth plane after drawing stencil but before reading the stencil plane. This branch is also 60 commits behind current main; please rebase and rerun the focused stencil/depth-plane tests and validation checks on the rebased head. I did not run the GPU test locally.
|
Windows + NVIDIA result for head This PR's own tests: the new Host: Windows 11 26300, Intel i7-12700K, NVIDIA GeForce RTX 2070 SUPER (vendor 0x10de, device 0x1e84; Vulkan loader 1.4.357 from the NVIDIA driver 621.01), Khronos Validation Layers nightly 1.4.366 (b2b44c0d37) through Same focused run on
The tree also carried the open PRs #12298, #12272, #12262, #12256, #12250, #12234, #12228, #12211, #12209, #12208, #12207, all merged cleanly, so the run is a joint one. Not run on a PS5. AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine. |
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the change; the stencil store/reload reads correctly and the new test pins the draw → read → CPU write → draw sequence. One bug remains (same as MarcZX10's review):
DepthSurface.cpp:1984(retire→retireStencil) clearsstencilStaleand removes the range without storing the pending stencil plane.RetireDepthSurfaces(:2835) retires a surface when either its depth or its stencil range overlaps, so a write that touches only the depth plane drops stencil results that were never stored.retireStoringStale(:1995) does the same when the depth side is clean (!AnyStale()goes straight toretire). Store the stale stencil plane before retiring unless the overlapping write covers the stencil range itself.- Add a regression: draw stencil, write the depth plane from the CPU, then read the stencil plane and expect the drawn value in guest memory.
- The branch is well behind
main; after the fix, rebase and rerunagc_driver_stencil_plane_memoryand the depth-plane tests with validation on.
Only the depth plane of a depth surface reached guest memory: stencil lived in the host image alone. A title that moves stencil with buffer copies read stale bytes from the source plane, and the destination surface never saw what the copy wrote. Uncharted 4 clears its G-buffer stencil plane with a fill, then copies it into the lighting depth target and on into last frame's planes with a buffer copy kernel every frame; its lighting kept the stencil marks of earlier frames, so characters left trails and the image doubled while the camera moved. The stencil plane of a single-sample surface with the 64 KiB Z swizzle is now marked drawn when the surface is bound, stored whole when a read overlaps it (FlushDepthPlanes, like the depth plane) and reloaded from guest memory when a collected guest write changed it before the surface is bound or its stencil sampled, unless a stencil clear is pending. agc_driver_stencil_plane_memory draws stencil, reads the plane through FlushDepthPlanes, then writes it from the CPU and tests it with stencil EQUAL; it fails without the change. AI-assisted: yes
The stencil plane text named the game; debt entries carry title IDs only. It also took the depth plane entry past the 1000-character limit, so it now has an entry of its own. AI-assisted: yes
… another write A surface retires when a write overlaps either of its planes. The stencil plane's pending GPU results were dropped with it even when the write only covered the depth plane. Retiring for a color target, a storage write or a guest write now stores a stale stencil plane first unless that write replaces the stencil plane itself. AI-assisted: yes
366ddec to
1dabe79
Compare
|
Thanks, both of you, the retire path was a real hole. Fixed in 1dabe79:
Rebased on Rebased on AI-assisted: yes |
|
Checked the new head against the previous points: stale stencil planes are now stored before |


What
Only the depth plane of a depth surface reaches guest memory (stale units stored by
FlushDepthPlanes, guest writes reloaded bySyncFromMemory). The stencil plane lived in the host image alone, so a title that moves stencil with buffer copies read stale bytes from the source plane, and the destination surface never saw what the copy wrote.PPSA05684 (Uncharted: Legacy of Thieves Collection) does exactly this every frame in Uncharted 4's prison and orphanage chapters, through a
buffer_load_format_x/buffer_store_format_xcopy kernel:The lighting and TAA passes sample those stencil planes. Since step 3 never reached the lighting target, its stencil kept the marks of earlier frames: characters left a trail of silhouettes, fog showed their old outlines, and the whole image smeared and doubled while the camera moved.
The stencil plane of a single-sample surface with the 64 KiB Z swizzle (the planes
FlushDepthPlanesalready stores for depth) now follows the depth plane's rules, as a whole plane:FlushDepthPlanes: buffer uploads,GuestBuffersV#s, image lookups, pending-store flushes) stores it through an R8_UINT mirror and notes the write generation, so the store does not count as a guest write;SyncFromMemorydoes for depth).The stencil plane is taken to use the depth plane's swizzle at one byte per texel; the debt entry for depth planes in guest memory says so.
Tested
Arch Linux 7.2.11-zen, GCC 16.2.1, Ninja, Release, on
main3ca715e:agc_driver_stencil_plane_memory: draws stencil 0x18 over a D32S8 surface, reads the plane throughFlushDepthPlanesand expects 0x18 in guest memory, then writes 0x05 from the CPU and draws with stencil EQUAL 0x05 (every pixel passes) and EQUAL 0x18 (none passes). WithDepthSurface.cppfrommainit fails:a read of the stencil plane after a draw wrote stencil stored nothing.ctest -j8(this branch together with my five other branches of today, on the samemain): 2619 of 2620 pass;agc_driver_mesh_barycentric_emulationfails the same way onmainon this GPU (the pixel shader did not emulate barycentrics).tools/check_conventions.py --base origin/mainpasses.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)