How would I compile shaders to spv without the glslangValidator file but in code

Started by LapisSea, October 05, 2017, 18:41:11

Previous topic - Next topic

LapisSea

Hi I recently started porting my game from opengl to Vulkan.
Now I got stuck on shaders. I have this system where I generate many shaders from "modules" depending on what a model needs. (if some face need to be glowing then add glowing module to shader source)
Now this was no issue in opengl as I could simply give the generated source to opengl and it would compile it. So I can't just include some compiled shaders in the game as I allow for user created content. (mods and similar)

Solutions:

  • Compile source to spv from glsl directly in game
  • Force user to have vulkan sdk installed and use command line to call glslangValidator.exe
  • Drop the whole system and lose on performance

Sooo.... first option is by far the best one. I know you can do it in c++ but I am really not sure how I would go about this in LWJGL3.
Building a vulkan rendering engine for fun! :D

KaiHH

There are no bindings to GLSL/SPIR-V compilers currently in LWJGL3 to support option 1.
It'd sure be a nice opportunity to add one, though.
See: https://github.com/LWJGL/lwjgl3/issues/77#issuecomment-137675918
Google's shaderc/libshaderc, integrating glslang and SPIR-V Tools, has a particularly simple C API, which I wrote a custom JNI binding to a while ago.
So, it should be very easy to port this to LWJGL3's binding approach with a Kotlin template.

LapisSea

Thanks for the info!  :)
This is means green light for option 2. (however i'd not recommend this as a final solution to anyone with similar problem...)
Hoping that it becomes a reality in next year or so.
Building a vulkan rendering engine for fun! :D

elect

There is actually a binding

I have used it successfully and can confirm it works flawless (done a couple of graphic samples + compute)

LapisSea

Oh yeah! I actually found that on accident! Works really well for me
Building a vulkan rendering engine for fun! :D