blob: dd67a72e34d3a88d728d5188e530d8a1e57091e3 [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 Lobodzinski64318ba2017-01-26 13:34:13 -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;
Mark Young0f183a82017-02-28 09:58:04 -070085 bool khx_device_group_creation_enabled;
86 bool khx_external_fence_capabilities_enabled;
87 bool khx_external_memory_capabilities_enabled;
88 bool khx_external_semaphore_capabilities_enabled;
Mark Young39389872017-01-19 21:10:49 -070089 bool ext_acquire_xlib_display_enabled;
90 bool ext_direct_mode_display_enabled;
91 bool ext_display_surface_counter_enabled;
92 bool nv_external_memory_capabilities_enabled;
Mark Lobodzinskiaf00fa82016-08-09 10:44:38 -060093};
94
Dustin Graves29148ff2016-03-23 19:44:00 -060095// String returned by string_VkStructureType for an unrecognized type.
Dustin Graves58c2f662016-03-08 17:48:20 -070096const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType";
97
Dustin Gravesca7aa7c2016-03-25 15:13:28 -060098// String returned by string_VkResult for an unrecognized type.
99const std::string UnsupportedResultString = "Unhandled VkResult";
100
Dustin Graves29148ff2016-03-23 19:44:00 -0600101// The base value used when computing the offset for an enumeration token value that is added by an extension.
102// When validating enumeration tokens, any value >= to this value is considered to be provided by an extension.
103// See Appendix C.10 "Assigning Extension Token Values" from the Vulkan specification
104const uint32_t ExtEnumBaseValue = 1000000000;
105
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700106template <typename T>
107bool is_extension_added_token(T value) {
Jamie Madill6069c822016-12-15 09:35:36 -0500108 return (static_cast<uint32_t>(std::abs(static_cast<int32_t>(value))) >= ExtEnumBaseValue);
Dustin Graves29148ff2016-03-23 19:44:00 -0600109}
110
111// VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE token is a special case that was converted from a core token to an
112// extension added token. Its original value was intentionally preserved after the conversion, so it does not use
113// the base value that other extension added tokens use, and it does not fall within the enum's begin/end range.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700114template <>
115bool is_extension_added_token(VkSamplerAddressMode value) {
Jamie Madill6069c822016-12-15 09:35:36 -0500116 bool result = (static_cast<uint32_t>(std::abs(static_cast<int32_t>(value))) >= ExtEnumBaseValue);
Dustin Graves29148ff2016-03-23 19:44:00 -0600117 return (result || (value == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE));
118}
119
Dustin Graves1e92cd72016-02-09 14:00:18 -0700120/**
Dustin Gravesf8032f22016-05-11 18:31:44 -0600121* Validate a minimum value.
122*
123* Verify that the specified value is greater than the specified lower bound.
124*
125* @param report_data debug_report_data object for routing validation messages.
126* @param api_name Name of API call being validated.
127* @param parameter_name Name of parameter being validated.
128* @param value Value to validate.
129* @param lower_bound Lower bound value to use for validation.
130* @return Boolean value indicating that the call should be skipped.
131*/
132template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600133bool ValidateGreaterThan(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name, T value,
134 T lower_bound) {
Dustin Gravesf8032f22016-05-11 18:31:44 -0600135 bool skip_call = false;
136
137 if (value <= lower_bound) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600138 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName,
139 "%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 -0600140 }
141
142 return skip_call;
143}
144
145/**
Dustin Graves1e92cd72016-02-09 14:00:18 -0700146 * Validate a required pointer.
147 *
Dustin Graves58c2f662016-03-08 17:48:20 -0700148 * Verify that a required pointer is not NULL.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700149 *
150 * @param report_data debug_report_data object for routing validation messages.
151 * @param apiName Name of API call being validated.
152 * @param parameterName Name of parameter being validated.
153 * @param value Pointer to validate.
154 * @return Boolean value indicating that the call should be skipped.
155 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600156static bool validate_required_pointer(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
Dustin Graves080069b2016-04-05 13:48:15 -0600157 const void *value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600158 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700159
160 if (value == NULL) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600161 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 -0600162 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
163 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700164 }
165
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600166 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700167}
168
169/**
170 * Validate array count and pointer to array.
171 *
Dustin Graves58d114b2016-03-08 14:42:59 -0700172 * Verify that required count and array parameters are not 0 or NULL. If the
173 * count parameter is not optional, verify that it is not 0. If the array
174 * parameter is NULL, and it is not optional, verify that count is 0.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700175 *
176 * @param report_data debug_report_data object for routing validation messages.
177 * @param apiName Name of API call being validated.
178 * @param countName Name of count parameter.
179 * @param arrayName Name of array parameter.
180 * @param count Number of elements in the array.
181 * @param array Array to validate.
182 * @param countRequired The 'count' parameter may not be 0 when true.
183 * @param arrayRequired The 'array' parameter may not be NULL when true.
184 * @return Boolean value indicating that the call should be skipped.
185 */
186template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600187bool validate_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
188 const ParameterName &arrayName, T count, const void *array, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600189 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700190
191 // Count parameters not tagged as optional cannot be 0
Józef Kucia20bb8fb2016-09-23 12:45:04 +0200192 if (countRequired && (count == 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600193 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 -0700194 REQUIRED_PARAMETER, LayerName, "%s: parameter %s must be greater than 0", apiName,
195 countName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700196 }
197
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600198 // Array parameters not tagged as optional cannot be NULL, unless the count is 0
Dustin Graves080069b2016-04-05 13:48:15 -0600199 if ((array == NULL) && arrayRequired && (count != 0)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600200 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 -0700201 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
202 arrayName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600203 }
204
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600205 return skip_call;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600206}
207
208/**
209* Validate pointer to array count and pointer to array.
210*
211* Verify that required count and array parameters are not NULL. If count
212* is not NULL and its value is not optional, verify that it is not 0. If the
213* array parameter is NULL, and it is not optional, verify that count is 0.
214* The array parameter will typically be optional for this case (where count is
215* a pointer), allowing the caller to retrieve the available count.
216*
217* @param report_data debug_report_data object for routing validation messages.
218* @param apiName Name of API call being validated.
219* @param countName Name of count parameter.
220* @param arrayName Name of array parameter.
221* @param count Pointer to the number of elements in the array.
222* @param array Array to validate.
223* @param countPtrRequired The 'count' parameter may not be NULL when true.
224* @param countValueRequired The '*count' value may not be 0 when true.
225* @param arrayRequired The 'array' parameter may not be NULL when true.
226* @return Boolean value indicating that the call should be skipped.
227*/
228template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600229bool validate_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
230 const ParameterName &arrayName, const T *count, const void *array, bool countPtrRequired,
231 bool countValueRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600232 bool skip_call = false;
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600233
234 if (count == NULL) {
235 if (countPtrRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600236 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 -0600237 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
238 countName.get_name().c_str());
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600239 }
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700240 } else {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600241 skip_call |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700242 }
243
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600244 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700245}
246
247/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600248 * Validate a pointer to a Vulkan structure.
249 *
250 * Verify that a required pointer to a structure is not NULL. If the pointer is
251 * not NULL, verify that each structure's sType field is set to the correct
252 * VkStructureType value.
Dustin Graves1e92cd72016-02-09 14:00:18 -0700253 *
254 * @param report_data debug_report_data object for routing validation messages.
255 * @param apiName Name of API call being validated.
256 * @param parameterName Name of struct parameter being validated.
257 * @param sTypeName Name of expected VkStructureType value.
258 * @param value Pointer to the struct to validate.
259 * @param sType VkStructureType for structure validation.
260 * @param required The parameter may not be NULL when true.
261 * @return Boolean value indicating that the call should be skipped.
262 */
263template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600264bool validate_struct_type(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
265 const char *sTypeName, const T *value, VkStructureType sType, bool required) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600266 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700267
268 if (value == NULL) {
Dustin Graves080069b2016-04-05 13:48:15 -0600269 if (required) {
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 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
272 parameterName.get_name().c_str());
Dustin Graves1e92cd72016-02-09 14:00:18 -0700273 }
274 } else if (value->sType != sType) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600275 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
276 INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s->sType must be %s", apiName,
277 parameterName.get_name().c_str(), sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700278 }
279
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600280 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700281}
282
283/**
Dustin Graves1e92cd72016-02-09 14:00:18 -0700284 * Validate an array of Vulkan structures
285 *
286 * Verify that required count and array parameters are not 0 or NULL. If
287 * the array contains 1 or more structures, verify that each structure's
288 * sType field is set to the correct VkStructureType value.
289 *
290 * @param report_data debug_report_data object for routing validation messages.
291 * @param apiName Name of API call being validated.
292 * @param countName Name of count parameter.
293 * @param arrayName Name of array parameter.
294 * @param sTypeName Name of expected VkStructureType value.
295 * @param count Number of elements in the array.
296 * @param array Array to validate.
297 * @param sType VkStructureType for structure validation.
298 * @param countRequired The 'count' parameter may not be 0 when true.
299 * @param arrayRequired The 'array' parameter may not be NULL when true.
300 * @return Boolean value indicating that the call should be skipped.
301 */
302template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600303bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
304 const ParameterName &arrayName, const char *sTypeName, uint32_t count, const T *array,
305 VkStructureType sType, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600306 bool skip_call = false;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700307
308 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600309 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700310 } else {
311 // Verify that all structs in the array have the correct type
312 for (uint32_t i = 0; i < count; ++i) {
313 if (array[i].sType != sType) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600314 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 -0600315 __LINE__, INVALID_STRUCT_STYPE, LayerName, "%s: parameter %s[%d].sType must be %s", apiName,
316 arrayName.get_name().c_str(), i, sTypeName);
Dustin Graves1e92cd72016-02-09 14:00:18 -0700317 }
318 }
319 }
320
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600321 return skip_call;
Dustin Graves1e92cd72016-02-09 14:00:18 -0700322}
323
Dustin Graves58d114b2016-03-08 14:42:59 -0700324/**
Mark Young39389872017-01-19 21:10:49 -0700325 * Validate an array of Vulkan structures.
326 *
327 * Verify that required count and array parameters are not NULL. If count
328 * is not NULL and its value is not optional, verify that it is not 0.
329 * If the array contains 1 or more structures, verify that each structure's
330 * sType field is set to the correct VkStructureType value.
331 *
332 * @param report_data debug_report_data object for routing validation messages.
333 * @param apiName Name of API call being validated.
334 * @param countName Name of count parameter.
335 * @param arrayName Name of array parameter.
336 * @param sTypeName Name of expected VkStructureType value.
337 * @param count Pointer to the number of elements in the array.
338 * @param array Array to validate.
339 * @param sType VkStructureType for structure validation.
340 * @param countPtrRequired The 'count' parameter may not be NULL when true.
341 * @param countValueRequired The '*count' value may not be 0 when true.
342 * @param arrayRequired The 'array' parameter may not be NULL when true.
343 * @return Boolean value indicating that the call should be skipped.
344 */
345template <typename T>
346bool validate_struct_type_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
347 const ParameterName &arrayName, const char *sTypeName, uint32_t *count, const T *array,
348 VkStructureType sType, bool countPtrRequired, bool countValueRequired, bool arrayRequired) {
349 bool skip_call = false;
350
351 if (count == NULL) {
352 if (countPtrRequired) {
353 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
354 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as NULL", apiName,
355 countName.get_name().c_str());
356 }
357 } else {
358 skip_call |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType,
359 countValueRequired, arrayRequired);
360 }
361
362 return skip_call;
363}
364
365/**
Dustin Graves20fd66f2016-04-18 18:33:21 -0600366* Validate a Vulkan handle.
367*
368* Verify that the specified handle is not VK_NULL_HANDLE.
369*
370* @param report_data debug_report_data object for routing validation messages.
371* @param api_name Name of API call being validated.
372* @param parameter_name Name of struct parameter being validated.
373* @param value Handle to validate.
374* @return Boolean value indicating that the call should be skipped.
375*/
376template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600377bool 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 -0600378 bool skip_call = false;
379
380 if (value == VK_NULL_HANDLE) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600381 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
382 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600383 parameter_name.get_name().c_str());
Dustin Graves20fd66f2016-04-18 18:33:21 -0600384 }
385
386 return skip_call;
387}
388
389/**
390* Validate an array of Vulkan handles.
391*
392* Verify that required count and array parameters are not NULL. If count
393* is not NULL and its value is not optional, verify that it is not 0.
394* If the array contains 1 or more handles, verify that no handle is set to
395* VK_NULL_HANDLE.
396*
397* @note This function is only intended to validate arrays of handles when none
398* of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles
399* that are allowed to contain VK_NULL_HANDLE, use validate_array() instead.
400*
401* @param report_data debug_report_data object for routing validation messages.
402* @param api_name Name of API call being validated.
403* @param count_name Name of count parameter.
404* @param array_name Name of array parameter.
405* @param count Number of elements in the array.
406* @param array Array to validate.
407* @param count_required The 'count' parameter may not be 0 when true.
408* @param array_required The 'array' parameter may not be NULL when true.
409* @return Boolean value indicating that the call should be skipped.
410*/
411template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600412bool validate_handle_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
413 const ParameterName &array_name, uint32_t count, const T *array, bool count_required,
414 bool array_required) {
Dustin Graves20fd66f2016-04-18 18:33:21 -0600415 bool skip_call = false;
416
417 if ((count == 0) || (array == NULL)) {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600418 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 -0600419 } else {
420 // Verify that no handles in the array are VK_NULL_HANDLE
421 for (uint32_t i = 0; i < count; ++i) {
422 if (array[i] == VK_NULL_HANDLE) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600423 skip_call |=
424 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
425 REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name,
426 array_name.get_name().c_str(), i);
Dustin Graves20fd66f2016-04-18 18:33:21 -0600427 }
428 }
429 }
430
431 return skip_call;
432}
433
434/**
Dustin Graves58d114b2016-03-08 14:42:59 -0700435 * Validate string array count and content.
436 *
437 * Verify that required count and array parameters are not 0 or NULL. If the
438 * count parameter is not optional, verify that it is not 0. If the array
439 * parameter is NULL, and it is not optional, verify that count is 0. If the
440 * array parameter is not NULL, verify that none of the strings are NULL.
441 *
442 * @param report_data debug_report_data object for routing validation messages.
443 * @param apiName Name of API call being validated.
444 * @param countName Name of count parameter.
445 * @param arrayName Name of array parameter.
446 * @param count Number of strings in the array.
447 * @param array Array of strings to validate.
448 * @param countRequired The 'count' parameter may not be 0 when true.
449 * @param arrayRequired The 'array' parameter may not be NULL when true.
450 * @return Boolean value indicating that the call should be skipped.
451 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600452static bool validate_string_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
453 const ParameterName &arrayName, uint32_t count, const char *const *array, bool countRequired,
454 bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600455 bool skip_call = false;
Dustin Graves58d114b2016-03-08 14:42:59 -0700456
457 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600458 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves58d114b2016-03-08 14:42:59 -0700459 } else {
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600460 // Verify that strings in the array are not NULL
Dustin Graves58d114b2016-03-08 14:42:59 -0700461 for (uint32_t i = 0; i < count; ++i) {
462 if (array[i] == NULL) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600463 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 -0600464 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: required parameter %s[%d] specified as NULL",
465 apiName, arrayName.get_name().c_str(), i);
Dustin Graves58d114b2016-03-08 14:42:59 -0700466 }
467 }
468 }
469
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600470 return skip_call;
Dustin Graves58d114b2016-03-08 14:42:59 -0700471}
472
Dustin Graves58c2f662016-03-08 17:48:20 -0700473/**
474 * Validate a structure's pNext member.
475 *
476 * Verify that the specified pNext value points to the head of a list of
477 * allowed extension structures. If no extension structures are allowed,
478 * verify that pNext is null.
479 *
480 * @param report_data debug_report_data object for routing validation messages.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600481 * @param api_name Name of API call being validated.
482 * @param parameter_name Name of parameter being validated.
483 * @param allowed_struct_names Names of allowed structs.
Dustin Graves58c2f662016-03-08 17:48:20 -0700484 * @param next Pointer to validate.
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600485 * @param allowed_type_count Total number of allowed structure types.
486 * @param allowed_types Array of strcuture types allowed for pNext.
487 * @param header_version Version of header defining the pNext validation rules.
Dustin Graves58c2f662016-03-08 17:48:20 -0700488 * @return Boolean value indicating that the call should be skipped.
489 */
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600490static bool validate_struct_pnext(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600491 const char *allowed_struct_names, const void *next, size_t allowed_type_count,
492 const VkStructureType *allowed_types, uint32_t header_version) {
493 bool skip_call = false;
Mark Lobodzinskic9b74d32017-03-27 11:52:02 -0600494 std::unordered_set<const void *> cycle_check;
495 std::unordered_set<VkStructureType, std::hash<int>> unique_stype_check;
496
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700497 const char disclaimer[] =
498 "This warning is based on the Valid Usage documentation for version %d of the Vulkan header. It "
499 "is possible that you are using a struct from a private extension or an extension that was added "
500 "to a later version of the Vulkan header, in which case your use of %s is perfectly valid but "
501 "is not guaranteed to work correctly with validation enabled";
Dustin Graves58c2f662016-03-08 17:48:20 -0700502
Mark Lobodzinskic9b74d32017-03-27 11:52:02 -0600503 // TODO: The valid pNext structure types are not recursive. Each structure has its own list of valid sTypes for pNext.
504 // Codegen a map of vectors containing the allowable pNext types for each struct and use that here -- also simplifies parms.
Dustin Graves58c2f662016-03-08 17:48:20 -0700505 if (next != NULL) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600506 if (allowed_type_count == 0) {
507 std::string message = "%s: value of %s must be NULL. ";
508 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600509 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
510 INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name, parameter_name.get_name().c_str(),
511 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700512 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600513 const VkStructureType *start = allowed_types;
514 const VkStructureType *end = allowed_types + allowed_type_count;
Dustin Graves58c2f662016-03-08 17:48:20 -0700515 const GenericHeader *current = reinterpret_cast<const GenericHeader *>(next);
516
Mark Lobodzinskic9b74d32017-03-27 11:52:02 -0600517 cycle_check.insert(next);
Dustin Graves58c2f662016-03-08 17:48:20 -0700518
Mark Lobodzinskic9b74d32017-03-27 11:52:02 -0600519
520 while (current != NULL) {
521 if (cycle_check.find(current->pNext) != cycle_check.end()) {
522 std::string message = "%s: %s chain contains a cycle -- pNext pointer " PRIx64 " is repeated.";
523 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
524 __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
525 parameter_name.get_name().c_str(), reinterpret_cast<uint64_t>(next));
526 break;
527 } else {
528 cycle_check.insert(current->pNext);
529 }
530
531 std::string type_name = string_VkStructureType(current->sType);
532 if (unique_stype_check.find(current->sType) != unique_stype_check.end()) {
533 std::string message = "%s: %s chain contains duplicate structure types: %s appears multiple times.";
534 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
535 __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
536 parameter_name.get_name().c_str(), type_name.c_str());
537 } else {
538 unique_stype_check.insert(current->sType);
539 }
540
541 if (std::find(start, end, current->sType) == end) {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600542 if (type_name == UnsupportedStructureTypeString) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700543 std::string message =
544 "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed "
545 "structures are [%s]. ";
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600546 message += disclaimer;
547 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
548 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600549 parameter_name.get_name().c_str(), current->sType, allowed_struct_names,
550 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700551 } else {
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600552 std::string message =
553 "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]. ";
554 message += disclaimer;
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600555 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
556 0, __LINE__, INVALID_STRUCT_PNEXT, LayerName, message.c_str(), api_name,
557 parameter_name.get_name().c_str(), type_name.c_str(), allowed_struct_names,
558 header_version, parameter_name.get_name().c_str());
Dustin Graves58c2f662016-03-08 17:48:20 -0700559 }
560 }
Dustin Graves58c2f662016-03-08 17:48:20 -0700561 current = reinterpret_cast<const GenericHeader *>(current->pNext);
562 }
563 }
564 }
565
Dustin Gravesaf5c0292016-07-19 13:43:53 -0600566 return skip_call;
Dustin Graves58c2f662016-03-08 17:48:20 -0700567}
568
Dustin Graves29148ff2016-03-23 19:44:00 -0600569/**
570* Validate a VkBool32 value.
571*
572* Generate a warning if a VkBool32 value is neither VK_TRUE nor VK_FALSE.
573*
574* @param report_data debug_report_data object for routing validation messages.
575* @param apiName Name of API call being validated.
576* @param parameterName Name of parameter being validated.
577* @param value Boolean value to validate.
578* @return Boolean value indicating that the call should be skipped.
579*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600580static bool validate_bool32(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
581 VkBool32 value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600582 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600583
584 if ((value != VK_TRUE) && (value != VK_FALSE)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600585 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 -0600586 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName,
587 parameterName.get_name().c_str(), value);
Dustin Graves29148ff2016-03-23 19:44:00 -0600588 }
589
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600590 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600591}
592
593/**
594* Validate a Vulkan enumeration value.
595*
596* Generate a warning if an enumeration token value does not fall within the core enumeration
597* begin and end token values, and was not added to the enumeration by an extension. Extension
598* provided enumerations use the equation specified in Appendix C.10 of the Vulkan specification,
599* with 1,000,000,000 as the base token value.
600*
601* @note This function does not expect to process enumerations defining bitmask flag bits.
602*
603* @param report_data debug_report_data object for routing validation messages.
604* @param apiName Name of API call being validated.
605* @param parameterName Name of parameter being validated.
606* @param enumName Name of the enumeration being validated.
607* @param begin The begin range value for the enumeration.
608* @param end The end range value for the enumeration.
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600609* @param value Enumeration value to validate.
Dustin Graves29148ff2016-03-23 19:44:00 -0600610* @return Boolean value indicating that the call should be skipped.
611*/
612template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600613bool validate_ranged_enum(debug_report_data *report_data, const char *apiName, const ParameterName &parameterName,
614 const char *enumName, T begin, T end, T value) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600615 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600616
617 if (((value < begin) || (value > end)) && !is_extension_added_token(value)) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700618 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
619 UNRECOGNIZED_VALUE, LayerName,
620 "%s: value of %s (%d) does not fall within the begin..end range of the core %s "
621 "enumeration tokens and is not an extension added token",
622 apiName, parameterName.get_name().c_str(), value, enumName);
Dustin Graves29148ff2016-03-23 19:44:00 -0600623 }
624
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600625 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600626}
627
628/**
629* Validate an array of Vulkan enumeration value.
630*
631* Process all enumeration token values in the specified array and generate a warning if a value
632* does not fall within the core enumeration begin and end token values, and was not added to
633* the enumeration by an extension. Extension provided enumerations use the equation specified
634* in Appendix C.10 of the Vulkan specification, with 1,000,000,000 as the base token value.
635*
636* @note This function does not expect to process enumerations defining bitmask flag bits.
637*
638* @param report_data debug_report_data object for routing validation messages.
639* @param apiName Name of API call being validated.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600640* @param countName Name of count parameter.
641* @param arrayName Name of array parameter.
Dustin Graves29148ff2016-03-23 19:44:00 -0600642* @param enumName Name of the enumeration being validated.
643* @param begin The begin range value for the enumeration.
644* @param end The end range value for the enumeration.
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600645* @param count Number of enumeration values in the array.
646* @param array Array of enumeration values to validate.
647* @param countRequired The 'count' parameter may not be 0 when true.
648* @param arrayRequired The 'array' parameter may not be NULL when true.
Dustin Graves29148ff2016-03-23 19:44:00 -0600649* @return Boolean value indicating that the call should be skipped.
650*/
651template <typename T>
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600652static bool validate_ranged_enum_array(debug_report_data *report_data, const char *apiName, const ParameterName &countName,
653 const ParameterName &arrayName, const char *enumName, T begin, T end, uint32_t count,
654 const T *array, bool countRequired, bool arrayRequired) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600655 bool skip_call = false;
Dustin Graves29148ff2016-03-23 19:44:00 -0600656
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600657 if ((count == 0) || (array == NULL)) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600658 skip_call |= validate_array(report_data, apiName, countName, arrayName, count, array, countRequired, arrayRequired);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600659 } else {
660 for (uint32_t i = 0; i < count; ++i) {
661 if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) {
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600662 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 -0600663 __LINE__, UNRECOGNIZED_VALUE, LayerName,
664 "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s "
665 "enumeration tokens and is not an extension added token",
666 apiName, arrayName.get_name().c_str(), i, array[i], enumName);
Dustin Graves0d15c6e2016-04-26 16:34:10 -0600667 }
Dustin Graves29148ff2016-03-23 19:44:00 -0600668 }
669 }
670
Mark Lobodzinski72ecd912016-08-11 13:25:38 -0600671 return skip_call;
Dustin Graves29148ff2016-03-23 19:44:00 -0600672}
673
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600674/**
Dustin Graves78df8512016-04-28 17:58:59 -0600675* Verify that a reserved VkFlags value is zero.
676*
677* Verify that the specified value is zero, to check VkFlags values that are reserved for
678* future use.
679*
680* @param report_data debug_report_data object for routing validation messages.
681* @param api_name Name of API call being validated.
682* @param parameter_name Name of parameter being validated.
683* @param value Value to validate.
684* @return Boolean value indicating that the call should be skipped.
685*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600686static bool validate_reserved_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600687 VkFlags value) {
688 bool skip_call = false;
689
690 if (value != 0) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600691 skip_call |=
692 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
693 RESERVED_PARAMETER, LayerName, "%s: parameter %s must be 0", api_name, parameter_name.get_name().c_str());
Dustin Graves78df8512016-04-28 17:58:59 -0600694 }
695
696 return skip_call;
697}
698
699/**
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600700* Validate a Vulkan bitmask value.
701*
702* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
703* for that type.
704*
705* @param report_data debug_report_data object for routing validation messages.
706* @param api_name Name of API call being validated.
707* @param parameter_name Name of parameter being validated.
708* @param flag_bits_name Name of the VkFlags type being validated.
709* @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
710* @param value VkFlags value to validate.
711* @param flags_required The 'value' parameter may not be 0 when true.
712* @return Boolean value indicating that the call should be skipped.
713*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600714static bool validate_flags(debug_report_data *report_data, const char *api_name, const ParameterName &parameter_name,
Dustin Graves78df8512016-04-28 17:58:59 -0600715 const char *flag_bits_name, VkFlags all_flags, VkFlags value, bool flags_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600716 bool skip_call = false;
717
718 if (value == 0) {
719 if (flags_required) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600720 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 -0600721 REQUIRED_PARAMETER, LayerName, "%s: value of %s must not be 0", api_name,
722 parameter_name.get_name().c_str());
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600723 }
724 } else if ((value & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600725 skip_call |=
726 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
727 UNRECOGNIZED_VALUE, LayerName, "%s: value of %s contains flag bits that are not recognized members of %s",
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600728 api_name, parameter_name.get_name().c_str(), flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600729 }
730
731 return skip_call;
732}
733
734/**
735* Validate an array of Vulkan bitmask values.
736*
737* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
738* for that type.
739*
740* @param report_data debug_report_data object for routing validation messages.
741* @param api_name Name of API call being validated.
742* @param count_name Name of parameter being validated.
743* @param array_name Name of parameter being validated.
744* @param flag_bits_name Name of the VkFlags type being validated.
745* @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
746* @param count Number of VkFlags values in the array.
747* @param array Array of VkFlags value to validate.
748* @param count_required The 'count' parameter may not be 0 when true.
749* @param array_required The 'array' parameter may not be NULL when true.
750* @return Boolean value indicating that the call should be skipped.
751*/
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600752static bool validate_flags_array(debug_report_data *report_data, const char *api_name, const ParameterName &count_name,
753 const ParameterName &array_name, const char *flag_bits_name, VkFlags all_flags, uint32_t count,
Dustin Graves78df8512016-04-28 17:58:59 -0600754 const VkFlags *array, bool count_required, bool array_required) {
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600755 bool skip_call = false;
756
757 if ((count == 0) || (array == NULL)) {
758 skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required);
759 } else {
760 // Verify that all VkFlags values in the array
761 for (uint32_t i = 0; i < count; ++i) {
Dustin Graves78df8512016-04-28 17:58:59 -0600762 if (array[i] == 0) {
763 // Current XML registry logic for validity generation uses the array parameter's optional tag to determine if
764 // elements in the array are allowed be 0
765 if (array_required) {
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600766 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
767 __LINE__, REQUIRED_PARAMETER, LayerName, "%s: value of %s[%d] must not be 0", api_name,
768 array_name.get_name().c_str(), i);
Dustin Graves78df8512016-04-28 17:58:59 -0600769 }
770 } else if ((array[i] & (~all_flags)) != 0) {
Dustin Gravesf233e502016-05-05 13:44:21 -0600771 skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
772 __LINE__, UNRECOGNIZED_VALUE, LayerName,
773 "%s: value of %s[%d] contains flag bits that are not recognized members of %s", api_name,
Dustin Graves8ffbbf62016-07-22 13:19:46 -0600774 array_name.get_name().c_str(), i, flag_bits_name);
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600775 }
776 }
777 }
778
779 return skip_call;
780}
781
782/**
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600783* Get VkResult code description.
784*
Dustin Graves9c6b62b2016-04-26 15:37:10 -0600785* Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API
786* specification.
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600787*
788* @param value VkResult code to process.
789* @return String describing the specified VkResult code.
790*/
791static std::string get_result_description(VkResult result) {
792 // clang-format off
793 switch (result) {
794 case VK_SUCCESS: return "a command completed successfully";
795 case VK_NOT_READY: return "a fence or query has not yet completed";
796 case VK_TIMEOUT: return "a wait operation has not completed in the specified time";
797 case VK_EVENT_SET: return "an event is signaled";
798 case VK_EVENT_RESET: return "an event is unsignalled";
799 case VK_INCOMPLETE: return "a return array was too small for the result";
800 case VK_ERROR_OUT_OF_HOST_MEMORY: return "a host memory allocation has failed";
801 case VK_ERROR_OUT_OF_DEVICE_MEMORY: return "a device memory allocation has failed";
Dustin Graves2adca842016-05-16 18:35:55 -0600802 case VK_ERROR_INITIALIZATION_FAILED: return "initialization of an object has failed";
803 case VK_ERROR_DEVICE_LOST: return "the logical device has been lost";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600804 case VK_ERROR_MEMORY_MAP_FAILED: return "mapping of a memory object has failed";
805 case VK_ERROR_LAYER_NOT_PRESENT: return "the specified layer does not exist";
806 case VK_ERROR_EXTENSION_NOT_PRESENT: return "the specified extension does not exist";
807 case VK_ERROR_FEATURE_NOT_PRESENT: return "the requested feature is not available on this device";
808 case VK_ERROR_INCOMPATIBLE_DRIVER: return "a Vulkan driver could not be found";
809 case VK_ERROR_TOO_MANY_OBJECTS: return "too many objects of the type have already been created";
810 case VK_ERROR_FORMAT_NOT_SUPPORTED: return "the requested format is not supported on this device";
811 case VK_ERROR_SURFACE_LOST_KHR: return "a surface is no longer available";
812 case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: return "the requested window is already connected to another "
813 "VkSurfaceKHR object, or some other non-Vulkan surface object";
814 case VK_SUBOPTIMAL_KHR: return "an image became available, and the swapchain no longer "
815 "matches the surface properties exactly, but can still be used to "
816 "present to the surface successfully.";
817 case VK_ERROR_OUT_OF_DATE_KHR: return "a surface has changed in such a way that it is no "
818 "longer compatible with the swapchain";
819 case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: return "the display used by a swapchain does not use the same "
820 "presentable image layout, or is incompatible in a way that prevents "
821 "sharing an image";
822 case VK_ERROR_VALIDATION_FAILED_EXT: return "API validation has detected an invalid use of the API";
823 case VK_ERROR_INVALID_SHADER_NV: return "one or more shaders failed to compile or link";
Eric Engestrombcbb0fd2016-04-02 22:06:13 +0100824 default: return "an error has occurred";
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600825 };
826 // clang-format on
827}
828
829/**
830* Validate return code.
831*
832* Print a message describing the reason for failure when an error code is returned.
833*
834* @param report_data debug_report_data object for routing validation messages.
835* @param apiName Name of API call being validated.
836* @param value VkResult value to validate.
837*/
838static void validate_result(debug_report_data *report_data, const char *apiName, VkResult result) {
Chris Forbesf1f4e382016-10-13 14:44:03 +1300839 if (result < 0 && result != VK_ERROR_VALIDATION_FAILED_EXT) {
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600840 std::string resultName = string_VkResult(result);
841
842 if (resultName == UnsupportedResultString) {
843 // Unrecognized result code
Dustin Gravesf233e502016-05-05 13:44:21 -0600844 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
845 FAILURE_RETURN_CODE, LayerName, "%s: returned a result code indicating that an error has occurred", apiName);
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600846 } else {
847 std::string resultDesc = get_result_description(result);
Dustin Gravesf233e502016-05-05 13:44:21 -0600848 log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
849 FAILURE_RETURN_CODE, LayerName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(),
850 resultDesc.c_str());
Dustin Gravesca7aa7c2016-03-25 15:13:28 -0600851 }
852 }
853}
854
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700855} // namespace parameter_validation
Dustin Gravesb83fc2d2016-05-04 12:56:08 -0600856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700857#endif // PARAMETER_VALIDATION_UTILS_H