Skip to content

fix(agc): keep PS4 depth planes coherent with buffer reads of their memory - #124

Open
Thimo188 wants to merge 15 commits into
mainfrom
upstream-pr/9895
Open

Thimo188 wants to merge 15 commits into
mainfrom
upstream-pr/9895

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#9895, originally opened by savvaniss.

Source commit: d70e6e1bc1caaee46f386a47afb104518e0be9f3. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Get-fix#20, moved upstream as Get-fix asked. boykopovar#9431 is on main now, so this PR's diff is only the change below.

A depth surface keeps its depth in a Vulkan image. boykopovar#7154 keeps a depth plane coherent with buffer reads and writes of its memory:

  • a plane drawn since its last store is stored into guest memory when a buffer upload, a GuestBuffers V#, an image lookup or a pending-store flush overlaps it;
  • a plane the guest wrote is reloaded at the next bind.

It only takes single-sample 32-bit planes with the PS5's 64 KiB Z swizzle (SW_MODE 24). A PS4 DB_Z_INFO names a GB_TILE_MODE index, not a swizzle mode. So a PS4 plane never took part, and a buffer read of it saw whatever guest memory held.

Risk (CUSA03312) reads its depth that way in every board frame. On the Hasbro experiment stack (test/ps4-stubs, RX 9070 XT) the frame does this:

  • a full-screen draw with DB_RENDER_CONTROL = 0x60 over the scene depth: 2048x1152 D32_SFLOAT_S8_UINT, DB_Z_INFO = 0xa0000003, so tile index 0 (Depth2D64);
  • ACQUIRE_MEM with CP_COHER_CNTL = 0x84c44000 (DB action) over the scene plane and over a second 9 MB buffer;
  • DISPATCH_DIRECT 0x2400 x 1 x 1, which is 9,216 groups of 64 threads at 16 bytes each. It copies the 9,437,184-byte plane into the second buffer with buffer loads and stores;
  • the depth-of-field compute reads that copy through an R32F Depth2D64 T# (1920x1080, pitch 2048) and writes its circle of confusion.

The copy carried stale memory, so the whole board was out of focus. Menus and 2D screens were sharp. Monopoly Plus, in the same pack, reads its depth through a T# smaller than the padded plane; that view reaches this PR's store through boykopovar#7154's image-lookup flush (see Tested).

This PR:

PS5 planes are unchanged.

Since boykopovar#9026 a plane is stored in 64 KiB units. A PS4 plane is tracked as one unit (SizeUnits), so it is stored and reloaded whole. With 64 KiB units, the Depth2D256 case below left the texels past its first unit unstored, even with a read in every unit. A debt entry of its own says so. D16, stencil and multisampled PS4 planes still keep depth in the host image only. main's stencil store (boykopovar#12210) needs the PS5 swizzle in StencilMirrorable, so it does not take a PS4 plane.

Source for TILE_MODE_INDEX. Nothing here is an AMD statement about Liverpool or a console measurement:

This code does not read DB_DEPTH_INFO, so a title whose two registers disagreed would be stored in the index's tiling. The debt entry records that.

boykopovar#9672 (Get-fix#9 upstream) adds DepthTarget::gcn next to the new field. The two compose, and whichever lands second rebases a neighbouring line and recomputes the guard.

Tested

Return to a tiling, 2 Nov. Head c72cf633cd, test-only. oneandonlydean's review: going back to a tiling whose surface still exists. TileModeSwitch now binds the first tiling again without writing and compares a draw at 0.5 under LESS with the plane's bytes in that tiling, on a new surface and on a reused one (a sampled texture held across the switch, DepthSurfacesSerial unchanged). No driver change was needed. Removing the SyncFromMemory call on that bind, hiding the store from the reused surface, or removing the store each fails it at its own check (see the thread). agc_driver_gcn_depth_plane_buffer_memory passes, 1 of 1 on the RX 9070 XT, no VUID- line. Not rerun: the other 34 tests of the 1 Nov run (no driver code changed), the same test on main, the flip tests, Linux, games.

