I have trouble with differences between layout std140 and std430.
this is my code of struct
in .Cpp
struct Particle {
glm::vec3 position = glm::vec3(0);
float density = 1;
};
for (int z = 0; z < d; ++z) {
for (int y = 0; y < d; ++y) {
for (int x = 0; x < d; ++x) {
int index = z * d * d + y * d + x;
if (index >= num) break;
// dam break
m_InitParticles[index].position = glm::vec3(x, y, z) * distance;
m_InitParticles[index].position += glm::vec3(getJitter(), getJitter(), getJitter());
m_InitParticles[index].density = index;
}
}
}
And compute shader code
struct Particle {
vec3 position;
float density;
};
layout(std140, binding = 0) restrict buffer Particles{
Particle particles[];
};
it seems that I get correct data std430 data in renderdoc by
pack#(std430)
struct Particle {
vec3 position;
float t;
}
And when I use pack#(std140)
, the struct seems to have a 8N space std140 in renderdoc.
pack#(std430)
struct Particle {
vec3 position;
float t;
}
With std140, glGetActiveUniformsiv
returns offset 0
and 12
.
Why struct vec + float
takes up extra space in std140?