loader: gh851 wrap debug report callbacks
authorMark Young <marky@lunarg.com>
Thu, 25 Aug 2016 20:54:58 +0000 (14:54 -0600)
committerMark Young <marky@lunarg.com>
Thu, 1 Sep 2016 17:38:43 +0000 (11:38 -0600)
Allow layers to wrap the debug report callbacks so they can
enable more messaging than the application, but also filter
the items returned.

Change-Id: I3fe8feecfa1838869de8a7338ff610e5ebca2e61

loader/debug_report.c
loader/trampoline.c

index 4da1413..83c5a6a 100644 (file)
@@ -65,22 +65,27 @@ util_CreateDebugReportCallback(struct loader_instance *inst,
                                VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
                                const VkAllocationCallbacks *pAllocator,
                                VkDebugReportCallbackEXT callback) {
-    VkLayerDbgFunctionNode *pNewDbgFuncNode;
+    VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
+
 #if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
     {
 #else
     if (pAllocator != NULL) {
-        pNewDbgFuncNode = (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(
-            pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
-            sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+        pNewDbgFuncNode =
+            (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(
+                pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
+                sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
     } else {
 #endif
-        pNewDbgFuncNode = (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(
-            inst, sizeof(VkLayerDbgFunctionNode),
-            VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+        pNewDbgFuncNode =
+            (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(
+                inst, sizeof(VkLayerDbgFunctionNode),
+                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
     }
-    if (!pNewDbgFuncNode)
+    if (!pNewDbgFuncNode) {
         return VK_ERROR_OUT_OF_HOST_MEMORY;
+    }
+    memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
 
     pNewDbgFuncNode->msgCallback = callback;
     pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback;
@@ -99,10 +104,6 @@ static VKAPI_ATTR VkResult VKAPI_CALL debug_report_CreateDebugReportCallback(
     loader_platform_thread_lock_mutex(&loader_lock);
     VkResult result = inst->disp->CreateDebugReportCallbackEXT(
         instance, pCreateInfo, pAllocator, pCallback);
-    if (result == VK_SUCCESS) {
-        result = util_CreateDebugReportCallback(inst, pCreateInfo, pAllocator,
-                                                *pCallback);
-    }
     loader_platform_thread_unlock_mutex(&loader_lock);
     return result;
 }
@@ -311,6 +312,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback(
     struct loader_instance *inst = (struct loader_instance *)instance;
     VkResult res = VK_SUCCESS;
     uint32_t storage_idx;
+    VkLayerDbgFunctionNode *pNewDbgFuncNode = NULL;
 
 #if (DEBUG_DISABLE_APP_ALLOCATORS == 1)
     {
@@ -346,6 +348,36 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateDebugReportCallback(
         storage_idx++;
     }
 
+    // Setup the debug report callback in the terminator since a layer may want
+    // to grab the information itself (RenderDoc) and then return back to the
+    // user callback a sub-set of the messages.
+#if (DEBUG_DISABLE_APP_ALLOCATORS == 0)
+    if (pAllocator != NULL) {
+        pNewDbgFuncNode =
+            (VkLayerDbgFunctionNode *)pAllocator->pfnAllocation(
+                pAllocator->pUserData, sizeof(VkLayerDbgFunctionNode),
+                sizeof(int *), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+    } else {
+#else
+    {
+#endif
+        pNewDbgFuncNode =
+            (VkLayerDbgFunctionNode *)loader_instance_heap_alloc(
+                inst, sizeof(VkLayerDbgFunctionNode),
+                VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+    }
+    if (!pNewDbgFuncNode) {
+        return VK_ERROR_OUT_OF_HOST_MEMORY;
+    }
+    memset(pNewDbgFuncNode, 0, sizeof(VkLayerDbgFunctionNode));
+
+    pNewDbgFuncNode->msgCallback = *pCallback;
+    pNewDbgFuncNode->pfnMsgCallback = pCreateInfo->pfnCallback;
+    pNewDbgFuncNode->msgFlags = pCreateInfo->flags;
+    pNewDbgFuncNode->pUserData = pCreateInfo->pUserData;
+    pNewDbgFuncNode->pNext = inst->DbgFunctionHead;
+    inst->DbgFunctionHead = pNewDbgFuncNode;
+
     /* roll back on errors */
     if (icd) {
         storage_idx = 0;
index 54a7105..7ed168f 100644 (file)
@@ -418,8 +418,6 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(
          * if enabled.
          */
         loader_activate_instance_layer_extensions(ptr_instance, *pInstance);
-    } else {
-        // TODO: cleanup here.
     }
 
 out: