blob: 32327b23129c9f75ae7fdb0630e46b7e6477582b [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"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060044#include "vk_layer_table.h"
45#include "vk_layer_debug_marker_table.h"
46#include "vk_layer_data.h"
47#include "vk_layer_logging.h"
48#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060049#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060050
Tobin Ehlis84492ee2015-10-06 09:09:24 -060051struct devExts {
52 bool debug_marker_enabled;
53};
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060054
55// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060056struct layer_data {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060057 debug_report_data *report_data;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -060058 std::vector<VkDbgMsgCallback> logging_callback;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060059 VkLayerDispatchTable* device_dispatch_table;
60 VkLayerInstanceDispatchTable* instance_dispatch_table;
61 devExts device_extensions;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060062 // Track state of each instance
63 unique_ptr<INSTANCE_STATE> instanceState;
64 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
65 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
66 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
67 unique_ptr<VkPhysicalDeviceProperties> physicalDeviceProperties;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060068 // Track physical device per logical device
69 VkPhysicalDevice physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060070 // Vector indices correspond to queueFamilyIndex
71 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060072
73 layer_data() :
74 report_data(nullptr),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060075 device_dispatch_table(nullptr),
76 instance_dispatch_table(nullptr),
77 device_extensions(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060078 instanceState(nullptr),
79 physicalDeviceState(nullptr),
80 physicalDeviceProperties(nullptr),
81 actualPhysicalDeviceFeatures(),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060082 requestedPhysicalDeviceFeatures(),
83 physicalDevice()
Cody Northrop73bb6572015-09-28 15:09:32 -060084 {};
85};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060086
Tobin Ehlis84492ee2015-10-06 09:09:24 -060087static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060088
89static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
90
91// TODO : This can be much smarter, using separate locks for separate global data
92static int globalLockInitialized = 0;
93static loader_platform_thread_mutex globalLock;
94
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060099static void init_device_limits(layer_data *my_data)
100{
101 uint32_t report_flags = 0;
102 uint32_t debug_action = 0;
103 FILE *log_output = NULL;
104 const char *option_str;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600105 VkDbgMsgCallback callback;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600106 // initialize DeviceLimits options
107 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
108 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
109
110 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
111 {
112 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -0600113 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600114 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback);
115 my_data->logging_callback.push_back(callback);
116 }
117
118 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
119 layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback);
120 my_data->logging_callback.push_back(callback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600121 }
122
123 if (!globalLockInitialized)
124 {
125 // TODO/TBD: Need to delete this mutex sometime. How??? One
126 // suggestion is to call this during vkCreateInstance(), and then we
127 // can clean it up during vkDestroyInstance(). However, that requires
128 // that the layer have per-instance locks. We need to come back and
129 // address this soon.
130 loader_platform_thread_create_mutex(&globalLock);
131 globalLockInitialized = 1;
132 }
133}
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600134/* DeviceLimits does not have any global extensions */
135VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
136 const char *pLayerName,
137 uint32_t *pCount,
138 VkExtensionProperties* pProperties)
139{
140 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
141}
142
143static const VkLayerProperties dl_global_layers[] = {
144 {
145 "DeviceLimits",
146 VK_API_VERSION,
147 VK_MAKE_VERSION(0, 1, 0),
148 "Validation layer: Device Limits",
149 }
150};
151
152VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
153 uint32_t *pCount,
154 VkLayerProperties* pProperties)
155{
156 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
157 dl_global_layers,
158 pCount, pProperties);
159}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600160
161VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
162{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600163 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
164 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600165 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
166
167 if (result == VK_SUCCESS) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600168 my_data->report_data = debug_report_create_instance(
169 pTable,
170 *pInstance,
171 pCreateInfo->extensionCount,
172 pCreateInfo->ppEnabledExtensionNames);
173
174 init_device_limits(my_data);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600175 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600176 }
177 return result;
178}
179
180/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600181VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600182{
183 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600184 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
185 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600186 pTable->DestroyInstance(instance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600187
188 // Clean up logging callback, if any
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600189 while (my_data->logging_callback.size() > 0) {
190 VkDbgMsgCallback callback = my_data->logging_callback.back();
191 layer_destroy_msg_callback(my_data->report_data, callback);
192 my_data->logging_callback.pop_back();
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600193 }
194
195 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600196 delete my_data->instance_dispatch_table;
197 layer_data_map.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600198 if (layer_data_map.empty()) {
199 // Release mutex when destroying last instance.
200 loader_platform_thread_delete_mutex(&globalLock);
201 globalLockInitialized = 0;
202 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600203}
204
205VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
206{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600207 VkBool32 skipCall = VK_FALSE;
208 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
209 if (my_data->instanceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600210 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
211 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600212 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600213 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600214 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600215 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600216 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 -0600217 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
218 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600219 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
220 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
221 "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 -0600222 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600223 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600224 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600225 if (skipCall)
226 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600227 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600228 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600229 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600230 } else { // Save physical devices
231 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600232 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
233 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
234 // Init actual features for each physical device
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600235 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600236 }
237 }
238 return result;
239 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600240 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 -0600241 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
242 }
243}
244
245VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
246{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600247 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
248 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600249 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600250 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600251}
252
253VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
254{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600255 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600256 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600257 return result;
258}
259
Courtney Goeltzenleuchter83c95f82015-09-10 13:44:12 -0600260VK_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 -0600261{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600262 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 -0600263 return result;
264}
265
266VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
267{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600268 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
269 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600270 if (VK_SUCCESS == result) {
271 // Save Properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600272 phy_dev_data->physicalDeviceProperties =
273 unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600274 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600275 return result;
276}
277
278VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
279{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600280 VkBool32 skipCall = VK_FALSE;
281 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
282 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600283 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600284 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600285 } else {
286 // 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 -0600287 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
288 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 -0600289 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
290 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600291 // Then verify that pCount that is passed in on second call matches what was returned
292 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
293 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
294 "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 -0600295 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600296 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600297 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600298 if (skipCall)
299 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600300 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600301 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600302 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600303 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600304 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600305 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600306 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600307 }
308 }
309 return result;
310 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600311 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 -0600312 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
313 }
314}
315
316VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
317{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600318 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 -0600319 return result;
320}
321
322VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
323{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600324 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 -0600325 return result;
326}
327
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600328VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
329 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600330 uint32_t viewportCount,
331 const VkViewport* pViewports)
332{
333 VkBool32 skipCall = VK_FALSE;
334 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
335 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600336 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
337 my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600338 }
339}
340
341VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
342 VkCmdBuffer cmdBuffer,
343 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600344 const VkRect2D* pScissors)
345{
346 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600347 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
348 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600349 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600350 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
351 my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600352 }
353}
354
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600355static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
356{
357 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600358 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
359 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600360
361 for (i = 0; i < pCreateInfo->extensionCount; i++) {
362 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
363 /* Found a matching extension name, mark it enabled and init dispatch table*/
364 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600365 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600366 }
367
368 }
369}
370
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600371// Verify that features have been queried and verify that requested features are available
372static VkBool32 validate_features_request(layer_data *phy_dev_data)
373{
374 VkBool32 skipCall = VK_FALSE;
375 // Verify that all of the requested features are available
376 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
377 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
378 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
379 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
380 // Need to provide the struct member name with the issue. To do that seems like we'll
381 // have to loop through each struct member which should be done w/ codegen to keep in synch.
382 uint32_t errors = 0;
383 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
384 for (uint32_t i = 0; i < totalBools; i++) {
385 if (requested[i] > actual[i]) {
386 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",
387 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
388 errors++;
389 }
390 }
391 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
392 // If user didn't request features, notify them that they should
393 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",
394 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
395 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600396 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600397}
398
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600399VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
400{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600401 VkBool32 skipCall = VK_FALSE;
402 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600403 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600404 if (!phy_dev_data->physicalDeviceState) {
405 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 -0600406 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600407 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
408 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 -0600409 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
410 } else {
411 // Check that the requested queue properties are valid
412 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
413 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600414 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
415 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 -0600416 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600417 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
418 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",
419 "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 -0600420 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600421 }
422 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600423 // Check that any requested features are available
424 if (pCreateInfo->pEnabledFeatures) {
425 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
426 skipCall |= validate_features_request(phy_dev_data);
427 }
428 if (skipCall)
429 return VK_ERROR_VALIDATION_FAILED;
430
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600431 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
432 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600433 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600434 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600435 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600436 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600437 }
438 return result;
439}
440
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600441VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600442{
443 // Free device lifetime allocations
444 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600445 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
446 my_device_data->device_dispatch_table->DestroyDevice(device);
447 tableDebugMarkerMap.erase(key);
448 delete my_device_data->device_dispatch_table;
449 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600450}
451
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600452VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600453{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600454 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600455 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 -0600456 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600457}
458
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600459VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600460{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600461 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600462}
463
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600464VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600465{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600466 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 -0600467 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600468}
469
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600470VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600471{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600472 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 -0600473 return result;
474}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600475
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600476VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
477{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600478 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600479}
480
481VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
482{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600483 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600484 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
485 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600486 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
487 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
488 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 -0600489 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600490 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
491 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",
492 "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 -0600493 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600494 if (skipCall)
495 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600496 VkResult result = dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600497 return result;
498}
499
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600500VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
501 VkDevice device,
502 const VkImageCreateInfo *pCreateInfo,
503 VkImage *pImage)
504{
505 VkBool32 skipCall = VK_FALSE;
506 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600507 VkImageType type;
508 VkImageFormatProperties ImageFormatProperties = {0};
509
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600510 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
511 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
512 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600513 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600514 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600515 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
516 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600517 if (!phy_dev_data->physicalDeviceProperties) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600518 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
519 DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
520 "CreateImage called before querying device properties ");
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600521 }
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600522
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600523 uint32_t imageGranularity = phy_dev_data->physicalDeviceProperties->limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600524 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
525
526 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
527 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
528 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600529 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
530 DEVLIMITS_LIMITS_VIOLATION, "DL",
531 "CreateImage extents exceed allowable limits for format: "
532 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
533 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
534 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
535 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600536
537 }
538
539 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
540 (uint64_t)pCreateInfo->extent.height *
541 (uint64_t)pCreateInfo->extent.depth *
542 (uint64_t)pCreateInfo->arraySize *
543 (uint64_t)pCreateInfo->samples *
544 (uint64_t)vk_format_get_size(pCreateInfo->format) +
545 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
546
547 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600548 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
549 DEVLIMITS_LIMITS_VIOLATION, "DL",
550 "CreateImage resource size exceeds allowable maximum "
551 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
552 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600553 }
554 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600555 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600556 }
557 return result;
558}
559
Mike Stroyan43909d82015-09-25 13:39:21 -0600560VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
561 VkCmdBuffer cmdBuffer,
562 VkBuffer destBuffer,
563 VkDeviceSize destOffset,
564 VkDeviceSize dataSize,
565 const uint32_t* pData)
566{
567 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
568
569 // destOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
570 if (destOffset & 3) {
571 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
572 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
573 "vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
574 return;
575 }
576 }
577
578 // dataSize is the number of bytes to update, which must be a multiple of 4.
579 if (dataSize & 3) {
580 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
581 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
582 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
583 return;
584 }
585 }
586
587 dev_data->device_dispatch_table->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
588}
589
590VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
591 VkCmdBuffer cmdBuffer,
592 VkBuffer destBuffer,
593 VkDeviceSize destOffset,
594 VkDeviceSize fillSize,
595 uint32_t data)
596{
597 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
598
599 // destOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
600 if (destOffset & 3) {
601 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
602 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
603 "vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
604 return;
605 }
606 }
607
608 // fillSize is the number of bytes to fill, which must be a multiple of 4.
609 if (fillSize & 3) {
610 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
611 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
612 "vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4")) {
613 return;
614 }
615 }
616
617 dev_data->device_dispatch_table->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
618}
619
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600620VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
621 VkInstance instance,
622 VkFlags msgFlags,
623 const PFN_vkDbgMsgCallback pfnMsgCallback,
624 void* pUserData,
625 VkDbgMsgCallback* pMsgCallback)
626{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600627 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
628 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600629 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600630 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
631 }
632 return res;
633}
634
635VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
636 VkInstance instance,
637 VkDbgMsgCallback msgCallback)
638{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600639 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600640 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600641 layer_destroy_msg_callback(my_data->report_data, msgCallback);
642 return res;
643}
644
645VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
646{
647 if (dev == NULL)
648 return NULL;
649
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600650 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600651 /* loader uses this to force layer initialization; device object is wrapped */
652 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600653 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
654 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
655 my_data->device_dispatch_table = new VkLayerDispatchTable;
656 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600657 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
658 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600659 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600660 if (!strcmp(funcName, "vkCreateDevice"))
661 return (PFN_vkVoidFunction) vkCreateDevice;
662 if (!strcmp(funcName, "vkDestroyDevice"))
663 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600664 if (!strcmp(funcName, "vkGetDeviceQueue"))
665 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600666 if (!strcmp(funcName, "vkCreateImage"))
667 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600668 if (!strcmp(funcName, "CreateCommandPool"))
669 return (PFN_vkVoidFunction) vkCreateCommandPool;
670 if (!strcmp(funcName, "DestroyCommandPool"))
671 return (PFN_vkVoidFunction) vkDestroyCommandPool;
672 if (!strcmp(funcName, "ResetCommandPool"))
673 return (PFN_vkVoidFunction) vkResetCommandPool;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600674 if (!strcmp(funcName, "vkCreateCommandBuffer"))
675 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600676 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
677 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Mike Stroyan43909d82015-09-25 13:39:21 -0600678 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
679 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
680 if (!strcmp(funcName, "vkCmdFillBuffer"))
681 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600682
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600683 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600684 {
685 if (pTable->GetDeviceProcAddr == NULL)
686 return NULL;
687 return pTable->GetDeviceProcAddr(dev, funcName);
688 }
689}
690
691VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
692{
693 PFN_vkVoidFunction fptr;
694 if (instance == NULL)
695 return NULL;
696
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600697 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600698 /* loader uses this to force layer initialization; instance object is wrapped */
699 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600700 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
701 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
702 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
703 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600704 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
705 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600706 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600707 if (!strcmp(funcName, "vkCreateInstance"))
708 return (PFN_vkVoidFunction) vkCreateInstance;
709 if (!strcmp(funcName, "vkDestroyInstance"))
710 return (PFN_vkVoidFunction) vkDestroyInstance;
711 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
712 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
713 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
714 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
715 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
716 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
717 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
718 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
719 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
720 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
721 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
722 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
723 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
724 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600725 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
726 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600727 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
728 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
729 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
730 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600731
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600732 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
733 if (fptr)
734 return fptr;
735
736 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600737 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600738 if (pTable->GetInstanceProcAddr == NULL)
739 return NULL;
740 return pTable->GetInstanceProcAddr(instance, funcName);
741 }
742}