【问题标题】:OpenGL Compute Shader Wont Compile If Includes Input Image如果包含输入图像,OpenGL 计算着色器将无法编译
【发布时间】:2020-07-21 21:02:24
【问题描述】:

此 GLSL 源代码编译(使用 GL_COMPUTE_SHADER)并运行没有问题(仅使用输出图像):

#version 460
layout (local_size_x = 16, local_size_y = 16) in;
layout (rgba8, binding = 3) uniform writeonly lowp image2D destTex;
void main() {
  ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
  imageStore(destTex, pixel_coords, vec4(1.0, 0.0, 0.0, 1.0)); // Solid red
}

但如果我只添加两行代码以允许输入图像,则以下内容无法编译:

#version 460
layout (local_size_x = 16, local_size_y = 16) in;
layout (rgba8, binding = 1) uniform readonly lowp image2D srcTex;
layout (rgba8, binding = 3) uniform writeonly lowp image2D destTex;
void main() {
  ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
  vec4 color = imageLoad(srcTex​, pixel_coords);
  imageStore(destTex, pixel_coords, color);
}

编译器的输出是:

0(7) : error C0000: syntax error, unexpected $undefined, expecting "::" at token "<undefined>"
0(8) : error C1503: undefined variable "color"

有什么想法吗?

【问题讨论】:

    标签: opengl glsl gpgpu compute-shader


    【解决方案1】:

    imageLoad 中的“x”和逗号之间似乎有一个“零宽度空格”(U+200B) 字符(不可见)。擦除后,您的代码对我来说编译得很好。

    【讨论】:

    • 就是这样。您如何从错误消息中看出?
    • @Labeno 我没有。我复制并粘贴了代码并得到了错误(来自 glslangValidator)ERROR: 0:7: '�' : unexpected token。所以我使用hexdump 来查找字符的位置,然后将字符粘贴到 Python 解释器中并搜索代码。
    猜你喜欢
    • 2018-05-30
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    相关资源
    最近更新 更多