bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.24k stars 3.58k forks source link

HDRs cannot be loaded in WASM #7588

Closed janhohenheim closed 2 months ago

janhohenheim commented 1 year ago

Bevy version

0.9.1

What you did

I used the asset server to load an HDR in WASM.

What went wrong

The game crashed with the console reporting 'failed to spawn thread: Error { kind: Unsupported, message: "operation not supported on this platform" }'

Additional information

This happens because the underlying image crate uses scoped_threadpool to decode HDRs, which spawns a thread pool: https://github.com/image-rs/image/blob/v0.24.5/src/codecs/hdr/decoder.rs#L463 As the error message says, this is not allowed in WASM

Per https://github.com/image-rs/image/issues/772#issuecomment-1382406241, we could just remove the multithreading entirely from the HDR decoding to solve this for the time being.

mockersf commented 1 year ago

seems it's blocked on someone making that change in the image crate then

janhohenheim commented 1 year ago

My friend @bash is working on it as we speek :)

bash commented 1 year ago

PR created 🙂 https://github.com/image-rs/image/pull/1857

janhohenheim commented 1 year ago

Little update: even after the fix, HDRis in WASM retain limited usefulnes since WebGPU does not support texture filtering on 32 bit depth textures . Using filter-less samplers in Bevy is possible, but annoying to setup. Dropping texture filtering quite limits what one can do with the HDRis. This means that in practice, I ended up converting my HDRis to 16 bit depth JPGs. This is not really relevant for this issue, but might be useful for people stumbling upon this issue in the future.