Skip to content

fix(libSceAgcDriver): keep stencil storage coherent with depth targets - #1684

Closed
ebarr24 wants to merge 1 commit into
boykopovar:mainfrom
ebarr24:codex/stencil-storage-coherence
Closed

ebarr24 wants to merge 1 commit into
boykopovar:mainfrom
ebarr24:codex/stencil-storage-coherence

Conversation

@ebarr24

@ebarr24 ebarr24 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What

Fix resident stencil storage materialization in AnyPS5's native user-space graphics implementation. A matching R8_UINT descriptor at a resident D32S8 stencil-plane address currently throws before dispatch. It now binds a storage image seeded from the resident stencil aspect and copies actual shader writes back to that aspect. Attachment uses refresh the storage content; unchanged lookups reuse it. Depth is preserved and the recorder retains images and scratch buffers through queued transfers.

Related to #1409 and README Status's libSceAgcDriver rendering capability. Private runtime retests of this exact head on two fresh processes pass the reproduced stencil/array materialization blocker and stop at a later unsupported depth-plane storage path. This is measured execution progress; the viewport remains black at FPS 0, with no rendered scene or gameplay controls verified.

The supported path is one matching level and layer of R8_UINT through a 2D or 2D-array view, SW_64KB_Z_X, over D32S8 with DB_STENCIL_INFO.TILE_STENCIL_DISABLE set. Other depth/stencil formats, HTILE stencil, descriptor metadata, extent reinterpretation, mips, multiple layers, nonzero slices and other tiling modes throw. Unsupported depth-plane and descriptor refusals identify the resident target and descriptor fields. Raw CPU accesses to resident depth/stencil memory remain outside this backend's synchronization model. Console layout/compression behavior remains unverified.

Vulkan's depth/stencil aspect copy table defines the D32S8 stencil buffer plane as S8_UINT. The implementation transports those bytes through a device buffer between the stencil aspect and the R8 storage image; it does not reinterpret the combined depth/stencil image as a color storage image. The single-layer array path uses the correct array view type, permitted by the Vulkan image/view compatibility table. No shader instruction semantics change.

Adjacent and competing work is acknowledged: #425 implements depth storage and mentions a stencil follow-up; #454 carries depth/coherence work and its discussion reports Celegans12's local stencil patch and a planned stacked PR. This independent, narrow implementation adds an executable synthetic coherence regression on main. It has no unmerged dependency. If complementary depth retirement, clear or sampled-array work lands first, combine the resource lifetime/coherence changes and rerun this regression and complete validation. The final complete scan (2026-10-08 16:08 UTC, 345 open PRs / 50 issues) reviewed all 164 shared-file results: 104 distinct results with no captured conflict in candidate paths and 60 captured branches with textual conflicts. Current main 4b005b229e24be9ec3f185def9e59cbc03aa9e4a merges cleanly with this validated head. Its independent color/DCC, import-watch, recompiler and build advances were compared to the pinned base; no change to this defect, regression or dependency requires a rebase. Other open branches are not claimed to be mergeable together.

Tested

Pinned base: 07c2405. Head: c46ecda. The identical base fixture reaches the real attachment positive control, then fails with the existing unsupported storage access at the resident stencil address. Windows 11 / MinGW GCC 15.2.0 / NVIDIA GeForce RTX 3080 (driver 616.92): the updated focused regression passed, all-target Full build and libs passed, 451/451 tests passed with no skips. Exact-head Ubuntu 24.04 / Mesa lavapipe fork CI built all targets and libs, then passed 433 tests with 23 reviewed feature skips and no failures out of 456; the stencil regression passed all three repetitions. The skipped tests require guest-wave subgroup widths, int64 atomics or conservative-rasterization features and do not cover this transport. Their precise feature cause is inferred from their source guards because CTest suppresses individual skip stdout.

The identical public fixture decodes hand-authored DB state and guest texture descriptors, constructs real Vulkan D32S8/R8 images, clears stencil to 0x11, and computes OR 0x04. Sampling and an actual stencil attachment comparison must see 0x15 while sampled depth remains 0.375. It also tests attachment-to-storage refresh, a second round trip, unchanged repeated lookup, unsupported format/layout/HTILE refusals, immediate and recorded work with typed R8UI and production-formatless storage shaders through both 2D and one-layer array views, coherence across both view types, pending clear/seed transfers and cache removal before GPU submission. An initial attachment comparison is a positive control before the unsupported base path. Generated SPIR-V remains in the build tree; no game data or proprietary shader enters the fixture.

Focused Windows commands build agc_driver_depth_stencil_storage_tests and run ^agc_driver_depth_stencil_storage$ in separate head/base trees. Final Windows validation builds all targets and libs and runs the entire Full profile. Exact-head Ubuntu fork CI builds all targets and libs and executes CTest. Windows hardware Vulkan and Ubuntu software Vulkan results are reported separately.

The test covers the changed library boundary, descriptor decode and GPU resource lifetime directly. PM4 submission and shader recompilation are unchanged and remain covered by the full existing suite; the separate private retest establishes only blocker-chain progress, and console hardware verification remains unclaimed.