Tile-mode switch, 1 Nov. Head 55f884b209 (0b365d9926 plus a shorter debt entry). oneandonlydean's review: a surface reused across a tile-mode change stored in its old layout. agc_driver_gcn_depth_plane_buffer_memory gains TileModeSwitch on one 512x256 allocation, Depth2D64 then Depth2D256 and the reverse. Removing the tile compare, the store at the switch or the reload each fails it at its own check (see the thread). 35 of 35 pass once on the RX 9070 XT: agc_driver, agc_driver_pm4, agc_driver_graphics, agc_driver_gcn_detile, agc_driver_gcn_depth_plane_buffer_memory, agc_driver_resource_cache_replaced_texture and every agc_driver_depth_* test, no VUID- line. Not rerun: the same set on main, the flip tests, Linux (no struct under the size guards changed), games.

Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (driver 32.0.31041.1004), ANYPS5_GPU=AMD.

Merge of main de83e8f270, 31 Oct. Head 5d1381c40e. The only conflict was in docs/dev/debt/libSceAgcDriver.md: both sides kept. agc_driver_gcn_depth_plane_buffer_memory, agc_driver_depth_fast_clear_submit and agc_driver_graphics pass, 3 of 3 on the RX 9070 XT, no VUID- line. Not rerun: the other tests, Linux (main changed no struct under the size guards in this merge), games.

