Filter extensions supported by wsi layer: 63/269963/1
authorTianhao Ni <tianhao.ni@samsung.com>
Tue, 18 May 2021 07:22:45 +0000 (15:22 +0800)
committerTianhao Ni <tianhao.ni@samsung.com>
Mon, 24 Jan 2022 01:17:30 +0000 (09:17 +0800)
- When enable wsi layer, ICD should not enable the VK_KHR_wayland_surface_extension in the
  VkInstanceCreateInfo structure, if we pass VK_KHR_wayland_surface_extension name when calling
  ICD's vkCreateInstance API, it will cause "unspported extension" issue. So we remove the
  VK_KHR_wayland_surface_extension in the layer, and do not pass it to ICD.

Check validation layer feature when validation layer is enabled:

- Wsi layer is calling before validation layer, so if validation layer must disable the
  feature "VK_VALIDATION_FEATURE_DISABLE_UNIQUE_HANDLES_EXT", otherwise wsi layer can not use handles
  with validation layer handle wrapper. So in wsi layer, we must check if this feature is disabled.

Change-Id: I07fcffc01f0ffb59f5cc8d088edf3de57d9dc840
Signed-off-by: Tianhao Ni <tianhao.ni@samsung.com>
layer/layer.cpp
layer/private_data.hpp
wsi/swapchain_base_tizen.cpp
wsi/tizen/surface_properties.cpp
wsi/tizen/swapchain.cpp
wsi/wsi_factory.cpp
wsi/wsi_factory.hpp

index e2b4c8dda00454ae132a3207ce4b09957594e956..261d954c1659d3489587c4ebf7eb7d77bf722bf9 100644 (file)
@@ -123,15 +123,65 @@ VKAPI_ATTR VkResult create_instance(const VkInstanceCreateInfo *pCreateInfo, con
       modified_app_info.apiVersion = minimum_required_vulkan_version;
    }
 
+   /* Check If validation layer is enabled, if app enable validation layer,
+    * The validation layer feature VK_VALIDATION_FEATURE_DISABLE_UNIQUE_HANDLES_EXT must be disabled
+    */
+   bool validationLayerEnabled = false;
+   const char *const *enabledLayerNames = pCreateInfo->ppEnabledLayerNames;
+   for (uint32_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
+      if (strcmp(enabledLayerNames[i], "VK_LAYER_KHRONOS_validation") == 0) {
+         validationLayerEnabled = true;
+         break;
+      }
+   }
+   if (validationLayerEnabled) {
+      VkValidationFeaturesEXT *pValidationFeatures = (VkValidationFeaturesEXT *)pCreateInfo->pNext;
+      while (pValidationFeatures && pValidationFeatures->sType != VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT) {
+         pValidationFeatures = (VkValidationFeaturesEXT *)pValidationFeatures->pNext;
+      }
+      assert(pValidationFeatures);
+      assert(pValidationFeatures->disabledValidationFeatureCount);
+
+      bool uniqueHandlesfeatureDisabled = false;
+      for (uint32_t i = 0; i < pValidationFeatures->disabledValidationFeatureCount; i++) {
+         if (pValidationFeatures->pDisabledValidationFeatures[i] == VK_VALIDATION_FEATURE_DISABLE_UNIQUE_HANDLES_EXT ||
+             pValidationFeatures->pDisabledValidationFeatures[i] == VK_VALIDATION_FEATURE_DISABLE_ALL_EXT) {
+            uniqueHandlesfeatureDisabled = true;
+            break;
+         }
+      }
+      assert(uniqueHandlesfeatureDisabled);
+   }
+
+   /* Exclude VK_KHR_wayland_surface extension from ppEnabledExtensionNames.
+    * This extension is supported by this layer, so ICDs does not need to support it.
+    */
+   util::allocator allocator{pAllocator, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND};
+   util::extension_list enabled_extensions{allocator};
+   VkResult result;
+   result = enabled_extensions.add(pCreateInfo->ppEnabledExtensionNames, pCreateInfo->enabledExtensionCount);
+   if (result != VK_SUCCESS)
+   {
+      return result;
+   }
+
+   util::vector<const char *> modified_enabled_extensions{allocator};
+   wsi::remove_extensions_supported_by_layer(enabled_extensions);
+   if (!enabled_extensions.get_extension_strings(modified_enabled_extensions))
+   {
+      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   }
+
    VkInstanceCreateInfo modified_info = *pCreateInfo;
    modified_info.pApplicationInfo = &modified_app_info;
