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.

I’m pretty much sold on Julia good for GPUs (and TPUs), for calculations, i.e. GPGPU, I understand even the best language for.

And it also has OpenGL and Vulkan support, and I recall 99% as fast as C++ for OpenGL. Would you say as good for (low-level) graphics/shading, i.e. (scanlline) rendering?

It may not matter, as ray-tracing is taking over from scanline rendering, and I haven’t seen any discussion about using Julia for that. Also with higher-level, e.g. game engines in C++, Julia is likely not to take over from graphics soon, mayby game logic? Still curious what your feelings are about Julia (theoretical) capability for graphics, i.e. feature completeness.