W3C Community Group Draft Report – WebGPU Explainer
gpuweb.github.io
gpuweb.github.io
How hard is it to make an array of errors instead of a single slot? What's the upside of this other than laziness?
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.
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
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.
All of that seems like more of a convenience than a necessity: even with just the current implementation of host references, it's perfectly possible to track objects purely through indices into a big table, using reference-counting on the module's side, with no JS assistance necessary.
In fact, wasm-bindgen has already implemented support for tracking JS objects as host references in this way, via the --reference-types flag [0]. I've tried out this flag with their WebGL example, and the shims are indeed very minimal: JS objects passed as input aruments go directly into the target functions, without any sort of decoding or lookups. However, JS objects as outputs are still inserted into the table by the shims (calling back into the module to get a free index), which I presume is just a limitation of Rust not being able to express a host reference stored in a local while calling another function.
So overall, there's no fundamental issue blocking native functions (or methods, through a bound Function.prototype.call) from being called from WASM with no shims at all, as long as the module can implement any sort of basic index allocator. Though I'd imagine sufficiently-simple shims would get compiled down to hardly anything regardless, in case that turns out to be more performant than Function.prototype.call.
[0] https://rustwasm.github.io/wasm-bindgen/reference/reference-...
Component Model is designed to eliminate the need for having this autogenerated rpc system & many of these shims, and let wasm itself actually hold references & invoke/use objects in a genuinely shared fashion.
I don't understand what you mean? With the --reference-types flag I mentioned, wasm-bindgen is literally passing the JavaScript objects in and out of the shims with absolutely no serialization or indirection on the JavaScript side: the only indirection is on the module's side, when it stores all the host references in a big table and passes around indices to them.
To give a concrete example, I've attached the entirety of the JavaScript code that wasm-bindgen generates with --reference-types enabled on its WebGL example [0]. You can see how many of the shims do absolutely nothing but call the underlying function, even when they take arbitrary JS objects as arguments:
imports.wbg.__wbg_attachShader_06c432ad16c8823a = function(arg0, arg1, arg2) {
arg0.attachShader(arg1, arg2);
};
imports.wbg.__wbg_bindBuffer_c0ef32bca575b1bf = function(arg0, arg1, arg2) {
arg0.bindBuffer(arg1 >>> 0, arg2);
};
imports.wbg.__wbg_clear_7f98b4d14a417e94 = function(arg0, arg1) {
arg0.clear(arg1 >>> 0);
};
imports.wbg.__wbg_clearColor_d0e4ba6b3de36fbc = function(arg0, arg1, arg2, arg3, arg4) {
arg0.clearColor(arg1, arg2, arg3, arg4);
};
imports.wbg.__wbg_compileShader_81181e6a219b7098 = function(arg0, arg1) {
arg0.compileShader(arg1);
};
So as you can see, we already have direct bridging, as long as the JS objects can be treated as opaque. In fact, the code works just as well if we ditch the anonymous functions entirely, and import the native methods directly into the WASM module (though wasm-bindgen currently doesn't do this on its own, and I have no idea how this affects performance): imports.wbg.__wbg_attachShader_06c432ad16c8823a =
Function.prototype.call.bind(WebGL2RenderingContext.prototype.attachShader),
imports.wbg.__wbg_bindBuffer_c0ef32bca575b1bf =
Function.prototype.call.bind(WebGL2RenderingContext.prototype.bindBuffer),
imports.wbg.__wbg_clear_7f98b4d14a417e94 =
Function.prototype.call.bind(WebGL2RenderingContext.prototype.clear),
imports.wbg.__wbg_clearColor_d0e4ba6b3de36fbc =
Function.prototype.call.bind(WebGL2RenderingContext.prototype.clearColor),
imports.wbg.__wbg_compileShader_81181e6a219b7098 =
Function.prototype.call.bind(WebGL2RenderingContext.prototype.compileShader),
Serialization and deserialization are really only needed if we have record types filled with raw data like numbers and strings that we want to ergonomically manipulate on the JavaScript side. If we just need to track opaque handle objects, as with WebGL or WebGPU, then WASM's feature of host references is already sufficient to avoid serialization overhead.[0] https://gist.github.com/LegionMammal978/9c4ac4de47b3b365a50a...
Maybe when reference types eventually become a thing.
Setup is still required.
There are some proposals regarding exposing the browser IDL to WASM via reference types, but it is far from happening.
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-...
https://hacks.mozilla.org/2019/08/webassembly-interface-type...
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.
Snark aside, the best resource I've found for learning WebGPU is: https://webgpufundamentals.org/
[2] https://www.construct.net/en/blogs/construct-official-blog-1...
It is good enough if aiming to PS3 like games, though.
https://www.destroyallsoftware.com/talks/the-birth-and-death...