I am setting a up a storage buffer and then using memcpy to pass data to it but when I try and get the data back from the buffer I am getting junk data.
Buffer payload_buffer;
VkDeviceSize buffer_size = sizeof(float);
CreateBuffer(engine, buffer_size, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, payload_buffer);
// Create the data that will be saved
float payload = 5.0f;
// Move the data to the GPU
memcpy(payload_buffer.mapped_memory, &payload, buffer_size);
// Move the data back
memcpy(&payload, &payload_buffer.mapped_memory, buffer_size);
// Output the data
std::cout << payload << std::endl;
// Destroy the buffer instance
DestroyBuffer(engine, payload_buffer);
I am making sure to use vkMapMemory and this is located inside the CreateBuffer function. I am really not sure what i’m doing wrong as i use this CreateBuffer for the rest of my application without fail.