Support using vulkan 1.1.

Bug: skia:
Change-Id: Ic1fc109557f64c748c9ba5427b400795dbde7250
Reviewed-on: https://skia-review.googlesource.com/137882
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/include/gpu/vk/GrVkBackendContext.h b/include/gpu/vk/GrVkBackendContext.h
index e711906..12a1ef6 100644
--- a/include/gpu/vk/GrVkBackendContext.h
+++ b/include/gpu/vk/GrVkBackendContext.h
@@ -45,8 +45,9 @@
     VkDevice                   fDevice;
     VkQueue                    fQueue;
     uint32_t                   fGraphicsQueueIndex;
-    uint32_t                   fMinAPIVersion;
-    uint32_t                   fExtensions = 0;
+    uint32_t                   fMinAPIVersion; // Deprecated. Set fInstanceVersion instead.
+    uint32_t                   fInstanceVersion = 0;
+    uint32_t                   fExtensions = 0; // Deprecated. Use fVkExtensions instead.
     const GrVkExtensions*      fVkExtensions = nullptr;
     uint32_t                   fFeatures = kIgnoreAllFlags_GrVkFeatureFlag;
     VkPhysicalDeviceFeatures   fDeviceFeatures;
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 2bfb11a..b0376da 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -15,7 +15,8 @@
 #include "vk/GrVkBackendContext.h"
 
 GrVkCaps::GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
-                   VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures& features)
+                   VkPhysicalDevice physDev, const VkPhysicalDeviceFeatures& features,
+                   uint32_t instanceVersion)
     : INHERITED(contextOptions) {
     fMustDoCopiesFromOrigin = false;
     fMustSubmitCommandsBeforeCopyOp = false;
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 3eb5b48..e58456b 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -27,7 +27,8 @@
      * be called to fill out the caps.
      */
     GrVkCaps(const GrContextOptions& contextOptions, const GrVkInterface* vkInterface,
-             VkPhysicalDevice device, const VkPhysicalDeviceFeatures& features);
+             VkPhysicalDevice device, const VkPhysicalDeviceFeatures& features,
+             uint32_t instanceVersion);
 
     bool isConfigTexturable(GrPixelConfig config) const override {
         return SkToBool(ConfigInfo::kTextureable_Flag & fConfigTable[config].fOptimalFlags);
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index edb4b77..efdca90 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -114,9 +114,12 @@
 
     fCompiler = new SkSL::Compiler();
 
+    uint32_t instanceVersion = backendContext.fInstanceVersion ? backendContext.fInstanceVersion
+                                                               : backendContext.fMinAPIVersion;
+
     if (backendContext.fFeatures & kIgnoreAllFlags_GrVkFeatureFlag) {
         fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendContext.fPhysicalDevice,
-                                   backendContext.fDeviceFeatures));
+                                   backendContext.fDeviceFeatures, instanceVersion));
     } else {
         VkPhysicalDeviceFeatures features;
         if (backendContext.fFeatures & kGeometryShader_GrVkFeatureFlag) {
@@ -129,7 +132,7 @@
             features.sampleRateShading = true;
         }
         fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendContext.fPhysicalDevice,
-                                   features));
+                                   features, instanceVersion));
     }
     fCaps.reset(SkRef(fVkCaps.get()));
 
diff --git a/tools/gpu/vk/VkTestUtils.cpp b/tools/gpu/vk/VkTestUtils.cpp
index 3b81953..2816f0a 100644
--- a/tools/gpu/vk/VkTestUtils.cpp
+++ b/tools/gpu/vk/VkTestUtils.cpp
@@ -75,6 +75,7 @@
     }
     return false;
 }
+
 VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(
     VkDebugReportFlagsEXT       flags,
     VkDebugReportObjectTypeEXT  objectType,
@@ -276,12 +277,10 @@
     return true;
 }
 
