loader: Update the loader to 1.0.39

Add new extensions for 1.0.39.  Also, updated layers to include
minimal set of functionality for 1.0.39 extensions. Extensions include:
 - VK_KHR_get_physical_device_properties2
 - VK_KHR_shader_draw_parameters
 - VK_EXT_direct_mode_display
 - VK_EXT_display_surface_counter
 - VK_EXT_display_control

Also, redo the LoaderAndLayerIf document.

Change-Id: I10412086da7a798afe832a3892e18f606259b5af
diff --git a/loader/wsi.c b/loader/wsi.c
index c577063..b2e96f8 100644
--- a/loader/wsi.c
+++ b/loader/wsi.c
@@ -152,7 +152,7 @@
 vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
                     const VkAllocationCallbacks *pAllocator) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     disp->DestroySurfaceKHR(instance, surface, pAllocator);
 }
 
@@ -205,7 +205,7 @@
     const VkLayerInstanceDispatchTable *disp;
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
     return res;
@@ -261,7 +261,7 @@
     const VkLayerInstanceDispatchTable *disp;
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(
         unwrapped_phys_dev, surface, pSurfaceCapabilities);
     return res;
@@ -317,7 +317,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(
         unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
     return res;
@@ -373,7 +373,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(
         unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
     return res;
@@ -548,7 +548,7 @@
     VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res = disp->CreateWin32SurfaceKHR(instance, pCreateInfo, pAllocator,
@@ -638,7 +638,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkBool32 res = disp->GetPhysicalDeviceWin32PresentationSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex);
     return res;
@@ -682,7 +682,7 @@
     VkInstance instance, const VkMirSurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res =
@@ -771,7 +771,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkBool32 res = disp->GetPhysicalDeviceMirPresentationSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex, connection);
     return res;
@@ -818,7 +818,7 @@
     VkInstance instance, const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res = disp->CreateWaylandSurfaceKHR(instance, pCreateInfo, pAllocator,
@@ -907,7 +907,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkBool32 res = disp->GetPhysicalDeviceWaylandPresentationSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex, display);
     return res;
@@ -953,7 +953,7 @@
     VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res =
@@ -1043,7 +1043,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkBool32 res = disp->GetPhysicalDeviceXcbPresentationSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex, connection, visual_id);
     return res;
@@ -1089,7 +1089,7 @@
     VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res =
@@ -1178,7 +1178,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkBool32 res = disp->GetPhysicalDeviceXlibPresentationSupportKHR(
         unwrapped_phys_dev, queueFamilyIndex, dpy, visualID);
     return res;
@@ -1224,7 +1224,7 @@
     VkInstance instance, ANativeWindow *window,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res = disp->CreateAndroidSurfaceKHR(instance, window, pAllocator, pSurface);
@@ -1271,7 +1271,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceDisplayPropertiesKHR(
         unwrapped_phys_dev, pPropertyCount, pProperties);
     return res;
@@ -1309,7 +1309,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetPhysicalDeviceDisplayPlanePropertiesKHR(
         unwrapped_phys_dev, pPropertyCount, pProperties);
     return res;
@@ -1351,7 +1351,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetDisplayPlaneSupportedDisplaysKHR(
         unwrapped_phys_dev, planeIndex, pDisplayCount, pDisplays);
     return res;
@@ -1388,7 +1388,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetDisplayModePropertiesKHR(
         unwrapped_phys_dev, display, pPropertyCount, pProperties);
     return res;
@@ -1426,7 +1426,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->CreateDisplayModeKHR(unwrapped_phys_dev, display,
                                               pCreateInfo, pAllocator, pMode);
     return res;
@@ -1464,7 +1464,7 @@
     VkPhysicalDevice unwrapped_phys_dev =
         loader_unwrap_physical_device(physicalDevice);
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(physicalDevice);
+    disp = loader_get_instance_layer_dispatch(physicalDevice);
     VkResult res = disp->GetDisplayPlaneCapabilitiesKHR(
         unwrapped_phys_dev, mode, planeIndex, pCapabilities);
     return res;
@@ -1499,7 +1499,7 @@
     VkInstance instance, const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
     const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
     const VkLayerInstanceDispatchTable *disp;
-    disp = loader_get_instance_dispatch(instance);
+    disp = loader_get_instance_layer_dispatch(instance);
     VkResult res;
 
     res = disp->CreateDisplayPlaneSurfaceKHR(instance, pCreateInfo, pAllocator,
@@ -1581,8 +1581,8 @@
     return vkRes;
 }
 
-// This is the trampoline entrypoint
-// for CreateSharedSwapchainsKHR
+// EXT_display_swapchain Extension command
+
 LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkCreateSharedSwapchainsKHR(
     VkDevice device, uint32_t swapchainCount,
     const VkSwapchainCreateInfoKHR *pCreateInfos,
@@ -1593,6 +1593,47 @@
                                            pAllocator, pSwapchains);
 }
 
+VKAPI_ATTR VkResult VKAPI_CALL terminator_vkCreateSharedSwapchainsKHR(
+    VkDevice device, uint32_t swapchainCount,
+    const VkSwapchainCreateInfoKHR *pCreateInfos,
+    const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchains) {
+    uint32_t icd_index = 0;
+    struct loader_device *dev;
+    struct loader_icd_term *icd_term =
+        loader_get_icd_and_device(device, &dev, &icd_index);
+    if (NULL != icd_term && NULL != icd_term->CreateSharedSwapchainsKHR) {
+        VkIcdSurface *icd_surface =
+            (VkIcdSurface *)(uintptr_t)pCreateInfos->surface;
+        if (NULL != icd_surface->real_icd_surfaces) {
+            if ((VkSurfaceKHR)NULL !=
+                icd_surface->real_icd_surfaces[icd_index]) {
+                // We found the ICD, and there is an ICD KHR surface
+                // associated with it, so copy the CreateInfo struct
+                // and point it at the ICD's surface.
+                VkSwapchainCreateInfoKHR *pCreateCopy =
+                    loader_stack_alloc(sizeof(VkSwapchainCreateInfoKHR) *
+                        swapchainCount);
+                if (NULL == pCreateCopy) {
+                    return VK_ERROR_OUT_OF_HOST_MEMORY;
+                }
+                memcpy(pCreateCopy, pCreateInfos,
+                       sizeof(VkSwapchainCreateInfoKHR) * swapchainCount);
+                for (uint32_t sc = 0; sc < swapchainCount; sc++) {
+                    pCreateCopy[sc].surface =
+                        icd_surface->real_icd_surfaces[icd_index];
+                }
+                return icd_term->CreateSharedSwapchainsKHR(
+                    device, swapchainCount, pCreateCopy, pAllocator,
+                    pSwapchains);
+            }
+        }
+        return icd_term->CreateSharedSwapchainsKHR(device, swapchainCount,
+                                                   pCreateInfos, pAllocator,
+                                                   pSwapchains);
+    }
+    return VK_SUCCESS;
+}
+
 bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance,
                                 const char *name, void **addr) {
     *addr = NULL;