我正在尝试实现平铺延迟渲染,但我坚持计算每个平铺的最小/最大深度。我正在使用计算着色器。这是完整的代码:
#version 430
#define TILE_SIZE 32
layout (location = 0, rgba32f) uniform image2D u_texture;
layout (location = 1, rgba32f) uniform image2D depthtex;
layout (local_size_x = TILE_SIZE, local_size_y = TILE_SIZE) in;
shared uint min_depth;
shared uint max_depth;
void main(void){
ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
ivec2 grid = ivec2(gl_WorkGroupID.xy);
if(gl_LocalInvocationIndex == 0){
min_depth = 0xFFFFFFFF;
max_depth = 0;
}
vec4 color;
vec4 color_tex = imageLoad(depthtex,pos);
float d = color_tex.x;
uint depth = uint(d * 0xFFFFFFFF);
atomicMin(min_depth, depth);
atomicMax(max_depth, depth);
barrier();
color = vec4(float(float(min_depth) / float(0xFFFFFFFF)));
imageStore(u_texture, grid, color);
}
当我尝试运行程序时,它在计算着色器编译中循环无限循环。知道为什么会引起这种情况以及如何解决这个问题?
编辑:所以当我尝试检查我正在使用此代码执行的计算着色器的链接状态时,我发现该问题是由 glGetProgramiv()函数引起的://throw exception if linking failed
GLint status;
glGetProgramiv(_object, GL_LINK_STATUS, &status);
if (status == GL_FALSE) {
std::string msg("Program linking failure: ");
GLint infoLogLength;
glGetProgramiv(_object, GL_INFO_LOG_LENGTH, &infoLogLength);
char* strInfoLog = new char[infoLogLength + 1];
glGetProgramInfoLog(_object, infoLogLength, NULL, strInfoLog);
msg += strInfoLog;
delete[] strInfoLog;
glDeleteProgram(_object); _object = 0;
throw std::runtime_error(msg);
}
但是,如果我从着色器中删除 atomicMin(),一切正常。