LWJGL Forum

Programming => Vulkan => Topic started by: LapisSea on October 05, 2017, 18:41:11

Title: How would I compile shaders to spv without the glslangValidator file but in code
Post by: LapisSea on October 05, 2017, 18:41:11
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:

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.
Title: Re: How would I compile shaders to spv without the glslangValidator file but in code
Post by: KaiHH on October 05, 2017, 19:39:49
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.
Title: Re: How would I compile shaders to spv without the glslangValidator file but in code
Post by: LapisSea on October 05, 2017, 19:49:35
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.
Title: Re: How would I compile shaders to spv without the glslangValidator file but in code
Post by: elect on July 11, 2018, 16:18:51
There is actually a binding (https://github.com/scenerygraphics/spirvcrossj)

I have used it successfully and can confirm it works flawless (done a couple of graphic samples + compute)
Title: Re: How would I compile shaders to spv without the glslangValidator file but in code
Post by: LapisSea on July 11, 2018, 16:30:08
Oh yeah! I actually found that on accident! Works really well for me