3

I would like to compile my GLSL shaders to SPIR-V binaries, and use that in my OpenGL project.

I've found glslang, using I can compile the glsl shaders to spir-v. But I haven't found any tutorials about how to use it in my C++ project. How to load these binaries and create shader programs from them?

Iter Ator
  • 8,226
  • 20
  • 73
  • 164

1 Answers1

5

Load the SPIR-V binary just like you're loading any other binary file in C++. Then, when you're compiling shaders, you must call glShaderBinary and glSpecializeShader:

GLuint vertexShader = glCreateShader( GL_VERTEX_SHADER );
glShaderBinary( 1, &vertexShader, GL_SHADER_BINARY_FORMAT_SPIR_V_ARB, vertexData, sizeof( vertexData ) ); // vertexData is the SPIR-V file contents
glSpecializeShader( vertexShader, "main", 0, nullptr, nullptr );
glAttachShader( program, vertexShader );
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87