feat(libScePigletv2VSH): implement the EGL and GLES 2 calls of the piglet sample #6521
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6521"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T18:36:50Z.
What
The OpenOrbis piglet sample renders through the PS4 GLES library
libScePigletv2VSH, which AnyPS5 does not have. It imports 47 functions from it:scePigletSetConfigurationVSH, 13 EGL 1.4 functions and 33 OpenGL ES 2.0 functions. It loads the library andlibScePrecompiledShaderswithsceKernelLoadStartModuleand passes the shaders from #6520 toglShaderBinary.This adds
libScePigletv2VSHwith those 47 functions on Vulkan. The first commit is #6520; this pull request adds the second one.glShaderBinarytakes AnyPS5's GLSL ES source from #6520;glLinkProgramcompiles it with glslang to SPIR-V, packs the loose uniforms into one uniform buffer and binds the samplers as combined image samplers. A PS4 shader binary throws.glPixelStoreiunpack alignment and theGL_RGBA,GL_RGB,GL_LUMINANCE,GL_LUMINANCE_ALPHAandGL_ALPHAtexel formats are handled. A texture whose minifying filter needs mipmaps it does not have samples as incomplete, as OpenGL ES requires. The Y axis is flipped with a negative viewport height, and OpenGL's clip-space depth is kept where the device hasVK_EXT_depth_clip_control.eglCreateWindowSurfaceopens a VideoOut port and registers two linear R8G8B8A8 buffers.eglSwapBufferscopies the frame into the next buffer once no flip is pending and submits the flip, on vblank for swap interval 1 and on hsync for 0. The sample callseglSwapIntervalbefore it has a context, so that call succeeds and sets the interval of the next surface.glGetErrorandeglGetErrorreport it. What the sample does not use throws, among it cube maps, mipmap levels other than 0, texel types other thanGL_UNSIGNED_BYTE, shared contexts andGL_LINE_LOOP;eglChooseConfigfinds no config with depth or stencil.__cxa_throw,_Unwind_*) then binds tolibc.prx, so exceptions thrown here reach the caller's handlers. glslang'sstd::stringmembers bind to libstdc++, because the import library lists 12 of them thatlibc.prxdoes not export, which made the library fail to load with error 127.The limits are in the new
docs/dev/debt/libScePigletv2VSH.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, onmain03c4cb5e7:guest_piglettest creates a 64x64 offscreen surface, links the two shaders from the table and renders five frames, checking pixels in each: a 2x2 RGBA texture on the left half (the four texels in place and the clear colour elsewhere); the same with opacity 0.5 andGL_SRC_ALPHAblending; a mipmapping filter without mipmaps (black); a 32x32 viewport; an RGB texture with the default 4-byte row alignment. It also checks EGL initialization, config choice,eglSwapIntervalwithout a context, the reflected attribute and uniforms, the GL errors of invalid calls, and that a PS4 shader binary throws an exception the test catches.glViewport, writingglUniform1fat offset 0, accepting a PS4 binary as source,eglSwapIntervalfailing without a context.libScePigletv2VSH.prxexports exactly the 47 functions the sample imports, and imports fromlibc.prxonly functions the patchedlibc.prxexports.main03c4cb5e7with this, #6519, #5990 to #5994, #6376, #5138 and a change that answers the LinuxTIOCGWINSZwithENOTTY, as #5569 did: it loads both modules, printsGL_RENDERER: AnyPS5 Piglet on Vulkan, finds both shaders and draws its rotating textured square at 59.96 FPS (window titleOpenOrbis piglet sample | FPS: 59.96 (666)). With neither library, it stops at start-up with 48FAIL: unresolved ELF importlines, one for each function and one forscePrecompiledShaderEntries. The 14 other samples that start with my open pull requests still start.main03c4cb5e7: 1296 of 1300 pass.agc_driver_gpu_indirect_arguments_misaligned_writer_aheaddoes not compile with MinGW onmain(#6452 fixes it), andprx_thread_local_destructorsfails as it did onmain92cdc7b62on this machine without my changes;agc_shader_disk_cache(timeout) andagc_driver_multisample_fill_host_onlyfailed underctest -j8and 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.pypasses.Not tested on Linux or macOS.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T18:37:37Z.
Progress report (
cecb540→95b1f00)📈 System libraries: 42.35% (+0.25%, +47 implemented functions)
✅ 47 implemented
eglBindAPIeglChooseConfigeglCreateContexteglCreateWindowSurfaceeglDestroyContexteglDestroySurfaceeglGetDisplayeglGetErroreglInitializeeglMakeCurrenteglSwapBufferseglSwapIntervaleglTerminateglActiveTextureglAttachShaderglBindTextureglBlendFuncglClearglClearColorglCreateProgramglCreateShaderglDeleteProgramglDeleteShaderglDeleteTexturesglDrawArraysglEnableglEnableVertexAttribArrayglGenTexturesglGetActiveAttribglGetActiveUniformglGetAttribLocationglGetErrorglGetProgramivglGetStringglGetUniformLocationglLinkProgramglPixelStoreiglShaderBinaryglTexImage2DglTexParameteriglUniform1fglUniform1iglUniformMatrix4fvglUseProgramglVertexAttribPointerglViewportscePigletSetConfigurationVSHImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T22:16:03Z.
Review: COMMENTED
A Linux run, since the description lists none.
Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, Ubuntu 26.04 (kernel 7.0.0-38), i7-8700. GCC 15.2, Release,
BUILD_TESTING=ON. Heade983d881fmerged ontomain31cbb55d7, no conflicts. After reconfiguring for the new library, the build finishes with no warnings.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), Linux; llvmpipe (Mesa 26.0.3), Linux
guest_pigletandguest_precompiled_shaderspass 3/3 withANYPS5_GPU="NVIDIA GeForce RTX 3070", 3/3 withANYPS5_GPU=llvmpipe, and 3/3 withANYPS5_GPUunset (both ICDs installed). WithANYPS5_GPU=NoSuchGPU,guest_pigletis skipped withno Vulkan 1.1 graphics device matches ANYPS5_GPU=NoSuchGPU, so the selector filters on Linux as well. The 3070 exposesVK_EXT_depth_clip_control, so that path is the one taken here.Context.cpp(originviewport[1], positive height),guest_pigletfails on the RTX 3070 at the first frame's texel check (Piglet check failed at line 204). With the flip restored, it passes.ctest -R "^agc" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64" -j1 --timeout 60: 591/593 pass, the same result as unchangedmainon this machine.agc_driver_stencil_ref_exportis skipped (noVK_EXT_shader_stencil_export), andagc_driver_store_over_untrackedfails as it does onmain(#6385).I did not run the OpenOrbis piglet sample itself.
Written with AI assistance (Claude Code). I ran the tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-15T23:26:43Z.
Thank you for the thorough Linux run, @jotitadev: two GPUs, the
ANYPS5_GPUselector, and the fault check with the Y flip taken out. It's good to know theVK_EXT_depth_clip_controlpath works on the RTX 3070, and that llvmpipe passes too.AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-19T18:30:03Z.
Review: COMMENTED
Static review on macOS, head of this branch. I could not build or run any of it: these libraries need the full build, which does not configure on macOS, so everything below comes from reading the code and from the OpenOrbis
pigletsample, not from execution.eglCreateWindowSurfaceleaks its Vulkan objects on every error path.ImageandBuffer(include/Vulkan.hpp) are plain structs with no destructor; they are released explicitly, asDestroySurfaceNowdoes withDestroyImage,DestroyBufferandvkDestroyFramebuffer.EglCreateWindowSurfacecreates the colour image, the readback buffer and the framebuffer, and only then reaches three statements that throw:Check(device.vkCreateFramebuffer(...), "vkCreateFramebuffer")if (created->videoOut < 0) throw ... sceVideoOutOpen failedif (sceVideoOutRegisterBuffers2(...) < 0) throw ... failedWhen one of them throws,
std::unique_ptr<WindowSurface>deletes the object without touching the handles, so aVkImage, itsVkDeviceMemoryandVkImageView, theVkFramebuffer, and the readbackVkBufferwith its memory are all lost.A title that creates a second window surface while the first is alive reaches this: the second
sceVideoOutOpenfails, and each retry leaks that set again. EGL allows more than one window surface, so this is not only a malformed-input path.Releasing what was created before rethrowing, or giving
Surfacethe destructor thatDestroySurfaceNowcurrently open-codes, would close all three at once.What I checked and found correct, in case it saves someone repeating it:
pigletsample of OpenOrbissamples-elf-llvm-18.zipimports exactly those 46, with nothing missing and nothing unused. I took the import list fromrelinker --registryon the sample.Describe()bounds its copy withmin(item.name.size(), bufferSize - 1)and writes the terminator inside the buffer, soglGetActiveAttribandglGetActiveUniformdo not overrun a caller buffer.lastErroristhread_local, as EGL requires, andobjectsMutexis held across thesurfacesandcontextsupdates ineglMakeCurrent.I did not review
Context.cpp's GLES state machine beyond the queries above, the glslang path inProgram.cpp, or the two companion PRs.Written with AI assistance. The import cross-check above was run on my own machine; nothing here was executed.
Imported from boykopovar/AnyPS5. Originally posted by javierUDP on 2026-10-19T18:30:04Z.
Code review location:
core/libs/prx/libScePigletv2VSH/src/Egl.cpp; line 155This throw, the one below it and the
CheckonvkCreateFramebufferall run after the colour image, the readback buffer and the framebuffer exist, andImage/Bufferhave no destructor, so unwinding here drops those handles. A second window surface created while the first is open reaches it throughsceVideoOutOpen.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T17:27:15Z.
Thanks, this builds and both guest tests pass for us on current main (NVIDIA, Linux).
One change before merge, the same point javierUDP raised: in
EglCreateWindowSurface(Egl.cpp), the colour image, readback buffer and framebuffer are created before three calls that can throw (vkCreateFramebufferat :152,sceVideoOutOpenat :155,sceVideoOutRegisterBuffers2at :165).WindowSurfacehas no destructor, so whencreatedgoes out of scope on a throw those Vulkan objects leak, and after asceVideoOutRegisterBuffers2failure the VideoOut port stays open, so every later attempt fails atsceVideoOutOpen. Could you release them on those paths, for example by givingWindowSurfacea destructor that does whatDestroySurfaceNowdoes (and havingDestroySurfaceNowrely on it)?Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T20:40:22Z.
There are four more problems besides the
eglCreateWindowSurfaceerror-path leak already raised.1.
eglDestroyContextfrees none of the context's Vulkan objects.Contexthas no destructor (Context.hpp#L87).Image,BufferandProgramhold raw handles, sodelete target(Egl.cpp#L272) anddelete previousineglMakeCurrent(Egl.cpp#L206) free only the containers. Each destroyed context leaks:incompleteimageA title that repeats
eglCreateContext,eglMakeCurrent, one texmapglDrawArrays,eglSwapBuffers,eglMakeCurrent(EGL_NO_CONTEXT)andeglDestroyContextloses at least 8 MiB of host-visible memory and threeVkDeviceMemoryallocations per round, until an allocation fails.Device::Submitwaits on its fence, so a destructor can free everything directly.vkFreeCommandBuffersandvkDestroyDescriptorPoolhave to be added toPIGLET_DEVICE_FUNCTIONSfirst:2.
eglDestroySurfacefrees the display buffers while the last flip may still read them.DestroySurfaceNowcloses the port, thendelete windowfreesstorage, which holds the two buffers registered withsceVideoOutRegisterBuffers2(Egl.cpp#L71).eglSwapBufferswaits forflipPendingNum == 0only before its next copy (Egl.cpp#L243), so the last flip is normally still pending when the surface is destroyed.On current main,
processFlipreleases the port's mutex after its vblank wait (VideoOutDriver.cpp#L551-L559). It then presents the buffer (L584), which reads a linear buffer throughReadDisplayBuffer(VulkanDevice.cpp#L3128).close()(L381) only setsclosingand does not wait for a presentation that is already past that point.flipPendingNumdrops only after the read (L615).So suppose
eglSwapBuffersis followed byeglMakeCurrent(EGL_NO_CONTEXT)andeglDestroySurface, and they land after that vblank but before the presenter has read the frame. The presenter then reads a freed block of about 8 MiB at 1920x1080. If the allocator has already given that block back to the system,CheckRangethrows or the read faults, and the presentation thread ends the process. Waiting the wayeglSwapBuffersdoes before closing avoids this, and the same order fits theWindowSurfacedestructor requested above:3. A 1x1 texture with a mipmap minifying filter samples as incomplete, including with the default
GL_NEAREST_MIPMAP_LINEAR.SampledTexturereturnsincompletefor any mipmap filter, whatever the texture size (Context.cpp#L293). The OpenGL ES 2.0glTexParameterpage says that a w x h texture has floor(log2(max(w, h))) + 1 mipmap levels, and that level floor(log2(max(w, h))) is the final 1x1 mipmap (es2.0/glTexParameter.xml#L161-L310). It returns (0, 0, 0, 1) only when "there are fewer texture images defined than are needed" (L548-L557). For a 1x1 texture, level 0 is the whole chain, so the texture is complete.Example: create a white 1x1
GL_RGBAtexture withglTexImage2D, call noglTexParameteri, and draw with texmap. OpenGL ES draws white; this draws black. The mipmap frame inguest_pigletuses the 2x2 texture, so it does not cover this case. Fix: change the condition toMipmapFilter(found->second.minFilter) && (found->second.width > 1 || found->second.height > 1).4.
maxLod = 0makes every sampler use the magnifying filter (Context.cpp#L308). The Vulkan spec note "Mapping of OpenGL to Vulkan Filter Modes" (samplers.adoc#L145-L172) emulates theGL_NEARESTandGL_LINEARminifying filters withVK_SAMPLER_MIPMAP_MODE_NEAREST,minLod = 0andmaxLod = 0.25. It also says that "using a maxLod of zero would cause magnification to always be performed, and the magFilter to always be used", which only works when the two filters are equal. SoGL_TEXTURE_MIN_FILTERis ignored whenever it differs from the magnifying filter.Example: set
GL_TEXTURE_MIN_FILTERtoGL_NEAREST, keep the defaultGL_TEXTURE_MAG_FILTER(GL_LINEAR), and draw a 64x64 checkerboard of single black and white texels into a 16x16 quad. OpenGL ES returns single texels (0 or 255); this blends neighbouring texels into grey.guest_pigletsets both filters toGL_NEAREST, so it cannot catch this. Fix:info.maxLod = 0.25f;.Imported from boykopovar/AnyPS5. Originally posted by Get-fix on 2026-10-21T21:51:22Z.
Thanks @oneandonlydean, @nikowolf123 and @javierUDP. All five points are fixed in Get-fix/AnyPS5@95b1f0029, and the branch is rebased onto
maincecb540a6(#6520 with it, since this one stacks on it):eglCreateWindowSurfaceerror paths.WindowSurfacenow has the destructorDestroySurfaceNowused to open-code: it releases the framebuffer, color image and readback buffer, and closes the VideoOut port. A throw fromvkCreateFramebuffer,sceVideoOutOpenorsceVideoOutRegisterBuffers2no longer leaks them, and the port no longer stays open after a failed registration.DestroySurfaceNownow just erases and deletes.eglDestroyContext.Contexthas a destructor that releases its programs and pipelines, retired and live textures, the incomplete texture, samplers, descriptor pools, ring chunks and its command buffer (vkDestroyDescriptorPoolandvkFreeCommandBuffersadded toPIGLET_DEVICE_FUNCTIONS).eglDestroySurfaceduring the last flip. The surface destructor waits untilflipPendingNumis 0 beforesceVideoOutClose, so the display buffers are freed only after the presenter has read them.maxLodis 0.25, soGL_TEXTURE_MIN_FILTERapplies when it differs from the magnifying filter.guest_pigletgains a 1x1 white texture drawn with the defaultGL_NEAREST_MIPMAP_LINEAR(white, not black), a 64x64 checkerboard minified 4:1 withGL_NEARESTand the defaultGL_LINEARmagnifying filter (only 0 or 255, no grey), and a second context created and destroyed while the first keeps drawing. Reverting fix 4 fails the test at the white texture, and reverting fix 5 at the checkerboard. Onmaincecb540a6with this branch,guest_pigletandguest_precompiled_shaderspass on Windows 11 with an RTX 5060 Ti (610.88), andcheck_conventions.pypasses for both branches. The long debt entry is split into three, each under 1000 characters.AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:22:04Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure programs with no active uniforms do not attempt to allocate a zero-sized uniform buffer.
What I ran
Reviewed head
95b1f0029a4e0b75e73a87bfcb27d24976df5733against the prepared diff and read changed source throughrepo_read.py. No build or tests were run; test results in the description are author-reported.Results
Findings
Blocking
uniformBindingremains-1anduniformDataremains empty.DrawArraysstill callsAllocatefor a zero-sized uniform buffer when that binding is present;Allocatethen creates a buffer of at least 4 MiB and copies zero bytes, but later writes a descriptor with range zero. Vulkan requires a nonzero uniform buffer descriptor range, so drawing with such a program reaches invalid descriptor state and can fail validation or rendering. Skip the uniform buffer allocation and descriptor write when the block size is zero, or otherwise ensure a valid nonzero range. Seecore/libs/prx/libScePigletv2VSH/src/Context.cpp:1559.Non-blocking
None.
Not verified
No build, tests, or hardware execution were performed. The description reports Windows tests and sample execution, but those results were not independently verified. Linux and macOS behavior was not tested according to the description. I read the prepared description, commits, manifest and diff, plus the changed Piglet EGL, context, shader program, Vulkan, and guest test code; all 16 manifest-listed files are included, but the full text of every changed file was not read. The excluded-file list was unavailable in the prepared bundle.
To get this to a good state
Guard uniform buffer descriptor allocation when no uniform block exists, then rerun the relevant guest Piglet test and build checks on the updated head.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.