
[ad_1]
I’m making an attempt to create a Vulkan Storage Space Buffer Object which accommodates an array of structs to be used in my vertex shader. I imagine I’m lacking one thing basic right here as a result of the first struct within the array works however all others give rubbish knowledge. Heres what I’m doing:
C++ I’ve received a easy struct outlined:
struct InstanceData {
glm::mat4 mannequin;
};
Later on I’ve a vector of those structs which I push knowledge into:
std::vector<InstanceData> instanceData;
instanceData.push_back(InstanceData());
instanceData.push_back(InstanceData());
And lastly memcpy the information from our vector into our VkBuffer (managed by VMA):
memcpy(occasionStorageSpaceAllocations[currentImage]->GetMappedData(), instanceData.knowledge(), sizeof(InstanceData) * instanceData.measurement());
In our vertex shader, I’m trying to entry this knowledge like so:
structure(std140, binding = 0) readonly buffer InstanceData {
mat4 mannequin;
} ssbo[];
void principal() {
gl_Position = PushConstants.view_proj * ssbo[gl_InstanceIndex].mannequin * inPosition;
}
Back in C++, we VkCmdDrawIndexed with the quantity of cases at present in our instanceData vector:
vkCmdDrawIndexed(CmdBuffer, static_cast<uint32_t>(_GLTF->Indices.measurement()), 1, instanceData.measurement()-1, 0, 0);
So, nevertheless many cases of InstanceData we push into our instanceData vector shall be drawn by the GPU.
When establishing our SSBO descriptor we do like so:
VkDescriptorBufferInfo bufferInfo = {};
bufferInfo.buffer = StorageBuffers[i];
bufferInfo.offset = 0;
bufferInfo.vary = VK_WHOLE_SIZE;
VK_WHOLE_SIZE is used right here so it makes use of all the measurement of the VkBuffer (as a result of we are going to resize the buffer when it turns into to small to carry all our InstanceData objects).
So this works for the first instanced draw (when instanceData.measurement() == 1), however any after leads to rubbish knowledge when accessing the SSBO from inside our shader.
Any concepts about what I’m doing fallacious right here..?
[ad_2]