Merge vk-gl-cts/vulkan-cts-1.0.2 into vk-gl-cts/master
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiImageClearingTests.cpp
index f69600b..3eeabd2 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "deRandom.hpp"
 #include "deMath.h"
+#include "deSTLUtil.hpp"
 #include "deStringUtil.hpp"
 #include "deUniquePtr.hpp"
 #include "deArrayUtil.hpp"
@@ -34,6 +35,7 @@
 #include "vkMemUtil.hpp"
 #include "vktTestCase.hpp"
 #include "vktTestCaseUtil.hpp"
+#include "vktTestGroupUtil.hpp"
 #include "vkQueryUtil.hpp"
 #include "vkRefUtil.hpp"
 #include "vkTypeUtil.hpp"
@@ -60,6 +62,74 @@ using namespace tcu;
 namespace
 {
 
+enum AllocationKind
+{
+       ALLOCATION_KIND_SUBALLOCATED = 0,
+       ALLOCATION_KIND_DEDICATED,
+
+       ALLOCATION_KIND_LAST,
+};
+
+de::MovePtr<Allocation> allocateBuffer (const InstanceInterface&       vki,
+                                                                               const DeviceInterface&          vkd,
+                                                                               const VkPhysicalDevice&         physDevice,
+                                                                               const VkDevice                          device,
+                                                                               const VkBuffer&                         buffer,
+                                                                               const MemoryRequirement         requirement,
+                                                                               Allocator&                                      allocator,
+                                                                               AllocationKind                          allocationKind)
+{
+       switch (allocationKind)
+       {
+               case ALLOCATION_KIND_SUBALLOCATED:
+               {
+                       const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
+
+                       return allocator.allocate(memoryRequirements, requirement);
+               }
+
+               case ALLOCATION_KIND_DEDICATED:
+               {
+                       return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
+               }
+
+               default:
+               {
+                       TCU_THROW(InternalError, "Invalid allocation kind");
+               }
+       }
+}
+
+de::MovePtr<Allocation> allocateImage (const InstanceInterface&                vki,
+                                                                          const DeviceInterface&               vkd,
+                                                                          const VkPhysicalDevice&              physDevice,
+                                                                          const VkDevice                               device,
+                                                                          const VkImage&                               image,
+                                                                          const MemoryRequirement              requirement,
+                                                                          Allocator&                                   allocator,
+                                                                          AllocationKind                               allocationKind)
+{
+       switch (allocationKind)
+       {
+               case ALLOCATION_KIND_SUBALLOCATED:
+               {
+                       const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
+
+                       return allocator.allocate(memoryRequirements, requirement);
+               }
+
+               case ALLOCATION_KIND_DEDICATED:
+               {
+                       return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
+               }
+
+               default:
+               {
+                       TCU_THROW(InternalError, "Invalid allocation kind");
+               }
+       }
+}
+
 VkExtent3D getMipLevelExtent (VkExtent3D baseExtent, const deUint32 mipLevel)
 {
        baseExtent.width        = std::max(baseExtent.width  >> mipLevel, 1u);
@@ -81,7 +151,7 @@ deUint32 greatestCommonDivisor (const deUint32 a, const deUint32 b)
        deUint32 x=a;
        deUint32 y=b;
 
-       while (x%b != 0)
+       while (x%y != 0)
        {
                temp = y;
                y = x%y;
@@ -121,9 +191,10 @@ inline bool isInClearRange (const UVec4& clearCoords, const deUint32 x, const de
        {
                // Only layers in range passed to clear command are cleared
 
-               const deUint32 clearBaseLayer = (imageViewLayerRange ? imageViewLayerRange->baseArrayLayer : 0) + attachmentClearLayerRange->baseArrayLayer;
+               const deUint32  clearBaseLayer  = (imageViewLayerRange ? imageViewLayerRange->baseArrayLayer : 0) + attachmentClearLayerRange->baseArrayLayer;
+               const deUint32  clearLayerCount = (attachmentClearLayerRange->layerCount == VK_REMAINING_ARRAY_LAYERS) ? imageViewLayerRange->layerCount : clearBaseLayer + attachmentClearLayerRange->layerCount;
 
-               if ((arrayLayer < clearBaseLayer) || (arrayLayer >= (clearBaseLayer + attachmentClearLayerRange->layerCount)))
+               if ((arrayLayer < clearBaseLayer) || (arrayLayer >= (clearLayerCount)))
                {
                        return false;
                }
@@ -396,6 +467,7 @@ struct TestParams
        VkClearValue    initValue;
        VkClearValue    clearValue[2];          //!< the second value is used with more than one mip map
        LayerRange              clearLayerRange;
+       AllocationKind  allocationKind;
 };
 
 class ImageClearingTestInstance : public vkt::TestInstance
@@ -494,6 +566,13 @@ ImageClearingTestInstance::ImageClearingTestInstance (Context& context, const Te
        , m_renderPass                          (m_isAttachmentFormat ? createRenderPass(params.imageFormat) : vk::Move<vk::VkRenderPass>())
        , m_frameBuffer                         (m_isAttachmentFormat ? createFrameBuffer(*m_imageView, *m_renderPass, params.imageExtent.width, params.imageExtent.height, params.imageViewLayerRange.layerCount) : vk::Move<vk::VkFramebuffer>())
 {
+       if (m_params.allocationKind == ALLOCATION_KIND_DEDICATED)
+       {
+               const std::string extensionName("VK_KHR_dedicated_allocation");
+
+               if (!de::contains(context.getDeviceExtensions().begin(), context.getDeviceExtensions().end(), extensionName))
+                       TCU_THROW(NotSupportedError, std::string(extensionName + " is not supported").c_str());
+       }
 }
 
 VkImageViewType ImageClearingTestInstance::getCorrespondingImageViewType (VkImageType imageType, ViewType viewType) const
@@ -588,7 +667,7 @@ VkImageFormatProperties ImageClearingTestInstance::getImageFormatProperties (voi
 
 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindImageMemory (VkImage image) const
 {
-       de::MovePtr<Allocation> imageMemory     (m_allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, image), MemoryRequirement::Any));
+       de::MovePtr<Allocation> imageMemory     (allocateImage(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, image, MemoryRequirement::Any, m_allocator, m_params.allocationKind));
        VK_CHECK(m_vkd.bindImageMemory(m_device, image, imageMemory->getMemory(), imageMemory->getOffset()));
        return imageMemory;
 }
@@ -857,7 +936,7 @@ de::MovePtr<TextureLevelPyramid> ImageClearingTestInstance::readImage (VkImageAs
                };
 
                buffer          = createBuffer(m_vkd, m_device, &bufferParams);
-               bufferAlloc     = m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible);
+               bufferAlloc     = allocateBuffer(m_vki, m_vkd, m_context.getPhysicalDevice(), m_device, *buffer, MemoryRequirement::HostVisible, m_allocator, m_params.allocationKind);
                VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
        }
 
@@ -1345,13 +1424,8 @@ const char* getImageTypeCaseName (VkImageType type)
        return de::getSizedArrayElement<VK_IMAGE_TYPE_LAST>(s_names, type);
 }
 
-} // anonymous
-
-TestCaseGroup* createImageClearingTests (TestContext& testCtx)
+TestCaseGroup* createImageClearingTestsCommon (TestContext& testCtx, tcu::TestCaseGroup* imageClearingTests, AllocationKind allocationKind)
 {
-       // Main testgroup.
-       de::MovePtr<TestCaseGroup>      imageClearingTests                                              (new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
-
        de::MovePtr<TestCaseGroup>      colorImageClearTests                                    (new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
        de::MovePtr<TestCaseGroup>      depthStencilImageClearTests                             (new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
        de::MovePtr<TestCaseGroup>      colorAttachmentClearTests                               (new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
@@ -1564,21 +1638,31 @@ TestCaseGroup* createImageClearingTests (TestContext& testCtx)
        const ImageLayerParams imageLayerParamsToTest[] =
        {
                {
-                       1u,                                     // imageLayerCount
-                       {0u, 1u},                       // imageViewRange
-                       {0u, 1u},                       // clearLayerRange
-                       DE_NULL                         // testName
+                       1u,                                                                     // imageLayerCount
+                       {0u, 1u},                                                       // imageViewRange
+                       {0u, 1u},                                                       // clearLayerRange
+                       "single_layer"                                          // testName
                },
                {
-                       16u,                            // imageLayerCount
-                       {3u, 12u},                      // imageViewRange
-                       {2u, 5u},                       // clearLayerRange
-                       "multiple_layers"       // testName
+                       16u,                                                            // imageLayerCount
+                       {3u, 12u},                                                      // imageViewRange
+                       {2u, 5u},                                                       // clearLayerRange
+                       "multiple_layers"                                       // testName
                },
+               {
+                       16u,                                                            // imageLayerCount
+                       { 3u, 12u },                                            // imageViewRange
+                       { 8u, VK_REMAINING_ARRAY_LAYERS },      // clearLayerRange
+                       "remaining_array_layers"                        // testName
+               }
        };
 
+       // Include test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearColorImage
        const size_t    numOfImageLayerParamsToTest                             = DE_LENGTH_OF_ARRAY(imageLayerParamsToTest);
 
+       // Exclude test cases with VK_REMAINING_ARRAY_LAYERS when using vkCmdClearAttachments
+       const size_t    numOfAttachmentLayerParamsToTest                = numOfImageLayerParamsToTest - 1;
+
        // Clear color image
        {
                const VkImageType                       imageTypesToTest[]              =
@@ -1597,152 +1681,185 @@ TestCaseGroup* createImageClearingTests (TestContext& testCtx)
                };
 
                for (size_t     imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
-               for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
-               for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
                {
+                       de::MovePtr<TestCaseGroup> imageTypeGroup(new TestCaseGroup(testCtx, getImageTypeCaseName(imageTypesToTest[imageTypeIndex]), ""));
 
-                       if (imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount > 1u && imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D)
+                       for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
                        {
                                // 3D ARRAY images are not supported
-                               continue;
-                       }
-
-                       const VkFormat          format          = colorImageFormatsToTest[imageFormatIndex];
-                       const TestParams        testParams      =
-                       {
-                               false,                                                                                                                          // bool                         useSingleMipLevel;
-                               imageTypesToTest[imageTypeIndex],                                                                       // VkImageType          imageType;
-                               format,                                                                                                                         // VkFormat                     imageFormat;
-                               imageDimensionsByType[imageTypeIndex],                                                          // VkExtent3D           imageExtent;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,          // deUint32         imageLayerCount;
-                               {
-                                       0u,
-                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
-                               },                                                                                                                                      // LayerRange           imageViewLayerRange;
-                               makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),                            // VkClearValue         initValue;
-                               {
-                                       makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),                            // VkClearValue         clearValue[0];
-                                       makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),                            // VkClearValue         clearValue[1];
-                               },
-                               imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,          // LayerRange       clearLayerRange;
-                       };
+                               if (imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount > 1u && imageTypesToTest[imageTypeIndex] == VK_IMAGE_TYPE_3D)
+                                       continue;
 
-                       std::ostringstream      testCaseName;
-                       testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
-                       if (imageLayerParamsToTest[imageLayerParamsIndex].testName != DE_NULL)
-                               testCaseName << "_" << imageLayerParamsToTest[imageLayerParamsIndex].testName;
+                               de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
 
-                       colorImageClearTests->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Image", testParams));
+                               for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
+                               {
+                                       const VkFormat          format                  = colorImageFormatsToTest[imageFormatIndex];
+                                       const std::string       testCaseName    = getFormatCaseName(format);
+                                       const TestParams        testParams              =
+                                       {
+                                               false,                                                                                                                          // bool                         useSingleMipLevel;
+                                               imageTypesToTest[imageTypeIndex],                                                                       // VkImageType          imageType;
+                                               format,                                                                                                                         // VkFormat                     imageFormat;
+                                               imageDimensionsByType[imageTypeIndex],                                                          // VkExtent3D           imageExtent;
+                                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,          // deUint32         imageLayerCount;
+                                               {
+                                                       0u,
+                                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
+                                               },                                                                                                                                      // LayerRange           imageViewLayerRange;
+                                               makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),                            // VkClearValue         initValue;
+                                               {
+                                                       makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),                            // VkClearValue         clearValue[0];
+                                                       makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),                            // VkClearValue         clearValue[1];
+                                               },
+                                               imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,          // LayerRange       clearLayerRange;
+                                               allocationKind                                                                                                          // AllocationKind       allocationKind;
+                                       };
+
+                                       imageLayersGroup->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Image", testParams));
+                               }
+                               imageTypeGroup->addChild(imageLayersGroup.release());
+                       }
+                       colorImageClearTests->addChild(imageTypeGroup.release());
                }
