blob: a3ba1f1395584a4d7645d3aa15d8aaea59679c95 [file] [log] [blame]
Mark Lobodzinski288e4f72016-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 Ehlisc345b8b2015-09-03 09:50:06 -06005 *
Mark Lobodzinski288e4f72016-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 Ehlisc345b8b2015-09-03 09:50:06 -060012 *
Mark Lobodzinski288e4f72016-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 Ehlisc345b8b2015-09-03 09:50:06 -060015 *
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070016 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060017 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 *
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23 * USE OR OTHER DEALINGS IN THE MATERIALS
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060024 *
25 * Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinski288e4f72016-02-02 15:55:36 -070026 * Author: Mike Stroyan <mike@LunarG.com>
27 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060028 */
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unordered_map>
34#include <memory>
35
36#include "vk_loader_platform.h"
37#include "vk_dispatch_table_helper.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060038#if defined(__GNUC__)
39#pragma GCC diagnostic ignored "-Wwrite-strings"
40#endif
41#if defined(__GNUC__)
42#pragma GCC diagnostic warning "-Wwrite-strings"
43#endif
44#include "vk_struct_size_helper.h"
45#include "device_limits.h"
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -070046#include "vulkan/vk_layer.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060047#include "vk_layer_config.h"
Michael Lentineea209c02016-01-28 15:03:46 -060048#include "vk_enum_validate_helper.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060049#include "vk_layer_table.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060050#include "vk_layer_data.h"
51#include "vk_layer_logging.h"
52#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060053#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060054
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060055// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060056struct layer_data {
Jon Ashburn491a3cd2016-03-08 17:48:44 -070057 debug_report_data *report_data;
58 std::vector<VkDebugReportCallbackEXT> logging_callback;
59 VkLayerDispatchTable *device_dispatch_table;
60 VkLayerInstanceDispatchTable *instance_dispatch_table;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060061 // Track state of each instance
Jon Ashburn491a3cd2016-03-08 17:48:44 -070062 unique_ptr<INSTANCE_STATE> instanceState;
63 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
64 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
65 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Mark Lobodzinski0fe21732016-01-13 10:23:15 -070066
Tobin Ehlis84492ee2015-10-06 09:09:24 -060067 // Track physical device per logical device
68 VkPhysicalDevice physicalDevice;
Dustin Graves2c905c82016-03-31 18:01:37 -060069 VkPhysicalDeviceProperties physicalDeviceProperties;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060070 // Vector indices correspond to queueFamilyIndex
71 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060072
Jon Ashburn491a3cd2016-03-08 17:48:44 -070073 layer_data()
74 : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), instanceState(nullptr),
75 physicalDeviceState(nullptr), actualPhysicalDeviceFeatures(), requestedPhysicalDeviceFeatures(), physicalDevice(){};
Cody Northrop73bb6572015-09-28 15:09:32 -060076};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060077
Tobin Ehlis84492ee2015-10-06 09:09:24 -060078static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060079
Mark Lobodzinskib838dc02016-02-03 09:57:14 -070080// TODO : This can be much smarter, using separate locks for separate global data
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060081static int globalLockInitialized = 0;
82static loader_platform_thread_mutex globalLock;
83
Jon Ashburn491a3cd2016-03-08 17:48:44 -070084template layer_data *get_my_data_ptr<layer_data>(void *data_key, std::unordered_map<void *, layer_data *> &data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060085
Jon Ashburn491a3cd2016-03-08 17:48:44 -070086static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060087
Mark Lobodzinskid11c4ee2016-03-15 14:21:59 -060088 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_device_limits");
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060089
Jon Ashburn491a3cd2016-03-08 17:48:44 -070090 if (!globalLockInitialized) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060091 // TODO/TBD: Need to delete this mutex sometime. How??? One
92 // suggestion is to call this during vkCreateInstance(), and then we
93 // can clean it up during vkDestroyInstance(). However, that requires
94 // that the layer have per-instance locks. We need to come back and
95 // address this soon.
96 loader_platform_thread_create_mutex(&globalLock);
97 globalLockInitialized = 1;
98 }
99}
Courtney Goeltzenleuchter03384052015-11-30 12:14:06 -0700100
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700101static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
Courtney Goeltzenleuchter03384052015-11-30 12:14:06 -0700102
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700103VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
104vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700105 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600106}
107
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700108VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
109 const char *pLayerName, uint32_t *pCount,
110 VkExtensionProperties *pProperties) {
Courtney Goeltzenleuchterbadf4cf2016-02-12 13:46:04 -0700111 if (pLayerName == NULL) {
112 dispatch_key key = get_dispatch_key(physicalDevice);
113 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700114 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, NULL, pCount, pProperties);
Courtney Goeltzenleuchterbadf4cf2016-02-12 13:46:04 -0700115 } else {
116 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
117 }
118}
119
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700120static const VkLayerProperties dl_global_layers[] = {{
Jon Ashburnf1ea4182016-03-22 12:57:13 -0600121 "VK_LAYER_LUNARG_device_limits", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer",
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700122}};
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600123
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700124VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
125vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
126 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), dl_global_layers, pCount, pProperties);
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600127}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600128
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700129VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
130vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) {
131 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers), dl_global_layers, pCount, pProperties);
Courtney Goeltzenleuchterbadf4cf2016-02-12 13:46:04 -0700132}
133
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700134VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
135vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700136 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600137
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700138 assert(chain_info->u.pLayerInfo);
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700139 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700140 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700141 if (fpCreateInstance == NULL) {
142 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600143 }
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700144
145 // Advance the link info for the next element on the chain
146 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
147
148 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
149 if (result != VK_SUCCESS)
150 return result;
151
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700152 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700153 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700154 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700155
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700156 my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance,
157 pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700158
159 init_device_limits(my_data, pAllocator);
160 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
161
162 return VK_SUCCESS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600163}
164
165/* hook DestroyInstance to remove tableInstanceMap entry */
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700166VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600167 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600168 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
169 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +0800170 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600171
172 // Clean up logging callback, if any
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600173 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700174 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -0700175 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600176 my_data->logging_callback.pop_back();
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600177 }
178
179 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600180 delete my_data->instance_dispatch_table;
181 layer_data_map.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600182 if (layer_data_map.empty()) {
183 // Release mutex when destroying last instance.
184 loader_platform_thread_delete_mutex(&globalLock);
185 globalLockInitialized = 0;
186 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600187}
188
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700189VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
190vkEnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600191 bool skipCall = false;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700192 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600193 if (my_data->instanceState) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700194 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600195 if (NULL == pPhysicalDevices) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700196 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600197 } else {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700198 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
199 // Flag error here, shouldn't be calling this without having queried count
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700200 skipCall |=
201 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0,
202 __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
203 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first "
204 "call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700205 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
206 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
207 // TODO: Having actual count match count from app is not a requirement, so this can be a warning
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700208 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
209 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
210 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count "
211 "supported by this instance is %u.",
212 *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600213 }
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700214 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600215 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600216 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -0700217 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700218 VkResult result =
219 my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600220 if (NULL == pPhysicalDevices) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700221 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600222 } else { // Save physical devices
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700223 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700224 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
225 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600226 // Init actual features for each physical device
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700227 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i],
228 &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600229 }
230 }
231 return result;
232 } else {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700233 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__,
234 DEVLIMITS_INVALID_INSTANCE, "DL", "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().",
235 (uint64_t)instance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600236 }
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -0700237 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600238}
239
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700240VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
241vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700242 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
243 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
244 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600245}
246
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700247VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
248vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties) {
249 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
250 ->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600251}
252
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700253VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
254vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling,
255 VkImageUsageFlags usage, VkImageCreateFlags flags,
256 VkImageFormatProperties *pImageFormatProperties) {
257 return get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
258 ->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags,
259 pImageFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600260}
261
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700262VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
263vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700264 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
265 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600266}
267
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700268VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
269vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
270 VkQueueFamilyProperties *pQueueFamilyProperties) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600271 bool skipCall = false;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700272 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600273 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600274 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700275 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600276 } else {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700277 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to
278 // get count
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700279 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700280 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
281 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
282 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL "
283 "pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ "
284 "NULL pQueueFamilyProperties to query pCount.");
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600285 }
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700286 // Then verify that pCount that is passed in on second call matches what was returned
287 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
Courtney Goeltzenleuchteracb13592015-12-09 15:48:16 -0700288
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700289 // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so
290 // provide as warning
291 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
292 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
293 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count "
294 "supported by this physicalDevice is %u.",
295 *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600296 }
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700297 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600298 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600299 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600300 return;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700301 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount,
302 pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600303 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700304 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600305 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600306 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700307 for (uint32_t i = 0; i < *pCount; i++) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700308 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600309 }
310 }
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600311 return;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600312 } else {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700313 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
314 __LINE__, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
315 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().",
316 (uint64_t)physicalDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600317 }
318}
319
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700320VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
321vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties *pMemoryProperties) {
322 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
323 ->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600324}
325
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700326VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
327vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
328 VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling,
329 uint32_t *pNumProperties, VkSparseImageFormatProperties *pProperties) {
330 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
331 ->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage,
332 tiling, pNumProperties, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600333}
334
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700335VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
336vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600337 bool skipCall = false;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600338 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
Dustin Gravesbb849942016-04-05 13:48:15 -0600339 if (!skipCall) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700340 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
341 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600342 }
343}
344
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700345VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
346vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600347 bool skipCall = false;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600348 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
349 /* TODO: viewportCount and scissorCount must match at draw time */
Dustin Gravesbb849942016-04-05 13:48:15 -0600350 if (!skipCall) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700351 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
352 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600353 }
354}
355
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700356// Verify that features have been queried and verify that requested features are available
Dustin Gravesbb849942016-04-05 13:48:15 -0600357static bool validate_features_request(layer_data *phy_dev_data) {
358 bool skipCall = false;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600359 // Verify that all of the requested features are available
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700360 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700361 VkBool32 *actual = (VkBool32 *)&(phy_dev_data->actualPhysicalDeviceFeatures);
362 VkBool32 *requested = (VkBool32 *)&(phy_dev_data->requestedPhysicalDeviceFeatures);
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700363 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
364 // Need to provide the struct member name with the issue. To do that seems like we'll
365 // have to loop through each struct member which should be done w/ codegen to keep in synch.
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600366 uint32_t errors = 0;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700367 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600368 for (uint32_t i = 0; i < totalBools; i++) {
369 if (requested[i] > actual[i]) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700370 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
371 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED,
372 "DL", "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, "
373 "which is not available on this device.",
374 i);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600375 errors++;
376 }
377 }
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700378 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600379 // If user didn't request features, notify them that they should
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700380 // TODO: Verify this against the spec. I believe this is an invalid use of the API and should return an error
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700381 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
382 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
383 "You requested features that are unavailable on this device. You should first query feature "
384 "availability by calling vkGetPhysicalDeviceFeatures().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600385 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600386 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600387}
388
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700389VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
390 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600391 bool skipCall = false;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700392 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600393 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600394 if (!phy_dev_data->physicalDeviceState) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700395 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
396 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
397 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700398 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
399 // TODO: This is not called out as an invalid use in the spec so make more informative recommendation.
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700400 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
401 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
402 "DL", "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
Tobin Ehlis76843842015-09-22 14:00:58 -0600403 } else {
404 // Check that the requested queue properties are valid
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700405 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700406 uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700407 if (phy_dev_data->queueFamilyProperties.size() <=
408 requestedIndex) { // requested index is out of bounds for this physical device
409 skipCall |= log_msg(
410 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
411 __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700412 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700413 } else if (pCreateInfo->pQueueCreateInfos[i].queueCount >
414 phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
415 skipCall |=
416 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
417 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
418 "DL", "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but "
419 "requested queueCount is %u.",
420 requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount,
421 pCreateInfo->pQueueCreateInfos[i].queueCount);
Tobin Ehlis76843842015-09-22 14:00:58 -0600422 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600423 }
424 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600425 // Check that any requested features are available
426 if (pCreateInfo->pEnabledFeatures) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700427 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600428 skipCall |= validate_features_request(phy_dev_data);
429 }
430 if (skipCall)
Courtney Goeltzenleuchter48605a52015-12-10 16:41:22 -0700431 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600432
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700433 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700434
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700435 assert(chain_info->u.pLayerInfo);
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700436 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
437 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700438 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(NULL, "vkCreateDevice");
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700439 if (fpCreateDevice == NULL) {
440 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600441 }
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700442
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700443 // Advance the link info for the next element on the chain
444 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
445
446 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
447 if (result != VK_SUCCESS) {
448 return result;
449 }
450
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700451 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700452 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700453 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
Dustin Graves2c905c82016-03-31 18:01:37 -0600454 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700455 my_device_data->physicalDevice = gpu;
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700456
457 // Get physical device properties for this device
Dustin Graves2c905c82016-03-31 18:01:37 -0600458 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physicalDeviceProperties));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600459 return result;
460}
461
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700462VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600463 // Free device lifetime allocations
464 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600465 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800466 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600467 delete my_device_data->device_dispatch_table;
468 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600469}
470
Michael Lentined0709972016-04-06 17:40:22 -0500471VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
472 const VkAllocationCallbacks *pAllocator,
473 VkRenderPass *pRenderPass) {
474 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
475 bool skip_call = false;
476 uint32_t max_color_attachments = dev_data->physicalDeviceProperties.limits.maxColorAttachments;
477 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
478 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
479 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
480 reinterpret_cast<uint64_t>(device), __LINE__, DEVLIMITS_INVALID_ATTACHMENT_COUNT, "DL",
481 "Cannot create a render pass with %d color attachments. Max is %d.",
482 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments);
483 }
484 }
485 if (skip_call) {
486 return VK_ERROR_VALIDATION_FAILED_EXT;
487 }
488 return dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
489}
490
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700491VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
492 const VkAllocationCallbacks *pAllocator,
493 VkCommandPool *pCommandPool) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600494 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700495 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
496 ->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600497 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600498}
499
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700500VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
501vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
502 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
503 ->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600504}
505
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700506VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
507vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) {
508 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
509 ->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600510 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600511}
512
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700513VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
514vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, VkCommandBuffer *pCommandBuffer) {
515 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
516 ->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600517 return result;
518}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600519
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700520VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
521vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers) {
522 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
523 ->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600524}
525
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700526VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
527vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
Michael Lentine7067c2b2016-01-28 14:20:46 -0600528 bool skipCall = false;
529 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tony Barbour594c0092016-03-25 13:04:20 -0600530 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(dev_data->physicalDevice), layer_data_map);
Michael Lentine7067c2b2016-01-28 14:20:46 -0600531 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tony Barbour594c0092016-03-25 13:04:20 -0600532 if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries == VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700533 skipCall |= log_msg(
534 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
535 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
536 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support inheritedQueries.");
Michael Lentine7067c2b2016-01-28 14:20:46 -0600537 }
Tony Barbour594c0092016-03-25 13:04:20 -0600538 if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries != VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE &&
Michael Lentineea209c02016-01-28 15:03:46 -0600539 !validate_VkQueryControlFlagBits(VkQueryControlFlagBits(pInfo->queryFlags))) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700540 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
541 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
542 "Cannot enable in occlusion queries in vkBeginCommandBuffer() and set queryFlags to %d which is not a "
543 "valid combination of VkQueryControlFlagBits.",
Michael Lentineea209c02016-01-28 15:03:46 -0600544 pInfo->queryFlags);
545 }
Michael Lentine584ccab2016-02-03 16:51:46 -0600546 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine7067c2b2016-01-28 14:20:46 -0600547 if (!skipCall)
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700548 result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Michael Lentine584ccab2016-02-03 16:51:46 -0600549 return result;
Michael Lentine7067c2b2016-01-28 14:20:46 -0600550}
551
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700552VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
553vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
Dustin Gravesbb849942016-04-05 13:48:15 -0600554 bool skipCall = false;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700555 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600556 VkPhysicalDevice gpu = dev_data->physicalDevice;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700557 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700558 if (queueFamilyIndex >=
559 phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
560 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
561 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
562 "DL", "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700563 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700564 skipCall |= log_msg(
565 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
566 DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
567 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.",
568 queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600569 }
Dustin Gravesbb849942016-04-05 13:48:15 -0600570 if (!skipCall)
571 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600572}
573
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700574VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
575vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
576 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
577 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Dustin Gravesbb849942016-04-05 13:48:15 -0600578 bool skipCall = false;
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700579
Mark Young0124e152016-01-25 12:18:32 -0700580 for (uint32_t i = 0; i < descriptorWriteCount; i++) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700581 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
582 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
Dustin Graves2c905c82016-03-31 18:01:37 -0600583 VkDeviceSize uniformAlignment = dev_data->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700584 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
585 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700586 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
587 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
588 DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
589 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64
590 ") must be a multiple of device limit minUniformBufferOffsetAlignment %#" PRIxLEAST64,
591 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700592 }
593 }
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700594 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
595 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dustin Graves2c905c82016-03-31 18:01:37 -0600596 VkDeviceSize storageAlignment = dev_data->physicalDeviceProperties.limits.minStorageBufferOffsetAlignment;
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700597 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
598 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700599 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
600 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
601 DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL",
602 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (%#" PRIxLEAST64
603 ") must be a multiple of device limit minStorageBufferOffsetAlignment %#" PRIxLEAST64,
604 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700605 }
606 }
607 }
608 }
Dustin Gravesbb849942016-04-05 13:48:15 -0600609 if (!skipCall) {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700610 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
611 pDescriptorCopies);
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700612 }
613}
614
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700615VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
616 VkDeviceSize dstOffset, VkDeviceSize dataSize, const uint32_t *pData) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700617 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600618
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700619 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
Chia-I Wu1f851912015-10-27 18:04:07 +0800620 if (dstOffset & 3) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700621 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Chris Forbes05752152016-04-07 12:00:33 +1200622 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__,
623 DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL",
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700624 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600625 return;
626 }
627 }
628
629 // dataSize is the number of bytes to update, which must be a multiple of 4.
630 if (dataSize & 3) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700631 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Chris Forbes05752152016-04-07 12:00:33 +1200632 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__,
633 DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL",
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700634 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600635 return;
636 }
637 }
638
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700639 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyan43909d82015-09-25 13:39:21 -0600640}
641
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700642VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
643vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700644 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600645
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700646 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
Chia-I Wu1f851912015-10-27 18:04:07 +0800647 if (dstOffset & 3) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700648 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Chris Forbes05752152016-04-07 12:00:33 +1200649 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__,
650 DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL",
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700651 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600652 return;
653 }
654 }
655
Chia-I Wu7e470702015-10-26 17:24:52 +0800656 // size is the number of bytes to fill, which must be a multiple of 4.
657 if (size & 3) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700658 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Chris Forbes05752152016-04-07 12:00:33 +1200659 if (log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VkDebugReportObjectTypeEXT(0), 0, __LINE__,
660 DEVLIMITS_INVALID_BUFFER_UPDATE_ALIGNMENT, "DL",
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700661 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600662 return;
663 }
664 }
665
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700666 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyan43909d82015-09-25 13:39:21 -0600667}
668
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700669VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
670vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
671 const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700672 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
673 VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600674 if (VK_SUCCESS == res) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700675 res = layer_create_msg_callback(my_data->report_data, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600676 }
677 return res;
678}
679
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700680VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance,
681 VkDebugReportCallbackEXT msgCallback,
682 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700683 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
684 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchterf6a6e222015-11-30 12:13:14 -0700685 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600686}
687
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700688VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL
689vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object,
690 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700691 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700692 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix,
693 pMsg);
Courtney Goeltzenleuchter5a424ce2015-12-01 14:10:55 -0700694}
695
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700696VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700697 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700698 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600699 if (!strcmp(funcName, "vkDestroyDevice"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700700 return (PFN_vkVoidFunction)vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600701 if (!strcmp(funcName, "vkGetDeviceQueue"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700702 return (PFN_vkVoidFunction)vkGetDeviceQueue;
Michael Lentined0709972016-04-06 17:40:22 -0500703 if (!strcmp(funcName, "vkCreateRenderPass"))
704 return (PFN_vkVoidFunction)vkCreateRenderPass;
705 if (!strcmp(funcName, "vkCreateCommandPool"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700706 return (PFN_vkVoidFunction)vkCreateCommandPool;
Michael Lentined0709972016-04-06 17:40:22 -0500707 if (!strcmp(funcName, "vkDestroyCommandPool"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700708 return (PFN_vkVoidFunction)vkDestroyCommandPool;
Michael Lentined0709972016-04-06 17:40:22 -0500709 if (!strcmp(funcName, "vkResetCommandPool"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700710 return (PFN_vkVoidFunction)vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +0800711 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700712 return (PFN_vkVoidFunction)vkAllocateCommandBuffers;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600713 if (!strcmp(funcName, "vkFreeCommandBuffers"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700714 return (PFN_vkVoidFunction)vkFreeCommandBuffers;
Michael Lentine7067c2b2016-01-28 14:20:46 -0600715 if (!strcmp(funcName, "vkBeginCommandBuffer"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700716 return (PFN_vkVoidFunction)vkBeginCommandBuffer;
Mike Stroyan43909d82015-09-25 13:39:21 -0600717 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700718 return (PFN_vkVoidFunction)vkCmdUpdateBuffer;
Mark Lobodzinski0fe21732016-01-13 10:23:15 -0700719 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700720 return (PFN_vkVoidFunction)vkUpdateDescriptorSets;
Mike Stroyan43909d82015-09-25 13:39:21 -0600721 if (!strcmp(funcName, "vkCmdFillBuffer"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700722 return (PFN_vkVoidFunction)vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600723
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700724 if (dev == NULL)
725 return NULL;
726
Mark Lobodzinskib838dc02016-02-03 09:57:14 -0700727 layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700728 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600729 {
730 if (pTable->GetDeviceProcAddr == NULL)
731 return NULL;
732 return pTable->GetDeviceProcAddr(dev, funcName);
733 }
734}
735
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700736VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600737 PFN_vkVoidFunction fptr;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600738
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600739 layer_data *my_data;
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700740 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700741 return (PFN_vkVoidFunction)vkGetInstanceProcAddr;
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700742 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700743 return (PFN_vkVoidFunction)vkGetDeviceProcAddr;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600744 if (!strcmp(funcName, "vkCreateInstance"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700745 return (PFN_vkVoidFunction)vkCreateInstance;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600746 if (!strcmp(funcName, "vkDestroyInstance"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700747 return (PFN_vkVoidFunction)vkDestroyInstance;
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700748 if (!strcmp(funcName, "vkCreateDevice"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700749 return (PFN_vkVoidFunction)vkCreateDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600750 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700751 return (PFN_vkVoidFunction)vkEnumeratePhysicalDevices;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600752 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700753 return (PFN_vkVoidFunction)vkGetPhysicalDeviceFeatures;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600754 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700755 return (PFN_vkVoidFunction)vkGetPhysicalDeviceFormatProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600756 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700757 return (PFN_vkVoidFunction)vkGetPhysicalDeviceImageFormatProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600758 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700759 return (PFN_vkVoidFunction)vkGetPhysicalDeviceProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600760 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700761 return (PFN_vkVoidFunction)vkGetPhysicalDeviceQueueFamilyProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600762 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700763 return (PFN_vkVoidFunction)vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600764 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700765 return (PFN_vkVoidFunction)vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600766 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700767 return (PFN_vkVoidFunction)vkEnumerateInstanceLayerProperties;
Courtney Goeltzenleuchterbadf4cf2016-02-12 13:46:04 -0700768 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
769 return (PFN_vkVoidFunction)vkEnumerateDeviceLayerProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600770 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700771 return (PFN_vkVoidFunction)vkEnumerateInstanceExtensionProperties;
Courtney Goeltzenleuchterbadf4cf2016-02-12 13:46:04 -0700772 if (!strcmp(funcName, "vkEnumerateInstanceDeviceProperties"))
773 return (PFN_vkVoidFunction)vkEnumerateDeviceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600774
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700775 if (!instance)
776 return NULL;
Courtney Goeltzenleuchter2bdf6da2016-01-08 12:18:43 -0700777
778 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
779
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600780 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
781 if (fptr)
782 return fptr;
783
784 {
Jon Ashburn491a3cd2016-03-08 17:48:44 -0700785 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600786 if (pTable->GetInstanceProcAddr == NULL)
787 return NULL;
788 return pTable->GetInstanceProcAddr(instance, funcName);
789 }
790}