Skip to content

fix(vita): Fix blit rendering and shader loading#48

Open
cerwym wants to merge 18 commits intodevelopfrom
feature/vita-hardware-acceleration
Open

fix(vita): Fix blit rendering and shader loading#48
cerwym wants to merge 18 commits intodevelopfrom
feature/vita-hardware-acceleration

Conversation

@cerwym
Copy link
Owner

@cerwym cerwym commented Mar 10, 2026

This pull request introduces improvements to the development environment, adds new automation and safety measures for git workflows, and simplifies the build configuration for the Vita platform. The most significant changes are the addition of git hooks to protect the master branch, enhancements to the VSCode task automation for Vita development, and the removal of the VITA_ENABLE_VITAGL option from the build system.

Git workflow protection and automation:

  • Added .githooks/pre-commit, .githooks/pre-push, and .githooks/post-checkout scripts to prevent direct commits and non-fast-forward pushes to master, and to warn about improper pushes to upstream. These scripts help enforce branch discipline and protect the integrity of the upstream mirror. [1] [2] [3]
  • Introduced new VSCode tasks for setting up git hooks, syncing repos, and creating upstream PR branches, providing easier fork management and automation for developers.

Vita development environment enhancements:

  • Added bind-mounts for sibling Vita reference repositories in .devcontainer/devcontainer.json files, making it easier to access read-only reference code during development. [1] [2] [3]
  • Expanded VSCode tasks for Vita development, including crash dump parsing, plugin setup, deployment, log fetching, and live log streaming with PrincessLog. These tasks streamline common workflows and improve developer productivity. [1] [2] [3]

Build system simplification for Vita:

  • Removed the VITA_ENABLE_VITAGL option from CMakeLists.txt and CMakePresets.json, making vitaGL always enabled for Vita builds and simplifying configuration. Also updated documentation to reflect this change. [1] [2] [3] [4] [5] [6] [7] [8] [9]
  • Excluded the SDL-based window system from homebrew platform builds, ensuring only platform-specific implementations are used.

These updates collectively improve development safety, streamline workflows, and clarify the build process for Vita and related platforms.

cerwym added 18 commits March 8, 2026 18:45
- .githooks/pre-commit: blocks direct commits to master
- .githooks/pre-push: blocks diverged master pushes and develop-to-upstream
- .githooks/post-checkout: reminds you when on master
- tools/setup-hooks.ps1: one-time setup (hooks, upstream remote, tracking)
- tools/sync-repos.ps1: sync upstream → master → develop → rebase vita
- tools/upstream-pr.ps1: cherry-pick commits into clean upstream PR branch
…port

- Parse Vita Crash Dump and Parse Local Crash Dump tasks now use the
  bash script natively in Linux containers, with Windows PowerShell
  fallback via the 'windows' override.
- Both tasks auto-open crash_report.html in VS Code after completion.
…wser

- Add --open flag to vita_crash Python tool that spins up a temporary
  HTTP server and opens the report via $BROWSER (VS Code Simple Browser
  in devcontainers, system browser on host).
- Update bash wrapper to pass --open through.
- Update VS Code tasks to use --open instead of 'code' raw open.
- Fix NOTE type constants: use 0x1003/0x1004/0x1005 instead of 1/3/6
- Rewrite _parse_thread_info with correct 200-byte entry layout
  (tid+0, name+4, pc+48, stop_reason+112)
- Rewrite _parse_thread_reg_info with correct register offsets
  (R0-R12 at +4..+52, SP+56, LR+60, PC+64)
- Rewrite _parse_module_info for variable-length entries
  (76-byte header + num_segs*20 segments + 20 trailing)
- Accumulate entities across multiple PT_NOTE segments
- Handle truncated final entries in thread/reg descriptors
- Remove DWARF stack walk (hangs on 32MB ELF with pyelftools)
- Prioritize thread-info PC as frame #0 in stack trace
- Include register PC and LR before heuristic scan results

All 4 test dumps now produce correct reports with symbolicated
crash locations via addr2line.
…havior

- Add tools/vita-companion.sh for vitacompanion plugin management
- Add new VS Code tasks for vita companion setup, deploy, and build+deploy
- Configure port 18080 in workspace settings for crash report preview
- Simplify crash report --open to use webbrowser.open (opens in host browser)
Two bugs caused vitaGL to always report init failure:

1. SystemInit pre-loaded libshacccg.suprx before vglInitExtended.
   When vitaGL's internal vitaSHARK then tried to load the same path,
   the kernel returned SCE_KERNEL_ERROR_MODULEMGR_OLD_LIB (0x8002D013) —
   it version-checks the already-mapped module against vitaSHARK's import
   stubs and rejects it. First-time loads by vitaSHARK skip this check.
   Fix: remove the pre-load entirely (matches vitaQuakeIII / d3es-vita).

