我是 Vulkan 计算着色器的新手,很抱歉问了这个愚蠢的问题。这是我的着色器(我只是想调试,这不是全部逻辑):
#version 450
layout(local_size_x = 32) in;
struct vertex {
vec3 pos;
vec3 color;
};
layout(std430, binding = 0) buffer output_buffer{
vertex bezier_curve[];
};
layout(std430, push_constant) uniform pc {
int points_size;
} push;
void main() {
const uint id = gl_GlobalInvocationID.x + 3; // first 3 elements are the control points
if (id > push.points_size) return;
bezier_curve[id].color = vec3(id, id, id);
}
发货:
command_buffers.front().dispatch(1, 1, 1); // since the amount of points is equal to 13 the only workgroup would be enough (just for test)
输出:
auto out_buffer_ptr = reinterpret_cast<vertex*>(logicalDevice.mapMemory(buffer_memory, 0, buffer_size));
for (int i = 0; i < vertices.size(); ++i)
std::cout << (out_buffer_ptr + i)->color.x << ' ' << (out_buffer_ptr + i)->color.y << ' ' << (out_buffer_ptr + i)->color.z << '\n';
logicalDevice.unmapMemory(buffer_memory);
所以我期望看到很少的向量,每个向量都填充唯一的数字(gl_GlobalInitationID.x),即
4 4 4
6 6 6
5 5 5
但这就是我所得到的:
1 0 0
0 1 0
0 0 1
0 0 0
0 3 3
0 0 0
0 0 0
5 5 0
0 6 6
0 0 0
0 0 0
8 8 0
0 9 9
那三个
1 0 0
0 1 0
0 0 1
很好,因为我自己硬编码了控制点和颜色,这就是
gl_GlobalInvocationID.x + 3;
的情况。但其他人从哪里来呢?
伙计们,我忘记了对齐。不敢相信这发生在我身上...抱歉浪费了您的时间!