From 36853f923e1e404923a5b7f471dada3c93ef55c6 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Mon, 7 Oct 2024 16:45:03 -0700 Subject: [PATCH] [emscripten] Fixes for data addresses above 2gb This includes both wasm64 and wasm32 when addressing more than 2gb of memory. Fixes: #9052 (cherry picked from commit 3deb07ea395373204462130c1e062bc1f71fe060) --- include/SDL_stdinc.h | 2 +- src/audio/emscripten/SDL_emscriptenaudio.c | 8 +++++++- src/video/emscripten/SDL_emscriptenframebuffer.c | 2 +- src/video/emscripten/SDL_emscriptenmouse.c | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 8113f453f3b37..8eb757957d58e 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -257,7 +257,7 @@ typedef uint64_t Uint64; #define SDL_PRIs64 "I64d" #elif defined(PRIs64) #define SDL_PRIs64 PRIs64 -#elif defined(__LP64__) && !defined(__APPLE__) +#elif defined(__LP64__) && !defined(__APPLE__) && !defined(__EMSCRIPTEN__) #define SDL_PRIs64 "ld" #else #define SDL_PRIs64 "lld" diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index 8d21dab597dc6..7d18d2a3c6f4b 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -39,6 +39,12 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen) /* *INDENT-OFF* */ /* clang-format off */ MAIN_THREAD_EM_ASM({ var SDL2 = Module['SDL2']; + /* Convert incoming buf pointer to a HEAPF32 offset. */ +#ifdef __wasm64__ + var buf = $0 / 4; +#else + var buf = $0 >>> 2; +#endif var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels']; for (var c = 0; c < numChannels; ++c) { var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c); @@ -47,7 +53,7 @@ static void FeedAudioDevice(_THIS, const void *buf, const int buflen) } for (var j = 0; j < $1; ++j) { - channelData[j] = HEAPF32[$0 + ((j*numChannels + c) << 2) >> 2]; /* !!! FIXME: why are these shifts here? */ + channelData[j] = HEAPF32[buf + (j*numChannels + c)]; } } }, buf, buflen / framelen); diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index 6a0e78fd43be3..43a9b7156f994 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -89,7 +89,7 @@ int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect SDL2.imageCtx = SDL2.ctx; } var data = SDL2.image.data; - var src = pixels >> 2; + var src = pixels / 4; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) { diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index 7d4601f42b0f5..5b1f205aedbe8 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -98,7 +98,7 @@ static SDL_Cursor *Emscripten_CreateCursor(SDL_Surface *surface, int hot_x, int var image = ctx.createImageData(w, h); var data = image.data; - var src = pixels >> 2; + var src = pixels / 4; var dst = 0; var num; if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {