fix(agc): fuse geometry shader halves into one self-contained program #124
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/124"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T00:32:53Z.
What
Rebased onto current
main. This PR now replaces only the geometry path ofsceAgcUnknownFuseShaderHalves(fd5Bp5tGTgo) andsceAgcUnknownGetFusedShaderSize(dolOmWH+huQ). Hull halves keep the register-level fusion fromfd4700b9unchanged, and the half-type andVGT_SHADER_STAGES_ENchecks stay shared.Why the geometry path changes.
fd4700b9fuses geometry halves at the register level: the back half's registers withSPI_SHADER_PGM_LO_ESpointing at the front half's code. The driver then compiles that front half as the draw's whole program (type 4,Stage::Mesh) and skips the back (Role::GeometryBack). Nothing links the two halves (LinkedProgramis only serialized, andDecodeRdnaFrontProgramhas no caller). The front half ends ins_setpc_b64 s[6:7]with nos_endpgm, so decoding runs on into thes_code_endpadding and the program trailer. In PPSA21564 the geometry-shader draws are skipped:Hull halves work with the register-level fusion, since the tessellation path compiles the local and hull programs separately, so they are left as they are.
Geometry halves are fused into one self-contained
Gsprogram:s_setpc_b64 s[6:7](its length comes from the program trailer), thens_noppadding to 256 bytes, then the whole back half. The front falls through into the back.PGM_LO/HI_GSpoints at the copied back code, and the ES program address at the fused code.s[0:1].Shaderpoints to, including a copy of the header, is written into the caller's memory after the code, and the header is registered with the driver as a self-contained shader. Titles pass memory without honouring the reported alignment (found by @Pacuka with The Smurfs Dreams), so the program is placed at the first 256-byte boundary inside it, andGetFusedShaderSizereturns the total size plus 255 bytes of padding, with log2 alignment 8.SizeAlignmoves intoShaderFusion.hppunchanged, so the test can call both functions.s_setpc_b64 s[6:7], a front half needing RSRC2 state the back half doesn't enable, geometry halves without fused memory, missing tables, and a program address above 48 bits. Mismatched half types and stage bits return0x8a6c0008as onmain.s[0:1]of aGsprogram is now loaded from its user-data address registers whenever they are set. Before, this only happened forGsFrontprograms. The back half of a fused program reads its user data through them. A program without those registers keeps zero there (SamG-Coder's fix, 8345fbc1).Tested
agc_shader_fusion_tests, registered in ctest:s_nopfall-through, both patched program addresses, the RSRC1/RSRC2 merge, the SH and context register merge, semantics, specials, scratch size and user data copied into the fused memory, the self-contained header, and nothing written past the reported size;main(checksums from the front, RSRC merge,PGM_LO/HI_LSat the front code, back registers untouched) andmain's size query;With
main'sShaderFusion.cppthe geometry cases fail ("fused shaders are not 256-byte aligned").ctest: 80/80 pass.agc_driver_graphics_tests,agc_driver_mesh_tests,agc_driver_testsandagc_driver_recorder_testspass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-09-29T19:48:29Z.
Tested this locally with The Smurfs Dreams (UE, Linux). The game calls
sceAgcUnknownFuseShaderHalveswith scratch memory that is not 256-byte aligned (e.g.0x7f7fdf3ee5a0), whateversceAgcUnknownGetFusedShaderSizereports as alignment (the address stayed the same withm_align= 8 and = 256), so it throwsfused shader memory is not a valid program address.What worked here: report
totalBytes + FusedCodeAlignment - 1as the size and place the fused program atAlignUp(scratch, FusedCodeAlignment)inside the scratch memory instead of requiring the scratch itself to be aligned. With that the fused GS draws run.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T19:52:52Z.
Thanks for testing with The Smurfs Dreams. You're right: the title doesn't honour the reported alignment, so the library has to align inside the scratch memory. I'll report
totalBytes + FusedCodeAlignment - 1as the size and place the fused program (and its header) atAlignUp(scratch, FusedCodeAlignment), keeping the 48-bit address check, plus a test that fuses into deliberately misaligned scratch.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T19:55:12Z.
Pushed: the fused program is now placed at the first 256-byte boundary inside the scratch memory, and the size query includes 255 bytes of padding. The test fuses into aligned and misaligned scratch (0xa0 and 4 bytes off) and fails without the change. Rebased on current main as well. Could you check it with The Smurfs Dreams when you get a chance?
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-09-30T16:12:45Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/Execution/src/Driver.cppL4168-4178core/libs/prx/libSceAgcDriver/Execution/src/Driver.cppL4165-4179Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-30T19:27:38Z.
Some data on how this compares with the fusion that landed on main (
fd4700b9), from PPSA21564.With main's register-level fusion, the geometry-shader draws in PPSA21564 are skipped:
What happens: the fused registers keep the back half's state with
SPI_SHADER_PGM_LO_ESpointing at the front half's code. The driver compiles that front half as the draw's whole program (type 4, Stage::Mesh) and skips the back (Role::GeometryBack). Nothing links the two halves (LinkedProgramis only serialized, andDecodeRdnaFrontProgramhas no caller). The front half ends ins_setpc_b64 s[6:7]with nos_endpgm, so decoding runs on into thes_code_endpadding and the program trailer, which is where opcode 31 and operand 115 come from.With this PR's approach for geometry halves (the front up to its
s_setpc_b64,s_noppadding to 256 bytes, then the back, as one self-contained program), those errors are gone and the title scene and the world map render as before. That is across three consecutive runs of our visual regression check on current main plus this change. Hull halves are fine with main's register-level fusion, so I'd keep that for them.I'll rebase this PR onto current main so it only replaces the geometry path and leaves the hull path as it is on main.