Dcompute on OpenGL / HLSL compute
Nicholas Wilson
iamthewilsonator at hotmail.com
Thu Sep 9 04:42:33 UTC 2021
I'm happy to announce that I've managed to generate OpenGL
compute shaders from the OpenCL compilation pipeline. Through the
use of https://github.com/KhronosGroup/SPIRV-Cross the means that
we can generate GLSL, HLSL and MSL source
The setup and compilation steps is very janky at the moment but
does produce legit looking GLSL/HLSL. I say looks, because I lack
the means to run it at the moment. This will hopefully become
less janky in the future.
To produce a compute shader source you will need:
ldc built with
https://github.com/KhronosGroup/SPIRV-LLVM-Translator as with the
regular means of producing OpenCL SPIR-V,
https://github.com/google/clspv/ with
https://github.com/google/clspv/pull/764 applied to convert the
OpenCL SPIR-V to OpenGL compute SPIR-V and
https://github.com/KhronosGroup/SPIRV-Cross to convert the
resulting GL compute SPIR-V to HLSL/MSL if desired.
The full compilation steps are then (I did say it was janky):
```
ldc2 --mdcompute-targets=ocl-200 -m32 ./kernel.d other_files.d
-Iother_imports
llvm-spirv -r kernels_ocl200_32.spv
llvm-dis kernels_ocl200_32.bc
clspv -x=ir kernels_ocl200_32.ll
# and optionally
spirv-cross --hlsl a.spv --output a.hlsl
```
32-bit mode for ldc is required because only 32-bit OpenCL SPIR-V
can be converted into OpenGL compute SPIR-V. If `-m32` doesn't
work the you may have to supply an equivalent `-mtriple`
More information about the Digitalmars-d-announce
mailing list