diff options
author | Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com> | 2023-09-19 10:19:39 +0100 |
---|---|---|
committer | Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com> | 2023-09-28 09:35:19 +0100 |
commit | 188ffe6a26a184cc2904535dd04ae4ec3c879e35 (patch) | |
tree | 6bcfd2abee618417268124f96c1868c2fa0d4b5c | |
parent | 07c1a4aa2149b79b2adbb85fa692753ae0c4b5de (diff) | |
download | vulkan-wsi-layer-188ffe6a26a184cc2904535dd04ae4ec3c879e35.tar.gz vulkan-wsi-layer-188ffe6a26a184cc2904535dd04ae4ec3c879e35.tar.bz2 vulkan-wsi-layer-188ffe6a26a184cc2904535dd04ae4ec3c879e35.zip |
Enable instance extensions
Modify the layer so that instance extensions needed for Wayland are only enabled when Wayland is selected.
In the past, the layer was changed to explicitly enable the instance extensions it needs in the intercepted calls to vkCreateInstance. Therefore, the layers always enabled the extension VK_KHR_external_memory_capabilities, despite this is only required by Wayland.
In this patch, this extension is only enabled when Wayland is enabled, i.e. when VK_KHR_wayland_surface is part of the extensions passed to vkCreateInstance.
Signed-off-by: Angeliki Agathi Tsintzira <angelikiagathi.tsintzira@arm.com>
Change-Id: I57e98b36e42012ba46769e9dd760a628a09b9ba5
-rw-r--r-- | layer/layer.cpp | 14 | ||||
-rw-r--r-- | wsi/headless/surface_properties.cpp | 14 | ||||
-rw-r--r-- | wsi/headless/surface_properties.hpp | 4 | ||||
-rw-r--r-- | wsi/surface_properties.hpp | 24 | ||||
-rw-r--r-- | wsi/wayland/surface_properties.cpp | 44 | ||||
-rw-r--r-- | wsi/wayland/surface_properties.hpp | 7 | ||||
-rw-r--r-- | wsi/wsi_factory.cpp | 39 | ||||
-rw-r--r-- | wsi/wsi_factory.hpp | 21 |
8 files changed, 118 insertions, 49 deletions
diff --git a/layer/layer.cpp b/layer/layer.cpp index 8ecc165..a999272 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -132,17 +132,7 @@ VKAPI_ATTR VkResult create_instance(const VkInstanceCreateInfo *pCreateInfo, con return VK_ERROR_EXTENSION_NOT_PRESENT; } - /* The extensions listed below are those strictly required by the layer. Other extensions may be used by the - * layer (such as calling their entrypoints), when they are enabled by the application. - */ - std::array<const char *, 4> extra_extensions = { - VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, - VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, - VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, - /* The extension below is only needed for Wayland. For now, enable it also for headless. */ - VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, - }; - TRY_LOG_CALL(extensions.add(extra_extensions.data(), extra_extensions.size())); + TRY_LOG_CALL(wsi::add_instance_extensions_required_by_layer(layer_platforms_to_enable, extensions)); TRY_LOG_CALL(extensions.get_extension_strings(modified_enabled_extensions)); modified_info.ppEnabledExtensionNames = modified_enabled_extensions.data(); @@ -249,7 +239,7 @@ VKAPI_ATTR VkResult create_device(VkPhysicalDevice physicalDevice, const VkDevic if (!enabled_platforms.empty()) { TRY_LOG_CALL(enabled_extensions.add(pCreateInfo->ppEnabledExtensionNames, pCreateInfo->enabledExtensionCount)); - TRY_LOG_CALL(wsi::add_extensions_required_by_layer(physicalDevice, enabled_platforms, enabled_extensions)); + TRY_LOG_CALL(wsi::add_device_extensions_required_by_layer(physicalDevice, enabled_platforms, enabled_extensions)); TRY_LOG_CALL(enabled_extensions.get_extension_strings(modified_enabled_extensions)); modified_info.ppEnabledExtensionNames = modified_enabled_extensions.data(); diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index 6530631..35891af 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2022 Arm Limited. + * Copyright (c) 2017-2019, 2021-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -48,7 +48,7 @@ namespace headless constexpr int max_core_1_0_formats = VK_FORMAT_ASTC_12x12_SRGB_BLOCK + 1; -surface_properties& surface_properties::get_instance() +surface_properties &surface_properties::get_instance() { static surface_properties instance; return instance; @@ -150,6 +150,16 @@ PFN_vkVoidFunction surface_properties::get_proc_addr(const char *name) return nullptr; } +VkResult surface_properties::get_required_instance_extensions(util::extension_list &extension_list) +{ + const std::array required_instance_extensions{ + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, + VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, + VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, + }; + return extension_list.add(required_instance_extensions.data(), required_instance_extensions.size()); +} + bool surface_properties::is_surface_extension_enabled(const layer::instance_private_data &instance_data) { return instance_data.is_instance_extension_enabled(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME); diff --git a/wsi/headless/surface_properties.hpp b/wsi/headless/surface_properties.hpp index fc97ea3..4678d64 100644 --- a/wsi/headless/surface_properties.hpp +++ b/wsi/headless/surface_properties.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2022 Arm Limited. + * Copyright (c) 2017-2019, 2022-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -48,6 +48,8 @@ public: PFN_vkVoidFunction get_proc_addr(const char *name) override; + VkResult get_required_instance_extensions(util::extension_list &extension_list) override; + bool is_surface_extension_enabled(const layer::instance_private_data &instance_data) override; static surface_properties &get_instance(); diff --git a/wsi/surface_properties.hpp b/wsi/surface_properties.hpp index 5160c07..99d8e5b 100644 --- a/wsi/surface_properties.hpp +++ b/wsi/surface_properties.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2022 Arm Limited. + * Copyright (c) 2017-2019, 2021-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -76,6 +76,11 @@ public: } /** + * @brief Return the instance extensions that this surface_properties implementation needs. + */ + virtual VkResult get_required_instance_extensions(util::extension_list &extension_list) = 0; + + /** * @brief Implements vkGetProcAddr for entrypoints specific to the surface type. * * At least the specific VkSurface creation entrypoint must be intercepted. @@ -89,17 +94,22 @@ public: /* There is no maximum theoretically speaking however we choose 6 for practicality */ static constexpr uint32_t MAX_SWAPCHAIN_IMAGE_COUNT = 6; - }; class surface_format_properties { public: surface_format_properties(VkFormat format) - : m_surface_format{ format, VK_COLORSPACE_SRGB_NONLINEAR_KHR } + : m_surface_format + { + format, VK_COLORSPACE_SRGB_NONLINEAR_KHR + } #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - , m_compression{ VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_PROPERTIES_EXT, nullptr, VK_IMAGE_COMPRESSION_DEFAULT_EXT, - VK_IMAGE_COMPRESSION_FIXED_RATE_NONE_EXT } + , m_compression + { + VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_PROPERTIES_EXT, nullptr, VK_IMAGE_COMPRESSION_DEFAULT_EXT, + VK_IMAGE_COMPRESSION_FIXED_RATE_NONE_EXT + } #endif { } @@ -119,11 +129,11 @@ public: void fill_format_properties(VkSurfaceFormat2KHR &surf_format) const; template <typename K> - static surface_format_properties& from_iterator(std::pair<const K, surface_format_properties> &iter) + static surface_format_properties &from_iterator(std::pair<const K, surface_format_properties> &iter) { return iter.second; } - static surface_format_properties& from_iterator(surface_format_properties &iter) + static surface_format_properties &from_iterator(surface_format_properties &iter) { return iter; } diff --git a/wsi/wayland/surface_properties.cpp b/wsi/wayland/surface_properties.cpp index defc638..26f4371 100644 --- a/wsi/wayland/surface_properties.cpp +++ b/wsi/wayland/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2022 Arm Limited. + * Copyright (c) 2017-2019, 2021-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -42,8 +42,6 @@ #include "util/macros.hpp" #include "util/helpers.hpp" -#define NELEMS(x) (sizeof(x) / sizeof(x[0])) - namespace wsi { namespace wayland @@ -224,23 +222,33 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical return get_surface_present_modes_common(pPresentModeCount, pPresentModes, modes); } -static const char *required_device_extensions[] = { - VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, - VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, - VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, - VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, - VK_KHR_MAINTENANCE1_EXTENSION_NAME, - VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, - VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME, - VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, - VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, - VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME, - VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME, -}; - VkResult surface_properties::get_required_device_extensions(util::extension_list &extension_list) { - return extension_list.add(required_device_extensions, NELEMS(required_device_extensions)); + const std::array required_device_extensions{ + VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, + VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, + VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, + VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, + VK_KHR_MAINTENANCE1_EXTENSION_NAME, + VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, + VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME, + VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, + VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, + VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME, + VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME, + }; + return extension_list.add(required_device_extensions.data(), required_device_extensions.size()); +} + +VkResult surface_properties::get_required_instance_extensions(util::extension_list &extension_list) +{ + const std::array required_instance_extensions{ + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, + VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME, + VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME, + VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, + }; + return extension_list.add(required_instance_extensions.data(), required_instance_extensions.size()); } struct required_properties diff --git a/wsi/wayland/surface_properties.hpp b/wsi/wayland/surface_properties.hpp index 594e430..7bc5653 100644 --- a/wsi/wayland/surface_properties.hpp +++ b/wsi/wayland/surface_properties.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2022 Arm Limited. + * Copyright (c) 2017-2019, 2021-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -40,7 +40,8 @@ struct surface_format_properties_hasher } }; -using surface_format_properties_map = util::unordered_map<VkFormat, surface_format_properties, surface_format_properties_hasher>; +using surface_format_properties_map = + util::unordered_map<VkFormat, surface_format_properties, surface_format_properties_hasher>; class surface; @@ -61,6 +62,8 @@ public: VkResult get_required_device_extensions(util::extension_list &extension_list) override; + VkResult get_required_instance_extensions(util::extension_list &extension_list) override; + PFN_vkVoidFunction get_proc_addr(const char *name) override; bool is_surface_extension_enabled(const layer::instance_private_data &instance_data) override; diff --git a/wsi/wsi_factory.cpp b/wsi/wsi_factory.cpp index bd86f66..c50b09f 100644 --- a/wsi/wsi_factory.cpp +++ b/wsi/wsi_factory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022 Arm Limited. + * Copyright (c) 2019-2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -140,8 +140,9 @@ static VkResult get_available_device_extensions(VkPhysicalDevice physical_device return VK_SUCCESS; } -VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms, - util::extension_list &extensions_to_enable) +VkResult add_device_extensions_required_by_layer(VkPhysicalDevice phys_dev, + const util::wsi_platform_set enabled_platforms, + util::extension_list &extensions_to_enable) { util::allocator allocator{ extensions_to_enable.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND }; @@ -203,6 +204,38 @@ VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util: return VK_SUCCESS; } +VkResult add_instance_extensions_required_by_layer(const util::wsi_platform_set enabled_platforms, + util::extension_list &extensions_to_enable) +{ + util::allocator allocator{ extensions_to_enable.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND }; + /* Requesting available instance extensions (as it happens with the device) + * before adding additional ones isn't supported during the instance creation. + * The reason for that is that the vulkan loader doesn't support layers to call vkEnumerateInstanceExtensionProperties. + */ + for (const auto &wsi_ext : supported_wsi_extensions) + { + /* Skip iterating over platforms not enabled in the instance. */ + if (!enabled_platforms.contains(wsi_ext.platform)) + { + continue; + } + + util::extension_list extensions_required_by_layer{ allocator }; + auto *props = get_surface_properties(wsi_ext.platform); + if (props == nullptr) + { + return VK_ERROR_INITIALIZATION_FAILED; + } + + TRY_LOG(props->get_required_instance_extensions(extensions_required_by_layer), + "Failed to acquire required instance extensions"); + + TRY_LOG_CALL(extensions_to_enable.add(extensions_required_by_layer)); + } + + return VK_SUCCESS; +} + void destroy_surface_swapchain(swapchain_base *swapchain, layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator) { diff --git a/wsi/wsi_factory.hpp b/wsi/wsi_factory.hpp index 298bf24..6211d77 100644 --- a/wsi/wsi_factory.hpp +++ b/wsi/wsi_factory.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Arm Limited. + * Copyright (c) 2019, 2021, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -67,7 +67,8 @@ util::unique_ptr<swapchain_base> allocate_surface_swapchain(VkSurfaceKHR surface * @param dev_data The device specific data. * @param pAllocator The allocator to use for freeing memory. */ -void destroy_surface_swapchain(swapchain_base *swapchain, layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator); +void destroy_surface_swapchain(swapchain_base *swapchain, layer::device_private_data &dev_data, + const VkAllocationCallbacks *pAllocator); /** * @brief Return which platforms the layer can handle for an instance constructed in the specified way. @@ -94,8 +95,20 @@ util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo * * * @retval @c VK_SUCCESS if the operation was successful. */ -VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms, - util::extension_list &extensions_to_enable); +VkResult add_device_extensions_required_by_layer(VkPhysicalDevice phys_dev, + const util::wsi_platform_set enabled_platforms, + util::extension_list &extensions_to_enable); + +/** + * @brief Add required instance extensions by the layer. + * + * @param[in] enabled_platforms All the enabled platforms for the current instance. + * @param[in,out] extensions_to_enable All the extensions required by the layer are added to this list. + * + * @retval @c VK_SUCCESS if the operation was successful. + */ +VkResult add_instance_extensions_required_by_layer(const util::wsi_platform_set enabled_platforms, + util::extension_list &extensions_to_enable); /** * @brief Return a function pointer for surface specific functions. |