-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable pthreads on Emscripten #17586
Merged
LibretroAdmin
merged 26 commits into
libretro:master
from
JoeOsborn:emscripten-worker-pthread
Feb 19, 2025
Merged
Enable pthreads on Emscripten #17586
LibretroAdmin
merged 26 commits into
libretro:master
from
JoeOsborn:emscripten-worker-pthread
Feb 19, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch eliminates the need for asyncify and uses modern filesystem APIs instead of the deprecated, unmaintained BrowserFS. This is a WIP patch because it won't fully work until these two Emscripten PRs land and are released: emscripten-core/emscripten#23518 emscripten-core/emscripten#23021 The former fixes an offscreen canvas context recreation bug, and the latter adds an equivalent to BrowserFS's XHR filesystem (but without the hazardous running-XHR-on-the-main-thread problem). The biggest issue is that local storage of users who were using the old version of the webplayer will be gone when they switch to the new webplayer. I don't have a good story for converting the old BrowserFS IDBFS contents into the new OPFS filesystem (the move is worth doing because OPFS supports seeking and reading only bits of a file, and because BrowserFS is dead). I've kept around the old libretro webplayer under pkg/emscripten/libretro-classic, and with these make flags you can build a non-workerized RA that uses asyncify to sleep as before: make -f Makefile.emscripten libretro=$CORE HAVE_WORKER=0 HAVE_WASMFS=0 PTHREAD=0 HAVE_AL=1 I also moved the default directory for core content on emscripten to not be a subdirectory of the local filesystem mount, because it's confusing to have a subdirectory that's lazily fetched and not mirrored to the local storage. I think it won't impact existing users of the classic web player because they already have a retroarch.cfg in place.
- Add http transfer support for emscripten - At the task_http level, not the net_http level --- so no netplay or webdav. - Change default paths to be more like other platforms - Gives us smaller bundles and a faster boot time - Had to work around a task queue bug on Emscripten - I made the smallest possible change to do it, but it may be better to fix in rthread.c
If no ozone assets are present, load a libretro_minimal package created using Emscripten's built-in file packager.
1. make PROXY_TO_PTHREAD=1 (slower) 2. make PROXY_TO_PTHREAD=0 (bad audio, because doesn't sleep in openal.c)
also make input_driver check existence of drv->axis, drv->button before calling them.
I think this can be fixed by moving the backend creation off the main thread.
Also improve Safari compatibility under proxy-to-pthread condition
BinBashBanana
approved these changes
Feb 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do a follow-up on this, but everything here right now looks good
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch eliminates the need for asyncify and uses modern filesystem APIs instead of the deprecated, unmaintained BrowserFS. I also added a new emscripten graphics backend for using webgl directly instead of (buggy) egl emulation.
Until this Emscripten patch lands in a release, the Makefile should be built with the default HAVE_EGL=1 (and PROXY_TO_PTHREAD=0). Once it's merged and we can update our emscripten version, HAVE_EGL=0 should be set and PROXY_TO_PTHREAD may be enabled (and ASYNC disabled).
There is a slowdown of maybe 20-30% in PROXY_TO_PTHREAD compared to ASYNC, which is due to proxied calls in openal.c and webgl_ctx. I'll submit fixes to those in future PRs; I've diagnosed the problem and have eliminated the slowdown in local testing by dummying out the relevant calls, but I'll have a real fix in the future.
The biggest issue is that local storage of users who were using the old version of the webplayer will be gone when they switch to the new webplayer. I don't have a good story for converting the old BrowserFS
IDBFS contents into the new OPFS filesystem (the move is worth doing because OPFS supports seeking and reading only bits of a file, and because BrowserFS is unmaintained). I think @BinBashBanana is looking at that.
I've kept around the old libretro webplayer under pkg/emscripten/libretro, and with the default make flags you can build a non-workerized RA that uses asyncify to sleep as before:
The new player should be built for the pkg/emscripten/libretro-pthread directory:
I think @BinBashBanana has some other quality of life fixes in development on top of this branch, but I think it's probably best to try and land this PR as-is now.
I've tested both make commands above and they produce working builds on Linux Firefox, Linux Chrome, and recent desktop Safari. I haven't tested other browsers or combinations.