Skip to content

feat: run PS4 games on the AGC driver — Limbo (CUSA01664) in game (integration branch) - #62

Draft
Thimo188 wants to merge 39 commits into
mainfrom
upstream-pr/6977
Draft

Thimo188 wants to merge 39 commits into
mainfrom
upstream-pr/6977

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#6977, originally opened by Get-fix.

Source commit: 45625370e478b2afc4732ea77b72f9feadb8f9ed. 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

Draft integration branch: PS4 titles on the AGC driver, with Limbo (CUSA01664) in game. This branch is main with the pull requests below merged, so they can be tested together. It isn't meant to merge itself: the members merge one by one, each with its own review, and the branch is rebased down as they land. Details, how to run and the bring-up story are in boykopovar#6978.

Part Member What Depends on
A boykopovar#9429 relinker: TLS relocations against the module's own section symbol merged
B boykopovar#9430 shader: PS4 (GCN) shaders re-encoded to RDNA none
C boykopovar#9431 AGC: PS4 targets, tiling and pattern fills boykopovar#9430
D boykopovar#9432 libSceGnmDriver and VideoOut boykopovar#9431
E boykopovar#9433 PS4 NpTrophy, save data v1, NpWebApi and Limbo's other imports merged
member boykopovar#9225 (YossiYad) sceNpSetContentRestriction, which Limbo calls at start merged

With A, E and boykopovar#9225 in main, the branch is now main 7e2ba73 plus boykopovar#9430 to boykopovar#9432, taken in with a merge commit so the pull requests other contributors opened against it (Get-fix#1 to boykopovar#21) keep their base. Those join the table once each is open upstream with its own review; ntamas94's boykopovar#9671 to boykopovar#9676 already are, on top of boykopovar#9430 to boykopovar#9432.

Tested

