blob: 22eca9984bb0d6a405bcf6449786d026a0984455 [file] [log] [blame]
Tobin Ehlisc345b8b2015-09-03 09:50:06 -06001/*
Tobin Ehlisc345b8b2015-09-03 09:50:06 -06002 *
Courtney Goeltzenleuchter8a17da52015-10-29 13:50:34 -06003 * Copyright (C) 2015 Valve Corporation
Tobin Ehlisc345b8b2015-09-03 09:50:06 -06004 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <unordered_map>
28#include <memory>
29
30#include "vk_loader_platform.h"
31#include "vk_dispatch_table_helper.h"
32#include "vk_struct_string_helper_cpp.h"
33#if defined(__GNUC__)
34#pragma GCC diagnostic ignored "-Wwrite-strings"
35#endif
36#if defined(__GNUC__)
37#pragma GCC diagnostic warning "-Wwrite-strings"
38#endif
39#include "vk_struct_size_helper.h"
40#include "device_limits.h"
41#include "vk_layer_config.h"
42#include "vk_debug_marker_layer.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060043#include "vk_layer_table.h"
44#include "vk_layer_debug_marker_table.h"
45#include "vk_layer_data.h"
46#include "vk_layer_logging.h"
47#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060048#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060049
Tobin Ehlis84492ee2015-10-06 09:09:24 -060050struct devExts {
51 bool debug_marker_enabled;
52};
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060053
54// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060055struct layer_data {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060056 debug_report_data *report_data;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -060057 std::vector<VkDbgMsgCallback> logging_callback;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060058 VkLayerDispatchTable* device_dispatch_table;
59 VkLayerInstanceDispatchTable* instance_dispatch_table;
60 devExts device_extensions;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060061 // Track state of each instance
62 unique_ptr<INSTANCE_STATE> instanceState;
63 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
64 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
65 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Tony Barbourafda27a2015-10-09 11:50:32 -060066 VkPhysicalDeviceProperties physicalDeviceProperties;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060067 // Track physical device per logical device
68 VkPhysicalDevice physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060069 // Vector indices correspond to queueFamilyIndex
70 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060071
72 layer_data() :
73 report_data(nullptr),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060074 device_dispatch_table(nullptr),
75 instance_dispatch_table(nullptr),
76 device_extensions(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060077 instanceState(nullptr),
78 physicalDeviceState(nullptr),
Tony Barbourafda27a2015-10-09 11:50:32 -060079 physicalDeviceProperties(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060080 actualPhysicalDeviceFeatures(),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060081 requestedPhysicalDeviceFeatures(),
82 physicalDevice()
Cody Northrop73bb6572015-09-28 15:09:32 -060083 {};
84};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060085
Tobin Ehlis84492ee2015-10-06 09:09:24 -060086static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060087
88static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
89
90// TODO : This can be much smarter, using separate locks for separate global data
91static int globalLockInitialized = 0;
92static loader_platform_thread_mutex globalLock;
93
94template layer_data *get_my_data_ptr<layer_data>(
95 void *data_key,
96 std::unordered_map<void *, layer_data *> &data_map);
97
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060098static void init_device_limits(layer_data *my_data)
99{
100 uint32_t report_flags = 0;
101 uint32_t debug_action = 0;
102 FILE *log_output = NULL;
103 const char *option_str;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600104 VkDbgMsgCallback callback;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600105 // initialize DeviceLimits options
106 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
107 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
108
109 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
110 {
111 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -0600112 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600113 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback);
114 my_data->logging_callback.push_back(callback);
115 }
116
117 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
118 layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback);
119 my_data->logging_callback.push_back(callback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600120 }
121
122 if (!globalLockInitialized)
123 {
124 // TODO/TBD: Need to delete this mutex sometime. How??? One
125 // suggestion is to call this during vkCreateInstance(), and then we
126 // can clean it up during vkDestroyInstance(). However, that requires
127 // that the layer have per-instance locks. We need to come back and
128 // address this soon.
129 loader_platform_thread_create_mutex(&globalLock);
130 globalLockInitialized = 1;
131 }
132}
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600133/* DeviceLimits does not have any global extensions */
134VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
135 const char *pLayerName,
136 uint32_t *pCount,
137 VkExtensionProperties* pProperties)
138{
139 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
140}
141
142static const VkLayerProperties dl_global_layers[] = {
143 {
144 "DeviceLimits",
145 VK_API_VERSION,
146 VK_MAKE_VERSION(0, 1, 0),
147 "Validation layer: Device Limits",
148 }
149};
150
151VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
152 uint32_t *pCount,
153 VkLayerProperties* pProperties)
154{
155 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
156 dl_global_layers,
157 pCount, pProperties);
158}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600159
Chia-I Wu1f851912015-10-27 18:04:07 +0800160VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600161{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600162 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
163 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +0800164 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600165
166 if (result == VK_SUCCESS) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600167 my_data->report_data = debug_report_create_instance(
168 pTable,
169 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +0800170 pCreateInfo->enabledExtensionNameCount,
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600171 pCreateInfo->ppEnabledExtensionNames);
172
173 init_device_limits(my_data);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600174 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600175 }
176 return result;
177}
178
179/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wu1f851912015-10-27 18:04:07 +0800180VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600181{
182 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600183 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
184 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +0800185 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600186
187 // Clean up logging callback, if any
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600188 while (my_data->logging_callback.size() > 0) {
189 VkDbgMsgCallback callback = my_data->logging_callback.back();
190 layer_destroy_msg_callback(my_data->report_data, callback);
191 my_data->logging_callback.pop_back();
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600192 }
193
194 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600195 delete my_data->instance_dispatch_table;
196 layer_data_map.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600197 if (layer_data_map.empty()) {
198 // Release mutex when destroying last instance.
199 loader_platform_thread_delete_mutex(&globalLock);
200 globalLockInitialized = 0;
201 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600202}
203
204VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
205{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600206 VkBool32 skipCall = VK_FALSE;
207 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
208 if (my_data->instanceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600209 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
210 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600211 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600212 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600213 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600214 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600215 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 -0600216 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
217 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600218 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
219 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
220 "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 -0600221 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600222 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600223 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600224 if (skipCall)
225 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600226 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600227 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600228 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600229 } else { // Save physical devices
230 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600231 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
232 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
233 // Init actual features for each physical device
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600234 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tony Barbourafda27a2015-10-09 11:50:32 -0600235 my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600236 }
237 }
238 return result;
239 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600240 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600241 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
242 }
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -0600243 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600244}
245
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600246VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600247{
Tobin Ehlis8a10b1b2015-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;
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600250 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600251}
252
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600253VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600254{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600255 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
256 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600257}
258
Chia-I Wu5202c542015-10-31 00:31:16 +0800259VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600260{
Chia-I Wu5202c542015-10-31 00:31:16 +0800261 return 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 -0600262}
263
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600264VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600265{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600266 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600267 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600268}
269
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600270VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600271{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600272 VkBool32 skipCall = VK_FALSE;
273 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
274 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600275 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600276 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600277 } else {
278 // 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 -0600279 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
280 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 -0600281 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
282 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600283 // Then verify that pCount that is passed in on second call matches what was returned
284 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
285 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
286 "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 -0600287 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600288 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600289 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600290 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600291 return;
292 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600293 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600294 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600295 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600296 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600297 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600298 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600299 }
300 }
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600301 return;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600302 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600303 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 -0600304 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
305 }
306}
307
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600308VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600309{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600310 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600311}
312
Chia-I Wu3138d6a2015-10-31 00:31:16 +0800313VK_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 -0600314{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600315 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 -0600316}
317
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600318VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +0800319 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600320 uint32_t viewportCount,
321 const VkViewport* pViewports)
322{
323 VkBool32 skipCall = VK_FALSE;
324 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
325 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800326 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
327 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600328 }
329}
330
331VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +0800332 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600333 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600334 const VkRect2D* pScissors)
335{
336 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600337 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
338 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600339 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800340 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
341 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600342 }
343}
344
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600345static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
346{
347 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600348 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
349 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600350
Chia-I Wu763a7492015-10-26 20:48:51 +0800351 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600352 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
353 /* Found a matching extension name, mark it enabled and init dispatch table*/
354 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600355 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600356 }
357
358 }
359}
360
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600361// Verify that features have been queried and verify that requested features are available
362static VkBool32 validate_features_request(layer_data *phy_dev_data)
363{
364 VkBool32 skipCall = VK_FALSE;
365 // Verify that all of the requested features are available
366 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
367 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
368 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
369 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
370 // Need to provide the struct member name with the issue. To do that seems like we'll
371 // have to loop through each struct member which should be done w/ codegen to keep in synch.
372 uint32_t errors = 0;
373 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
374 for (uint32_t i = 0; i < totalBools; i++) {
375 if (requested[i] > actual[i]) {
376 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",
377 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
378 errors++;
379 }
380 }
381 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
382 // If user didn't request features, notify them that they should
383 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",
384 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
385 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600386 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600387}
388
Chia-I Wu1f851912015-10-27 18:04:07 +0800389VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600390{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600391 VkBool32 skipCall = VK_FALSE;
392 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600393 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600394 if (!phy_dev_data->physicalDeviceState) {
395 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 -0600396 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600397 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
398 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 -0600399 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
400 } else {
401 // Check that the requested queue properties are valid
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600402 for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) {
Tobin Ehlis76843842015-09-22 14:00:58 -0600403 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600404 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
405 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 -0600406 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Chia-I Wu763a7492015-10-26 20:48:51 +0800407 } else if (pCreateInfo->pRequestedQueues[i].queuePriorityCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600408 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 +0800409 "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 -0600410 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600411 }
412 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600413 // Check that any requested features are available
414 if (pCreateInfo->pEnabledFeatures) {
415 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
416 skipCall |= validate_features_request(phy_dev_data);
417 }
418 if (skipCall)
419 return VK_ERROR_VALIDATION_FAILED;
420
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600421 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800422 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600423 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600424 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600425 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600426 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600427 }
428 return result;
429}
430
Chia-I Wu1f851912015-10-27 18:04:07 +0800431VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600432{
433 // Free device lifetime allocations
434 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600435 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800436 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600437 tableDebugMarkerMap.erase(key);
438 delete my_device_data->device_dispatch_table;
439 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600440}
441
Chia-I Wu1f851912015-10-27 18:04:07 +0800442VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600443{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600444 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Chia-I Wu1f851912015-10-27 18:04:07 +0800445 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 -0600446 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600447}
448
Chia-I Wu1f851912015-10-27 18:04:07 +0800449VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600450{
Chia-I Wu1f851912015-10-27 18:04:07 +0800451 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 -0600452}
453
Chia-I Wu1f851912015-10-27 18:04:07 +0800454VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600455{
Chia-I Wu1f851912015-10-27 18:04:07 +0800456 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 -0600457 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600458}
459
Chia-I Wu1f851912015-10-27 18:04:07 +0800460VK_LAYER_EXPORT VkResult VKAPI vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600461{
Chia-I Wu1f851912015-10-27 18:04:07 +0800462 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 -0600463 return result;
464}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600465
Chia-I Wu1f851912015-10-27 18:04:07 +0800466VK_LAYER_EXPORT void VKAPI vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer* pCommandBuffers)
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600467{
Chia-I Wu1f851912015-10-27 18:04:07 +0800468 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 -0600469}
470
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600471VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600472{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600473 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600474 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
475 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600476 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
477 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
478 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 -0600479 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600480 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
481 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",
482 "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 -0600483 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600484 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600485 return;
486 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600487}
488
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600489VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
490 VkDevice device,
491 const VkImageCreateInfo *pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +0800492 const VkAllocationCallbacks* pAllocator,
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600493 VkImage *pImage)
494{
495 VkBool32 skipCall = VK_FALSE;
496 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600497 VkImageFormatProperties ImageFormatProperties = {0};
498
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600499 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
500 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
501 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600502 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600503 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600504 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
505 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600506
Tony Barbourafda27a2015-10-09 11:50:32 -0600507 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600508 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
509
510 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
511 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
512 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600513 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
514 DEVLIMITS_LIMITS_VIOLATION, "DL",
515 "CreateImage extents exceed allowable limits for format: "
516 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
517 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
518 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
519 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600520
521 }
522
523 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
524 (uint64_t)pCreateInfo->extent.height *
525 (uint64_t)pCreateInfo->extent.depth *
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600526 (uint64_t)pCreateInfo->arrayLayers *
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600527 (uint64_t)pCreateInfo->samples *
528 (uint64_t)vk_format_get_size(pCreateInfo->format) +
529 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
530
531 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600532 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
533 DEVLIMITS_LIMITS_VIOLATION, "DL",
534 "CreateImage resource size exceeds allowable maximum "
535 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
536 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600537 }
538 if (VK_FALSE == skipCall) {
Chia-I Wu69f40122015-10-26 21:10:41 +0800539 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600540 }
541 return result;
542}
543
Mike Stroyan43909d82015-09-25 13:39:21 -0600544VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800545 VkCommandBuffer commandBuffer,
546 VkBuffer dstBuffer,
547 VkDeviceSize dstOffset,
Mike Stroyan43909d82015-09-25 13:39:21 -0600548 VkDeviceSize dataSize,
549 const uint32_t* pData)
550{
Chia-I Wu1f851912015-10-27 18:04:07 +0800551 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600552
Chia-I Wu1f851912015-10-27 18:04:07 +0800553 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
554 if (dstOffset & 3) {
555 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600556 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 +0800557 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600558 return;
559 }
560 }
561
562 // dataSize is the number of bytes to update, which must be a multiple of 4.
563 if (dataSize & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800564 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600565 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
566 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
567 return;
568 }
569 }
570
Chia-I Wu1f851912015-10-27 18:04:07 +0800571 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyan43909d82015-09-25 13:39:21 -0600572}
573
574VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800575 VkCommandBuffer commandBuffer,
576 VkBuffer dstBuffer,
577 VkDeviceSize dstOffset,
Chia-I Wu7e470702015-10-26 17:24:52 +0800578 VkDeviceSize size,
Mike Stroyan43909d82015-09-25 13:39:21 -0600579 uint32_t data)
580{
Chia-I Wu1f851912015-10-27 18:04:07 +0800581 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600582
Chia-I Wu1f851912015-10-27 18:04:07 +0800583 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
584 if (dstOffset & 3) {
585 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600586 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 +0800587 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600588 return;
589 }
590 }
591
Chia-I Wu7e470702015-10-26 17:24:52 +0800592 // size is the number of bytes to fill, which must be a multiple of 4.
593 if (size & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800594 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600595 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 +0800596 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600597 return;
598 }
599 }
600
Chia-I Wu1f851912015-10-27 18:04:07 +0800601 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyan43909d82015-09-25 13:39:21 -0600602}
603
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600604VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
605 VkInstance instance,
606 VkFlags msgFlags,
607 const PFN_vkDbgMsgCallback pfnMsgCallback,
608 void* pUserData,
609 VkDbgMsgCallback* pMsgCallback)
610{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600611 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
612 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600613 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600614 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
615 }
616 return res;
617}
618
619VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
620 VkInstance instance,
621 VkDbgMsgCallback msgCallback)
622{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600623 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600624 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600625 layer_destroy_msg_callback(my_data->report_data, msgCallback);
626 return res;
627}
628
629VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
630{
631 if (dev == NULL)
632 return NULL;
633
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600634 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600635 /* loader uses this to force layer initialization; device object is wrapped */
636 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600637 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
638 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
639 my_data->device_dispatch_table = new VkLayerDispatchTable;
640 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600641 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
642 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600643 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600644 if (!strcmp(funcName, "vkCreateDevice"))
645 return (PFN_vkVoidFunction) vkCreateDevice;
646 if (!strcmp(funcName, "vkDestroyDevice"))
647 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600648 if (!strcmp(funcName, "vkGetDeviceQueue"))
649 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600650 if (!strcmp(funcName, "vkCreateImage"))
651 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600652 if (!strcmp(funcName, "CreateCommandPool"))
653 return (PFN_vkVoidFunction) vkCreateCommandPool;
654 if (!strcmp(funcName, "DestroyCommandPool"))
655 return (PFN_vkVoidFunction) vkDestroyCommandPool;
656 if (!strcmp(funcName, "ResetCommandPool"))
657 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +0800658 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
659 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600660 if (!strcmp(funcName, "vkFreeCommandBuffers"))
661 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyan43909d82015-09-25 13:39:21 -0600662 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
663 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
664 if (!strcmp(funcName, "vkCmdFillBuffer"))
665 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600666
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600667 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600668 {
669 if (pTable->GetDeviceProcAddr == NULL)
670 return NULL;
671 return pTable->GetDeviceProcAddr(dev, funcName);
672 }
673}
674
675VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
676{
677 PFN_vkVoidFunction fptr;
678 if (instance == NULL)
679 return NULL;
680
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600681 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600682 /* loader uses this to force layer initialization; instance object is wrapped */
683 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600684 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
685 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
686 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
687 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600688 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
689 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600690 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600691 if (!strcmp(funcName, "vkCreateInstance"))
692 return (PFN_vkVoidFunction) vkCreateInstance;
693 if (!strcmp(funcName, "vkDestroyInstance"))
694 return (PFN_vkVoidFunction) vkDestroyInstance;
695 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
696 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
697 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
698 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
699 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
700 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
701 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
702 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
703 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
704 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
705 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
706 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
707 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
708 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600709 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
710 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600711 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
712 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
713 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
714 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600715
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600716 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
717 if (fptr)
718 return fptr;
719
720 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600721 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600722 if (pTable->GetInstanceProcAddr == NULL)
723 return NULL;
724 return pTable->GetInstanceProcAddr(instance, funcName);
725 }
726}