From 43901a048d87f5b5dde23298df412c0775c63bfe Mon Sep 17 00:00:00 2001 From: Dustin Graves Date: Mon, 18 Apr 2016 18:33:21 -0600 Subject: layers: Add handle NULL checks to codegen Add support for validating that required handle parameters are not specified as VK_NULL_HANDLE to the parameter validation layer's code generator. - Add new parameter validation utility functions to validate required handles and arrays of handles. - Add new parameter validation layer entrypoints for functions that previously had no parameters to validate. - Add handle validation logic to the parameter validation code generator. Change-Id: I7a5680954245db4c1b12587f78e30e17c3903d6c --- layers/parameter_validation_utils.h | 83 ++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) (limited to 'layers/parameter_validation_utils.h') diff --git a/layers/parameter_validation_utils.h b/layers/parameter_validation_utils.h index 70e5fccc..83315f6d 100644 --- a/layers/parameter_validation_utils.h +++ b/layers/parameter_validation_utils.h @@ -161,7 +161,11 @@ bool validate_array(debug_report_data *report_data, const char *apiName, const c } /** - * Validate an Vulkan structure type. + * Validate a pointer to a Vulkan structure. + * + * Verify that a required pointer to a structure is not NULL. If the pointer is + * not NULL, verify that each structure's sType field is set to the correct + * VkStructureType value. * * @param report_data debug_report_data object for routing validation messages. * @param apiName Name of API call being validated. @@ -282,6 +286,83 @@ bool validate_struct_type_array(debug_report_data *report_data, const char *apiN return skipCall; } +/** +* Validate a Vulkan handle. +* +* Verify that the specified handle is not VK_NULL_HANDLE. +* +* @param report_data debug_report_data object for routing validation messages. +* @param api_name Name of API call being validated. +* @param parameter_name Name of struct parameter being validated. +* @param value Handle to validate. +* @return Boolean value indicating that the call should be skipped. +*/ +template +bool validate_required_handle(debug_report_data *report_data, const char *api_name, const char *parameter_name, T value) { + bool skip_call = false; + + if (value == VK_NULL_HANDLE) { + skip_call |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + ParameterValidationName, "%s: required parameter %s specified as VK_NULL_HANDLE", api_name, parameter_name); + } + + return skip_call; +} + +/** +* Validate an array of Vulkan handles. +* +* Verify that required count and array parameters are not NULL. If count +* is not NULL and its value is not optional, verify that it is not 0. +* If the array contains 1 or more handles, verify that no handle is set to +* VK_NULL_HANDLE. +* +* @note This function is only intended to validate arrays of handles when none +* of the handles are allowed to be VK_NULL_HANDLE. For arrays of handles +* that are allowed to contain VK_NULL_HANDLE, use validate_array() instead. +* +* @param report_data debug_report_data object for routing validation messages. +* @param api_name Name of API call being validated. +* @param count_name Name of count parameter. +* @param array_name Name of array parameter. +* @param count Number of elements in the array. +* @param array Array to validate. +* @param count_required The 'count' parameter may not be 0 when true. +* @param array_required The 'array' parameter may not be NULL when true. +* @return Boolean value indicating that the call should be skipped. +*/ +template +bool validate_handle_array(debug_report_data *report_data, const char *api_name, const char *count_name, const char *array_name, + uint32_t count, const T *array, bool count_required, bool array_required) { + bool skip_call = false; + + if ((count == 0) || (array == NULL)) { + // Count parameters not tagged as optional cannot be 0 + if ((count == 0) && count_required) { + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + ParameterValidationName, "%s: parameter %s must be greater than 0", api_name, count_name); + } + + // Array parameters not tagged as optional cannot be NULL, unless the count is 0 + if ((array == NULL) && array_required && (count != 0)) { + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + ParameterValidationName, "%s: required parameter %s specified as NULL", api_name, array_name); + } + } else { + // Verify that no handles in the array are VK_NULL_HANDLE + for (uint32_t i = 0; i < count; ++i) { + if (array[i] == VK_NULL_HANDLE) { + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + ParameterValidationName, "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name, + array_name, i); + } + } + } + + return skip_call; +} + /** * Validate string array count and content. * -- cgit v1.2.3