Vulkan api update to 1.1

Import Vulkan 1.1 header from
khronos master@5b2d66c0e6906388385ed7adfd015d80ec0d846a
with the following modifications:
- VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETER_FEATURES 10006300 -> 1000063000
- remove VK_KHR_get_display_properties2 (which is not ratified)
- device_group interactions from KHR_surface to KHR_swapchain (per MR 2409)

Summary of changes since 1.0.61:
* VK_KHR_surface -> v26 (subsumed interactions with VK_KHR_device_group)
* VK_KHR_swapchain -> v69 (subsumed interactions with VK_KHR_device_group)
* VK_EXT_debug_report -> v9 (no api changes)
* VK_KHX_multiview -> VK_KHR_multiview
* VK_KHX_device_group -> VK_KHR_device_group
* VK_KHX_device_group_creation -> VK_KHR_device_group_creation
* VK_KHR_push_descriptor -> v2
* Added VK_KHR_maintenance3
* Added 1.1 core enums, structs, and functions (kept KHR suffixed ones too)

Implemented the following in libvulkan:
* EnumerateInstanceVersion
* GetDeviceGroupPresentCapabilitiesKHR (minimal support for 1 device)
* GetDeviceGroupSurfacePresentModesKHR (minimal support for local present modes only)
* GetPhysicalDevicePresentRectanglesKHR (assumes whole window)
* AcquireNextImage2KHR (minimal thunk to AcquireNextImageKHR)
* GetDeviceQueue2
* added support for VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR
* support for 1.1 core device_groups functionality (no VK_KHR_device_group_creation)
  - EnumeratePhysicalDeviceGroups
* added trampolines for 1.1 core entry points
* disabled apiVersion >= 1.1 check

Implemented in nulldrv (but largely untested beyond build/link)
* EnumerateInstanceVersion
* enough empty thunks for VK 1.1 core functions that it links

Test: Build Android
Change-Id: I247cd670543867bdf80877156d941cf3bfcf6303
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 665a32b..d5e7c43 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -23,9 +23,12 @@
 #include <utils/StrongPointer.h>
 #include <utils/Vector.h>
 #include <system/window.h>
+#include <android/hardware/graphics/common/1.0/types.h>
 
 #include "driver.h"
 
+using android::hardware::graphics::common::V1_0::BufferUsage;
+
 // TODO(jessehall): Currently we don't have a good error code for when a native
 // window operation fails. Just returning INITIALIZATION_FAILED for now. Later
 // versions (post SDK 0.9) of the API/extension have a better error code.
@@ -771,6 +774,94 @@
 }
 
 VKAPI_ATTR
+VkResult GetDeviceGroupPresentCapabilitiesKHR(
+    VkDevice device,
+    VkDeviceGroupPresentCapabilitiesKHR* pDeviceGroupPresentCapabilities) {
+    ALOGV("vkGetDeviceGroupPresentCapabilitiesKHR: device=0x%" PRIx64
+          "pDeviceGroupPresentCapabilities=0x%" PRIx64,
+          reinterpret_cast<uint64_t>(device),
+          reinterpret_cast<uint64_t>(pDeviceGroupPresentCapabilities));
+
+    ALOGV_IF(pDeviceGroupPresentCapabilities->sType !=
+                 VK_STRUCTURE_TYPE_DEVICE_GROUP_PRESENT_CAPABILITIES_KHR,
+             "vkGetDeviceGroupPresentCapabilitiesKHR: invalid "
+             "VkDeviceGroupPresentCapabilitiesKHR structure type %d",
+             pDeviceGroupPresentCapabilities->sType);
+
+    memset(pDeviceGroupPresentCapabilities->presentMask, 0,
+           sizeof(pDeviceGroupPresentCapabilities->presentMask));
+
+    // assume device group of size 1
+    pDeviceGroupPresentCapabilities->presentMask[0] = 1 << 0;
+    pDeviceGroupPresentCapabilities->modes =
+        VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
+
+    return VK_SUCCESS;
+}
+
+VKAPI_ATTR
+VkResult GetDeviceGroupSurfacePresentModesKHR(
+    VkDevice device,
+    VkSurfaceKHR surface,
+    VkDeviceGroupPresentModeFlagsKHR* pModes) {
+    ALOGV("vkGetDeviceGroupSurfacePresentModesKHR: device=0x%" PRIx64
+          "surface=0x%" PRIx64 "pModes=0x%" PRIx64,
+          reinterpret_cast<uint64_t>(device),
+          reinterpret_cast<uint64_t>(surface),
+          reinterpret_cast<uint64_t>(pModes));
+
+    *pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
+    return VK_SUCCESS;
+}
+
+VKAPI_ATTR
+VkResult GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,
+                                               VkSurfaceKHR surface,
+                                               uint32_t* pRectCount,
+                                               VkRect2D* pRects) {
+    ALOGV("GetPhysicalDevicePresentRectanglesKHR: physicalDevice=0x%" PRIx64
+          "surface=0x%" PRIx64 "pRectCount=%d pRects=0x%" PRIx64,
+          reinterpret_cast<uint64_t>(physicalDevice),
+          reinterpret_cast<uint64_t>(surface), *pRectCount,
+          reinterpret_cast<uint64_t>(pRects));
+
+    if (!pRects) {
+        *pRectCount = 1;
+    } else {
+        uint32_t count = std::min(*pRectCount, 1u);
+        bool incomplete = *pRectCount < 1;
+
+        *pRectCount = count;
+
+        if (incomplete) {
+            return VK_INCOMPLETE;
+        }
+
+        int err;
+        ANativeWindow* window = SurfaceFromHandle(surface)->window.get();
+
+        int width = 0, height = 0;
+        err = window->query(window, NATIVE_WINDOW_DEFAULT_WIDTH, &width);
+        if (err != 0) {
+            ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)",
+                  strerror(-err), err);
+        }
+        err = window->query(window, NATIVE_WINDOW_DEFAULT_HEIGHT, &height);
+        if (err != 0) {
+            ALOGE("NATIVE_WINDOW_DEFAULT_WIDTH query failed: %s (%d)",
+                  strerror(-err), err);
+        }
+
+        // TODO: Return something better than "whole window"
+        pRects[0].offset.x = 0;
+        pRects[0].offset.y = 0;
+        pRects[0].extent = VkExtent2D{static_cast<uint32_t>(width),
+                                      static_cast<uint32_t>(height)};
+    }
+    return VK_SUCCESS;
+}
+
+VKAPI_ATTR
 VkResult CreateSwapchainKHR(VkDevice device,
                             const VkSwapchainCreateInfoKHR* create_info,
                             const VkAllocationCallbacks* allocator,
@@ -996,7 +1087,7 @@
         return VK_ERROR_SURFACE_LOST_KHR;
     }
 
