From 9a626f2c8cf33897ed371ef321669efc574de142 Mon Sep 17 00:00:00 2001 From: Pyry Haulos Date: Thu, 4 Aug 2016 11:29:52 -0700 Subject: [PATCH] Disallow decoding ASTC sRGB formats in HDR mode sRGB is not supported in HDR mode --- framework/common/tcuAstcUtil.cpp | 7 ++++++ modules/internal/ditAstcTests.cpp | 45 ++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/framework/common/tcuAstcUtil.cpp b/framework/common/tcuAstcUtil.cpp index cf23073..03a2798 100644 --- a/framework/common/tcuAstcUtil.cpp +++ b/framework/common/tcuAstcUtil.cpp @@ -2923,6 +2923,10 @@ bool isValidBlock (const deUint8* data, CompressedTexFormat format, TexDecompres const tcu::IVec3 blockPixelSize = getBlockPixelSize(format); const bool isSRGB = isAstcSRGBFormat(format); const bool isLDR = isSRGB || mode == TexDecompressionParams::ASTCMODE_LDR; + + // sRGB is not supported in HDR mode + DE_ASSERT(!(mode == TexDecompressionParams::ASTCMODE_HDR && isSRGB)); + union { deUint8 sRGB[MAX_BLOCK_WIDTH*MAX_BLOCK_HEIGHT*4]; @@ -2948,6 +2952,9 @@ void decompress (const PixelBufferAccess& dst, const deUint8* data, CompressedTe DE_ASSERT(mode == TexDecompressionParams::ASTCMODE_LDR || mode == TexDecompressionParams::ASTCMODE_HDR); #endif + // sRGB is not supported in HDR mode + DE_ASSERT(!(mode == TexDecompressionParams::ASTCMODE_HDR && isSRGBFormat)); + decompress(dst, data, isSRGBFormat, isSRGBFormat || mode == TexDecompressionParams::ASTCMODE_LDR); } diff --git a/modules/internal/ditAstcTests.cpp b/modules/internal/ditAstcTests.cpp index 8ef101d..58d2a2b 100644 --- a/modules/internal/ditAstcTests.cpp +++ b/modules/internal/ditAstcTests.cpp @@ -65,24 +65,31 @@ AstcCase::AstcCase (tcu::TestContext& testCtx, CompressedTexFormat format) { } -void testDecompress (CompressedTexFormat format, size_t numBlocks, const deUint8* data) +void testDecompress (CompressedTexFormat format, TexDecompressionParams::AstcMode mode, size_t numBlocks, const deUint8* data) { - const IVec3 blockPixelSize = getBlockPixelSize(format); + const IVec3 blockPixelSize = getBlockPixelSize(format); + const TexDecompressionParams decompressionParams (mode); + const TextureFormat uncompressedFormat = getUncompressedFormat(format); + TextureLevel texture (uncompressedFormat, blockPixelSize.x()*(int)numBlocks, blockPixelSize.y()); - for (int astcModeNdx = 0; astcModeNdx < TexDecompressionParams::ASTCMODE_LAST; astcModeNdx++) - { - const TexDecompressionParams decompressionParams ((TexDecompressionParams::AstcMode)astcModeNdx); - const TextureFormat uncompressedFormat = getUncompressedFormat(format); - TextureLevel texture (uncompressedFormat, blockPixelSize.x()*(int)numBlocks, blockPixelSize.y()); + decompress(texture.getAccess(), format, data, decompressionParams); +} - decompress(texture.getAccess(), format, data, decompressionParams); - } +void testDecompress (CompressedTexFormat format, size_t numBlocks, const deUint8* data) +{ + testDecompress(format, TexDecompressionParams::ASTCMODE_LDR, numBlocks, data); + + if (!isAstcSRGBFormat(format)) + testDecompress(format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, data); } void verifyBlocksValid (CompressedTexFormat format, TexDecompressionParams::AstcMode mode, size_t numBlocks, const deUint8* data) { for (size_t blockNdx = 0; blockNdx < numBlocks; blockNdx++) - TCU_CHECK(astc::isValidBlock(data + blockNdx*astc::BLOCK_SIZE_BYTES, format, mode)); + { + if (!astc::isValidBlock(data + blockNdx*astc::BLOCK_SIZE_BYTES, format, mode)) + TCU_FAIL("Invalid ASTC block was generated"); + } } inline size_t getNumBlocksFromBytes (size_t numBytes) @@ -106,17 +113,18 @@ AstcCase::IterateResult AstcCase::iterate (void) generatedData.clear(); astc::generateBlockCaseTestData(generatedData, m_format, blockTestType); - testDecompress(m_format, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]); + // testDecompress(m_format, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]); // All but random case should generate only valid blocks if (blockTestType != astc::BLOCK_TEST_TYPE_RANDOM) { - verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]); - // \note CEMS generates HDR blocks as well if (!astc::isBlockTestTypeHDROnly(blockTestType) && (blockTestType != astc::BLOCK_TEST_TYPE_CEMS)) verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]); + + if (!isAstcSRGBFormat(m_format)) + verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]); } } @@ -130,7 +138,9 @@ AstcCase::IterateResult AstcCase::iterate (void) testDecompress(m_format, numBlocks, &generatedData[0]); verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, numBlocks, &generatedData[0]); - verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]); + + if (!isAstcSRGBFormat(m_format)) + verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]); } // Verify generating dummy normal blocks @@ -144,7 +154,9 @@ AstcCase::IterateResult AstcCase::iterate (void) testDecompress(m_format, numBlocks, &generatedData[0]); verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, numBlocks, &generatedData[0]); - verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]); + + if (!isAstcSRGBFormat(m_format)) + verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]); } // Verify generating random valid blocks @@ -153,6 +165,9 @@ AstcCase::IterateResult AstcCase::iterate (void) const TexDecompressionParams::AstcMode mode = (TexDecompressionParams::AstcMode)astcModeNdx; const size_t numBlocks = 1024; + if (mode == tcu::TexDecompressionParams::ASTCMODE_HDR && isAstcFormat(m_format)) + continue; // sRGB is not supported in HDR mode + generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES); astc::generateRandomValidBlocks(&generatedData[0], numBlocks, m_format, mode, deInt32Hash(m_format) ^ deInt32Hash(mode)); -- 2.7.4