1 #ifndef _GLSTEXTURETESTUTIL_HPP
2 #define _GLSTEXTURETESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL (ES) Module
5 * -----------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Texture test utilities.
26 * + Quads consist of 2 triangles, rendered using explicit indices.
27 * + All TextureTestUtil functions and classes expect texture coordinates
28 * for quads to be specified in order (-1, -1), (-1, 1), (1, -1), (1, 1).
29 *//*--------------------------------------------------------------------*/
31 #include "tcuDefs.hpp"
32 #include "tcuTexture.hpp"
33 #include "tcuSurface.hpp"
34 #include "tcuPixelFormat.hpp"
35 #include "tcuRenderTarget.hpp"
36 #include "tcuTestContext.hpp"
37 #include "tcuTestLog.hpp"
38 #include "tcuCompressedTexture.hpp"
39 #include "tcuTextureUtil.hpp"
41 #include "gluShaderProgram.hpp"
42 #include "gluShaderUtil.hpp"
51 struct LookupPrecision;
53 struct TexComparePrecision;
60 namespace TextureTestUtil
69 TEXTURETYPE_CUBE_ARRAY,
84 SAMPLERTYPE_FETCH_FLOAT,
85 SAMPLERTYPE_FETCH_INT,
86 SAMPLERTYPE_FETCH_UINT,
91 SamplerType getSamplerType (tcu::TextureFormat format);
92 SamplerType getFetchSamplerType (tcu::TextureFormat format);
100 LOG_PROGRAMS = (1<<2),
101 LOG_UNIFORMS = (1<<3),
103 LOG_ALL = LOG_PROGRAMS|LOG_UNIFORMS
106 RenderParams (TextureType texType_)
108 , samplerType (SAMPLERTYPE_FLOAT)
118 TextureType texType; //!< Texture type.
119 SamplerType samplerType; //!< Sampler type.
120 deUint32 flags; //!< Feature flags.
121 tcu::Vec4 w; //!< w coordinates for quad vertices.
122 float bias; //!< User-supplied bias.
123 float ref; //!< Reference value for shadow lookups.
125 // color = lookup() * scale + bias
126 tcu::Vec4 colorScale; //!< Scale for texture color values.
127 tcu::Vec4 colorBias; //!< Bias for texture color values.
132 PROGRAM_2D_FLOAT = 0,
137 PROGRAM_2D_FLOAT_BIAS,
139 PROGRAM_2D_UINT_BIAS,
140 PROGRAM_2D_SHADOW_BIAS,
147 PROGRAM_1D_FLOAT_BIAS,
149 PROGRAM_1D_UINT_BIAS,
150 PROGRAM_1D_SHADOW_BIAS,
157 PROGRAM_CUBE_FLOAT_BIAS,
158 PROGRAM_CUBE_INT_BIAS,
159 PROGRAM_CUBE_UINT_BIAS,
160 PROGRAM_CUBE_SHADOW_BIAS,
162 PROGRAM_1D_ARRAY_FLOAT,
163 PROGRAM_1D_ARRAY_INT,
164 PROGRAM_1D_ARRAY_UINT,
165 PROGRAM_1D_ARRAY_SHADOW,
167 PROGRAM_2D_ARRAY_FLOAT,
168 PROGRAM_2D_ARRAY_INT,
169 PROGRAM_2D_ARRAY_UINT,
170 PROGRAM_2D_ARRAY_SHADOW,
176 PROGRAM_3D_FLOAT_BIAS,
178 PROGRAM_3D_UINT_BIAS,
180 PROGRAM_CUBE_ARRAY_FLOAT,
181 PROGRAM_CUBE_ARRAY_INT,
182 PROGRAM_CUBE_ARRAY_UINT,
183 PROGRAM_CUBE_ARRAY_SHADOW,
185 PROGRAM_BUFFER_FLOAT,
195 ProgramLibrary (const glu::RenderContext& context, tcu::TestLog& log, glu::GLSLVersion glslVersion, glu::Precision texCoordPrecision);
196 ~ProgramLibrary (void);
198 glu::ShaderProgram* getProgram (Program program);
202 ProgramLibrary (const ProgramLibrary& other);
203 ProgramLibrary& operator= (const ProgramLibrary& other);
205 const glu::RenderContext& m_context;
207 glu::GLSLVersion m_glslVersion;
208 glu::Precision m_texCoordPrecision;
209 std::map<Program, glu::ShaderProgram*> m_programs;
212 class TextureRenderer
215 TextureRenderer (const glu::RenderContext& context, tcu::TestLog& log, glu::GLSLVersion glslVersion, glu::Precision texCoordPrecision);
216 ~TextureRenderer (void);
218 void clear (void); //!< Frees allocated resources. Destructor will call clear() as well.
220 void renderQuad (int texUnit, const float* texCoord, TextureType texType);
221 void renderQuad (int texUnit, const float* texCoord, const RenderParams& params);
224 TextureRenderer (const TextureRenderer& other);
225 TextureRenderer& operator= (const TextureRenderer& other);
227 const glu::RenderContext& m_renderCtx;
229 ProgramLibrary m_programLibrary;
240 RandomViewport (const tcu::RenderTarget& renderTarget, int preferredWidth, int preferredHeight, deUint32 seed);
243 inline tcu::RGBA toRGBAMasked (const tcu::Vec4& v, deUint8 mask)
245 return tcu::RGBA((mask&tcu::RGBA::RED_MASK) ? tcu::floatToU8(v.x()) : 0,
246 (mask&tcu::RGBA::GREEN_MASK) ? tcu::floatToU8(v.y()) : 0,
247 (mask&tcu::RGBA::BLUE_MASK) ? tcu::floatToU8(v.z()) : 0,
248 (mask&tcu::RGBA::ALPHA_MASK) ? tcu::floatToU8(v.w()) : 0xFF); //!< \note Alpha defaults to full saturation when reading masked format
251 // \todo[jarkko 2015-05-19] remove this
252 inline tcu::Vec4 toVec4 (const tcu::RGBA& c)
257 inline deUint8 getColorMask (const tcu::PixelFormat& format)
259 return (deUint8)((format.redBits ? tcu::RGBA::RED_MASK : 0) |
260 (format.greenBits ? tcu::RGBA::GREEN_MASK : 0) |
261 (format.blueBits ? tcu::RGBA::BLUE_MASK : 0) |
262 (format.alphaBits ? tcu::RGBA::ALPHA_MASK : 0));
265 inline tcu::IVec4 getBitsVec (const tcu::PixelFormat& format)
267 return tcu::IVec4(format.redBits, format.greenBits, format.blueBits, format.alphaBits);
270 inline tcu::BVec4 getCompareMask (const tcu::PixelFormat& format)
272 return tcu::BVec4(format.redBits > 0,
273 format.greenBits > 0,
275 format.alphaBits > 0);
278 // \todo [2012-02-09 pyry] Move to tcuSurfaceAccess?
282 SurfaceAccess (tcu::Surface& surface, const tcu::PixelFormat& colorFmt);
283 SurfaceAccess (tcu::Surface& surface, const tcu::PixelFormat& colorFmt, int x, int y, int width, int height);
284 SurfaceAccess (const SurfaceAccess& parent, int x, int y, int width, int height);
286 int getWidth (void) const { return m_width; }
287 int getHeight (void) const { return m_height; }
289 void setPixel (const tcu::Vec4& color, int x, int y) const;
292 mutable tcu::Surface* m_surface;
300 inline void SurfaceAccess::setPixel (const tcu::Vec4& color, int x, int y) const
302 DE_ASSERT(de::inBounds(x, 0, m_width) && de::inBounds(y, 0, m_height));
303 m_surface->setPixel(m_x+x, m_y+y, toRGBAMasked(color, m_colorMask));
308 LODMODE_EXACT = 0, //!< Ideal lod computation.
309 LODMODE_MIN_BOUND, //!< Use estimation range minimum bound.
310 LODMODE_MAX_BOUND, //!< Use estimation range maximum bound.
315 struct ReferenceParams : public RenderParams
317 ReferenceParams (TextureType texType_)
318 : RenderParams (texType_)
320 , lodMode (LODMODE_EXACT)
328 ReferenceParams (TextureType texType_, const tcu::Sampler& sampler_, LodMode lodMode_ = LODMODE_EXACT)
329 : RenderParams (texType_)
339 tcu::Sampler sampler;
347 // Similar to sampleTexture() except uses texelFetch.
348 void fetchTexture (const SurfaceAccess& dst, const tcu::ConstPixelBufferAccess& src, const float* texCoord, const tcu::Vec4& colorScale, const tcu::Vec4& colorBias);
350 void sampleTexture (const SurfaceAccess& dst, const tcu::Texture2DView& src, const float* texCoord, const ReferenceParams& params);
351 void sampleTexture (const SurfaceAccess& dst, const tcu::TextureCubeView& src, const float* texCoord, const ReferenceParams& params);
352 void sampleTexture (const SurfaceAccess& dst, const tcu::Texture2DArrayView& src, const float* texCoord, const ReferenceParams& params);
353 void sampleTexture (const SurfaceAccess& dst, const tcu::Texture3DView& src, const float* texCoord, const ReferenceParams& params);
354 void sampleTexture (const SurfaceAccess& dst, const tcu::TextureCubeArrayView& src, const float* texCoord, const ReferenceParams& params);
355 void sampleTexture (const SurfaceAccess& dst, const tcu::Texture1DView& src, const float* texCoord, const ReferenceParams& params);
356 void sampleTexture (const SurfaceAccess& dst, const tcu::Texture1DArrayView& src, const float* texCoord, const ReferenceParams& params);
358 float computeLodFromDerivates (LodMode mode, float dudx, float dudy);
359 float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dudy, float dvdy);
360 float computeLodFromDerivates (LodMode mode, float dudx, float dvdx, float dwdx, float dudy, float dvdy, float dwdy);
362 void computeQuadTexCoord1D (std::vector<float>& dst, float left, float right);
363 void computeQuadTexCoord1DArray (std::vector<float>& dst, int layerNdx, float left, float right);
364 void computeQuadTexCoord2D (std::vector<float>& dst, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
365 void computeQuadTexCoord2DArray (std::vector<float>& dst, int layerNdx, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
366 void computeQuadTexCoord3D (std::vector<float>& dst, const tcu::Vec3& p0, const tcu::Vec3& p1, const tcu::IVec3& dirSwz);
367 void computeQuadTexCoordCube (std::vector<float>& dst, tcu::CubeFace face);
368 void computeQuadTexCoordCube (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight);
369 void computeQuadTexCoordCubeArray (std::vector<float>& dst, tcu::CubeFace face, const tcu::Vec2& bottomLeft, const tcu::Vec2& topRight, const tcu::Vec2& layerRange);
371 bool compareImages (tcu::TestLog& log, const char* name, const char* desc, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
372 bool compareImages (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, tcu::RGBA threshold);
373 int measureAccuracy (tcu::TestLog& log, const tcu::Surface& reference, const tcu::Surface& rendered, int bestScoreDiff, int worstScoreDiff);
375 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
376 const tcu::ConstPixelBufferAccess& reference,
377 const tcu::PixelBufferAccess& errorMask,
378 const tcu::Texture1DView& src,
379 const float* texCoord,
380 const ReferenceParams& sampleParams,
381 const tcu::LookupPrecision& lookupPrec,
382 const tcu::LodPrecision& lodPrec,
383 qpWatchDog* watchDog);
385 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
386 const tcu::ConstPixelBufferAccess& reference,
387 const tcu::PixelBufferAccess& errorMask,
388 const tcu::Texture2DView& src,
389 const float* texCoord,
390 const ReferenceParams& sampleParams,
391 const tcu::LookupPrecision& lookupPrec,
392 const tcu::LodPrecision& lodPrec,
393 qpWatchDog* watchDog);
395 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
396 const tcu::ConstPixelBufferAccess& reference,
397 const tcu::PixelBufferAccess& errorMask,
398 const tcu::TextureCubeView& src,
399 const float* texCoord,
400 const ReferenceParams& sampleParams,
401 const tcu::LookupPrecision& lookupPrec,
402 const tcu::LodPrecision& lodPrec,
403 qpWatchDog* watchDog);
405 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
406 const tcu::ConstPixelBufferAccess& reference,
407 const tcu::PixelBufferAccess& errorMask,
408 const tcu::Texture1DArrayView& src,
409 const float* texCoord,
410 const ReferenceParams& sampleParams,
411 const tcu::LookupPrecision& lookupPrec,
412 const tcu::LodPrecision& lodPrec,
413 qpWatchDog* watchDog);
415 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
416 const tcu::ConstPixelBufferAccess& reference,
417 const tcu::PixelBufferAccess& errorMask,
418 const tcu::Texture2DArrayView& src,
419 const float* texCoord,
420 const ReferenceParams& sampleParams,
421 const tcu::LookupPrecision& lookupPrec,
422 const tcu::LodPrecision& lodPrec,
423 qpWatchDog* watchDog);
425 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
426 const tcu::ConstPixelBufferAccess& reference,
427 const tcu::PixelBufferAccess& errorMask,
428 const tcu::Texture3DView& src,
429 const float* texCoord,
430 const ReferenceParams& sampleParams,
431 const tcu::LookupPrecision& lookupPrec,
432 const tcu::LodPrecision& lodPrec,
433 qpWatchDog* watchDog);
435 int computeTextureLookupDiff (const tcu::ConstPixelBufferAccess& result,
436 const tcu::ConstPixelBufferAccess& reference,
437 const tcu::PixelBufferAccess& errorMask,
438 const tcu::TextureCubeArrayView& src,
439 const float* texCoord,
440 const ReferenceParams& sampleParams,
441 const tcu::LookupPrecision& lookupPrec,
442 const tcu::IVec4& coordBits,
443 const tcu::LodPrecision& lodPrec,
444 qpWatchDog* watchDog);
446 bool verifyTextureResult (tcu::TestContext& testCtx,
447 const tcu::ConstPixelBufferAccess& result,
448 const tcu::Texture1DView& src,
449 const float* texCoord,
450 const ReferenceParams& sampleParams,
451 const tcu::LookupPrecision& lookupPrec,
452 const tcu::LodPrecision& lodPrec,
453 const tcu::PixelFormat& pixelFormat);
455 bool verifyTextureResult (tcu::TestContext& testCtx,
456 const tcu::ConstPixelBufferAccess& result,
457 const tcu::Texture2DView& src,
458 const float* texCoord,
459 const ReferenceParams& sampleParams,
460 const tcu::LookupPrecision& lookupPrec,
461 const tcu::LodPrecision& lodPrec,
462 const tcu::PixelFormat& pixelFormat);
464 bool verifyTextureResult (tcu::TestContext& testCtx,
465 const tcu::ConstPixelBufferAccess& result,
466 const tcu::TextureCubeView& src,
467 const float* texCoord,
468 const ReferenceParams& sampleParams,
469 const tcu::LookupPrecision& lookupPrec,
470 const tcu::LodPrecision& lodPrec,
471 const tcu::PixelFormat& pixelFormat);
473 bool verifyTextureResult (tcu::TestContext& testCtx,
474 const tcu::ConstPixelBufferAccess& result,
475 const tcu::Texture1DArrayView& src,
476 const float* texCoord,
477 const ReferenceParams& sampleParams,
478 const tcu::LookupPrecision& lookupPrec,
479 const tcu::LodPrecision& lodPrec,
480 const tcu::PixelFormat& pixelFormat);
482 bool verifyTextureResult (tcu::TestContext& testCtx,
483 const tcu::ConstPixelBufferAccess& result,
484 const tcu::Texture2DArrayView& src,
485 const float* texCoord,
486 const ReferenceParams& sampleParams,
487 const tcu::LookupPrecision& lookupPrec,
488 const tcu::LodPrecision& lodPrec,
489 const tcu::PixelFormat& pixelFormat);
491 bool verifyTextureResult (tcu::TestContext& testCtx,
492 const tcu::ConstPixelBufferAccess& result,
493 const tcu::Texture3DView& src,
494 const float* texCoord,
495 const ReferenceParams& sampleParams,
496 const tcu::LookupPrecision& lookupPrec,
497 const tcu::LodPrecision& lodPrec,
498 const tcu::PixelFormat& pixelFormat);
500 bool verifyTextureResult (tcu::TestContext& testCtx,
501 const tcu::ConstPixelBufferAccess& result,
502 const tcu::TextureCubeArrayView& src,
503 const float* texCoord,
504 const ReferenceParams& sampleParams,
505 const tcu::LookupPrecision& lookupPrec,
506 const tcu::IVec4& coordBits,
507 const tcu::LodPrecision& lodPrec,
508 const tcu::PixelFormat& pixelFormat);
510 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result,
511 const tcu::ConstPixelBufferAccess& reference,
512 const tcu::PixelBufferAccess& errorMask,
513 const tcu::Texture2DView& src,
514 const float* texCoord,
515 const ReferenceParams& sampleParams,
516 const tcu::TexComparePrecision& comparePrec,
517 const tcu::LodPrecision& lodPrec,
518 const tcu::Vec3& nonShadowThreshold);
520 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result,
521 const tcu::ConstPixelBufferAccess& reference,
522 const tcu::PixelBufferAccess& errorMask,
523 const tcu::TextureCubeView& src,
524 const float* texCoord,
525 const ReferenceParams& sampleParams,
526 const tcu::TexComparePrecision& comparePrec,
527 const tcu::LodPrecision& lodPrec,
528 const tcu::Vec3& nonShadowThreshold);
530 int computeTextureCompareDiff (const tcu::ConstPixelBufferAccess& result,
531 const tcu::ConstPixelBufferAccess& reference,
532 const tcu::PixelBufferAccess& errorMask,
533 const tcu::Texture2DArrayView& src,
534 const float* texCoord,
535 const ReferenceParams& sampleParams,
536 const tcu::TexComparePrecision& comparePrec,
537 const tcu::LodPrecision& lodPrec,
538 const tcu::Vec3& nonShadowThreshold);
540 // Mipmap generation comparison.
542 struct GenMipmapPrecision
544 tcu::IVec3 filterBits; //!< Bits in filtering parameters (fixed-point).
545 tcu::Vec4 colorThreshold; //!< Threshold for color value comparison.
546 tcu::BVec4 colorMask; //!< Color channel comparison mask.
549 qpTestResult compareGenMipmapResult (tcu::TestLog& log, const tcu::Texture2D& resultTexture, const tcu::Texture2D& level0Reference, const GenMipmapPrecision& precision);
550 qpTestResult compareGenMipmapResult (tcu::TestLog& log, const tcu::TextureCube& resultTexture, const tcu::TextureCube& level0Reference, const GenMipmapPrecision& precision);
552 // Utility for logging texture gradient ranges.
553 struct LogGradientFmt
555 LogGradientFmt (const tcu::Vec4* min_, const tcu::Vec4* max_) : valueMin(min_), valueMax(max_) {}
556 const tcu::Vec4* valueMin;
557 const tcu::Vec4* valueMax;
560 std::ostream& operator<< (std::ostream& str, const LogGradientFmt& fmt);
561 inline LogGradientFmt formatGradient (const tcu::Vec4* minVal, const tcu::Vec4* maxVal) { return LogGradientFmt(minVal, maxVal); }
567 #endif // _GLSTEXTURETESTUTIL_HPP