Skip to content

fix(recompiler): declare pixel shader inputs at their parameter slots - #137

Merged
boykopovar merged 2 commits into
boykopovar:mainfrom
oneandonlydean:fix/pixel-inputs-at-parameter-slots
Oct 1, 2026
Merged

boykopovar merged 2 commits into
boykopovar:mainfrom
oneandonlydean:fix/pixel-inputs-at-parameter-slots

Conversation

@oneandonlydean

@oneandonlydean oneandonlydean commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

SPI_PS_INPUT_CNTL_n.OFFSET (bits 0 to 5) names the parameter slot that pixel input n reads. Several inputs may read one slot, and an input may read a slot the vertex stage never exports. With OFFSET bit 5 set and FLAT_SHADE clear, the input is the DEFAULT_VAL constant instead (bits 8 to 9: 0000, 0001, 1110, 1111). With OFFSET bit 5 and FLAT_SHADE both set, the input is a pass-through: the slot in the low bits is read with its three vertices unchanged, so v_interp_mov P0, P10 and P20 return vertices 0, 1 and 2 rather than P0, P1−P0 and P2−P0. The PS5 compiler writes such inputs as 0x422 and 0x423.

Main's mapping (PixelInputLocation in SpirvInputOutput.cpp) mishandled three cases:

  • It masked OFFSET to five bits, so a defaulted input landed on a real slot.
  • When a second input read the same slot, it got the same Location: two variables, "duplicate shader interface location".
  • When one of two inputs sharing a slot was flat, the second got a free Location the vertex stage never wrote: "graphics interfaces disagree at location N".

Now:

  • One input variable is declared per slot actually read, at Location = slot, and all inputs reading that slot share it.
  • A slot read both flat and interpolated, or through both a perspective and a linear pair by different inputs, is declared PerVertexKHR:
    • flat readers take the provoking vertex,
    • the others interpolate with the barycentrics of their own pair (BaryCoordKHR and/or BaryCoordNoPerspKHR, each declared only when used).
  • A per-vertex read without its barycentric input throws.
  • Pass-through inputs are declared PerVertexKHR at their slot, and their P10/P20 reads return the raw vertices without subtracting vertex 0. Reading a pass-through input with v_interp_p1/p2 has no exact translation and throws.
  • Defaulted inputs read their DEFAULT_VAL constant and declare nothing. Asking for a defaulted input's Location throws.
  • Inputs the program never reads are no longer declared.
  • DescribeFragmentParameters (used by the rect-list shaders) reports the slot as both source and location.

The pass-through case was found because PPSA21564's intro video went black: one of its pixel shaders reads input 0x423 (slot 3, flat) with v_interp_mov p0/p10/p20 and unpacks each vertex as 16-bit integers. An earlier revision of this PR treated every OFFSET bit 5 as a default, so that input became the constant 0.

A slot the vertex stage never exports is still rejected by validation here. The separate PR fix/agc-unexported-pixel-inputs handles that.

Tested

  • Linux (CachyOS, GCC). agc_shader_memory gains verifyPixelParameterSlots:
    • two inputs of slot 3 are declared once at Location 3,
    • inputs of slots 0 and 4 keep their slots,
    • inputs with OFFSET bit 5 declare no parameter,
    • a slot read flat and interpolated becomes one per-vertex input at its slot,
    • a pass-through input (0x423) is one per-vertex input at slot 3 whose p10/p20 reads subtract nothing, while a plain flat input (0x403) still reads differences to vertex 0,
    • 0x23 is still a default, and interpolating a pass-through input throws.
      It fails on the base branch ("inputs reading one slot were not declared once at the slot").
  • agc_driver_graphics_tests pixelParameterSlotTests runs the same shapes through DecodePixelStageInfo and ValidateShaders against a vertex module, including the control words (0x0, 0x400, 0x22, 0x320), and the pass-through case validated against a vertex module that exports slot 3. Without the pass-through change it fails with "a pass-through input (OFFSET bit 5 with FLAT_SHADE) was not read per vertex at its slot". Run on a throwaway merge with test(agc): link agc_driver_graphics_tests again, run it under ctest and bring its stale expectations up to date #113, where 58/58 pass.
  • Exercised in PPSA21564 on our integration branch. The intro (SIE card, PlayStation Studios video) renders in 7/7 runs, where treating 0x423 as a default left it black.
  • ctest: 57/57 pass.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: feat(agc): centroid pixel inputs and NoPerspective by I/J pair #136 (stacked on it: uses its per-parameter I/J pair record; its commit is the first one here)
  • AI-assisted: yes

@oneandonlydean
oneandonlydean marked this pull request as draft September 29, 2026 01:56
@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

Moving this to draft: in a game test, the change it comes from blanks Astro Bot's intro. I'm narrowing down which part is responsible and will update or close this PR.

@oneandonlydean
oneandonlydean force-pushed the fix/pixel-inputs-at-parameter-slots branch from 8e7b935 to ee7ddfd Compare September 29, 2026 03:38
@oneandonlydean
oneandonlydean marked this pull request as ready for review September 29, 2026 03:38
@oneandonlydean

Copy link
Copy Markdown
Collaborator Author

