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

Merged
oneandonlydean merged 2 commits from upstream-pr/137 into main 2026-10-01 07:49:17 +00:00
oneandonlydean commented 2026-09-29 00:33:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T00:33:29Z.


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 #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: #136 (stacked on it: uses its per-parameter I/J pair record; its commit is the first one here)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4670965044 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/137). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-29T00:33:29Z. --- ### 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 #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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: #136 (stacked on it: uses its per-parameter I/J pair record; its commit is the first one here) - [x] AI-assisted: yes
oneandonlydean commented 2026-09-29 01:56:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T01:56:51Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5882174864 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/137#issuecomment-5882174864). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-29T01:56:51Z. --- 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 commented 2026-09-29 03:38:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-09-29T03:38:22Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5883158786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/137#issuecomment-5883158786). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-09-29T03:38:22Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!137
No description provided.