fix(agc): draw without a pixel program when SPI_SHADER_PGM_PS is unset #469
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/469"
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 Pacuka on 2026-10-03T16:19:53Z.
What
A depth-only pass (a depth prepass, shadow maps) leaves the pixel program address
SPI_SHADER_PGM_LO/HI_PSat 0. Such a pass often never writesSPI_PS_INPUT_ENA/ADDRorSPI_SHADER_COL_FORMATeither. On hardware this is valid: the rasterizer still writes depth. The driver refused these draws twice:DrawRejectionreturned "missing register at DWORD 0x1b3" (or 0x1b4/0x1c5) for a bank without the pixel input registers.decodeDrawfailed with "graphics program does not belong to a registered shader", because address 0 lies below every registered shader.With this change:
RegisterShaderalso registers a built-in pixel program, a lones_endpgmwith a minimal header.decodeDrawuses it whenSPI_SHADER_PGM_LO/HI_PSare both 0. IfSPI_SHADER_PGM_RSRC2_PSwas never written, it reads no user data for it.PixelProgramUnset/NullPixelProgramRejection(shared byDrawRejectionanddecodeDraw) refuse a PS address of 0 whenCB_TARGET_MASK & CB_SHADER_MASKis nonzero, since the Vulkan draw would leave those attachments undefined. Depth export is already refused byDrawRejection.DecodePixelStageInforeads an absentSPI_PS_INPUT_ENA/ADDRasPERSP_CENTER_ENA(the smallest input set the hardware accepts) and an absentSPI_SHADER_COL_FORMATas no colour exports. With a real pixel program an absent register is still amissing registerrefusal, inDrawRejectionand in the decode.DecodeStatereadsSPI_SHADER_COL_FORMATonly when a target is written; the format cannot matter otherwise.In The Smurfs Dreams (UE4) about 7,000 draws per 100 s were refused this way, plus 4,400 for the missing registers. These are the depth passes of the title screen and the levels.
Draws that keep a real pixel program which reads no inputs and exports nothing (the Astro Bot case in the comments) are not covered; accepting absent
SPI_PS_INPUT_ENA/ADDRthere when the recompiled program reads no input VGPRs would be a separate PR.Tested
agc_driver_graphicscovers a real pixel program withoutSPI_PS_INPUT_ENA/ADDR/SPI_SHADER_COL_FORMAT(refused asmissing register), PS = 0 with colour writes (refused), and PS = 0 depth-only (accepted,PERSP_CENTER_ENA, no colour exports,DecodeStatewithoutCOL_FORMAT). I found no harness that runs packets throughdecodeDraw, so the null-program decision lives in the shared helpers the test drives. Fullctest: 182 of 183 pass; the only failure isagc_driver_pixel_helper_lanes, which also fails onmainon this GPU.APS5_TRACE_SKIPS=1, both refusals were gone over 110 s from boot through the menus into a level load, with no new failures and no GPU faults. The rework (null-program-only fallbacks, no colour writes) is covered by the unit tests above.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 repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T19:51:38Z.
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/Graphics/src/State.cppL518-519, L778-780core/libs/prx/libSceAgcDriver/Graphics/src/State.cppL518-519, L778-780core/libs/prx/libSceAgcDriver/Graphics/src/State.cppL518-519, L778-780core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppL109core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppL24-27Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:45:59Z.
Thanks, the null program for depth-only passes makes sense to me. Two things I'd change. First, the register fallbacks now apply to every draw: with a real pixel shader, a bank without SPI_PS_INPUT_ENA/ADDR or SPI_SHADER_COL_FORMAT now gets PERSP_CENTER and no exports invented for it, instead of the "missing register" refusal that
DrawRejectiongave. Could the fallbacks (and the relaxedDrawRejectioncheck) apply only when the program is the built-in null one? Second, the null program is taken whenever the PS address is 0, even if the draw has colour writes enabled (CB_TARGET_MASK & CB_SHADER_MASK). In that case the Vulkan draw leaves the colour attachments undefined, since the fragment shader never writes them. Requiring no colour writes for the null path (and refusing otherwise) keeps it exact and still covers depth prepasses and shadow maps; depth export is already refused byDrawRejection, so that side is covered. A small test that drivesdecodeDrawwith PGM_LO_PS = 0 would also help, if a harness can be found.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-04T07:02:52Z.
Test note from PPSA21567 (Astro Bot), on Linux with #426, main
870bdd81and local changes (not clean main):missing register at DWORD 0x1b3on depth-only draws (no color target: a 1536x1536 shadow pass and a 2432x1368 depth prepass).ShaderRecompiler::Recompile: shader info collection failed: interpolation parameter reference is out of range, 1105 reports in a 9-minute run.SPI_SHADER_PGM_LO/HI_PSis not 0. A local trace shows pixel program addresses 0x500893a00 (a real registered program) and 0x5600a9ce4000 (which looks like a stale or unrelated value). So the null-program path is not taken: the draw keeps a real pixel program, and the absentSPI_PS_INPUT_ENA/ADDRread asPERSP_CENTER_ENAonly, which that program's interpolation does not fit.I have not checked how the hardware decides that these draws run without a pixel shader while the PS address register still holds a value (for example a disabled PS stage in another register). Happy to dump the registers of one of these draws if that helps.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:39:56Z.
Thanks @ThisIsAkill for testing it. Your run shows the first point from my earlier comment in practice: those draws keep a real pixel program, the absent SPI_PS_INPUT_ENA/ADDR turn into PERSP_CENTER only, and the recompiler then refuses the program (
interpolation parameter reference is out of range). So the clearmissing registerrefusal becomes a recompile failure on every such draw, and a program that happened to read only PERSP_CENTER would draw with invented inputs instead of failing. One thing about the trace: 0x5600a9ce4000 is not a guest address, so it may be the PR's ownNullPixelCodeafter the substitution indecodeDrawrather than a stale register value. If so, the draws with PS = 0 are handled and only the ones at 0x500893a00 fail.@Pacuka, both points from my earlier comment still apply to the current head: the fallbacks and the relaxed
DrawRejectioncheck should only apply to the built-in null program, and the null path should require no colour writes (CB_TARGET_MASK & CB_SHADER_MASK). The failing draws in that note have a nonzero PGM_LO_PS, so this PR can't cover them as it stands; running them without SPI_PS_INPUT_ENA/ADDR would need evidence of what the hardware does with that pixel program. A register dump of one of those draws, as ThisIsAkill offered (CB_COLOR_CONTROL, CB_TARGET_MASK, CB_SHADER_MASK, DB_SHADER_CONTROL, SPI_SHADER_Z_FORMAT, SPI_PS_IN_CONTROL and SPI_SHADER_PGM_LO/HI_PS), would be a good start.Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-04T09:02:18Z.
Here is the register dump, from a run before this PR was applied (the driver's dump of a draw it refused with
missing register at DWORD 0x1b3, PPSA21567):SPI_SHADER_PGM_LO_PS/HI_PS(SH 0x008 / 0x009)0xdf16f800/0x00000055-> address0x55df16f80000SPI_SHADER_PGM_RSRC1_PS/RSRC2_PS(SH 0x00a / 0x00b)0x022c0000/0x00000000CB_COLOR_CONTROL(0x202)0x00cc0000(MODE 0 =CB_DISABLE, ROP3 0xcc)CB_TARGET_MASK(0x08e)0x00000000CB_SHADER_MASK(0x08f)0x00000000DB_SHADER_CONTROL(0x203)0x00000000SPI_SHADER_Z_FORMAT(0x1c4)0x00000000SPI_PS_IN_CONTROL(0x1b6)0x00000000SPI_SHADER_COL_FORMAT(0x1c5)0x00000000SPI_PS_INPUT_ENA/ADDR(0x1b3 / 0x1b4)Two facts from it:
NullPixelCode. This dump predates the PR, andSPI_SHADER_PGM_LO/HI_PSthemselves give0x55df16f80000. The0x5600a9ce4000in my earlier note is the same kind of value from another run (ASLR). In this relinked native process,0x55...addresses lie in the executable's own image or heap, not in registered guest shader memory. I haven't checked what is at that address.CB_COLOR_CONTROLMODE isCB_DISABLE, andCB_TARGET_MASK,CB_SHADER_MASKandSPI_SHADER_COL_FORMATare all 0. So it fits the "no colour writes" condition for the null path, but the PS address is nonzero.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:52:27Z.
Thanks @ThisIsAkill, that settles it, and I was wrong about the address: it's the register's own value, so these draws do have a pixel program. It reads no user data (RSRC2_PS is 0) and exports nothing (CB_DISABLE, and CB_TARGET_MASK, CB_SHADER_MASK, SPI_SHADER_COL_FORMAT and SPI_SHADER_Z_FORMAT are all 0). That fits the no-colour-writes condition, but this PR's null path only applies when PGM_LO_PS is 0, so it never covers these draws, and the register fallbacks then apply to a real program, which was my first point.
@Pacuka, both points from my earlier comment still apply to the current head. For draws like these, one way that stays exact: accept absent SPI_PS_INPUT_ENA/ADDR only when the recompiled program reads none of the pixel input VGPRs before writing them, since the input layout can't change its result then, and keep refusing otherwise. Swapping such a program for the null one wouldn't be exact in general, because a program that kills pixels (alpha-tested shadows) changes the depth result. A disassembly of the first instructions at that PS address would show whether these draws read any inputs.
Imported from boykopovar/AnyPS5. Originally posted by Pacuka on 2026-10-04T18:57:52Z.
Thanks both. Reworked in
a48a9eab(rebased on main):SPI_PS_INPUT_ENA/ADDRandSPI_SHADER_COL_FORMATfallbacks now apply only to the built-in null program (DecodePixelStageInfo(..., nullProgram)); with a real pixel program an absent register is amissing registerrefusal again, andDrawRejectionkeeps that check.PixelProgramUnset/NullPixelProgramRejection(shared byDrawRejectionanddecodeDraw) refuse a PS address of 0 whenCB_TARGET_MASK & CB_SHADER_MASKis nonzero ("a draw without a pixel program writes color").DecodeStatereadsSPI_SHADER_COL_FORMATonly when a target is written, since the format cannot matter otherwise.COL_FORMATneeded). I didn't find a harness that runs packets throughdecodeDraw, so the decision lives in the shared helpers the test drives.The Astro Bot draws (nonzero PS that reads no inputs and exports nothing) are out of scope here; accepting absent
SPI_PS_INPUT_ENA/ADDRwhen the recompiled program reads no input VGPRs would be a separate PR.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:06Z.
Thanks @Pacuka, this addresses my first point. With a real pixel program an absent SPI_PS_INPUT_ENA/ADDR or SPI_SHADER_COL_FORMAT is refused again, both in
DrawRejectionand inDecodePixelStageInfo, and the PERSP_CENTER default is now limited to the built-in null program. The null path also refuses colour writes (CB_TARGET_MASK & CB_SHADER_MASK), which was the other condition for swapping in a program that exports nothing. The tests cover the three cases.Two small notes, neither blocking:
DecodeStatenow reads SPI_SHADER_COL_FORMAT only when a target is written, butDrawRejectionstill refuses a real program whose COL_FORMAT is absent even when no target is written. Both refuse safely, so this only matters if you want the two to agree; the comment aboveDrawRejection("a register a rule needs that is absent is no verdict here") also no longer holds for the three registers it now checks.ShaderRegistry.cpp(both editRegisterShader), so whichever lands second needs a small rebase.Merged with current main (and the other open PRs I'm checking today) it builds, and
agc_driver_graphicspasses, including your three new cases.The draws @ThisIsAkill dumped stay refused as on main (they have a real program), but depth-only draws with no pixel program now run, so I'll run it through my PPSA21564 check before merging.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T08:31:14Z.
Gated on PPSA21564: no visual or FPS change.