On main 7e2ba73 with boykopovar#9430 to boykopovar#9432, Windows 11, WinLibs GCC 15.2, NVIDIA GeForce RTX 5060 Ti (driver 610.88):

  • The full suite of 1,893 tests: 1,886 pass and 4 skip, the same 4 that skip on main. The 3 that fail also fail on main 7e2ba73 on this machine: agc_driver_sample_order and its --grid-reference and --recipe-depth-locations cases.
  • Validation layer, main against the branch with the same focused tests: the same 50 VUID- errors in the same 8 existing PS5 tests, none added (details in feat(libSceGnmDriver): build PS4 command buffers and submit them boykopovar/AnyPS5#9432).
  • Limbo (CUSA01664), converted with this build's relinker and its two bundled modules: a 60 s scripted run from start into gameplay with no errors and no not-implemented calls, on 22 Oct with the GPU otherwise idle.

Checklist

🤖 Generated with Claude Code

Get-fix and others added 30 commits October 15, 2026 20:59
PS4 programs load system libraries with sceKernelLoadStartModule and
their console path. The OpenOrbis piglet sample loads
/<sandbox word>/common/lib/libScePigletv2VSH.sprx and
libScePrecompiledShaders.sprx, the sandboxed form of
/system/common/lib/ that sceKernelGetFsSandboxRandomWord names. The path
was opened as a guest file and the load failed with ENOENT.

A path in /system/common/lib/ or in the sandboxed /<word>/common/lib/
whose file name ends in .sprx now loads the host libs/<name>.prx, as
libSceSysmodule does for module IDs. Names with a directory part are
not mapped, so such a path cannot leave libs/.
PS4 titles ship sce_sys/param.sfo instead of param.json. When param.json
is absent, the application metadata now reads the title, title ID,
download data size and user defined parameters from param.sfo, and
/data and /download0 are mounted for it as for param.json. param.json
is still preferred when both files exist.
PS4 titles built with Sony's toolchain place a switch statement's jump
table in the code segment, after the last instruction of the function
that indexes it and inside the function's unwind range:

    lea    rcx, [rip + table]
    movsxd rax, dword ptr [rcx + rax*4]
    add    rax, rcx
    jmp    rax

Code analysis decodes each function range from start to end, so it read
the table as instructions; the syscall scan and the call-site resolver
sweep the whole segment and lost their instruction boundaries there.
Limbo (CUSA01664) stopped at "Unsupported Windows guest TLS instruction
(bytes: 65 f9)" and Bloodborne (CUSA00900) at "Instruction exceeds 15
bytes".

FindInlineJumpTables decodes a function range, follows the table
address of each RIP-relative lea through 64-bit register moves, and
records the address a movsxd with scale 4 indexes when it lies later
in the same function. When decoding reaches the first such address and
every dword from there to the end of the function is an offset, from
the nearest table before it, to code before the first table, the rest
of the function is taken as tables. Anything else is decoded as before.
Code analysis stops each function there and keeps the control-flow
pass out of the tables; the pipeline fills them with nops in the copies
the syscall scan and the call-site resolver read.
# Conflicts:
#	core/relinker/relinker/src/guest/GuestImageReader.cpp
# Conflicts:
#	docs/dev/debt/libkernel.md
# Conflicts:
#	docs/dev/debt/relinker.md
# Conflicts:
#	docs/dev/debt/libkernel.md
…ction symbol

Limbo's bundled libSceFios2.prx (CUSA01664) has DTPMOD64 relocations
against a local section symbol of value 0. As for a TLS relocation
without a symbol, the module and offset are the module's own TLS block,
so such a relocation is passed on without its symbol; a section symbol
with a value, or a module without PT_TLS, still fails.
Each GCN instruction is re-encoded to its RDNA form and decoded by the
existing RDNA decoder, so the PS4 path shares the recompiler. Covers the
legacy VS stage (program at the VS slot, user SGPRs from s0, vertex and
instance index in v0-v3), fetch shaders linked as user-data calls, MIMG
(image_sample and friends), PS4 buffer descriptors (GCN DATA_FORMAT /
NUM_FORMAT, 44-bit base) and T# image descriptors (GCN tiling in word 7).
The GCN switch is keyed into the shader disk cache. PS5 behaviour is
unchanged: every PS4-only rule is gated on GcnGuestShaders().
PS4 color and depth targets, buffer and image descriptors and the PS4
tile modes (1D/2D thin and display, depth with tile split, PRT, linear
general) on the AGC executor, with a GPU detiler for every mode. Textures
sampled over the padded corner of a render target are GPU block copies,
and the PS4 SDK pattern-fill compute kernel runs as a GPU fill (render
targets and HTILE are cleared without a CPU drain), so Limbo holds 60 fps.
Tests cover the tiling equations against addrlib formulas, the GPU
detiler for every mode and element size, descriptors and fills.
Real sceGnm shader, state and draw packet writers, submit and
submit-and-flip into the AGC executor, PS4 sync packets lowered to their
PS5 forms, constant engine buffers merged into the draw buffer and the
PS4 graphics EOP event. VideoOut accepts the PS4 10-bit display format.
NpTrophy reads the trophy count and icons from the title's trophy
package (names are encrypted and stay not implemented), PS4 v1 save data
calls wrap the native v2/v3 ones, NpWebApi library contexts, handles and
push event filters work offline (service filters fail without a
signed-in user), sceNpSetContentRestriction validates and stores.
libSceAjm is built from the libSceAjm.native sources for PS4 titles, and
Limbo's remaining imports are exported as not implemented.
…gain

Running Limbo's two-dword clears of its 64-bit target as buffer fills
made its gameplay advance about half as far per frame as with the
kernel (same input, same save), although the stored values are equal.
Only single-dword patterns are filled again until the cause is known.
Each GCN instruction is re-encoded to its RDNA form and decoded by the
existing RDNA decoder, so the PS4 path shares the recompiler. Covers the
legacy VS stage (program at the VS slot, user SGPRs from s0, vertex and
instance index in v0-v3), fetch shaders linked as user-data calls, MIMG
(image_sample and friends), PS4 buffer descriptors (GCN DATA_FORMAT /
NUM_FORMAT, 44-bit base) and T# image descriptors (GCN tiling in word 7).
The GCN switch is keyed into the shader disk cache. PS5 behaviour is
unchanged: every PS4-only rule is gated on GcnGuestShaders().
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; the new
agc_gcn_decode test decodes the reported stream.

Co-authored-by: javierUDP <35921725+javierUDP@users.noreply.github.com>
Co-authored-by: Savvanis Spyros <savvaniss@yahoo.gr>
PS4 color and depth targets, PS4 graphics EOP events, and the PS4 tile
modes (1D/2D thin and display, depth with tile split, PRT, linear
general) on the AGC executor, with a GPU detiler for every mode.
Textures sampled over the padded corner of a render target are GPU block
copies, and the PS4 SDK pattern-fill compute kernel runs as a GPU fill
when it repeats one dword, so render targets and HTILE are cleared
without a CPU drain. Two-dword patterns keep running the kernel: as
fills, Limbo's clears of its 64-bit target made its gameplay advance
about half as far per frame.
Tests cover the tiling equations against addrlib formulas, the GPU
detiler for every mode and element size, and the fill ranges.
Real sceGnm shader, state and draw packet writers, submit and
submit-and-flip into the AGC executor, PS4 sync packets lowered to their
PS5 forms, constant engine buffers merged into the draw buffer and the
PS4 graphics EOP event. VideoOut keeps the pitch of tiled PS4 display
buffers and accepts the PS4 10-bit display format. The four tool-state
queries (submissions allowed, user PA, GPU capture, Razor) are silent
stubs listed in the debt file.
…imports

NpTrophy reads the trophy count and icons from the title's trophy
package (names are encrypted and stay not implemented), PS4 v1 save data
calls wrap the native v2/v3 ones, NpWebApi library contexts, handles and
push event filters work offline (service filters fail without a
signed-in user), sceNpSetContentRestriction validates and stores.
libSceAjm is built from the libSceAjm.native sources for PS4 titles.
Limbo's (CUSA01664) remaining PS4 imports, including the synchronous PS4
TUS calls and the Facebook dialog calls next to the existing libraries,
are exported as not implemented.
…cb540

The branch is now main cecb540 with ps4/relinker-own-tls, ps4/gnm-driver (which carries ps4/gcn-shaders and ps4/agc-gcn) and ps4/limbo-libs merged. The pull requests it carried before have merged into main; the old history is kept as the first parent so pull requests against this branch keep their base.
sceNpSetContentRestriction, which Limbo calls at start; ps4/limbo-libs no longer implements it.
…ntegration branch

boykopovar#9429, boykopovar#9433 and boykopovar#9225 are merged into main, so the branch is now main 7e2ba73 with boykopovar#9430 to boykopovar#9432. The merge keeps the earlier history as a parent so the pull requests opened against this branch keep their base.
@Thimo188 Thimo188 closed this Dec 2, 2026
@Thimo188 Thimo188 reopened this Dec 2, 2026
@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line already in main Merging would not change main; never closed automatically labels Dec 2, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Merging this pull request would not change main: GitHub's test merge of it into main at 82216ca has the same files as that commit, and no file it touches has changed in main since, including its mode and type. Its changes look merged already, possibly through another pull request. Nothing is closed automatically. Close it if it is superseded, or push what is still missing; the already in main label goes away once merging would change main again.

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

Labels

already in main Merging would not change main; never closed automatically unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants