layers: Validate command buffer is not being used simultaneously unless specified.
authorMichael Lentine <mlentine@google.com>
Wed, 3 Feb 2016 15:20:33 +0000 (09:20 -0600)
committerTobin Ehlis <tobine@google.com>
Thu, 4 Feb 2016 19:20:17 +0000 (12:20 -0700)
layers/draw_state.cpp

index 909bb0d711e5d0032e89f9af2b677606f19ecece..ee343dbda94a3c42e46dadc1d7e897a63a19e0df 100644 (file)
@@ -3428,19 +3428,45 @@ void trackCommandBuffers(layer_data* my_data, VkQueue queue, uint32_t cmdBufferC
     }
 }
 
-static VkBool32 validateCommandBufferState(layer_data* dev_data, GLOBAL_CB_NODE* pCB)
-{
+bool validateCommandBufferSimultaneousUse(layer_data *dev_data,
+                                           GLOBAL_CB_NODE *pCB) {
+    bool skip_call = false;
+    if (dev_data->globalInFlightCmdBuffers.count(pCB->commandBuffer) &&
+        !(pCB->beginInfo.flags &
+          VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
+        skip_call |= log_msg(
+            dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
+            VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
+            DRAWSTATE_INVALID_FENCE, "DS",
+            "Command Buffer %#" PRIx64 " is already in use and is not marked "
+            "for simultaneous use.",
+            reinterpret_cast<uint64_t>(pCB->commandBuffer));
+    }
+    return skip_call;
+}
+
+static VkBool32 validateCommandBufferState(layer_data *dev_data,
+                                           GLOBAL_CB_NODE *pCB) {
     // Track in-use for resources off of primary and any secondary CBs
     VkBool32 skipCall = validateAndIncrementResources(dev_data, pCB);
     if (!pCB->secondaryCommandBuffers.empty()) {
         for (auto secondaryCmdBuffer : pCB->secondaryCommandBuffers) {
-            skipCall |= validateAndIncrementResources(dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
-        }
-    }
-    if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) && (pCB->submitCount > 1)) {
-        skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
-                "CB %#" PRIxLEAST64 " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted %#" PRIxLEAST64 " times.",
-                (uint64_t)(pCB->commandBuffer), pCB->submitCount);
+            skipCall |= validateAndIncrementResources(
+                dev_data, dev_data->commandBufferMap[secondaryCmdBuffer]);
+            GLOBAL_CB_NODE* pSubCB = getCBNode(dev_data, secondaryCmdBuffer);
+            skipCall |= validateCommandBufferSimultaneousUse(dev_data, pSubCB);
+        }
+    }
+    if ((pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT) &&
+        (pCB->submitCount > 1)) {
+        skipCall |=
+            log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
+                    VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__,
+                    DRAWSTATE_COMMAND_BUFFER_SINGLE_SUBMIT_VIOLATION, "DS",
+                    "CB %#" PRIxLEAST64
+                    " was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT "
+                    "set, but has been submitted %#" PRIxLEAST64 " times.",
+                    (uint64_t)(pCB->commandBuffer), pCB->submitCount);
     }
     // Validate that cmd buffers have been updated
     if (CB_RECORDED != pCB->state) {
@@ -3467,13 +3493,9 @@ static VkBool32 validateCommandBufferState(layer_data* dev_data, GLOBAL_CB_NODE*
                 "You must call vkEndCommandBuffer() on CB %#" PRIxLEAST64 " before this call to vkQueueSubmit()!", (uint64_t)(pCB->commandBuffer));
         }
     }
-    // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing on device
-    if (!(pCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
-        if (dev_data->globalInFlightCmdBuffers.find(pCB->commandBuffer) != dev_data->globalInFlightCmdBuffers.end()) {
-            skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)(pCB->commandBuffer), __LINE__, DRAWSTATE_INVALID_CB_SIMULTANEOUS_USE, "DS",
-                "Attempt to simultaneously execute CB %#" PRIxLEAST64 " w/o VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!", (uint64_t)(pCB->commandBuffer));
-        }
-    }
+    // If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing
+    // on device
+    skipCall |= validateCommandBufferSimultaneousUse(dev_data, pCB);
     return skipCall;
 }