The GLSL module is used to streamline applications by embedding SPIR-V inside the executable binary, avoiding the need to load a file from disk at runtime containing the SPIR-V. This module also tracks depencies between GLSL, SPIR-V, and the execuable. Liberating developers from having to manually run the glslang compiler to generate SPIR-V after every GLSL shader modifications.
See also
Embedding SPIR-V in an application is done as part of our VectorAddition
Vulkan example which uses this CMake module.
UnitVK
Vulkan unit tests also make uses of GLSL.cmake
to avoid
having to maintain paths to shader files, allowing the test executable to be
moved between directories without keeping track of the shader file
dependencies.
Utilities to compile GLSL compute shaders to SPIR-V binaries and convert them to header files at build time. This module depends on the Bin2H Module and CAPlatform Module modules to function. To use these utilities:
include(GLSL)
add_glsl_command(
${path_to_input}/file.comp
${path_to_output}/file.spv)
add_glsl_target(my_spv
${path_to_input}/file.comp
${path_to_output}/file.spv)
add_glsl_bin2h_command(my_spv
${path_to_input}/file.comp
${path_to_output}/file.h)
add_glsl_bin2h_target(my_spv
${path_to_input}/file.comp
${path_to_output}/file.h)
- add_glsl_command
The
add_glsl_command
macro creates a custom command which compiles a GLSL compute shader into a SPIR-V binary using glslangValidator provided by the Vulkan SDK.- Arguments:
input
: The GLSL compute shader source filepathoutput
: The SPIR-V binary output filepath
- add_spvasm_command
The
add_spvasm_command
macro creates a custom command which compiles a hand-written SPVASM compute shader into a SPIR-V binary using spv-as provided by the Vulkan SDK.- Arguments:
input
: The GLSL compute shader source filepathoutput
: The SPIR-V binary output filepath
- add_glsl_target
The
add_glsl_target
macro creates creates a custom target which compiles a GLSL compute shader into a SPIR-V binary and used in CMake dependency tracking.- Arguments:
target
: The name of the targetinput
: The GLSL compute shader source filepathoutput
: The SPIR-V binary output filepath
- add_glsl_bin2h_command
The
add_glsl_bin2h_command
function creates a custom command which compiles a GLSL compute shader into a SPIR-V binary then generates a header that can be included into source code.See also
See add_bin2h_command documentation for more information.
- Arguments:
variable
: The name of the variable to access the data in the header fileinput
: The GLSL compute shader source filepathoutput
: The header filepath to generate
- add_spvasm_bin2h_command
The
add_spvasm_bin2h_command
function creates a custom command which compiles a hand-written spvasm compute shader into a SPIR-V binary then generates a header that can be included into source code.See also
See add_bin2h_command documentation for more information.
- Arguments:
variable
: The name of the variable to access the data in the header fileinput
: The SPVASM compute shader source filepathoutput
: The header filepath to generate
- add_glsl_bin2h_target
The
add_glsl_bin2h_target
macro creates a custom target which compiles a GLSL compute shader into a SPIR-V binary then generates a header that can be included into source code and use the target in CMake dependency tracking.- Arguments:
target
: The name of the target and the name of the variable to access the data in the header fileinput
: The GLSL compute shader source filepathoutput
: The header filepath to generate