1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/*
* Vulkan
*
* Copyright (C) 2014 LunarG, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdio.h>
#include <stdbool.h>
#include "vkLayer.h"
static VkLayerDbgFunctionNode *g_pDbgFunctionHead = NULL;
static VkFlags g_reportFlags = (VkFlags) 0;
static VkLayerDbgAction g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
static bool g_actionIsDefault = true;
static bool g_DEBUG_REPORT = false;
static FILE *g_logFile = NULL;
static void enable_debug_report(
uint32_t extension_count,
const VkExtensionProperties* pEnabledExtensions) // layer or extension name to be enabled
{
for (uint32_t i = 0; i < extension_count; i++) {
/* TODO: Check other property fields */
if (strcmp(pEnabledExtensions[i].name, DEBUG_REPORT_EXTENSION_NAME) == 0) {
g_DEBUG_REPORT = true;
}
}
}
static VkResult layer_create_msg_callback(
VkInstance instance,
VkLayerInstanceDispatchTable* nextTable,
VkFlags msgFlags,
const PFN_vkDbgMsgCallback pfnMsgCallback,
void* pUserData,
VkDbgMsgCallback* pMsgCallback)
{
VkLayerDbgFunctionNode *pNewDbgFuncNode = (VkLayerDbgFunctionNode*)malloc(sizeof(VkLayerDbgFunctionNode));
if (!pNewDbgFuncNode)
return VK_ERROR_OUT_OF_HOST_MEMORY;
VkResult result = nextTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
if (result == VK_SUCCESS) {
pNewDbgFuncNode->msgCallback = *pMsgCallback;
pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
pNewDbgFuncNode->msgFlags = msgFlags;
pNewDbgFuncNode->pUserData = pUserData;
pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
/* TODO: This should be a per-instance resource */
g_pDbgFunctionHead = pNewDbgFuncNode;
} else {
free(pNewDbgFuncNode);
}
return result;
}
static VkResult layer_destroy_msg_callback(
VkInstance instance,
VkLayerInstanceDispatchTable *nextTable,
VkDbgMsgCallback msg_callback)
{
VkLayerDbgFunctionNode *pTrav = g_pDbgFunctionHead;
VkLayerDbgFunctionNode *pPrev = pTrav;
VkResult result = nextTable->DbgDestroyMsgCallback(instance, msg_callback);
while (pTrav) {
if (pTrav->msgCallback == msg_callback) {
pPrev->pNext = pTrav->pNext;
if (g_pDbgFunctionHead == pTrav)
g_pDbgFunctionHead = pTrav->pNext;
free(pTrav);
break;
}
pPrev = pTrav;
pTrav = pTrav->pNext;
}
return result;
}
static inline void debug_report_init_instance_extension_dispatch_table(
VkLayerInstanceDispatchTable *table,
PFN_vkGetInstanceProcAddr gpa,
VkInstance inst)
{
table->DbgCreateMsgCallback = (PFN_vkDbgCreateMsgCallback) gpa(inst, "vkDbgCreateMsgCallback");
table->DbgDestroyMsgCallback = (PFN_vkDbgDestroyMsgCallback) gpa(inst, "vkDbgDestroyMsgCallback");
}
static void* msg_callback_get_proc_addr(
const char *funcName)
{
if (!g_DEBUG_REPORT) {
return NULL;
}
if (!strcmp(funcName, "vkDbgCreateMsgCallback")) {
return (void *) vkDbgCreateMsgCallback;
}
if (!strcmp(funcName, "vkDbgDestroyMsgCallback")) {
return (void *) vkDbgDestroyMsgCallback;
}
return NULL;
}
// Utility function to handle reporting
// If callbacks are enabled, use them, otherwise use printf
static void layerCbMsg(
VkFlags msgFlags,
VkObjectType objectType,
VkObject srcObject,
size_t location,
int32_t msgCode,
const char* pLayerPrefix,
const char* pMsg)
{
if (g_logFile == NULL) {
g_logFile = stdout;
}
VkLayerDbgFunctionNode *pTrav = g_pDbgFunctionHead;
while (pTrav) {
if (pTrav->msgFlags & msgFlags) {
pTrav->pfnMsgCallback(msgFlags,
objectType, srcObject,
location,
msgCode,
pLayerPrefix,
pMsg,
(void *) pTrav->pUserData);
}
pTrav = pTrav->pNext;
}
}
|