radv: only reset command buffers when the allocation fails
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 30 Nov 2017 21:23:37 +0000 (22:23 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 1 Dec 2017 10:38:34 +0000 (11:38 +0100)
   "vkAllocateCommandBuffers can be used to create multiple command
    buffers. If the creation of any of those command buffers fails, the
    implementation must destroy all successfully created command buffer
    objects from this command, set all entries of the pCommandBuffers
    array to NULL and return the error."

This has been suggested by gabriel@system.is.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_cmd_buffer.c

index 18a1c55ad189ccfe1719ba2cb87e7bf247243dcd..fe4f989dd1b9037cc8e71c809aba14a61ee7b69d 100644 (file)
@@ -2140,9 +2140,6 @@ VkResult radv_AllocateCommandBuffers(
        VkResult result = VK_SUCCESS;
        uint32_t i;
 
-       memset(pCommandBuffers, 0,
-                       sizeof(*pCommandBuffers)*pAllocateInfo->commandBufferCount);
-
        for (i = 0; i < pAllocateInfo->commandBufferCount; i++) {
 
                if (!list_empty(&pool->free_cmd_buffers)) {
@@ -2164,10 +2161,23 @@ VkResult radv_AllocateCommandBuffers(
                        break;
        }
 
-       if (result != VK_SUCCESS)
+       if (result != VK_SUCCESS) {
                radv_FreeCommandBuffers(_device, pAllocateInfo->commandPool,
                                        i, pCommandBuffers);
 
+               /* From the Vulkan 1.0.66 spec:
+                *
+                * "vkAllocateCommandBuffers can be used to create multiple
+                *  command buffers. If the creation of any of those command
+                *  buffers fails, the implementation must destroy all
+                *  successfully created command buffer objects from this
+                *  command, set all entries of the pCommandBuffers array to
+                *  NULL and return the error."
+                */
+               memset(pCommandBuffers, 0,
+                      sizeof(*pCommandBuffers) * pAllocateInfo->commandBufferCount);
+       }
+
        return result;
 }