layers: Update DrawState to handle creation of multiple gfx pipelines
authorTobin Ehlis <tobin@lunarg.com>
Wed, 16 Sep 2015 16:33:53 +0000 (10:33 -0600)
committerTobin Ehlis <tobin@lunarg.com>
Thu, 17 Sep 2015 21:21:12 +0000 (15:21 -0600)
layers/draw_state.cpp

index 8a51043e9355b4e773914bdba9c9cfc3a1d833c5..d7df92287035f2531b8023d7ffc357f624e66805 100644 (file)
@@ -1734,30 +1734,37 @@ VkResult VKAPI vkMergePipelineCaches(
 VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkGraphicsPipelineCreateInfo* pCreateInfos, VkPipeline* pPipelines)
 {
     VkResult result = VK_SUCCESS;
-    //TODO handle count > 1  and handle pipelineCache
+    //TODO What to do with pipelineCache?
     // The order of operations here is a little convoluted but gets the job done
     //  1. Pipeline create state is first shadowed into PIPELINE_NODE struct
     //  2. Create state is then validated (which uses flags setup during shadowing)
     //  3. If everything looks good, we'll then create the pipeline and add NODE to pipelineMap
+    VkBool32 skipCall = VK_FALSE;
+    PIPELINE_NODE* pPipeNode[count] = {};
+    uint32_t i=0;
     loader_platform_thread_lock_mutex(&globalLock);
-    PIPELINE_NODE* pPipeNode = initPipeline(pCreateInfos, NULL);
-    VkBool32 skipCall = verifyPipelineCreateState(device, pPipeNode);
+    for (i=0; i<count; i++) {
+        pPipeNode[i] = initPipeline(&pCreateInfos[i], NULL);
+        skipCall |= verifyPipelineCreateState(device, pPipeNode[i]);
+    }
     loader_platform_thread_unlock_mutex(&globalLock);
     if (VK_FALSE == skipCall) {
         result = get_dispatch_table(draw_state_device_table_map, device)->CreateGraphicsPipelines(device, pipelineCache, count, pCreateInfos, pPipelines);
-        log_msg(mdd(device), VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_PIPELINE, (*pPipelines).handle, 0, DRAWSTATE_NONE, "DS",
-                "Created Gfx Pipeline %#" PRIxLEAST64, (*pPipelines).handle);
         loader_platform_thread_lock_mutex(&globalLock);
-        pPipeNode->pipeline = *pPipelines;
-        pipelineMap[pPipeNode->pipeline.handle] = pPipeNode;
+        for (i=0; i<count; i++) {
+            pPipeNode[i]->pipeline = pPipelines[i];
+            pipelineMap[pPipeNode[i]->pipeline.handle] = pPipeNode[i];
+        }
         loader_platform_thread_unlock_mutex(&globalLock);
     } else {
-        if (pPipeNode) {
-            // If we allocated a pipeNode, need to clean it up here
-            delete[] pPipeNode->pVertexBindingDescriptions;
-            delete[] pPipeNode->pVertexAttributeDescriptions;
-            delete[] pPipeNode->pAttachments;
-            delete pPipeNode;
+        for (i=0; i<count; i++) {
+            if (pPipeNode[i]) {
+                // If we allocated a pipeNode, need to clean it up here
+                delete[] pPipeNode[i]->pVertexBindingDescriptions;
+                delete[] pPipeNode[i]->pVertexAttributeDescriptions;
+                delete[] pPipeNode[i]->pAttachments;
+                delete pPipeNode[i];
+            }
         }
         return VK_ERROR_VALIDATION_FAILED;
     }