GLSL compiled to SPIR-V

Started by
8 comments, last by PAM79 1 year ago

Let me see if I’ve got this straight: Vulkan uses SPIR-V shaders, which are basically pre-compiled GLSL shaders?

Advertisement

SPIR-V afaik is just an intermediate representation, any compiler that generate SPIR-V ( obviously matching the Vulkan programmable graphics pipeline stages) would theoretically work and is not limited to GLSL. You have compilers that will generate SPIR-V from HLSL also. The GPU specific Vulkan shader compiler would then convert that intermediate representation into HW specific shader blob. Not too different from what they do for OpenGL except that the compiler can be simpler as its now just functioning as a translator( gross simplification as there is still potential HW specific optimization).

I use glslc from the Vulkan SDK to generate the spv files.

taby said:

Let me see if I’ve got this straight: Vulkan uses SPIR-V shaders, which are basically pre-compiled GLSL shaders?

Yep! A SPIR-V module is a sequence of 32-bit words stored in memory, generated by a tool from GLSL or HLSL code. The Vulkan driver uses this binary blob to compile machine (GPU) code during pipeline creation. Therefore, as stated by the specification, SPIR-V is a binary intermediate representation interchange format used to interface with a heterogeneous machine.

Does this conversion obfuscate the meaning of the code? Like, are there good SPIR-V disassemblers, or are they all relatively useless?

Some constructs will be de-sugared by the compiler, and won't be reversed back to the original code, for sure.

The code can be read, though. (You'd also need to come up with nice names for the bindings for yourself, those are not stored in the bytecode.)

Try SPIR-V-Cross, or Shader Playground (which lets you play with a variety of compilers / decompilers)

https://github.com/KhronosGroup/SPIRV-Cross

https://github.com/tgjones/shader-playground

enum Bool { True, False, FileNotFound };

I'm trying to grok this.

In OpenGL, I create a vector<vertex_3> etc., and add triangle data into that. Then, I pass it to the GPU via glVertexAttribPointer.

In Vulkan, I use the exact same vector<vertex_3>, but I pass it using some Vulkan function(s). Is this correct? It would seem so, since the shaders are still GLSL, right?

Is Vulkan seriously just OpenGL with ray tracing plus a neurotic amount of control over the GPU?

Yes and no. The graphic and computing functionalities offered by OpenGL and Vulkan overlap, and you probably won't get a performance boost from the GPU by using Vulkan instead of OpenGL. In other words, the GPU won't render more frames just because you're using Vulkan. However, there are still advantages in using Vulkan rather than OpenGL, such as lower CPU overhead. Please refer to section 1.2.1 of my "Hello Window" tutorial for additional details.

This topic is closed to new replies.

Advertisement