[SPIR-V]: We should define a safe subset of SPIR-V and accept it directly in WebGPU implementations.
<SPIR-V is too low level>: SPIR-V is meant to be fed into drivers, as well as processed by tools, while WebGPU needs to be able to generate HLSL and MSL, which are higher level. This makes some translation paths inefficient and awkward to implement.
[Text formats are better on the Web]: Using a text human readable format is more idiomatic to the Web.
+
JavaScript is the language of the Web.
+
Being able to see the web source and tinker with it was one of the principles of the Web as it was emerging, and it's still important today.
-
WASM is the new form of the language of the Web, and it's binary.
-
Parsing a text format is more complex and takes more time than parsing a SPIR-V binary.
-
shader parsing is only a couple of % for the time total spent in a pipeline creation. Most time is still spent within the driver.
-
Text is more verbose and redundant, from the point of view of the data transferred from the client.
-
there is no indication that text-based shaders are going to be larger than SPIR-V, which is known for its big size. Compressed, text should be close in size, if not smaller.
-
Text format is more complex than binary
-
complexity is independent of the form. There can be complex binary languages and simple text ones.
Khronos working group has different constraints, it doesn't have any obligation to make SPIR-V changes that WebGPU would need.
(2)
It is likely that WebGPU would need to have different versions of the same functionality present in core SPIR-V, like the instructions for ray tracing.
<Nobody wants yet another shading language>: we already have a diversity of shading languages, as well as huge shader code bases. Adding support for another one is something nobody is excited about.
<SPIR-V is well-specified>: It's an existing modern shading language that has a very detailed specification and a good conformance test suite.
-
SPIR-V isn't tested directly, but rather via GLSL
-
It's specified in 2 different documents: language itself and the execution environment. Sometimes it's not easy to figure out which of them is responsible for describing a particular behavior.
-
WebGPU could compile both of these pieces together with the main specification
+
It has a memory model
-
WebGPU can borrow the memory model without taking the full SPIR-V
There are libraries for reflecting SPIR-V in popular languages: C++, Rust, Go, Python etc.
+
There is both an optimizer and a validator in SPIRV-Tools.
+
SPIRV-Cross exists, it can translate SPIR-V into MSL, HLSL, and GLSL
-
After inspecting it and experimenting with it, both Google and Mozilla decided to not use SPIRV-Cross. It's hard to bring it into shape that will be suitable for shipping in a browser.