Checklist

  • Based on current main; no other open PR implements the same functions — pinned base and final clean merge are checked, while adjacent/planned/alternative work is explicitly acknowledged above.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stub added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, written with Codex assistance; the author is responsible for the change

Core and synchronization validation layers are unavailable on this Windows host (only NVIDIA Optimus/Presentation layers are installed). Behavioral GPU execution and Vulkan copy/barrier source review are provided; a clean validation-layer report is not claimed. The upstream template checker may report the truthfully unchecked combined overlap item; the workspace's explicit scenario exception preserves that finding and keeps all other gates.

Exact captured competing/adjacent heads and conflict integration

The most direct overlaps are #425 (depth storage with explicit stencil refusal/planned follow-up), #454 (last-writer retirement plus the local stencil discussion), #374/#419/#1186/#1189 (HTILE/MSAA/depth-array stacks), #1368 (versioned sampled arrays, storage aliases excluded), #1395 (draft clear/copy recognition with unresolved coverage), #1430 (sampled depth proof), and #1619 (storage-to-depth comparison copies). For each, combine aspect versions, accepted clears and view arguments without dropping retained ownership or admitting unsupported stencil states; resident storage must still refresh outside guest-memory fast proofs. Preserve the new regression and run each complementary regression plus Full Windows/exact-head Ubuntu on any integrated head. If a competing stencil implementation is published first, compare it and select one coherent implementation; this candidate does not silently stack duplicate writers.

Every captured conflict is disclosed below. Renderer paths are relative to core/libs/prx/libSceAgcDriver/Graphics/; debt means docs/dev/TechnicalDebt.md. For independent older branches, reconcile inherited renderer context with current main while retaining the resident transfer branches, append independent tests and preserve both accurate debt entries. The formatter/debt-rewrite proposals require preserving the full semantic change and limitations if upstream selects those policies first. These plans do not assert the conflicts are already resolved.

