Skip to content

Commit 45efffb

Browse files
Prevent modifying vulkan resource that might still be used by GPU
1 parent 74e6309 commit 45efffb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

PluginSource/source/RenderAPI_Vulkan.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,19 +749,14 @@ void* RenderAPI_Vulkan::BeginModifyVertexBuffer(void* bufferHandle, size_t* outB
749749
if (!bufferInfo.memory.mapped)
750750
return NULL;
751751

752-
UnityVulkanBuffer src;
753-
if (!m_UnityVulkan->AccessBuffer(bufferHandle, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_HOST_READ_BIT, kUnityVulkanResourceAccess_PipelineBarrier, &src))
752+
// We don't want to start modifying a resource that might still be used by the GPU,
753+
// so we can use kUnityVulkanResourceAccess_Recreate to recreate it while still keeping the old one alive if it's in use.
754+
UnityVulkanBuffer recreatedBuffer;
755+
if (!m_UnityVulkan->AccessBuffer(bufferHandle, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_HOST_WRITE_BIT, kUnityVulkanResourceAccess_Recreate, &recreatedBuffer))
754756
return NULL;
755757

756-
UnityVulkanBuffer dst;
757-
if (!m_UnityVulkan->AccessBuffer(bufferHandle, VK_PIPELINE_STAGE_HOST_BIT, VK_ACCESS_HOST_WRITE_BIT, kUnityVulkanResourceAccess_PipelineBarrier, &dst))
758-
return NULL;
759-
760-
// read might be slow because it's not cached
761-
// can't use GPU transfer here because is not marked as transfer src
762-
memcpy(dst.memory.mapped, src.memory.mapped, bufferInfo.sizeInBytes);
763-
764-
return dst.memory.mapped;
758+
// We don't care about the previous contents of this vertex buffer so we can return the mapped pointer to the new resource memory
759+
return recreatedBuffer.memory.mapped;
765760
}
766761

767762
void RenderAPI_Vulkan::EndModifyVertexBuffer(void* bufferHandle)

0 commit comments

Comments
 (0)