LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: How would I compile shaders to spv without the glslangValidator file but in code  (Read 367 times)

LapisSea

  • Newbie
  • *
  • Offline Offline
  • Posts: 7

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.
Logged

KaiHH

  • Newbie
  • *
  • Offline Offline
  • Posts: 16

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.
Logged

LapisSea

  • Newbie
  • *
  • Offline Offline
  • Posts: 7

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.
Logged