blob: 257a66965e17d0ac5cd9722aaffe9a0fa23df248 [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
Chia-I Wu1f851912015-10-27 18:04:07 +0800161VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600162{
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;
Chia-I Wu69f40122015-10-26 21:10:41 +0800165 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600166
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,
Chia-I Wu763a7492015-10-26 20:48:51 +0800171 pCreateInfo->enabledExtensionNameCount,
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600172 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 */
Chia-I Wu1f851912015-10-27 18:04:07 +0800181VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
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;
Chia-I Wu69f40122015-10-26 21:10:41 +0800186 pTable->DestroyInstance(instance, pAllocator);
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
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600247VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600248{
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;
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600251 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600252}
253
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600254VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600255{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600256 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
257 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600258}
259
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600260VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600261{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600262 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600263}
264
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600265VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600266{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600267 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600268 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600269}
270
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600271VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600272{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600273 VkBool32 skipCall = VK_FALSE;
274 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
275 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600276 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600277 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600278 } else {
279 // 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 -0600280 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
281 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 -0600282 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
283 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600284 // Then verify that pCount that is passed in on second call matches what was returned
285 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
286 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
287 "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 -0600288 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600289 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600290 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600291 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600292 return;
293 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600294 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600295 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600296 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600297 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600298 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600299 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600300 }
301 }
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600302 return;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600303 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600304 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 -0600305 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
306 }
307}
308
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600309VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600310{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600311 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600312}
313
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800314VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600315{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600316 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 -0600317}
318
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600319VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +0800320 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600321 uint32_t viewportCount,
322 const VkViewport* pViewports)
323{
324 VkBool32 skipCall = VK_FALSE;
325 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
326 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800327 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
328 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600329 }
330}
331
332VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +0800333 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600334 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600335 const VkRect2D* pScissors)
336{
337 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600338 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
339 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600340 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800341 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
342 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600343 }
344}
345
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600346static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
347{
348 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600349 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
350 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600351
Chia-I Wu763a7492015-10-26 20:48:51 +0800352 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600353 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
354 /* Found a matching extension name, mark it enabled and init dispatch table*/
355 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600356 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600357 }
358
359 }
360}
361
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600362// Verify that features have been queried and verify that requested features are available
363static VkBool32 validate_features_request(layer_data *phy_dev_data)
364{
365 VkBool32 skipCall = VK_FALSE;
366 // Verify that all of the requested features are available
367 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
368 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
369 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
370 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
371 // Need to provide the struct member name with the issue. To do that seems like we'll
372 // have to loop through each struct member which should be done w/ codegen to keep in synch.
373 uint32_t errors = 0;
374 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
375 for (uint32_t i = 0; i < totalBools; i++) {
376 if (requested[i] > actual[i]) {
377 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",
378 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
379 errors++;
380 }
381 }
382 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
383 // If user didn't request features, notify them that they should
384 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",
385 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
386 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600387 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600388}
389
Chia-I Wu1f851912015-10-27 18:04:07 +0800390VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600391{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600392 VkBool32 skipCall = VK_FALSE;
393 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600394 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600395 if (!phy_dev_data->physicalDeviceState) {
396 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 -0600397 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600398 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
399 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 -0600400 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
401 } else {
402 // Check that the requested queue properties are valid
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600403 for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) {
Tobin Ehlis76843842015-09-22 14:00:58 -0600404 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600405 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
406 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 -0600407 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Chia-I Wu763a7492015-10-26 20:48:51 +0800408 } else if (pCreateInfo->pRequestedQueues[i].queuePriorityCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600409 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",
Chia-I Wu763a7492015-10-26 20:48:51 +0800410 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queuePriorityCount is %u.", requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, pCreateInfo->pRequestedQueues[i].queuePriorityCount);
Tobin Ehlis76843842015-09-22 14:00:58 -0600411 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600412 }
413 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600414 // Check that any requested features are available
415 if (pCreateInfo->pEnabledFeatures) {
416 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
417 skipCall |= validate_features_request(phy_dev_data);
418 }
419 if (skipCall)
420 return VK_ERROR_VALIDATION_FAILED;
421
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600422 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800423 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600424 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600425 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600426 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600427 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600428 }
429 return result;
430}
431
Chia-I Wu1f851912015-10-27 18:04:07 +0800432VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600433{
434 // Free device lifetime allocations
435 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600436 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800437 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600438 tableDebugMarkerMap.erase(key);
439 delete my_device_data->device_dispatch_table;
440 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600441}
442
Chia-I Wu1f851912015-10-27 18:04:07 +0800443VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600444{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600445 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Chia-I Wu1f851912015-10-27 18:04:07 +0800446 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600447 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600448}
449
Chia-I Wu1f851912015-10-27 18:04:07 +0800450VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600451{
Chia-I Wu1f851912015-10-27 18:04:07 +0800452 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, commandPool, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600453}
454
Chia-I Wu1f851912015-10-27 18:04:07 +0800455VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600456{
Chia-I Wu1f851912015-10-27 18:04:07 +0800457 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, commandPool, flags);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600458 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600459}
460
Chia-I Wu1f851912015-10-27 18:04:07 +0800461VK_LAYER_EXPORT VkResult VKAPI vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600462{
Chia-I Wu1f851912015-10-27 18:04:07 +0800463 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->AllocateCommandBuffers(device, pCreateInfo, pCommandBuffer);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600464 return result;
465}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600466
Chia-I Wu1f851912015-10-27 18:04:07 +0800467VK_LAYER_EXPORT void VKAPI vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer* pCommandBuffers)
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600468{
Chia-I Wu1f851912015-10-27 18:04:07 +0800469 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->FreeCommandBuffers(device, commandPool, count, pCommandBuffers);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600470}
471
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600472VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600473{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600474 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600475 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
476 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600477 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
478 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
479 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600480 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600481 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
482 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
483 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600484 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600485 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600486 return;
487 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600488}
489
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600490VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
491 VkDevice device,
492 const VkImageCreateInfo *pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +0800493 const VkAllocationCallbacks* pAllocator,
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600494 VkImage *pImage)
495{
496 VkBool32 skipCall = VK_FALSE;
497 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600498 VkImageFormatProperties ImageFormatProperties = {0};
499
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600500 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
501 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
502 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600503 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600504 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600505 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
506 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600507
Tony Barbourafda27a2015-10-09 11:50:32 -0600508 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600509 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
510
511 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
512 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
513 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600514 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
515 DEVLIMITS_LIMITS_VIOLATION, "DL",
516 "CreateImage extents exceed allowable limits for format: "
517 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
518 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
519 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
520 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600521
522 }
523
524 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
525 (uint64_t)pCreateInfo->extent.height *
526 (uint64_t)pCreateInfo->extent.depth *
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600527 (uint64_t)pCreateInfo->arrayLayers *
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600528 (uint64_t)pCreateInfo->samples *
529 (uint64_t)vk_format_get_size(pCreateInfo->format) +
530 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
531
532 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600533 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
534 DEVLIMITS_LIMITS_VIOLATION, "DL",
535 "CreateImage resource size exceeds allowable maximum "
536 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
537 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600538 }
539 if (VK_FALSE == skipCall) {
Chia-I Wu69f40122015-10-26 21:10:41 +0800540 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600541 }
542 return result;
543}
544
Mike Stroyan43909d82015-09-25 13:39:21 -0600545VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800546 VkCommandBuffer commandBuffer,
547 VkBuffer dstBuffer,
548 VkDeviceSize dstOffset,
Mike Stroyan43909d82015-09-25 13:39:21 -0600549 VkDeviceSize dataSize,
550 const uint32_t* pData)
551{
Chia-I Wu1f851912015-10-27 18:04:07 +0800552 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600553
Chia-I Wu1f851912015-10-27 18:04:07 +0800554 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
555 if (dstOffset & 3) {
556 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600557 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
Chia-I Wu1f851912015-10-27 18:04:07 +0800558 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600559 return;
560 }
561 }
562
563 // dataSize is the number of bytes to update, which must be a multiple of 4.
564 if (dataSize & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800565 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600566 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
567 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
568 return;
569 }
570 }
571
Chia-I Wu1f851912015-10-27 18:04:07 +0800572 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyan43909d82015-09-25 13:39:21 -0600573}
574
575VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800576 VkCommandBuffer commandBuffer,
577 VkBuffer dstBuffer,
578 VkDeviceSize dstOffset,
Chia-I Wu7e470702015-10-26 17:24:52 +0800579 VkDeviceSize size,
Mike Stroyan43909d82015-09-25 13:39:21 -0600580 uint32_t data)
581{
Chia-I Wu1f851912015-10-27 18:04:07 +0800582 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600583
Chia-I Wu1f851912015-10-27 18:04:07 +0800584 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
585 if (dstOffset & 3) {
586 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600587 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
Chia-I Wu1f851912015-10-27 18:04:07 +0800588 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600589 return;
590 }
591 }
592
Chia-I Wu7e470702015-10-26 17:24:52 +0800593 // size is the number of bytes to fill, which must be a multiple of 4.
594 if (size & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800595 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600596 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
Chia-I Wu7e470702015-10-26 17:24:52 +0800597 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600598 return;
599 }
600 }
601
Chia-I Wu1f851912015-10-27 18:04:07 +0800602 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyan43909d82015-09-25 13:39:21 -0600603}
604
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600605VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
606 VkInstance instance,
607 VkFlags msgFlags,
608 const PFN_vkDbgMsgCallback pfnMsgCallback,
609 void* pUserData,
610 VkDbgMsgCallback* pMsgCallback)
611{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600612 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
613 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600614 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600615 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
616 }
617 return res;
618}
619
620VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
621 VkInstance instance,
622 VkDbgMsgCallback msgCallback)
623{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600624 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600625 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600626 layer_destroy_msg_callback(my_data->report_data, msgCallback);
627 return res;
628}
629
630VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
631{
632 if (dev == NULL)
633 return NULL;
634
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600635 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600636 /* loader uses this to force layer initialization; device object is wrapped */
637 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600638 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
639 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
640 my_data->device_dispatch_table = new VkLayerDispatchTable;
641 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600642 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
643 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600644 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600645 if (!strcmp(funcName, "vkCreateDevice"))
646 return (PFN_vkVoidFunction) vkCreateDevice;
647 if (!strcmp(funcName, "vkDestroyDevice"))
648 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600649 if (!strcmp(funcName, "vkGetDeviceQueue"))
650 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600651 if (!strcmp(funcName, "vkCreateImage"))
652 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600653 if (!strcmp(funcName, "CreateCommandPool"))
654 return (PFN_vkVoidFunction) vkCreateCommandPool;
655 if (!strcmp(funcName, "DestroyCommandPool"))
656 return (PFN_vkVoidFunction) vkDestroyCommandPool;
657 if (!strcmp(funcName, "ResetCommandPool"))
658 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +0800659 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
660 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600661 if (!strcmp(funcName, "vkFreeCommandBuffers"))
662 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyan43909d82015-09-25 13:39:21 -0600663 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
664 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
665 if (!strcmp(funcName, "vkCmdFillBuffer"))
666 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600667
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600668 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600669 {
670 if (pTable->GetDeviceProcAddr == NULL)
671 return NULL;
672 return pTable->GetDeviceProcAddr(dev, funcName);
673 }
674}
675
676VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
677{
678 PFN_vkVoidFunction fptr;
679 if (instance == NULL)
680 return NULL;
681
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600682 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600683 /* loader uses this to force layer initialization; instance object is wrapped */
684 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600685 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
686 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
687 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
688 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600689 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
690 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600691 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600692 if (!strcmp(funcName, "vkCreateInstance"))
693 return (PFN_vkVoidFunction) vkCreateInstance;
694 if (!strcmp(funcName, "vkDestroyInstance"))
695 return (PFN_vkVoidFunction) vkDestroyInstance;
696 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
697 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
698 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
699 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
700 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
701 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
702 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
703 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
704 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
705 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
706 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
707 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
708 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
709 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600710 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
711 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600712 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
713 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
714 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
715 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600716
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600717 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
718 if (fptr)
719 return fptr;
720
721 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600722 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600723 if (pTable->GetInstanceProcAddr == NULL)
724 return NULL;
725 return pTable->GetInstanceProcAddr(instance, funcName);
726 }
727}