From 7dec2d1c56894da99ab229dbdf627d121b9c3379 Mon Sep 17 00:00:00 2001 From: Idan Raiter Date: Mon, 29 Jul 2019 23:31:49 +0000 Subject: [PATCH] Use Vulkan 1.1 if available Bug: chromium:976495 Change-Id: I10940340fab44b44e26cfb025f8c932a5e62f02e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9500 Reviewed-by: Kai Ninomiya Reviewed-by: Corentin Wallez Commit-Queue: Kai Ninomiya --- src/dawn_native/vulkan/BackendVk.cpp | 2 +- src/dawn_native/vulkan/VulkanFunctions.cpp | 4 ++++ src/dawn_native/vulkan/VulkanFunctions.h | 3 +++ src/dawn_native/vulkan/VulkanInfo.cpp | 13 +++++++++++++ src/dawn_native/vulkan/VulkanInfo.h | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/vulkan/BackendVk.cpp b/src/dawn_native/vulkan/BackendVk.cpp index 6ca0a26ca3..f1c00ec10f 100644 --- a/src/dawn_native/vulkan/BackendVk.cpp +++ b/src/dawn_native/vulkan/BackendVk.cpp @@ -166,7 +166,7 @@ namespace dawn_native { namespace vulkan { appInfo.applicationVersion = 0; appInfo.pEngineName = nullptr; appInfo.engineVersion = 0; - appInfo.apiVersion = VK_API_VERSION_1_0; + appInfo.apiVersion = mGlobalInfo.apiVersion; VkInstanceCreateInfo createInfo; createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; diff --git a/src/dawn_native/vulkan/VulkanFunctions.cpp b/src/dawn_native/vulkan/VulkanFunctions.cpp index 771c5d5f1f..6921244af5 100644 --- a/src/dawn_native/vulkan/VulkanFunctions.cpp +++ b/src/dawn_native/vulkan/VulkanFunctions.cpp @@ -34,6 +34,10 @@ namespace dawn_native { namespace vulkan { GET_GLOBAL_PROC(EnumerateInstanceExtensionProperties); GET_GLOBAL_PROC(EnumerateInstanceLayerProperties); + // Is not available in Vulkan 1.0, so allow nullptr + EnumerateInstanceVersion = reinterpret_cast( + GetInstanceProcAddr(nullptr, "vkEnumerateInstanceVersion")); + return {}; } diff --git a/src/dawn_native/vulkan/VulkanFunctions.h b/src/dawn_native/vulkan/VulkanFunctions.h index 6dcfe7e135..e3b0b23c89 100644 --- a/src/dawn_native/vulkan/VulkanFunctions.h +++ b/src/dawn_native/vulkan/VulkanFunctions.h @@ -45,6 +45,9 @@ namespace dawn_native { namespace vulkan { // before querying the instance procs in case we need to error out during initialization. PFN_vkDestroyInstance DestroyInstance = nullptr; + // Core Vulkan 1.1 + PFN_vkEnumerateInstanceVersion EnumerateInstanceVersion = nullptr; + // ---------- Instance procs // Core Vulkan 1.0 diff --git a/src/dawn_native/vulkan/VulkanInfo.cpp b/src/dawn_native/vulkan/VulkanInfo.cpp index 747202aae0..2c0128e579 100644 --- a/src/dawn_native/vulkan/VulkanInfo.cpp +++ b/src/dawn_native/vulkan/VulkanInfo.cpp @@ -120,6 +120,19 @@ namespace dawn_native { namespace vulkan { } } + // Gather info on available API version + { + uint32_t supportedAPIVersion = VK_MAKE_VERSION(1, 0, 0); + if (vkFunctions.EnumerateInstanceVersion) { + vkFunctions.EnumerateInstanceVersion(&supportedAPIVersion); + } + + // Use Vulkan 1.1 if it's available. + info.apiVersion = (supportedAPIVersion >= VK_MAKE_VERSION(1, 1, 0)) + ? VK_MAKE_VERSION(1, 1, 0) + : VK_MAKE_VERSION(1, 0, 0); + } + // TODO(cwallez@chromium:org): Each layer can expose additional extensions, query them? return info; diff --git a/src/dawn_native/vulkan/VulkanInfo.h b/src/dawn_native/vulkan/VulkanInfo.h index 4425de5148..168f677f39 100644 --- a/src/dawn_native/vulkan/VulkanInfo.h +++ b/src/dawn_native/vulkan/VulkanInfo.h @@ -59,6 +59,7 @@ namespace dawn_native { namespace vulkan { struct VulkanGlobalInfo : VulkanGlobalKnobs { std::vector layers; std::vector extensions; + uint32_t apiVersion; // TODO(cwallez@chromium.org): layer instance extensions };