blob: 3cc85c0123095b296e3e9405c5b30429826023e0 [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 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070038 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.
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
59 FAILURE_RETURN_CODE, // A Vulkan return code indicating a failure condition
60 // was encountered.
61 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 {
Chris Forbesd017eff2016-11-02 17:36:42 +130076 bool surface_enabled;
Mark Lobodzinskiaf00fa82016-08-09 10:44:38 -060077 bool xlib_enabled;
78 bool xcb_enabled;
79 bool wayland_enabled;
80 bool mir_enabled;
81 bool android_enabled;
82 bool win32_enabled;
Chris Forbes2e47f432016-11-03 10:18:18 +130083 bool display_enabled;
Mark Young39389872017-01-19 21:10:49 -070084 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 Lobodzinskiaf00fa82016-08-09 10:44:38 -060089};
90
Dustin Graves29148ff2016-03-23 19:44:00 -060091// String returned by string_VkStructureType for an unrecognized type.
Dustin Graves58c2f662016-03-08 17:48:20 -070092const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType";
93
Dustin Gravesca7aa7c2016-03-25 15:13:28 -060094// String returned by string_VkResult for an unrecognized type.
95const std::string UnsupportedResultString = "Unhandled VkResult";
96
Dustin Graves29148ff2016-03-23 19:44:00 -060097// 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
100const uint32_t ExtEnumBaseValue = 1000000000;
101
102template <typename T> bool is_extension_added_token(T value) {
Jamie Madill6069c822016-12-15 09:35:36 -0500103 return (static_cast<uint32_t>(std::abs(static_cast<int32_t>(value))) >= ExtEnumBaseValue);
Dustin Graves29148ff2016-03-23 19:44:00 -0600104}
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.
109template <> bool is_extension_added_token(VkSamplerAddressMode value) {
Jamie Madill6069c822016-12-15 09:35:36 -0500110 bool result = (static_cast<uint32_t>(std::abs(static_cast<int32_t>(value))) >= ExtEnumBaseValue);
Dustin Graves29148ff2016-03-23 19:44:00 -0600111 return (result || (value == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE));
112}
113
Dustin Graves1e92cd72016-02-09 14:00:18 -0700114/**
Dustin Gravesf8032f22016-05-11 18:31:44 -0600115* 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*/
126template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600127bool ValidateGreaterThan(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name, T value,
128 T lower_bound) {
Dustin Gravesf8032f22016-05-11 18:31:44 -0600129 bool skip_call = false;
130
131 if (value <= lower_bound) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600132 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 Gravesf8032f22016-05-11 18:31:44 -0600134 }
135
136 return skip_call;
137}
138
139/**
Dustin Graves1e92cd72016-02-09 14:00:18 -0700140 * Validate a required pointer.
141 *
Dustin Graves58c2f662016-03-08 17:48:20 -0700142 * Verify that a required pointer is not NULL.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700143 *
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 Graves8ffbbf62016-07-22 13:19:46 -0600150static bool validate_required_pointer(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
Dustin Graves080069b2016-04-05 13:48:15 -0600151 const void *value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600152 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700153
154 if (value == NULL) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600155
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600156 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 -0600157 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
158 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700159 }
160
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600161 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700162}
163
164/**
165 * Validate array count and pointer to array.
166 *
Dustin Graves58d114b2016-03-08 14:42:59 -0700167 * 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 Graves1e92cd72016-02-09 14:00:18 -0700170 *
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 */
181template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600182bool 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 Lobodzinski72ecd912016-08-11 13:25:38 -0600184 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700185
186 // Count parameters not tagged as optional cannot be 0
Józef Kucia20bb8fb2016-09-23 12:45:04 +0200187 if (countRequired && (count == 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600188 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700189 REQUIRED_PARAMETER, LayerName, "%s: parameter %s must be greater than 0", apiName,
190 countName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700191 }
192
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600193 // Array parameters not tagged as optional cannot be NULL, unless the count is 0
Dustin Graves080069b2016-04-05 13:48:15 -0600194 if ((array == NULL) && arrayRequired && (count != 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600195 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700196 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
197 arrayName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600198 }
199
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600200 return skip_call;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600201}
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*/
223template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600224bool 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 Lobodzinski72ecd912016-08-11 13:25:38 -0600227 bool skip_call = false;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600228
229 if (count == NULL) {
230 if (countPtrRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600231 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 -0600232 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
233 countName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600234 }
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700235 } else {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600236 skip_call |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700237 }
238
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600239 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700240}
241
242/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600243 * Validate a pointer to a Vulkan structure.
244 *
245 * Verify that a required pointer to a structure is not NULL. If the pointer is
246 * not NULL, verify that each structure's sType field is set to the correct
247 * VkStructureType value.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700248 *
249 * @param report_data debug_report_data object for routing validation messages.
250 * @param apiName Name of API call being validated.
251 * @param parameterName Name of struct parameter being validated.
252 * @param sTypeName Name of expected VkStructureType value.
253 * @param value Pointer to the struct to validate.
254 * @param sType VkStructureType for structure validation.
255 * @param required The parameter may not be NULL when true.
256 * @return Boolean value indicating that the call should be skipped.
257 */
258template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600259bool validate_struct_type(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
260 const char *sTypeName, const T *value, VkStructureType sType, bool required) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600261 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700262
263 if (value == NULL) {
Dustin Graves080069b2016-04-05 13:48:15 -0600264 if (required) {
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 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
267 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700268 }
269 } else if (value->sType != sType) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600270 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
271 INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s->sType must be %s", apiName,
272 parameterName.get_name().c_str(), sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700273 }
274
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600275 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700276}
277
278/**
Dustin Graves1e92cd72016-02-09 14:00:18 -0700279 * Validate an array of Vulkan structures
280 *
281 * Verify that required count and array parameters are not 0 or NULL. If
282 * the array contains 1 or more structures, verify that each structure's
283 * sType field is set to the correct VkStructureType value.
284 *
285 * @param report_data debug_report_data object for routing validation messages.
286 * @param apiName Name of API call being validated.
287 * @param countName Name of count parameter.
288 * @param arrayName Name of array parameter.
289 * @param sTypeName Name of expected VkStructureType value.
290 * @param count Number of elements in the array.
291 * @param array Array to validate.
292 * @param sType VkStructureType for structure validation.
293 * @param countRequired The 'count' parameter may not be 0 when true.
294 * @param arrayRequired The 'array' parameter may not be NULL when true.
295 * @return Boolean value indicating that the call should be skipped.
296 */
297template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600298bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
299 const ParameterName &arrayName, const char *sTypeName, uint32_t count, const T *array,
300 VkStructureType sType, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600301 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700302
303 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600304 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700305 } else {
306 // Verify that all structs in the array have the correct type
307 for (uint32_t i = 0; i < count; ++i) {
308 if (array[i].sType != sType) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600309 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 -0600310 __LINE__, INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s[%d].sType must be %s", apiName,
311 arrayName.get_name().c_str(), i, sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700312 }
313 }
314 }
315
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600316 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700317}
318
Dustin Graves58d114b2016-03-08 14:42:59 -0700319/**
Mark Young39389872017-01-19 21:10:49 -0700320 * Validate an array of Vulkan structures.
321 *
322 * Verify that required count and array parameters are not NULL. If count
323 * is not NULL and its value is not optional, verify that it is not 0.
324 * If the array contains 1 or more structures, verify that each structure's
325 * sType field is set to the correct VkStructureType value.
326 *
327 * @param report_data debug_report_data object for routing validation messages.
328 * @param apiName Name of API call being validated.
329 * @param countName Name of count parameter.
330 * @param arrayName Name of array parameter.
331 * @param sTypeName Name of expected VkStructureType value.
332 * @param count Pointer to the number of elements in the array.
333 * @param array Array to validate.
334 * @param sType VkStructureType for structure validation.
335 * @param countPtrRequired The 'count' parameter may not be NULL when true.
336 * @param countValueRequired The '*count' value may not be 0 when true.
337 * @param arrayRequired The 'array' parameter may not be NULL when true.
338 * @return Boolean value indicating that the call should be skipped.
339 */
340template <typename T>
341bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
342 const ParameterName &arrayName, const char *sTypeName, uint32_t *count, const T *array,
343 VkStructureType sType, bool countPtrRequired, bool countValueRequired, bool arrayRequired) {
344 bool skip_call = false;
345
346 if (count == NULL) {
347 if (countPtrRequired) {
348 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
349 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
350 countName.get_name().c_str());
351 }
352 } else {
353 skip_call |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType,
354 countValueRequired, arrayRequired);
355 }
356
357 return skip_call;
358}
359
360/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600361* Validate a Vulkan handle.
362*
363* Verify that the specified handle is not VK_NULL_HANDLE.
364*
365* @param report_data debug_report_data object for routing validation messages.
366* @param api_name Name of API call being validated.
367* @param parameter_name Name of struct parameter being validated.
368* @param value Handle to validate.
369* @return Boolean value indicating that the call should be skipped.
370*/
371template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600372bool 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 -0600373 bool skip_call = false;
374
375 if (value == VK_NULL_HANDLE) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600376 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
377 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600378 parameter_name.get_name().c_str());
Dustin Graves20fd66f2016-04-18 18:33:21 -0600379 }
380
381 return skip_call;
382}
383
384/**
385* Validate an array of Vulkan handles.
386*
387* Verify that required count and array parameters are not NULL. If count
388* is not NULL and its value is not optional, verify that it is not 0.
389* If the array contains 1 or more handles, verify that no handle is set to
390* VK_NULL_HANDLE.
391*
392* @note This function is only intended to validate arrays of handles when none
393* of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles
394* that are allowed to contain VK_NULL_HANDLE, use validate_array() instead.
395*
396* @param report_data debug_report_data object for routing validation messages.
397* @param api_name Name of API call being validated.
398* @param count_name Name of count parameter.
399* @param array_name Name of array parameter.
400* @param count Number of elements in the array.
401* @param array Array to validate.
402* @param count_required The 'count' parameter may not be 0 when true.
403* @param array_required The 'array' parameter may not be NULL when true.
404* @return Boolean value indicating that the call should be skipped.
405*/
406template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600407bool validate_handle_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
408 const ParameterName &array_name, uint32_t count, const T *array, bool count_required,
409 bool array_required) {
Dustin Graves20fd66f2016-04-18 18:33:21 -0600410 bool skip_call = false;
411
412 if ((count == 0) || (array == NULL)) {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600413 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 -0600414 } else {
415 // Verify that no handles in the array are VK_NULL_HANDLE
416 for (uint32_t i = 0; i < count; ++i) {
417 if (array[i] == VK_NULL_HANDLE) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600418 skip_call |=
419 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
420 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name,
421 array_name.get_name().c_str(), i);
Dustin Graves20fd66f2016-04-18 18:33:21 -0600422 }
423 }
424 }
425
426 return skip_call;
427}
428
429/**
Dustin Graves58d114b2016-03-08 14:42:59 -0700430 * Validate string array count and content.
431 *
432 * Verify that required count and array parameters are not 0 or NULL. If the
433 * count parameter is not optional, verify that it is not 0. If the array
434 * parameter is NULL, and it is not optional, verify that count is 0. If the
435 * array parameter is not NULL, verify that none of the strings are NULL.
436 *
437 * @param report_data debug_report_data object for routing validation messages.
438 * @param apiName Name of API call being validated.
439 * @param countName Name of count parameter.
440 * @param arrayName Name of array parameter.
441 * @param count Number of strings in the array.
442 * @param array Array of strings to validate.
443 * @param countRequired The 'count' parameter may not be 0 when true.
444 * @param arrayRequired The 'array' parameter may not be NULL when true.
445 * @return Boolean value indicating that the call should be skipped.
446 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600447static bool validate_string_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
448 const ParameterName &arrayName, uint32_t count, const char *const *array, bool countRequired,
449 bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600450 bool skip_call = false;
Dustin Graves58d114b2016-03-08 14:42:59 -0700451
452 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600453 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves58d114b2016-03-08 14:42:59 -0700454 } else {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600455 // Verify that strings in the array are not NULL
Dustin Graves58d114b2016-03-08 14:42:59 -0700456 for (uint32_t i = 0; i < count; ++i) {
457 if (array[i] == NULL) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600458 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 -0600459 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as NULL",
460 apiName, arrayName.get_name().c_str(), i);
Dustin Graves58d114b2016-03-08 14:42:59 -0700461 }
462 }
463 }
464
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600465 return skip_call;
Dustin Graves58d114b2016-03-08 14:42:59 -0700466}
467
Dustin Graves58c2f662016-03-08 17:48:20 -0700468/**
469 * Validate a structure's pNext member.
470 *
471 * Verify that the specified pNext value points to the head of a list of
472 * allowed extension structures. If no extension structures are allowed,
473 * verify that pNext is null.
474 *
475 * @param report_data debug_report_data object for routing validation messages.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600476 * @param api_name Name of API call being validated.
477 * @param parameter_name Name of parameter being validated.
478 * @param allowed_struct_names Names of allowed structs.
Dustin Graves58c2f662016-03-08 17:48:20 -0700479 * @param next Pointer to validate.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600480 * @param allowed_type_count Total number of allowed structure types.
481 * @param allowed_types Array of strcuture types allowed for pNext.
482 * @param header_version Version of header defining the pNext validation rules.
Dustin Graves58c2f662016-03-08 17:48:20 -0700483 * @return Boolean value indicating that the call should be skipped.
484 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600485static bool validate_struct_pnext(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600486 const char *allowed_struct_names, const void *next, size_t allowed_type_count,
487 const VkStructureType *allowed_types, uint32_t header_version) {
488 bool skip_call = false;
489 const char disclaimer[] = "This warning is based on the Valid Usage documentation for version %d of the Vulkan header. It "
490 "is possible that you are using a struct from a private extension or an extension that was added "
491 "to a later version of the Vulkan header, in which case your use of %s is perfectly valid but "
492 "is not guaranteed to work correctly with validation enabled";
Dustin Graves58c2f662016-03-08 17:48:20 -0700493
494 if (next != NULL) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600495 if (allowed_type_count == 0) {
496 std::string message = "%s: value of %s must be NULL. ";
497 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600498 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
499 INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name, parameter_name.get_name().c_str(),
500 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700501 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600502 const VkStructureType *start = allowed_types;
503 const VkStructureType *end = allowed_types + allowed_type_count;
Dustin Graves58c2f662016-03-08 17:48:20 -0700504 const GenericHeader *current = reinterpret_cast<const GenericHeader *>(next);
505
506 while (current != NULL) {
507 if (std::find(start, end, current->sType) == end) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600508 std::string type_name = string_VkStructureType(current->sType);
Dustin Graves58c2f662016-03-08 17:48:20 -0700509
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600510 if (type_name == UnsupportedStructureTypeString) {
511 std::string message = "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed "
512 "structures are [%s]. ";
513 message += disclaimer;
514 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
515 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600516 parameter_name.get_name().c_str(), current->sType, allowed_struct_names,
517 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700518 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600519 std::string message =
520 "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]. ";
521 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600522 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
523 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
524 parameter_name.get_name().c_str(), type_name.c_str(), allowed_struct_names,
525 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700526 }
527 }
528
529 current = reinterpret_cast<const GenericHeader *>(current->pNext);
530 }
531 }
532 }
533
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600534 return skip_call;
Dustin Graves58c2f662016-03-08 17:48:20 -0700535}
536
Dustin Graves29148ff2016-03-23 19:44:00 -0600537/**
538* Validate a VkBool32 value.
539*
540* Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE.
541*
542* @param report_data debug_report_data object for routing validation messages.
543* @param apiName Name of API call being validated.
544* @param parameterName Name of parameter being validated.
545* @param value Boolean value to validate.
546* @return Boolean value indicating that the call should be skipped.
547*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600548static bool validate_bool32(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
549 VkBool32 value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600550 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600551
552 if ((value != VK_TRUE) && (value != VK_FALSE)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600553 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 -0600554 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName,
555 parameterName.get_name().c_str(), value);
Dustin Graves29148ff2016-03-23 19:44:00 -0600556 }
557
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600558 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600559}
560
561/**
562* Validate a Vulkan enumeration value.
563*
564* Generate a warning if an enumeration token value does not fall within the core enumeration
565* begin and end token values, and was not added to the enumeration by an extension. Extension
566* provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification,
567* with 1,000,000,000 as the base token value.
568*
569* @note This function does not expect to process enumerations defining bitmask flag bits.
570*
571* @param report_data debug_report_data object for routing validation messages.
572* @param apiName Name of API call being validated.
573* @param parameterName Name of parameter being validated.
574* @param enumName Name of the enumeration being validated.
575* @param begin The begin range value for the enumeration.
576* @param end The end range value for the enumeration.
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600577* @param value Enumeration value to validate.
Dustin Graves29148ff2016-03-23 19:44:00 -0600578* @return Boolean value indicating that the call should be skipped.
579*/
580template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600581bool validate_ranged_enum(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
582 const char *enumName, T begin, T end, T value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600583 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600584
585 if (((value < begin) || (value > end)) && !is_extension_added_token(value)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600586 skip_call |=
Dustin Gravesf233e502016-05-05 13:44:21 -0600587 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
588 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s (%d) does not fall within the begin..end range of the core %s "
589 "enumeration tokens and is not an extension added token",
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600590 apiName, parameterName.get_name().c_str(), value, enumName);
Dustin Graves29148ff2016-03-23 19:44:00 -0600591 }
592
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600593 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600594}
595
596/**
597* Validate an array of Vulkan enumeration value.
598*
599* Process all enumeration token values in the specified array and generate a warning if a value
600* does not fall within the core enumeration begin and end token values, and was not added to
601* the enumeration by an extension. Extension provided enumerations use the equation specified
602* in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value.
603*
604* @note This function does not expect to process enumerations defining bitmask flag bits.
605*
606* @param report_data debug_report_data object for routing validation messages.
607* @param apiName Name of API call being validated.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600608* @param countName Name of count parameter.
609* @param arrayName Name of array parameter.
Dustin Graves29148ff2016-03-23 19:44:00 -0600610* @param enumName Name of the enumeration being validated.
611* @param begin The begin range value for the enumeration.
612* @param end The end range value for the enumeration.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600613* @param count Number of enumeration values in the array.
614* @param array Array of enumeration values to validate.
615* @param countRequired The 'count' parameter may not be 0 when true.
616* @param arrayRequired The 'array' parameter may not be NULL when true.
Dustin Graves29148ff2016-03-23 19:44:00 -0600617* @return Boolean value indicating that the call should be skipped.
618*/
619template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600620static bool validate_ranged_enum_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
621 const ParameterName &arrayName, const char *enumName, T begin, T end, uint32_t count,
622 const T *array, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600623 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600624
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600625 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600626 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600627 } else {
628 for (uint32_t i = 0; i < count; ++i) {
629 if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600630 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 -0600631 __LINE__, UNRECOGNIZED_VALUE, LayerName,
632 "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
633 "enumeration tokens and is not an extension added token",
634 apiName, arrayName.get_name().c_str(), i, array[i], enumName);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600635 }
Dustin Graves29148ff2016-03-23 19:44:00 -0600636 }
637 }
638
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600639 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600640}
641
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600642/**
Dustin Graves78df8512016-04-28 17:58:59 -0600643* Verify that a reserved VkFlags value is zero.
644*
645* Verify that the specified value is zero, to check VkFlags values that are reserved for
646* future use.
647*
648* @param report_data debug_report_data object for routing validation messages.
649* @param api_name Name of API call being validated.
650* @param parameter_name Name of parameter being validated.
651* @param value Value to validate.
652* @return Boolean value indicating that the call should be skipped.
653*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600654static bool validate_reserved_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600655 VkFlags value) {
656 bool skip_call = false;
657
658 if (value != 0) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600659 skip_call |=
660 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
661 RESERVED_PARAMETER, LayerName, "%s: parameter %s must be 0", api_name, parameter_name.get_name().c_str());
Dustin Graves78df8512016-04-28 17:58:59 -0600662 }
663
664 return skip_call;
665}
666
667/**
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600668* Validate a Vulkan bitmask value.
669*
670* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
671* for that type.
672*
673* @param report_data debug_report_data object for routing validation messages.
674* @param api_name Name of API call being validated.
675* @param parameter_name Name of parameter being validated.
676* @param flag_bits_name Name of the VkFlags type being validated.
677* @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
678* @param value VkFlags value to validate.
679* @param flags_required The 'value' parameter may not be 0 when true.
680* @return Boolean value indicating that the call should be skipped.
681*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600682static bool validate_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600683 const char *flag_bits_name, VkFlags all_flags, VkFlags value, bool flags_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600684 bool skip_call = false;
685
686 if (value == 0) {
687 if (flags_required) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600688 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 -0600689 REQUIRED_PARAMETER, LayerName, "%s: value of %s must not be 0", api_name,
690 parameter_name.get_name().c_str());
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600691 }
692 } else if ((value & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600693 skip_call |=
694 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
695 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s contains flag bits that are not recognized members of %s",
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600696 api_name, parameter_name.get_name().c_str(), flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600697 }
698
699 return skip_call;
700}
701
702/**
703* Validate an array of Vulkan bitmask values.
704*
705* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
706* for that type.
707*
708* @param report_data debug_report_data object for routing validation messages.
709* @param api_name Name of API call being validated.
710* @param count_name Name of parameter being validated.
711* @param array_name Name of parameter being validated.
712* @param flag_bits_name Name of the VkFlags type being validated.
713* @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
714* @param count Number of VkFlags values in the array.
715* @param array Array of VkFlags value to validate.
716* @param count_required The 'count' parameter may not be 0 when true.
717* @param array_required The 'array' parameter may not be NULL when true.
718* @return Boolean value indicating that the call should be skipped.
719*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600720static bool validate_flags_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
721 const ParameterName &array_name, const char *flag_bits_name, VkFlags all_flags, uint32_t count,
Dustin Graves78df8512016-04-28 17:58:59 -0600722 const VkFlags *array, bool count_required, bool array_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600723 bool skip_call = false;
724
725 if ((count == 0) || (array == NULL)) {
726 skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required);
727 } else {
728 // Verify that all VkFlags values in the array
729 for (uint32_t i = 0; i < count; ++i) {
Dustin Graves78df8512016-04-28 17:58:59 -0600730 if (array[i] == 0) {
731 // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if
732 // elements in the array are allowed be 0
733 if (array_required) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600734 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
735 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: value of %s[%d] must not be 0", api_name,
736 array_name.get_name().c_str(), i);
Dustin Graves78df8512016-04-28 17:58:59 -0600737 }
738 } else if ((array[i] & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600739 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
740 __LINE__, UNRECOGNIZED_VALUE, LayerName,
741 "%s: value of %s[%d] contains flag bits that are not recognized members of %s", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600742 array_name.get_name().c_str(), i, flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600743 }
744 }
745 }
746
747 return skip_call;
748}
749
750/**
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600751* Get VkResult code description.
752*
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600753* Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API
754* specification.
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600755*
756* @param value VkResult code to process.
757* @return String describing the specified VkResult code.
758*/
759static std::string get_result_description(VkResult result) {
760 // clang-format off
761 switch (result) {
762 case VK_SUCCESS: return "a command completed successfully";
763 case VK_NOT_READY: return "a fence or query has not yet completed";
764 case VK_TIMEOUT: return "a wait operation has not completed in the specified time";
765 case VK_EVENT_SET: return "an event is signaled";
766 case VK_EVENT_RESET: return "an event is unsignalled";
767 case VK_INCOMPLETE: return "a return array was too small for the result";
768 case VK_ERROR_OUT_OF_HOST_MEMORY: return "a host memory allocation has failed";
769 case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "a device memory allocation has failed";
Dustin Graves2adca842016-05-16 18:35:55 -0600770 case VK_ERROR_INITIALIZATION_FAILED: return "initialization of an object has failed";
771 case VK_ERROR_DEVICE_LOST: return "the logical device has been lost";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600772 case VK_ERROR_MEMORY_MAP_FAILED: return "mapping of a memory object has failed";
773 case VK_ERROR_LAYER_NOT_PRESENT: return "the specified layer does not exist";
774 case VK_ERROR_EXTENSION_NOT_PRESENT: return "the specified extension does not exist";
775 case VK_ERROR_FEATURE_NOT_PRESENT: return "the requested feature is not available on this device";
776 case VK_ERROR_INCOMPATIBLE_DRIVER: return "a Vulkan driver could not be found";
777 case VK_ERROR_TOO_MANY_OBJECTS: return "too many objects of the type have already been created";
778 case VK_ERROR_FORMAT_NOT_SUPPORTED: return "the requested format is not supported on this device";
779 case VK_ERROR_SURFACE_LOST_KHR: return "a surface is no longer available";
780 case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "the requested window is already connected to another "
781 "VkSurfaceKHR object, or some other non-Vulkan surface object";
782 case VK_SUBOPTIMAL_KHR: return "an image became available, and the swapchain no longer "
783 "matches the surface properties exactly, but can still be used to "
784 "present to the surface successfully.";
785 case VK_ERROR_OUT_OF_DATE_KHR: return "a surface has changed in such a way that it is no "
786 "longer compatible with the swapchain";
787 case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "the display used by a swapchain does not use the same "
788 "presentable image layout, or is incompatible in a way that prevents "
789 "sharing an image";
790 case VK_ERROR_VALIDATION_FAILED_EXT: return "API validation has detected an invalid use of the API";
791 case VK_ERROR_INVALID_SHADER_NV: return "one or more shaders failed to compile or link";
Eric Engestrombcbb0fd2016-04-02 22:06:13 +0100792 default: return "an error has occurred";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600793 };
794 // clang-format on
795}
796
797/**
798* Validate return code.
799*
800* Print a message describing the reason for failure when an error code is returned.
801*
802* @param report_data debug_report_data object for routing validation messages.
803* @param apiName Name of API call being validated.
804* @param value VkResult value to validate.
805*/
806static void validate_result(debug_report_data *report_data, const char *apiName, VkResult result) {
Chris Forbesf1f4e382016-10-13 14:44:03 +1300807 if (result < 0 && result != VK_ERROR_VALIDATION_FAILED_EXT) {
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600808 std::string resultName = string_VkResult(result);
809
810 if (resultName == UnsupportedResultString) {
811 // Unrecognized result code
Dustin Gravesf233e502016-05-05 13:44:21 -0600812 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
813 FAILURE_RETURN_CODE, LayerName, "%s: returned a result code indicating that an error has occurred", apiName);
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600814 } else {
815 std::string resultDesc = get_result_description(result);
Dustin Gravesf233e502016-05-05 13:44:21 -0600816 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
817 FAILURE_RETURN_CODE, LayerName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(),
818 resultDesc.c_str());
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600819 }
820 }
821}
822
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600823} // namespace parameter_validation
824
Mark Lobodzinski739391a2016-03-17 15:08:18 -0600825#endif // PARAMETER_VALIDATION_UTILS_H