fix(agc): count adjacent registered allocations as covering a storage-image write-back #5321

Merged
lubaxe merged 1 commit from upstream-pr/5321 into main 2026-10-14 18:57:28 +00:00
lubaxe commented 2026-10-13 17:12:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by lubaxe on 2026-10-13T17:12:33Z.


What

StorageTexture::writeBackLayers drops a surface's pending results when its memory is no longer registered (RegisteredReadableCovers is false), so that stale texels are not stored over memory that was freed or reused. RegisteredReadableCovers looked for one readable registered range containing the whole span (containingRange). A surface placed across two adjacent allocations was therefore reported as unregistered, and every write-back of it was dropped. Only the first four drops are logged, and a title usually uses them all at startup, so the later drops are silent.

PPSA06694 (Remnant 2, UE5) hits this with its HZB occlusion test. A pixel shader tests object bounds against the HZB into a 256x256 RGBA8 target. A compute pass copies that target into a 256x256 linear staging image, and the CPU reads the result (Remnant2.exe+0x2f8e75d). The staging image (0x40000 bytes) lies across two registered allocations (0x30000 + 0x10000), so its results never reached guest memory. The CPU read zeros and treated every object as occluded: the logo mesh was drawn on the first frame only and the screen then stayed black, and later the Create Character screen shows no character.

RegisteredReadableCovers now walks the registered ranges from the start of the span. The span is covered when consecutive readable ranges reach its end without a gap. The other caller, the DMA_DATA copy in PacketMemory.cpp (outcome.path == 2), uses it to decide whether a destination is registered memory; a destination across adjacent allocations now counts as registered there too.

Tested

  • Windows 11 Pro, Ryzen 7 9800X3D, RTX 5090 (driver 617.42), WinLibs GCC 15.2.0 r7, Release.
  • New registeredReadableCoverTests in agc_driver_graphics: a range inside one allocation, across two adjacent ones, and over both; not covered past the last allocation, over a gap, over an unreadable allocation, an empty range, and after removal. On main it fails with a range across two adjacent registered allocations must be covered.
  • ctest on main 8c772ad3 with this change: 1076 of 1077 passed. The failure is agc_driver_pixel_lds, which also fails on unmodified main on this GPU. Rebased onto main 61b8742b; there agc_driver_graphics, guest_np_auth and agc_driver_vertex_clip_cull_distances pass.
  • PPSA06694 on main e152ba8f with the other changes listed in the bring-up discussion (#5322, #5323, #5324 with APS5_STORE_AT_LABEL=1): 8 of 8 runs show the character on the Create Character screen. Without this change, 4 of 4 runs do not: in two it is missing, in two it is drawn black with metallic highlights.
  • tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions (#1191 and #1324 also change RegisteredReadableCovers, for speed, and will conflict with this one there)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA06694 #5320
  • GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 Pro
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846804617 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5321). Originally posted by [lubaxe](https://github.com/lubaxe) on 2026-10-13T17:12:33Z. --- ### What `StorageTexture::writeBackLayers` drops a surface's pending results when its memory is no longer registered (`RegisteredReadableCovers` is false), so that stale texels are not stored over memory that was freed or reused. `RegisteredReadableCovers` looked for one readable registered range containing the whole span (`containingRange`). A surface placed across two adjacent allocations was therefore reported as unregistered, and every write-back of it was dropped. Only the first four drops are logged, and a title usually uses them all at startup, so the later drops are silent. PPSA06694 (Remnant 2, UE5) hits this with its HZB occlusion test. A pixel shader tests object bounds against the HZB into a 256x256 RGBA8 target. A compute pass copies that target into a 256x256 linear staging image, and the CPU reads the result (`Remnant2.exe+0x2f8e75d`). The staging image (0x40000 bytes) lies across two registered allocations (0x30000 + 0x10000), so its results never reached guest memory. The CPU read zeros and treated every object as occluded: the logo mesh was drawn on the first frame only and the screen then stayed black, and later the Create Character screen shows no character. `RegisteredReadableCovers` now walks the registered ranges from the start of the span. The span is covered when consecutive readable ranges reach its end without a gap. The other caller, the `DMA_DATA` copy in `PacketMemory.cpp` (`outcome.path == 2`), uses it to decide whether a destination is registered memory; a destination across adjacent allocations now counts as registered there too. ### Tested - Windows 11 Pro, Ryzen 7 9800X3D, RTX 5090 (driver 617.42), WinLibs GCC 15.2.0 r7, Release. - New `registeredReadableCoverTests` in `agc_driver_graphics`: a range inside one allocation, across two adjacent ones, and over both; not covered past the last allocation, over a gap, over an unreadable allocation, an empty range, and after removal. On `main` it fails with `a range across two adjacent registered allocations must be covered`. - `ctest` on `main` 8c772ad3 with this change: 1076 of 1077 passed. The failure is `agc_driver_pixel_lds`, which also fails on unmodified `main` on this GPU. Rebased onto `main` 61b8742b; there `agc_driver_graphics`, `guest_np_auth` and `agc_driver_vertex_clip_cull_distances` pass. - PPSA06694 on `main` e152ba8f with the other changes listed in the bring-up discussion (#5322, #5323, #5324 with `APS5_STORE_AT_LABEL=1`): 8 of 8 runs show the character on the Create Character screen. Without this change, 4 of 4 runs do not: in two it is missing, in two it is drawn black with metallic highlights. - `tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#1191 and #1324 also change `RegisteredReadableCovers`, for speed, and will conflict with this one there) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA06694 #5320 - [x] GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 Pro - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
coltken95 commented 2026-10-13 19:18:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T19:18:40Z.


Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with db1ddb96c merged into main 18c438b10:

  • With the PR: all five tests in the PR's targets pass (agc_driver_graphics, agc_sparse_buffer_holes, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags, agc_driver_covered_centroid_state).
  • With main's sources and the PR's tests: agc_driver_graphics fails with
    AGC graphics: a range across two adjacent registered allocations must be covered

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153297662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5321#issuecomment-6153297662). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T19:18:40Z. --- Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with db1ddb96c merged into main 18c438b10: - With the PR: all five tests in the PR's targets pass (`agc_driver_graphics`, `agc_sparse_buffer_holes`, `agc_descriptor_pool_reset_failure`, `agc_compute_descriptor_layout_flags`, `agc_driver_covered_centroid_state`). - With main's sources and the PR's tests: `agc_driver_graphics` fails with `AGC graphics: a range across two adjacent registered allocations must be covered` AI-assisted: yes (Claude Code)
Nesyth commented 2026-10-13 20:02:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Nesyth on 2026-10-13T20:02:39Z.


Ready or Not (PPSA18605, #4184) loses storage-image write-backs the same way, and this PR fixes the visible effect there. Measured on main 18c438b10 (Windows 11, RX 7900 XTX), with every module built from that commit:

  • On main, every session drops write-backs from boot on: the log shows the 4 memory no longer registered; 1 pending ranges dropped lines it allows (images of 1 MiB to 64 MiB) in each of 4 sessions. With this PR there are none in any of 3 sessions.
  • The visible case is UE's volumetric lightmap brick atlas, a 1280x85 3D R11G11B10F texture of 5 slices. In some sessions it lies across two registered ranges of one allocation (an older commit and the tail committed when the atlas is built). Its write-back is then dropped, the atlas keeps stale bytes, and the station's fog and the characters it lights take a green or purple tint for the whole session, while the lightmapped walls stay correct. The log tells these sessions apart: the atlas is read from a CPU snapshot (1280x85 mips=1 layers=5 dim=4 tile=7 format=36) instead of from its storage image. On my bring-up build without a fix, all 11 sessions with that layout had the tint and none of the 18 without it.
  • With this PR, session 707 had that layout and the station was clean (first screenshot): green-dominant pixels cover 1.6% of the scene and purple ones 0.01%, the same as in sessions without the layout. None of today's 4 main sessions had the layout, so the tinted example (second screenshot) is from my bring-up build.
  • The same layout as a unit check: a 128x256 R32 storage image over one 128 KiB allocation registered as two 64 KiB ranges. On main the write-back is dropped and none of the 32 stored texels reach memory; with this PR all 32 do.

One difference from the rule I had tested locally, which accepted only adjacent ranges of the same allocation: memory that is freed and registered again as two adjacent allocations now gets the write-back too (32 texels stored into the new allocations in the same unit check, where main drops it). main already writes back into memory registered again as a single allocation, so this may be intended.

image
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154087650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5321#issuecomment-6154087650). Originally posted by [Nesyth](https://github.com/Nesyth) on 2026-10-13T20:02:39Z. --- Ready or Not (PPSA18605, #4184) loses storage-image write-backs the same way, and this PR fixes the visible effect there. Measured on `main` 18c438b10 (Windows 11, RX 7900 XTX), with every module built from that commit: - On `main`, every session drops write-backs from boot on: the log shows the 4 `memory no longer registered; 1 pending ranges dropped` lines it allows (images of 1 MiB to 64 MiB) in each of 4 sessions. With this PR there are none in any of 3 sessions. - The visible case is UE's volumetric lightmap brick atlas, a 1280x85 3D R11G11B10F texture of 5 slices. In some sessions it lies across two registered ranges of one allocation (an older commit and the tail committed when the atlas is built). Its write-back is then dropped, the atlas keeps stale bytes, and the station's fog and the characters it lights take a green or purple tint for the whole session, while the lightmapped walls stay correct. The log tells these sessions apart: the atlas is read from a CPU snapshot (`1280x85 mips=1 layers=5 dim=4 tile=7 format=36`) instead of from its storage image. On my bring-up build without a fix, all 11 sessions with that layout had the tint and none of the 18 without it. - With this PR, session 707 had that layout and the station was clean (first screenshot): green-dominant pixels cover 1.6% of the scene and purple ones 0.01%, the same as in sessions without the layout. None of today's 4 `main` sessions had the layout, so the tinted example (second screenshot) is from my bring-up build. - The same layout as a unit check: a 128x256 R32 storage image over one 128 KiB allocation registered as two 64 KiB ranges. On `main` the write-back is dropped and none of the 32 stored texels reach memory; with this PR all 32 do. One difference from the rule I had tested locally, which accepted only adjacent ranges of the same allocation: memory that is freed and registered again as two adjacent allocations now gets the write-back too (32 texels stored into the new allocations in the same unit check, where `main` drops it). `main` already writes back into memory registered again as a single allocation, so this may be intended. <img width="2568" height="720" alt="image" src="https://github.com/user-attachments/assets/f060fbf7-b7d7-47cc-8396-d6170338302e" />
adriadam10 commented 2026-10-14 18:32:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T18:32:42Z.


Checked on Linux (build + ctest scoped to libSceAgcDriver: only the pre-existing agc_driver_tessellation SEGFAULT fails, same as main). With RegisteredReadableCovers reverted, agc_driver_graphics fails on the new test, so it pins the change. The walk over contiguous readable ranges stops at gaps and unreadable ranges, and the test covers those cases. Also confirmed by @coltken95 (Linux) and @Nesyth (Ready or Not, RX 7900 XTX); merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6175505109 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5321#issuecomment-6175505109). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T18:32:42Z. --- Checked on Linux (build + ctest scoped to libSceAgcDriver: only the pre-existing `agc_driver_tessellation` SEGFAULT fails, same as main). With `RegisteredReadableCovers` reverted, `agc_driver_graphics` fails on the new test, so it pins the change. The walk over contiguous readable ranges stops at gaps and unreadable ranges, and the test covers those cases. Also confirmed by @coltken95 (Linux) and @Nesyth (Ready or Not, RX 7900 XTX); merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5321
No description provided.