Godot Version
4.5.1
Question
I try to implement a flood fill in a compute shader. even with only 1 shader invocation, it seems that that data written with imageStore() cannot be read again with imageLoad()
here the relevant code:
layout (r32ui, set = 0, binding = 0) uniform coherent uimage3D light_map;
...
// use a ring buffer as stack, so that we have breadth first, like with recursion
pos_stack[0] = pos;
lev_stack[0] = level;
while (stack_min != stack_max && guard-- > 0) {
pos = pos_stack[stack_min];
level = lev_stack[stack_min];
stack_min = (stack_min + 1) % STACK_SIZE;
imageStore(light_map, pos, ivec4(level, 0, 0, 0));
if (level > 0x01000000) {
level -= 0x01000000;
for (int i = 0; i < 4; i++) {
const ivec3 next_pos = pos + DIRS[i];
// check if we need to continue
uint ll = imageLoad(light_map, next_pos).x;
if (level > ll) {
pos_stack[stack_max] = next_pos;
lev_stack[stack_max] = level;
stack_max = (stack_max + 1) % STACK_SIZE;
}
}
}
}
what seems to happen is that the level written in the imageStore() can later not be read again by imageLoad().
out of desperation, I tried other possible memory qualifiers (volatile, restrict) and calling barrier(). nothing helps.
FYI, it works kind of, i.e. it writes the data to the image buffer, but just doesn’t loop correctly.