Skip to content
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

Emscripten_UpdateWindowFramebuffer fails if pixel data is higher than 2gb in address space #9052

Closed
sbc100 opened this issue Feb 12, 2024 · 13 comments
Assignees
Milestone

Comments

@sbc100
Copy link
Contributor

sbc100 commented Feb 12, 2024

Specifically the line var src = pixels >> 2 needs updating.

It should probably be:

#if __wasm64__
   var src = pixels  / 4;
#else
   var src = pixels >>> 0; 
#endif 

(I can work look into uploading a PR for this)

@icculus
Copy link
Collaborator

icculus commented Feb 15, 2024

Yes, please send a PR when you get a chance; this feels like something I'll get wrong if I try to do it myself. :)

@slouken slouken added this to the 3.2.0 milestone Mar 3, 2024
@sbc100 sbc100 removed their assignment Mar 8, 2024
@ericoporto
Copy link
Contributor

Trying to understand the issuepixels is a void* (I guess of size either 4 or 8 depending on it being a wasm64) and HEAP32 sees the memory like a sequence of 32-bit int. The SDL_Surface->pixels is allocated using SDL_SIMDAlloc which takes the size in bytes.

>>> 0 is a trick to cast to 32-bit int, it's a weird change assuming the current >> 2 is working (this is the same as / 4 here?)

@sbc100
Copy link
Contributor Author

sbc100 commented Mar 11, 2024

Sorry I meant to write >>> 2. The triple right shift is an unsigned shift (which is want) and the double right shift is a signed shift (which don't work for 32-bit addresses in the upper half of the range).

@sbc100
Copy link
Contributor Author

sbc100 commented Mar 11, 2024

If this is not in performance critical code you could just use a divide by 4 operation in all cases and keep the code simple.

@icculus icculus self-assigned this May 22, 2024
@icculus
Copy link
Collaborator

icculus commented May 22, 2024

Just coming back to this, do we just need that one var src = pixels >> 2; line fixed? I'll put that in revision control today if so!

@sbc100
Copy link
Contributor Author

sbc100 commented May 22, 2024

Any place >> or >>> is used on a pointer value would need to be fixed. I don't know if var src = pixels >> 2 is the only one.

@slouken
Copy link
Collaborator

slouken commented Oct 6, 2024

We are scoping work for the SDL 3.2.0 release, so please let us know if this is a showstopper for you.

@slouken slouken modified the milestones: 3.2.0, 3.x Oct 6, 2024
@sbc100
Copy link
Contributor Author

sbc100 commented Oct 7, 2024

This would be a showstopper for supporting memory64 AKA wasm64. It looks like there are 3 places that would need updating:

src/video/emscripten/SDL_emscriptenevents.c:                        var idx = ptr >> 2;
src/video/emscripten/SDL_emscriptenframebuffer.c:        var src = pixels >> 2;
src/video/emscripten/SDL_emscriptenmouse.c:        var src = pixels >> 2;

Should I send a RP for this? If so could it also be backported to the SDL2 branch (which emscritpen uses)?

@slouken
Copy link
Collaborator

slouken commented Oct 7, 2024

This would be a showstopper for supporting memory64 AKA wasm64. It looks like there are 3 places that would need updating:

src/video/emscripten/SDL_emscriptenevents.c:                        var idx = ptr >> 2;
src/video/emscripten/SDL_emscriptenframebuffer.c:        var src = pixels >> 2;
src/video/emscripten/SDL_emscriptenmouse.c:        var src = pixels >> 2;

Should I send a RP for this? If so could it also be backported to the SDL2 branch (which emscritpen uses)?

Yes please. :) We can backport it, that's fine.

@slouken slouken modified the milestones: 3.x, 3.2.0 Oct 7, 2024
@icculus
Copy link
Collaborator

icculus commented Oct 7, 2024

I'm surprised there are only three places we need this fix.

@sbc100
Copy link
Contributor Author

sbc100 commented Oct 7, 2024

I'm surprised there are only three places we need this fix.

I'll do a more thorough search. I can also very that all the emscripten-side tests pass under wasm64 after making the change.

sbc100 added a commit to sbc100/SDL that referenced this issue Oct 7, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: libsdl-org#9052
sbc100 added a commit to sbc100/SDL that referenced this issue Oct 8, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: libsdl-org#9052
sbc100 added a commit to sbc100/SDL that referenced this issue Oct 8, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: libsdl-org#9052
icculus pushed a commit that referenced this issue Oct 8, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: #9052
@icculus icculus closed this as completed in 02434cd Oct 8, 2024
slouken pushed a commit that referenced this issue Oct 8, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of
memory.

Fixes: #9052
(cherry picked from commit 3deb07e)
@slouken
Copy link
Collaborator

slouken commented Nov 1, 2024

FYI, the fix for this is in the latest SDL2 release:
https://github.com/libsdl-org/SDL/releases/tag/release-2.30.9

@sbc100
Copy link
Contributor Author

sbc100 commented Nov 1, 2024

Thanks: emscripten-core/emscripten#22830

klukaszek pushed a commit to klukaszek/SDL that referenced this issue Nov 17, 2024
This includes both wasm64 and wasm32 when addressing more than 2gb of memory.

Fixes: libsdl-org#9052

(Manually cherry-picked from 3deb07e.)
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

No branches or pull requests

4 participants