vkDeviceWait 空闲后使用 Vulkan CommandBuffer

Vulkan CommandBuffer in use after vkDeviceWait Idle

在我的程序初始化期间,我想使用一些单次命令缓冲区来进行图像布局转换和加速结构构建等

但是,我似乎无法在完成后释放命令缓冲区。

VkCommandBuffer AppContext::singleTimeCommandBuffer() const {
    VkCommandBuffer ret;
    auto allocInfo = vks::initializers::commandBufferAllocateInfo(vkCommandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1);
    vkCheck(vkAllocateCommandBuffers(vkDevice, &allocInfo, &ret));
    auto beginInfo = vks::initializers::commandBufferBeginInfo();
    beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
    vkCheck(vkBeginCommandBuffer(ret, &beginInfo));
    return ret;
}

void AppContext::endSingleTimeCommands(VkCommandBuffer cmdBuffer) const {
    vkCheck(vkEndCommandBuffer(cmdBuffer));
    auto submitInfo = vks::initializers::submitInfo(&cmdBuffer);
    vkQueueSubmit(queues.graphics, 1, &submitInfo, VK_NULL_HANDLE);

    vkQueueWaitIdle(queues.graphics);
    // Overkill, I know
    vkDeviceWaitIdle(vkDevice);
    vkFreeCommandBuffers(vkDevice, vkCommandPool, 1, &cmdBuffer);
}

这会产生以下验证错误:

VUID-vkFreeCommandBuffers-pCommandBuffers-00047(ERROR / SPEC): msgNum: 448332540 - Validation Error: [ VUID-vkFreeCommandBuffers-pCommandBuffers-00047 ] Object 0: handle = 0x5586acaeff78, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x1ab902fc | Attempt to free VkCommandBuffer 0x5586acaeff78[] which is in use. The Vulkan spec states: All elements of pCommandBuffers must not be in the pending state (https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#VUID-vkFreeCommandBuffers-pCommandBuffers-00047)
    Objects: 1
        [0] 0x5586acaeff78, type: 6, name: NULL

我不明白这是怎么回事,因为 VkQueueWaitIdle 和 vkDeviceWaitIdle 应该确保命令缓冲区不处于挂起状态。我是不是误解了 Vulkan 规范,或者我可能偶然发现了视频驱动程序或验证层中的错误?

您没有检查 vkQueueSubmit()、vkQueueWaitIdle() 或 vkDeviceWaitIdle() 的 return 值。他们中的任何一个失败了吗?这可能会导致此错误。