Fix ASTC issues in pipeline image, image_view, and sampler tests
authorPyry Haulos <phaulos@google.com>
Thu, 21 Jan 2016 02:03:22 +0000 (18:03 -0800)
committerPyry Haulos <phaulos@google.com>
Thu, 21 Jan 2016 17:47:47 +0000 (09:47 -0800)
 * Use only valid ASTC blocks as result comparison doesn't currently
handle invalid blocks correctly.

 * Avoid normalizing non-sRGB ASTC blocks. Normalizing them based on
uncompressed format (F16) leads to complete lack of coverage.

Fixes #203

Change-Id: Ib5e7bedd07932ec1baa5cbd96cb66b357689bb75

external/vulkancts/modules/vulkan/pipeline/vktPipelineImageSamplingInstance.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineImageTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineImageUtil.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineImageUtil.hpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineImageViewTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineReferenceRenderer.hpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineSamplerTests.cpp

index 27a0762ffa7e0fce4ab2097c40efcef51496aa13..dbf142ea29a43388200432ad6cead937962388b2 100644 (file)
@@ -197,7 +197,22 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                 renderTarge
                                                                                  const VkImageSubresourceRange&        subresource)
 {
        MovePtr<Program>        program;
-       const VkImageType       imageType       = getCompatibleImageType(viewType);
+       const VkImageType       imageType               = getCompatibleImageType(viewType);
+       tcu::Vec4                       lookupScale             (1.0f);
+       tcu::Vec4                       lookupBias              (0.0f);
+
+       if (!testTexture.isCompressed())
+       {
+               const tcu::TextureFormatInfo    fmtInfo = tcu::getTextureFormatInfo(testTexture.getLevel(0, 0).getFormat());
+
+               // Needed to normalize various formats to 0..1 range for writing into RT
+               lookupScale     = fmtInfo.lookupScale;
+               lookupBias      = fmtInfo.lookupBias;
+       }
+       // else: All supported compressed formats are fine with no normalization.
+       //               ASTC LDR blocks decompress to f16 so querying normalization parameters
+       //               based on uncompressed formats would actually lead to massive precision loss
+       //               and complete lack of coverage in case of R8G8B8A8_UNORM RT.
 
        switch (imageType)
        {
@@ -205,7 +220,7 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                  renderTarge
                        if (layerCount == 1)
                        {
                                const tcu::Texture1D& texture = dynamic_cast<const TestTexture1D&>(testTexture).getTexture();
-                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture1D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture1D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                        }
                        else
                        {
@@ -219,11 +234,11 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                        renderTarge
 
                                        copySubresourceRange(textureView, texture, subresource);
 
-                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                }
                                else
                                {
-                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture1DArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                }
                        }
                        break;
@@ -232,7 +247,7 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                  renderTarge
                        if (layerCount == 1)
                        {
                                const tcu::Texture2D& texture = dynamic_cast<const TestTexture2D&>(testTexture).getTexture();
-                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                        }
                        else
                        {
@@ -241,7 +256,7 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                  renderTarge
                                        if (layerCount == tcu::CUBEFACE_LAST)
                                        {
                                                const tcu::TextureCube& texture = dynamic_cast<const TestTextureCube&>(testTexture).getTexture();
-                                               program = MovePtr<Program>(new SamplerProgram<tcu::TextureCube>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                                               program = MovePtr<Program>(new SamplerProgram<tcu::TextureCube>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                        }
                                        else
                                        {
@@ -259,12 +274,12 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                        renderTarge
 
                                                        copySubresourceRange(textureView, texture, subresource);
 
-                                                       program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+                                                       program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                                }
                                                else
                                                {
                                                        // Use all array layers
-                                                       program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                                                       program = MovePtr<Program>(new SamplerProgram<tcu::TextureCubeArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                                }
                                        }
                                }
@@ -282,12 +297,12 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                        renderTarge
 
                                                copySubresourceRange(textureView, texture, subresource);
 
-                                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+                                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                        }
                                        else
                                        {
                                                // Use all array layers
-                                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                                               program = MovePtr<Program>(new SamplerProgram<tcu::Texture2DArray>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                        }
                                }
                        }
@@ -305,11 +320,11 @@ static MovePtr<Program> createRefProgram(const tcu::TextureFormat&                        renderTarge
 
                                        copySubresourceRange(textureView, texture, subresource);
 
-                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, textureView, sampler, samplerLod, componentMapping));
+                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, textureView, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                }
                                else
                                {
-                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, texture, sampler, samplerLod, componentMapping));
+                                       program = MovePtr<Program>(new SamplerProgram<tcu::Texture3D>(renderTargetFormat, texture, sampler, samplerLod, lookupScale, lookupBias, componentMapping));
                                }
                        }
                        break;
index 58f1a7f5f9ac5bff71c34a62a4226733608cf05a..af592c58af9a490a0128872854728a05199349f6 100644 (file)
@@ -102,7 +102,13 @@ void ImageTest::initPrograms (SourceCollections& sourceCollections) const
        const char*                                             texCoordSwizzle = DE_NULL;
        const tcu::TextureFormat                format                  = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
                                                                                                                                                                                  : mapVkFormat(m_imageFormat);
-       const tcu::TextureFormatInfo    formatInfo              = tcu::getTextureFormatInfo(format);
+
+       // \note We don't want to perform normalization on any compressed formats.
+       //               In case of non-sRGB LDR ASTC it would lead to lack of coverage
+       //               as uncompressed format for that is f16 but values will be in range
+       //               0..1 already.
+       const tcu::TextureFormatInfo    formatInfo              = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+                                                                                                                                                                                 : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
 
        switch (m_imageViewType)
        {
index 623947222e3c57390db499118d6dd0028acea85a..b873a29e446399449c7d6e01f80e244c8b219fed 100644 (file)
@@ -39,6 +39,7 @@
 #include "vkQueryUtil.hpp"
 #include "vkRefUtil.hpp"
 #include "tcuTextureUtil.hpp"
+#include "tcuAstcUtil.hpp"
 #include "deRandom.hpp"
 
 namespace vkt
@@ -713,7 +714,7 @@ void TestTexture::populateLevels (const std::vector<tcu::PixelBufferAccess>& lev
                TestTexture::fillWithGradient(levels[levelNdx]);
 }
 
-void TestTexture::populateCompressedLevels (const tcu::CompressedTexFormat& format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels)
+void TestTexture::populateCompressedLevels (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels)
 {
        // Generate random compressed data and update decompressed data
 
@@ -725,14 +726,23 @@ void TestTexture::populateCompressedLevels (const tcu::CompressedTexFormat& form
                tcu::CompressedTexture*                 compressedLevel         = new tcu::CompressedTexture(format, level.getWidth(), level.getHeight(), level.getDepth());
                deUint8* const                                  compressedData          = (deUint8*)compressedLevel->getData();
 
-               // Generate random compressed data
-               for (int byteNdx = 0; byteNdx < compressedLevel->getDataSize(); byteNdx++)
-                       compressedData[byteNdx] = 0xFF & random.getUint32();
+               if (tcu::isAstcFormat(format))
+               {
+                       // \todo [2016-01-20 pyry] Comparison doesn't currently handle invalid blocks correctly so we use only valid blocks
+                       tcu::astc::generateRandomValidBlocks(compressedData, compressedLevel->getDataSize()/tcu::astc::BLOCK_SIZE_BYTES,
+                                                                                                format, tcu::TexDecompressionParams::ASTCMODE_LDR, random.getUint32());
+               }
+               else
+               {
+                       // Generate random compressed data
+                       for (int byteNdx = 0; byteNdx < compressedLevel->getDataSize(); byteNdx++)
+                               compressedData[byteNdx] = 0xFF & random.getUint32();
+               }
 
                m_compressedLevels.push_back(compressedLevel);
 
                // Store decompressed data
-               compressedLevel->decompress(level, tcu::TexDecompressionParams::ASTCMODE_LDR);
+               compressedLevel->decompress(level, tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR));
        }
 }
 
index e40d4c582bd60a957aaf0aa3ae5915232cd7fc4f..3c2c24d68afa23720955ff5ff14a35a2c2b7cc9a 100644 (file)
@@ -121,7 +121,7 @@ public:
 
 protected:
        void                                                                            populateLevels                          (const std::vector<tcu::PixelBufferAccess>& levels);
