Skip to content

fix(agc): PS4 display, textures and GCN instructions for CUSA03312 - #1

Closed
savvaniss wants to merge 11 commits into
Get-fix:ps4/limbo-gpufrom
savvaniss:fix/ps4-gcn-path
Closed

savvaniss wants to merge 11 commits into
Get-fix:ps4/limbo-gpufrom
savvaniss:fix/ps4-gcn-path

Conversation

@savvaniss

@savvaniss savvaniss commented Oct 19, 2026 •

Copy link
Copy Markdown

What

Ten fixes to this PR's PS4 path, found while bringing up Risk and Monopoly Plus from CUSA03312 (Hasbro Family Fun Pack, my own dump) on top of boykopovar#6977. With them, the converted Risk executable plays a local match against the AI, and Monopoly Plus reaches its loading screen. This targets boykopovar#6977's branch so you can take any of them into your PR; each commit stands alone.

  1. Display buffers presented before they are drawn. PresentDisplayBuffer uploaded a tiled display buffer with no resident image through GpuColorTransfer, in the PS5 render-target layout. That layout needs 64 KiB alignment and doesn't know GCN tiling. Risk flips its 32 KiB-aligned 1920x1080 buffers before drawing into them and failed with "null or misaligned address". A GCN-tiled buffer without a resident image now goes through ReadDisplayBuffer, which decodes the GCN layout and checks the buffer's own 4 KiB alignment.
  2. T# base address. In a GCN T#, word 1 bits 6-7 are MTYPE_L2, so the base is 38 bits (shadPS4's resource.h: base_address : 38; mtype_l2 : 2). DecodeTextureResource read 40 bits, so MTYPE_L2 = 1 set address bit 46, and a storage texture failed with "storage texture has no committed guest pages".
  3. MTBUF. GCN MTBUF is the RDNA encoding with DFMT/NFMT in word 0 bits 19-25 instead of the unified format. The opcodes are the same, ADDR64 still throws, and the format comes from GcnBufferFormats().
  4. Linear-aligned color targets. Tile mode index 8 used the PS5 linear layout, which pads the pitch to 256 bytes. GCN pads a linear-aligned pitch to max(8, 64 / bytes per element) elements, as AddrLib's SiLib::HwlGetPitchAlignmentLinear does and as this PR's PS4 texture layout already does. ColorTileMode::GcnLinear carries that alignment.
  5. V_RSQ_CLAMP_F32 (VOP1 0x2c, VOP3 0x1ac) has no RDNA opcode. It decodes as V_RSQ_F32 tagged VRsqClampF32, and an infinite result becomes the largest finite float of the same sign.
  6. SOPK 0x03 to 0x0f (s_cmpk_*, s_addk_i32) have the same opcodes on RDNA and are now in the GCN table.
  7. GCN image dimension from the T# (new; this answers the question I asked on feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) boykopovar/AnyPS5#6977). GCN MIMG has no DIM field: the T# type decides how many address VGPRs the hardware reads. The translation still infers 2D, or 2D array with DA, but now reads up to three more address VGPRs. The materializer takes the dimension from the T# (a cube as a 2D array of faces) instead of refusing a mismatch, and the emitter counts the address's coordinates and gradients for that dimension. An image selected at run time offers every T# dimension, except those SPIR-V cannot express for its accesses (3D under a depth comparison; 1D and 3D under a gather, which a new ImageResource::gathered flag records). Risk samples a cube T# and a 2D T# under DA samples; Monopoly Plus samples a 3D T# under a 2D-inferred sample.
  8. SMRD literal offsets (new). With IMM 0 and OFFSET 255, a GCN SMRD takes a 32-bit literal that counts dwords. It becomes the RDNA SMEM byte offset with a null SOFFSET; a literal past the 20-bit positive range throws. Monopoly Plus uses s_buffer_load_dwordx4 with a literal.
  9. PS4 3D textures in thin tile modes (new). A thin-tiled volume is laid out like a layered surface whose level n holds max(1, depth >> n) slices, padded to a power of two with POW2_PAD. That is how ac_surface and AddrLib's PostComputeMipLevel count them. It becomes one 3D image of its depth; thick modes still throw.
  10. s_setreg_imm32_b32 keeps its literal (new; @javierUDP's suggestion on feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) boykopovar/AnyPS5#6977). The SOPK branch of the decoder never copied the literal of this eight-byte instruction, so it was re-encoded as one word and its decode threw "literal operand word is out of the code span bounds". The commit credits @javierUDP as co-author.

Tests:

  • agc_gcn_decode covers 3, 5, 6, 8 and 10.
  • agc_driver_graphics covers 9, through TextureTiling.cpp.
  • agc_shader_memory covers 7. It checks the run-time modes on a 2D-inferred image, and the dimension each T# selects. It also checks that gathers and comparisons refuse the dimensions SPIR-V lacks. And it recompiles a GCN compute shader (s_load, image_sample_lz, buffer_store) whose T# is 3D, and checks that the sample reads a 3D image with three coordinates. Both new checks fail without the change.

Not in this PR:

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, on boykopovar#6977's head 93eeee014.

  • Validation: Khronos validation layer 1.4.363 (Vulkan SDK), with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1. Ran ctest -R <tests> -V on your head and on this branch. The tests:
    • agc_display_buffer_dcc, agc_driver_graphics, agc_driver_gcn_detile and linear_display_buffer;
    • the color target execution tests packed_unorm, srgb8, uint8x4 and uint8x4_no_resident;
    • agc_shader_memory, agc_shader_disk_cache and agc_shader_type_zero_image_materialization;
    • agc_gcn_decode, on this branch only.
UHD 770 RX 9070 XT
boykopovar#6977 93eeee014 11 of 11 pass 11 of 11 pass
this branch f9b38d16d 12 of 12 pass 12 of 12 pass

Neither log reports was not found but was requested by env var VK_INSTANCE_LAYERS. Both sides log the same three VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 errors on both GPUs, all from agc_driver_srgb8_color_target, so this branch adds no VUID-.

  • Risk: started with the launcher's arguments (root=/app0/risk sku=eu) on the RX 9070 XT, with APS5_SYNC_DRAWS=1 and APS5_SYNC_FLIP=1. The rest of the stack: the PRs above, quad lists, and the local stand-ins above. It plays its intro, reaches the title, Uplay and main menus, and plays a three-player match against the AI: draft, attack and fortify turns. The menus run at 18-20 fps and the board at 6-8 fps with the sync switches.
  • Monopoly Plus: started the same way (root=/app0/monopoly). With fixes 7 to 9 it gets past its 3D colour texture and literal SMRD loads and shows its loading animation at 60 fps.
  • Fix 10: the new agc_gcn_decode case decodes {0xba80f801, 0x12345678, 0xbf810000}. On f9b38d16d7 it fails with "literal operand word is out of the code span bounds". With 0dd1e4b384 it decodes as SSetregImm32B32, two words, with the literal in source0. Fix 10 changes only the GCN decoder, and agc_gcn_decode opens no Vulkan device, so it adds nothing to the validation logs above.
  • Checks: tools/check_conventions.py --base 93eeee014 passes.

Checklist

🤖 Generated with Claude Code

savvaniss and others added 7 commits October 19, 2026 23:41
…nt through the GCN decode

PresentDisplayBuffer presents a tiled display buffer from its resident
image when a draw rendered it. Otherwise it uploaded the buffer with
GpuColorTransfer in the PS5 render-target layout, which needs 64 KiB
alignment and does not know GCN tiling. A PS4 title that flips a buffer
before drawing into it, with its buffers 32 KiB aligned, failed with
"null or misaligned address". A GCN-tiled buffer without a resident
image is now read through ReadDisplayBuffer, which decodes the GCN
layout and checks the buffer's own 4 KiB alignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In a GCN T#, word 0 and bits 0-5 of word 1 hold the 256-byte base
address; bits 6-7 of word 1 are MTYPE_L2 (shadPS4's resource.h:
base_address : 38, mtype_l2 : 2). The decode read 40 bits, so a T# with
MTYPE_L2 set addressed bit 46 (0x4002_xxxx_xxxx), which no guest page
backs: "storage texture has no committed guest pages".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GCN MTBUF has the RDNA layout except that word 0 bits 19-25 hold DFMT
(4 bits) and NFMT (3 bits) where RDNA has one 7-bit unified format.
Opcodes 0-7 (tbuffer_load/store_format_x to xyzw) are the same, word 1
bit 21 (RDNA's opcode bit 3) is reserved on GCN, and bit 15 (ADDR64) has
no RDNA counterpart and still throws. The format is mapped with
GcnBufferFormats(), the table the V# decode already uses; a DFMT/NFMT
pair without an RDNA format throws.

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

A PS4 color target with tile mode index 8 (ARRAY_LINEAR_ALIGNED) used
the PS5 linear layout, which pads the pitch to 256 bytes. GCN aligns a
linear-aligned pitch to max(8, 64 / bytes per element) elements, as
AddrLib's SiLib::HwlGetPitchAlignmentLinear does for a surface that is
not interleaved and as this driver's PS4 texture layout already does. A
320-element 16-bit target failed "PS4 color target pitch or slice is not
padded the way its tile mode pads them", and its rows would have been
addressed 384 elements apart. ColorTileMode::GcnLinear has that pitch
alignment and is linear and GCN everywhere else.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VOP1 0x2c (VOP3 0x1ac) has no RDNA opcode. It is decoded as V_RSQ_F32
and tagged VRsqClampF32, whose translation is the V_RSQ_F32 one with an
infinite result replaced by the largest finite float of the same sign,
as GCN defines the instruction (D = 1 / sqrt(S0), clamped to
+-max_float).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SOPK 0x03 to 0x0e (s_cmpk_*) and 0x0f (s_addk_i32) have the same opcodes
and fields on RDNA, which the RDNA decoder already handles, so the GCN
table now maps them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agc_gcn_decode checks the new GCN translations through
DecodeGcnInstruction:
- tbuffer_store_format_xyzw keeps its opcode, offset and flags, and its
  DFMT/NFMT become the unified format of GcnBufferFormats();
- ADDR64 and DFMT INVALID still throw;
- v_rsq_clamp_f32 decodes as VRsqClampF32 in VOP1 and VOP3 while
  v_rsq_f32 keeps its opcode;
- s_addk_i32 and s_cmpk_* decode as their RDNA opcodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
savvaniss and others added 3 commits October 20, 2026 01:20
With IMM 0 and OFFSET 255 a GCN SMRD reads a 32-bit literal that counts
dwords. It becomes the byte offset of the RDNA SMEM encoding with a null
SOFFSET; a literal past the 20-bit positive offset range throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A thin-tiled PS4 volume is stored like a layered surface whose level n
holds max(1, depth >> n) slices, padded to a power of two with POW2_PAD.
It becomes one 3D image of its depth; thick modes still throw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GCN MIMG has no DIM field: the T# type decides how many address VGPRs
the hardware reads. The materializer now takes the dimension from the T#
instead of refusing one that differs from the inferred 2D or 2D array, the
translation reads up to three more address VGPRs, and the emitter counts
the coordinates and gradients for the T#'s dimension. An image selected at
run time offers every T# dimension SPIR-V can express for its accesses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SOPK branch of the GCN decoder never set the literal for
s_setreg_imm32_b32, so the eight-byte instruction was re-encoded as one
word and its decode threw "literal operand word is out of the code span
bounds". The decoder now copies the literal for that opcode.

Co-authored-by: javierUDP <35921725+javierUDP@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Get-fix

Get-fix commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Thanks @savvaniss. boykopovar#6977 is now a draft integration branch, and its own work is split into boykopovar#9429 to boykopovar#9433 (details). The maintainers asked that the branch not land anything without its own review, so could you open this upstream against main, with the shader commits on boykopovar#9430 and the AGC ones on boykopovar#9431, with Depends on? Once it's open, I'll merge it into ps4/limbo-gpu, list it as a member and run Limbo with it. ps4/limbo-gpu now moves to the split branches, so this pull request may show conflicts here. Your 0dd1e4b38 is already in boykopovar#9430 as its own commit, with you and javierUDP as co-authors, so it can drop from here.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@savvaniss

Copy link
Copy Markdown
Author

Moved upstream as two pull requests: the shader half is boykopovar#9889, straight on main now that boykopovar#9430 has merged, and the AGC half is boykopovar#9891 on boykopovar#9431. 0dd1e4b38 was already in boykopovar#9430, so it dropped out. 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.

2 participants