-1
\$\begingroup\$

I have been attempting to push data to a storage buffer then then read back from it but to no avail. I am creating the buffer like I always do, populate it with VK_BUFFER_USAGE_STORAGE_BUFFER_BIT

And give it the flags

VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT

Then when I read from the buffer I only get 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);

Dose anyone know how i would track down the issue?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Remove the ampersand from the 2nd parameter. It should be:

memcpy(&payload, payload_buffer.mapped_memory, buffer_size);

If mapped_memory is already a pointer.

Otherwise with the ampersand you're copying the pointer itself into your float rather than the memory it points to.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .