0

I've been trying to learn Vulkan for 1 week now and I managed to draw a triangle on the screen following the turoial on https://vulkan-tutorial.com. The memory usage increases and doesn't stop and while doing some debuging I figured out it is the RecordCommandBuffer function.

Here is the function that records the command buffer:

void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex)
{
    VkCommandBufferBeginInfo beginInfo = {0};
    beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
    beginInfo.flags = 0;
    beginInfo.pInheritanceInfo = NULL;

    if (vkBeginCommandBuffer(commandBuffer, &beginInfo) != VK_SUCCESS)
        fprintf(stderr, "Failed to begin recording command buffer!");

    VkRenderPassBeginInfo renderPassInfo = { 0 };
    renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
    renderPassInfo.renderPass = application.renderPass;
    renderPassInfo.framebuffer = application.swapChainFramebuffers[imageIndex];

    renderPassInfo.renderArea.offset = (VkOffset2D){ 0, 0 };
    renderPassInfo.renderArea.extent = application.swapChainExtent;

    VkClearValue clearColor = { { {0.0f, 0.0f, 0.0f, 1.0f} } };
    renderPassInfo.clearValueCount = 1;
    renderPassInfo.pClearValues = &clearColor;

    vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
    vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, application.graphicsPipeline);

    VkViewport viewport = { 0 };
    viewport.x = 0.0f;
    viewport.y = 0.0f;
    viewport.width = (float)application.swapChainExtent.width;
    viewport.height = (float)application.swapChainExtent.height;
    viewport.minDepth = 0.0f;
    viewport.maxDepth = 1.0f;
    vkCmdSetViewport(commandBuffer, 0, 1, &viewport);

    VkRect2D scissor = { 0 };
    scissor.offset = (VkOffset2D){ 0, 0 };
    scissor.extent = application.swapChainExtent;
    vkCmdSetScissor(commandBuffer, 0, 1, &scissor);

    vkCmdDraw(commandBuffer, 3, 1, 0, 0);

    vkEndCommandBuffer(commandBuffer);
}

I found out that it could be the vkCmdBeginRenderPass function but I don't know how to fix it.

1 Answers1

0

It turns out I missed the vkCmdEndRenderPass function. The RenderPass was created but never released. :)

  • You really should use validation layers. It would have been able to tell you that calling `vkEndCommandBuffer` without ending the render pass is an error. – Nicol Bolas Oct 01 '22 at 17:08