Mesa (main): vulkan/runtime: Validate instance version on 1.0 implementations
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Dec 20 17:12:32 UTC 2021
Module: Mesa
Branch: main
Commit: 88b9b68f3023df0651d970896cc3123a2dfdef15
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=88b9b68f3023df0651d970896cc3123a2dfdef15
Author: Jason Ekstrand <jason at jlekstrand.net>
Date: Fri Dec 10 10:34:20 2021 -0600
vulkan/runtime: Validate instance version on 1.0 implementations
This isn't something that ANV or RADV have cared about in a long time
but, as people bring up new Vulkan drivers, shipping Vulkan 1.0 is still
a thing that happens in Mesa. The common code should also implement the
1.0 rules.
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14150>
---
src/vulkan/runtime/vk_instance.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/vulkan/runtime/vk_instance.c b/src/vulkan/runtime/vk_instance.c
index a247bc3f096..66b896f9749 100644
--- a/src/vulkan/runtime/vk_instance.c
+++ b/src/vulkan/runtime/vk_instance.c
@@ -32,6 +32,9 @@
#include "compiler/glsl_types.h"
+#define VERSION_IS_1_0(version) \
+ (VK_API_VERSION_MAJOR(version) == 1 && VK_API_VERSION_MINOR(version) == 0)
+
VkResult
vk_instance_init(struct vk_instance *instance,
const struct vk_instance_extension_table *supported_extensions,
@@ -75,6 +78,10 @@ vk_instance_init(struct vk_instance *instance,
}
}
+ uint32_t instance_version = VK_API_VERSION_1_0;
+ if (dispatch_table->EnumerateInstanceVersion)
+ dispatch_table->EnumerateInstanceVersion(&instance_version);
+
instance->app_info = (struct vk_app_info) { .api_version = 0 };
if (pCreateInfo->pApplicationInfo) {
const VkApplicationInfo *app = pCreateInfo->pApplicationInfo;
@@ -92,9 +99,37 @@ vk_instance_init(struct vk_instance *instance,
instance->app_info.api_version = app->apiVersion;
}
+ /* From the Vulkan 1.2.199 spec:
+ *
+ * "Note:
+ *
+ * Providing a NULL VkInstanceCreateInfo::pApplicationInfo or providing
+ * an apiVersion of 0 is equivalent to providing an apiVersion of
+ * VK_MAKE_API_VERSION(0,1,0,0)."
+ */
if (instance->app_info.api_version == 0)
instance->app_info.api_version = VK_API_VERSION_1_0;
+ /* From the Vulkan 1.2.199 spec:
+ *
+ * VUID-VkApplicationInfo-apiVersion-04010
+ *
+ * "If apiVersion is not 0, then it must be greater than or equal to
+ * VK_API_VERSION_1_0"
+ */
+ assert(instance->app_info.api_version >= VK_API_VERSION_1_0);
+
+ /* From the Vulkan 1.2.199 spec:
+ *
+ * "Vulkan 1.0 implementations were required to return
+ * VK_ERROR_INCOMPATIBLE_DRIVER if apiVersion was larger than 1.0.
+ * Implementations that support Vulkan 1.1 or later must not return
+ * VK_ERROR_INCOMPATIBLE_DRIVER for any value of apiVersion."
+ */
+ if (VERSION_IS_1_0(instance_version) &&
+ !VERSION_IS_1_0(instance->app_info.api_version))
+ return VK_ERROR_INCOMPATIBLE_DRIVER;
+
for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
int idx;
for (idx = 0; idx < VK_INSTANCE_EXTENSION_COUNT; idx++) {
More information about the mesa-commit
mailing list