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 , unnormal (false) 130 { 131 } 132 133 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 computeLodFromDerivates (LodMode mode, float dudx, float dudy); 170 float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dudy, float dvdy); 171 float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy); 172 173 void computeQuadTexCoord1D (std::vector<float>& dst, float left, float right); 174 void computeQuadTexCoord1DArray (std::vector<float>& dst, int layerNdx, float left, float right); 175 void computeQuadTexCoord2D (std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight); 176 void computeQuadTexCoord2DArray (std::vector<float>& dst, int layerNdx, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight); 177 void computeQuadTexCoord3D (std::vector<float>& dst, const tcu::Vec3& p0, const tcu::Vec3& p1, const tcu::IVec3& dirSwz); 178 void computeQuadTexCoordCube (std::vector<float>& dst, tcu::CubeFace face); 179 void computeQuadTexCoordCube (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight); 180 void computeQuadTexCoordCubeArray (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight, const tcu::Vec2& layerRange); 181 182 bool compareImages (tcu::TestLog& log, const char* name, const char* desc, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold); 183 bool compareImages (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold); 184 int measureAccuracy (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, int bestScoreDiff, int worstScoreDiff); 185 186 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 187 const tcu::ConstPixelBufferAccess& reference, 188 const tcu::PixelBufferAccess& errorMask, 189 const tcu::Texture1DView& src, 190 const float* texCoord, 191 const ReferenceParams& sampleParams, 192 const tcu::LookupPrecision& lookupPrec, 193 const tcu::LodPrecision& lodPrec, 194 qpWatchDog* watchDog); 195 196 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 197 const tcu::ConstPixelBufferAccess& reference, 198 const tcu::PixelBufferAccess& errorMask, 199 const tcu::Texture2DView& src, 200 const float* texCoord, 201 const ReferenceParams& sampleParams, 202 const tcu::LookupPrecision& lookupPrec, 203 const tcu::LodPrecision& lodPrec, 204 qpWatchDog* watchDog); 205 206 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 207 const tcu::ConstPixelBufferAccess& reference, 208 const tcu::PixelBufferAccess& errorMask, 209 const tcu::TextureCubeView& src, 210 const float* texCoord, 211 const ReferenceParams& sampleParams, 212 const tcu::LookupPrecision& lookupPrec, 213 const tcu::LodPrecision& lodPrec, 214 qpWatchDog* watchDog); 215 216 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 217 const tcu::ConstPixelBufferAccess& reference, 218 const tcu::PixelBufferAccess& errorMask, 219 const tcu::Texture1DArrayView& src, 220 const float* texCoord, 221 const ReferenceParams& sampleParams, 222 const tcu::LookupPrecision& lookupPrec, 223 const tcu::LodPrecision& lodPrec, 224 qpWatchDog* watchDog); 225 226 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 227 const tcu::ConstPixelBufferAccess& reference, 228 const tcu::PixelBufferAccess& errorMask, 229 const tcu::Texture2DArrayView& src, 230 const float* texCoord, 231 const ReferenceParams& sampleParams, 232 const tcu::LookupPrecision& lookupPrec, 233 const tcu::LodPrecision& lodPrec, 234 qpWatchDog* watchDog); 235 236 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 237 const tcu::ConstPixelBufferAccess& reference, 238 const tcu::PixelBufferAccess& errorMask, 239 const tcu::Texture3DView& src, 240 const float* texCoord, 241 const ReferenceParams& sampleParams, 242 const tcu::LookupPrecision& lookupPrec, 243 const tcu::LodPrecision& lodPrec, 244 qpWatchDog* watchDog); 245 246 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result, 247 const tcu::ConstPixelBufferAccess& reference, 248 const tcu::PixelBufferAccess& errorMask, 249 const tcu::TextureCubeArrayView& src, 250 const float* texCoord, 251 const ReferenceParams& sampleParams, 252 const tcu::LookupPrecision& lookupPrec, 253 const tcu::IVec4& coordBits, 254 const tcu::LodPrecision& lodPrec, 255 qpWatchDog* watchDog); 256 257 bool verifyTextureResult (tcu::TestContext& testCtx, 258 const tcu::ConstPixelBufferAccess& result, 259 const tcu::Texture1DView& src, 260 const float* texCoord, 261 const ReferenceParams& sampleParams, 262 const tcu::LookupPrecision& lookupPrec, 263 const tcu::LodPrecision& lodPrec, 264 const tcu::PixelFormat& pixelFormat); 265 266 bool verifyTextureResult (tcu::TestContext& testCtx, 267 const tcu::ConstPixelBufferAccess& result, 268 const tcu::Texture2DView& src, 269 const float* texCoord, 270 const ReferenceParams& sampleParams, 271 const tcu::LookupPrecision& lookupPrec, 272 const tcu::LodPrecision& lodPrec, 273 const tcu::PixelFormat& pixelFormat); 274 275 bool verifyTextureResult (tcu::TestContext& testCtx, 276 const tcu::ConstPixelBufferAccess& result, 277 const tcu::TextureCubeView& src, 278 const float* texCoord, 279 const ReferenceParams& sampleParams, 280 const tcu::LookupPrecision& lookupPrec, 281 const tcu::LodPrecision& lodPrec, 282 const tcu::PixelFormat& pixelFormat); 283 284 bool verifyTextureResult (tcu::TestContext& testCtx, 285 const tcu::ConstPixelBufferAccess& result, 286 const tcu::Texture1DArrayView& src, 287 const float* texCoord, 288 const ReferenceParams& sampleParams, 289 const tcu::LookupPrecision& lookupPrec, 290 const tcu::LodPrecision& lodPrec, 291 const tcu::PixelFormat& pixelFormat); 292 293 bool verifyTextureResult (tcu::TestContext& testCtx, 294 const tcu::ConstPixelBufferAccess& result, 295 const tcu::Texture2DArrayView& src, 296 const float* texCoord, 297 const ReferenceParams& sampleParams, 298 const tcu::LookupPrecision& lookupPrec, 299 const tcu::LodPrecision& lodPrec, 300 const tcu::PixelFormat& pixelFormat); 301 302 bool verifyTextureResult (tcu::TestContext& testCtx, 303 const tcu::ConstPixelBufferAccess& result, 304 const tcu::Texture3DView& src, 305 const float* texCoord, 306 const ReferenceParams& sampleParams, 307 const tcu::LookupPrecision& lookupPrec, 308 const tcu::LodPrecision& lodPrec, 309 const tcu::PixelFormat& pixelFormat); 310 311 bool verifyTextureResult (tcu::TestContext& testCtx, 312 const tcu::ConstPixelBufferAccess& result, 313 const tcu::TextureCubeArrayView& src, 314 const float* texCoord, 315 const ReferenceParams& sampleParams, 316 const tcu::LookupPrecision& lookupPrec, 317 const tcu::IVec4& coordBits, 318 const tcu::LodPrecision& lodPrec, 319 const tcu::PixelFormat& pixelFormat); 320 321 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result, 322 const tcu::ConstPixelBufferAccess& reference, 323 const tcu::PixelBufferAccess& errorMask, 324 const tcu::Texture2DView& src, 325 const float* texCoord, 326 const ReferenceParams& sampleParams, 327 const tcu::TexComparePrecision& comparePrec, 328 const tcu::LodPrecision& lodPrec, 329 const tcu::Vec3& nonShadowThreshold); 330 331 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result, 332 const tcu::ConstPixelBufferAccess& reference, 333 const tcu::PixelBufferAccess& errorMask, 334 const tcu::TextureCubeView& src, 335 const float* texCoord, 336 const ReferenceParams& sampleParams, 337 const tcu::TexComparePrecision& comparePrec, 338 const tcu::LodPrecision& lodPrec, 339 const tcu::Vec3& nonShadowThreshold); 340 341 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result, 342 const tcu::ConstPixelBufferAccess& reference, 343 const tcu::PixelBufferAccess& errorMask, 344 const tcu::Texture2DArrayView& src, 345 const float* texCoord, 346 const ReferenceParams& sampleParams, 347 const tcu::TexComparePrecision& comparePrec, 348 const tcu::LodPrecision& lodPrec, 349 const tcu::Vec3& nonShadowThreshold); 350 351 352 inline tcu::IVec4 getBitsVec (const tcu::PixelFormat& format) 353 { 354 return tcu::IVec4(format.redBits, format.greenBits, format.blueBits, format.alphaBits); 355 } 356 357 inline tcu::BVec4 getCompareMask (const tcu::PixelFormat& format) 358 { 359 return tcu::BVec4(format.redBits > 0, 360 format.greenBits > 0, 361 format.blueBits > 0, 362 format.alphaBits > 0); 363 } 364 365 366 // Mipmap generation comparison. 367 368 struct GenMipmapPrecision 369 { 370 tcu::IVec3 filterBits; //!< Bits in filtering parameters (fixed-point). 371 tcu::Vec4 colorThreshold; //!< Threshold for color value comparison. 372 tcu::BVec4 colorMask; //!< Color channel comparison mask. 373 }; 374 375 qpTestResult compareGenMipmapResult (tcu::TestLog& log, const tcu::Texture2D& resultTexture, const tcu::Texture2D& level0Reference, const GenMipmapPrecision& precision); 376 qpTestResult compareGenMipmapResult (tcu::TestLog& log, const tcu::TextureCube& resultTexture, const tcu::TextureCube& level0Reference, const GenMipmapPrecision& precision); 377 378 // Utility for logging texture gradient ranges. 379 struct LogGradientFmt 380 { 381 LogGradientFmt (const tcu::Vec4* min_, const tcu::Vec4* max_) : valueMin(min_), valueMax(max_) {} 382 const tcu::Vec4* valueMin; 383 const tcu::Vec4* valueMax; 384 }; 385 386 std::ostream& operator<< (std::ostream& str, const LogGradientFmt& fmt); 387 inline LogGradientFmt formatGradient (const tcu::Vec4* minVal, const tcu::Vec4* maxVal) { return LogGradientFmt(minVal, maxVal); } 388 389 } // TextureTestUtil 390 } // glu 391 392 #endif // _GLUTEXTURETESTUTIL_HPP 393