aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Zulauf <jzulauf@lunarg.com>2018-03-30 14:51:59 -0600
committerjzulauf-lunarg <32470354+jzulauf-lunarg@users.noreply.github.com>2018-04-03 16:35:29 -0600
commit856d773b0e67e13848defe49109300315527ea0f (patch)
tree9aa15bd95e34939488974271598e4d60ff02983a
parent874651452c6fd4e576729aee5061388a389de4fe (diff)
downloadusermoji-856d773b0e67e13848defe49109300315527ea0f.tar.xz
layers: Add correct validation for apiVersion
Update and correct validation of passed apiVersion for 1.1 specified behavior. Instances with apiVersion > 1.1 will be validated as 1.1 instances (and warn). Instances with apiVersions < 0 and < 1.0 will be validated as 1.0 instances and generate an error. Instances with missing or 0 apiVersions will be treated as 1.0 instances. LOGCONSOLE warning converted to log_msg warning. Change-Id: I2debb6175cf094918fc86cdea2973ddae9479a0b
-rw-r--r--layers/parameter_validation_utils.cpp35
-rw-r--r--scripts/helper_file_generator.py5
2 files changed, 24 insertions, 16 deletions
diff --git a/layers/parameter_validation_utils.cpp b/layers/parameter_validation_utils.cpp
index 3644096e..b9adf037 100644
--- a/layers/parameter_validation_utils.cpp
+++ b/layers/parameter_validation_utils.cpp
@@ -256,18 +256,29 @@ VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCre
}
init_parameter_validation(my_instance_data, pAllocator);
-
- uint32_t api_version = my_instance_data->extensions.InitFromInstanceCreateInfo(
- (pCreateInfo->pApplicationInfo ? pCreateInfo->pApplicationInfo->apiVersion : VK_API_VERSION_1_0), pCreateInfo);
-
- if (pCreateInfo->pApplicationInfo) {
- uint32_t specified_api_version = pCreateInfo->pApplicationInfo->apiVersion & ~VK_VERSION_PATCH(~0);
- if (!(specified_api_version == VK_API_VERSION_1_0) && !(specified_api_version == VK_API_VERSION_1_1)) {
- LOGCONSOLE(
- "Warning: Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number -- (0x%08x) assuming "
- "%s.\n",
- pCreateInfo->pApplicationInfo->apiVersion,
- (api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1");
+ // Note: From the spec--
+ // Providing a NULL VkInstanceCreateInfo::pApplicationInfo or providing an apiVersion of 0 is equivalent to providing
+ // an apiVersion of VK_MAKE_VERSION(1, 0, 0). (a.k.a. VK_API_VERSION_1_0)
+ uint32_t api_version = (pCreateInfo->pApplicationInfo && pCreateInfo->pApplicationInfo->apiVersion)
+ ? pCreateInfo->pApplicationInfo->apiVersion
+ : VK_API_VERSION_1_0;
+
+ uint32_t effective_api_version = my_instance_data->extensions.InitFromInstanceCreateInfo(api_version, pCreateInfo);
+
+ uint32_t api_version_nopatch = VK_MAKE_VERSION(VK_VERSION_MAJOR(api_version), VK_VERSION_MINOR(api_version), 0);
+ if (api_version_nopatch != effective_api_version) {
+ const char *effective_api_string =
+ (effective_api_version == VK_API_VERSION_1_0) ? "VK_API_VERSION_1_0" : "VK_API_VERSION_1_1";
+ if (api_version_nopatch < VK_API_VERSION_1_0) {
+ log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+ VALIDATION_ERROR_UNDEFINED,
+ "Invalid CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). Using %s.\n",
+ api_version, effective_api_string);
+ } else {
+ log_msg(my_instance_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
+ VALIDATION_ERROR_UNDEFINED,
+ "Unrecognized CreateInstance->pCreateInfo->pApplicationInfo.apiVersion number (0x%08x). Assuming %s.\n",
+ api_version, effective_api_string);
}
}
diff --git a/scripts/helper_file_generator.py b/scripts/helper_file_generator.py
index 794864d9..ba2f14a9 100644
--- a/scripts/helper_file_generator.py
+++ b/scripts/helper_file_generator.py
@@ -515,10 +515,7 @@ class HelperFileOutputGenerator(OutputGenerator):
struct += '\n'
if type == 'Instance':
struct += ' uint32_t NormalizeApiVersion(uint32_t specified_version) {\n'
- struct += ' uint32_t api_version = specified_version & ~VK_VERSION_PATCH(~0);\n'
- struct += ' if (!(api_version == VK_API_VERSION_1_0) && !(api_version == VK_API_VERSION_1_1)) {\n'
- struct += ' api_version = VK_API_VERSION_1_1;\n'
- struct += ' }\n'
+ struct += ' uint32_t api_version = (specified_version < VK_API_VERSION_1_1) ? VK_API_VERSION_1_0 : VK_API_VERSION_1_1;\n'
struct += ' return api_version;\n'
struct += ' }\n'
struct += '\n'