Search code examples
opengl-esglslshaderopengl-es-3.0mali

OpenGL ES 3.0 Matrix/Array Stride


I have this UBO:

layout(std140)uniform _ObjMatrix
{
    layout(row_major)mat4x3 ViewMatrix[256];
};

On OpenGL desktop, the size is 3*Vec4*256 elements (total size 12288 bytes) - this is what I was expecting = OK

However when running on my mobile phone, OpenGL ES 3.0, the size is 4*Vec4*256 elements (total size 16384 bytes) = Not OK

I thought std140 should guarantee same layout on all platforms?

So what's the problem and how to fix it?

I need the smaller size for faster performance (because of smaller bandwidth for transfers)

Works OK on Desktop, Apple iOS, but fails on 2 Android ARM Mali GPU's, perhaps it's a bug in ARM Mali drivers


Solution

  • This is a confirmed Mali driver bug which affects row_major annotation for array declarations. The workaround is to apply the row_major annotation to the uniform block rather than the array element:

    layout(std140, row_major) uniform _ObjMatrix {
        mat4x3 ViewMatrix[256];
    };