I ran into an issue with the alignment/stride of SSBOs in compute shaders which are arrays of larger structs. I'm using a scalar alignment to make the mapping 1:1 as it is in C++.
Specifically in my case the struct has a nested array of integers that looks like this:
#version 450
#extension GL_EXT_scalar_block_layout : enable
struct Cluster
{
vec4 minPoint;
vec4 maxPoint;
uint count;
uint lightIndices[1]; //<<< 1 element
};
layout(scalar, set = 0, binding = 2) restrict buffer clusterSSBO
{
Cluster clusters[];
} clusterData;In Nsight the byte offsets of the array elements look like this:
Screenshot: Nvidia Nsight 1 element
Indexing into that array worked fine in the compute shader.
However, if we increase the "lightIndices" array to a larger size:
struct Cluster
{
vec4 minPoint;
vec4 maxPoint;
uint count;
uint lightIndices[100]; //<<< 100 elements
};The offsets between the array elements becomes very large (we have a stride of exactly 4000 bytes?) Which causes issues with indexing into the array.
Screenshot: Nvidia Nsight 100 elements
You can see in the second screenshot in the "offset" column how it jumps from byte 432 to 4000. (And the next struct is then at offset 8000)
Am i missing something with regards to this struct configuration? My assumption was that the scalar layout should result it a tight/packed mapping as it's the case in C++.
Any kind of input/direction would be appreciated.