如果包含输入图像,OpenGL 计算着色器将无法编译
OpenGL Compute Shader Wont Compile If Includes Input Image
此 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"
有什么想法吗?
您似乎在 'x' 和 imageLoad
中的逗号之间有一个 'ZERO WIDTH SPACE' (U+200B) 字符(不可见)。擦除后,你的代码对我来说编译得很好。
此 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"
有什么想法吗?
您似乎在 'x' 和 imageLoad
中的逗号之间有一个 'ZERO WIDTH SPACE' (U+200B) 字符(不可见)。擦除后,你的代码对我来说编译得很好。