MCPcopy Create free account
hub / github.com/KhronosGroup/glslang

github.com/KhronosGroup/glslang @16.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 16.3.0 ↗ · + Follow
3,690 symbols 13,134 edges 173 files 1,214 documented · 33% updated 4d agomain-tot · 2023-01-30★ 3,546409 open issues

Browse by type

Functions 3,297 Types & classes 393
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Continuous Integration Continuous Deployment OpenSSF Scorecard

News

  1. The HLSL front-end is deprecated as of April 2026 and will be removed at the next major version of glslang. See issue #4210 for rationale and migration guidance.

  2. The --shift-texture-binding[s] option no longer affects combined samplers. The new --shift-combined-sampler-binding[s] option should be used to control combined sampler bindings independently from separate textures. The old behavior can be achieved by setting both options to the same value.

  3. The spirv-remap utility from glslang has been ported to the SPIRV-Tools repository as a new optimization pass called canonicalize-ids, available in spirv-opt. See spirv-opt --help for usage details.

  4. Building glslang as a DLL or shared library is now possible and supported.

Glslang Components and Status

There are several components:

Reference Validator and GLSL/ESSL -> AST Front End

An OpenGL GLSL and OpenGL|ES GLSL (ESSL) front-end for reference validation and translation of GLSL/ESSL into an internal abstract syntax tree (AST).

Status: Virtually complete, with results carrying similar weight as the specifications.

HLSL -> AST Front End

An HLSL front-end for translation of an approximation of HLSL to glslang's AST form.

Status: Deprecated as of April 2026. The HLSL front-end will be removed at the next major version of glslang, with at least 18 months of notice from this announcement.

Bug reports for the HLSL front-end will no longer be accepted. Security issues will be assessed on a case-by-case basis. Projects that require continued HLSL support should maintain a fork of glslang at the tag corresponding to the deprecation announcement.

See issue #4210 for the rationale and migration guidance.

AST -> SPIR-V Back End

Translates glslang's AST to the Khronos-specified SPIR-V intermediate language.

Status: Virtually complete.

Reflector

An API for getting reflection information from the AST, reflection types/variables/etc. from the HLL source (not the SPIR-V).

Status: There is a large amount of functionality present, but no specification/goal to measure completeness against. It is accurate for the input HLL and AST, but only approximate for what would later be emitted for SPIR-V.

Standalone Wrapper

glslang is command-line tool for accessing the functionality above.

Status: Complete.

Tasks waiting to be done are documented as GitHub issues.

Other References

Also see the Khronos landing page for glslang as a reference front end:

https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/

The above page, while not kept up to date, includes additional information regarding glslang as a reference validator.

How to Use Glslang

Execution of Standalone Wrapper

To use the standalone binary form, execute glslang, and it will print a usage statement. Basic operation is to give it a file containing a shader, and it will print out warnings/errors and optionally an AST.

The applied stage-specific rules are based on the file extension: * .vert for a vertex shader * .tesc for a tessellation control shader * .tese for a tessellation evaluation shader * .geom for a geometry shader * .frag for a fragment shader * .comp for a compute shader

For ray tracing pipeline shaders: * .rgen for a ray generation shader * .rint for a ray intersection shader * .rahit for a ray any-hit shader * .rchit for a ray closest-hit shader * .rmiss for a ray miss shader * .rcall for a callable shader

There is also a non-shader extension: * .conf for a configuration file of limits, see usage statement for example

Building (CMake)

Instead of building manually, you can also download the binaries for your platform directly from the [main-tot release][main-tot-release] on GitHub. Those binaries are automatically uploaded by the buildbots after successful testing and they always reflect the current top of the tree of the main branch.

Dependencies

  • A C++17 compiler. (For MSVS: use 2019 or later.)
  • [CMake][cmake]: for generating compilation targets.
  • make: Linux, ninja is an alternative, if configured.
  • [Python 3.x][python]: for executing SPIRV-Tools scripts. (Optional if not using SPIRV-Tools and the 'External' subdirectory does not exist.)
  • [bison][bison]: optional, but needed when changing the grammar (glslang.y).
  • [googletest][googletest]: optional, but should use if making any changes to glslang.