Base. This branch is now 853389c92c: main 5b913d40c6 merged in (d8a0a2734b), then the guard bump, the decode test and a debt line. Every file boykopovar#9431 touched takes main's version. git diff 5b913d40c6 853389c92c holds only this PR's ten files. git merge-tree with main d2250771ab has no conflicts; that merge was not built. The Windows and Linux runs below were on 4c37f8af0c; 853389c92c adds one debt sentence to it.

  • New agc_driver_gcn_depth_plane_buffer_memory runs a Depth2D64 and a Depth2D256 PS4 target, each two macro tiles wide and high (512x256 for Depth2D64):

    • it draws depth 0.75, then 0.25 over the left half and 0.5 in a 6x7 block, fetches vertices from the plane (a buffer read), and checks every texel at its GCN tiled offset;
    • it then writes 0.25 to the left half and 0.75 to the right half of the tiled plane, and checks pixel by pixel that a draw at 0.5 under LESS passes exactly on the right half.

    The test harness gains an optional GCN tile mode on Surface and an optional scissor in DrawOptions.

  • New GcnDepthTileModeTests in agc_driver_graphics decodes DB_Z_INFO through DecodeState: 0xa0000003 with DB_DEPTH_SIZE for 2048x1152 gives Depth2D64 at that size, index 2 gives Depth2D256, index 7 gives DepthPrt1K, the field above the index changes nothing, a PS4 surface with no depth plane stays unset, and a PS5 DB_Z_INFO stays unset.

  • Revert checks on 4c37f8af0c, one rebuild each. Each test fails as shown and passes again with the files restored:

    Removed Test Failure
    DepthSurface.cpp, GuestTextureResource.cpp and State.cpp as on 5b913d40c6, headers kept agc_driver_gcn_depth_plane_buffer_memory PS4 depth tile mode 19 (512x256): after a buffer read of the depth plane, texel 0,0 holds 0.000000 at its tiled offset, expected 0.250000
    The gcnTileMode test in SizeUnits (one-unit rule) agc_driver_gcn_depth_plane_buffer_memory PS4 depth tile mode 21 (256x128): after a buffer read of the depth plane, texel 0,64 holds 0.000000 at its tiled offset, expected 0.250000
    The decode line in State.cpp agc_driver_graphics PS4 DB_Z_INFO 0xa0000003 did not decode as Depth2D64
    Shift by 21 instead of 20 agc_driver_graphics PS4 DB_Z_INFO TILE_MODE_INDEX 2 did not decode as Depth2D256
    Mask of 15 instead of 7 agc_driver_graphics PS4 DB_Z_INFO bits above TILE_MODE_INDEX changed the depth tiling
    The zFormat != 0 test agc_driver_graphics a PS4 surface without a depth plane took a depth tiling
    The if (gcn) scope (PS5 decode also takes the index) agc_driver_graphics a PS5 DB_Z_INFO took a GCN depth tiling
  • Validation layer: run with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -V, on main 5b913d40c6 and on this branch. The tests:

    • agc_driver_gcn_depth_plane_buffer_memory, agc_driver, agc_driver_pm4, agc_driver_pm4_replay, agc_driver_graphics, agc_driver_register_key, agc_driver_gcn_detile and agc_driver_pattern_buffer_fill
    • agc_driver_flip and the 17 video_out_flip_* modes
    • agc_gcn_decode, texture_format_lookup, agc_driver_resource_cache_replaced_texture and agc_depth_copy_kept_bytes
    • the 29 agc_driver_depth_* tests, among them agc_driver_depth_plane_buffer_memory, agc_driver_depth_fast_clear and agc_driver_depth_fast_clear_submit

    Results:

    • main: 58 of 58 pass (the new test is not on main).
    • This branch: 59 of 59 pass.
    • Neither log has a VUID- line or was not found but was requested by env var VK_INSTANCE_LAYERS. Every Selected GPU line names the RX 9070 XT (49 on main, 50 here).
  • Linux: WSL Ubuntu, g++ 15.2.0, cmake 4.2.3, Unix Makefiles, -j4, from a git archive of this code on the Linux filesystem.

    • A plain configure stops at CMakeLists.txt:513 and :521, because the machine has no X11 or audio development packages. In that local copy only, those two FATAL_ERRORs became warnings. FFmpeg came from the project's ffmpeg-linux-x64.zip through FFMPEG_PREBUILT_DIR.
    • Before the bump, PipelineJournal.cpp stopped at the guard with (928 == 920). ShaderStages stays at 164.
    • Built after the bump: shader_recompiler_agc_driver, agc_driver_pm4_tests, agc_driver_graphics_tests, agc_driver_depth_plane_buffer_memory_tests and agc_driver_gcn_depth_plane_buffer_memory_tests, and so all of libSceAgcDriver. That includes Graphics/src/PipelineJournal.cpp and core/shader/recompiler/ShaderDiskCache.cpp, with their size guards active.
    • Ran: those four tests, 4 of 4 pass. agc_driver_depth_plane_buffer_memory and agc_driver_gcn_depth_plane_buffer_memory ran on llvmpipe (LLVM 21.1.8); the other two print no Selected GPU line.
    • Not run on Linux: every other test, a hardware GPU, the validation layer, and any build with SDL's X11 or audio backends.
  • Risk (CUSA03312): its board is sharp with a local stand-in that stores the same plane in the same tiling on the DB-flush ACQUIRE_MEM. That stand-in ran on ps4/limbo-gpu at 93eeee0141 (feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) boykopovar/AnyPS5#6977's head then), with the Get-fix pull requests and local stand-ins for sceGnmDrawInitDefaultHardwareState200 and sceGnmUpdate*Shader; that base predates fix(agc): keep depth planes coherent with buffer reads and writes of their memory boykopovar/AnyPS5#7154. This exact commit wasn't run in the title, which also needs feat(libSceGnmDriver): build PS4 command buffers and submit them boykopovar/AnyPS5#9432.

  • tools/check_conventions.py --base origin/main passes.

  • tools/pr_overlap.py --branch pr9895-local (this commit), against main d2250771ab. Six pull requests conflict with this PR's lines:

    All of them compose, and whichever lands second resolves the conflict and recomputes the guard if State changed. Another 64 pull requests conflict with main themselves, so the tool could not compare them; 41 of those share a file with this PR's code or tests, among them feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) boykopovar/AnyPS5#6977 and feat(libSceGnmDriver): build PS4 command buffers and submit them boykopovar/AnyPS5#9432.

  • Head 224af33ff1 (2026-11-03): a docs-only commit on 55cc111fe4 that drops this PR's clause from the PS4 render-target debt entry, as XairRrR's review of 55cc111fe4 suggested; the entry is now identical to main's and the PS4 depth-plane entry still states the tiling. tools/check_conventions.py --base origin/main (1e658521a0) passes. No code changed, so nothing was rebuilt or rerun.

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
  • 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: CUSA03312 Hasbro Family Fun Pack (CUSA03312) boykopovar/AnyPS5#7198
  • GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.31041.1004, Windows 11 Pro 26300
  • AI-assisted: yes

🤖 Generated with Claude Code

savvaniss and others added 15 commits October 22, 2026 23:42
…emory

