Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use glslang

I am trying to use glslang to compile glsl shader code to SPIR-V binaries. The glslang project can be found here:

https://github.com/KhronosGroup/glslang

It works well via the glslangValidator.exe manually in the command line. But i would like to use the c++ interface.

I have build the project as described on the github page, and now I am struggling with how to actually use the interface.

I would rather not actually include any projects in my solution (I am using Visual Studio), but link the .lib's and headers needed to use it. I just cannot find out which ones i need to link. The github page only mentions ShaderLang.h and StandAlone.cpp, which is not enough.

Can someone explain how to setup a project where you can use glslang? I need it only for compiling glsl shader code to SPIR-V binaries (with debugging info about the shader compilation). I Suppose this would be a very easy question for someone who has already done it, or has more experience.

like image 206
Aedoro Avatar asked Jul 06 '16 22:07

Aedoro


2 Answers

There are several libs you need to use. An example consumer to look at is LunarGLASS: https://github.com/LunarG/LunarGLASS. There, you can see the file:

https://github.com/LunarG/LunarGLASS/blob/master/CMakeLists.txt

Which inside contains this for the libraries:

set(GLSLANGLIBS
    glslang
    HLSL
    OSDependent
    OGLCompiler
    SPIRV)

The readme for glslang contains some important information. In addition, within glslang, the glslangValidator tool (basically StandAlone.cpp) shows how to use the API for the libraries. You can also see the Frontends/glslang directory in the LunarGLASS project for a similar use.

like image 90
johnkslang Avatar answered Oct 07 '22 14:10

johnkslang


The Shaderc project at https://github.com/google/shaderc provides an easy-to-use C++ API that wraps around Glslang's compiler to SPIR-V.

For example usage, see https://github.com/google/shaderc/blob/master/examples/online-compile/main.cc

like image 36
David Neto Avatar answered Oct 07 '22 15:10

David Neto