hrydgard / ppsspp

A PSP emulator for Android, Windows, Mac and Linux, written in C++. Want to contribute? Join us on Discord at https://discord.gg/5NJB6dD or just send pull requests / issues. For discussion use the forums at forums.ppsspp.org.
https://www.ppsspp.org
Other
10.8k stars 2.12k forks source link

Building emscripten with GLES is broken #18861

Open ethanaobrien opened 4 months ago

ethanaobrien commented 4 months ago

Platform

libretro / Retroarch

Compiler and build tool versions

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.53 (ce5114bdd2175c7297583d3c25a53ca95d22f4ce)

Operating system version

Debian GNU/Linux bookworm 12.0 x86_64

Build commands used

Using the patches mentioned here for sub modules, and this commit, disabling GLES, then linking with RetroArch using gles2 causes PPSSPP to run almost flawlessly.

As far as I can tell the emulation itself runs perfectly, playable* as long as you don't need video. Much better than it was a few months ago when I originally tried getting it to run.

And here's the fun part, of course compiling without GLES and targeting gles2 wont work, that was just to get it to run at all. Currently, if you build with GLES enabled (specifically if you pass the USING_GLES2 definition) the page will freeze upon load. I traced the freeze here where it seems to be waiting on another thread. This only happens when GLES is enabled, with it disabled the emulation runs as well as the browser can handle it, which is suspiring.

To build this:

  1. git clone https://github.com/EmulatorJS/ppsspp.git
  2. git clone https://github.com/EmulatorJS/RetroArch.git
  3. git clone https://github.com/EmulatorJS/EmulatorJS.git
  4. cd ppsspp/libretro/
  5. Apply patches mentioned in #17779
  6. emmake make clean && emmake make platform=emscripten -j$(nproc)
  7. cp ppsspp_libretro_emscripten.bc ../../RetroArch/dist-scripts/
  8. cd ../../RetroArch/dist-scripts/
  9. emmake ./dist-cores.sh emscripten clean
  10. Open your file explorer and navigate to EmulatorJS/data/cores/ and open the .data file with 7zip, open the .js file (not .worker.js( in a text editor and search for asyncifyStubs. Remove any definitions of this. This errors because of a bug with emscripten where its defined but does not do anything. Removing this definition will fix the issue.
  11. Download this zip to the EmulatorJS/data/cores folder
  12. Launch your favorite web server pointing at the EmulatorJS folder. Be sure to set the headers mentioned here
  13. Edit the core function to always return psp.
  14. Open a web browser and go to http://localhost:8080/index.html?debug=1&threads=1. It should warn you if threads is not properly enabled.
  15. Upload your rom to the page. It will automatically launch the game assuming you did step 13.

Through writing this (40-50 minutes) I've had ppsspp running in the browser with gles disabled (no video) and have had no crashes nor performance decreases (playing the title menu music). The only issue with the emscripten build target is gles.

A demo with gles disabled can be found here.

What happens

gles disabled log (working emulation, black screen): gles--disabled.log

gles enabled log (freezes page): gles-enabled.log

PPSSPP version affected

v1.17.1-11-gb41753896

Last working version

No response

Checklist

hrydgard commented 4 months ago

Emscripten isn't a platform that the project (or at least I) care about, you're on your own. I'll leave the issue open, though.