如果包含输入图像,则OpenGL计算着色器不会编译

如果包含输入图像,则OpenGL计算着色器不会编译,opengl,glsl,gpgpu,compute-shader,Opengl,Glsl,Gpgpu,Compute Shader,此GLSL源代码使用GL_COMPUTE_着色器进行编译,运行时不会出现问题,仅使用输出图像: #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);

此GLSL源代码使用GL_COMPUTE_着色器进行编译,运行时不会出现问题,仅使用输出图像:

#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"

有什么想法吗?

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

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

就是这样。你怎么能从错误信息中分辨出来?@Labeno我没有。我复制并粘贴了代码,并从glslangValidator错误中获得了错误:0:7:'�' : 意外标记。因此,我使用hextump查找字符所在的位置,然后将字符粘贴到Python解释器中并用谷歌搜索代码。就是这样。你怎么能从错误信息中分辨出来?@Labeno我没有。我复制并粘贴了代码,并从glslangValidator错误中获得了错误:0:7:'�' : 意外标记。因此,我使用hextump查找字符所在的位置,然后将字符粘贴到Python解释器中并用谷歌搜索代码。