Skip to content

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

Open
Get-fix wants to merge 1 commit into
boykopovar:mainfrom
Get-fix:ps4/precompiled-shaders
Open

Get-fix wants to merge 1 commit into
boykopovar:mainfrom
Get-fix:ps4/precompiled-shaders

Conversation

@Get-fix

@Get-fix Get-fix commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

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:

Not tested on Linux or macOS.

Checklist

🤖 Generated with Claude Code

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Get-fix commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

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

@javierUDP javierUDP left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…sample uses

The OpenOrbis piglet sample loads libScePrecompiledShaders and looks up
"texmap/v_2.vert" and "texmap/f_2.frag" in scePrecompiledShaderEntries,
a table of 0x28-byte entries (name, size at 0x18, data at 0x20) that
ends with a null name, and passes the data to glShaderBinary. The
console table holds Sony's shader binaries, which AnyPS5 cannot ship.

The library now exports the table with AnyPS5's own two shaders under
those names, as GLSL ES 3.10 source behind an "APS5GLSL" line. They are
written from the interface the sample uses: a_vertex with the position
in xy and the texture coordinate in zw, the projection, model-view and
texture-space matrices, the opacity applied to alpha and the sampler.
@Get-fix
Get-fix force-pushed the ps4/precompiled-shaders branch from 2f779a5 to 0b42ec3 Compare October 21, 2026 16:23
@Get-fix

Get-fix commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

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 cecb540 (now 0b42ec3), 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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants