1 /*-------------------------------------------------------------------------
2 * drawElements Internal Test Module
3 * ---------------------------------
5 * Copyright 2016 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 *//*--------------------------------------------------------------------*/
24 #include "ditAstcTests.hpp"
26 #include "tcuCompressedTexture.hpp"
27 #include "tcuAstcUtil.hpp"
29 #include "deUniquePtr.hpp"
30 #include "deStringUtil.hpp"
42 class AstcCase : public tcu::TestCase
45 AstcCase (tcu::TestContext& testCtx, CompressedTexFormat format);
47 IterateResult iterate (void);
50 const CompressedTexFormat m_format;
53 static const string getASTCFormatShortName (CompressedTexFormat format)
55 DE_ASSERT(isAstcFormat(format));
56 const IVec3 blockSize = getBlockPixelSize(format);
57 DE_ASSERT(blockSize.z() == 1);
59 return de::toString(blockSize.x()) + "x" + de::toString(blockSize.y()) + (tcu::isAstcSRGBFormat(format) ? "_srgb" : "");
62 AstcCase::AstcCase (tcu::TestContext& testCtx, CompressedTexFormat format)
63 : tcu::TestCase (testCtx, getASTCFormatShortName(format).c_str(), "")
68 void testDecompress (CompressedTexFormat format, size_t numBlocks, const deUint8* data)
70 const IVec3 blockPixelSize = getBlockPixelSize(format);
72 for (int astcModeNdx = 0; astcModeNdx < TexDecompressionParams::ASTCMODE_LAST; astcModeNdx++)
74 const TexDecompressionParams decompressionParams ((TexDecompressionParams::AstcMode)astcModeNdx);
75 const TextureFormat uncompressedFormat = getUncompressedFormat(format);
76 TextureLevel texture (uncompressedFormat, blockPixelSize.x()*(int)numBlocks, blockPixelSize.y());
78 decompress(texture.getAccess(), format, data, decompressionParams);
82 void verifyBlocksValid (CompressedTexFormat format, TexDecompressionParams::AstcMode mode, size_t numBlocks, const deUint8* data)
84 for (size_t blockNdx = 0; blockNdx < numBlocks; blockNdx++)
85 TCU_CHECK(astc::isValidBlock(data + blockNdx*astc::BLOCK_SIZE_BYTES, format, mode));
88 inline size_t getNumBlocksFromBytes (size_t numBytes)
90 TCU_CHECK(numBytes % astc::BLOCK_SIZE_BYTES == 0);
91 return (numBytes / astc::BLOCK_SIZE_BYTES);
94 AstcCase::IterateResult AstcCase::iterate (void)
96 vector<deUint8> generatedData;
98 // Verify that can generate & decode data with all BlockTestType's
99 for (int blockTestTypeNdx = 0; blockTestTypeNdx < astc::BLOCK_TEST_TYPE_LAST; blockTestTypeNdx++)
101 const astc::BlockTestType blockTestType = (const astc::BlockTestType)blockTestTypeNdx;
103 if (astc::isBlockTestTypeHDROnly(blockTestType) && isAstcSRGBFormat(m_format))
106 generatedData.clear();
107 astc::generateBlockCaseTestData(generatedData, m_format, blockTestType);
109 testDecompress(m_format, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);
111 // All but random case should generate only valid blocks
112 if (blockTestType != astc::BLOCK_TEST_TYPE_RANDOM)
114 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);
116 // \note CEMS generates HDR blocks as well
117 if (!astc::isBlockTestTypeHDROnly(blockTestType) &&
118 (blockTestType != astc::BLOCK_TEST_TYPE_CEMS))
119 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, getNumBlocksFromBytes(generatedData.size()), &generatedData[0]);
123 // Verify generating void extent blocks (format-independent)
125 const size_t numBlocks = 1024;
127 generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES);
128 astc::generateDummyVoidExtentBlocks(&generatedData[0], numBlocks);
130 testDecompress(m_format, numBlocks, &generatedData[0]);
132 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, numBlocks, &generatedData[0]);
133 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]);
136 // Verify generating dummy normal blocks
138 const size_t numBlocks = 1024;
139 const IVec3 blockPixelSize = getBlockPixelSize(m_format);
141 generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES);
142 astc::generateDummyNormalBlocks(&generatedData[0], numBlocks, blockPixelSize.x(), blockPixelSize.y());
144 testDecompress(m_format, numBlocks, &generatedData[0]);
146 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_LDR, numBlocks, &generatedData[0]);
147 verifyBlocksValid(m_format, TexDecompressionParams::ASTCMODE_HDR, numBlocks, &generatedData[0]);
150 // Verify generating random valid blocks
151 for (int astcModeNdx = 0; astcModeNdx < TexDecompressionParams::ASTCMODE_LAST; astcModeNdx++)
153 const TexDecompressionParams::AstcMode mode = (TexDecompressionParams::AstcMode)astcModeNdx;
154 const size_t numBlocks = 1024;
156 generatedData.resize(numBlocks*astc::BLOCK_SIZE_BYTES);
157 astc::generateRandomValidBlocks(&generatedData[0], numBlocks, m_format, mode, deInt32Hash(m_format) ^ deInt32Hash(mode));
159 testDecompress(m_format, numBlocks, &generatedData[0]);
161 verifyBlocksValid(m_format, mode, numBlocks, &generatedData[0]);
164 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "All checks passed");
170 tcu::TestCaseGroup* createAstcTests (tcu::TestContext& testCtx)
172 de::MovePtr<tcu::TestCaseGroup> astcTests (new tcu::TestCaseGroup(testCtx, "astc", "Tests for ASTC Utilities"));
174 for (int formatNdx = 0; formatNdx < COMPRESSEDTEXFORMAT_LAST; formatNdx++)
176 const CompressedTexFormat format = (CompressedTexFormat)formatNdx;
178 if (isAstcFormat(format))
179 astcTests->addChild(new AstcCase(testCtx, format));
182 return astcTests.release();