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

Support for wasm32-unknown-unknown via binding with the provided emscripten wasm file #10

Open
expenses opened this issue Apr 24, 2022 · 6 comments

Comments

@expenses
Copy link

CC @superdump

I've been working on writing bindings for the transcoder wasm that basis_universal provides so that I can parse and transcode basis files in wasm. I've got a repo for this here:
https://github.com/expenses/basis-universal-rs-wasm

It'd be fantastic if we could get support for this into this crate, so that wasm support just works. A couple of notes:

This will all take a while, but I'll try to create good bindings for the .basisu transcoder and work from there.

@expenses
Copy link
Author

We should be able to use once_cell to safely make the module static: https://docs.rs/once_cell/latest/once_cell/

@superdump
Copy link
Contributor

Awesome!!!

@aclysma
Copy link
Owner

aclysma commented Apr 24, 2022

Nice work, thanks for writing all this down! I’m happy to consider merging something like this in.

When the time comes to review, anything we can do to keep the “native” use-case of the crate relatively simple and to minimize ongoing future maintenance will be appreciated. (I want this project to be sustainable!) If appropriate maybe we could have some of it (like the wrappers) in a downstream but in-tree crate? An extra review by someone more familiar with bindgen would also be very welcome!

@expenses
Copy link
Author

So one think I've ran into is that (and I've love to be corrected on this if I'm wrong) it doesn't seem like you can create rust slices from javascript Uint8Arrays. You can only copy them into Vec<u8>s (See https://docs.rs/js-sys/latest/js_sys/struct.Uint8Array.html#method.to_vec). This is a problem for trying to replicate the Transcoder API (https://docs.rs/basis-universal/latest/basis_universal/transcoding/struct.Transcoder.html) as all the methods take &[u8] slices and these would all need to be copied. As a result I think that I'll stick with the existing BasisFile abstraction that only makes a single copy.

I think the main API to get into parity is the LowLevelUastcTranscoder. That's the only thing that you need for ktx2 support anyway (See https://github.com/bevyengine/bevy/blob/00f83941b16e7a175c5c1503be81a648e23d81df/crates/bevy_render/src/texture/ktx2.rs#L117-L149)

@expenses
Copy link
Author

expenses commented May 7, 2022

I've worked on this a bit more today and have created some commits that let me use LowLevelUastcTranscoder in the browser!
Firstly BinomialLLC/basis_universal@9177a09 expenses transcode_slice in the basisu wasm, expenses/basis-universal-rs-wasm@009a82c adds it to my bindings and 613c4d3 hackily adds it to this crate. I'm going to work on merging in things soon.

@expenses
Copy link
Author

expenses commented May 7, 2022

I'm going to work on merging in things soon.

BinomialLLC/basis_universal#299

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

3 participants