Last I looked at creating shaders that work across various platforms & APIs (i.e. shader translation hlsl -> glsl) it was quite a mess. I know you wrote about this topic on your blog a while ago. Have things improved since?

I hope that they did to some extent, however I have not personally used any of these new shader cross-compilers, so can't vouch for them.
The situation right now in 2016 seems to be:
If you need DX9-level HLSL (with a tiny bit of DX10 things, like instance IDs and some texture arrays), then using hlsl2glslfork + glsl-optimizer is still probably the most "battle tested" solution (being used in Unity and so on). However, the DX9 HLSL syntax is starting to get old. This can get conversion from DX9 HLSL into: GL2.x, GLES2.0, GLES3.0, Metal.
For a "mostly DX9 HLSL but with somewhat more DX10 stuffs", I'd look at HLSLParser , specifically Thekla's fork of it ( This recently got Metal conversion backend too (from The Witness game port to Metal I guess), and a bunch of improvements from ROBLOX folks. This, as far as I can tell, can get you conversion into OpenGL (possibly ES too?) and Metal.
Khronos' glslang ( is getting a HLSL parsing frontend recently, which seems to be targeted at full DX11 HLSL syntax, and is under very active development, with compute shader bits being done as we speak. So this can take GLSL or HLSL as input, and can output SPIR-V (which can be used directly in Vulkan). Another tool, SPIRV-Cross ( could be used to convert that into GLSL or Metal. Possibly with some optimization step via SPIRV-Tools in the middle (
There's a DX11 bytecode level translator (as in, compile HLSL with actual D3DCompiler/fxc, and translate the bytecode into GLSL) via HLSLCrossCompiler -- my impression is that it needs "a lot" of tweaks on top to be "production ready". We use a fork of it in Unity, but the people working on it haven't got around to push their changes somewhere public. I just know they did *a lot* of changes :)
And then Microsoft at GDC2016 talked about their upcoming open source HLSL compiler, that would be built on top of clang+llvm, and I think they talked about "end of 2016" as potential release date. But I haven't heard updates on that. This of course would only be a HLSL -> DXIL toolchain, but if it were open source then I guess someone could make DXIL -> SPIR-V translator, and from there to other backends via SPIRV-Cross.
So, in summary: right now, for modern HLSL I'd take a look at Khronos' glslang + SPIRV-Cross. If you can wait a bit until Microsoft ships their new HLSL compiler, then would be worth taking a look at that too.

View more

  • 61
  • 31

About Aras Pranckevičius:

Graphics programmer and code plumber at Unity

Kaunas, Lithuania

#graphics #programming