-    int gralloc_usage = 0;
+    int32_t legacy_usage = 0;
     if (dispatch.GetSwapchainGrallocUsage2ANDROID) {
         uint64_t consumer_usage, producer_usage;
         result = dispatch.GetSwapchainGrallocUsage2ANDROID(
@@ -1006,18 +1097,25 @@
             ALOGE("vkGetSwapchainGrallocUsage2ANDROID failed: %d", result);
             return VK_ERROR_SURFACE_LOST_KHR;
         }
-        gralloc_usage =
+        legacy_usage =
             android_convertGralloc1To0Usage(producer_usage, consumer_usage);
     } else if (dispatch.GetSwapchainGrallocUsageANDROID) {
         result = dispatch.GetSwapchainGrallocUsageANDROID(
             device, create_info->imageFormat, create_info->imageUsage,
-            &gralloc_usage);
+            &legacy_usage);
         if (result != VK_SUCCESS) {
             ALOGE("vkGetSwapchainGrallocUsageANDROID failed: %d", result);
             return VK_ERROR_SURFACE_LOST_KHR;
         }
     }
-    err = native_window_set_usage(surface.window.get(), uint64_t(gralloc_usage));
+    uint64_t native_usage = static_cast<uint64_t>(legacy_usage);
+
+    bool createProtectedSwapchain = false;
+    if (create_info->flags & VK_SWAPCHAIN_CREATE_PROTECTED_BIT_KHR) {
+        createProtectedSwapchain = true;
+        native_usage |= BufferUsage::PROTECTED;
+    }
+    err = native_window_set_usage(surface.window.get(), native_usage);
     if (err != 0) {
         // TODO(jessehall): Improve error reporting. Can we enumerate possible
         // errors and translate them to valid Vulkan result codes?
@@ -1065,7 +1163,7 @@
         .samples = VK_SAMPLE_COUNT_1_BIT,
         .tiling = VK_IMAGE_TILING_OPTIMAL,
         .usage = create_info->imageUsage,
-        .flags = 0,
+        .flags = createProtectedSwapchain ? VK_IMAGE_CREATE_PROTECTED_BIT : 0u,
         .sharingMode = create_info->imageSharingMode,
         .queueFamilyIndexCount = create_info->queueFamilyIndexCount,
         .pQueueFamilyIndices = create_info->pQueueFamilyIndices,
@@ -1273,6 +1371,17 @@
     return VK_SUCCESS;
 }
 
+VKAPI_ATTR
+VkResult AcquireNextImage2KHR(VkDevice device,
+                              const VkAcquireNextImageInfoKHR* pAcquireInfo,
+                              uint32_t* pImageIndex) {
+    // TODO: this should actually be the other way around and this function
+    // should handle any additional structures that get passed in
+    return AcquireNextImageKHR(device, pAcquireInfo->swapchain,
+                               pAcquireInfo->timeout, pAcquireInfo->semaphore,
+                               pAcquireInfo->fence, pImageIndex);
+}
+
 static VkResult WorstPresentResult(VkResult a, VkResult b) {
     // See the error ranking for vkQueuePresentKHR at the end of section 29.6
     // (in spec version 1.0.14).