Years ago when I was trying to clone Firefox’s and Chrome’s code bases WebIDL capabilities in order to simplify native bindings in Titanium SDK, I would have killed for such an article. Very interesting!
I've been looking around, and it seems WebGPU is doing the same things we've been using WebGL for. Is it a more generic interface that also allows for arbitary computation? (a la GPGPU)
> it seems WebGPU is doing the same things we've been using WebGL for.
Not really the same though, the purpose of WebGPU is exposing a sandboxed GPU hardware directly to the web, not exposing just a graphical API like WebGL exposes OpenGL variants.
It currently is looking at being SPIR-V compatible. As both Vulkan and OpenCL supports SPIR-V we might use WebGPU for GPGPU in the future.
Vulkan and OpenCL use two drastically different profiles of SPIR-V. You cannot just take OpenCL kernels and run them as compute shaders, huge portions of the execution model are different.
I'm not entirely convinced spriv is good for webdev. imagine the only way to code in a browser was to use an offline compiler to emit byte code. some people might like that but I'd argue there have been many indirect benefits to having the text version of JavaScript be the default on the web.
sure there will be workarounds like building your own DSL to spriv compiler and including it on your page but I'd argue a standard high level text format leads to more collaboration / standardization / interop / knowledge sharing
I'm sure others would prefer the web had just started as sandboxed assembly
I've had enough experience with deploying GLSL on many Android devices and also WebGL to be disillusioned with it. There's no great modern textual shading language out there, GLSL is missing a lot of modern niceities, HLSL isn't really an "independent language" (could talk more about that), and Apple's WHLSL/WSL proposal is drastically underspec'd to the point of hilarity.
I think if you want to compile shaders from source, you are free to include your favorite transpiler as WebAssembly, like glslang. That's currently what I'm doing for my WebGPU prototype project.
Generic types are probably one of the biggest ones. GLSL has generic builtins, but you can't define your own. But besides that, HLSL's support and management of buffers and bindings is a great deal saner than GLSL's. Especially the new syntax for loading structures from a ByteAddressBuffer. Beats the craziness that is SSBOs and image load/store.
GLSL's upbringing with integrated texture/samplers is a bit ridiculous in a separable texture/sampler world, like in Vulkan. You need to create an integrated texture/sampler with the sampler2D constructor, and then immediately use it. The GLSL spec specifically says you can't pass it to your own user-created functions, I'm guessing because they didn't trust platform vendors to write working compilers?
You also can't put any binding object like texture2D in a struct, even though you can pass it between functions? The whole enterprise really feels like it was limitations in baby's-first-compiler that added a bunch of weird restrictions.
HLSL is a C++-esque derivative that supports quite a bit more functionality than you probably imagine, and a lot less of the goofy limitations, given that it has a single compiler stack made by a company with competent compiler engineers.
As someone who has written in every shader dialect and also dealt with bytecode for all the major consoles, I think SPIR-V is really awesome tbh...
The thing is, a text format is the worst format for interoperability between consoles, desktop and web. Having something like SPIR-V is more akin to LLVM for programming languages. LLVM doesn't preclude the existence of C, C++, etc, but it strictly benefits the ecosystem (which now includes Rust, Haskell, etc). In the same way, I see SPIR-V having the same potential as the interchange format for all the major IHVs.
SPIR-V already has a lot of collaboration, and will provide natural synergy with non Web use cases, since it's the standard bytecode format for shaders there already. So collaboration argument goes for SPIR-V here.
Human readability of the shader shipped from the page is a different argument, and it can have some merit, but the same could be argued against using WebAssembly for instance which is not very human readable in comparison with JavaScript. I don't think it's a strong argument against using it.
SPIR-V “assembly” can be disassembled, the disassembly is fairly easy to read, and it's not that hard to write by hand, though rather verbose.
An advantage of SPIR-V is that unlike both text-based programming languages and traditional machine code, SPIR-V is very very easy for machines to read and write — even for JS code — and it has a structure designed to be (mostly) cleanly extensible.
During Metal Shading Language's development, there were multiple opportunities to engage for Apple to open up their shading language toolchain, and make MSL a standard that would be respected by multiple people. They ignored that advice, and now lots of people grumble about writing MSL. It is, in many people's eyes, a quite decent shading language, but it's "different enough" and for a niche enough platform (in the games world) that it pays the price heavily. Tooling is pretty abysmal, and GPU debugging in Xcode is not the greatest experience.
Now, with that said, Apple did not propose MSL to the WebGPU working group either. Apple originally proposed a hilariously underspecified fork of HLSL called WHLSL which had three goals: 1. Be a safe shading language for the web, 2. Be compatible with existing HLSL content, 3. Add pointers.
Nobody ever justified the existence of that last one to me or the rest of the group, other than making the Metal implementation slightly easier for Safari, since Metal's binding model is based on pointers, and coincidentally, the Safari pre-release only supported binding pointers, and not the standard HLSL way of doing things. But still, the WHLSL proposal was interesting to a lot of people because HLSL seemed like a good language to start from.
After a lot of debate, Apple secretly went back to the drawing board, and released a revised version of the language, WSL, which dropped the goal of HLSL compatibility but still has pointers for some reason. Nobody has ever explained why it has pointers, despite everyone continuing to ask. The goals are still there if you want to read them [0].
Thanks for the summary. It highlights how "collaboration" from Apple's perspective works. Throwing something over the fence, and then going back to discuss things in secret.
The track record of industry GPU language development is very poor (arguably even disastrous).
I worry that we now just count on nice languages / compilers magically appearing deus ex machina, and we end up not having any. Big multiplatform frameworks like Unity will just put a SPIR-V backend on their existing tooling.
The rest of us will be stuck with POC-quality GLSL transpiler tools, without the browser devtools and other tooling support that we slowly got over the ~10 years of WebGL history.
(I'm not saying GLSL is that excellent, just that could be heading backwards from current almost-good-enough GLSL implementation quality in WebGL.)
Metal Shading Language is a C++ dialect. HLSL is as much of a C dialect as GLSL is. And I would argue that C++ provides no benefits over C for shading languages.
Moved but remained proprietary. So the problem is not solved. Language shouldn't be proprietary to begin with. It's an obsolete and invalid practice from the last century.
Apparently not, given the monthly occurrence of FOSS projects that decide to go dual license, or even back to proprietary, because this century practice doesn't cover their existence and life responsibilities.
For languages? That's a dead end really. That's why whatever Apple will produce will also be dead, as long it's proprietary. Apple is stuck in that mentality and has hard time getting out of it.
It kind of has, if Khronos never provides anything better, as it has been proven before, hardly anyone will step up to improve it, until the standard starts being put aside in preference to proprietary middleware or competing APIs.
There is nothing wrong per se with SPIR-V to provide anything much better. What you said has indeed nothing to do with the intermediate language itself.
It's relevant to what you choose to use as the standard. A language can be fine on its own terms, but also you should only install it with a layer on top and not by itself.
Yeah, around 500 boilerplate lines of code to draw a triangle on Vulkan, plus having to going hunting for features that every graphics application requires and all other APIs provide on their SDKs.
With Khronos APIs, every newbie graphics developer learns to build their engine from day one.
But for bug reports, debugging and fixing bugs in the shader compiler, validation layers, etc they are pretty responsive to issue reports and pull requests.