2
$\begingroup$

I'm making a cross-platform application, and i need my shaders to be compiled to SPIR-V for both Opengl and Vulkan. It seems that the only way to do so is to call a separate program, called "glslangValidator.exe/.deb/.dmg". This sort of makes it cross-platform, but it requires me to change the command that calls the program on each platform (and that's not ideal to me). Can i embed some code or use something else to compile shaders directly from my application?

$\endgroup$
  • $\begingroup$ Be advised that, in some cases, the same construct in GLSL can mean subtly different things in OpenGL and Vulkan. Not to mention the differences in layout qualifiers for resource binding. $\endgroup$ – Nicol Bolas Oct 2 '18 at 20:10
4
$\begingroup$

Typically compiling GLSL to SPIRV would be something you do as part of the build process, so that you end up distributing SPIRV instead of GLSL. Then you don't need to compile it at runtime. Assuming you're using the Vulkan SDK, the binary for glslangValidator (or a shell script to build it) should be part of the installed SDK.

That said, if you want to compile GLSL to SPIRV at runtime, you can link against the glslang library and do that. Take a look at the Programatic Interface section in the readme.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.