I'm attempting to generate a kind of octree from a triangle mesh and I'm using a spin-lock mechanism to lock a node before subdividing it. I'm familiar with this kind of thing and I already made it work using HLSL but I'm a bit puzzled that the same code hangs the gpu with GLSL and Vulkan.
Here's the relevant code
struct Node
{
int nodeAddr;
int dataAddr;
int level;
int mutex;
};
layout(binding = 1, std430) coherent buffer buf1
{
Node Nodes[];
};
int GetNodeAddr(uint parent, ivec3 c, int level)
{
int addr = Nodes[parent].nodeAddr;
if (addr < 0)
{
int value;
do
{
value = atomicCompSwap(Nodes[parent].mutex, 0, 1);
if (value == 0)
{
addr = Nodes[parent].nodeAddr;
if (addr < 0)
{
//addr = AllocateNodes(level);
addr = 0;
Nodes[parent].nodeAddr = addr;
}
atomicExchange(Nodes[parent].mutex, 0);
}
}while(value != 0);
}
return addr + (c.z * 16 + c.y * 4 + c.x);
}
Am I missing something ?