blob: c311f5d6bd981b21e1f2f66905f55974cd369711 [file] [log] [blame]
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29#include <memory>
30
31#include "vk_loader_platform.h"
32#include "vk_dispatch_table_helper.h"
33#include "vk_struct_string_helper_cpp.h"
34#if defined(__GNUC__)
35#pragma GCC diagnostic ignored "-Wwrite-strings"
36#endif
37#if defined(__GNUC__)
38#pragma GCC diagnostic warning "-Wwrite-strings"
39#endif
40#include "vk_struct_size_helper.h"
41#include "device_limits.h"
42#include "vk_layer_config.h"
43#include "vk_debug_marker_layer.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060044#include "vk_layer_table.h"
45#include "vk_layer_debug_marker_table.h"
46#include "vk_layer_data.h"
47#include "vk_layer_logging.h"
48#include "vk_layer_extension_utils.h"
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060049#include "vk_layer_utils.h"
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060050
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060051struct devExts {
52 bool debug_marker_enabled;
53};
Tobin Ehlis9da65002015-09-24 15:25:16 -060054
55// This struct will be stored in a map hashed by the dispatchable object
Cody Northrop55443ef2015-09-28 15:09:32 -060056struct layer_data {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060057 debug_report_data *report_data;
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -060058 std::vector<VkDbgMsgCallback> logging_callback;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060059 VkLayerDispatchTable* device_dispatch_table;
60 VkLayerInstanceDispatchTable* instance_dispatch_table;
61 devExts device_extensions;
Tobin Ehlis9da65002015-09-24 15:25:16 -060062 // Track state of each instance
63 unique_ptr<INSTANCE_STATE> instanceState;
64 unique_ptr<PHYSICAL_DEVICE_STATE> physicalDeviceState;
65 VkPhysicalDeviceFeatures actualPhysicalDeviceFeatures;
66 VkPhysicalDeviceFeatures requestedPhysicalDeviceFeatures;
Tony Barbour1088c402015-10-09 11:50:32 -060067 VkPhysicalDeviceProperties physicalDeviceProperties;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060068 // Track physical device per logical device
69 VkPhysicalDevice physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -060070 // Vector indices correspond to queueFamilyIndex
71 vector<unique_ptr<VkQueueFamilyProperties>> queueFamilyProperties;
Cody Northrop55443ef2015-09-28 15:09:32 -060072
73 layer_data() :
74 report_data(nullptr),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060075 device_dispatch_table(nullptr),
76 instance_dispatch_table(nullptr),
77 device_extensions(),
Tobin Ehlis9da65002015-09-24 15:25:16 -060078 instanceState(nullptr),
79 physicalDeviceState(nullptr),
Tony Barbour1088c402015-10-09 11:50:32 -060080 physicalDeviceProperties(),
Tobin Ehlis9da65002015-09-24 15:25:16 -060081 actualPhysicalDeviceFeatures(),
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060082 requestedPhysicalDeviceFeatures(),
83 physicalDevice()
Cody Northrop55443ef2015-09-28 15:09:32 -060084 {};
85};
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060086
Tobin Ehlis1cb7f572015-10-06 09:09:24 -060087static unordered_map<void *, layer_data *> layer_data_map;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060088
89static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
90
91// TODO : This can be much smarter, using separate locks for separate global data
92static int globalLockInitialized = 0;
93static loader_platform_thread_mutex globalLock;
94
95template layer_data *get_my_data_ptr<layer_data>(
96 void *data_key,
97 std::unordered_map<void *, layer_data *> &data_map);
98
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -060099static void init_device_limits(layer_data *my_data)
100{
101 uint32_t report_flags = 0;
102 uint32_t debug_action = 0;
103 FILE *log_output = NULL;
104 const char *option_str;
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600105 VkDbgMsgCallback callback;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600106 // initialize DeviceLimits options
107 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
108 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
109
110 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
111 {
112 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -0600113 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600114 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &callback);
115 my_data->logging_callback.push_back(callback);
116 }
117
118 if (debug_action & VK_DBG_LAYER_ACTION_DEBUG_OUTPUT) {
119 layer_create_msg_callback(my_data->report_data, report_flags, win32_debug_output_msg, NULL, &callback);
120 my_data->logging_callback.push_back(callback);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600121 }
122
123 if (!globalLockInitialized)
124 {
125 // TODO/TBD: Need to delete this mutex sometime. How??? One
126 // suggestion is to call this during vkCreateInstance(), and then we
127 // can clean it up during vkDestroyInstance(). However, that requires
128 // that the layer have per-instance locks. We need to come back and
129 // address this soon.
130 loader_platform_thread_create_mutex(&globalLock);
131 globalLockInitialized = 1;
132 }
133}
Tobin Ehlisfd3843f2015-09-29 12:26:00 -0600134/* DeviceLimits does not have any global extensions */
135VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
136 const char *pLayerName,
137 uint32_t *pCount,
138 VkExtensionProperties* pProperties)
139{
140 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
141}
142
143static const VkLayerProperties dl_global_layers[] = {
144 {
145 "DeviceLimits",
146 VK_API_VERSION,
147 VK_MAKE_VERSION(0, 1, 0),
148 "Validation layer: Device Limits",
149 }
150};
151
152VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
153 uint32_t *pCount,
154 VkLayerProperties* pProperties)
155{
156 return util_GetLayerProperties(ARRAY_SIZE(dl_global_layers),
157 dl_global_layers,
158 pCount, pProperties);
159}
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600160
161VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
162{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600163 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
164 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600165 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
166
167 if (result == VK_SUCCESS) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600168 my_data->report_data = debug_report_create_instance(
169 pTable,
170 *pInstance,
171 pCreateInfo->extensionCount,
172 pCreateInfo->ppEnabledExtensionNames);
173
174 init_device_limits(my_data);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600175 my_data->instanceState = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600176 }
177 return result;
178}
179
180/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600181VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600182{
183 dispatch_key key = get_dispatch_key(instance);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600184 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
185 VkLayerInstanceDispatchTable *pTable = my_data->instance_dispatch_table;
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600186 pTable->DestroyInstance(instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600187
188 // Clean up logging callback, if any
Courtney Goeltzenleuchterd6fce632015-10-05 14:51:41 -0600189 while (my_data->logging_callback.size() > 0) {
190 VkDbgMsgCallback callback = my_data->logging_callback.back();
191 layer_destroy_msg_callback(my_data->report_data, callback);
192 my_data->logging_callback.pop_back();
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600193 }
194
195 layer_debug_report_destroy_instance(my_data->report_data);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600196 delete my_data->instance_dispatch_table;
197 layer_data_map.erase(key);
Tobin Ehlis0b632332015-10-07 09:38:40 -0600198 if (layer_data_map.empty()) {
199 // Release mutex when destroying last instance.
200 loader_platform_thread_delete_mutex(&globalLock);
201 globalLockInitialized = 0;
202 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600203}
204
205VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
206{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600207 VkBool32 skipCall = VK_FALSE;
208 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
209 if (my_data->instanceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600210 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
211 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600212 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600213 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600214 if (UNCALLED == my_data->instanceState->vkEnumeratePhysicalDevicesState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600215 // Flag error here, shouldn't be calling this without having queried count
Tobin Ehlis9da65002015-09-24 15:25:16 -0600216 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600217 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
218 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
Tobin Ehlis9da65002015-09-24 15:25:16 -0600219 else if (my_data->instanceState->physicalDevicesCount != *pPhysicalDeviceCount) {
220 skipCall |= log_msg(my_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
221 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, my_data->instanceState->physicalDevicesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600222 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600223 my_data->instanceState->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600224 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600225 if (skipCall)
226 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600227 VkResult result = my_data->instance_dispatch_table->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600228 if (NULL == pPhysicalDevices) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600229 my_data->instanceState->physicalDevicesCount = *pPhysicalDeviceCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600230 } else { // Save physical devices
231 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600232 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(pPhysicalDevices[i]), layer_data_map);
233 phy_dev_data->physicalDeviceState = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
234 // Init actual features for each physical device
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600235 my_data->instance_dispatch_table->GetPhysicalDeviceFeatures(pPhysicalDevices[i], &(phy_dev_data->actualPhysicalDeviceFeatures));
Tony Barbour1088c402015-10-09 11:50:32 -0600236 my_data->instance_dispatch_table->GetPhysicalDeviceProperties(pPhysicalDevices[i], &(phy_dev_data->physicalDeviceProperties));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600237 }
238 }
239 return result;
240 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600241 log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600242 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
243 }
Courtney Goeltzenleuchter58f3eff2015-10-07 13:28:58 -0600244 return VK_ERROR_VALIDATION_FAILED;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600245}
246
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600247VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600248{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600249 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
250 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState = QUERY_DETAILS;
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600251 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600252}
253
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600254VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600255{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600256 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceFormatProperties(
257 physicalDevice, format, pFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600258}
259
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600260VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600261{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600262 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600263}
264
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600265VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600266{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600267 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600268 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceProperties(physicalDevice, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600269}
270
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600271VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600272{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600273 VkBool32 skipCall = VK_FALSE;
274 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map);
275 if (phy_dev_data->physicalDeviceState) {
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600276 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600277 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600278 } else {
279 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
Tobin Ehlis9da65002015-09-24 15:25:16 -0600280 if (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
281 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600282 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
283 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600284 // Then verify that pCount that is passed in on second call matches what was returned
285 if (phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount != *pCount) {
286 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
287 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600288 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600289 phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600290 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600291 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600292 return;
293 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600294 if (NULL == pQueueFamilyProperties) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600295 phy_dev_data->physicalDeviceState->queueFamilyPropertiesCount = *pCount;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600296 } else { // Save queue family properties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600297 phy_dev_data->queueFamilyProperties.reserve(*pCount);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600298 for (uint32_t i=0; i < *pCount; i++) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600299 phy_dev_data->queueFamilyProperties.emplace_back(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600300 }
301 }
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600302 return;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600303 } else {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600304 log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600305 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
306 }
307}
308
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600309VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600310{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600311 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600312}
313
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600314VK_LAYER_EXPORT void VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600315{
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600316 get_my_data_ptr(get_dispatch_key(physicalDevice), layer_data_map)->instance_dispatch_table->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600317}
318
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600319VK_LAYER_EXPORT void VKAPI vkCmdSetViewport(
320 VkCmdBuffer cmdBuffer,
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600321 uint32_t viewportCount,
322 const VkViewport* pViewports)
323{
324 VkBool32 skipCall = VK_FALSE;
325 /* TODO: Verify viewportCount < maxViewports from VkPhysicalDeviceLimits */
326 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600327 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
328 my_data->device_dispatch_table->CmdSetViewport(cmdBuffer, viewportCount, pViewports);
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600329 }
330}
331
332VK_LAYER_EXPORT void VKAPI vkCmdSetScissor(
333 VkCmdBuffer cmdBuffer,
334 uint32_t scissorCount,
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600335 const VkRect2D* pScissors)
336{
337 VkBool32 skipCall = VK_FALSE;
Courtney Goeltzenleuchter078f8172015-09-21 11:44:06 -0600338 /* TODO: Verify scissorCount < maxViewports from VkPhysicalDeviceLimits */
339 /* TODO: viewportCount and scissorCount must match at draw time */
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600340 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600341 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
342 my_data->device_dispatch_table->CmdSetScissor(cmdBuffer, scissorCount, pScissors);
Courtney Goeltzenleuchter49c73082015-09-17 15:06:17 -0600343 }
344}
345
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600346static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
347{
348 uint32_t i;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600349 layer_data *my_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
350 my_data->device_extensions.debug_marker_enabled = false;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600351
352 for (i = 0; i < pCreateInfo->extensionCount; i++) {
353 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
354 /* Found a matching extension name, mark it enabled and init dispatch table*/
355 initDebugMarkerTable(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600356 my_data->device_extensions.debug_marker_enabled = true;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600357 }
358
359 }
360}
361
Tobin Ehlis9da65002015-09-24 15:25:16 -0600362// Verify that features have been queried and verify that requested features are available
363static VkBool32 validate_features_request(layer_data *phy_dev_data)
364{
365 VkBool32 skipCall = VK_FALSE;
366 // Verify that all of the requested features are available
367 // Get ptrs into actual and requested structs and if requested is 1 but actual is 0, request is invalid
368 VkBool32* actual = (VkBool32*)&(phy_dev_data->actualPhysicalDeviceFeatures);
369 VkBool32* requested = (VkBool32*)&(phy_dev_data->requestedPhysicalDeviceFeatures);
370 // TODO : This is a nice, compact way to loop through struct, but a bad way to report issues
371 // Need to provide the struct member name with the issue. To do that seems like we'll
372 // have to loop through each struct member which should be done w/ codegen to keep in synch.
373 uint32_t errors = 0;
374 uint32_t totalBools = sizeof(VkPhysicalDeviceFeatures)/sizeof(VkBool32);
375 for (uint32_t i = 0; i < totalBools; i++) {
376 if (requested[i] > actual[i]) {
377 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
378 "While calling vkCreateDevice(), requesting feature #%u in VkPhysicalDeviceFeatures struct, which is not available on this device.", i);
379 errors++;
380 }
381 }
382 if (errors && (UNCALLED == phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceFeaturesState)) {
383 // If user didn't request features, notify them that they should
384 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_FEATURE_REQUESTED, "DL",
385 "You requested features that are unavailable on this device. You should first query feature availability by calling vkGetPhysicalDeviceFeatures().");
386 }
Tobin Ehlis72b27cc2015-09-29 11:22:37 -0600387 return skipCall;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600388}
389
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600390VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
391{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600392 VkBool32 skipCall = VK_FALSE;
393 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600394 // First check is app has actually requested queueFamilyProperties
Tobin Ehlis9da65002015-09-24 15:25:16 -0600395 if (!phy_dev_data->physicalDeviceState) {
396 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600397 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
Tobin Ehlis9da65002015-09-24 15:25:16 -0600398 } else if (QUERY_DETAILS != phy_dev_data->physicalDeviceState->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
399 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600400 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
401 } else {
402 // Check that the requested queue properties are valid
Courtney Goeltzenleuchter7831e962015-10-15 16:58:44 -0600403 for (uint32_t i=0; i<pCreateInfo->requestedQueueCount; i++) {
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600404 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600405 if (phy_dev_data->queueFamilyProperties.size() <= requestedIndex) { // requested index is out of bounds for this physical device
406 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600407 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600408 } else if (pCreateInfo->pRequestedQueues[i].queueCount > phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount) {
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",
410 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, phy_dev_data->queueFamilyProperties[requestedIndex]->queueCount, pCreateInfo->pRequestedQueues[i].queueCount);
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600411 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600412 }
413 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600414 // Check that any requested features are available
415 if (pCreateInfo->pEnabledFeatures) {
416 phy_dev_data->requestedPhysicalDeviceFeatures = *(pCreateInfo->pEnabledFeatures);
417 skipCall |= validate_features_request(phy_dev_data);
418 }
419 if (skipCall)
420 return VK_ERROR_VALIDATION_FAILED;
421
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600422 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
423 VkResult result = my_device_data->device_dispatch_table->CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600424 if (result == VK_SUCCESS) {
Tobin Ehlis9da65002015-09-24 15:25:16 -0600425 my_device_data->report_data = layer_debug_report_create_device(phy_dev_data->report_data, *pDevice);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600426 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600427 my_device_data->physicalDevice = gpu;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600428 }
429 return result;
430}
431
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600432VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600433{
434 // Free device lifetime allocations
435 dispatch_key key = get_dispatch_key(device);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600436 layer_data *my_device_data = get_my_data_ptr(key, layer_data_map);
437 my_device_data->device_dispatch_table->DestroyDevice(device);
438 tableDebugMarkerMap.erase(key);
439 delete my_device_data->device_dispatch_table;
440 layer_data_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600441}
442
Tobin Ehlis9da65002015-09-24 15:25:16 -0600443VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandPool(VkDevice device, const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600444{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600445 // TODO : Verify that requested QueueFamilyIndex for this pool exists
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600446 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->CreateCommandPool(device, pCreateInfo, pCmdPool);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600447 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600448}
449
Tobin Ehlis9da65002015-09-24 15:25:16 -0600450VK_LAYER_EXPORT void VKAPI vkDestroyCommandPool(VkDevice device, VkCmdPool cmdPool)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600451{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600452 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->DestroyCommandPool(device, cmdPool);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600453}
454
Tobin Ehlis9da65002015-09-24 15:25:16 -0600455VK_LAYER_EXPORT VkResult VKAPI vkResetCommandPool(VkDevice device, VkCmdPool cmdPool, VkCmdPoolResetFlags flags)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600456{
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600457 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->ResetCommandPool(device, cmdPool, flags);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600458 return result;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600459}
460
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600461VK_LAYER_EXPORT VkResult VKAPI vkAllocCommandBuffers(VkDevice device, const VkCmdBufferAllocInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600462{
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600463 VkResult result = get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->AllocCommandBuffers(device, pCreateInfo, pCmdBuffer);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600464 return result;
465}
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600466
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600467VK_LAYER_EXPORT void VKAPI vkFreeCommandBuffers(VkDevice device, VkCmdPool cmdPool, uint32_t count, const VkCmdBuffer* pCommandBuffers)
Tobin Ehlis9da65002015-09-24 15:25:16 -0600468{
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600469 get_my_data_ptr(get_dispatch_key(device), layer_data_map)->device_dispatch_table->FreeCommandBuffers(device, cmdPool, count, pCommandBuffers);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600470}
471
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600472VK_LAYER_EXPORT void VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600473{
Tobin Ehlis9da65002015-09-24 15:25:16 -0600474 VkBool32 skipCall = VK_FALSE;
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600475 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(device), layer_data_map);
476 VkPhysicalDevice gpu = dev_data->physicalDevice;
Tobin Ehlis9da65002015-09-24 15:25:16 -0600477 layer_data *phy_dev_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
478 if (queueFamilyIndex >= phy_dev_data->queueFamilyProperties.size()) { // requested index is out of bounds for this physical device
479 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600480 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
Tobin Ehlis9da65002015-09-24 15:25:16 -0600481 } else if (queueIndex >= phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount) {
482 skipCall |= log_msg(phy_dev_data->report_data, VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
483 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, phy_dev_data->queueFamilyProperties[queueFamilyIndex]->queueCount, queueIndex);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600484 }
Tobin Ehlis9da65002015-09-24 15:25:16 -0600485 if (skipCall)
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -0600486 return;
487 dev_data->device_dispatch_table->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600488}
489
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600490VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
491 VkDevice device,
492 const VkImageCreateInfo *pCreateInfo,
493 VkImage *pImage)
494{
495 VkBool32 skipCall = VK_FALSE;
496 VkResult result = VK_ERROR_VALIDATION_FAILED;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600497 VkImageFormatProperties ImageFormatProperties = {0};
498
Tobin Ehlis1cb7f572015-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 Lobodzinski6f2274e2015-09-22 09:33:21 -0600502 // Internal call to get format info. Still goes through layers, could potentially go directly to ICD.
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600503 phy_dev_data->instance_dispatch_table->GetPhysicalDeviceImageFormatProperties(
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600504 physicalDevice, pCreateInfo->format, pCreateInfo->imageType, pCreateInfo->tiling,
505 pCreateInfo->usage, pCreateInfo->flags, &ImageFormatProperties);
Mark Lobodzinskifbb130e2015-10-06 11:59:54 -0600506
Tony Barbour1088c402015-10-09 11:50:32 -0600507 VkDeviceSize imageGranularity = phy_dev_data->physicalDeviceProperties.limits.bufferImageGranularity;
Mark Lobodzinski6f2274e2015-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 Lobodzinskifbb130e2015-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 Lobodzinski6f2274e2015-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 Goeltzenleuchter5d2aed42015-10-21 17:57:31 -0600526 (uint64_t)pCreateInfo->arrayLayers *
Mark Lobodzinski6f2274e2015-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 Lobodzinskifbb130e2015-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 Lobodzinski6f2274e2015-09-22 09:33:21 -0600537 }
538 if (VK_FALSE == skipCall) {
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600539 result = dev_data->device_dispatch_table->CreateImage(device, pCreateInfo, pImage);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600540 }
541 return result;
542}
543
Mike Stroyana3082432015-09-25 13:39:21 -0600544VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
545 VkCmdBuffer cmdBuffer,
546 VkBuffer destBuffer,
547 VkDeviceSize destOffset,
548 VkDeviceSize dataSize,
549 const uint32_t* pData)
550{
551 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
552
553 // destOffset is the byte offset into the buffer to start updating and must be a multiple of 4.
554 if (destOffset & 3) {
555 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
556 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
557 "vkCmdUpdateBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
558 return;
559 }
560 }
561
562 // dataSize is the number of bytes to update, which must be a multiple of 4.
563 if (dataSize & 3) {
564 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
565 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
566 "vkCmdUpdateBuffer parameter, VkDeviceSize dataSize, is not a multiple of 4")) {
567 return;
568 }
569 }
570
571 dev_data->device_dispatch_table->CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
572}
573
574VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
575 VkCmdBuffer cmdBuffer,
576 VkBuffer destBuffer,
577 VkDeviceSize destOffset,
578 VkDeviceSize fillSize,
579 uint32_t data)
580{
581 layer_data *dev_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
582
583 // destOffset is the byte offset into the buffer to start filling and must be a multiple of 4.
584 if (destOffset & 3) {
585 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
586 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
587 "vkCmdFillBuffer parameter, VkDeviceSize destOffset, is not a multiple of 4")) {
588 return;
589 }
590 }
591
592 // fillSize is the number of bytes to fill, which must be a multiple of 4.
593 if (fillSize & 3) {
594 layer_data *my_data = get_my_data_ptr(get_dispatch_key(cmdBuffer), layer_data_map);
595 if (log_msg(my_data->report_data, VK_DBG_REPORT_ERROR_BIT, (VkDbgObjectType)0, 0, 0, 1, "DL",
596 "vkCmdFillBuffer parameter, VkDeviceSize fillSize, is not a multiple of 4")) {
597 return;
598 }
599 }
600
601 dev_data->device_dispatch_table->CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
602}
603
Tobin Ehlisb5fc4fb2015-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 Ehlis1cb7f572015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600613 if (VK_SUCCESS == res) {
Tobin Ehlisb5fc4fb2015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600623 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600624 VkResult res = my_data->instance_dispatch_table->DbgDestroyMsgCallback(instance, msgCallback);
Tobin Ehlisb5fc4fb2015-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 Ehlis1cb7f572015-10-06 09:09:24 -0600634 layer_data *my_data;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600635 /* loader uses this to force layer initialization; device object is wrapped */
636 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
Tobin Ehlis1cb7f572015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600641 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
642 }
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600643 my_data = get_my_data_ptr(get_dispatch_key(dev), layer_data_map);
Tobin Ehlisb5fc4fb2015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600648 if (!strcmp(funcName, "vkGetDeviceQueue"))
649 return (PFN_vkVoidFunction) vkGetDeviceQueue;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -0600650 if (!strcmp(funcName, "vkCreateImage"))
651 return (PFN_vkVoidFunction) vkCreateImage;
Tobin Ehlis9da65002015-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;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -0600658 if (!strcmp(funcName, "vkAllocCommandBuffers"))
659 return (PFN_vkVoidFunction) vkAllocCommandBuffers;
660 if (!strcmp(funcName, "vkFreeCommandBuffers"))
661 return (PFN_vkVoidFunction) vkFreeCommandBuffers;
Mike Stroyana3082432015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600666
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600667 VkLayerDispatchTable* pTable = my_data->device_dispatch_table;
Tobin Ehlisb5fc4fb2015-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 Ehlis1cb7f572015-10-06 09:09:24 -0600681 layer_data *my_data;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600682 /* loader uses this to force layer initialization; instance object is wrapped */
683 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
Tobin Ehlis1cb7f572015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600688 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
689 }
Tobin Ehlis1cb7f572015-10-06 09:09:24 -0600690 my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
Tobin Ehlisb5fc4fb2015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600709 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
710 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Tobin Ehlisfd3843f2015-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 Ehlisb5fc4fb2015-09-03 09:50:06 -0600715
Tobin Ehlisb5fc4fb2015-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 Ehlis1cb7f572015-10-06 09:09:24 -0600721 VkLayerInstanceDispatchTable* pTable = my_data->instance_dispatch_table;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600722 if (pTable->GetInstanceProcAddr == NULL)
723 return NULL;
724 return pTable->GetInstanceProcAddr(instance, funcName);
725 }
726}