• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 		, float16TexCoord	(false)
131 	{
132 	}
133 
ReferenceParamsglu::TextureTestUtil::ReferenceParams134 	ReferenceParams (TextureType texType_, const tcu::Sampler& sampler_, LodMode lodMode_ = LODMODE_EXACT)
135 		: RenderParams		(texType_)
136 		, sampler			(sampler_)
137 		, lodMode			(lodMode_)
138 		, minLod			(-1000.0f)
139 		, maxLod			(1000.0f)
140 		, baseLevel			(0)
141 		, maxLevel			(1000)
142 		, unnormal			(false)
143 		, float16TexCoord	(false)
144 	{
145 	}
146 
147 	tcu::Sampler		sampler;
148 	LodMode				lodMode;
149 	float				minLod;
150 	float				maxLod;
151 	int					baseLevel;
152 	int					maxLevel;
153 	bool				unnormal;
154 	bool				float16TexCoord;
155 };
156 
157 
158 SamplerType		getSamplerType		(tcu::TextureFormat format);
159 SamplerType		getFetchSamplerType	(tcu::TextureFormat format);
160 
161 // Similar to sampleTexture() except uses texelFetch.
162 void			fetchTexture				(const tcu::SurfaceAccess& dst, const tcu::ConstPixelBufferAccess& src, const float* texCoord, const tcu::Vec4& colorScale, const tcu::Vec4& colorBias);
163 
164 void			sampleTexture				(const tcu::PixelBufferAccess& dst, const tcu::Texture2DView&	src, const float* texCoord, const ReferenceParams& params);
165 
166 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture2DView&		src, const float* texCoord, const ReferenceParams& params);
167 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::TextureCubeView&		src, const float* texCoord, const ReferenceParams& params);
168 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture2DArrayView&	src, const float* texCoord, const ReferenceParams& params);
169 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture3DView&		src, const float* texCoord, const ReferenceParams& params);
170 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::TextureCubeArrayView&	src, const float* texCoord, const ReferenceParams& params);
171 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture1DView&		src, const float* texCoord, const ReferenceParams& params);
172 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture1DArrayView&	src, const float* texCoord, const ReferenceParams& params);
173 
174 float			triangleInterpolate			(float v0, float v1, float v2, float x, float y);
175 float			triangleInterpolate			(const tcu::Vec3& v, float x, float y);
176 
177 float			computeLodFromDerivates		(LodMode mode, float dudx, float dudy);
178 float			computeLodFromDerivates		(LodMode mode, float dudx, float dvdx, float dudy, float dvdy);
179 float			computeLodFromDerivates		(LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy);
180 
181 float			computeNonProjectedTriLod	(LodMode mode, const tcu::IVec2& dstSize, deInt32 srcSize, const tcu::Vec3& sq);
182 float			computeNonProjectedTriLod	(LodMode mode, const tcu::IVec2& dstSize, const tcu::IVec2& srcSize, const tcu::Vec3& sq, const tcu::Vec3& tq);
183 float			computeNonProjectedTriLod	(LodMode mode, const tcu::IVec2& dstSize, const tcu::IVec3& srcSize, const tcu::Vec3& sq, const tcu::Vec3& tq, const tcu::Vec3& rq);
184 
185 void			computeQuadTexCoord1D			(std::vector<float>& dst, float left, float right);
186 void			computeQuadTexCoord1DArray		(std::vector<float>& dst, int layerNdx, float left, float right);
187 void			computeQuadTexCoord2D			(std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
188 void			computeQuadTexCoord2DArray		(std::vector<float>& dst, int layerNdx, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
189 void			computeQuadTexCoord3D			(std::vector<float>& dst, const tcu::Vec3& p0, const tcu::Vec3& p1, const tcu::IVec3& dirSwz);
190 void			computeQuadTexCoordCube			(std::vector<float>& dst, tcu::CubeFace face);
191 void			computeQuadTexCoordCube			(std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
192 void			computeQuadTexCoordCubeArray	(std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight, const tcu::Vec2& layerRange);
193 
194 bool			compareImages				(tcu::TestLog& log, const char* name, const char* desc, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
195 bool			compareImages				(tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
196 int				measureAccuracy				(tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, int bestScoreDiff, int worstScoreDiff);
197 
198 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
199 											 const tcu::ConstPixelBufferAccess&	reference,
200 											 const tcu::PixelBufferAccess&		errorMask,
201 											 const tcu::Texture1DView&			src,
202 											 const float*						texCoord,
203 											 const ReferenceParams&				sampleParams,
204 											 const tcu::LookupPrecision&		lookupPrec,
205 											 const tcu::LodPrecision&			lodPrec,
206 											 qpWatchDog*						watchDog);
207 
208 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
209 											 const tcu::ConstPixelBufferAccess&	reference,
210 											 const tcu::PixelBufferAccess&		errorMask,
211 											 const tcu::Texture2DView&			src,
212 											 const float*						texCoord,
213 											 const ReferenceParams&				sampleParams,
214 											 const tcu::LookupPrecision&		lookupPrec,
215 											 const tcu::LodPrecision&			lodPrec,
216 											 qpWatchDog*						watchDog);
217 
218 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
219 											 const tcu::ConstPixelBufferAccess&	reference,
220 											 const tcu::PixelBufferAccess&		errorMask,
221 											 const tcu::TextureCubeView&		src,
222 											 const float*						texCoord,
223 											 const ReferenceParams&				sampleParams,
224 											 const tcu::LookupPrecision&		lookupPrec,
225 											 const tcu::LodPrecision&			lodPrec,
226 											 qpWatchDog*						watchDog);
227 
228 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
229 											 const tcu::ConstPixelBufferAccess&	reference,
230 											 const tcu::PixelBufferAccess&		errorMask,
231 											 const tcu::Texture1DArrayView&		src,
232 											 const float*						texCoord,
233 											 const ReferenceParams&				sampleParams,
234 											 const tcu::LookupPrecision&		lookupPrec,
235 											 const tcu::LodPrecision&			lodPrec,
236 											 qpWatchDog*						watchDog);
237 
238 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
239 											 const tcu::ConstPixelBufferAccess&	reference,
240 											 const tcu::PixelBufferAccess&		errorMask,
241 											 const tcu::Texture2DArrayView&		src,
242 											 const float*						texCoord,
243 											 const ReferenceParams&				sampleParams,
244 											 const tcu::LookupPrecision&		lookupPrec,
245 											 const tcu::LodPrecision&			lodPrec,
246 											 qpWatchDog*						watchDog);
247 
248 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
249 											 const tcu::ConstPixelBufferAccess&	reference,
250 											 const tcu::PixelBufferAccess&		errorMask,
251 											 const tcu::Texture3DView&			src,
252 											 const float*						texCoord,
253 											 const ReferenceParams&				sampleParams,
254 											 const tcu::LookupPrecision&		lookupPrec,
255 											 const tcu::LodPrecision&			lodPrec,
256 											 qpWatchDog*						watchDog);
257 
258 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
259 											 const tcu::ConstPixelBufferAccess&	reference,
260 											 const tcu::PixelBufferAccess&		errorMask,
261 											 const tcu::TextureCubeArrayView&	src,
262 											 const float*						texCoord,
263 											 const ReferenceParams&				sampleParams,
264 											 const tcu::LookupPrecision&		lookupPrec,
265 											 const tcu::IVec4&					coordBits,
266 											 const tcu::LodPrecision&			lodPrec,
267 											 qpWatchDog*						watchDog);
268 
269 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
270 											 const tcu::ConstPixelBufferAccess&	result,
271 											 const tcu::Texture1DView&			src,
272 											 const float*						texCoord,
273 											 const ReferenceParams&				sampleParams,
274 											 const tcu::LookupPrecision&		lookupPrec,
275 											 const tcu::LodPrecision&			lodPrec,
276 											 const tcu::PixelFormat&			pixelFormat);
277 
278 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
279 											 const tcu::ConstPixelBufferAccess&	result,
280 											 const tcu::Texture2DView&			src,
281 											 const float*						texCoord,
282 											 const ReferenceParams&				sampleParams,
283 											 const tcu::LookupPrecision&		lookupPrec,
284 											 const tcu::LodPrecision&			lodPrec,
285 											 const tcu::PixelFormat&			pixelFormat);
286 
287 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
288 											 const tcu::ConstPixelBufferAccess&	result,
289 											 const tcu::TextureCubeView&		src,
290 											 const float*						texCoord,
291 											 const ReferenceParams&				sampleParams,
292 											 const tcu::LookupPrecision&		lookupPrec,
293 											 const tcu::LodPrecision&			lodPrec,
294 											 const tcu::PixelFormat&			pixelFormat);
295 
296 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
297 											 const tcu::ConstPixelBufferAccess&	result,
298 											 const tcu::Texture1DArrayView&		src,
299 											 const float*						texCoord,
300 											 const ReferenceParams&				sampleParams,
301 											 const tcu::LookupPrecision&		lookupPrec,
302 											 const tcu::LodPrecision&			lodPrec,
303 											 const tcu::PixelFormat&			pixelFormat);
304 
305 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
306 											 const tcu::ConstPixelBufferAccess&	result,
307 											 const tcu::Texture2DArrayView&		src,
308 											 const float*						texCoord,
309 											 const ReferenceParams&				sampleParams,
310 											 const tcu::LookupPrecision&		lookupPrec,
311 											 const tcu::LodPrecision&			lodPrec,
312 											 const tcu::PixelFormat&			pixelFormat);
313 
314 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
315 											 const tcu::ConstPixelBufferAccess&	result,
316 											 const tcu::Texture3DView&			src,
317 											 const float*						texCoord,
318 											 const ReferenceParams&				sampleParams,
319 											 const tcu::LookupPrecision&		lookupPrec,
320 											 const tcu::LodPrecision&			lodPrec,
321 											 const tcu::PixelFormat&			pixelFormat);
322 
323 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
324 											 const tcu::ConstPixelBufferAccess&	result,
325 											 const tcu::TextureCubeArrayView&	src,
326 											 const float*						texCoord,
327 											 const ReferenceParams&				sampleParams,
328 											 const tcu::LookupPrecision&		lookupPrec,
329 											 const tcu::IVec4&					coordBits,
330 											 const tcu::LodPrecision&			lodPrec,
331 											 const tcu::PixelFormat&			pixelFormat);
332 
333 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
334 											 const tcu::ConstPixelBufferAccess&	reference,
335 											 const tcu::PixelBufferAccess&		errorMask,
336 											 const tcu::Texture2DView&			src,
337 											 const float*						texCoord,
338 											 const ReferenceParams&				sampleParams,
339 											 const tcu::TexComparePrecision&	comparePrec,
340 											 const tcu::LodPrecision&			lodPrec,
341 											 const tcu::Vec3&					nonShadowThreshold);
342 
343 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
344 											 const tcu::ConstPixelBufferAccess&	reference,
345 											 const tcu::PixelBufferAccess&		errorMask,
346 											 const tcu::TextureCubeView&		src,
347 											 const float*						texCoord,
348 											 const ReferenceParams&				sampleParams,
349 											 const tcu::TexComparePrecision&	comparePrec,
350 											 const tcu::LodPrecision&			lodPrec,
351 											 const tcu::Vec3&					nonShadowThreshold);
352 
353 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
354 											 const tcu::ConstPixelBufferAccess&	reference,
355 											 const tcu::PixelBufferAccess&		errorMask,
356 											 const tcu::Texture2DArrayView&		src,
357 											 const float*						texCoord,
358 											 const ReferenceParams&				sampleParams,
359 											 const tcu::TexComparePrecision&	comparePrec,
360 											 const tcu::LodPrecision&			lodPrec,
361 											 const tcu::Vec3&					nonShadowThreshold);
362 
363 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
364 											 const tcu::ConstPixelBufferAccess&	reference,
365 											 const tcu::PixelBufferAccess&		errorMask,
366 											 const tcu::Texture1DView&			src,
367 											 const float*						texCoord,
368 											 const ReferenceParams&				sampleParams,
369 											 const tcu::TexComparePrecision&	comparePrec,
370 											 const tcu::LodPrecision&			lodPrec,
371 											 const tcu::Vec3&					nonShadowThreshold);
372 
373 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
374 											 const tcu::ConstPixelBufferAccess&	reference,
375 											 const tcu::PixelBufferAccess&		errorMask,
376 											 const tcu::Texture1DArrayView&		src,
377 											 const float*						texCoord,
378 											 const ReferenceParams&				sampleParams,
379 											 const tcu::TexComparePrecision&	comparePrec,
380 											 const tcu::LodPrecision&			lodPrec,
381 											 const tcu::Vec3&					nonShadowThreshold);
382 
383 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
384 											 const tcu::ConstPixelBufferAccess&	reference,
385 											 const tcu::PixelBufferAccess&		errorMask,
386 											 const tcu::TextureCubeArrayView&	src,
387 											 const float*						texCoord,
388 											 const ReferenceParams&				sampleParams,
389 											 const tcu::TexComparePrecision&	comparePrec,
390 											 const tcu::LodPrecision&			lodPrec,
391 											 const tcu::Vec3&					nonShadowThreshold);
392 
getBitsVec(const tcu::PixelFormat & format)393 inline tcu::IVec4 getBitsVec (const tcu::PixelFormat& format)
394 {
395 	return tcu::IVec4(format.redBits, format.greenBits, format.blueBits, format.alphaBits);
396 }
397 
getCompareMask(const tcu::PixelFormat & format)398 inline tcu::BVec4 getCompareMask (const tcu::PixelFormat& format)
399 {
400 	return tcu::BVec4(format.redBits	> 0,
401 					  format.greenBits	> 0,
402 					  format.blueBits	> 0,
403 					  format.alphaBits	> 0);
404 }
405 
406 
407 // Mipmap generation comparison.
408 
409 struct GenMipmapPrecision
410 {
411 	tcu::IVec3			filterBits;			//!< Bits in filtering parameters (fixed-point).
412 	tcu::Vec4			colorThreshold;		//!< Threshold for color value comparison.
413 	tcu::BVec4			colorMask;			//!< Color channel comparison mask.
414 };
415 
416 qpTestResult	compareGenMipmapResult		(tcu::TestLog& log, const tcu::Texture2D& resultTexture, const tcu::Texture2D& level0Reference, const GenMipmapPrecision& precision);
417 qpTestResult	compareGenMipmapResult		(tcu::TestLog& log, const tcu::TextureCube& resultTexture, const tcu::TextureCube& level0Reference, const GenMipmapPrecision& precision);
418 
419 // Utility for logging texture gradient ranges.
420 struct LogGradientFmt
421 {
LogGradientFmtglu::TextureTestUtil::LogGradientFmt422 	LogGradientFmt (const tcu::Vec4* min_, const tcu::Vec4* max_) : valueMin(min_), valueMax(max_) {}
423 	const tcu::Vec4* valueMin;
424 	const tcu::Vec4* valueMax;
425 };
426 
427 std::ostream&			operator<<		(std::ostream& str, const LogGradientFmt& fmt);
formatGradient(const tcu::Vec4 * minVal,const tcu::Vec4 * maxVal)428 inline LogGradientFmt	formatGradient	(const tcu::Vec4* minVal, const tcu::Vec4* maxVal) { return LogGradientFmt(minVal, maxVal); }
429 
430 } // TextureTestUtil
431 } // glu
432 
433 #endif // _GLUTEXTURETESTUTIL_HPP
434