其中struct在.cpp
中`
struct {
float data[Length];
float convol[Length];
}inkernel;
DeviceSize deviceSize = sizeof(inkernel);
for (uint32_t i = 0;i < Length;i++)
{
inkernel.convol[i] = 2;
inkernel.data[i] = 3;
}
status = HPC::bvk::createBuffer(
info.gpus[0],
info.device,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
deviceSize,
&inBuffer);
inBuffer.map();
memcpy(inBuffer.mapped, &inkernel, deviceSize);
inBuffer.unmap();`
在着色器中使用两个数组(使用glsl)
`
layout (local_size_x = 4) in;
// Binding 0 : for test
layout(binding = 0) buffer In
{
float indata[];
float cal[];
}inkernel;
layout(binding = 1) buffer Out
{
float outdata[];
}outkernel;
void main()
{
uint index = gl_GlobalInvocationID.x;
outkernel.outdata[index] = inkernel.cal[index];
} `
通过计算,我用outkernel.data读取数据,但结果是 3,而不是2 。我不知道为什么inkernel.cal的值被改为 3,而不是2
答案 0 :(得分:0)
值不必在同一个ssbo中。
layout(binding = 0) buffer In
{
float indata[];
}inkernel1;
layout(binding = 1) buffer In
{
float cal[];
}inkernel2;
layout(binding = 2) buffer Out
{
float outdata[];
}outkernel;
缓冲区仍然相同,您只需要调整描述符。