Skip to content

fix(agc): leave a stage the title's pipeline ABI cannot prepare to its first use - #6366

Merged
adriadam10 merged 8 commits into
boykopovar:mainfrom
EagleBearerYS:fix/agc-defer-unpreparable-abi-stages-v3
Oct 19, 2026
Merged

adriadam10 merged 8 commits into
boykopovar:mainfrom
EagleBearerYS:fix/agc-defer-unpreparable-abi-stages-v3

Conversation

@EagleBearerYS

@EagleBearerYS EagleBearerYS commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What

When a title creates a pipeline, sceAgcDriverResolveShaderAbi, sceAgcDriverResolveGraphicsStagesAbi and sceAgcDriverResolveGraphicsAbi prepare its stages. If the recompiler could not prepare a stage there, the call threw and the title stopped at pipeline creation. Two cases on main:

  • Resident Evil Village stops this way on a pixel shader whose T# pointer is a phi of user data and a ballot (GetImageResource dword 0 is not a valid runtime value).
  • A compute shader that calls user-data pointers stopped the same way, although its dispatch links the callees.

Such a stage is now left to its first use, like a stage registration cannot prepare:

  • ResolveShaderAbi and PrepareGraphicsStages catch the failure inside their own preparation transaction. The ShaderPreparationScope that libSceAgc opens around the call (sceAgcLinkShaders, sceAgcCreateInterpolantMapping, sceAgcCreatePrimState) still commits. A catch at the entry point would leave that scope aborted.
  • The shader is logged once ("could not be prepared when the title created its pipeline (…); preparing it when it is used") and marked deferred. The ABI key is recorded, so a repeated call prepares nothing.
  • ResolvePreparedGraphics skips the rectangles of a deferred stage that has no artifact yet. This also lets sceAgcDriverResolveGraphicsAbi through for a stage deferred at registration, which threw "rectangle ABI has missing stage artifacts".

The draw or dispatch that uses the stage prepares it as before, and fails there if it cannot. Resident Evil Village's pixel shader would still fail at a draw: the resource plan depends only on the code and the stage interface, so the draw builds the same plan.

Driver failures and ProcessShutdown still propagate. docs/dev/ARCHITECTURE.md gets a line.

