feat(libScePrecompiledShaders): export the texmap shaders the piglet sample uses #6520

Closed
Get-fix wants to merge 1 commit from upstream-pr/6520 into main
Get-fix commented 2026-10-15 18:36:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T18:36:45Z.


What

The OpenOrbis piglet sample draws with the PS4 GLES library, libScePigletv2VSH, and takes its shaders from libScePrecompiledShaders: it looks up texmap/v_2.vert and texmap/f_2.frag in the exported table scePrecompiledShaderEntries and passes their data to glShaderBinary. The table is an array of 0x28-byte entries (name at 0x0, size at 0x18, data at 0x20) that ends with a null name. AnyPS5 has no libScePrecompiledShaders, and the console table holds Sony's compiled shaders, which AnyPS5 cannot ship.

This adds the library with a table of AnyPS5's own two shaders under those names. Each is GLSL ES 3.10 source behind an APS5GLSL line, a format of AnyPS5's own that the Piglet library in #6521 compiles with glslang; a PS4 binary given to that glShaderBinary throws. The shaders are written from the interface the sample uses:

  • the attribute a_vertex, with the position in xy and the texture coordinate in zw;
  • u_projectionMatrix, u_modelViewMatrix and u_textureSpaceMatrix;
  • u_opacity, applied to alpha, as the sample's GL_SRC_ALPHA blending expects;
  • s_sampler.

What the console shaders compute, the other names in the console table and the entry fields at 0x8 and 0x10 are unknown; they are recorded in the new docs/dev/debt/libScePrecompiledShaders.md. Part of the PS4 homebrew work tracked in #3093.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main 03c4cb5e7:

  • The new guest_precompiled_shaders test walks the table to its null entry and checks the two names, that the reserved fields are 0, and that each size is the length of the source without its terminator. It compiles and links both shaders with glslang and checks the reflected interface: the three mat4 matrices, the float opacity, the sampler2D, and a_vertex as the only vec4 input. It also checks that the fragment shader produces SPIR-V.
  • Each of these makes the test fail: a size that counts the terminator, the vertex entry under another name, the fragment source without its APS5GLSL line, the opacity not applied, the texture-space matrix not applied. Reading the position from zw instead of xy is caught only by guest_piglet in #6521, which renders with these shaders.
  • The OpenOrbis piglet sample on main 03c4cb5e7 with this, #6519, #6521, #5990 to #5994, #6376, #5138 and a change that answers the Linux TIOCGWINSZ with ENOTTY, as #5569 did: it finds both shaders (Found shader texmap/v_2.vert ... of size 342, Found shader texmap/f_2.frag ... of size 263) and draws at 59.96 FPS. With neither this library nor Piglet's, it stops at start-up with 48 FAIL: unresolved ELF import lines, the first Q-JroQdKRfM (scePrecompiledShaderEntries) and one for each Piglet function.
  • Full ctest of the branch of #6521, which contains this commit, on main 03c4cb5e7: 1296 of 1300 pass. agc_driver_gpu_indirect_arguments_misaligned_writer_ahead does not compile with MinGW on main (#6452 fixes it), and prx_thread_local_destructors fails as it did on main 92cdc7b62 on this machine without my changes; agc_shader_disk_cache (timeout) and agc_driver_multisample_fill_host_only failed under ctest -j8 and pass when run alone. Full ctest of the build with all my open pull requests: 1304 of 1306 pass; the two that do not are the first two above.
  • tools/check_conventions.py passes.

