无法写入只能写入Shader存储块

时间:2016-08-12 09:56:08

标签: opengl glsl shader

几何着色器代码的一部分如下所示:

layout(std430) restrict coherent buffer BufferName
{
     uint bufferName[][MAX_EXPECTED_ENTRIES];
};

...

void main()
{   
... 
bufferName[a][b] = someValue;
...
}

在我向writeonlyBufferName或两者添加bufferName语句之前,所有内容都按预期工作。
使用writeonly语句,我收到以下错误:error C7586: OpenGL does not allow reading writeonly variable 'bufferName'

这里发生了什么? 我所做的就是写信bufferNamespecwriteonly是允许的。对于存储块中的一维数组也会发生这种情况。

提前致谢。

以下是完整着色器代码(示例中的BufferName现为IDsPerVertex):

#version 450
#define MAX_EXPECTED_VERTEX_PRIMITIVE_IDS 10

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

layout(std430) restrict coherent buffer IDsPerVertex
{
     uint iDsPerVertex[][MAX_EXPECTED_VERTEX_PRIMITIVE_IDS];
};

layout(std430) restrict coherent buffer Counter
{
    uint counter[];
};

in int ID[3]; // contains gl_VertexID
out vec4 debugColor;

uint index[3];

void writeIDsPerVertex()
{
    // get the next free location for each vertex
    index[0] = atomicAdd(counter[ID[0]], 1u);
    index[1]  = atomicAdd(counter[ID[1]], 1u);
    index[2]  = atomicAdd(counter[ID[2]], 1u);

    // write the triangle primitive ID to each vertex list
    iDsPerVertex[ID[0]][index[0]] = gl_PrimitiveIDIn;
    iDsPerVertex[ID[1]][index[1]] = gl_PrimitiveIDIn;
    iDsPerVertex[ID[2]][index[2]] = gl_PrimitiveIDIn;
}

void passThrough()
{
    for(int i = 0; i < gl_in.length(); i++)
    {
        gl_Position = projection * view * model * gl_in[i].gl_Position;
        debugColor = vec4(1);
        EmitVertex();
    }
    EndPrimitive();
}

void main()
{
    writeIDsPerVertex();
    passThrough();
}

我的环境给出的完整错误消息:

SHADER PROGRAM 37 LOG
Geometry info
-------------
(0) : error C7586: OpenGL does not allow reading writeonly variable 'iDsPerVertex'

0 个答案:

没有答案
相关问题