A pipeline ABI whose state does not decode also leaves its stages to their first use (6bd8647). On our own test tree, which carries this PR and other open PRs (not main), Resident Evil Village (PPSA01556) aborted 11 minutes into its save load, before control, with AGC graphics: VGT_SHADER_STAGES_EN=0x2030: unsupported geometry input or output assembly. sceAgcDriverResolveGraphicsStagesAbi decodes the stage routing and programs from the stages' registered state and the call's context and primitive registers before it prepares anything, and DecodeShaderStages refused that combined state outside the preparation this PR already guards. A refused decode now defers every stage of the call like a stage whose preparation fails: each is logged once with the decode's reason and prepared by the draw that uses it, which decodes its own state; a repeated call prepares and logs nothing. With this commit added (and one fix elsewhere that doesn't touch this path), the tree loaded that save to control with no driver failure and held control for about 8 minutes (Windows 11, RTX 3070 Laptop GPU, driver 617.42). That run prepares shaders lazily (#5872's APS5_LAZY_SHADER_PREPARE=1), which marks every stage deferred at registration, so the deferral itself logs nothing there.

A completeness review of every path of the pipeline call found three more cases that could end a title before the stage's first use. No title has hit them yet.

A stage whose registration preparation failed is left to its first use too (19a3e07). The scope libSceAgc opens around a pipeline call (sceAgcLinkShaders, sceAgcCreatePrimState, sceAgcCreateInterpolantMapping) no longer rethrows a failure the background registration preparation stored. The ABI calls log such a stage once with the stored reason and prepare the call's other stages, and the stage's first draw or dispatch rethrows the same exception. This replaces this PR's earlier choice that stored registration failures propagate at the pipeline call: that call cannot know whether the title will use the pipeline, and the abort now happens where the stage is used, with the same message.

Vertex inputs and rect-list pairs (502085c, e986ee0). A stage whose vertex inputs the decode refuses at the pipeline call (NGG vertex shaders that use their workgroup, and mesh, hull and domain stages, which registration does not decode) is left to its first draw, which decodes the same header. A rect-list pair the pipeline call cannot build (no pixel shader, a pixel with no artifact, or one the rect-list builder refuses) is left to its draw, and a draw now builds only its own fragment's pair, so another fragment's refusal no longer fails an unrelated draw. Rect-list pairs are still built per pixel shader, not per variant: when a pixel's passthrough pair is refused, the rect-list draw of its normal variant fails with that reason. The pipeline call's abort hid that case before.

Overlap: #5872 (shader preparation on first use) is on main now, and this branch merges main with it. The prepared-shader modes are the union of both lists. With #5872's lazy mode on, every snapshot starts deferred, so this line doesn't print for such a stage, and the draw reports the failure as before. #5872's LazyRegistration check now requires that the pipeline ABI of a lazily registered shader it cannot prepare leaves the stage deferred with no prepared entry, where it used to throw; its dispatch and shutdown failure checks are unchanged. The merge also makes the tests' stderr capture flush main's async driver log before reading it, and has the undecodable-state check match the decode's VGT_SHADER_STAGES_EN=0x2030: reason, which main's geometry subgroup check now gives first.

#6612 (tessellation followed by an NGG geometry stage) and #6639 (point lists with their point size) change the lines of PrepareGraphicsStages that 19a3e07 and 502085c reorder, where the push offset now comes first and the vertex-input decode sits in a try. Whichever merges second keeps that order and puts #6612's wave = Graphics::StageWaveSize(...) and #6639's Graphics::ApplyPointSize(decoded.state, *vertex) into the if (vertex) block after the try.

Related: #5884 (AnthonyClemens) draws line-strip output of NGG geometry programs as mesh lines, one of the states VGT_SHADER_STAGES_EN=0x2030: unsupported geometry input or output assembly refuses, and merges cleanly with this PR. With it, such stages decode at the pipeline call and are prepared there instead of at first use. JJenkx's Cocoon (PPSA08766) report (#6651) passes that refusal at startup with #5884.

Tested

Resident Evil Village (PPSA01556), Windows 11, NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), on main 6ea62f9, before and with this branch's two commits (the same commits; the head is only rebased onto 71bd287). Both arms ran with the same env, APS5_NO_GPL=1, which skips Vulkan graphics pipeline libraries and saves about 2.5 GB of host memory during Resident Evil Village's pipeline creation on this 16 GB machine. The title was relinked with main's relinker.

  • Main:
    • Before: shader 0x207e84c500 stage 5: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: …, then FATAL: abort() at pipeline creation, 5 min 48 s in.
    • With this branch: Shader 0x207e85cf00 could not be prepared when the title created its pipeline (shader 0x207e85cf00 stage 5: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; …); preparing it when it is used, once. Resident Evil Village then runs on to main's next stop at the intro video, mprotect of uncommitted memory outside the guest arena (fix(libkernel): commit a reserved host stack before protecting it #5703 fixes it). No other runtime-value line.
  • Main with fix(libkernel): commit a reserved host stack before protecting it #5703 (open, 187e5fc) in both arms:
    • Before: the same FATAL, 28 s in.
    • With this branch: the deferral line once, then through the start-up dialogs and the intro video, about 7.7 min, with no other runtime-value line and no access violation. The deferred shader is not drawn in that time. It stops before the title on an unrelated check, the depth target's sample count differs from the rasterizer's; a separate fix for that is coming.
  • On our own test trees, which also carry other open PRs (not main), an earlier local form of this deferral (every stage of an ABI call left to its first use) took Resident Evil Village to its title and first scene with no runtime-value failure.