-
                imageClearingTests->addChild(colorImageClearTests.release());
        }
 
        // Clear depth/stencil image
        {
-               for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
                for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
                {
-                       const TestParams testParams =
+                       de::MovePtr<TestCaseGroup> imageLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
+
+                       for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
                        {
-                               true,                                                                                                                           // bool                         useSingleMipLevel;
-                               VK_IMAGE_TYPE_2D,                                                                                                       // VkImageType          imageType;
-                               depthStencilImageFormatsToTest[imageFormatIndex],                                       // VkFormat                     format;
-                               { 256, 256, 1 },                                                                                                        // VkExtent3D           extent;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,          // deUint32         imageLayerCount;
+                               const VkFormat          format                  = depthStencilImageFormatsToTest[imageFormatIndex];
+                               const std::string       testCaseName    = getFormatCaseName(format);
+                               const TestParams        testParams              =
                                {
-                                       0u,
-                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
-                               },                                                                                                                                      // LayerRange           imageViewLayerRange;
-                               makeClearValueDepthStencil(0.5f, 0x03),                                                         // VkClearValue         initValue
-                               {
-                                       makeClearValueDepthStencil(0.1f, 0x06),                                                         // VkClearValue         clearValue[0];
-                                       makeClearValueDepthStencil(0.3f, 0x04),                                                         // VkClearValue         clearValue[1];
-                               },
-                               imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,          // LayerRange       clearLayerRange;
-                       };
-
-                       std::ostringstream      testCaseName;
-                       testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
-                       if (imageLayerParamsToTest[imageLayerParamsIndex].testName != DE_NULL)
-                               testCaseName << "_" << imageLayerParamsToTest[imageLayerParamsIndex].testName;
-
-                       depthStencilImageClearTests->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Image", testParams));
+                                       true,                                                                                                                           // bool                         useSingleMipLevel;
+                                       VK_IMAGE_TYPE_2D,                                                                                                       // VkImageType          imageType;
+                                       format,                                                                                                                         // VkFormat                     format;
+                                       { 256, 256, 1 },                                                                                                        // VkExtent3D           extent;
+                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,          // deUint32         imageLayerCount;
+                                       {
+                                               0u,
+                                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount
+                                       },                                                                                                                                      // LayerRange           imageViewLayerRange;
+                                       makeClearValueDepthStencil(0.5f, 0x03),                                                         // VkClearValue         initValue
+                                       {
+                                               makeClearValueDepthStencil(0.1f, 0x06),                                                         // VkClearValue         clearValue[0];
+                                               makeClearValueDepthStencil(0.3f, 0x04),                                                         // VkClearValue         clearValue[1];
+                                       },
+                                       imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,          // LayerRange       clearLayerRange;
+                                       allocationKind                                                                                                          // AllocationKind       allocationKind;
+                               };
+
+                               imageLayersGroup->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Image", testParams));
+                       }
+                       depthStencilImageClearTests->addChild(imageLayersGroup.release());
                }
