feat(libSceAgc): implement sceAgcUpdateInterpolantMapping_0100 #4826

Closed
winstrex wants to merge 1 commit from upstream-pr/4826 into main
winstrex commented 2026-10-12 23:03:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by winstrex on 2026-10-12T23:03:34Z.


What

sceAgcUpdateInterpolantMapping_0100 (k0E7vkgqAuE) was a throwing stub in Misc/src/ShaderFusion.cpp. It now sits next to the other interpolant mapping exports in Shader/src/InterpolantMapping.cpp:

return CreateInterpolantMapping(__func__, regs, vs, ps, CreateInterpolantValue, false);

It writes one SPI_PS_INPUT_CNTL_0 + i register per pixel shader input (input_semantics, +0x30; count, +0x50). Each input is matched to the first vertex shader output (output_semantics, +0x38; count, +0x56) with the same semantic byte. There is no identity tail, so a pixel shader without inputs writes nothing and does not read the vertex shader. It returns 0. The technical debt entry that marked its behaviour as unknown is removed.

Sources:

  • Behaviour taken from a disassembly of libSceAgc.sprx found in the fakelib/ folder of an ANIMAL WELL 01.000.011 dump (not part of the game's package; firmware version unknown). The implementation was written from a text specification of that behaviour.
  • No public reimplementation has a body for this export (OpenAGC, KytyPS5 and shadPS4 do not), so the specification is the only source of its behaviour.

It matches CreateInterpolantValue formula by formula, the per-input value sceAgcCreateInterpolantMapping_0100 already uses (InterpolantMapping.cpp L22):

  • An is_f16 input ((p & 0x00300000) != 0) takes bits 24–25 from p << 4. Unmatched, it gets 0x00180020. Matched, bits 5, 19 and 20 come from p & s. Bits 21–22 hold default_value_hi. This is CreateInterpolantF16Value (ShaderUtils.cpp L111).

  • A 32-bit input sets bit 5 for is_custom or no match. This is CreateInterpolantNonF16Value (L126).

  • Then, in both cases:

    • bits 0–4 take the matched output's hardware_mapping, or 0;
    • bit 10 is set for a match with is_flat_shaded or is_custom;
    • bits 8–9 hold default_value.

    This is CreateInterpolantMappingValue / CreateInterpolantDefaultValue (L134, L144).

  • The match is the first output whose semantic byte equals the input's, which is FindOutputSemantic (L150).

  • The offset template 0x191 is SPI_PS_INPUT_CNTL_0.

How it differs from vieBRwlh1Lw (which this PR leaves untouched; L135). vieBRwlh1Lw uses UpdateInterpolantValue, which differs in two ways:

  1. It goes through CreateInterpolantValueSplitF16, which builds is_f16 2 (high-half-only) inputs another way (CreateInterpolantF16HiValue). The specification uses the same F16 path for every is_f16 value; for example, the first input of the test gives 0x02680527 here and 0x02680707 from vieBRwlh1Lw.
  2. It throws for an is_f16 1 or 3 input whose default_value and default_value_hi differ. The specification says both are applied separately (low to bits 8–9, high to bits 21–22) and such an input is not rejected.

The two remaining deviations from the specification are on invalid input, where the original faults or writes past the hardware's 32 registers: a null regs or ps, a null vs with pixel shader inputs, or more than 32 inputs throw (CreateInterpolantMapping's existing checks).

Tests in agc_interpolant_mapping:

  • the five-input set of the existing test, with values computed from the specification's formulas and equal to sceAgcCreateInterpolantMapping_0100 over the written registers;
  • F16 inputs with different low and high defaults, which are accepted and keep both;
  • no write past the inputs;
  • no write and no preparation without inputs;
  • the three rejections.

Without this change the test does not link (undefined reference to sceAgcUpdateInterpolantMapping_0100). With UpdateInterpolantValue (the vieBRwlh1Lw transform) in place of CreateInterpolantValue it fails with "matched high f16 half is not mapped as an f16 input".

Tested

Windows 11, WinLibs GCC 15.2.0, Release: agc_interpolant_mapping and the other 13 agc_interpolant_mapping|guest_shader|agc_shader tests pass, and libs builds. CI on the fork: Linux, Windows and the relinker, register-context and write-watch jobs pass.

