4 ms·
eh, I think the game is given away when kvark self-admits in that post that he's never written a compiler before, or done parsing before. Yes, SPIR-V is weird
by Jasper_ 3y ago
eh, I think the game is given away when kvark self-admits in that post that he's never written a compiler before, or done parsing before.
Yes, SPIR-V is weird and confusing... if you've never worked on a compiler. A lot of it is relatively standard if you have. Some of the messy control flow stuff got pretty massively cleaned up by the POPL paper. [0]
The issue is that Naga wants to support SPIR-V, but doesn't want to grow to become a full compiler. e.g.
> When writing SPIR-V, you can’t have two integer types of the same width.
This makes compilers much easier as now you can guarantee that all types are uniquely comparable by index. Just shove the type in an array, done.
> However, it can also declare an output “interface struct” with a bunch of special built-ins and an empty name… Perhaps, it’s a mechanism that helps with tessellation shaders. But for us in Naga land that caused more trouble than good.
No clue why you would care, unless you just blindly broadcast names when translating from SPIR-V. But also, don't do that? It's fine for things to have no names.
> Later I was pointed to the fact that all the existing production tools for generating SPIR-V (namely, glslang and dxc) only do so for a concrete entry point. So the multiple entry points is there in spirit, but discriminated in practice by the driver bugs, as well as this little validation rule.
Yeah, this is unfortunate. Multiple entry points are one of those things that make it seem easy to write a translator. Unfortunately, they're under-tested, not in the CTS, as glslang/DXC don't support them, and aren't how most shader pipelines tend to work.
Anyway, I don't want to enumerate all of this. SPIR-V has issues, sure, but it can be simultaneously true that SPIR-V isn't flawless, while also being true that it's the best version of this that anyone's seen yet.
[0] https://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2023/POPL.pdf https://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2023/POP...