Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2016 Valve Corporation |
| 3 | * Copyright (c) 2015-2016 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2016 Google Inc. |
| 5 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 9 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 11 | * |
Jon Ashburn | 3ebf125 | 2016-04-19 11:30:31 -0600 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 17 | * |
| 18 | * Author: Dustin Graves <dustin@lunarg.com> |
| 19 | */ |
| 20 | |
Mark Lobodzinski | 739391a | 2016-03-17 15:08:18 -0600 | [diff] [blame] | 21 | #ifndef PARAMETER_VALIDATION_UTILS_H |
| 22 | #define PARAMETER_VALIDATION_UTILS_H |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 23 | |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 24 | #include <algorithm> |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 25 | #include <cstdlib> |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 26 | #include <string> |
| 27 | |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 28 | #include "vulkan/vulkan.h" |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 29 | #include "vk_enum_string_helper.h" |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 30 | #include "vk_layer_logging.h" |
| 31 | |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 32 | namespace { |
| 33 | struct GenericHeader { |
| 34 | VkStructureType sType; |
| 35 | const void *pNext; |
| 36 | }; |
| 37 | } |
| 38 | |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 39 | // Layer name string to be logged with validation messages. |
| 40 | const char ParameterValidationName[] = "ParameterValidation"; |
| 41 | |
| 42 | // String returned by string_VkStructureType for an unrecognized type. |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 43 | const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType"; |
| 44 | |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 45 | // String returned by string_VkResult for an unrecognized type. |
| 46 | const std::string UnsupportedResultString = "Unhandled VkResult"; |
| 47 | |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 48 | // The base value used when computing the offset for an enumeration token value that is added by an extension. |
| 49 | // When validating enumeration tokens, any value >= to this value is considered to be provided by an extension. |
| 50 | // See Appendix C.10 "Assigning Extension Token Values" from the Vulkan specification |
| 51 | const uint32_t ExtEnumBaseValue = 1000000000; |
| 52 | |
| 53 | template <typename T> bool is_extension_added_token(T value) { |
| 54 | return (std::abs(static_cast<int32_t>(value)) >= ExtEnumBaseValue); |
| 55 | } |
| 56 | |
| 57 | // VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE token is a special case that was converted from a core token to an |
| 58 | // extension added token. Its original value was intentionally preserved after the conversion, so it does not use |
| 59 | // the base value that other extension added tokens use, and it does not fall within the enum's begin/end range. |
| 60 | template <> bool is_extension_added_token(VkSamplerAddressMode value) { |
| 61 | bool result = (std::abs(static_cast<int32_t>(value)) >= ExtEnumBaseValue); |
| 62 | return (result || (value == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE)); |
| 63 | } |
| 64 | |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Validate a required pointer. |
| 67 | * |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 68 | * Verify that a required pointer is not NULL. |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 69 | * |
| 70 | * @param report_data debug_report_data object for routing validation messages. |
| 71 | * @param apiName Name of API call being validated. |
| 72 | * @param parameterName Name of parameter being validated. |
| 73 | * @param value Pointer to validate. |
| 74 | * @return Boolean value indicating that the call should be skipped. |
| 75 | */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 76 | static bool validate_required_pointer(debug_report_data *report_data, const char *apiName, const char *parameterName, |
| 77 | const void *value) { |
| 78 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 79 | |
| 80 | if (value == NULL) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 81 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 82 | ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName); |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 83 | } |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 84 | |
| 85 | return skipCall; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Validate pointer to array count and pointer to array. |
| 90 | * |
| 91 | * Verify that required count and array parameters are not NULL. If count |
Dustin Graves | eec48bf | 2016-03-02 18:23:29 -0700 | [diff] [blame] | 92 | * is not NULL and its value is not optional, verify that it is not 0. If the |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 93 | * array parameter is NULL, and it is not optional, verify that count is 0. |
| 94 | * The array parameter will typically be optional for this case (where count is |
| 95 | * a pointer), allowing the caller to retrieve the available count. |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 96 | * |
| 97 | * @param report_data debug_report_data object for routing validation messages. |
| 98 | * @param apiName Name of API call being validated. |
| 99 | * @param countName Name of count parameter. |
| 100 | * @param arrayName Name of array parameter. |
| 101 | * @param count Pointer to the number of elements in the array. |
| 102 | * @param array Array to validate. |
| 103 | * @param countPtrRequired The 'count' parameter may not be NULL when true. |
| 104 | * @param countValueRequired The '*count' value may not be 0 when true. |
| 105 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
| 106 | * @return Boolean value indicating that the call should be skipped. |
| 107 | */ |
| 108 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 109 | bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, |
| 110 | const T *count, const void *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired) { |
| 111 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 112 | |
| 113 | if (count == NULL) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 114 | if (countPtrRequired) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 115 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 116 | ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 117 | } |
| 118 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 119 | skipCall |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | return skipCall; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Validate array count and pointer to array. |
| 127 | * |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 128 | * Verify that required count and array parameters are not 0 or NULL. If the |
| 129 | * count parameter is not optional, verify that it is not 0. If the array |
| 130 | * parameter is NULL, and it is not optional, verify that count is 0. |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 131 | * |
| 132 | * @param report_data debug_report_data object for routing validation messages. |
| 133 | * @param apiName Name of API call being validated. |
| 134 | * @param countName Name of count parameter. |
| 135 | * @param arrayName Name of array parameter. |
| 136 | * @param count Number of elements in the array. |
| 137 | * @param array Array to validate. |
| 138 | * @param countRequired The 'count' parameter may not be 0 when true. |
| 139 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
| 140 | * @return Boolean value indicating that the call should be skipped. |
| 141 | */ |
| 142 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 143 | bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, T count, |
| 144 | const void *array, bool countRequired, bool arrayRequired) { |
| 145 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 146 | |
| 147 | // Count parameters not tagged as optional cannot be 0 |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 148 | if ((count == 0) && countRequired) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 149 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 150 | ParameterValidationName, "%s: parameter %s must be greater than 0", apiName, countName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 153 | // Array parameters not tagged as optional cannot be NULL, unless the count is 0 |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 154 | if ((array == NULL) && arrayRequired && (count != 0)) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 155 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 156 | ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, arrayName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | return skipCall; |
| 160 | } |
| 161 | |
| 162 | /** |
Dustin Graves | 20fd66f | 2016-04-18 18:33:21 -0600 | [diff] [blame] | 163 | * Validate a pointer to a Vulkan structure. |
| 164 | * |
| 165 | * Verify that a required pointer to a structure is not NULL. If the pointer is |
| 166 | * not NULL, verify that each structure's sType field is set to the correct |
| 167 | * VkStructureType value. |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 168 | * |
| 169 | * @param report_data debug_report_data object for routing validation messages. |
| 170 | * @param apiName Name of API call being validated. |
| 171 | * @param parameterName Name of struct parameter being validated. |
| 172 | * @param sTypeName Name of expected VkStructureType value. |
| 173 | * @param value Pointer to the struct to validate. |
| 174 | * @param sType VkStructureType for structure validation. |
| 175 | * @param required The parameter may not be NULL when true. |
| 176 | * @return Boolean value indicating that the call should be skipped. |
| 177 | */ |
| 178 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 179 | bool validate_struct_type(debug_report_data *report_data, const char *apiName, const char *parameterName, const char *sTypeName, |
| 180 | const T *value, VkStructureType sType, bool required) { |
| 181 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 182 | |
| 183 | if (value == NULL) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 184 | if (required) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 185 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 186 | ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 187 | } |
| 188 | } else if (value->sType != sType) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 189 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 190 | ParameterValidationName, "%s: parameter %s->sType must be %s", apiName, parameterName, sTypeName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | return skipCall; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Validate an array of Vulkan structures. |
| 198 | * |
| 199 | * Verify that required count and array parameters are not NULL. If count |
| 200 | * is not NULL and its value is not optional, verify that it is not 0. |
| 201 | * If the array contains 1 or more structures, verify that each structure's |
| 202 | * sType field is set to the correct VkStructureType value. |
| 203 | * |
| 204 | * @param report_data debug_report_data object for routing validation messages. |
| 205 | * @param apiName Name of API call being validated. |
| 206 | * @param countName Name of count parameter. |
| 207 | * @param arrayName Name of array parameter. |
| 208 | * @param sTypeName Name of expected VkStructureType value. |
| 209 | * @param count Pointer to the number of elements in the array. |
| 210 | * @param array Array to validate. |
| 211 | * @param sType VkStructureType for structure validation. |
| 212 | * @param countPtrRequired The 'count' parameter may not be NULL when true. |
| 213 | * @param countValueRequired The '*count' value may not be 0 when true. |
| 214 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
| 215 | * @return Boolean value indicating that the call should be skipped. |
| 216 | */ |
| 217 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 218 | bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, |
| 219 | const char *sTypeName, const uint32_t *count, const T *array, VkStructureType sType, |
| 220 | bool countPtrRequired, bool countValueRequired, bool arrayRequired) { |
| 221 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 222 | |
| 223 | if (count == NULL) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 224 | if (countPtrRequired) { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 225 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 226 | ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 227 | } |
| 228 | } else { |
Jon Ashburn | 5484e0c | 2016-03-08 17:48:44 -0700 | [diff] [blame] | 229 | skipCall |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType, |
| 230 | countValueRequired, arrayRequired); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | return skipCall; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Validate an array of Vulkan structures |
| 238 | * |
| 239 | * Verify that required count and array parameters are not 0 or NULL. If |
| 240 | * the array contains 1 or more structures, verify that each structure's |
| 241 | * sType field is set to the correct VkStructureType value. |
| 242 | * |
| 243 | * @param report_data debug_report_data object for routing validation messages. |
| 244 | * @param apiName Name of API call being validated. |
| 245 | * @param countName Name of count parameter. |
| 246 | * @param arrayName Name of array parameter. |
| 247 | * @param sTypeName Name of expected VkStructureType value. |
| 248 | * @param count Number of elements in the array. |
| 249 | * @param array Array to validate. |
| 250 | * @param sType VkStructureType for structure validation. |
| 251 | * @param countRequired The 'count' parameter may not be 0 when true. |
| 252 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
| 253 | * @return Boolean value indicating that the call should be skipped. |
| 254 | */ |
| 255 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 256 | bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, |
| 257 | const char *sTypeName, uint32_t count, const T *array, VkStructureType sType, bool countRequired, |
| 258 | bool arrayRequired) { |
| 259 | bool skipCall = false; |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 260 | |
| 261 | if ((count == 0) || (array == NULL)) { |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 262 | skipCall |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 263 | } else { |
| 264 | // Verify that all structs in the array have the correct type |
| 265 | for (uint32_t i = 0; i < count; ++i) { |
| 266 | if (array[i].sType != sType) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 267 | skipCall |= |
| 268 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 269 | ParameterValidationName, "%s: parameter %s[%d].sType must be %s", apiName, arrayName, i, sTypeName); |
Dustin Graves | 1e92cd7 | 2016-02-09 14:00:18 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | return skipCall; |
| 275 | } |
| 276 | |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 277 | /** |
Dustin Graves | 20fd66f | 2016-04-18 18:33:21 -0600 | [diff] [blame] | 278 | * Validate a Vulkan handle. |
| 279 | * |
| 280 | * Verify that the specified handle is not VK_NULL_HANDLE. |
| 281 | * |
| 282 | * @param report_data debug_report_data object for routing validation messages. |
| 283 | * @param api_name Name of API call being validated. |
| 284 | * @param parameter_name Name of struct parameter being validated. |
| 285 | * @param value Handle to validate. |
| 286 | * @return Boolean value indicating that the call should be skipped. |
| 287 | */ |
| 288 | template <typename T> |
| 289 | bool validate_required_handle(debug_report_data *report_data, const char *api_name, const char *parameter_name, T value) { |
| 290 | bool skip_call = false; |
| 291 | |
| 292 | if (value == VK_NULL_HANDLE) { |
| 293 | skip_call |= |
| 294 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 295 | ParameterValidationName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name, parameter_name); |
| 296 | } |
| 297 | |
| 298 | return skip_call; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Validate an array of Vulkan handles. |
| 303 | * |
| 304 | * Verify that required count and array parameters are not NULL. If count |
| 305 | * is not NULL and its value is not optional, verify that it is not 0. |
| 306 | * If the array contains 1 or more handles, verify that no handle is set to |
| 307 | * VK_NULL_HANDLE. |
| 308 | * |
| 309 | * @note This function is only intended to validate arrays of handles when none |
| 310 | * of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles |
| 311 | * that are allowed to contain VK_NULL_HANDLE, use validate_array() instead. |
| 312 | * |
| 313 | * @param report_data debug_report_data object for routing validation messages. |
| 314 | * @param api_name Name of API call being validated. |
| 315 | * @param count_name Name of count parameter. |
| 316 | * @param array_name Name of array parameter. |
| 317 | * @param count Number of elements in the array. |
| 318 | * @param array Array to validate. |
| 319 | * @param count_required The 'count' parameter may not be 0 when true. |
| 320 | * @param array_required The 'array' parameter may not be NULL when true. |
| 321 | * @return Boolean value indicating that the call should be skipped. |
| 322 | */ |
| 323 | template <typename T> |
| 324 | bool validate_handle_array(debug_report_data *report_data, const char *api_name, const char *count_name, const char *array_name, |
| 325 | uint32_t count, const T *array, bool count_required, bool array_required) { |
| 326 | bool skip_call = false; |
| 327 | |
| 328 | if ((count == 0) || (array == NULL)) { |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 329 | skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required); |
Dustin Graves | 20fd66f | 2016-04-18 18:33:21 -0600 | [diff] [blame] | 330 | } else { |
| 331 | // Verify that no handles in the array are VK_NULL_HANDLE |
| 332 | for (uint32_t i = 0; i < count; ++i) { |
| 333 | if (array[i] == VK_NULL_HANDLE) { |
| 334 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 335 | ParameterValidationName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name, |
| 336 | array_name, i); |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | return skip_call; |
| 342 | } |
| 343 | |
| 344 | /** |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 345 | * Validate string array count and content. |
| 346 | * |
| 347 | * Verify that required count and array parameters are not 0 or NULL. If the |
| 348 | * count parameter is not optional, verify that it is not 0. If the array |
| 349 | * parameter is NULL, and it is not optional, verify that count is 0. If the |
| 350 | * array parameter is not NULL, verify that none of the strings are NULL. |
| 351 | * |
| 352 | * @param report_data debug_report_data object for routing validation messages. |
| 353 | * @param apiName Name of API call being validated. |
| 354 | * @param countName Name of count parameter. |
| 355 | * @param arrayName Name of array parameter. |
| 356 | * @param count Number of strings in the array. |
| 357 | * @param array Array of strings to validate. |
| 358 | * @param countRequired The 'count' parameter may not be 0 when true. |
| 359 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
| 360 | * @return Boolean value indicating that the call should be skipped. |
| 361 | */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 362 | static bool validate_string_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, |
| 363 | uint32_t count, const char *const *array, bool countRequired, bool arrayRequired) { |
| 364 | bool skipCall = false; |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 365 | |
| 366 | if ((count == 0) || (array == NULL)) { |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 367 | skipCall |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired); |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 368 | } else { |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 369 | // Verify that strings in the array are not NULL |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 370 | for (uint32_t i = 0; i < count; ++i) { |
| 371 | if (array[i] == NULL) { |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 372 | skipCall |= |
| 373 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 374 | ParameterValidationName, "%s: required parameter %s[%d] specified as NULL", apiName, arrayName, i); |
Dustin Graves | 58d114b | 2016-03-08 14:42:59 -0700 | [diff] [blame] | 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | return skipCall; |
| 380 | } |
| 381 | |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 382 | /** |
| 383 | * Validate a structure's pNext member. |
| 384 | * |
| 385 | * Verify that the specified pNext value points to the head of a list of |
| 386 | * allowed extension structures. If no extension structures are allowed, |
| 387 | * verify that pNext is null. |
| 388 | * |
| 389 | * @param report_data debug_report_data object for routing validation messages. |
| 390 | * @param apiName Name of API call being validated. |
| 391 | * @param parameterName Name of parameter being validated. |
| 392 | * @param allowedStructNames Names of allowed structs. |
| 393 | * @param next Pointer to validate. |
| 394 | * @param allowedTypeCount total number of allowed structure types. |
| 395 | * @param allowedTypes array of strcuture types allowed for pNext. |
| 396 | * @return Boolean value indicating that the call should be skipped. |
| 397 | */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 398 | static bool validate_struct_pnext(debug_report_data *report_data, const char *apiName, const char *parameterName, |
| 399 | const char *allowedStructNames, const void *next, size_t allowedTypeCount, |
| 400 | const VkStructureType *allowedTypes) { |
| 401 | bool skipCall = false; |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 402 | |
| 403 | if (next != NULL) { |
| 404 | if (allowedTypeCount == 0) { |
| 405 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 406 | ParameterValidationName, "%s: value of %s must be NULL", apiName, parameterName); |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 407 | } else { |
| 408 | const VkStructureType *start = allowedTypes; |
| 409 | const VkStructureType *end = allowedTypes + allowedTypeCount; |
| 410 | const GenericHeader *current = reinterpret_cast<const GenericHeader *>(next); |
| 411 | |
| 412 | while (current != NULL) { |
| 413 | if (std::find(start, end, current->sType) == end) { |
| 414 | std::string typeName = string_VkStructureType(current->sType); |
| 415 | |
| 416 | if (typeName == UnsupportedStructureTypeString) { |
| 417 | skipCall |= log_msg( |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 418 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 419 | ParameterValidationName, |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 420 | "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed structures are [%s]", |
| 421 | apiName, parameterName, current->sType, allowedStructNames); |
| 422 | } else { |
| 423 | skipCall |= log_msg( |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 424 | report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 425 | ParameterValidationName, |
Dustin Graves | 58c2f66 | 2016-03-08 17:48:20 -0700 | [diff] [blame] | 426 | "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]", |
| 427 | apiName, parameterName, typeName.c_str(), allowedStructNames); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | current = reinterpret_cast<const GenericHeader *>(current->pNext); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | return skipCall; |
| 437 | } |
| 438 | |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 439 | /** |
| 440 | * Validate a VkBool32 value. |
| 441 | * |
| 442 | * Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE. |
| 443 | * |
| 444 | * @param report_data debug_report_data object for routing validation messages. |
| 445 | * @param apiName Name of API call being validated. |
| 446 | * @param parameterName Name of parameter being validated. |
| 447 | * @param value Boolean value to validate. |
| 448 | * @return Boolean value indicating that the call should be skipped. |
| 449 | */ |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 450 | static bool validate_bool32(debug_report_data *report_data, const char *apiName, const char *parameterName, VkBool32 value) { |
| 451 | bool skipCall = false; |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 452 | |
| 453 | if ((value != VK_TRUE) && (value != VK_FALSE)) { |
| 454 | skipCall |= |
| 455 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 456 | ParameterValidationName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName, parameterName, value); |
| 457 | } |
| 458 | |
| 459 | return skipCall; |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Validate a Vulkan enumeration value. |
| 464 | * |
| 465 | * Generate a warning if an enumeration token value does not fall within the core enumeration |
| 466 | * begin and end token values, and was not added to the enumeration by an extension. Extension |
| 467 | * provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification, |
| 468 | * with 1,000,000,000 as the base token value. |
| 469 | * |
| 470 | * @note This function does not expect to process enumerations defining bitmask flag bits. |
| 471 | * |
| 472 | * @param report_data debug_report_data object for routing validation messages. |
| 473 | * @param apiName Name of API call being validated. |
| 474 | * @param parameterName Name of parameter being validated. |
| 475 | * @param enumName Name of the enumeration being validated. |
| 476 | * @param begin The begin range value for the enumeration. |
| 477 | * @param end The end range value for the enumeration. |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 478 | * @param value Enumeration value to validate. |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 479 | * @return Boolean value indicating that the call should be skipped. |
| 480 | */ |
| 481 | template <typename T> |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 482 | bool validate_ranged_enum(debug_report_data *report_data, const char *apiName, const char *parameterName, const char *enumName, |
| 483 | T begin, T end, T value) { |
| 484 | bool skipCall = false; |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 485 | |
| 486 | if (((value < begin) || (value > end)) && !is_extension_added_token(value)) { |
| 487 | skipCall |= |
| 488 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 489 | ParameterValidationName, "%s: value of %s (%d) does not fall within the begin..end range of the core %s " |
| 490 | "enumeration tokens and is not an extension added token", |
| 491 | apiName, parameterName, value, enumName); |
| 492 | } |
| 493 | |
| 494 | return skipCall; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Validate an array of Vulkan enumeration value. |
| 499 | * |
| 500 | * Process all enumeration token values in the specified array and generate a warning if a value |
| 501 | * does not fall within the core enumeration begin and end token values, and was not added to |
| 502 | * the enumeration by an extension. Extension provided enumerations use the equation specified |
| 503 | * in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value. |
| 504 | * |
| 505 | * @note This function does not expect to process enumerations defining bitmask flag bits. |
| 506 | * |
| 507 | * @param report_data debug_report_data object for routing validation messages. |
| 508 | * @param apiName Name of API call being validated. |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 509 | * @param countName Name of count parameter. |
| 510 | * @param arrayName Name of array parameter. |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 511 | * @param enumName Name of the enumeration being validated. |
| 512 | * @param begin The begin range value for the enumeration. |
| 513 | * @param end The end range value for the enumeration. |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 514 | * @param count Number of enumeration values in the array. |
| 515 | * @param array Array of enumeration values to validate. |
| 516 | * @param countRequired The 'count' parameter may not be 0 when true. |
| 517 | * @param arrayRequired The 'array' parameter may not be NULL when true. |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 518 | * @return Boolean value indicating that the call should be skipped. |
| 519 | */ |
| 520 | template <typename T> |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 521 | static bool validate_ranged_enum_array(debug_report_data *report_data, const char *apiName, const char *countName, |
| 522 | const char *arrayName, const char *enumName, T begin, T end, uint32_t count, const T *array, |
| 523 | bool countRequired, bool arrayRequired) { |
Dustin Graves | 080069b | 2016-04-05 13:48:15 -0600 | [diff] [blame] | 524 | bool skipCall = false; |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 525 | |
Dustin Graves | 0d15c6e | 2016-04-26 16:34:10 -0600 | [diff] [blame] | 526 | if ((count == 0) || (array == NULL)) { |
| 527 | skipCall |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired); |
| 528 | } else { |
| 529 | for (uint32_t i = 0; i < count; ++i) { |
| 530 | if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) { |
| 531 | skipCall |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 532 | ParameterValidationName, |
| 533 | "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s " |
| 534 | "enumeration tokens and is not an extension added token", |
| 535 | apiName, arrayName, i, array[i], enumName); |
| 536 | } |
Dustin Graves | 29148ff | 2016-03-23 19:44:00 -0600 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | return skipCall; |
| 541 | } |
| 542 | |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 543 | /** |
Dustin Graves | 78df851 | 2016-04-28 17:58:59 -0600 | [diff] [blame] | 544 | * Verify that a reserved VkFlags value is zero. |
| 545 | * |
| 546 | * Verify that the specified value is zero, to check VkFlags values that are reserved for |
| 547 | * future use. |
| 548 | * |
| 549 | * @param report_data debug_report_data object for routing validation messages. |
| 550 | * @param api_name Name of API call being validated. |
| 551 | * @param parameter_name Name of parameter being validated. |
| 552 | * @param value Value to validate. |
| 553 | * @return Boolean value indicating that the call should be skipped. |
| 554 | */ |
| 555 | static bool validate_reserved_flags(debug_report_data *report_data, const char *api_name, const char *parameter_name, |
| 556 | VkFlags value) { |
| 557 | bool skip_call = false; |
| 558 | |
| 559 | if (value != 0) { |
| 560 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 561 | ParameterValidationName, "%s: parameter %s must be 0", api_name, parameter_name); |
| 562 | } |
| 563 | |
| 564 | return skip_call; |
| 565 | } |
| 566 | |
| 567 | /** |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 568 | * Validate a Vulkan bitmask value. |
| 569 | * |
| 570 | * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits |
| 571 | * for that type. |
| 572 | * |
| 573 | * @param report_data debug_report_data object for routing validation messages. |
| 574 | * @param api_name Name of API call being validated. |
| 575 | * @param parameter_name Name of parameter being validated. |
| 576 | * @param flag_bits_name Name of the VkFlags type being validated. |
| 577 | * @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated. |
| 578 | * @param value VkFlags value to validate. |
| 579 | * @param flags_required The 'value' parameter may not be 0 when true. |
| 580 | * @return Boolean value indicating that the call should be skipped. |
| 581 | */ |
Dustin Graves | 78df851 | 2016-04-28 17:58:59 -0600 | [diff] [blame] | 582 | static bool validate_flags(debug_report_data *report_data, const char *api_name, const char *parameter_name, |
| 583 | const char *flag_bits_name, VkFlags all_flags, VkFlags value, bool flags_required) { |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 584 | bool skip_call = false; |
| 585 | |
| 586 | if (value == 0) { |
| 587 | if (flags_required) { |
| 588 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 589 | ParameterValidationName, "%s: value of %s must not be 0", api_name, parameter_name); |
| 590 | } |
| 591 | } else if ((value & (~all_flags)) != 0) { |
| 592 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 593 | ParameterValidationName, "%s: value of %s contains flag bits that are not recognized members of %s", |
| 594 | api_name, parameter_name, flag_bits_name); |
| 595 | } |
| 596 | |
| 597 | return skip_call; |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Validate an array of Vulkan bitmask values. |
| 602 | * |
| 603 | * Generate a warning if a value with a VkFlags derived type does not contain valid flag bits |
| 604 | * for that type. |
| 605 | * |
| 606 | * @param report_data debug_report_data object for routing validation messages. |
| 607 | * @param api_name Name of API call being validated. |
| 608 | * @param count_name Name of parameter being validated. |
| 609 | * @param array_name Name of parameter being validated. |
| 610 | * @param flag_bits_name Name of the VkFlags type being validated. |
| 611 | * @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated. |
| 612 | * @param count Number of VkFlags values in the array. |
| 613 | * @param array Array of VkFlags value to validate. |
| 614 | * @param count_required The 'count' parameter may not be 0 when true. |
| 615 | * @param array_required The 'array' parameter may not be NULL when true. |
| 616 | * @return Boolean value indicating that the call should be skipped. |
| 617 | */ |
Dustin Graves | 78df851 | 2016-04-28 17:58:59 -0600 | [diff] [blame] | 618 | static bool validate_flags_array(debug_report_data *report_data, const char *api_name, const char *count_name, |
| 619 | const char *array_name, const char *flag_bits_name, VkFlags all_flags, uint32_t count, |
| 620 | const VkFlags *array, bool count_required, bool array_required) { |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 621 | bool skip_call = false; |
| 622 | |
| 623 | if ((count == 0) || (array == NULL)) { |
| 624 | skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required); |
| 625 | } else { |
| 626 | // Verify that all VkFlags values in the array |
| 627 | for (uint32_t i = 0; i < count; ++i) { |
Dustin Graves | 78df851 | 2016-04-28 17:58:59 -0600 | [diff] [blame] | 628 | if (array[i] == 0) { |
| 629 | // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if |
| 630 | // elements in the array are allowed be 0 |
| 631 | if (array_required) { |
| 632 | skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, |
| 633 | 1, ParameterValidationName, "%s: value of %s[%d] must not be 0", api_name, array_name, i); |
| 634 | } |
| 635 | } else if ((array[i] & (~all_flags)) != 0) { |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 636 | skip_call |= |
| 637 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 638 | ParameterValidationName, "%s: value of %s[%d] contains flag bits that are not recognized members of %s", |
| 639 | api_name, array_name, i, flag_bits_name); |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | return skip_call; |
| 645 | } |
| 646 | |
| 647 | /** |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 648 | * Get VkResult code description. |
| 649 | * |
Dustin Graves | 9c6b62b | 2016-04-26 15:37:10 -0600 | [diff] [blame] | 650 | * Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API |
| 651 | * specification. |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 652 | * |
| 653 | * @param value VkResult code to process. |
| 654 | * @return String describing the specified VkResult code. |
| 655 | */ |
| 656 | static std::string get_result_description(VkResult result) { |
| 657 | // clang-format off |
| 658 | switch (result) { |
| 659 | case VK_SUCCESS: return "a command completed successfully"; |
| 660 | case VK_NOT_READY: return "a fence or query has not yet completed"; |
| 661 | case VK_TIMEOUT: return "a wait operation has not completed in the specified time"; |
| 662 | case VK_EVENT_SET: return "an event is signaled"; |
| 663 | case VK_EVENT_RESET: return "an event is unsignalled"; |
| 664 | case VK_INCOMPLETE: return "a return array was too small for the result"; |
| 665 | case VK_ERROR_OUT_OF_HOST_MEMORY: return "a host memory allocation has failed"; |
| 666 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "a device memory allocation has failed"; |
| 667 | case VK_ERROR_INITIALIZATION_FAILED: return "the logical device has been lost"; |
| 668 | case VK_ERROR_DEVICE_LOST: return "initialization of an object has failed"; |
| 669 | case VK_ERROR_MEMORY_MAP_FAILED: return "mapping of a memory object has failed"; |
| 670 | case VK_ERROR_LAYER_NOT_PRESENT: return "the specified layer does not exist"; |
| 671 | case VK_ERROR_EXTENSION_NOT_PRESENT: return "the specified extension does not exist"; |
| 672 | case VK_ERROR_FEATURE_NOT_PRESENT: return "the requested feature is not available on this device"; |
| 673 | case VK_ERROR_INCOMPATIBLE_DRIVER: return "a Vulkan driver could not be found"; |
| 674 | case VK_ERROR_TOO_MANY_OBJECTS: return "too many objects of the type have already been created"; |
| 675 | case VK_ERROR_FORMAT_NOT_SUPPORTED: return "the requested format is not supported on this device"; |
| 676 | case VK_ERROR_SURFACE_LOST_KHR: return "a surface is no longer available"; |
| 677 | case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "the requested window is already connected to another " |
| 678 | "VkSurfaceKHR object, or some other non-Vulkan surface object"; |
| 679 | case VK_SUBOPTIMAL_KHR: return "an image became available, and the swapchain no longer " |
| 680 | "matches the surface properties exactly, but can still be used to " |
| 681 | "present to the surface successfully."; |
| 682 | case VK_ERROR_OUT_OF_DATE_KHR: return "a surface has changed in such a way that it is no " |
| 683 | "longer compatible with the swapchain"; |
| 684 | case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "the display used by a swapchain does not use the same " |
| 685 | "presentable image layout, or is incompatible in a way that prevents " |
| 686 | "sharing an image"; |
| 687 | case VK_ERROR_VALIDATION_FAILED_EXT: return "API validation has detected an invalid use of the API"; |
| 688 | case VK_ERROR_INVALID_SHADER_NV: return "one or more shaders failed to compile or link"; |
Eric Engestrom | bcbb0fd | 2016-04-02 22:06:13 +0100 | [diff] [blame] | 689 | default: return "an error has occurred"; |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 690 | }; |
| 691 | // clang-format on |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Validate return code. |
| 696 | * |
| 697 | * Print a message describing the reason for failure when an error code is returned. |
| 698 | * |
| 699 | * @param report_data debug_report_data object for routing validation messages. |
| 700 | * @param apiName Name of API call being validated. |
| 701 | * @param value VkResult value to validate. |
| 702 | */ |
| 703 | static void validate_result(debug_report_data *report_data, const char *apiName, VkResult result) { |
| 704 | if (result < 0) { |
| 705 | std::string resultName = string_VkResult(result); |
| 706 | |
| 707 | if (resultName == UnsupportedResultString) { |
| 708 | // Unrecognized result code |
| 709 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
Eric Engestrom | bcbb0fd | 2016-04-02 22:06:13 +0100 | [diff] [blame] | 710 | ParameterValidationName, "%s: returned a result code indicating that an error has occurred", apiName); |
Dustin Graves | ca7aa7c | 2016-03-25 15:13:28 -0600 | [diff] [blame] | 711 | } else { |
| 712 | std::string resultDesc = get_result_description(result); |
| 713 | log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, |
| 714 | ParameterValidationName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(), resultDesc.c_str()); |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
Mark Lobodzinski | 739391a | 2016-03-17 15:08:18 -0600 | [diff] [blame] | 719 | #endif // PARAMETER_VALIDATION_UTILS_H |