【发布时间】:2020-05-18 21:24:07
【问题描述】:
我在 glsl SSBO 中有以下结构数组:
struct node {
vec3 min, max;
int hitNext;
int missNext;
int firstTri, numTris;
};
layout(std430, binding = 3) readonly buffer Nodes {
node[] nodes;
};
我正在向他们传递一个字节缓冲区,我在其中存储了以下格式的数据:
4 bytes min.x, 4 bytes min.y, 4 bytes min.z, 4 bytes 1.0f,
4 bytes max.x, 4 bytes max.y, 4 bytes max.z, 4 bytes 1.0f,
4 bytes hitNext, 4 bytes missNext, 4 bytes firstTrue, 4 bytes numTris
但是 glsl 没有正确读取数据。如果我将结构定义中的vec3 更改为vec4,它将完美运行。但为什么会这样呢?根据 OpenGL 规范,这不是对齐方式吗?:
struct node { //Base alignment Aligned Offset
vec3 min; // 16 0
vec3 max; // 16 16
int hitNext; // 4 32
int missNext; // 4 36
int firstTri, numTris; // 4 40
// 4 44
};
layout(std430, binding = 3) readonly buffer Nodes {
node[] nodes; // 16 48
};
但是这种对齐方式与我传入的数据相匹配。为什么这不起作用但vec4 起作用?
【问题讨论】: