emscripten-core / emscripten-core/emscripten

SIMD glitched on iPhone and crashes on iPad

Open
#19,619 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

In my emscripten + C + WebGL project with [cglm](https://github.com/recp/cglm/issues/312) doing vector math, enabling SIMD via `-msimd128` produces broken floats, resulting in warping of the texture on screen, but only on an iPhone SE, iOS 16.4.1. On an iPad 9th gen, iOS 16.3.1, the WebApp straight up refuses to launch with SIMD active.
Tested this behavior is browser independent, as both Safari and Edge are affected. According to https://webassembly.org/roadmap/, SIMD should work on these browsers.

https://github.com/emscripten-core/emscripten/assets/60887273/31e83ca4-74f3-442d-ba35-ddbc2598efc9

Since I'm still preparing my WebApp and don't expect users, I have purposefully left the WebApp in this broken state via commit https://github.com/FrostKiwi/frostorama/commit/a065c5a7d62e3f89f2aed6a0e514134bd571cafe#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52. ~~You can test this out live (until I revert SIMD usage in a week) by going to https://frostkiwi.github.io/frostorama/ clicking on `Project image` and seeing the image glitch out, as opposed to having proper projection math applied on Android or a normal PC browser.~~ Reverted buggy simd again with https://github.com/FrostKiwi/frostorama/commit/c92cf22bfe58f2fec4dff4abab3412aa54574a2d

I have not yet tracked down the specific line responsible, but highly suspect the vector operations from this line up to line 50 https://github.com/FrostKiwi/frostorama/blob/a065c5a7d62e3f89f2aed6a0e514134bd571cafe/src/render_loop.c#L22 . There are calculations happening preparing a Fullscreen quad to raytrace and passing these floats to a WebGL shader. I suspect, that enabling SIMD makes these calculations become invalid on the iPhone.

I was looking forward to enabling SIMD, since https://github.com/recp/cglm is purposefully designed to have WASM SIMD functions. However, I will have to revert the use of SIMD, since it breaks on iOS.

Version of emscripten/emsdk

```console
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.38 (9eff02bc816c50ab0e3b70a3bd5b72a8dc2893a2)
clang version 17.0.0 (https://github.com/llvm/llvm-project 004bf170c6cbaa049601bcf92f86a9459aec2dc2)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\\min\home\artsimow\build\emsdk\upstream\bin
```

Cross-posted this in the cglm repo as well, since I suspect the math issues influencing that library: https://github.com/recp/cglm/issues/312

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.