Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically compile OpenGL Shaders for Vulkan

Is there any way to automatically compile OpenGL shaders for Vulkan? The problem is with the uniforms.

'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan

I have tried compiling for OpenGL, then decompiling with spirv-cross with --vulkan-semantics, but it still has non-opaque uniforms.

spirv-cross seems to only have tools for compiling Vulkan shaders for OpenGL.

[--glsl-emit-push-constant-as-ubo]
[--glsl-emit-ubo-as-plain-uniforms]
like image 438
me' Avatar asked Nov 23 '19 20:11

me'


People also ask

How do you compile shaders in Vulkan?

Double click the file to run it. Replace the path to glslc with the path to where you installed the Vulkan SDK. Make the script executable with chmod +x compile.sh and run it. These two commands tell the compiler to read the GLSL source file and output a SPIR-V bytecode file using the -o (output) flag.

Can Vulkan use GLSL shaders?

Vulkan does not directly consume shaders in a human-readable text format, but instead uses SPIR-V as an intermediate representation. This opens the option to use shader languages other than e.g. GLSL, as long as they can target the Vulkan SPIR-V environment.

Can I skip processing Vulkan shaders?

If the game spends too long to compiling shaders before starting a game, the process can be skipped. Skipping the process may result in jank and frame drops during gameplay.

Does Vulkan use HLSL or GLSL?

OpenGL Shading Language (GLSL) is the standard shader programming language for Khronos APIs such as Vulkan, OpenGL 4.


1 Answers

A shader meant for OpenGL consumption will not work on Vulkan. Even ignoring the difference in how they consider uniforms, they have very different resource models. Vulkan uses descriptor sets and binding points, with all resources using the same binding indices (set+binding). By contrast, OpenGL gives each kind of resource its own unique set of indices. So a GLSL shader meant for OpenGL consumption might assign a texture uniform and a uniform block to the same binding index. But you can't do that in a GLSL shader meant for Vulkan, not unless the two resources are in different descriptor sets.

If you want to share shaders, you're going to need to employ pre-processor trickery to make sure that the shader assigns resources (including how it apportions uniforms) for the specific target that the shader is being compiled for.

like image 192
Nicol Bolas Avatar answered Sep 28 '22 08:09

Nicol Bolas