简体   繁体   English

为 Vulkan 自动编译 OpenGL 着色器

[英]Automatically compile OpenGL Shaders for Vulkan

Is there any way to automatically compile OpenGL shaders for Vulkan?有没有办法为 Vulkan 自动编译 OpenGL 着色器? 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.我曾尝试为 OpenGL 编译,然后使用 spirv-cross 和--vulkan-semantics进行反编译,但它仍然具有非不透明的制服。

spirv-cross seems to only have tools for compiling Vulkan shaders for OpenGL. spirv-cross 似乎只有用于为 OpenGL 编译 Vulkan 着色器的工具。

[--glsl-emit-push-constant-as-ubo]
[--glsl-emit-ubo-as-plain-uniforms]

A shader meant for OpenGL consumption will not work on Vulkan.用于 OpenGL 消耗的着色器不适用于 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). Vulkan 使用描述符集和绑定点,所有资源都使用相同的绑定索引(集+绑定)。 By contrast, OpenGL gives each kind of resource its own unique set of indices.相比之下,OpenGL 为每种资源提供了自己独特的索引集。 So a GLSL shader meant for OpenGL consumption might assign a texture uniform and a uniform block to the same binding index.因此,用于 OpenGL 消耗的 GLSL 着色器可能会将纹理统一和统一块分配给相同的绑定索引。 But you can't do that in a GLSL shader meant for Vulkan, not unless the two resources are in different descriptor sets.但是您不能在用于 Vulkan 的 GLSL 着色器中执行此操作,除非这两个资源位于不同的描述符集中。

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.如果您想共享着色器,您将需要使用预处理器技巧来确保着色器为正在编译着色器的特定目标分配资源(包括它如何分配制服)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM