diff options
| author | Dustin Graves <dustin@lunarg.com> | 2016-05-04 12:56:08 -0600 |
|---|---|---|
| committer | Mark Lobodzinski <mark@lunarg.com> | 2016-05-09 11:46:23 -0600 |
| commit | fd533e358307f6264fb7824a5367eb243df2e85e (patch) | |
| tree | 81363ee6b903d50ab36bacaaa4fa1b74b206c6bf /layers/parameter_validation_utils.h | |
| parent | 56dba6a326542cb8345232cbcbc973f20bbf573b (diff) | |
| download | usermoji-fd533e358307f6264fb7824a5367eb243df2e85e.tar.xz | |
layers: Add parameter_validation namespace
Add parameter_validation namespace for utility functions. Namespace will
be extended to include core layer functions in a future update.
Change-Id: I0929f5caacbf3e1b4509f051ea020566cce44e3e
Diffstat (limited to 'layers/parameter_validation_utils.h')
| -rw-r--r-- | layers/parameter_validation_utils.h | 180 |
1 files changed, 87 insertions, 93 deletions
diff --git a/layers/parameter_validation_utils.h b/layers/parameter_validation_utils.h index 56673513..29182bf8 100644 --- a/layers/parameter_validation_utils.h +++ b/layers/parameter_validation_utils.h @@ -29,15 +29,15 @@ #include "vk_enum_string_helper.h" #include "vk_layer_logging.h" -namespace { +namespace parameter_validation { + struct GenericHeader { VkStructureType sType; const void *pNext; }; -} // Layer name string to be logged with validation messages. -const char ParameterValidationName[] = "ParameterValidation"; +const char LayerName[] = "ParameterValidation"; // String returned by string_VkStructureType for an unrecognized type. const std::string UnsupportedStructureTypeString = "Unhandled VkStructureType"; @@ -78,45 +78,8 @@ static bool validate_required_pointer(debug_report_data *report_data, const char bool skipCall = false; if (value == NULL) { - skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName); - } - - return skipCall; -} - -/** - * Validate pointer to array count and pointer to array. - * - * 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 parameter is NULL, and it is not optional, verify that count is 0. - * The array parameter will typically be optional for this case (where count is - * a pointer), allowing the caller to retrieve the available count. - * - * @param report_data debug_report_data object for routing validation messages. - * @param apiName Name of API call being validated. - * @param countName Name of count parameter. - * @param arrayName Name of array parameter. - * @param count Pointer to the number of elements in the array. - * @param array Array to validate. - * @param countPtrRequired The 'count' parameter may not be NULL when true. - * @param countValueRequired The '*count' value may not be 0 when true. - * @param arrayRequired The 'array' parameter may not be NULL when true. - * @return Boolean value indicating that the call should be skipped. - */ -template <typename T> -bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, - const T *count, const void *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired) { - bool skipCall = false; - - if (count == NULL) { - if (countPtrRequired) { - skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName); - } - } else { - skipCall |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: required parameter %s specified as NULL", apiName, parameterName); } return skipCall; @@ -146,14 +109,52 @@ bool validate_array(debug_report_data *report_data, const char *apiName, const c // Count parameters not tagged as optional cannot be 0 if ((count == 0) && countRequired) { - skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: parameter %s must be greater than 0", apiName, countName); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: parameter %s must be greater than 0", apiName, countName); } // Array parameters not tagged as optional cannot be NULL, unless the count is 0 if ((array == NULL) && arrayRequired && (count != 0)) { - skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, arrayName); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: required parameter %s specified as NULL", apiName, arrayName); + } + + return skipCall; +} + +/** +* Validate pointer to array count and pointer to array. +* +* 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 parameter is NULL, and it is not optional, verify that count is 0. +* The array parameter will typically be optional for this case (where count is +* a pointer), allowing the caller to retrieve the available count. +* +* @param report_data debug_report_data object for routing validation messages. +* @param apiName Name of API call being validated. +* @param countName Name of count parameter. +* @param arrayName Name of array parameter. +* @param count Pointer to the number of elements in the array. +* @param array Array to validate. +* @param countPtrRequired The 'count' parameter may not be NULL when true. +* @param countValueRequired The '*count' value may not be 0 when true. +* @param arrayRequired The 'array' parameter may not be NULL when true. +* @return Boolean value indicating that the call should be skipped. +*/ +template <typename T> +bool validate_array(debug_report_data *report_data, const char *apiName, const char *countName, const char *arrayName, + const T *count, const void *array, bool countPtrRequired, bool countValueRequired, bool arrayRequired) { + bool skipCall = false; + + if (count == NULL) { + if (countPtrRequired) { + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + LayerName, "%s: required parameter %s specified as NULL", apiName, countName); + } + } + else { + skipCall |= validate_array(report_data, apiName, countName, arrayName, (*count), array, countValueRequired, arrayRequired); } return skipCall; @@ -183,11 +184,11 @@ bool validate_struct_type(debug_report_data *report_data, const char *apiName, c if (value == NULL) { if (required) { skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, parameterName); + LayerName, "%s: required parameter %s specified as NULL", apiName, parameterName); } } else if (value->sType != sType) { - skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: parameter %s->sType must be %s", apiName, parameterName, sTypeName); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: parameter %s->sType must be %s", apiName, parameterName, sTypeName); } return skipCall; @@ -223,7 +224,7 @@ bool validate_struct_type_array(debug_report_data *report_data, const char *apiN if (count == NULL) { if (countPtrRequired) { skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s specified as NULL", apiName, countName); + LayerName, "%s: required parameter %s specified as NULL", apiName, countName); } } else { skipCall |= validate_struct_type_array(report_data, apiName, countName, arrayName, sTypeName, (*count), array, sType, @@ -264,9 +265,8 @@ bool validate_struct_type_array(debug_report_data *report_data, const char *apiN // Verify that all structs in the array have the correct type for (uint32_t i = 0; i < count; ++i) { if (array[i].sType != sType) { - skipCall |= - log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: parameter %s[%d].sType must be %s", apiName, arrayName, i, sTypeName); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + LayerName, "%s: parameter %s[%d].sType must be %s", apiName, arrayName, i, sTypeName); } } } @@ -290,9 +290,8 @@ bool validate_required_handle(debug_report_data *report_data, const char *api_na 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); + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: required parameter %s specified as VK_NULL_HANDLE", api_name, parameter_name); } return skip_call; @@ -331,9 +330,9 @@ bool validate_handle_array(debug_report_data *report_data, const char *api_name, // 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); + skip_call |= + log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: required parameter %s[%d] specified as VK_NULL_HANDLE", api_name, array_name, i); } } } @@ -369,9 +368,8 @@ static bool validate_string_array(debug_report_data *report_data, const char *ap // Verify that strings in the array are not NULL for (uint32_t i = 0; i < count; ++i) { if (array[i] == NULL) { - skipCall |= - log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: required parameter %s[%d] specified as NULL", apiName, arrayName, i); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + LayerName, "%s: required parameter %s[%d] specified as NULL", apiName, arrayName, i); } } } @@ -403,7 +401,7 @@ static bool validate_struct_pnext(debug_report_data *report_data, const char *ap if (next != NULL) { if (allowedTypeCount == 0) { skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s must be NULL", apiName, parameterName); + LayerName, "%s: value of %s must be NULL", apiName, parameterName); } else { const VkStructureType *start = allowedTypes; const VkStructureType *end = allowedTypes + allowedTypeCount; @@ -415,14 +413,12 @@ static bool validate_struct_pnext(debug_report_data *report_data, const char *ap if (typeName == UnsupportedStructureTypeString) { skipCall |= log_msg( - report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, + report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, "%s: %s chain includes a structure with unexpected VkStructureType (%d); Allowed structures are [%s]", apiName, parameterName, current->sType, allowedStructNames); } else { skipCall |= log_msg( - report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, + report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, "%s: %s chain includes a structure with unexpected VkStructureType %s; Allowed structures are [%s]", apiName, parameterName, typeName.c_str(), allowedStructNames); } @@ -451,9 +447,8 @@ static bool validate_bool32(debug_report_data *report_data, const char *apiName, bool skipCall = false; if ((value != VK_TRUE) && (value != VK_FALSE)) { - skipCall |= - log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName, parameterName, value); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: value of %s (%d) is neither VK_TRUE nor VK_FALSE", apiName, parameterName, value); } return skipCall; @@ -484,11 +479,10 @@ bool validate_ranged_enum(debug_report_data *report_data, const char *apiName, c bool skipCall = false; if (((value < begin) || (value > end)) && !is_extension_added_token(value)) { - skipCall |= - log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s (%d) does not fall within the begin..end range of the core %s " - "enumeration tokens and is not an extension added token", - apiName, parameterName, value, enumName); + skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: value of %s (%d) does not fall within the begin..end range of the core %s " + "enumeration tokens and is not an extension added token", + apiName, parameterName, value, enumName); } return skipCall; @@ -529,9 +523,8 @@ static bool validate_ranged_enum_array(debug_report_data *report_data, const cha for (uint32_t i = 0; i < count; ++i) { if (((array[i] < begin) || (array[i] > end)) && !is_extension_added_token(array[i])) { skipCall |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, - "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s " - "enumeration tokens and is not an extension added token", + LayerName, "%s: value of %s[%d] (%d) does not fall within the begin..end range of the core %s " + "enumeration tokens and is not an extension added token", apiName, arrayName, i, array[i], enumName); } } @@ -557,8 +550,8 @@ static bool validate_reserved_flags(debug_report_data *report_data, const char * bool skip_call = false; if (value != 0) { - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: parameter %s must be 0", api_name, parameter_name); + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: parameter %s must be 0", api_name, parameter_name); } return skip_call; @@ -586,12 +579,12 @@ static bool validate_flags(debug_report_data *report_data, const char *api_name, if (value == 0) { if (flags_required) { skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s must not be 0", api_name, parameter_name); + LayerName, "%s: value of %s must not be 0", api_name, parameter_name); } } else if ((value & (~all_flags)) != 0) { - skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s contains flag bits that are not recognized members of %s", - api_name, parameter_name, flag_bits_name); + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: value of %s contains flag bits that are not recognized members of %s", api_name, parameter_name, + flag_bits_name); } return skip_call; @@ -630,13 +623,12 @@ static bool validate_flags_array(debug_report_data *report_data, const char *api // elements in the array are allowed be 0 if (array_required) { skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, - 1, ParameterValidationName, "%s: value of %s[%d] must not be 0", api_name, array_name, i); + 1, LayerName, "%s: value of %s[%d] must not be 0", api_name, array_name, i); } } else if ((array[i] & (~all_flags)) != 0) { - skip_call |= - log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: value of %s[%d] contains flag bits that are not recognized members of %s", - api_name, array_name, i, flag_bits_name); + skip_call |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, + LayerName, "%s: value of %s[%d] contains flag bits that are not recognized members of %s", + api_name, array_name, i, flag_bits_name); } } } @@ -706,14 +698,16 @@ static void validate_result(debug_report_data *report_data, const char *apiName, if (resultName == UnsupportedResultString) { // Unrecognized result code - log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: returned a result code indicating that an error has occurred", apiName); + log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: returned a result code indicating that an error has occurred", apiName); } else { std::string resultDesc = get_result_description(result); - log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, - ParameterValidationName, "%s: returned %s, indicating that %s", apiName, resultName.c_str(), resultDesc.c_str()); + log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1, LayerName, + "%s: returned %s, indicating that %s", apiName, resultName.c_str(), resultDesc.c_str()); } } } +} // namespace parameter_validation + #endif // PARAMETER_VALIDATION_UTILS_H |
