From 10bc64d5c328cb76df26c050062afce1908e4590 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 14 Jan 2025 21:42:43 +0100 Subject: [PATCH] Handle `vkMapMemory` result. Fail if memory exceeds max buffer size for stream buffers. --- .../client/backend/vulkan/backend_vulkan.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/engine/client/backend/vulkan/backend_vulkan.cpp b/src/engine/client/backend/vulkan/backend_vulkan.cpp index 149858cc672..28ea56686c8 100644 --- a/src/engine/client/backend/vulkan/backend_vulkan.cpp +++ b/src/engine/client/backend/vulkan/backend_vulkan.cpp @@ -1361,7 +1361,8 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase VkSubresourceLayout SubResourceLayout; vkGetImageSubresourceLayout(m_VKDevice, m_GetPresentedImgDataHelperImage, &SubResource, &SubResourceLayout); - vkMapMemory(m_VKDevice, m_GetPresentedImgDataHelperMem.m_Mem, 0, VK_WHOLE_SIZE, 0, (void **)&m_pGetPresentedImgDataHelperMappedMemory); + if(vkMapMemory(m_VKDevice, m_GetPresentedImgDataHelperMem.m_Mem, 0, VK_WHOLE_SIZE, 0, (void **)&m_pGetPresentedImgDataHelperMappedMemory) != VK_SUCCESS) + return false; m_GetPresentedImgDataHelperMappedLayoutOffset = SubResourceLayout.offset; m_GetPresentedImgDataHelperMappedLayoutPitch = SubResourceLayout.rowPitch; m_pGetPresentedImgDataHelperMappedMemory += m_GetPresentedImgDataHelperMappedLayoutOffset; @@ -1694,7 +1695,8 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase void *pMapData = nullptr; if(RequiresMapping) { - vkMapMemory(m_VKDevice, TmpBufferMemory.m_Mem, 0, VK_WHOLE_SIZE, 0, &pMapData); + if(vkMapMemory(m_VKDevice, TmpBufferMemory.m_Mem, 0, VK_WHOLE_SIZE, 0, &pMapData) != VK_SUCCESS) + return false; mem_copy(pMapData, pBufferData, static_cast(RequiredSize)); } @@ -6339,7 +6341,8 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase return false; void *pMappedData = nullptr; - vkMapMemory(m_VKDevice, StreamBufferMemory.m_Mem, 0, VK_WHOLE_SIZE, 0, &pMappedData); + if(vkMapMemory(m_VKDevice, StreamBufferMemory.m_Mem, 0, VK_WHOLE_SIZE, 0, &pMappedData) != VK_SUCCESS) + return false; size_t NewBufferIndex = StreamUniformBuffer.GetBuffers(m_CurImageIndex).size(); for(size_t i = 0; i < BufferCreateCount; ++i) @@ -6362,6 +6365,13 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase StreamUniformBuffer.IncreaseUsedCount(m_CurImageIndex); } + if(BufferMem.m_Size < DataSize) + { + SetError(EGfxErrorType::GFX_ERROR_TYPE_OUT_OF_MEMORY_BUFFER, "Stream buffers are limited to CCommandBuffer::MAX_VERTICES. Exceeding it is a bug in the high level code.", + GetMemoryUsageShort()); + return false; + } + { mem_copy(pMem + Offset, pData, DataSize); }