I am writing a program that uses a transfer queue and a compute queue. As the names suggest, the transfer queue loads data from the CPU to the GPU and from the GPU to the CPU and the compute queue uses this data to perform some calculations and also to update them.
The general concept is that I have two staging buffers:
- stagingBufferToGPU (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) with TRANSFER_SRC_BIT. This buffer should load data from CPU to GPU.
- stagingBufferToCPU (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) with TRANSFER_DST_BIT. This Buffer should load data from GPU to CPU.
The data stored in the stage buffers is copied to memory with VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT for faster calculation.
Since the data I want to calculate comprises tons of GigaBytes, the entire calculation is split up. The staging buffers are therefore used several times.
Each of my buffers has a VkSemaphore that signals whether the buffer is currently in use. So the idea is that when a calculation command is sent, it waits for the signal from the semaphore. After the calculation command has completed its work, it will send a signal to the semaphore again. The same applies if the buffer is used by a copy-submit...
Now the problem:
The staging buffers are also used by the host. The CPU loads data into the stagingBufferToGPU in the following way:
void* mappedData; vkMapMemory(m_device, m_bufferMemory, memoryOffsetGPU, dataSize, 0, &mappedData); memcpy(mappedData, data, dataSize); vkUnmapMemory(m_device, m_bufferMemory); same with the stagingBufferToCPU:
void* mappedData; vkMapMemory(m_device, m_bufferMemory, memoryOffsetGPU, dataSize, 0, &mappedData); memcpy(data, mappedData, dataSize); vkUnmapMemory(m_device, m_bufferMemory); How can I ensure that no operations are performed while these assignments are taking place? Do I need a VkFence for this? Or can I use the VkSemaphore that I already have?
Something like:
waitForSemaphoreAndDesignalIt Do memory mapping signal semaphore BTW: I'm new to Vulkan, so please bear with me =)