+   modified_info.ppEnabledExtensionNames = modified_enabled_extensions.data();
+   modified_info.enabledExtensionCount = modified_enabled_extensions.size();
 
    /* Now call create instance on the chain further down the list.
     * Note that we do not remove the extensions that the layer supports from modified_info.ppEnabledExtensionNames.
     * Layers have to abide the rule that vkCreateInstance must not generate an error for unrecognized extension names.
     * Also, the loader filters the extension list to ensure that ICDs do not see extensions that they do not support.
     */
-   VkResult result;
    result = fpCreateInstance(&modified_info, pAllocator, pInstance);
    if (result != VK_SUCCESS)
    {
index 11fa5ce8c02a2458176fe78ab9cbd31b252437b2..a3598e7c96f83870f314468c67d6b4a5609deb4e 100644 (file)
@@ -138,6 +138,7 @@ struct instance_dispatch_table
    OPTIONAL(AcquireNextImage2KHR)                   \
    OPTIONAL(GetFenceFdKHR)
 
+
 struct device_dispatch_table
 {
    /**
index acbafb68ac4a482e9cef140bd363838b3089e0b6..76ece53d77410199e3c15b47047871f39d53cc63 100644 (file)
@@ -73,11 +73,6 @@ VkResult swapchain_base::init(VkDevice device, const VkSwapchainCreateInfoKHR *s
    }
 
    m_device_data.disp.GetDeviceQueue(m_device, 0, 0, &m_queue);
-   result = m_device_data.SetDeviceLoaderData(m_device, m_queue);
-   if (VK_SUCCESS != result)
-   {
-      return result;
-   }
 
    if (swapchain_create_info->oldSwapchain != VK_NULL_HANDLE)
    {
index 3bd73d73459257a53b1eeb8bc6bbf6b0aef8e2de..fceb584c370364c6d812ecd7984b19fb2e41aca1 100644 (file)
@@ -58,7 +58,7 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_
    if (vk_surf == NULL || vk_surf->display == NULL || vk_surf->surface == NULL)
       return VK_ERROR_SURFACE_LOST_KHR;
 
-   tpl_display_t *tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI, vk_surf->display);
+   tpl_display_t *tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, vk_surf->display);
    if (tpl_display == NULL) {
       return VK_ERROR_OUT_OF_HOST_MEMORY;
    }
@@ -137,13 +137,31 @@ VkResult surface_properties::get_surface_formats(VkPhysicalDevice physical_devic
 VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical_device, VkSurfaceKHR surface,
                                                        uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes)
 {
-
+   VkIcdSurfaceWayland *vk_surf = reinterpret_cast<VkIcdSurfaceWayland *>(surface);
    VkResult res = VK_SUCCESS;
-   /* TODO: Check that FIFO is okay on Wayland */
-   static std::array<const VkPresentModeKHR, 2> modes = {
-      VK_PRESENT_MODE_FIFO_KHR,
-      VK_PRESENT_MODE_MAILBOX_KHR,
-   };
+
+   if (vk_surf == NULL || vk_surf->display == NULL || vk_surf->surface == NULL)
+      return VK_ERROR_SURFACE_LOST_KHR;
+
+   tpl_display_t *tpl_display = tpl_display_create(TPL_BACKEND_WAYLAND_VULKAN_WSI_THREAD, vk_surf->display);
+   if (tpl_display == NULL) {
+      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   }
+
+   int tplModes;
+   if (tpl_display_query_supported_present_modes_from_native_window(tpl_display, vk_surf->display, &tplModes) != TPL_ERROR_NONE) {
+      return VK_ERROR_SURFACE_LOST_KHR;
+   }
+
+   std::vector<VkPresentModeKHR> modes = {};
+   if (tplModes & TPL_DISPLAY_PRESENT_MODE_IMMEDIATE)
+      modes.push_back(VK_PRESENT_MODE_IMMEDIATE_KHR);
+   if (tplModes & TPL_DISPLAY_PRESENT_MODE_MAILBOX)
+      modes.push_back(VK_PRESENT_MODE_MAILBOX_KHR);
+   if (tplModes & TPL_DISPLAY_PRESENT_MODE_FIFO)
+      modes.push_back(VK_PRESENT_MODE_FIFO_KHR);
+   if (tplModes & TPL_DISPLAY_PRESENT_MODE_FIFO_RELAXED)
+      modes.push_back(VK_PRESENT_MODE_FIFO_RELAXED_KHR);
 
    assert(pPresentModeCount != nullptr);
 
index 77d6983367427a864a2bea003dbe5f0dceb5efec..e21efa7ea5610e2bfa381f960818647a24b1f502 100644 (file)
@@ -59,6 +59,8 @@ struct swapchain::tizen_image_data
 
 swapchain::swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator)
    : swapchain_base(dev_data, pAllocator)
+   , m_tpl_surface(nullptr)
+   , m_tpl_display(nullptr)
 {
 }
 
@@ -72,60 +74,60 @@ swapchain::~swapchain()
 }
 
 #define TBM_FORMAT_0   0
-#define RETURN_FORMAT(comp, opaque, pre, post, inherit)                                        \
-       do {                                                                                                                            \
-               if (comp == VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR)                                  \
-                       return TBM_FORMAT_##opaque;                                                                     \
-               else if (comp == VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR)             \
-                       return TBM_FORMAT_##pre;                                                                        \
-               else if (comp == VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR)    \
-                       return TBM_FORMAT_##post;                                                                       \
-               else if (comp == VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR)                    \
-                       return TBM_FORMAT_##inherit;                                                            \
-               else                                                                                                                    \
-                       return 0;                                                                                                       \
-       } while (0)
+#define RETURN_FORMAT(comp, opaque, pre, post, inherit)             \
+   do {                                                             \
+      if (comp == VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR)                \
+         return TBM_FORMAT_##opaque;                                \
+      else if (comp == VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR)   \
+         return TBM_FORMAT_##pre;                                   \
+      else if (comp == VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR)  \
+         return TBM_FORMAT_##post;                                  \
+      else if (comp == VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR)          \
+         return TBM_FORMAT_##inherit;                               \
+      else                                                          \
+         return 0;                                                  \
+   } while (0)
 
 
 static inline tbm_format
 wsi_tizen_get_tbm_format(VkFormat format, VkCompositeAlphaFlagBitsKHR comp)
 {
-       switch (format) {
-       /* 4 4 4 4 */
-       case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
-               RETURN_FORMAT(comp, RGBX4444, RGBA4444, 0, RGBA4444);
-       case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
-               RETURN_FORMAT(comp, BGRX4444, BGRA4444, 0, BGRA4444);
-       /* 5 6 5 */
-       case VK_FORMAT_R5G6B5_UNORM_PACK16:
-               RETURN_FORMAT(comp, RGB565, RGB565, RGB565, RGB565);
-       case VK_FORMAT_B5G6R5_UNORM_PACK16:
-               RETURN_FORMAT(comp, BGR565, BGR565, BGR565, BGR565);
-       /* 5 5 5 1 */
-       case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
-               RETURN_FORMAT(comp, RGBX5551, RGBA5551, 0, RGBA5551);
-       case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
-               RETURN_FORMAT(comp, BGRX5551, BGRA5551, 0, BGRA5551);
-       case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
-               RETURN_FORMAT(comp, XRGB1555, ARGB1555, 0, ARGB1555);
-       /* 8 8 8 */
-       case VK_FORMAT_R8G8B8_UNORM:
-               RETURN_FORMAT(comp, BGR888, BGR888, BGR888, BGR888);
-       case VK_FORMAT_B8G8R8_UNORM:
-               RETURN_FORMAT(comp, RGB888, RGB888, RGB888, RGB888);
-       /* 8 8 8 8 */
-       case VK_FORMAT_B8G8R8A8_UNORM:
-               RETURN_FORMAT(comp, XRGB8888, ARGB8888, 0, ARGB8888);
-       case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
-               RETURN_FORMAT(comp, XBGR8888, ABGR8888, 0, ABGR8888);
-       /* 2 10 10 10 */
-       case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
-               RETURN_FORMAT(comp, XRGB2101010, ARGB2101010, 0, ARGB2101010);
-       case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
-               RETURN_FORMAT(comp, XBGR2101010, ABGR2101010, 0, ABGR2101010);
-       default:
-               break;
-       }
+   switch (format) {
+   /* 4 4 4 4 */
+   case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
+      RETURN_FORMAT(comp, RGBX4444, RGBA4444, 0, RGBA4444);
+   case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
+      RETURN_FORMAT(comp, BGRX4444, BGRA4444, 0, BGRA4444);
+   /* 5 6 5 */
+   case VK_FORMAT_R5G6B5_UNORM_PACK16:
+      RETURN_FORMAT(comp, RGB565, RGB565, RGB565, RGB565);
+   case VK_FORMAT_B5G6R5_UNORM_PACK16:
+      RETURN_FORMAT(comp, BGR565, BGR565, BGR565, BGR565);
+   /* 5 5 5 1 */
+   case VK_FORMAT_R5G5B5A1_UNORM_PACK16:
+      RETURN_FORMAT(comp, RGBX5551, RGBA5551, 0, RGBA5551);
+   case VK_FORMAT_B5G5R5A1_UNORM_PACK16:
+      RETURN_FORMAT(comp, BGRX5551, BGRA5551, 0, BGRA5551);
+   case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
+      RETURN_FORMAT(comp, XRGB1555, ARGB1555, 0, ARGB1555);
+   /* 8 8 8 */
+   case VK_FORMAT_R8G8B8_UNORM:
+      RETURN_FORMAT(comp, BGR888, BGR888, BGR888, BGR888);
+   case VK_FORMAT_B8G8R8_UNORM:
+      RETURN_FORMAT(comp, RGB888, RGB888, RGB888, RGB888);
+   /* 8 8 8 8 */
+   case VK_FORMAT_B8G8R8A8_UNORM:
+      RETURN_FORMAT(comp, XRGB8888, ARGB8888, 0, ARGB8888);
+   case VK_FORMAT_A8B8G8R8_UNORM_PACK32:
+      RETURN_FORMAT(comp, XBGR8888, ABGR8888, 0, ABGR8888);
+   /* 2 10 10 10 */
+   case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
+      RETURN_FORMAT(comp, XRGB2101010, ARGB2101010, 0, ARGB2101010);
+   case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
+      RETURN_FORMAT(comp, XBGR2101010, ABGR2101010, 0, ABGR2101010);
+   default:
+      break;
+   }
 
        return 0;
 }
@@ -199,7 +201,6 @@ VkResult swapchain::allocate_image(const VkImageCreateInfo &image_create_info, t
    drm_mod_info.drmFormatModifier = DRM_FORMAT_MOD_LINEAR;
    drm_mod_info.drmFormatModifierPlaneCount = 1;
    drm_mod_info.pPlaneLayouts = &image_layout;
-
    VkExternalMemoryImageCreateInfoKHR external_info = {};
    external_info.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO_KHR;
    external_info.pNext = &drm_mod_info;
@@ -269,7 +270,16 @@ VkResult swapchain::create_image(const VkImageCreateInfo &image_create_info)
    VkResult result = VK_SUCCESS;
    tpl_result_t res;
    tbm_surface_h *buffers;
-   int tbm_buf_cnt, i = 0;
+   int tbm_buf_cnt = 0, i = 0;
+
+   res = tpl_surface_get_swapchain_buffers(m_tpl_surface, NULL, &tbm_buf_cnt);
+   if (res == TPL_ERROR_OUT_OF_MEMORY)
+      return VK_ERROR_OUT_OF_HOST_MEMORY;
+   else if (res != TPL_ERROR_NONE)
+      return VK_ERROR_INITIALIZATION_FAILED;
+
+   if (tbm_buf_cnt < 2)
+      return VK_ERROR_OUT_OF_HOST_MEMORY;
 
    res = tpl_surface_get_swapchain_buffers(m_tpl_surface, &buffers, &tbm_buf_cnt);
    if (res == TPL_ERROR_OUT_OF_MEMORY)
index d0dc448fadf151a5e576d2c53b9f058e71229ea4..b23998a22197e6c6c979042b740faecaa68d65a7 100644 (file)
@@ -210,6 +210,16 @@ VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util:
    return VK_SUCCESS;
 }
 
+void remove_extensions_supported_by_layer(util::extension_list &extensions_to_enable)
+{
+   for (const auto &wsi_ext : supported_wsi_extensions)
+   {
+      if (extensions_to_enable.contains(wsi_ext.extension.extensionName)) {
+         extensions_to_enable.remove(wsi_ext.extension.extensionName);
+      }
+   }
+}
+
 void destroy_surface_swapchain(swapchain_base *swapchain, layer::device_private_data &dev_data,
                                const VkAllocationCallbacks *pAllocator)
 {
index 3bfa688a3288b263c1b6411f62af3f63441092c4..a643f978b80c75a95023954b2a5994e0d5e89414 100644 (file)
@@ -101,6 +101,8 @@ util::wsi_platform_set find_enabled_layer_platforms(const VkInstanceCreateInfo *
 VkResult add_extensions_required_by_layer(VkPhysicalDevice phys_dev, const util::wsi_platform_set enabled_platforms,
                                           util::extension_list &extensions_to_enable);
 
+void remove_extensions_supported_by_layer(util::extension_list &extensions_to_enable);
+
 /**
  * @brief Return a function pointer for surface specific functions.
  *