Linux, GitHub runner with Mesa lavapipe, head 695ec6c on main 71bd287:

  • the four new tests fail with the fix's two source files reverted to main's, and pass 5 runs in a row with them;
  • ^agc: 601 tests, 0 failures.
  • With the same two commits on a08de68: the fix commit alone passed the 21 prepared-shader, user-data-call, tessellation and shutdown tests, and the four new tests passed 10 runs in a row.

Windows:

  • RTX 3070 Laptop GPU, driver 617.42, NVIDIA's Vulkan driver only, WinLibs MinGW Release build: with the fix's two source files reverted to main's, all four new tests fail with the reasons in the table below (s_swappc_b64 … is not statically resolvable; GetImageResource dword 0 is not a valid runtime value for the pixel and the vertex stage; rectangle ABI has missing stage artifacts). With them, all four pass 5 runs in a row.
  • GitHub runner (WinLibs MinGW): the build passes and ^agc passes 594 of 595. The four new tests skip there (no Vulkan device). agc_driver_pm4_replay_tool fails the same way with main's sources in the same run (the tool exits 0xc0000139 on the runner).

The undecodable-state follow-up (6bd8647, 661d3cb), Linux, GitHub runner with Mesa lavapipe (run): with ShaderRegistry.cpp reverted to 695ec6c's, agc_driver_prepared_shaders_abi_deferred_undecodable_state fails in all 3 runs with AGC graphics: VGT_SHADER_STAGES_EN=0x2030: unsupported geometry input or output assembly, and the other 12 prepared-shader modes pass. With it, all 13 pass 10 runs in a row. On the Windows runner the 13 skip (no Vulkan device). On a Linux cloud worker (Ubuntu 24.04, GCC 13.3, lavapipe) the whole ^agc sweep passes, 561 tests there.

The completeness follow-ups (19a3e07, 502085c, e986ee0), Linux, GitHub runner with Mesa lavapipe (run): with ShaderRegistry.cpp reverted to 661d3cb's, the three new modes (registration_failure, vertex_inputs, rectangle_pairs) fail in all 3 runs and the other prepared-shader modes and agc_driver_prepared_publication pass. With it, all 17 pass 10 runs in a row. On the Windows runner they skip (no Vulkan device). On a Linux cloud worker, with these three and one more commit not in this PR, the whole ^agc sweep passes (606 tests there) and CI's test-registration check passes.

Eight new agc_driver_prepared_shaders_abi_deferred_* modes. Each is red with the fix reverted:

Mode Without the fix With it
compute ResolveShaderAbi throws "s_swappc_b64 call target … is not statically resolvable" resolved twice with one preparation; the dispatch prepares the shader at use and every lane holds 3 × (5 + 64)
pixel throws "GetImageResource dword 0 is not a valid runtime value" (a phi of user data and a ballot) logged once with that reason, no second preparation, and a resolve inside a ShaderPreparationScope commits; the draw fails at use with the same reason, and the next ABI call throws the stored driver failure
stages nested and direct ResolveGraphicsStagesAbi throw the same reason for a vertex shader one line each, no second preparation; the scope commits
rectangle "rectangle ABI has missing stage artifacts" returns, with a pixel shader deferred at registration and with one deferred at its ABI call
undecodable state ResolveGraphicsStagesAbi throws "VGT_SHADER_STAGES_EN=0x2030: unsupported geometry input or output assembly" for a geometry-routed vertex shader, with the registers sceAgcCreatePrimState passes deferred once with that reason, a repeated call prepares and logs nothing, and a later draw prepares the stage at its first use
registration failure the scope and every ABI entry point rethrow a stored registration failure ("GetImageResource dword 0 is not a valid runtime value") for a pixel, a compute and a vertex stage each logged once with the stored reason, nothing logged on a second pass, and the dispatch fails at use with the same reason
vertex inputs ResolveGraphicsStagesAbi throws "statically bound vertex attributes are not implemented" logged once with that reason, no front-end build, and the draw fails with the same text
rectangle pairs the rect-list pairing throws "custom per-vertex interpolation is unsupported" logged once with that reason; a draw with a null pixel on the same front succeeds, and the passthrough draw fails with the builder's text

