gfx-rs / wgpu-rs

Rust bindings to wgpu native library
https://wgpu.rs
Mozilla Public License 2.0
1.68k stars 186 forks source link

Target the Web directly #101

Closed kvark closed 4 years ago

kvark commented 4 years ago

We need to make wgpu-rs do the actual Web calls and run in the browser supporting WebGPU API. The API itself is still evolving, but we should start exploring what our side would look like, and maybe we'll already get something running.

grovesNL commented 4 years ago

Steps to get this working:

  1. Ensure mozilla-central has up-to-date WebGPU WebIDL
    • This step can probably be omitted, but technically this is the upstream for many of the existing web-sys WebIDL files
    • Done (we use the complete WebIDL from gpuweb instead)!
  2. Update the existing WebGPU WebIDL in web-sys so we can generate Rust bindings
  3. Split calls in wgpu-rs to use #[cfg(target_arch = "wasm32")] to target web-sys, and #[cfg(not(target_arch = "wasm32"))] to target wgpu-native
    • We might want to consider splitting wgpu-rs into two backends (wgpu-native and web-sys), or use a trait like we do in glow, or something else
  4. Now we can build for wasm32-unknown-unknown and use wasm-bindgen-cli or wasm-pack as usual
kvark commented 4 years ago

Thank you for describing the steps! They look very actionable, and make me believe we can get a prototype running (at least device creation) by the end of the year.

FYI, (1) was mostly updated to latest WebIDL by https://phabricator.services.mozilla.com/D46166, which took more of my blood and tears than I'd hope or expect.

Edit: actually, we settled on not exporting any WebGPU logic that isn't implemented yet, other than the bare interfaces... which means that at least my https://phabricator.services.mozilla.com/D49458 needs to be merged before we proceed here.

kvark commented 4 years ago

Gecko PR has landed, and now one can at least create a device on WebGPU (in Nightly!). I think the work can be started here, according to @grovesNL plan.

grovesNL commented 4 years ago

I also already have some branches for web-sys changes and wgpu-rs changes for this – just need to update them based on the recent changes and then we can start making some progress here.

grovesNL commented 4 years ago

Small update: https://github.com/rustwasm/wasm-bindgen/pull/1997 has been merged which allows us to use web-sys bindings for WebGPU while the WebIDL is still unstable

kvark commented 4 years ago

Let's consider this fixed by #193 Amazing work of @grovesNL and everyone involved, thank you all!