I have an UBO that looks like this:
#version 450
#extension GL_ARB_separate_shader_objects : enable
const uint InstanceCount = 64;
layout(std140, align = 16, binding = 0) uniform UBO
{
vec4 array_indices[InstanceCount];
mat4 proj;
mat4 model;
mat4 models[InstanceCount];
uint selection[128];
} ubo;
and each vertex shader instance accesses one bit from uint selection[128]
like this:
layout(location = 1) out uint is_selected;
void main() {
uint id = gl_InstanceIndex;
uint num_index = id / 32;
uint bit_index = id % uint(32);
uint n = ubo.selection[num_index];
is_selected = n & (1u << bit_index);
...
}
The problem is that whenever id
is greater than 31 (that is when num_index
is 1 or greater) n
is always zero. But RenderDoc shows that the first 2 uint
s of ubo.selection[128]
are F0000380 and 0000000F (which means the 2nd uint
is not zero), so I'm guessing the shader has problems indexing into the array, so any ideas why n
is zero unless I'm indexing into the first elem of the array?
AMD Polaris10 video card.
The C++ structure which feeds this UBO is:
static const u32 InstanceCount = 64;
struct UBO
{
vkm::vec4 array_indices[InstanceCount];
vkm::mat4 proj;
vkm::mat4 model;
vkm::mat4 models[InstanceCount];
u32 selection[128];
};
vkm::mat4
is a class with a single member float arr[16].