Add barrier and invalidate when reading back memory via GPU

This commit is contained in:
baldurk
2020-08-10 15:19:10 +01:00
parent 152170dc58
commit dd5f4202cf
2 changed files with 27 additions and 0 deletions
+1
View File
@@ -74,6 +74,7 @@ public:
byte *GetReadbackPtr() { return m_ReadbackPtr; }
VkBuffer GetReadbackBuffer() { return m_ReadbackWindow.buf; }
VkDeviceMemory GetReadbackMemory() { return m_ReadbackWindow.mem; }
VkPipelineCache GetPipelineCache() { return m_PipelineCache; }
VkPipeline GetCustomPipeline() { return m_Custom.TexPipeline; }
VkImage GetCustomTexture() { return m_Custom.TexImg; }
@@ -1093,6 +1093,21 @@ VkResult WrappedVulkan::vkQueueSubmit(VkQueue queue, uint32_t submitCount,
Unwrap(GetDebugManager()->GetReadbackBuffer()), 1,
&region);
// wait for transfer to finish before reading on CPU
VkBufferMemoryBarrier bufBarrier = {
VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
NULL,
VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_HOST_READ_BIT,
VK_QUEUE_FAMILY_IGNORED,
VK_QUEUE_FAMILY_IGNORED,
Unwrap(GetDebugManager()->GetReadbackBuffer()),
0,
VK_WHOLE_SIZE,
};
DoPipelineBarrier(copycmd, 1, &bufBarrier);
ObjDisp(copycmd)->EndCommandBuffer(Unwrap(copycmd));
VkSubmitInfo submit = {
@@ -1103,6 +1118,17 @@ VkResult WrappedVulkan::vkQueueSubmit(VkQueue queue, uint32_t submitCount,
ObjDisp(queue)->QueueWaitIdle(Unwrap(queue));
VkMappedMemoryRange range = {
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
NULL,
Unwrap(GetDebugManager()->GetReadbackMemory()),
0,
VK_WHOLE_SIZE,
};
copyret = ObjDisp(queue)->InvalidateMappedMemoryRanges(Unwrap(m_Device), 1, &range);
RDCASSERTEQUAL(copyret, VK_SUCCESS);
RemovePendingCommandBuffer(copycmd);
AddFreeCommandBuffer(copycmd);