Build steps

The following steps assume a Bash shell. On Windows, that could be the Git Bash shell or some other shell of your choosing.

1) Check-Out this project

cd <parent of where you want glslang to be>
git clone https://github.com/KhronosGroup/glslang.git

2) Check-Out External Projects

./update_glslang_sources.py

3) Configure

Assume the source directory is $SOURCE_DIR and the build directory is $BUILD_DIR. CMake will create the $BUILD_DIR for the user if it doesn't exist.

First change your working directory:

cd $SOURCE_DIR

For building on Linux:

cmake -B $BUILD_DIR -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/install"
# "Release" (for CMAKE_BUILD_TYPE) could also be "Debug" or "RelWithDebInfo"

For building on Android:

cmake -B $BUILD_DIR -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$(pwd)/install" -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -DANDROID_STL=c++_static -DANDROID_PLATFORM=android-24 -DCMAKE_SYSTEM_NAME=Android -DANDROID_TOOLCHAIN=clang -DANDROID_ARM_MODE=arm -DCMAKE_MAKE_PROGRAM=$ANDROID_NDK_HOME/prebuilt/linux-x86_64/bin/make -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake
# If on Windows will be -DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_HOME%\prebuilt\windows-x86_64\bin\make.exe
# -G is needed for building on Windows
# -DANDROID_ABI can also be armeabi-v7a for 32 bit

For building on Windows:

cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX="$(pwd)/install"
# The CMAKE_INSTALL_PREFIX part is for testing (explained later).

Also, consider using git config --global core.fileMode false (or with --local) on Windows to prevent the addition of execution permission on files.

4) Build and Install

# for Linux:
make -j4 install

# for Windows:
cmake --build . --config Release --target install
# "Release" (for --config) could also be "Debug", "MinSizeRel", or "RelWithDebInfo"

If using MSVC, after running CMake to configure, use the Configuration Manager to check the INSTALL project.

Building (GN)

glslang can also be built with the GN build system.

1) Install depot_tools

Download depot_tools.zip, extract to a directory, and add this directory to your PATH.

2) Synchronize dependencies and generate build files

This only needs to be done once after updating glslang.

With the current directory set to your glslang checkout, type:

./update_glslang_sources.py
gclient sync --gclientfile=standalone.gclient
gn gen out/Default

3) Build

With the current directory set to your glslang checkout, type:

cd out/Default
ninja

If you need to change the GLSL grammar

The grammar in glslang/MachineIndependent/glslang.y has to be recompiled with bison if it changes, the output files are committed to the repo to avoid every developer needing to have bison configured to compile the project when grammar changes are quite infrequent. For windows you can get binaries from [GnuWin32][bison-gnu-win32].

The command to rebuild is:

bison --defines=MachineIndependent/glslang_tab.cpp.h
      -t MachineIndependent/glslang.y
      -o MachineIndependent/glslang_tab.cpp

The above command is also available in the bash script in updateGrammar, when executed from the glslang subdirectory of the glslang repository.

If you need to update the NonSemantic instruction headers

SPIRV/NonSemanticShaderDebugInfo.h and SPIRV/NonSemanticDebugPrintf.h are local copies of the canonical headers from SPIRV-Headers. They are kept here because the SPIRV-Headers include path is not unconditionally available in all glslang build configurations (it is only present when ENABLE_OPT is on).

When SPIRV-Headers publishes a new version of either header, copy the updated file from

External/spirv-tools/external/spirv-headers/include/spirv/unified1/

over the corresponding file in SPIRV/. After copying, verify that the build still compiles and update the golden test output if instruction names or opcode numbers changed.

Building to WASM for the Web and Node

Building a standalone JS/WASM library for the Web and Node

Use the steps in Build Steps, with the following notes/exceptions: * emsdk needs to be present in your executable search path, PATH for Bash-like environments: + Instructions located here * Wrap cmake call: emcmake cmake * Set -DENABLE_OPT=OFF. * Set -DENABLE_HLSL=OFF if HLSL is not needed. * For a standalone JS/WASM library, turn on -DENABLE_GLSLANG_JS=ON. * To get a fully minimized build, make sure to use brotli to compress the .js and .wasm files * Note that by default, Emscripten allocates a very small stack size, which may cause stack overflows when compiling large shaders. Use the STACK_SIZE compiler setting to increase the stack size.

Example:

emcmake cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GLSLANG_JS=ON \
    -DENABLE_HLSL=OFF -DENABLE_OPT=OFF ..

Building glslang - Using vcpkg

You can download and install glslang using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install glslang

The glslang port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Testing

Right now, there are two test harnesses existing in glslang: one is Google Test, one is the runtests script. The former runs unit tests and single-shader single-threaded integration tests, while the latter runs multiple-shader linking tests and multi-threaded tests.

Tests may erroneously fail or pass if using ALLOW_EXTERNAL_SPIRV_TOOLS with any commit other than the one specified in known_good.json.

Running tests

The runtests script requires compiled binaries to be installed into $BUILD_DIR/install. Please make sure you have supplied the correct configuration to CMake (using -DCMAKE_INSTALL_PREFIX) when building; otherwise, you may want to modify the path in the runtests script.

Running Google Test-backed tests:

cd $BUILD_DIR

# for Linux:
ctest

# for Windows:
ctest -C {Debug|Release|RelWithDebInfo|MinSizeRel}

# or, run the test binary directly
# (which gives more fine-grained control like filtering):
<dir-to-glslangtests-in-build-dir>/glslangtests

Running runtests script-backed tests:

cd $SOURCE_DIR/Test && ./runtests

If some tests fail with validation errors, there may be a mismatch between the version of spirv-val on the system and the version of glslang. In this case, it is necessary to run update_glslang_sources.py. See "Check-Out External Projects" above for more details.

Contributing tests

Test results should always be included with a pull request that modifies functionality.

If you are writing unit tests, please use the Google Test framework and place the tests under the gtests/ directory.

Integration tests are placed in the Test/ directory. It contains test input and a subdirectory baseResults/ that contains the expected results of the tests. Both the tests and baseResults/ are under source-code control.

Google Test runs those integration tests by reading the test input, compiling them, and then compare against the expected results in baseResults/. The integration tests to run via Google Test is registered in various gtests/*.FromFile.cpp source files. glslangtests provides a command-line option --update-mode, which, if supplied, will overwrite the golden files under the baseResults/ directory with real output from that invocation. For more information, please check gtests/ directory's README.

For the runtests script, it will generate current results in the localResults/ directory and diff them against the baseResults/. When you want to update the tracked test results, they need to be copied from localResults/ to baseResults/. This can be done by the bump shell script.

You can add your own private list of tests, not tracked publicly, by using localtestlist to list non-tracked tests. This is automatically read by runtests and included in the diff and bump process.

Programmatic Interfaces

Another piece of software can programmatically translate shaders to an AST using one of two different interfaces: * A new C++ class-oriented interface, or * The original C functional interface

The main() in `StandAlone/StandA

Core symbols most depended-on inside this repo

Shape

Method 2,859
Function 438
Class 319
Enum 74

Languages

C++99%
Python1%
TypeScript1%
C1%

Modules by API surface

glslang/Include/Types.h330 symbols
glslang/MachineIndependent/localintermediate.h249 symbols
glslang/Include/intermediate.h190 symbols
SPIRV/SpvBuilder.cpp181 symbols
glslang/MachineIndependent/ParseHelper.cpp178 symbols
glslang/HLSL/hlslParseHelper.cpp163 symbols
glslang/MachineIndependent/ShaderLang.cpp126 symbols
SPIRV/SpvBuilder.h126 symbols
SPIRV/GlslangToSpv.cpp120 symbols
glslang/MachineIndependent/SymbolTable.h119 symbols
glslang/MachineIndependent/preprocessor/PpContext.h98 symbols
SPIRV/hex_float.h90 symbols

For agents

$ claude mcp add glslang \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page