fix(recompiler): give vertex-path shaders a full NGG merged wave info #1412

Merged
TheAggie merged 2 commits from upstream-pr/1412 into main 2026-10-08 13:08:22 +00:00
TheAggie commented 2026-10-08 03:01:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T03:01:29Z.


What

On the vertex path (ShaderPath::Vertex, PRIMGEN_EN), the translator's vertex entry set only v5 (vertex index) and v8 (instance index). The NGG merged wave info SGPR s3 stayed 0. NGG shaders build their own EXEC from it. Mesa's ACO emits this at the start of every NGG vertex shader:

s_lshl_b32        s0, s3, 8      ; primitive count to bits 16..22
s_bfe_u64         exec, -1, s0   ; EXEC = (1 << primitive count) - 1
s_pack_ll_b32_b16 s3, 0, s3      ; vertex count to bits 16..22
s_bfe_u64         exec, -1, s3   ; EXEC = (1 << vertex count) - 1

With s3 = 0 both masks are empty, so the shader skipped its vertex fetch and position export and no geometry was rasterized.

Each host invocation on this path is one vertex of a full wave, so the vertex entry now sets s3 to waveSize | waveSize << 8 (vertex and primitive count of a full wave, wave index 0) when the program's user data starts at s8 or later, i.e. s0–s7 are system SGPRs as in NGG programs. Shaders that do not read s3 are unaffected.

  • agc_driver_ngg_vertex_wave_info: an execution test whose vertex shader starts with the prologue above, with user data at s8, and draws a full-screen triangle for wave64 and wave32. Without the change no pixel is written (the test fails with the target's fill value); with it every pixel is.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.

  • All agc_* and shader_* tests pass, including the new one. They were run from the generated CTestTestfile.cmake commands, because antivirus blocks ctest.exe on this machine.
  • Homebrew built on ps5-opengl (Mesa 26.2 on AGC, blackbearreloaded/ps5-opengl, GPL-3.0): PS5 OpenGL Showcase (PPSA99005) and Homebrew UI Lab (PPSA99050) executed thousands of draws per second but presented black frames (APS5_DUMP_FRAMES). Forcing the pixel shader output to a constant colour did not change that. The recompiled vertex shaders evaluated EXEC as the constant 0. With this change their geometry is rasterized. Other fixes are needed before these titles render completely; those follow in separate PRs.

Not tested on AMD, Intel or Linux.

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:4781179897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1412). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T03:01:29Z. --- ### What On the vertex path (`ShaderPath::Vertex`, PRIMGEN_EN), the translator's vertex entry set only `v5` (vertex index) and `v8` (instance index). The NGG merged wave info SGPR `s3` stayed 0. NGG shaders build their own EXEC from it. Mesa's ACO emits this at the start of every NGG vertex shader: ``` s_lshl_b32 s0, s3, 8 ; primitive count to bits 16..22 s_bfe_u64 exec, -1, s0 ; EXEC = (1 << primitive count) - 1 s_pack_ll_b32_b16 s3, 0, s3 ; vertex count to bits 16..22 s_bfe_u64 exec, -1, s3 ; EXEC = (1 << vertex count) - 1 ``` With `s3` = 0 both masks are empty, so the shader skipped its vertex fetch and position export and no geometry was rasterized. Each host invocation on this path is one vertex of a full wave, so the vertex entry now sets `s3` to `waveSize | waveSize << 8` (vertex and primitive count of a full wave, wave index 0) when the program's user data starts at `s8` or later, i.e. `s0`–`s7` are system SGPRs as in NGG programs. Shaders that do not read `s3` are unaffected. - `agc_driver_ngg_vertex_wave_info`: an execution test whose vertex shader starts with the prologue above, with user data at `s8`, and draws a full-screen triangle for wave64 and wave32. Without the change no pixel is written (the test fails with the target's fill value); with it every pixel is. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti. - All `agc_*` and `shader_*` tests pass, including the new one. They were run from the generated `CTestTestfile.cmake` commands, because antivirus blocks `ctest.exe` on this machine. - Homebrew built on ps5-opengl (Mesa 26.2 on AGC, [blackbearreloaded/ps5-opengl](https://github.com/blackbearreloaded/ps5-opengl), GPL-3.0): PS5 OpenGL Showcase (PPSA99005) and Homebrew UI Lab (PPSA99050) executed thousands of draws per second but presented black frames (`APS5_DUMP_FRAMES`). Forcing the pixel shader output to a constant colour did not change that. The recompiled vertex shaders evaluated EXEC as the constant 0. With this change their geometry is rasterized. Other fixes are needed before these titles render completely; those follow in separate PRs. Not tested on AMD, Intel or Linux. ### 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 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)
TheAggie commented 2026-10-08 03:23:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T03:23:00Z.


Before/after frames from APS5_DUMP_FRAMES. Before: UI Lab presents black. After this change: the backdrop and the Showcase's HUD, particles and bloom render. The UI and the 3D scene still need the other pending fixes (#1413, #1414, #1415).
1412-before-ui-lab-black
1412-after-showcase-hud-particles
1412-after-ui-lab-backdrop

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051511145 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1412#issuecomment-6051511145). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T03:23:00Z. --- Before/after frames from APS5_DUMP_FRAMES. Before: UI Lab presents black. After this change: the backdrop and the Showcase's HUD, particles and bloom render. The UI and the 3D scene still need the other pending fixes (#1413, #1414, #1415). <img width="960" height="540" alt="1412-before-ui-lab-black" src="https://github.com/user-attachments/assets/c5cc2578-1b30-4841-a229-4dd48e79fb58" /> <img width="1280" height="720" alt="1412-after-showcase-hud-particles" src="https://github.com/user-attachments/assets/4fe17e4b-23e9-4e2c-a800-4c407c600bcc" /> <img width="1280" height="720" alt="1412-after-ui-lab-backdrop" src="https://github.com/user-attachments/assets/2f32353b-469e-46a6-a548-2df6a7875f18" />
adriadam10 commented 2026-10-08 13:08:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:08:15Z.


Checked on Linux (RADV): build and ctest green on current main, and agc_driver_ngg_vertex_wave_info fails without the translator change and passes with it.

Pushed one commit on top:

  • docs/dev/TechnicalDebt.md ("Unknown function info"): the s3 layout comes from the prologue Mesa's ACO emits, not from a measurement. The line also says that userDataBaseRegister >= 8 is true for every graphics program here (firstUserSgpr = 8, DrawDecode.cpp), so it does not single out NGG shaders, and that a partial last wave still reports a full one.

Merging once the CI runs (they were waiting for approval, I approved them) are green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060569704 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1412#issuecomment-6060569704). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T13:08:15Z. --- Checked on Linux (RADV): build and ctest green on current main, and `agc_driver_ngg_vertex_wave_info` fails without the translator change and passes with it. Pushed one commit on top: - `docs/dev/TechnicalDebt.md` ("Unknown function info"): the `s3` layout comes from the prologue Mesa's ACO emits, not from a measurement. The line also says that `userDataBaseRegister >= 8` is true for every graphics program here (`firstUserSgpr = 8`, `DrawDecode.cpp`), so it does not single out NGG shaders, and that a partial last wave still reports a full one. Merging once the CI runs (they were waiting for approval, I approved them) are green.
EdouardSence commented 2026-10-08 13:18:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-08T13:18:04Z.


Tested on AMD under Linux, since this PR wasn't: RX 9070 XT (RDNA4, GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9 (CachyOS), GCC Release build.

  • ctest: this PR merged onto main 07c2405c, all 453 tests pass with ctest -j8 (main alone: 452/452 on the same machine).
  • Astro Bot (PPSA21567, retail): built as main + #759 (needed to boot this title on main) + this PR, then one scripted run headless from boot through the title screen. No error and no amdgpu fault came from this change.
    • Presents per 10 s on the title screen: 226, 232, 229; with main + #759 alone: 226, 229, 226.
    • The run then stops, with and without this PR, on storage image access to depth/stencil surface ... is not implemented (the gap #425 fills). So nothing past the title screen is covered.

AI-assisted: the runs and this write-up were done by Claude (Claude Code) on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060744820 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1412#issuecomment-6060744820). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-08T13:18:04Z. --- Tested on AMD under Linux, since this PR wasn't: RX 9070 XT (RDNA4, GFX1201), RADV / Mesa 26.2.4, Linux 7.2.9 (CachyOS), GCC Release build. - **`ctest`**: this PR merged onto `main` 07c2405c, all 453 tests pass with `ctest -j8` (main alone: 452/452 on the same machine). - **Astro Bot (PPSA21567, retail)**: built as `main` + #759 (needed to boot this title on `main`) + this PR, then one scripted run headless from boot through the title screen. No error and no amdgpu fault came from this change. - Presents per 10 s on the title screen: 226, 232, 229; with `main` + #759 alone: 226, 229, 226. - The run then stops, with and without this PR, on `storage image access to depth/stencil surface ... is not implemented` (the gap #425 fills). So nothing past the title screen is covered. AI-assisted: the runs and this write-up were done by Claude (Claude Code) on my machine.
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!1412
No description provided.