2. vglInitExtended return value was checked as (== GL_TRUE), but the
   function returns res_fallback — GL_FALSE on a normal successful init
   (exact resolution used), GL_TRUE only if the resolution was clamped.
   Neither vitaQuakeIII nor d3es-vita check the return value at all.
   Fix: ignore the return value, set s_vita_video_ready = GL_TRUE always
   (a GXM context failure would be caught by the SCE_DIAG hook log).

Also adds fetch-logs subcommand to vita-companion.sh and a matching
VS Code task to pull kfx_boot.log, kfx_preinit.log, vitaGL.log and
keeperfx.log from the device in one step.
…it FBO/viewport/texture binds

vitaGL.log revealed two rendering bugs causing the black screen:

1) RAM starvation: vglInitExtended(ram_threshold=0x1000000) calls
   sceKernelGetFreeMemorySize() and computes pool = size_user - threshold.
   kfx_preinit.log showed KfxAlloc(32MB)=OK, meaning ~32MB free user RAM.
   With 16MB threshold vitaGL only got ~16MB, but the log also showed
   'vglMalloc failed allocating 0xFEBE9FF4 bytes' (≈ -2MB signed underflow)
   which means actual free user RAM was slightly below the threshold — vitaGL
   got 0 bytes of heap. All glTexImage2D calls silently failed; textures were
   invalid; the draw call was skipped by vitaGL's sceGxmTextureValidate check.
   Fix: lower ram_threshold to 0x400000 (4MB) for all MSAA modes so vitaGL
   gets ~28MB+ of allocatable RAM.

2) Missing explicit viewport + framebuffer bind in the direct-to-screen path:
   The glBindFramebuffer(0) + glViewport(0,0,960,544) calls were only present
   in the gpu_passes!=empty branch; the direct path had neither, leaving the
   viewport state wherever vitaGL last set it.
   Fix: always bind FBO 0 and set the display viewport before the blit.

3) Texture units not explicitly rebound at draw time: added explicit
   glActiveTexture(GL_TEXTURE0/1) + glBindTexture calls before m_blit.Bind()
   to ensure both textures are current on their units when vglDrawObjects runs.
The GXP binary approach had two problems:

1) use-after-free: load_shader_binary() called KfxFree(buf) immediately after
   glShaderBinary(). vitaGL passes the GXP pointer to sceGxmShaderPatcherRegister
   Program which stores a reference (not a copy); subsequent allocations could
   overwrite the shader binary before it was used at draw time.

2) sampler binding: glGetUniformLocation on a binary GXP program returns a raw
   GXM SceGxmProgramParameter address (~2GB). vitaGL's glUniform1i may not
   correctly handle these as sampler-unit bindings, leaving texture units
   unconnected to the shader samplers.

Fix: use inline GLSL source strings compiled at runtime via vita_build_pass_program
(same path as VitaPassthroughPass, which we know works). glGetUniformLocation
now returns small integer indices and glUniform1i correctly binds indexTex to
unit 0 and paletteTex to unit 1.
Comprehensive commit of all vita-hardware-acceleration feature work that
was modified but not yet committed:

Renderer layer:
- RendererVita (already committed in 65aa293) - skip
- IPostProcessPass.h: GPU post-process pass interface
- VitaPassCommon.h: shared GLSL helpers (compile, link, quad draw)
- VitaPassthroughPass: RGBA passthrough blit (stage-3 final output)
- VitaDisplacePass/VitaFlyeyePass/VitaMistPass/VitaOverlayPass: GPU lens passes
- VitaShaderProgram: GXP binary loader (retained, not used by blit shader)

Platform updates:
- PlatformVita: vitaGL init, file I/O, input (PlatformVita.cpp committed earlier)
- PlatformManager, PlatformLinux, Platform3DS, PlatformSwitch: abstraction layer
- PlatformHomebrewMain: common homebrew entry point
- WindowSystemVita: virtual cursor, display setup

Lens system:
- LensEffect/LensManager: CPU+GPU lens effect coordination
- DisplacementEffect/FlyeyeEffect/MistEffect/OverlayEffect: GPU-aware lens impls

Build:
- CMakeLists.txt: Vita target, vitaGL, vitashark, new source files
- CMakePresets.json: vita-release/vita-reldebug/vita-debug presets
- devcontainer: vitasdk toolchain container

Docs: vita renderer design doc, cmake build instructions
Updates rendering calls for fullscreen quads on Vita to use
standard OpenGL ES 2.0 array functions. Replaces custom
vitaGL immediate mode helpers with `glDrawArrays` and
`glVertexAttribPointer`. This improves compatibility with
runtime-compiled GLSL programs and modernizes the rendering
pipeline for better maintainability.
Ensures the video subsystem is correctly initialized by the
platform manager during application startup on Windows. This
addresses a missing initialization step for the video backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant