Hello guys.
I'm having difficulty writting to an SSBO.
its an array of uint32_t, and in each of those uint32_t, there are 4 uint8_t that I write into the uint32_t.
Now here is the glsl code for it:
ArrayOffset colorIndicesOffset = GetArrayOffset(id);
uint packedColorIndices = colorIndices[colorIndicesOffset.indexOffset];
packedColorIndices &= ~(0xFF << (colorIndicesOffset.byteOffset * 8));
packedColorIndices |= (chunkIDLod << (colorIndicesOffset.byteOffset * 8));
debugPrintfEXT("i Index: %u\n", colorIndicesOffset.byteOffset);
colorIndices[colorIndicesOffset.indexOffset] = packedColorIndices;
SynchronizeBufferAccess();
the indexOffset is index / 4 and the byteoffset is index % 4.
when I do this on the cpu side, it works just fine, but not in the shader.
when I do
colorIndices[colorIndicesOffset.indexOffset] = packedColorIndices
and then I do
debugPrintfEXT("u Index: %u\n", colorIndices[colorIndicesOffset.indexOffset]);
it prints me the original value in the array (or some garbage idk), not the updated one.
here is the buffer declaration:
layout (std430, binding = 5) buffer coherent ChunksColorIndicesBuffer
{
uint colorIndices[];
};
and on the cpu side, the setup of the buffer:
_chunksColorsIndicesBuffer = BoxelVulkanBuffer("Chunks Color Indices Buffer");
_chunksColorsIndicesBuffer.CreateBuffer(sizeof(uint32_t) * MAX_CHUNKS_TOTAL / 4, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
VMA_MEMORY_USAGE_AUTO_PREFER_HOST);
std::vector<uint32_t> initColorIndices = std::vector<uint32_t>(MAX_CHUNKS_TOTAL / 4, 0);
_chunksColorsIndicesBuffer.CopyDataToBuffer(initColorIndices.data());
Thanks in advance for the help!
also the SynchronizeBufferAccess:
void SynchronizeBufferAccess()
{
memoryBarrier();
barrier();
}