aboutsummaryrefslogtreecommitdiff
path: root/layers/parameter_validation_utils.h
diff options
context:
space:
mode:
authorDustin Graves <dustin@lunarg.com>2016-04-26 15:37:10 -0600
committerDustin Graves <dustin@lunarg.com>2016-04-28 17:24:42 -0600
commitd33465e2c8a578a4e1bbd15e76d5e0f674aa7364 (patch)
treeb06eedc0c87de76650c68c31607bb3cea07aebb8 /layers/parameter_validation_utils.h
parent298e942df7ae24098c8338a98163556566afed1e (diff)
downloadusermoji-d33465e2c8a578a4e1bbd15e76d5e0f674aa7364.tar.xz
layers: Add VkFlags parameter validation
Add parameter validation for VkFlags derived types to the parameter_validation layer's code generation scripts. The following validation checks are performed: - If a VkFlags parameter is not marked as optional in the XML, a message is generated when the parameter is 0. - If a VkFlags parameter is not 0, a message is generated if it combines bits that are not defined by its associated flag bits enumeration. - If a VkFlags parameter does not have an associated flag bits enumeration it is treated as a reserved value that must be 0. Change-Id: I6daed360cde46e2a27c84deda1e0798621f92d50
Diffstat (limited to 'layers/parameter_validation_utils.h')
-rw-r--r--layers/parameter_validation_utils.h106
1 files changed, 104 insertions, 2 deletions
diff --git a/layers/parameter_validation_utils.h b/layers/parameter_validation_utils.h
index fb37add3..5a9ff503 100644
--- a/layers/parameter_validation_utils.h
+++ b/layers/parameter_validation_utils.h
@@ -24,6 +24,7 @@
#include <algorithm>
#include <cstdlib>
#include <string>
+#include <type_traits>
#include "vulkan/vulkan.h"
#include "vk_enum_string_helper.h"
@@ -63,6 +64,31 @@ template <> bool is_extension_added_token(VkSamplerAddressMode value) {
}
/**
+* Verify that a reserved value is zero.
+*
+* Verify that the specified value is zero. Primarily intended to check VkFlags values that are reserved for
+* future use.
+*
+* @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 parameter being validated.
+* @param value Value to validate.
+* @return Boolean value indicating that the call should be skipped.
+*/
+template <typename T>
+bool validate_reserved(debug_report_data *report_data, const char *api_name, const char *parameter_name, T value) {
+ static_assert(std::is_integral<T>::value, "validate_reserved is only designed to process integer types");
+ 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);
+ }
+
+ return skip_call;
+}
+
+/**
* Validate a required pointer.
*
* Verify that a required pointer is not NULL.
@@ -475,7 +501,7 @@ static bool validate_bool32(debug_report_data *report_data, const char *apiName,
* @param enumName Name of the enumeration being validated.
* @param begin The begin range value for the enumeration.
* @param end The end range value for the enumeration.
-* @param value Boolean value to validate.
+* @param value Enumeration value to validate.
* @return Boolean value indicating that the call should be skipped.
*/
template <typename T>
@@ -541,9 +567,85 @@ static bool validate_ranged_enum_array(debug_report_data *report_data, const cha
}
/**
+* Validate a Vulkan bitmask value.
+*
+* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
+* for that type.
+*
+* @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 parameter being validated.
+* @param flag_bits_name Name of the VkFlags type being validated.
+* @param all_flags A bit mask combining all valid flag bits for the VkFlags type being validated.
+* @param value VkFlags value to validate.
+* @param flags_required The 'value' parameter may not be 0 when true.
+* @return Boolean value indicating that the call should be skipped.
+*/
+template <typename T>
+bool validate_flags(debug_report_data *report_data, const char *api_name, const char *parameter_name, const char *flag_bits_name,
+ T all_flags, T value, bool flags_required) {
+ bool skip_call = false;
+
+ if (value == 0) {
+ if (flags_required) {
+ skip_call |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, (VkDebugReportObjectTypeEXT)0, 0, __LINE__, 1,
+ ParameterValidationName, "%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_WARNING_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);
+ }
+
+ return skip_call;
+}
+
+/**
+* Validate an array of Vulkan bitmask values.
+*
+* Generate a warning if a value with a VkFlags derived type does not contain valid flag bits
+* for that type.
+*
+* @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 parameter being validated.
+* @param array_name Name of parameter being validated.
+* @param flag_bits_name Name of the VkFlags type being validated.
+* @param all_flags A bitmask combining all valid flag bits for the VkFlags type being validated.
+* @param count Number of VkFlags values in the array.
+* @param array Array of VkFlags value 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 <typename T>
+bool validate_flags_array(debug_report_data *report_data, const char *api_name, const char *count_name, const char *array_name,
+ const char *flag_bits_name, T all_flags, uint32_t count, const T *array, bool count_required,
+ bool array_required) {
+ bool skip_call = false;
+
+ if ((count == 0) || (array == NULL)) {
+ skip_call |= validate_array(report_data, api_name, count_name, array_name, count, array, count_required, array_required);
+ } else {
+ // Verify that all VkFlags values in the array
+ for (uint32_t i = 0; i < count; ++i) {
+ if ((array[i] & (~all_flags)) != 0) {
+ skip_call |=
+ log_msg(report_data, VK_DEBUG_REPORT_WARNING_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);
+ }
+ }
+ }
+
+ return skip_call;
+}
+
+/**
* Get VkResult code description.
*
-* Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API specification.
+* Returns a string describing the specified VkResult code. The description is based on the language in the Vulkan API
+* specification.
*
* @param value VkResult code to process.
* @return String describing the specified VkResult code.