1#ifndef _TCUTEXLOOKUPVERIFIER_HPP
2#define _TCUTEXLOOKUPVERIFIER_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
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 Texture lookup simulator that is capable of verifying generic
24 *		  lookup results based on accuracy parameters.
25 *//*--------------------------------------------------------------------*/
26
27#include "tcuDefs.hpp"
28#include "tcuTexture.hpp"
29
30namespace tcu
31{
32
33/*--------------------------------------------------------------------*//*!
34 * \brief Generic lookup precision parameters.
35 *
36 * For (assumed) floating-point values recision is defined by number of
37 * accurate bits in significand. Maximum number of accurate bits supported
38 * is 23 (limit of single-precision FP).
39 *
40 * For fixed-point values precision is defined by number of bits in
41 * the fractional part.
42 *//*--------------------------------------------------------------------*/
43struct LookupPrecision
44{
45	IVec3		coordBits;		//!< Bits per coordinate component before any transformations. Assumed to be floating-point.
46	IVec3		uvwBits;		//!< Bits per component in final per-level UV(W) coordinates. Assumed to be fixed-point.
47	Vec4		colorThreshold;	//!< Threshold for match.
48	BVec4		colorMask;		//!< Channel mask for comparison.
49
50	LookupPrecision (void)
51		: coordBits			(22)
52		, uvwBits			(16)
53		, colorThreshold	(0.0f)
54		, colorMask			(true)
55	{
56	}
57};
58
59struct IntLookupPrecision
60{
61	IVec3		coordBits;		//!< Bits per coordinate component before any transformations. Assumed to be floating-point.
62	IVec3		uvwBits;		//!< Bits per component in final per-level UV(W) coordinates. Assumed to be fixed-point.
63	UVec4		colorThreshold;	//!< Threshold for match.
64	BVec4		colorMask;		//!< Channel mask for comparison.
65
66	IntLookupPrecision (void)
67		: coordBits			(22)
68		, uvwBits			(16)
69		, colorThreshold	(0)
70		, colorMask			(true)
71	{
72	}
73};
74
75/*--------------------------------------------------------------------*//*!
76 * \brief Lod computation precision parameters.
77 *//*--------------------------------------------------------------------*/
78struct LodPrecision
79{
80	int			derivateBits;	//!< Number of bits in derivates. (Floating-point)
81	int			lodBits;		//!< Number of bits in final lod (accuracy of log2()). (Fixed-point)
82
83	LodPrecision (void)
84		: derivateBits	(22)
85		, lodBits		(16)
86	{
87	}
88};
89
90enum TexLookupScaleMode
91{
92	TEX_LOOKUP_SCALE_MINIFY	= 0,
93	TEX_LOOKUP_SCALE_MAGNIFY,
94
95	TEX_LOOKUP_SCALE_MODE_LAST
96};
97
98Vec4		computeFixedPointThreshold			(const IVec4& bits);
99Vec4		computeFloatingPointThreshold		(const IVec4& bits, const Vec4& value);
100
101Vec2		computeLodBoundsFromDerivates		(const float dudx, const float dudy, const LodPrecision& prec);
102Vec2		computeLodBoundsFromDerivates		(const float dudx, const float dvdx, const float dudy, const float dvdy, const LodPrecision& prec);
103Vec2		computeLodBoundsFromDerivates		(const float dudx, const float dvdx, const float dwdx, const float dudy, const float dvdy, const float dwdy, const LodPrecision& prec);
104Vec2		computeCubeLodBoundsFromDerivates	(const Vec3& coord, const Vec3& coordDx, const Vec3& coordDy, const int faceSize, const LodPrecision& prec);
105
106Vec2		clampLodBounds						(const Vec2& lodBounds, const Vec2& lodMinMax, const LodPrecision& prec);
107
108bool		isLookupResultValid					(const Texture1DView&			texture, const Sampler& sampler, const LookupPrecision& prec, const float coord, const Vec2& lodBounds, const Vec4& result);
109bool		isLookupResultValid					(const Texture2DView&			texture, const Sampler& sampler, const LookupPrecision& prec, const Vec2& coord, const Vec2& lodBounds, const Vec4& result);
110bool		isLookupResultValid					(const TextureCubeView&			texture, const Sampler& sampler, const LookupPrecision& prec, const Vec3& coord, const Vec2& lodBounds, const Vec4& result);
111bool		isLookupResultValid					(const Texture1DArrayView&		texture, const Sampler& sampler, const LookupPrecision& prec, const Vec2& coord, const Vec2& lodBounds, const Vec4& result);
112bool		isLookupResultValid					(const Texture2DArrayView&		texture, const Sampler& sampler, const LookupPrecision& prec, const Vec3& coord, const Vec2& lodBounds, const Vec4& result);
113bool		isLookupResultValid					(const Texture3DView&			texture, const Sampler& sampler, const LookupPrecision& prec, const Vec3& coord, const Vec2& lodBounds, const Vec4& result);
114bool		isLookupResultValid					(const TextureCubeArrayView&	texture, const Sampler& sampler, const LookupPrecision& prec, const IVec4& coordBits, const Vec4& coord, const Vec2& lodBounds, const Vec4& result);
115
116bool		isLevel1DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const LookupPrecision& prec, const float coordX, const int coordY, const Vec4& result);
117bool		isLevel1DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const float coordX, const int coordY, const IVec4& result);
118bool		isLevel1DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const float coordX, const int coordY, const UVec4& result);
119
120bool		isLevel2DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const LookupPrecision& prec, const Vec2& coord, const int coordZ, const Vec4& result);
121bool		isLevel2DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const Vec2& coord, const int coordZ, const IVec4& result);
122bool		isLevel2DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const Vec2& coord, const int coordZ, const UVec4& result);
123
124bool		isLevel3DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const LookupPrecision& prec, const Vec3& coord, const Vec4& result);
125bool		isLevel3DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const Vec3& coord, const IVec4& result);
126bool		isLevel3DLookupResultValid			(const ConstPixelBufferAccess& access, const Sampler& sampler, TexLookupScaleMode scaleMode, const IntLookupPrecision& prec, const Vec3& coord, const UVec4& result);
127
128bool		isLinearSampleResultValid			(const ConstPixelBufferAccess& level, const Sampler& sampler, const LookupPrecision& prec, const Vec2& coord, const int coordZ, const Vec4& result);
129
130bool		isGatherOffsetsResultValid			(const Texture2DView&		texture, const Sampler& sampler, const LookupPrecision& prec,		const Vec2& coord, int componentNdx, const IVec2 (&offsets)[4], const Vec4& result);
131bool		isGatherOffsetsResultValid			(const Texture2DView&		texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec2& coord, int componentNdx, const IVec2 (&offsets)[4], const IVec4& result);
132bool		isGatherOffsetsResultValid			(const Texture2DView&		texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec2& coord, int componentNdx, const IVec2 (&offsets)[4], const UVec4& result);
133
134bool		isGatherOffsetsResultValid			(const Texture2DArrayView&	texture, const Sampler& sampler, const LookupPrecision& prec,		const Vec3& coord, int componentNdx, const IVec2 (&offsets)[4], const Vec4& result);
135bool		isGatherOffsetsResultValid			(const Texture2DArrayView&	texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec3& coord, int componentNdx, const IVec2 (&offsets)[4], const IVec4& result);
136bool		isGatherOffsetsResultValid			(const Texture2DArrayView&	texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec3& coord, int componentNdx, const IVec2 (&offsets)[4], const UVec4& result);
137
138// \note For cube textures, gather is only defined without offset.
139bool		isGatherResultValid					(const TextureCubeView&		texture, const Sampler& sampler, const LookupPrecision& prec,		const Vec3& coord, int componentNdx, const Vec4& result);
140bool		isGatherResultValid					(const TextureCubeView&		texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec3& coord, int componentNdx, const IVec4& result);
141bool		isGatherResultValid					(const TextureCubeView&		texture, const Sampler& sampler, const IntLookupPrecision& prec,	const Vec3& coord, int componentNdx, const UVec4& result);
142
143} // tcu
144
145#endif // _TCUTEXLOOKUPVERIFIER_HPP
146