PR Captured head Paths to reconcile
#290 25bc2098690df4a7738af6c8094e2f23b221ed78 src/DepthSurface.cpp, src/Texture.cpp, debt
#374 b8ae1f4b7f35a9b12815803c90c2c67d57c04e20 include/State.hpp, src/DepthSurface.cpp, src/State.cpp
#407 993ccfadd04f8b90376c29b36e830bbae058b9d6 src/Texture.cpp, debt
#419 fb6999abc42ec12ef7ea48cbf95a9800c7282bc5 include/State.hpp, src/DepthSurface.cpp, src/State.cpp, src/Texture.cpp, debt
#423 5c5b106dce37f6dd8081f1f8947039a3f3fe1c14 src/Texture.cpp, debt
#425 62b1e55215ef9936a1df12c2a23ef29725c9b17e include/DepthSurface.hpp, include/State.hpp, include/Texture.hpp, src/DepthSurface.cpp, src/ShaderResources.cpp, src/State.cpp, src/Texture.cpp
#448 31d47639e62acadd16ab2e3f05daa1bd3e18e748 src/Texture.cpp, debt
#454 8e5ba4783668f25665904774b37d3ef915b2a03f include/DepthSurface.hpp, include/State.hpp, include/Texture.hpp, src/DepthSurface.cpp, src/ShaderResources.cpp, src/State.cpp, src/Texture.cpp, debt
#545 2a3a2a7cb6dcdd9fb8066c930640cadaf66f2ad0 src/Texture.cpp, debt
#560 43eba76feeb8facb7d95e892a0aae1636b077f2f src/Texture.cpp, debt
#571 7a894554de838d6bca053ed0037adb24d9c71582 src/Texture.cpp, debt
#572 633b8f39e9e52e93f6fac6fce6ea4238674036d8 src/Texture.cpp, debt
#959 27aa6e1619812f7379cf8b7ba9a2dba07455bfb3 src/Texture.cpp, debt
#964 03bf25f0bb6377eca6ad111e95605b6a1733011f src/Texture.cpp, debt
#1017 32a7c349ad3224863f89fc5275604fcf00db0d4b src/Texture.cpp, debt
#1046 7857d689fa8485f51a227277e1b308916202979b src/Texture.cpp, debt
#1073 74870921d94811133d9dba1cf5a1da914edbd4d9 src/Texture.cpp, debt
#1077 d86365c7e3652f0c676a772514b1c129c1400685 src/Texture.cpp, debt
#1091 7f5f456585e9a112ac468726c43df636d711a1d8 debt
#1128 f9db6c15838002f4a000e95ba92a7d4a33db9d31 include/DepthSurface.hpp, include/Texture.hpp, src/DepthSurface.cpp, src/ShaderResources.cpp, src/Texture.cpp, debt
#1141 6d380536ede30d889d1d1cafba5929fb10d464c7 src/Texture.cpp, debt
#1152 41b87057b519e814c882917919232ebc20b83d0f src/Texture.cpp, debt
#1184 1761a5d86133d52b4af12825d6fa9406d202bfc1 src/Texture.cpp, debt
#1186 fd0ddc6a6243e7ff50e6c4b5189d4673aa36dd4a include/DepthSurface.hpp, include/State.hpp, include/Texture.hpp, src/DepthSurface.cpp, src/ShaderResources.cpp, src/State.cpp, src/Texture.cpp
#1189 13c1cbf92d040d55748357ef2d6bbdf7e164c8fd include/State.hpp, src/DepthSurface.cpp, src/State.cpp, src/Texture.cpp, debt
#1201 081440799de5a6adf9cf596c50ccb48cb7a8e111 src/Texture.cpp, debt
#1202 b5be7a11458fe379f004610eeb341bdddb367eb1 src/Texture.cpp, debt
#1237 541d1748c90df76013ff9e13d0769b1cd8ba6b8b src/Texture.cpp, debt
#1287 c88e9af64132320456eade1826540879174fa79d src/Texture.cpp, debt
#1298 2a2141fc57ea62b6f17211e9595341ec41570794 debt
#1299 e66af07498a40f1b287cd7763270d1a9d485dea2 src/Texture.cpp, debt
#1300 f501c142592bad9e851ac0eb7524a25a0858a8a2 debt
#1309 349781da4109531546dde35e582d0a33b855ce7e debt
#1311 398077671a47c78e3237ff79e621af0be9810e10 debt
#1312 c9e08e60ade60449479a7e431d6a700cd6636758 debt
#1313 5afe2d4df2d659181b6f21fb17c786cca166b40f debt
#1315 71d4800ef400d63ea55f867c45b2511612659b8f src/Texture.cpp, debt
#1316 1f8e6b23a743790864c6dca8b4ac8bccc9682981 debt
#1318 63763c6a0ada57b7bdd1d24dc50e8bf2ba517923 debt
#1331 c6ba437eec3f5518c89a0656a1bc58a24b62a07e src/Texture.cpp, debt
#1333 6529493ab11fbeea6102b8e5c4cc315e4847e3b2 debt
#1334 cc32a55fd72510e1dc35bef3458ffc2d0f094f24 debt
#1337 af64ea997dc405a590e9c410198f7ea56473fcf6 debt
#1339 a99c4a0bfbb8f783b64597ebf2fd76b58f402a3c src/Texture.cpp, debt
#1341 202d5f5746c8af1172b5a82f022b4dd84741d7ea debt
#1349 335f703408db24fbcfde52e2054d3627a7c504d7 debt
#1357 04bc4e5fcb51e357a361dc0173e1860b5efa1120 debt
#1359 6aa7e9c96694a4314ddf146327079113cefa8245 debt
#1361 88076041c224ddb652c565f5bf206ca9f4740a36 debt
#1364 85593a17a8e07baf3a1fac487f234374308c4b64 debt
#1366 f74fa3d6aaa2a8675ee0642ec8d9bf97af39618a debt
#1368 80979c992b51585a1b65364b761d75f0220bc049 include/Texture.hpp, src/DepthSurface.cpp, src/Texture.cpp, debt
#1384 70b4d2de4b4e9ed4c27259f4ef75f0e9f7b366e0 debt
#1395 cedec6e1d5765800c2ffb039d8675d864d27cd57 include/Texture.hpp, src/DepthSurface.cpp, src/Texture.cpp, debt
#1430 965f018048f3cee686a37ae61b138a396dca9d55 src/DepthSurface.cpp
#1442 3d896a2a69c95395e34f60f9aa8fee5ff6c34997 debt
#1481 d93a8376e33b706f0520db1d0763db7c1afb7399 debt
#1498 7f0951c61d66878df37f43f5adf04b6856a440d5 debt
#1539 a1ece68929c30c4ed7ccad5d2c7ad1aae21790dc debt
#1619 1c0a5b6c8ebd1e4ca538510daca2c527a8f455cc include/Texture.hpp

@fisherjoey

Copy link
Copy Markdown
Contributor

Linux results for this PR and #1842 (stacked on it), on NVIDIA and AMD. Nobara 44 (Linux 7.2), GCC 16.2.1, Release. Both merge cleanly onto main f145139.

-R agc_driver -j1 main + #1684 + #1842
RTX 5070 Ti, NVIDIA 595.91.07 207/207 208/208 209/209
RADV gfx1036 (RDNA2 iGPU), Mesa 26.2.1 207/207 207/208 208/209

CPU tests (-E agc_driver) are 286/287 in all three; the one failure (guest_dynamic_loader) also fails on main.

On RADV the new agc_driver_depth_stencil_storage stops at:

AGC graphics: depth/stencil format 129 cannot be an attachment on this device

(DepthSurface.cpp:25). VkFormat 129 is D24_UNORM_S8_UINT, which RADV doesn't offer as a depth/stencil attachment. The PR description says the fixture builds a D32S8 surface, so either the DB format decodes to D24S8 here, or the test needs a D32S8 fallback (or a skip) on devices without D24S8. It passes on NVIDIA, which supports D24S8.

AI-assisted: yes

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#1430 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L107

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is named that renders further with this (the description says the screen stays black at 0 fps), Conventions is red, and the new test fails on RADV with depth/stencil format 129 cannot be an attachment on this device. Please reopen with the title ID and what it gets to with the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants