blob: 75422bc5e434d3ae91384d0d330b1de928ed3042 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06005 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and/or associated documentation files (the "Materials"), to
8 * deal in the Materials without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Materials, and to permit persons to whom the Materials
11 * are furnished to do so, subject to the following conditions:
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060012 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070013 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060015 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070016 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060024 *
25 * Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070026 * Author: Mike Stroyan <mike@LunarG.com>
27 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060028 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unordered_map>
34#include <memory>
35
36#include "vk_loader_platform.h"
37#include "vk_dispatch_table_helper.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060038#if defined(__GNUC__)
39#pragma GCC diagnostic ignored "-Wwrite-strings"
40#endif
41#if defined(__GNUC__)
42#pragma GCC diagnostic warning "-Wwrite-strings"
43#endif
44#include "vk_struct_size_helper.h"
45#include "device_limits.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070046#include "vulkan/vk_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060047#include "vk_layer_config.h"
Michael Lentine5d8ad0a2016-01-28 15:03:46 -060048#include "vk_enum_validate_helper.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060049#include "vk_layer_table.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060050#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
Tobin Ehlis9da65002015-09-24 15:25:16 -060055// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060056struct layer_data {
Jon Ashburn5484e0c2016-03-08 17:48:44 -070057 debug_report_data *report_data;
58 std::vector<VkDebugReportCallbackEXT> logging_callback;
59 VkLayerDispatchTable *device_dispatch_table;
60 VkLayerInstanceDispatchTable *instance_dispatch_table;
Tobin Ehlis9da65002015-09-24 15:25:16 -060061 // Track state of each instance
Jon Ashburn5484e0c2016-03-08 17:48:44 -070062 unique_ptr<INSTANCE_STATE> instanceState;
63 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
64 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
65 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Mark Lobodzinski941aea92016-01-13 10:23:15 -070066 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
67
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060068 // Track physical device per logical device
69 VkPhysicalDevice physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -060070 // Vector indices correspond to queueFamilyIndex
71 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060072
Jon Ashburn5484e0c2016-03-08 17:48:44 -070073 layer_data()
74 : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), instanceState(nullptr),
75 physicalDeviceState(nullptr), actualPhysicalDeviceFeatures(), requestedPhysicalDeviceFeatures(), physicalDevice(){};
Cody Northrop55443ef2015-09-28 15:09:32 -060076};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060077
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060078static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060079
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070080// TODO : This can be much smarter, using separate locks for separate global data
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060081static int globalLockInitialized = 0;
82static loader_platform_thread_mutex globalLock;
83
Jon Ashburn5484e0c2016-03-08 17:48:44 -070084template layer_data *get_my_data_ptr<layer_data>(void *data_key, std::unordered_map<void *, layer_data *> &data_map);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060085
Jon Ashburn5484e0c2016-03-08 17:48:44 -070086static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060087 uint32_t report_flags = 0;
88 uint32_t debug_action = 0;
89 FILE *log_output = NULL;
90 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070091 VkDebugReportCallbackEXT callback;
Mark Lobodzinski8cbde242016-02-23 09:58:39 -070092 // initialize device_limits options
93 report_flags = getLayerOptionFlags("lunarg_device_limits.report_flags", 0);
Jon Ashburn5484e0c2016-03-08 17:48:44 -070094 getLayerOptionEnum("lunarg_device_limits.debug_action", (uint32_t *)&debug_action);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060095
Jon Ashburn5484e0c2016-03-08 17:48:44 -070096 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG) {
Mark Lobodzinski8cbde242016-02-23 09:58:39 -070097 option_str = getLayerOption("lunarg_device_limits.log_filename");
98 log_output = getLayerLogOutput(option_str, "lunarg_device_limits");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070099 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700100 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700101 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700102 dbgCreateInfo.flags = report_flags;
103 dbgCreateInfo.pfnCallback = log_callback;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700104 dbgCreateInfo.pUserData = (void *)log_output;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700105 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600106 my_data->logging_callback.push_back(callback);
107 }
108
109 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700110 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700111 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700112 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700113 dbgCreateInfo.flags = report_flags;
114 dbgCreateInfo.pfnCallback = win32_debug_output_msg;
115 dbgCreateInfo.pUserData = NULL;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700116 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600117 my_data->logging_callback.push_back(callback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600118 }
119
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700120 if (!globalLockInitialized) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600121 // TODO/TBD: Need to delete this mutex sometime. How??? One
122 // suggestion is to call this during vkCreateInstance(), and then we
123 // can clean it up during vkDestroyInstance(). However, that requires
124 // that the layer have per-instance locks. We need to come back and
125 // address this soon.
126 loader_platform_thread_create_mutex(&globalLock);
127 globalLockInitialized = 1;
128 }
129}
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700130
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700131static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700132
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700133VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
134vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700135 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600136}
137
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700138VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
139 const char *pLayerName, uint32_t *pCount,
140 VkExtensionProperties *pProperties) {
Courtney Goeltzenleuchterbeb42f82016-02-12 13:46:04 -0700141 if (pLayerName == NULL) {
142 dispatch_key key = get_dispatch_key(physicalDevice);
143 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700144 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
Courtney Goeltzenleuchterbeb42f82016-02-12 13:46:04 -0700145 } else {
146 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
147 }
148}
149
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700150static const VkLayerProperties dl_global_layers[] = {{
151 "VK_LAYER_LUNARG_device_limits", VK_API_VERSION, 1, "LunarG Validation Layer",
152}};
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600153
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700154VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
155vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
156 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), dl_global_layers, pCount, pProperties);
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600157}
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600158
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700159VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
160vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) {
161 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), dl_global_layers, pCount, pProperties);
Courtney Goeltzenleuchterbeb42f82016-02-12 13:46:04 -0700162}
163
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700164VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
165vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700166 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600167
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700168 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700169 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700170 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700171 if (fpCreateInstance == NULL) {
172 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600173 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700174
175 // Advance the link info for the next element on the chain
176 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
177
178 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
179 if (result != VK_SUCCESS)
180 return result;
181
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700182 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700183 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700184 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700185
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700186 my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance,
187 pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700188
189 init_device_limits(my_data, pAllocator);
190 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
191
192 return VK_SUCCESS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600193}
194
195/* hook DestroyInstance to remove tableInstanceMap entry */
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700196VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600197 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600198 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
199 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800200 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600201
202 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600203 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700204 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700205 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600206 my_data->logging_callback.pop_back();
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600207 }
208
209 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600210 delete my_data->instance_dispatch_table;
211 layer_data_map.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -0600212 if (layer_data_map.empty()) {
213 // Release mutex when destroying last instance.
214 loader_platform_thread_delete_mutex(&globalLock);
215 globalLockInitialized = 0;
216 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600217}
218
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700219VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
220vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600221 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700222 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600223 if (my_data->instanceState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700224 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600225 if (NULL == pPhysicalDevices) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700226 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600227 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700228 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
229 // Flag error here, shouldn't be calling this without having queried count
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700230 skipCall |=
231 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0,
232 __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
233 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first "
234 "call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700235 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
236 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
237 // TODO: Having actual count match count from app is not a requirement, so this can be a warning
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700238 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
239 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
240 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count "
241 "supported by this instance is %u.",
242 *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600243 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700244 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600245 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600246 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700247 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700248 VkResult result =
249 my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600250 if (NULL == pPhysicalDevices) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700251 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600252 } else { // Save physical devices
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700253 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700254 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
255 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
Tobin Ehlis9da65002015-09-24 15:25:16 -0600256 // Init actual features for each physical device
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700257 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i],
258 &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600259 }
260 }
261 return result;
262 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700263 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__,
264 DEVLIMITS_INVALID_INSTANCE, "DL", "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().",
265 (uint64_t)instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600266 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700267 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600268}
269
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700270VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
271vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700272 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
273 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
274 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600275}
276
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700277VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
278vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties) {
279 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
280 ->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600281}
282
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700283VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
284vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling,
285 VkImageUsageFlags usage, VkImageCreateFlags flags,
286 VkImageFormatProperties *pImageFormatProperties) {
287 return get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
288 ->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags,
289 pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600290}
291
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700292VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
293vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700294 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
295 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600296}
297
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700298VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
299vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
300 VkQueueFamilyProperties *pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600301 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700302 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600303 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600304 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700305 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600306 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700307 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to
308 // get count
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700309 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700310 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
311 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
312 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL "
313 "pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ "
314 "NULL pQueueFamilyProperties to query pCount.");
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600315 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700316 // Then verify that pCount that is passed in on second call matches what was returned
317 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700318
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700319 // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so
320 // provide as warning
321 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
322 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
323 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count "
324 "supported by this physicalDevice is %u.",
325 *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600326 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700327 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600328 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600329 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600330 return;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700331 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount,
332 pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600333 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700334 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600335 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600336 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700337 for (uint32_t i = 0; i < *pCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700338 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600339 }
340 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600341 return;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600342 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700343 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
344 __LINE__, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
345 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().",
346 (uint64_t)physicalDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600347 }
348}
349
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700350VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
351vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties *pMemoryProperties) {
352 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
353 ->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600354}
355
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700356VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
357vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
358 VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling,
359 uint32_t *pNumProperties, VkSparseImageFormatProperties *pProperties) {
360 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
361 ->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage,
362 tiling, pNumProperties, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600363}
364
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700365VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
366vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports) {
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600367 VkBool32 skipCall = VK_FALSE;
368 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
369 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700370 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
371 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600372 }
373}
374
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700375VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
376vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600377 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600378 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
379 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600380 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700381 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
382 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600383 }
384}
385
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700386// Verify that features have been queried and verify that requested features are available
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700387static VkBool32 validate_features_request(layer_data *phy_dev_data) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600388 VkBool32 skipCall = VK_FALSE;
389 // Verify that all of the requested features are available
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700390 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700391 VkBool32 *actual = (VkBool32 *)&(phy_dev_data->actualPhysicalDeviceFeatures);
392 VkBool32 *requested = (VkBool32 *)&(phy_dev_data->requestedPhysicalDeviceFeatures);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700393 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
394 // Need to provide the struct member name with the issue. To do that seems like we'll
395 // have to loop through each struct member which should be done w/ codegen to keep in synch.
Tobin Ehlis9da65002015-09-24 15:25:16 -0600396 uint32_t errors = 0;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700397 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600398 for (uint32_t i = 0; i < totalBools; i++) {
399 if (requested[i] > actual[i]) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700400 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
401 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED,
402 "DL", "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, "
403 "which is not available on this device.",
404 i);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600405 errors++;
406 }
407 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700408 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600409 // If user didn't request features, notify them that they should
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700410 // TODO: Verify this against the spec. I believe this is an invalid use of the API and should return an error
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700411 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
412 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
413 "You requested features that are unavailable on this device. You should first query feature "
414 "availability by calling vkGetPhysicalDeviceFeatures().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600415 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600416 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600417}
418
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700419VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
420 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600421 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700422 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600423 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600424 if (!phy_dev_data->physicalDeviceState) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700425 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
426 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
427 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700428 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
429 // TODO: This is not called out as an invalid use in the spec so make more informative recommendation.
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700430 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
431 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
432 "DL", "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600433 } else {
434 // Check that the requested queue properties are valid
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700435 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700436 uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700437 if (phy_dev_data->queueFamilyProperties.size() <=
438 requestedIndex) { // requested index is out of bounds for this physical device
439 skipCall |= log_msg(
440 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
441 __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700442 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700443 } else if (pCreateInfo->pQueueCreateInfos[i].queueCount >
444 phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
445 skipCall |=
446 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
447 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
448 "DL", "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but "
449 "requested queueCount is %u.",
450 requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount,
451 pCreateInfo->pQueueCreateInfos[i].queueCount);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600452 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600453 }
454 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600455 // Check that any requested features are available
456 if (pCreateInfo->pEnabledFeatures) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700457 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600458 skipCall |= validate_features_request(phy_dev_data);
459 }
460 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700461 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600462
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700463 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700464
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700465 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700466 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
467 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700468 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700469 if (fpCreateDevice == NULL) {
470 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600471 }
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700472
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700473 // Advance the link info for the next element on the chain
474 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
475
476 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
477 if (result != VK_SUCCESS) {
478 return result;
479 }
480
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700481 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
482 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700483 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700484 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
485 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700486 my_device_data->physicalDevice = gpu;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700487
488 // Get physical device properties for this device
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700489 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(phy_dev_data->physDevPropertyMap[*pDevice]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600490 return result;
491}
492
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700493VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600494 // Free device lifetime allocations
495 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600496 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800497 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600498 delete my_device_data->device_dispatch_table;
499 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600500}
501
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700502VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
503 const VkAllocationCallbacks *pAllocator,
504 VkCommandPool *pCommandPool) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600505 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700506 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
507 ->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600508 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600509}
510
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700511VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
512vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
513 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
514 ->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600515}
516
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700517VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
518vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) {
519 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
520 ->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600521 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600522}
523
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700524VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
525vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, VkCommandBuffer *pCommandBuffer) {
526 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
527 ->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600528 return result;
529}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600530
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700531VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
532vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers) {
533 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
534 ->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600535}
536
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700537VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
538vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
Michael Lentine09853ef2016-01-28 14:20:46 -0600539 bool skipCall = false;
540 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
541 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
542 if (dev_data->actualPhysicalDeviceFeatures.inheritedQueries == VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700543 skipCall |= log_msg(
544 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
545 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
546 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support inheritedQueries.");
Michael Lentine09853ef2016-01-28 14:20:46 -0600547 }
Michael Lentine5d8ad0a2016-01-28 15:03:46 -0600548 if (dev_data->actualPhysicalDeviceFeatures.inheritedQueries != VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE &&
549 !validate_VkQueryControlFlagBits(VkQueryControlFlagBits(pInfo->queryFlags))) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700550 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
551 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
552 "Cannot enable in occlusion queries in vkBeginCommandBuffer() and set queryFlags to %d which is not a "
553 "valid combination of VkQueryControlFlagBits.",
Michael Lentine5d8ad0a2016-01-28 15:03:46 -0600554 pInfo->queryFlags);
555 }
Michael Lentine0a369f62016-02-03 16:51:46 -0600556 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine09853ef2016-01-28 14:20:46 -0600557 if (!skipCall)
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700558 result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Michael Lentine0a369f62016-02-03 16:51:46 -0600559 return result;
Michael Lentine09853ef2016-01-28 14:20:46 -0600560}
561
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700562VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
563vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600564 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700565 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600566 VkPhysicalDevice gpu = dev_data->physicalDevice;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700567 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700568 if (queueFamilyIndex >=
569 phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
570 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
571 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
572 "DL", "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700573 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700574 skipCall |= log_msg(
575 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
576 DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
577 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.",
578 queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600579 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600580 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600581 return;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700582 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600583}
584
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700585VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
586vkBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700587 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700588 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
589 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700590
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700591 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700592 if (vk_safe_modulo(memoryOffset, uniformAlignment) != 0) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700593 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT,
594 0, __LINE__, DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
595 "vkBindBufferMemory(): memoryOffset %#" PRIxLEAST64
596 " must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
597 memoryOffset, uniformAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700598 }
599
600 if (VK_FALSE == skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700601 result = dev_data->device_dispatch_table->BindBufferMemory(device, buffer, mem, memoryOffset);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700602 }
603 return result;
604}
605
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700606VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
607vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
608 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
609 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
610 VkBool32 skipCall = VK_FALSE;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700611
Mark Youngee3f3a22016-01-25 12:18:32 -0700612 for (uint32_t i = 0; i < descriptorWriteCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700613 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
614 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700615 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
616 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
617 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700618 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
619 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
620 DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
621 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64
622 ") must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
623 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700624 }
625 }
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700626 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
627 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700628 VkDeviceSize storageAlignment = dev_data->physDevPropertyMap[device].limits.minStorageBufferOffsetAlignment;
629 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
630 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700631 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
632 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
633 DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL",
634 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64
635 ") must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
636 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700637 }
638 }
639 }
640 }
641 if (skipCall == VK_FALSE) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700642 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
643 pDescriptorCopies);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700644 }
645}
646
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700647VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
648 VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700649 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600650
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700651 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800652 if (dstOffset & 3) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700653 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
654 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700655 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600656 return;
657 }
658 }
659
660 // dataSize is the number of bytes to update, which must be a multiple of 4.
661 if (dataSize & 3) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700662 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
663 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700664 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600665 return;
666 }
667 }
668
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700669 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyana3082432015-09-25 13:39:21 -0600670}
671
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700672VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
673vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700674 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600675
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700676 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800677 if (dstOffset & 3) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700678 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
679 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700680 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600681 return;
682 }
683 }
684
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800685 // size is the number of bytes to fill, which must be a multiple of 4.
686 if (size & 3) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700687 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
688 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700689 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600690 return;
691 }
692 }
693
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700694 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyana3082432015-09-25 13:39:21 -0600695}
696
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700697VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
698vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
699 const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700700 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
701 VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600702 if (VK_SUCCESS == res) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700703 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600704 }
705 return res;
706}
707
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700708VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance,
709 VkDebugReportCallbackEXT msgCallback,
710 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700711 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
712 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700713 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600714}
715
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700716VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
717vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object,
718 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700719 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700720 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix,
721 pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700722}
723
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700724VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700725 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700726 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600727 if (!strcmp(funcName, "vkDestroyDevice"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700728 return (PFN_vkVoidFunction)vkDestroyDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600729 if (!strcmp(funcName, "vkGetDeviceQueue"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700730 return (PFN_vkVoidFunction)vkGetDeviceQueue;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600731 if (!strcmp(funcName, "CreateCommandPool"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700732 return (PFN_vkVoidFunction)vkCreateCommandPool;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600733 if (!strcmp(funcName, "DestroyCommandPool"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700734 return (PFN_vkVoidFunction)vkDestroyCommandPool;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600735 if (!strcmp(funcName, "ResetCommandPool"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700736 return (PFN_vkVoidFunction)vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800737 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700738 return (PFN_vkVoidFunction)vkAllocateCommandBuffers;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600739 if (!strcmp(funcName, "vkFreeCommandBuffers"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700740 return (PFN_vkVoidFunction)vkFreeCommandBuffers;
Michael Lentine09853ef2016-01-28 14:20:46 -0600741 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700742 return (PFN_vkVoidFunction)vkBeginCommandBuffer;
Mike Stroyana3082432015-09-25 13:39:21 -0600743 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700744 return (PFN_vkVoidFunction)vkCmdUpdateBuffer;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700745 if (!strcmp(funcName, "vkBindBufferMemory"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700746 return (PFN_vkVoidFunction)vkBindBufferMemory;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700747 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700748 return (PFN_vkVoidFunction)vkUpdateDescriptorSets;
Mike Stroyana3082432015-09-25 13:39:21 -0600749 if (!strcmp(funcName, "vkCmdFillBuffer"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700750 return (PFN_vkVoidFunction)vkCmdFillBuffer;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600751
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700752 if (dev == NULL)
753 return NULL;
754
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700755 layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700756 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600757 {
758 if (pTable->GetDeviceProcAddr == NULL)
759 return NULL;
760 return pTable->GetDeviceProcAddr(dev, funcName);
761 }
762}
763
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700764VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600765 PFN_vkVoidFunction fptr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600766
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600767 layer_data *my_data;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700768 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700769 return (PFN_vkVoidFunction)vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700770 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700771 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600772 if (!strcmp(funcName, "vkCreateInstance"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700773 return (PFN_vkVoidFunction)vkCreateInstance;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600774 if (!strcmp(funcName, "vkDestroyInstance"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700775 return (PFN_vkVoidFunction)vkDestroyInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700776 if (!strcmp(funcName, "vkCreateDevice"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700777 return (PFN_vkVoidFunction)vkCreateDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600778 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700779 return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600780 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700781 return (PFN_vkVoidFunction)vkGetPhysicalDeviceFeatures;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600782 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700783 return (PFN_vkVoidFunction)vkGetPhysicalDeviceFormatProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600784 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700785 return (PFN_vkVoidFunction)vkGetPhysicalDeviceImageFormatProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600786 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700787 return (PFN_vkVoidFunction)vkGetPhysicalDeviceProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600788 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700789 return (PFN_vkVoidFunction)vkGetPhysicalDeviceQueueFamilyProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600790 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700791 return (PFN_vkVoidFunction)vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600792 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700793 return (PFN_vkVoidFunction)vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600794 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700795 return (PFN_vkVoidFunction)vkEnumerateInstanceLayerProperties;
Courtney Goeltzenleuchterbeb42f82016-02-12 13:46:04 -0700796 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
797 return (PFN_vkVoidFunction)vkEnumerateDeviceLayerProperties;
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600798 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700799 return (PFN_vkVoidFunction)vkEnumerateInstanceExtensionProperties;
Courtney Goeltzenleuchterbeb42f82016-02-12 13:46:04 -0700800 if (!strcmp(funcName, "vkEnumerateInstanceDeviceProperties"))
801 return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600802
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700803 if (!instance)
804 return NULL;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700805
806 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
807
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600808 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
809 if (fptr)
810 return fptr;
811
812 {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700813 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600814 if (pTable->GetInstanceProcAddr == NULL)
815 return NULL;
816 return pTable->GetInstanceProcAddr(instance, funcName);
817 }
818}