blob: 6edb77de7fe3b33fe32d7b37087998c44157b95f [file] [log] [blame]
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06001/*
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06002 *
Courtney Goeltzenleuchterfcbe16f2015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Michael Lentine03107b42015-12-11 10:49:51 -08004 * Copyright (C) 2015 Google Inc.
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060023 *
24 * Author: Mark Lobodzinski <mark@lunarg.com>
25 * Author: Mike Stroyan <mike@LunarG.com>
26 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060027 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
32#include <unordered_map>
33#include <memory>
34
35#include "vk_loader_platform.h"
36#include "vk_dispatch_table_helper.h"
37#include "vk_struct_string_helper_cpp.h"
38#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 Lentine03107b42015-12-11 10:49:51 -080048#include "vulkan/vk_debug_marker_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060049#include "vk_layer_table.h"
50#include "vk_layer_debug_marker_table.h"
51#include "vk_layer_data.h"
52#include "vk_layer_logging.h"
53#include "vk_layer_extension_utils.h"
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060054#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060055
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060056struct devExts {
57 bool debug_marker_enabled;
58};
Tobin Ehlis9da65002015-09-24 15:25:16 -060059
60// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060061struct layer_data {
Mark Lobodzinski941aea92016-01-13 10:23:15 -070062 debug_report_data *report_data;
63 std::vector<VkDebugReportCallbackEXT> logging_callback;
64 VkLayerDispatchTable *device_dispatch_table;
65 VkLayerInstanceDispatchTable *instance_dispatch_table;
66 devExts device_extensions;
Tobin Ehlis9da65002015-09-24 15:25:16 -060067 // Track state of each instance
Mark Lobodzinski941aea92016-01-13 10:23:15 -070068 unique_ptr<INSTANCE_STATE> instanceState;
69 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
70 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
71 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
72 unordered_map<VkDevice, VkPhysicalDeviceProperties> physDevPropertyMap;
73
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060074 // Track physical device per logical device
75 VkPhysicalDevice physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -060076 // Vector indices correspond to queueFamilyIndex
77 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060078
79 layer_data() :
80 report_data(nullptr),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060081 device_dispatch_table(nullptr),
82 instance_dispatch_table(nullptr),
83 device_extensions(),
Tobin Ehlis9da65002015-09-24 15:25:16 -060084 instanceState(nullptr),
85 physicalDeviceState(nullptr),
Tobin Ehlis9da65002015-09-24 15:25:16 -060086 actualPhysicalDeviceFeatures(),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060087 requestedPhysicalDeviceFeatures(),
88 physicalDevice()
Cody Northrop55443ef2015-09-28 15:09:32 -060089 {};
90};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060091
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060092static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060093
94static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
95
96// TODO : This can be much smarter, using separate locks for separate global data
97static int globalLockInitialized = 0;
98static loader_platform_thread_mutex globalLock;
99
100template layer_data *get_my_data_ptr<layer_data>(
101 void *data_key,
102 std::unordered_map<void *, layer_data *> &data_map);
103
Courtney Goeltzenleuchter6d8e8182015-11-25 14:31:49 -0700104static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600105{
106 uint32_t report_flags = 0;
107 uint32_t debug_action = 0;
108 FILE *log_output = NULL;
109 const char *option_str;
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700110 VkDebugReportCallbackEXT callback;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600111 // initialize DeviceLimits options
112 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
113 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
114
115 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
116 {
117 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -0600118 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700119 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700120 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700121 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700122 dbgCreateInfo.flags = report_flags;
123 dbgCreateInfo.pfnCallback = log_callback;
124 dbgCreateInfo.pUserData = (void *) log_output;
125 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600126 my_data->logging_callback.push_back(callback);
127 }
128
129 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700130 VkDebugReportCallbackCreateInfoEXT dbgCreateInfo;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700131 memset(&dbgCreateInfo, 0, sizeof(dbgCreateInfo));
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700132 dbgCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700133 dbgCreateInfo.flags = report_flags;
134 dbgCreateInfo.pfnCallback = win32_debug_output_msg;
135 dbgCreateInfo.pUserData = NULL;
136 layer_create_msg_callback(my_data->report_data, &dbgCreateInfo, pAllocator, &callback);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600137 my_data->logging_callback.push_back(callback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600138 }
139
140 if (!globalLockInitialized)
141 {
142 // TODO/TBD: Need to delete this mutex sometime. How??? One
143 // suggestion is to call this during vkCreateInstance(), and then we
144 // can clean it up during vkDestroyInstance(). However, that requires
145 // that the layer have per-instance locks. We need to come back and
146 // address this soon.
147 loader_platform_thread_create_mutex(&globalLock);
148 globalLockInitialized = 1;
149 }
150}
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700151
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -0700152static const VkExtensionProperties instance_extensions[] = {
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700153 {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700154 VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
Courtney Goeltzenleuchterb69cd592016-01-19 16:08:39 -0700155 VK_EXT_DEBUG_REPORT_SPEC_VERSION
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -0700156 }
157};
158
Chia-I Wu9ab61502015-11-06 06:42:02 +0800159VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600160 const char *pLayerName,
161 uint32_t *pCount,
162 VkExtensionProperties* pProperties)
163{
Courtney Goeltzenleuchter52857662015-12-01 14:08:28 -0700164 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600165}
166
167static const VkLayerProperties dl_global_layers[] = {
168 {
Michael Lentine03107b42015-12-11 10:49:51 -0800169 "VK_LAYER_LUNARG_device_limits",
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600170 VK_API_VERSION,
171 VK_MAKE_VERSION(0, 1, 0),
172 "Validation layer: Device Limits",
173 }
174};
175
Chia-I Wu9ab61502015-11-06 06:42:02 +0800176VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600177 uint32_t *pCount,
178 VkLayerProperties* pProperties)
179{
180 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
181 dl_global_layers,
182 pCount, pProperties);
183}
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600184
Chia-I Wu9ab61502015-11-06 06:42:02 +0800185VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600186{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700187 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600188
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700189 assert(chain_info->u.pLayerInfo);
190 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
191 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance) fpGetInstanceProcAddr(NULL, "vkCreateInstance");
192 if (fpCreateInstance == NULL) {
193 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600194 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700195
196 // Advance the link info for the next element on the chain
197 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
198
199 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
200 if (result != VK_SUCCESS)
201 return result;
202
203 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
204 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
205 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
206
207 my_data->report_data = debug_report_create_instance(
208 my_data->instance_dispatch_table,
209 *pInstance,
210 pCreateInfo->enabledExtensionCount,
211 pCreateInfo->ppEnabledExtensionNames);
212
213 init_device_limits(my_data, pAllocator);
214 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
215
216 return VK_SUCCESS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600217}
218
219/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu9ab61502015-11-06 06:42:02 +0800220VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600221{
222 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600223 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
224 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800225 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600226
227 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600228 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700229 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700230 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600231 my_data->logging_callback.pop_back();
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600232 }
233
234 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600235 delete my_data->instance_dispatch_table;
236 layer_data_map.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -0600237 if (layer_data_map.empty()) {
238 // Release mutex when destroying last instance.
239 loader_platform_thread_delete_mutex(&globalLock);
240 globalLockInitialized = 0;
241 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600242}
243
Chia-I Wu9ab61502015-11-06 06:42:02 +0800244VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600245{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600246 VkBool32 skipCall = VK_FALSE;
247 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
248 if (my_data->instanceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600249 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
250 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600251 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600252 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600253 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600254 // Flag error here, shouldn't be calling this without having queried count
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700255 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 -0600256 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
257 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis9da65002015-09-24 15:25:16 -0600258 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700259 // 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 -0700260 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 -0600261 "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 -0600262 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600263 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600264 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600265 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700266 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600267 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600268 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600269 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600270 } else { // Save physical devices
271 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600272 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
273 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
274 // Init actual features for each physical device
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600275 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600276 }
277 }
278 return result;
279 } else {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700280 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 -0800281 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", (uint64_t)instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600282 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700283 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600284}
285
Chia-I Wu9ab61502015-11-06 06:42:02 +0800286VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600287{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600288 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
289 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600290 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600291}
292
Chia-I Wu9ab61502015-11-06 06:42:02 +0800293VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600294{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600295 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
296 physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600297}
298
Chia-I Wu9ab61502015-11-06 06:42:02 +0800299VK_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 -0600300{
Chia-I Wu17241042015-10-31 00:31:16 +0800301 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 -0600302}
303
Chia-I Wu9ab61502015-11-06 06:42:02 +0800304VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600305{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600306 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600307 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600308}
309
Chia-I Wu9ab61502015-11-06 06:42:02 +0800310VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600311{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600312 VkBool32 skipCall = VK_FALSE;
313 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
314 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600315 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600316 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600317 } else {
318 // 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 -0600319 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700320 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 -0600321 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
322 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600323 // Then verify that pCount that is passed in on second call matches what was returned
324 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700325
326 // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so provide as warning
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700327 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 -0600328 "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 -0600329 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600330 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600331 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600332 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600333 return;
334 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600335 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600336 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600337 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600338 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600339 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600340 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600341 }
342 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600343 return;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600344 } else {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700345 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 -0800346 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", (uint64_t)physicalDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600347 }
348}
349
Chia-I Wu9ab61502015-11-06 06:42:02 +0800350VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600351{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600352 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600353}
354
Chia-I Wu9ab61502015-11-06 06:42:02 +0800355VK_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 -0600356{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600357 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 -0600358}
359
Chia-I Wu9ab61502015-11-06 06:42:02 +0800360VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800361 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700362 uint32_t firstViewport,
363 uint32_t viewportCount,
364 const VkViewport* pViewports)
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600365{
366 VkBool32 skipCall = VK_FALSE;
367 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
368 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800369 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700370 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600371 }
372}
373
Chia-I Wu9ab61502015-11-06 06:42:02 +0800374VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800375 VkCommandBuffer commandBuffer,
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700376 uint32_t firstScissor,
377 uint32_t scissorCount,
378 const VkRect2D* pScissors)
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600379{
380 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600381 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
382 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600383 if (VK_FALSE == skipCall) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800384 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Jon Ashburn19d3bf12015-12-30 14:06:55 -0700385 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600386 }
387}
388
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600389static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
390{
391 uint32_t i;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600392 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
393 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600394
Jon Ashburnf19916e2016-01-11 13:12:43 -0700395 for (i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600396 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
397 /* Found a matching extension name, mark it enabled and init dispatch table*/
398 initDebugMarkerTable(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600399 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600400 }
401
402 }
403}
404
Tobin Ehlis9da65002015-09-24 15:25:16 -0600405// Verify that features have been queried and verify that requested features are available
406static VkBool32 validate_features_request(layer_data *phy_dev_data)
407{
408 VkBool32 skipCall = VK_FALSE;
409 // Verify that all of the requested features are available
410 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
411 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
412 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
413 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
414 // Need to provide the struct member name with the issue. To do that seems like we'll
415 // have to loop through each struct member which should be done w/ codegen to keep in synch.
416 uint32_t errors = 0;
417 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
418 for (uint32_t i = 0; i < totalBools; i++) {
419 if (requested[i] > actual[i]) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700420 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 -0600421 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
422 errors++;
423 }
424 }
425 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
426 // If user didn't request features, notify them that they should
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700427 // 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 -0700428 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 -0600429 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
430 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600431 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600432}
433
Chia-I Wu9ab61502015-11-06 06:42:02 +0800434VK_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 -0600435{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600436 VkBool32 skipCall = VK_FALSE;
437 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600438 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600439 if (!phy_dev_data->physicalDeviceState) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700440 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 -0600441 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600442 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700443 // 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 -0700444 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 -0700445 "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600446 } else {
447 // Check that the requested queue properties are valid
Chia-I Wu02124482015-11-06 06:42:02 +0800448 for (uint32_t i=0; i<pCreateInfo->queueCreateInfoCount; i++) {
449 uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600450 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700451 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 -0600452 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Chia-I Wu02124482015-11-06 06:42:02 +0800453 } else if (pCreateInfo->pQueueCreateInfos[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700454 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 +0800455 "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 -0600456 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600457 }
458 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600459 // Check that any requested features are available
460 if (pCreateInfo->pEnabledFeatures) {
461 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
462 skipCall |= validate_features_request(phy_dev_data);
463 }
464 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700465 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600466
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700467 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700468
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700469 assert(chain_info->u.pLayerInfo);
470 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
471 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
472 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice) fpGetInstanceProcAddr(NULL, "vkCreateDevice");
473 if (fpCreateDevice == NULL) {
474 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600475 }
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700476
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700477 // Advance the link info for the next element on the chain
478 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
479
480 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
481 if (result != VK_SUCCESS) {
482 return result;
483 }
484
485 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
486 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
487 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
488 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
489 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
490 my_device_data->physicalDevice = gpu;
491 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
492
493 // Get physical device properties for this device
494 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(phy_dev_data->physDevPropertyMap[*pDevice]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600495 return result;
496}
497
Chia-I Wu9ab61502015-11-06 06:42:02 +0800498VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600499{
500 // Free device lifetime allocations
501 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600502 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800503 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600504 tableDebugMarkerMap.erase(key);
505 delete my_device_data->device_dispatch_table;
506 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600507}
508
Chia-I Wu9ab61502015-11-06 06:42:02 +0800509VK_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 -0600510{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600511 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800512 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 -0600513 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600514}
515
Chia-I Wu9ab61502015-11-06 06:42:02 +0800516VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600517{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800518 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 -0600519}
520
Chia-I Wu9ab61502015-11-06 06:42:02 +0800521VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600522{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800523 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 -0600524 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600525}
526
Chia-I Wu9ab61502015-11-06 06:42:02 +0800527VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600528{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800529 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 -0600530 return result;
531}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600532
Chia-I Wu9ab61502015-11-06 06:42:02 +0800533VK_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 -0600534{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800535 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 -0600536}
537
Chia-I Wu9ab61502015-11-06 06:42:02 +0800538VK_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 -0600539{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600540 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600541 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
542 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600543 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
544 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700545 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 -0600546 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600547 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700548 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 -0600549 "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 -0600550 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600551 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600552 return;
553 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600554}
555
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700556VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkBindBufferMemory(
557 VkDevice device,
558 VkBuffer buffer,
559 VkDeviceMemory mem,
560 VkDeviceSize memoryOffset)
561{
562 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
563 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
564 VkBool32 skipCall = VK_FALSE;
565
566 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
567 if (vk_safe_modulo(memoryOffset, uniformAlignment) != 0) {
568 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
569 __LINE__, DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
570 "vkBindBufferMemory(): memoryOffset %#" PRIxLEAST64 " must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
571 memoryOffset, uniformAlignment);
572 }
573
574 if (VK_FALSE == skipCall) {
575 result = dev_data->device_dispatch_table->BindBufferMemory(device, buffer, mem, memoryOffset);
576 }
577 return result;
578}
579
580VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkUpdateDescriptorSets(
581 VkDevice device,
582 uint32_t descriptorWriteCount,
583 const VkWriteDescriptorSet *pDescriptorWrites,
584 uint32_t descriptorCopyCount,
585 const VkCopyDescriptorSet *pDescriptorCopies)
586{
587 layer_data* dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
588 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
589 VkBool32 skipCall = VK_FALSE;
590
Mark Youngee3f3a22016-01-25 12:18:32 -0700591 for (uint32_t i = 0; i < descriptorWriteCount; i++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700592 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
593 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
594 VkDeviceSize uniformAlignment = dev_data->physDevPropertyMap[device].limits.minUniformBufferOffsetAlignment;
Mark Youngee3f3a22016-01-25 12:18:32 -0700595 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700596 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
597 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
598 __LINE__, DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
599 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 ") must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
600 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
601 }
602 }
603 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
604 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
605 VkDeviceSize storageAlignment = dev_data->physDevPropertyMap[device].limits.minStorageBufferOffsetAlignment;
Mark Youngee3f3a22016-01-25 12:18:32 -0700606 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700607 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
608 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
609 __LINE__, DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL",
610 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64 ") must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
611 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
612 }
613 }
614 }
615 }
616 if (skipCall == VK_FALSE) {
617 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount, pDescriptorCopies);
618 }
619}
620
Chia-I Wu9ab61502015-11-06 06:42:02 +0800621VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800622 VkCommandBuffer commandBuffer,
623 VkBuffer dstBuffer,
624 VkDeviceSize dstOffset,
Mike Stroyana3082432015-09-25 13:39:21 -0600625 VkDeviceSize dataSize,
626 const uint32_t* pData)
627{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800628 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600629
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800630 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
631 if (dstOffset & 3) {
632 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700633 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 +0800634 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600635 return;
636 }
637 }
638
639 // dataSize is the number of bytes to update, which must be a multiple of 4.
640 if (dataSize & 3) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800641 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700642 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 -0600643 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
644 return;
645 }
646 }
647
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800648 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyana3082432015-09-25 13:39:21 -0600649}
650
Chia-I Wu9ab61502015-11-06 06:42:02 +0800651VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800652 VkCommandBuffer commandBuffer,
653 VkBuffer dstBuffer,
654 VkDeviceSize dstOffset,
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800655 VkDeviceSize size,
Mike Stroyana3082432015-09-25 13:39:21 -0600656 uint32_t data)
657{
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800658 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyana3082432015-09-25 13:39:21 -0600659
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800660 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
661 if (dstOffset & 3) {
662 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700663 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 +0800664 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600665 return;
666 }
667 }
668
Chia-I Wu2bfb33c2015-10-26 17:24:52 +0800669 // size is the number of bytes to fill, which must be a multiple of 4.
670 if (size & 3) {
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800671 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mark Lobodzinskib66216b2016-01-04 13:18:50 -0700672 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 +0800673 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyana3082432015-09-25 13:39:21 -0600674 return;
675 }
676 }
677
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800678 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyana3082432015-09-25 13:39:21 -0600679}
680
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700681VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(
682 VkInstance instance,
683 const VkDebugReportCallbackCreateInfoEXT* pCreateInfo,
684 const VkAllocationCallbacks* pAllocator,
685 VkDebugReportCallbackEXT* pMsgCallback)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600686{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600687 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700688 VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600689 if (VK_SUCCESS == res) {
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700690 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600691 }
692 return res;
693}
694
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700695VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700696 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700697 VkDebugReportCallbackEXT msgCallback,
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700698 const VkAllocationCallbacks* pAllocator)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600699{
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600700 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700701 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700702 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600703}
704
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700705VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDebugReportMessageEXT(
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700706 VkInstance instance,
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700707 VkDebugReportFlagsEXT flags,
708 VkDebugReportObjectTypeEXT objType,
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700709 uint64_t object,
710 size_t location,
711 int32_t msgCode,
712 const char* pLayerPrefix,
713 const char* pMsg)
714{
715 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700716 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700717}
718
Chia-I Wu9ab61502015-11-06 06:42:02 +0800719VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600720{
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700721 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600722 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600723 if (!strcmp(funcName, "vkDestroyDevice"))
724 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600725 if (!strcmp(funcName, "vkGetDeviceQueue"))
726 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600727 if (!strcmp(funcName, "CreateCommandPool"))
728 return (PFN_vkVoidFunction) vkCreateCommandPool;
729 if (!strcmp(funcName, "DestroyCommandPool"))
730 return (PFN_vkVoidFunction) vkDestroyCommandPool;
731 if (!strcmp(funcName, "ResetCommandPool"))
732 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800733 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
734 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600735 if (!strcmp(funcName, "vkFreeCommandBuffers"))
736 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyana3082432015-09-25 13:39:21 -0600737 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
738 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700739 if (!strcmp(funcName, "vkBindBufferMemory"))
740 return (PFN_vkVoidFunction) vkBindBufferMemory;
741 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
742 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
Mike Stroyana3082432015-09-25 13:39:21 -0600743 if (!strcmp(funcName, "vkCmdFillBuffer"))
744 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600745
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700746 if (dev == NULL)
747 return NULL;
748
749 layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600750 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600751 {
752 if (pTable->GetDeviceProcAddr == NULL)
753 return NULL;
754 return pTable->GetDeviceProcAddr(dev, funcName);
755 }
756}
757
Chia-I Wu9ab61502015-11-06 06:42:02 +0800758VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600759{
760 PFN_vkVoidFunction fptr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600761
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600762 layer_data *my_data;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700763 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600764 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700765 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
766 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600767 if (!strcmp(funcName, "vkCreateInstance"))
768 return (PFN_vkVoidFunction) vkCreateInstance;
769 if (!strcmp(funcName, "vkDestroyInstance"))
770 return (PFN_vkVoidFunction) vkDestroyInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700771 if (!strcmp(funcName, "vkCreateDevice"))
772 return (PFN_vkVoidFunction) vkCreateDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600773 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
774 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
775 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
776 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
777 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
778 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
779 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
780 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
781 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
782 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
783 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
784 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
785 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
786 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600787 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
788 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600789 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
790 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
791 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
792 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600793
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700794 if (!instance) return NULL;
795
796 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
797
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600798 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
799 if (fptr)
800 return fptr;
801
802 {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600803 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600804 if (pTable->GetInstanceProcAddr == NULL)
805 return NULL;
806 return pTable->GetInstanceProcAddr(instance, funcName);
807 }
808}