Not tested on Linux or macOS.

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 for the code; the piglet sample also needs #6519 and #6521
  • Unblocks: OpenOrbis PS4 toolchain sample piglet, #3093
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4878093488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-15T18:36:45Z. --- ### What The OpenOrbis piglet sample draws with the PS4 GLES library, libScePigletv2VSH, and takes its shaders from `libScePrecompiledShaders`: it looks up `texmap/v_2.vert` and `texmap/f_2.frag` in the exported table `scePrecompiledShaderEntries` and passes their data to `glShaderBinary`. The table is an array of 0x28-byte entries (name at 0x0, size at 0x18, data at 0x20) that ends with a null name. AnyPS5 has no `libScePrecompiledShaders`, and the console table holds Sony's compiled shaders, which AnyPS5 cannot ship. This adds the library with a table of AnyPS5's own two shaders under those names. Each is GLSL ES 3.10 source behind an `APS5GLSL` line, a format of AnyPS5's own that the Piglet library in #6521 compiles with glslang; a PS4 binary given to that `glShaderBinary` throws. The shaders are written from the interface the sample uses: - the attribute `a_vertex`, with the position in `xy` and the texture coordinate in `zw`; - `u_projectionMatrix`, `u_modelViewMatrix` and `u_textureSpaceMatrix`; - `u_opacity`, applied to alpha, as the sample's `GL_SRC_ALPHA` blending expects; - `s_sampler`. What the console shaders compute, the other names in the console table and the entry fields at 0x8 and 0x10 are unknown; they are recorded in the new `docs/dev/debt/libScePrecompiledShaders.md`. Part of the PS4 homebrew work tracked in #3093. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on `main` `03c4cb5e7`: - The new `guest_precompiled_shaders` test walks the table to its null entry and checks the two names, that the reserved fields are 0, and that each size is the length of the source without its terminator. It compiles and links both shaders with glslang and checks the reflected interface: the three `mat4` matrices, the `float` opacity, the `sampler2D`, and `a_vertex` as the only `vec4` input. It also checks that the fragment shader produces SPIR-V. - Each of these makes the test fail: a size that counts the terminator, the vertex entry under another name, the fragment source without its `APS5GLSL` line, the opacity not applied, the texture-space matrix not applied. Reading the position from `zw` instead of `xy` is caught only by `guest_piglet` in #6521, which renders with these shaders. - The OpenOrbis piglet sample on `main` `03c4cb5e7` with this, #6519, #6521, #5990 to #5994, #6376, #5138 and a change that answers the Linux `TIOCGWINSZ` with `ENOTTY`, as #5569 did: it finds both shaders (`Found shader texmap/v_2.vert ... of size 342`, `Found shader texmap/f_2.frag ... of size 263`) and draws at 59.96 FPS. With neither this library nor Piglet's, it stops at start-up with 48 `FAIL: unresolved ELF import` lines, the first `Q-JroQdKRfM` (`scePrecompiledShaderEntries`) and one for each Piglet function. - Full ctest of the branch of #6521, which contains this commit, on `main` `03c4cb5e7`: 1296 of 1300 pass. `agc_driver_gpu_indirect_arguments_misaligned_writer_ahead` does not compile with MinGW on `main` (#6452 fixes it), and `prx_thread_local_destructors` fails as it did on `main` `92cdc7b62` on this machine without my changes; `agc_shader_disk_cache` (timeout) and `agc_driver_multisample_fill_host_only` failed under `ctest -j8` and pass when run alone. Full ctest of the build with all my open pull requests: 1304 of 1306 pass; the two that do not are the first two above. - `tools/check_conventions.py` passes. Not tested on Linux or macOS. ### 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 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 for the code; the piglet sample also needs #6519 and #6521 - [x] Unblocks: OpenOrbis PS4 toolchain sample piglet, #3093 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-15 20:19:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T20:19:16Z.

Review: COMMENTED


Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head 2f779a57e merged onto main 44df21632. The description says it was not tested on Linux.

  • The new library configures, builds and passes NID patching (OK: .../libScePrecompiledShaders.prx); guest_precompiled_shaders passes, including the glslang compile and link of both shaders.
  • No red run: the library is new, so the test cannot build without it.

Non-GPU suite (ctest -E "^agc"): same result as main; only file_writer_binary and file_writer_text fail, and they fail on main too on this machine (Ubuntu 26.04 coreutils).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5539355534 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520#pullrequestreview-5539355534). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-15T20:19:16Z. **Review:** COMMENTED --- Linux run (Ubuntu 26.04, Intel i7-8700, GCC 15.2, full build, non-GPU tests), head `2f779a57e` merged onto `main` `44df21632`. The description says it was not tested on Linux. - The new library configures, builds and passes NID patching (`OK: .../libScePrecompiledShaders.prx`); `guest_precompiled_shaders` passes, including the glslang compile and link of both shaders. - No red run: the library is new, so the test cannot build without it. Non-GPU suite (`ctest -E "^agc"`): same result as `main`; only `file_writer_binary` and `file_writer_text` fail, and they fail on `main` too on this machine (Ubuntu 26.04 coreutils). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Get-fix commented 2026-10-15 23:26:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:26:39Z.


Thanks for the Linux run, @jotitadev. Good to know glslang compiles and links both shaders there too.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6204397180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520#issuecomment-6204397180). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-15T23:26:39Z. --- Thanks for the Linux run, @jotitadev. Good to know glslang compiles and links both shaders there too. AI-assisted: yes (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
javierUDP commented 2026-10-19 19:05:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-19T19:05:35Z.

Review: COMMENTED


Static review of this PR and of #6519, both read against the OpenOrbis piglet sample rather than executed: the full build does not configure on macOS, so I could not compile or run either one. I found nothing to change in either. Recording what I checked so the next reader does not repeat it.

The entry names match the sample. strings on samples/piglet/.../piglet.elf from samples-elf-llvm-18.zip (v0.5.3) contains exactly texmap/v_2.vert and texmap/f_2.frag, the two entries this PR exports, and no other shader path.

The symbol kind matches how the sample imports it. relinker --registry on that sample resolves scePrecompiledShaderEntries as R_X86_64_GLOB_DAT, so the importer expects data, which is what scePrecompiledShaderEntries_nid_postfix[] provides; scePigletSetConfigurationVSH comes through as R_X86_64_JUMP_SLOT, a function, matching #6521.

The source marker is produced and consumed consistently. SourceMagic is written by both entries here and checked in #6521 at Context.cpp:342, which refuses a binary without it and strips it before handing the text to glslang, so the APS5GLSL\n prefix never reaches the compiler.

On #6519: SystemLibraryPath rejects a name with a path separator, which keeps /common/lib/../x.sprx out, and the test covers that case along with a missing module and a .prx suffix. sceKernelGetFsSandboxRandomWord returns a static constant, so the sandbox prefix cannot be built from a null pointer, and the same concatenation already appears in SandboxCertificates.cpp.

I did not review the GLES state machine in #6521 beyond what I commented there.

Written with AI assistance. The sample cross-checks above were run on my own machine; nothing was compiled or executed from these PRs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5576363538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520#pullrequestreview-5576363538). Originally posted by [javierUDP](https://github.com/javierUDP) on 2026-10-19T19:05:35Z. **Review:** COMMENTED --- Static review of this PR and of #6519, both read against the OpenOrbis `piglet` sample rather than executed: the full build does not configure on macOS, so I could not compile or run either one. I found nothing to change in either. Recording what I checked so the next reader does not repeat it. **The entry names match the sample.** `strings` on `samples/piglet/.../piglet.elf` from `samples-elf-llvm-18.zip` ([v0.5.3](https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/releases/tag/v0.5.3)) contains exactly `texmap/v_2.vert` and `texmap/f_2.frag`, the two entries this PR exports, and no other shader path. **The symbol kind matches how the sample imports it.** `relinker --registry` on that sample resolves `scePrecompiledShaderEntries` as `R_X86_64_GLOB_DAT`, so the importer expects data, which is what `scePrecompiledShaderEntries_nid_postfix[]` provides; `scePigletSetConfigurationVSH` comes through as `R_X86_64_JUMP_SLOT`, a function, matching #6521. **The source marker is produced and consumed consistently.** `SourceMagic` is written by both entries here and checked in #6521 at `Context.cpp:342`, which refuses a binary without it and strips it before handing the text to glslang, so the `APS5GLSL\n` prefix never reaches the compiler. On #6519: `SystemLibraryPath` rejects a name with a path separator, which keeps `/common/lib/../x.sprx` out, and the test covers that case along with a missing module and a `.prx` suffix. `sceKernelGetFsSandboxRandomWord` returns a static constant, so the sandbox prefix cannot be built from a null pointer, and the same concatenation already appears in `SandboxCertificates.cpp`. I did not review the GLES state machine in #6521 beyond what I commented there. Written with AI assistance. The sample cross-checks above were run on my own machine; nothing was compiled or executed from these PRs.
Get-fix commented 2026-10-21 21:51:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-21T21:51:23Z.


Thanks @javierUDP for checking the entry names, the symbol kinds and the source marker against the sample. Doing that from the sample itself is the check this PR needed.

The branch is rebased onto main cecb540a6 (now 0b42ec382), with #6521 on top of it. #6519 has merged, so the piglet sample now needs only this PR and #6521. guest_precompiled_shaders passes on Windows 11, and check_conventions.py passes.

AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6327346957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520#issuecomment-6327346957). Originally posted by [Get-fix](https://github.com/Get-fix) on 2026-10-21T21:51:23Z. --- Thanks @javierUDP for checking the entry names, the symbol kinds and the source marker against the sample. Doing that from the sample itself is the check this PR needed. The branch is rebased onto `main` cecb540a6 (now 0b42ec382), with #6521 on top of it. #6519 has merged, so the piglet sample now needs only this PR and #6521. `guest_precompiled_shaders` passes on Windows 11, and `check_conventions.py` passes. AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-21 03:22:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:22:52Z.

Review: APPROVED


Reviewed — looks good

The changed files are readable and the library is included by the existing PRX build loop; author-reported tests and runtime checks were not rerun here.

What I ran

Reviewed head 0b42ec38273c7638cd11f98acb0a962f55e74f6f. I read the prepared description, commits, diff and manifest, all five changed files, and the relevant PRX target-discovery section of core/libs/CMakeLists.txt. No build or tests were run.

Results

Check Result Note
Changed source review passed All five changed files read
PRX target discovery passed Existing CMake loop adds the target
Build and tests not run Claims in description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The reported Windows build, ctest results, convention check and Piglet sample runtime were not independently verified. Linux and macOS behavior was not tested. No files were excluded by the manifest; all five files marked reviewed were read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002526596 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6520#pullrequestreview-6002526596). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T03:22:52Z. **Review:** APPROVED --- # Reviewed — looks good The changed files are readable and the library is included by the existing PRX build loop; author-reported tests and runtime checks were not rerun here. ## What I ran Reviewed head `0b42ec38273c7638cd11f98acb0a962f55e74f6f`. I read the prepared description, commits, diff and manifest, all five changed files, and the relevant PRX target-discovery section of `core/libs/CMakeLists.txt`. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed source review | passed | All five changed files read | | PRX target discovery | passed | Existing CMake loop adds the target | | Build and tests | not run | Claims in description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The reported Windows build, ctest results, convention check and Piglet sample runtime were not independently verified. Linux and macOS behavior was not tested. No files were excluded by the manifest; all five files marked reviewed were read. ## To get this to a good state Nothing is required.

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