0
$\begingroup$

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];
};
GlobalShaderData globalShaderData;

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.)

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

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;

struct GlobalShaderData
{
    ivec4 pointLightIndices[plix_index_size];
    ivec4 pointLightsPerTile[plpt_index_size];
};

layout(std140) uniform shaderData
{
    GlobalShaderData globalShaderData;
};

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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.