I am having problems where shader storage buffers are inconsistent with what is actually on the cpu. For example i have a structure in a compute shader:
struct BVHNode
{
AABB BoundingBox;
int LeftNode;
int RightNode;
bool IsLeaf;
int Primitive[20];
};
readonly layout(std430, binding = 4) buffer AccelerationStructure
{
BVHNode nodes[];
} BVHStructure;
which is the same as the structure on the cpu.
struct BVHNode
{
AABB BoundingBox;
int LeftNode = -1; //-1 represent null
int RightNode = -1;
bool IsLeaf = false;
int Primitive[20] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
};
however the IsLeaf
variable is set to true within the Nsight debugger and is set to false
within my visual studio debugger.
I have made sure that my code is following the alignment rules of std430
using vec4
s instead of vec3
s etc… however I can’t seem to fix this issue.
I tried using an integer to represnt IsLeaf
both on cpp code and in shader, however it seemed to crash my program here
Triangle* TriData = (Triangle*)m_TriangleBuffer.Map();
memmove(TriData, m_TriangleData.data(), m_TriangleData.size() * sizeof(Triangle));
m_TriangleBuffer.UnMap();
BVHNode* nodes = (BVHNode*)m_NodeBuffer.Map();
memmove(nodes, m_Nodes.data(), m_Nodes.size() * sizeof(BVHNode));
m_NodeBuffer.UnMap();
specifically at the line where i am mapping the Triangle buffer. the crash is cased by nvogl64
(nvidia opengl) and it gives me no more information other than that. Map and Unmap are just the
glMapNamedBuffer(m_Buffer, GL_WRITE_ONLY)
andglUnmap
.
I have been stuck on this issue for quite a couple of days now and i am not sure how to go about further debugging it.