Add format check to SharedPresentableImageTest
authorMikolaj Chadzynski <m.chadzynski@partner.samsung.com>
Thu, 23 Dec 2021 08:38:54 +0000 (09:38 +0100)
committerMatthew Netsch <quic_mnetsch@quicinc.com>
Fri, 14 Jan 2022 05:19:16 +0000 (05:19 +0000)
The SharedPresentableImageTest does not follow Vulkan spec.
The SurfaceFormats got by getPhysicalDeviceSurfaceFormats ->
getPhysicalDeviceSurfaceFormatsKHR should be checked by
vkGetPhysicalDeviceImageFormatProperties. This is according to:
www.khronos.org/registry/vulkan/specs/1.2-extensions/html/chap33.html
"33.5. Surface Queries
In addition to the surface capabilities as obtained by surface queries
below, swapchain images are also subject to ordinary image creation
limits as reported by vkGetPhysicalDeviceImageFormatProperties. As an
application is instructed by the appropriate Valid Usage sections, both
the surface capabilities and the image creation limits have to be
satisfied whenever swapchain images are created."

Unsupported format can lead to non-deterministic behavior e.g.
a segmentation fault, a null pointer dereference in a test or a driver.

VK-GL-CTS issue: 3422

Affects:
dEQP-VK.wsi.android.shared_presentable_image.*

Components: Vulkan

Change-Id: Id4bb4d1c81e090ed1d7f34a76f3cfafc464d8cf8

external/vulkancts/modules/vulkan/wsi/vktWsiSharedPresentableImageTests.cpp

index ea660ab..35b8344 100644 (file)
@@ -588,7 +588,9 @@ private:
        void                                                                                    render                                          (void);
 };
 
-std::vector<vk::VkSwapchainCreateInfoKHR> generateSwapchainConfigs (vk::VkSurfaceKHR                                           surface,
+std::vector<vk::VkSwapchainCreateInfoKHR> generateSwapchainConfigs (const vk::InstanceDriver&                          vki,
+                                                                                                                                       const vk::VkPhysicalDevice                              physicalDevice,
+                                                                                                                                       vk::VkSurfaceKHR                                                surface,
                                                                                                                                        deUint32                                                                queueFamilyIndex,
                                                                                                                                        Scaling                                                                 scaling,
                                                                                                                                        const vk::VkSurfaceCapabilitiesKHR&             properties,
@@ -670,6 +672,17 @@ std::vector<vk::VkSwapchainCreateInfoKHR> generateSwapchainConfigs (vk::VkSurfac
                        (vk::VkSwapchainKHR)0
                };
 
+               {
+                       vk::VkImageFormatProperties                     imageFormatProperties;
+
+                       deMemset(&imageFormatProperties, 0, sizeof(imageFormatProperties));
+
+                       vk::VkResult result = vki.getPhysicalDeviceImageFormatProperties(physicalDevice, imageFormat, vk::VK_IMAGE_TYPE_2D, vk::VK_IMAGE_TILING_OPTIMAL, imageUsage, 0, &imageFormatProperties);
+
+                       if (result == vk::VK_ERROR_FORMAT_NOT_SUPPORTED)
+                               continue;
+               }
+
                createInfos.push_back(createInfo);
        }
 
@@ -734,7 +747,7 @@ SharedPresentableImageTestInstance::SharedPresentableImageTestInstance (Context&
        , m_surfaceFormats                      (vk::wsi::getPhysicalDeviceSurfaceFormats(m_vki, m_physicalDevice, *m_surface))
        , m_presentModes                        (vk::wsi::getPhysicalDeviceSurfacePresentModes(m_vki, m_physicalDevice, *m_surface))
 
-       , m_swapchainConfigs            (generateSwapchainConfigs(*m_surface, m_queueFamilyIndex, testConfig.scaling, m_surfaceProperties, m_surfaceFormats, m_presentModes, testConfig.presentMode, m_supportedUsageFlags, testConfig.transform, testConfig.alpha))
+       , m_swapchainConfigs            (generateSwapchainConfigs(m_vki, m_physicalDevice, *m_surface, m_queueFamilyIndex, testConfig.scaling, m_surfaceProperties, m_surfaceFormats, m_presentModes, testConfig.presentMode, m_supportedUsageFlags, testConfig.transform, testConfig.alpha))
        , m_swapchainConfigNdx          (0u)
 
        , m_frameCount                          (60u * 5u)
@@ -968,7 +981,7 @@ tcu::TestStatus SharedPresentableImageTestInstance::iterate (void)
        {
                if (error.getError() == vk::VK_ERROR_OUT_OF_DATE_KHR)
                {
-                       m_swapchainConfigs = generateSwapchainConfigs(*m_surface, m_queueFamilyIndex, m_testConfig.scaling, m_surfaceProperties, m_surfaceFormats, m_presentModes, m_testConfig.presentMode, m_supportedUsageFlags, m_testConfig.transform, m_testConfig.alpha);
+                       m_swapchainConfigs = generateSwapchainConfigs(m_vki, m_physicalDevice, *m_surface, m_queueFamilyIndex, m_testConfig.scaling, m_surfaceProperties, m_surfaceFormats, m_presentModes, m_testConfig.presentMode, m_supportedUsageFlags, m_testConfig.transform, m_testConfig.alpha);
 
                        if (m_outOfDateCount < m_maxOutOfDateCount)
                        {