Cost: I timed the success path of each entry point on main and on this branch (on a08de68): 5 and 6 interleaved runs, 7 × 20,000 resolved-key calls and 7 × 100 new keys each.

  • Resolved keys took 1.9-2.6 µs per call; new keys 20-46 µs.
  • Every branch median was within the run-to-run spread, -2.5 % to +7.7 %. The largest difference is on a path this branch doesn't change.

The merge of main 82ddae7 (with #5872, the async driver log and the geometry subgroup check), on GitHub's runners (run): the 19 prepared-shader modes and the async-log tests pass 5 runs in a row on Linux and Windows (the GPU modes skip on Windows). The run's other failures are libc's precise_wait on Linux, a timing test; guest_kqueue on Windows, which fails on main there; and guest_shader_link on Windows, which timed out once in five. On main 82ddae7 alone it times out the same way, on the ninth run after 8 passes (run).

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: PPSA01556 Resident Evil Village (PPSA01556) #5169 (pipeline creation; to reach its title, Resident Evil Village also needs fix(libkernel): commit a reserved host stack before protecting it #5703 and a fix for the depth-sample check above)
  • GPUs tested: NVIDIA GeForce RTX 3070 Laptop GPU, driver 617.42, Windows 11; Mesa lavapipe (CPU), Linux
  • AI-assisted: yes

…s first use

sceAgcDriverResolveShaderAbi and sceAgcDriverResolveGraphicsStagesAbi
prepare every stage when the title creates its pipeline, and threw when
the recompiler could not: Resident Evil Village stops there on a pixel
shader whose T# pointer is a phi of user data and a ballot, and a
compute shader that calls user-data pointers stopped the same way
although its dispatch links the callees.

ResolveShaderAbi and PrepareGraphicsStages now catch the failure inside
their own preparation transaction, so the ShaderPreparationScope that
libSceAgc opens around the call still commits. The shader is logged
once, marked deferred like a shader deferred at registration, and the
ABI key is recorded, so a repeated call prepares nothing. The draw or
dispatch that uses the stage prepares it as before and fails there if
it cannot. ResolvePreparedGraphics skips the rectangles of a deferred
stage that has no artifact yet, which also lets a stage deferred at
registration through sceAgcDriverResolveGraphicsAbi.

Driver failures, ProcessShutdown and a failure stored by the shader's
registration preparation still propagate.
… prepare

Four prepared-shader modes, run with the recompiler's failure memo off
so a second preparation would show as a second front-end build:

- compute: a shader that calls user-data pointers is resolved twice and
  prepared once, then its dispatch links the callees and every lane
  holds 3 * (5 + 64); a shader whose registration preparation failed
  still throws its stored failure from the ABI call.
- pixel: a waterfall whose T# pointer is a phi of user data and a
  ballot is logged once with its reason, resolved again without a
  second preparation, and resolved for another state inside a
  ShaderPreparationScope that commits. A draw of it fails at use with
  the same reason, and the ABI call then throws the driver's failure.
- stages: the same chain in a vertex shader that registration leaves
  alone, through ResolveShaderAbi inside a scope and through
  ResolveGraphicsStagesAbi.
- rectangle: sceAgcDriverResolveGraphicsAbi with a pixel shader
  deferred at registration and with one deferred at its ABI call.
This was referenced Oct 15, 2026
…s not decode

A fifth ABI deferral mode, abi_deferred_undecodable_state. A vertex
shader whose specials route it through geometry (VGT_SHADER_STAGES_EN
0x2030), which registration leaves alone, is resolved through
ResolveGraphicsStagesAbi with the context and primitive registers that
sceAgcCreatePrimState passes for it. DecodeShaderStages refuses its
VGT_GS_OUT_PRIM_TYPE of 1.

The call must not throw and must log the stage once with the decode's
reason, and a second call must neither prepare nor log it again. A draw
that routes the stage through the vertex path then prepares it at its
first use without reporting it as missing a registration artifact.
EagleBearerYS added a commit to EagleBearerYS/AnyPS5 that referenced this pull request Oct 15, 2026
…first use

A failure stored by a shader's background registration preparation was
rethrown by every pipeline ABI call that touched the stage. The
ShaderPreparationScope that sceAgcLinkShaders, sceAgcCreatePrimState and
sceAgcCreateInterpolantMapping open settled the stages and threw first,
and ResolveShaderAbi, ResolveGraphicsStagesAbi and ResolveGraphicsAbi
threw it again from their reads of the stage. A title that creates its
pipelines ahead of drawing ended there, although the draw or dispatch
that uses the stage rethrows the same stored failure.

Settling a scope no longer rethrows. Each ABI call logs such a stage
once with its stored reason, marks it deferred and prepares the other
stages of the call as before. ResolveGraphicsStagesAbi keeps its ABI
record on the first stage that did not fail, PrepareGraphicsStages skips
a failed program, and ResolvePreparedGraphics records no rectangle for
a failed stage and never adds a failed fragment to a front stage, where
the rectangle draw of another fragment would meet it.

The compute mode no longer expects the stored failure from the ABI call.
A new mode registers a compute, a pixel and a vertex shader whose
registration preparation fails, resolves them through every ABI entry
point inside a scope twice, and expects three deferrals with the stored
reason the first time and none the second, then the stored reason from
the compute shader's dispatch.
…e to its first use

PrepareGraphicsStages decodes each front-end stage's vertex inputs from
its AGC header before it prepares the stage, outside the catch that
defers a stage the recompiler cannot prepare. A header the decode
refuses, such as a semantic with a statically bound vertex buffer,
threw out of sceAgcDriverResolveGraphicsStagesAbi and ended a title that
creates its pipelines ahead of drawing. Registration leaves such a stage
alone when it is an NGG vertex shader that uses its workgroup, or a
mesh, hull or domain stage, so the pipeline ABI is the first to decode
it.

A decode failure now defers the stage the same way a preparation
failure does. The draw that uses it decodes the same header with the
draw's own user data and fails there with the same reason.

A new mode registers an NGG vertex shader with vertex buffer and
attribute tables and one statically bound semantic, resolves its
pipeline ABI twice inside a scope, and expects one deferral with the
decode's reason and no front-end build, then the same reason from its
first draw.
…eir first draw

sceAgcLinkShaders resolves the rect-list pairing of a pipeline when the
title creates it, and three cases ended the title there although the
rect-list draw that uses the pipeline builds its pair itself:

- a pipeline without a pixel shader reached ResolveGraphicsAbi with a
  null pixel, which required both stages, although the draw pairs the
  front stage with the null pixel program;
- a stage with no artifact yet, such as a pixel shader that exports
  stencil on a device without VK_EXT_shader_stencil_export, failed the
  missing stage artifacts check;
- a pair that BuildRectListShaders refuses, such as a pixel input with
  passthrough interpolation, threw from the builder.

The ABI now skips the first two, and logs the third once as a deferral
of the pixel shader without recording the pair, so the pair's draw
builds it again and fails with the builder's reason. When a draw builds
the rectangles of its front stage, only the pair of its own fragment can
fail it; the pair of another fragment that has no artifact or that the
builder refuses is left to that fragment's draw.

A new mode resolves a front stage with a null pixel, with a pixel before
it has an artifact, with a pixel that never gets one and with the first
pixel's passthrough variant, and expects one deferral with the
builder's reason. It then draws the front stage as a rect list with the
null pixel program, which succeeds although the other two pairs cannot
be built, and with the passthrough pixel, which fails with the
builder's reason.
Brings boykopovar#5872 (shader preparation on first use), main's async driver log and its geometry subgroup checks. The prepared-shader modes are the union of both lists. With this branch, the pipeline ABI of a lazily registered shader it cannot prepare leaves the stage deferred instead of throwing, so LazyRegistration now requires the stage to stay deferred with no prepared entry after that call; its dispatch and shutdown failure checks are unchanged. StderrCapture flushes the async log when it starts and before it reads, since a deferral's log line can otherwise still be queued. The undecodable-state check now matches the decode's VGT_SHADER_STAGES_EN reason rather than one message, which main's subgroup output check now gives first.
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 16, 2026
EagleBearerYS added a commit to EagleBearerYS/AnyPS5 that referenced this pull request Oct 17, 2026
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 18, 2026
@adriadam10 adriadam10 self-assigned this Oct 18, 2026
@adriadam10
adriadam10 merged commit 7978a4b into boykopovar:main Oct 19, 2026
9 checks passed
@Scramblrrrr

Copy link
Copy Markdown
Contributor

Windows cross-test on clean main324e0e48e found six of the new ABI-deferral modes aborting during logger initialization: the test's inline FlushAsyncLog call instantiates its own PE-local AsyncLog, then the driver attempts to register a different end-flush callback. All six reproduce without our 007 stack. Small two-file fix in #7709 moves the existing flush helper into the driver translation unit; unchanged fixtures, 29/29 prepared/logger/shutdown tests pass on88c8320e3. The same fix on our refreshed 007 stack passes114/114 focused native checks. No title/FPS claim. AI-assisted: Codex.

TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
…refusals

Upstream's abi_deferred_* modes (boykopovar#6366) expect a draw of a deferred pixel
shader that its static ABI cannot prepare to fail the queue
(agc_driver_prepared_shaders_abi_deferred_pixel: "expected preparation
failure"). Our e7fe39a skips such a draw by default and reports it;
APS5_STRICT_SHADER_REFUSALS=1 restores the failure. The abi_deferred
tests now set that switch, which selects the behaviour they check.

AI-assisted: yes
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
Our b18d883 test expected a domain program the recompiler refuses to
fail ResolveGraphicsStagesAbi unless APS5_SKIP_REFUSED_SHADERS is set.
Upstream boykopovar#6366 (in the merge) resolves the graphics stage ABI with
deferUnprepared: an unpreparable stage is logged and prepared when it is
used, and the call returns ("the refused domain program did not stop ABI
resolution: it was prepared"). Without the switch the test now requires
that deferral and idles the driver as with it.

AI-assisted: yes
Pipodi pushed a commit to Pipodi/AnyPS5 that referenced this pull request Nov 14, 2026
…refusals

Upstream's abi_deferred_* modes (boykopovar#6366) expect a draw of a deferred pixel
shader that its static ABI cannot prepare to fail the queue
(agc_driver_prepared_shaders_abi_deferred_pixel: "expected preparation
failure"). Our e7fe39a skips such a draw by default and reports it;
APS5_STRICT_SHADER_REFUSALS=1 restores the failure. The abi_deferred
tests now set that switch, which selects the behaviour they check.

AI-assisted: yes
Pipodi pushed a commit to Pipodi/AnyPS5 that referenced this pull request Nov 14, 2026
Our b18d883 test expected a domain program the recompiler refuses to
fail ResolveGraphicsStagesAbi unless APS5_SKIP_REFUSED_SHADERS is set.
Upstream boykopovar#6366 (in the merge) resolves the graphics stage ABI with
deferUnprepared: an unpreparable stage is logged and prepared when it is
used, and the call returns ("the refused domain program did not stop ABI
resolution: it was prepared"). Without the switch the test now requires
that deferral and idles the driver as with it.

AI-assisted: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants