xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fASTCDecompressionCases.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.0 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief ASTC decompression tests
22*35238bceSAndroid Build Coastguard Worker  *
23*35238bceSAndroid Build Coastguard Worker  * \todo Parts of the block-generation code are same as in decompression
24*35238bceSAndroid Build Coastguard Worker  *         code in tcuCompressedTexture.cpp ; could put them to some shared
25*35238bceSAndroid Build Coastguard Worker  *         ASTC utility file.
26*35238bceSAndroid Build Coastguard Worker  *
27*35238bceSAndroid Build Coastguard Worker  * \todo Tests for void extents with nontrivial extent coordinates.
28*35238bceSAndroid Build Coastguard Worker  *
29*35238bceSAndroid Build Coastguard Worker  * \todo Better checking of the error color. Currently legitimate error
30*35238bceSAndroid Build Coastguard Worker  *         pixels are just ignored in image comparison; however, spec says
31*35238bceSAndroid Build Coastguard Worker  *         that error color is either magenta or all-NaNs. Can NaNs cause
32*35238bceSAndroid Build Coastguard Worker  *         troubles, or can we assume that NaNs are well-supported in shader
33*35238bceSAndroid Build Coastguard Worker  *         if the implementation chooses NaNs as error color?
34*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker #include "es3fASTCDecompressionCases.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "gluTexture.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
39*35238bceSAndroid Build Coastguard Worker #include "gluStrUtil.hpp"
40*35238bceSAndroid Build Coastguard Worker #include "gluTextureUtil.hpp"
41*35238bceSAndroid Build Coastguard Worker #include "glsTextureTestUtil.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "tcuCompressedTexture.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
44*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
45*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
46*35238bceSAndroid Build Coastguard Worker #include "tcuVectorUtil.hpp"
47*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
48*35238bceSAndroid Build Coastguard Worker #include "deStringUtil.hpp"
49*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
50*35238bceSAndroid Build Coastguard Worker #include "deFloat16.h"
51*35238bceSAndroid Build Coastguard Worker #include "deString.h"
52*35238bceSAndroid Build Coastguard Worker #include "deMemory.h"
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
55*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker #include <vector>
58*35238bceSAndroid Build Coastguard Worker #include <string>
59*35238bceSAndroid Build Coastguard Worker #include <algorithm>
60*35238bceSAndroid Build Coastguard Worker 
61*35238bceSAndroid Build Coastguard Worker using std::string;
62*35238bceSAndroid Build Coastguard Worker using std::vector;
63*35238bceSAndroid Build Coastguard Worker using tcu::CompressedTexFormat;
64*35238bceSAndroid Build Coastguard Worker using tcu::CompressedTexture;
65*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
66*35238bceSAndroid Build Coastguard Worker using tcu::IVec3;
67*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
68*35238bceSAndroid Build Coastguard Worker using tcu::Sampler;
69*35238bceSAndroid Build Coastguard Worker using tcu::Surface;
70*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
71*35238bceSAndroid Build Coastguard Worker using tcu::Vec2;
72*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
73*35238bceSAndroid Build Coastguard Worker using tcu::astc::BlockTestType;
74*35238bceSAndroid Build Coastguard Worker 
75*35238bceSAndroid Build Coastguard Worker namespace deqp
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker 
78*35238bceSAndroid Build Coastguard Worker using gls::TextureTestUtil::RandomViewport;
79*35238bceSAndroid Build Coastguard Worker using gls::TextureTestUtil::TextureRenderer;
80*35238bceSAndroid Build Coastguard Worker using namespace glu::TextureTestUtil;
81*35238bceSAndroid Build Coastguard Worker 
82*35238bceSAndroid Build Coastguard Worker namespace gles3
83*35238bceSAndroid Build Coastguard Worker {
84*35238bceSAndroid Build Coastguard Worker namespace Functional
85*35238bceSAndroid Build Coastguard Worker {
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker namespace ASTCDecompressionCaseInternal
88*35238bceSAndroid Build Coastguard Worker {
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker // Get a string describing the data of an ASTC block. Currently contains just hex and bin dumps of the block.
astcBlockDataStr(const uint8_t * data)91*35238bceSAndroid Build Coastguard Worker static string astcBlockDataStr(const uint8_t *data)
92*35238bceSAndroid Build Coastguard Worker {
93*35238bceSAndroid Build Coastguard Worker     string result;
94*35238bceSAndroid Build Coastguard Worker     result += "  Hexadecimal (big endian: upper left hex digit is block bits 127 to 124):";
95*35238bceSAndroid Build Coastguard Worker 
96*35238bceSAndroid Build Coastguard Worker     {
97*35238bceSAndroid Build Coastguard Worker         static const char *const hexDigits = "0123456789ABCDEF";
98*35238bceSAndroid Build Coastguard Worker 
99*35238bceSAndroid Build Coastguard Worker         for (int i = tcu::astc::BLOCK_SIZE_BYTES - 1; i >= 0; i--)
100*35238bceSAndroid Build Coastguard Worker         {
101*35238bceSAndroid Build Coastguard Worker             if ((i + 1) % 2 == 0)
102*35238bceSAndroid Build Coastguard Worker                 result += "\n    ";
103*35238bceSAndroid Build Coastguard Worker             else
104*35238bceSAndroid Build Coastguard Worker                 result += "  ";
105*35238bceSAndroid Build Coastguard Worker 
106*35238bceSAndroid Build Coastguard Worker             result += hexDigits[(data[i] & 0xf0) >> 4];
107*35238bceSAndroid Build Coastguard Worker             result += " ";
108*35238bceSAndroid Build Coastguard Worker             result += hexDigits[(data[i] & 0x0f) >> 0];
109*35238bceSAndroid Build Coastguard Worker         }
110*35238bceSAndroid Build Coastguard Worker     }
111*35238bceSAndroid Build Coastguard Worker 
112*35238bceSAndroid Build Coastguard Worker     result += "\n\n  Binary (big endian: upper left bit is block bit 127):";
113*35238bceSAndroid Build Coastguard Worker 
114*35238bceSAndroid Build Coastguard Worker     for (int i = tcu::astc::BLOCK_SIZE_BYTES - 1; i >= 0; i--)
115*35238bceSAndroid Build Coastguard Worker     {
116*35238bceSAndroid Build Coastguard Worker         if ((i + 1) % 2 == 0)
117*35238bceSAndroid Build Coastguard Worker             result += "\n    ";
118*35238bceSAndroid Build Coastguard Worker         else
119*35238bceSAndroid Build Coastguard Worker             result += "  ";
120*35238bceSAndroid Build Coastguard Worker 
121*35238bceSAndroid Build Coastguard Worker         for (int j = 8 - 1; j >= 0; j--)
122*35238bceSAndroid Build Coastguard Worker         {
123*35238bceSAndroid Build Coastguard Worker             if (j == 3)
124*35238bceSAndroid Build Coastguard Worker                 result += " ";
125*35238bceSAndroid Build Coastguard Worker 
126*35238bceSAndroid Build Coastguard Worker             result += (data[i] >> j) & 1 ? "1" : "0";
127*35238bceSAndroid Build Coastguard Worker         }
128*35238bceSAndroid Build Coastguard Worker     }
129*35238bceSAndroid Build Coastguard Worker 
130*35238bceSAndroid Build Coastguard Worker     result += "\n";
131*35238bceSAndroid Build Coastguard Worker 
132*35238bceSAndroid Build Coastguard Worker     return result;
133*35238bceSAndroid Build Coastguard Worker }
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker // Compare reference and result block images, reporting also the position of the first non-matching block.
compareBlockImages(const Surface & reference,const Surface & result,const tcu::RGBA & thresholdRGBA,const IVec2 & blockSize,int numUsedBlocks,IVec2 & firstFailedBlockCoordDst,Surface & errorMaskDst,IVec4 & maxDiffDst)136*35238bceSAndroid Build Coastguard Worker static bool compareBlockImages(const Surface &reference, const Surface &result, const tcu::RGBA &thresholdRGBA,
137*35238bceSAndroid Build Coastguard Worker                                const IVec2 &blockSize, int numUsedBlocks, IVec2 &firstFailedBlockCoordDst,
138*35238bceSAndroid Build Coastguard Worker                                Surface &errorMaskDst, IVec4 &maxDiffDst)
139*35238bceSAndroid Build Coastguard Worker {
140*35238bceSAndroid Build Coastguard Worker     TCU_CHECK_INTERNAL(reference.getWidth() == result.getWidth() && reference.getHeight() == result.getHeight());
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker     const int width       = result.getWidth();
143*35238bceSAndroid Build Coastguard Worker     const int height      = result.getHeight();
144*35238bceSAndroid Build Coastguard Worker     const IVec4 threshold = thresholdRGBA.toIVec();
145*35238bceSAndroid Build Coastguard Worker     const int numXBlocks  = width / blockSize.x();
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(width % blockSize.x() == 0 && height % blockSize.y() == 0);
148*35238bceSAndroid Build Coastguard Worker 
149*35238bceSAndroid Build Coastguard Worker     errorMaskDst.setSize(width, height);
150*35238bceSAndroid Build Coastguard Worker 
151*35238bceSAndroid Build Coastguard Worker     firstFailedBlockCoordDst = IVec2(-1, -1);
152*35238bceSAndroid Build Coastguard Worker     maxDiffDst               = IVec4(0);
153*35238bceSAndroid Build Coastguard Worker 
154*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < height; y++)
155*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < width; x++)
156*35238bceSAndroid Build Coastguard Worker         {
157*35238bceSAndroid Build Coastguard Worker             const IVec2 blockCoord = IVec2(x, y) / blockSize;
158*35238bceSAndroid Build Coastguard Worker 
159*35238bceSAndroid Build Coastguard Worker             if (blockCoord.y() * numXBlocks + blockCoord.x() < numUsedBlocks)
160*35238bceSAndroid Build Coastguard Worker             {
161*35238bceSAndroid Build Coastguard Worker                 const IVec4 refPix = reference.getPixel(x, y).toIVec();
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker                 if (refPix == IVec4(255, 0, 255, 255))
164*35238bceSAndroid Build Coastguard Worker                 {
165*35238bceSAndroid Build Coastguard Worker                     // ASTC error color - allow anything in result.
166*35238bceSAndroid Build Coastguard Worker                     errorMaskDst.setPixel(x, y, tcu::RGBA(255, 0, 255, 255));
167*35238bceSAndroid Build Coastguard Worker                     continue;
168*35238bceSAndroid Build Coastguard Worker                 }
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker                 const IVec4 resPix = result.getPixel(x, y).toIVec();
171*35238bceSAndroid Build Coastguard Worker                 const IVec4 diff   = tcu::abs(refPix - resPix);
172*35238bceSAndroid Build Coastguard Worker                 const bool isOk    = tcu::boolAll(tcu::lessThanEqual(diff, threshold));
173*35238bceSAndroid Build Coastguard Worker 
174*35238bceSAndroid Build Coastguard Worker                 maxDiffDst = tcu::max(maxDiffDst, diff);
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker                 errorMaskDst.setPixel(x, y, isOk ? tcu::RGBA::green() : tcu::RGBA::red());
177*35238bceSAndroid Build Coastguard Worker 
178*35238bceSAndroid Build Coastguard Worker                 if (!isOk && firstFailedBlockCoordDst.x() == -1)
179*35238bceSAndroid Build Coastguard Worker                     firstFailedBlockCoordDst = blockCoord;
180*35238bceSAndroid Build Coastguard Worker             }
181*35238bceSAndroid Build Coastguard Worker         }
182*35238bceSAndroid Build Coastguard Worker 
183*35238bceSAndroid Build Coastguard Worker     return boolAll(lessThanEqual(maxDiffDst, threshold));
184*35238bceSAndroid Build Coastguard Worker }
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker enum ASTCSupportLevel
187*35238bceSAndroid Build Coastguard Worker {
188*35238bceSAndroid Build Coastguard Worker     // \note Ordered from smallest subset to full, for convenient comparison.
189*35238bceSAndroid Build Coastguard Worker     ASTCSUPPORTLEVEL_NONE = 0,
190*35238bceSAndroid Build Coastguard Worker     ASTCSUPPORTLEVEL_LDR,
191*35238bceSAndroid Build Coastguard Worker     ASTCSUPPORTLEVEL_HDR,
192*35238bceSAndroid Build Coastguard Worker     ASTCSUPPORTLEVEL_FULL
193*35238bceSAndroid Build Coastguard Worker };
194*35238bceSAndroid Build Coastguard Worker 
getASTCSupportLevel(const glu::ContextInfo & contextInfo,const glu::RenderContext & renderCtx)195*35238bceSAndroid Build Coastguard Worker static inline ASTCSupportLevel getASTCSupportLevel(const glu::ContextInfo &contextInfo,
196*35238bceSAndroid Build Coastguard Worker                                                    const glu::RenderContext &renderCtx)
197*35238bceSAndroid Build Coastguard Worker {
198*35238bceSAndroid Build Coastguard Worker     const bool isES32 = glu::contextSupports(renderCtx.getType(), glu::ApiType::es(3, 2));
199*35238bceSAndroid Build Coastguard Worker 
200*35238bceSAndroid Build Coastguard Worker     const vector<string> &extensions = contextInfo.getExtensions();
201*35238bceSAndroid Build Coastguard Worker 
202*35238bceSAndroid Build Coastguard Worker     ASTCSupportLevel maxLevel = ASTCSUPPORTLEVEL_NONE;
203*35238bceSAndroid Build Coastguard Worker 
204*35238bceSAndroid Build Coastguard Worker     for (int extNdx = 0; extNdx < (int)extensions.size(); extNdx++)
205*35238bceSAndroid Build Coastguard Worker     {
206*35238bceSAndroid Build Coastguard Worker         const string &ext = extensions[extNdx];
207*35238bceSAndroid Build Coastguard Worker         if (isES32)
208*35238bceSAndroid Build Coastguard Worker         {
209*35238bceSAndroid Build Coastguard Worker             maxLevel = de::max(maxLevel, ext == "GL_KHR_texture_compression_astc_hdr" ? ASTCSUPPORTLEVEL_HDR :
210*35238bceSAndroid Build Coastguard Worker                                          ext == "GL_OES_texture_compression_astc"     ? ASTCSUPPORTLEVEL_FULL :
211*35238bceSAndroid Build Coastguard Worker                                                                                         ASTCSUPPORTLEVEL_LDR);
212*35238bceSAndroid Build Coastguard Worker         }
213*35238bceSAndroid Build Coastguard Worker         else
214*35238bceSAndroid Build Coastguard Worker         {
215*35238bceSAndroid Build Coastguard Worker             maxLevel = de::max(maxLevel, ext == "GL_KHR_texture_compression_astc_ldr" ? ASTCSUPPORTLEVEL_LDR :
216*35238bceSAndroid Build Coastguard Worker                                          ext == "GL_KHR_texture_compression_astc_hdr" ? ASTCSUPPORTLEVEL_HDR :
217*35238bceSAndroid Build Coastguard Worker                                          ext == "GL_OES_texture_compression_astc"     ? ASTCSUPPORTLEVEL_FULL :
218*35238bceSAndroid Build Coastguard Worker                                                                                         ASTCSUPPORTLEVEL_NONE);
219*35238bceSAndroid Build Coastguard Worker         }
220*35238bceSAndroid Build Coastguard Worker     }
221*35238bceSAndroid Build Coastguard Worker 
222*35238bceSAndroid Build Coastguard Worker     return maxLevel;
223*35238bceSAndroid Build Coastguard Worker }
224*35238bceSAndroid Build Coastguard Worker 
225*35238bceSAndroid Build Coastguard Worker // Class handling the common rendering stuff of ASTC cases.
226*35238bceSAndroid Build Coastguard Worker class ASTCRenderer2D
227*35238bceSAndroid Build Coastguard Worker {
228*35238bceSAndroid Build Coastguard Worker public:
229*35238bceSAndroid Build Coastguard Worker     ASTCRenderer2D(Context &context, CompressedTexFormat format, uint32_t randomSeed);
230*35238bceSAndroid Build Coastguard Worker 
231*35238bceSAndroid Build Coastguard Worker     ~ASTCRenderer2D(void);
232*35238bceSAndroid Build Coastguard Worker 
233*35238bceSAndroid Build Coastguard Worker     void initialize(int minRenderWidth, int minRenderHeight, const Vec4 &colorScale, const Vec4 &colorBias);
234*35238bceSAndroid Build Coastguard Worker     void clear(void);
235*35238bceSAndroid Build Coastguard Worker 
236*35238bceSAndroid Build Coastguard Worker     void render(Surface &referenceDst, Surface &resultDst, const glu::Texture2D &texture,
237*35238bceSAndroid Build Coastguard Worker                 const tcu::TextureFormat &uncompressedFormat);
238*35238bceSAndroid Build Coastguard Worker 
getFormat(void) const239*35238bceSAndroid Build Coastguard Worker     CompressedTexFormat getFormat(void) const
240*35238bceSAndroid Build Coastguard Worker     {
241*35238bceSAndroid Build Coastguard Worker         return m_format;
242*35238bceSAndroid Build Coastguard Worker     }
getBlockSize(void) const243*35238bceSAndroid Build Coastguard Worker     IVec2 getBlockSize(void) const
244*35238bceSAndroid Build Coastguard Worker     {
245*35238bceSAndroid Build Coastguard Worker         return m_blockSize;
246*35238bceSAndroid Build Coastguard Worker     }
getASTCSupport(void) const247*35238bceSAndroid Build Coastguard Worker     ASTCSupportLevel getASTCSupport(void) const
248*35238bceSAndroid Build Coastguard Worker     {
249*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_initialized);
250*35238bceSAndroid Build Coastguard Worker         return m_astcSupport;
251*35238bceSAndroid Build Coastguard Worker     }
252*35238bceSAndroid Build Coastguard Worker 
253*35238bceSAndroid Build Coastguard Worker private:
254*35238bceSAndroid Build Coastguard Worker     Context &m_context;
255*35238bceSAndroid Build Coastguard Worker     TextureRenderer m_renderer;
256*35238bceSAndroid Build Coastguard Worker 
257*35238bceSAndroid Build Coastguard Worker     const CompressedTexFormat m_format;
258*35238bceSAndroid Build Coastguard Worker     const IVec2 m_blockSize;
259*35238bceSAndroid Build Coastguard Worker     ASTCSupportLevel m_astcSupport;
260*35238bceSAndroid Build Coastguard Worker     Vec4 m_colorScale;
261*35238bceSAndroid Build Coastguard Worker     Vec4 m_colorBias;
262*35238bceSAndroid Build Coastguard Worker 
263*35238bceSAndroid Build Coastguard Worker     de::Random m_rnd;
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker     bool m_initialized;
266*35238bceSAndroid Build Coastguard Worker };
267*35238bceSAndroid Build Coastguard Worker 
268*35238bceSAndroid Build Coastguard Worker } // namespace ASTCDecompressionCaseInternal
269*35238bceSAndroid Build Coastguard Worker 
270*35238bceSAndroid Build Coastguard Worker using namespace ASTCDecompressionCaseInternal;
271*35238bceSAndroid Build Coastguard Worker 
ASTCRenderer2D(Context & context,CompressedTexFormat format,uint32_t randomSeed)272*35238bceSAndroid Build Coastguard Worker ASTCRenderer2D::ASTCRenderer2D(Context &context, CompressedTexFormat format, uint32_t randomSeed)
273*35238bceSAndroid Build Coastguard Worker     : m_context(context)
274*35238bceSAndroid Build Coastguard Worker     , m_renderer(context.getRenderContext(), context.getTestContext().getLog(), glu::GLSL_VERSION_300_ES,
275*35238bceSAndroid Build Coastguard Worker                  glu::PRECISION_HIGHP)
276*35238bceSAndroid Build Coastguard Worker     , m_format(format)
277*35238bceSAndroid Build Coastguard Worker     , m_blockSize(tcu::getBlockPixelSize(format).xy())
278*35238bceSAndroid Build Coastguard Worker     , m_astcSupport(ASTCSUPPORTLEVEL_NONE)
279*35238bceSAndroid Build Coastguard Worker     , m_colorScale(-1.0f)
280*35238bceSAndroid Build Coastguard Worker     , m_colorBias(-1.0f)
281*35238bceSAndroid Build Coastguard Worker     , m_rnd(randomSeed)
282*35238bceSAndroid Build Coastguard Worker     , m_initialized(false)
283*35238bceSAndroid Build Coastguard Worker {
284*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(tcu::getBlockPixelSize(format).z() == 1);
285*35238bceSAndroid Build Coastguard Worker }
286*35238bceSAndroid Build Coastguard Worker 
~ASTCRenderer2D(void)287*35238bceSAndroid Build Coastguard Worker ASTCRenderer2D::~ASTCRenderer2D(void)
288*35238bceSAndroid Build Coastguard Worker {
289*35238bceSAndroid Build Coastguard Worker     clear();
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker 
initialize(int minRenderWidth,int minRenderHeight,const Vec4 & colorScale,const Vec4 & colorBias)292*35238bceSAndroid Build Coastguard Worker void ASTCRenderer2D::initialize(int minRenderWidth, int minRenderHeight, const Vec4 &colorScale, const Vec4 &colorBias)
293*35238bceSAndroid Build Coastguard Worker {
294*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_initialized);
295*35238bceSAndroid Build Coastguard Worker 
296*35238bceSAndroid Build Coastguard Worker     const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
297*35238bceSAndroid Build Coastguard Worker     TestLog &log                          = m_context.getTestContext().getLog();
298*35238bceSAndroid Build Coastguard Worker 
299*35238bceSAndroid Build Coastguard Worker     m_astcSupport = getASTCSupportLevel(m_context.getContextInfo(), m_context.getRenderContext());
300*35238bceSAndroid Build Coastguard Worker     m_colorScale  = colorScale;
301*35238bceSAndroid Build Coastguard Worker     m_colorBias   = colorBias;
302*35238bceSAndroid Build Coastguard Worker 
303*35238bceSAndroid Build Coastguard Worker     switch (m_astcSupport)
304*35238bceSAndroid Build Coastguard Worker     {
305*35238bceSAndroid Build Coastguard Worker     case ASTCSUPPORTLEVEL_NONE:
306*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "No ASTC support detected" << TestLog::EndMessage;
307*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("ASTC not supported");
308*35238bceSAndroid Build Coastguard Worker     case ASTCSUPPORTLEVEL_LDR:
309*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "LDR ASTC support detected" << TestLog::EndMessage;
310*35238bceSAndroid Build Coastguard Worker         break;
311*35238bceSAndroid Build Coastguard Worker     case ASTCSUPPORTLEVEL_HDR:
312*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "HDR ASTC support detected" << TestLog::EndMessage;
313*35238bceSAndroid Build Coastguard Worker         break;
314*35238bceSAndroid Build Coastguard Worker     case ASTCSUPPORTLEVEL_FULL:
315*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Full ASTC support detected" << TestLog::EndMessage;
316*35238bceSAndroid Build Coastguard Worker         break;
317*35238bceSAndroid Build Coastguard Worker     default:
318*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(false);
319*35238bceSAndroid Build Coastguard Worker     }
320*35238bceSAndroid Build Coastguard Worker 
321*35238bceSAndroid Build Coastguard Worker     if (renderTarget.getWidth() < minRenderWidth || renderTarget.getHeight() < minRenderHeight)
322*35238bceSAndroid Build Coastguard Worker         throw tcu::NotSupportedError("Render target must be at least " + de::toString(minRenderWidth) + "x" +
323*35238bceSAndroid Build Coastguard Worker                                      de::toString(minRenderHeight));
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker     log << TestLog::Message << "Using color scale and bias: result = raw * " << colorScale << " + " << colorBias
326*35238bceSAndroid Build Coastguard Worker         << TestLog::EndMessage;
327*35238bceSAndroid Build Coastguard Worker 
328*35238bceSAndroid Build Coastguard Worker     m_initialized = true;
329*35238bceSAndroid Build Coastguard Worker }
330*35238bceSAndroid Build Coastguard Worker 
clear(void)331*35238bceSAndroid Build Coastguard Worker void ASTCRenderer2D::clear(void)
332*35238bceSAndroid Build Coastguard Worker {
333*35238bceSAndroid Build Coastguard Worker     m_renderer.clear();
334*35238bceSAndroid Build Coastguard Worker }
335*35238bceSAndroid Build Coastguard Worker 
render(Surface & referenceDst,Surface & resultDst,const glu::Texture2D & texture,const tcu::TextureFormat & uncompressedFormat)336*35238bceSAndroid Build Coastguard Worker void ASTCRenderer2D::render(Surface &referenceDst, Surface &resultDst, const glu::Texture2D &texture,
337*35238bceSAndroid Build Coastguard Worker                             const tcu::TextureFormat &uncompressedFormat)
338*35238bceSAndroid Build Coastguard Worker {
339*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_initialized);
340*35238bceSAndroid Build Coastguard Worker 
341*35238bceSAndroid Build Coastguard Worker     const glw::Functions &gl            = m_context.getRenderContext().getFunctions();
342*35238bceSAndroid Build Coastguard Worker     const glu::RenderContext &renderCtx = m_context.getRenderContext();
343*35238bceSAndroid Build Coastguard Worker     const int textureWidth              = texture.getRefTexture().getWidth();
344*35238bceSAndroid Build Coastguard Worker     const int textureHeight             = texture.getRefTexture().getHeight();
345*35238bceSAndroid Build Coastguard Worker     const RandomViewport viewport(renderCtx.getRenderTarget(), textureWidth, textureHeight, m_rnd.getUint32());
346*35238bceSAndroid Build Coastguard Worker     ReferenceParams renderParams(TEXTURETYPE_2D);
347*35238bceSAndroid Build Coastguard Worker     vector<float> texCoord;
348*35238bceSAndroid Build Coastguard Worker     computeQuadTexCoord2D(texCoord, Vec2(0.0f, 0.0f), Vec2(1.0f, 1.0f));
349*35238bceSAndroid Build Coastguard Worker 
350*35238bceSAndroid Build Coastguard Worker     renderParams.samplerType = getSamplerType(uncompressedFormat);
351*35238bceSAndroid Build Coastguard Worker     renderParams.sampler     = Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE,
352*35238bceSAndroid Build Coastguard Worker                                        Sampler::NEAREST, Sampler::NEAREST);
353*35238bceSAndroid Build Coastguard Worker     renderParams.colorScale  = m_colorScale;
354*35238bceSAndroid Build Coastguard Worker     renderParams.colorBias   = m_colorBias;
355*35238bceSAndroid Build Coastguard Worker 
356*35238bceSAndroid Build Coastguard Worker     // Setup base viewport.
357*35238bceSAndroid Build Coastguard Worker     gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
358*35238bceSAndroid Build Coastguard Worker 
359*35238bceSAndroid Build Coastguard Worker     // Bind to unit 0.
360*35238bceSAndroid Build Coastguard Worker     gl.activeTexture(GL_TEXTURE0);
361*35238bceSAndroid Build Coastguard Worker     gl.bindTexture(GL_TEXTURE_2D, texture.getGLTexture());
362*35238bceSAndroid Build Coastguard Worker 
363*35238bceSAndroid Build Coastguard Worker     // Setup nearest neighbor filtering and clamp-to-edge.
364*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
365*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
366*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
367*35238bceSAndroid Build Coastguard Worker     gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
368*35238bceSAndroid Build Coastguard Worker 
369*35238bceSAndroid Build Coastguard Worker     GLU_EXPECT_NO_ERROR(gl.getError(), "Set texturing state");
370*35238bceSAndroid Build Coastguard Worker 
371*35238bceSAndroid Build Coastguard Worker     // Issue GL draws.
372*35238bceSAndroid Build Coastguard Worker     m_renderer.renderQuad(0, &texCoord[0], renderParams);
373*35238bceSAndroid Build Coastguard Worker     gl.flush();
374*35238bceSAndroid Build Coastguard Worker 
375*35238bceSAndroid Build Coastguard Worker     // Compute reference.
376*35238bceSAndroid Build Coastguard Worker     sampleTexture(tcu::SurfaceAccess(referenceDst, renderCtx.getRenderTarget().getPixelFormat()),
377*35238bceSAndroid Build Coastguard Worker                   texture.getRefTexture(), &texCoord[0], renderParams);
378*35238bceSAndroid Build Coastguard Worker 
379*35238bceSAndroid Build Coastguard Worker     // Read GL-rendered image.
380*35238bceSAndroid Build Coastguard Worker     glu::readPixels(renderCtx, viewport.x, viewport.y, resultDst.getAccess());
381*35238bceSAndroid Build Coastguard Worker }
382*35238bceSAndroid Build Coastguard Worker 
ASTCBlockCase2D(Context & context,const char * name,const char * description,BlockTestType testType,CompressedTexFormat format)383*35238bceSAndroid Build Coastguard Worker ASTCBlockCase2D::ASTCBlockCase2D(Context &context, const char *name, const char *description, BlockTestType testType,
384*35238bceSAndroid Build Coastguard Worker                                  CompressedTexFormat format)
385*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
386*35238bceSAndroid Build Coastguard Worker     , m_testType(testType)
387*35238bceSAndroid Build Coastguard Worker     , m_format(format)
388*35238bceSAndroid Build Coastguard Worker     , m_numBlocksTested(0)
389*35238bceSAndroid Build Coastguard Worker     , m_currentIteration(0)
390*35238bceSAndroid Build Coastguard Worker     , m_renderer(new ASTCRenderer2D(context, format, deStringHash(getName())))
391*35238bceSAndroid Build Coastguard Worker {
392*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!(tcu::isAstcSRGBFormat(m_format) &&
393*35238bceSAndroid Build Coastguard Worker                 tcu::astc::isBlockTestTypeHDROnly(
394*35238bceSAndroid Build Coastguard Worker                     m_testType))); // \note There is no HDR sRGB mode, so these would be redundant.
395*35238bceSAndroid Build Coastguard Worker }
396*35238bceSAndroid Build Coastguard Worker 
~ASTCBlockCase2D(void)397*35238bceSAndroid Build Coastguard Worker ASTCBlockCase2D::~ASTCBlockCase2D(void)
398*35238bceSAndroid Build Coastguard Worker {
399*35238bceSAndroid Build Coastguard Worker     ASTCBlockCase2D::deinit();
400*35238bceSAndroid Build Coastguard Worker }
401*35238bceSAndroid Build Coastguard Worker 
init(void)402*35238bceSAndroid Build Coastguard Worker void ASTCBlockCase2D::init(void)
403*35238bceSAndroid Build Coastguard Worker {
404*35238bceSAndroid Build Coastguard Worker     m_renderer->initialize(64, 64, tcu::astc::getBlockTestTypeColorScale(m_testType),
405*35238bceSAndroid Build Coastguard Worker                            tcu::astc::getBlockTestTypeColorBias(m_testType));
406*35238bceSAndroid Build Coastguard Worker 
407*35238bceSAndroid Build Coastguard Worker     generateBlockCaseTestData(m_blockData, m_format, m_testType);
408*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(!m_blockData.empty());
409*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(m_blockData.size() % tcu::astc::BLOCK_SIZE_BYTES == 0);
410*35238bceSAndroid Build Coastguard Worker 
411*35238bceSAndroid Build Coastguard Worker     m_testCtx.getLog() << TestLog::Message << "Total " << m_blockData.size() / tcu::astc::BLOCK_SIZE_BYTES
412*35238bceSAndroid Build Coastguard Worker                        << " blocks to test" << TestLog::EndMessage << TestLog::Message
413*35238bceSAndroid Build Coastguard Worker                        << "Note: Legitimate ASTC error pixels will be ignored when comparing to reference"
414*35238bceSAndroid Build Coastguard Worker                        << TestLog::EndMessage;
415*35238bceSAndroid Build Coastguard Worker }
416*35238bceSAndroid Build Coastguard Worker 
deinit(void)417*35238bceSAndroid Build Coastguard Worker void ASTCBlockCase2D::deinit(void)
418*35238bceSAndroid Build Coastguard Worker {
419*35238bceSAndroid Build Coastguard Worker     m_renderer->clear();
420*35238bceSAndroid Build Coastguard Worker     m_blockData.clear();
421*35238bceSAndroid Build Coastguard Worker }
422*35238bceSAndroid Build Coastguard Worker 
iterate(void)423*35238bceSAndroid Build Coastguard Worker ASTCBlockCase2D::IterateResult ASTCBlockCase2D::iterate(void)
424*35238bceSAndroid Build Coastguard Worker {
425*35238bceSAndroid Build Coastguard Worker     TestLog &log = m_testCtx.getLog();
426*35238bceSAndroid Build Coastguard Worker 
427*35238bceSAndroid Build Coastguard Worker     if (m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR && tcu::astc::isBlockTestTypeHDROnly(m_testType))
428*35238bceSAndroid Build Coastguard Worker     {
429*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message
430*35238bceSAndroid Build Coastguard Worker             << "Passing the case immediately, since only LDR support was detected and test only contains HDR blocks"
431*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
432*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
433*35238bceSAndroid Build Coastguard Worker         return STOP;
434*35238bceSAndroid Build Coastguard Worker     }
435*35238bceSAndroid Build Coastguard Worker 
436*35238bceSAndroid Build Coastguard Worker     const IVec2 blockSize               = m_renderer->getBlockSize();
437*35238bceSAndroid Build Coastguard Worker     const int totalNumBlocks            = (int)m_blockData.size() / tcu::astc::BLOCK_SIZE_BYTES;
438*35238bceSAndroid Build Coastguard Worker     const int numXBlocksPerImage        = de::min(m_context.getRenderTarget().getWidth(), 512) / blockSize.x();
439*35238bceSAndroid Build Coastguard Worker     const int numYBlocksPerImage        = de::min(m_context.getRenderTarget().getHeight(), 512) / blockSize.y();
440*35238bceSAndroid Build Coastguard Worker     const int numBlocksPerImage         = numXBlocksPerImage * numYBlocksPerImage;
441*35238bceSAndroid Build Coastguard Worker     const int imageWidth                = numXBlocksPerImage * blockSize.x();
442*35238bceSAndroid Build Coastguard Worker     const int imageHeight               = numYBlocksPerImage * blockSize.y();
443*35238bceSAndroid Build Coastguard Worker     const int numBlocksRemaining        = totalNumBlocks - m_numBlocksTested;
444*35238bceSAndroid Build Coastguard Worker     const int curNumUsedBlocks          = de::min(numBlocksPerImage, numBlocksRemaining);
445*35238bceSAndroid Build Coastguard Worker     const int curNumUnusedBlocks        = numBlocksPerImage - curNumUsedBlocks;
446*35238bceSAndroid Build Coastguard Worker     const glu::RenderContext &renderCtx = m_context.getRenderContext();
447*35238bceSAndroid Build Coastguard Worker     const tcu::RGBA threshold           = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() +
448*35238bceSAndroid Build Coastguard Worker                                 (tcu::isAstcSRGBFormat(m_format) ? tcu::RGBA(2, 2, 2, 2) : tcu::RGBA(1, 1, 1, 1));
449*35238bceSAndroid Build Coastguard Worker     tcu::CompressedTexture compressed(m_format, imageWidth, imageHeight);
450*35238bceSAndroid Build Coastguard Worker 
451*35238bceSAndroid Build Coastguard Worker     if (m_currentIteration == 0)
452*35238bceSAndroid Build Coastguard Worker     {
453*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Using texture of size " << imageWidth << "x" << imageHeight << ", with "
454*35238bceSAndroid Build Coastguard Worker             << numXBlocksPerImage << " block columns and " << numYBlocksPerImage << " block rows "
455*35238bceSAndroid Build Coastguard Worker             << ", with block size " << blockSize.x() << "x" << blockSize.y() << TestLog::EndMessage;
456*35238bceSAndroid Build Coastguard Worker     }
457*35238bceSAndroid Build Coastguard Worker 
458*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(compressed.getDataSize() == numBlocksPerImage * tcu::astc::BLOCK_SIZE_BYTES);
459*35238bceSAndroid Build Coastguard Worker     deMemcpy(compressed.getData(), &m_blockData[m_numBlocksTested * tcu::astc::BLOCK_SIZE_BYTES],
460*35238bceSAndroid Build Coastguard Worker              curNumUsedBlocks * tcu::astc::BLOCK_SIZE_BYTES);
461*35238bceSAndroid Build Coastguard Worker     if (curNumUsedBlocks > 1)
462*35238bceSAndroid Build Coastguard Worker         tcu::astc::generateDefaultVoidExtentBlocks(
463*35238bceSAndroid Build Coastguard Worker             (uint8_t *)compressed.getData() + curNumUsedBlocks * tcu::astc::BLOCK_SIZE_BYTES, curNumUnusedBlocks);
464*35238bceSAndroid Build Coastguard Worker 
465*35238bceSAndroid Build Coastguard Worker     // Create texture and render.
466*35238bceSAndroid Build Coastguard Worker 
467*35238bceSAndroid Build Coastguard Worker     const tcu::TexDecompressionParams::AstcMode decompressionMode =
468*35238bceSAndroid Build Coastguard Worker         (m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR || tcu::isAstcSRGBFormat(m_format)) ?
469*35238bceSAndroid Build Coastguard Worker             tcu::TexDecompressionParams::ASTCMODE_LDR :
470*35238bceSAndroid Build Coastguard Worker             tcu::TexDecompressionParams::ASTCMODE_HDR;
471*35238bceSAndroid Build Coastguard Worker     glu::Texture2D texture(renderCtx, m_context.getContextInfo(), 1, &compressed,
472*35238bceSAndroid Build Coastguard Worker                            tcu::TexDecompressionParams(decompressionMode));
473*35238bceSAndroid Build Coastguard Worker     Surface renderedFrame(imageWidth, imageHeight);
474*35238bceSAndroid Build Coastguard Worker     Surface referenceFrame(imageWidth, imageHeight);
475*35238bceSAndroid Build Coastguard Worker 
476*35238bceSAndroid Build Coastguard Worker     m_renderer->render(referenceFrame, renderedFrame, texture, getUncompressedFormat(compressed.getFormat()));
477*35238bceSAndroid Build Coastguard Worker 
478*35238bceSAndroid Build Coastguard Worker     // Compare and log.
479*35238bceSAndroid Build Coastguard Worker     // \note Since a case can draw quite many images, only log the first iteration and failures.
480*35238bceSAndroid Build Coastguard Worker 
481*35238bceSAndroid Build Coastguard Worker     {
482*35238bceSAndroid Build Coastguard Worker         Surface errorMask;
483*35238bceSAndroid Build Coastguard Worker         IVec2 firstFailedBlockCoord;
484*35238bceSAndroid Build Coastguard Worker         IVec4 maxDiff;
485*35238bceSAndroid Build Coastguard Worker         const bool compareOk = compareBlockImages(referenceFrame, renderedFrame, threshold, blockSize, curNumUsedBlocks,
486*35238bceSAndroid Build Coastguard Worker                                                   firstFailedBlockCoord, errorMask, maxDiff);
487*35238bceSAndroid Build Coastguard Worker 
488*35238bceSAndroid Build Coastguard Worker         if (m_currentIteration == 0 || !compareOk)
489*35238bceSAndroid Build Coastguard Worker         {
490*35238bceSAndroid Build Coastguard Worker             const char *const imageSetName = "ComparisonResult";
491*35238bceSAndroid Build Coastguard Worker             const char *const imageSetDesc = "Comparison Result";
492*35238bceSAndroid Build Coastguard Worker 
493*35238bceSAndroid Build Coastguard Worker             {
494*35238bceSAndroid Build Coastguard Worker                 tcu::ScopedLogSection section(log, "Iteration " + de::toString(m_currentIteration),
495*35238bceSAndroid Build Coastguard Worker                                               "Blocks " + de::toString(m_numBlocksTested) + " to " +
496*35238bceSAndroid Build Coastguard Worker                                                   de::toString(m_numBlocksTested + curNumUsedBlocks - 1));
497*35238bceSAndroid Build Coastguard Worker 
498*35238bceSAndroid Build Coastguard Worker                 if (curNumUsedBlocks > 0)
499*35238bceSAndroid Build Coastguard Worker                     log << TestLog::Message << "Note: Only the first " << curNumUsedBlocks
500*35238bceSAndroid Build Coastguard Worker                         << " blocks in the image are relevant; rest " << curNumUnusedBlocks
501*35238bceSAndroid Build Coastguard Worker                         << " are dummies and not checked" << TestLog::EndMessage;
502*35238bceSAndroid Build Coastguard Worker 
503*35238bceSAndroid Build Coastguard Worker                 if (!compareOk)
504*35238bceSAndroid Build Coastguard Worker                 {
505*35238bceSAndroid Build Coastguard Worker                     log << TestLog::Message << "Image comparison failed: max difference = " << maxDiff
506*35238bceSAndroid Build Coastguard Worker                         << ", threshold = " << threshold << TestLog::EndMessage
507*35238bceSAndroid Build Coastguard Worker                         << TestLog::ImageSet(imageSetName, imageSetDesc)
508*35238bceSAndroid Build Coastguard Worker                         << TestLog::Image("Result", "Result", renderedFrame)
509*35238bceSAndroid Build Coastguard Worker                         << TestLog::Image("Reference", "Reference", referenceFrame)
510*35238bceSAndroid Build Coastguard Worker                         << TestLog::Image("ErrorMask", "Error mask", errorMask) << TestLog::EndImageSet;
511*35238bceSAndroid Build Coastguard Worker 
512*35238bceSAndroid Build Coastguard Worker                     const int blockNdx =
513*35238bceSAndroid Build Coastguard Worker                         m_numBlocksTested + firstFailedBlockCoord.y() * numXBlocksPerImage + firstFailedBlockCoord.x();
514*35238bceSAndroid Build Coastguard Worker                     DE_ASSERT(blockNdx < totalNumBlocks);
515*35238bceSAndroid Build Coastguard Worker 
516*35238bceSAndroid Build Coastguard Worker                     log << TestLog::Message << "First failed block at column " << firstFailedBlockCoord.x()
517*35238bceSAndroid Build Coastguard Worker                         << " and row " << firstFailedBlockCoord.y() << TestLog::EndMessage << TestLog::Message
518*35238bceSAndroid Build Coastguard Worker                         << "Data of first failed block:\n"
519*35238bceSAndroid Build Coastguard Worker                         << astcBlockDataStr(&m_blockData[blockNdx * tcu::astc::BLOCK_SIZE_BYTES])
520*35238bceSAndroid Build Coastguard Worker                         << TestLog::EndMessage;
521*35238bceSAndroid Build Coastguard Worker 
522*35238bceSAndroid Build Coastguard Worker                     m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
523*35238bceSAndroid Build Coastguard Worker                     return STOP;
524*35238bceSAndroid Build Coastguard Worker                 }
525*35238bceSAndroid Build Coastguard Worker                 else
526*35238bceSAndroid Build Coastguard Worker                 {
527*35238bceSAndroid Build Coastguard Worker                     log << TestLog::ImageSet(imageSetName, imageSetDesc)
528*35238bceSAndroid Build Coastguard Worker                         << TestLog::Image("Result", "Result", renderedFrame) << TestLog::EndImageSet;
529*35238bceSAndroid Build Coastguard Worker                 }
530*35238bceSAndroid Build Coastguard Worker             }
531*35238bceSAndroid Build Coastguard Worker 
532*35238bceSAndroid Build Coastguard Worker             if (m_numBlocksTested + curNumUsedBlocks < totalNumBlocks)
533*35238bceSAndroid Build Coastguard Worker                 log << TestLog::Message << "Note: not logging further images unless reference comparison fails"
534*35238bceSAndroid Build Coastguard Worker                     << TestLog::EndMessage;
535*35238bceSAndroid Build Coastguard Worker         }
536*35238bceSAndroid Build Coastguard Worker     }
537*35238bceSAndroid Build Coastguard Worker 
538*35238bceSAndroid Build Coastguard Worker     m_currentIteration++;
539*35238bceSAndroid Build Coastguard Worker     m_numBlocksTested += curNumUsedBlocks;
540*35238bceSAndroid Build Coastguard Worker 
541*35238bceSAndroid Build Coastguard Worker     if (m_numBlocksTested >= totalNumBlocks)
542*35238bceSAndroid Build Coastguard Worker     {
543*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_numBlocksTested == totalNumBlocks);
544*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
545*35238bceSAndroid Build Coastguard Worker         return STOP;
546*35238bceSAndroid Build Coastguard Worker     }
547*35238bceSAndroid Build Coastguard Worker 
548*35238bceSAndroid Build Coastguard Worker     return CONTINUE;
549*35238bceSAndroid Build Coastguard Worker }
550*35238bceSAndroid Build Coastguard Worker 
ASTCBlockSizeRemainderCase2D(Context & context,const char * name,const char * description,CompressedTexFormat format)551*35238bceSAndroid Build Coastguard Worker ASTCBlockSizeRemainderCase2D::ASTCBlockSizeRemainderCase2D(Context &context, const char *name, const char *description,
552*35238bceSAndroid Build Coastguard Worker                                                            CompressedTexFormat format)
553*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
554*35238bceSAndroid Build Coastguard Worker     , m_format(format)
555*35238bceSAndroid Build Coastguard Worker     , m_currentIteration(0)
556*35238bceSAndroid Build Coastguard Worker     , m_renderer(new ASTCRenderer2D(context, format, deStringHash(getName())))
557*35238bceSAndroid Build Coastguard Worker {
558*35238bceSAndroid Build Coastguard Worker }
559*35238bceSAndroid Build Coastguard Worker 
~ASTCBlockSizeRemainderCase2D(void)560*35238bceSAndroid Build Coastguard Worker ASTCBlockSizeRemainderCase2D::~ASTCBlockSizeRemainderCase2D(void)
561*35238bceSAndroid Build Coastguard Worker {
562*35238bceSAndroid Build Coastguard Worker     ASTCBlockSizeRemainderCase2D::deinit();
563*35238bceSAndroid Build Coastguard Worker }
564*35238bceSAndroid Build Coastguard Worker 
init(void)565*35238bceSAndroid Build Coastguard Worker void ASTCBlockSizeRemainderCase2D::init(void)
566*35238bceSAndroid Build Coastguard Worker {
567*35238bceSAndroid Build Coastguard Worker     const IVec2 blockSize = m_renderer->getBlockSize();
568*35238bceSAndroid Build Coastguard Worker     m_renderer->initialize(MAX_NUM_BLOCKS_X * blockSize.x(), MAX_NUM_BLOCKS_Y * blockSize.y(), Vec4(1.0f), Vec4(0.0f));
569*35238bceSAndroid Build Coastguard Worker }
570*35238bceSAndroid Build Coastguard Worker 
deinit(void)571*35238bceSAndroid Build Coastguard Worker void ASTCBlockSizeRemainderCase2D::deinit(void)
572*35238bceSAndroid Build Coastguard Worker {
573*35238bceSAndroid Build Coastguard Worker     m_renderer->clear();
574*35238bceSAndroid Build Coastguard Worker }
575*35238bceSAndroid Build Coastguard Worker 
iterate(void)576*35238bceSAndroid Build Coastguard Worker ASTCBlockSizeRemainderCase2D::IterateResult ASTCBlockSizeRemainderCase2D::iterate(void)
577*35238bceSAndroid Build Coastguard Worker {
578*35238bceSAndroid Build Coastguard Worker     TestLog &log                        = m_testCtx.getLog();
579*35238bceSAndroid Build Coastguard Worker     const IVec2 blockSize               = m_renderer->getBlockSize();
580*35238bceSAndroid Build Coastguard Worker     const int curRemainderX             = m_currentIteration % blockSize.x();
581*35238bceSAndroid Build Coastguard Worker     const int curRemainderY             = m_currentIteration / blockSize.x();
582*35238bceSAndroid Build Coastguard Worker     const int imageWidth                = (MAX_NUM_BLOCKS_X - 1) * blockSize.x() + curRemainderX;
583*35238bceSAndroid Build Coastguard Worker     const int imageHeight               = (MAX_NUM_BLOCKS_Y - 1) * blockSize.y() + curRemainderY;
584*35238bceSAndroid Build Coastguard Worker     const int numBlocksX                = deDivRoundUp32(imageWidth, blockSize.x());
585*35238bceSAndroid Build Coastguard Worker     const int numBlocksY                = deDivRoundUp32(imageHeight, blockSize.y());
586*35238bceSAndroid Build Coastguard Worker     const int totalNumBlocks            = numBlocksX * numBlocksY;
587*35238bceSAndroid Build Coastguard Worker     const glu::RenderContext &renderCtx = m_context.getRenderContext();
588*35238bceSAndroid Build Coastguard Worker     const tcu::RGBA threshold           = renderCtx.getRenderTarget().getPixelFormat().getColorThreshold() +
589*35238bceSAndroid Build Coastguard Worker                                 (tcu::isAstcSRGBFormat(m_format) ? tcu::RGBA(2, 2, 2, 2) : tcu::RGBA(1, 1, 1, 1));
590*35238bceSAndroid Build Coastguard Worker     tcu::CompressedTexture compressed(m_format, imageWidth, imageHeight);
591*35238bceSAndroid Build Coastguard Worker 
592*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(compressed.getDataSize() == totalNumBlocks * tcu::astc::BLOCK_SIZE_BYTES);
593*35238bceSAndroid Build Coastguard Worker     tcu::astc::generateDefaultNormalBlocks((uint8_t *)compressed.getData(), totalNumBlocks, blockSize.x(),
594*35238bceSAndroid Build Coastguard Worker                                            blockSize.y());
595*35238bceSAndroid Build Coastguard Worker 
596*35238bceSAndroid Build Coastguard Worker     // Create texture and render.
597*35238bceSAndroid Build Coastguard Worker 
598*35238bceSAndroid Build Coastguard Worker     const tcu::TexDecompressionParams::AstcMode decompressionMode =
599*35238bceSAndroid Build Coastguard Worker         (m_renderer->getASTCSupport() == ASTCSUPPORTLEVEL_LDR || tcu::isAstcSRGBFormat(m_format)) ?
600*35238bceSAndroid Build Coastguard Worker             tcu::TexDecompressionParams::ASTCMODE_LDR :
601*35238bceSAndroid Build Coastguard Worker             tcu::TexDecompressionParams::ASTCMODE_HDR;
602*35238bceSAndroid Build Coastguard Worker     Surface renderedFrame(imageWidth, imageHeight);
603*35238bceSAndroid Build Coastguard Worker     Surface referenceFrame(imageWidth, imageHeight);
604*35238bceSAndroid Build Coastguard Worker     glu::Texture2D texture(renderCtx, m_context.getContextInfo(), 1, &compressed,
605*35238bceSAndroid Build Coastguard Worker                            tcu::TexDecompressionParams(decompressionMode));
606*35238bceSAndroid Build Coastguard Worker 
607*35238bceSAndroid Build Coastguard Worker     m_renderer->render(referenceFrame, renderedFrame, texture, getUncompressedFormat(compressed.getFormat()));
608*35238bceSAndroid Build Coastguard Worker 
609*35238bceSAndroid Build Coastguard Worker     {
610*35238bceSAndroid Build Coastguard Worker         // Compare and log.
611*35238bceSAndroid Build Coastguard Worker 
612*35238bceSAndroid Build Coastguard Worker         tcu::ScopedLogSection section(log, "Iteration " + de::toString(m_currentIteration),
613*35238bceSAndroid Build Coastguard Worker                                       "Remainder " + de::toString(curRemainderX) + "x" + de::toString(curRemainderY));
614*35238bceSAndroid Build Coastguard Worker 
615*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Using texture of size " << imageWidth << "x" << imageHeight << " and block size "
616*35238bceSAndroid Build Coastguard Worker             << blockSize.x() << "x" << blockSize.y() << "; the x and y remainders are " << curRemainderX << " and "
617*35238bceSAndroid Build Coastguard Worker             << curRemainderY << " respectively" << TestLog::EndMessage;
618*35238bceSAndroid Build Coastguard Worker 
619*35238bceSAndroid Build Coastguard Worker         const bool compareOk = tcu::pixelThresholdCompare(
620*35238bceSAndroid Build Coastguard Worker             m_testCtx.getLog(), "ComparisonResult", "Comparison Result", referenceFrame, renderedFrame, threshold,
621*35238bceSAndroid Build Coastguard Worker             m_currentIteration == 0 ? tcu::COMPARE_LOG_RESULT : tcu::COMPARE_LOG_ON_ERROR);
622*35238bceSAndroid Build Coastguard Worker 
623*35238bceSAndroid Build Coastguard Worker         if (!compareOk)
624*35238bceSAndroid Build Coastguard Worker         {
625*35238bceSAndroid Build Coastguard Worker             m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
626*35238bceSAndroid Build Coastguard Worker             return STOP;
627*35238bceSAndroid Build Coastguard Worker         }
628*35238bceSAndroid Build Coastguard Worker     }
629*35238bceSAndroid Build Coastguard Worker 
630*35238bceSAndroid Build Coastguard Worker     if (m_currentIteration == 0 && m_currentIteration + 1 < blockSize.x() * blockSize.y())
631*35238bceSAndroid Build Coastguard Worker         log << TestLog::Message << "Note: not logging further images unless reference comparison fails"
632*35238bceSAndroid Build Coastguard Worker             << TestLog::EndMessage;
633*35238bceSAndroid Build Coastguard Worker 
634*35238bceSAndroid Build Coastguard Worker     m_currentIteration++;
635*35238bceSAndroid Build Coastguard Worker 
636*35238bceSAndroid Build Coastguard Worker     if (m_currentIteration >= blockSize.x() * blockSize.y())
637*35238bceSAndroid Build Coastguard Worker     {
638*35238bceSAndroid Build Coastguard Worker         DE_ASSERT(m_currentIteration == blockSize.x() * blockSize.y());
639*35238bceSAndroid Build Coastguard Worker         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
640*35238bceSAndroid Build Coastguard Worker         return STOP;
641*35238bceSAndroid Build Coastguard Worker     }
642*35238bceSAndroid Build Coastguard Worker     return CONTINUE;
643*35238bceSAndroid Build Coastguard Worker }
644*35238bceSAndroid Build Coastguard Worker 
645*35238bceSAndroid Build Coastguard Worker } // namespace Functional
646*35238bceSAndroid Build Coastguard Worker } // namespace gles3
647*35238bceSAndroid Build Coastguard Worker } // namespace deqp
648