Home | History | Annotate | Download | only in opengl
      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 
     86 	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 {
    121 	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 	{
    130 	}
    131 
    132 	ReferenceParams (TextureType texType_, const tcu::Sampler& sampler_, LodMode lodMode_ = LODMODE_EXACT)
    133 		: RenderParams	(texType_)
    134 		, sampler		(sampler_)
    135 		, lodMode		(lodMode_)
    136 		, minLod		(-1000.0f)
    137 		, maxLod		(1000.0f)
    138 		, baseLevel		(0)
    139 		, maxLevel		(1000)
    140 	{
    141 	}
    142 
    143 	tcu::Sampler		sampler;
    144 	LodMode				lodMode;
    145 	float				minLod;
    146 	float				maxLod;
    147 	int					baseLevel;
    148 	int					maxLevel;
    149 };
    150 
    151 
    152 SamplerType		getSamplerType		(tcu::TextureFormat format);
    153 SamplerType		getFetchSamplerType	(tcu::TextureFormat format);
    154 
    155 // Similar to sampleTexture() except uses texelFetch.
    156 void			fetchTexture				(const tcu::SurfaceAccess& dst, const tcu::ConstPixelBufferAccess& src, const float* texCoord, const tcu::Vec4& colorScale, const tcu::Vec4& colorBias);
    157 
    158 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture2DView&		src, const float* texCoord, const ReferenceParams& params);
    159 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::TextureCubeView&		src, const float* texCoord, const ReferenceParams& params);
    160 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture2DArrayView&	src, const float* texCoord, const ReferenceParams& params);
    161 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture3DView&		src, const float* texCoord, const ReferenceParams& params);
    162 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::TextureCubeArrayView&	src, const float* texCoord, const ReferenceParams& params);
    163 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture1DView&		src, const float* texCoord, const ReferenceParams& params);
    164 void			sampleTexture				(const tcu::SurfaceAccess& dst, const tcu::Texture1DArrayView&	src, const float* texCoord, const ReferenceParams& params);
    165 
    166 float			computeLodFromDerivates		(LodMode mode, float dudx, float dudy);
    167 float			computeLodFromDerivates		(LodMode mode, float dudx, float dvdx, float dudy, float dvdy);
    168 float			computeLodFromDerivates		(LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy);
    169 
    170 void			computeQuadTexCoord1D			(std::vector<float>& dst, float left, float right);
    171 void			computeQuadTexCoord1DArray		(std::vector<float>& dst, int layerNdx, float left, float right);
    172 void			computeQuadTexCoord2D			(std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
    173 void			computeQuadTexCoord2DArray		(std::vector<float>& dst, int layerNdx, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
    174 void			computeQuadTexCoord3D			(std::vector<float>& dst, const tcu::Vec3& p0, const tcu::Vec3& p1, const tcu::IVec3& dirSwz);
    175 void			computeQuadTexCoordCube			(std::vector<float>& dst, tcu::CubeFace face);
    176 void			computeQuadTexCoordCube			(std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
    177 void			computeQuadTexCoordCubeArray	(std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight, const tcu::Vec2& layerRange);
    178 
    179 bool			compareImages				(tcu::TestLog& log, const char* name, const char* desc, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
    180 bool			compareImages				(tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
    181 int				measureAccuracy				(tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, int bestScoreDiff, int worstScoreDiff);
    182 
    183 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
    184 											 const tcu::ConstPixelBufferAccess&	reference,
    185 											 const tcu::PixelBufferAccess&		errorMask,
    186 											 const tcu::Texture1DView&			src,
    187 											 const float*						texCoord,
    188 											 const ReferenceParams&				sampleParams,
    189 											 const tcu::LookupPrecision&		lookupPrec,
    190 											 const tcu::LodPrecision&			lodPrec,
    191 											 qpWatchDog*						watchDog);
    192 
    193 int				computeTextureLookupDiff	(const tcu::ConstPixelBufferAccess&	result,
    194 											 const tcu::ConstPixelBufferAccess&	reference,
    195 											 const tcu::PixelBufferAccess&		errorMask,
    196 											 const tcu::Texture2DView&			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::TextureCubeView&		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::Texture1DArrayView&		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::Texture2DArrayView&		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::Texture3DView&			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::TextureCubeArrayView&	src,
    247 											 const float*						texCoord,
    248 											 const ReferenceParams&				sampleParams,
    249 											 const tcu::LookupPrecision&		lookupPrec,
    250 											 const tcu::IVec4&					coordBits,
    251 											 const tcu::LodPrecision&			lodPrec,
    252 											 qpWatchDog*						watchDog);
    253 
    254 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    255 											 const tcu::ConstPixelBufferAccess&	result,
    256 											 const tcu::Texture1DView&			src,
    257 											 const float*						texCoord,
    258 											 const ReferenceParams&				sampleParams,
    259 											 const tcu::LookupPrecision&		lookupPrec,
    260 											 const tcu::LodPrecision&			lodPrec,
    261 											 const tcu::PixelFormat&			pixelFormat);
    262 
    263 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    264 											 const tcu::ConstPixelBufferAccess&	result,
    265 											 const tcu::Texture2DView&			src,
    266 											 const float*						texCoord,
    267 											 const ReferenceParams&				sampleParams,
    268 											 const tcu::LookupPrecision&		lookupPrec,
    269 											 const tcu::LodPrecision&			lodPrec,
    270 											 const tcu::PixelFormat&			pixelFormat);
    271 
    272 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    273 											 const tcu::ConstPixelBufferAccess&	result,
    274 											 const tcu::TextureCubeView&		src,
    275 											 const float*						texCoord,
    276 											 const ReferenceParams&				sampleParams,
    277 											 const tcu::LookupPrecision&		lookupPrec,
    278 											 const tcu::LodPrecision&			lodPrec,
    279 											 const tcu::PixelFormat&			pixelFormat);
    280 
    281 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    282 											 const tcu::ConstPixelBufferAccess&	result,
    283 											 const tcu::Texture1DArrayView&		src,
    284 											 const float*						texCoord,
    285 											 const ReferenceParams&				sampleParams,
    286 											 const tcu::LookupPrecision&		lookupPrec,
    287 											 const tcu::LodPrecision&			lodPrec,
    288 											 const tcu::PixelFormat&			pixelFormat);
    289 
    290 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    291 											 const tcu::ConstPixelBufferAccess&	result,
    292 											 const tcu::Texture2DArrayView&		src,
    293 											 const float*						texCoord,
    294 											 const ReferenceParams&				sampleParams,
    295 											 const tcu::LookupPrecision&		lookupPrec,
    296 											 const tcu::LodPrecision&			lodPrec,
    297 											 const tcu::PixelFormat&			pixelFormat);
    298 
    299 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    300 											 const tcu::ConstPixelBufferAccess&	result,
    301 											 const tcu::Texture3DView&			src,
    302 											 const float*						texCoord,
    303 											 const ReferenceParams&				sampleParams,
    304 											 const tcu::LookupPrecision&		lookupPrec,
    305 											 const tcu::LodPrecision&			lodPrec,
    306 											 const tcu::PixelFormat&			pixelFormat);
    307 
    308 bool			verifyTextureResult			(tcu::TestContext&					testCtx,
    309 											 const tcu::ConstPixelBufferAccess&	result,
    310 											 const tcu::TextureCubeArrayView&	src,
    311 											 const float*						texCoord,
    312 											 const ReferenceParams&				sampleParams,
    313 											 const tcu::LookupPrecision&		lookupPrec,
    314 											 const tcu::IVec4&					coordBits,
    315 											 const tcu::LodPrecision&			lodPrec,
    316 											 const tcu::PixelFormat&			pixelFormat);
    317 
    318 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
    319 											 const tcu::ConstPixelBufferAccess&	reference,
    320 											 const tcu::PixelBufferAccess&		errorMask,
    321 											 const tcu::Texture2DView&			src,
    322 											 const float*						texCoord,
    323 											 const ReferenceParams&				sampleParams,
    324 											 const tcu::TexComparePrecision&	comparePrec,
    325 											 const tcu::LodPrecision&			lodPrec,
    326 											 const tcu::Vec3&					nonShadowThreshold);
    327 
    328 int				computeTextureCompareDiff	(const tcu::ConstPixelBufferAccess&	result,
    329 											 const tcu::ConstPixelBufferAccess&	reference,
    330 											 const tcu::PixelBufferAccess&		errorMask,
    331 											 const tcu::TextureCubeView&		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::Texture2DArrayView&		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 
    349 inline tcu::IVec4 getBitsVec (const tcu::PixelFormat& format)
    350 {
    351 	return tcu::IVec4(format.redBits, format.greenBits, format.blueBits, format.alphaBits);
    352 }
    353 
    354 inline tcu::BVec4 getCompareMask (const tcu::PixelFormat& format)
    355 {
    356 	return tcu::BVec4(format.redBits	> 0,
    357 					  format.greenBits	> 0,
    358 					  format.blueBits	> 0,
    359 					  format.alphaBits	> 0);
    360 }
    361 
    362 
    363 // Mipmap generation comparison.
    364 
    365 struct GenMipmapPrecision
    366 {
    367 	tcu::IVec3			filterBits;			//!< Bits in filtering parameters (fixed-point).
    368 	tcu::Vec4			colorThreshold;		//!< Threshold for color value comparison.
    369 	tcu::BVec4			colorMask;			//!< Color channel comparison mask.
    370 };
    371 
    372 qpTestResult	compareGenMipmapResult		(tcu::TestLog& log, const tcu::Texture2D& resultTexture, const tcu::Texture2D& level0Reference, const GenMipmapPrecision& precision);
    373 qpTestResult	compareGenMipmapResult		(tcu::TestLog& log, const tcu::TextureCube& resultTexture, const tcu::TextureCube& level0Reference, const GenMipmapPrecision& precision);
    374 
    375 // Utility for logging texture gradient ranges.
    376 struct LogGradientFmt
    377 {
    378 	LogGradientFmt (const tcu::Vec4* min_, const tcu::Vec4* max_) : valueMin(min_), valueMax(max_) {}
    379 	const tcu::Vec4* valueMin;
    380 	const tcu::Vec4* valueMax;
    381 };
    382 
    383 std::ostream&			operator<<		(std::ostream& str, const LogGradientFmt& fmt);
    384 inline LogGradientFmt	formatGradient	(const tcu::Vec4* minVal, const tcu::Vec4* maxVal) { return LogGradientFmt(minVal, maxVal); }
    385 
    386 } // TextureTestUtil
    387 } // glu
    388 
    389 #endif // _GLUTEXTURETESTUTIL_HPP
    390