Std140 implementation dependant or misunderstanding?

Hello there,

I got some misunderstanding on uniform buffer with layout std140,

I got my glsl (330) struct but depending on which computer is use it, the memory doesn’t seem to be handled the same way (windows/nvidia vs osx/integrated intel)
for each struct i will show i have a unique array like so in a uniform:

layout (std140) uniform Organs
    Organ organs[2048];

and the proper matching C structs (rust but i think it does not matter)

Here is the first struct:

struct Organ {
    vec2  p;          // 2N Ok
    float range;    // 1N Not ok
    int kind          // 1N Not ok
}; // 4N Ok

Problem is this code works on windows/nvidia but not osx (i have range and kind with aberrant behaviour but p is fine), is this some kind of luck from implementation details ?

Second behaviour i don’t get

on osx, this does not work

struct Organ {
    vec2  p;    // 2N Ok
    vec2  d;    // 2N Ok
};  // total 4N Ok

but this works

struct Organ {
    vec4  p;   // 4N Ok
};  // total 4N Ok

But still from what i understand of the specs, both should be fine ?

I could have working this struct

struct Organ {
    vec2  p;                       // 2N ok
    float range;                  // 1N
    float pad1;                   // 1N => total 2N Ok
    int   kind;                     // 1N
    int   pad2;                    // 1N => total 2N Ok
    float roundtovec4;       // 1N
    float roundtovec41;     // 1N => total 2N
};  // total 8N => 2 vec4  =>  32 bits Ok

So is this a valid way of using std140 on any platform ?

Could you point me out some errors i could have done in understanding std140 and structs ?

It sounds like MacOS’s implementation has bugs in it. However, you never really say what about it “does not work,” so it’s hard to be sure.

If it is a MacOS bug, then it’s highly unlikely to be fixed, since MacOS has deprecated OpenGL and will probably remove it in a future release. It’s clear that they’re not interested in supporting GL, so they’re probably not interested in fixing existing bugs.

Thanks for the answer !

By not working I mean incoherent values in my struct: (my display show me that inner values are wrong)

I’ve been struggling a bit on std140 layout memory offset and want to be sure that I get it fine

the three structs I’ve given presents things I’me not sure to get

  • the first one: if this is a valid struct, this means that no padding should be needed between scalar values ? and shame that i can’t get the good values for range and type on osx.
  • the second one, did i missed something ? for me both are valid
  • the third => i guess is valid but wow i have to double the size of my struct