Ready again. The blank intro came from this PR: OFFSET bit 5 together with FLAT_SHADE means pass-through (the slot's three vertices unchanged), not DEFAULT_VAL. That's fixed and covered by tests; the description is updated.

@github-actions github-actions Bot added shader core/shader agc libSceAgc* needs rebase Conflicts with main, rebase needed labels Sep 29, 2026
@oneandonlydean
oneandonlydean force-pushed the fix/pixel-inputs-at-parameter-slots branch from ee7ddfd to e37ea6e Compare September 29, 2026 21:59
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Sep 29, 2026
@oneandonlydean
oneandonlydean force-pushed the fix/pixel-inputs-at-parameter-slots branch 2 times, most recently from aa4e59b to dd9f57b Compare September 30, 2026 11:12
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Sep 30, 2026
SPI_PS_INPUT_ENA/ADDR with PERSP_CENTROID (bit 2) or LINEAR_CENTROID
(bit 6) was rejected; PPSA21564 binds 0x326 (perspective center and
centroid, linear center, POS_X/Y).

The PS input VGPR layout now follows the hardware rule: SPI_PS_INPUT_ADDR
places every input it names in SPI order (two VGPRs per I/J pair, three
for the pull model, one otherwise), loaded or not, and ENA & ADDR selects
the loaded ones. ShaderPixelStageInfo carries inputAddr (replacing
perspectiveCenterVgpr) plus perspectiveCentroid and linearCentroid; the
recompiler places each loaded input with PixelInputVgpr. This also fixes
the system inputs, which were always written from v0 (psSystemInputBase
was never set), so POS_X overwrote the center I in any draw with
barycentrics enabled.

Draws are rasterized single-sampled, where the centroid is the pixel
center: with fragment barycentrics the centroid pairs carry the center
barycentrics (BaryCoordKHR for perspective; the linear center and
centroid pairs now get BaryCoordNoPerspKHR).

NoPerspective was decided for every parameter by one flag (LINEAR_CENTER
loaded). v_interp_p2 now records whether it reads the J of a linear or a
perspective pair, and a parameter is NoPerspective when it is read
through a linear pair; parameters read through neither keep the old
rule. A parameter read through both kinds of pair throws. Only pixel
stages consult this.

The request serializer moves to version 5 (older requests read back with
their loaded inputs as the layout); the cache key and the driver's draw
key compare and hash the new fields. The unsupported-input error names
ENA and ADDR.
SPI_PS_INPUT_CNTL_n.OFFSET (bits 0-5) names the parameter slot pixel
input n reads, so several inputs may read one slot and an input may read
a slot the vertex stage never exports. With OFFSET bit 5 set and
FLAT_SHADE clear the input is the DEFAULT_VAL constant instead (bits 8-9:
0000, 0001, 1110, 1111). With OFFSET bit 5 and FLAT_SHADE both set the
slot in the low bits is passed through with its three vertices unchanged:
v_interp_mov P0, P10 and P20 read vertices 0, 1 and 2 rather than P0,
P1-P0 and P2-P0. The PS5 compiler writes such inputs as 0x422 and 0x423.

The old mapping masked OFFSET to five bits, so a defaulted input landed
on a real slot, and gave the second of two inputs reading one slot either
the same Location (two variables, "duplicate shader interface location")
or, when one was flat, a free Location the vertex stage never wrote
("graphics interfaces disagree at location N").

Now one input variable is declared per slot actually read, at Location =
slot, and inputs reading that slot share it. A slot read both flat and
interpolated (or through the perspective and linear pairs) is read per
vertex: flat readers take the provoking vertex, the others interpolate
with the barycentrics of their own pair. Pass-through inputs are read per
vertex at their slot without subtracting vertex 0, and reading one with
v_interp_p1/p2 is refused. Defaulted inputs read their DEFAULT_VAL
constant and declare nothing; inputs the program never reads are no
longer declared.
@oneandonlydean
oneandonlydean force-pushed the fix/pixel-inputs-at-parameter-slots branch from dd9f57b to 6a33a3d Compare September 30, 2026 19:48
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Sep 30, 2026
pidsmandaks-ux added a commit to pidsmandaks-ux/AnyPS5 that referenced this pull request Oct 1, 2026
Import generic pixel-input compatibility fixes from upstream PRs boykopovar#136 and boykopovar#137.
@boykopovar
boykopovar merged commit 8764959 into boykopovar:main Oct 1, 2026
3 checks passed
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 1, 2026
…opovar#208 test layout, our merged PRs) into astrobot

Conflicts resolved:
- Driver.cpp: upstream split it into Execution/src/Driver/*; astrobot's
  driver changes are ported into the split files (flip throttle
  APS5_MAX_QUEUED_FLIPS, dispatch tolerance, NoteProgram, metadata-pass
  switch and DB HTILE blits, depth state in the draw register key, HTILE
  fill clears, wait outcome counters, opt-in deferred EOP interrupts).
  boykopovar#192's KnownDrawRejection is taken.
- Our merged PRs take upstream's reviewed versions: boykopovar#124 shader fusion,
  boykopovar#128 videoout open param, boykopovar#132 CB metadata passes, boykopovar#138 EOP events,
  boykopovar#176 GE_INDX_OFFSET, boykopovar#136/boykopovar#137 pixel inputs and NoPerspective by I/J
  pair, boykopovar#133 mesh tests. boykopovar#142's interpolation validation is upstream's.
- Depth: astrobot's DepthTarget model stays; upstream's DepthSurface
  module is dropped again, boykopovar#188's 16-bit depth-bit reads are kept on top.
- Videodec2: upstream's ffmpeg-core version (boykopovar#42 rework); 3rdparty/FFmpeg
  stays for libSceAvPlayer only.
- Tests follow boykopovar#208's layout (add_test_executable, build/tests); the
  AvPlayer, GDS and wave tests are defined the same way.
- Shader disk cache format 5 and request serialization version 7 cover
  both sides' fields.
- Duplicates the auto-merge produced (state decoders, RequestInputInfo,
  structurizer helpers, image offsets, opcode enum, tests) are removed.
@oneandonlydean
oneandonlydean deleted the fix/pixel-inputs-at-parameter-slots branch October 1, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants