<p>No, g++/gcc are not involved.</p>

<p>In OpenGL (prior to Vulkan), GLSL code is submitted to the driver as source code strings via a <a href="http://docs.gl/gl4/glShaderSource" rel="nofollow noreferrer"><code>glShaderSource</code></a> call. The driver is fully responsible for compilation, i.e. the driver must provide a built-in GLSL compiler for that GPU architecture. This would typically happen on startup of an app, or during level loading for a game.</p>

<p>With Vulkan, <a href="https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation" rel="nofollow noreferrer">SPIR-V</a> was introduced, which is a device-independent bytecode for shaders (vaguely based on <a href="https://en.wikipedia.org/wiki/LLVM#Intermediate_representation" rel="nofollow noreferrer">LLVM IR</a>). Now, GLSL code can be pre-compiled to SPIR-V offline using the <a href="https://github.com/google/shaderc" rel="nofollow noreferrer">shaderc</a> toolchain. The developers would do this ahead of time and ship the SPIR-V bytecode with their app. Then at runtime the SPIR-V gets submitted to the Vulkan driver and compiled the rest of the way to GPU machine code.</p>

<p>It's also possible to compile other languages to SPIR-V; for instance, Microsoft's <a href="https://github.com/Microsoft/DirectXShaderCompiler" rel="nofollow noreferrer">dxc</a> compiler for HLSL can optionally output SPIR-V, so you can use this to write Vulkan shaders in HLSL. Also, SPIR-V support has been backported to OpenGL 4.6, so you can now also <a href="https://www.khronos.org/opengl/wiki/SPIR-V" rel="nofollow noreferrer">load precompiled SPIR-V shaders in OpenGL</a>.</p>

CC BY-SA 4.0
2018-12-02T03:38:12.043Z
Does that mean you could write an app in GL 4.6 and do your shaders in HLSL as well?
russ
CC BY-SA 4.0
2018-12-02T05:49:47.347Z
@russ Maybe! I've never tried it, but that may well be possible.
Nathan Reed
CC BY-SA 4.0
2020-07-04T13:47:25.500Z
@russ Yes, it's possible to compile HLSL shaders to GLSL using the [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) compiler.
Anderson Green
CC BY-SA 4.0
2018-11-30T22:56:30.067Z
2018-11-30T22:56:30.067Z
Nathan Reed
<p>I just wanted to find out for sure how GLSL code gets loaded and compiled. </p>

<p>Does the g++ compiler do it? </p>

<glsl>
How does GLSL code get “loaded” and “compiled”?
user9778
# How does GLSL code get “loaded” and “compiled”?

(Asked by: username_0 on 2018-11-30)

I just wanted to find out for sure how GLSL code gets loaded and compiled.

Does the g++ compiler do it?

**Tags:** glsl


---

## 1 answers

### Answer by username_1 on 2018-11-30. Score: 3 | Accepted answer

No, g++/gcc are not involved.

In OpenGL (prior to Vulkan), GLSL code is submitted to the driver as source code strings via a [`glShaderSource`](http://docs.gl/gl4/glShaderSource) call. The driver is fully responsible for compilation, i.e. the driver must provide a built-in GLSL compiler for that GPU architecture. This would typically happen on startup of an app, or during level loading for a game.

With Vulkan, [SPIR-V](https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation) was introduced, which is a device-independent bytecode for shaders (vaguely based on [LLVM IR](https://en.wikipedia.org/wiki/LLVM#Intermediate_representation)). Now, GLSL code can be pre-compiled to SPIR-V offline using the [shaderc](https://github.com/google/shaderc) toolchain. The developers would do this ahead of time and ship the SPIR-V bytecode with their app. Then at runtime the SPIR-V gets submitted to the Vulkan driver and compiled the rest of the way to GPU machine code.

It's also possible to compile other languages to SPIR-V; for instance, Microsoft's [dxc](https://github.com/Microsoft/DirectXShaderCompiler) compiler for HLSL can optionally output SPIR-V, so you can use this to write Vulkan shaders in HLSL. Also, SPIR-V support has been backported to OpenGL 4.6, so you can now also [load precompiled SPIR-V shaders in OpenGL](https://www.khronos.org/opengl/wiki/SPIR-V).

> **Comments:**
> **username_2**: Does that mean you could write an app in GL 4.6 and do your shaders in HLSL as well?  
> **username_1**: @username_2 Maybe! I've never tried it, but that may well be possible.  
> **username_3**: @username_2 Yes, it's possible to compile HLSL shaders to GLSL using the [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) compiler.  

---

