Opengl: vertices of vec3 followed by int_2_10_10_10 [closed]

  amd-gpu, c++, glsl, opengl

Consider a vbo with vertices of the format

struct Vertex
{
    float x;
    float y;
    float z;
    uint32_t n;
};

where n is encoded as GL_INT_2_10_10_10_REV.

I wrote a demo with two triangles of such vertices:

std::vector<Vertex> vboData;
vboData.emplace_back(0.0f, 0.0f, 0.0f, Int2101010RevPacked(1.0f, 0.0f, 0.0f));
vboData.emplace_back(0.5f, 0.0f, 0.0f, Int2101010RevPacked(0.0f, 1.0f, 0.0f));
vboData.emplace_back(0.5f, 0.5f, 0.0f, Int2101010RevPacked(0.0f, 0.0f, 1.0f));
const auto triangle2Begin = vboData.size() * sizeof(Vertex);
vboData.emplace_back(0.0f, 0.0f, 0.0f, Int2101010RevPacked(0.5f, 0.5f, 0.0f));
vboData.emplace_back(0.9f, 0.0f, 0.0f, Int2101010RevPacked(0.0f, 0.5f, 0.5f));
vboData.emplace_back(0.9f, 0.9f, 0.0f, Int2101010RevPacked(0.5f, 0.0f, 0.5f));

and constructed a VAO with the following format:

const auto stride = sizeof(Vertex);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void*)(0));
glVertexAttribPointer(2, 4, GL_INT_2_10_10_10_REV, GL_TRUE, stride, (void*)(3 * sizeof(float)));
glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, stride, (void*)(triangle2Begin));
glVertexAttribPointer(7, 4, GL_INT_2_10_10_10_REV, GL_TRUE, stride, (void*)(3 * sizeof(float) + triangle2Begin));

Then I rendered it with 3 elements with the following vertex shader (yes, originally it was morph animation):

layout(location = 0) in vec3 v1;
layout(location = 2) in vec4 n1;
layout(location = 6) in vec3 v2;
layout(location = 7) in vec4 n2;

smooth out vec3 color;

void main() {
    color = n1.xyz * 0.01 + n2.xyz;
    gl_Position = vec4(v1.xy, 0.0, 1.0);
}

Fragment shader is trivially passing color to the output. It works properly almost everywhere except some AMD gpus. I tested on various Intel, Nvidia and old AMD devices.

Everything looks tightly packed and properly aligned. Even 4-bytes alignment for each vertex attribute is observed. I double-checked the full source against documentation and found nothing wrong.

What can be wrong with it? I reported it on AMD forum a year ago, and got no reply. Now I faced the same problem again, checked my demo from the report on the up-to-date driver, and got different but still erroneous picture. What am I missing here?

Source: Windows Questions C++

LEAVE A COMMENT