-       void                                                                            populateCompressedLevels        (const tcu::CompressedTexFormat& format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
+       void                                                                            populateCompressedLevels        (tcu::CompressedTexFormat format, const std::vector<tcu::PixelBufferAccess>& decompressedLevels);
 
        static void                                                                     fillWithGradient                        (const tcu::PixelBufferAccess& levelAccess);
 
index 8546796e2af22530e7a788dca6fd8ef967abcff5..da35e7821c236512966935c2aca7a33264de403c 100644 (file)
@@ -137,7 +137,13 @@ void ImageViewTest::initPrograms (SourceCollections& sourceCollections) const
        const char*                                             texCoordSwizzle = DE_NULL;
        const tcu::TextureFormat                format                  = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
                                                                                                                                                                                  : mapVkFormat(m_imageFormat);
-       const tcu::TextureFormatInfo    formatInfo              = tcu::getTextureFormatInfo(format);
+
+       // \note We don't want to perform normalization on any compressed formats.
+       //               In case of non-sRGB LDR ASTC it would lead to lack of coverage
+       //               as uncompressed format for that is f16 but values will be in range
+       //               0..1 already.
+       const tcu::TextureFormatInfo    formatInfo              = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+                                                                                                                                                                                 : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
 
        tcu::Vec4                                               swizzledScale   = swizzle(formatInfo.lookupScale, m_componentMapping);
        tcu::Vec4                                               swizzledBias    = swizzle(formatInfo.lookupBias, m_componentMapping);
index 2b2a94e2c76d1ad4c58d741d94e43fed442c350a..3de3cf18838993a86f52599084b518f80750c839 100644 (file)
@@ -180,20 +180,22 @@ private:
        const tcu::TextureFormat                m_colorFormat;
        const tcu::TextureFormatInfo    m_colorFormatInfo;
        const TextureType                               m_texture;
-       const tcu::TextureFormatInfo    m_textureFormatInfo;
        const tcu::Sampler                              m_sampler;
        const float                                             m_lod;
+       const tcu::Vec4                                 m_lookupScale;
+       const tcu::Vec4                                 m_lookupBias;
        const tcu::UVec4                                m_swizzle;
 
 public:
-       SamplerFragmentShader (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::UVec4& swizzle)
+       SamplerFragmentShader (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::Vec4& lookupScale, const tcu::Vec4& lookupBias, const tcu::UVec4& swizzle)
                : rr::FragmentShader    (2, 1)
                , m_colorFormat                 (colorFormat)
                , m_colorFormatInfo             (tcu::getTextureFormatInfo(m_colorFormat))
                , m_texture                             (texture)
-               , m_textureFormatInfo   (tcu::getTextureFormatInfo(m_texture.getFormat()))
                , m_sampler                             (sampler)
                , m_lod                                 (lod)
+               , m_lookupScale                 (lookupScale)
+               , m_lookupBias                  (lookupBias)
                , m_swizzle                             (swizzle)
        {
                const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(m_colorFormat.type);
@@ -255,9 +257,9 @@ public:
                        {
                                const tcu::Vec4 vtxTexCoord     = rr::readVarying<float>(packet, context, 1, fragNdx);
                                const tcu::Vec4 texColor        = sampleTexture(m_texture, m_sampler, vtxTexCoord, m_lod);
-                               const tcu::Vec4 swizColor       = swizzle(texColor, m_swizzle);
-                               const tcu::Vec4 normColor       = swizColor * swizzle(m_textureFormatInfo.lookupScale, m_swizzle) + swizzle(m_textureFormatInfo.lookupBias, m_swizzle);
-                               const tcu::Vec4 color           = (normColor - m_colorFormatInfo.lookupBias) / m_colorFormatInfo.lookupScale;
+                               const tcu::Vec4 normColor       = texColor * m_lookupScale + m_lookupBias;
+                               const tcu::Vec4 swizColor       = swizzle(normColor, m_swizzle);
+                               const tcu::Vec4 color           = (swizColor + m_colorFormatInfo.lookupBias) / m_colorFormatInfo.lookupScale;
                                rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
                        }
                }
@@ -279,9 +281,9 @@ private:
        TexCoordVertexShader                            m_vertexShader;
        SamplerFragmentShader<TextureType>      m_fragmentShader;
 public:
-       SamplerProgram (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::UVec4& swizzle)
+       SamplerProgram (const tcu::TextureFormat& colorFormat, const TextureType& texture, const tcu::Sampler& sampler, float lod, const tcu::Vec4& lookupScale, const tcu::Vec4& lookupBias, const tcu::UVec4& swizzle)
                : m_vertexShader        ()
-               , m_fragmentShader      (colorFormat, texture, sampler, lod, swizzle)
+               , m_fragmentShader      (colorFormat, texture, sampler, lod, lookupScale, lookupBias, swizzle)
        {
        }
 
index f00844e582e4f57ed58d2f4eded992b47c088bff..9a0aa142ec2bc9c0eb94ff7e20efcd14fc2943d2 100644 (file)
@@ -195,7 +195,13 @@ void SamplerTest::initPrograms (SourceCollections& sourceCollections) const
        const char*                                             texCoordSwizzle = DE_NULL;
        tcu::TextureFormat                              format                  = (isCompressedFormat(m_imageFormat)) ? tcu::getUncompressedFormat(mapVkCompressedFormat(m_imageFormat))
                                                                                                                                                                                  : mapVkFormat(m_imageFormat);
-       const tcu::TextureFormatInfo    formatInfo              = tcu::getTextureFormatInfo(format);
+
+       // \note We don't want to perform normalization on any compressed formats.
+       //               In case of non-sRGB LDR ASTC it would lead to lack of coverage
+       //               as uncompressed format for that is f16 but values will be in range
+       //               0..1 already.
+       const tcu::TextureFormatInfo    formatInfo              = (!isCompressedFormat(m_imageFormat) ? tcu::getTextureFormatInfo(format)
+                                                                                                                                                                                 : tcu::getTextureFormatInfo(tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8)));
 
        switch (m_imageViewType)
        {