lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#ifndef _GLUTEXTURETESTUTIL_HPP
#define _GLUTEXTURETESTUTIL_HPP
/*-------------------------------------------------------------------------
 * drawElements Quality Program OpenGL ES Utilities
 * ------------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Utility functions and structures for texture tests.
 *
 * This code is originated from the modules/glshared/glsTextureTestUtil.hpp
 * and it is tightly coupled with the GLES and Vulkan texture tests!
 *
 * About coordinates:
 *  + Quads consist of 2 triangles, rendered using explicit indices.
 *  + All TextureTestUtil functions and classes expect texture coordinates
 *    for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1).
 *//*--------------------------------------------------------------------*/
 
#include "tcuDefs.hpp"
#include "tcuSurfaceAccess.hpp"
#include "tcuTestContext.hpp"
#include "tcuTestLog.hpp"
#include "tcuTexture.hpp"
#include "tcuTexCompareVerifier.hpp"
#include "qpWatchDog.h"
 
namespace glu
{
namespace TextureTestUtil
{
enum TextureType
{
   TEXTURETYPE_2D = 0,
   TEXTURETYPE_CUBE,
   TEXTURETYPE_2D_ARRAY,
   TEXTURETYPE_3D,
   TEXTURETYPE_CUBE_ARRAY,
   TEXTURETYPE_1D,
   TEXTURETYPE_1D_ARRAY,
   TEXTURETYPE_BUFFER,
 
   TEXTURETYPE_LAST
};
 
enum SamplerType
{
   SAMPLERTYPE_FLOAT,
   SAMPLERTYPE_INT,
   SAMPLERTYPE_UINT,
   SAMPLERTYPE_SHADOW,
 
   SAMPLERTYPE_FETCH_FLOAT,
   SAMPLERTYPE_FETCH_INT,
   SAMPLERTYPE_FETCH_UINT,
 
   SAMPLERTYPE_LAST
};
 
struct RenderParams
{
   enum Flags
   {
       PROJECTED        = (1<<0),
       USE_BIAS        = (1<<1),
       LOG_PROGRAMS    = (1<<2),
       LOG_UNIFORMS    = (1<<3),
 
       LOG_ALL            = LOG_PROGRAMS|LOG_UNIFORMS
   };
 
   RenderParams (TextureType texType_)
       : texType        (texType_)
       , samplerType    (SAMPLERTYPE_FLOAT)
       , flags            (0)
       , w                (1.0f)
       , bias            (0.0f)
       , ref            (0.0f)
       , colorScale    (1.0f)
       , colorBias        (0.0f)
   {
   }
 
   TextureType        texType;        //!< Texture type.
   SamplerType        samplerType;    //!< Sampler type.
   deUint32        flags;            //!< Feature flags.
   tcu::Vec4        w;                //!< w coordinates for quad vertices.
   float            bias;            //!< User-supplied bias.
   float            ref;            //!< Reference value for shadow lookups.
 
   // color = lookup() * scale + bias
   tcu::Vec4        colorScale;        //!< Scale for texture color values.
   tcu::Vec4        colorBias;        //!< Bias for texture color values.
};
 
enum LodMode
{
   LODMODE_EXACT = 0,        //!< Ideal lod computation.
   LODMODE_MIN_BOUND,        //!< Use estimation range minimum bound.
   LODMODE_MAX_BOUND,        //!< Use estimation range maximum bound.
 
   LODMODE_LAST
};
 
struct ReferenceParams : public RenderParams
{
   ReferenceParams (TextureType texType_)
       : RenderParams    (texType_)
       , sampler        ()
       , lodMode        (LODMODE_EXACT)
       , minLod        (-1000.0f)
       , maxLod        (1000.0f)
       , baseLevel        (0)
       , maxLevel        (1000)
       , unnormal        (false)
   {
   }
 
   ReferenceParams (TextureType texType_, const tcu::Sampler& sampler_, LodMode lodMode_ = LODMODE_EXACT)
       : RenderParams    (texType_)
       , sampler        (sampler_)
       , lodMode        (lodMode_)
       , minLod        (-1000.0f)
       , maxLod        (1000.0f)
       , baseLevel        (0)
       , maxLevel        (1000)
       , unnormal        (false)
   {
   }
 
   tcu::Sampler        sampler;
   LodMode                lodMode;
   float                minLod;
   float                maxLod;
   int                    baseLevel;
   int                    maxLevel;
   bool                unnormal;
};
 
 
SamplerType        getSamplerType        (tcu::TextureFormat format);
SamplerType        getFetchSamplerType    (tcu::TextureFormat format);
 
// Similar to sampleTexture() except uses texelFetch.
void            fetchTexture                (const tcu::SurfaceAccess& dst, const tcu::ConstPixelBufferAccess& src, const float* texCoord, const tcu::Vec4& colorScale, const tcu::Vec4& colorBias);
 
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::Texture2DView&        src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::TextureCubeView&        src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::Texture2DArrayView&    src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::Texture3DView&        src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::TextureCubeArrayView&    src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::Texture1DView&        src, const float* texCoord, const ReferenceParams& params);
void            sampleTexture                (const tcu::SurfaceAccess& dst, const tcu::Texture1DArrayView&    src, const float* texCoord, const ReferenceParams& params);
 
float            computeLodFromDerivates        (LodMode mode, float dudx, float dudy);
float            computeLodFromDerivates        (LodMode mode, float dudx, float dvdx, float dudy, float dvdy);
float            computeLodFromDerivates        (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy);
 
void            computeQuadTexCoord1D            (std::vector<float>& dst, float left, float right);
void            computeQuadTexCoord1DArray        (std::vector<float>& dst, int layerNdx, float left, float right);
void            computeQuadTexCoord2D            (std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
void            computeQuadTexCoord2DArray        (std::vector<float>& dst, int layerNdx, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
void            computeQuadTexCoord3D            (std::vector<float>& dst, const tcu::Vec3& p0, const tcu::Vec3& p1, const tcu::IVec3& dirSwz);
void            computeQuadTexCoordCube            (std::vector<float>& dst, tcu::CubeFace face);
void            computeQuadTexCoordCube            (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
void            computeQuadTexCoordCubeArray    (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight, const tcu::Vec2& layerRange);
 
bool            compareImages                (tcu::TestLog& log, const char* name, const char* desc, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
bool            compareImages                (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
int                measureAccuracy                (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, int bestScoreDiff, int worstScoreDiff);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture1DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture2DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::TextureCubeView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture1DArrayView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture2DArrayView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture3DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
int                computeTextureLookupDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::TextureCubeArrayView&    src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::IVec4&                    coordBits,
                                            const tcu::LodPrecision&            lodPrec,
                                            qpWatchDog*                        watchDog);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::Texture1DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::Texture2DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::TextureCubeView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::Texture1DArrayView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::Texture2DArrayView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::Texture3DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
bool            verifyTextureResult            (tcu::TestContext&                    testCtx,
                                            const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::TextureCubeArrayView&    src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::LookupPrecision&        lookupPrec,
                                            const tcu::IVec4&                    coordBits,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::PixelFormat&            pixelFormat);
 
int                computeTextureCompareDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture2DView&            src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::TexComparePrecision&    comparePrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::Vec3&                    nonShadowThreshold);
 
int                computeTextureCompareDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::TextureCubeView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::TexComparePrecision&    comparePrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::Vec3&                    nonShadowThreshold);
 
int                computeTextureCompareDiff    (const tcu::ConstPixelBufferAccess&    result,
                                            const tcu::ConstPixelBufferAccess&    reference,
                                            const tcu::PixelBufferAccess&        errorMask,
                                            const tcu::Texture2DArrayView&        src,
                                            const float*                        texCoord,
                                            const ReferenceParams&                sampleParams,
                                            const tcu::TexComparePrecision&    comparePrec,
                                            const tcu::LodPrecision&            lodPrec,
                                            const tcu::Vec3&                    nonShadowThreshold);
 
 
inline tcu::IVec4 getBitsVec (const tcu::PixelFormat& format)
{
   return tcu::IVec4(format.redBits, format.greenBits, format.blueBits, format.alphaBits);
}
 
inline tcu::BVec4 getCompareMask (const tcu::PixelFormat& format)
{
   return tcu::BVec4(format.redBits    > 0,
                     format.greenBits    > 0,
                     format.blueBits    > 0,
                     format.alphaBits    > 0);
}
 
 
// Mipmap generation comparison.
 
struct GenMipmapPrecision
{
   tcu::IVec3            filterBits;            //!< Bits in filtering parameters (fixed-point).
   tcu::Vec4            colorThreshold;        //!< Threshold for color value comparison.
   tcu::BVec4            colorMask;            //!< Color channel comparison mask.
};
 
qpTestResult    compareGenMipmapResult        (tcu::TestLog& log, const tcu::Texture2D& resultTexture, const tcu::Texture2D& level0Reference, const GenMipmapPrecision& precision);
qpTestResult    compareGenMipmapResult        (tcu::TestLog& log, const tcu::TextureCube& resultTexture, const tcu::TextureCube& level0Reference, const GenMipmapPrecision& precision);
 
// Utility for logging texture gradient ranges.
struct LogGradientFmt
{
   LogGradientFmt (const tcu::Vec4* min_, const tcu::Vec4* max_) : valueMin(min_), valueMax(max_) {}
   const tcu::Vec4* valueMin;
   const tcu::Vec4* valueMax;
};
 
std::ostream&            operator<<        (std::ostream& str, const LogGradientFmt& fmt);
inline LogGradientFmt    formatGradient    (const tcu::Vec4* minVal, const tcu::Vec4* maxVal) { return LogGradientFmt(minVal, maxVal); }
 
} // TextureTestUtil
} // glu
 
#endif // _GLUTEXTURETESTUTIL_HPP