-// the minimum version of Vulkan supported
-#ifdef SK_BUILD_FOR_ANDROID
-const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 3);
-#else
-const uint32_t kGrVkMinimumVersion = VK_MAKE_VERSION(1, 0, 8);
-#endif
+#define ACQUIRE_VK_PROC_NOCHECK(name, instance, device)                        \
+    PFN_vk##name grVk##name =                                                  \
+        reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, device));
+
 
 #define ACQUIRE_VK_PROC(name, instance, device)                                \
     PFN_vk##name grVk##name =                                                  \
@@ -320,10 +319,24 @@
                             VkDebugReportCallbackEXT* debugCallback,
                             uint32_t* presentQueueIndexPtr,
                             CanPresentFn canPresent) {
+    VkResult err;
+
+    ACQUIRE_VK_PROC_NOCHECK(EnumerateInstanceVersion, VK_NULL_HANDLE, VK_NULL_HANDLE);
+    uint32_t instanceVersion = 0;
+    if (!grVkEnumerateInstanceVersion) {
+        instanceVersion = VK_MAKE_VERSION(1, 0, 0);
+    } else {
+        err = grVkEnumerateInstanceVersion(&instanceVersion);
+        if (err) {
+            SkDebugf("failed ot enumerate instance version. Err: %d\n", err);
+            return false;
+        }
+    }
+    SkASSERT(instanceVersion >= VK_MAKE_VERSION(1, 0, 0));
+
     VkPhysicalDevice physDev;
     VkDevice device;
     VkInstance inst;
-    VkResult err;
 
     const VkApplicationInfo app_info = {
         VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
@@ -332,13 +345,13 @@
         0,                                  // applicationVersion
         "vktest",                           // pEngineName
         0,                                  // engineVerison
-        kGrVkMinimumVersion,                // apiVersion
+        instanceVersion,                    // apiVersion
     };
 
     SkTArray<VkLayerProperties> instanceLayers;
     SkTArray<VkExtensionProperties> instanceExtensions;
 
-    if (!init_instance_extensions_and_layers(getProc, kGrVkMinimumVersion,
+    if (!init_instance_extensions_and_layers(getProc, instanceVersion,
                                              &instanceExtensions,
                                              &instanceLayers)) {
         return false;
@@ -402,6 +415,7 @@
 #endif
 
     ACQUIRE_VK_PROC(EnumeratePhysicalDevices, inst, VK_NULL_HANDLE);
+    ACQUIRE_VK_PROC(GetPhysicalDeviceProperties, inst, VK_NULL_HANDLE);
     ACQUIRE_VK_PROC(GetPhysicalDeviceQueueFamilyProperties, inst, VK_NULL_HANDLE);
     ACQUIRE_VK_PROC(GetPhysicalDeviceFeatures, inst, VK_NULL_HANDLE);
     ACQUIRE_VK_PROC(CreateDevice, inst, VK_NULL_HANDLE);
@@ -432,6 +446,10 @@
         return false;
     }
 
+    VkPhysicalDeviceProperties physDeviceProperties;
+    grVkGetPhysicalDeviceProperties(physDev, &physDeviceProperties);
+    int physDeviceVersion = physDeviceProperties.apiVersion;
+
     // query to get the initial queue props size
     uint32_t queueCount;
     grVkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
@@ -484,7 +502,7 @@
 
     SkTArray<VkLayerProperties> deviceLayers;
     SkTArray<VkExtensionProperties> deviceExtensions;
-    if (!init_device_extensions_and_layers(getProc, kGrVkMinimumVersion,
+    if (!init_device_extensions_and_layers(getProc, physDeviceVersion,
                                            inst, physDev,
                                            &deviceExtensions,
                                            &deviceLayers)) {
@@ -571,7 +589,7 @@
     ctx->fDevice = device;
     ctx->fQueue = queue;
     ctx->fGraphicsQueueIndex = graphicsQueueIndex;
-    ctx->fMinAPIVersion = kGrVkMinimumVersion;
+    ctx->fInstanceVersion = instanceVersion;
     ctx->fVkExtensions = extensions;
     ctx->fDeviceFeatures = deviceFeatures;
     ctx->fGetProc = getProc;