Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

WASM: Support loading assets for GL backend #2174

Closed
azriel91 opened this issue Mar 18, 2020 · 2 comments
Closed

WASM: Support loading assets for GL backend #2174

azriel91 opened this issue Mar 18, 2020 · 2 comments
Labels
feat: WASM support This issue is related to WebAssembly compilation target support
Projects

Comments

@azriel91
Copy link
Member

Currently, an application compiled using the the "gl" backend crashes when loading textures.

This is because the Window is created on one thread, and in open GL the textures must also be loaded on the same thread. However, amethyst_assets' AssetStorage takes in a ThreadPool, and loads assets asynchronously on any thread that picks up the processing task.

Code points of interest:

  1. amethyst/amethyst_rendy/src/bundle.rs:121 adds a TextureProcessorSystem.
  2. amethyst/amethyst_rendy/src/system.rs:230 calls process on AssetStorage.
  3. rendy/resource/src/image.rs:86 calls device.create_image.
  4. gfx/src/backend/gl/src/lib.rs:375 asserts the thread IDs are equal.

What should succeed:

cargo run --example pong --features "gl audio"
@azriel91 azriel91 added status: ready feat: WASM support This issue is related to WebAssembly compilation target support labels Mar 18, 2020
@azriel91 azriel91 added this to To do in WASM via automation Mar 18, 2020
bors bot added a commit that referenced this issue Mar 24, 2020
2189: WASM: make it possible to run pong_wasm r=azriel91 a=chemicstry

## Description

Minimum workarounds to get wasm running.
Issues that need proper fix:
- `shred` is patched to be singlethreaded, need to resolve main thread synchronisation.
- #2174 is resolved by `add_thread_local`. Does that move too much processing to the main thread?
- Audio crashes on wasm.
- UI crashes on wasm.

Other:
- Need to move `web_worker` to amethyst and apply latest commit.

## PR Checklist

By placing an x in the boxes I certify that I have:

- [ ] Updated the content of the book if this PR would make the book outdated.
- [ ] Added a changelog entry if this will impact users, or modified more than 5 lines of Rust that wasn't a doc comment.
- [ ] Added unit tests for new code added in this PR.
- [ ] Acknowledged that by making this pull request I release this code under an MIT/Apache 2.0 dual licensing scheme.

If this modified or created any rs files:

- [ ] Ran `cargo +stable fmt --all`
- [ ] Ran `cargo clippy --all --features "empty"`
- [ ] Ran `cargo test --all --features "empty"`


Co-authored-by: chemicstry <chemicstry@gmail.com>
@azriel91
Copy link
Member Author

azriel91 commented Mar 28, 2020

Partially solved by #2198.

Even with that merged, GL backend cannot load texture assets with Rgb8Srgb format, so that's why this issue remains open. Test using:

cargo run --example ui --features "audio gl system_font" # --release

@azriel91
Copy link
Member Author

Looks like the remainder is resolved by #2217 (thanks 🙇‍♂️!)

WASM automation moved this from To do to Done Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: WASM support This issue is related to WebAssembly compilation target support
Projects
No open projects
WASM
  
Done
Development

No branches or pull requests

1 participant