-
                imageClearingTests->addChild(depthStencilImageClearTests.release());
        }
 
        // Clear color attachment
        {
-               for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
-               for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
+               for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
                {
-                       const VkFormat          format          = colorImageFormatsToTest[imageFormatIndex];
+                       de::MovePtr<TestCaseGroup> colorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
+                       de::MovePtr<TestCaseGroup> partialColorAttachmentClearLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
 
-                       const TestParams        testParams =
+                       for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
                        {
-                               true,                                                                                                                   // bool                         useSingleMipLevel;
-                               VK_IMAGE_TYPE_2D,                                                                                               // VkImageType          imageType;
-                               format,                                                                                                                 // VkFormat                     format;
-                               { 256, 256, 1 },                                                                                                // VkExtent3D           extent;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,  // deUint32         imageLayerCount;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,   // LayerRange           imageViewLayerRange;
-                               makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),                    // VkClearValue         initValue
+                               const VkFormat          format                  = colorImageFormatsToTest[imageFormatIndex];
+                               const std::string       testCaseName    = getFormatCaseName(format);
+                               const TestParams        testParams              =
                                {
-                                       makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),                    // VkClearValue         clearValue[0];
-                                       makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),                    // VkClearValue         clearValue[1];
-                               },
-                               imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,  // LayerRange       clearLayerRange;
-                       };
-
-                       std::ostringstream      testCaseName;
-                       testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
-                       if (imageLayerParamsToTest[imageLayerParamsIndex].testName != DE_NULL)
-                               testCaseName << "_" << imageLayerParamsToTest[imageLayerParamsIndex].testName;
-
-                       colorAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Attachment", testParams));
-                       partialColorAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Partial Clear Color Attachment", testParams));
+                                       true,                                                                                                                   // bool                         useSingleMipLevel;
+                                       VK_IMAGE_TYPE_2D,                                                                                               // VkImageType          imageType;
+                                       format,                                                                                                                 // VkFormat                     format;
+                                       { 256, 256, 1 },                                                                                                // VkExtent3D           extent;
+                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,  // deUint32         imageLayerCount;
+                                       imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,   // LayerRange           imageViewLayerRange;
+                                       makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),                    // VkClearValue         initValue
+                                       {
+                                               makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),                    // VkClearValue         clearValue[0];
+                                               makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),                    // VkClearValue         clearValue[1];
+                                       },
+                                       imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,  // LayerRange       clearLayerRange;
+                                       allocationKind                                                                                                  // AllocationKind       allocationKind;
+                               };
+
+                               colorAttachmentClearLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Color Attachment", testParams));
+                               partialColorAttachmentClearLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Partial Clear Color Attachment", testParams));
+                       }
+                       colorAttachmentClearTests->addChild(colorAttachmentClearLayersGroup.release());
+                       partialColorAttachmentClearTests->addChild(partialColorAttachmentClearLayersGroup.release());
                }
-
                imageClearingTests->addChild(colorAttachmentClearTests.release());
                imageClearingTests->addChild(partialColorAttachmentClearTests.release());
        }
 
        // Clear depth/stencil attachment
        {
-               for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
-               for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfImageLayerParamsToTest; ++imageLayerParamsIndex)
+               for (size_t imageLayerParamsIndex = 0; imageLayerParamsIndex < numOfAttachmentLayerParamsToTest; ++imageLayerParamsIndex)
                {
-                       const TestParams testParams =
+                       de::MovePtr<TestCaseGroup> depthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
+                       de::MovePtr<TestCaseGroup> partialDepthStencilLayersGroup(new TestCaseGroup(testCtx, imageLayerParamsToTest[imageLayerParamsIndex].testName, ""));
+
+                       for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
                        {
-                               true,                                                                                                                   // bool                         useSingleMipLevel;
-                               VK_IMAGE_TYPE_2D,                                                                                               // VkImageType          imageType;
-                               depthStencilImageFormatsToTest[imageFormatIndex],                               // VkFormat                     format;
-                               { 256, 256, 1 },                                                                                                // VkExtent3D           extent;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,  // deUint32         imageLayerCount;
-                               imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,   // LayerRange           imageViewLayerRange;
-                               makeClearValueDepthStencil(0.5f, 0x03),                                                 // VkClearValue         initValue
+                               const VkFormat          format                  = depthStencilImageFormatsToTest[imageFormatIndex];
+                               const std::string       testCaseName    = getFormatCaseName(format);
+                               const TestParams        testParams              =
                                {
-                                       makeClearValueDepthStencil(0.1f, 0x06),                                                 // VkClearValue         clearValue[0];
-                                       makeClearValueDepthStencil(0.3f, 0x04),                                                 // VkClearValue         clearValue[1];
-                               },
-                               imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,  // LayerRange       clearLayerRange;
-                       };
-
-                       std::ostringstream      testCaseName;
-                       testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
-                       if (imageLayerParamsToTest[imageLayerParamsIndex].testName != DE_NULL)
-                               testCaseName << "_" << imageLayerParamsToTest[imageLayerParamsIndex].testName;
-
-                       depthStencilAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Attachment", testParams));
-                       partialDepthStencilAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Parital Clear Depth/Stencil Attachment", testParams));
+                                       true,                                                                                                                   // bool                         useSingleMipLevel;
+                                       VK_IMAGE_TYPE_2D,                                                                                               // VkImageType          imageType;
+                                       format,                                                                                                                 // VkFormat                     format;
+                                       { 256, 256, 1 },                                                                                                // VkExtent3D           extent;
+                                       imageLayerParamsToTest[imageLayerParamsIndex].imageLayerCount,  // deUint32         imageLayerCount;
+                                       imageLayerParamsToTest[imageLayerParamsIndex].imageViewRange,   // LayerRange           imageViewLayerRange;
+                                       makeClearValueDepthStencil(0.5f, 0x03),                                                 // VkClearValue         initValue
+                                       {
+                                               makeClearValueDepthStencil(0.1f, 0x06),                                                 // VkClearValue         clearValue[0];
+                                               makeClearValueDepthStencil(0.3f, 0x04),                                                 // VkClearValue         clearValue[1];
+                                       },
+                                       imageLayerParamsToTest[imageLayerParamsIndex].clearLayerRange,  // LayerRange       clearLayerRange;
+                                       allocationKind                                                                                                  // AllocationKind       allocationKind;
+                               };
+
+                               depthStencilLayersGroup->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Clear Depth/Stencil Attachment", testParams));
+                               partialDepthStencilLayersGroup->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName, "Parital Clear Depth/Stencil Attachment", testParams));
+                       }
+                       depthStencilAttachmentClearTests->addChild(depthStencilLayersGroup.release());
+                       partialDepthStencilAttachmentClearTests->addChild(partialDepthStencilLayersGroup.release());
                }
-
                imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
                imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
        }
 
+       return imageClearingTests;
+}
+
+void createCoreImageClearingTests (tcu::TestCaseGroup* group)
+{
+       createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_SUBALLOCATED);
+}
+
+void createDedicatedAllocationImageClearingTests (tcu::TestCaseGroup* group)
+{
+       createImageClearingTestsCommon(group->getTestContext(), group, ALLOCATION_KIND_DEDICATED);
+}
+
+} // anonymous
+
+TestCaseGroup* createImageClearingTests (TestContext& testCtx)
+{
+       de::MovePtr<TestCaseGroup>      imageClearingTests      (new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
+
+       imageClearingTests->addChild(createTestGroup(testCtx, "core",                                   "Core Image Clearing Tests",                                                    createCoreImageClearingTests));
+       imageClearingTests->addChild(createTestGroup(testCtx, "dedicated_allocation",   "Image Clearing Tests For Dedicated Memory Allocation", createDedicatedAllocationImageClearingTests));
+
        return imageClearingTests.release();
 }