blob: b991a86a499b675a1d0ebb887e437d28951b4e38 [file] [log] [blame]
Tobin Ehlisc345b8b2015-09-03 09:50:06 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29#include <memory>
30
31#include "vk_loader_platform.h"
32#include "vk_dispatch_table_helper.h"
33#include "vk_struct_string_helper_cpp.h"
34#if defined(__GNUC__)
35#pragma GCC diagnostic ignored "-Wwrite-strings"
36#endif
37#if defined(__GNUC__)
38#pragma GCC diagnostic warning "-Wwrite-strings"
39#endif
40#include "vk_struct_size_helper.h"
41#include "device_limits.h"
42#include "vk_layer_config.h"
43#include "vk_debug_marker_layer.h"
44// The following is #included again to catch certain OS-specific functions
45// being used:
46#include "vk_loader_platform.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060047#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
51#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060052#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060053
Tobin Ehlis84492ee2015-10-06 09:09:24 -060054struct devExts {
55 bool debug_marker_enabled;
56};
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060057
58// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060059struct layer_data {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060060 debug_report_data *report_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060061 VkDbgMsgCallback logging_callback;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060062 VkLayerDispatchTable* device_dispatch_table;
63 VkLayerInstanceDispatchTable* instance_dispatch_table;
64 devExts device_extensions;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060065 // Track state of each instance
66 unique_ptr<INSTANCE_STATE> instanceState;
67 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
68 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
69 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
70 unique_ptr<VkPhysicalDeviceProperties> physicalDeviceProperties;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060071 // Track physical device per logical device
72 VkPhysicalDevice physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060073 // Vector indices correspond to queueFamilyIndex
74 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060075
76 layer_data() :
77 report_data(nullptr),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060078 logging_callback(nullptr),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060079 device_dispatch_table(nullptr),
80 instance_dispatch_table(nullptr),
81 device_extensions(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060082 instanceState(nullptr),
83 physicalDeviceState(nullptr),
84 physicalDeviceProperties(nullptr),
85 actualPhysicalDeviceFeatures(),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060086 requestedPhysicalDeviceFeatures(),
87 physicalDevice()
Cody Northrop73bb6572015-09-28 15:09:32 -060088 {};
89};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060090
Tobin Ehlis84492ee2015-10-06 09:09:24 -060091static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060092
93static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
94
95// TODO : This can be much smarter, using separate locks for separate global data
96static int globalLockInitialized = 0;
97static loader_platform_thread_mutex globalLock;
98
99template layer_data *get_my_data_ptr<layer_data>(
100 void *data_key,
101 std::unordered_map<void *, layer_data *> &data_map);
102
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600103static void init_device_limits(layer_data *my_data)
104{
105 uint32_t report_flags = 0;
106 uint32_t debug_action = 0;
107 FILE *log_output = NULL;
108 const char *option_str;
109 // initialize DeviceLimits options
110 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
111 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
112
113 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
114 {
115 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -0600116 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600117 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
118 }
119
120 if (!globalLockInitialized)
121 {
122 // TODO/TBD: Need to delete this mutex sometime. How??? One
123 // suggestion is to call this during vkCreateInstance(), and then we
124 // can clean it up during vkDestroyInstance(). However, that requires
125 // that the layer have per-instance locks. We need to come back and
126 // address this soon.
127 loader_platform_thread_create_mutex(&globalLock);
128 globalLockInitialized = 1;
129 }
130}
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600131/* DeviceLimits does not have any global extensions */
132VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
133 const char *pLayerName,
134 uint32_t *pCount,
135 VkExtensionProperties* pProperties)
136{
137 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
138}
139
140static const VkLayerProperties dl_global_layers[] = {
141 {
142 "DeviceLimits",
143 VK_API_VERSION,
144 VK_MAKE_VERSION(0, 1, 0),
145 "Validation layer: Device Limits",
146 }
147};
148
149VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
150 uint32_t *pCount,
151 VkLayerProperties* pProperties)
152{
153 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
154 dl_global_layers,
155 pCount, pProperties);
156}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600157
158VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
159{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600160 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
161 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600162 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
163
164 if (result == VK_SUCCESS) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600165 my_data->report_data = debug_report_create_instance(
166 pTable,
167 *pInstance,
168 pCreateInfo->extensionCount,
169 pCreateInfo->ppEnabledExtensionNames);
170
171 init_device_limits(my_data);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600172 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600173 }
174 return result;
175}
176
177/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600178VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600179{
180 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600181 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
182 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600183 pTable->DestroyInstance(instance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600184
185 // Clean up logging callback, if any
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600186 if (my_data->logging_callback) {
187 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
188 }
189
190 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600191 delete my_data->instance_dispatch_table;
192 layer_data_map.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600193 if (layer_data_map.empty()) {
194 // Release mutex when destroying last instance.
195 loader_platform_thread_delete_mutex(&globalLock);
196 globalLockInitialized = 0;
197 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600198}
199
200VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
201{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600202 VkBool32 skipCall = VK_FALSE;
203 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
204 if (my_data->instanceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600205 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
206 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600207 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600208 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600209 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600210 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600211 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600212 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
213 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600214 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
215 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
216 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600217 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600218 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600219 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600220 if (skipCall)
221 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600222 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600223 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600224 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600225 } else { // Save physical devices
226 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600227 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
228 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
229 // Init actual features for each physical device
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600230 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600231 }
232 }
233 return result;
234 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600235 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600236 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
237 }
238}
239
240VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
241{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600242 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
243 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600244 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600245 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600246}
247
248VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
249{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600250 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600251 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600252 return result;
253}
254
Courtney Goeltzenleuchter83c95f82015-09-10 13:44:12 -0600255VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600256{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600257 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600258 return result;
259}
260
261VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
262{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600263 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
264 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600265 if (VK_SUCCESS == result) {
266 // Save Properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600267 phy_dev_data->physicalDeviceProperties =
268 unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600269 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600270 return result;
271}
272
273VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
274{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600275 VkBool32 skipCall = VK_FALSE;
276 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
277 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600278 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600279 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600280 } else {
281 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600282 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
283 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600284 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
285 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600286 // Then verify that pCount that is passed in on second call matches what was returned
287 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
288 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
289 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600290 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600291 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600292 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600293 if (skipCall)
294 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600295 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600296 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600297 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600298 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600299 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600300 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600301 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600302 }
303 }
304 return result;
305 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600306 log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600307 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
308 }
309}
310
311VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
312{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600313 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600314 return result;
315}
316
317VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
318{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600319 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600320 return result;
321}
322
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600323VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
324 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600325 uint32_t viewportCount,
326 const VkViewport* pViewports)
327{
328 VkBool32 skipCall = VK_FALSE;
329 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
330 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600331 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
332 my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600333 }
334}
335
336VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
337 VkCmdBuffer cmdBuffer,
338 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600339 const VkRect2D* pScissors)
340{
341 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600342 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
343 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600344 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600345 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
346 my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600347 }
348}
349
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600350static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
351{
352 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600353 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
354 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600355
356 for (i = 0; i < pCreateInfo->extensionCount; i++) {
357 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
358 /* Found a matching extension name, mark it enabled and init dispatch table*/
359 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600360 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600361 }
362
363 }
364}
365
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600366// Verify that features have been queried and verify that requested features are available
367static VkBool32 validate_features_request(layer_data *phy_dev_data)
368{
369 VkBool32 skipCall = VK_FALSE;
370 // Verify that all of the requested features are available
371 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
372 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
373 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
374 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
375 // Need to provide the struct member name with the issue. To do that seems like we'll
376 // have to loop through each struct member which should be done w/ codegen to keep in synch.
377 uint32_t errors = 0;
378 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
379 for (uint32_t i = 0; i < totalBools; i++) {
380 if (requested[i] > actual[i]) {
381 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
382 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
383 errors++;
384 }
385 }
386 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
387 // If user didn't request features, notify them that they should
388 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
389 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
390 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600391 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600392}
393
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600394VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
395{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600396 VkBool32 skipCall = VK_FALSE;
397 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600398 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600399 if (!phy_dev_data->physicalDeviceState) {
400 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlis76843842015-09-22 14:00:58 -0600401 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600402 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
403 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis76843842015-09-22 14:00:58 -0600404 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
405 } else {
406 // Check that the requested queue properties are valid
407 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
408 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600409 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
410 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis76843842015-09-22 14:00:58 -0600411 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600412 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
413 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
414 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, pCreateInfo->pRequestedQueues[i].queueCount);
Tobin Ehlis76843842015-09-22 14:00:58 -0600415 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600416 }
417 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600418 // Check that any requested features are available
419 if (pCreateInfo->pEnabledFeatures) {
420 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
421 skipCall |= validate_features_request(phy_dev_data);
422 }
423 if (skipCall)
424 return VK_ERROR_VALIDATION_FAILED;
425
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600426 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
427 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600428 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600429 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600430 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600431 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600432 }
433 return result;
434}
435
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600436VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600437{
438 // Free device lifetime allocations
439 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600440 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
441 my_device_data->device_dispatch_table->DestroyDevice(device);
442 tableDebugMarkerMap.erase(key);
443 delete my_device_data->device_dispatch_table;
444 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600445}
446
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600447VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600448{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600449 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600450 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pCmdPool);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600451 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600452}
453
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600454VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600455{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600456 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600457}
458
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600459VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600460{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600461 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, cmdPool, flags);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600462 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600463}
464
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600465VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600466{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600467 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600468 return result;
469}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600470
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600471VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
472{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600473 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600474}
475
476VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
477{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600478 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600479 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
480 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600481 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
482 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
483 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600484 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600485 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
486 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
487 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600488 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600489 if (skipCall)
490 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600491 VkResult result = dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600492 return result;
493}
494
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600495VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
496 VkDevice device,
497 const VkImageCreateInfo *pCreateInfo,
498 VkImage *pImage)
499{
500 VkBool32 skipCall = VK_FALSE;
501 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600502 VkImageType type;
503 VkImageFormatProperties ImageFormatProperties = {0};
504
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600505 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
506 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
507 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600508 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600509 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600510 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
511 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600512 if (!phy_dev_data->physicalDeviceProperties) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600513 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
514 DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
515 "CreateImage called before querying device properties ");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600516 }
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600517
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600518 uint32_t imageGranularity = phy_dev_data->physicalDeviceProperties->limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600519 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
520
521 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
522 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
523 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600524 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
525 DEVLIMITS_LIMITS_VIOLATION, "DL",
526 "CreateImage extents exceed allowable limits for format: "
527 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
528 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
529 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
530 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600531
532 }
533
534 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
535 (uint64_t)pCreateInfo->extent.height *
536 (uint64_t)pCreateInfo->extent.depth *
537 (uint64_t)pCreateInfo->arraySize *
538 (uint64_t)pCreateInfo->samples *
539 (uint64_t)vk_format_get_size(pCreateInfo->format) +
540 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
541
542 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600543 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
544 DEVLIMITS_LIMITS_VIOLATION, "DL",
545 "CreateImage resource size exceeds allowable maximum "
546 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
547 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600548 }
549 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600550 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600551 }
552 return result;
553}
554
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600555VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
556 VkInstance instance,
557 VkFlags msgFlags,
558 const PFN_vkDbgMsgCallback pfnMsgCallback,
559 void* pUserData,
560 VkDbgMsgCallback* pMsgCallback)
561{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600562 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
563 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600564 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600565 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
566 }
567 return res;
568}
569
570VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
571 VkInstance instance,
572 VkDbgMsgCallback msgCallback)
573{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600574 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600575 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600576 layer_destroy_msg_callback(my_data->report_data, msgCallback);
577 return res;
578}
579
580VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
581{
582 if (dev == NULL)
583 return NULL;
584
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600585 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600586 /* loader uses this to force layer initialization; device object is wrapped */
587 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600588 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
589 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
590 my_data->device_dispatch_table = new VkLayerDispatchTable;
591 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600592 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
593 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600594 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600595 if (!strcmp(funcName, "vkCreateDevice"))
596 return (PFN_vkVoidFunction) vkCreateDevice;
597 if (!strcmp(funcName, "vkDestroyDevice"))
598 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600599 if (!strcmp(funcName, "vkGetDeviceQueue"))
600 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600601 if (!strcmp(funcName, "vkCreateImage"))
602 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600603 if (!strcmp(funcName, "CreateCommandPool"))
604 return (PFN_vkVoidFunction) vkCreateCommandPool;
605 if (!strcmp(funcName, "DestroyCommandPool"))
606 return (PFN_vkVoidFunction) vkDestroyCommandPool;
607 if (!strcmp(funcName, "ResetCommandPool"))
608 return (PFN_vkVoidFunction) vkResetCommandPool;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600609 if (!strcmp(funcName, "vkCreateCommandBuffer"))
610 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600611 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
612 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600613
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600614 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600615 {
616 if (pTable->GetDeviceProcAddr == NULL)
617 return NULL;
618 return pTable->GetDeviceProcAddr(dev, funcName);
619 }
620}
621
622VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
623{
624 PFN_vkVoidFunction fptr;
625 if (instance == NULL)
626 return NULL;
627
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600628 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600629 /* loader uses this to force layer initialization; instance object is wrapped */
630 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600631 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
632 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
633 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
634 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600635 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
636 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600637 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600638 if (!strcmp(funcName, "vkCreateInstance"))
639 return (PFN_vkVoidFunction) vkCreateInstance;
640 if (!strcmp(funcName, "vkDestroyInstance"))
641 return (PFN_vkVoidFunction) vkDestroyInstance;
642 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
643 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
644 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
645 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
646 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
647 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
648 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
649 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
650 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
651 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
652 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
653 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
654 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
655 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600656 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
657 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600658 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
659 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
660 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
661 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600662
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600663 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
664 if (fptr)
665 return fptr;
666
667 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600668 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600669 if (pTable->GetInstanceProcAddr == NULL)
670 return NULL;
671 return pTable->GetInstanceProcAddr(instance, funcName);
672 }
673}