blob: af9c6e9e1f4fb467958929fe44825be36ea38736 [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"
47#include "vk_layer_msg.h"
48#include "vk_layer_table.h"
49#include "vk_layer_debug_marker_table.h"
50#include "vk_layer_data.h"
51#include "vk_layer_logging.h"
52#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060053#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060054
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060055
56// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060057struct layer_data {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060058 debug_report_data *report_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060059 VkDbgMsgCallback logging_callback;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060060 // Track state of each instance
61 unique_ptr<INSTANCE_STATE> instanceState;
62 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
63 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
64 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
65 unique_ptr<VkPhysicalDeviceProperties> physicalDeviceProperties;
66 // Vector indices correspond to queueFamilyIndex
67 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060068
69 layer_data() :
70 report_data(nullptr),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060071 logging_callback(nullptr),
72 instanceState(nullptr),
73 physicalDeviceState(nullptr),
74 physicalDeviceProperties(nullptr),
75 actualPhysicalDeviceFeatures(),
76 requestedPhysicalDeviceFeatures()
Cody Northrop73bb6572015-09-28 15:09:32 -060077 {};
78};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060079
80static std::unordered_map<void *, layer_data *> layer_data_map;
81static device_table_map device_limits_device_table_map;
82static instance_table_map device_limits_instance_table_map;
83
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060084static unordered_map<VkDevice, VkPhysicalDevice> deviceMap;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060085
86struct devExts {
87 bool debug_marker_enabled;
88};
89
90static std::unordered_map<void *, struct devExts> deviceExtMap;
91
92static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
93
94// TODO : This can be much smarter, using separate locks for separate global data
95static int globalLockInitialized = 0;
96static loader_platform_thread_mutex globalLock;
97
98template layer_data *get_my_data_ptr<layer_data>(
99 void *data_key,
100 std::unordered_map<void *, layer_data *> &data_map);
101
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600102static void init_device_limits(layer_data *my_data)
103{
104 uint32_t report_flags = 0;
105 uint32_t debug_action = 0;
106 FILE *log_output = NULL;
107 const char *option_str;
108 // initialize DeviceLimits options
109 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
110 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
111
112 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
113 {
114 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -0600115 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600116 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
117 }
118
119 if (!globalLockInitialized)
120 {
121 // TODO/TBD: Need to delete this mutex sometime. How??? One
122 // suggestion is to call this during vkCreateInstance(), and then we
123 // can clean it up during vkDestroyInstance(). However, that requires
124 // that the layer have per-instance locks. We need to come back and
125 // address this soon.
126 loader_platform_thread_create_mutex(&globalLock);
127 globalLockInitialized = 1;
128 }
129}
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600130/* DeviceLimits does not have any global extensions */
131VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
132 const char *pLayerName,
133 uint32_t *pCount,
134 VkExtensionProperties* pProperties)
135{
136 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
137}
138
139static const VkLayerProperties dl_global_layers[] = {
140 {
141 "DeviceLimits",
142 VK_API_VERSION,
143 VK_MAKE_VERSION(0, 1, 0),
144 "Validation layer: Device Limits",
145 }
146};
147
148VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
149 uint32_t *pCount,
150 VkLayerProperties* pProperties)
151{
152 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
153 dl_global_layers,
154 pCount, pProperties);
155}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600156
157VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
158{
159 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map,*pInstance);
160 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
161
162 if (result == VK_SUCCESS) {
163 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
164 my_data->report_data = debug_report_create_instance(
165 pTable,
166 *pInstance,
167 pCreateInfo->extensionCount,
168 pCreateInfo->ppEnabledExtensionNames);
169
170 init_device_limits(my_data);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600171 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600172 }
173 return result;
174}
175
176/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600177VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600178{
179 dispatch_key key = get_dispatch_key(instance);
180 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600181 pTable->DestroyInstance(instance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600182
183 // Clean up logging callback, if any
184 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
185 if (my_data->logging_callback) {
186 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
187 }
188
189 layer_debug_report_destroy_instance(my_data->report_data);
190 layer_data_map.erase(pTable);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600191 my_data->instanceState.release();
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600192 device_limits_instance_table_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600193}
194
195VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
196{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600197 VkBool32 skipCall = VK_FALSE;
198 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
199 if (my_data->instanceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600200 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
201 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600202 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600203 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600204 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600205 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600206 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 -0600207 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
208 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600209 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
210 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
211 "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 -0600212 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600213 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600214 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600215 if (skipCall)
216 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600217 VkResult result = get_dispatch_table(device_limits_instance_table_map,instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
218 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600219 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600220 } else { // Save physical devices
221 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600222 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
223 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
224 // Init actual features for each physical device
225 get_dispatch_table(device_limits_instance_table_map,instance)->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600226 }
227 }
228 return result;
229 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600230 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 -0600231 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
232 }
233}
234
235VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
236{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600237 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
238 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
239 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600240 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600241}
242
243VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
244{
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600245 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties(
246 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600247 return result;
248}
249
Courtney Goeltzenleuchter83c95f82015-09-10 13:44:12 -0600250VK_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 -0600251{
Courtney Goeltzenleuchter83c95f82015-09-10 13:44:12 -0600252 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600253 return result;
254}
255
256VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
257{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600258 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600259 GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600260 if (VK_SUCCESS == result) {
261 // Save Properties
262 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
263 phy_dev_data->physicalDeviceProperties =
264 unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600265 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600266 return result;
267}
268
269VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
270{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600271 VkBool32 skipCall = VK_FALSE;
272 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
273 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600274 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600275 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600276 } else {
277 // 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 -0600278 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
279 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 -0600280 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
281 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600282 // Then verify that pCount that is passed in on second call matches what was returned
283 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
284 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
285 "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 -0600286 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600287 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600288 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600289 if (skipCall)
290 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600291 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
292 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600293 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600294 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600295 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600296 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600297 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600298 }
299 }
300 return result;
301 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600302 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 -0600303 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
304 }
305}
306
307VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
308{
309 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
310 return result;
311}
312
313VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
314{
315 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
316 return result;
317}
318
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600319VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
320 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600321 uint32_t viewportCount,
322 const VkViewport* pViewports)
323{
324 VkBool32 skipCall = VK_FALSE;
325 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
326 if (VK_FALSE == skipCall) {
327 get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
328 }
329}
330
331VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
332 VkCmdBuffer cmdBuffer,
333 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600334 const VkRect2D* pScissors)
335{
336 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600337 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
338 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600339 if (VK_FALSE == skipCall) {
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600340 get_dispatch_table(device_limits_device_table_map, cmdBuffer)->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600341 }
342}
343
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600344static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
345{
346 uint32_t i;
347 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
348 deviceExtMap[pDisp].debug_marker_enabled = false;
349
350 for (i = 0; i < pCreateInfo->extensionCount; i++) {
351 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
352 /* Found a matching extension name, mark it enabled and init dispatch table*/
353 initDebugMarkerTable(device);
354 deviceExtMap[pDisp].debug_marker_enabled = true;
355 }
356
357 }
358}
359
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600360// Verify that features have been queried and verify that requested features are available
361static VkBool32 validate_features_request(layer_data *phy_dev_data)
362{
363 VkBool32 skipCall = VK_FALSE;
364 // Verify that all of the requested features are available
365 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
366 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
367 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
368 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
369 // Need to provide the struct member name with the issue. To do that seems like we'll
370 // have to loop through each struct member which should be done w/ codegen to keep in synch.
371 uint32_t errors = 0;
372 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
373 for (uint32_t i = 0; i < totalBools; i++) {
374 if (requested[i] > actual[i]) {
375 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",
376 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
377 errors++;
378 }
379 }
380 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
381 // If user didn't request features, notify them that they should
382 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",
383 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
384 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600385 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600386}
387
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600388VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
389{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600390 VkBool32 skipCall = VK_FALSE;
391 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600392 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600393 if (!phy_dev_data->physicalDeviceState) {
394 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 -0600395 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600396 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
397 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 -0600398 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
399 } else {
400 // Check that the requested queue properties are valid
401 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
402 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600403 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
404 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 -0600405 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600406 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
407 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",
408 "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 -0600409 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600410 }
411 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600412 // Check that any requested features are available
413 if (pCreateInfo->pEnabledFeatures) {
414 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
415 skipCall |= validate_features_request(phy_dev_data);
416 }
417 if (skipCall)
418 return VK_ERROR_VALIDATION_FAILED;
419
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600420 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
421 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
422 if (result == VK_SUCCESS) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600423 VkLayerDispatchTable *pTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
424 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600425 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600426 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
427 deviceMap[*pDevice] = gpu;
428 }
429 return result;
430}
431
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600432VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600433{
434 // Free device lifetime allocations
435 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600436 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600437 pDisp->DestroyDevice(device);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600438 deviceExtMap.erase(pDisp);
439 device_limits_device_table_map.erase(key);
440 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600441}
442
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600443VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600444{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600445 // TODO : Verify that requested QueueFamilyIndex for this pool exists
446 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->CreateCommandPool(device, pCreateInfo, pCmdPool);
447 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600448}
449
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600450VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600451{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600452 get_dispatch_table(device_limits_device_table_map, device)->DestroyCommandPool(device, cmdPool);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600453}
454
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600455VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600456{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600457 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->ResetCommandPool(device, cmdPool, flags);
458 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600459}
460
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600461VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600462{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600463 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
464 return result;
465}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600466
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600467VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
468{
469
470 get_dispatch_table(device_limits_device_table_map, device)->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600471}
472
473VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
474{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600475 VkBool32 skipCall = VK_FALSE;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600476 VkPhysicalDevice gpu = deviceMap[device];
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600477 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
478 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
479 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 -0600480 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600481 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
482 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",
483 "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 -0600484 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600485 if (skipCall)
486 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600487 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
488 return result;
489}
490
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600491VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
492 VkDevice device,
493 const VkImageCreateInfo *pCreateInfo,
494 VkImage *pImage)
495{
496 VkBool32 skipCall = VK_FALSE;
497 VkResult result = VK_ERROR_VALIDATION_FAILED;
498 VkPhysicalDevice physicalDevice = deviceMap[device];
499 VkImageType type;
500 VkImageFormatProperties ImageFormatProperties = {0};
501
502 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
503 get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(
504 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
505 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
506
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600507 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
508 if (!phy_dev_data->physicalDeviceProperties) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600509 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
510 DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
511 "CreateImage called before querying device properties ");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600512 }
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600513
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600514 uint32_t imageGranularity = phy_dev_data->physicalDeviceProperties->limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600515 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
516
517 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
518 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
519 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600520 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
521 DEVLIMITS_LIMITS_VIOLATION, "DL",
522 "CreateImage extents exceed allowable limits for format: "
523 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
524 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
525 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
526 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600527
528 }
529
530 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
531 (uint64_t)pCreateInfo->extent.height *
532 (uint64_t)pCreateInfo->extent.depth *
533 (uint64_t)pCreateInfo->arraySize *
534 (uint64_t)pCreateInfo->samples *
535 (uint64_t)vk_format_get_size(pCreateInfo->format) +
536 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
537
538 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600539 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
540 DEVLIMITS_LIMITS_VIOLATION, "DL",
541 "CreateImage resource size exceeds allowable maximum "
542 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
543 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600544 }
545 if (VK_FALSE == skipCall) {
546 result = get_dispatch_table(device_limits_device_table_map, device)->CreateImage(device, pCreateInfo, pImage);
547 }
548 return result;
549}
550
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600551VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
552 VkInstance instance,
553 VkFlags msgFlags,
554 const PFN_vkDbgMsgCallback pfnMsgCallback,
555 void* pUserData,
556 VkDbgMsgCallback* pMsgCallback)
557{
558 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
559 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
560 if (VK_SUCCESS == res) {
561 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
562 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
563 }
564 return res;
565}
566
567VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
568 VkInstance instance,
569 VkDbgMsgCallback msgCallback)
570{
571 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
572 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
573 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
574 layer_destroy_msg_callback(my_data->report_data, msgCallback);
575 return res;
576}
577
578VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
579{
580 if (dev == NULL)
581 return NULL;
582
583 /* loader uses this to force layer initialization; device object is wrapped */
584 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
585 initDeviceTable(device_limits_device_table_map, (const VkBaseLayerObject *) dev);
586 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
587 }
588 if (!strcmp(funcName, "vkCreateDevice"))
589 return (PFN_vkVoidFunction) vkCreateDevice;
590 if (!strcmp(funcName, "vkDestroyDevice"))
591 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600592 if (!strcmp(funcName, "vkGetDeviceQueue"))
593 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600594 if (!strcmp(funcName, "vkCreateImage"))
595 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600596 if (!strcmp(funcName, "CreateCommandPool"))
597 return (PFN_vkVoidFunction) vkCreateCommandPool;
598 if (!strcmp(funcName, "DestroyCommandPool"))
599 return (PFN_vkVoidFunction) vkDestroyCommandPool;
600 if (!strcmp(funcName, "ResetCommandPool"))
601 return (PFN_vkVoidFunction) vkResetCommandPool;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600602 if (!strcmp(funcName, "vkCreateCommandBuffer"))
603 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600604 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
605 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600606
607 VkLayerDispatchTable* pTable = get_dispatch_table(device_limits_device_table_map, dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600608 {
609 if (pTable->GetDeviceProcAddr == NULL)
610 return NULL;
611 return pTable->GetDeviceProcAddr(dev, funcName);
612 }
613}
614
615VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
616{
617 PFN_vkVoidFunction fptr;
618 if (instance == NULL)
619 return NULL;
620
621 /* loader uses this to force layer initialization; instance object is wrapped */
622 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
623 initInstanceTable(device_limits_instance_table_map, (const VkBaseLayerObject *) instance);
624 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
625 }
626 if (!strcmp(funcName, "vkCreateInstance"))
627 return (PFN_vkVoidFunction) vkCreateInstance;
628 if (!strcmp(funcName, "vkDestroyInstance"))
629 return (PFN_vkVoidFunction) vkDestroyInstance;
630 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
631 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
632 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
633 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
634 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
635 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
636 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
637 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
638 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
639 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
640 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
641 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
642 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
643 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600644 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
645 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600646 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
647 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
648 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
649 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600650
651 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
652 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
653 if (fptr)
654 return fptr;
655
656 {
657 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(device_limits_instance_table_map, instance);
658 if (pTable->GetInstanceProcAddr == NULL)
659 return NULL;
660 return pTable->GetInstanceProcAddr(instance, funcName);
661 }
662}