7 ms·
W3C Community Group Draft Report – WebGPU Explainer
- drfuchs 3y agoGreat. Now how do I call this API from WASM without any intervening JavaScript?
- pjmlp 3y agoYou don't. Maybe when reference types eventually become a thing.
- davexunit 3y agoWASM GC reference types are rolling out to stable browser releases now. Chrome 119 just shipped with them enabled by default.
- pjmlp 3y agoThose ones are unrelated to exposing browser APIs directly to WASM code. Setup is still required.
- davexunit 3y agoI don't quite understand what you mean. WASM modules don't have direct access to anything. They have to be granted capabilities from by the host. Are you referring to optimizations that various engines do where they recognize well-known imports like Math.sin and compile things such that they don't invoke JS at all?
- pjmlp 3y agoExactly, hence it is currently impossible to use WebGPU without JavaScript's help. There are some proposals regarding exposing the browser IDL to WASM via reference types, but it is far from happening.
- davexunit 3y agoYou need the host (whatever it is) to provide the capabilities to WASM. On the web, the host environment is JS. Browser engines are free to optimize well-known imports with or without any new proposals. I guess I just don't really see the issue...
- pjmlp 3y agoThe issue is that currently this is impossible "Now how do I call this API from WASM without any intervening JavaScript?". Now the Web IDL bindings have evolved to some kind of reference types, and that is what I was talking about, not GC reference types. https://www.w3.org/2018/12/games-workshop/slides/08-web-idl-bindings.pdf https://www.w3.org/2018/12/games-workshop/slides/08-web-idl-... https://hacks.mozilla.org/2019/08/webassembly-interface-types/ https://hacks.mozilla.org/2019/08/webassembly-interface-type... https://component-model.bytecodealliance.org/introduction.html https://component-model.bytecodealliance.org/introduction.ht... However I did the mistake to keep calling them reference types, when in reality they are now called component model. As for the browser, yeah that is what matters for WebGPU, outside of the browser there are so many middleware options with much better tooling (GPU debuggers for Web 3D still aren't a thing 10 years later, besides poor SpectorJS), and access to latest hardware features, instead of what was the state of the art in 2015.
- davexunit 3y agoYou'll need some JavaScript to instantiate the WASM module and pass in a set of imported functions for using WebGPU. After passing in the capabilities it can be all WASM from there.
- jauntywundrkind 3y agoAfaik, there's no means to pass in imported functions right now. Rust has a very extensive bindgen to make it kind of look like you can, but it's really a huge payload of js running on the page's main-thread that's converting back and forth. At significant cost. We just shipped garbage collection, which is one precondition to actually being able to pass things around (so things passed in can participate properly in gc). Next is component-model, which allows for passing non-trivial objects around; currently it's just primitives like numbers that can be passed. After that goes in, hopefully it won't be long before we have host-object bridging, where platform objects can be sent across. https://github.com/WebAssembly/component-model https://github.com/WebAssembly/component-model
- davexunit 3y agoYou can pass around arbitrary JS objects via the (ref extern) type. The (import "module" "name" ...) form can be used to declare an imported thing (function, global, memory, table.) I don't do Rust so I don't know what the limitations are with Rust on WASM right now but speaking just about core WASM stuff all the basic pieces are there now.
- jauntywundrkind 3y agoAfaik, no. What you are talking about is the future, not anything available on any platforms today. Right now, different runtimes don't have any way to communicate what type an object or function is. That's what component model is trying to figure out. Without that, there's not really a way for a ref to do anyone any good, as far as I know. If you can link any docs or examples, that'd be great. I feel like it's been a long long long wait, & I've been very eager. But if I'm mistaken, and passing stuff across boundaries is possible, that'd be amazing to see.
- Buttons840 3y agoSoon, even our game engines will be written in JavaScript: https://www.youtube.com/watch?v=_SCfNhyIo_U https://www.youtube.com/watch?v=_SCfNhyIo_U Snark aside, the best resource I've found for learning WebGPU is: https://webgpufundamentals.org/ https://webgpufundamentals.org/
- pjmlp 3y agoWebGPU will always have the issue to lang behind native capabilities. It is good enough if aiming to PS3 like games, though.
- Buttons840 3y agoAny WGPU users among us? How does native and web performance, with the same graphics code, compare?
- pjmlp 3y agoWhatever WGPU might do in addition to WebGPU is naturally going beyond the standard features a browser is expected to provide, thus no different from any other graphics middleware.
- AshleysBrain 3y agoWe are building a full game engine and editor fully in JavaScript [1], and we've got WebGPU support too [2]. [1] https://www.construct.net https://www.construct.net [2] https://www.construct.net/en/blogs/construct-official-blog-1/introducing-constructs-new-1768 https://www.construct.net/en/blogs/construct-official-blog-1...
- astlouis44 3y agoMy team is bringing Unreal Engine 5 to WebGPU, to enable next generation browser games and 3D web applications.
- deleted 3y ago[deleted]
- kevingadd 3y ago"Each error scope stores only the first error it captures; any further errors it captures are silently ignored." is one of the worst design decisions I've ever seen. That means if code is expecting one error to occur, any unexpected errors that occur after it in the scope are unobservable. The only way to handle that would be to push/pop tons of scopes. How hard is it to make an array of errors instead of a single slot? What's the upside of this other than laziness?
- johncolanduoni 3y agoThese kinds of errors are usually programmer errors that cause literally hundreds of downstream errors because they put an object later used by other code in an invalid state. In these cases only the first error is particularly useful, the rest are just noise.
- xnorswap 3y agoThe worst? No, that belongs to VB: > On Error Resume Next Literally, "Ignore the error, and continue as if nothing bad had happened". That's the worst design decision ever when it comes to error handling. Only storing the first error is bad, but that's why they describe it as a problem with WebGL that they solve in WebGPU by using a stack.