layers: DrawState layout tracking improvements
authorTobin Ehlis <tobin@lunarg.com>
Tue, 20 Oct 2015 16:11:55 +0000 (10:11 -0600)
committerTobin Ehlis <tobin@lunarg.com>
Thu, 22 Oct 2015 17:12:27 +0000 (11:12 -0600)
Descriptor type per layout tracked via vector to simplify allocation/cleanup.
Added tracking for pipeline layout that can be used for further validation checks

layers/draw_state.cpp
layers/draw_state.h

index 82377d5..63df706 100755 (executable)
@@ -69,6 +69,7 @@ struct layer_data {
     unordered_map<uint64_t, POOL_NODE*> poolMap;
     unordered_map<uint64_t, SET_NODE*> setMap;
     unordered_map<uint64_t, LAYOUT_NODE*> layoutMap;
+    unordered_map<uint64_t, PIPELINE_LAYOUT_NODE> pipelineLayoutMap;
     // Map for layout chains
     unordered_map<void*, GLOBAL_CB_NODE*> cmdBufferMap;
     unordered_map<uint64_t, VkRenderPassCreateInfo*> renderPassMap;
@@ -824,10 +825,10 @@ static VkBool32 validateUpdateType(const VkDevice device, const LAYOUT_NODE* pLa
     skipCall |= getUpdateEndIndex(device, pLayout, pUpdateStruct, &endIndex);
     if (VK_FALSE == skipCall) {
         for (i = startIndex; i <= endIndex; i++) {
-            if (pLayout->pTypes[i] != actualType) {
+            if (pLayout->descriptorTypes[i] != actualType) {
                 skipCall |= log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType) 0, 0, 0, DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, "DS",
                         "Descriptor update type of %s has descriptor type %s that does not match overlapping binding descriptor type of %s!",
-                        string_VkStructureType(pUpdateStruct->sType), string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->pTypes[i]));
+                        string_VkStructureType(pUpdateStruct->sType), string_VkDescriptorType(actualType), string_VkDescriptorType(pLayout->descriptorTypes[i]));
             }
         }
     }
@@ -1063,9 +1064,6 @@ static void deleteLayouts(layer_data* my_data)
             }
             delete[] pLayout->createInfo.pBinding;
         }
-        if (pLayout->pTypes) {
-            delete[] pLayout->pTypes;
-        }
         delete pLayout;
     }
     my_data->layoutMap.clear();
@@ -1827,12 +1825,12 @@ VK_LAYER_EXPORT VkResult VKAPI vkCreateDescriptorSetLayout(VkDevice device, cons
             }
         }
         if (totalCount > 0) {
-            pNewNode->pTypes = new VkDescriptorType[totalCount];
+            pNewNode->descriptorTypes.reserve(totalCount);
             uint32_t offset = 0;
             uint32_t j = 0;
             for (uint32_t i=0; i<pCreateInfo->count; i++) {
                 for (j = 0; j < pCreateInfo->pBinding[i].arraySize; j++) {
-                    pNewNode->pTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
+                    pNewNode->descriptorTypes[offset + j] = pCreateInfo->pBinding[i].descriptorType;
                 }
                 offset += j;
             }
@@ -1854,7 +1852,16 @@ VkResult VKAPI vkCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCre
     layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
     VkResult result = dev_data->device_dispatch_table->CreatePipelineLayout(device, pCreateInfo, pPipelineLayout);
     if (VK_SUCCESS == result) {
-        // TODO : Need to capture the pipeline layout
+        PIPELINE_LAYOUT_NODE plNode = dev_data->pipelineLayoutMap[pPipelineLayout->handle];
+        plNode.descriptorSetLayouts.reserve(pCreateInfo->descriptorSetCount);
+        uint32_t i = 0;
+        for (i=0; i<pCreateInfo->descriptorSetCount; ++i) {
+            plNode.descriptorSetLayouts[i] = pCreateInfo->pSetLayouts[i];
+        }
+        plNode.pushConstantRanges.reserve(pCreateInfo->pushConstantRangeCount);
+        for (i=0; i<pCreateInfo->pushConstantRangeCount; ++i) {
+            plNode.pushConstantRanges[i] = pCreateInfo->pPushConstantRanges[i];
+        }
     }
     return result;
 }
index 2328936..c4acd8d 100755 (executable)
@@ -144,11 +144,17 @@ typedef struct _BUFFER_NODE {
 // Layout Node has the core layout data
 typedef struct _LAYOUT_NODE {
     VkDescriptorSetLayout           layout;
-    VkDescriptorType*               pTypes; // Dynamic array that will be created to verify descriptor types
     VkDescriptorSetLayoutCreateInfo createInfo;
     uint32_t                        startIndex; // 1st index of this layout
     uint32_t                        endIndex; // last index of this layout
+    vector<VkDescriptorType>        descriptorTypes; // Type per descriptor in this layout to verify correct updates
 } LAYOUT_NODE;
+// Store layouts and pushconstants for PipelineLayout
+struct PIPELINE_LAYOUT_NODE {
+    vector<VkDescriptorSetLayout>  descriptorSetLayouts;
+    vector<VkPushConstantRange>    pushConstantRanges;
+};
+
 typedef struct _SET_NODE {
     VkDescriptorSet      set;
     VkDescriptorPool     pool;