layers: Add object type validation to object tracker
authorMark Lobodzinski <mark@lunarg.com>
Tue, 5 May 2015 23:24:45 +0000 (18:24 -0500)
committerMark Lobodzinski <mark@lunarg.com>
Tue, 5 May 2015 23:24:45 +0000 (18:24 -0500)
Validate that objects match the objectType any time both are specified.

layers/object_track.h
vk-layer-generate.py

index 7697d60a72f13ce2198d92da47acedc8c9b0b316..9c45e2a72ac85d670b8ad60321172ce436b58bae 100644 (file)
@@ -31,6 +31,7 @@ typedef enum _OBJECT_TRACK_ERROR
     OBJTRACK_INTERNAL_ERROR,                    // Bug with data tracking within the layer
     OBJTRACK_DESTROY_OBJECT_FAILED,             // Couldn't find object to be destroyed
     OBJTRACK_MISSING_OBJECT,                    // Attempted look-up on object that isn't in global object list
+    OBJTRACK_OBJECT_TYPE_MISMATCH,              // Object did not match corresponding Object Type
     OBJTRACK_OBJECT_LEAK,                       // OBJECT was not correctly freed/destroyed
     OBJTRACK_OBJCOUNT_MAX_EXCEEDED,             // Request for Object data in excess of max obj count
     OBJTRACK_INVALID_FENCE,                     // Requested status of unsubmitted fence object
index 09593a178f229e71c2337964e5e3f56bbeab5b70..5fa03d189bcb6a19a723ffc1bd36d3121249cd8b 100755 (executable)
@@ -923,6 +923,27 @@ class ObjectTrackerSubcommand(Subcommand):
         header_txt.append('    return index;')
         header_txt.append('}')
         header_txt.append('')
+        header_txt.append('// Validate that object parameter matches designated object type')
+        header_txt.append('static void validateObjectType(')
+        header_txt.append('    const char  *apiName,')
+        header_txt.append('    VkObjectType objType,')
+        header_txt.append('    VkObject     object)')
+        header_txt.append('{')
+        header_txt.append('    objNode *pObjNode = pGlobalHead;')
+        header_txt.append('    while ((pObjNode != NULL) && (pObjNode->obj.vkObj != object)) {')
+        header_txt.append('        pObjNode = pObjNode->pNextGlobal;')
+        header_txt.append('    }')
+        header_txt.append('    if (pObjNode != NULL) {')
+        header_txt.append('        // Found our object, check type')
+        header_txt.append('        if (strcmp(string_VkObjectType(pObjNode->obj.objType), string_VkObjectType(objType)) != 0) {')
+        header_txt.append('            char str[1024];')
+        header_txt.append('            sprintf(str, "ERROR: Object Parameter Type %s does not match designated type %s",')
+        header_txt.append('                string_VkObjectType(pObjNode->obj.objType), string_VkObjectType(objType));')
+        header_txt.append('            layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, OBJTRACK_OBJECT_TYPE_MISMATCH, "OBJTRACK", str);')
+        header_txt.append('        }')
+        header_txt.append('    }')
+        header_txt.append('}')
+        header_txt.append('')
         header_txt.append('// Add new queue to head of global queue list')
         header_txt.append('static void addQueueInfo(uint32_t queueNodeIndex, VkQueue queue)')
         header_txt.append('{')
@@ -1220,14 +1241,25 @@ class ObjectTrackerSubcommand(Subcommand):
             using_line += '    // validate_memory_mapping_status(pMemRefs, memRefCount);\n'
             using_line += '    // validate_mem_ref_count(memRefCount);\n'
             using_line += '    loader_platform_thread_unlock_mutex(&objLock);\n'
-        elif 'QueueBindObjectMemoryRange' in proto.name or 'QueueBindImageMemoryRange' in proto.name:
-            using_line = '    loader_platform_thread_lock_mutex(&objLock);\n'
+        elif 'QueueBindObject' in proto.name:
+            using_line += '    loader_platform_thread_lock_mutex(&objLock);\n'
+            using_line += '    validateObjectType("vk%s", objType, object);\n' % (proto.name)
+            using_line += '    if (validateQueueFlags(queue) == VK_FALSE) {\n'
+            using_line += '        char str[1024];\n'
+            using_line += '        sprintf(str, "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_MEMMGR_BIT not set");\n' % (proto.name)
+            using_line += '        layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);\n'
+            using_line += '    }\n'
+            using_line += '    loader_platform_thread_unlock_mutex(&objLock);\n'
+        elif 'QueueBindImage' in proto.name:
+            using_line += '    loader_platform_thread_lock_mutex(&objLock);\n'
             using_line += '    if (validateQueueFlags(queue) == VK_FALSE) {\n'
             using_line += '        char str[1024];\n'
             using_line += '        sprintf(str, "Attempting %s on a non-memory-management capable queue -- VK_QUEUE_MEMMGR_BIT not set");\n' % (proto.name)
             using_line += '        layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, OBJTRACK_UNKNOWN_OBJECT, "OBJTRACK", str);\n'
             using_line += '    }\n'
             using_line += '    loader_platform_thread_unlock_mutex(&objLock);\n'
+        elif 'GetObjectInfo' in proto.name:
+            using_line += '    validateObjectType("vk%s", objType, object);\n' % (proto.name)
         elif 'GetFenceStatus' in proto.name:
             using_line += '    // Warn if submitted_flag is not set\n'
             using_line += '    validate_status(fence, VK_OBJECT_TYPE_FENCE, OBJSTATUS_FENCE_IS_SUBMITTED, OBJSTATUS_FENCE_IS_SUBMITTED, VK_DBG_MSG_ERROR, OBJTRACK_INVALID_FENCE, "Status Requested for Unsubmitted Fence");\n'
@@ -1266,6 +1298,7 @@ class ObjectTrackerSubcommand(Subcommand):
             using_line += '    loader_platform_thread_unlock_mutex(&objLock);\n'
         if 'DestroyObject' in proto.name:
             destroy_line = '    loader_platform_thread_lock_mutex(&objLock);\n'
+            destroy_line += '    validateObjectType("vk%s", objType, object);\n' % (proto.name)
             destroy_line += '    ll_destroy_obj(%s);\n' % (proto.params[2].name)
             destroy_line += '    loader_platform_thread_unlock_mutex(&objLock);\n'
             using_line = ''