1#ifndef _VKTSAMPLEVERIFIER_HPP
2#define _VKTSAMPLEVERIFIER_HPP
3/*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
6 *
7 * Copyright (c) 2016 Google Inc.
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 GPU image sample verification
24 *//*--------------------------------------------------------------------*/
25
26#include "vkDefs.hpp"
27
28#include "deUniquePtr.hpp"
29
30#include "tcuFloatFormat.hpp"
31#include "tcuTexture.hpp"
32#include "tcuVector.hpp"
33
34#include <iostream>
35#include <string>
36#include <vector>
37
38namespace vkt
39{
40namespace texture
41{
42
43struct SampleArguments
44{
45	tcu::Vec4	coord;
46	tcu::Vec4	dPdx;
47	tcu::Vec4	dPdy;
48	float		layer;
49	float		lod;
50	float		lodBias;
51	float		dRef;
52};
53
54enum LookupLodMode
55{
56	LOOKUP_LOD_MODE_DERIVATIVES = 0,
57	LOOKUP_LOD_MODE_LOD,
58
59	LOOKUP_LOD_MODE_LAST
60};
61
62struct SampleLookupSettings
63{
64	LookupLodMode	lookupLodMode;
65	bool			hasLodBias;
66	bool			isProjective;
67};
68
69enum WrappingMode
70{
71	WRAPPING_MODE_REPEAT = 0,
72	WRAPPING_MODE_MIRRORED_REPEAT,
73	WRAPPING_MODE_CLAMP_TO_EDGE,
74	WRAPPING_MODE_CLAMP_TO_BORDER,
75	WRAPPING_MODE_MIRROR_CLAMP_TO_EDGE,
76
77	WRAPPING_MODE_LAST
78};
79
80struct SamplerParameters
81{
82	vk::VkFilter				magFilter;
83	vk::VkFilter				minFilter;
84	vk::VkSamplerMipmapMode		mipmapFilter;
85
86	vk::VkSamplerAddressMode	wrappingModeU;
87	vk::VkSamplerAddressMode	wrappingModeV;
88	vk::VkSamplerAddressMode	wrappingModeW;
89
90	vk::VkBorderColor			borderColor;
91
92	float						lodBias;
93	float						minLod;
94	float						maxLod;
95
96	bool						isUnnormalized;
97	bool						isCompare;
98};
99
100enum ImgDim
101{
102	IMG_DIM_INVALID = 0,
103	IMG_DIM_1D,
104	IMG_DIM_2D,
105	IMG_DIM_3D,
106	IMG_DIM_CUBE,
107
108	IMG_DIM_LAST
109};
110
111struct ImageViewParameters
112{
113	ImgDim			dim;
114	vk::VkFormat	format;
115	tcu::IVec3		size;
116	int				levels;
117
118	bool			isArrayed;
119	int				arrayLayers;
120};
121
122class SampleVerifier
123{
124public:
125	SampleVerifier						(const ImageViewParameters&							imParams,
126										 const SamplerParameters&							samplerParams,
127										 const SampleLookupSettings&						sampleLookupSettings,
128										 int												coordBits,
129										 int												mipmapBits,
130										 const tcu::FloatFormat&							conversionPrecision,
131										 const tcu::FloatFormat&							filteringPrecision,
132										 const std::vector<tcu::ConstPixelBufferAccess>&	levels);
133
134	bool verifySample					(const SampleArguments&								args,
135										 const tcu::Vec4&									result) const;
136
137	bool verifySampleReport				(const SampleArguments&								args,
138										 const tcu::Vec4&									result,
139										 std::string&										report) const;
140
141private:
142
143	bool verifySampleFiltered			(const tcu::Vec4&									result,
144										 const tcu::IVec3&								    baseTexelHi,
145										 const tcu::IVec3&								    baseTexelLo,
146										 const tcu::IVec3&								    texelGridOffsetHi,
147										 const tcu::IVec3&								    texelGridOffsetLo,
148										 int												layer,
149										 int												levelHi,
150										 const tcu::Vec2&									lodFracBounds,
151										 vk::VkFilter										filter,
152										 vk::VkSamplerMipmapMode							mipmapFilter,
153										 std::ostream&										report) const;
154
155	bool verifySampleTexelGridCoords	(const SampleArguments&								args,
156										 const tcu::Vec4&									result,
157										 const tcu::IVec3&									gridCoordHi,
158										 const tcu::IVec3&									gridCoordLo,
159										 const tcu::Vec2&									lodBounds,
160										 int												level,
161										 vk::VkSamplerMipmapMode							mipmapFilter,
162										 std::ostream&										report) const;
163
164	bool verifySampleMipmapLevel		(const SampleArguments&								args,
165										 const tcu::Vec4&									result,
166										 const tcu::Vec4&									coord,
167										 const tcu::Vec2&									lodFracBounds,
168										 int												level,
169										 std::ostream&										report) const;
170
171	bool verifySampleCubemapFace		(const SampleArguments&								args,
172										 const tcu::Vec4&									result,
173										 const tcu::Vec4&									coord,
174										 const tcu::Vec4&									dPdx,
175										 const tcu::Vec4&									dPdy,
176										 int												face,
177										 std::ostream&										report) const;
178
179	bool verifySampleImpl				(const SampleArguments&								args,
180										 const tcu::Vec4&									result,
181										 std::ostream&										report) const;
182
183	bool coordOutOfRange				(const tcu::IVec3&									coord,
184										 int												compNdx,
185										 int												level) const;
186
187	void fetchTexel						(const tcu::IVec3&									coordIn,
188										 int												layer,
189										 int												level,
190										 vk::VkFilter										filter,
191										 tcu::Vec4&											resultMin,
192										 tcu::Vec4&											resultMax) const;
193
194	void fetchTexelWrapped				(const tcu::IVec3&									coord,
195										 int												layer,
196										 int												level,
197										 tcu::Vec4&											resultMin,
198										 tcu::Vec4&											resultMax) const;
199
200    void getFilteredSample1D			(const tcu::IVec3&									texelBase,
201										 float												weight,
202										 int												layer,
203										 int												level,
204										 tcu::Vec4&											resultMin,
205										 tcu::Vec4&											resultMax) const;
206
207	void getFilteredSample2D			(const tcu::IVec3&									texelBase,
208										 const tcu::Vec2&									weights,
209										 int												layer,
210										 int												level,
211										 tcu::Vec4&											resultMin,
212										 tcu::Vec4&											resultMax) const;
213
214	void getFilteredSample3D			(const tcu::IVec3&									texelBase,
215										 const tcu::Vec3&									weights,
216										 int												layer,
217										 int												level,
218										 tcu::Vec4&											resultMin,
219										 tcu::Vec4&											resultMax) const;
220
221	void getFilteredSample				(const tcu::IVec3&									texelBase,
222										 const tcu::Vec3&									weights,
223										 int												layer,
224										 int												level,
225										 tcu::Vec4&											resultMin,
226										 tcu::Vec4&											resultMax) const;
227
228	void getMipmapStepBounds			(const tcu::Vec2&									lodFracBounds,
229										 deInt32&											stepMin,
230										 deInt32&											stepMax) const;
231
232	const ImageViewParameters&						m_imParams;
233	const SamplerParameters&						m_samplerParams;
234	const SampleLookupSettings&						m_sampleLookupSettings;
235
236    const int										m_coordBits;
237	const int										m_mipmapBits;
238	const tcu::FloatFormat							m_conversionPrecision;
239	const tcu::FloatFormat							m_filteringPrecision;
240
241	const int										m_unnormalizedDim;
242
243	const std::vector<tcu::ConstPixelBufferAccess>&	m_levels;
244};
245
246} // texture
247} // vkt
248
249#endif // _VKTSAMPLEVERIFIER_HPP
250