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