blob: 30e57d4463eddc9953fa22a09268a3cf3239ac7b [file] [log] [blame]
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 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
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29#include <memory>
30
31#include "vk_loader_platform.h"
32#include "vk_dispatch_table_helper.h"
33#include "vk_struct_string_helper_cpp.h"
34#if defined(__GNUC__)
35#pragma GCC diagnostic ignored "-Wwrite-strings"
36#endif
37#if defined(__GNUC__)
38#pragma GCC diagnostic warning "-Wwrite-strings"
39#endif
40#include "vk_struct_size_helper.h"
41#include "device_limits.h"
42#include "vk_layer_config.h"
43#include "vk_debug_marker_layer.h"
44// The following is #included again to catch certain OS-specific functions
45// being used:
46#include "vk_loader_platform.h"
47#include "vk_layer_msg.h"
48#include "vk_layer_table.h"
49#include "vk_layer_debug_marker_table.h"
50#include "vk_layer_data.h"
51#include "vk_layer_logging.h"
52#include "vk_layer_extension_utils.h"
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060053#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060054
55typedef struct _layer_data {
56 debug_report_data *report_data;
57 // TODO: put instance data here
58 VkDbgMsgCallback logging_callback;
59} layer_data;
60
61static std::unordered_map<void *, layer_data *> layer_data_map;
62static device_table_map device_limits_device_table_map;
63static instance_table_map device_limits_instance_table_map;
64
65// Track state of each instance
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060066unordered_map<VkInstance, unique_ptr<INSTANCE_STATE>> instanceMap;
67unordered_map<VkPhysicalDevice, unique_ptr<PHYSICAL_DEVICE_STATE>> physicalDeviceMap;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060068unordered_map<VkPhysicalDevice, unordered_map<uint32_t, unique_ptr<VkQueueFamilyProperties>>> queueFamilyPropertiesMap;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060069unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceFeatures>> physicalDeviceFeaturesMap;
70unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceProperties>> physicalDevicePropertiesMap;
71unordered_map<VkDevice, VkPhysicalDevice> deviceMap;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060072
73struct devExts {
74 bool debug_marker_enabled;
75};
76
77static std::unordered_map<void *, struct devExts> deviceExtMap;
78
79static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
80
81// TODO : This can be much smarter, using separate locks for separate global data
82static int globalLockInitialized = 0;
83static loader_platform_thread_mutex globalLock;
84
85template layer_data *get_my_data_ptr<layer_data>(
86 void *data_key,
87 std::unordered_map<void *, layer_data *> &data_map);
88
89debug_report_data *mdd(void* object)
90{
91 dispatch_key key = get_dispatch_key(object);
92 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
93#if DISPATCH_MAP_DEBUG
94 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
95#endif
96 return my_data->report_data;
97}
98
99debug_report_data *mid(VkInstance object)
100{
101 dispatch_key key = get_dispatch_key(object);
102 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
103#if DISPATCH_MAP_DEBUG
104 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
105#endif
106 return my_data->report_data;
107}
108
109static void init_device_limits(layer_data *my_data)
110{
111 uint32_t report_flags = 0;
112 uint32_t debug_action = 0;
113 FILE *log_output = NULL;
114 const char *option_str;
115 // initialize DeviceLimits options
116 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
117 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
118
119 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
120 {
121 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -0600122 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600123 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
124 }
125
126 if (!globalLockInitialized)
127 {
128 // TODO/TBD: Need to delete this mutex sometime. How??? One
129 // suggestion is to call this during vkCreateInstance(), and then we
130 // can clean it up during vkDestroyInstance(). However, that requires
131 // that the layer have per-instance locks. We need to come back and
132 // address this soon.
133 loader_platform_thread_create_mutex(&globalLock);
134 globalLockInitialized = 1;
135 }
136}
137
138VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
139{
140 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map,*pInstance);
141 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
142
143 if (result == VK_SUCCESS) {
144 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
145 my_data->report_data = debug_report_create_instance(
146 pTable,
147 *pInstance,
148 pCreateInfo->extensionCount,
149 pCreateInfo->ppEnabledExtensionNames);
150
151 init_device_limits(my_data);
152 instanceMap[*pInstance] = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
153 }
154 return result;
155}
156
157/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600158VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600159{
160 dispatch_key key = get_dispatch_key(instance);
161 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600162 pTable->DestroyInstance(instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600163
164 // Clean up logging callback, if any
165 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
166 if (my_data->logging_callback) {
167 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
168 }
169
170 layer_debug_report_destroy_instance(my_data->report_data);
171 layer_data_map.erase(pTable);
172 instanceMap.erase(instance);
173 device_limits_instance_table_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600174}
175
176VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
177{
178 auto it = instanceMap.find(instance);
179 if (it != instanceMap.end()) {
180 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
181 if (NULL == pPhysicalDevices) {
182 it->second->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
183 } else {
184 if (UNCALLED == it->second->vkEnumeratePhysicalDevicesState) {
185 // Flag error here, shouldn't be calling this without having queried count
186 log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
187 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
188 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
189 else if (it->second->physicalDevicesCount != *pPhysicalDeviceCount) {
190 log_msg(mid(instance), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
191 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, it->second->physicalDevicesCount);
192 }
193 it->second->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
194 }
195 VkResult result = get_dispatch_table(device_limits_instance_table_map,instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
196 if (NULL == pPhysicalDevices) {
197 it->second->physicalDevicesCount = *pPhysicalDeviceCount;
198 } else { // Save physical devices
199 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
200 physicalDeviceMap[pPhysicalDevices[i]] = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
201 }
202 }
203 return result;
204 } else {
205 log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
206 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
207 }
208}
209
210VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
211{
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600212 VkResult result = VK_SUCCESS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600213 auto it = physicalDeviceMap.find(physicalDevice);
214 if (it != physicalDeviceMap.end()) {
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600215 result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600216 // Save Features
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600217 if (VK_SUCCESS == result) {
218 physicalDeviceFeaturesMap[physicalDevice] =
219 unique_ptr<VkPhysicalDeviceFeatures>(new VkPhysicalDeviceFeatures(*pFeatures));
220 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600221 }
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600222 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600223}
224
225VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
226{
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600227 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties(
228 physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600229 return result;
230}
231
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600232VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600233{
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600234 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600235 return result;
236}
237
238VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
239{
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600240 VkResult result = VK_SUCCESS;
241 auto it = physicalDeviceMap.find(physicalDevice);
242 if (it != physicalDeviceMap.end()) {
243 result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->
244 GetPhysicalDeviceProperties(physicalDevice, pProperties);
245 if (VK_SUCCESS == result) {
246 // Save Properties
247 physicalDevicePropertiesMap[physicalDevice] =
248 unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
249 }
250 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600251 return result;
252}
253
254VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
255{
256 auto it = physicalDeviceMap.find(physicalDevice);
257 if (it != physicalDeviceMap.end()) {
258 if (NULL == pQueueFamilyProperties) {
259 it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
260 } else {
261 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
262 if (UNCALLED == it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
263 log_msg(mdd(physicalDevice), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
264 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
265 }
266 if (it->second->queueFamilyPropertiesCount != *pCount) {
267 log_msg(mdd(physicalDevice), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
268 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, it->second->queueFamilyPropertiesCount);
269 }
270 it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
271 }
272 // Then verify that pCount that is passed in on second call matches what was returned
273 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
274 if (NULL == pQueueFamilyProperties) {
275 it->second->queueFamilyPropertiesCount = *pCount;
276 } else { // Save queue family properties
277 for (uint32_t i=0; i < *pCount; i++) {
278 queueFamilyPropertiesMap[physicalDevice][i] = unique_ptr<VkQueueFamilyProperties>(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
279 }
280 }
281 return result;
282 } else {
283 log_msg(mdd(physicalDevice), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
284 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
285 }
286}
287
288VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
289{
290 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
291 return result;
292}
293
294VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
295{
296 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
297 return result;
298}
299
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600300VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
301 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600302 uint32_t viewportCount,
303 const VkViewport* pViewports)
304{
305 VkBool32 skipCall = VK_FALSE;
306 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
307 if (VK_FALSE == skipCall) {
308 get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
309 }
310}
311
312VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
313 VkCmdBuffer cmdBuffer,
314 uint32_t scissorCount,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600315 const VkRect2D* pScissors)
316{
317 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600318 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
319 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600320 if (VK_FALSE == skipCall) {
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600321 get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600322 }
323}
324
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600325static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
326{
327 uint32_t i;
328 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
329 deviceExtMap[pDisp].debug_marker_enabled = false;
330
331 for (i = 0; i < pCreateInfo->extensionCount; i++) {
332 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
333 /* Found a matching extension name, mark it enabled and init dispatch table*/
334 initDebugMarkerTable(device);
335 deviceExtMap[pDisp].debug_marker_enabled = true;
336 }
337
338 }
339}
340
341VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
342{
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600343 // First check is app has actually requested queueFamilyProperties
344 auto it = physicalDeviceMap.find(gpu);
345 if (it == physicalDeviceMap.end()) {
346 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
347 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
348 } else if (QUERY_DETAILS != it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
349 log_msg(mdd(gpu), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
350 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
351 } else {
352 // Check that the requested queue properties are valid
353 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
354 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
355 auto qfp_it = queueFamilyPropertiesMap[gpu].find(requestedIndex);
356 if (qfp_it == queueFamilyPropertiesMap[gpu].end()) { // requested index is out of bounds for this physical device
357 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
358 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
359 } else if (pCreateInfo->pRequestedQueues[i].queueCount > qfp_it->second->queueCount) {
360 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
361 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, qfp_it->second->queueCount, pCreateInfo->pRequestedQueues[i].queueCount);
362 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600363 }
364 }
365 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
366 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
367 if (result == VK_SUCCESS) {
368 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
369 VkLayerDispatchTable *pTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
370 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
371 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
372 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
373 deviceMap[*pDevice] = gpu;
374 }
375 return result;
376}
377
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600378VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600379{
380 // Free device lifetime allocations
381 dispatch_key key = get_dispatch_key(device);
382 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600383 pDisp->DestroyDevice(device);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600384 deviceExtMap.erase(pDisp);
385 device_limits_device_table_map.erase(key);
386 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600387}
388
389static const VkLayerProperties ds_global_layers[] = {
390 {
391 "DeviceLimits",
392 VK_API_VERSION,
393 VK_MAKE_VERSION(0, 1, 0),
394 "Validation layer: DeviceLimits",
395 }
396};
397
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600398VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600399 const char *pLayerName,
400 uint32_t *pCount,
401 VkExtensionProperties* pProperties)
402{
403 /* DeviceLimits does not have any global extensions */
404 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
405}
406
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600407VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600408 uint32_t *pCount,
409 VkLayerProperties* pProperties)
410{
411 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
412 ds_global_layers,
413 pCount, pProperties);
414}
415
416static const VkExtensionProperties ds_device_extensions[] = {
417 {
418 DEBUG_MARKER_EXTENSION_NAME,
419 VK_MAKE_VERSION(0, 1, 0),
420 }
421};
422
423static const VkLayerProperties ds_device_layers[] = {
424 {
425 "DeviceLimits",
426 VK_API_VERSION,
427 VK_MAKE_VERSION(0, 1, 0),
428 "Validation layer: DeviceLimits",
429 }
430};
431
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600432VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600433 VkPhysicalDevice physicalDevice,
434 const char* pLayerName,
435 uint32_t* pCount,
436 VkExtensionProperties* pProperties)
437{
438 /* Device Limits does not have any physical device extensions */
439 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
440 pCount, pProperties);
441}
442
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600443VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600444 VkPhysicalDevice physicalDevice,
445 uint32_t* pCount,
446 VkLayerProperties* pProperties)
447{
448 /* Device Limits' physical device layers are the same as global */
449 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
450 pCount, pProperties);
451}
452
453VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
454{
455 VkPhysicalDevice gpu = deviceMap[device];
456 auto qfp_it = queueFamilyPropertiesMap[gpu].find(queueFamilyIndex);
457 if (qfp_it == queueFamilyPropertiesMap[gpu].end()) { // requested index is out of bounds for this physical device
458 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
459 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
460 } else if (queueIndex >= qfp_it->second->queueCount) {
461 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
462 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, qfp_it->second->queueCount, queueIndex);
463 }
464 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
465 return result;
466}
467
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600468VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
469 VkDevice device,
470 const VkImageCreateInfo *pCreateInfo,
471 VkImage *pImage)
472{
473 VkBool32 skipCall = VK_FALSE;
474 VkResult result = VK_ERROR_VALIDATION_FAILED;
475 VkPhysicalDevice physicalDevice = deviceMap[device];
476 VkImageType type;
477 VkImageFormatProperties ImageFormatProperties = {0};
478
479 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
480 get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(
481 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
482 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
483
484 auto pdp_it = physicalDevicePropertiesMap.find(physicalDevice);
485 if (pdp_it == physicalDevicePropertiesMap.end()) {
486 skipCall = log_msg(mdd(device), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
487 DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
488 "CreateImage called before querying device properties ");
489 }
490 uint32_t imageGranularity = pdp_it->second->limits.bufferImageGranularity;
491 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
492
493 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
494 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
495 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
496 skipCall = log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
497 DEVLIMITS_LIMITS_VIOLATION, "DL",
498 "CreateImage extents exceed allowable limits for format: "
499 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
500 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
501 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
502 string_VkFormat(pCreateInfo->format));
503
504 }
505
506 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
507 (uint64_t)pCreateInfo->extent.height *
508 (uint64_t)pCreateInfo->extent.depth *
509 (uint64_t)pCreateInfo->arraySize *
510 (uint64_t)pCreateInfo->samples *
511 (uint64_t)vk_format_get_size(pCreateInfo->format) +
512 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
513
514 if (totalSize > ImageFormatProperties.maxResourceSize) {
515 skipCall = log_msg(mdd(device), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
516 DEVLIMITS_LIMITS_VIOLATION, "DL",
517 "CreateImage resource size exceeds allowable maximum "
518 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
519 totalSize, ImageFormatProperties.maxResourceSize);
520 }
521 if (VK_FALSE == skipCall) {
522 result = get_dispatch_table(device_limits_device_table_map, device)->CreateImage(device, pCreateInfo, pImage);
523 }
524 return result;
525}
526
527
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600528VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
529 VkInstance instance,
530 VkFlags msgFlags,
531 const PFN_vkDbgMsgCallback pfnMsgCallback,
532 void* pUserData,
533 VkDbgMsgCallback* pMsgCallback)
534{
535 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
536 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
537 if (VK_SUCCESS == res) {
538 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
539 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
540 }
541 return res;
542}
543
544VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
545 VkInstance instance,
546 VkDbgMsgCallback msgCallback)
547{
548 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
549 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
550 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
551 layer_destroy_msg_callback(my_data->report_data, msgCallback);
552 return res;
553}
554
555VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
556{
557 if (dev == NULL)
558 return NULL;
559
560 /* loader uses this to force layer initialization; device object is wrapped */
561 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
562 initDeviceTable(device_limits_device_table_map, (const VkBaseLayerObject *) dev);
563 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
564 }
565 if (!strcmp(funcName, "vkCreateDevice"))
566 return (PFN_vkVoidFunction) vkCreateDevice;
567 if (!strcmp(funcName, "vkDestroyDevice"))
568 return (PFN_vkVoidFunction) vkDestroyDevice;
569 /*if (!strcmp(funcName, "vkQueueSubmit"))
570 return (PFN_vkVoidFunction) vkQueueSubmit;*/
571 if (!strcmp(funcName, "vkGetDeviceQueue"))
572 return (PFN_vkVoidFunction) vkGetDeviceQueue;
573/* if (!strcmp(funcName, "vkDestroyFence"))
574 return (PFN_vkVoidFunction) vkDestroyFence;
575 if (!strcmp(funcName, "vkDestroySemaphore"))
576 return (PFN_vkVoidFunction) vkDestroySemaphore;
577 if (!strcmp(funcName, "vkDestroyEvent"))
578 return (PFN_vkVoidFunction) vkDestroyEvent;
579 if (!strcmp(funcName, "vkDestroyQueryPool"))
580 return (PFN_vkVoidFunction) vkDestroyQueryPool;
581 if (!strcmp(funcName, "vkDestroyBuffer"))
582 return (PFN_vkVoidFunction) vkDestroyBuffer;
583 if (!strcmp(funcName, "vkDestroyBufferView"))
584 return (PFN_vkVoidFunction) vkDestroyBufferView;
585 if (!strcmp(funcName, "vkDestroyImage"))
586 return (PFN_vkVoidFunction) vkDestroyImage;
587 if (!strcmp(funcName, "vkDestroyImageView"))
588 return (PFN_vkVoidFunction) vkDestroyImageView;
589 if (!strcmp(funcName, "vkDestroyShaderModule"))
590 return (PFN_vkVoidFunction) vkDestroyShaderModule;
591 if (!strcmp(funcName, "vkDestroyShader"))
592 return (PFN_vkVoidFunction) vkDestroyShader;
593 if (!strcmp(funcName, "vkDestroyPipeline"))
594 return (PFN_vkVoidFunction) vkDestroyPipeline;
595 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
596 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
597 if (!strcmp(funcName, "vkDestroySampler"))
598 return (PFN_vkVoidFunction) vkDestroySampler;
599 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
600 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
601 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
602 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600603 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
604 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
605 if (!strcmp(funcName, "vkDestroyFramebuffer"))
606 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
607 if (!strcmp(funcName, "vkDestroyRenderPass"))
608 return (PFN_vkVoidFunction) vkDestroyRenderPass;
609 if (!strcmp(funcName, "vkCreateBufferView"))
610 return (PFN_vkVoidFunction) vkCreateBufferView;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600611*/
612 if (!strcmp(funcName, "vkCreateImage"))
613 return (PFN_vkVoidFunction) vkCreateImage;
614/*
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600615 if (!strcmp(funcName, "vkCreateImageView"))
616 return (PFN_vkVoidFunction) vkCreateImageView;
617 if (!strcmp(funcName, "CreatePipelineCache"))
618 return (PFN_vkVoidFunction) vkCreatePipelineCache;
619 if (!strcmp(funcName, "DestroyPipelineCache"))
620 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
621 if (!strcmp(funcName, "GetPipelineCacheSize"))
622 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
623 if (!strcmp(funcName, "GetPipelineCacheData"))
624 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
625 if (!strcmp(funcName, "MergePipelineCaches"))
626 return (PFN_vkVoidFunction) vkMergePipelineCaches;
627 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
628 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
629 if (!strcmp(funcName, "vkCreateSampler"))
630 return (PFN_vkVoidFunction) vkCreateSampler;
631 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
632 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
633 if (!strcmp(funcName, "vkCreatePipelineLayout"))
634 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
635 if (!strcmp(funcName, "vkCreateDescriptorPool"))
636 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
637 if (!strcmp(funcName, "vkResetDescriptorPool"))
638 return (PFN_vkVoidFunction) vkResetDescriptorPool;
639 if (!strcmp(funcName, "vkAllocDescriptorSets"))
640 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
641 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
642 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600643 if (!strcmp(funcName, "vkCreateCommandBuffer"))
644 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
645 if (!strcmp(funcName, "vkBeginCommandBuffer"))
646 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
647 if (!strcmp(funcName, "vkEndCommandBuffer"))
648 return (PFN_vkVoidFunction) vkEndCommandBuffer;
649 if (!strcmp(funcName, "vkResetCommandBuffer"))
650 return (PFN_vkVoidFunction) vkResetCommandBuffer;
651 if (!strcmp(funcName, "vkCmdBindPipeline"))
652 return (PFN_vkVoidFunction) vkCmdBindPipeline;
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600653 if (!strcmp(funcName, "vkCmdSetViewport"))
654 return (PFN_vkVoidFunction) vkCmdSetViewport;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600655 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
656 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
657 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
658 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
659 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
660 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
661 if (!strcmp(funcName, "vkCmdDraw"))
662 return (PFN_vkVoidFunction) vkCmdDraw;
663 if (!strcmp(funcName, "vkCmdDrawIndexed"))
664 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
665 if (!strcmp(funcName, "vkCmdDrawIndirect"))
666 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
667 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
668 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
669 if (!strcmp(funcName, "vkCmdDispatch"))
670 return (PFN_vkVoidFunction) vkCmdDispatch;
671 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
672 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
673 if (!strcmp(funcName, "vkCmdCopyBuffer"))
674 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
675 if (!strcmp(funcName, "vkCmdCopyImage"))
676 return (PFN_vkVoidFunction) vkCmdCopyImage;
677 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
678 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
679 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
680 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
681 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
682 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
683 if (!strcmp(funcName, "vkCmdFillBuffer"))
684 return (PFN_vkVoidFunction) vkCmdFillBuffer;
685 if (!strcmp(funcName, "vkCmdClearColorImage"))
686 return (PFN_vkVoidFunction) vkCmdClearColorImage;
687 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
688 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
689 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
690 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
691 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
692 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
693 if (!strcmp(funcName, "vkCmdResolveImage"))
694 return (PFN_vkVoidFunction) vkCmdResolveImage;
695 if (!strcmp(funcName, "vkCmdSetEvent"))
696 return (PFN_vkVoidFunction) vkCmdSetEvent;
697 if (!strcmp(funcName, "vkCmdResetEvent"))
698 return (PFN_vkVoidFunction) vkCmdResetEvent;
699 if (!strcmp(funcName, "vkCmdWaitEvents"))
700 return (PFN_vkVoidFunction) vkCmdWaitEvents;
701 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
702 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
703 if (!strcmp(funcName, "vkCmdBeginQuery"))
704 return (PFN_vkVoidFunction) vkCmdBeginQuery;
705 if (!strcmp(funcName, "vkCmdEndQuery"))
706 return (PFN_vkVoidFunction) vkCmdEndQuery;
707 if (!strcmp(funcName, "vkCmdResetQueryPool"))
708 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
709 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
710 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
711 if (!strcmp(funcName, "vkCreateFramebuffer"))
712 return (PFN_vkVoidFunction) vkCreateFramebuffer;
713 if (!strcmp(funcName, "vkCreateRenderPass"))
714 return (PFN_vkVoidFunction) vkCreateRenderPass;
715 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
716 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
717 if (!strcmp(funcName, "vkCmdNextSubpass"))
718 return (PFN_vkVoidFunction) vkCmdNextSubpass;
719 if (!strcmp(funcName, "vkCmdEndRenderPass"))
720 return (PFN_vkVoidFunction) vkCmdEndRenderPass;*/
721
722 VkLayerDispatchTable* pTable = get_dispatch_table(device_limits_device_table_map, dev);
723 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
724 {
725// if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
726// return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
727// if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
728// return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
729// if (!strcmp(funcName, "vkDbgSetObjectTag"))
730// return (void*) vkDbgSetObjectTag;
731// if (!strcmp(funcName, "vkDbgSetObjectName"))
732// return (void*) vkDbgSetObjectName;
733 }
734 {
735 if (pTable->GetDeviceProcAddr == NULL)
736 return NULL;
737 return pTable->GetDeviceProcAddr(dev, funcName);
738 }
739}
740
741VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
742{
743 PFN_vkVoidFunction fptr;
744 if (instance == NULL)
745 return NULL;
746
747 /* loader uses this to force layer initialization; instance object is wrapped */
748 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
749 initInstanceTable(device_limits_instance_table_map, (const VkBaseLayerObject *) instance);
750 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
751 }
752 if (!strcmp(funcName, "vkCreateInstance"))
753 return (PFN_vkVoidFunction) vkCreateInstance;
754 if (!strcmp(funcName, "vkDestroyInstance"))
755 return (PFN_vkVoidFunction) vkDestroyInstance;
756 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
757 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
758 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
759 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
760 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
761 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
762 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
763 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
764 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
765 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
766 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
767 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
768 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
769 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600770 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
771 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
772 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
773 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600774 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
775 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600776 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
777 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
778 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
779 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600780
781 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
782 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
783 if (fptr)
784 return fptr;
785
786 {
787 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(device_limits_instance_table_map, instance);
788 if (pTable->GetInstanceProcAddr == NULL)
789 return NULL;
790 return pTable->GetInstanceProcAddr(instance, funcName);
791 }
792}