A depth surface keeps its depth in a Vulkan image. boykopovar#7154
stores a single-sample 32-bit plane with the 64 KiB Z swizzle into guest
memory when a buffer read overlaps it, and reloads it when the guest wrote
it. A PS4 depth target never took part: its DB_Z_INFO names a GB_TILE_MODE
index, not a swizzle mode, so the plane kept whatever guest memory held.

Risk (CUSA03312) decompresses its scene depth, flushes the depth block's
cache over it and copies the 9 MB plane into a second buffer with a compute
shader (buffer loads and stores). Its depth of field reads that copy
through an R32F Depth2D64 T#, so with stale bytes the whole board was out
of focus.

A PS4 depth target now records the GB_TILE_MODE of its depth plane
(DB_Z_INFO TILE_MODE_INDEX, mapped as the T# decode maps a tiling index).
Such a 32-bit plane is mirrored in that tiling with DB_DEPTH_SIZE as its
pitch, through the existing store and reload paths.

Since boykopovar#9026 a plane is stored in 64 KiB units. A PS4 plane is tracked as
one unit, so it is stored and reloaded whole: with 64 KiB units the
Depth2D256 case left the texels past its first unit unstored.

agc_driver_gcn_depth_plane_buffer_memory draws three depths into
Depth2D64 and Depth2D256 PS4 targets, reads the plane as a buffer and
checks every texel at its GCN tiled offset. It then writes a left/right
pattern into the tiled plane and checks that a LESS draw passes exactly
where memory holds the greater depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in main 07da04f through the boykopovar#9431 merge offered as
Get-fix#22. The PS4 tile mode lands in main's decodeDepthPlane,
which now holds boykopovar#9431's PS4 depth decode. The debt file keeps this
branch's PS4 depth plane entry under the guest-memory entry it extends,
followed by main's shared-memory and unmapped-plane entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
boykopovar#9431 is on main now, so every file it touched takes main's version. Only
this PR's own changes stay on top. In the debt file, this PR's PS4 entry sits
after main's "Depth planes in guest memory" entry, with main's text of that
entry and of its new stencil entry; StencilMirrorable still needs the PS5
swizzle, so a PS4 stencil plane stays in the host image as the entry says.
The entry now names its sources for TILE_MODE_INDEX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The new optional adds 8 bytes to State (928 on Linux x86_64 with libstdc++).
The journal needs no other change: CanonicalPipelineState and the recipe codec
keep only the depth target's format and samples, so the field never reaches a
recipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Mode

Covers Risk's 0xa0000003 as Depth2D64, indices 2 and 7, the field above the
index, a PS4 surface with no depth plane, and a PS5 DB_Z_INFO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sameSurface does not compare DepthTarget::gcnTileMode, as it does not compare
the swizzle of a single-sample PS5 plane, so a surface rebound at the same
address and size keeps the mode it was created with.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A surface was reused at the same address and extent when only its GCN tile
mode changed, so stores kept the layout it was created with while the sync
at bind used the new one. Surfaces now compare the tile mode. Binding another
tiling of the same storage stores the old surface's stale depth in its own
layout and retires it, and a surface created for the new tiling reads the
plane from memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rfaces

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch and main both contain 26d651d, so a default merge uses a
virtual base and reports conflicts in GuestTextureResource.hpp/.cpp,
TextureDetiler.cpp, TextureTiling.cpp and the libSceAgcDriver debt file that
neither side made. Merged against main's last merge base de83e8f instead.
The one conflict left, in GuestTextureResource.cpp, is two new functions
added at the same place (this branch's GcnTileMode, main's
TextureResourceAllocationAddress); both are kept.


Both sides grew State and each set the size check in PipelineJournal.cpp
from 920 to 928, so git kept 928 silently. With both sets of fields State
is 936; the canonical state and recipe codec already cover each side's fields.
State.hpp: DepthTarget keeps both fields, the PR's gcnTileMode (DB_Z_INFO tiling of a PS4 depth plane) and main's gcn (PS4 guest flag, boykopovar#9672); they are separate facts.
Debt doc: the PS4 render target line keeps both added clauses.
The PS4 depth-plane entry already says a 32-bit plane reaches guest
memory in its GB_TILE_MODE, and the added clause took the render-target
entry past the 1000-character limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both sides grew State by 8 bytes and both set the size guard to 936; the merged State is 944.
@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line needs rebase Conflicts with main, rebase needed labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants