diff options
author | Bryan Law-Smith <bryan.law-smith@arm.com> | 2019-04-01 11:45:55 +0300 |
---|---|---|
committer | Lenny Komow <lenny@lunarg.com> | 2019-04-27 00:23:45 +0300 |
commit | 5730569e72bac9b7b3b77181fc60e92beb1fefd7 (patch) | |
tree | 6269bbefc29d2f9a47ba7518edb3268f68fff3e3 | |
parent | 8df99b31f01ef1ef7fb17082dd577e77f20cb050 (diff) |
loader: VK_EXT_headless_surface additionsv1.1.107
As VK_EXT_headless_surface is a WSI extension, supporting it
requires changes to the loader. This commit makes the necessary
changes, which are mostly straightforward plumbing.
However, this commit also includes a minor tweak to avoid a
segmentation fault when an implicitly enabled layer provides
support for an instance extension.
-rw-r--r-- | loader/loader.c | 12 | ||||
-rw-r--r-- | loader/loader.h | 1 | ||||
-rw-r--r-- | loader/wsi.c | 80 | ||||
-rw-r--r-- | loader/wsi.h | 5 | ||||
-rw-r--r-- | scripts/loader_extension_generator.py | 1 |
5 files changed, 93 insertions, 6 deletions
diff --git a/loader/loader.c b/loader/loader.c index b487c1c32..c74a501aa 100644 --- a/loader/loader.c +++ b/loader/loader.c @@ -5645,18 +5645,18 @@ VkResult loader_validate_instance_extensions(struct loader_instance *inst, const // Not in global list, search layer extension lists struct loader_layer_properties *layer_prop = NULL; for (uint32_t j = 0; NULL == extension_prop && j < expanded_layers.count; ++j) { - layer_prop = loaderFindLayerProperty(pCreateInfo->ppEnabledLayerNames[j], instance_layers); - if (NULL == layer_prop) { - // Should NOT get here, loaderValidateLayers should have already filtered this case out. - continue; - } - extension_prop = get_extension_property(pCreateInfo->ppEnabledExtensionNames[i], &expanded_layers.list[j].instance_extension_list); if (extension_prop) { // Found the extension in one of the layers enabled by the app. break; } + + layer_prop = loaderFindLayerProperty(pCreateInfo->ppEnabledLayerNames[j], instance_layers); + if (NULL == layer_prop) { + // Should NOT get here, loaderValidateLayers should have already filtered this case out. + continue; + } } if (!extension_prop) { diff --git a/loader/loader.h b/loader/loader.h index 2d3990ab9..beb8e1eb3 100644 --- a/loader/loader.h +++ b/loader/loader.h @@ -332,6 +332,7 @@ struct loader_instance { #ifdef VK_USE_PLATFORM_IOS_MVK bool wsi_ios_surface_enabled; #endif + bool wsi_headless_surface_enabled; bool wsi_display_enabled; bool wsi_display_props2_enabled; }; diff --git a/loader/wsi.c b/loader/wsi.c index 08e405442..e9f573f07 100644 --- a/loader/wsi.c +++ b/loader/wsi.c @@ -111,6 +111,10 @@ void wsi_create_instance(struct loader_instance *ptr_instance, const VkInstanceC continue; } #endif // VK_USE_PLATFORM_IOS_MVK + if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME) == 0) { + ptr_instance->wsi_headless_surface_enabled = true; + continue; + } if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_DISPLAY_EXTENSION_NAME) == 0) { ptr_instance->wsi_display_enabled = true; continue; @@ -973,6 +977,75 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateAndroidSurfaceKHR(VkInstance ins #endif // VK_USE_PLATFORM_ANDROID_KHR +// Functions for the VK_EXT_headless_surface extension: + +VKAPI_ATTR VkResult VKAPI_CALL vkCreateHeadlessSurfaceEXT(VkInstance instance, const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) { + const VkLayerInstanceDispatchTable *disp; + disp = loader_get_instance_layer_dispatch(instance); + VkResult res; + + res = disp->CreateHeadlessSurfaceEXT(instance, pCreateInfo, pAllocator, pSurface); + return res; +} + +VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance instance, + const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkSurfaceKHR *pSurface) { + struct loader_instance *inst = loader_get_instance(instance); + VkIcdSurface *pIcdSurface = NULL; + VkResult vkRes = VK_SUCCESS; + uint32_t i = 0; + + if (!inst->wsi_headless_surface_enabled) { + loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, + "VK_EXT_headless_surface extension not enabled. " + "vkCreateHeadlessSurfaceEXT not executed!\n"); + return VK_SUCCESS; + } + + // Next, if so, proceed with the implementation of this function: + pIcdSurface = AllocateIcdSurfaceStruct(inst, sizeof(pIcdSurface->headless_surf.base), sizeof(pIcdSurface->headless_surf)); + if (pIcdSurface == NULL) { + vkRes = VK_ERROR_OUT_OF_HOST_MEMORY; + goto out; + } + + pIcdSurface->headless_surf.base.platform = VK_ICD_WSI_PLATFORM_HEADLESS; + // Loop through each ICD and determine if they need to create a surface + for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) { + if (icd_term->scanned_icd->interface_version >= ICD_VER_SUPPORTS_ICD_SURFACE_KHR) { + if (NULL != icd_term->dispatch.CreateHeadlessSurfaceEXT) { + vkRes = icd_term->dispatch.CreateHeadlessSurfaceEXT(icd_term->instance, pCreateInfo, pAllocator, + &pIcdSurface->real_icd_surfaces[i]); + if (VK_SUCCESS != vkRes) { + goto out; + } + } + } + } + + *pSurface = (VkSurfaceKHR)pIcdSurface; + +out: + + if (VK_SUCCESS != vkRes && NULL != pIcdSurface) { + if (NULL != pIcdSurface->real_icd_surfaces) { + i = 0; + for (struct loader_icd_term *icd_term = inst->icd_terms; icd_term != NULL; icd_term = icd_term->next, i++) { + if ((VkSurfaceKHR)NULL != pIcdSurface->real_icd_surfaces[i] && NULL != icd_term->dispatch.DestroySurfaceKHR) { + icd_term->dispatch.DestroySurfaceKHR(icd_term->instance, pIcdSurface->real_icd_surfaces[i], pAllocator); + } + } + loader_instance_heap_free(inst, pIcdSurface->real_icd_surfaces); + } + loader_instance_heap_free(inst, pIcdSurface); + } + + return vkRes; +} + #ifdef VK_USE_PLATFORM_MACOS_MVK // Functions for the VK_MVK_macos_surface extension: @@ -1785,6 +1858,7 @@ bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char return true; } #endif // VK_USE_PLATFORM_ANDROID_KHR + #ifdef VK_USE_PLATFORM_MACOS_MVK // Functions for the VK_MVK_macos_surface extension: @@ -1802,6 +1876,12 @@ bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char } #endif // VK_USE_PLATFORM_IOS_MVK + // Functions for the VK_EXT_headless_surface extension: + if (!strcmp("vkCreateHeadlessSurfaceEXT", name)) { + *addr = ptr_instance->wsi_headless_surface_enabled ? (void *)vkCreateHeadlessSurfaceEXT : NULL; + return true; + } + // Functions for VK_KHR_display extension: if (!strcmp("vkGetPhysicalDeviceDisplayPropertiesKHR", name)) { *addr = ptr_instance->wsi_display_enabled ? (void *)vkGetPhysicalDeviceDisplayPropertiesKHR : NULL; diff --git a/loader/wsi.h b/loader/wsi.h index a65bef2ff..b09f168fd 100644 --- a/loader/wsi.h +++ b/loader/wsi.h @@ -43,6 +43,7 @@ typedef struct { VkIcdSurfaceMacOS macos_surf; #endif // VK_USE_PLATFORM_MACOS_MVK VkIcdSurfaceDisplay display_surf; + VkIcdSurfaceHeadless headless_surf; }; uint32_t base_size; // Size of VkIcdSurfaceBase uint32_t platform_size; // Size of corresponding VkIcdSurfaceXXX @@ -56,6 +57,10 @@ bool wsi_swapchain_instance_gpa(struct loader_instance *ptr_instance, const char void wsi_create_instance(struct loader_instance *ptr_instance, const VkInstanceCreateInfo *pCreateInfo); bool wsi_unsupported_instance_extension(const VkExtensionProperties *ext_prop); +VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateHeadlessSurfaceEXT(VkInstance instance, + const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo, + const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface); + VKAPI_ATTR VkResult VKAPI_CALL terminator_CreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain); diff --git a/scripts/loader_extension_generator.py b/scripts/loader_extension_generator.py index 9641477c7..cb4cc2df9 100644 --- a/scripts/loader_extension_generator.py +++ b/scripts/loader_extension_generator.py @@ -36,6 +36,7 @@ WSI_EXT_NAMES = ['VK_KHR_surface', 'VK_KHR_android_surface', 'VK_MVK_macos_surface', 'VK_MVK_ios_surface', + 'VK_EXT_headless_surface', 'VK_KHR_swapchain', 'VK_KHR_display_swapchain', 'VK_KHR_get_display_properties2'] |