blob: f70f421eca63c7869dee033f1fae41d8ac0e9593 [file] [log] [blame]
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -07001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06005 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06006 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
Courtney Goeltzenleuchter05559522015-10-30 11:14:30 -060017 *
18 * Author: Mark Lobodzinski <mark@lunarg.com>
Mark Lobodzinski6eda00a2016-02-02 15:55:36 -070019 * Author: Mike Stroyan <mike@LunarG.com>
20 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060021 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <unordered_map>
27#include <memory>
28
29#include "vk_loader_platform.h"
30#include "vk_dispatch_table_helper.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060031#if defined(__GNUC__)
32#pragma GCC diagnostic ignored "-Wwrite-strings"
33#endif
34#if defined(__GNUC__)
35#pragma GCC diagnostic warning "-Wwrite-strings"
36#endif
37#include "vk_struct_size_helper.h"
38#include "device_limits.h"
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -070039#include "vulkan/vk_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060040#include "vk_layer_config.h"
Michael Lentine5d8ad0a2016-01-28 15:03:46 -060041#include "vk_enum_validate_helper.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060042#include "vk_layer_table.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060043#include "vk_layer_data.h"
44#include "vk_layer_logging.h"
45#include "vk_layer_extension_utils.h"
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060046#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060047
Chia-I Wu080cb7a2016-04-28 11:27:46 +080048namespace device_limits {
49
Tobin Ehlis9da65002015-09-24 15:25:16 -060050// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060051struct layer_data {
Chia-I Wu50c4ad92016-04-28 16:04:15 +080052 VkInstance instance;
53
Jon Ashburn5484e0c2016-03-08 17:48:44 -070054 debug_report_data *report_data;
55 std::vector<VkDebugReportCallbackEXT> logging_callback;
56 VkLayerDispatchTable *device_dispatch_table;
57 VkLayerInstanceDispatchTable *instance_dispatch_table;
Tobin Ehlis9da65002015-09-24 15:25:16 -060058 // Track state of each instance
Jon Ashburn5484e0c2016-03-08 17:48:44 -070059 unique_ptr<INSTANCE_STATE> instanceState;
60 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
61 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
62 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Mark Lobodzinski941aea92016-01-13 10:23:15 -070063
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060064 // Track physical device per logical device
65 VkPhysicalDevice physicalDevice;
Dustin Gravesa97c3942016-03-31 18:01:37 -060066 VkPhysicalDeviceProperties physicalDeviceProperties;
Tobin Ehlis9da65002015-09-24 15:25:16 -060067 // Vector indices correspond to queueFamilyIndex
68 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060069
Jon Ashburn5484e0c2016-03-08 17:48:44 -070070 layer_data()
71 : report_data(nullptr), device_dispatch_table(nullptr), instance_dispatch_table(nullptr), instanceState(nullptr),
72 physicalDeviceState(nullptr), actualPhysicalDeviceFeatures(), requestedPhysicalDeviceFeatures(), physicalDevice(){};
Cody Northrop55443ef2015-09-28 15:09:32 -060073};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060074
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060075static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060076
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -070077// TODO : This can be much smarter, using separate locks for separate global data
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060078static int globalLockInitialized = 0;
79static loader_platform_thread_mutex globalLock;
80
Jon Ashburn5484e0c2016-03-08 17:48:44 -070081static void init_device_limits(layer_data *my_data, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060082
Mark Lobodzinski1079e1b2016-03-15 14:21:59 -060083 layer_debug_actions(my_data->report_data, my_data->logging_callback, pAllocator, "lunarg_device_limits");
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060084
Jon Ashburn5484e0c2016-03-08 17:48:44 -070085 if (!globalLockInitialized) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060086 // TODO/TBD: Need to delete this mutex sometime. How??? One
87 // suggestion is to call this during vkCreateInstance(), and then we
88 // can clean it up during vkDestroyInstance(). However, that requires
89 // that the layer have per-instance locks. We need to come back and
90 // address this soon.
91 loader_platform_thread_create_mutex(&globalLock);
92 globalLockInitialized = 1;
93 }
94}
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -070095
Jon Ashburn5484e0c2016-03-08 17:48:44 -070096static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
Courtney Goeltzenleuchter20c35012015-11-30 12:14:06 -070097
Chia-I Wucc0aa7a2016-04-28 14:12:27 +080098static const VkLayerProperties global_layer = {
Jon Ashburndc9111c2016-03-22 12:57:13 -060099 "VK_LAYER_LUNARG_device_limits", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer",
Chia-I Wucc0aa7a2016-04-28 14:12:27 +0800100};
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600101
Chia-I Wu99860202016-04-28 14:01:30 +0800102VKAPI_ATTR VkResult VKAPI_CALL
103CreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkInstance *pInstance) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700104 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600105
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700106 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700107 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700108 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700109 if (fpCreateInstance == NULL) {
110 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600111 }
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700112
113 // Advance the link info for the next element on the chain
114 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
115
116 VkResult result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
117 if (result != VK_SUCCESS)
118 return result;
119
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700120 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
Chia-I Wu50c4ad92016-04-28 16:04:15 +0800121 my_data->instance = *pInstance;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700122 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700123 layer_init_instance_dispatch_table(*pInstance, my_data->instance_dispatch_table, fpGetInstanceProcAddr);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700124
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700125 my_data->report_data = debug_report_create_instance(my_data->instance_dispatch_table, *pInstance,
126 pCreateInfo->enabledExtensionCount, pCreateInfo->ppEnabledExtensionNames);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700127
128 init_device_limits(my_data, pAllocator);
129 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
130
131 return VK_SUCCESS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600132}
133
134/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu99860202016-04-28 14:01:30 +0800135VKAPI_ATTR void VKAPI_CALL
136DestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600137 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600138 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
139 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wuf7458c52015-10-26 21:10:41 +0800140 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600141
142 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600143 while (my_data->logging_callback.size() > 0) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700144 VkDebugReportCallbackEXT callback = my_data->logging_callback.back();
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700145 layer_destroy_msg_callback(my_data->report_data, callback, pAllocator);
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600146 my_data->logging_callback.pop_back();
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600147 }
148
149 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600150 delete my_data->instance_dispatch_table;
151 layer_data_map.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -0600152 if (layer_data_map.empty()) {
153 // Release mutex when destroying last instance.
154 loader_platform_thread_delete_mutex(&globalLock);
155 globalLockInitialized = 0;
156 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600157}
158
Chia-I Wu99860202016-04-28 14:01:30 +0800159VKAPI_ATTR VkResult VKAPI_CALL
160EnumeratePhysicalDevices(VkInstance instance, uint32_t *pPhysicalDeviceCount, VkPhysicalDevice *pPhysicalDevices) {
Dustin Graves080069b2016-04-05 13:48:15 -0600161 bool skipCall = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700162 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600163 if (my_data->instanceState) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700164 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600165 if (NULL == pPhysicalDevices) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700166 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600167 } else {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700168 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Jan-Harald Fredriksen4f57fd12016-06-08 18:51:52 +0200169 // Flag warning here. You can call this without having queried the count, but it may not be
170 // robust on platforms with multiple physical devices.
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700171 skipCall |=
Jan-Harald Fredriksen4f57fd12016-06-08 18:51:52 +0200172 log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0,
173 __LINE__, DEVLIMITS_MISSING_QUERY_COUNT, "DL",
174 "Call sequence has vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first "
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700175 "call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700176 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
177 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
Jan-Harald Fredriksen4f57fd12016-06-08 18:51:52 +0200178 // Having actual count match count from app is not a requirement, so this can be a warning
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700179 skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
180 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
181 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count "
182 "supported by this instance is %u.",
183 *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600184 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700185 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600186 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600187 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700188 return VK_ERROR_VALIDATION_FAILED_EXT;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700189 VkResult result =
190 my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600191 if (NULL == pPhysicalDevices) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700192 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600193 } else { // Save physical devices
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700194 for (uint32_t i = 0; i < *pPhysicalDeviceCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700195 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
196 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
Tobin Ehlis9da65002015-09-24 15:25:16 -0600197 // Init actual features for each physical device
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700198 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i],
199 &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600200 }
201 }
202 return result;
203 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700204 log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, 0, __LINE__,
Mark Muelleraab36502016-05-03 13:17:29 -0600205 DEVLIMITS_INVALID_INSTANCE, "DL", "Invalid instance (0x%" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700206 (uint64_t)instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600207 }
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700208 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600209}
210
Chia-I Wu99860202016-04-28 14:01:30 +0800211VKAPI_ATTR void VKAPI_CALL
212GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures *pFeatures) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700213 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
214 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
215 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600216}
217
Chia-I Wu99860202016-04-28 14:01:30 +0800218VKAPI_ATTR void VKAPI_CALL
219GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties *pFormatProperties) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700220 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
221 ->instance_dispatch_table->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600222}
223
Chia-I Wu99860202016-04-28 14:01:30 +0800224VKAPI_ATTR VkResult VKAPI_CALL
225GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling,
226 VkImageUsageFlags usage, VkImageCreateFlags flags,
227 VkImageFormatProperties *pImageFormatProperties) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700228 return get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
229 ->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags,
230 pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600231}
232
Chia-I Wu99860202016-04-28 14:01:30 +0800233VKAPI_ATTR void VKAPI_CALL
234GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties *pProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700235 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
236 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600237}
238
Chia-I Wu99860202016-04-28 14:01:30 +0800239VKAPI_ATTR void VKAPI_CALL
240GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
241 VkQueueFamilyProperties *pQueueFamilyProperties) {
Dustin Graves080069b2016-04-05 13:48:15 -0600242 bool skipCall = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700243 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600244 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600245 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700246 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600247 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700248 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to
249 // get count
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700250 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
Jan-Harald Fredriksen4f57fd12016-06-08 18:51:52 +0200251 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
252 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MISSING_QUERY_COUNT, "DL",
253 "Call sequence has vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL "
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700254 "pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ "
255 "NULL pQueueFamilyProperties to query pCount.");
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600256 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700257 // Then verify that pCount that is passed in on second call matches what was returned
258 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700259
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700260 // TODO: this is not a requirement of the Valid Usage section for vkGetPhysicalDeviceQueueFamilyProperties, so
261 // provide as warning
262 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
263 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_COUNT_MISMATCH, "DL",
264 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count "
265 "supported by this physicalDevice is %u.",
266 *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600267 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700268 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600269 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600270 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600271 return;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700272 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount,
273 pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600274 if (NULL == pQueueFamilyProperties) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700275 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600276 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600277 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700278 for (uint32_t i = 0; i < *pCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700279 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600280 }
281 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600282 return;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600283 } else {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700284 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
285 __LINE__, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
Mark Muelleraab36502016-05-03 13:17:29 -0600286 "Invalid physicalDevice (0x%" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().",
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700287 (uint64_t)physicalDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600288 }
289}
290
Chia-I Wu99860202016-04-28 14:01:30 +0800291VKAPI_ATTR void VKAPI_CALL
292GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties *pMemoryProperties) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700293 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
294 ->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600295}
296
Chia-I Wu99860202016-04-28 14:01:30 +0800297VKAPI_ATTR void VKAPI_CALL
298GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type,
299 VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling,
300 uint32_t *pNumProperties, VkSparseImageFormatProperties *pProperties) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700301 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)
302 ->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage,
303 tiling, pNumProperties, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600304}
305
Chia-I Wu99860202016-04-28 14:01:30 +0800306VKAPI_ATTR void VKAPI_CALL
307CmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount, const VkViewport *pViewports) {
Dustin Graves080069b2016-04-05 13:48:15 -0600308 bool skipCall = false;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600309 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
Dustin Graves080069b2016-04-05 13:48:15 -0600310 if (!skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700311 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
312 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, firstViewport, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600313 }
314}
315
Chia-I Wu99860202016-04-28 14:01:30 +0800316VKAPI_ATTR void VKAPI_CALL
317CmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
Dustin Graves080069b2016-04-05 13:48:15 -0600318 bool skipCall = false;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600319 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
320 /* TODO: viewportCount and scissorCount must match at draw time */
Dustin Graves080069b2016-04-05 13:48:15 -0600321 if (!skipCall) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700322 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
323 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, firstScissor, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600324 }
325}
326
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700327// Verify that features have been queried and verify that requested features are available
Dustin Graves080069b2016-04-05 13:48:15 -0600328static bool validate_features_request(layer_data *phy_dev_data) {
329 bool skipCall = false;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600330 // Verify that all of the requested features are available
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700331 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700332 VkBool32 *actual = (VkBool32 *)&(phy_dev_data->actualPhysicalDeviceFeatures);
333 VkBool32 *requested = (VkBool32 *)&(phy_dev_data->requestedPhysicalDeviceFeatures);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700334 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
335 // Need to provide the struct member name with the issue. To do that seems like we'll
336 // have to loop through each struct member which should be done w/ codegen to keep in synch.
Tobin Ehlis9da65002015-09-24 15:25:16 -0600337 uint32_t errors = 0;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700338 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600339 for (uint32_t i = 0; i < totalBools; i++) {
340 if (requested[i] > actual[i]) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700341 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
342 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED,
343 "DL", "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, "
344 "which is not available on this device.",
345 i);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600346 errors++;
347 }
348 }
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700349 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600350 // If user didn't request features, notify them that they should
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700351 // TODO: Verify this against the spec. I believe this is an invalid use of the API and should return an error
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700352 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
353 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
354 "You requested features that are unavailable on this device. You should first query feature "
355 "availability by calling vkGetPhysicalDeviceFeatures().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600356 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600357 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600358}
359
Chia-I Wu99860202016-04-28 14:01:30 +0800360VKAPI_ATTR VkResult VKAPI_CALL
361CreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
362 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
Dustin Graves080069b2016-04-05 13:48:15 -0600363 bool skipCall = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700364 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600365 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600366 if (!phy_dev_data->physicalDeviceState) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700367 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
368 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_MUST_QUERY_COUNT, "DL",
369 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700370 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
371 // TODO: This is not called out as an invalid use in the spec so make more informative recommendation.
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700372 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT,
373 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
374 "DL", "Call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600375 } else {
376 // Check that the requested queue properties are valid
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700377 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700378 uint32_t requestedIndex = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700379 if (phy_dev_data->queueFamilyProperties.size() <=
380 requestedIndex) { // requested index is out of bounds for this physical device
381 skipCall |= log_msg(
382 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0,
383 __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700384 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700385 } else if (pCreateInfo->pQueueCreateInfos[i].queueCount >
386 phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
387 skipCall |=
388 log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
389 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
390 "DL", "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but "
391 "requested queueCount is %u.",
392 requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount,
393 pCreateInfo->pQueueCreateInfos[i].queueCount);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600394 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600395 }
396 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600397 // Check that any requested features are available
398 if (pCreateInfo->pEnabledFeatures) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700399 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600400 skipCall |= validate_features_request(phy_dev_data);
401 }
402 if (skipCall)
Courtney Goeltzenleuchter52fee652015-12-10 16:41:22 -0700403 return VK_ERROR_VALIDATION_FAILED_EXT;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600404
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700405 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700406
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700407 assert(chain_info->u.pLayerInfo);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700408 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
409 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
Chia-I Wu50c4ad92016-04-28 16:04:15 +0800410 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(phy_dev_data->instance, "vkCreateDevice");
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700411 if (fpCreateDevice == NULL) {
412 return VK_ERROR_INITIALIZATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600413 }
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700414
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700415 // Advance the link info for the next element on the chain
416 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
417
418 VkResult result = fpCreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
419 if (result != VK_SUCCESS) {
420 return result;
421 }
422
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700423 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700424 my_device_data->device_dispatch_table = new VkLayerDispatchTable;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700425 layer_init_device_dispatch_table(*pDevice, my_device_data->device_dispatch_table, fpGetDeviceProcAddr);
Dustin Gravesa97c3942016-03-31 18:01:37 -0600426 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700427 my_device_data->physicalDevice = gpu;
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700428
429 // Get physical device properties for this device
Dustin Gravesa97c3942016-03-31 18:01:37 -0600430 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(gpu, &(my_device_data->physicalDeviceProperties));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600431 return result;
432}
433
Chia-I Wu99860202016-04-28 14:01:30 +0800434VKAPI_ATTR void VKAPI_CALL
435DestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600436 // Free device lifetime allocations
437 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600438 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wuf7458c52015-10-26 21:10:41 +0800439 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600440 delete my_device_data->device_dispatch_table;
441 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600442}
443
Chia-I Wu99860202016-04-28 14:01:30 +0800444VKAPI_ATTR VkResult VKAPI_CALL
445CreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
446 const VkAllocationCallbacks *pAllocator,
447 VkRenderPass *pRenderPass) {
Michael Lentine20e4c192016-04-06 17:40:22 -0500448 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
449 bool skip_call = false;
450 uint32_t max_color_attachments = dev_data->physicalDeviceProperties.limits.maxColorAttachments;
451 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
452 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
453 skip_call |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
454 reinterpret_cast<uint64_t>(device), __LINE__, DEVLIMITS_INVALID_ATTACHMENT_COUNT, "DL",
455 "Cannot create a render pass with %d color attachments. Max is %d.",
456 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments);
457 }
458 }
459 if (skip_call) {
460 return VK_ERROR_VALIDATION_FAILED_EXT;
461 }
462 return dev_data->device_dispatch_table->CreateRenderPass(device, pCreateInfo, pAllocator, pRenderPass);
463}
464
Chia-I Wu99860202016-04-28 14:01:30 +0800465VKAPI_ATTR VkResult VKAPI_CALL
466CreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
467 const VkAllocationCallbacks *pAllocator,
468 VkCommandPool *pCommandPool) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600469 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700470 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
471 ->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600472 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600473}
474
Chia-I Wu99860202016-04-28 14:01:30 +0800475VKAPI_ATTR void VKAPI_CALL
476DestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks *pAllocator) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700477 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
478 ->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600479}
480
Chia-I Wu99860202016-04-28 14:01:30 +0800481VKAPI_ATTR VkResult VKAPI_CALL
482ResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700483 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
484 ->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600485 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600486}
487
Chia-I Wu99860202016-04-28 14:01:30 +0800488VKAPI_ATTR VkResult VKAPI_CALL
489AllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo, VkCommandBuffer *pCommandBuffer) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700490 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)
491 ->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600492 return result;
493}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600494
Chia-I Wu99860202016-04-28 14:01:30 +0800495VKAPI_ATTR void VKAPI_CALL
496FreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer *pCommandBuffers) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700497 get_my_data_ptr(get_dispatch_key(device), layer_data_map)
498 ->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600499}
500
Chia-I Wu99860202016-04-28 14:01:30 +0800501VKAPI_ATTR VkResult VKAPI_CALL
502BeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
Michael Lentine09853ef2016-01-28 14:20:46 -0600503 bool skipCall = false;
504 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Tony Barboure24b8e32016-03-25 13:04:20 -0600505 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(dev_data->physicalDevice), layer_data_map);
Michael Lentine09853ef2016-01-28 14:20:46 -0600506 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
Tony Barboure24b8e32016-03-25 13:04:20 -0600507 if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries == VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700508 skipCall |= log_msg(
509 dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
510 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
511 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support inheritedQueries.");
Michael Lentine09853ef2016-01-28 14:20:46 -0600512 }
Tony Barboure24b8e32016-03-25 13:04:20 -0600513 if (phy_dev_data->actualPhysicalDeviceFeatures.inheritedQueries != VK_FALSE && pInfo && pInfo->occlusionQueryEnable != VK_FALSE &&
Michael Lentine5d8ad0a2016-01-28 15:03:46 -0600514 !validate_VkQueryControlFlagBits(VkQueryControlFlagBits(pInfo->queryFlags))) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700515 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
516 reinterpret_cast<uint64_t>(commandBuffer), __LINE__, DEVLIMITS_INVALID_INHERITED_QUERY, "DL",
517 "Cannot enable in occlusion queries in vkBeginCommandBuffer() and set queryFlags to %d which is not a "
518 "valid combination of VkQueryControlFlagBits.",
Michael Lentine5d8ad0a2016-01-28 15:03:46 -0600519 pInfo->queryFlags);
520 }
Michael Lentine0a369f62016-02-03 16:51:46 -0600521 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
Michael Lentine09853ef2016-01-28 14:20:46 -0600522 if (!skipCall)
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700523 result = dev_data->device_dispatch_table->BeginCommandBuffer(commandBuffer, pBeginInfo);
Michael Lentine0a369f62016-02-03 16:51:46 -0600524 return result;
Michael Lentine09853ef2016-01-28 14:20:46 -0600525}
526
Chia-I Wu99860202016-04-28 14:01:30 +0800527VKAPI_ATTR void VKAPI_CALL
528GetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
Dustin Graves080069b2016-04-05 13:48:15 -0600529 bool skipCall = false;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700530 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600531 VkPhysicalDevice gpu = dev_data->physicalDevice;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700532 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700533 if (queueFamilyIndex >=
534 phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
535 skipCall |= log_msg(phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
536 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST,
537 "DL", "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700538 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700539 skipCall |= log_msg(
540 phy_dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
541 DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
542 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.",
543 queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600544 }
Dustin Graves080069b2016-04-05 13:48:15 -0600545 if (!skipCall)
546 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600547}
548
Chia-I Wu99860202016-04-28 14:01:30 +0800549VKAPI_ATTR void VKAPI_CALL
550UpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700551 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
552 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
Dustin Graves080069b2016-04-05 13:48:15 -0600553 bool skipCall = false;
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700554
Mark Youngee3f3a22016-01-25 12:18:32 -0700555 for (uint32_t i = 0; i < descriptorWriteCount; i++) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700556 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
557 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
Dustin Gravesa97c3942016-03-31 18:01:37 -0600558 VkDeviceSize uniformAlignment = dev_data->physicalDeviceProperties.limits.minUniformBufferOffsetAlignment;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700559 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
560 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700561 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
562 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
563 DEVLIMITS_INVALID_UNIFORM_BUFFER_OFFSET, "DL",
Mark Muelleraab36502016-05-03 13:17:29 -0600564 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
565 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700566 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700567 }
568 }
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700569 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
570 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
Dustin Gravesa97c3942016-03-31 18:01:37 -0600571 VkDeviceSize storageAlignment = dev_data->physicalDeviceProperties.limits.minStorageBufferOffsetAlignment;
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700572 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
573 if (vk_safe_modulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700574 skipCall |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
575 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__,
576 DEVLIMITS_INVALID_STORAGE_BUFFER_OFFSET, "DL",
Mark Muelleraab36502016-05-03 13:17:29 -0600577 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
578 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64,
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700579 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700580 }
581 }
582 }
583 }
Dustin Graves080069b2016-04-05 13:48:15 -0600584 if (!skipCall) {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700585 dev_data->device_dispatch_table->UpdateDescriptorSets(device, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
586 pDescriptorCopies);
Mark Lobodzinski941aea92016-01-13 10:23:15 -0700587 }
588}
589
Chia-I Wu99860202016-04-28 14:01:30 +0800590VKAPI_ATTR VkResult VKAPI_CALL
591CreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
592 const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700593 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
594 VkResult res = my_data->instance_dispatch_table->CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600595 if (VK_SUCCESS == res) {
Mark Lobodzinski97c4d512016-05-19 15:27:18 -0600596 res = layer_create_msg_callback(my_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600597 }
598 return res;
599}
600
Chia-I Wu99860202016-04-28 14:01:30 +0800601VKAPI_ATTR void VKAPI_CALL
602DestroyDebugReportCallbackEXT(VkInstance instance,
603 VkDebugReportCallbackEXT msgCallback,
604 const VkAllocationCallbacks *pAllocator) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700605 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
606 my_data->instance_dispatch_table->DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Courtney Goeltzenleuchter05854bf2015-11-30 12:13:14 -0700607 layer_destroy_msg_callback(my_data->report_data, msgCallback, pAllocator);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600608}
609
Chia-I Wu99860202016-04-28 14:01:30 +0800610VKAPI_ATTR void VKAPI_CALL
611DebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object,
612 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700613 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700614 my_data->instance_dispatch_table->DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix,
615 pMsg);
Courtney Goeltzenleuchterf0de7242015-12-01 14:10:55 -0700616}
617
Chia-I Wu99860202016-04-28 14:01:30 +0800618VKAPI_ATTR VkResult VKAPI_CALL
Chia-I Wub02600c2016-05-20 07:11:22 +0800619EnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
620 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
621}
622
623VKAPI_ATTR VkResult VKAPI_CALL
624EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) {
625 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
626}
627
628VKAPI_ATTR VkResult VKAPI_CALL
629EnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) {
630 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
631 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
632
633 return VK_ERROR_LAYER_NOT_PRESENT;
634}
635
636VKAPI_ATTR VkResult VKAPI_CALL
Chia-I Wu99860202016-04-28 14:01:30 +0800637EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
638 const char *pLayerName, uint32_t *pCount,
639 VkExtensionProperties *pProperties) {
Chia-I Wuc83c0832016-04-28 14:21:13 +0800640 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
Chia-I Wu16489ac2016-04-28 11:21:49 +0800641 return util_GetExtensionProperties(0, nullptr, pCount, pProperties);
Chia-I Wuc83c0832016-04-28 14:21:13 +0800642
643 assert(physicalDevice);
644
645 dispatch_key key = get_dispatch_key(physicalDevice);
646 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
647 return my_data->instance_dispatch_table->EnumerateDeviceExtensionProperties(physicalDevice, pLayerName, pCount, pProperties);
Chia-I Wu16489ac2016-04-28 11:21:49 +0800648}
649
Chia-I Wuafe42442016-04-28 14:38:57 +0800650static PFN_vkVoidFunction
Chia-I Wu2b8c6e62016-04-28 14:38:57 +0800651intercept_core_instance_command(const char *name);
652
653static PFN_vkVoidFunction
Chia-I Wuafe42442016-04-28 14:38:57 +0800654intercept_core_device_command(const char *name);
655
Chia-I Wu99860202016-04-28 14:01:30 +0800656VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
657GetDeviceProcAddr(VkDevice dev, const char *funcName) {
Chia-I Wuafe42442016-04-28 14:38:57 +0800658 PFN_vkVoidFunction proc = intercept_core_device_command(funcName);
659 if (proc)
660 return proc;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600661
Chia-I Wuafe42442016-04-28 14:38:57 +0800662 assert(dev);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700663
Mark Lobodzinski1ed594e2016-02-03 09:57:14 -0700664 layer_data *my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700665 VkLayerDispatchTable *pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600666 {
667 if (pTable->GetDeviceProcAddr == NULL)
668 return NULL;
669 return pTable->GetDeviceProcAddr(dev, funcName);
670 }
671}
672
Chia-I Wu99860202016-04-28 14:01:30 +0800673VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
674GetInstanceProcAddr(VkInstance instance, const char *funcName) {
Chia-I Wu2b8c6e62016-04-28 14:38:57 +0800675 PFN_vkVoidFunction proc = intercept_core_instance_command(funcName);
Chia-I Wu79d1c8d2016-04-28 15:16:59 +0800676 if (!proc)
677 intercept_core_device_command(funcName);
Chia-I Wu2b8c6e62016-04-28 14:38:57 +0800678 if (proc)
679 return proc;
680
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600681 layer_data *my_data;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600682
Chia-I Wu79d1c8d2016-04-28 15:16:59 +0800683 assert(instance);
Courtney Goeltzenleuchter00150eb2016-01-08 12:18:43 -0700684 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
685
Chia-I Wu79d1c8d2016-04-28 15:16:59 +0800686 proc = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
687 if (proc)
688 return proc;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600689
690 {
Jon Ashburn5484e0c2016-03-08 17:48:44 -0700691 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600692 if (pTable->GetInstanceProcAddr == NULL)
693 return NULL;
694 return pTable->GetInstanceProcAddr(instance, funcName);
695 }
696}
Chia-I Wu16489ac2016-04-28 11:21:49 +0800697
Chia-I Wuafe42442016-04-28 14:38:57 +0800698static PFN_vkVoidFunction
Chia-I Wu2b8c6e62016-04-28 14:38:57 +0800699intercept_core_instance_command(const char *name) {
700 static const struct {
701 const char *name;
702 PFN_vkVoidFunction proc;
703 } core_instance_commands[] = {
704 { "vkGetInstanceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr) },
705 { "vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr) },
706 { "vkCreateInstance", reinterpret_cast<PFN_vkVoidFunction>(CreateInstance) },
707 { "vkDestroyInstance", reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance) },
708 { "vkCreateDevice", reinterpret_cast<PFN_vkVoidFunction>(CreateDevice) },
709 { "vkEnumeratePhysicalDevices", reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices) },
710 { "vkGetPhysicalDeviceFeatures", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFeatures) },
711 { "vkGetPhysicalDeviceFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceFormatProperties) },
712 { "vkGetPhysicalDeviceImageFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceImageFormatProperties) },
713 { "vkGetPhysicalDeviceProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceProperties) },
714 { "vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceQueueFamilyProperties) },
715 { "vkGetPhysicalDeviceMemoryProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceMemoryProperties) },
716 { "vkGetPhysicalDeviceSparseImageFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(GetPhysicalDeviceSparseImageFormatProperties) },
Chia-I Wub02600c2016-05-20 07:11:22 +0800717 { "vkEnumerateInstanceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceLayerProperties) },
718 { "vkEnumerateDeviceLayerProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceLayerProperties) },
719 { "vkEnumerateInstanceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceExtensionProperties) },
Chia-I Wudfe8e6c2016-04-28 15:17:27 +0800720 { "vkEnumerateDeviceExtensionProperties", reinterpret_cast<PFN_vkVoidFunction>(EnumerateDeviceExtensionProperties) },
Chia-I Wu2b8c6e62016-04-28 14:38:57 +0800721 };
722
723 for (size_t i = 0; i < ARRAY_SIZE(core_instance_commands); i++) {
724 if (!strcmp(core_instance_commands[i].name, name))
725 return core_instance_commands[i].proc;
726 }
727
728 return nullptr;
729}
730
731static PFN_vkVoidFunction
Chia-I Wuafe42442016-04-28 14:38:57 +0800732intercept_core_device_command(const char *name) {
733 static const struct {
734 const char *name;
735 PFN_vkVoidFunction proc;
736 } core_device_commands[] = {
737 { "vkGetDeviceProcAddr", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceProcAddr) },
738 { "vkDestroyDevice", reinterpret_cast<PFN_vkVoidFunction>(DestroyDevice) },
739 { "vkGetDeviceQueue", reinterpret_cast<PFN_vkVoidFunction>(GetDeviceQueue) },
740 { "vkCreateRenderPass", reinterpret_cast<PFN_vkVoidFunction>(CreateRenderPass) },
741 { "vkCreateCommandPool", reinterpret_cast<PFN_vkVoidFunction>(CreateCommandPool) },
742 { "vkDestroyCommandPool", reinterpret_cast<PFN_vkVoidFunction>(DestroyCommandPool) },
743 { "vkResetCommandPool", reinterpret_cast<PFN_vkVoidFunction>(ResetCommandPool) },
744 { "vkAllocateCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers) },
745 { "vkFreeCommandBuffers", reinterpret_cast<PFN_vkVoidFunction>(FreeCommandBuffers) },
746 { "vkBeginCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(BeginCommandBuffer) },
Chia-I Wuafe42442016-04-28 14:38:57 +0800747 { "vkUpdateDescriptorSets", reinterpret_cast<PFN_vkVoidFunction>(UpdateDescriptorSets) },
Chia-I Wufa5e51c2016-04-28 14:44:08 +0800748 { "vkCmdSetScissor", reinterpret_cast<PFN_vkVoidFunction>(CmdSetScissor) },
749 { "vkCmdSetViewport", reinterpret_cast<PFN_vkVoidFunction>(CmdSetViewport) },
Chia-I Wuafe42442016-04-28 14:38:57 +0800750 };
751
752 for (size_t i = 0; i < ARRAY_SIZE(core_device_commands); i++) {
753 if (!strcmp(core_device_commands[i].name, name))
754 return core_device_commands[i].proc;
755 }
756
757 return nullptr;
758}
759
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800760} // namespace device_limits
761
762// vk_layer_logging.h expects these to be defined
763
Chia-I Wu99860202016-04-28 14:01:30 +0800764VKAPI_ATTR VkResult VKAPI_CALL
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800765vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
766 const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pMsgCallback) {
Chia-I Wu99860202016-04-28 14:01:30 +0800767 return device_limits::CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800768}
769
Chia-I Wu99860202016-04-28 14:01:30 +0800770VKAPI_ATTR void VKAPI_CALL
771vkDestroyDebugReportCallbackEXT(VkInstance instance,
772 VkDebugReportCallbackEXT msgCallback,
773 const VkAllocationCallbacks *pAllocator) {
774 device_limits::DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800775}
776
Chia-I Wu99860202016-04-28 14:01:30 +0800777VKAPI_ATTR void VKAPI_CALL
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800778vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objType, uint64_t object,
779 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg) {
Chia-I Wu99860202016-04-28 14:01:30 +0800780 device_limits::DebugReportMessageEXT(instance, flags, objType, object, location, msgCode, pLayerPrefix, pMsg);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800781}
782
Chia-I Wub02600c2016-05-20 07:11:22 +0800783// loader-layer interface v0, just wrappers since there is only a layer
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800784
Chia-I Wu16489ac2016-04-28 11:21:49 +0800785VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
786vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
Chia-I Wub02600c2016-05-20 07:11:22 +0800787 return device_limits::EnumerateInstanceLayerProperties(pCount, pProperties);
Chia-I Wu16489ac2016-04-28 11:21:49 +0800788}
789
790VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
791vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) {
Chia-I Wub02600c2016-05-20 07:11:22 +0800792 // the layer command handles VK_NULL_HANDLE just fine internally
793 assert(physicalDevice == VK_NULL_HANDLE);
794 return device_limits::EnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
Chia-I Wu16489ac2016-04-28 11:21:49 +0800795}
796
797VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
798vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount, VkExtensionProperties *pProperties) {
Chia-I Wub02600c2016-05-20 07:11:22 +0800799 return device_limits::EnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800800}
801
802VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
803 const char *pLayerName, uint32_t *pCount,
804 VkExtensionProperties *pProperties) {
Chia-I Wub02600c2016-05-20 07:11:22 +0800805 // the layer command handles VK_NULL_HANDLE just fine internally
806 assert(physicalDevice == VK_NULL_HANDLE);
Chia-I Wuc83c0832016-04-28 14:21:13 +0800807 return device_limits::EnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800808}
809
810VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
Chia-I Wu99860202016-04-28 14:01:30 +0800811 return device_limits::GetDeviceProcAddr(dev, funcName);
Chia-I Wu080cb7a2016-04-28 11:27:46 +0800812}
813
814VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
Chia-I Wu99860202016-04-28 14:01:30 +0800815 return device_limits::GetInstanceProcAddr(instance, funcName);
Chia-I Wu16489ac2016-04-28 11:21:49 +0800816}