Compiling HLSL to Vulkan

Started by
3 comments, last by Matias Goldberg 8 years ago

Recently I've been playing around with a prototype for compiling HLSL to Vulkan. This seems like a kind of useful thing to do, so I was wondering if anyone else has tried it (using this approach, or maybe some other approach).

My prototype uses James Jones' cross compiler for this. The cross compiler takes HLSL bytecode and generates GLSL code. So the compilation steps are:

  • HLSL -> HLSL bytecode
  • HLSL bytecode -> GLSL
  • GLSL -> SPIR-V

In theory, it seems like a viable approach, because HLSL bytecode is a reasonably simple language. And while hand-optimising code would be difficult with this approach, the compiler optimisation should still be effective.

In practice, each compilation step has it's own set of idiosyncrasies. In particular, the cross compiler needs a bit of love and attention. I've been working on adding support for the Vulkan SDK's particular subset of GLSL. And also fixing translation errors as I come across them (my branch is here, btw)

Anyway, it's such a useful thing, my guess is that maybe other people have tried similar approaches? I'd love to hear about it if so.

Advertisement

It should be possible (and more useful) to remove GLSL entirely from this, and do HLSL bytecode directly to SPIR-V.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I'd love to use OpenCL language for compute shaders in Vulkan.
It might be possible to use goodies like 2.0 workgroup functions (broadcast, reduce, scan...) that work without LDS.
It really hurts those features are still hidden from PC APIs.

Apparently with the next version of HLSL, MS is moving over to using LLVM as the back-end for their compiler, which should make a direct HLSL->SPIR-V project a lot easier :)

I'd love to use OpenCL language for compute shaders in Vulkan.
It might be possible to use goodies like 2.0 workgroup functions (broadcast, reduce, scan...) that work without LDS.
It really hurts those features are still hidden from PC APIs.

These are apparently coming in the new HLSL too ;)
I haven't looked as to whether they exist in SPIR-V yet, but that would obviously be a requirement.

There is an hlsl-frontend to compile HLSL to SPIR-V, but I don't know in which state it is.

This topic is closed to new replies.

Advertisement