blob: c54bf2335056f098b077c57343a708a93c6e1121 [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.
Courtney Goeltzenleuchter96cd7952015-10-30 11:14:30 -060022 *
23 * Author: Mark Lobodzinski <mark@lunarg.com>
24 * Author: Mike Stroyan <mike@LunarG.com>
25 * Author: Tobin Ehlis <tobin@lunarg.com>
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060026 */
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unordered_map>
32#include <memory>
33
34#include "vk_loader_platform.h"
35#include "vk_dispatch_table_helper.h"
36#include "vk_struct_string_helper_cpp.h"
37#if defined(__GNUC__)
38#pragma GCC diagnostic ignored "-Wwrite-strings"
39#endif
40#if defined(__GNUC__)
41#pragma GCC diagnostic warning "-Wwrite-strings"
42#endif
43#include "vk_struct_size_helper.h"
44#include "device_limits.h"
45#include "vk_layer_config.h"
46#include "vk_debug_marker_layer.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060047#include "vk_layer_table.h"
48#include "vk_layer_debug_marker_table.h"
49#include "vk_layer_data.h"
50#include "vk_layer_logging.h"
51#include "vk_layer_extension_utils.h"
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -060052#include "vk_layer_utils.h"
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060053
Tobin Ehlis84492ee2015-10-06 09:09:24 -060054struct devExts {
55 bool debug_marker_enabled;
56};
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060057
58// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop73bb6572015-09-28 15:09:32 -060059struct layer_data {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060060 debug_report_data *report_data;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -060061 std::vector<VkDbgMsgCallback> logging_callback;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060062 VkLayerDispatchTable* device_dispatch_table;
63 VkLayerInstanceDispatchTable* instance_dispatch_table;
64 devExts device_extensions;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060065 // Track state of each instance
66 unique_ptr<INSTANCE_STATE> instanceState;
67 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
68 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
69 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Tony Barbourafda27a2015-10-09 11:50:32 -060070 VkPhysicalDeviceProperties physicalDeviceProperties;
Tobin Ehlis84492ee2015-10-06 09:09:24 -060071 // Track physical device per logical device
72 VkPhysicalDevice physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060073 // Vector indices correspond to queueFamilyIndex
74 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop73bb6572015-09-28 15:09:32 -060075
76 layer_data() :
77 report_data(nullptr),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060078 device_dispatch_table(nullptr),
79 instance_dispatch_table(nullptr),
80 device_extensions(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060081 instanceState(nullptr),
82 physicalDeviceState(nullptr),
Tony Barbourafda27a2015-10-09 11:50:32 -060083 physicalDeviceProperties(),
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -060084 actualPhysicalDeviceFeatures(),
Tobin Ehlis84492ee2015-10-06 09:09:24 -060085 requestedPhysicalDeviceFeatures(),
86 physicalDevice()
Cody Northrop73bb6572015-09-28 15:09:32 -060087 {};
88};
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060089
Tobin Ehlis84492ee2015-10-06 09:09:24 -060090static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -060091
92static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
93
94// TODO : This can be much smarter, using separate locks for separate global data
95static int globalLockInitialized = 0;
96static loader_platform_thread_mutex globalLock;
97
98template layer_data *get_my_data_ptr<layer_data>(
99 void *data_key,
100 std::unordered_map<void *, layer_data *> &data_map);
101
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600102static void init_device_limits(layer_data *my_data)
103{
104 uint32_t report_flags = 0;
105 uint32_t debug_action = 0;
106 FILE *log_output = NULL;
107 const char *option_str;
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600108 VkDbgMsgCallback callback;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600109 // initialize DeviceLimits options
110 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
111 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
112
113 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
114 {
115 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb4b6e7c2015-09-15 09:55:54 -0600116 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600117 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback);
118 my_data->logging_callback.push_back(callback);
119 }
120
121 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
122 layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback);
123 my_data->logging_callback.push_back(callback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600124 }
125
126 if (!globalLockInitialized)
127 {
128 // TODO/TBD: Need to delete this mutex sometime. How??? One
129 // suggestion is to call this during vkCreateInstance(), and then we
130 // can clean it up during vkDestroyInstance(). However, that requires
131 // that the layer have per-instance locks. We need to come back and
132 // address this soon.
133 loader_platform_thread_create_mutex(&globalLock);
134 globalLockInitialized = 1;
135 }
136}
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600137/* DeviceLimits does not have any global extensions */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800138VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600139 const char *pLayerName,
140 uint32_t *pCount,
141 VkExtensionProperties* pProperties)
142{
143 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
144}
145
146static const VkLayerProperties dl_global_layers[] = {
147 {
148 "DeviceLimits",
149 VK_API_VERSION,
150 VK_MAKE_VERSION(0, 1, 0),
151 "Validation layer: Device Limits",
152 }
153};
154
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800155VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600156 uint32_t *pCount,
157 VkLayerProperties* pProperties)
158{
159 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
160 dl_global_layers,
161 pCount, pProperties);
162}
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600163
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800164VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkInstance* pInstance)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600165{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600166 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
167 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +0800168 VkResult result = pTable->CreateInstance(pCreateInfo, pAllocator, pInstance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600169
170 if (result == VK_SUCCESS) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600171 my_data->report_data = debug_report_create_instance(
172 pTable,
173 *pInstance,
Chia-I Wu763a7492015-10-26 20:48:51 +0800174 pCreateInfo->enabledExtensionNameCount,
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600175 pCreateInfo->ppEnabledExtensionNames);
176
177 init_device_limits(my_data);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600178 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600179 }
180 return result;
181}
182
183/* hook DestroyInstance to remove tableInstanceMap entry */
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800184VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600185{
186 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600187 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
188 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Chia-I Wu69f40122015-10-26 21:10:41 +0800189 pTable->DestroyInstance(instance, pAllocator);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600190
191 // Clean up logging callback, if any
Courtney Goeltzenleuchter7136d142015-10-05 14:51:41 -0600192 while (my_data->logging_callback.size() > 0) {
193 VkDbgMsgCallback callback = my_data->logging_callback.back();
194 layer_destroy_msg_callback(my_data->report_data, callback);
195 my_data->logging_callback.pop_back();
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600196 }
197
198 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600199 delete my_data->instance_dispatch_table;
200 layer_data_map.erase(key);
Tobin Ehlise6ab55a2015-10-07 09:38:40 -0600201 if (layer_data_map.empty()) {
202 // Release mutex when destroying last instance.
203 loader_platform_thread_delete_mutex(&globalLock);
204 globalLockInitialized = 0;
205 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600206}
207
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800208VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600209{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600210 VkBool32 skipCall = VK_FALSE;
211 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
212 if (my_data->instanceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600213 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
214 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600215 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600216 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600217 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600218 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600219 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 -0600220 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
221 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600222 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
223 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
224 "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 -0600225 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600226 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600227 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600228 if (skipCall)
229 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600230 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600231 if (NULL == pPhysicalDevices) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600232 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600233 } else { // Save physical devices
234 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600235 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
236 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
237 // Init actual features for each physical device
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600238 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tony Barbourafda27a2015-10-09 11:50:32 -0600239 my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600240 }
241 }
242 return result;
243 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600244 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -0800245 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", (uint64_t)instance);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600246 }
Courtney Goeltzenleuchter0abdb662015-10-07 13:28:58 -0600247 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600248}
249
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800250VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600251{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600252 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
253 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600254 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600255}
256
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800257VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600258{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600259 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
260 physicalDevice, format, pFormatProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600261}
262
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800263VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600264{
Chia-I Wu5202c542015-10-31 00:31:16 +0800265 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 -0600266}
267
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800268VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600269{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600270 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600271 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600272}
273
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800274VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600275{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600276 VkBool32 skipCall = VK_FALSE;
277 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
278 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600279 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600280 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600281 } else {
282 // 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 -0600283 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
284 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 -0600285 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
286 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600287 // Then verify that pCount that is passed in on second call matches what was returned
288 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
289 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
290 "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 -0600291 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600292 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600293 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600294 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600295 return;
296 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600297 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600298 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600299 } else { // Save queue family properties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600300 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600301 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600302 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600303 }
304 }
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600305 return;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600306 } else {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600307 log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
Michael Lentinecbc4a5e2015-11-03 16:19:46 -0800308 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", (uint64_t)physicalDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600309 }
310}
311
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800312VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600313{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600314 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600315}
316
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800317VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL 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 -0600318{
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600319 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 -0600320}
321
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800322VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetViewport(
Chia-I Wu1f851912015-10-27 18:04:07 +0800323 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600324 uint32_t viewportCount,
325 const VkViewport* pViewports)
326{
327 VkBool32 skipCall = VK_FALSE;
328 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
329 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800330 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
331 my_data->device_dispatch_table->CmdSetViewport(commandBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600332 }
333}
334
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800335VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdSetScissor(
Chia-I Wu1f851912015-10-27 18:04:07 +0800336 VkCommandBuffer commandBuffer,
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600337 uint32_t scissorCount,
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600338 const VkRect2D* pScissors)
339{
340 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter932cdb52015-09-21 11:44:06 -0600341 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
342 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600343 if (VK_FALSE == skipCall) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800344 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
345 my_data->device_dispatch_table->CmdSetScissor(commandBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter09772bb2015-09-17 15:06:17 -0600346 }
347}
348
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600349static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
350{
351 uint32_t i;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600352 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
353 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600354
Chia-I Wu763a7492015-10-26 20:48:51 +0800355 for (i = 0; i < pCreateInfo->enabledExtensionNameCount; i++) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600356 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
357 /* Found a matching extension name, mark it enabled and init dispatch table*/
358 initDebugMarkerTable(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600359 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600360 }
361
362 }
363}
364
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600365// Verify that features have been queried and verify that requested features are available
366static VkBool32 validate_features_request(layer_data *phy_dev_data)
367{
368 VkBool32 skipCall = VK_FALSE;
369 // Verify that all of the requested features are available
370 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
371 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
372 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
373 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
374 // Need to provide the struct member name with the issue. To do that seems like we'll
375 // have to loop through each struct member which should be done w/ codegen to keep in synch.
376 uint32_t errors = 0;
377 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
378 for (uint32_t i = 0; i < totalBools; i++) {
379 if (requested[i] > actual[i]) {
380 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",
381 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
382 errors++;
383 }
384 }
385 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
386 // If user didn't request features, notify them that they should
387 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",
388 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
389 }
Tobin Ehlis6454cd92015-09-29 11:22:37 -0600390 return skipCall;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600391}
392
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800393VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDevice* pDevice)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600394{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600395 VkBool32 skipCall = VK_FALSE;
396 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis76843842015-09-22 14:00:58 -0600397 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600398 if (!phy_dev_data->physicalDeviceState) {
399 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 -0600400 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600401 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
402 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 -0600403 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
404 } else {
405 // Check that the requested queue properties are valid
Courtney Goeltzenleuchterdfd53f52015-10-15 16:58:44 -0600406 for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) {
Tobin Ehlis76843842015-09-22 14:00:58 -0600407 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600408 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
409 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 -0600410 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Chia-I Wu763a7492015-10-26 20:48:51 +0800411 } else if (pCreateInfo->pRequestedQueues[i].queuePriorityCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600412 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 +0800413 "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 -0600414 }
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600415 }
416 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600417 // Check that any requested features are available
418 if (pCreateInfo->pEnabledFeatures) {
419 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
420 skipCall |= validate_features_request(phy_dev_data);
421 }
422 if (skipCall)
423 return VK_ERROR_VALIDATION_FAILED;
424
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600425 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800426 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pAllocator, pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600427 if (result == VK_SUCCESS) {
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600428 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600429 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600430 my_device_data->physicalDevice = gpu;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600431 }
432 return result;
433}
434
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800435VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600436{
437 // Free device lifetime allocations
438 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600439 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
Chia-I Wu69f40122015-10-26 21:10:41 +0800440 my_device_data->device_dispatch_table->DestroyDevice(device, pAllocator);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600441 tableDebugMarkerMap.erase(key);
442 delete my_device_data->device_dispatch_table;
443 layer_data_map.erase(key);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600444}
445
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800446VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkCommandPool* pCommandPool)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600447{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600448 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Chia-I Wu1f851912015-10-27 18:04:07 +0800449 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 -0600450 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600451}
452
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800453VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool commandPool, const VkAllocationCallbacks* pAllocator)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600454{
Chia-I Wu1f851912015-10-27 18:04:07 +0800455 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 -0600456}
457
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800458VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600459{
Chia-I Wu1f851912015-10-27 18:04:07 +0800460 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 -0600461 return result;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600462}
463
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800464VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pCreateInfo, VkCommandBuffer* pCommandBuffer)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600465{
Chia-I Wu1f851912015-10-27 18:04:07 +0800466 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 -0600467 return result;
468}
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600469
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800470VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t count, const VkCommandBuffer* pCommandBuffers)
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600471{
Chia-I Wu1f851912015-10-27 18:04:07 +0800472 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 -0600473}
474
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800475VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600476{
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600477 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600478 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
479 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600480 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
481 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
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",
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600483 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600484 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
485 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",
486 "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 -0600487 }
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600488 if (skipCall)
Courtney Goeltzenleuchter01d2ae12015-10-20 16:40:38 -0600489 return;
490 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600491}
492
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800493VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateImage(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600494 VkDevice device,
495 const VkImageCreateInfo *pCreateInfo,
Chia-I Wu1f851912015-10-27 18:04:07 +0800496 const VkAllocationCallbacks* pAllocator,
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600497 VkImage *pImage)
498{
499 VkBool32 skipCall = VK_FALSE;
500 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600501 VkImageFormatProperties ImageFormatProperties = {0};
502
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600503 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
504 VkPhysicalDevice physicalDevice = dev_data->physicalDevice;
505 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600506 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600507 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600508 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
509 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600510
Tony Barbourafda27a2015-10-09 11:50:32 -0600511 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600512 imageGranularity = imageGranularity == 1 ? 0 : imageGranularity;
513
514 if ((pCreateInfo->extent.depth > ImageFormatProperties.maxExtent.depth) ||
515 (pCreateInfo->extent.width > ImageFormatProperties.maxExtent.width) ||
516 (pCreateInfo->extent.height > ImageFormatProperties.maxExtent.height)) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600517 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
518 DEVLIMITS_LIMITS_VIOLATION, "DL",
519 "CreateImage extents exceed allowable limits for format: "
520 "Width = %d Height = %d Depth = %d: Limits for Width = %d Height = %d Depth = %d for format %s.",
521 pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth,
522 ImageFormatProperties.maxExtent.width, ImageFormatProperties.maxExtent.height, ImageFormatProperties.maxExtent.depth,
523 string_VkFormat(pCreateInfo->format));
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600524
525 }
526
527 uint64_t totalSize = ((uint64_t)pCreateInfo->extent.width *
528 (uint64_t)pCreateInfo->extent.height *
529 (uint64_t)pCreateInfo->extent.depth *
Courtney Goeltzenleuchter2ebc2342015-10-21 17:57:31 -0600530 (uint64_t)pCreateInfo->arrayLayers *
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600531 (uint64_t)pCreateInfo->samples *
532 (uint64_t)vk_format_get_size(pCreateInfo->format) +
533 (uint64_t)imageGranularity ) & ~(uint64_t)imageGranularity;
534
535 if (totalSize > ImageFormatProperties.maxResourceSize) {
Mark Lobodzinski806aa6a2015-10-06 11:59:54 -0600536 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, (uint64_t)pImage, 0,
537 DEVLIMITS_LIMITS_VIOLATION, "DL",
538 "CreateImage resource size exceeds allowable maximum "
539 "Image resource size = %#" PRIxLEAST64 ", maximum resource size = %#" PRIxLEAST64 " ",
540 totalSize, ImageFormatProperties.maxResourceSize);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600541 }
542 if (VK_FALSE == skipCall) {
Chia-I Wu69f40122015-10-26 21:10:41 +0800543 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pAllocator, pImage);
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600544 }
545 return result;
546}
547
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800548VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdUpdateBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800549 VkCommandBuffer commandBuffer,
550 VkBuffer dstBuffer,
551 VkDeviceSize dstOffset,
Mike Stroyan43909d82015-09-25 13:39:21 -0600552 VkDeviceSize dataSize,
553 const uint32_t* pData)
554{
Chia-I Wu1f851912015-10-27 18:04:07 +0800555 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600556
Chia-I Wu1f851912015-10-27 18:04:07 +0800557 // dstOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
558 if (dstOffset & 3) {
559 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600560 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 +0800561 "vkCmdUpdateBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600562 return;
563 }
564 }
565
566 // dataSize is the number of bytes to update, which must be a multiple of 4.
567 if (dataSize & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800568 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600569 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
570 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
571 return;
572 }
573 }
574
Chia-I Wu1f851912015-10-27 18:04:07 +0800575 dev_data->device_dispatch_table->CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
Mike Stroyan43909d82015-09-25 13:39:21 -0600576}
577
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800578VK_LAYER_EXPORT VKAPI_ATTR void VKAPI_CALL vkCmdFillBuffer(
Chia-I Wu1f851912015-10-27 18:04:07 +0800579 VkCommandBuffer commandBuffer,
580 VkBuffer dstBuffer,
581 VkDeviceSize dstOffset,
Chia-I Wu7e470702015-10-26 17:24:52 +0800582 VkDeviceSize size,
Mike Stroyan43909d82015-09-25 13:39:21 -0600583 uint32_t data)
584{
Chia-I Wu1f851912015-10-27 18:04:07 +0800585 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600586
Chia-I Wu1f851912015-10-27 18:04:07 +0800587 // dstOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
588 if (dstOffset & 3) {
589 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600590 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 +0800591 "vkCmdFillBuffer parameter, VkDeviceSize dstOffset, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600592 return;
593 }
594 }
595
Chia-I Wu7e470702015-10-26 17:24:52 +0800596 // size is the number of bytes to fill, which must be a multiple of 4.
597 if (size & 3) {
Chia-I Wu1f851912015-10-27 18:04:07 +0800598 layer_data *my_data = get_my_data_ptr(get_dispatch_key(commandBuffer), layer_data_map);
Mike Stroyan43909d82015-09-25 13:39:21 -0600599 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 +0800600 "vkCmdFillBuffer parameter, VkDeviceSize size, is not a multiple of 4")) {
Mike Stroyan43909d82015-09-25 13:39:21 -0600601 return;
602 }
603 }
604
Chia-I Wu1f851912015-10-27 18:04:07 +0800605 dev_data->device_dispatch_table->CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data);
Mike Stroyan43909d82015-09-25 13:39:21 -0600606}
607
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800608VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgCreateMsgCallback(
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600609 VkInstance instance,
610 VkFlags msgFlags,
611 const PFN_vkDbgMsgCallback pfnMsgCallback,
612 void* pUserData,
613 VkDbgMsgCallback* pMsgCallback)
614{
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600615 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
616 VkResult res = my_data->instance_dispatch_table->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600617 if (VK_SUCCESS == res) {
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600618 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
619 }
620 return res;
621}
622
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800623VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkDbgDestroyMsgCallback(
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600624 VkInstance instance,
625 VkDbgMsgCallback msgCallback)
626{
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600627 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600628 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600629 layer_destroy_msg_callback(my_data->report_data, msgCallback);
630 return res;
631}
632
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800633VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600634{
635 if (dev == NULL)
636 return NULL;
637
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600638 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600639 /* loader uses this to force layer initialization; device object is wrapped */
640 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600641 VkBaseLayerObject* wrapped_dev = (VkBaseLayerObject*) dev;
642 my_data = get_my_data_ptr(get_dispatch_key(wrapped_dev->baseObject), layer_data_map);
643 my_data->device_dispatch_table = new VkLayerDispatchTable;
644 layer_initialize_dispatch_table(my_data->device_dispatch_table, wrapped_dev);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600645 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
646 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600647 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600648 if (!strcmp(funcName, "vkCreateDevice"))
649 return (PFN_vkVoidFunction) vkCreateDevice;
650 if (!strcmp(funcName, "vkDestroyDevice"))
651 return (PFN_vkVoidFunction) vkDestroyDevice;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600652 if (!strcmp(funcName, "vkGetDeviceQueue"))
653 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinskiddaecf82015-09-22 09:33:21 -0600654 if (!strcmp(funcName, "vkCreateImage"))
655 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis8a10b1b2015-09-24 15:25:16 -0600656 if (!strcmp(funcName, "CreateCommandPool"))
657 return (PFN_vkVoidFunction) vkCreateCommandPool;
658 if (!strcmp(funcName, "DestroyCommandPool"))
659 return (PFN_vkVoidFunction) vkDestroyCommandPool;
660 if (!strcmp(funcName, "ResetCommandPool"))
661 return (PFN_vkVoidFunction) vkResetCommandPool;
Chia-I Wu1f851912015-10-27 18:04:07 +0800662 if (!strcmp(funcName, "vkAllocateCommandBuffers"))
663 return (PFN_vkVoidFunction) vkAllocateCommandBuffers;
Courtney Goeltzenleuchter831c1832015-10-23 14:21:05 -0600664 if (!strcmp(funcName, "vkFreeCommandBuffers"))
665 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyan43909d82015-09-25 13:39:21 -0600666 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
667 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
668 if (!strcmp(funcName, "vkCmdFillBuffer"))
669 return (PFN_vkVoidFunction) vkCmdFillBuffer;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600670
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600671 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600672 {
673 if (pTable->GetDeviceProcAddr == NULL)
674 return NULL;
675 return pTable->GetDeviceProcAddr(dev, funcName);
676 }
677}
678
Chia-I Wuaf9e4fd2015-11-06 06:42:02 +0800679VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600680{
681 PFN_vkVoidFunction fptr;
682 if (instance == NULL)
683 return NULL;
684
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600685 layer_data *my_data;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600686 /* loader uses this to force layer initialization; instance object is wrapped */
687 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600688 VkBaseLayerObject* wrapped_inst = (VkBaseLayerObject*) instance;
689 my_data = get_my_data_ptr(get_dispatch_key(wrapped_inst->baseObject), layer_data_map);
690 my_data->instance_dispatch_table = new VkLayerInstanceDispatchTable;
691 layer_init_instance_dispatch_table(my_data->instance_dispatch_table, wrapped_inst);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600692 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
693 }
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600694 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600695 if (!strcmp(funcName, "vkCreateInstance"))
696 return (PFN_vkVoidFunction) vkCreateInstance;
697 if (!strcmp(funcName, "vkDestroyInstance"))
698 return (PFN_vkVoidFunction) vkDestroyInstance;
699 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
700 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
701 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
702 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
703 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
704 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
705 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
706 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
707 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
708 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
709 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
710 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
711 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
712 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600713 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
714 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisc95fa8d2015-09-29 12:26:00 -0600715 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
716 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
717 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
718 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600719
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600720 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
721 if (fptr)
722 return fptr;
723
724 {
Tobin Ehlis84492ee2015-10-06 09:09:24 -0600725 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisc345b8b2015-09-03 09:50:06 -0600726 if (pTable->GetInstanceProcAddr == NULL)
727 return NULL;
728 return pTable->GetInstanceProcAddr(instance, funcName);
729 }
730}