137 points · by panic · 6y ago · 128 comments
When people write interactive 3D graphics for the web, there's ThreeJS and WebGL.
Where does WebAssembly games using I/O devices fit in all of this?
Browsers are similar in that they are like mini-sandboxed OS’s with “standardised” interfaces. So applying the idea of standardised, sandboxed interfaces to WebAssembly you end up with WASI and probably eventually extension to GPU, audio and other interfaces useful to games.
It’s actually a pretty old idea, plenty of old games were actually written to run on interpreters that were then rewritten for each platform. For example Another World which has cropped up on the front page recently takes this approach.
I'm sure over time, and if desired, WASI will get a set of higher level platform-wrapper APIs for rendering, audio, input and networking, but the requirements are somewhat different from traditional "native" APIs, for instance, compatibility with web APIs is useful. So we'll probably see the WebGPU API for 3D rendering, instead of Vulkan, D3D12 or Metal.
SDL? Has ports for more obscure platforms, too
SDL_Window *window;
SDL_Renderer *renderer;
SDL_CreateWindowAndRenderer(800, 600, 0, &window, &renderer);
SDL_RenderDrawPoint(renderer, 400, 300); //Renders on middle of screen.
SDL_RenderPresent(renderer);
There's also SDL bindings in a bunch of languages, a few official ones herePersonally I think Web compatibility is so useful that wasm off the Web should use Web APIs, instead of the direction WASI is going.
WASI is an effort to create a new OS API layer from scratch, without the baggage of POSIX or the Web or such. That's definitely interesting, and may be a big deal in the long run, but it has risks (it will take a lot longer, in particular) and it has downsides for the Web (which is personally the platform I care most about).
Because if you "blit a bunch of pixels to the screen", you don't care about performance regardless.
PS: I think there's some confusion about WASM running in browsers, vs WASM running on top of WASI. WASI is all about running WASM outside the browser: https://wasi.dev/
For 3D rendering, WebGPU would be the better option to support in WASI because it has standalone native implementations:
https://dawn.googlesource.com/dawn
https://github.com/gfx-rs/wgpu
But for blitting CPU-generated 2D image data to the screen WebGPU is also sort of overkill (of course it would be possible to create a much simplified wrapper library in WASM).
That's why Godot is moving to Vulkan, that can also run on Metal: https://godotengine.org/article/retrospective-and-future
For Godot game developers, this will not be visible in any way, it's under the hood change to engine.
For other apps, there is in progress development to run full OpenGL on top of Vulkan with Zink. There is a blogpost about it here: https://www.collabora.com/news-and-blog/blog/2018/10/31/intr...
There is also a talk about it at The X.Org Developer's Conference 2019-10-02 here, for example Blender seems to work already: https://youtu.be/rV0P1ChE_5o?t=3970
All conference recordings are listed at conference website: https://xdc2019.x.org/
You cannot create a window or handle input with OpenGL.
The article linked here is an advertisement for a startup.
It's also an open collaborative cross-vendor specification with at least four different independent implementations.
MSIL/CIL is similar in some ways, but it's still largely only supported by Microsoft and doesn't sandbox binaries the same way. It's an inspiration to We assembly, but not a feasible alternative to it. Similar to Google's PNaCl bytecode.
Some more detail here:
https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webas...
https://hacks.mozilla.org/2019/11/announcing-the-bytecode-al... "secure-by-default foundations for native development that are portable and scalable."
There are so many parties interested in wasm, there are a ton of inflight proposals and extensions to get it beyond the mvp stage.
[0]: https://github.com/WebAssembly/threads [1]: https://github.com/WebAssembly/multi-memory
Ideally, libraries should only use a very small subset of the POSIX / C-runtime APIs (ideally none which need to call into the underlying operating system), and provide ways for the library user to override this functionality, or not depend on those at all (simple example: allow to provide input data via memory instead of letting the library call into the C runtime I/O functions). Same for threading: instead of spawning threads inside the library, provide an API which takes "chunks of work", and let the library user care about doing this across multiple threads.