feat(agc): run COND_INDIRECT_BUFFER branches whose comparison always passes #898

Merged
alfalfa-star merged 1 commit from upstream-pr/898 into main 2026-10-07 16:26:59 +00:00
alfalfa-star commented 2026-10-06 14:20:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-06T14:20:29Z.


What

Run COND_INDIRECT_BUFFER branches whose comparison always passes, and stop sceAgcCbBranch from rejecting fields that such a branch never reads.

PPSA14632 (LEGO Horizon Adventures, Unreal Engine) calls sceAgcCbBranch(cb, mode 1, compare function 0, compareAddress, mask 0, reference 0, 0, then, n, 0, nullptr, 0) from one place (eboot 0x5084ea4, through a wrapper at 0x50ff640). The caller never sets rcx, so the compare address is whatever the register holds: it was 0x300d5f4ac8 in one run and 0x300d5f4e84 (only 4-byte aligned) in another. On main:

  • The writer throws sceAgcCbBranch: null or misaligned address 0x0 for the null else buffer, and, once that is relaxed, for the misaligned compare address.
  • The driver accepts opcode 0x3f only as the 4-dword INDIRECT_BUFFER (invalid INDIRECT_BUFFER size), so the 14-dword branch would fail at submission.

Changes:

  • Writer: sceAgcCbBranch checks the compare address only when the compare function is not 0 (always), and a buffer address only when its size is not 0. The packet is written as before.
  • Driver: copySegment runs the first buffer of an always-pass COND_INDIRECT_BUFFER in modes 1 and 2 in place of the packet, as it does for a non-chained INDIRECT_BUFFER. Modes 1 and 2 are assumed to be AMD's if-then and if-then-else. A real comparison, a predicated branch and other modes throw. A comparison would have to read memory that earlier packets of the queue may still write, so it is left for a title that needs it.

TechnicalDebt lists both.

Tested

  • Arch Linux, GCC 16.2, Release, RX 9070 XT (RADV).
  • agc_branch_patch_tests: an always-pass branch with an unaligned compare address and a null else buffer of 0 dwords, and an empty branch, are written; a comparison with a misaligned address, or a null buffer with a size, still throws without advancing the buffer. Fails on main.
  • agc_driver_pm4: an always-pass if-then and if-then-else run only the first buffer, an empty branch skips to the next packet, and a comparison or mode 0 rejects the whole submission. Fails on main with invalid INDIRECT_BUFFER size.
  • Full ctest: 359/359.
  • PPSA14632: the title gets past the branch and runs on to an unrelated storage image access to depth/stencil surface ... is not implemented, which #425 may address.
  • Windows not built or tested.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4760090206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/898). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-06T14:20:29Z. --- ### What Run `COND_INDIRECT_BUFFER` branches whose comparison always passes, and stop `sceAgcCbBranch` from rejecting fields that such a branch never reads. PPSA14632 (LEGO Horizon Adventures, Unreal Engine) calls `sceAgcCbBranch(cb, mode 1, compare function 0, compareAddress, mask 0, reference 0, 0, then, n, 0, nullptr, 0)` from one place (eboot 0x5084ea4, through a wrapper at 0x50ff640). The caller never sets `rcx`, so the compare address is whatever the register holds: it was 0x300d5f4ac8 in one run and 0x300d5f4e84 (only 4-byte aligned) in another. On `main`: - The writer throws `sceAgcCbBranch: null or misaligned address 0x0` for the null else buffer, and, once that is relaxed, for the misaligned compare address. - The driver accepts opcode 0x3f only as the 4-dword `INDIRECT_BUFFER` (`invalid INDIRECT_BUFFER size`), so the 14-dword branch would fail at submission. Changes: - **Writer**: `sceAgcCbBranch` checks the compare address only when the compare function is not 0 (always), and a buffer address only when its size is not 0. The packet is written as before. - **Driver**: `copySegment` runs the first buffer of an always-pass `COND_INDIRECT_BUFFER` in modes 1 and 2 in place of the packet, as it does for a non-chained `INDIRECT_BUFFER`. Modes 1 and 2 are assumed to be AMD's if-then and if-then-else. A real comparison, a predicated branch and other modes throw. A comparison would have to read memory that earlier packets of the queue may still write, so it is left for a title that needs it. TechnicalDebt lists both. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> - Arch Linux, GCC 16.2, Release, RX 9070 XT (RADV). - `agc_branch_patch_tests`: an always-pass branch with an unaligned compare address and a null else buffer of 0 dwords, and an empty branch, are written; a comparison with a misaligned address, or a null buffer with a size, still throws without advancing the buffer. Fails on `main`. - `agc_driver_pm4`: an always-pass if-then and if-then-else run only the first buffer, an empty branch skips to the next packet, and a comparison or mode 0 rejects the whole submission. Fails on `main` with `invalid INDIRECT_BUFFER size`. - Full ctest: 359/359. - PPSA14632: the title gets past the branch and runs on to an unrelated `storage image access to depth/stencil surface ... is not implemented`, which #425 may address. - Windows not built or tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-07 11:46:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T11:46:16Z.


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
#1100 docs/dev/TechnicalDebt.md L231
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6037229865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/898#issuecomment-6037229865). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T11:46:16Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #1100 | `docs/dev/TechnicalDebt.md` [L231](https://github.com/boykopovar/AnyPS5/blob/6b3e8c476eaad58d5cd63c917d16179eb85b5398/docs/dev/TechnicalDebt.md#L231) | | |
adriadam10 commented 2026-10-07 16:26:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:26:56Z.


Checked the packet layout, modes 1/2 and compare function 0 against AMD's si_ci_vi_merged_pm4defs.h (COND_INDIRECT_BUFFER_MODE_IF/IF_ELSE, FUNC_ALWAYS), build + full ctest on Linux (398/398), and that both new tests fail without the change; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6042172838 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/898#issuecomment-6042172838). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T16:26:56Z. --- Checked the packet layout, modes 1/2 and compare function 0 against AMD's `si_ci_vi_merged_pm4defs.h` (`COND_INDIRECT_BUFFER_MODE_IF/IF_ELSE`, `FUNC_ALWAYS`), build + full ctest on Linux (398/398), and that both new tests fail without the change; merging.
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!898
No description provided.