Merge vk-gl-cts/vulkan-cts-1.3.2 into vk-gl-cts/main
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / robustness / vktRobustnessExtsTests.cpp
index 7678fa9..6a34ea8 100644 (file)
@@ -28,6 +28,7 @@
 #include "vkImageWithMemory.hpp"
 #include "vkImageUtil.hpp"
 #include "vkQueryUtil.hpp"
+#include "vkDeviceUtil.hpp"
 #include "vkBuilderUtil.hpp"
 #include "vkCmdUtil.hpp"
 #include "vkTypeUtil.hpp"
@@ -77,7 +78,7 @@ template <RobustnessFeatures FEATURES>
 class SingletonDevice
 {
        SingletonDevice (Context& context)
-               : m_logicalDevice ()
+               : m_context(context), m_instanceWrapper(new CustomInstanceWrapper(context)),  m_logicalDevice ()
        {
                // Note we are already checking the needed features are available in checkSupport().
                VkPhysicalDeviceRobustness2FeaturesEXT                          robustness2Features                             = initVulkanStructure();
@@ -109,11 +110,36 @@ class SingletonDevice
                        features2.pNext = &shaderImageAtomicInt64Features;
                }
 
-               context.getInstanceInterface().getPhysicalDeviceFeatures2(context.getPhysicalDevice(), &features2);
-               m_logicalDevice = createRobustBufferAccessDevice(context, &features2);
+               const VkPhysicalDevice physicalDevice = chooseDevice(m_instanceWrapper->instance.getDriver(), m_instanceWrapper->instance, context.getTestContext().getCommandLine());
+               m_instanceWrapper->instance.getDriver().getPhysicalDeviceFeatures2(physicalDevice, &features2);
+               m_logicalDevice = createRobustBufferAccessDevice(context, m_instanceWrapper->instance, m_instanceWrapper->instance.getDriver(), &features2);
+
+#ifndef CTS_USES_VULKANSC
+               m_deviceDriver = de::MovePtr<DeviceDriver>(new DeviceDriver(context.getPlatformInterface(), m_instanceWrapper->instance, *m_logicalDevice));
+#else
+               m_deviceDriver = de::MovePtr<DeviceDriverSC, DeinitDeviceDeleter>(new DeviceDriverSC(context.getPlatformInterface(), m_instanceWrapper->instance, *m_logicalDevice, context.getTestContext().getCommandLine(), context.getResourceInterface(), m_context.getDeviceVulkanSC10Properties()), vk::DeinitDeviceDeleter(context.getResourceInterface().get(), *m_logicalDevice));
+#endif // CTS_USES_VULKANSC
        }
 
 public:
+       ~SingletonDevice()
+       {
+       }
+       static VkInstance getInstance(Context& context)
+       {
+               if (!m_singletonDevice)
+                       m_singletonDevice = SharedPtr<SingletonDevice>(new SingletonDevice(context));
+               DE_ASSERT(m_singletonDevice);
+               return m_singletonDevice->m_instanceWrapper->instance;
+       }
+       static const InstanceInterface& getInstanceInterface(Context& context)
+       {
+               if (!m_singletonDevice)
+                       m_singletonDevice = SharedPtr<SingletonDevice>(new SingletonDevice(context));
+               DE_ASSERT(m_singletonDevice);
+               return m_singletonDevice->m_instanceWrapper->instance.getDriver();
+       }
+
        static VkDevice getDevice(Context& context)
        {
                if (!m_singletonDevice)
@@ -121,6 +147,13 @@ public:
                DE_ASSERT(m_singletonDevice);
                return m_singletonDevice->m_logicalDevice.get();
        }
+       static const DeviceInterface& getDeviceInterface(Context& context)
+       {
+               if (!m_singletonDevice)
+                       m_singletonDevice = SharedPtr<SingletonDevice>(new SingletonDevice(context));
+               DE_ASSERT(m_singletonDevice);
+               return *(m_singletonDevice->m_deviceDriver.get());
+       }
 
        static void destroy()
        {
@@ -128,7 +161,15 @@ public:
        }
 
 private:
+       const Context&                                                          m_context;
+       std::shared_ptr<CustomInstanceWrapper>          m_instanceWrapper;
        Move<vk::VkDevice>                                                      m_logicalDevice;
+#ifndef CTS_USES_VULKANSC
+       de::MovePtr<vk::DeviceDriver>                           m_deviceDriver;
+#else
+       de::MovePtr<vk::DeviceDriverSC, vk::DeinitDeviceDeleter>        m_deviceDriver;
+#endif // CTS_USES_VULKANSC
+
        static SharedPtr<SingletonDevice<FEATURES>>     m_singletonDevice;
 };
 
@@ -193,6 +234,36 @@ static bool formatIsR64(const VkFormat& f)
 }
 
 // Returns the appropriate singleton device for the given case.
+VkInstance getInstance(Context& ctx, const CaseDef& caseDef)
+{
+       if (formatIsR64(caseDef.format))
+       {
+               if (caseDef.testRobustness2)
+                       return Robustness2Int64AtomicsSingleton::getInstance(ctx);
+               return ImageRobustnessInt64AtomicsSingleton::getInstance(ctx);
+       }
+
+       if (caseDef.testRobustness2)
+               return Robustness2Singleton::getInstance(ctx);
+       return ImageRobustnessSingleton::getInstance(ctx);
+}
+
+// Returns the appropriate singleton device driver for the given case.
+const InstanceInterface& getInstanceInterface(Context& ctx, const CaseDef& caseDef)
+{
+       if (formatIsR64(caseDef.format))
+       {
+               if (caseDef.testRobustness2)
+                       return Robustness2Int64AtomicsSingleton::getInstanceInterface(ctx);
+               return ImageRobustnessInt64AtomicsSingleton::getInstanceInterface(ctx);
+       }
+
+       if (caseDef.testRobustness2)
+               return Robustness2Singleton::getInstanceInterface(ctx);
+       return ImageRobustnessSingleton::getInstanceInterface(ctx);
+}
+
+// Returns the appropriate singleton device for the given case.
 VkDevice getLogicalDevice (Context& ctx, const CaseDef& caseDef)
 {
        if (formatIsR64(caseDef.format))
@@ -207,6 +278,22 @@ VkDevice getLogicalDevice (Context& ctx, const CaseDef& caseDef)
        return ImageRobustnessSingleton::getDevice(ctx);
 }
 
+// Returns the appropriate singleton device driver for the given case.
+const DeviceInterface& getDeviceInterface(Context& ctx, const CaseDef& caseDef)
+{
+       if (formatIsR64(caseDef.format))
+       {
+               if (caseDef.testRobustness2)
+                       return Robustness2Int64AtomicsSingleton::getDeviceInterface(ctx);
+               return ImageRobustnessInt64AtomicsSingleton::getDeviceInterface(ctx);
+       }
+
+       if (caseDef.testRobustness2)
+               return Robustness2Singleton::getDeviceInterface(ctx);
+       return ImageRobustnessSingleton::getDeviceInterface(ctx);
+}
+
+
 class Layout
 {
 public:
@@ -309,7 +396,7 @@ void RobustnessExtsTestCase::checkSupport(Context& context) const
        VkPhysicalDeviceRobustness2FeaturesEXT                          robustness2Features                             = initVulkanStructure();
        VkPhysicalDeviceImageRobustnessFeaturesEXT                      imageRobustnessFeatures                 = initVulkanStructure();
        VkPhysicalDeviceScalarBlockLayoutFeatures                       scalarLayoutFeatures                    = initVulkanStructure();
-       VkPhysicalDeviceFeatures2KHR                                            features2                                               = initVulkanStructure();
+       VkPhysicalDeviceFeatures2                                                       features2                                               = initVulkanStructure();
 
        context.requireInstanceFunctionality("VK_KHR_get_physical_device_properties2");
 
@@ -335,7 +422,7 @@ void RobustnessExtsTestCase::checkSupport(Context& context) const
                context.requireDeviceFunctionality("VK_EXT_shader_image_atomic_int64");
 
                VkFormatProperties formatProperties;
-               vki.getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_data.format, &formatProperties);
+               vki.getPhysicalDeviceFormatProperties(physicalDevice, m_data.format, &formatProperties);
 
                switch (m_data.descriptorType)
                {
@@ -427,9 +514,10 @@ void RobustnessExtsTestCase::checkSupport(Context& context) const
                !features2.features.shaderStorageImageMultisample)
                TCU_THROW(NotSupportedError, "shaderStorageImageMultisample not supported");
 
-       if ((m_data.useTemplate || formatIsR64(m_data.format)) && !context.contextSupports(vk::ApiVersion(1, 1, 0)))
+       if ((m_data.useTemplate || formatIsR64(m_data.format)) && !context.contextSupports(vk::ApiVersion(0, 1, 1, 0)))
                TCU_THROW(NotSupportedError, "Vulkan 1.1 not supported");
 
+#ifndef CTS_USES_VULKANSC
        if ((m_data.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER || m_data.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) &&
                !m_data.formatQualifier)
        {
@@ -439,6 +527,12 @@ void RobustnessExtsTestCase::checkSupport(Context& context) const
                if (!(formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_2_STORAGE_WRITE_WITHOUT_FORMAT_BIT_KHR))
                        TCU_THROW(NotSupportedError, "Format does not support writing without format");
        }
+#else
+       if ((m_data.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER || m_data.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) &&
+               !m_data.formatQualifier &&
+               (!features2.features.shaderStorageImageReadWithoutFormat || !features2.features.shaderStorageImageWriteWithoutFormat))
+               TCU_THROW(NotSupportedError, "shaderStorageImageReadWithoutFormat or shaderStorageImageWriteWithoutFormat not supported");
+#endif // CTS_USES_VULKANSC
 
        if (m_data.pushDescriptor)
                context.requireDeviceFunctionality("VK_KHR_push_descriptor");
@@ -711,6 +805,9 @@ string genCoord(string c, int numCoords, VkSampleCountFlagBits samples, int dim)
 // Normalized coordinates. Divide by "imageDim" and add 0.25 so we're not on a pixel boundary.
 string genCoordNorm(const CaseDef &caseDef, string c, int numCoords, int numNormalizedCoords, int dim)
 {
+       // dim can be 3 for cube_array. Reuse the number of layers in that case.
+       dim = std::min(dim, 2);
+
        if (numCoords == 1)
                return c + " / float(" + to_string(caseDef.imageDim[dim]) + ")";
 
@@ -1547,10 +1644,11 @@ TestInstance* RobustnessExtsTestCase::createInstance (Context& context) const
 
 tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
 {
-       const InstanceInterface&        vki                                     = m_context.getInstanceInterface();
+       const VkInstance                        instance                        = getInstance(m_context, m_data);
+       const InstanceInterface&        vki                                     = getInstanceInterface(m_context, m_data);
        const VkDevice                          device                          = getLogicalDevice(m_context, m_data);
-       const DeviceDriver                      vk                                      (m_context.getPlatformInterface(), m_context.getInstance(), device);
-       const VkPhysicalDevice          physicalDevice          = m_context.getPhysicalDevice();
+       const vk::DeviceInterface&      vk                                      = getDeviceInterface(m_context, m_data);
+       const VkPhysicalDevice          physicalDevice          = chooseDevice(vki, instance, m_context.getTestContext().getCommandLine());
        SimpleAllocator                         allocator                       (vk, device, getPhysicalDeviceMemoryProperties(vki, physicalDevice));
 
        Layout layout;
@@ -1562,19 +1660,23 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
        properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
        void** pNextTail = &properties.pNext;
 
+#ifndef CTS_USES_VULKANSC
        VkPhysicalDeviceRayTracingPropertiesNV rayTracingProperties;
        deMemset(&rayTracingProperties, 0, sizeof(rayTracingProperties));
        rayTracingProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PROPERTIES_NV;
+#endif
 
        VkPhysicalDeviceRobustness2PropertiesEXT robustness2Properties;
        deMemset(&robustness2Properties, 0, sizeof(robustness2Properties));
        robustness2Properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_PROPERTIES_EXT;
 
+#ifndef CTS_USES_VULKANSC
        if (m_context.isDeviceFunctionalitySupported("VK_NV_ray_tracing"))
        {
                *pNextTail = &rayTracingProperties;
                pNextTail = &rayTracingProperties.pNext;
        }
+#endif
 
        if (m_context.isDeviceFunctionalitySupported("VK_EXT_robustness2"))
        {
@@ -1603,9 +1705,11 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
        case STAGE_COMPUTE:
                bindPoint = VK_PIPELINE_BIND_POINT_COMPUTE;
                break;
+#ifndef CTS_USES_VULKANSC
        case STAGE_RAYGEN:
                bindPoint = VK_PIPELINE_BIND_POINT_RAY_TRACING_NV;
                break;
+#endif
        default:
                bindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
                break;
@@ -1621,7 +1725,12 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
        vector<VkDescriptorSetLayoutBinding> &bindings = layout.layoutBindings;
 
        VkDescriptorPoolCreateFlags poolCreateFlags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
+
+#ifndef CTS_USES_VULKANSC
        VkDescriptorSetLayoutCreateFlags layoutCreateFlags = m_data.pushDescriptor ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR : 0;
+#else
+       VkDescriptorSetLayoutCreateFlags layoutCreateFlags = 0;
+#endif
 
        // Create a layout and allocate a descriptor set for it.
 
@@ -1780,8 +1889,8 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
        if (m_data.viewType == VK_IMAGE_VIEW_TYPE_CUBE || m_data.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
                imageCreateFlags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
 
-       const bool featureSampledImage = ((getPhysicalDeviceFormatProperties(m_context.getInstanceInterface(),
-                                                                               m_context.getPhysicalDevice(),
+       const bool featureSampledImage = ((getPhysicalDeviceFormatProperties(vki,
+                                                                               physicalDevice,
                                                                                m_data.format).optimalTilingFeatures &
                                                                                VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) == VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
 
@@ -2184,9 +2293,11 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                int vecIndex = 0;
                int numDynamic = 0;
 
+#ifndef CTS_USES_VULKANSC
                vector<VkDescriptorUpdateTemplateEntry> imgTemplateEntriesBefore,
                                                                                                bufTemplateEntriesBefore,
                                                                                                texelBufTemplateEntriesBefore;
+#endif
 
                for (size_t b = 0; b < bindings.size(); ++b)
                {
@@ -2235,6 +2346,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                                        &bufferViewVec[vecIndex],                                                       // pTexelBufferView
                                };
 
+#ifndef CTS_USES_VULKANSC
                                VkDescriptorUpdateTemplateEntry templateEntry =
                                {
                                        (deUint32)b,                            // uint32_t                             dstBinding;
@@ -2266,6 +2378,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                                        bufTemplateEntriesBefore.push_back(templateEntry);
                                        break;
                                }
+#endif
 
                                vecIndex++;
 
@@ -2287,6 +2400,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                // Randomly select between vkUpdateDescriptorSets and vkUpdateDescriptorSetWithTemplate
                if (m_data.useTemplate)
                {
+#ifndef CTS_USES_VULKANSC
                        VkDescriptorUpdateTemplateCreateInfo templateCreateInfo =
                        {
                                VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO,       // VkStructureType                                                      sType;
@@ -2345,15 +2459,18 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
 
                                vk.cmdBindDescriptorSets(*cmdBuffer, bindPoint, *pipelineLayout, 0, 1, &descriptorSet.get(), numDynamic, &zeros[0]);
                        }
+#endif
                }
                else
                {
                        if (m_data.pushDescriptor)
                        {
+#ifndef CTS_USES_VULKANSC
                                if (writesBeforeBindVec.size())
                                {
                                        vk.cmdPushDescriptorSetKHR(*cmdBuffer, bindPoint, *pipelineLayout, 0, (deUint32)writesBeforeBindVec.size(), &writesBeforeBindVec[0]);
                                }
+#endif
                        }
                        else
                        {
@@ -2380,6 +2497,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                pipeline = makeComputePipeline(vk, device, *pipelineLayout, *shader);
 
        }
+#ifndef CTS_USES_VULKANSC
        else if (m_data.stage == STAGE_RAYGEN)
        {
                const Unique<VkShaderModule>    shader(createShaderModule(vk, device, m_context.getBinaryCollection().get("test"), 0));
@@ -2430,6 +2548,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
 
                vk.getRayTracingShaderGroupHandlesNV(device, *pipeline, 0, 1, rayTracingProperties.shaderGroupHandleSize, ptr);
        }
+#endif
        else
        {
                const VkSubpassDescription              subpassDesc                             =
@@ -2698,6 +2817,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
        {
                vk.cmdDispatch(*cmdBuffer, DIM, DIM, 1);
        }
+#ifndef CTS_USES_VULKANSC
        else if (m_data.stage == STAGE_RAYGEN)
        {
                vk.cmdTraceRaysNV(*cmdBuffer,
@@ -2707,6 +2827,7 @@ tcu::TestStatus RobustnessExtsTestInstance::iterate (void)
                        DE_NULL, 0, 0,
                        DIM, DIM, 1);
        }
+#endif
        else
        {
                beginRenderPass(vk, *cmdBuffer, *renderPass, *framebuffer,
@@ -2894,7 +3015,9 @@ static void createTests (tcu::TestCaseGroup* group, bool robustness2)
                { STAGE_COMPUTE,        "comp",         "compute"       },
                { STAGE_FRAGMENT,       "frag",         "fragment"      },
                { STAGE_VERTEX,         "vert",         "vertex"        },
+#ifndef CTS_USES_VULKANSC
                { STAGE_RAYGEN,         "rgen",         "raygen"        },
+#endif
        };
 
        TestGroupCase volCases[] =
@@ -2912,13 +3035,17 @@ static void createTests (tcu::TestCaseGroup* group, bool robustness2)
        TestGroupCase tempCases[] =
        {
                { 0,                    "notemplate",   ""              },
+#ifndef CTS_USES_VULKANSC
                { 1,                    "template",             ""              },
+#endif
        };
 
        TestGroupCase pushCases[] =
        {
                { 0,                    "bind",                 ""              },
+#ifndef CTS_USES_VULKANSC
                { 1,                    "push",                 ""              },
+#endif
        };
 
        TestGroupCase fmtQualCases[] =
@@ -3037,11 +3164,13 @@ static void createTests (tcu::TestCaseGroup* group, bool robustness2)
                                                                                                        Stage currentStage = static_cast<Stage>(stageCases[stageNdx].count);
                                                                                                        VkFlags allShaderStages = VK_SHADER_STAGE_COMPUTE_BIT | VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
                                                                                                        VkFlags allPipelineStages = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
+#ifndef CTS_USES_VULKANSC
                                                                                                        if ((Stage)stageCases[stageNdx].count == STAGE_RAYGEN)
                                                                                                        {
                                                                                                                allShaderStages |= VK_SHADER_STAGE_RAYGEN_BIT_NV;
                                                                                                                allPipelineStages |= VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_NV;
                                                                                                        }
+#endif // CTS_USES_VULKANSC
 
                                                                                                        if (descCases[descNdx].count == VERTEX_ATTRIBUTE_FETCH &&
                                                                                                                currentStage != STAGE_VERTEX)