Skip to content

fix(agc): draw without a pixel program when SPI_SHADER_PGM_PS is unset - #469

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Pacuka:fix/agc-null-pixel-program
Oct 5, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Pacuka:fix/agc-null-pixel-program

Conversation

@Pacuka

@Pacuka Pacuka commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What

A depth-only pass (a depth prepass, shadow maps) leaves the pixel program address SPI_SHADER_PGM_LO/HI_PS at 0. Such a pass often never writes SPI_PS_INPUT_ENA/ADDR or SPI_SHADER_COL_FORMAT either. On hardware this is valid: the rasterizer still writes depth. The driver refused these draws twice:

  • DrawRejection returned "missing register at DWORD 0x1b3" (or 0x1b4/0x1c5) for a bank without the pixel input registers.
  • decodeDraw failed with "graphics program does not belong to a registered shader", because address 0 lies below every registered shader.

With this change:

  • RegisterShader also registers a built-in pixel program, a lone s_endpgm with a minimal header. decodeDraw uses it when SPI_SHADER_PGM_LO/HI_PS are both 0. If SPI_SHADER_PGM_RSRC2_PS was never written, it reads no user data for it.
  • The null path only takes draws that write no colour: PixelProgramUnset / NullPixelProgramRejection (shared by DrawRejection and decodeDraw) refuse a PS address of 0 when CB_TARGET_MASK & CB_SHADER_MASK is nonzero, since the Vulkan draw would leave those attachments undefined. Depth export is already refused by DrawRejection.
  • Only for the null program, DecodePixelStageInfo reads an absent SPI_PS_INPUT_ENA/ADDR as PERSP_CENTER_ENA (the smallest input set the hardware accepts) and an absent SPI_SHADER_COL_FORMAT as no colour exports. With a real pixel program an absent register is still a missing register refusal, in DrawRejection and in the decode.
  • DecodeState reads SPI_SHADER_COL_FORMAT only 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/ADDR there when the recompiled program reads no input VGPRs would be a separate PR.

Tested

  • Linux (CachyOS, RX 6650 XT): agc_driver_graphics covers a real pixel program without SPI_PS_INPUT_ENA/ADDR/SPI_SHADER_COL_FORMAT (refused as missing register), PS = 0 with colour writes (refused), and PS = 0 depth-only (accepted, PERSP_CENTER_ENA, no colour exports, DecodeState without COL_FORMAT). I found no harness that runs packets through decodeDraw, so the null-program decision lives in the shared helpers the test drives. Full ctest: 182 of 183 pass; the only failure is agc_driver_pixel_helper_lanes, which also fails on main on this GPU.
  • The Smurfs Dreams (first revision): with 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#295 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L518-519, L778-780
#375 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L518-519, L778-780
#423 core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp L518-519, L778-780
#473 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp L109
#494 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cpp L24-27

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 DrawRejection gave. Could the fallbacks (and the relaxed DrawRejection check) 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 by DrawRejection, so that side is covered. A small test that drives decodeDraw with PGM_LO_PS = 0 would also help, if a harness can be found.

@ThisIsAkill

Copy link
Copy Markdown
Contributor

Test note from PPSA21567 (Astro Bot), on Linux with #426, main 870bdd8 and local changes (not clean main):

  • Before this PR, the title's only remaining skip was missing register at DWORD 0x1b3 on depth-only draws (no color target: a 1536x1536 shadow pass and a 2432x1368 depth prepass).
  • With this PR, that skip is gone, but those draws now fail recompilation: ShaderRecompiler::Recompile: shader info collection failed: interpolation parameter reference is out of range, 1105 reports in a 9-minute run.
  • The reason seems to be that in these draws SPI_SHADER_PGM_LO/HI_PS is 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 absent SPI_PS_INPUT_ENA/ADDR read as PERSP_CENTER_ENA only, 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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 clear missing register refusal 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 own NullPixelCode after the substitution in decodeDraw rather 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 DrawRejection check 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.

@ThisIsAkill

Copy link
Copy Markdown
Contributor

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):

Register Value
SPI_SHADER_PGM_LO_PS / HI_PS (SH 0x008 / 0x009) 0xdf16f800 / 0x00000055 -> address 0x55df16f80000
SPI_SHADER_PGM_RSRC1_PS / RSRC2_PS (SH 0x00a / 0x00b) 0x022c0000 / 0x00000000
CB_COLOR_CONTROL (0x202) 0x00cc0000 (MODE 0 = CB_DISABLE, ROP3 0xcc)
CB_TARGET_MASK (0x08e) 0x00000000
CB_SHADER_MASK (0x08f) 0x00000000
DB_SHADER_CONTROL (0x203) 0x00000000
SPI_SHADER_Z_FORMAT (0x1c4) 0x00000000
SPI_PS_IN_CONTROL (0x1b6) 0x00000000
SPI_SHADER_COL_FORMAT (0x1c5) 0x00000000
SPI_PS_INPUT_ENA / ADDR (0x1b3 / 0x1b4) absent

