In my compute shader I have a very simple piece of code
layout(set = 0, binding = 3) buffer Velocity{
vec3 velocities[];
};
void main(){
uint gID = gl_GlobalInvocationID.x;
velocities[gID]=vec3(1,2,3);
vec3 velocity = velocities[gID];
debugPrintfEXT("%d (%v3f)", gID, velocity);
}
but the logs that I get are rather unexpected
0 (1.000000, 2.000000, 3.000000)
1 (0.000000, 0.000000, 0.000000)
When I allocate the buffer, I specify it's size as
buffer_create_info.size = sizeof(glm::vec3)*capacity; //here capacity==2
so I'm sure there should be enough space in that buffer. I also double checked if the binding number is correct. This buffer is used by only this one shader and there are no other threads/shaders that could lead to data races. I have validation layers enabled and I see no problems there either.
What could be the cause of such strange behavior? Has anybody seen such problems before?
Edit:
I tried allocating buffer larger than necessary and it seems to help. I still don't understand why. The sizeof(glm::vec3)
returns 12
. When I set capacity==3
that gives me buffer of 36
bytes. It should also work with 24
bytes, but for some reason reading from such a buffer returns zeros.