Sending data from GPU to CPU

Sorry if this is too much of a beginner question but I have been banging my head against a wall trying to get this to work.

I have a compute shader and within it I am writing data to a buffer and am successfully sending that data to a fragment shader and all looks in order when looking at it through RenderDoc.

For this storage buffer I am using the properties flags:

VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT

Here is my code for fetching the data but it crashes with a read access violation reading location error:

void vk::Vulkan_Loader::fetchChunkDataFromGPU(PhysicalDevice& physicalDevice, loadObject& objectToLoad, int bufferIndex) {
	vkWaitForFences(physicalDevice.logicalDevice.handle, 1, &physicalDevice.logicalDevice.computeTerrainGenerationInFlightFences[0], VK_TRUE, UINT64_MAX);
	void* pointer;
	int data;
	int size = sizeof(int);
	vkMapMemory(physicalDevice.logicalDevice.handle, physicalDevice.logicalDevice.storagePixelDataBuffersMemory[bufferIndex], 0, size, 0, &pointer);
	memcpy(&data, pointer, size);
}

​

Posted Nov 1, 2023, 4:09 PM UTC

315
Loading comments…