blob: 1c3018b19658da3dd9e45cc2ffa6e701b31acbad [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;
Tony Barbourafda27a2015-10-09 11:50:32 -060067 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),
Tony Barbourafda27a2015-10-09 11:50:32 -060080 physicalDeviceProperties(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060081 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));
Tony Barbourafda27a2015-10-09 11:50:32 -0600236 my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600237 }
238 }
239 return result;
240 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600241 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 -0600242 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
243 }
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -0600244 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600245}
246
247VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
248{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600249 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
250 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600251 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600252 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600253}
254
255VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
256{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600257 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600258 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600259 return result;
260}
261
Courtney Goeltzenleuchter83c95f82015-09-10 13:44:12 -0600262VK_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 -0600263{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600264 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 -0600265 return result;
266}
267
268VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
269{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600270 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
271 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tony Barbourafda27a2015-10-09 11:50:32 -0600272
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600273 return result;
274}
275
276VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
277{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600278 VkBool32 skipCall = VK_FALSE;
279 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
280 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600281 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600282 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600283 } else {
284 // 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 -0600285 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
286 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 -0600287 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
288 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600289 // Then verify that pCount that is passed in on second call matches what was returned
290 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
291 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
292 "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 -0600293 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600294 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600295 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600296 if (skipCall)
297 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600298 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600299 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600300 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600301 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600302 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600303 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600304 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600305 }
306 }
307 return result;
308 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600309 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 -0600310 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
311 }
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -0600312 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600313}
314
315VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
316{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600317 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 -0600318 return result;
319}
320
321VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
322{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600323 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 -0600324 return result;
325}
326
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600327VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
328 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600329 uint32_t viewportCount,
330 const VkViewport* pViewports)
331{
332 VkBool32 skipCall = VK_FALSE;
333 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
334 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600335 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
336 my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600337 }
338}
339
340VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
341 VkCmdBuffer cmdBuffer,
342 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600343 const VkRect2D* pScissors)
344{
345 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600346 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
347 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600348 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600349 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
350 my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600351 }
352}
353
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600354static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
355{
356 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600357 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
358 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600359
360 for (i = 0; i < pCreateInfo->extensionCount; i++) {
361 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
362 /* Found a matching extension name, mark it enabled and init dispatch table*/
363 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600364 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600365 }
366
367 }
368}
369
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600370// Verify that features have been queried and verify that requested features are available
371static VkBool32 validate_features_request(layer_data *phy_dev_data)
372{
373 VkBool32 skipCall = VK_FALSE;
374 // Verify that all of the requested features are available
375 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
376 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
377 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
378 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
379 // Need to provide the struct member name with the issue. To do that seems like we'll
380 // have to loop through each struct member which should be done w/ codegen to keep in synch.
381 uint32_t errors = 0;
382 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
383 for (uint32_t i = 0; i < totalBools; i++) {
384 if (requested[i] > actual[i]) {
385 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",
386 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
387 errors++;
388 }
389 }
390 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
391 // If user didn't request features, notify them that they should
392 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",
393 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
394 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600395 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600396}
397
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600398VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
399{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600400 VkBool32 skipCall = VK_FALSE;
401 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600402 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600403 if (!phy_dev_data->physicalDeviceState) {
404 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 -0600405 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600406 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
407 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 -0600408 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
409 } else {
410 // Check that the requested queue properties are valid
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600411 for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) {
Tobin Ehlis76843842015-09-22 14:00:58 -0600412 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600413 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
414 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 -0600415 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600416 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
417 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",
418 "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 -0600419 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600420 }
421 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600422 // Check that any requested features are available
423 if (pCreateInfo->pEnabledFeatures) {
424 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
425 skipCall |= validate_features_request(phy_dev_data);
426 }
427 if (skipCall)
428 return VK_ERROR_VALIDATION_FAILED;
429
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600430 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
431 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600432 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600433 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600434 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600435 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600436 }
437 return result;
438}
439
Mark Lobodzinski67b42b72015-09-07 13:59:43 -0600440VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600441{
442 // Free device lifetime allocations
443 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600444 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
445 my_device_data->device_dispatch_table->DestroyDevice(device);
446 tableDebugMarkerMap.erase(key);
447 delete my_device_data->device_dispatch_table;
448 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600449}
450
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600451VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600452{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600453 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600454 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 -0600455 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600456}
457
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600458VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600459{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600460 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600461}
462
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600463VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600464{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600465 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 -0600466 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600467}
468
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600469VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600470{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600471 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 -0600472 return result;
473}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600474
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600475VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
476{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600477 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600478}
479
480VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
481{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600482 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600483 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
484 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600485 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
486 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
487 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 -0600488 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600489 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
490 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",
491 "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 -0600492 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600493 if (skipCall)
494 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600495 VkResult result = dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600496 return result;
497}
498
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600499VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
500 VkDevice device,
501 const VkImageCreateInfo *pCreateInfo,
502 VkImage *pImage)
503{
504 VkBool32 skipCall = VK_FALSE;
505 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600506 VkImageFormatProperties ImageFormatProperties = {0};
507
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600508 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
509 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
510 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600511 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600512 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600513 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
514 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600515
Tony Barbourafda27a2015-10-09 11:50:32 -0600516 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600517 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
518
519 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
520 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
521 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600522 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
523 DEVLIMITS_LIMITS_VIOLATION, "DL",
524 "CreateImage extents exceed allowable limits for format: "
525 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
526 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
527 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
528 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600529
530 }
531
532 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
533 (uint64_t)pCreateInfo->extent.height *
534 (uint64_t)pCreateInfo->extent.depth *
535 (uint64_t)pCreateInfo->arraySize *
536 (uint64_t)pCreateInfo->samples *
537 (uint64_t)vk_format_get_size(pCreateInfo->format) +
538 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
539
540 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600541 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
542 DEVLIMITS_LIMITS_VIOLATION, "DL",
543 "CreateImage resource size exceeds allowable maximum "
544 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
545 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600546 }
547 if (VK_FALSE == skipCall) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600548 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600549 }
550 return result;
551}
552
Mike Stroyan43909d82015-09-25 13:39:21 -0600553VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
554 VkCmdBuffer cmdBuffer,
555 VkBuffer destBuffer,
556 VkDeviceSize destOffset,
557 VkDeviceSize dataSize,
558 const uint32_t* pData)
559{
560 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
561
562 // destOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
563 if (destOffset & 3) {
564 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
565 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
566 "vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
567 return;
568 }
569 }
570
571 // dataSize is the number of bytes to update, which must be a multiple of 4.
572 if (dataSize & 3) {
573 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
574 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
575 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
576 return;
577 }
578 }
579
580 dev_data->device_dispatch_table->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
581}
582
583VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
584 VkCmdBuffer cmdBuffer,
585 VkBuffer destBuffer,
586 VkDeviceSize destOffset,
587 VkDeviceSize fillSize,
588 uint32_t data)
589{
590 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
591
592 // destOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
593 if (destOffset & 3) {
594 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
595 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
596 "vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
597 return;
598 }
599 }
600
601 // fillSize is the number of bytes to fill, which must be a multiple of 4.
602 if (fillSize & 3) {
603 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
604 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
605 "vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4")) {
606 return;
607 }
608 }
609
610 dev_data->device_dispatch_table->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
611}
612
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600613VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
614 VkInstance instance,
615 VkFlags msgFlags,
616 const PFN_vkDbgMsgCallback pfnMsgCallback,
617 void* pUserData,
618 VkDbgMsgCallback* pMsgCallback)
619{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600620 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
621 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600622 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600623 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
624 }
625 return res;
626}
627
628VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
629 VkInstance instance,
630 VkDbgMsgCallback msgCallback)
631{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600632 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600633 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600634 layer_destroy_msg_callback(my_data->report_data, msgCallback);
635 return res;
636}
637
638VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
639{
640 if (dev == NULL)
641 return NULL;
642
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600643 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600644 /* loader uses this to force layer initialization; device object is wrapped */
645 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600646 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
647 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
648 my_data->device_dispatch_table = new VkLayerDispatchTable;
649 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600650 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
651 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600652 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600653 if (!strcmp(funcName, "vkCreateDevice"))
654 return (PFN_vkVoidFunction) vkCreateDevice;
655 if (!strcmp(funcName, "vkDestroyDevice"))
656 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600657 if (!strcmp(funcName, "vkGetDeviceQueue"))
658 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600659 if (!strcmp(funcName, "vkCreateImage"))
660 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600661 if (!strcmp(funcName, "CreateCommandPool"))
662 return (PFN_vkVoidFunction) vkCreateCommandPool;
663 if (!strcmp(funcName, "DestroyCommandPool"))
664 return (PFN_vkVoidFunction) vkDestroyCommandPool;
665 if (!strcmp(funcName, "ResetCommandPool"))
666 return (PFN_vkVoidFunction) vkResetCommandPool;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600667 if (!strcmp(funcName, "vkCreateCommandBuffer"))
668 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600669 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
670 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Mike Stroyan43909d82015-09-25 13:39:21 -0600671 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
672 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
673 if (!strcmp(funcName, "vkCmdFillBuffer"))
674 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600675
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600676 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600677 {
678 if (pTable->GetDeviceProcAddr == NULL)
679 return NULL;
680 return pTable->GetDeviceProcAddr(dev, funcName);
681 }
682}
683
684VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
685{
686 PFN_vkVoidFunction fptr;
687 if (instance == NULL)
688 return NULL;
689
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600690 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600691 /* loader uses this to force layer initialization; instance object is wrapped */
692 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600693 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
694 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
695 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
696 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600697 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
698 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600699 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600700 if (!strcmp(funcName, "vkCreateInstance"))
701 return (PFN_vkVoidFunction) vkCreateInstance;
702 if (!strcmp(funcName, "vkDestroyInstance"))
703 return (PFN_vkVoidFunction) vkDestroyInstance;
704 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
705 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
706 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
707 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
708 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
709 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
710 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
711 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
712 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
713 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
714 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
715 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
716 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
717 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600718 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
719 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600720 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
721 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
722 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
723 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600724
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600725 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
726 if (fptr)
727 return fptr;
728
729 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600730 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600731 if (pTable->GetInstanceProcAddr == NULL)
732 return NULL;
733 return pTable->GetInstanceProcAddr(instance, funcName);
734 }
735}