我正在使用 vulkan 编写一个简单的程序,只是为了开始。我正在清除背面颜色,就是这样。问题是程序的每一帧都会分配越来越多的内存,而我不知道内存来自哪里。
bool VulkanRenderer::Update()
{
PrepareFrame(); ///--- < Commenting this
SubmitFrame(); ///--- < and this avoids memory leak
}//Update
Run Code Online (Sandbox Code Playgroud)
这是另外两个函数,当它们不被调用时,程序的内存保持不变。
void VulkanRenderer::PrepareFrame()
{
///--- Reset command buffers
vkResetCommandPool(m_pDevice, m_pCoreCommandPool, VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
VkResult iRes;
// Get the index of the next available swapchain image:
iRes=m_oSwapChain.AcquireNextImage(m_oSemaphorePresentReady, &m_uSwapChainImage);
if(iRes!=VK_SUCCESS){
CheckVulkanError(iRes);
}
///---------------------------------
/// Convert image to drawable
///---------------------------------
VkCommandBufferBeginInfo oCmdBegin={};
oCmdBegin.sType=VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
///---------------------------------
/// Prepare primary command buffer
///---------------------------------
//vkFreeCommandBuffers(m_pDevice, m_pCoreCommandPool, 1, &m_oPrimaryCmd);
//m_oPrimaryCmd=CreateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
vkBeginCommandBuffer(m_oPrimaryCmd, &oCmdBegin);
{///--- Convert image …Run Code Online (Sandbox Code Playgroud)