title: Vulkan: aggressive increase in memory usage when splitting one VkBuffer into two
body: <p><strong>Setup</strong></p>
  <p>I followed <a href="https://vulkan-tutorial.com/" rel="nofollow noreferrer">this tutorial</a> to set up a vulkan application. This is how it looks:</p>
  <p><a href="https://i.stack.imgur.com/1QUWZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1QUWZ.png" alt="enter image description here" /></a></p>
  <p>The source code for this stage is available <a href="https://vulkan-tutorial.com/code/26_depth_buffering.cpp" rel="nofollow noreferrer">here</a>.</p>
  <p><strong>What I'm trying to do</strong></p>
  <p>I'm trying to apply two different textures to the two squares. To do that, I split the two squares into separate VkBuffers (a Vertex buffer and an index buffer for each of them).</p>
  <p><strong>What went wrong</strong></p>
  <p>Before splitting, the memory usage floats around 120MB. But afterwards, the usage is around 230MB. I think that shouldn't happen and I'm trying to figure out why.</p>
  <p><strong>What I did</strong></p>
  <p>To create the buffers (take vertex buffer for example).</p>
  <pre class="lang-cpp prettyprint-override"><code>  vertexBuffers.resize(vertices.size());
    vertexBufferAllocations.resize(vertices.size());
    for (size_t i = 0; i != vertices.size(); i++) {
      VkDeviceSize bufferSize = sizeof(vertices[i][0]) * vertices[i].size();
  
      VkBuffer stagingBuffer;
      VmaAllocation stagingBufferAllocation;
      createBuffer(bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
                   VMA_MEMORY_USAGE_CPU_ONLY, stagingBuffer,
                   stagingBufferAllocation);
  
      void *data;
      vmaMapMemory(allocator, stagingBufferAllocation, &amp;data);
      memcpy(data, vertices[i].data(), bufferSize);
      vmaUnmapMemory(allocator, stagingBufferAllocation);
  
      createBuffer(bufferSize,
                   VK_BUFFER_USAGE_TRANSFER_DST_BIT |
                       VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
                   VMA_MEMORY_USAGE_GPU_ONLY, vertexBuffers[i],
                   vertexBufferAllocations[i]);
      copyBuffer(stagingBuffer, vertexBuffers[i], bufferSize);
  
      vmaDestroyBuffer(allocator, stagingBuffer, stagingBufferAllocation);
    }
  </code></pre>
  <p>The command buffer I'm using (I think this has nothing to do with the memory usage, but just in case):</p>
  <pre class="lang-cpp prettyprint-override"><code>  if (vkBeginCommandBuffer(commandBuffers[i], &amp;beginInfo) != VK_SUCCESS) {
      throw runtime_error(&quot;failed to begin recording command buffer!&quot;);
    }
  
    array&lt;VkClearValue, 2&gt; clearValues{};
    clearValues[0].color = {0.0f, 0.0f, 0.0f, 1.0f};
    clearValues[1].depthStencil = {1.0f, 0};
    VkRenderPassBeginInfo renderPassBeginInfo{
        .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
        .renderPass = renderPass,
        .framebuffer = swapChainFramebuffers[i],
        .renderArea = {.offset = {0, 0}, .extent = swapChainExtent},
        .clearValueCount = static_cast&lt;uint32_t&gt;(clearValues.size()),
        .pClearValues = clearValues.data(),
    };
    vkCmdBeginRenderPass(commandBuffers[i], &amp;renderPassBeginInfo,
                         VK_SUBPASS_CONTENTS_INLINE);
    vkCmdBindPipeline(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS,
                      pipeline);
  
    vkCmdBindDescriptorSets(commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS,
                            pipelineLayout, 0, 1, &amp;descriptorSets[i], 0,
                            nullptr);
    for (size_t j = 0; j != vertices.size(); j++) {
      VkBuffer vertexBufferArray[] = {vertexBuffers[j]};
      VkDeviceSize offsets[] = {0};
      vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBufferArray,
                             offsets);
      vkCmdBindIndexBuffer(commandBuffers[i], indexBuffers[j], 0,
                           VK_INDEX_TYPE_UINT16);
      vkCmdDrawIndexed(commandBuffers[i], static_cast&lt;uint32_t&gt;(indices[j].size()),
                       1, 0, 0, 0);
    }
  
    vkCmdEndRenderPass(commandBuffers[i]);
    if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
      throw runtime_error(&quot;failed to record command buffer!&quot;);
    }
  
  </code></pre>
  <p>Thanks in advance!</p>