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
39namespace dit
40{
41
42namespace
43{
44
45using std::string;
46using std::vector;
47
48using tcu::TestLog;
49using tcu::TextureFormat;
50using tcu::TextureChannelClass;
51using tcu::TextureAccessType;
52using tcu::PixelBufferAccess;
53using tcu::ConstPixelBufferAccess;
54using tcu::Vector;
55using tcu::IVec3;
56
57// Test data
58
59static 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};
66static 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};
73static 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};
80static 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
88static 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};
99static 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};
106static 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};
113static 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
121static 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};
140static 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};
147static 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};
154static 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
162static 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};
169static 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};
176static 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};
183static 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
191static 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};
202static 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};
209static 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};
216static 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
224static 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};
239static 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};
246static 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};
253static 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
261static 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};
280static 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};
287static 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};
294static 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
302static const deUint8 s_unormByte44In[] =
303{
304	0xdb, 0xa8, 0x29, 0x2d,
305};
306static 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};
313static 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};
320static 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
328static const deUint8 s_unormShort565In[] =
329{
330	0xea, 0x7e, 0xcc, 0x28,
331	0x38, 0xce, 0x8f, 0x16,
332};
333static 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};
340static 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};
347static 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
355static const deUint8 s_unormShort555In[] =
356{
357	0x02, 0xea, 0x89, 0x13,
358	0x94, 0x5a, 0x5b, 0x60,
359};
360static 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};
367static 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
375static const deUint8 s_unormShort4444In[] =
376{
377	0x19, 0xdb, 0xa8, 0xa8,
378	0x72, 0x29, 0xb4, 0x2d,
379};
380static 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};
387static 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};
394static 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
402static const deUint8 s_unormShort5551In[] =
403{
404	0x13, 0x89, 0x6f, 0x3c,
405	0xae, 0xe9, 0xf2, 0xd9,
406};
407static 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};
414static 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};
421static 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
429static const deUint8 s_unormShort1555In[] =
430{
431	0xf8, 0xc5, 0x1f, 0x6c,
432	0xf0, 0x2f, 0xf2, 0x95,
433};
434static 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};
441static 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
449static 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};
456static 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};
463static 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
471static 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};
478static 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};
485static 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};
492static 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};
499static 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
507static 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};
514static 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};
521static 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};
528static 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};
535static 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
543static 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};
550static 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
558static 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};
565static 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
573static 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};
580static 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};
587static 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
595static 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};
602static 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};
609static 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
617static 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};
624static 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};
631static 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
639static 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};
646static 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};
653static 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};
660static 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
668static 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};
679static 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};
686static 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};
693static 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
701static 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};
720static 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};
727static 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};
734static 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
742static 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};
749static 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};
756static 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};
763static 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
771static 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};
782static 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};
789static 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};
796static 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
804static 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};
819static 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};
826static 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};
833static 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
841static 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};
860static 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};
867static 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};
874static 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
882static const deUint8 s_Int64In[] =
883{
884	0x90, 0xb0, 0x00, 0x78, 0x01, 0x00, 0x00, 0x00,
885	0x40, 0x70, 0x38, 0x2a, 0x01, 0x01, 0x00, 0x00,
886	0x04, 0x0d, 0x67, 0x87, 0x01, 0x01, 0x01, 0x00,
887	0xfc, 0x37, 0xe6, 0x40, 0x01, 0x01, 0x01, 0x01,
888	0x09, 0x0e, 0xb6, 0x2f, 0x02, 0x01, 0x01, 0x01,
889	0x24, 0xde, 0x70, 0x2a, 0x01, 0x02, 0x01, 0x01,
890	0x16, 0x9f, 0x65, 0x0e, 0x01, 0x01, 0x02, 0x01,
891	0xef, 0x86, 0x94, 0x72, 0x01, 0x01, 0x01, 0x02,
892	0xc6, 0x7e, 0x50, 0x2a, 0x01, 0x00, 0x00, 0x00,
893	0x4d, 0xa9, 0x77, 0x0d, 0x01, 0x01, 0x00, 0x00,
894	0xf0, 0xb7, 0xde, 0x6b, 0x01, 0x01, 0x01, 0x00,
895	0xa8, 0x9c, 0xfc, 0x6d, 0x01, 0x01, 0x01, 0x01,
896	0xf3, 0x19, 0x14, 0x97, 0x02, 0x01, 0x01, 0x01,
897	0x95, 0x32, 0xab, 0x7a, 0x01, 0x02, 0x01, 0x01,
898	0x68, 0x84, 0xd9, 0x71, 0x01, 0x01, 0x02, 0x01,
899	0xf7, 0x73, 0x8f, 0x0a, 0x01, 0x01, 0x01, 0x02,
900};
901
902static const deUint32 s_Int64FloatRef[] =
903{
904	0x4fbc0058, 0x5380951c, 0x578080c4, 0x5b808081,
905	0x5b808081, 0x5b808101, 0x5b810081, 0x5c004040,
906	0x4f95283f, 0x538086bc, 0x578080b6, 0x5b808081,
907	0x5b808081, 0x5b808101, 0x5b810081, 0x5c004040,
908};
909
910static const deUint32 s_Int64IntRef[] =
911{
912	0x7800b090, 0x2a387040, 0x87670d04, 0x40e637fc,
913	0x2fb60e09, 0x2a70de24, 0x0e659f16, 0x729486ef,
914	0x2a507ec6, 0x0d77a94d, 0x6bdeb7f0, 0x6dfc9ca8,
915	0x971419f3, 0x7aab3295, 0x71d98468, 0x0a8f73f7,
916};
917
918static const deUint8 s_halfFloatIn[] =
919{
920	0x2b, 0x74, 0x6a, 0x5d,
921	0x1c, 0xb2, 0x9a, 0x4d,
922	0xad, 0x55, 0x22, 0x01,
923	0xce, 0x2d, 0x97, 0x0d,
924	0x71, 0x31, 0x42, 0x2b,
925	0xeb, 0x26, 0xc7, 0x16,
926	0x94, 0xd2, 0x22, 0x79,
927	0x89, 0xbd, 0xff, 0xbc,
928};
929static const deUint32 s_halfFloatFloatRef[] =
930{
931	0x46856000, 0x43ad4000, 0xbe438000, 0x41b34000,
932	0x42b5a000, 0x37910000, 0x3db9c000, 0x39b2e000,
933	0x3e2e2000, 0x3d684000, 0x3cdd6000, 0x3ad8e000,
934	0xc2528000, 0x47244000, 0xbfb12000, 0xbf9fe000,
935};
936static const deUint32 s_halfFloatUintRef[] =
937{
938	0x000042b0, 0x0000015a, 0x00000000, 0x00000016,
939	0x0000005a, 0x00000000, 0x00000000, 0x00000000,
940	0x00000000, 0x00000000, 0x00000000, 0x00000000,
941	0xffffffcc, 0x0000a440, 0xffffffff, 0xffffffff,
942};
943static const deUint32 s_halfFloatIntRef[] =
944{
945	0x000042b0, 0x0000015a, 0x00000000, 0x00000016,
946	0x0000005a, 0x00000000, 0x00000000, 0x00000000,
947	0x00000000, 0x00000000, 0x00000000, 0x00000000,
948	0xffffffcc, 0x0000a440, 0xffffffff, 0xffffffff,
949};
950
951static const deUint8 s_floatIn[] =
952{
953	0x92, 0xac, 0x68, 0x36,
954	0x9f, 0x42, 0x0b, 0x6e,
955	0x67, 0xcf, 0x0f, 0x20,
956	0x22, 0x6c, 0xe4, 0x0f,
957	0xb3, 0x72, 0xc8, 0x8a,
958	0x4b, 0x99, 0xc3, 0xb0,
959	0xbd, 0x78, 0x5c, 0x16,
960	0x1c, 0xce, 0xb7, 0x4e,
961	0x15, 0xdf, 0x37, 0xfd,
962	0xeb, 0x32, 0xe9, 0x47,
963	0x68, 0x1a, 0xaa, 0xd0,
964	0xb9, 0xba, 0x77, 0xe7,
965	0x81, 0x0a, 0x42, 0x5a,
966	0xb0, 0x5a, 0xee, 0x06,
967	0x77, 0xb4, 0x7b, 0x57,
968	0xf5, 0x35, 0xac, 0x56,
969};
970static const deUint32 s_floatFloatRef[] =
971{
972	0x3668ac92, 0x6e0b429f, 0x200fcf67, 0x0fe46c22,
973	0x8ac872b3, 0xb0c3994b, 0x165c78bd, 0x4eb7ce1c,
974	0xfd37df15, 0x47e932eb, 0xd0aa1a68, 0xe777bab9,
975	0x5a420a81, 0x06ee5ab0, 0x577bb477, 0x56ac35f5,
976};
977static const deUint32 s_floatUintRef[] =
978{
979	0x00000000, 0x80000000, 0x00000000, 0x00000000,
980	0x00000000, 0x00000000, 0x00000000, 0x5be70e00,
981	0x80000000, 0x0001d265, 0x80000000, 0x80000000,
982	0x80000000, 0x00000000, 0x80000000, 0x80000000,
983};
984static const deUint32 s_floatIntRef[] =
985{
986	0x00000000, 0x80000000, 0x00000000, 0x00000000,
987	0x00000000, 0x00000000, 0x00000000, 0x5be70e00,
988	0x80000000, 0x0001d265, 0x80000000, 0x80000000,
989	0x80000000, 0x00000000, 0x80000000, 0x80000000,
990};
991
992static const deUint8 s_float64In[] =
993{
994	0xbd, 0xb6, 0xc3, 0xd2,
995	0xf6, 0x62, 0x29, 0xd9,
996	0x2f, 0xc2, 0x46, 0x18,
997	0x6b, 0x0d, 0x0a, 0x53,
998	0x6d, 0x0c, 0xf3, 0x80,
999	0xbd, 0xa9, 0x12, 0x89,
1000	0x6b, 0x9f, 0x3d, 0xdd,
1001	0xb3, 0x91, 0xee, 0xf5,
1002	0x92, 0xac, 0x68, 0x36,
1003	0x9f, 0x42, 0x0b, 0x6e,
1004	0x67, 0xcf, 0x0f, 0x20,
1005	0x22, 0x6c, 0xe4, 0x0f,
1006	0xb3, 0x72, 0xc8, 0x8a,
1007	0x4b, 0x99, 0xc3, 0xb0,
1008	0xbd, 0x78, 0x5c, 0x16,
1009	0x1c, 0xce, 0xb7, 0x4e,
1010	0x15, 0xdf, 0x37, 0xfd,
1011	0xeb, 0x32, 0xe9, 0x47,
1012	0x68, 0x1a, 0xaa, 0xd0,
1013	0xb9, 0xba, 0x77, 0xe7,
1014	0x81, 0x0a, 0x42, 0x5a,
1015	0xb0, 0x5a, 0xee, 0x06,
1016	0x77, 0xb4, 0x7b, 0x57,
1017	0xf5, 0x35, 0xac, 0x56,
1018	0x2b, 0x74, 0x6a, 0x5d,
1019	0x1c, 0xb2, 0x9a, 0x4d,
1020	0xad, 0x55, 0x22, 0x01,
1021	0xce, 0x2d, 0x97, 0x0d,
1022	0x71, 0x31, 0x42, 0x2b,
1023	0xeb, 0x26, 0xc7, 0x16,
1024	0x94, 0xd2, 0x22, 0x79,
1025	0x89, 0xbd, 0xff, 0xbc,
1026};
1027static const deUint32 s_float64FloatRef[] =
1028{
1029	0xff800000, 0x7f800000, 0x80000000, 0xff800000,
1030	0x7f800000, 0x00000000, 0x80000000, 0x7f800000,
1031	0x7f499760, 0xff800000, 0x00000000, 0x7f800000,
1032	0x7f800000, 0x00000000, 0x00000000, 0xa7fdec4c,
1033};
1034static const deUint32 s_float64IntRef[] =
1035{
1036	0x80000000, 0x80000000, 0x00000000, 0x80000000,
1037	0x80000000, 0x00000000, 0x00000000, 0x80000000,
1038	0x80000000, 0x80000000, 0x00000000, 0x80000000,
1039	0x80000000, 0x00000000, 0x00000000, 0x00000000,
1040};
1041
1042static const deUint8 s_floatUnsignedInt248RevIn[] =
1043{
1044	0xbd, 0xb6, 0xc3, 0xd2,
1045	0xf6, 0x62, 0x29, 0xd9,
1046	0x2f, 0xc2, 0x46, 0x18,
1047	0x6b, 0x0d, 0x0a, 0x53,
1048	0x6d, 0x0c, 0xf3, 0x80,
1049	0xbd, 0xa9, 0x12, 0x89,
1050	0x6b, 0x9f, 0x3d, 0xdd,
1051	0xb3, 0x91, 0xee, 0xf5,
1052};
1053static const deUint32 s_floatUnsignedInt248RevFloatRef[] =
1054{
1055	0xd2c3b6bd, 0x00000000, 0x00000000, 0x3f800000,
1056	0x1846c22f, 0x00000000, 0x00000000, 0x3f800000,
1057	0x80f30c6d, 0x00000000, 0x00000000, 0x3f800000,
1058	0xdd3d9f6b, 0x00000000, 0x00000000, 0x3f800000,
1059};
1060static const deUint32 s_floatUnsignedInt248RevUintRef[] =
1061{
1062	0x000000f6, 0x00000000, 0x00000000, 0x00000001,
1063	0x0000006b, 0x00000000, 0x00000000, 0x00000001,
1064	0x000000bd, 0x00000000, 0x00000000, 0x00000001,
1065	0x000000b3, 0x00000000, 0x00000000, 0x00000001,
1066};
1067
1068static const deUint8 s_unormShort10In[] =
1069{
1070	0x80, 0x84, 0x40, 0x3b,
1071	0x40, 0xfd, 0x80, 0x1a,
1072	0x80, 0x0c, 0x80, 0x15,
1073	0x40, 0x11, 0x80, 0xc3,
1074	0x80, 0xc8, 0x80, 0xd5,
1075	0xc0, 0xf9, 0x00, 0x0a,
1076	0xc0, 0x39, 0x40, 0xd5,
1077	0xc0, 0x4d, 0xc0, 0x26
1078};
1079static const deUint32 s_unormShort10FloatRef[] =
1080{
1081	0x3f04a128, 0x3e6d3b4f,
1082	0x3f7d7f60, 0x3dd4350d,
1083	0x3d48320d, 0x3dac2b0b,
1084	0x3d8a2289, 0x3f43b0ec,
1085	0x3f48b22d, 0x3f55b56d,
1086	0x3f79fe80, 0x3d20280a,
1087	0x3e6739ce, 0x3f55755d,
1088	0x3e9ba6ea, 0x3e1b26ca
1089};
1090static const deUint32 s_unormShort10UintRef[] =
1091{
1092	0x212, 0x0ed, 0x3f5, 0x06a,
1093	0x032, 0x056, 0x045, 0x30e,
1094	0x322, 0x356, 0x3e7, 0x028,
1095	0x0e7, 0x355, 0x137, 0x09b,
1096};
1097static const deUint32 s_unormShort10IntRef[] =
1098{
1099	0x212, 0x0ed, 0x3f5, 0x06a,
1100	0x032, 0x056, 0x045, 0x30e,
1101	0x322, 0x356, 0x3e7, 0x028,
1102	0x0e7, 0x355, 0x137, 0x09b,
1103};
1104
1105static const deUint8 s_unormShort12In[] =
1106{
1107	0x30, 0x46, 0xf0, 0x38,
1108	0x90, 0x85, 0xf0, 0x88,
1109	0x90, 0x92, 0x30, 0x5d,
1110	0x30, 0x3a, 0x00, 0xc9,
1111	0x00, 0x64, 0xb0, 0x9b,
1112	0x20, 0x71, 0xd0, 0x5b,
1113	0xa0, 0xc5, 0x70, 0x27,
1114	0x30, 0x0b, 0xa0, 0x53
1115};
1116static const deUint32 s_unormShort12FloatRef[] =
1117{
1118	0x3e8c68c7, 0x3e63ce3d,
1119	0x3f05985a, 0x3f08f890,
1120	0x3f12992a, 0x3eba6ba7,
1121	0x3e68ce8d, 0x3f490c91,
1122	0x3ec80c81, 0x3f1bb9bc,
1123	0x3ee24e25, 0x3eb7ab7b,
1124	0x3f45ac5b, 0x3e1dc9dd,
1125	0x3d330b31, 0x3ea74a75
1126};
1127static const deUint32 s_unormShort12UintRef[] =
1128{
1129	0x463, 0x38f,
1130	0x859, 0x88f,
1131	0x929, 0x5d3,
1132	0x3a3, 0xc90,
1133	0x640, 0x9bb,
1134	0x712, 0x5bd,
1135	0xc5a, 0x277,
1136	0x0b3, 0x53a
1137};
1138static const deUint32 s_unormShort12IntRef[] =
1139{
1140	0x463, 0x38f,
1141	0x859, 0x88f,
1142	0x929, 0x5d3,
1143	0x3a3, 0xc90,
1144	0x640, 0x9bb,
1145	0x712, 0x5bd,
1146	0xc5a, 0x277,
1147	0x0b3, 0x53a
1148};
1149
1150// \todo [2015-10-12 pyry] Collapse duplicate ref arrays
1151
1152static const struct
1153{
1154	const deUint8*		input;
1155	const int			inputSize;
1156	const deUint32*		floatRef;
1157	const deUint32*		intRef;
1158	const deUint32*		uintRef;
1159} s_formatData[] =
1160{
1161	{ s_snormInt8In,				DE_LENGTH_OF_ARRAY(s_snormInt8In),					s_snormInt8FloatRef,				s_snormInt8IntRef,				s_snormInt8UintRef				},
1162	{ s_snormInt16In,				DE_LENGTH_OF_ARRAY(s_snormInt16In),					s_snormInt16FloatRef,				s_snormInt16IntRef,				s_snormInt16UintRef				},
1163	{ s_snormInt32In,				DE_LENGTH_OF_ARRAY(s_snormInt32In),					s_snormInt32FloatRef,				s_snormInt32IntRef,				s_snormInt32UintRef				},
1164	{ s_unormInt8In,				DE_LENGTH_OF_ARRAY(s_unormInt8In),					s_unormInt8FloatRef,				s_unormInt8IntRef,				s_unormInt8UintRef				},
1165	{ s_unormInt16In,				DE_LENGTH_OF_ARRAY(s_unormInt16In),					s_unormInt16FloatRef,				s_unormInt16IntRef,				s_unormInt16UintRef				},
1166	{ s_unormInt24In,				DE_LENGTH_OF_ARRAY(s_unormInt24In),					s_unormInt24FloatRef,				s_unormInt24IntRef,				s_unormInt24UintRef				},
1167	{ s_unormInt32In,				DE_LENGTH_OF_ARRAY(s_unormInt32In),					s_unormInt32FloatRef,				s_unormInt32IntRef,				s_unormInt32UintRef				},
1168	{ s_unormByte44In,				DE_LENGTH_OF_ARRAY(s_unormByte44In),				s_unormByte44FloatRef,				s_unormByte44IntRef,			s_unormByte44IntRef				},
1169	{ s_unormShort565In,			DE_LENGTH_OF_ARRAY(s_unormShort565In),				s_unormShort565FloatRef,			s_unormShort565IntRef,			s_unormShort565IntRef,			},
1170	{ s_unormShort555In,			DE_LENGTH_OF_ARRAY(s_unormShort555In),				s_unormShort555FloatRef,			s_unormShort555IntRef,			s_unormShort555IntRef,			},
1171	{ s_unormShort4444In,			DE_LENGTH_OF_ARRAY(s_unormShort4444In),				s_unormShort4444FloatRef,			s_unormShort4444IntRef,			s_unormShort4444IntRef,			},
1172	{ s_unormShort5551In,			DE_LENGTH_OF_ARRAY(s_unormShort5551In),				s_unormShort5551FloatRef,			s_unormShort5551IntRef,			s_unormShort5551IntRef,			},
1173	{ s_unormShort1555In,			DE_LENGTH_OF_ARRAY(s_unormShort1555In),				s_unormShort1555FloatRef,			s_unormShort1555IntRef,			s_unormShort1555IntRef,			},
1174	{ s_unormInt101010In,			DE_LENGTH_OF_ARRAY(s_unormInt101010In),				s_unormInt101010FloatRef,			s_unormInt101010IntRef,			s_unormInt101010IntRef			},
1175
1176	// \note Same input data & int reference used for {U,S}NORM_INT_1010102_REV
1177	{ s_unormInt1010102RevIn,		DE_LENGTH_OF_ARRAY(s_unormInt1010102RevIn),			s_snormInt1010102RevFloatRef,		s_snormInt1010102RevIntRef,		s_snormInt1010102RevIntRef		},
1178	{ s_unormInt1010102RevIn,		DE_LENGTH_OF_ARRAY(s_unormInt1010102RevIn),			s_unormInt1010102RevFloatRef,		s_unormInt1010102RevIntRef,		s_unormInt1010102RevIntRef		},
1179
1180	// \note UNSIGNED_BYTE_* and UNSIGNED_SHORT_* re-use input data and integer reference values from UNORM_* cases
1181	{ s_unormByte44In,				DE_LENGTH_OF_ARRAY(s_unormByte44In),				s_unsignedByte44FloatRef,			s_unormByte44IntRef,			s_unormByte44IntRef				},
1182	{ s_unormShort565In,			DE_LENGTH_OF_ARRAY(s_unormShort565In),				s_unsignedShort565FloatRef,			s_unormShort565IntRef,			s_unormShort565IntRef,			},
1183	{ s_unormShort4444In,			DE_LENGTH_OF_ARRAY(s_unormShort4444In),				s_unsignedShort4444FloatRef,		s_unormShort4444IntRef,			s_unormShort4444IntRef,			},
1184	{ s_unormShort5551In,			DE_LENGTH_OF_ARRAY(s_unormShort5551In),				s_unsignedShort5551FloatRef,		s_unormShort5551IntRef,			s_unormShort5551IntRef,			},
1185
1186	// \note (UN)SIGNED_INT_1010102_REV formats use same input data
1187	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_signedInt1010102RevFloatRef,		s_signedInt1010102RevIntRef,	s_signedInt1010102RevIntRef		},
1188	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_unsignedInt1010102RevFloatRef,	s_unsignedInt1010102RevIntRef,	s_unsignedInt1010102RevIntRef	},
1189
1190	{ s_unsignedInt11f11f10fRevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt11f11f10fRevIn),	s_unsignedInt11f11f10fRevFloatRef,	DE_NULL,						DE_NULL							},
1191	{ s_unsignedInt999E5RevIn,		DE_LENGTH_OF_ARRAY(s_unsignedInt999E5RevIn),		s_unsignedInt999E5RevFloatRef,		DE_NULL,						DE_NULL							},
1192	{ s_unsignedInt1688In,			DE_LENGTH_OF_ARRAY(s_unsignedInt1688In),			s_unsignedInt1688FloatRef,			DE_NULL,						s_unsignedInt1688UintRef		},
1193	{ s_unsignedInt248In,			DE_LENGTH_OF_ARRAY(s_unsignedInt248In),				s_unsignedInt248FloatRef,			DE_NULL,						s_unsignedInt248UintRef			},
1194	{ s_unsignedInt248RevIn,		DE_LENGTH_OF_ARRAY(s_unsignedInt248RevIn),			s_unsignedInt248RevFloatRef,		DE_NULL,						s_unsignedInt248RevUintRef		},
1195	{ s_signedInt8In,				DE_LENGTH_OF_ARRAY(s_signedInt8In),					s_signedInt8FloatRef,				s_signedInt8IntRef,				s_signedInt8UintRef				},
1196	{ s_signedInt16In,				DE_LENGTH_OF_ARRAY(s_signedInt16In),				s_signedInt16FloatRef,				s_signedInt16IntRef,			s_signedInt16UintRef			},
1197	{ s_signedInt32In,				DE_LENGTH_OF_ARRAY(s_signedInt32In),				s_signedInt32FloatRef,				s_signedInt32IntRef,			s_signedInt32UintRef			},
1198	{ s_Int64In,					DE_LENGTH_OF_ARRAY(s_Int64In),						s_Int64FloatRef,					s_Int64IntRef,					s_Int64IntRef					},
1199	{ s_unsignedInt8In,				DE_LENGTH_OF_ARRAY(s_unsignedInt8In),				s_unsignedInt8FloatRef,				s_unsignedInt8IntRef,			s_unsignedInt8UintRef			},
1200	{ s_unsignedInt16In,			DE_LENGTH_OF_ARRAY(s_unsignedInt16In),				s_unsignedInt16FloatRef,			s_unsignedInt16IntRef,			s_unsignedInt16UintRef			},
1201	{ s_unsignedInt24In,			DE_LENGTH_OF_ARRAY(s_unsignedInt24In),				s_unsignedInt24FloatRef,			s_unsignedInt24IntRef,			s_unsignedInt24UintRef			},
1202	{ s_unsignedInt32In,			DE_LENGTH_OF_ARRAY(s_unsignedInt32In),				s_unsignedInt32FloatRef,			s_unsignedInt32IntRef,			s_unsignedInt32UintRef			},
1203	{ s_Int64In,					DE_LENGTH_OF_ARRAY(s_Int64In),						s_Int64FloatRef,					s_Int64IntRef,					s_Int64IntRef					},
1204
1205	{ s_halfFloatIn,				DE_LENGTH_OF_ARRAY(s_halfFloatIn),					s_halfFloatFloatRef,				s_halfFloatIntRef,				s_halfFloatUintRef				},
1206	{ s_floatIn,					DE_LENGTH_OF_ARRAY(s_floatIn),						s_floatFloatRef,					s_floatIntRef,					s_floatUintRef					},
1207	{ s_float64In,					DE_LENGTH_OF_ARRAY(s_float64In),					s_float64FloatRef,					s_float64IntRef,				s_float64IntRef					},
1208	{ s_floatUnsignedInt248RevIn,	DE_LENGTH_OF_ARRAY(s_floatUnsignedInt248RevIn),		s_floatUnsignedInt248RevFloatRef,	DE_NULL,						s_floatUnsignedInt248RevUintRef	},
1209
1210	{ s_unormShort10In,				DE_LENGTH_OF_ARRAY(s_unormShort10In),				s_unormShort10FloatRef,				s_unormShort10IntRef,			s_unormShort10UintRef			},
1211	{ s_unormShort12In,				DE_LENGTH_OF_ARRAY(s_unormShort12In),				s_unormShort12FloatRef,				s_unormShort12IntRef,			s_unormShort12UintRef			},
1212
1213	{ s_unsignedInt8In,				DE_LENGTH_OF_ARRAY(s_unsignedInt8In),				s_unsignedInt8FloatRef,				s_unsignedInt8IntRef,			s_unsignedInt8UintRef			},
1214	{ s_unsignedInt16In,			DE_LENGTH_OF_ARRAY(s_unsignedInt16In),				s_unsignedInt16FloatRef,			s_unsignedInt16IntRef,			s_unsignedInt16UintRef			},
1215	{ s_signedInt8In,				DE_LENGTH_OF_ARRAY(s_signedInt8In),					s_signedInt8FloatRef,				s_signedInt8IntRef,				s_signedInt8UintRef				},
1216	{ s_signedInt16In,				DE_LENGTH_OF_ARRAY(s_signedInt16In),				s_signedInt16FloatRef,				s_signedInt16IntRef,			s_signedInt16UintRef			},
1217	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_unsignedInt1010102RevFloatRef,	s_unsignedInt1010102RevIntRef,	s_unsignedInt1010102RevIntRef	},
1218	{ s_unsignedInt1010102RevIn,	DE_LENGTH_OF_ARRAY(s_unsignedInt1010102RevIn),		s_signedInt1010102RevFloatRef,		s_signedInt1010102RevIntRef,	s_signedInt1010102RevIntRef		}
1219};
1220DE_STATIC_ASSERT(DE_LENGTH_OF_ARRAY(s_formatData) == TextureFormat::CHANNELTYPE_LAST);
1221
1222TextureFormat getBaseFormat (TextureFormat format)
1223{
1224	const TextureFormat::ChannelOrder baseOrders[] = { TextureFormat::RGBA, TextureFormat::RGB, TextureFormat::DS };
1225
1226	for (int baseOrderNdx = 0; baseOrderNdx < DE_LENGTH_OF_ARRAY(baseOrders); baseOrderNdx++)
1227	{
1228		const TextureFormat	curBaseFmt	(baseOrders[baseOrderNdx], format.type);
1229		if (isValid(curBaseFmt))
1230			return curBaseFmt;
1231	}
1232
1233	return format;
1234}
1235
1236ConstPixelBufferAccess getInputAccess (TextureFormat format)
1237{
1238	const TextureFormat	inputFormat		= getBaseFormat(format);
1239	const int			inputPixelSize	= getPixelSize(inputFormat);
1240	const int			numPixels		= s_formatData[format.type].inputSize / inputPixelSize;
1241
1242	DE_ASSERT(numPixels == 4);
1243	DE_ASSERT(numPixels*inputPixelSize == s_formatData[format.type].inputSize);
1244
1245	return ConstPixelBufferAccess(format, IVec3(numPixels, 1, 1), IVec3(inputPixelSize, 0, 0), s_formatData[format.type].input);
1246}
1247
1248template<typename T>
1249const deUint32* getRawReference (TextureFormat format);
1250
1251template<>
1252const deUint32* getRawReference<float> (TextureFormat format)
1253{
1254	return s_formatData[format.type].floatRef;
1255}
1256
1257template<>
1258const deUint32* getRawReference<deInt32> (TextureFormat format)
1259{
1260	return s_formatData[format.type].intRef;
1261}
1262
1263template<>
1264const deUint32* getRawReference<deUint32> (TextureFormat format)
1265{
1266	return s_formatData[format.type].uintRef;
1267}
1268
1269template<typename T>
1270void getReferenceValues (TextureFormat storageFormat, TextureFormat viewFormat, vector<Vector<T, 4> >& dst)
1271{
1272	const int					numPixels	= getInputAccess(storageFormat).getWidth();
1273	const deUint32* const		rawValues	= getRawReference<T>(storageFormat);
1274	const tcu::TextureSwizzle&	swizzle		= tcu::getChannelReadSwizzle(viewFormat.order);
1275
1276	dst.resize(numPixels);
1277
1278	for (int pixelNdx = 0; pixelNdx < numPixels; pixelNdx++)
1279	{
1280		const deUint32*	srcPixPtr	= rawValues + pixelNdx*4;
1281		T*				dstPixPtr	= (T*)&dst[pixelNdx];
1282
1283		for (int c = 0; c < 4; c++)
1284		{
1285			switch (swizzle.components[c])
1286			{
1287				case tcu::TextureSwizzle::CHANNEL_0:
1288				case tcu::TextureSwizzle::CHANNEL_1:
1289				case tcu::TextureSwizzle::CHANNEL_2:
1290				case tcu::TextureSwizzle::CHANNEL_3:
1291					deMemcpy(dstPixPtr + c, srcPixPtr + (int)swizzle.components[c], sizeof(deUint32));
1292					break;
1293
1294				case tcu::TextureSwizzle::CHANNEL_ZERO:
1295					dstPixPtr[c] = T(0);
1296					break;
1297
1298				case tcu::TextureSwizzle::CHANNEL_ONE:
1299					dstPixPtr[c] = T(1);
1300					break;
1301
1302				default:
1303					DE_FATAL("Unknown swizzle");
1304			}
1305		}
1306	}
1307}
1308
1309template<typename T>
1310bool componentEqual (T a, T b)
1311{
1312	return a == b;
1313}
1314
1315template<>
1316bool componentEqual<float> (float a, float b)
1317{
1318	return (a == b) || (deFloatIsNaN(a) && deFloatIsNaN(b));
1319}
1320
1321template<typename T, int Size>
1322bool allComponentsEqual (const Vector<T, Size>& a, const Vector<T, Size>& b)
1323{
1324	for (int ndx = 0; ndx < Size; ndx++)
1325	{
1326		if (!componentEqual(a[ndx], b[ndx]))
1327			return false;
1328	}
1329
1330	return true;
1331}
1332
1333template<typename T>
1334void copyPixels (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1335{
1336	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1337		dst.setPixel(src.getPixelT<T>(ndx, 0, 0), ndx, 0, 0);
1338}
1339
1340void copyGetSetDepth (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1341{
1342	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1343		dst.setPixDepth(src.getPixDepth(ndx, 0, 0), ndx, 0, 0);
1344}
1345
1346void copyGetSetStencil (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1347{
1348	for (int ndx = 0; ndx < src.getWidth(); ndx++)
1349		dst.setPixStencil(src.getPixStencil(ndx, 0, 0), ndx, 0, 0);
1350}
1351
1352void copyPixels (const ConstPixelBufferAccess& src, const PixelBufferAccess& dst)
1353{
1354	switch (getTextureChannelClass(dst.getFormat().type))
1355	{
1356		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1357		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1358		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1359			copyPixels<float>(src, dst);
1360			break;
1361
1362		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1363			copyPixels<deInt32>(src, dst);
1364			break;
1365
1366		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1367			copyPixels<deUint32>(src, dst);
1368			break;
1369
1370		default:
1371			DE_FATAL("Unknown channel class");
1372	}
1373}
1374
1375const char* getTextureAccessTypeDescription (TextureAccessType type)
1376{
1377	static const char* s_desc[] =
1378	{
1379		"floating-point",
1380		"signed integer",
1381		"unsigned integer"
1382	};
1383	return de::getSizedArrayElement<tcu::TEXTUREACCESSTYPE_LAST>(s_desc, type);
1384}
1385
1386template<typename T>
1387TextureAccessType getTextureAccessType (void);
1388
1389template<>
1390TextureAccessType getTextureAccessType<float> (void)
1391{
1392	return tcu::TEXTUREACCESSTYPE_FLOAT;
1393}
1394
1395template<>
1396TextureAccessType getTextureAccessType<deInt32> (void)
1397{
1398	return tcu::TEXTUREACCESSTYPE_SIGNED_INT;
1399}
1400
1401template<>
1402TextureAccessType getTextureAccessType<deUint32> (void)
1403{
1404	return tcu::TEXTUREACCESSTYPE_UNSIGNED_INT;
1405}
1406
1407static std::string getCaseName (TextureFormat format)
1408{
1409	std::ostringstream str;
1410
1411	str << format.type << "_" << format.order;
1412
1413	return de::toLower(str.str());
1414}
1415
1416class TextureFormatCase : public tcu::TestCase
1417{
1418public:
1419	TextureFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1420		: tcu::TestCase	(testCtx, getCaseName(format).c_str(), "")
1421		, m_format		(format)
1422	{
1423		DE_ASSERT(isValid(format));
1424	}
1425
1426protected:
1427	template<typename T>
1428	void verifyRead (const ConstPixelBufferAccess& src)
1429	{
1430		const int				numPixels	= src.getWidth();
1431		vector<Vector<T, 4> >	res			(numPixels);
1432		vector<Vector<T, 4> >	ref;
1433
1434		m_testCtx.getLog()
1435			<< TestLog::Message << "Verifying " << getTextureAccessTypeDescription(getTextureAccessType<T>()) << " access" << TestLog::EndMessage;
1436
1437		for (int ndx = 0; ndx < numPixels; ndx++)
1438			res[ndx] = src.getPixelT<T>(ndx, 0, 0);
1439
1440		// \note m_format != src.getFormat() for DS formats, and we specifically need to
1441		//		 use the combined format as storage format to get right reference values.
1442		getReferenceValues<T>(m_format, src.getFormat(), ref);
1443
1444		for (int pixelNdx = 0; pixelNdx < numPixels; pixelNdx++)
1445		{
1446			if (!allComponentsEqual(res[pixelNdx], ref[pixelNdx]))
1447			{
1448				m_testCtx.getLog()
1449					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref[pixelNdx] << ", got " << res[pixelNdx] << TestLog::EndMessage;
1450
1451				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1452			}
1453		}
1454	}
1455
1456	void verifyRead (const ConstPixelBufferAccess& src)
1457	{
1458		// \todo [2016-08-04 pyry] Overflow in float->int conversion is not defined and
1459		//						   produces different results depending on arch.
1460		const bool	isFloat32Or64	= src.getFormat().type == tcu::TextureFormat::FLOAT ||
1461									  src.getFormat().type == tcu::TextureFormat::FLOAT64;
1462
1463		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_FLOAT))
1464			verifyRead<float>(src);
1465
1466		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_UNSIGNED_INT) && !isFloat32Or64)
1467			verifyRead<deUint32>(src);
1468
1469		if (isAccessValid(src.getFormat(), tcu::TEXTUREACCESSTYPE_SIGNED_INT) && !isFloat32Or64)
1470			verifyRead<deInt32>(src);
1471	}
1472
1473	void verifyGetPixDepth (const ConstPixelBufferAccess& refAccess, const ConstPixelBufferAccess& combinedAccess)
1474	{
1475		m_testCtx.getLog()
1476			<< TestLog::Message << "Verifying getPixDepth()" << TestLog::EndMessage;
1477
1478		for (int pixelNdx = 0; pixelNdx < refAccess.getWidth(); pixelNdx++)
1479		{
1480			const float		ref		= refAccess.getPixel(pixelNdx, 0, 0).x();
1481			const float		res		= combinedAccess.getPixDepth(pixelNdx, 0, 0);
1482
1483			if (!componentEqual(res, ref))
1484			{
1485				m_testCtx.getLog()
1486					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref << ", got " << res << TestLog::EndMessage;
1487
1488				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1489			}
1490		}
1491	}
1492
1493	void verifyGetPixStencil (const ConstPixelBufferAccess& refAccess, const ConstPixelBufferAccess& combinedAccess)
1494	{
1495		m_testCtx.getLog()
1496			<< TestLog::Message << "Verifying getPixStencil()" << TestLog::EndMessage;
1497
1498		for (int pixelNdx = 0; pixelNdx < refAccess.getWidth(); pixelNdx++)
1499		{
1500			const int	ref		= refAccess.getPixelInt(pixelNdx, 0, 0).x();
1501			const int	res		= combinedAccess.getPixStencil(pixelNdx, 0, 0);
1502
1503			if (!componentEqual(res, ref))
1504			{
1505				m_testCtx.getLog()
1506					<< TestLog::Message << "ERROR: at pixel " << pixelNdx << ": expected " << ref << ", got " << res << TestLog::EndMessage;
1507
1508				m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Comparison failed");
1509			}
1510		}
1511	}
1512
1513	void verifyInfoQueries (void)
1514	{
1515		const tcu::TextureChannelClass	chnClass	= tcu::getTextureChannelClass(m_format.type);
1516		const tcu::TextureFormatInfo	fmtInfo		= tcu::getTextureFormatInfo(m_format);
1517
1518		if (tcu::isCombinedDepthStencilType(m_format.type))
1519			TCU_CHECK(chnClass == tcu::TEXTURECHANNELCLASS_LAST);
1520		else
1521			TCU_CHECK(de::inBounds(chnClass, (tcu::TextureChannelClass)0, tcu::TEXTURECHANNELCLASS_LAST));
1522
1523		DE_UNREF(fmtInfo);
1524	}
1525
1526	const TextureFormat		m_format;
1527};
1528
1529class ColorFormatCase : public TextureFormatCase
1530{
1531public:
1532	ColorFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1533		: TextureFormatCase(testCtx, format)
1534	{
1535		DE_ASSERT(format.order != TextureFormat::D &&
1536				  format.order != TextureFormat::S &&
1537				  format.order != TextureFormat::DS);
1538	}
1539
1540	IterateResult iterate (void)
1541	{
1542		const ConstPixelBufferAccess	inputAccess		= getInputAccess(m_format);
1543		vector<deUint8>					tmpMem			(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1544		const PixelBufferAccess			tmpAccess		(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1545
1546		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1547
1548		verifyInfoQueries();
1549
1550		verifyRead(inputAccess);
1551
1552		// \todo [2015-10-12 pyry] Handle lossy conversion with *NORM_INT32
1553		if (m_format.type != TextureFormat::UNORM_INT32 && m_format.type != TextureFormat::SNORM_INT32)
1554		{
1555			m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1556			copyPixels(inputAccess, tmpAccess);
1557			verifyRead(tmpAccess);
1558		}
1559
1560		return STOP;
1561	}
1562};
1563
1564class DepthFormatCase : public TextureFormatCase
1565{
1566public:
1567	DepthFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1568		: TextureFormatCase(testCtx, format)
1569	{
1570		DE_ASSERT(format.order == TextureFormat::D);
1571	}
1572
1573	IterateResult iterate (void)
1574	{
1575		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1576		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1577		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1578		const ConstPixelBufferAccess	inputDepthAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_DEPTH);
1579		const PixelBufferAccess			tmpDepthAccess		= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_DEPTH);
1580
1581		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1582
1583		verifyInfoQueries();
1584
1585		verifyRead(inputDepthAccess);
1586
1587		m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1588		copyPixels(inputDepthAccess, tmpDepthAccess);
1589		verifyRead(tmpDepthAccess);
1590
1591		verifyGetPixDepth(inputDepthAccess, inputAccess);
1592
1593		m_testCtx.getLog() << TestLog::Message << "Copying both depth getPixDepth() -> setPixDepth()" << TestLog::EndMessage;
1594		tcu::clear(tmpDepthAccess, tcu::Vec4(0.0f));
1595		copyGetSetDepth(inputAccess, tmpAccess);
1596		verifyGetPixDepth(tmpDepthAccess, tmpAccess);
1597
1598		return STOP;
1599	}
1600};
1601
1602class StencilFormatCase : public TextureFormatCase
1603{
1604public:
1605	StencilFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1606		: TextureFormatCase(testCtx, format)
1607	{
1608		DE_ASSERT(format.order == TextureFormat::S);
1609	}
1610
1611	IterateResult iterate (void)
1612	{
1613		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1614		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1615		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1616		const ConstPixelBufferAccess	inputStencilAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_STENCIL);
1617		const PixelBufferAccess			tmpStencilAccess	= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_STENCIL);
1618
1619		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1620
1621		verifyInfoQueries();
1622
1623		verifyRead(inputStencilAccess);
1624
1625		m_testCtx.getLog() << TestLog::Message << "Copying with getPixel() -> setPixel()" << TestLog::EndMessage;
1626		copyPixels(inputStencilAccess, tmpStencilAccess);
1627		verifyRead(tmpStencilAccess);
1628
1629		verifyGetPixStencil(inputStencilAccess, inputAccess);
1630
1631		m_testCtx.getLog() << TestLog::Message << "Copying both depth getPixStencil() -> setPixStencil()" << TestLog::EndMessage;
1632		tcu::clear(tmpStencilAccess, tcu::IVec4(0));
1633		copyGetSetStencil(inputAccess, tmpAccess);
1634		verifyGetPixStencil(tmpStencilAccess, tmpAccess);
1635
1636		return STOP;
1637	}
1638};
1639
1640class DepthStencilFormatCase : public TextureFormatCase
1641{
1642public:
1643	DepthStencilFormatCase (tcu::TestContext& testCtx, TextureFormat format)
1644		: TextureFormatCase(testCtx, format)
1645	{
1646		DE_ASSERT(format.order == TextureFormat::DS);
1647	}
1648
1649	IterateResult iterate (void)
1650	{
1651		const ConstPixelBufferAccess	inputAccess			= getInputAccess(m_format);
1652		vector<deUint8>					tmpMem				(getPixelSize(inputAccess.getFormat())*inputAccess.getWidth());
1653		const PixelBufferAccess			tmpAccess			(inputAccess.getFormat(), inputAccess.getWidth(), 1, 1, &tmpMem[0]);
1654		const ConstPixelBufferAccess	inputDepthAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_DEPTH);
1655		const ConstPixelBufferAccess	inputStencilAccess	= getEffectiveDepthStencilAccess(inputAccess, tcu::Sampler::MODE_STENCIL);
1656		const PixelBufferAccess			tmpDepthAccess		= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_DEPTH);
1657		const PixelBufferAccess			tmpStencilAccess	= getEffectiveDepthStencilAccess(tmpAccess, tcu::Sampler::MODE_STENCIL);
1658
1659		m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
1660
1661		verifyInfoQueries();
1662
1663		verifyRead(inputDepthAccess);
1664		verifyRead(inputStencilAccess);
1665
1666		verifyGetPixDepth(inputDepthAccess, inputAccess);
1667		verifyGetPixStencil(inputStencilAccess, inputAccess);
1668
1669		m_testCtx.getLog() << TestLog::Message << "Copying both depth and stencil with getPixel() -> setPixel()" << TestLog::EndMessage;
1670		copyPixels(inputDepthAccess, tmpDepthAccess);
1671		copyPixels(inputStencilAccess, tmpStencilAccess);
1672		verifyRead(tmpDepthAccess);
1673		verifyRead(tmpStencilAccess);
1674
1675		m_testCtx.getLog() << TestLog::Message << "Copying both depth and stencil with getPix{Depth,Stencil}() -> setPix{Depth,Stencil}()" << TestLog::EndMessage;
1676		copyGetSetDepth(inputDepthAccess, tmpDepthAccess);
1677		copyGetSetStencil(inputStencilAccess, tmpStencilAccess);
1678		verifyRead(tmpDepthAccess);
1679		verifyRead(tmpStencilAccess);
1680
1681		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing depth component with clearDepth() doesn't affect stencil" << TestLog::EndMessage;
1682		tcu::copy(tmpAccess, inputAccess);
1683		tcu::clearDepth(tmpAccess, 0.0f);
1684		verifyRead(tmpStencilAccess);
1685
1686		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing stencil component with clearStencil() doesn't affect depth" << TestLog::EndMessage;
1687		tcu::copy(tmpAccess, inputAccess);
1688		tcu::clearStencil(tmpAccess, 0);
1689		verifyRead(tmpDepthAccess);
1690
1691		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing depth component with setPixDepth() doesn't affect stencil" << TestLog::EndMessage;
1692		tcu::copy(tmpAccess, inputAccess);
1693
1694		for (int ndx = 0; ndx < tmpAccess.getWidth(); ndx++)
1695			tmpAccess.setPixDepth(0.0f, ndx, 0, 0);
1696
1697		verifyRead(tmpStencilAccess);
1698
1699		m_testCtx.getLog() << TestLog::Message << "Verifying that clearing stencil component with setPixStencil() doesn't affect depth" << TestLog::EndMessage;
1700		tcu::copy(tmpAccess, inputAccess);
1701
1702		for (int ndx = 0; ndx < tmpAccess.getWidth(); ndx++)
1703			tmpAccess.setPixStencil(0, ndx, 0, 0);
1704
1705		verifyRead(tmpDepthAccess);
1706
1707		return STOP;
1708	}
1709};
1710
1711} // anonymous
1712
1713tcu::TestCaseGroup* createTextureFormatTests (tcu::TestContext& testCtx)
1714{
1715	de::MovePtr<tcu::TestCaseGroup>	group	(new tcu::TestCaseGroup(testCtx, "texture_format", "Texture format tests"));
1716
1717	for (int channelType = 0; channelType < TextureFormat::CHANNELTYPE_LAST; channelType++)
1718	{
1719		// \todo [2020-04-08] Missing tests for SIGNED_INT64 and UNSIGNED_INT64
1720		if (TextureFormat::SIGNED_INT64 == channelType || channelType == TextureFormat::UNSIGNED_INT64)
1721			continue;
1722
1723		for (int channelOrder = 0; channelOrder < TextureFormat::CHANNELORDER_LAST; channelOrder++)
1724		{
1725			const TextureFormat		format		((TextureFormat::ChannelOrder)channelOrder, (TextureFormat::ChannelType)channelType);
1726
1727			if (!isValid(format))
1728				continue;
1729
1730			if (tcu::isSRGB(format))
1731				continue; // \todo [2015-10-12 pyry] Tests for sRGB formats (need thresholds)
1732
1733			if (format.order == TextureFormat::DS)
1734				group->addChild(new DepthStencilFormatCase(testCtx, format));
1735			else if (format.order == TextureFormat::D)
1736				group->addChild(new DepthFormatCase(testCtx, format));
1737			else if (format.order == TextureFormat::S)
1738				group->addChild(new StencilFormatCase(testCtx, format));
1739			else
1740				group->addChild(new ColorFormatCase(testCtx, format));
1741		}
1742	}
1743
1744	return group.release();
1745}
1746
1747} // dit
1748