Not tested with a title. The Pathless (PPSA01825) and Balatro (PPSA21402) import k0E7vkgqAuE; no run has reached it.

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: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836016459 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4826). Originally posted by [winstrex](https://github.com/winstrex) on 2026-10-12T23:03:34Z. --- ### What `sceAgcUpdateInterpolantMapping_0100` (`k0E7vkgqAuE`) was a throwing stub in `Misc/src/ShaderFusion.cpp`. It now sits next to the other interpolant mapping exports in `Shader/src/InterpolantMapping.cpp`: ```cpp return CreateInterpolantMapping(__func__, regs, vs, ps, CreateInterpolantValue, false); ``` It writes one `SPI_PS_INPUT_CNTL_0 + i` register per pixel shader input (`input_semantics`, +0x30; count, +0x50). Each input is matched to the first vertex shader output (`output_semantics`, +0x38; count, +0x56) with the same semantic byte. There is no identity tail, so a pixel shader without inputs writes nothing and does not read the vertex shader. It returns 0. The technical debt entry that marked its behaviour as unknown is removed. Sources: - Behaviour taken from a disassembly of `libSceAgc.sprx` found in the `fakelib/` folder of an ANIMAL WELL 01.000.011 dump (not part of the game's package; firmware version unknown). The implementation was written from a text specification of that behaviour. - No public reimplementation has a body for this export (OpenAGC, KytyPS5 and shadPS4 do not), so the specification is the only source of its behaviour. **It matches `CreateInterpolantValue` formula by formula**, the per-input value `sceAgcCreateInterpolantMapping_0100` already uses ([InterpolantMapping.cpp L22](https://github.com/boykopovar/AnyPS5/blob/584cc4c5716b02210ca031593d1a6b0b4ce049cb/core/libs/prx/libSceAgc/Shader/src/InterpolantMapping.cpp#L22)): - An `is_f16` input (`(p & 0x00300000) != 0`) takes bits 24–25 from `p << 4`. Unmatched, it gets `0x00180020`. Matched, bits 5, 19 and 20 come from `p & s`. Bits 21–22 hold `default_value_hi`. This is `CreateInterpolantF16Value` ([ShaderUtils.cpp L111](https://github.com/boykopovar/AnyPS5/blob/584cc4c5716b02210ca031593d1a6b0b4ce049cb/core/libs/prx/libSceAgc/Shader/src/ShaderUtils.cpp#L111)). - A 32-bit input sets bit 5 for `is_custom` or no match. This is `CreateInterpolantNonF16Value` (L126). - Then, in both cases: - bits 0–4 take the matched output's `hardware_mapping`, or 0; - bit 10 is set for a match with `is_flat_shaded` or `is_custom`; - bits 8–9 hold `default_value`. This is `CreateInterpolantMappingValue` / `CreateInterpolantDefaultValue` (L134, L144). - The match is the first output whose semantic byte equals the input's, which is `FindOutputSemantic` (L150). - The offset template 0x191 is `SPI_PS_INPUT_CNTL_0`. **How it differs from `vieBRwlh1Lw`** (which this PR leaves untouched; [L135](https://github.com/boykopovar/AnyPS5/blob/584cc4c5716b02210ca031593d1a6b0b4ce049cb/core/libs/prx/libSceAgc/Shader/src/InterpolantMapping.cpp#L135)). `vieBRwlh1Lw` uses `UpdateInterpolantValue`, which differs in two ways: 1. It goes through `CreateInterpolantValueSplitF16`, which builds `is_f16` 2 (high-half-only) inputs another way (`CreateInterpolantF16HiValue`). The specification uses the same F16 path for every `is_f16` value; for example, the first input of the test gives `0x02680527` here and `0x02680707` from `vieBRwlh1Lw`. 2. It throws for an `is_f16` 1 or 3 input whose `default_value` and `default_value_hi` differ. The specification says both are applied separately (low to bits 8–9, high to bits 21–22) and such an input is not rejected. The two remaining deviations from the specification are on invalid input, where the original faults or writes past the hardware's 32 registers: a null `regs` or `ps`, a null `vs` with pixel shader inputs, or more than 32 inputs throw (`CreateInterpolantMapping`'s existing checks). Tests in `agc_interpolant_mapping`: - the five-input set of the existing test, with values computed from the specification's formulas and equal to `sceAgcCreateInterpolantMapping_0100` over the written registers; - F16 inputs with different low and high defaults, which are accepted and keep both; - no write past the inputs; - no write and no preparation without inputs; - the three rejections. Without this change the test does not link (`undefined reference to sceAgcUpdateInterpolantMapping_0100`). With `UpdateInterpolantValue` (the `vieBRwlh1Lw` transform) in place of `CreateInterpolantValue` it fails with "matched high f16 half is not mapped as an f16 input". ### Tested Windows 11, WinLibs GCC 15.2.0, Release: `agc_interpolant_mapping` and the other 13 `agc_interpolant_mapping|guest_shader|agc_shader` tests pass, and `libs` builds. CI on the fork: Linux, Windows and the relinker, register-context and write-watch jobs pass. Not tested with a title. The Pathless (PPSA01825) and Balatro (PPSA21402) import `k0E7vkgqAuE`; no run has reached it. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-12 23:03:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T23:03:58Z.


Progress report (90c6839 → c4c6068)

📈 System libraries: 87.89% (+0.02%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceAgc sceAgcUpdateInterpolantMapping_0100
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134295749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4826#issuecomment-6134295749). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-12T23:03:58Z. --- <!-- progress-report --> ### Progress report (90c6839 → c4c6068) 📈 **System libraries**: 87.89% (+0.02%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceAgc | `sceAgcUpdateInterpolantMapping_0100` | </details>
coltken95 commented 2026-10-13 18:59:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T18:59:12Z.


Tested on Linux x86-64 (Release build, CTest), with c4c606818 merged into main 9d0a41d5a:

  • With the PR: agc_interpolant_mapping passes.
  • With main's libSceAgc sources the test executable doesn't build (the function isn't implemented there), so the test can't run.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152935465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4826#issuecomment-6152935465). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T18:59:12Z. --- Tested on Linux x86-64 (Release build, CTest), with c4c606818 merged into main 9d0a41d5a: - With the PR: `agc_interpolant_mapping` passes. - With main's libSceAgc sources the test executable doesn't build (the function isn't implemented there), so the test can't run. AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-14 02:32:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:32:47Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159585925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4826#issuecomment-6159585925). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:32:47Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!4826
No description provided.