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