154 points · by pplonski86 · 7y ago · 23 comments
Everyday we stray further from god's light.
Edit: grammar
- Evolving API design in Rust — Simon Nicholas Heath (https://www.youtube.com/watch?v=Xt1JOVeQ5hw)
AFAIK DX12 still requires DXIL so it might be saving both SPIR-V and DXIL, or taking in HLSL and compiling/translating as needed.
Microsoft has generally gotten a lot friendlier in the last decade, they have tools to compile HLSL down to SPIR-V, if you want to support everything including DX12 you'll probably be writing HLSL. Otherwise you can pick any language that compiles down to SPIR-V.
GLSL gets compiled to SPIR-V ahead of time by a compiler of your choice (probably glslangValidator). You can take that binary blob and feed it into Vulkan (vkCreateShaderModule) or OpenGL (glShaderBinary as long as you have the right extension).
For everything else, Khronos has a tool called SPIRV-Cross (second link), which reads the SPIR-V binary data and emits a text file/string in ESSL for OpenGL ES, MSL for Metal, or HLSL for DirectX <=11. Those all go through the "normal" paths for loading shader code in their own APIs.
To try to answer your original question, I've never used gfx, but we use SPIRV-Cross in mpv to translate video processing shaders written in GLSL to HLSL for Direct3D 11, and it works quite well. Modern GLSL and HLSL seem to be pretty similar, apart from using different coordinate systems. Most HLSL concepts directly map to a GLSL concept (eg. GLSL UBOs become HLSL cbuffers, etc.) Shader translation with SPIRV-Cross definitely isn't the slowest part of our shader compilation pipeline, either. D3DCompile is much slower.
Not trying to be rude, but I'd just like to point out the apostrophe on API's indicates ownership, as in "John's dog jumped". APIs is fine, as in "John has two dogs".