Writing GPU Shaders in Julia

I was going over the GLAbstraction tutorials to learn how do do simple animations on the GPU, and things work fairly well.

One pain point, however, is that the shaders needs to be written in a special language, meaning that they clash with the rest of the code. Is it possible to compile shaders from julia code?

Rust has rust-gpu, but I could not find anything similar for Julia.

Notice that the rust code in the example looks a lot like shader language code. For some limited subset of Julia syntax, it’s probably relatively straight-forward for a macro to generate a shader langage code string, but that would likely be unsatisfying. It would be sort of like this situation Aliases for `=` and `==` - #19 by Jeff_Emanuel

There was a PR out for this a few years ago on VulkanCore: WIP compile julia to spir-v by carnaval · Pull Request #4 · JuliaGPU/VulkanCore.jl · GitHub. However, it’s a non-trival effort because LLVM doesn’t have a SPIR-V backend. oneAPI.jl works around this by using GitHub - KhronosGroup/SPIRV-LLVM-Translator: A tool and a library for bi-directional translation between SPIR-V and LLVM IR, but it only supports OpenCL kernels and not OpenGL/Vulkan shader SPIR-V. Rust-GPU had to essentially write their own backend from scratch.

1 Like

Thanks for these links.

I suppose the best way forward is to wait for this LLVM translator to gain support for shaders, and then we can call it from julia.