blob: be27cbf268f343108083db63df4d8af400a5ece1 [file] [log] [blame]
Dustin Graves1e92cd72016-02-09 14:00:18 -07001/* 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 Ashburn3ebf1252016-04-19 11:30:31 -06006 * 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 Graves1e92cd72016-02-09 14:00:18 -07009 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060010 * http://www.apache.org/licenses/LICENSE-2.0
Dustin Graves1e92cd72016-02-09 14:00:18 -070011 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060012 * 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 Graves1e92cd72016-02-09 14:00:18 -070017 *
18 * Author: Dustin Graves <dustin@lunarg.com>
19 */
20
Mark Lobodzinski739391a2016-03-17 15:08:18 -060021#ifndef PARAMETER_VALIDATION_UTILS_H
22#define PARAMETER_VALIDATION_UTILS_H
Dustin Graves1e92cd72016-02-09 14:00:18 -070023
Dustin Graves58c2f662016-03-08 17:48:20 -070024#include <algorithm>
Dustin Graves29148ff2016-03-23 19:44:00 -060025#include <cstdlib>
Dustin Graves58c2f662016-03-08 17:48:20 -070026#include <string>
27
Dustin Graves1e92cd72016-02-09 14:00:18 -070028#include "vulkan/vulkan.h"
Dustin Graves58c2f662016-03-08 17:48:20 -070029#include "vk_enum_string_helper.h"
Dustin Graves1e92cd72016-02-09 14:00:18 -070030#include "vk_layer_logging.h"
Karl Schultza9ef1e52016-10-06 17:53:48 -060031#include "vk_validation_error_messages.h"
Dustin Graves1e92cd72016-02-09 14:00:18 -070032
Dustin Graves8ffbbf62016-07-22 13:19:46 -060033#include "parameter_name.h"
34
Dustin Gravesb83fc2d2016-05-04 12:56:08 -060035namespace parameter_validation {
36
Dustin Gravesf233e502016-05-05 13:44:21 -060037enum 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 Lobodzinski4dc6cb02016-06-28 11:23:08 -060055 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 Gravesf233e502016-05-05 13:44:21 -060059 FAILURE_RETURN_CODE, // A Vulkan return code indicating a failure condition
60 // was encountered.
Chris Forbes9a083b92016-11-02 16:58:15 +130061 EXTENSION_NOT_ENABLED,// An extension entrypoint was called, but the required
62 // extension was not enabled at CreateInstance or
63 // CreateDevice time.
Dustin Gravesf233e502016-05-05 13:44:21 -060064};
65
Dustin Graves58c2f662016-03-08 17:48:20 -070066struct GenericHeader {
67 VkStructureType sType;
68 const void *pNext;
69};
Dustin Graves58c2f662016-03-08 17:48:20 -070070
Dustin Graves29148ff2016-03-23 19:44:00 -060071// Layer name string to be logged with validation messages.
Dustin Gravesb83fc2d2016-05-04 12:56:08 -060072const char LayerName[] = "ParameterValidation";
Dustin Graves29148ff2016-03-23 19:44:00 -060073
Mark Lobodzinskiaf00fa82016-08-09 10:44:38 -060074// Enables for display-related instance extensions
75struct instance_extension_enables {
76 bool wsi_enabled;
77 bool xlib_enabled;
78 bool xcb_enabled;
79 bool wayland_enabled;
80 bool mir_enabled;
81 bool android_enabled;
82 bool win32_enabled;
83};
84
Dustin Graves29148ff2016-03-23 19:44:00 -060085// String returned by string_VkStructureType for an unrecognized type.
Dustin Graves58c2f662016-03-08 17:48:20 -070086const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType";
87
Dustin Gravesca7aa7c2016-03-25 15:13:28 -060088// String returned by string_VkResult for an unrecognized type.
89const std::string UnsupportedResultString = "Unhandled VkResult";
90
Dustin Graves29148ff2016-03-23 19:44:00 -060091// The base value used when computing the offset for an enumeration token value that is added by an extension.
92// When validating enumeration tokens, any value >= to this value is considered to be provided by an extension.
93// See Appendix C.10 "Assigning Extension Token Values" from the Vulkan specification
94const uint32_t ExtEnumBaseValue = 1000000000;
95
96template <typename T> bool is_extension_added_token(T value) {
97 return (std::abs(static_cast<int32_t>(value)) >= ExtEnumBaseValue);
98}
99
100// VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE token is a special case that was converted from a core token to an
101// extension added token. Its original value was intentionally preserved after the conversion, so it does not use
102// the base value that other extension added tokens use, and it does not fall within the enum's begin/end range.
103template <> bool is_extension_added_token(VkSamplerAddressMode value) {
104 bool result = (std::abs(static_cast<int32_t>(value)) >= ExtEnumBaseValue);
105 return (result || (value == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE));
106}
107
Dustin Graves1e92cd72016-02-09 14:00:18 -0700108/**
Dustin Gravesf8032f22016-05-11 18:31:44 -0600109* Validate a minimum value.
110*
111* Verify that the specified value is greater than the specified lower bound.
112*
113* @param report_data debug_report_data object for routing validation messages.
114* @param api_name Name of API call being validated.
115* @param parameter_name Name of parameter being validated.
116* @param value Value to validate.
117* @param lower_bound Lower bound value to use for validation.
118* @return Boolean value indicating that the call should be skipped.
119*/
120template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600121bool ValidateGreaterThan(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name, T value,
122 T lower_bound) {
Dustin Gravesf8032f22016-05-11 18:31:44 -0600123 bool skip_call = false;
124
125 if (value <= lower_bound) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600126 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
127 "%s: parameter %s must be greater than %d", api_name, parameter_name.get_name().c_str(), lower_bound);
Dustin Gravesf8032f22016-05-11 18:31:44 -0600128 }
129
130 return skip_call;
131}
132
133/**
Dustin Graves1e92cd72016-02-09 14:00:18 -0700134 * Validate a required pointer.
135 *
Dustin Graves58c2f662016-03-08 17:48:20 -0700136 * Verify that a required pointer is not NULL.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700137 *
138 * @param report_data debug_report_data object for routing validation messages.
139 * @param apiName Name of API call being validated.
140 * @param parameterName Name of parameter being validated.
141 * @param value Pointer to validate.
142 * @return Boolean value indicating that the call should be skipped.
143 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600144static bool validate_required_pointer(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
Dustin Graves080069b2016-04-05 13:48:15 -0600145 const void *value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600146 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700147
148 if (value == NULL) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600149
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600150 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600151 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
152 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700153 }
154
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600155 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700156}
157
158/**
159 * Validate array count and pointer to array.
160 *
Dustin Graves58d114b2016-03-08 14:42:59 -0700161 * Verify that required count and array parameters are not 0 or NULL. If the
162 * count parameter is not optional, verify that it is not 0. If the array
163 * parameter is NULL, and it is not optional, verify that count is 0.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700164 *
165 * @param report_data debug_report_data object for routing validation messages.
166 * @param apiName Name of API call being validated.
167 * @param countName Name of count parameter.
168 * @param arrayName Name of array parameter.
169 * @param count Number of elements in the array.
170 * @param array Array to validate.
171 * @param countRequired The 'count' parameter may not be 0 when true.
172 * @param arrayRequired The 'array' parameter may not be NULL when true.
173 * @return Boolean value indicating that the call should be skipped.
174 */
175template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600176bool validate_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
177 const ParameterName &arrayName, T count, const void *array, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600178 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700179
180 // Count parameters not tagged as optional cannot be 0
Józef Kucia20bb8fb2016-09-23 12:45:04 +0200181 if (countRequired && (count == 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600182 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600183 REQUIRED_PARAMETER, LayerName, "%s: parameter %s must be greater than 0", apiName,
184 countName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700185 }
186
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600187 // Array parameters not tagged as optional cannot be NULL, unless the count is 0
Dustin Graves080069b2016-04-05 13:48:15 -0600188 if ((array == NULL) && arrayRequired && (count != 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600189 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600190 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
191 arrayName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600192 }
193
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600194 return skip_call;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600195}
196
197/**
198* Validate pointer to array count and pointer to array.
199*
200* Verify that required count and array parameters are not NULL. If count
201* is not NULL and its value is not optional, verify that it is not 0. If the
202* array parameter is NULL, and it is not optional, verify that count is 0.
203* The array parameter will typically be optional for this case (where count is
204* a pointer), allowing the caller to retrieve the available count.
205*
206* @param report_data debug_report_data object for routing validation messages.
207* @param apiName Name of API call being validated.
208* @param countName Name of count parameter.
209* @param arrayName Name of array parameter.
210* @param count Pointer to the number of elements in the array.
211* @param array Array to validate.
212* @param countPtrRequired The 'count' parameter may not be NULL when true.
213* @param countValueRequired The '*count' value may not be 0 when true.
214* @param arrayRequired The 'array' parameter may not be NULL when true.
215* @return Boolean value indicating that the call should be skipped.
216*/
217template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600218bool validate_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
219 const ParameterName &arrayName, const T *count, const void *array, bool countPtrRequired,
220 bool countValueRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600221 bool skip_call = false;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600222
223 if (count == NULL) {
224 if (countPtrRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600225 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600226 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
227 countName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600228 }
229 }
230 else {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600231 skip_call |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700232 }
233
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600234 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700235}
236
237/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600238 * Validate a pointer to a Vulkan structure.
239 *
240 * Verify that a required pointer to a structure is not NULL. If the pointer is
241 * not NULL, verify that each structure's sType field is set to the correct
242 * VkStructureType value.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700243 *
244 * @param report_data debug_report_data object for routing validation messages.
245 * @param apiName Name of API call being validated.
246 * @param parameterName Name of struct parameter being validated.
247 * @param sTypeName Name of expected VkStructureType value.
248 * @param value Pointer to the struct to validate.
249 * @param sType VkStructureType for structure validation.
250 * @param required The parameter may not be NULL when true.
251 * @return Boolean value indicating that the call should be skipped.
252 */
253template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600254bool validate_struct_type(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
255 const char *sTypeName, const T *value, VkStructureType sType, bool required) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600256 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700257
258 if (value == NULL) {
Dustin Graves080069b2016-04-05 13:48:15 -0600259 if (required) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600260 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
261 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
262 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700263 }
264 } else if (value->sType != sType) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600265 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
266 INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s->sType must be %s", apiName,
267 parameterName.get_name().c_str(), sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700268 }
269
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600270 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700271}
272
273/**
274 * Validate an array of Vulkan structures.
275 *
276 * Verify that required count and array parameters are not NULL. If count
277 * is not NULL and its value is not optional, verify that it is not 0.
278 * If the array contains 1 or more structures, verify that each structure's
279 * sType field is set to the correct VkStructureType value.
280 *
281 * @param report_data debug_report_data object for routing validation messages.
282 * @param apiName Name of API call being validated.
283 * @param countName Name of count parameter.
284 * @param arrayName Name of array parameter.
285 * @param sTypeName Name of expected VkStructureType value.
286 * @param count Pointer to the number of elements in the array.
287 * @param array Array to validate.
288 * @param sType VkStructureType for structure validation.
289 * @param countPtrRequired The 'count' parameter may not be NULL when true.
290 * @param countValueRequired The '*count' value may not be 0 when true.
291 * @param arrayRequired The 'array' parameter may not be NULL when true.
292 * @return Boolean value indicating that the call should be skipped.
293 */
294template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600295bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
296 const ParameterName &arrayName, const char *sTypeName, const uint32_t *count, const T *array,
297 VkStructureType sType, bool countPtrRequired, bool countValueRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600298 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700299
300 if (count == NULL) {
Dustin Graves080069b2016-04-05 13:48:15 -0600301 if (countPtrRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600302 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600303 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
304 countName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700305 }
306 } else {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600307 skip_call |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600308 countValueRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700309 }
310
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600311 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700312}
313
314/**
315 * Validate an array of Vulkan structures
316 *
317 * Verify that required count and array parameters are not 0 or NULL. If
318 * the array contains 1 or more structures, verify that each structure's
319 * sType field is set to the correct VkStructureType value.
320 *
321 * @param report_data debug_report_data object for routing validation messages.
322 * @param apiName Name of API call being validated.
323 * @param countName Name of count parameter.
324 * @param arrayName Name of array parameter.
325 * @param sTypeName Name of expected VkStructureType value.
326 * @param count Number of elements in the array.
327 * @param array Array to validate.
328 * @param sType VkStructureType for structure validation.
329 * @param countRequired The 'count' parameter may not be 0 when true.
330 * @param arrayRequired The 'array' parameter may not be NULL when true.
331 * @return Boolean value indicating that the call should be skipped.
332 */
333template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600334bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
335 const ParameterName &arrayName, const char *sTypeName, uint32_t count, const T *array,
336 VkStructureType sType, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600337 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700338
339 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600340 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700341 } else {
342 // Verify that all structs in the array have the correct type
343 for (uint32_t i = 0; i < count; ++i) {
344 if (array[i].sType != sType) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600345 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600346 __LINE__, INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s[%d].sType must be %s", apiName,
347 arrayName.get_name().c_str(), i, sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700348 }
349 }
350 }
351
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600352 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700353}
354
Dustin Graves58d114b2016-03-08 14:42:59 -0700355/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600356* Validate a Vulkan handle.
357*
358* Verify that the specified handle is not VK_NULL_HANDLE.
359*
360* @param report_data debug_report_data object for routing validation messages.
361* @param api_name Name of API call being validated.
362* @param parameter_name Name of struct parameter being validated.
363* @param value Handle to validate.
364* @return Boolean value indicating that the call should be skipped.
365*/
366template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600367bool validate_required_handle(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name, T value) {
Dustin Graves20fd66f2016-04-18 18:33:21 -0600368 bool skip_call = false;
369
370 if (value == VK_NULL_HANDLE) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600371 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
372 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600373 parameter_name.get_name().c_str());
Dustin Graves20fd66f2016-04-18 18:33:21 -0600374 }
375
376 return skip_call;
377}
378
379/**
380* Validate an array of Vulkan handles.
381*
382* Verify that required count and array parameters are not NULL. If count
383* is not NULL and its value is not optional, verify that it is not 0.
384* If the array contains 1 or more handles, verify that no handle is set to
385* VK_NULL_HANDLE.
386*
387* @note This function is only intended to validate arrays of handles when none
388* of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles
389* that are allowed to contain VK_NULL_HANDLE, use validate_array() instead.
390*
391* @param report_data debug_report_data object for routing validation messages.
392* @param api_name Name of API call being validated.
393* @param count_name Name of count parameter.
394* @param array_name Name of array parameter.
395* @param count Number of elements in the array.
396* @param array Array to validate.
397* @param count_required The 'count' parameter may not be 0 when true.
398* @param array_required The 'array' parameter may not be NULL when true.
399* @return Boolean value indicating that the call should be skipped.
400*/
401template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600402bool validate_handle_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
403 const ParameterName &array_name, uint32_t count, const T *array, bool count_required,
404 bool array_required) {
Dustin Graves20fd66f2016-04-18 18:33:21 -0600405 bool skip_call = false;
406
407 if ((count == 0) || (array == NULL)) {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600408 skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required);
Dustin Graves20fd66f2016-04-18 18:33:21 -0600409 } else {
410 // Verify that no handles in the array are VK_NULL_HANDLE
411 for (uint32_t i = 0; i < count; ++i) {
412 if (array[i] == VK_NULL_HANDLE) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600413 skip_call |=
414 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
415 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name,
416 array_name.get_name().c_str(), i);
Dustin Graves20fd66f2016-04-18 18:33:21 -0600417 }
418 }
419 }
420
421 return skip_call;
422}
423
424/**
Dustin Graves58d114b2016-03-08 14:42:59 -0700425 * Validate string array count and content.
426 *
427 * Verify that required count and array parameters are not 0 or NULL. If the
428 * count parameter is not optional, verify that it is not 0. If the array
429 * parameter is NULL, and it is not optional, verify that count is 0. If the
430 * array parameter is not NULL, verify that none of the strings are NULL.
431 *
432 * @param report_data debug_report_data object for routing validation messages.
433 * @param apiName Name of API call being validated.
434 * @param countName Name of count parameter.
435 * @param arrayName Name of array parameter.
436 * @param count Number of strings in the array.
437 * @param array Array of strings to validate.
438 * @param countRequired The 'count' parameter may not be 0 when true.
439 * @param arrayRequired The 'array' parameter may not be NULL when true.
440 * @return Boolean value indicating that the call should be skipped.
441 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600442static bool validate_string_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
443 const ParameterName &arrayName, uint32_t count, const char *const *array, bool countRequired,
444 bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600445 bool skip_call = false;
Dustin Graves58d114b2016-03-08 14:42:59 -0700446
447 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600448 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves58d114b2016-03-08 14:42:59 -0700449 } else {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600450 // Verify that strings in the array are not NULL
Dustin Graves58d114b2016-03-08 14:42:59 -0700451 for (uint32_t i = 0; i < count; ++i) {
452 if (array[i] == NULL) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600453 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600454 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as NULL",
455 apiName, arrayName.get_name().c_str(), i);
Dustin Graves58d114b2016-03-08 14:42:59 -0700456 }
457 }
458 }
459
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600460 return skip_call;
Dustin Graves58d114b2016-03-08 14:42:59 -0700461}
462
Dustin Graves58c2f662016-03-08 17:48:20 -0700463/**
464 * Validate a structure's pNext member.
465 *
466 * Verify that the specified pNext value points to the head of a list of
467 * allowed extension structures. If no extension structures are allowed,
468 * verify that pNext is null.
469 *
470 * @param report_data debug_report_data object for routing validation messages.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600471 * @param api_name Name of API call being validated.
472 * @param parameter_name Name of parameter being validated.
473 * @param allowed_struct_names Names of allowed structs.
Dustin Graves58c2f662016-03-08 17:48:20 -0700474 * @param next Pointer to validate.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600475 * @param allowed_type_count Total number of allowed structure types.
476 * @param allowed_types Array of strcuture types allowed for pNext.
477 * @param header_version Version of header defining the pNext validation rules.
Dustin Graves58c2f662016-03-08 17:48:20 -0700478 * @return Boolean value indicating that the call should be skipped.
479 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600480static bool validate_struct_pnext(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600481 const char *allowed_struct_names, const void *next, size_t allowed_type_count,
482 const VkStructureType *allowed_types, uint32_t header_version) {
483 bool skip_call = false;
484 const char disclaimer[] = "This warning is based on the Valid Usage documentation for version %d of the Vulkan header. It "
485 "is possible that you are using a struct from a private extension or an extension that was added "
486 "to a later version of the Vulkan header, in which case your use of %s is perfectly valid but "
487 "is not guaranteed to work correctly with validation enabled";
Dustin Graves58c2f662016-03-08 17:48:20 -0700488
489 if (next != NULL) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600490 if (allowed_type_count == 0) {
491 std::string message = "%s: value of %s must be NULL. ";
492 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600493 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
494 INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name, parameter_name.get_name().c_str(),
495 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700496 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600497 const VkStructureType *start = allowed_types;
498 const VkStructureType *end = allowed_types + allowed_type_count;
Dustin Graves58c2f662016-03-08 17:48:20 -0700499 const GenericHeader *current = reinterpret_cast<const GenericHeader *>(next);
500
501 while (current != NULL) {
502 if (std::find(start, end, current->sType) == end) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600503 std::string type_name = string_VkStructureType(current->sType);
Dustin Graves58c2f662016-03-08 17:48:20 -0700504
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600505 if (type_name == UnsupportedStructureTypeString) {
506 std::string message = "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed "
507 "structures are [%s]. ";
508 message += disclaimer;
509 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
510 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600511 parameter_name.get_name().c_str(), current->sType, allowed_struct_names,
512 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700513 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600514 std::string message =
515 "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]. ";
516 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600517 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
518 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
519 parameter_name.get_name().c_str(), type_name.c_str(), allowed_struct_names,
520 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700521 }
522 }
523
524 current = reinterpret_cast<const GenericHeader *>(current->pNext);
525 }
526 }
527 }
528
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600529 return skip_call;
Dustin Graves58c2f662016-03-08 17:48:20 -0700530}
531
Dustin Graves29148ff2016-03-23 19:44:00 -0600532/**
533* Validate a VkBool32 value.
534*
535* Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE.
536*
537* @param report_data debug_report_data object for routing validation messages.
538* @param apiName Name of API call being validated.
539* @param parameterName Name of parameter being validated.
540* @param value Boolean value to validate.
541* @return Boolean value indicating that the call should be skipped.
542*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600543static bool validate_bool32(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
544 VkBool32 value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600545 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600546
547 if ((value != VK_TRUE) && (value != VK_FALSE)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600548 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600549 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName,
550 parameterName.get_name().c_str(), value);
Dustin Graves29148ff2016-03-23 19:44:00 -0600551 }
552
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600553 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600554}
555
556/**
557* Validate a Vulkan enumeration value.
558*
559* Generate a warning if an enumeration token value does not fall within the core enumeration
560* begin and end token values, and was not added to the enumeration by an extension. Extension
561* provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification,
562* with 1,000,000,000 as the base token value.
563*
564* @note This function does not expect to process enumerations defining bitmask flag bits.
565*
566* @param report_data debug_report_data object for routing validation messages.
567* @param apiName Name of API call being validated.
568* @param parameterName Name of parameter being validated.
569* @param enumName Name of the enumeration being validated.
570* @param begin The begin range value for the enumeration.
571* @param end The end range value for the enumeration.
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600572* @param value Enumeration value to validate.
Dustin Graves29148ff2016-03-23 19:44:00 -0600573* @return Boolean value indicating that the call should be skipped.
574*/
575template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600576bool validate_ranged_enum(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
577 const char *enumName, T begin, T end, T value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600578 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600579
580 if (((value < begin) || (value > end)) && !is_extension_added_token(value)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600581 skip_call |=
Dustin Gravesf233e502016-05-05 13:44:21 -0600582 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
583 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s (%d) does not fall within the begin..end range of the core %s "
584 "enumeration tokens and is not an extension added token",
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600585 apiName, parameterName.get_name().c_str(), value, enumName);
Dustin Graves29148ff2016-03-23 19:44:00 -0600586 }
587
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600588 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600589}
590
591/**
592* Validate an array of Vulkan enumeration value.
593*
594* Process all enumeration token values in the specified array and generate a warning if a value
595* does not fall within the core enumeration begin and end token values, and was not added to
596* the enumeration by an extension. Extension provided enumerations use the equation specified
597* in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value.
598*
599* @note This function does not expect to process enumerations defining bitmask flag bits.
600*
601* @param report_data debug_report_data object for routing validation messages.
602* @param apiName Name of API call being validated.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600603* @param countName Name of count parameter.
604* @param arrayName Name of array parameter.
Dustin Graves29148ff2016-03-23 19:44:00 -0600605* @param enumName Name of the enumeration being validated.
606* @param begin The begin range value for the enumeration.
607* @param end The end range value for the enumeration.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600608* @param count Number of enumeration values in the array.
609* @param array Array of enumeration values to validate.
610* @param countRequired The 'count' parameter may not be 0 when true.
611* @param arrayRequired The 'array' parameter may not be NULL when true.
Dustin Graves29148ff2016-03-23 19:44:00 -0600612* @return Boolean value indicating that the call should be skipped.
613*/
614template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600615static bool validate_ranged_enum_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
616 const ParameterName &arrayName, const char *enumName, T begin, T end, uint32_t count,
617 const T *array, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600618 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600619
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600620 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600621 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600622 } else {
623 for (uint32_t i = 0; i < count; ++i) {
624 if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600625 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600626 __LINE__, UNRECOGNIZED_VALUE, LayerName,
627 "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
628 "enumeration tokens and is not an extension added token",
629 apiName, arrayName.get_name().c_str(), i, array[i], enumName);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600630 }
Dustin Graves29148ff2016-03-23 19:44:00 -0600631 }
632 }
633
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600634 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600635}
636
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600637/**
Dustin Graves78df8512016-04-28 17:58:59 -0600638* Verify that a reserved VkFlags value is zero.
639*
640* Verify that the specified value is zero, to check VkFlags values that are reserved for
641* future use.
642*
643* @param report_data debug_report_data object for routing validation messages.
644* @param api_name Name of API call being validated.
645* @param parameter_name Name of parameter being validated.
646* @param value Value to validate.
647* @return Boolean value indicating that the call should be skipped.
648*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600649static bool validate_reserved_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600650 VkFlags value) {
651 bool skip_call = false;
652
653 if (value != 0) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600654 skip_call |=
655 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
656 RESERVED_PARAMETER, LayerName, "%s: parameter %s must be 0", api_name, parameter_name.get_name().c_str());
Dustin Graves78df8512016-04-28 17:58:59 -0600657 }
658
659 return skip_call;
660}
661
662/**
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600663* Validate a Vulkan bitmask value.
664*
665* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
666* for that type.
667*
668* @param report_data debug_report_data object for routing validation messages.
669* @param api_name Name of API call being validated.
670* @param parameter_name Name of parameter being validated.
671* @param flag_bits_name Name of the VkFlags type being validated.
672* @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
673* @param value VkFlags value to validate.
674* @param flags_required The 'value' parameter may not be 0 when true.
675* @return Boolean value indicating that the call should be skipped.
676*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600677static bool validate_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600678 const char *flag_bits_name, VkFlags all_flags, VkFlags value, bool flags_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600679 bool skip_call = false;
680
681 if (value == 0) {
682 if (flags_required) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600683 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600684 REQUIRED_PARAMETER, LayerName, "%s: value of %s must not be 0", api_name,
685 parameter_name.get_name().c_str());
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600686 }
687 } else if ((value & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600688 skip_call |=
689 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
690 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s contains flag bits that are not recognized members of %s",
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600691 api_name, parameter_name.get_name().c_str(), flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600692 }
693
694 return skip_call;
695}
696
697/**
698* Validate an array of Vulkan bitmask values.
699*
700* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
701* for that type.
702*
703* @param report_data debug_report_data object for routing validation messages.
704* @param api_name Name of API call being validated.
705* @param count_name Name of parameter being validated.
706* @param array_name Name of parameter being validated.
707* @param flag_bits_name Name of the VkFlags type being validated.
708* @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
709* @param count Number of VkFlags values in the array.
710* @param array Array of VkFlags value to validate.
711* @param count_required The 'count' parameter may not be 0 when true.
712* @param array_required The 'array' parameter may not be NULL when true.
713* @return Boolean value indicating that the call should be skipped.
714*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600715static bool validate_flags_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
716 const ParameterName &array_name, const char *flag_bits_name, VkFlags all_flags, uint32_t count,
Dustin Graves78df8512016-04-28 17:58:59 -0600717 const VkFlags *array, bool count_required, bool array_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600718 bool skip_call = false;
719
720 if ((count == 0) || (array == NULL)) {
721 skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required);
722 } else {
723 // Verify that all VkFlags values in the array
724 for (uint32_t i = 0; i < count; ++i) {
Dustin Graves78df8512016-04-28 17:58:59 -0600725 if (array[i] == 0) {
726 // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if
727 // elements in the array are allowed be 0
728 if (array_required) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600729 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
730 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: value of %s[%d] must not be 0", api_name,
731 array_name.get_name().c_str(), i);
Dustin Graves78df8512016-04-28 17:58:59 -0600732 }
733 } else if ((array[i] & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600734 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
735 __LINE__, UNRECOGNIZED_VALUE, LayerName,
736 "%s: value of %s[%d] contains flag bits that are not recognized members of %s", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600737 array_name.get_name().c_str(), i, flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600738 }
739 }
740 }
741
742 return skip_call;
743}
744
745/**
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600746* Get VkResult code description.
747*
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600748* Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API
749* specification.
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600750*
751* @param value VkResult code to process.
752* @return String describing the specified VkResult code.
753*/
754static std::string get_result_description(VkResult result) {
755 // clang-format off
756 switch (result) {
757 case VK_SUCCESS: return "a command completed successfully";
758 case VK_NOT_READY: return "a fence or query has not yet completed";
759 case VK_TIMEOUT: return "a wait operation has not completed in the specified time";
760 case VK_EVENT_SET: return "an event is signaled";
761 case VK_EVENT_RESET: return "an event is unsignalled";
762 case VK_INCOMPLETE: return "a return array was too small for the result";
763 case VK_ERROR_OUT_OF_HOST_MEMORY: return "a host memory allocation has failed";
764 case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "a device memory allocation has failed";
Dustin Graves2adca842016-05-16 18:35:55 -0600765 case VK_ERROR_INITIALIZATION_FAILED: return "initialization of an object has failed";
766 case VK_ERROR_DEVICE_LOST: return "the logical device has been lost";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600767 case VK_ERROR_MEMORY_MAP_FAILED: return "mapping of a memory object has failed";
768 case VK_ERROR_LAYER_NOT_PRESENT: return "the specified layer does not exist";
769 case VK_ERROR_EXTENSION_NOT_PRESENT: return "the specified extension does not exist";
770 case VK_ERROR_FEATURE_NOT_PRESENT: return "the requested feature is not available on this device";
771 case VK_ERROR_INCOMPATIBLE_DRIVER: return "a Vulkan driver could not be found";
772 case VK_ERROR_TOO_MANY_OBJECTS: return "too many objects of the type have already been created";
773 case VK_ERROR_FORMAT_NOT_SUPPORTED: return "the requested format is not supported on this device";
774 case VK_ERROR_SURFACE_LOST_KHR: return "a surface is no longer available";
775 case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "the requested window is already connected to another "
776 "VkSurfaceKHR object, or some other non-Vulkan surface object";
777 case VK_SUBOPTIMAL_KHR: return "an image became available, and the swapchain no longer "
778 "matches the surface properties exactly, but can still be used to "
779 "present to the surface successfully.";
780 case VK_ERROR_OUT_OF_DATE_KHR: return "a surface has changed in such a way that it is no "
781 "longer compatible with the swapchain";
782 case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "the display used by a swapchain does not use the same "
783 "presentable image layout, or is incompatible in a way that prevents "
784 "sharing an image";
785 case VK_ERROR_VALIDATION_FAILED_EXT: return "API validation has detected an invalid use of the API";
786 case VK_ERROR_INVALID_SHADER_NV: return "one or more shaders failed to compile or link";
Eric Engestrombcbb0fd2016-04-02 22:06:13 +0100787 default: return "an error has occurred";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600788 };
789 // clang-format on
790}
791
792/**
793* Validate return code.
794*
795* Print a message describing the reason for failure when an error code is returned.
796*
797* @param report_data debug_report_data object for routing validation messages.
798* @param apiName Name of API call being validated.
799* @param value VkResult value to validate.
800*/
801static void validate_result(debug_report_data *report_data, const char *apiName, VkResult result) {
Chris Forbesf1f4e382016-10-13 14:44:03 +1300802 if (result < 0 && result != VK_ERROR_VALIDATION_FAILED_EXT) {
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600803 std::string resultName = string_VkResult(result);
804
805 if (resultName == UnsupportedResultString) {
806 // Unrecognized result code
Dustin Gravesf233e502016-05-05 13:44:21 -0600807 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
808 FAILURE_RETURN_CODE, LayerName, "%s: returned a result code indicating that an error has occurred", apiName);
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600809 } else {
810 std::string resultDesc = get_result_description(result);
Dustin Gravesf233e502016-05-05 13:44:21 -0600811 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
812 FAILURE_RETURN_CODE, LayerName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(),
813 resultDesc.c_str());
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600814 }
815 }
816}
817
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600818} // namespace parameter_validation
819
Mark Lobodzinski739391a2016-03-17 15:08:18 -0600820#endif // PARAMETER_VALIDATION_UTILS_H