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