4

我正在尝试实现平铺延迟渲染,但我坚持计算每个平铺的最小/最大深度。我为此使用计算着色器。这是它的完整代码:

#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()一切正常。

4

0 回答 0