1 /*-------------------------------------------------------------------------
2  * drawElements Internal Test Module
3  * ---------------------------------
4  *
5  * Copyright 2015 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Texture format tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "ditTextureFormatTests.hpp"
25 #include "tcuTestLog.hpp"
26 
27 #include "rrRenderer.hpp"
28 #include "tcuTextureUtil.hpp"
29 #include "tcuVectorUtil.hpp"
30 #include "tcuFormatUtil.hpp"
31 
32 #include "deRandom.hpp"
33 #include "deArrayUtil.hpp"
34 #include "deStringUtil.hpp"
35 #include "deUniquePtr.hpp"
36 
37 #include <sstream>
38 
39 namespace dit
40 {
41 
42 namespace
43 {
44 
45 using std::string;
46 using std::vector;
47 
48 using tcu::TestLog;
49 using tcu::TextureFormat;
50 using tcu::TextureChannelClass;
51 using tcu::TextureAccessType;
52 using tcu::PixelBufferAccess;
53 using tcu::ConstPixelBufferAccess;
54 using tcu::Vector;
55 using tcu::IVec3;
56 
57 // Test data
58 
59 static const deUint8 s_snormInt8In[] =
60 {
61 	0x1b, 0x23, 0xc5, 0x09,
62 	0xb4, 0xbf, 0xbf, 0x24,
63 	0x1a, 0x8a, 0xdb, 0x96,
64 	0xc0, 0xa1, 0xde, 0x78,
65 };
66 static const deUint32 s_snormInt8FloatRef[] =
67 {
68 	0x3e59b367, 0x3e8d1a34, 0xbeeddbb7, 0x3d912245,
69 	0xbf193265, 0xbf03060c, 0xbf03060c, 0x3e912245,
70 	0x3e51a347, 0xbf6ddbb7, 0xbe952a55, 0xbf55ab57,
71 	0xbf010204, 0xbf3f7efe, 0xbe891224, 0x3f71e3c8,
72 };
73 static const deUint32 s_snormInt8UintRef[] =
74 {
75 	0x0000001b, 0x00000023, 0xffffffc5, 0x00000009,
76 	0xffffffb4, 0xffffffbf, 0xffffffbf, 0x00000024,
77 	0x0000001a, 0xffffff8a, 0xffffffdb, 0xffffff96,
78 	0xffffffc0, 0xffffffa1, 0xffffffde, 0x00000078,
79 };
80 static const deUint32 s_snormInt8IntRef[] =
81 {
82 	0x0000001b, 0x00000023, 0xffffffc5, 0x00000009,
83 	0xffffffb4, 0xffffffbf, 0xffffffbf, 0x00000024,
84 	0x0000001a, 0xffffff8a, 0xffffffdb, 0xffffff96,
85 	0xffffffc0, 0xffffffa1, 0xffffffde, 0x00000078,
86 };
87 
88 static const deUint8 s_snormInt16In[] =
89 {
90 	0xa0, 0xe9, 0xaa, 0x30,
91 	0x16, 0x61, 0x37, 0xa2,
92 	0x23, 0x4c, 0x46, 0xac,
93 	0x8b, 0xf9, 0x36, 0x3e,
94 	0x92, 0x7c, 0x96, 0x81,
95 	0xc5, 0xb2, 0x95, 0x6e,
96 	0x4f, 0x1e, 0xbc, 0x49,
97 	0x14, 0x6c, 0x3c, 0x61,
98 };
99 static const deUint32 s_snormInt16FloatRef[] =
100 {
101 	0xbe330166, 0x3ec2a985, 0x3f422d84, 0xbf3b9377,
102 	0x3f184731, 0xbf27754f, 0xbd4ea19d, 0x3ef8d9f2,
103 	0x3f7925f2, 0xbf7cd5fa, 0xbf1a7735, 0x3f5d2bba,
104 	0x3e7279e5, 0x3f137927, 0x3f5829b0, 0x3f427985,
105 };
106 static const deUint32 s_snormInt16UintRef[] =
107 {
108 	0xffffe9a0, 0x000030aa, 0x00006116, 0xffffa237,
109 	0x00004c23, 0xffffac46, 0xfffff98b, 0x00003e36,
110 	0x00007c92, 0xffff8196, 0xffffb2c5, 0x00006e95,
111 	0x00001e4f, 0x000049bc, 0x00006c14, 0x0000613c,
112 };
113 static const deUint32 s_snormInt16IntRef[] =
114 {
115 	0xffffe9a0, 0x000030aa, 0x00006116, 0xffffa237,
116 	0x00004c23, 0xffffac46, 0xfffff98b, 0x00003e36,
117 	0x00007c92, 0xffff8196, 0xffffb2c5, 0x00006e95,
118 	0x00001e4f, 0x000049bc, 0x00006c14, 0x0000613c,
119 };
120 
121 static const deUint8 s_snormInt32In[] =
122 {
123 	0xba, 0x2c, 0x02, 0xea,
124 	0x75, 0x59, 0x74, 0x48,
125 	0x32, 0xad, 0xb0, 0xda,
126 	0x0b, 0xf7, 0x6f, 0x49,
127 	0x98, 0x9b, 0x76, 0x66,
128 	0x79, 0x7d, 0x69, 0x33,
129 	0xb5, 0x74, 0x61, 0xa4,
130 	0x4c, 0xcd, 0x5c, 0x20,
131 	0xc3, 0xba, 0x90, 0xfc,
132 	0xe3, 0x17, 0xd0, 0x89,
133 	0x28, 0x61, 0x5d, 0xb0,
134 	0x5d, 0xc9, 0xad, 0xc9,
135 	0xfc, 0x8c, 0x48, 0x3c,
136 	0x11, 0x13, 0x40, 0x27,
137 	0xe4, 0x88, 0x27, 0x4f,
138 	0x52, 0xa2, 0x54, 0x50,
139 };
140 static const deUint32 s_snormInt32FloatRef[] =
141 {
142 	0xbe2fee9a, 0x3f10e8b3, 0xbe953d4b, 0x3f12dfee,
143 	0x3f4ced37, 0x3ecda5f6, 0xbf373d17, 0x3e817335,
144 	0xbcdbd14f, 0xbf6c5fd0, 0xbf1f453e, 0xbed948db,
145 	0x3ef12234, 0x3e9d004c, 0x3f1e4f12, 0x3f20a945,
146 };
147 static const deUint32 s_snormInt32UintRef[] =
148 {
149 	0xea022cba, 0x48745975, 0xdab0ad32, 0x496ff70b,
150 	0x66769b98, 0x33697d79, 0xa46174b5, 0x205ccd4c,
151 	0xfc90bac3, 0x89d017e3, 0xb05d6128, 0xc9adc95d,
152 	0x3c488cfc, 0x27401311, 0x4f2788e4, 0x5054a252,
153 };
154 static const deUint32 s_snormInt32IntRef[] =
155 {
156 	0xea022cba, 0x48745975, 0xdab0ad32, 0x496ff70b,
157 	0x66769b98, 0x33697d79, 0xa46174b5, 0x205ccd4c,
158 	0xfc90bac3, 0x89d017e3, 0xb05d6128, 0xc9adc95d,
159 	0x3c488cfc, 0x27401311, 0x4f2788e4, 0x5054a252,
160 };
161 
162 static const deUint8 s_unormInt8In[] =
163 {
164 	0x90, 0xa0, 0xa9, 0x26,
165 	0x24, 0xc4, 0xa1, 0xa5,
166 	0xdb, 0x0e, 0x09, 0x7a,
167 	0x7f, 0x3d, 0xf2, 0x1f,
168 };
169 static const deUint32 s_unormInt8FloatRef[] =
170 {
171 	0x3f109091, 0x3f20a0a1, 0x3f29a9aa, 0x3e189899,
172 	0x3e109091, 0x3f44c4c5, 0x3f21a1a2, 0x3f25a5a6,
173 	0x3f5bdbdc, 0x3d60e0e1, 0x3d109091, 0x3ef4f4f5,
174 	0x3efefeff, 0x3e74f4f5, 0x3f72f2f3, 0x3df8f8f9,
175 };
176 static const deUint32 s_unormInt8UintRef[] =
177 {
178 	0x00000090, 0x000000a0, 0x000000a9, 0x00000026,
179 	0x00000024, 0x000000c4, 0x000000a1, 0x000000a5,
180 	0x000000db, 0x0000000e, 0x00000009, 0x0000007a,
181 	0x0000007f, 0x0000003d, 0x000000f2, 0x0000001f,
182 };
183 static const deUint32 s_unormInt8IntRef[] =
184 {
185 	0x00000090, 0x000000a0, 0x000000a9, 0x00000026,
186 	0x00000024, 0x000000c4, 0x000000a1, 0x000000a5,
187 	0x000000db, 0x0000000e, 0x00000009, 0x0000007a,
188 	0x0000007f, 0x0000003d, 0x000000f2, 0x0000001f,
189 };
190 
191 static const deUint8 s_unormInt16In[] =
192 {
193 	0xb6, 0x85, 0xf0, 0x1a,
194 	0xbc, 0x76, 0x5b, 0x59,
195 	0xf8, 0x74, 0x80, 0x6c,
196 	0xb1, 0x80, 0x4a, 0xdc,
197 	0xeb, 0x61, 0xa3, 0x12,
198 	0xf6, 0x65, 0x6b, 0x25,
199 	0x29, 0xe0, 0xe3, 0x0d,
200 	0x3a, 0xac, 0xa7, 0x97,
201 };
202 static const deUint32 s_unormInt16FloatRef[] =
203 {
204 	0x3f05b686, 0x3dd780d8, 0x3eed78ed, 0x3eb2b6b3,
205 	0x3ee9f0ea, 0x3ed900d9, 0x3f00b181, 0x3f5c4adc,
206 	0x3ec3d6c4, 0x3d951895, 0x3ecbeccc, 0x3e15ac96,
207 	0x3f6029e0, 0x3d5e30de, 0x3f2c3aac, 0x3f17a798,
208 };
209 static const deUint32 s_unormInt16UintRef[] =
210 {
211 	0x000085b6, 0x00001af0, 0x000076bc, 0x0000595b,
212 	0x000074f8, 0x00006c80, 0x000080b1, 0x0000dc4a,
213 	0x000061eb, 0x000012a3, 0x000065f6, 0x0000256b,
214 	0x0000e029, 0x00000de3, 0x0000ac3a, 0x000097a7,
215 };
216 static const deUint32 s_unormInt16IntRef[] =
217 {
218 	0x000085b6, 0x00001af0, 0x000076bc, 0x0000595b,
219 	0x000074f8, 0x00006c80, 0x000080b1, 0x0000dc4a,
220 	0x000061eb, 0x000012a3, 0x000065f6, 0x0000256b,
221 	0x0000e029, 0x00000de3, 0x0000ac3a, 0x000097a7,
222 };
223 
224 static const deUint8 s_unormInt24In[] =
225 {
226 	0xea, 0x65, 0x31, 0xb3,
227 	0x53, 0x62, 0x02, 0xf1,
228 	0xda, 0x3c, 0xaf, 0x31,
229 	0x35, 0xd6, 0x1f, 0xe4,
230 	0xfa, 0x3b, 0xb9, 0x48,
231 	0x73, 0x9a, 0xde, 0x6b,
232 	0x3e, 0xa5, 0x15, 0x90,
233 	0x95, 0xc2, 0x56, 0x8b,
234 	0xd2, 0x14, 0xd5, 0xe5,
235 	0xd0, 0x7b, 0x9f, 0x74,
236 	0x79, 0x58, 0x86, 0xa9,
237 	0xc0, 0xdf, 0xb6, 0xb4,
238 };
239 static const deUint32 s_unormInt24FloatRef[] =
240 {
241 	0x3e4597a9, 0x3ec4a767, 0x3f5af103, 0x3e46bcf1,
242 	0x3dfeb1a9, 0x3e6feb91, 0x3ee69173, 0x3ed7bd35,
243 	0x3dad29f1, 0x3f429591, 0x3f528b57, 0x3f65d515,
244 	0x3f1f7bd1, 0x3eb0f2e9, 0x3f40a987, 0x3f34b6e0,
245 };
246 static const deUint32 s_unormInt24UintRef[] =
247 {
248 	0x003165ea, 0x006253b3, 0x00daf102, 0x0031af3c,
249 	0x001fd635, 0x003bfae4, 0x007348b9, 0x006bde9a,
250 	0x0015a53e, 0x00c29590, 0x00d28b56, 0x00e5d514,
251 	0x009f7bd0, 0x00587974, 0x00c0a986, 0x00b4b6df,
252 };
253 static const deUint32 s_unormInt24IntRef[] =
254 {
255 	0x003165ea, 0x006253b3, 0x00daf102, 0x0031af3c,
256 	0x001fd635, 0x003bfae4, 0x007348b9, 0x006bde9a,
257 	0x0015a53e, 0x00c29590, 0x00d28b56, 0x00e5d514,
258 	0x009f7bd0, 0x00587974, 0x00c0a986, 0x00b4b6df,
259 };
260 
261 static const deUint8 s_unormInt32In[] =
262 {
263 	0x45, 0x7d, 0xe1, 0x55,
264 	0xd2, 0xcb, 0xc5, 0x17,
265 	0x64, 0x87, 0x84, 0x50,
266 	0x37, 0x60, 0x54, 0xa1,
267 	0xa8, 0x7e, 0xea, 0x98,
268 	0x1a, 0xd1, 0xb4, 0x70,
269 	0x2d, 0xcb, 0xff, 0x13,
270 	0x3d, 0xd7, 0x3c, 0xe4,
271 	0x94, 0xd6, 0xb4, 0xf7,
272 	0x01, 0x58, 0x32, 0x9d,
273 	0x91, 0x2b, 0x49, 0x1f,
274 	0xd0, 0xca, 0x3d, 0x05,
275 	0x14, 0x5a, 0x95, 0xd0,
276 	0xfd, 0x64, 0x33, 0xd3,
277 	0x73, 0x87, 0xa5, 0xf9,
278 	0x6d, 0xc8, 0x39, 0x03,
279 };
280 static const deUint32 s_unormInt32FloatRef[] =
281 {
282 	0x3eabc2fb, 0x3dbe2e5f, 0x3ea1090f, 0x3f215460,
283 	0x3f18ea7f, 0x3ee169a2, 0x3d9ffe59, 0x3f643cd7,
284 	0x3f77b4d7, 0x3f1d3258, 0x3dfa495d, 0x3ca7b95a,
285 	0x3f50955a, 0x3f533365, 0x3f79a587, 0x3c4e721b,
286 };
287 static const deUint32 s_unormInt32UintRef[] =
288 {
289 	0x55e17d45, 0x17c5cbd2, 0x50848764, 0xa1546037,
290 	0x98ea7ea8, 0x70b4d11a, 0x13ffcb2d, 0xe43cd73d,
291 	0xf7b4d694, 0x9d325801, 0x1f492b91, 0x053dcad0,
292 	0xd0955a14, 0xd33364fd, 0xf9a58773, 0x0339c86d,
293 };
294 static const deUint32 s_unormInt32IntRef[] =
295 {
296 	0x55e17d45, 0x17c5cbd2, 0x50848764, 0xa1546037,
297 	0x98ea7ea8, 0x70b4d11a, 0x13ffcb2d, 0xe43cd73d,
298 	0xf7b4d694, 0x9d325801, 0x1f492b91, 0x053dcad0,
299 	0xd0955a14, 0xd33364fd, 0xf9a58773, 0x0339c86d,
300 };
301 
302 static const deUint8 s_unormByte44In[] =
303 {
304 	0xdb, 0xa8, 0x29, 0x2d,
305 };
306 static const deUint32 s_unormByte44FloatRef[] =
307 {
308 	0x3f5dddde, 0x3f3bbbbc, 0x00000000, 0x3f800000,
309 	0x3f2aaaab, 0x3f088889, 0x00000000, 0x3f800000,
310 	0x3e088889, 0x3f19999a, 0x00000000, 0x3f800000,
311 	0x3e088889, 0x3f5dddde, 0x00000000, 0x3f800000,
312 };
313 static const deUint32 s_unormByte44IntRef[] =
314 {
315 	0x0000000d, 0x0000000b, 0x00000000, 0x00000001,
316 	0x0000000a, 0x00000008, 0x00000000, 0x00000001,
317 	0x00000002, 0x00000009, 0x00000000, 0x00000001,
318 	0x00000002, 0x0000000d, 0x00000000, 0x00000001,
319 };
320 static const deUint32 s_unsignedByte44FloatRef[] =
321 {
322 	0x41500000, 0x41300000, 0x00000000, 0x3f800000,
323 	0x41200000, 0x41000000, 0x00000000, 0x3f800000,
324 	0x40000000, 0x41100000, 0x00000000, 0x3f800000,
325 	0x40000000, 0x41500000, 0x00000000, 0x3f800000,
326 };
327 
328 static const deUint8 s_unormShort565In[] =
329 {
330 	0xea, 0x7e, 0xcc, 0x28,
331 	0x38, 0xce, 0x8f, 0x16,
332 };
333 static const deUint32 s_unormShort565FloatRef[] =
334 {
335 	0x3ef7bdef, 0x3f5f7df8, 0x3ea5294a, 0x3f800000,
336 	0x3e25294a, 0x3dc30c31, 0x3ec6318c, 0x3f800000,
337 	0x3f4e739d, 0x3f471c72, 0x3f46318c, 0x3f800000,
338 	0x3d842108, 0x3f534d35, 0x3ef7bdef, 0x3f800000,
339 };
340 static const deUint32 s_unormShort565IntRef[] =
341 {
342 	0x0000000f, 0x00000037, 0x0000000a, 0x00000001,
343 	0x00000005, 0x00000006, 0x0000000c, 0x00000001,
344 	0x00000019, 0x00000031, 0x00000018, 0x00000001,
345 	0x00000002, 0x00000034, 0x0000000f, 0x00000001,
346 };
347 static const deUint32 s_unsignedShort565FloatRef[] =
348 {
349 	0x41700000, 0x425c0000, 0x41200000, 0x3f800000,
350 	0x40a00000, 0x40c00000, 0x41400000, 0x3f800000,
351 	0x41c80000, 0x42440000, 0x41c00000, 0x3f800000,
352 	0x40000000, 0x42500000, 0x41700000, 0x3f800000,
353 };
354 
355 static const deUint8 s_unormShort555In[] =
356 {
357 	0x02, 0xea, 0x89, 0x13,
358 	0x94, 0x5a, 0x5b, 0x60,
359 };
360 static const deUint32 s_unormShort555FloatRef[] =
361 {
362 	0x3f56b5ad, 0x3f042108, 0x3d842108, 0x3f800000,
363 	0x3e042108, 0x3f6739ce, 0x3e94a529, 0x3f800000,
364 	0x3f35ad6b, 0x3f25294a, 0x3f25294a, 0x3f800000,
365 	0x3f46318c, 0x3d842108, 0x3f5ef7be, 0x3f800000,
366 };
367 static const deUint32 s_unormShort555IntRef[] =
368 {
369 	0x0000001a, 0x00000010, 0x00000002, 0x00000001,
370 	0x00000004, 0x0000001c, 0x00000009, 0x00000001,
371 	0x00000016, 0x00000014, 0x00000014, 0x00000001,
372 	0x00000018, 0x00000002, 0x0000001b, 0x00000001,
373 };
374 
375 static const deUint8 s_unormShort4444In[] =
376 {
377 	0x19, 0xdb, 0xa8, 0xa8,
378 	0x72, 0x29, 0xb4, 0x2d,
379 };
380 static const deUint32 s_unormShort4444FloatRef[] =
381 {
382 	0x3f5dddde, 0x3f3bbbbc, 0x3d888889, 0x3f19999a,
383 	0x3f2aaaab, 0x3f088889, 0x3f2aaaab, 0x3f088889,
384 	0x3e088889, 0x3f19999a, 0x3eeeeeef, 0x3e088889,
385 	0x3e088889, 0x3f5dddde, 0x3f3bbbbc, 0x3e888889,
386 };
387 static const deUint32 s_unormShort4444IntRef[] =
388 {
389 	0x0000000d, 0x0000000b, 0x00000001, 0x00000009,
390 	0x0000000a, 0x00000008, 0x0000000a, 0x00000008,
391 	0x00000002, 0x00000009, 0x00000007, 0x00000002,
392 	0x00000002, 0x0000000d, 0x0000000b, 0x00000004,
393 };
394 static const deUint32 s_unsignedShort4444FloatRef[] =
395 {
396 	0x41500000, 0x41300000, 0x3f800000, 0x41100000,
397 	0x41200000, 0x41000000, 0x41200000, 0x41000000,
398 	0x40000000, 0x41100000, 0x40e00000, 0x40000000,
399 	0x40000000, 0x41500000, 0x41300000, 0x40800000,
400 };
401 
402 static const deUint8 s_unormShort5551In[] =
403 {
404 	0x13, 0x89, 0x6f, 0x3c,
405 	0xae, 0xe9, 0xf2, 0xd9,
406 };
407 static const deUint32 s_unormShort5551FloatRef[] =
408 {
409 	0x3f0c6319, 0x3e042108, 0x3e94a529, 0x3f800000,
410 	0x3e6739ce, 0x3f0c6319, 0x3f3def7c, 0x3f800000,
411 	0x3f6f7bdf, 0x3e46318c, 0x3f3def7c, 0x00000000,
412 	0x3f5ef7be, 0x3e6739ce, 0x3f4e739d, 0x00000000,
413 };
414 static const deUint32 s_unormShort5551IntRef[] =
415 {
416 	0x00000011, 0x00000004, 0x00000009, 0x00000001,
417 	0x00000007, 0x00000011, 0x00000017, 0x00000001,
418 	0x0000001d, 0x00000006, 0x00000017, 0x00000000,
419 	0x0000001b, 0x00000007, 0x00000019, 0x00000000,
420 };
421 static const deUint32 s_unsignedShort5551FloatRef[] =
422 {
423 	0x41880000, 0x40800000, 0x41100000, 0x3f800000,
424 	0x40e00000, 0x41880000, 0x41b80000, 0x3f800000,
425 	0x41e80000, 0x40c00000, 0x41b80000, 0x00000000,
426 	0x41d80000, 0x40e00000, 0x41c80000, 0x00000000,
427 };
428 
429 static const deUint8 s_unormShort1555In[] =
430 {
431 	0xf8, 0xc5, 0x1f, 0x6c,
432 	0xf0, 0x2f, 0xf2, 0x95,
433 };
434 static const deUint32 s_unormShort1555FloatRef[] =
435 {
436 	0x3f800000, 0x3f0c6319, 0x3ef7bdef, 0x3f46318c,
437 	0x00000000, 0x3f5ef7be, 0x00000000, 0x3f800000,
438 	0x00000000, 0x3eb5ad6b, 0x3f800000, 0x3f042108,
439 	0x3f800000, 0x3e25294a, 0x3ef7bdef, 0x3f14a529,
440 };
441 static const deUint32 s_unormShort1555IntRef[] =
442 {
443 	0x00000001, 0x00000011, 0x0000000f, 0x00000018,
444 	0x00000000, 0x0000001b, 0x00000000, 0x0000001f,
445 	0x00000000, 0x0000000b, 0x0000001f, 0x00000010,
446 	0x00000001, 0x00000005, 0x0000000f, 0x00000012,
447 };
448 
449 static const deUint8 s_unormInt101010In[] =
450 {
451 	0x81, 0xb3, 0x67, 0x51,
452 	0xa9, 0x00, 0x34, 0xc5,
453 	0xf0, 0x2f, 0xf2, 0x95,
454 	0xf8, 0xc5, 0x1f, 0x6c,
455 };
456 static const deUint32 s_unormInt101010FloatRef[] =
457 {
458 	0x3ea2a8aa, 0x3f1ee7ba, 0x3e60380e, 0x3f800000,
459 	0x3f45314c, 0x3f50340d, 0x3d282a0b, 0x3f800000,
460 	0x3f15e579, 0x3f48b22d, 0x3f7f3fd0, 0x3f800000,
461 	0x3ed8360e, 0x3efe3f90, 0x3ebf2fcc, 0x3f800000,
462 };
463 static const deUint32 s_unormInt101010IntRef[] =
464 {
465 	0x00000145, 0x0000027b, 0x000000e0, 0x00000001,
466 	0x00000314, 0x00000340, 0x0000002a, 0x00000001,
467 	0x00000257, 0x00000322, 0x000003fc, 0x00000001,
468 	0x000001b0, 0x000001fc, 0x0000017e, 0x00000001,
469 };
470 
471 static const deUint8 s_unormInt1010102RevIn[] =
472 {
473 	0xfd, 0xc6, 0xf5, 0xc4,
474 	0x32, 0xa8, 0xfd, 0x7d,
475 	0xe7, 0x3f, 0x10, 0xd0,
476 	0x86, 0x0d, 0x66, 0xd0,
477 };
478 static const deUint32 s_unormInt1010102RevFloatRef[] =
479 {
480 	0x3f3f6fdc, 0x3eb8ae2c, 0x3d9e278a, 0x3f800000,
481 	0x3d48320d, 0x3f5ab6ae, 0x3f77fdff, 0x3eaaaaab,
482 	0x3f79fe80, 0x3c703c0f, 0x3e80a028, 0x3f800000,
483 	0x3ec330cc, 0x3ec1b06c, 0x3e8320c8, 0x3f800000,
484 };
485 static const deUint32 s_unormInt1010102RevIntRef[] =
486 {
487 	0x000002fd, 0x00000171, 0x0000004f, 0x00000003,
488 	0x00000032, 0x0000036a, 0x000003df, 0x00000001,
489 	0x000003e7, 0x0000000f, 0x00000101, 0x00000003,
490 	0x00000186, 0x00000183, 0x00000106, 0x00000003,
491 };
492 static const deUint32 s_snormInt1010102RevFloatRef[] =
493 {
494 	0xbf01c0e0, 0x3f38dc6e, 0x3e1e4f28, 0xbf800000,
495 	0x3dc86432, 0xbe964b26, 0xbd844221, 0x3f800000,
496 	0xbd486432, 0x3cf0783c, 0x3f00c060, 0xbf800000,
497 	0x3f4361b1, 0x3f41e0f0, 0x3f0341a1, 0xbf800000,
498 };
499 static const deUint32 s_snormInt1010102RevIntRef[] =
500 {
501 	0xfffffefd, 0x00000171, 0x0000004f, 0xffffffff,
502 	0x00000032, 0xffffff6a, 0xffffffdf, 0x00000001,
503 	0xffffffe7, 0x0000000f, 0x00000101, 0xffffffff,
504 	0x00000186, 0x00000183, 0x00000106, 0xffffffff,
505 };
506 
507 static const deUint8 s_unsignedInt1010102RevIn[] =
508 {
509 	0xb8, 0x4c, 0xfd, 0x00,
510 	0x65, 0x7f, 0xb2, 0x4e,
511 	0x11, 0x3e, 0x03, 0x23,
512 	0xae, 0xc9, 0xdd, 0xa2,
513 };
514 static const deUint32 s_unsignedInt1010102RevFloatRef[] =
515 {
516 	0x43380000, 0x4454c000, 0x41700000, 0x00000000,
517 	0x44594000, 0x431f0000, 0x436b0000, 0x3f800000,
518 	0x44044000, 0x434f0000, 0x440c0000, 0x00000000,
519 	0x43d70000, 0x445c8000, 0x440b4000, 0x40000000,
520 };
521 static const deUint32 s_unsignedInt1010102RevIntRef[] =
522 {
523 	0x000000b8, 0x00000353, 0x0000000f, 0x00000000,
524 	0x00000365, 0x0000009f, 0x000000eb, 0x00000001,
525 	0x00000211, 0x000000cf, 0x00000230, 0x00000000,
526 	0x000001ae, 0x00000372, 0x0000022d, 0x00000002,
527 };
528 static const deUint32 s_signedInt1010102RevFloatRef[] =
529 {
530 	0x43380000, 0x4f7fffff, 0x41700000, 0x00000000,
531 	0x4f7fffff, 0x431f0000, 0x436b0000, 0x3f800000,
532 	0x4f7ffffe, 0x434f0000, 0x4f7ffffe, 0x00000000,
533 	0x43d70000, 0x4f7fffff, 0x4f7ffffe, 0x4f800000,
534 };
535 static const deUint32 s_signedInt1010102RevIntRef[] =
536 {
537 	0x000000b8, 0xffffff53, 0x0000000f, 0x00000000,
538 	0xffffff65, 0x0000009f, 0x000000eb, 0x00000001,
539 	0xfffffe11, 0x000000cf, 0xfffffe30, 0x00000000,
540 	0x000001ae, 0xffffff72, 0xfffffe2d, 0xfffffffe,
541 };
542 
543 static const deUint8 s_unsignedInt11f11f10fRevIn[] =
544 {
545 	0x8e, 0x1b, 0x81, 0x45,
546 	0xcf, 0x47, 0x50, 0x29,
547 	0xff, 0x5e, 0x8e, 0x93,
548 	0x95, 0x07, 0x45, 0x4a,
549 };
550 static const deUint32 s_unsignedInt11f11f10fRevFloatRef[] =
551 {
552 	0x3f1c0000, 0x380c0000, 0x3c580000, 0x3f800000,
553 	0x7fffffff, 0x3c100000, 0x3a940000, 0x3f800000,
554 	0x45fe0000, 0x3b960000, 0x41380000, 0x3f800000,
555 	0x472a0000, 0x39400000, 0x3ca40000, 0x3f800000,
556 };
557 
558 static const deUint8 s_unsignedInt999E5RevIn[] =
559 {
560 	0x88, 0x8b, 0x50, 0x34,
561 	0x2b, 0x2f, 0xe2, 0x92,
562 	0x95, 0x7f, 0xeb, 0x18,
563 	0x6b, 0xe2, 0x27, 0x30,
564 };
565 static const deUint32 s_unsignedInt999E5RevFloatRef[] =
566 {
567 	0x3ac40000, 0x398a0000, 0x3a8a0000, 0x3f800000,
568 	0x40958000, 0x408b8000, 0x40380000, 0x3f800000,
569 	0x394a8000, 0x395f8000, 0x37e80000, 0x3f800000,
570 	0x39d60000, 0x3af88000, 0x38100000, 0x3f800000,
571 };
572 
573 static const deUint8 s_unsignedInt1688In[] =
574 {
575 	0x02, 0x50, 0x91, 0x85,
576 	0xcc, 0xe2, 0xfd, 0xc8,
577 	0x62, 0xeb, 0x0f, 0xe6,
578 	0x95, 0x27, 0x26, 0x24,
579 };
580 static const deUint32 s_unsignedInt1688FloatRef[] =
581 {
582 	0x3f059186, 0x00000000, 0x00000000, 0x3f800000,
583 	0x3f48fdc9, 0x00000000, 0x00000000, 0x3f800000,
584 	0x3f660fe6, 0x00000000, 0x00000000, 0x3f800000,
585 	0x3e109891, 0x00000000, 0x00000000, 0x3f800000,
586 };
587 static const deUint32 s_unsignedInt1688UintRef[] =
588 {
589 	0x00000002, 0x00000000, 0x00000000, 0x00000001,
590 	0x000000cc, 0x00000000, 0x00000000, 0x00000001,
591 	0x00000062, 0x00000000, 0x00000000, 0x00000001,
592 	0x00000095, 0x00000000, 0x00000000, 0x00000001,
593 };
594 
595 static const deUint8 s_unsignedInt248In[] =
596 {
597 	0xea, 0x7e, 0xcc, 0x28,
598 	0x38, 0xce, 0x8f, 0x16,
599 	0x3e, 0x4f, 0xe2, 0xfd,
600 	0x74, 0x5e, 0xf2, 0x30,
601 };
602 static const deUint32 s_unsignedInt248FloatRef[] =
603 {
604 	0x3e2331f9, 0x00000000, 0x00000000, 0x3f800000,
605 	0x3db47e71, 0x00000000, 0x00000000, 0x3f800000,
606 	0x3f7de250, 0x00000000, 0x00000000, 0x3f800000,
607 	0x3e43c979, 0x00000000, 0x00000000, 0x3f800000,
608 };
609 static const deUint32 s_unsignedInt248UintRef[] =
610 {
611 	0x000000ea, 0x00000000, 0x00000000, 0x00000001,
612 	0x00000038, 0x00000000, 0x00000000, 0x00000001,
613 	0x0000003e, 0x00000000, 0x00000000, 0x00000001,
614 	0x00000074, 0x00000000, 0x00000000, 0x00000001,
615 };
616 
617 static const deUint8 s_unsignedInt248RevIn[] =
618 {
619 	0x7e, 0xcc, 0x28, 0xea,
620 	0xce, 0x8f, 0x16, 0x38,
621 	0x4f, 0xe2, 0xfd, 0x3e,
622 	0x5e, 0xf2, 0x30, 0x74,
623 };
624 static const deUint32 s_unsignedInt248RevFloatRef[] =
625 {
626 	0x3e2331f9, 0x00000000, 0x00000000, 0x3f800000,
627 	0x3db47e71, 0x00000000, 0x00000000, 0x3f800000,
628 	0x3f7de250, 0x00000000, 0x00000000, 0x3f800000,
629 	0x3e43c979, 0x00000000, 0x00000000, 0x3f800000,
630 };
631 static const deUint32 s_unsignedInt248RevUintRef[] =
632 {
633 	0x000000ea, 0x00000000, 0x00000000, 0x00000001,
634 	0x00000038, 0x00000000, 0x00000000, 0x00000001,
635 	0x0000003e, 0x00000000, 0x00000000, 0x00000001,
636 	0x00000074, 0x00000000, 0x00000000, 0x00000001,
637 };
638 
639 static const deUint8 s_signedInt8In[] =
640 {
641 	0x3a, 0x5b, 0x6d, 0x6a,
642 	0x44, 0x56, 0x6b, 0x21,
643 	0x6a, 0x0b, 0x24, 0xd9,
644 	0xd4, 0xb4, 0xda, 0x97,
645 };
646 static const deUint32 s_signedInt8FloatRef[] =
647 {
648 	0x42680000, 0x42b60000, 0x42da0000, 0x42d40000,
649 	0x42880000, 0x42ac0000, 0x42d60000, 0x42040000,
650 	0x42d40000, 0x41300000, 0x42100000, 0xc21c0000,
651 	0xc2300000, 0xc2980000, 0xc2180000, 0xc2d20000,
652 };
653 static const deUint32 s_signedInt8UintRef[] =
654 {
655 	0x0000003a, 0x0000005b, 0x0000006d, 0x0000006a,
656 	0x00000044, 0x00000056, 0x0000006b, 0x00000021,
657 	0x0000006a, 0x0000000b, 0x00000024, 0xffffffd9,
658 	0xffffffd4, 0xffffffb4, 0xffffffda, 0xffffff97,
659 };
660 static const deUint32 s_signedInt8IntRef[] =
661 {
662 	0x0000003a, 0x0000005b, 0x0000006d, 0x0000006a,
663 	0x00000044, 0x00000056, 0x0000006b, 0x00000021,
664 	0x0000006a, 0x0000000b, 0x00000024, 0xffffffd9,
665 	0xffffffd4, 0xffffffb4, 0xffffffda, 0xffffff97,
666 };
667 
668 static const deUint8 s_signedInt16In[] =
669 {
670 	0xf1, 0xdd, 0xcd, 0xc3,
671 	0x1c, 0xb6, 0x6f, 0x74,
672 	0x19, 0x13, 0x25, 0xed,
673 	0x16, 0xce, 0x0d, 0x0f,
674 	0x5c, 0xf4, 0x3c, 0xa3,
675 	0x6d, 0x25, 0x65, 0x6d,
676 	0xae, 0x5d, 0x88, 0xfa,
677 	0x86, 0x3e, 0x6a, 0x91,
678 };
679 static const deUint32 s_signedInt16FloatRef[] =
680 {
681 	0xc6083c00, 0xc670cc00, 0xc693c800, 0x46e8de00,
682 	0x4598c800, 0xc596d800, 0xc647a800, 0x4570d000,
683 	0xc53a4000, 0xc6b98800, 0x4615b400, 0x46daca00,
684 	0x46bb5c00, 0xc4af0000, 0x467a1800, 0xc6dd2c00,
685 };
686 static const deUint32 s_signedInt16UintRef[] =
687 {
688 	0xffffddf1, 0xffffc3cd, 0xffffb61c, 0x0000746f,
689 	0x00001319, 0xffffed25, 0xffffce16, 0x00000f0d,
690 	0xfffff45c, 0xffffa33c, 0x0000256d, 0x00006d65,
691 	0x00005dae, 0xfffffa88, 0x00003e86, 0xffff916a,
692 };
693 static const deUint32 s_signedInt16IntRef[] =
694 {
695 	0xffffddf1, 0xffffc3cd, 0xffffb61c, 0x0000746f,
696 	0x00001319, 0xffffed25, 0xffffce16, 0x00000f0d,
697 	0xfffff45c, 0xffffa33c, 0x0000256d, 0x00006d65,
698 	0x00005dae, 0xfffffa88, 0x00003e86, 0xffff916a,
699 };
700 
701 static const deUint8 s_signedInt32In[] =
702 {
703 	0xc6, 0x7e, 0x50, 0x2a,
704 	0xec, 0x0f, 0x9b, 0x44,
705 	0x4d, 0xa9, 0x77, 0x0d,
706 	0x69, 0x4c, 0xd3, 0x76,
707 	0xf0, 0xb7, 0xde, 0x6b,
708 	0x4e, 0xe2, 0xb1, 0x58,
709 	0xa8, 0x9c, 0xfc, 0x6d,
710 	0x75, 0x8f, 0x3c, 0x7f,
711 	0xf3, 0x19, 0x14, 0x97,
712 	0xf0, 0x87, 0x5c, 0x11,
713 	0x95, 0x32, 0xab, 0x7a,
714 	0x03, 0x2b, 0xdf, 0x52,
715 	0x68, 0x84, 0xd9, 0x91,
716 	0xec, 0x2a, 0xf1, 0xd0,
717 	0xf7, 0x73, 0x8f, 0x0a,
718 	0x62, 0xd2, 0x76, 0xfd,
719 };
720 static const deUint32 s_signedInt32FloatRef[] =
721 {
722 	0x4e2941fb, 0x4e893620, 0x4d577a95, 0x4eeda699,
723 	0x4ed7bd70, 0x4eb163c5, 0x4edbf939, 0x4efe791f,
724 	0xced1d7cc, 0x4d8ae440, 0x4ef55665, 0x4ea5be56,
725 	0xcedc4cf7, 0xce3c3b54, 0x4d28f73f, 0xcc224b68,
726 };
727 static const deUint32 s_signedInt32UintRef[] =
728 {
729 	0x2a507ec6, 0x449b0fec, 0x0d77a94d, 0x76d34c69,
730 	0x6bdeb7f0, 0x58b1e24e, 0x6dfc9ca8, 0x7f3c8f75,
731 	0x971419f3, 0x115c87f0, 0x7aab3295, 0x52df2b03,
732 	0x91d98468, 0xd0f12aec, 0x0a8f73f7, 0xfd76d262,
733 };
734 static const deUint32 s_signedInt32IntRef[] =
735 {
736 	0x2a507ec6, 0x449b0fec, 0x0d77a94d, 0x76d34c69,
737 	0x6bdeb7f0, 0x58b1e24e, 0x6dfc9ca8, 0x7f3c8f75,
738 	0x971419f3, 0x115c87f0, 0x7aab3295, 0x52df2b03,
739 	0x91d98468, 0xd0f12aec, 0x0a8f73f7, 0xfd76d262,
740 };
741 
742 static const deUint8 s_unsignedInt8In[] =
743 {
744 	0x68, 0xa6, 0x99, 0x6e,
745 	0x13, 0x90, 0x0f, 0x40,
746 	0x34, 0x76, 0x05, 0x9a,
747 	0x6c, 0x9c, 0x1d, 0x6a,
748 };
749 static const deUint32 s_unsignedInt8FloatRef[] =
750 {
751 	0x42d00000, 0x43260000, 0x43190000, 0x42dc0000,
752 	0x41980000, 0x43100000, 0x41700000, 0x42800000,
753 	0x42500000, 0x42ec0000, 0x40a00000, 0x431a0000,
754 	0x42d80000, 0x431c0000, 0x41e80000, 0x42d40000,
755 };
756 static const deUint32 s_unsignedInt8UintRef[] =
757 {
758 	0x00000068, 0x000000a6, 0x00000099, 0x0000006e,
759 	0x00000013, 0x00000090, 0x0000000f, 0x00000040,
760 	0x00000034, 0x00000076, 0x00000005, 0x0000009a,
761 	0x0000006c, 0x0000009c, 0x0000001d, 0x0000006a,
762 };
763 static const deUint32 s_unsignedInt8IntRef[] =
764 {
765 	0x00000068, 0x000000a6, 0x00000099, 0x0000006e,
766 	0x00000013, 0x00000090, 0x0000000f, 0x00000040,
767 	0x00000034, 0x00000076, 0x00000005, 0x0000009a,
768 	0x0000006c, 0x0000009c, 0x0000001d, 0x0000006a,
769 };
770 
771 static const deUint8 s_unsignedInt16In[] =
772 {
773 	0xa5, 0x62, 0x98, 0x7c,
774 	0x13, 0x21, 0xc8, 0xf4,
775 	0x78, 0x0b, 0x9f, 0xc2,
776 	0x92, 0x1c, 0xa9, 0x25,
777 	0x86, 0xea, 0x1f, 0x1c,
778 	0x41, 0xf7, 0xe2, 0x2e,
779 	0x38, 0x69, 0xf2, 0x6d,
780 	0x01, 0xec, 0x7f, 0xc5,
781 };
782 static const deUint32 s_unsignedInt16FloatRef[] =
783 {
784 	0x46c54a00, 0x46f93000, 0x46044c00, 0x4774c800,
785 	0x45378000, 0x47429f00, 0x45e49000, 0x4616a400,
786 	0x476a8600, 0x45e0f800, 0x47774100, 0x463b8800,
787 	0x46d27000, 0x46dbe400, 0x476c0100, 0x47457f00,
788 };
789 static const deUint32 s_unsignedInt16UintRef[] =
790 {
791 	0x000062a5, 0x00007c98, 0x00002113, 0x0000f4c8,
792 	0x00000b78, 0x0000c29f, 0x00001c92, 0x000025a9,
793 	0x0000ea86, 0x00001c1f, 0x0000f741, 0x00002ee2,
794 	0x00006938, 0x00006df2, 0x0000ec01, 0x0000c57f,
795 };
796 static const deUint32 s_unsignedInt16IntRef[] =
797 {
798 	0x000062a5, 0x00007c98, 0x00002113, 0x0000f4c8,
799 	0x00000b78, 0x0000c29f, 0x00001c92, 0x000025a9,
800 	0x0000ea86, 0x00001c1f, 0x0000f741, 0x00002ee2,
801 	0x00006938, 0x00006df2, 0x0000ec01, 0x0000c57f,
802 };
803 
804 static const deUint8 s_unsignedInt24In[] =
805 {
806 	0xa8, 0x11, 0x00, 0xc8,
807 	0xe5, 0x07, 0xd3, 0x6d,
808 	0x0a, 0xc7, 0xe4, 0x42,
809 	0x2d, 0xf7, 0x5d, 0x9c,
810 	0x2e, 0x18, 0xfd, 0xa4,
811 	0x9e, 0x90, 0x0c, 0x31,
812 	0x06, 0x04, 0xc4, 0xc2,
813 	0xde, 0xfe, 0x7c, 0x1d,
814 	0x57, 0x37, 0x4a, 0xf2,
815 	0xe2, 0xf3, 0x74, 0x8e,
816 	0x8f, 0xd6, 0x73, 0xc4,
817 	0x91, 0xa0, 0x49, 0xe3,
818 };
819 static const deUint32 s_unsignedInt24FloatRef[] =
820 {
821 	0x458d4000, 0x48fcb900, 0x4926dd30, 0x4a85c98e,
822 	0x4abbee5a, 0x49c174e0, 0x4b1ea4fd, 0x4a443240,
823 	0x4b440406, 0x4b7edec2, 0x4aae3af8, 0x4b724a37,
824 	0x4ae9e7c4, 0x4b568f8e, 0x4b11c473, 0x4b6349a0,
825 };
826 static const deUint32 s_unsignedInt24UintRef[] =
827 {
828 	0x000011a8, 0x0007e5c8, 0x000a6dd3, 0x0042e4c7,
829 	0x005df72d, 0x00182e9c, 0x009ea4fd, 0x00310c90,
830 	0x00c40406, 0x00fedec2, 0x00571d7c, 0x00f24a37,
831 	0x0074f3e2, 0x00d68f8e, 0x0091c473, 0x00e349a0,
832 };
833 static const deUint32 s_unsignedInt24IntRef[] =
834 {
835 	0x000011a8, 0x0007e5c8, 0x000a6dd3, 0x0042e4c7,
836 	0x005df72d, 0x00182e9c, 0x009ea4fd, 0x00310c90,
837 	0x00c40406, 0x00fedec2, 0x00571d7c, 0x00f24a37,
838 	0x0074f3e2, 0x00d68f8e, 0x0091c473, 0x00e349a0,
839 };
840 
841 static const deUint8 s_unsignedInt32In[] =
842 {
843 	0x90, 0xb0, 0x00, 0xa8,
844 	0xd8, 0x42, 0x5b, 0xae,
845 	0x40, 0x70, 0x38, 0x2a,
846 	0x92, 0x76, 0xd8, 0x70,
847 	0x04, 0x0d, 0x67, 0x87,
848 	0x9c, 0xdd, 0xb1, 0xeb,
849 	0xfc, 0x37, 0xe6, 0x40,
850 	0x24, 0x9c, 0x6a, 0x0f,
851 	0x09, 0x0e, 0xb6, 0x2f,
852 	0x31, 0x95, 0x43, 0x22,
853 	0x24, 0xde, 0x70, 0x2a,
854 	0x05, 0xa2, 0x84, 0x38,
855 	0x16, 0x9f, 0x65, 0x0e,
856 	0xb2, 0x99, 0x84, 0x6d,
857 	0xef, 0x86, 0x94, 0xf0,
858 	0x25, 0x9d, 0xf9, 0x67,
859 };
860 static const deUint32 s_unsignedInt32FloatRef[] =
861 {
862 	0x4f2800b1, 0x4f2e5b43, 0x4e28e1c1, 0x4ee1b0ed,
863 	0x4f07670d, 0x4f6bb1de, 0x4e81cc70, 0x4d76a9c2,
864 	0x4e3ed838, 0x4e090e55, 0x4e29c379, 0x4e621288,
865 	0x4d6659f1, 0x4edb0933, 0x4f709487, 0x4ecff33a,
866 };
867 static const deUint32 s_unsignedInt32UintRef[] =
868 {
869 	0xa800b090, 0xae5b42d8, 0x2a387040, 0x70d87692,
870 	0x87670d04, 0xebb1dd9c, 0x40e637fc, 0x0f6a9c24,
871 	0x2fb60e09, 0x22439531, 0x2a70de24, 0x3884a205,
872 	0x0e659f16, 0x6d8499b2, 0xf09486ef, 0x67f99d25,
873 };
874 static const deUint32 s_unsignedInt32IntRef[] =
875 {
876 	0xa800b090, 0xae5b42d8, 0x2a387040, 0x70d87692,
877 	0x87670d04, 0xebb1dd9c, 0x40e637fc, 0x0f6a9c24,
878 	0x2fb60e09, 0x22439531, 0x2a70de24, 0x3884a205,
879 	0x0e659f16, 0x6d8499b2, 0xf09486ef, 0x67f99d25,
880 };
881 
882 static const deUint8 s_halfFloatIn[] =
883 {
884 	0x2b, 0x74, 0x6a, 0x5d,
885 	0x1c, 0xb2, 0x9a, 0x4d,
886 	0xad, 0x55, 0x22, 0x01,
887 	0xce, 0x2d, 0x97, 0x0d,
888 	0x71, 0x31, 0x42, 0x2b,
889 	0xeb, 0x26, 0xc7, 0x16,
890 	0x94, 0xd2, 0x22, 0x79,
891 	0x89, 0xbd, 0xff, 0xbc,
892 };
893 static const deUint32 s_halfFloatFloatRef[] =
894 {
895 	0x46856000, 0x43ad4000, 0xbe438000, 0x41b34000,
896 	0x42b5a000, 0x37910000, 0x3db9c000, 0x39b2e000,
897 	0x3e2e2000, 0x3d684000, 0x3cdd6000, 0x3ad8e000,
898 	0xc2528000, 0x47244000, 0xbfb12000, 0xbf9fe000,
899 };
900 static const deUint32 s_halfFloatUintRef[] =
901 {
902 	0x000042b0, 0x0000015a, 0x00000000, 0x00000016,
903 	0x0000005a, 0x00000000, 0x00000000, 0x00000000,
904 	0x00000000, 0x00000000, 0x00000000, 0x00000000,
905 	0xffffffcc, 0x0000a440, 0xffffffff, 0xffffffff,
906 };
907 static const deUint32 s_halfFloatIntRef[] =
908 {
909 	0x000042b0, 0x0000015a, 0x00000000, 0x00000016,
910 	0x0000005a, 0x00000000, 0x00000000, 0x00000000,
911 	0x00000000, 0x00000000, 0x00000000, 0x00000000,
912 	0xffffffcc, 0x0000a440, 0xffffffff, 0xffffffff,
913 };
914 
915 static const deUint8 s_floatIn[] =
916 {
917 	0x92, 0xac, 0x68, 0x36,
918 	0x9f, 0x42, 0x0b, 0x6e,
919 	0x67, 0xcf, 0x0f, 0x20,
920 	0x22, 0x6c, 0xe4, 0x0f,
921 	0xb3, 0x72, 0xc8, 0x8a,
922 	0x4b, 0x99, 0xc3, 0xb0,
923 	0xbd, 0x78, 0x5c, 0x16,
924 	0x1c, 0xce, 0xb7, 0x4e,
925 	0x15, 0xdf, 0x37, 0xfd,
926 	0xeb, 0x32, 0xe9, 0x47,
927 	0x68, 0x1a, 0xaa, 0xd0,
928 	0xb9, 0xba, 0x77, 0xe7,
929 	0x81, 0x0a, 0x42, 0x5a,
930 	0xb0, 0x5a, 0xee, 0x06,
931 	0x77, 0xb4, 0x7b, 0x57,
932 	0xf5, 0x35, 0xac, 0x56,
933 };
934 static const deUint32 s_floatFloatRef[] =
935 {
936 	0x3668ac92, 0x6e0b429f, 0x200fcf67, 0x0fe46c22,
937 	0x8ac872b3, 0xb0c3994b, 0x165c78bd, 0x4eb7ce1c,
938 	0xfd37df15, 0x47e932eb, 0xd0aa1a68, 0xe777bab9,
939 	0x5a420a81, 0x06ee5ab0, 0x577bb477, 0x56ac35f5,
940 };
941 static const deUint32 s_floatUintRef[] =
942 {
943 	0x00000000, 0x80000000, 0x00000000, 0x00000000,
944 	0x00000000, 0x00000000, 0x00000000, 0x5be70e00,
945 	0x80000000, 0x0001d265, 0x80000000, 0x80000000,
946 	0x80000000, 0x00000000, 0x80000000, 0x80000000,
947 };
948 static const deUint32 s_floatIntRef[] =
949 {
950 	0x00000000, 0x80000000, 0x00000000, 0x00000000,
951 	0x00000000, 0x00000000, 0x00000000, 0x5be70e00,
952 	0x80000000, 0x0001d265, 0x80000000, 0x80000000,
953 	0x80000000, 0x00000000, 0x80000000, 0x80000000,
954 };
955 
956 static const deUint8 s_float64In[] =
957 {
958 	0xbd, 0xb6, 0xc3, 0xd2,
959 	0xf6, 0x62, 0x29, 0xd9,
960 	0x2f, 0xc2, 0x46, 0x18,
961 	0x6b, 0x0d, 0x0a, 0x53,
962 	0x6d, 0x0c, 0xf3, 0x80,
963 	0xbd, 0xa9, 0x12, 0x89,
964 	0x6b, 0x9f, 0x3d, 0xdd,
965 	0xb3, 0x91, 0xee, 0xf5,
966 	0x92, 0xac, 0x68, 0x36,
967 	0x9f, 0x42, 0x0b, 0x6e,
968 	0x67, 0xcf, 0x0f, 0x20,
969 	0x22, 0x6c, 0xe4, 0x0f,
970 	0xb3, 0x72, 0xc8, 0x8a,
971 	0x4b, 0x99, 0xc3, 0xb0,
972 	0xbd, 0x78, 0x5c, 0x16,
973 	0x1c, 0xce, 0xb7, 0x4e,
974 	0x15, 0xdf, 0x37, 0xfd,
975 	0xeb, 0x32, 0xe9, 0x47,
976 	0x68, 0x1a, 0xaa, 0xd0,
977 	0xb9, 0xba, 0x77, 0xe7,
978 	0x81, 0x0a, 0x42, 0x5a,
979 	0xb0, 0x5a, 0xee, 0x06,
980 	0x77, 0xb4, 0x7b, 0x57,
981 	0xf5, 0x35, 0xac, 0x56,
982 	0x2b, 0x74, 0x6a, 0x5d,
983 	0x1c, 0xb2, 0x9a, 0x4d,
984 	0xad, 0x55, 0x22, 0x01,
985 	0xce, 0x2d, 0x97, 0x0d,
986 	0x71, 0x31, 0x42, 0x2b,
987 	0xeb, 0x26, 0xc7, 0x16,
988 	0x94, 0xd2, 0x22, 0x79,
989 	0x89, 0xbd, 0xff, 0xbc,
990 };
991 static const deUint32 s_float64FloatRef[] =
992 {
993 	0xff800000, 0x7f800000, 0x80000000, 0xff800000,
994 	0x7f800000, 0x00000000, 0x80000000, 0x7f800000,
995 	0x7f499760, 0xff800000, 0x00000000, 0x7f800000,
996 	0x7f800000, 0x00000000, 0x00000000, 0xa7fdec4c,
997 };
998 static const deUint32 s_float64IntRef[] =
999 {
1000 	0x80000000, 0x80000000, 0x00000000, 0x80000000,
1001 	0x80000000, 0x00000000, 0x00000000, 0x80000000,
1002 	0x80000000, 0x80000000, 0x00000000, 0x80000000,
1003 	0x80000000, 0x00000000, 0x00000000, 0x00000000,
1004 };
1005 
1006 static const deUint8 s_floatUnsignedInt248RevIn[] =
1007 {
1008 	0xbd, 0xb6, 0xc3, 0xd2,
1009 	0xf6, 0x62, 0x29, 0xd9,
1010 	0x2f, 0xc2, 0x46, 0x18,
1011 	0x6b, 0x0d, 0x0a, 0x53,
1012 	0x6d, 0x0c, 0xf3, 0x80,
1013 	0xbd, 0xa9, 0x12, 0x89,
1014 	0x6b, 0x9f, 0x3d, 0xdd,
1015 	0xb3, 0x91, 0xee, 0xf5,
1016 };
1017 static const deUint32 s_floatUnsignedInt248RevFloatRef[] =
1018 {
1019 	0xd2c3b6bd, 0x00000000, 0x00000000, 0x3f800000,
1020 	0x1846c22f, 0x00000000, 0x00000000, 0x3f800000,
1021 	0x80f30c6d, 0x00000000, 0x00000000, 0x3f800000,
1022 	0xdd3d9f6b, 0x00000000, 0x00000000, 0x3f800000,
1023 };
1024 static const deUint32 s_floatUnsignedInt248RevUintRef[] =
1025 {
1026 	0x000000f6, 0x00000000, 0x00000000, 0x00000001,
1027 	0x0000006b, 0x00000000, 0x00000000, 0x00000001,
1028 	0x000000bd, 0x00000000, 0x00000000, 0x00000001,
1029 	0x000000b3, 0x00000000, 0x00000000, 0x00000001,
1030 };
1031 
1032 // \todo [2015-10-12 pyry] Collapse duplicate ref arrays
1033 
1034 static const struct
1035 {
1036 	const deUint8*		input;
1037 	const int			inputSize;
1038 	const deUint32*		floatRef;
1039 	const deUint32*		intRef;
1040 	const deUint32*		uintRef;
1041 } s_formatData[] =
1042 {
1043 	{ s_snormInt8In,				DE_LENGTH_OF_ARRAY(s_snormInt8In),					s_snormInt8FloatRef,				s_snormInt8IntRef,				s_snormInt8UintRef				},
1044 	{ s_snormInt16In,				DE_LENGTH_OF_ARRAY(s_snormInt16In),					s_snormInt16FloatRef,				s_snormInt16IntRef,				s_snormInt16UintRef				},
1045 	{ s_snormInt32In,				DE_LENGTH_OF_ARRAY(s_snormInt32In),					s_snormInt32FloatRef,				s_snormInt32IntRef,				s_snormInt32UintRef				},
1046 	{ s_unormInt8In,				DE_LENGTH_OF_ARRAY(s_unormInt8In),					s_unormInt8FloatRef,				s_unormInt8IntRef,				s_unormInt8UintRef				},
1047 	{ s_unormInt16In,				DE_LENGTH_OF_ARRAY(s_unormInt16In),					s_unormInt16FloatRef,				s_unormInt16IntRef,				s_unormInt16UintRef				},
1048 	{ s_unormInt24In,				DE_LENGTH_OF_ARRAY(s_unormInt24In),					s_unormInt24FloatRef,				s_unormInt24IntRef,				s_unormInt24UintRef				},
1049 	{ s_unormInt32In,				DE_LENGTH_OF_ARRAY(s_unormInt32In),					s_unormInt32FloatRef,				s_unormInt32IntRef,				s_unormInt32UintRef				},
1050 	{ s_unormByte44In,				DE_LENGTH_OF_ARRAY(s_unormByte44In),				s_unormByte44FloatRef,				s_unormByte44IntRef,			s_unormByte44IntRef				},
1051 	{ s_unormShort565In,			DE_LENGTH_OF_ARRAY(s_unormShort565In),				s_unormShort565FloatRef,			s_unormShort565IntRef,			s_unormShort565IntRef,			},
1052 	{ s_unormShort555In,			DE_LENGTH_OF_ARRAY(s_unormShort555In),				s_unormShort555FloatRef,			s_unormShort555IntRef,			s_unormShort555IntRef,			},
1053 	{ s_unormShort4444In,			DE_LENGTH_OF_ARRAY(s_unormShort4444In),				s_unormShort4444FloatRef,			s_unormShort4444IntRef,			s_unormShort4444IntRef,			},
1054 	{ s_unormShort5551In,			DE_LENGTH_OF_ARRAY(s_unormShort5551In),				s_unormShort5551FloatRef,			s_unormShort5551IntRef,			s_unormShort5551IntRef,			},
1055 	{ s_unormShort1555In,			DE_LENGTH_OF_ARRAY(s_unormShort1555In),				s_unormShort1555FloatRef,			s_unormShort1555IntRef,			s_unormShort1555IntRef,			},
1056 	{ s_unormInt101010In,			DE_LENGTH_OF_ARRAY(s_unormInt101010In),				s_unormInt101010FloatRef,			s_unormInt101010IntRef,			s_unormInt101010IntRef			},
1057 
1058 	// \note Same input data & int reference used for {U,S}NORM_INT_1010102_REV
1059 	{ s_unormInt1010102RevIn,		DE_LENGTH_OF_ARRAY(s_unormInt1010102RevIn),			s_snormInt1010102RevFloatRef,		s_snormInt1010102RevIntRef,		s_snormInt1010102RevIntRef		},
1060 	{ s_unormInt1010102RevIn,		DE_LENGTH_OF_ARRAY(s_unormInt1010102RevIn),			s_unormInt1010102RevFloatRef,		s_unormInt1010102RevIntRef,		s_unormInt1010102RevIntRef		},
1061 
1062 	// \note UNSIGNED_BYTE_* and UNSIGNED_SHORT_* re-use input data and integer reference values from UNORM_* cases
1063 	{ s_unormByte44In,				DE_LENGTH_OF_ARRAY(s_unormByte44In),				s_unsignedByte44FloatRef,			s_unormByte44IntRef,			s_unormByte44IntRef				},
1064 	{ s_unormShort565In,			DE_LENGTH_OF_ARRAY(s_unormShort565In),				s_unsignedShort565FloatRef,			s_unormShort565IntRef,			s_unormShort565IntRef,			},
1065 	{ s_unormShort4444In,			DE_LENGTH_OF_ARRAY(s_unormShort4444In),				s_unsignedShort4444FloatRef,		s_unormShort4444IntRef,			s_unormShort4444IntRef,			},
1066 	{ s_unormShort5551In,			DE_LENGTH_OF_ARRAY(s_unormShort5551In),				s_unsignedShort5551FloatRef,		s_unormShort5551IntRef,			s_unormShort5551IntRef,			},
1067 
1068 	// \note (UN)SIGNED_INT_1010102_REV formats use same input data
1069 	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_signedInt1010102RevFloatRef,		s_signedInt1010102RevIntRef,	s_signedInt1010102RevIntRef		},
1070 	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_unsignedInt1010102RevFloatRef,	s_unsignedInt1010102RevIntRef,	s_unsignedInt1010102RevIntRef	},
1071 
1072 	{ s_unsignedInt11f11f10fRevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt11f11f10fRevIn),	s_unsignedInt11f11f10fRevFloatRef,	DE_NULL,						DE_NULL							},
1073 	{ s_unsignedInt999E5RevIn,		DE_LENGTH_OF_ARRAY(s_unsignedInt999E5RevIn),		s_unsignedInt999E5RevFloatRef,		DE_NULL,						DE_NULL							},
1074 	{ s_unsignedInt1688In,			DE_LENGTH_OF_ARRAY(s_unsignedInt1688In),			s_unsignedInt1688FloatRef,			DE_NULL,						s_unsignedInt1688UintRef		},
1075 	{ s_unsignedInt248In,			DE_LENGTH_OF_ARRAY(s_unsignedInt248In),				s_unsignedInt248FloatRef,			DE_NULL,						s_unsignedInt248UintRef			},
1076 	{ s_unsignedInt248RevIn,		DE_LENGTH_OF_ARRAY(s_unsignedInt248RevIn),			s_unsignedInt248RevFloatRef,		DE_NULL,						s_unsignedInt248RevUintRef		},
1077 	{ s_signedInt8In,				DE_LENGTH_OF_ARRAY(s_signedInt8In),					s_signedInt8FloatRef,				s_signedInt8IntRef,				s_signedInt8UintRef				},
1078 	{ s_signedInt16In,				DE_LENGTH_OF_ARRAY(s_signedInt16In),				s_signedInt16FloatRef,				s_signedInt16IntRef,			s_signedInt16UintRef			},
1079 	{ s_signedInt32In,				DE_LENGTH_OF_ARRAY(s_signedInt32In),				s_signedInt32FloatRef,				s_signedInt32IntRef,			s_signedInt32UintRef			},
1080 	{ s_unsignedInt8In,				DE_LENGTH_OF_ARRAY(s_unsignedInt8In),				s_unsignedInt8FloatRef,				s_unsignedInt8IntRef,			s_unsignedInt8UintRef			},
1081 	{ s_unsignedInt16In,			DE_LENGTH_OF_ARRAY(s_unsignedInt16In),				s_unsignedInt16FloatRef,			s_unsignedInt16IntRef,			s_unsignedInt16UintRef			},
1082 	{ s_unsignedInt24In,			DE_LENGTH_OF_ARRAY(s_unsignedInt24In),				s_unsignedInt24FloatRef,			s_unsignedInt24IntRef,			s_unsignedInt24UintRef			},
1083 	{ s_unsignedInt32In,			DE_LENGTH_OF_ARRAY(s_unsignedInt32In),				s_unsignedInt32FloatRef,			s_unsignedInt32IntRef,			s_unsignedInt32UintRef			},
1084 	{ s_halfFloatIn,				DE_LENGTH_OF_ARRAY(s_halfFloatIn),					s_halfFloatFloatRef,				s_halfFloatIntRef,				s_halfFloatUintRef				},
1085 	{ s_floatIn,					DE_LENGTH_OF_ARRAY(s_floatIn),						s_floatFloatRef,					s_floatIntRef,					s_floatUintRef					},
1086 	{ s_float64In,					DE_LENGTH_OF_ARRAY(s_float64In),					s_float64FloatRef,					s_float64IntRef,				s_float64IntRef					},
1087 	{ s_floatUnsignedInt248RevIn,	DE_LENGTH_OF_ARRAY(s_floatUnsignedInt248RevIn),		s_floatUnsignedInt248RevFloatRef,	DE_NULL,						s_floatUnsignedInt248RevUintRef	},
1088 };
1089 DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_formatData) == TextureFormat::CHANNELTYPE_LAST);
1090 
getBaseFormat(TextureFormat format)1091 TextureFormat getBaseFormat (TextureFormat format)
1092 {
1093 	const TextureFormat::ChannelOrder baseOrders[] = { TextureFormat::RGBA, TextureFormat::RGB, TextureFormat::DS };
1094 
1095 	for (int baseOrderNdx = 0; baseOrderNdx < DE_LENGTH_OF_ARRAY(baseOrders); baseOrderNdx++)
1096 	{
1097 		const TextureFormat	curBaseFmt	(baseOrders[baseOrderNdx], format.type);
1098 		if (isValid(curBaseFmt))
1099 			return curBaseFmt;
1100 	}
1101 
1102 	return format;
1103 }
1104 
getInputAccess(TextureFormat format)1105 ConstPixelBufferAccess getInputAccess (TextureFormat format)
1106 {
1107 	const TextureFormat	inputFormat		= getBaseFormat(format);
1108 	const int			inputPixelSize	= getPixelSize(inputFormat);
1109 	const int			numPixels		= s_formatData[format.type].inputSize / inputPixelSize;
1110 
1111 	DE_ASSERT(numPixels == 4);
1112 	DE_ASSERT(numPixels*inputPixelSize == s_formatData[format.type].inputSize);
1113 
1114 	return ConstPixelBufferAccess(format, IVec3(numPixels, 1, 1), IVec3(inputPixelSize, 0, 0), s_formatData[format.type].input);
1115 }
1116 
1117 template<typename T>
1118 const deUint32* getRawReference (TextureFormat format);
1119 
1120 template<>
getRawReference(TextureFormat format)1121 const deUint32* getRawReference<float> (TextureFormat format)
1122 {
1123 	return s_formatData[format.type].floatRef;
1124 }
1125 
1126 template<>
getRawReference(TextureFormat format)1127 const deUint32* getRawReference<deInt32> (TextureFormat format)
1128 {
1129 	return s_formatData[format.type].intRef;
1130 }
1131 
1132 template<>
getRawReference(TextureFormat format)1133 const deUint32* getRawReference<deUint32> (TextureFormat format)
1134 {
1135 	return s_formatData[format.type].uintRef;
1136 }
1137 
1138 template<typename T>
getReferenceValues(TextureFormat storageFormat,TextureFormat viewFormat,vector<Vector<T,4>> & dst)1139 void getReferenceValues (TextureFormat storageFormat, TextureFormat viewFormat, vector<Vector<T, 4> >& dst)
1140 {
1141 	const int					numPixels	= getInputAccess(storageFormat).getWidth();
1142 	const deUint32* const		rawValues	= getRawReference<T>(storageFormat);
1143 	const tcu::TextureSwizzle&	swizzle		= tcu::getChannelReadSwizzle(viewFormat.order);
1144 
1145 	dst.resize(numPixels);
1146 
1147 	for (int pixelNdx = 0; pixelNdx < numPixels; pixelNdx++)
1148 	{
1149 		const deUint32*	srcPixPtr	= rawValues + pixelNdx*4;
1150 		T*				dstPixPtr	= (T*)&dst[pixelNdx];
1151 
1152 		for (int c = 0; c < 4; c++)
1153 		{
1154 			switch (swizzle.components[c])
1155 			{
1156 				case tcu::TextureSwizzle::CHANNEL_0:
1157 				case tcu::TextureSwizzle::CHANNEL_1:
1158 				case tcu::TextureSwizzle::CHANNEL_2:
1159 				case tcu::TextureSwizzle::CHANNEL_3:
1160 					deMemcpy(dstPixPtr + c, srcPixPtr + (int)swizzle.components[c], sizeof(deUint32));
1161 					break;
1162 
1163 				case tcu::TextureSwizzle::CHANNEL_ZERO:
1164 					dstPixPtr[c] = T(0);
1165 					break;
1166 
1167 				case tcu::TextureSwizzle::CHANNEL_ONE:
1168 					dstPixPtr[c] = T(1);
1169 					break;
1170 
1171 				default:
1172 					DE_FATAL("Unknown swizzle");
1173 			}
1174 		}
1175 	}
1176 }
1177 
1178 template<typename T>
componentEqual(T a,T b)1179 bool componentEqual (T a, T b)
1180 {
1181 	return a == b;
1182 }
1183 
1184 template<>
componentEqual(float a,float b)1185 bool componentEqual<float> (float a, float b)
1186 {
1187 	return (a == b) || (deFloatIsNaN(a) && deFloatIsNaN(b));
1188 }
1189 
1190 template<typename T, int Size>
allComponentsEqual(const Vector<T,Size> & a,const Vector<T,Size> & b)1191 bool allComponentsEqual (const Vector<T, Size>& a, const Vector<T, Size>& b)
1192 {
1193 	for (int ndx = 0; ndx < Size; ndx++)
1194 	{
1195 		if (!componentEqual(a[ndx], b[ndx]))
1196 			return false;
1197 	}
1198 
1199 	return true;
1200 }
1201 
1202 template<typename T>
copyPixels(const ConstPixelBufferAccess & src,const PixelBufferAccess & dst)1203 void copyPixels (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1204 {
1205 	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1206 		dst.setPixel(src.getPixelT<T>(ndx, 0, 0), ndx, 0, 0);
1207 }
1208 
copyGetSetDepth(const ConstPixelBufferAccess & src,const PixelBufferAccess & dst)1209 void copyGetSetDepth (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1210 {
1211 	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1212 		dst.setPixDepth(src.getPixDepth(ndx, 0, 0), ndx, 0, 0);
1213 }
1214 
copyGetSetStencil(const ConstPixelBufferAccess & src,const PixelBufferAccess & dst)1215 void copyGetSetStencil (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1216 {
1217 	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1218 		dst.setPixStencil(src.getPixStencil(ndx, 0, 0), ndx, 0, 0);
1219 }
1220 
copyPixels(const ConstPixelBufferAccess & src,const PixelBufferAccess & dst)1221 void copyPixels (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1222 {
1223 	switch (getTextureChannelClass(dst.getFormat().type))
1224 	{
1225 		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1226 		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1227 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1228 			copyPixels<float>(src, dst);
1229 			break;
1230 
1231 		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1232 			copyPixels<deInt32>(src, dst);
1233 			break;
1234 
1235 		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1236 			copyPixels<deUint32>(src, dst);
1237 			break;
1238 
1239 		default:
1240 			DE_FATAL("Unknown channel class");
1241 	}
1242 }
1243 
getTextureAccessTypeDescription(TextureAccessType type)1244 const char* getTextureAccessTypeDescription (TextureAccessType type)
1245 {
1246 	static const char* s_desc[] =
1247 	{
1248 		"floating-point",
1249 		"signed integer",
1250 		"unsigned integer"
1251 	};
1252 	return de::getSizedArrayElement<tcu::TEXTUREACCESSTYPE_LAST>(s_desc, type);
1253 }
1254 
1255 template<typename T>
1256 TextureAccessType getTextureAccessType (void);
1257 
1258 template<>
getTextureAccessType(void)1259 TextureAccessType getTextureAccessType<float> (void)
1260 {
1261 	return tcu::TEXTUREACCESSTYPE_FLOAT;
1262 }
1263 
1264 template<>
getTextureAccessType(void)1265 TextureAccessType getTextureAccessType<deInt32> (void)
1266 {
1267 	return tcu::TEXTUREACCESSTYPE_SIGNED_INT;
1268 }
1269 
1270 template<>
getTextureAccessType(void)1271 TextureAccessType getTextureAccessType<deUint32> (void)
1272 {
1273 	return tcu::TEXTUREACCESSTYPE_UNSIGNED_INT;
1274 }
1275 
getCaseName(TextureFormat format)1276 static std::string getCaseName (TextureFormat format)
1277 {
1278 	std::ostringstream str;
1279 
1280 	str << format.type << "_" << format.order;
1281 
1282 	return de::toLower(str.str());
1283 }
1284 
1285 class TextureFormatCase : public tcu::TestCase
1286 {
1287 public:
TextureFormatCase(tcu::TestContext & testCtx,TextureFormat format)1288 	TextureFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1289 		: tcu::TestCase	(testCtx, getCaseName(format).c_str(), "")
1290 		, m_format		(format)
1291 	{
1292 		DE_ASSERT(isValid(format));
1293 	}
1294 
1295 protected:
1296 	template<typename T>
verifyRead(const ConstPixelBufferAccess & src)1297 	void verifyRead (const ConstPixelBufferAccess& src)
1298 	{
1299 		const int				numPixels	= src.getWidth();
1300 		vector<Vector<T, 4> >	res			(numPixels);
1301 		vector<Vector<T, 4> >	ref;
1302 
1303 		m_testCtx.getLog()
1304 			<< TestLog::Message << "Verifying " << getTextureAccessTypeDescription(getTextureAccessType<T>()) << " access" << TestLog::EndMessage;
1305 
1306 		for (int ndx = 0; ndx < numPixels; ndx++)
1307 			res[ndx] = src.getPixelT<T>(ndx, 0, 0);
1308 
1309 		// \note m_format != src.getFormat() for DS formats, and we specifically need to
1310 		//		 use the combined format as storage format to get right reference values.
1311 		getReferenceValues<T>(m_format, src.getFormat(), ref);
1312 
1313 		for (int pixelNdx = 0; pixelNdx < numPixels; pixelNdx++)
1314 		{
1315 			if (!allComponentsEqual(res[pixelNdx], ref[pixelNdx]))
1316 			{
1317 				m_testCtx.getLog()
1318 					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref[pixelNdx] << ", got " << res[pixelNdx] << TestLog::EndMessage;
1319 
1320 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1321 			}
1322 		}
1323 	}
1324 
verifyRead(const ConstPixelBufferAccess & src)1325 	void verifyRead (const ConstPixelBufferAccess& src)
1326 	{
1327 		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_FLOAT))
1328 			verifyRead<float>(src);
1329 
1330 		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_UNSIGNED_INT))
1331 			verifyRead<deUint32>(src);
1332 
1333 		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_SIGNED_INT))
1334 			verifyRead<deInt32>(src);
1335 	}
1336 
verifyGetPixDepth(const ConstPixelBufferAccess & refAccess,const ConstPixelBufferAccess & combinedAccess)1337 	void verifyGetPixDepth (const ConstPixelBufferAccess& refAccess, const ConstPixelBufferAccess& combinedAccess)
1338 	{
1339 		m_testCtx.getLog()
1340 			<< TestLog::Message << "Verifying getPixDepth()" << TestLog::EndMessage;
1341 
1342 		for (int pixelNdx = 0; pixelNdx < refAccess.getWidth(); pixelNdx++)
1343 		{
1344 			const float		ref		= refAccess.getPixel(pixelNdx, 0, 0).x();
1345 			const float		res		= combinedAccess.getPixDepth(pixelNdx, 0, 0);
1346 
1347 			if (!componentEqual(res, ref))
1348 			{
1349 				m_testCtx.getLog()
1350 					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref << ", got " << res << TestLog::EndMessage;
1351 
1352 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1353 			}
1354 		}
1355 	}
1356 
verifyGetPixStencil(const ConstPixelBufferAccess & refAccess,const ConstPixelBufferAccess & combinedAccess)1357 	void verifyGetPixStencil (const ConstPixelBufferAccess& refAccess, const ConstPixelBufferAccess& combinedAccess)
1358 	{
1359 		m_testCtx.getLog()
1360 			<< TestLog::Message << "Verifying getPixStencil()" << TestLog::EndMessage;
1361 
1362 		for (int pixelNdx = 0; pixelNdx < refAccess.getWidth(); pixelNdx++)
1363 		{
1364 			const int	ref		= refAccess.getPixelInt(pixelNdx, 0, 0).x();
1365 			const int	res		= combinedAccess.getPixStencil(pixelNdx, 0, 0);
1366 
1367 			if (!componentEqual(res, ref))
1368 			{
1369 				m_testCtx.getLog()
1370 					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref << ", got " << res << TestLog::EndMessage;
1371 
1372 				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1373 			}
1374 		}
1375 	}
1376 
verifyInfoQueries(void)1377 	void verifyInfoQueries (void)
1378 	{
1379 		const tcu::TextureChannelClass	chnClass	= tcu::getTextureChannelClass(m_format.type);
1380 		const tcu::TextureFormatInfo	fmtInfo		= tcu::getTextureFormatInfo(m_format);
1381 
1382 		if (tcu::isCombinedDepthStencilType(m_format.type))
1383 			TCU_CHECK(chnClass == tcu::TEXTURECHANNELCLASS_LAST);
1384 		else
1385 			TCU_CHECK(de::inBounds(chnClass, (tcu::TextureChannelClass)0, tcu::TEXTURECHANNELCLASS_LAST));
1386 
1387 		DE_UNREF(fmtInfo);
1388 	}
1389 
1390 	const TextureFormat		m_format;
1391 };
1392 
1393 class ColorFormatCase : public TextureFormatCase
1394 {
1395 public:
ColorFormatCase(tcu::TestContext & testCtx,TextureFormat format)1396 	ColorFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1397 		: TextureFormatCase(testCtx, format)
1398 	{
1399 		DE_ASSERT(format.order != TextureFormat::D &&
1400 				  format.order != TextureFormat::S &&
1401 				  format.order != TextureFormat::DS);
1402 	}
1403 
iterate(void)1404 	IterateResult iterate (void)
1405 	{
1406 		const ConstPixelBufferAccess	inputAccess		= getInputAccess(m_format);
1407 		vector<deUint8>					tmpMem			(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1408 		const PixelBufferAccess			tmpAccess		(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1409 
1410 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1411 
1412 		verifyInfoQueries();
1413 
1414 		verifyRead(inputAccess);
1415 
1416 		// \todo [2015-10-12 pyry] Handle lossy conversion with *NORM_INT32
1417 		if (m_format.type != TextureFormat::UNORM_INT32 && m_format.type != TextureFormat::SNORM_INT32)
1418 		{
1419 			m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1420 			copyPixels(inputAccess, tmpAccess);
1421 			verifyRead(tmpAccess);
1422 		}
1423 
1424 		return STOP;
1425 	}
1426 };
1427 
1428 class DepthFormatCase : public TextureFormatCase
1429 {
1430 public:
DepthFormatCase(tcu::TestContext & testCtx,TextureFormat format)1431 	DepthFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1432 		: TextureFormatCase(testCtx, format)
1433 	{
1434 		DE_ASSERT(format.order == TextureFormat::D);
1435 	}
1436 
iterate(void)1437 	IterateResult iterate (void)
1438 	{
1439 		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1440 		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1441 		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1442 		const ConstPixelBufferAccess	inputDepthAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_DEPTH);
1443 		const PixelBufferAccess			tmpDepthAccess		= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_DEPTH);
1444 
1445 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1446 
1447 		verifyInfoQueries();
1448 
1449 		verifyRead(inputDepthAccess);
1450 
1451 		m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1452 		copyPixels(inputDepthAccess, tmpDepthAccess);
1453 		verifyRead(tmpDepthAccess);
1454 
1455 		verifyGetPixDepth(inputDepthAccess, inputAccess);
1456 
1457 		m_testCtx.getLog() << TestLog::Message << "Copying both depth getPixDepth() -> setPixDepth()" << TestLog::EndMessage;
1458 		tcu::clear(tmpDepthAccess, tcu::Vec4(0.0f));
1459 		copyGetSetDepth(inputAccess, tmpAccess);
1460 		verifyGetPixDepth(tmpDepthAccess, tmpAccess);
1461 
1462 		return STOP;
1463 	}
1464 };
1465 
1466 class StencilFormatCase : public TextureFormatCase
1467 {
1468 public:
StencilFormatCase(tcu::TestContext & testCtx,TextureFormat format)1469 	StencilFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1470 		: TextureFormatCase(testCtx, format)
1471 	{
1472 		DE_ASSERT(format.order == TextureFormat::S);
1473 	}
1474 
iterate(void)1475 	IterateResult iterate (void)
1476 	{
1477 		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1478 		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1479 		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1480 		const ConstPixelBufferAccess	inputStencilAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_STENCIL);
1481 		const PixelBufferAccess			tmpStencilAccess	= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_STENCIL);
1482 
1483 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1484 
1485 		verifyInfoQueries();
1486 
1487 		verifyRead(inputStencilAccess);
1488 
1489 		m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1490 		copyPixels(inputStencilAccess, tmpStencilAccess);
1491 		verifyRead(tmpStencilAccess);
1492 
1493 		verifyGetPixStencil(inputStencilAccess, inputAccess);
1494 
1495 		m_testCtx.getLog() << TestLog::Message << "Copying both depth getPixStencil() -> setPixStencil()" << TestLog::EndMessage;
1496 		tcu::clear(tmpStencilAccess, tcu::IVec4(0));
1497 		copyGetSetStencil(inputAccess, tmpAccess);
1498 		verifyGetPixStencil(tmpStencilAccess, tmpAccess);
1499 
1500 		return STOP;
1501 	}
1502 };
1503 
1504 class DepthStencilFormatCase : public TextureFormatCase
1505 {
1506 public:
DepthStencilFormatCase(tcu::TestContext & testCtx,TextureFormat format)1507 	DepthStencilFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1508 		: TextureFormatCase(testCtx, format)
1509 	{
1510 		DE_ASSERT(format.order == TextureFormat::DS);
1511 	}
1512 
iterate(void)1513 	IterateResult iterate (void)
1514 	{
1515 		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1516 		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1517 		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1518 		const ConstPixelBufferAccess	inputDepthAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_DEPTH);
1519 		const ConstPixelBufferAccess	inputStencilAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_STENCIL);
1520 		const PixelBufferAccess			tmpDepthAccess		= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_DEPTH);
1521 		const PixelBufferAccess			tmpStencilAccess	= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_STENCIL);
1522 
1523 		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1524 
1525 		verifyInfoQueries();
1526 
1527 		verifyRead(inputDepthAccess);
1528 		verifyRead(inputStencilAccess);
1529 
1530 		verifyGetPixDepth(inputDepthAccess, inputAccess);
1531 		verifyGetPixStencil(inputStencilAccess, inputAccess);
1532 
1533 		m_testCtx.getLog() << TestLog::Message << "Copying both depth and stencil with getPixel() -> setPixel()" << TestLog::EndMessage;
1534 		copyPixels(inputDepthAccess, tmpDepthAccess);
1535 		copyPixels(inputStencilAccess, tmpStencilAccess);
1536 		verifyRead(tmpDepthAccess);
1537 		verifyRead(tmpStencilAccess);
1538 
1539 		m_testCtx.getLog() << TestLog::Message << "Copying both depth and stencil with getPix{Depth,Stencil}() -> setPix{Depth,Stencil}()" << TestLog::EndMessage;
1540 		copyGetSetDepth(inputDepthAccess, tmpDepthAccess);
1541 		copyGetSetStencil(inputStencilAccess, tmpStencilAccess);
1542 		verifyRead(tmpDepthAccess);
1543 		verifyRead(tmpStencilAccess);
1544 
1545 		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing depth component with clearDepth() doesn't affect stencil" << TestLog::EndMessage;
1546 		tcu::copy(tmpAccess, inputAccess);
1547 		tcu::clearDepth(tmpAccess, 0.0f);
1548 		verifyRead(tmpStencilAccess);
1549 
1550 		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing stencil component with clearStencil() doesn't affect depth" << TestLog::EndMessage;
1551 		tcu::copy(tmpAccess, inputAccess);
1552 		tcu::clearStencil(tmpAccess, 0);
1553 		verifyRead(tmpDepthAccess);
1554 
1555 		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing depth component with setPixDepth() doesn't affect stencil" << TestLog::EndMessage;
1556 		tcu::copy(tmpAccess, inputAccess);
1557 
1558 		for (int ndx = 0; ndx < tmpAccess.getWidth(); ndx++)
1559 			tmpAccess.setPixDepth(0.0f, ndx, 0, 0);
1560 
1561 		verifyRead(tmpStencilAccess);
1562 
1563 		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing stencil component with setPixStencil() doesn't affect depth" << TestLog::EndMessage;
1564 		tcu::copy(tmpAccess, inputAccess);
1565 
1566 		for (int ndx = 0; ndx < tmpAccess.getWidth(); ndx++)
1567 			tmpAccess.setPixStencil(0, ndx, 0, 0);
1568 
1569 		verifyRead(tmpDepthAccess);
1570 
1571 		return STOP;
1572 	}
1573 };
1574 
1575 } // anonymous
1576 
createTextureFormatTests(tcu::TestContext & testCtx)1577 tcu::TestCaseGroup* createTextureFormatTests (tcu::TestContext& testCtx)
1578 {
1579 	de::MovePtr<tcu::TestCaseGroup>	group	(new tcu::TestCaseGroup(testCtx, "texture_format", "Texture format tests"));
1580 
1581 	for (int channelType = 0; channelType < TextureFormat::CHANNELTYPE_LAST; channelType++)
1582 	{
1583 		for (int channelOrder = 0; channelOrder < TextureFormat::CHANNELORDER_LAST; channelOrder++)
1584 		{
1585 			const TextureFormat		format		((TextureFormat::ChannelOrder)channelOrder, (TextureFormat::ChannelType)channelType);
1586 
1587 			if (!isValid(format))
1588 				continue;
1589 
1590 			if (tcu::isSRGB(format))
1591 				continue; // \todo [2015-10-12 pyry] Tests for sRGB formats (need thresholds)
1592 
1593 			if (format.order == TextureFormat::DS)
1594 				group->addChild(new DepthStencilFormatCase(testCtx, format));
1595 			else if (format.order == TextureFormat::D)
1596 				group->addChild(new DepthFormatCase(testCtx, format));
1597 			else if (format.order == TextureFormat::S)
1598 				group->addChild(new StencilFormatCase(testCtx, format));
1599 			else
1600 				group->addChild(new ColorFormatCase(testCtx, format));
1601 		}
1602 	}
1603 
1604 	return group.release();
1605 }
1606 
1607 } // dit
1608