Make browser main-loop ownership explicit when changing VSync mode
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Start with psyz/src/platform/sdl3_gl.c at Psyz_VideoSetVsyncMode and trace how ConfigureVSync calls SDL_GL_SetSwapInterval; compare that with the Emscripten backend behavior cited in the issue. The standalone scheduler.c reproduction shows the scheduler change, and the requested outcome is an explicit opt-out or a documented ownership contract. Decide which approach fits the project before changing the VSync behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
In an Emscripten application using emscripten_set_main_loop(..., 0, ...), changing PsyZ's VSync mode can also change the scheduler of the application's entire main loop. An application expecting RAF-driven callbacks can silently end up running on timers.
Reproduce without game code
Save the attached scheduler.c as assets/scheduler.c next to the following CMakeLists.txt:
CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(psyz_scheduler_probe C CXX)
if(NOT EMSCRIPTEN OR NOT IS_DIRECTORY "${PSYZ_ROOT}/psyz")
message(FATAL_ERROR "Use emcmake and -DPSYZ_ROOT=<PsyZ checkout>")
endif()
add_compile_options(-pthread)
add_link_options(-pthread)
set(SDL_PTHREADS ON CACHE BOOL "" FORCE)
add_subdirectory("${PSYZ_ROOT}/psyz" psyz EXCLUDE_FROM_ALL)
add_executable(scheduler_probe assets/scheduler.c)
target_link_libraries(scheduler_probe PRIVATE psyz)
psyz_web_configure_target(scheduler_probe)
Build with PsyZ and Emscripten:
emcmake cmake -S . -B build -DPSYZ_ROOT=/path/to/psyz -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel 8
Serve build/ with COOP/COEP headers (same-origin / require-corp), open index.html, and inspect the browser console. No disc or game assets are required. The example initializes video inside an RAF-driven main loop and calls VSync(0) once to create the backend and pump deferred SDL setup. It then changes the three VSync modes and queries emscripten_get_main_loop_timing after each change.
Observed output from the standalone example with unmodified PsyZ and SDL:
PSYZ_VSYNC_ON: RAF, value=1
PSYZ_VSYNC_OFF: SETTIMEOUT, value=0
PSYZ_VSYNC_LIMITLESS: SETTIMEOUT, value=0
The intended outcome is not necessarily to change these defaults. An application-owned main loop needs either an explicit opt-out from scheduler changes or a clearly documented ownership contract.
Cause
Psyz_VideoSetVsyncMode calls ConfigureVSync, which calls SDL_GL_SetSwapInterval. In SDL's Emscripten backend, interval zero calls emscripten_set_main_loop_timing(EM_TIMING_SETTIMEOUT, 0); a positive interval selects RAF. The existing SDL main-callback/hint exception does not apply to our direct Emscripten loop.
This is an SDL side effect exposed through PsyZ, not evidence of a defect in SDL's implementation.
Why it mattered in our port
Our new high-refresh loop incorrectly assumed it was still driven by RAF. With a stationary scene and an unmapped key repeatedly pressed, its render rate dropped while an independent RAF counter stayed near 120/s. A Chrome trace showed MainLoop_runner executing under TimerFire. Restoring RAF and restarting the loop to invalidate pending timer runners removed the drop:
| Same key-repeat test | Render submissions/s | Simulation steps/s | Browser RAF callbacks/s |
|---|---|---|---|
| Timer-driven game loop | 111.12 | 30.09 | 119.86 |
| RAF-driven game loop | 120.01 | 29.97 | 120.01 |
These eight-second measurements are from our modified Rewired loop on macOS Chrome, not a claim that every PsyZ application loses FPS on keyboard input. The standalone example reproduces the scheduler change only, not the full performance regression. Render/RAF counters do not measure physical display delivery.
Reference
Standalone reproduction tested on macOS, Chrome 157.0.8103.38 and Emscripten 6.0.13-git.
- PsyZ:
35c673e. - SDL:
fa2c02b, Emscripten swap interval.
Related: #232. This issue is about ownership of browser scheduling; separating presentation from the emulated VBlank API is independent.
- Lingua principale
- C
- Stelle
- 107
- Fork
- 26
- Merge medio
- 2g 21h
- PR unite (30g)
- 5
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Xeeynamo/psyz
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Missing XA 18.9 khz supportAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 38/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Tutte le issue di Xeeynamo/psyz
Issue simili
-
GXF: heap buffer overflow in parse_ad_cdp() — unbounded cc_count in CDP cc data sectionForse già presa @pranayr710 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CCExtractor/ccextractor#2498 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
area: services kind: bug preview-effort: small priority: low
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Static Analysis failureForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100