blob: 5c36c8023883db5794de7407d2f107ece1722fa5 [file] [log] [blame]
Courtney Goeltzenleuchter210efbc2015-05-05 18:18:01 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include <string.h>
25#include <stdlib.h>
26#include <assert.h>
27#include <unordered_map>
28#include "loader_platform.h"
29#include "vk_dispatch_table_helper.h"
30#include "vkLayer.h"
31// The following is #included again to catch certain OS-specific functions
32// being used:
33#include "loader_platform.h"
34
35static std::unordered_map<void *, VkLayerDispatchTable *> tableMap;
36
37static VkLayerDispatchTable * initLayerTable(const VkBaseLayerObject *gpuw)
38{
39 VkLayerDispatchTable *pTable;
40
41 assert(gpuw);
42 std::unordered_map<void *, VkLayerDispatchTable *>::const_iterator it = tableMap.find((void *) gpuw->baseObject);
43 if (it == tableMap.end())
44 {
45 pTable = new VkLayerDispatchTable;
46 tableMap[(void *) gpuw->baseObject] = pTable;
47 } else
48 {
49 return it->second;
50 }
51
52 layer_initialize_dispatch_table(pTable, gpuw->pGPA, (VkPhysicalDevice) gpuw->nextObject);
53
54 return pTable;
55}
56
57VK_LAYER_EXPORT VkResult VKAPI vkLayerExtension1(VkDevice device)
58{
59 printf("In vkLayerExtension1() call w/ device: %p\n", (void*)device);
60 printf("vkLayerExtension1 returning SUCCESS\n");
61 return VK_SUCCESS;
62}
63
64struct extProps {
65 uint32_t version;
66 const char * const name;
67};
68#define DEBUG_SUPPORT_LAYER_EXT_ARRAY_SIZE 2
69static const struct extProps debugReportExts[DEBUG_SUPPORT_LAYER_EXT_ARRAY_SIZE] = {
70 0x10, "DebugReport",
71 0x10, "DebugMarker",
72};
73
74VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
75 VkExtensionInfoType infoType,
76 uint32_t extensionIndex,
77 size_t* pDataSize,
78 void* pData)
79{
80 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
81 VkExtensionProperties *ext_props;
82 uint32_t *count;
83
84 if (pDataSize == NULL)
85 return VK_ERROR_INVALID_POINTER;
86
87 switch (infoType) {
88 case VK_EXTENSION_INFO_TYPE_COUNT:
89 *pDataSize = sizeof(uint32_t);
90 if (pData == NULL)
91 return VK_SUCCESS;
92 count = (uint32_t *) pData;
93 *count = DEBUG_SUPPORT_LAYER_EXT_ARRAY_SIZE;
94 break;
95 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
96 *pDataSize = sizeof(VkExtensionProperties);
97 if (pData == NULL)
98 return VK_SUCCESS;
99 if (extensionIndex >= DEBUG_SUPPORT_LAYER_EXT_ARRAY_SIZE)
100 return VK_ERROR_INVALID_VALUE;
101 ext_props = (VkExtensionProperties *) pData;
102 ext_props->version = debugReportExts[extensionIndex].version;
103 strncpy(ext_props->extName, debugReportExts[extensionIndex].name,
104 VK_MAX_EXTENSION_NAME);
105 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
106 break;
107 default:
108 return VK_ERROR_INVALID_VALUE;
109 };
110
111 return VK_SUCCESS;
112}
113
114static VkResult VKAPI DbgCreateMsgCallback(
115 VkInstance instance,
116 VkFlags msgFlags,
117 const PFN_vkDbgMsgCallback pfnMsgCallback,
118 const void* pUserData,
119 const VkDbgMsgCallback* pMsgCallback)
120{
121
122}
123
124// DebugReport utility callback functions
125static void VKAPI StringCallback(
126 VkFlags msgFlags,
127 VkObjectType objType,
128 VkObject srcObject,
129 size_t location,
130 int32_t msgCode,
131 const char* pLayerPrefix,
132 const char* pMsg,
133 void* pUserData)
134{
135
136}
137
138static void VKAPI StdioCallback(
139 VkFlags msgFlags,
140 VkObjectType objType,
141 VkObject srcObject,
142 size_t location,
143 int32_t msgCode,
144 const char* pLayerPrefix,
145 const char* pMsg,
146 void* pUserData)
147{
148
149}
150
151static void VKAPI BreakCallback(
152 VkFlags msgFlags,
153 VkObjectType objType,
154 VkObject srcObject,
155 size_t location,
156 int32_t msgCode,
157 const char* pLayerPrefix,
158 const char* pMsg,
159 void* pUserData)
160{
161
162}
163
164// DebugMarker extension entrypoints
165static void VKAPI CmdDbgMarkerBegin(
166 VkCmdBuffer cmdBuffer,
167 const char* pMarker)
168{
169
170}
171
172static void VKAPI CmdDbgMarkerEnd(
173 VkCmdBuffer cmdBuffer)
174{
175
176}
177
178static VkResult VKAPI DbgSetObjectTag(
179 VkDevice device,
180 VkObjectType objType,
181 VkObject object,
182 size_t tagSize,
183 const void* pTag)
184{
185
186}
187
188static VkResult VKAPI DbgSetObjectName(
189 VkDevice device,
190 VkObjectType objType,
191 VkObject object,
192 size_t nameSize,
193 const char* pName)
194{
195
196}
197
198VK_LAYER_EXPORT void * VKAPI vkGetProcAddr(VkPhysicalDevice gpu, const char* pName)
199{
200 if (gpu == NULL)
201 return NULL;
202
203 initLayerTable((const VkBaseLayerObject *) gpu);
204
205 if (!strncmp("vkGetProcAddr", pName, sizeof("vkGetProcAddr")))
206 return (void *) vkGetProcAddr;
207 else if (!strcmp("vkDbgCreateMsgCallback", pName))
208 return (void *) DbgCreateMsgCallback;
209 else if (!strcmp("vkStringCallback", pName))
210 return (void *) StringCallback;
211 else if (!strcmp("vkStdioCallback", pName))
212 return (void *) StdioCallback;
213 else if (!strcmp("vkBreakCallback", pName))
214 return (void *) BreakCallback;
215 else if (!strcmp("vkCmdDbgMarkerBegin", pName))
216 return (void *) CmdDbgMarkerBegin;
217 else if (!strcmp("vkCmdDbgMarkerEnd", pName))
218 return (void *) CmdDbgMarkerEnd;
219 else if (!strcmp("vkDbgSetObjectTag", pName))
220 return (void *) DbgSetObjectTag;
221 else if (!strcmp("vkDbgSetObjectName", pName))
222 return (void *) DbgSetObjectName;
223 else {
224 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
225 if (gpuw->pGPA == NULL)
226 return NULL;
227 return gpuw->pGPA((VkPhysicalDevice) gpuw->nextObject, pName);
228 }
229}