# Force int array to compact memory

I have following structure which i use as an uniform buffer object.

struct GlobalShaderData
{
#define CLUSTER_X_MAX 16
#define CLUSTER_Y_MAX 8
#define CLUSTER_Z_MAX 8
#define CLUSTER_MAX_LIGHTS 4
int pointLightIndices[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX * CLUSTER_MAX_LIGHTS];
int pointLightsPerTile[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX];
};


The total size of the first int array should be 4 bytes * 16 * 8 * 8 * 4 = 16384 bytes, thus the maximum ubo memory is not exceeded.

However, when compiling the shaders I receive an "out of resource" error message.

I guess the integer actually takes 16 bytes on the glsl side to align with a vec4. Because if we calculate with 16 bytes * 16 * 8 * 8 * 4 = 65536 bytes, which just exceedes the maximum capacity.

What are my options to have an smaller integer array on glsl side.

(I know that I could use other storage buffers but thats not relevant to the question.)

• "thus the maximum ubo memory is not exceeded." That's not a UBO; your globalShaderData variable isn't even a uniform. Jun 8 '20 at 4:03
• That is true. It is the c++ side structure, I should have made it more clear. Jun 9 '20 at 10:21

Assuming you use this structure within an actual UBO (which your example code doesn't do), just use an array of ivec4 and two indices.

const ivec3 cluster_max = ivec3(16, 8, 8);
const int cluster_max_lights = 4;

const int plix_count = cluster_max.x * cluster_max.y * cluster_max.z * cluster_max_lights;
const int plix_index_size = pl_count / 4;

const int plpt_count = cluster_max.x * cluster_max.y * cluster_max.z;
const int plpt_index_size = plpt_count / 4;


To access a value from the arrays, you will have to divide the index by 4 to get the ivec4 index, then take the original index mod 4 and use that to index the ivec4. To get the