| From [1]: > When writing SPIR-V, you can’t have two integer types of the same width. Or two texture types that match. All non-composite types have to be unique for some reason. We don’t have this restriction in Naga IR, it just doesn’t seem to make any sense. For example, what if I’m writing a shader, and I basically want to use the same “int32” type for both indices and lengths. I may want to name these types differently This doesn't really make sense for IR. IR is not meant to be human writeable. It's meant to be generated by a compiler. So, having a one to one mapping between concept and name in the IR is a feature, not a bug. Honestly, WGSL just repeats the JavaScript mistake: where we should have started with something like WASM instead of JavaScript. And JS could have been just one of the many languages that targeted WASM. We were this close to not repeating this mistake by adopting an IR language (SPIR-V) for WebGPU, but then that got abandoned mostly for political reasons. Too bad. Now we get to write transpilers and hacks for decades to come, just like web people have been trying to paper over JS problems for decades. |
Do you consider the name for a type to be a part of the concept? SPIR-V doesn't. Overall, if you wanted one-to-one mapping, at least that would be consistent. But SPIR-V decided to require this only for simple types, while you can still have duplicate composite types.
> Honestly, WGSL just repeats the JavaScript mistake: where we should have started with something like WASM instead of JavaScript. And JS could have been just one of the many languages that targeted WASM.
We don't know if Web would be nearly as successful if it started with WASM instead of JS. The ability to just open a text editor and make a web page has served well in the early days.
> We were this close to not repeating this mistake by adopting an IR language (SPIR-V) for WebGPU, but then that got abandoned mostly for political reasons.
Look at the situation today: the very same people who were rooting for SPIR-V are currently introducing features the diverge WGSL away from SPIR-V, further and further. It's quite telling, I think. The moral of the story is: regardless of reasons (which we can argue a ton), WG members admit that what we ideally need is not SPIR-V, and this is supported by the way WGSL is shaping.