blob: b8a2bc932bc183feb3a4ec73eae9643f8f966237 [file] [log] [blame]
Tobin Ehlisb5fc4fb2015-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 Ehlisb5fc4fb2015-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 Lobodzinski6f2274e2015-09-22 09:33:21 -060049#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060050
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060051struct devExts {
52 bool debug_marker_enabled;
53};
Tobin Ehlis9da65002015-09-24 15:25:16 -060054
55// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060056struct layer_data {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060057 debug_report_data *report_data;
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -060058 std::vector<VkDbgMsgCallback> logging_callback;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060059 VkLayerDispatchTable* device_dispatch_table;
60 VkLayerInstanceDispatchTable* instance_dispatch_table;
61 devExts device_extensions;
Tobin Ehlis9da65002015-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 Ehlis1cb7f572015-10-06 09:09:24 -060068 // Track physical device per logical device
69 VkPhysicalDevice physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -060070 // Vector indices correspond to queueFamilyIndex
71 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060072
73 layer_data() :
74 report_data(nullptr),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060075 device_dispatch_table(nullptr),
76 instance_dispatch_table(nullptr),
77 device_extensions(),
Tobin Ehlis9da65002015-09-24 15:25:16 -060078 instanceState(nullptr),
79 physicalDeviceState(nullptr),
80 physicalDeviceProperties(nullptr),
81 actualPhysicalDeviceFeatures(),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060082 requestedPhysicalDeviceFeatures(),
83 physicalDevice()
Cody Northrop55443ef2015-09-28 15:09:32 -060084 {};
85};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060086
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060087static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-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 Ehlisb5fc4fb2015-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 Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600105 VkDbgMsgCallback callback;
Tobin Ehlisb5fc4fb2015-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 Ehlisb1df55e2015-09-15 09:55:54 -0600113 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchterd6fce632015-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 Ehlisb5fc4fb2015-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 Ehlisfd3843f2015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600160
161VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
162{
Tobin Ehlis1cb7f572015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600165 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
166
167 if (result == VK_SUCCESS) {
Tobin Ehlisb5fc4fb2015-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 Ehlis9da65002015-09-24 15:25:16 -0600175 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600176 }
177 return result;
178}
179
180/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600181VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600182{
183 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-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 Lobodzinski2141f652015-09-07 13:59:43 -0600186 pTable->DestroyInstance(instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600187
188 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600193 }
194
195 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600196 delete my_data->instance_dispatch_table;
197 layer_data_map.erase(key);
Tobin Ehlis0b632332015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600203}
204
205VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
206{
Tobin Ehlis9da65002015-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 Ehlisb5fc4fb2015-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 Ehlis9da65002015-09-24 15:25:16 -0600212 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600213 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600214 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600215 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis9da65002015-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 Ehlisb5fc4fb2015-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 Ehlis9da65002015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600222 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600223 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600224 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600225 if (skipCall)
226 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600227 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600228 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600229 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600230 } else { // Save physical devices
231 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis9da65002015-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 Ehlis1cb7f572015-10-06 09:09:24 -0600235 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600236 }
237 }
238 return result;
239 } else {
Tobin Ehlis9da65002015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600241 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
242 }
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600243 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600244}
245
246VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
247{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600248 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
249 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600250 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600251 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600252}
253
254VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
255{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600256 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600257 physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600258 return result;
259}
260
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600261VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600262{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600263 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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600264 return result;
265}
266
267VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
268{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600269 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
270 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600271 if (VK_SUCCESS == result) {
272 // Save Properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600273 phy_dev_data->physicalDeviceProperties =
274 unique_ptr<VkPhysicalDeviceProperties>(new VkPhysicalDeviceProperties(*pProperties));
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600275 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600276 return result;
277}
278
279VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
280{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600281 VkBool32 skipCall = VK_FALSE;
282 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
283 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600284 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600285 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600286 } else {
287 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
Tobin Ehlis9da65002015-09-24 15:25:16 -0600288 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
289 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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600290 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
291 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600292 // Then verify that pCount that is passed in on second call matches what was returned
293 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
294 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
295 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600296 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600297 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600298 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600299 if (skipCall)
300 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600301 VkResult result = phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600302 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600303 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600304 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600305 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600306 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600307 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600308 }
309 }
310 return result;
311 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600312 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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600313 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
314 }
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600315 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600316}
317
318VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
319{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600320 VkResult result = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600321 return result;
322}
323
324VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
325{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600326 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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600327 return result;
328}
329
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600330VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
331 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600332 uint32_t viewportCount,
333 const VkViewport* pViewports)
334{
335 VkBool32 skipCall = VK_FALSE;
336 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
337 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600338 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
339 my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600340 }
341}
342
343VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
344 VkCmdBuffer cmdBuffer,
345 uint32_t scissorCount,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600346 const VkRect2D* pScissors)
347{
348 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600349 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
350 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600351 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600352 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
353 my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600354 }
355}
356
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600357static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
358{
359 uint32_t i;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600360 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
361 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600362
363 for (i = 0; i < pCreateInfo->extensionCount; i++) {
364 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
365 /* Found a matching extension name, mark it enabled and init dispatch table*/
366 initDebugMarkerTable(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600367 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600368 }
369
370 }
371}
372
Tobin Ehlis9da65002015-09-24 15:25:16 -0600373// Verify that features have been queried and verify that requested features are available
374static VkBool32 validate_features_request(layer_data *phy_dev_data)
375{
376 VkBool32 skipCall = VK_FALSE;
377 // Verify that all of the requested features are available
378 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
379 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
380 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
381 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
382 // Need to provide the struct member name with the issue. To do that seems like we'll
383 // have to loop through each struct member which should be done w/ codegen to keep in synch.
384 uint32_t errors = 0;
385 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
386 for (uint32_t i = 0; i < totalBools; i++) {
387 if (requested[i] > actual[i]) {
388 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",
389 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
390 errors++;
391 }
392 }
393 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
394 // If user didn't request features, notify them that they should
395 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",
396 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
397 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600398 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600399}
400
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600401VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
402{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600403 VkBool32 skipCall = VK_FALSE;
404 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600405 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600406 if (!phy_dev_data->physicalDeviceState) {
407 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 Ehlis54a6c182015-09-22 14:00:58 -0600408 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600409 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
410 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 Ehlis54a6c182015-09-22 14:00:58 -0600411 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
412 } else {
413 // Check that the requested queue properties are valid
414 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
415 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600416 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
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",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600418 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600419 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
420 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",
421 "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 Ehlis54a6c182015-09-22 14:00:58 -0600422 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600423 }
424 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600425 // Check that any requested features are available
426 if (pCreateInfo->pEnabledFeatures) {
427 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
428 skipCall |= validate_features_request(phy_dev_data);
429 }
430 if (skipCall)
431 return VK_ERROR_VALIDATION_FAILED;
432
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600433 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
434 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600435 if (result == VK_SUCCESS) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600436 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600437 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600438 my_device_data->physicalDevice = gpu;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600439 }
440 return result;
441}
442
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600443VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600444{
445 // Free device lifetime allocations
446 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600447 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
448 my_device_data->device_dispatch_table->DestroyDevice(device);
449 tableDebugMarkerMap.erase(key);
450 delete my_device_data->device_dispatch_table;
451 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600452}
453
Tobin Ehlis9da65002015-09-24 15:25:16 -0600454VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600455{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600456 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600457 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pCmdPool);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600458 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600459}
460
Tobin Ehlis9da65002015-09-24 15:25:16 -0600461VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600462{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600463 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600464}
465
Tobin Ehlis9da65002015-09-24 15:25:16 -0600466VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600467{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600468 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, cmdPool, flags);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600469 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600470}
471
Tobin Ehlis9da65002015-09-24 15:25:16 -0600472VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600473{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600474 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600475 return result;
476}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600477
Tobin Ehlis9da65002015-09-24 15:25:16 -0600478VK_LAYER_EXPORT void VKAPI vkDestroyCommandBuffer(VkDevice device, VkCmdBuffer commandBuffer)
479{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600480 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandBuffer(device, commandBuffer);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600481}
482
483VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
484{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600485 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600486 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
487 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600488 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
489 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
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",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600491 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600492 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
493 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",
494 "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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600495 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600496 if (skipCall)
497 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600498 VkResult result = dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600499 return result;
500}
501
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600502VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
503 VkDevice device,
504 const VkImageCreateInfo *pCreateInfo,
505 VkImage *pImage)
506{
507 VkBool32 skipCall = VK_FALSE;
508 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600509 VkImageFormatProperties ImageFormatProperties = {0};
510
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600511 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
512 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
513 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600514 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600515 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600516 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
517 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600518 if (!phy_dev_data->physicalDeviceProperties) {
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600519 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
520 DEVLIMITS_MUST_QUERY_PROPERTIES, "DL",
521 "CreateImage called before querying device properties ");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600522 }
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600523
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600524 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties->limits.bufferImageGranularity;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600525 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
526
527 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
528 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
529 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600530 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
531 DEVLIMITS_LIMITS_VIOLATION, "DL",
532 "CreateImage extents exceed allowable limits for format: "
533 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
534 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
535 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
536 string_VkFormat(pCreateInfo->format));
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600537
538 }
539
540 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
541 (uint64_t)pCreateInfo->extent.height *
542 (uint64_t)pCreateInfo->extent.depth *
543 (uint64_t)pCreateInfo->arraySize *
544 (uint64_t)pCreateInfo->samples *
545 (uint64_t)vk_format_get_size(pCreateInfo->format) +
546 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
547
548 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600549 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
550 DEVLIMITS_LIMITS_VIOLATION, "DL",
551 "CreateImage resource size exceeds allowable maximum "
552 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
553 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600554 }
555 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600556 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600557 }
558 return result;
559}
560
Mike Stroyana3082432015-09-25 13:39:21 -0600561VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
562 VkCmdBuffer cmdBuffer,
563 VkBuffer destBuffer,
564 VkDeviceSize destOffset,
565 VkDeviceSize dataSize,
566 const uint32_t* pData)
567{
568 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
569
570 // destOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
571 if (destOffset & 3) {
572 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
573 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
574 "vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
575 return;
576 }
577 }
578
579 // dataSize is the number of bytes to update, which must be a multiple of 4.
580 if (dataSize & 3) {
581 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
582 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
583 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
584 return;
585 }
586 }
587
588 dev_data->device_dispatch_table->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
589}
590
591VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
592 VkCmdBuffer cmdBuffer,
593 VkBuffer destBuffer,
594 VkDeviceSize destOffset,
595 VkDeviceSize fillSize,
596 uint32_t data)
597{
598 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
599
600 // destOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
601 if (destOffset & 3) {
602 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
603 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
604 "vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
605 return;
606 }
607 }
608
609 // fillSize is the number of bytes to fill, which must be a multiple of 4.
610 if (fillSize & 3) {
611 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
612 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
613 "vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4")) {
614 return;
615 }
616 }
617
618 dev_data->device_dispatch_table->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
619}
620
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600621VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
622 VkInstance instance,
623 VkFlags msgFlags,
624 const PFN_vkDbgMsgCallback pfnMsgCallback,
625 void* pUserData,
626 VkDbgMsgCallback* pMsgCallback)
627{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600628 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
629 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600630 if (VK_SUCCESS == res) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600631 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
632 }
633 return res;
634}
635
636VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
637 VkInstance instance,
638 VkDbgMsgCallback msgCallback)
639{
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600640 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600641 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600642 layer_destroy_msg_callback(my_data->report_data, msgCallback);
643 return res;
644}
645
646VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
647{
648 if (dev == NULL)
649 return NULL;
650
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600651 layer_data *my_data;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600652 /* loader uses this to force layer initialization; device object is wrapped */
653 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600654 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
655 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
656 my_data->device_dispatch_table = new VkLayerDispatchTable;
657 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600658 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
659 }
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600660 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600661 if (!strcmp(funcName, "vkCreateDevice"))
662 return (PFN_vkVoidFunction) vkCreateDevice;
663 if (!strcmp(funcName, "vkDestroyDevice"))
664 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600665 if (!strcmp(funcName, "vkGetDeviceQueue"))
666 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600667 if (!strcmp(funcName, "vkCreateImage"))
668 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600669 if (!strcmp(funcName, "CreateCommandPool"))
670 return (PFN_vkVoidFunction) vkCreateCommandPool;
671 if (!strcmp(funcName, "DestroyCommandPool"))
672 return (PFN_vkVoidFunction) vkDestroyCommandPool;
673 if (!strcmp(funcName, "ResetCommandPool"))
674 return (PFN_vkVoidFunction) vkResetCommandPool;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600675 if (!strcmp(funcName, "vkCreateCommandBuffer"))
676 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600677 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
678 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
Mike Stroyana3082432015-09-25 13:39:21 -0600679 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
680 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
681 if (!strcmp(funcName, "vkCmdFillBuffer"))
682 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600683
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600684 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600685 {
686 if (pTable->GetDeviceProcAddr == NULL)
687 return NULL;
688 return pTable->GetDeviceProcAddr(dev, funcName);
689 }
690}
691
692VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
693{
694 PFN_vkVoidFunction fptr;
695 if (instance == NULL)
696 return NULL;
697
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600698 layer_data *my_data;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600699 /* loader uses this to force layer initialization; instance object is wrapped */
700 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600701 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
702 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
703 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
704 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600705 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
706 }
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600707 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600708 if (!strcmp(funcName, "vkCreateInstance"))
709 return (PFN_vkVoidFunction) vkCreateInstance;
710 if (!strcmp(funcName, "vkDestroyInstance"))
711 return (PFN_vkVoidFunction) vkDestroyInstance;
712 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
713 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
714 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
715 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
716 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
717 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
718 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
719 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
720 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
721 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
722 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
723 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
724 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
725 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600726 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
727 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600728 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
729 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
730 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
731 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600732
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600733 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
734 if (fptr)
735 return fptr;
736
737 {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600738 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600739 if (pTable->GetInstanceProcAddr == NULL)
740 return NULL;
741 return pTable->GetInstanceProcAddr(instance, funcName);
742 }
743}