Hello Guest

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

  • 4 Replies
  • 10010 Views
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.
« Last Edit: October 05, 2017, 19:41:02 by LapisSea »
Building a vulkan rendering engine for fun! :D

*

Offline KaiHH

  • ****
  • 334
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.

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

*

Offline elect

  • *
  • 20
There is actually a binding

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

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