blob: 699abf4d528bd204b9debcd9f803aefcf312985e [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 Confidential Information as defined by the Khronos
17 * Membership Agreement until designated non-confidential by Khronos, at which
18 * point this condition clause shall be removed.
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060019 *
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070020 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060021 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070022 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 *
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
26 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
27 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060028 *
29 * Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070030 * Author: Mike Stroyan <mike@LunarG.com>
31 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060032 */
33
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <unordered_map>
38#include <memory>
39
40#include "vk_loader_platform.h"
41#include "vk_dispatch_table_helper.h"
42#include "vk_struct_string_helper_cpp.h"
43#if defined(__GNUC__)
44#pragma GCC diagnostic ignored "-Wwrite-strings"
45#endif
46#if defined(__GNUC__)
47#pragma GCC diagnostic warning "-Wwrite-strings"
48#endif
49#include "vk_struct_size_helper.h"
50#include "device_limits.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070051#include "vulkan/vk_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060052#include "vk_layer_config.h"
Michael Lentine03107b42015-12-11 10:49:51 -080053#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060054#include "vk_layer_table.h"
55#include "vk_layer_debug_marker_table.h"
56#include "vk_layer_data.h"
57#include "vk_layer_logging.h"
58#include "vk_layer_extension_utils.h"
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060059#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060060
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060061struct devExts {
62 bool debug_marker_enabled;
63};
Tobin Ehlis9da65002015-09-24 15:25:16 -060064
65// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060066struct layer_data {
Mark Lobodzinski941aea92016-01-13 10:23:15 -070067 debug_report_data *report_data;
68 std::vector<VkDebugReportCallbackEXT> logging_callback;
69 VkLayerDispatchTable *device_dispatch_table;
70 VkLayerInstanceDispatchTable *instance_dispatch_table;
71 devExts device_extensions;
Tobin Ehlis9da65002015-09-24 15:25:16 -060072 // Track state of each instance
Mark Lobodzinski941aea92016-01-13 10:23:15 -070073 unique_ptr<INSTANCE_STATE> instanceState;
74 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
75 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
76 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
77 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
78
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060079 // Track physical device per logical device
80 VkPhysicalDevice physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -060081 // Vector indices correspond to queueFamilyIndex
82 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060083
84 layer_data() :
85 report_data(nullptr),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060086 device_dispatch_table(nullptr),
87 instance_dispatch_table(nullptr),
88 device_extensions(),
Tobin Ehlis9da65002015-09-24 15:25:16 -060089 instanceState(nullptr),
90 physicalDeviceState(nullptr),
Tobin Ehlis9da65002015-09-24 15:25:16 -060091 actualPhysicalDeviceFeatures(),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060092 requestedPhysicalDeviceFeatures(),
93 physicalDevice()
Cody Northrop55443ef2015-09-28 15:09:32 -060094 {};
95};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060096
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060097static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060098
99static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
100
101// TODO : This can be much smarter, using separate locks for separate global data
102static int globalLockInitialized = 0;
103static loader_platform_thread_mutex globalLock;
104
105template layer_data *get_my_data_ptr<layer_data>(
106 void *data_key,
107 std::unordered_map<void *, layer_data *> &data_map);
108
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700109static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600110{
111 uint32_t report_flags = 0;
112 uint32_t debug_action = 0;
113 FILE *log_output = NULL;
114 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700115 VkDebugReportCallbackEXT callback;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600116 // initialize DeviceLimits options
117 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
118 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
119
120 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
121 {
122 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -0600123 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700124 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700125 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700126 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700127 dbgCreateInfo.flags = report_flags;
128 dbgCreateInfo.pfnCallback = log_callback;
129 dbgCreateInfo.pUserData = (void *) log_output;
130 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600131 my_data->logging_callback.push_back(callback);
132 }
133
134 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700135 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700136 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700137 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700138 dbgCreateInfo.flags = report_flags;
139 dbgCreateInfo.pfnCallback = win32_debug_output_msg;
140 dbgCreateInfo.pUserData = NULL;
141 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600142 my_data->logging_callback.push_back(callback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600143 }
144
145 if (!globalLockInitialized)
146 {
147 // TODO/TBD: Need to delete this mutex sometime. How??? One
148 // suggestion is to call this during vkCreateInstance(), and then we
149 // can clean it up during vkDestroyInstance(). However, that requires
150 // that the layer have per-instance locks. We need to come back and
151 // address this soon.
152 loader_platform_thread_create_mutex(&globalLock);
153 globalLockInitialized = 1;
154 }
155}
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700156
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -0700157static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700158 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700159 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -0700160 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700161 }
162};
163
Chia-I Wu9ab61502015-11-06 06:42:02 +0800164VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600165 const char *pLayerName,
166 uint32_t *pCount,
167 VkExtensionProperties* pProperties)
168{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -0700169 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600170}
171
172static const VkLayerProperties dl_global_layers[] = {
173 {
Michael Lentine03107b42015-12-11 10:49:51 -0800174 "VK_LAYER_LUNARG_device_limits",
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600175 VK_API_VERSION,
176 VK_MAKE_VERSION(0, 1, 0),
177 "Validation layer: Device Limits",
178 }
179};
180
Chia-I Wu9ab61502015-11-06 06:42:02 +0800181VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600182 uint32_t *pCount,
183 VkLayerProperties* pProperties)
184{
185 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
186 dl_global_layers,
187 pCount, pProperties);
188}
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600189
Chia-I Wu9ab61502015-11-06 06:42:02 +0800190VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600191{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700192 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600193
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700194 assert(chain_info->u.pLayerInfo);
195 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
196 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
197 if (fpCreateInstance == NULL) {
198 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600199 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700200
201 // Advance the link info for the next element on the chain
202 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
203
204 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
205 if (result != VK_SUCCESS)
206 return result;
207
208 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
209 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
210 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
211
212 my_data->report_data = debug_report_create_instance(
213 my_data->instance_dispatch_table,
214 *pInstance,
215 pCreateInfo->enabledExtensionCount,
216 pCreateInfo->ppEnabledExtensionNames);
217
218 init_device_limits(my_data, pAllocator);
219 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
220
221 return VK_SUCCESS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600222}
223
224/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +0800225VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600226{
227 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600228 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
229 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800230 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600231
232 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600233 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700234 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700235 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600236 my_data->logging_callback.pop_back();
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600237 }
238
239 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600240 delete my_data->instance_dispatch_table;
241 layer_data_map.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -0600242 if (layer_data_map.empty()) {
243 // Release mutex when destroying last instance.
244 loader_platform_thread_delete_mutex(&globalLock);
245 globalLockInitialized = 0;
246 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600247}
248
Chia-I Wu9ab61502015-11-06 06:42:02 +0800249VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600250{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600251 VkBool32 skipCall = VK_FALSE;
252 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
253 if (my_data->instanceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600254 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
255 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600256 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600257 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600258 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600259 // Flag error here, shouldn't be calling this without having queried count
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700260 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600261 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
262 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis9da65002015-09-24 15:25:16 -0600263 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700264 // TODO: Having actual count match count from app is not a requirement, so this can be a warning
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700265 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
Tobin Ehlis9da65002015-09-24 15:25:16 -0600266 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600267 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600268 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600269 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600270 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700271 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600272 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600273 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600274 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600275 } else { // Save physical devices
276 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600277 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
278 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
279 // Init actual features for each physical device
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600280 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600281 }
282 }
283 return result;
284 } else {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700285 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__, DEVLIMITS_INVALID_INSTANCE, "DL",
Michael Lentine010f4692015-11-03 16:19:46 -0800286 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", (uint64_t)instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600287 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700288 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600289}
290
Chia-I Wu9ab61502015-11-06 06:42:02 +0800291VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600292{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600293 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
294 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600295 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600296}
297
Chia-I Wu9ab61502015-11-06 06:42:02 +0800298VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600299{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600300 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
301 physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600302}
303
Chia-I Wu9ab61502015-11-06 06:42:02 +0800304VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600305{
Chia-I Wu17241042015-10-31 00:31:16 +0800306 return get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600307}
308
Chia-I Wu9ab61502015-11-06 06:42:02 +0800309VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600310{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600311 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600312 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600313}
314
Chia-I Wu9ab61502015-11-06 06:42:02 +0800315VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600316{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600317 VkBool32 skipCall = VK_FALSE;
318 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
319 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600320 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600321 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600322 } else {
323 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
Tobin Ehlis9da65002015-09-24 15:25:16 -0600324 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700325 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600326 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
327 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600328 // Then verify that pCount that is passed in on second call matches what was returned
329 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700330
331 // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so provide as warning
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700332 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
Tobin Ehlis9da65002015-09-24 15:25:16 -0600333 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600334 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600335 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600336 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600337 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600338 return;
339 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600340 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600341 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600342 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600343 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600344 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600345 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600346 }
347 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600348 return;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600349 } else {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700350 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
Michael Lentine010f4692015-11-03 16:19:46 -0800351 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", (uint64_t)physicalDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600352 }
353}
354
Chia-I Wu9ab61502015-11-06 06:42:02 +0800355VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600356{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600357 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600358}
359
Chia-I Wu9ab61502015-11-06 06:42:02 +0800360VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600361{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600362 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600363}
364
Chia-I Wu9ab61502015-11-06 06:42:02 +0800365VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800366 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700367 uint32_t firstViewport,
368 uint32_t viewportCount,
369 const VkViewport* pViewports)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600370{
371 VkBool32 skipCall = VK_FALSE;
372 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
373 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800374 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700375 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600376 }
377}
378
Chia-I Wu9ab61502015-11-06 06:42:02 +0800379VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800380 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700381 uint32_t firstScissor,
382 uint32_t scissorCount,
383 const VkRect2D* pScissors)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600384{
385 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600386 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
387 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600388 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800389 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700390 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600391 }
392}
393
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600394static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
395{
396 uint32_t i;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600397 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
398 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600399
Jon Ashburnf19916e2016-01-11 13:12:43 -0700400 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600401 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
402 /* Found a matching extension name, mark it enabled and init dispatch table*/
403 initDebugMarkerTable(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600404 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600405 }
406
407 }
408}
409
Tobin Ehlis9da65002015-09-24 15:25:16 -0600410// Verify that features have been queried and verify that requested features are available
411static VkBool32 validate_features_request(layer_data *phy_dev_data)
412{
413 VkBool32 skipCall = VK_FALSE;
414 // Verify that all of the requested features are available
415 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
416 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
417 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
418 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
419 // Need to provide the struct member name with the issue. To do that seems like we'll
420 // have to loop through each struct member which should be done w/ codegen to keep in synch.
421 uint32_t errors = 0;
422 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
423 for (uint32_t i = 0; i < totalBools; i++) {
424 if (requested[i] > actual[i]) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700425 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
Tobin Ehlis9da65002015-09-24 15:25:16 -0600426 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
427 errors++;
428 }
429 }
430 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
431 // If user didn't request features, notify them that they should
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700432 // TODO: Verify this against the spec. I believe this is an invalid use of the API and should return an error
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700433 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
Tobin Ehlis9da65002015-09-24 15:25:16 -0600434 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
435 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600436 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600437}
438
Chia-I Wu9ab61502015-11-06 06:42:02 +0800439VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600440{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600441 VkBool32 skipCall = VK_FALSE;
442 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600443 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600444 if (!phy_dev_data->physicalDeviceState) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700445 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600446 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600447 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700448 // TODO: This is not called out as an invalid use in the spec so make more informative recommendation.
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700449 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARN_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700450 "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600451 } else {
452 // Check that the requested queue properties are valid
Chia-I Wu02124482015-11-06 06:42:02 +0800453 for (uint32_t i=0; i<pCreateInfo->queueCreateInfoCount; i++) {
454 uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600455 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700456 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600457 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Chia-I Wu02124482015-11-06 06:42:02 +0800458 } else if (pCreateInfo->pQueueCreateInfos[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700459 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Chia-I Wu02124482015-11-06 06:42:02 +0800460 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, pCreateInfo->pQueueCreateInfos[i].queueCount);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600461 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600462 }
463 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600464 // Check that any requested features are available
465 if (pCreateInfo->pEnabledFeatures) {
466 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
467 skipCall |= validate_features_request(phy_dev_data);
468 }
469 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700470 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600471
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700472 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700473
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700474 assert(chain_info->u.pLayerInfo);
475 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
476 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
477 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
478 if (fpCreateDevice == NULL) {
479 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600480 }
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700481
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700482 // Advance the link info for the next element on the chain
483 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
484
485 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
486 if (result != VK_SUCCESS) {
487 return result;
488 }
489
490 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
491 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
492 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
493 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
494 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
495 my_device_data->physicalDevice = gpu;
496 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
497
498 // Get physical device properties for this device
499 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(phy_dev_data->physDevPropertyMap[*pDevice]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600500 return result;
501}
502
Chia-I Wu9ab61502015-11-06 06:42:02 +0800503VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600504{
505 // Free device lifetime allocations
506 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600507 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800508 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600509 tableDebugMarkerMap.erase(key);
510 delete my_device_data->device_dispatch_table;
511 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600512}
513
Chia-I Wu9ab61502015-11-06 06:42:02 +0800514VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600515{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600516 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800517 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600518 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600519}
520
Chia-I Wu9ab61502015-11-06 06:42:02 +0800521VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600522{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800523 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600524}
525
Chia-I Wu9ab61502015-11-06 06:42:02 +0800526VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600527{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800528 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600529 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600530}
531
Chia-I Wu9ab61502015-11-06 06:42:02 +0800532VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600533{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800534 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600535 return result;
536}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600537
Chia-I Wu9ab61502015-11-06 06:42:02 +0800538VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer* pCommandBuffers)
Tobin Ehlis9da65002015-09-24 15:25:16 -0600539{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800540 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600541}
542
Chia-I Wu9ab61502015-11-06 06:42:02 +0800543VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600544{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600545 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600546 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
547 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600548 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
549 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700550 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600551 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600552 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700553 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis9da65002015-09-24 15:25:16 -0600554 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600555 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600556 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600557 return;
558 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600559}
560
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700561VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(
562 VkDevice device,
563 VkBuffer buffer,
564 VkDeviceMemory mem,
565 VkDeviceSize memoryOffset)
566{
567 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
568 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
569 VkBool32 skipCall = VK_FALSE;
570
571 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
572 if (vk_safe_modulo(memoryOffset, uniformAlignment) != 0) {
573 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
574 __LINE__, DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
575 "vkBindBufferMemory(): memoryOffset %#" PRIxLEAST64 " must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
576 memoryOffset, uniformAlignment);
577 }
578
579 if (VK_FALSE == skipCall) {
580 result = dev_data->device_dispatch_table->BindBufferMemory(device, buffer, mem, memoryOffset);
581 }
582 return result;
583}
584
585VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(
586 VkDevice device,
587 uint32_t descriptorWriteCount,
588 const VkWriteDescriptorSet *pDescriptorWrites,
589 uint32_t descriptorCopyCount,
590 const VkCopyDescriptorSet *pDescriptorCopies)
591{
592 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
593 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
594 VkBool32 skipCall = VK_FALSE;
595
Mark Youngee3f3a22016-01-25 12:18:32 -0700596 for (uint32_t i = 0; i < descriptorWriteCount; i++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700597 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
598 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
599 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
Mark Youngee3f3a22016-01-25 12:18:32 -0700600 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700601 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
602 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
603 __LINE__, DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
604 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 ") must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
605 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
606 }
607 }
608 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
609 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
610 VkDeviceSize storageAlignment = dev_data->physDevPropertyMap[device].limits.minStorageBufferOffsetAlignment;
Mark Youngee3f3a22016-01-25 12:18:32 -0700611 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700612 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
613 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
614 __LINE__, DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL",
615 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 ") must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
616 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
617 }
618 }
619 }
620 }
621 if (skipCall == VK_FALSE) {
622 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
623 }
624}
625
Chia-I Wu9ab61502015-11-06 06:42:02 +0800626VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800627 VkCommandBuffer commandBuffer,
628 VkBuffer dstBuffer,
629 VkDeviceSize dstOffset,
Mike Stroyana3082432015-09-25 13:39:21 -0600630 VkDeviceSize dataSize,
631 const uint32_t* pData)
632{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800633 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600634
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800635 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
636 if (dstOffset & 3) {
637 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700638 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800639 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600640 return;
641 }
642 }
643
644 // dataSize is the number of bytes to update, which must be a multiple of 4.
645 if (dataSize & 3) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800646 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700647 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Mike Stroyana3082432015-09-25 13:39:21 -0600648 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
649 return;
650 }
651 }
652
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800653 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyana3082432015-09-25 13:39:21 -0600654}
655
Chia-I Wu9ab61502015-11-06 06:42:02 +0800656VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800657 VkCommandBuffer commandBuffer,
658 VkBuffer dstBuffer,
659 VkDeviceSize dstOffset,
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800660 VkDeviceSize size,
Mike Stroyana3082432015-09-25 13:39:21 -0600661 uint32_t data)
662{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800663 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600664
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800665 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
666 if (dstOffset & 3) {
667 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700668 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800669 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600670 return;
671 }
672 }
673
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800674 // size is the number of bytes to fill, which must be a multiple of 4.
675 if (size & 3) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800676 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700677 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, "DL",
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800678 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600679 return;
680 }
681 }
682
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800683 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyana3082432015-09-25 13:39:21 -0600684}
685
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700686VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
687 VkInstance instance,
688 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
689 const VkAllocationCallbacks* pAllocator,
690 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600691{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600692 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700693 VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600694 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700695 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600696 }
697 return res;
698}
699
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700700VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700701 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700702 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700703 const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600704{
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600705 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700706 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700707 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600708}
709
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700710VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700711 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700712 VkDebugReportFlagsEXT flags,
713 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700714 uint64_t object,
715 size_t location,
716 int32_t msgCode,
717 const char* pLayerPrefix,
718 const char* pMsg)
719{
720 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700721 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700722}
723
Chia-I Wu9ab61502015-11-06 06:42:02 +0800724VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600725{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700726 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600727 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600728 if (!strcmp(funcName, "vkDestroyDevice"))
729 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600730 if (!strcmp(funcName, "vkGetDeviceQueue"))
731 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600732 if (!strcmp(funcName, "CreateCommandPool"))
733 return (PFN_vkVoidFunction) vkCreateCommandPool;
734 if (!strcmp(funcName, "DestroyCommandPool"))
735 return (PFN_vkVoidFunction) vkDestroyCommandPool;
736 if (!strcmp(funcName, "ResetCommandPool"))
737 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800738 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
739 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600740 if (!strcmp(funcName, "vkFreeCommandBuffers"))
741 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyana3082432015-09-25 13:39:21 -0600742 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
743 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700744 if (!strcmp(funcName, "vkBindBufferMemory"))
745 return (PFN_vkVoidFunction) vkBindBufferMemory;
746 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
747 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mike Stroyana3082432015-09-25 13:39:21 -0600748 if (!strcmp(funcName, "vkCmdFillBuffer"))
749 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600750
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700751 if (dev == NULL)
752 return NULL;
753
754 layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600755 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600756 {
757 if (pTable->GetDeviceProcAddr == NULL)
758 return NULL;
759 return pTable->GetDeviceProcAddr(dev, funcName);
760 }
761}
762
Chia-I Wu9ab61502015-11-06 06:42:02 +0800763VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600764{
765 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"))
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600769 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700770 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
771 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600772 if (!strcmp(funcName, "vkCreateInstance"))
773 return (PFN_vkVoidFunction) vkCreateInstance;
774 if (!strcmp(funcName, "vkDestroyInstance"))
775 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700776 if (!strcmp(funcName, "vkCreateDevice"))
777 return (PFN_vkVoidFunction) vkCreateDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600778 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
779 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
780 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
781 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
782 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
783 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
784 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
785 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
786 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
787 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
788 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
789 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
790 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
791 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600792 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
793 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600794 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
795 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
796 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
797 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600798
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700799 if (!instance) return NULL;
800
801 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
802
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600803 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
804 if (fptr)
805 return fptr;
806
807 {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600808 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600809 if (pTable->GetInstanceProcAddr == NULL)
810 return NULL;
811 return pTable->GetInstanceProcAddr(instance, funcName);
812 }
813}