Two facts from it:

  • The odd address is the register's own content, not the PR's NullPixelCode. This dump predates the PR, and SPI_SHADER_PGM_LO/HI_PS themselves give 0x55df16f80000. The 0x5600a9ce4000 in 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.
  • The draw writes no colour: CB_COLOR_CONTROL MODE is CB_DISABLE, and CB_TARGET_MASK, CB_SHADER_MASK and SPI_SHADER_COL_FORMAT are all 0. So it fits the "no colour writes" condition for the null path, but the PS address is nonzero.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

Pacuka and others added 2 commits October 4, 2026 20:54
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…efuse its color writes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Pacuka
Pacuka force-pushed the fix/agc-null-pixel-program branch from 7fe7c1e to a48a9ea Compare October 4, 2026 18:57
@Pacuka

Pacuka commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks both. Reworked in a48a9ea (rebased on main):

  • The SPI_PS_INPUT_ENA/ADDR and SPI_SHADER_COL_FORMAT fallbacks now apply only to the built-in null program (DecodePixelStageInfo(..., nullProgram)); with a real pixel program an absent register is a missing register refusal again, and DrawRejection keeps that check.
  • The null path requires no colour writes: PixelProgramUnset / NullPixelProgramRejection (shared by DrawRejection and decodeDraw) refuse a PS address of 0 when CB_TARGET_MASK & CB_SHADER_MASK is nonzero ("a draw without a pixel program writes color").
  • DecodeState reads SPI_SHADER_COL_FORMAT only when a target is written, since the format cannot matter otherwise.
  • Tests cover a real program without the registers (refused), PS = 0 with colour writes (refused), and PS = 0 depth-only (accepted, PERSP_CENTER, no exports, no COL_FORMAT needed). I didn't find a harness that runs packets through decodeDraw, 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/ADDR when the recompiled program reads no input VGPRs would be a separate PR.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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 DrawRejection and in DecodePixelStageInfo, 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:

  • DecodeState now reads SPI_SHADER_COL_FORMAT only when a target is written, but DrawRejection still 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 above DrawRejection ("a register a rule needs that is absent is no verdict here") also no longer holds for the three registers it now checks.
  • This conflicts with perf(agc): build compute shaders' front end when they are registered #473 in ShaderRegistry.cpp (both edit RegisterShader), 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_graphics passes, 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.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit 2cce4bd into boykopovar:main Oct 5, 2026
3 checks passed
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
Takes upstream's merged versions of our boykopovar#586 boykopovar#611 boykopovar#612 boykopovar#505 boykopovar#490 boykopovar#619
boykopovar#503 boykopovar#627 boykopovar#628 boykopovar#618 and drops astrobot's local copies, plus gate-batch-3
(boykopovar#469 boykopovar#500 boykopovar#504 boykopovar#509 boykopovar#510 boykopovar#514 boykopovar#525 boykopovar#526 boykopovar#528), round o/p (boykopovar#617 boykopovar#620
boykopovar#621 boykopovar#622 boykopovar#623 boykopovar#624 boykopovar#501 boykopovar#508 boykopovar#629 boykopovar#630 boykopovar#631).

Conflicts:
- SpirvAnalysis.hpp/.cpp, SpirvBufferAccess.cpp: upstream's boykopovar#586/boykopovar#612.
  The 64-bit LDS atomics keep the full array (f27d6e5 no longer needed).
- SpirvMemoryInstructions.cpp: upstream's constant slot plus offset;
  astrobot's split-wave append/consume kept.
- GuestTextureResource.cpp, TextureTiling.cpp and their tests: upstream's
  boykopovar#490/boykopovar#503 (astrobot had no other change there).
- MaskedSelect.cpp test, ShaderMemory.cpp LDS test: upstream's.
- State.cpp: upstream's boykopovar#505 export count and boykopovar#469 null pixel program;
  astrobot's depth export rejection and depth target model kept.
- Pipeline.cpp: upstream's pipeline key; astrobot's depth attachment and
  blend check (a trailing unused attachment stays valid, as
  colorGapPipelineTests expects).
- Draw.cpp, Recorder.cpp, ShaderResources.cpp: astrobot's (renderPassKey
  with depth, moved sample functions, residency maintenance), which
  already hold the merged boykopovar#505/boykopovar#628/boykopovar#490 changes.
- ShaderInputState.cpp: both register sets.
- State.hpp: the duplicate exportIndex member from the auto-merge removed.
- CMakeLists.txt: astrobot's test list (a superset of upstream's).
- tests/Graphics.cpp: upstream's CompactedExportTests replaces astrobot's
  inline copy; tests/Recorder.cpp: upstream's viewPastLastMipTests added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants