Helper to copy the contents of one buffer to another buffer
| 1329 | |
| 1330 | // Helper to copy the contents of one buffer to another buffer |
| 1331 | bool copyBuffer(VkBuffer dst, VkBuffer src, VkDeviceSize size) |
| 1332 | { |
| 1333 | // Allocate a primary command buffer out of our command pool |
| 1334 | VkCommandBufferAllocateInfo commandBufferAllocateInfo = VkCommandBufferAllocateInfo(); |
| 1335 | commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
| 1336 | commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
| 1337 | commandBufferAllocateInfo.commandPool = commandPool; |
| 1338 | commandBufferAllocateInfo.commandBufferCount = 1; |
| 1339 | |
| 1340 | VkCommandBuffer commandBuffer = nullptr; |
| 1341 | |
| 1342 | if (vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) != VK_SUCCESS) |
| 1343 | return false; |
| 1344 | |
| 1345 | // Begin the command buffer |
| 1346 | VkCommandBufferBeginInfo commandBufferBeginInfo = VkCommandBufferBeginInfo(); |
| 1347 | commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
| 1348 | commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1349 | |
| 1350 | if (vkBeginCommandBuffer(commandBuffer, &commandBufferBeginInfo) != VK_SUCCESS) |
| 1351 | { |
| 1352 | vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); |
| 1353 | |
| 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | // Add our buffer copy command |
| 1358 | VkBufferCopy bufferCopy = VkBufferCopy(); |
| 1359 | bufferCopy.srcOffset = 0; |
| 1360 | bufferCopy.dstOffset = 0; |
| 1361 | bufferCopy.size = size; |
| 1362 | |
| 1363 | vkCmdCopyBuffer(commandBuffer, src, dst, 1, &bufferCopy); |
| 1364 | |
| 1365 | // End and submit the command buffer |
| 1366 | vkEndCommandBuffer(commandBuffer); |
| 1367 | |
| 1368 | VkSubmitInfo submitInfo = VkSubmitInfo(); |
| 1369 | submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
| 1370 | submitInfo.commandBufferCount = 1; |
| 1371 | submitInfo.pCommandBuffers = &commandBuffer; |
| 1372 | |
| 1373 | if (vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE) != VK_SUCCESS) |
| 1374 | { |
| 1375 | vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); |
| 1376 | |
| 1377 | return false; |
| 1378 | } |
| 1379 | |
| 1380 | // Ensure the command buffer has been processed |
| 1381 | if (vkQueueWaitIdle(queue) != VK_SUCCESS) |
| 1382 | { |
| 1383 | vkFreeCommandBuffers(device, commandPool, 1, &commandBuffer); |
| 1384 | |
| 1385 | return false; |
| 1386 | } |
| 1387 | |
| 1388 | // Free the command buffer |
nothing calls this directly
no test coverage detected