Skip to content

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

Closed
savvaniss wants to merge 1 commit into
Get-fix:ps4/limbo-gpufrom
savvaniss:fix/ps4-depth-plane-buffer-memory
Closed

savvaniss wants to merge 1 commit into
Get-fix:ps4/limbo-gpufrom
savvaniss:fix/ps4-depth-plane-buffer-memory

Conversation

@savvaniss

@savvaniss savvaniss commented Oct 21, 2026 •

Copy link
Copy Markdown

What

A depth surface keeps its depth in a Vulkan image. boykopovar#7154, now on ps4/limbo-gpu, 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. D16, stencil and multisampled PS4 planes still keep depth in the host image only, as on the PS5, and the debt entry says so.

#9 adds DepthTarget::gcn next to the new field. The two compose, and whichever lands second rebases a neighbouring line.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on ps4/limbo-gpu 5ed564fa79, AMD Radeon RX 9070 XT.

  • New agc_driver_gcn_depth_plane_buffer_memory, for a Depth2D64 and a Depth2D256 PS4 target 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.
  • Each part of the change is needed. Reverting one at a time, the same test gives:

    build result
    mirrorable and mirrorResource as on 5ed564fa79 fails: "texel 0,0 holds 0.000000 at its tiled offset, expected 0.250000"
    only mirrorable as before fails the same way
    only mirrorResource as before (the plane stored as SW_64KB_Z_X) fails: "texel 4,0 holds 0.750000 at its tiled offset, expected 0.250000"
    this PR passes
  • Validation layer, with ANYPS5_GPU=AMD, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The same 27 tests ran on 5ed564fa79 and on this branch, which also runs the new test: agc_driver, agc_driver_graphics, agc_driver_depth_bounds_state, every agc_driver_depth_* execution test, agc_driver_gcn_detile, agc_driver_native_depth_bda_clear, agc_driver_native_multisample_depth, and the other users of the changed harness (agc_driver_alpha_to_coverage, agc_driver_dispatch_move_depth, agc_driver_multisampled_pass_order, agc_driver_pass_input_hazard).

    • All pass: 27 of 27 and 28 of 28.
    • Neither log has a VUID- line. Both have the same three Undefined-Value-ShaderOutputNotConsumed-DynamicRendering warnings.
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS. Every device in both logs is the RX 9070 XT.
  • No unit test covers the DB_Z_INFO decode line, because no test runs DecodeState with GCN guest shaders. The title run below covers it.

  • Risk (CUSA03312): test/ps4-stubs predates fix(agc): keep depth planes coherent with buffer reads and writes of their memory boykopovar/AnyPS5#7154, so this exact commit was not run in the title. A local experiment on that stack stores the same plane into guest memory, in the same tiling, on the ACQUIRE_MEM DB flush instead of on the buffer read. With it the board is sharp, at the same 21-24 fps. Before and after screenshots of the same board scene are kept locally and available on request.

  • Monopoly Plus, in the same pack, blurs its board for the fix(libSceAgcDriver): sample a PS4 depth buffer through a T# smaller than its padded extent #9 reason. Its depth of field samples the 2048x1152 depth plane through a 1920x1080 R32F Depth2D64 T#, which the depth surface does not serve, so the view read guest memory.

  • tools/check_conventions.py --base getfix/ps4/limbo-gpu passes.

  • tools/pr_overlap.py --repo Get-fix/AnyPS5 --base ps4/limbo-gpu --branch fix/ps4-depth-plane-buffer-memory could not compare 13 open PRs that conflict with the rebuilt base. I read their diffs: none decodes the PS4 depth tile mode or touches the depth plane mirror, and fix(libSceAgcDriver): sample a PS4 depth buffer through a T# smaller than its padded extent #9 only adds the field noted above.

Checklist

🤖 Generated with Claude Code

…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.

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>
@savvaniss

Copy link
Copy Markdown
Author

Moved upstream as boykopovar#9895 on boykopovar#9431. Closing this one.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant