Skip to content

fix(agc): publish only the bytes a write-back retiled into a shadow unit - #22705

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
B-Howell:claude/shadow-publish-produced-bytes
Nov 19, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
B-Howell:claude/shadow-publish-produced-bytes

Conversation

@B-Howell

@B-Howell B-Howell commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

A unit shadow publish copied all 64 KiB of every selected unit from the slab to the import, even when write-backs had retiled only part of the unit. The rest of the slab unit holds bytes that were seeded from the import or left over from an earlier retile, so they are not GPU results. If the guest changed those bytes after the seed read them, the publish wrote the older bytes back over the guest's.

MarkShadowed now records the byte spans that retiles wrote into each unit since it went live, as a sorted list of disjoint spans. publishUnits copies only those spans. Freshness is still decided per unit, as before.

Found in Bloodborne (CUSA00900 1.09). The title's GPU-visible heap keeps chunk headers and free-list links right after its render targets, at offsets such as +0x78040 inside the unit that holds the end of a 0x78000-byte surface. Instrumented runs did the following:

  • snapshotted the heap chain at each unlock of the title's heap mutex, and compared it at the next lock;
  • caught a free chunk's fd link (0x25ab28050) changed while no thread held the heap lock, to an older but plausible heap pointer;
  • showed that the address is in the tail of a unit that shadow publishes copy whole (0x25aab0000+0x80000 over a surface ending at 0x25ab28000).

The stale link later made the title's allocator hand out a chunk inside a live render target. The game crashed in its own free() (rip 0x248599f) at 110-150 s, during the hand-over from the loading screen to gameplay.

Known gap (fragment claude-shadow-publish-produced-bytes.md): freshness is still judged per unit. A CPU store anywhere in a unit drops the unit's retiled bytes too.

Tested

  • Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, RTX 4080 SUPER 621.14.
  • New case in tests/execution/StorageFlushOrdering.cpp (RunPartlyShadowedUnitPublish): it fills a whole slab unit, marks only part of it shadowed, publishes, and checks the guest bytes outside the marked spans. It covers half a unit, two disjoint spans, and a second span marked into an already published unit.
  • On main the half-unit case fails: FAILED, 8192 dwords past the retiled range hold the slab's bytes, not the guest's. With this change, agc_driver_storage_flush_ordering and agc_driver_storage_flush_ordering_no_import pass.
  • Validation: both arms ran ctest --test-dir build -R agc_driver_storage_flush_ordering -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer (LunarG layer 1.4.363).
    • Both logs contain Insert instance layer "VK_LAYER_KHRONOS_validation".
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
    • Neither log has any VUID- line.
  • domx4q on head d7258c0045 merged onto main 1ccc399b17: Arch Linux, GCC 16.2.1, RTX 4090 (Ada), NVIDIA 620.70.06, Khronos layer 1.4.363.1. Both focused tests pass on main and on the PR, the layer loads in both, and neither log has a VUID- line. With main's UnitShadow.cpp the new partly-retiled case fails 2 of 2 runs.
  • milescoviello on head d7258c0045 merged onto main 6119c53c4b: Linux 7.0, RTX 4070 Ti, NVIDIA 615.71.09, Ghost of Tsushima (PPSA02225), 450 s scripted runs from a pinned save with a cold shader cache. No visible corruption; menus and cutscene frames match main. One black-screen stall was also seen on a build without this change, and one segfault was in the shader recompiler (FencedEntries), which this PR does not touch.
  • Bloodborne CUSA00900 retest with this change (Windows 11, RTX 4080 SUPER): the crash at the loading-to-gameplay handover did not occur in 3 of 3 runs, where it had occurred in every handover run before the change (result).
  • rafaconvaitis on head d7258c0045 merged onto main 3c07e1d05e: Windows 11 25H2, WinLibs GCC 15.2.0, AMD Radeon 760M iGPU, AMD Software 26.11.2, Khronos layer 1.4.363. Both focused tests pass 3 of 3 runs on main and on the PR, the layer loads in every run, and no log has a VUID- line. With this PR's tests on main's sources, agc_driver_storage_flush_ordering fails (quarter 2 has 4096 dwords that are not 0x3f800000).
  • Colewiz7 on head d7258c0045 merged onto main 7c836568c8: Linux 7.3.4, GCC 16.2.1, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036). The full test set (6206 tests on the 7900 XT, the 2007 GPU tests on the iGPU) and -R '^agc' with the Khronos layer 1.4.363.1 show no new failures against main, and neither GPU has a VUID- or SYNC-HAZARD line.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: CUSA00900 Bloodborne PS4 executables on AnyPS5: first results (a PS4 homebrew runs) and what retail PS4 games would need #3094
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 621.14, Windows 11 Pro 10.0.26300; NVIDIA GeForce RTX 4090, driver 620.70.06, Arch Linux (domx4q); AMD Radeon 760M, AMD Software 26.11.2, Windows 11 25H2 (rafaconvaitis); AMD Radeon RX 7900 XT and 7800X3D iGPU, Mesa 26.2.6 RADV, Linux 7.3.4 (Colewiz7)
  • AI-assisted: yes

B-Howell and others added 2 commits November 17, 2026 22:55
A unit shadow publish copied every byte of a 64 KiB unit from the slab to
the import. In a unit that a write-back covers only in part, the rest of
the slab holds bytes seeded from the import or left by an earlier retile.
Those bytes are not GPU results. If a CPU store landed after the seed read
the import, the publish put the old bytes back over it.

MarkShadowed now records the span of each unit that retiles wrote since
its last publish, and a publish copies only that span.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A unit's produced range was the hull of its retiled spans, so slab
bytes in a gap between two spans were still published. Keep the spans
as a sorted list and copy each one.

The test now also covers two disjoint spans and a second span retiled
into a unit that was already published.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Nov 18, 2026
@B-Howell

Copy link
Copy Markdown
Contributor Author

@PrivacyOnion @MarcZX10 could one of you review this on d7258c0045c, please? CI passes and it merges cleanly with main.

The new StorageFlushOrdering case fails on main and passes with the change, and the validation logs of both arms have no VUID- lines. I have not yet retested it in Bloodborne: a local display change stopped the game run before gameplay. I will post that result here when it is done.

@github-actions github-actions Bot added docs agc libSceAgc* labels Nov 18, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the optional point below concerns test coverage.

What I ran

Reviewed head d7258c0045cf479d1d652691f1d68374a2d8a7f8. I read UnitShadow.cpp, StorageFlushOrdering.cpp, and claude-shadow-publish-produced-bytes.md, along with the prepared description, commits, manifest, and diff. No commands or tests were run in this review; the test results in the description are author-reported.

Results

Check Result Note
Changed code review passed Read all three changed files
Tests not run Results supplied by author

Findings

Blocking

None.

Non-blocking

  • The added test checks partial, disjoint, and subsequent spans, but not a range clipped at the start or end of a partially covered import unit. Adding such a case would exercise the UnitRange clipping used when forming copy regions.

Not verified

No tests were run. Runtime behavior, including the reported Bloodborne issue, was not independently verified. All files listed as reviewed in the manifest were read; none were excluded.

To get this to a good state

Nothing is required. Optionally add coverage for spans clipped at an import boundary.

@B-Howell

Copy link
Copy Markdown
Contributor Author

@oneandonlydean MarcZX10 approved the current head d7258c0045c, all checks pass on it and it merges cleanly with main. Please merge when ready.

It fixes a heap overwrite that crashed Bloodborne CUSA00900 at the handover into gameplay. The in-game retest is still pending.

@MarcZX10 thanks for the review. I will add the optional case for a span clipped at an import-unit boundary as a follow-up rather than move this head.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 6186 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/UnitShadow.cpp
core/libs/prx/libSceAgcDriver/tests/execution/StorageFlushOrdering.cpp

@domx4q

domx4q commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Ran the storage flush ordering tests on NVIDIA's proprietary Linux driver with the Khronos validation layer, since the description's runs are on Windows.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head d7258c0045 merged onto main 1ccc399b17 with --no-ff, clean merge. Main baseline is a Release build of 1ccc399b17 on the same machine.

WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 DISPLAY=:0 ANYPS5_REQUIRE_DISPLAY=1 \
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R '^agc_driver_storage_flush_ordering.*$' -V
main 1ccc399b17 this PR
Result 2/2 passed 2/2 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 2 2
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

Main runs its own version of StorageFlushOrdering.cpp, without the new partly-retiled case. On this PR, agc_driver_storage_flush_ordering with that case and agc_driver_storage_flush_ordering_no_import pass. Every device selection picked the RTX 4090.

Negative control: this PR's build with main's UnitShadow.cpp fails agc_driver_storage_flush_ordering deterministically (2 of 2 runs) with storage flush ordering, publish of a unit retiled only in part: FAILED, quarter 2 has 4096 dwords that are not 0x3f800000; _no_import still passes, and neither run logs a VUID-.

No new VUID- errors; all focused tests pass on Ada.

AI-assisted: yes (Claude Code)

@B-Howell

Copy link
Copy Markdown
Contributor Author

Thanks @domx4q, this is a great run. Linux and Ada were the gaps, and the negative control with main's UnitShadow.cpp shows the new case really catches the bug. I added it to the Tested section and the GPU list.

@B-Howell

Copy link
Copy Markdown
Contributor Author

In-game retest on Bloodborne CUSA00900 01.09 (Windows, local tree = main plus earlier Bloodborne fixes plus this PR's d7258c0045c change), Continue from a save made right after the contract:

  • The handover crash is gone in 3 of 3 runs. Before this change, every run that reached the end of the item-tip loading screen crashed at 110-150 s in the title's free() (rip 0x248599f, overwritten heap header). With it, all three runs got through the loading screen into the opening in-engine cutscene ("Good. All signed and sealed.") with no heap fault.
  • Run 1 (no input after Continue) played the cutscene until I stopped it at 290 s, with no error.
  • Runs 2 and 3 pressed Options then Cross to skip the cutscene. Both stopped about 1-15 s after the skip on an unrelated AGC error, the same in both runs:
[gpu] driver failure: shader 0x313e0e300 stage 5: runtime image descriptor is invalid: image 1 first used at pc 0x44 (required, read 1, written 0, r128 0), T# 13e25d40 000c0003 00000002 20050fac 00031d44 00000050 00000000 0007c480

That is a new, separate stop (a pixel shader prepared at first use right after the skip) and is not related to the shadow publish. Controllable gameplay is not reached yet, so there is no gameplay FPS. Presents per 10 s: title and menus 17-26 FPS, the loading screen 0.9-13 FPS while the map streams, and the cutscene 15-24 FPS (about 21 on average).

@milescoviello

Copy link
Copy Markdown
Contributor

Ghost of Tsushima (PPSA02225) runs with this PR. I was watching for corruption or crashes from GPU bytes that are no longer published, since GoT leans heavily on shadow units.

Setup:

  • Builds: main 6119c53c4b against 64045de75d, which is that main with this head (d7258c0045) merged. Release libraries.
  • Hardware: Linux 7.0, RTX 4070 Ti 12 GiB, NVIDIA 615.71.09.
  • Run: pinned save, the same scripted presses each run, 450 s, 22 GB memory cap, a cold shader cache every run.
run build end presents at 300 / 450 s
1 main 453 s timeout 1291 pause menu, cutscene
2 this PR 452 s timeout 1267 pause menu, cutscene
3 main killed at 247 s by my 22 GB cap 1246 —
4 this PR 457 s timeout 808 black from about 200 s, presents stopped
5 this PR 452 s timeout 1207 black frame, then the pause menu
6 main 453 s timeout 1225 options menu
7 this PR segfault at 67 s 699 —
  • No corruption I can see. The menus and the cutscene frames match between the arms.
  • Run 4's stall isn't specific to this PR. The same black screen with presents stopping also showed up in a run of a different build without this change: main + perf(agc): demand-driven texture cache budgets behind a switch #22580 with its switch off, on the same day.
  • Run 7's crash is outside this PR's code. It is a SIGSEGV (code 2) at 0x1000500c7 in libSceAgcDriver.prx+0xb5d2d8, which resolves to ShaderRecompiler::Analysis::FencedEntries in SpirvSpannedUniformity.cpp, during the cold shader compile. This PR doesn't touch the recompiler, and the other six runs compiled the same shaders without it, so I read it as an intermittent crash on main.
  • I couldn't exercise the Bloodborne case here: GoT doesn't keep allocator headers after its render targets. So this is a check that nothing else regresses, not a check of the fix.

AI-assisted: yes (Claude Code). The runs are from this machine.

@B-Howell

Copy link
Copy Markdown
Contributor Author

Thanks @milescoviello, added to Tested. Agreed on both: the run 4 stall also shows up without this change, and the run 7 segfault is in the shader recompiler, which this PR does not touch.

@rafaconvaitis

Copy link
Copy Markdown
Contributor

Windows + AMD run; I found no AMD run in the description or in the comments. Head d7258c0045 merged alone onto main 3c07e1d05e with git merge --no-ff (clean merge).

Setup: Windows 11 25H2 (build 26200), AMD Radeon 760M integrated graphics (1002:15bf, Vulkan device name Radeon 5), AMD Software 26.11.2 (driver 32.0.32029.2010, Vulkan 1.4.359), selected with ANYPS5_GPU=Radeon, WinLibs GCC 15.2.0 r7 UCRT, Release, BUILD_TESTING=ON, Khronos validation layer 1.4.363 (LunarG SDK 1.4.363.1). Only the focused test targets were built; the other execution tests were left out with ANYPS5_AGC_EXECUTION_TESTS.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, ctest -R '^(agc_driver_storage_flush_ordering|agc_driver_storage_flush_ordering_no_import)$' -V -j 1, 3 runs per side.

test main this PR this PR's tests on main's sources (1 run)
agc_driver_storage_flush_ordering passes 3/3 passes 3/3 fails
agc_driver_storage_flush_ordering_no_import passes 3/3 passes 3/3 passes
  • Negative control: with the tests of this PR built on main's sources (without the 1 production file this PR changes), agc_driver_storage_flush_ordering does not pass, so on this driver the test detects the change. It fails with storage flush ordering, publish of a unit retiled only in part: FAILED, quarter 2 has 4096 dwords that are not 0x3f800000.
  • VUID- lines: 0 in the main and PR logs. Every run logs Selected GPU name=Radeon 5 vendor=0x1002 device=0x15bf and Insert instance layer "VK_LAYER_KHRONOS_validation", and none logs was not found but was requested.

AI-assisted: yes (build and runs scripted with an AI assistant, on the hardware above).

@B-Howell

Copy link
Copy Markdown
Contributor Author

@rafaconvaitis thanks for testing d7258c0045 on the Radeon 760M: both focused tests pass with no VUID- lines, and the new case fails on main's sources. Added to Tested.

@Colewiz7

Copy link
Copy Markdown
Contributor

Head d7258c0045 merged onto main 7c836568c8 as 835553baf7, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6206 on the 7900 XT, the 2007 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1940 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@B-Howell

Copy link
Copy Markdown
Contributor Author

@Colewiz7 thanks for running d7258c0045 on RADV with the RX 7900 XT and the iGPU: no new failures and no VUID- or SYNC-HAZARD lines on either. Added to Tested.

@B-Howell

Copy link
Copy Markdown
Contributor Author

@MarcZX10 the follow-up for your coverage point is #23825: it tests a retiled span that starts at the import's first byte and one that ends at its last byte, both inside partly covered units. Both checks fail with this PR's fix reverted.

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

Labels

agc libSceAgc* docs unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants