me'
me'

Reputation: 534

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]

Upvotes: 5

Views: 2525

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 473352

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.

Upvotes: 6

Related Questions