Skip to content

Commit

Permalink
Handle vkMapMemory result. Fail if memory exceeds max buffer size f…
Browse files Browse the repository at this point in the history
…or stream buffers.
  • Loading branch information
Jupeyy committed Jan 14, 2025
1 parent 1ec83d5 commit 10bc64d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/engine/client/backend/vulkan/backend_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<size_t>(RequiredSize));
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down

0 comments on commit 10bc64d

Please sign in to comment.