Repository navigation
fix(libSceAgcDriver): retire a depth surface once another writer covers its memory - #454
Conversation
|
Thanks for tracking this down. My concern is the case where the memory still holds the depth surface. On main a depth surface lives only in its Vulkan image: nothing writes it back to guest memory ( |
|
Thanks, you're right: as it stands this silently returns stale guest memory whenever the title really does read the depth bits through another format, and nothing in the PR tells those two cases apart. Deciding by the last writer is the better rule. I'll rework it that way:
Since #425 rewrites the same condition in A note on timing: I'm away until Wednesday 7 October, so the rework comes after that. Until then please treat this PR as not ready. Written with AI assistance (Claude Code). |
|
A data point for the rework: The Smurfs Dreams (PPSA21607, Unreal Engine) hits the case where the format does match the depth view: a compute shader samples a 2848x1600 |
fac1275 to
fda7da9
Compare
|
@oneandonlydean reworked as agreed, on top of #425 (
Tests for both orders are in the new device test @Pacuka this should cover your 2848x1600 R32 view over the 1024x1024 D32 surface, provided whatever reused that memory was a color target, a written storage image at another address, or a CPU/DMA store. If the reuse was a storage write at exactly the depth address, it still throws, at the storage lookup this time ( Written with AI assistance (Claude Code). |
|
Thanks for the rework, I ran The Smurfs Dreams with it (on top of main def8119). It still throws at the same view, but the reason is a second depth surface at the same address, not a missed writer: the game binds a 1024x1024 D32 surface and a 2848x1600 D32 surface at Locally, retiring the other surfaces that overlap a depth target's depth/stencil address in |
fda7da9 to
6b56080
Compare
|
@Pacuka thanks for tracking it down. I took your approach in The branch is also rebased onto @MichonGoddijn231849's new #425 head ( Written with AI assistance (Claude Code). |
|
Ran The Smurfs Dreams with 6b56080 (on top of main def8119 + a few other open PRs): the depth-plane abort is gone and the game ran 180 s without a crash. The 2848x1600 R32 view now resolves to the surface bound last. |
|
I ran Ghost of Yōtei (PPSA26344 v1.008) for an hour with this PR at 6b56080, and it clears almost all of the game's depth-surface skips. Without the PR, our previous run skipped 705 draws that sample the depth plane of a depth surface through another view (for example the 1664x936 surface read as a 1920x1080 guest format 22 texture). With it there are none. The five compute shaders that wrote depth/stencil surfaces as storage images (499 skipped dispatches before) also run now. To be precise about that part: two of them write a depth plane, which the #425 commits this PR carries cover, and the other three write the stencil plane, which I handled in a small commit stacked on yours (an R8 storage image seeded from and copied back into the stencil aspect), so that half isn't this PR alone. The world frames went from mostly dark to properly lit in the same run, though I haven't isolated which change did that. What's left in the hour: one depth-plane dispatch in 0x800027c200, which reads the 3328x1872 view of the depth surface at 0x5002870000 as a 3840x2160 guest format 22 texture, and 31 stencil-plane sampling skips (118 before) in 0x8000316900 and 0x800027c200, all format 5 views of that surface's stencil. No FATAL and no Vulkan error. GitHub currently shows the PR as conflicting with main: the only hunk is in TechnicalDebt.md, where the two HTILE lines this PR carries sit next to main's new scePlayerReviewDialog line. Would you be able to rebase? Once you have, I'd like to open the stencil-plane storage commit as a PR stacked on this one, if that's all right with you. DetailsWindows 11, RTX 3080 Laptop. With the PR: our integration tree on main c8a2f06 + this PR at 6b56080 (+ the stencil-plane commit on top). Without: the previous integration build. Gone (previous run): Left (this run): |
6b56080 to
8e5ba47
Compare
|
@Celegans12 thanks for the hour-long run and the breakdown. Rebased onto main Yes, please open the stencil-plane storage commit stacked on this one. The 3328x1872 depth view of the 3840x2160 surface you have left looks like the same extent mismatch outside the last-writer rule; I have no case for it here. @Pacuka thanks for confirming on Smurfs. Written with AI assistance (Claude Code). |
|
Rebased onto
Full ctest: 1254/1254 pass (14 environment skips; AI-assisted (Claude Code). |
df13acf to
af87b92
Compare
…rs its memory A depth surface lives only in its Vulkan image, so a view of its memory with another layout could only throw, and a matching view kept reading the image after other writes over its memory. Retire the surface when a color target or a written storage image it does not serve overlaps its planes, or when a view it cannot serve finds guest memory over the planes written since the surface was last bound; lookups then skip it and the view reads the memory like any texture. Binding the target again brings the surface back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
af87b92 to
626cff7
Compare
|
Rebased onto
Linux build + full ctest: 1234/1235, the only failure is |
adriadam10
left a comment
There was a problem hiding this comment.
Rebased and retested (see above); the earlier request was only the rebase.
|
A regression report from PPSA15304 (Linux, RTX 5080, NVIDIA 595.99.02). Since this PR is in, the gameplay scene renders almost black: the mean grey of the fixed-camera frame at the save's start position drops from about 100 to about 28. Lit surfaces keep only scattered bright specks, which looks like every shadow or depth lookup reading as occluded. Two runs on main plus our open PRs showed it, and a build of the same tree with only this merge reverted renders normally again (mean RGB 101/106/92, as before). A local trace in
The 2848x1600 surface is the scene depth. By A possible direction: on the storage path, retire only when the written level and slice's own byte range covers the plane (as |
|
@ee6aba54 thanks for the trace, that is exactly the information needed. The storage path retires on any overlap of the view's described size, and a retired surface reads guest memory, which never received the depth image's contents. So a partial overlap throws away the whole plane, while on hardware only the overlapped bytes would change. That matches the dark frame with surviving bright specks. The direction I'd take: on the storage path, retire only when the bytes of the written level and slice ( Your offer to trace further would help: for the storage views in your table, could you log the descriptor fields (dimension, width/height, base level and mip count, base/last array, tile mode, format)? The 512x512 case worries me most: seven 4 MiB views 64 KiB apart all cover its 1 MiB plane by described size, so whether they still cover it by the written level's bytes decides if the narrower rule fixes your scene. |
|
@SP4C3B4R-8 Here are the descriptor fields, from PPSA15304 at the same spot (Linux, RTX 5080, one run of 60 s). For every written storage view whose described range overlaps a live depth surface, a local trace logged the view's descriptor and how many bytes of each plane the written level's Dimension 1 is 2D, 2 is 2D array, 4 is 3D. Tile mode 4 is Z64KB_X and 7 is R64KB_X. Formats are the guest codes with the Vulkan format the driver maps them to. 512x512 surface (D32_SFLOAT_S8_UINT, depth plane 0x100000, stencil 0x40000 at +0x100000)
So the 4 MiB views that worried you (A) do cover the 512x512 depth and stencil planes with written bytes, not just by described size. The narrower rule would still retire this surface, and B to E would retire it as well. 2848x1600 scene depth (D32_SFLOAT_S8_UINT, depth plane 0x12b0000, stencil 0x540000 at +0x12b0000)
G and H are the 0x12b0000-sized writes from my earlier table, and K and L the 0x540000-sized ones. None of them covers either plane of the scene depth with written bytes, and neither does any other view that overlaps it (the closest is J, which reaches 0x11e0000 of 0x12b0000). The 3D views M and N contain no whole 64 KiB block per slice (a 64 KiB R64KB_X block of a 4-byte format is 128x128). By this data, the narrower rule keeps the scene depth alive and still retires the 512x512 surface. I have not run a build with the rule yet, so I can't say yet whether the scene comes out at its normal brightness. Once you have a revision, I'll run it at the same spot and compare the frame. |
|
@ee6aba54 thanks, that table settles it. The fix is up as #7050: a written storage view retires a depth surface only when the bytes its written level holds ( If you can run it at the same spot and compare the frame, that's the check I can't do here. |
…te covers a whole plane Since boykopovar#454 a written storage image retires every depth surface its described size overlaps, and a retired surface reads guest memory, which never received the depth image. PPSA15304 writes storage views that overlap the scene depth without covering it (the largest reaches 0x11e0000 of its 0x12b0000 depth plane), so the whole depth was thrown away and the scene came out almost black. A written storage view now retires a surface only when the bytes its written level holds, per array layer or depth slice (CoveredMipBytes, whole tile blocks, no padding), cover the surface's whole depth or stencil plane; a partial overlap leaves the surface alive, as before boykopovar#454. Thick 3D views hold no whole block per slice and retire nothing. agc_driver_depth_storage_reuse now checks that a half-width write keeps the surface sampled from the depth image and that a write over the whole plane retires it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GN8FJFTedayRXLHythXkZ4
Main brings the pipelined-draw stack (boykopovar#1193/boykopovar#1201/boykopovar#1202), boykopovar#6316 after boykopovar#6060, boykopovar#5893, boykopovar#5910 and depth/HTILE work (boykopovar#454, boykopovar#5496, boykopovar#5554, boykopovar#5524, boykopovar#5627, 626cff7). Our SharedSpirv / cold-SPIR-V storage is replaced by main's mapped cache entries (CreateFileMappingW on Windows), so cached variants' words are views into the cache files instead of heap copies; APS5_COLD_SPIRV, APS5_COLD_SPIRV_FILE and APS5_CACHE_SPIRV_BACKING are gone. Kept local: lane hang fixes, boykopovar#5815, boykopovar#6227, table stores and storage tables, option 1 substitutes (.slots), stencil remap and alias path (a written storage view our alias path serves seeds from the depth surface instead of retiring it), 10_11_11 blending next to main's reversed-order blending, VRAM share/spill/fallbacks, diagnostics. Versions: FormatVersion 43, RuntimeAbi 17, request serializer v31. Notes in work/sync-20261013/*-4.md. AI-assisted: yes
What
A depth surface lives only in its Vulkan image: nothing writes it back to guest memory. So once another pass reuses its memory, a view of that memory with another layout (another format, extent, slice or levels) can only throw, and a view that matches the plane keeps reading the stale image. This decides by the last writer, as suggested in review:
DepthSurfaceStorageserves, the plane's own extent and format, is not a retiring writer), or when a view the surface cannot serve finds guest memory over its planes written (CPU or driver store) since the surface was last bound;main;Two depth surfaces at one address are already resolved on
mainby the plane owners from #4683 (the one bound last serves), so this PR no longer retires on bind.The retired surface is never destroyed (its image may still be in flight). Known limit, listed in
docs/dev/debt/libSceAgcDriver.md: brought back, it keeps its own depth, not the bytes written over it. Without write watching, a view the surface cannot serve still throws.Tested
Windows 11, MinGW-w64 GCC 15.2.0, RTX 5070 Ti.
agc_driver_depth_surface_last_writer: depth then a view with two levels: throws; depth, color target, view: memory, and its own view is no longer served; depth, color target, depth again, view: throws; depth, CPU write, view: memory while its own view is still served before it; CPU write, depth, view: throws; depth, driver store, view: memory; a write past the plane retires nothing.agc_driver_depth_storage_reusegains one GPU case: a D32 surface drawn to 0.5, then a written storage image of another extent over it, then the plane's own sampled view returns the memory (0.25) instead of the stale 0.5.main).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository🤖 Generated with Claude Code