es31fCopyImageTests.cpp revision 9cb5b076f78c1f85fd9c4d10eca3f0532f0d24e6
1/*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 3.1 Module
3 * -------------------------------------------------
4 *
5 * Copyright 2014 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 Copy image tests for GL_EXT_copy_image.
22 *//*--------------------------------------------------------------------*/
23
24#include "es31fCopyImageTests.hpp"
25
26#include "tes31TestCase.hpp"
27
28#include "glsTextureTestUtil.hpp"
29
30#include "gluContextInfo.hpp"
31#include "gluObjectWrapper.hpp"
32#include "gluRenderContext.hpp"
33#include "gluStrUtil.hpp"
34#include "gluTextureUtil.hpp"
35#include "gluPixelTransfer.hpp"
36
37#include "glwEnums.hpp"
38#include "glwFunctions.hpp"
39
40#include "tcuCompressedTexture.hpp"
41#include "tcuFloat.hpp"
42#include "tcuImageCompare.hpp"
43#include "tcuTestLog.hpp"
44#include "tcuTexture.hpp"
45#include "tcuTextureUtil.hpp"
46#include "tcuVector.hpp"
47#include "tcuVectorUtil.hpp"
48#include "tcuSeedBuilder.hpp"
49#include "tcuResultCollector.hpp"
50
51#include "deArrayBuffer.hpp"
52#include "deFloat16.h"
53#include "deRandom.hpp"
54#include "deStringUtil.hpp"
55#include "deUniquePtr.hpp"
56#include "deArrayUtil.hpp"
57
58#include <map>
59#include <string>
60#include <vector>
61
62using namespace deqp::gls::TextureTestUtil;
63
64using tcu::Float;
65using tcu::IVec3;
66using tcu::Sampler;
67using tcu::ScopedLogSection;
68using tcu::TestLog;
69using tcu::Vec4;
70using tcu::SeedBuilder;
71
72using de::ArrayBuffer;
73
74using std::map;
75using std::string;
76using std::vector;
77using std::pair;
78
79namespace deqp
80{
81namespace gles31
82{
83namespace Functional
84{
85namespace
86{
87
88enum ViewClass
89{
90	VIEWCLASS_128_BITS = 0,
91	VIEWCLASS_96_BITS,
92	VIEWCLASS_64_BITS,
93	VIEWCLASS_48_BITS,
94	VIEWCLASS_32_BITS,
95	VIEWCLASS_24_BITS,
96	VIEWCLASS_16_BITS,
97	VIEWCLASS_8_BITS,
98
99	VIEWCLASS_EAC_R11,
100	VIEWCLASS_EAC_RG11,
101	VIEWCLASS_ETC2_RGB,
102	VIEWCLASS_ETC2_RGBA,
103	VIEWCLASS_ETC2_EAC_RGBA,
104	VIEWCLASS_ASTC_4x4_RGBA,
105	VIEWCLASS_ASTC_5x4_RGBA,
106	VIEWCLASS_ASTC_5x5_RGBA,
107	VIEWCLASS_ASTC_6x5_RGBA,
108	VIEWCLASS_ASTC_6x6_RGBA,
109	VIEWCLASS_ASTC_8x5_RGBA,
110	VIEWCLASS_ASTC_8x6_RGBA,
111	VIEWCLASS_ASTC_8x8_RGBA,
112	VIEWCLASS_ASTC_10x5_RGBA,
113	VIEWCLASS_ASTC_10x6_RGBA,
114	VIEWCLASS_ASTC_10x8_RGBA,
115	VIEWCLASS_ASTC_10x10_RGBA,
116	VIEWCLASS_ASTC_12x10_RGBA,
117	VIEWCLASS_ASTC_12x12_RGBA
118};
119
120const char* viewClassToName (ViewClass viewClass)
121{
122	switch (viewClass)
123	{
124		case VIEWCLASS_128_BITS:			return "viewclass_128_bits";
125		case VIEWCLASS_96_BITS:				return "viewclass_96_bits";
126		case VIEWCLASS_64_BITS:				return "viewclass_64_bits";
127		case VIEWCLASS_48_BITS:				return "viewclass_48_bits";
128		case VIEWCLASS_32_BITS:				return "viewclass_32_bits";
129		case VIEWCLASS_24_BITS:				return "viewclass_24_bits";
130		case VIEWCLASS_16_BITS:				return "viewclass_16_bits";
131		case VIEWCLASS_8_BITS:				return "viewclass_8_bits";
132		case VIEWCLASS_EAC_R11:				return "viewclass_eac_r11";
133		case VIEWCLASS_EAC_RG11:			return "viewclass_eac_rg11";
134		case VIEWCLASS_ETC2_RGB:			return "viewclass_etc2_rgb";
135		case VIEWCLASS_ETC2_RGBA:			return "viewclass_etc2_rgba";
136		case VIEWCLASS_ETC2_EAC_RGBA:		return "viewclass_etc2_eac_rgba";
137		case VIEWCLASS_ASTC_4x4_RGBA:		return "viewclass_astc_4x4_rgba";
138		case VIEWCLASS_ASTC_5x4_RGBA:		return "viewclass_astc_5x4_rgba";
139		case VIEWCLASS_ASTC_5x5_RGBA:		return "viewclass_astc_5x5_rgba";
140		case VIEWCLASS_ASTC_6x5_RGBA:		return "viewclass_astc_6x5_rgba";
141		case VIEWCLASS_ASTC_6x6_RGBA:		return "viewclass_astc_6x6_rgba";
142		case VIEWCLASS_ASTC_8x5_RGBA:		return "viewclass_astc_8x5_rgba";
143		case VIEWCLASS_ASTC_8x6_RGBA:		return "viewclass_astc_8x6_rgba";
144		case VIEWCLASS_ASTC_8x8_RGBA:		return "viewclass_astc_8x8_rgba";
145		case VIEWCLASS_ASTC_10x5_RGBA:		return "viewclass_astc_10x5_rgba";
146		case VIEWCLASS_ASTC_10x6_RGBA:		return "viewclass_astc_10x6_rgba";
147		case VIEWCLASS_ASTC_10x8_RGBA:		return "viewclass_astc_10x8_rgba";
148		case VIEWCLASS_ASTC_10x10_RGBA:		return "viewclass_astc_10x10_rgba";
149		case VIEWCLASS_ASTC_12x10_RGBA:		return "viewclass_astc_12x10_rgba";
150		case VIEWCLASS_ASTC_12x12_RGBA:		return "viewclass_astc_12x12_rgba";
151
152		default:
153			DE_ASSERT(false);
154			return NULL;
155	}
156}
157
158const char* targetToName (deUint32 target)
159{
160	switch (target)
161	{
162		case GL_RENDERBUFFER:		return "renderbuffer";
163		case GL_TEXTURE_2D:			return "texture2d";
164		case GL_TEXTURE_3D:			return "texture3d";
165		case GL_TEXTURE_2D_ARRAY:	return "texture2d_array";
166		case GL_TEXTURE_CUBE_MAP:	return "cubemap";
167
168		default:
169			DE_ASSERT(false);
170			return NULL;
171	}
172}
173
174string formatToName (deUint32 format)
175{
176	string enumName;
177
178	if (glu::isCompressedFormat(format))
179		enumName = glu::getCompressedTexFormatStr(format).toString().substr(14); // Strip GL_COMPRESSED_
180	else
181		enumName = glu::getPixelFormatStr(format).toString().substr(3); // Strip GL_
182
183	return de::toLower(enumName);
184}
185
186bool isFloatFormat (deUint32 format)
187{
188	if (glu::isCompressedFormat(format))
189		return false;
190	else
191		return tcu::getTextureChannelClass(glu::mapGLInternalFormat(format).type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
192}
193
194bool isUintFormat (deUint32 format)
195{
196	if (glu::isCompressedFormat(format))
197		return false;
198	else
199		return tcu::getTextureChannelClass(glu::mapGLInternalFormat(format).type) == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER;
200}
201
202bool isIntFormat (deUint32 format)
203{
204	if (glu::isCompressedFormat(format))
205		return false;
206	else
207		return tcu::getTextureChannelClass(glu::mapGLInternalFormat(format).type) == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER;
208}
209
210bool isTextureTarget (deUint32 target)
211{
212	return target != GL_RENDERBUFFER;
213}
214
215int getTargetTexDims (deUint32 target)
216{
217	DE_ASSERT(isTextureTarget(target));
218
219	switch (target)
220	{
221		case GL_TEXTURE_1D:
222			return 1;
223
224		case GL_TEXTURE_1D_ARRAY:
225		case GL_TEXTURE_2D:
226		case GL_TEXTURE_CUBE_MAP:
227			return 2;
228
229		case GL_TEXTURE_2D_ARRAY:
230		case GL_TEXTURE_3D:
231			return 3;
232
233		default:
234			DE_ASSERT(false);
235			return -1;
236	}
237}
238
239class ImageInfo
240{
241public:
242					ImageInfo		(deUint32 format, deUint32 target, const IVec3& size);
243
244	deUint32		getFormat		(void) const { return m_format; }
245	deUint32		getTarget		(void) const { return m_target; }
246	const IVec3&	getSize			(void) const { return m_size; }
247
248private:
249	deUint32		m_format;
250	deUint32		m_target;
251	IVec3			m_size;
252};
253
254ImageInfo::ImageInfo (deUint32 format, deUint32 target, const IVec3& size)
255	: m_format		(format)
256	, m_target		(target)
257	, m_size		(size)
258{
259	DE_ASSERT(m_target == GL_TEXTURE_2D_ARRAY || m_target == GL_TEXTURE_3D || m_size.z() == 1);
260	DE_ASSERT(isTextureTarget(m_target) || !glu::isCompressedFormat(m_target));
261}
262
263
264SeedBuilder& operator<< (SeedBuilder& builder, const ImageInfo& info)
265{
266	builder << info.getFormat() << info.getTarget() << info.getSize();
267	return builder;
268}
269
270const glu::ObjectTraits& getObjectTraits (const ImageInfo& info)
271{
272	if (isTextureTarget(info.getTarget()))
273		return glu::objectTraits(glu::OBJECTTYPE_TEXTURE);
274	else
275		return glu::objectTraits(glu::OBJECTTYPE_RENDERBUFFER);
276}
277
278int getLevelCount (const ImageInfo& info)
279{
280	const deUint32	target	= info.getTarget();
281	const IVec3		size	= info.getSize();
282
283	if (target == GL_RENDERBUFFER)
284		return 1;
285	else if (target == GL_TEXTURE_2D_ARRAY)
286	{
287		const int maxSize = de::max(size.x(), size.y());
288
289		return deLog2Ceil32(maxSize);
290	}
291	else
292	{
293		const int maxSize = de::max(size.x(), de::max(size.y(), size.z()));
294
295		return deLog2Ceil32(maxSize);
296	}
297}
298
299// Return format that has more restrictions on texel data.
300deUint32 getMoreRestrictiveFormat (deUint32 formatA, deUint32 formatB)
301{
302	if (formatA == formatB)
303		return formatA;
304	else if (glu::isCompressedFormat(formatA) && isAstcFormat(glu::mapGLCompressedTexFormat(formatA)))
305		return formatA;
306	else if (glu::isCompressedFormat(formatB) && isAstcFormat(glu::mapGLCompressedTexFormat(formatB)))
307		return formatB;
308	else if (isFloatFormat(formatA))
309	{
310		DE_ASSERT(!isFloatFormat(formatB));
311
312		return formatA;
313	}
314	else if (isFloatFormat(formatB))
315	{
316		DE_ASSERT(!isFloatFormat(formatA));
317
318		return formatB;
319	}
320	else if (glu::isCompressedFormat(formatA))
321	{
322		return formatA;
323	}
324	else if (glu::isCompressedFormat(formatB))
325	{
326		return formatB;
327	}
328	else
329		return formatA;
330}
331
332int getTexelBlockSize (deUint32 format)
333{
334	if (glu::isCompressedFormat(format))
335		return tcu::getBlockSize(glu::mapGLCompressedTexFormat(format));
336	else
337		return glu::mapGLInternalFormat(format).getPixelSize();
338}
339
340IVec3 getTexelBlockPixelSize (deUint32 format)
341{
342	if (glu::isCompressedFormat(format))
343		return tcu::getBlockPixelSize(glu::mapGLCompressedTexFormat(format));
344	else
345		return IVec3(1, 1, 1);
346}
347
348IVec3 getLevelSize (deUint32 target, const IVec3& baseSize, int level)
349{
350	IVec3 size;
351
352	if (target != GL_TEXTURE_2D_ARRAY)
353	{
354		for (int i = 0; i < 3; i++)
355			size[i] = de::max(baseSize[i] >> level, 1);
356	}
357	else
358	{
359		for (int i = 0; i < 2; i++)
360			size[i] = de::max(baseSize[i] >> level, 1);
361
362		size[2] = baseSize[2];
363	}
364
365	return size;
366}
367
368bool isColorRenderable (deUint32 format)
369{
370	switch (format)
371	{
372		case GL_R8:
373		case GL_RG8:
374		case GL_RGB8:
375		case GL_RGB565:
376		case GL_RGB4:
377		case GL_RGB5_A1:
378		case GL_RGBA8:
379		case GL_RGB10_A2:
380		case GL_RGB10_A2UI:
381		case GL_SRGB8_ALPHA8:
382		case GL_R8I:
383		case GL_R8UI:
384		case GL_R16I:
385		case GL_R16UI:
386		case GL_R32I:
387		case GL_R32UI:
388		case GL_RG8I:
389		case GL_RG8UI:
390		case GL_RG16I:
391		case GL_RG16UI:
392		case GL_RG32I:
393		case GL_RG32UI:
394		case GL_RGBA8I:
395		case GL_RGBA8UI:
396		case GL_RGBA16I:
397		case GL_RGBA16UI:
398		case GL_RGBA32I:
399		case GL_RGBA32UI:
400			return true;
401
402		default:
403			return false;
404	}
405}
406
407deUint32 getTypeForInternalFormat (deUint32 format)
408{
409	return glu::getTransferFormat(glu::mapGLInternalFormat(format)).dataType;
410}
411
412void genTexel (de::Random& rng, deUint32 glFormat, int texelBlockSize, const int texelCount, deUint8* buffer)
413{
414	if (isFloatFormat(glFormat))
415	{
416		const tcu::TextureFormat		format	= glu::mapGLInternalFormat(glFormat);
417		const tcu::PixelBufferAccess	access	(format, texelCount, 1, 1, buffer);
418		const tcu::TextureFormatInfo	info	= tcu::getTextureFormatInfo(format);
419
420		for (int texelNdx = 0; texelNdx < texelCount; texelNdx++)
421		{
422			const float	red		= rng.getFloat(info.valueMin.x(), info.valueMax.x());
423			const float green	= rng.getFloat(info.valueMin.y(), info.valueMax.y());
424			const float blue	= rng.getFloat(info.valueMin.z(), info.valueMax.z());
425			const float alpha	= rng.getFloat(info.valueMin.w(), info.valueMax.w());
426
427			const Vec4	color	(red, green, blue, alpha);
428
429			access.setPixel(color, texelNdx, 0, 0);
430		}
431	}
432	else if (glu::isCompressedFormat(glFormat))
433	{
434		const tcu::CompressedTexFormat compressedFormat = glu::mapGLCompressedTexFormat(glFormat);
435
436		if (tcu::isAstcFormat(compressedFormat))
437		{
438			const int		BLOCK_SIZE				= 16;
439			const deUint8	blocks[][BLOCK_SIZE]	=
440			{
441				// \note All of the following blocks are valid in LDR mode.
442				{ 252,	253,	255,	255,	255,	255,	255,	255,	8,		71,		90,		78,		22,		17,		26,		66,		},
443				{ 252,	253,	255,	255,	255,	255,	255,	255,	220,	74,		139,	235,	249,	6,		145,	125		},
444				{ 252,	253,	255,	255,	255,	255,	255,	255,	223,	251,	28,		206,	54,		251,	160,	174		},
445				{ 252,	253,	255,	255,	255,	255,	255,	255,	39,		4,		153,	219,	180,	61,		51,		37		},
446				{ 67,	2,		0,		254,	1,		0,		64,		215,	83,		211,	159,	105,	41,		140,	50,		2		},
447				{ 67,	130,	0,		170,	84,		255,	65,		215,	83,		211,	159,	105,	41,		140,	50,		2		},
448				{ 67,	2,		129,	38,		51,		229,	95,		215,	83,		211,	159,	105,	41,		140,	50,		2		},
449				{ 67,	130,	193,	56,		213,	144,	95,		215,	83,		211,	159,	105,	41,		140,	50,		2		}
450			};
451
452			DE_ASSERT(texelBlockSize == BLOCK_SIZE);
453
454			for (int i = 0; i < texelCount; i++)
455			{
456				const int blockNdx = rng.getInt(0, DE_LENGTH_OF_ARRAY(blocks)-1);
457
458				deMemcpy(buffer + i * BLOCK_SIZE,  blocks[blockNdx], BLOCK_SIZE);
459			}
460		}
461		else
462		{
463			for (int i = 0; i < texelBlockSize * texelCount; i++)
464			{
465				const deUint8 val = rng.getUint8();
466
467				buffer[i] = val;
468			}
469		}
470	}
471	else
472	{
473		for (int i = 0; i < texelBlockSize * texelCount; i++)
474		{
475			const deUint8 val = rng.getUint8();
476
477			buffer[i] = val;
478		}
479	}
480}
481
482IVec3 divRoundUp (const IVec3& a, const IVec3& b)
483{
484	IVec3 res;
485
486	for (int i =0; i < 3; i++)
487		res[i] = a[i] / b[i] + ((a[i] % b[i]) ? 1 : 0);
488
489	return res;
490}
491
492deUint32 mapFaceNdxToFace (int ndx)
493{
494	const deUint32 cubeFaces[] =
495	{
496		GL_TEXTURE_CUBE_MAP_POSITIVE_X,
497		GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
498
499		GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
500		GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
501
502		GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
503		GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
504	};
505
506	return de::getSizedArrayElement<6>(cubeFaces, ndx);
507}
508
509deUint32 getFormatForInternalFormat (deUint32 format)
510{
511	return glu::getTransferFormat(glu::mapGLInternalFormat(format)).format;
512}
513
514void genericTexImage (const glw::Functions&	gl,
515					  deUint32				target,
516					  int					faceNdx,
517					  int					level,
518					  const IVec3&			size,
519					  deUint32				format,
520					  size_t				dataSize,
521					  const void*			data)
522{
523	const deUint32 glTarget = (target == GL_TEXTURE_CUBE_MAP ? mapFaceNdxToFace(faceNdx) : target);
524
525	DE_ASSERT(target == GL_TEXTURE_CUBE_MAP || faceNdx == 0);
526
527	if (glu::isCompressedFormat(format))
528	{
529		switch (getTargetTexDims(target))
530		{
531			case 2:
532				DE_ASSERT(size.z() == 1);
533				gl.compressedTexImage2D(glTarget, level, format, (glw::GLsizei)size.x(), (glw::GLsizei)size.y(), 0, (glw::GLsizei)dataSize, data);
534				GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage2D failed.");
535				break;
536
537			case 3:
538				gl.compressedTexImage3D(glTarget, level, format, (glw::GLsizei)size.x(), (glw::GLsizei)size.y(), (glw::GLsizei)size.z(), 0, (glw::GLsizei)dataSize, data);
539				GLU_EXPECT_NO_ERROR(gl.getError(), "glCompressedTexImage3D failed.");
540				break;
541
542			default:
543				DE_ASSERT(false);
544		}
545	}
546	else
547	{
548		const deUint32	glFormat	= getFormatForInternalFormat(format);
549		const deUint32	glType		= getTypeForInternalFormat(format);
550
551		switch (getTargetTexDims(target))
552		{
553			case 2:
554				DE_ASSERT(size.z() == 1);
555				gl.texImage2D(glTarget, level, format, (glw::GLsizei)size.x(), (glw::GLsizei)size.y(), 0, glFormat, glType, data);
556				GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage2D failed.");
557				break;
558
559			case 3:
560				gl.texImage3D(glTarget, level, format, (glw::GLsizei)size.x(), (glw::GLsizei)size.y(), (glw::GLsizei)size.z(), 0, glFormat, glType, data);
561				GLU_EXPECT_NO_ERROR(gl.getError(), "glTexImage3D failed.");
562				break;
563
564			default:
565				DE_ASSERT(false);
566		}
567	}
568}
569
570void genTextureImage (const glw::Functions&				gl,
571					  de::Random&						rng,
572					  deUint32							name,
573					  vector<ArrayBuffer<deUint8> >&	levels,
574					  const ImageInfo&					info,
575					  deUint32							moreRestrictiveFormat)
576{
577	const int		texelBlockSize			= getTexelBlockSize(info.getFormat());
578	const IVec3		texelBlockPixelSize 	= getTexelBlockPixelSize(info.getFormat());
579
580	levels.resize(getLevelCount(info));
581
582	gl.pixelStorei(GL_UNPACK_ALIGNMENT, 1);
583	GLU_EXPECT_NO_ERROR(gl.getError(), "Setting pixel store aligment failed.");
584
585	gl.bindTexture(info.getTarget(), name);
586	GLU_EXPECT_NO_ERROR(gl.getError(), "Binding texture failed.");
587
588	for (int levelNdx = 0; levelNdx < getLevelCount(info); levelNdx++)
589	{
590		ArrayBuffer<deUint8>&	level					= levels[levelNdx];
591
592		const int				faceCount				= (info.getTarget() == GL_TEXTURE_CUBE_MAP ? 6 : 1);
593
594		const IVec3				levelPixelSize			= getLevelSize(info.getTarget(), info.getSize(), levelNdx);
595		const IVec3				levelTexelBlockSize		= divRoundUp(levelPixelSize, texelBlockPixelSize);
596		const int				levelTexelBlockCount	= levelTexelBlockSize.x() * levelTexelBlockSize.y() * levelTexelBlockSize.z();
597		const int				levelSize 				= levelTexelBlockCount * texelBlockSize;
598
599		level.setStorage(levelSize * faceCount);
600
601		for (int faceNdx = 0; faceNdx < faceCount; faceNdx++)
602		{
603			genTexel(rng, moreRestrictiveFormat, texelBlockSize, levelTexelBlockCount, level.getElementPtr(faceNdx * levelSize));
604
605			genericTexImage(gl, info.getTarget(), faceNdx, levelNdx, levelPixelSize, info.getFormat(), levelSize, level.getElementPtr(faceNdx * levelSize));
606		}
607	}
608
609	gl.texParameteri(info.getTarget(), GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
610	gl.texParameteri(info.getTarget(), GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
611
612	if (info.getTarget() == GL_TEXTURE_3D)
613		gl.texParameteri(info.getTarget(), GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
614
615	gl.texParameteri(info.getTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
616	gl.texParameteri(info.getTarget(), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
617	GLU_EXPECT_NO_ERROR(gl.getError(), "Setting texture parameters failed");
618
619	gl.bindTexture(info.getTarget(), 0);
620	GLU_EXPECT_NO_ERROR(gl.getError(), "Unbinding texture failed.");
621}
622
623void genRenderbufferImage (const glw::Functions&			gl,
624						   de::Random&						rng,
625						   deUint32							name,
626						   vector<ArrayBuffer<deUint8> >&	levels,
627						   const ImageInfo&					info,
628						   deUint32							moreRestrictiveFormat)
629{
630	const IVec3					size	= info.getSize();
631	const tcu::TextureFormat	format	= glu::mapGLInternalFormat(info.getFormat());
632
633	DE_ASSERT(info.getTarget() == GL_RENDERBUFFER);
634	DE_ASSERT(info.getSize().z() == 1);
635	DE_ASSERT(getLevelCount(info) == 1);
636	DE_ASSERT(!glu::isCompressedFormat(info.getFormat()));
637
638	glu::Framebuffer framebuffer(gl);
639
640	levels.resize(1);
641	levels[0].setStorage(format.getPixelSize() * size.x() * size.y());
642	tcu::PixelBufferAccess refAccess(format, size.x(), size.y(), 1, levels[0].getPtr());
643
644	gl.bindRenderbuffer(GL_RENDERBUFFER, name);
645	gl.renderbufferStorage(GL_RENDERBUFFER, info.getFormat(), info.getSize().x(), info.getSize().y());
646	GLU_EXPECT_NO_ERROR(gl.getError(), "Binding and setting storage for renderbuffer failed.");
647
648	gl.bindFramebuffer(GL_FRAMEBUFFER, *framebuffer);
649	gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, name);
650	GLU_EXPECT_NO_ERROR(gl.getError(), "Binding framebuffer and attaching renderbuffer failed.");
651
652	{
653		vector<deUint8> texelBlock(format.getPixelSize());
654
655		genTexel(rng, moreRestrictiveFormat, format.getPixelSize(), 1, &(texelBlock[0]));
656
657		{
658			const tcu::ConstPixelBufferAccess texelAccess (format, 1, 1, 1, &(texelBlock[0]));
659
660			if (isFloatFormat(info.getFormat()))
661			{
662				const tcu::Vec4 color = texelAccess.getPixel(0, 0, 0);
663
664				gl.clearBufferfv(GL_COLOR, 0, (const float*)&color);
665				GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer.");
666
667				tcu::clear(refAccess, (tcu::isSRGB(format) ? tcu::linearToSRGB(color) : color));
668			}
669			else if (isIntFormat(info.getFormat()))
670			{
671				const tcu::IVec4 color = texelAccess.getPixelInt(0, 0, 0);
672
673				gl.clearBufferiv(GL_COLOR, 0, (const deInt32*)&color);
674				GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer.");
675
676				DE_ASSERT(!tcu::isSRGB(format));
677				tcu::clear(refAccess, color);
678			}
679			else if (isUintFormat(info.getFormat()))
680			{
681				const tcu::IVec4 color = texelAccess.getPixelInt(0, 0, 0);
682
683				gl.clearBufferuiv(GL_COLOR, 0, (const deUint32*)&color);
684				GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer.");
685
686				DE_ASSERT(!tcu::isSRGB(format));
687				tcu::clear(refAccess, color);
688			}
689			else
690			{
691				const tcu::Vec4 color = texelAccess.getPixel(0, 0, 0);
692
693				gl.clearColor(color.x(), color.y(), color.z(), color.w());
694				gl.clear(GL_COLOR_BUFFER_BIT);
695				GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer.");
696
697				tcu::clear(refAccess, (tcu::isSRGB(format) ? tcu::linearToSRGB(color) : color));
698			}
699		}
700	}
701
702	gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
703	gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
704	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind renderbufer and framebuffer.");
705}
706
707
708
709void genImage (const glw::Functions&			gl,
710			   de::Random&						rng,
711			   deUint32							name,
712			   vector<ArrayBuffer<deUint8> >&	levels,
713			   const ImageInfo&					info,
714			   deUint32							moreRestrictiveFormat)
715{
716	if (isTextureTarget(info.getTarget()))
717		genTextureImage(gl, rng, name, levels, info, moreRestrictiveFormat);
718	else
719		genRenderbufferImage(gl, rng, name, levels, info, moreRestrictiveFormat);
720}
721
722IVec3 getTexelBlockStride (const ImageInfo& info, int level)
723{
724	const IVec3	size					= getLevelSize(info.getTarget(), info.getSize(), level);
725	const int	texelBlockSize			= getTexelBlockSize(info.getFormat());
726	const IVec3 texelBlockPixelSize		= getTexelBlockPixelSize(info.getFormat());
727	const IVec3 textureTexelBlockSize	= divRoundUp(size, texelBlockPixelSize);
728
729	return IVec3(texelBlockSize, textureTexelBlockSize.x() * texelBlockSize, textureTexelBlockSize.x() * textureTexelBlockSize.y() * texelBlockSize);
730}
731
732int sumComponents (const IVec3& v)
733{
734	int s = 0;
735
736	for (int i = 0; i < 3; i++)
737		s += v[i];
738
739	return s;
740}
741
742void copyImageData (vector<ArrayBuffer<deUint8> >&			dstImageData,
743					const ImageInfo&						dstImageInfo,
744					int										dstLevel,
745					const IVec3&							dstPos,
746
747					const vector<ArrayBuffer<deUint8> >&	srcImageData,
748					const ImageInfo&						srcImageInfo,
749					int										srcLevel,
750					const IVec3&							srcPos,
751
752					const IVec3&							copySize)
753{
754	const ArrayBuffer<deUint8>&	srcLevelData			= srcImageData[srcLevel];
755	ArrayBuffer<deUint8>&		dstLevelData			= dstImageData[dstLevel];
756
757	const IVec3					srcTexelBlockPixelSize	= getTexelBlockPixelSize(srcImageInfo.getFormat());
758	const int					srcTexelBlockSize		= getTexelBlockSize(srcImageInfo.getFormat());
759	const IVec3					srcTexelPos				= srcPos / srcTexelBlockPixelSize;
760	const IVec3					srcTexelBlockStride		= getTexelBlockStride(srcImageInfo, srcLevel);
761
762	const IVec3					dstTexelBlockPixelSize	= getTexelBlockPixelSize(dstImageInfo.getFormat());
763	const int					dstTexelBlockSize		= getTexelBlockSize(dstImageInfo.getFormat());
764	const IVec3					dstTexelPos				= dstPos / dstTexelBlockPixelSize;
765	const IVec3					dstTexelBlockStride		= getTexelBlockStride(dstImageInfo, dstLevel);
766
767	const IVec3					copyTexelBlockCount		= copySize / srcTexelBlockPixelSize;
768	const int					texelBlockSize			= srcTexelBlockSize;
769
770	DE_ASSERT(srcTexelBlockSize == dstTexelBlockSize);
771	DE_UNREF(dstTexelBlockSize);
772
773	DE_ASSERT((copySize.x() % srcTexelBlockPixelSize.x()) == 0);
774	DE_ASSERT((copySize.y() % srcTexelBlockPixelSize.y()) == 0);
775	DE_ASSERT((copySize.z() % srcTexelBlockPixelSize.z()) == 0);
776
777	DE_ASSERT((srcPos.x() % srcTexelBlockPixelSize.x()) == 0);
778	DE_ASSERT((srcPos.y() % srcTexelBlockPixelSize.y()) == 0);
779	DE_ASSERT((srcPos.z() % srcTexelBlockPixelSize.z()) == 0);
780
781	for (int z = 0; z < copyTexelBlockCount.z(); z++)
782	for (int y = 0; y < copyTexelBlockCount.y(); y++)
783	{
784		const IVec3				blockPos		(0, y, z);
785		const deUint8* const	srcPtr			= srcLevelData.getElementPtr(sumComponents((srcTexelPos + blockPos) * srcTexelBlockStride));
786		deUint8* const			dstPtr			= dstLevelData.getElementPtr(sumComponents((dstTexelPos + blockPos) * dstTexelBlockStride));
787		const int				copyLineSize	= copyTexelBlockCount.x() * texelBlockSize;
788
789		deMemcpy(dstPtr, srcPtr, copyLineSize);
790	}
791}
792
793vector<tcu::ConstPixelBufferAccess> getLevelAccesses (const vector<ArrayBuffer<deUint8> >& data, const ImageInfo& info)
794{
795	const tcu::TextureFormat			format	= glu::mapGLInternalFormat(info.getFormat());
796	const IVec3							size	= info.getSize();
797
798	vector<tcu::ConstPixelBufferAccess>	result;
799
800	DE_ASSERT((int)data.size() == getLevelCount(info));
801
802	for (int level = 0; level < (int)data.size(); level++)
803	{
804		const IVec3 levelSize = getLevelSize(info.getTarget(), size, level);
805
806		result.push_back(tcu::ConstPixelBufferAccess(format, levelSize.x(), levelSize.y(), levelSize.z(), data[level].getPtr()));
807	}
808
809	return result;
810}
811
812vector<tcu::ConstPixelBufferAccess> getCubeLevelAccesses (const vector<ArrayBuffer<deUint8> >&	data,
813														  const ImageInfo&						info,
814														  int									faceNdx)
815{
816	const tcu::TextureFormat			format				= glu::mapGLInternalFormat(info.getFormat());
817	const IVec3							size				= info.getSize();
818	const int							texelBlockSize		= getTexelBlockSize(info.getFormat());
819	const IVec3							texelBlockPixelSize = getTexelBlockPixelSize(info.getFormat());
820	vector<tcu::ConstPixelBufferAccess>	result;
821
822	DE_ASSERT(info.getTarget() == GL_TEXTURE_CUBE_MAP);
823	DE_ASSERT((int)data.size() == getLevelCount(info));
824
825	for (int level = 0; level < (int)data.size(); level++)
826	{
827		const IVec3 levelPixelSize			= getLevelSize(info.getTarget(), size, level);
828		const IVec3	levelTexelBlockSize		= divRoundUp(levelPixelSize, texelBlockPixelSize);
829		const int	levelTexelBlockCount	= levelTexelBlockSize.x() * levelTexelBlockSize.y() * levelTexelBlockSize.z();
830		const int	levelSize				= levelTexelBlockCount * texelBlockSize;
831
832		result.push_back(tcu::ConstPixelBufferAccess(format, levelPixelSize.x(), levelPixelSize.y(), levelPixelSize.z(), data[level].getElementPtr(levelSize * faceNdx)));
833	}
834
835	return result;
836}
837
838void copyImage (const glw::Functions&					gl,
839
840				deUint32								dstName,
841				vector<ArrayBuffer<deUint8> >&			dstImageData,
842				const ImageInfo&						dstImageInfo,
843				int										dstLevel,
844				const IVec3&							dstPos,
845
846				deUint32								srcName,
847				const vector<ArrayBuffer<deUint8> >&	srcImageData,
848				const ImageInfo&						srcImageInfo,
849				int										srcLevel,
850				const IVec3&							srcPos,
851
852				const IVec3&							copySize)
853{
854	gl.copyImageSubData(srcName, srcImageInfo.getTarget(), srcLevel, srcPos.x(), srcPos.y(), srcPos.z(),
855						dstName, dstImageInfo.getTarget(), dstLevel, dstPos.x(), dstPos.y(), dstPos.z(),
856						copySize.x(), copySize.y(), copySize.z());
857
858	GLU_EXPECT_NO_ERROR(gl.getError(), "glCopyImageSubData failed.");
859
860	copyImageData(dstImageData, dstImageInfo, dstLevel, dstPos,
861				  srcImageData, srcImageInfo, srcLevel, srcPos, copySize);
862}
863
864void verifyTexture2DView (tcu::TestContext&			testContext,
865						  glu::RenderContext&		renderContext,
866						  TextureRenderer&			renderer,
867						  tcu::ResultCollector&		results,
868						  de::Random&				rng,
869						  deUint32					name,
870						  const ImageInfo&			info,
871						  const tcu::Texture2DView&	refTexture)
872{
873	tcu::TestLog&					log				= testContext.getLog();
874	const glw::Functions&			gl				= renderContext.getFunctions();
875	const tcu::RGBA					threshold		= renderContext.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
876	const tcu::TextureFormat		format			= refTexture.getLevel(0).getFormat();
877	const tcu::TextureFormatInfo	spec			= tcu::getTextureFormatInfo(format);
878
879	ReferenceParams					renderParams	(TEXTURETYPE_2D);
880
881	renderParams.samplerType	= getSamplerType(format);
882	renderParams.sampler		= Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST_MIPMAP_NEAREST, Sampler::NEAREST);
883	renderParams.colorScale		= spec.lookupScale;
884	renderParams.colorBias		= spec.lookupBias;
885
886	gl.activeTexture(GL_TEXTURE0);
887	gl.bindTexture(GL_TEXTURE_2D, name);
888	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind texture.");
889
890	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
891	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
892	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
893	gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
894	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup texture filtering state.");
895
896	for (int level = 0; level < getLevelCount(info); level++)
897	{
898		const IVec3				levelSize		= getLevelSize(info.getTarget(), info.getSize(), level);
899		const RandomViewport	viewport		(renderContext.getRenderTarget(), levelSize.x(), levelSize.y(), rng.getUint32());
900
901		vector<float>			texCoord;
902		tcu::Surface			renderedFrame	(viewport.width, viewport.height);
903		tcu::Surface			referenceFrame	(viewport.width, viewport.height);
904
905		computeQuadTexCoord2D(texCoord, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
906
907		// Setup base viewport.
908		gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
909
910		// Draw.
911		renderer.renderQuad(0, &texCoord[0], renderParams);
912		glu::readPixels(renderContext, viewport.x, viewport.y, renderedFrame.getAccess());
913		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render and read pixels.");
914
915		// Compute reference.
916		sampleTexture(SurfaceAccess(referenceFrame, renderContext.getRenderTarget().getPixelFormat()), refTexture, &texCoord[0], renderParams);
917
918		// Compare and log.
919		if (!pixelThresholdCompare(log, ("Level" + de::toString(level)).c_str(), ("Render level " + de::toString(level)).c_str(), referenceFrame, renderedFrame, threshold, tcu::COMPARE_LOG_ON_ERROR))
920			results.fail("Image comparison of level " + de::toString(level) + " failed.");
921		else
922			log << TestLog::Message << "Image comparison of level " << level << " passed." << TestLog::EndMessage;
923	}
924
925	gl.bindTexture(GL_TEXTURE_2D, 0);
926	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind texture.");
927}
928
929void decompressTextureLevel (const tcu::TexDecompressionParams&		params,
930							 ArrayBuffer<deUint8>&					levelData,
931							 tcu::PixelBufferAccess& 				levelAccess,
932							 const tcu::CompressedTexFormat&		compressedFormat,
933							 const tcu::TextureFormat&				decompressedFormat,
934							 const IVec3&							levelPixelSize,
935							 const void*							data)
936{
937	levelData.setStorage(levelPixelSize.x() * levelPixelSize.y() * levelPixelSize.z() * decompressedFormat.getPixelSize());
938	levelAccess = tcu::PixelBufferAccess(decompressedFormat, levelPixelSize.x(), levelPixelSize.y(), levelPixelSize.z(), levelData.getPtr());
939
940	tcu::decompress(levelAccess, compressedFormat, (const deUint8*)data, params);
941}
942
943void decompressTexture (vector<ArrayBuffer<deUint8> >&			levelDatas,
944						vector<tcu::PixelBufferAccess>& 		levelAccesses,
945						glu::RenderContext&						renderContext,
946						const ImageInfo&						info,
947						const vector<ArrayBuffer<deUint8> >&	data)
948{
949	const tcu::CompressedTexFormat	compressedFormat	= glu::mapGLCompressedTexFormat(info.getFormat());
950	const tcu::TextureFormat		decompressedFormat	= tcu::getUncompressedFormat(compressedFormat);
951	const IVec3						size				= info.getSize();
952	de::UniquePtr<glu::ContextInfo>	ctxInfo				(glu::ContextInfo::create(renderContext));
953	tcu::TexDecompressionParams		decompressParams;
954
955	if (tcu::isAstcFormat(compressedFormat))
956	{
957		if (ctxInfo->isExtensionSupported("GL_KHR_texture_compression_astc_hdr"))
958			decompressParams = tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_HDR);
959		else if (ctxInfo->isExtensionSupported("GL_KHR_texture_compression_astc_ldr"))
960			decompressParams = tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR);
961		else
962			DE_ASSERT(false);
963	}
964
965	levelDatas.resize(getLevelCount(info));
966	levelAccesses.resize(getLevelCount(info));
967
968	for (int level = 0; level < getLevelCount(info); level++)
969	{
970		const IVec3					levelPixelSize	= getLevelSize(info.getTarget(), size, level);
971		de::ArrayBuffer<deUint8>&	levelData		= levelDatas[level];
972		tcu::PixelBufferAccess&		levelAccess 	= levelAccesses[level];
973
974		decompressTextureLevel(decompressParams, levelData, levelAccess, compressedFormat, decompressedFormat, levelPixelSize, data[level].getPtr());
975	}
976}
977
978void verifyTexture2D (tcu::TestContext&						testContext,
979					  glu::RenderContext&					renderContext,
980					  TextureRenderer&						textureRenderer,
981					  tcu::ResultCollector&					results,
982					  de::Random&							rng,
983					  deUint32								name,
984					  const vector<ArrayBuffer<deUint8> >&	data,
985					  const ImageInfo&						info)
986{
987	if (glu::isCompressedFormat(info.getFormat()))
988	{
989		vector<de::ArrayBuffer<deUint8> >	levelDatas;
990		vector<tcu::PixelBufferAccess>		levelAccesses;
991
992		decompressTexture(levelDatas, levelAccesses, renderContext, info, data);
993
994		{
995			const tcu::Texture2DView refTexture((int)levelAccesses.size(), &(levelAccesses[0]));
996
997			verifyTexture2DView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
998		}
999	}
1000	else
1001	{
1002		const vector<tcu::ConstPixelBufferAccess>	levelAccesses	= getLevelAccesses(data, info);
1003		const tcu::Texture2DView					refTexture		((int)levelAccesses.size(), &(levelAccesses[0]));
1004
1005		verifyTexture2DView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1006	}
1007}
1008
1009void verifyTexture3DView (tcu::TestContext&			testContext,
1010						  glu::RenderContext&		renderContext,
1011						  TextureRenderer&			renderer,
1012						  tcu::ResultCollector&		results,
1013						  de::Random&				rng,
1014						  deUint32					name,
1015						  const ImageInfo&			info,
1016						  const tcu::Texture3DView&	refTexture)
1017{
1018	tcu::TestLog&					log				= testContext.getLog();
1019	const glw::Functions&			gl				= renderContext.getFunctions();
1020	const tcu::RGBA					threshold		= renderContext.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
1021	const tcu::TextureFormat		format			= refTexture.getLevel(0).getFormat();
1022	const tcu::TextureFormatInfo	spec			= tcu::getTextureFormatInfo(format);
1023
1024	ReferenceParams					renderParams	(TEXTURETYPE_3D);
1025
1026	renderParams.samplerType	= getSamplerType(format);
1027	renderParams.sampler		= Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST_MIPMAP_NEAREST, Sampler::NEAREST);
1028	renderParams.colorScale		= spec.lookupScale;
1029	renderParams.colorBias		= spec.lookupBias;
1030
1031	gl.activeTexture(GL_TEXTURE0);
1032	gl.bindTexture(GL_TEXTURE_3D, name);
1033	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind texture.");
1034
1035	gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1036	gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1037	gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
1038	gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1039	gl.texParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1040	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup texture filtering state.");
1041
1042	for (int level = 0; level < getLevelCount(info); level++)
1043	{
1044		const IVec3 levelSize = getLevelSize(info.getTarget(), info.getSize(), level);
1045
1046		for (int slice = 0; slice < levelSize.z(); slice++)
1047		{
1048			const RandomViewport	viewport		(renderContext.getRenderTarget(), levelSize.x(), levelSize.y(), rng.getUint32());
1049			const float				r				= (float(slice) + 0.5f) / levelSize.z();
1050			tcu::Surface			renderedFrame	(viewport.width, viewport.height);
1051			tcu::Surface			referenceFrame	(viewport.width, viewport.height);
1052			vector<float>			texCoord;
1053
1054			computeQuadTexCoord3D(texCoord, tcu::Vec3(0.0f, 0.0f, r), tcu::Vec3(1.0f, 1.0f, r), tcu::IVec3(0, 1, 2));
1055
1056			// Setup base viewport.
1057			gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
1058
1059			// Draw.
1060			renderer.renderQuad(0, &texCoord[0], renderParams);
1061			glu::readPixels(renderContext, viewport.x, viewport.y, renderedFrame.getAccess());
1062			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render and read pixels.");
1063
1064			// Compute reference.
1065			sampleTexture(SurfaceAccess(referenceFrame, renderContext.getRenderTarget().getPixelFormat()), refTexture, &texCoord[0], renderParams);
1066
1067			// Compare and log.
1068			if (!pixelThresholdCompare(log, ("Level" + de::toString(level) + "Slice" + de::toString(slice)).c_str(), ("Render level " + de::toString(level) + ", Slice" + de::toString(slice)).c_str(), referenceFrame, renderedFrame, threshold, tcu::COMPARE_LOG_ON_ERROR))
1069				results.fail("Image comparison of level " + de::toString(level) + " and slice " + de::toString(slice) + " failed.");
1070			else
1071				log << TestLog::Message << "Image comparison of level " << level << " and slice " << slice << " passed." << TestLog::EndMessage;;
1072		}
1073	}
1074
1075	gl.bindTexture(GL_TEXTURE_3D, 0);
1076	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind texture.");
1077}
1078
1079void verifyTexture3D (tcu::TestContext&						testContext,
1080					  glu::RenderContext&					renderContext,
1081					  TextureRenderer&						textureRenderer,
1082					  tcu::ResultCollector&					results,
1083					  de::Random&							rng,
1084					  deUint32								name,
1085					  const vector<ArrayBuffer<deUint8> >&	data,
1086					  const ImageInfo&						info)
1087{
1088	if (glu::isCompressedFormat(info.getFormat()))
1089	{
1090		vector<de::ArrayBuffer<deUint8> >	levelDatas;
1091		vector<tcu::PixelBufferAccess>		levelAccesses;
1092
1093		decompressTexture(levelDatas, levelAccesses, renderContext, info, data);
1094
1095		{
1096			const tcu::Texture3DView refTexture((int)levelAccesses.size(), &(levelAccesses[0]));
1097
1098			verifyTexture3DView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1099		}
1100	}
1101	else
1102	{
1103		const vector<tcu::ConstPixelBufferAccess>	levelAccesses	= getLevelAccesses(data, info);
1104		const tcu::Texture3DView					refTexture		((int)levelAccesses.size(), &(levelAccesses[0]));
1105
1106		verifyTexture3DView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1107	}
1108}
1109
1110void verifyTextureCubemapView (tcu::TestContext&			testContext,
1111							   glu::RenderContext&			renderContext,
1112							   TextureRenderer&				renderer,
1113							   tcu::ResultCollector&		results,
1114							   de::Random&					rng,
1115							   deUint32						name,
1116							   const ImageInfo&				info,
1117							   const tcu::TextureCubeView&	refTexture)
1118{
1119	tcu::TestLog&					log				= testContext.getLog();
1120	const glw::Functions&			gl				= renderContext.getFunctions();
1121	const tcu::RGBA					threshold		= renderContext.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
1122	const tcu::TextureFormat		format			= refTexture.getLevelFace(0, tcu::CUBEFACE_POSITIVE_X).getFormat();
1123	const tcu::TextureFormatInfo	spec			= tcu::getTextureFormatInfo(format);
1124
1125	ReferenceParams					renderParams	(TEXTURETYPE_CUBE);
1126
1127	renderParams.samplerType	= getSamplerType(format);
1128	renderParams.sampler		= Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST_MIPMAP_NEAREST, Sampler::NEAREST);
1129	renderParams.colorScale		= spec.lookupScale;
1130	renderParams.colorBias		= spec.lookupBias;
1131
1132	gl.activeTexture(GL_TEXTURE0);
1133	gl.bindTexture(GL_TEXTURE_CUBE_MAP, name);
1134	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind texture.");
1135
1136	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1137	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1138	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1139	gl.texParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1140	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup texture filtering state.");
1141
1142	for (int level = 0; level < getLevelCount(info); level++)
1143	{
1144		const IVec3 levelSize = getLevelSize(info.getTarget(), info.getSize(), level);
1145
1146		// \note It seems we can't reliably sample two smallest texture levels with cubemaps
1147		if (levelSize.x() < 4 && levelSize.y() < 4)
1148			continue;
1149
1150		for (int face = 0; face < 6; face++)
1151		{
1152			const RandomViewport	viewport		(renderContext.getRenderTarget(), levelSize.x(), levelSize.y(), rng.getUint32());
1153			const string			cubemapFaceName	= glu::getCubeMapFaceStr(mapFaceNdxToFace(face)).toString();
1154			tcu::Surface			renderedFrame	(viewport.width, viewport.height);
1155			tcu::Surface			referenceFrame	(viewport.width, viewport.height);
1156			vector<float>			texCoord;
1157
1158			computeQuadTexCoordCube(texCoord, glu::getCubeFaceFromGL(mapFaceNdxToFace(face)));
1159
1160			// Setup base viewport.
1161			gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
1162
1163			// Draw.
1164			renderer.renderQuad(0, &texCoord[0], renderParams);
1165			glu::readPixels(renderContext, viewport.x, viewport.y, renderedFrame.getAccess());
1166			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render and read pixels.");
1167
1168			// Compute reference.
1169			sampleTexture(SurfaceAccess(referenceFrame, renderContext.getRenderTarget().getPixelFormat()), refTexture, &texCoord[0], renderParams);
1170
1171			// Compare and log.
1172			if (!pixelThresholdCompare(log, ("Level" + de::toString(level) + "Face" + cubemapFaceName).c_str(), ("Render level " + de::toString(level) + ", Face " + cubemapFaceName).c_str(), referenceFrame, renderedFrame, threshold, tcu::COMPARE_LOG_ON_ERROR))
1173				results.fail("Image comparison of level " + de::toString(level) + " and face " + cubemapFaceName + " failed.");
1174			else
1175				log << TestLog::Message << "Image comparison of level " << level << " and face " << cubemapFaceName << " passed." << TestLog::EndMessage;
1176		}
1177	}
1178
1179	gl.bindTexture(GL_TEXTURE_CUBE_MAP, 0);
1180	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind texture.");
1181}
1182
1183void verifyTextureCubemap (tcu::TestContext&					testContext,
1184						   glu::RenderContext&					renderContext,
1185						   TextureRenderer&						textureRenderer,
1186						   tcu::ResultCollector&				results,
1187						   de::Random&							rng,
1188						   deUint32								name,
1189						   const vector<ArrayBuffer<deUint8> >&	data,
1190						   const ImageInfo&						info)
1191{
1192	if (glu::isCompressedFormat(info.getFormat()))
1193	{
1194		const tcu::CompressedTexFormat&	compressedFormat	= glu::mapGLCompressedTexFormat(info.getFormat());
1195		const tcu::TextureFormat&		decompressedFormat	= tcu::getUncompressedFormat(compressedFormat);
1196
1197		const int						texelBlockSize		= getTexelBlockSize(info.getFormat());
1198		const IVec3						texelBlockPixelSize = getTexelBlockPixelSize(info.getFormat());
1199
1200		vector<tcu::PixelBufferAccess>	levelAccesses[6];
1201		vector<ArrayBuffer<deUint8> >	levelDatas[6];
1202		de::UniquePtr<glu::ContextInfo>	ctxInfo				(glu::ContextInfo::create(renderContext));
1203		tcu::TexDecompressionParams		decompressParams;
1204
1205		if (tcu::isAstcFormat(compressedFormat))
1206		{
1207			if (ctxInfo->isExtensionSupported("GL_KHR_texture_compression_astc_hdr"))
1208				decompressParams = tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_HDR);
1209			else if (ctxInfo->isExtensionSupported("GL_KHR_texture_compression_astc_ldr"))
1210				decompressParams = tcu::TexDecompressionParams(tcu::TexDecompressionParams::ASTCMODE_LDR);
1211			else
1212				DE_ASSERT(false);
1213		}
1214
1215		for (int faceNdx = 0; faceNdx < 6; faceNdx++)
1216		{
1217			levelAccesses[faceNdx].resize(getLevelCount(info));
1218			levelDatas[faceNdx].resize(getLevelCount(info));
1219		}
1220
1221		for (int level = 0; level < getLevelCount(info); level++)
1222		{
1223			for (int faceNdx = 0; faceNdx < 6; faceNdx++)
1224			{
1225				const IVec3				levelPixelSize			= getLevelSize(info.getTarget(), info.getSize(), level);
1226				const IVec3				levelTexelBlockSize		= divRoundUp(levelPixelSize, texelBlockPixelSize);
1227				const int				levelTexelBlockCount	= levelTexelBlockSize.x() * levelTexelBlockSize.y() * levelTexelBlockSize.z();
1228				const int				levelSize 				= levelTexelBlockCount * texelBlockSize;
1229
1230				const deUint8*			dataPtr					= data[level].getElementPtr(faceNdx * levelSize);
1231				tcu::PixelBufferAccess& levelAccess				= levelAccesses[faceNdx][level];
1232				ArrayBuffer<deUint8>&	levelData				= levelDatas[faceNdx][level];
1233
1234				decompressTextureLevel(decompressParams, levelData, levelAccess, compressedFormat, decompressedFormat, levelPixelSize, dataPtr);
1235			}
1236		}
1237
1238		const tcu::ConstPixelBufferAccess* levels[6];
1239
1240		for (int faceNdx = 0; faceNdx < 6; faceNdx++)
1241			levels[glu::getCubeFaceFromGL(mapFaceNdxToFace(faceNdx))] = &(levelAccesses[faceNdx][0]);
1242
1243		{
1244			const tcu::TextureCubeView refTexture(getLevelCount(info), levels);
1245
1246			verifyTextureCubemapView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1247		}
1248	}
1249	else
1250	{
1251		const vector<tcu::ConstPixelBufferAccess> levelAccesses[6] =
1252		{
1253			getCubeLevelAccesses(data, info, 0),
1254			getCubeLevelAccesses(data, info, 1),
1255			getCubeLevelAccesses(data, info, 2),
1256			getCubeLevelAccesses(data, info, 3),
1257			getCubeLevelAccesses(data, info, 4),
1258			getCubeLevelAccesses(data, info, 5),
1259		};
1260
1261		const tcu::ConstPixelBufferAccess* levels[6];
1262
1263		for (int faceNdx = 0; faceNdx < 6; faceNdx++)
1264			levels[glu::getCubeFaceFromGL(mapFaceNdxToFace(faceNdx))] = &(levelAccesses[faceNdx][0]);
1265
1266		{
1267			const tcu::TextureCubeView refTexture(getLevelCount(info), levels);
1268
1269			verifyTextureCubemapView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1270		}
1271	}
1272}
1273
1274void verifyTexture2DArrayView (tcu::TestContext&				testContext,
1275							   glu::RenderContext&				renderContext,
1276							   TextureRenderer&					renderer,
1277							   tcu::ResultCollector&			results,
1278							   de::Random&						rng,
1279							   deUint32							name,
1280							   const ImageInfo&					info,
1281							   const tcu::Texture2DArrayView&	refTexture)
1282{
1283	tcu::TestLog&					log				= testContext.getLog();
1284	const glw::Functions&			gl				= renderContext.getFunctions();
1285	const tcu::RGBA					threshold		= renderContext.getRenderTarget().getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1);
1286	const tcu::TextureFormat		format			= refTexture.getLevel(0).getFormat();
1287	const tcu::TextureFormatInfo	spec			= tcu::getTextureFormatInfo(format);
1288
1289	ReferenceParams					renderParams	(TEXTURETYPE_2D_ARRAY);
1290
1291	renderParams.samplerType	= getSamplerType(format);
1292	renderParams.sampler		= Sampler(Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE, Sampler::NEAREST_MIPMAP_NEAREST, Sampler::NEAREST);
1293	renderParams.colorScale		= spec.lookupScale;
1294	renderParams.colorBias		= spec.lookupBias;
1295
1296	gl.activeTexture(GL_TEXTURE0);
1297	gl.bindTexture(GL_TEXTURE_2D_ARRAY, name);
1298	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind texture.");
1299
1300	gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1301	gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1302	gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1303	gl.texParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1304	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to setup texture filtering state.");
1305
1306	for (int level = 0; level < getLevelCount(info); level++)
1307	{
1308		const IVec3 levelSize = getLevelSize(info.getTarget(), info.getSize(), level);
1309
1310		for (int layer = 0; layer < levelSize.z(); layer++)
1311		{
1312			const RandomViewport	viewport		(renderContext.getRenderTarget(), levelSize.x(), levelSize.y(), rng.getUint32());
1313			tcu::Surface			renderedFrame	(viewport.width, viewport.height);
1314			tcu::Surface			referenceFrame	(viewport.width, viewport.height);
1315			vector<float>			texCoord;
1316
1317			computeQuadTexCoord2DArray(texCoord, layer, tcu::Vec2(0.0f, 0.0f), tcu::Vec2(1.0f, 1.0f));
1318
1319			// Setup base viewport.
1320			gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
1321
1322			// Draw.
1323			renderer.renderQuad(0, &texCoord[0], renderParams);
1324			glu::readPixels(renderContext, viewport.x, viewport.y, renderedFrame.getAccess());
1325			GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to render and read pixels.");
1326
1327			// Compute reference.
1328			sampleTexture(SurfaceAccess(referenceFrame, renderContext.getRenderTarget().getPixelFormat()), refTexture, &texCoord[0], renderParams);
1329
1330			// Compare and log.
1331			if (!pixelThresholdCompare(log, ("Level" + de::toString(level) + "Layer" + de::toString(layer)).c_str(), ("Render level " + de::toString(level) + ", Layer" + de::toString(layer)).c_str(), referenceFrame, renderedFrame, threshold, tcu::COMPARE_LOG_ON_ERROR))
1332				results.fail("Image comparison of level " + de::toString(level) + " and layer " + de::toString(layer) + " failed.");
1333			else
1334				log << TestLog::Message << "Image comparison of level " << level << " and layer " << layer << " passed." << TestLog::EndMessage;
1335		}
1336	}
1337
1338	gl.bindTexture(GL_TEXTURE_2D_ARRAY, 0);
1339	GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind texture.");
1340}
1341
1342void verifyTexture2DArray (tcu::TestContext&					testContext,
1343						   glu::RenderContext&					renderContext,
1344						   TextureRenderer&						textureRenderer,
1345						   tcu::ResultCollector&				results,
1346						   de::Random&							rng,
1347						   deUint32								name,
1348						   const vector<ArrayBuffer<deUint8> >&	data,
1349						   const ImageInfo&						info)
1350{
1351	if (glu::isCompressedFormat(info.getFormat()))
1352	{
1353		vector<de::ArrayBuffer<deUint8> >	levelDatas;
1354		vector<tcu::PixelBufferAccess>		levelAccesses;
1355
1356		decompressTexture(levelDatas, levelAccesses, renderContext, info, data);
1357
1358		{
1359			const tcu::Texture2DArrayView refTexture((int)levelAccesses.size(), &(levelAccesses[0]));
1360
1361			verifyTexture2DArrayView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1362		}
1363	}
1364	else
1365	{
1366		const vector<tcu::ConstPixelBufferAccess>	levelAccesses	= getLevelAccesses(data, info);
1367		const tcu::Texture2DArrayView				refTexture		((int)levelAccesses.size(), &(levelAccesses[0]));
1368
1369		verifyTexture2DArrayView(testContext, renderContext, textureRenderer, results, rng, name, info, refTexture);
1370	}
1371}
1372
1373tcu::TextureFormat getReadPixelFormat (const tcu::TextureFormat& format)
1374{
1375	switch (tcu::getTextureChannelClass(format.type))
1376	{
1377		case tcu::TEXTURECHANNELCLASS_FLOATING_POINT:
1378		case tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
1379		case tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
1380			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8);
1381
1382		case tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER:
1383			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::SIGNED_INT32);
1384
1385		case tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
1386			return tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32);
1387
1388		default:
1389			DE_ASSERT(false);
1390			return tcu::TextureFormat();
1391	}
1392}
1393
1394Vec4 calculateThreshold (const tcu::TextureFormat& sourceFormat, const tcu::TextureFormat& readPixelsFormat)
1395{
1396	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_FLOATING_POINT);
1397	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_FLOATING_POINT);
1398
1399	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
1400	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER);
1401
1402	DE_ASSERT(tcu::getTextureChannelClass(sourceFormat.type) != tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER);
1403	DE_ASSERT(tcu::getTextureChannelClass(readPixelsFormat.type) != tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER);
1404
1405	{
1406		const tcu::IVec4	srcBits		= tcu::getTextureFormatBitDepth(sourceFormat);
1407		const tcu::IVec4	readBits	= tcu::getTextureFormatBitDepth(readPixelsFormat);
1408
1409		return Vec4(1.0f) / ((tcu::IVec4(1) << (tcu::min(srcBits, readBits))) - tcu::IVec4(1)).cast<float>();
1410	}
1411}
1412
1413void verifyRenderbuffer (tcu::TestContext&						testContext,
1414						 glu::RenderContext&					renderContext,
1415						 tcu::ResultCollector&					results,
1416						 deUint32								name,
1417						 const vector<ArrayBuffer<deUint8> >&	data,
1418						 const ImageInfo&						info)
1419{
1420	const glw::Functions&				gl					= renderContext.getFunctions();
1421	TestLog&							log					= testContext.getLog();
1422
1423	const tcu::TextureFormat			format				= glu::mapGLInternalFormat(info.getFormat());
1424	const IVec3							size				= info.getSize();
1425	const tcu::ConstPixelBufferAccess	refRenderbuffer		(format, size.x(), size.y(), 1, data[0].getPtr());
1426	const tcu::TextureFormat			readPixelsFormat	= getReadPixelFormat(format);
1427	tcu::TextureLevel					renderbuffer		(readPixelsFormat, size.x(), size.y());
1428
1429	DE_ASSERT(size.z() == 1);
1430	DE_ASSERT(data.size() == 1);
1431
1432	{
1433		glu::Framebuffer framebuffer(gl);
1434
1435		gl.bindFramebuffer(GL_FRAMEBUFFER, *framebuffer);
1436		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to create and bind framebuffer.");
1437
1438		gl.bindRenderbuffer(GL_RENDERBUFFER, name);
1439		gl.framebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, name);
1440		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to bind and attach renderbuffer to framebuffer.");
1441
1442		glu::readPixels(renderContext, 0, 0, renderbuffer.getAccess());
1443
1444		gl.bindRenderbuffer(GL_RENDERBUFFER, 0);
1445		gl.bindFramebuffer(GL_FRAMEBUFFER, 0);
1446		GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to unbind renderbuffer and framebuffer.");
1447	}
1448
1449	if (isFloatFormat(info.getFormat()))
1450	{
1451		const tcu::UVec4 threshold (2, 2, 2, 2);
1452
1453		if (!(tcu::floatUlpThresholdCompare(log, "Image comparison", "Image comparison", refRenderbuffer, renderbuffer.getAccess(), threshold, tcu::COMPARE_LOG_ON_ERROR)))
1454			results.fail("Image comparison failed.");
1455		else
1456			log << TestLog::Message << "Image comarison passed." << TestLog::EndMessage;
1457	}
1458	else if (isIntFormat(info.getFormat()) || isUintFormat(info.getFormat()))
1459	{
1460		const tcu::UVec4 threshold (1, 1, 1, 1);
1461
1462		if (!(tcu::intThresholdCompare(log, "Image comparison", "Image comparison", refRenderbuffer, renderbuffer.getAccess(), threshold, tcu::COMPARE_LOG_ON_ERROR)))
1463			results.fail("Image comparison failed.");
1464		else
1465			log << TestLog::Message << "Image comarison passed." << TestLog::EndMessage;
1466	}
1467	else
1468	{
1469		const Vec4 threshold = calculateThreshold(format, readPixelsFormat);
1470
1471		if (!(tcu::floatThresholdCompare(log, "Image comparison", "Image comparison", refRenderbuffer, renderbuffer.getAccess(), threshold, tcu::COMPARE_LOG_ON_ERROR)))
1472			results.fail("Image comparison failed.");
1473		else
1474			log << TestLog::Message << "Image comarison passed." << TestLog::EndMessage;
1475	}
1476}
1477
1478void verify (tcu::TestContext&						testContext,
1479			 glu::RenderContext&					renderContext,
1480			 TextureRenderer&						textureRenderer,
1481			 tcu::ResultCollector&					results,
1482			 de::Random&							rng,
1483			 deUint32								name,
1484			 const vector<ArrayBuffer<deUint8> >&	data,
1485			 const ImageInfo&						info)
1486{
1487	switch (info.getTarget())
1488	{
1489		case GL_TEXTURE_2D:
1490			verifyTexture2D(testContext, renderContext, textureRenderer, results, rng, name, data, info);
1491			break;
1492
1493		case GL_TEXTURE_3D:
1494			verifyTexture3D(testContext, renderContext, textureRenderer, results, rng, name, data, info);
1495			break;
1496
1497		case GL_TEXTURE_CUBE_MAP:
1498			verifyTextureCubemap(testContext, renderContext, textureRenderer, results, rng, name, data, info);
1499			break;
1500
1501		case GL_TEXTURE_2D_ARRAY:
1502			verifyTexture2DArray(testContext, renderContext, textureRenderer, results, rng, name, data, info);
1503			break;
1504
1505		case GL_RENDERBUFFER:
1506			verifyRenderbuffer(testContext, renderContext, results, name, data, info);
1507			break;
1508
1509		default:
1510			DE_ASSERT(false);
1511	}
1512}
1513
1514void logTestImageInfo (TestLog&			log,
1515					   const ImageInfo&	imageInfo)
1516{
1517	log << TestLog::Message << "Target: " << targetToName(imageInfo.getTarget()) << TestLog::EndMessage;
1518	log << TestLog::Message << "Size: " << imageInfo.getSize() << TestLog::EndMessage;
1519	log << TestLog::Message << "Levels: " << getLevelCount(imageInfo) << TestLog::EndMessage;
1520	log << TestLog::Message << "Format: " << formatToName(imageInfo.getFormat()) << TestLog::EndMessage;
1521}
1522
1523void logTestInfo (TestLog&			log,
1524				  const ImageInfo&	srcImageInfo,
1525				  const ImageInfo&	dstImageInfo)
1526{
1527	tcu::ScopedLogSection section(log, "TestCaseInfo", "Test case info");
1528
1529	log << TestLog::Message << "Testing copying from " << targetToName(srcImageInfo.getTarget()) << " to " << targetToName(dstImageInfo.getTarget()) << "." << TestLog::EndMessage;
1530
1531	{
1532		tcu::ScopedLogSection srcSection(log, "Source image info.", "Source image info.");
1533		logTestImageInfo(log, srcImageInfo);
1534	}
1535
1536	{
1537		tcu::ScopedLogSection dstSection(log, "Destination image info.", "Destination image info.");
1538		logTestImageInfo(log, dstImageInfo);
1539	}
1540}
1541
1542class CopyImageTest : public TestCase
1543{
1544public:
1545							CopyImageTest			(Context&			context,
1546													 const ImageInfo&	srcImage,
1547													 const ImageInfo&	dstImage,
1548													 const char*		name,
1549													 const char*		description);
1550
1551							~CopyImageTest			(void);
1552
1553	void					init					(void);
1554	void					deinit					(void);
1555
1556	TestCase::IterateResult	iterate					(void);
1557
1558private:
1559	void					logTestInfoIter			(void);
1560	void					createImagesIter		(void);
1561	void					destroyImagesIter		(void);
1562	void					verifySourceIter		(void);
1563	void					verifyDestinationIter	(void);
1564	void					copyImageIter			(void);
1565
1566	struct State
1567	{
1568		State (int					seed,
1569			   tcu::TestLog&		log,
1570			   glu::RenderContext&	renderContext)
1571			: rng				(seed)
1572			, results			(log)
1573			, srcImage			(NULL)
1574			, dstImage			(NULL)
1575			, textureRenderer	(renderContext, log, glu::GLSL_VERSION_310_ES, glu::PRECISION_HIGHP)
1576		{
1577		}
1578
1579		~State (void)
1580		{
1581			delete srcImage;
1582			delete dstImage;
1583		}
1584
1585		de::Random						rng;
1586		tcu::ResultCollector			results;
1587		glu::ObjectWrapper*				srcImage;
1588		glu::ObjectWrapper*				dstImage;
1589		TextureRenderer					textureRenderer;
1590
1591		vector<ArrayBuffer<deUint8> >	srcImageLevels;
1592		vector<ArrayBuffer<deUint8> >	dstImageLevels;
1593	};
1594
1595	const ImageInfo	m_srcImageInfo;
1596	const ImageInfo	m_dstImageInfo;
1597
1598	int				m_iteration;
1599	State*			m_state;
1600};
1601
1602CopyImageTest::CopyImageTest (Context&			context,
1603							  const ImageInfo&	srcImage,
1604							  const ImageInfo&	dstImage,
1605							  const char*		name,
1606							  const char*		description)
1607	: TestCase			(context, name, description)
1608	, m_srcImageInfo	(srcImage)
1609	, m_dstImageInfo	(dstImage)
1610
1611	, m_iteration		(0)
1612	, m_state			(NULL)
1613{
1614}
1615
1616CopyImageTest::~CopyImageTest (void)
1617{
1618	deinit();
1619}
1620
1621void checkFormatSupport (glu::ContextInfo& info, deUint32 format, deUint32 target)
1622{
1623	if (glu::isCompressedFormat(format))
1624	{
1625		if (isAstcFormat(glu::mapGLCompressedTexFormat(format)))
1626		{
1627			DE_ASSERT(target != GL_RENDERBUFFER);
1628			if (!info.isExtensionSupported("GL_KHR_texture_compression_astc_hdr") &&
1629				!info.isExtensionSupported("GL_OES_texture_compression_astc"))
1630			{
1631				if (target == GL_TEXTURE_3D)
1632					TCU_THROW(NotSupportedError, "TEXTURE_3D target requires HDR astc support.");
1633				if (!info.isExtensionSupported("GL_KHR_texture_compression_astc_ldr"))
1634					TCU_THROW(NotSupportedError, "Compressed astc texture not supported.");
1635			}
1636		}
1637		else
1638		{
1639			if (!info.isCompressedTextureFormatSupported(format))
1640				TCU_THROW(NotSupportedError, "Compressed texture not supported.");
1641		}
1642	}
1643}
1644
1645void CopyImageTest::init (void)
1646{
1647	de::UniquePtr<glu::ContextInfo> ctxInfo(glu::ContextInfo::create(m_context.getRenderContext()));
1648
1649	if (!ctxInfo->isExtensionSupported("GL_EXT_copy_image"))
1650		throw tcu::NotSupportedError("Extension GL_EXT_copy_image not supported.", "", __FILE__, __LINE__);
1651
1652	checkFormatSupport(*ctxInfo, m_srcImageInfo.getFormat(), m_srcImageInfo.getTarget());
1653	checkFormatSupport(*ctxInfo, m_dstImageInfo.getFormat(), m_dstImageInfo.getTarget());
1654
1655	{
1656		SeedBuilder builder;
1657
1658		builder << 903980
1659				<< m_srcImageInfo
1660				<< m_dstImageInfo;
1661
1662		m_state = new State(builder.get(), m_testCtx.getLog(), m_context.getRenderContext());
1663	}
1664}
1665
1666void CopyImageTest::deinit (void)
1667{
1668	delete m_state;
1669	m_state = NULL;
1670}
1671
1672void CopyImageTest::logTestInfoIter (void)
1673{
1674	TestLog& log = m_testCtx.getLog();
1675
1676	logTestInfo(log, m_srcImageInfo, m_dstImageInfo);
1677}
1678
1679void CopyImageTest::createImagesIter (void)
1680{
1681	TestLog&				log						= m_testCtx.getLog();
1682	glu::RenderContext&		renderContext			= m_context.getRenderContext();
1683	const glw::Functions&	gl						= renderContext.getFunctions();
1684	const deUint32			moreRestrictiveFormat	= getMoreRestrictiveFormat(m_srcImageInfo.getFormat(), m_dstImageInfo.getFormat());
1685	de::Random&				rng						= m_state->rng;
1686
1687	DE_ASSERT(!m_state->srcImage);
1688	DE_ASSERT(!m_state->dstImage);
1689
1690	m_state->srcImage = new glu::ObjectWrapper(gl, getObjectTraits(m_srcImageInfo));
1691	m_state->dstImage = new glu::ObjectWrapper(gl, getObjectTraits(m_dstImageInfo));
1692
1693	{
1694		glu::ObjectWrapper&				srcImage				= *m_state->srcImage;
1695		glu::ObjectWrapper&				dstImage				= *m_state->dstImage;
1696
1697		vector<ArrayBuffer<deUint8> >&	srcImageLevels			= m_state->srcImageLevels;
1698		vector<ArrayBuffer<deUint8> >&	dstImageLevels			= m_state->dstImageLevels;
1699
1700		log << TestLog::Message << "Creating source image." << TestLog::EndMessage;
1701		genImage(gl, rng, *srcImage, srcImageLevels, m_srcImageInfo, moreRestrictiveFormat);
1702
1703		log << TestLog::Message << "Creating destination image." << TestLog::EndMessage;
1704		genImage(gl, rng, *dstImage, dstImageLevels, m_dstImageInfo, moreRestrictiveFormat);
1705	}
1706}
1707
1708void CopyImageTest::destroyImagesIter (void)
1709{
1710	TestLog& log = m_testCtx.getLog();
1711
1712	log << TestLog::Message << "Deleting source image. " << TestLog::EndMessage;
1713
1714	delete m_state->srcImage;
1715	m_state->srcImage = NULL;
1716	m_state->srcImageLevels.clear();
1717
1718	log << TestLog::Message << "Deleting destination image. " << TestLog::EndMessage;
1719
1720	delete m_state->dstImage;
1721	m_state->dstImage = NULL;
1722	m_state->dstImageLevels.clear();
1723}
1724
1725void CopyImageTest::verifySourceIter (void)
1726{
1727	TestLog&						log					= m_testCtx.getLog();
1728	const tcu::ScopedLogSection		sourceSection		(log, "Source image verify.", "Source image verify.");
1729
1730	de::Random&						rng					= m_state->rng;
1731	tcu::ResultCollector&			results				= m_state->results;
1732	glu::ObjectWrapper&				srcImage			= *m_state->srcImage;
1733	vector<ArrayBuffer<deUint8> >&	srcImageLevels		= m_state->srcImageLevels;
1734
1735	log << TestLog::Message << "Verifying source image." << TestLog::EndMessage;
1736
1737	verify(m_testCtx, m_context.getRenderContext(), m_state->textureRenderer, results, rng, *srcImage, srcImageLevels, m_srcImageInfo);
1738}
1739
1740void CopyImageTest::verifyDestinationIter (void)
1741{
1742	TestLog&						log					= m_testCtx.getLog();
1743	const tcu::ScopedLogSection		destinationSection	(log, "Destination image verify.", "Destination image verify.");
1744
1745	de::Random&						rng					= m_state->rng;
1746	tcu::ResultCollector&			results				= m_state->results;
1747	glu::ObjectWrapper&				dstImage			= *m_state->dstImage;
1748	vector<ArrayBuffer<deUint8> >&	dstImageLevels		= m_state->dstImageLevels;
1749
1750	log << TestLog::Message << "Verifying destination image." << TestLog::EndMessage;
1751
1752	verify(m_testCtx, m_context.getRenderContext(), m_state->textureRenderer, results, rng, *dstImage, dstImageLevels, m_dstImageInfo);
1753}
1754
1755struct Copy
1756{
1757	Copy (const IVec3&	srcPos_,
1758		  int			srcLevel_,
1759
1760		  const IVec3&	dstPos_,
1761		  int			dstLevel_,
1762
1763		  const IVec3&	size_)
1764		: srcPos	(srcPos_)
1765		, srcLevel	(srcLevel_)
1766
1767		, dstPos	(dstPos_)
1768		, dstLevel	(dstLevel_)
1769		, size		(size_)
1770	{
1771	}
1772
1773	IVec3	srcPos;
1774	int		srcLevel;
1775	IVec3	dstPos;
1776	int		dstLevel;
1777	IVec3	size;
1778};
1779
1780int getLastFullLevel (const ImageInfo& info)
1781{
1782	const int	levelCount		= getLevelCount(info);
1783	const IVec3	blockPixelSize	= getTexelBlockPixelSize(info.getFormat());
1784
1785	for (int level = 0; level < levelCount; level++)
1786	{
1787		const IVec3 levelSize = getLevelSize(info.getTarget(), info.getSize(), level);
1788
1789		if (levelSize.x() < blockPixelSize.x() || levelSize.y() < blockPixelSize.y() || levelSize.z() < blockPixelSize.z())
1790			return level - 1;
1791	}
1792
1793	return levelCount -1;
1794}
1795
1796void generateCopies (vector<Copy>& copies, const ImageInfo& srcInfo, const ImageInfo& dstInfo)
1797{
1798	const deUint32	srcTarget		= srcInfo.getTarget();
1799	const deUint32	dstTarget		= dstInfo.getTarget();
1800
1801	const bool		srcIsTexture	= isTextureTarget(srcInfo.getTarget());
1802	const bool		dstIsTexture	= isTextureTarget(dstInfo.getTarget());
1803
1804	const bool		srcIsCube		= srcTarget == GL_TEXTURE_CUBE_MAP;
1805	const bool		dstIsCube		= dstTarget == GL_TEXTURE_CUBE_MAP;
1806
1807	const IVec3		srcBlockPixelSize		= getTexelBlockPixelSize(srcInfo.getFormat());
1808	const IVec3		dstBlockPixelSize		= getTexelBlockPixelSize(dstInfo.getFormat());
1809
1810	const int levels[] =
1811	{
1812		0, 1, -1
1813	};
1814
1815	for (int levelNdx = 0; levelNdx < (srcIsTexture || dstIsTexture ? DE_LENGTH_OF_ARRAY(levels) : 1); levelNdx++)
1816	{
1817		const int	srcLevel				= (srcIsTexture ? (levels[levelNdx] >= 0 ? levels[levelNdx] : getLastFullLevel(srcInfo)) : 0);
1818		const int	dstLevel				= (dstIsTexture ? (levels[levelNdx] >= 0 ? levels[levelNdx] : getLastFullLevel(dstInfo)) : 0);
1819
1820		const IVec3	srcSize					= getLevelSize(srcInfo.getTarget(), srcInfo.getSize(), srcLevel);
1821		const IVec3	dstSize					= getLevelSize(dstInfo.getTarget(), dstInfo.getSize(), dstLevel);
1822
1823		// \note These are rounded down
1824		const IVec3	srcCompleteBlockSize	= IVec3(srcSize.x() / srcBlockPixelSize.x(), srcSize.y() / srcBlockPixelSize.y(), (srcIsCube ? 6 : srcSize.z() / srcBlockPixelSize.z()));
1825		const IVec3	dstCompleteBlockSize	= IVec3(dstSize.x() / dstBlockPixelSize.x(), dstSize.y() / dstBlockPixelSize.y(), (dstIsCube ? 6 : dstSize.z() / dstBlockPixelSize.z()));
1826
1827		const IVec3	maxCopyBlockSize		= tcu::min(srcCompleteBlockSize, dstCompleteBlockSize);
1828
1829		// \note These are rounded down
1830		const int	copyBlockWidth			= de::max((2 * (maxCopyBlockSize.x() / 4)) - 1, 1);
1831		const int	copyBlockHeight			= de::max((2 * (maxCopyBlockSize.y() / 4)) - 1, 1);
1832		const int	copyBlockDepth			= de::max((2 * (maxCopyBlockSize.z() / 4)) - 1, 1);
1833
1834		// Copy NPOT block from (0,0,0) to other corner on dst
1835		{
1836			const IVec3	copyBlockSize	(copyBlockWidth, copyBlockHeight, copyBlockDepth);
1837			const IVec3	srcBlockPos		(srcCompleteBlockSize - copyBlockSize);
1838			const IVec3	dstBlockPos		(0, 0, 0);
1839
1840			const IVec3	srcPos			(srcBlockPos * srcBlockPixelSize);
1841			const IVec3	dstPos			(dstBlockPos * dstBlockPixelSize);
1842			const IVec3 copySize		(copyBlockSize * srcBlockPixelSize);
1843
1844			copies.push_back(Copy(srcPos, srcLevel, dstPos, dstLevel, copySize));
1845		}
1846
1847		// Copy NPOT block to (0,0,0) from other corner on src
1848		{
1849			const IVec3	copyBlockSize	(copyBlockWidth, copyBlockHeight, copyBlockDepth);
1850			const IVec3	srcBlockPos		(0, 0, 0);
1851			const IVec3	dstBlockPos		(dstCompleteBlockSize - copyBlockSize);
1852
1853			const IVec3	srcPos			(srcBlockPos * srcBlockPixelSize);
1854			const IVec3	dstPos			(dstBlockPos * dstBlockPixelSize);
1855			const IVec3 copySize		(copyBlockSize * srcBlockPixelSize);
1856
1857			copies.push_back(Copy(srcPos, srcLevel, dstPos, dstLevel, copySize));
1858		}
1859
1860		// Copy NPOT block to (0,0,0) from other corner on src
1861		{
1862			const IVec3	copyBlockSize	(copyBlockWidth, copyBlockHeight, copyBlockDepth);
1863			const IVec3	srcBlockPos		(tcu::max((srcCompleteBlockSize / 4) * 4 - copyBlockSize, IVec3(0)));
1864			const IVec3	dstBlockPos		(tcu::max((dstCompleteBlockSize / 4) * 4 - copyBlockSize, IVec3(0)));
1865
1866			const IVec3	srcPos			(srcBlockPos * srcBlockPixelSize);
1867			const IVec3	dstPos			(dstBlockPos * dstBlockPixelSize);
1868			const IVec3 copySize		(copyBlockSize * srcBlockPixelSize);
1869
1870			copies.push_back(Copy(srcPos, srcLevel, dstPos, dstLevel, copySize));
1871		}
1872	}
1873}
1874
1875void CopyImageTest::copyImageIter (void)
1876{
1877	TestLog&						log				= m_testCtx.getLog();
1878	const glw::Functions&			gl				= m_context.getRenderContext().getFunctions();
1879	glu::ObjectWrapper&				srcImage		= *m_state->srcImage;
1880	glu::ObjectWrapper&				dstImage		= *m_state->dstImage;
1881
1882	vector<ArrayBuffer<deUint8> >&	srcImageLevels	= m_state->srcImageLevels;
1883	vector<ArrayBuffer<deUint8> >&	dstImageLevels	= m_state->dstImageLevels;
1884	vector<Copy>					copies;
1885
1886	generateCopies(copies, m_srcImageInfo, m_dstImageInfo);
1887
1888	for (int copyNdx = 0; copyNdx < (int)copies.size(); copyNdx++)
1889	{
1890		const Copy& copy = copies[copyNdx];
1891
1892		log << TestLog::Message << "Copying block " << copy.size << " from source image position " << copy.srcPos << " and mipmap level " << copy.srcLevel
1893								<< " to destination image position " << copy.dstPos << " and mipmap level " << copy.dstLevel << TestLog::EndMessage;
1894
1895		copyImage(gl, *dstImage, dstImageLevels, m_dstImageInfo, copy.dstLevel, copy.dstPos,
1896					  *srcImage, srcImageLevels, m_srcImageInfo, copy.srcLevel, copy.srcPos, copy.size);
1897	}
1898}
1899
1900TestCase::IterateResult CopyImageTest::iterate (void)
1901{
1902	void(CopyImageTest::*methods[])(void) =
1903	{
1904		&CopyImageTest::logTestInfoIter,
1905
1906		// Render both images and then copy and verify again.
1907		&CopyImageTest::createImagesIter,
1908		&CopyImageTest::verifySourceIter,
1909		&CopyImageTest::verifyDestinationIter,
1910		&CopyImageTest::copyImageIter,
1911		&CopyImageTest::verifySourceIter,
1912		&CopyImageTest::verifyDestinationIter,
1913		&CopyImageTest::destroyImagesIter,
1914
1915		// Create images and immediately copies between thew and verify.
1916		&CopyImageTest::createImagesIter,
1917		&CopyImageTest::copyImageIter,
1918		&CopyImageTest::verifySourceIter,
1919		&CopyImageTest::verifyDestinationIter,
1920		&CopyImageTest::destroyImagesIter
1921	};
1922
1923	if (m_iteration < DE_LENGTH_OF_ARRAY(methods))
1924	{
1925		(this->*methods[m_iteration])();
1926		m_iteration++;
1927		return CONTINUE;
1928	}
1929	else
1930	{
1931		m_state->results.setTestContextResult(m_testCtx);
1932		return STOP;
1933	}
1934}
1935
1936class CopyImageTests : public TestCaseGroup
1937{
1938public:
1939						CopyImageTests			(Context& context);
1940						~CopyImageTests			(void);
1941
1942	void				init					(void);
1943
1944private:
1945						CopyImageTests			(const CopyImageTests& other);
1946	CopyImageTests&		operator=				(const CopyImageTests& other);
1947};
1948
1949CopyImageTests::CopyImageTests (Context& context)
1950	: TestCaseGroup	(context, "copy_image", "Copy image tests for GL_EXT_copy_image.")
1951{
1952}
1953
1954CopyImageTests::~CopyImageTests (void)
1955{
1956}
1957
1958int smallestCommonMultiple (int a_, int b_)
1959{
1960	int	a		= (a_ > b_ ? a_ : b_);
1961	int	b		= (a_ > b_ ? b_ : a_);
1962	int	result  = 1;
1963
1964	for (int i = b/2; i > 1; i--)
1965	{
1966		while ((a % i) == 0 && (b % i) == 0)
1967		{
1968			result *= i;
1969			a /= i;
1970			b /= i;
1971		}
1972	}
1973
1974	return result * a * b;
1975}
1976
1977IVec3 getTestedSize (deUint32 target, deUint32 format, const IVec3& targetSize)
1978{
1979	const IVec3 texelBlockPixelSize = getTexelBlockPixelSize(format);
1980	const bool	isCube				= target == GL_TEXTURE_CUBE_MAP;
1981	const bool	is3D				= target == GL_TEXTURE_3D || target == GL_TEXTURE_2D_ARRAY;
1982
1983	if (isCube)
1984	{
1985		const int	multiplier	= smallestCommonMultiple(texelBlockPixelSize.x(), texelBlockPixelSize.y());
1986		const int	size		= (1 + (targetSize.x() / multiplier)) * multiplier;
1987
1988		return IVec3(size, size, 1);
1989	}
1990	else if (is3D)
1991	{
1992		return (1 + (targetSize / texelBlockPixelSize)) * texelBlockPixelSize;
1993	}
1994	else
1995	{
1996		const int width = (1 + targetSize.x() / texelBlockPixelSize.x()) * texelBlockPixelSize.x();
1997		const int height = ((targetSize.y() / texelBlockPixelSize.y()) - 1) * texelBlockPixelSize.y();
1998
1999		return IVec3(width, height, 1);
2000	}
2001}
2002
2003void addCopyTests (TestCaseGroup* root, deUint32 srcFormat, deUint32 dstFormat)
2004{
2005	const string			groupName	= string(formatToName(srcFormat)) + "_" + formatToName(dstFormat);
2006	TestCaseGroup* const	group		= new TestCaseGroup(root->getContext(), groupName.c_str(), groupName.c_str());
2007
2008	const deUint32 targets[] =
2009	{
2010		GL_TEXTURE_2D,
2011		GL_TEXTURE_3D,
2012		GL_TEXTURE_CUBE_MAP,
2013		GL_TEXTURE_2D_ARRAY,
2014		GL_RENDERBUFFER
2015	};
2016
2017	root->addChild(group);
2018
2019	for (int srcTargetNdx = 0; srcTargetNdx < DE_LENGTH_OF_ARRAY(targets); srcTargetNdx++)
2020	{
2021		const deUint32	srcTarget				= targets[srcTargetNdx];
2022		const bool		srcIs3D					= srcTarget == GL_TEXTURE_2D_ARRAY || srcTarget == GL_TEXTURE_3D;
2023
2024		if (glu::isCompressedFormat(srcFormat) && srcTarget == GL_RENDERBUFFER)
2025			continue;
2026
2027		if (srcTarget == GL_RENDERBUFFER && !isColorRenderable(srcFormat))
2028			continue;
2029
2030		if (glu::isCompressedFormat(srcFormat) && !tcu::isAstcFormat(glu::mapGLCompressedTexFormat(srcFormat)) && srcIs3D)
2031			continue;
2032
2033		for (int dstTargetNdx = 0; dstTargetNdx < DE_LENGTH_OF_ARRAY(targets); dstTargetNdx++)
2034		{
2035			const deUint32	dstTarget				= targets[dstTargetNdx];
2036			const bool		dstIs3D					= dstTarget == GL_TEXTURE_2D_ARRAY || dstTarget == GL_TEXTURE_3D;
2037
2038			if (glu::isCompressedFormat(dstFormat) && dstTarget == GL_RENDERBUFFER)
2039				continue;
2040
2041			if (dstTarget == GL_RENDERBUFFER && !isColorRenderable(dstFormat))
2042				continue;
2043
2044			if (glu::isCompressedFormat(dstFormat) && !tcu::isAstcFormat(glu::mapGLCompressedTexFormat(dstFormat)) && dstIs3D)
2045				continue;
2046
2047			const string	targetTestName	= string(targetToName(srcTarget)) + "_to_" + targetToName(dstTarget);
2048
2049			const IVec3		targetSize2D	(128, 128, 1);
2050			const IVec3		targetSize3D	(128, 128, 16);
2051
2052			const IVec3		srcSize			= getTestedSize(srcTarget, srcFormat, (srcIs3D ? targetSize3D : targetSize2D));
2053			const IVec3		dstSize			= getTestedSize(dstTarget, dstFormat, (dstIs3D ? targetSize3D : targetSize2D));
2054
2055			group->addChild(new CopyImageTest(root->getContext(),
2056											ImageInfo(srcFormat, srcTarget, srcSize),
2057											ImageInfo(dstFormat, dstTarget, dstSize),
2058											targetTestName.c_str(), targetTestName.c_str()));
2059		}
2060	}
2061}
2062
2063void CopyImageTests::init (void)
2064{
2065	TestCaseGroup* const	nonCompressedGroup	= new TestCaseGroup(m_context, "non_compressed", "Test copying between textures.");
2066	TestCaseGroup* const	compressedGroup		= new TestCaseGroup(m_context, "compressed", "Test copying between compressed textures.");
2067	TestCaseGroup* const	mixedGroup			= new TestCaseGroup(m_context, "mixed", "Test copying between compressed and non-compressed textures.");
2068
2069	addChild(nonCompressedGroup);
2070	addChild(compressedGroup);
2071	addChild(mixedGroup);
2072
2073	map<ViewClass, vector<deUint32> >							textureFormatViewClasses;
2074	map<ViewClass, vector<deUint32> >							compressedTextureFormatViewClasses;
2075	map<ViewClass, pair<vector<deUint32>, vector<deUint32> > >	mixedViewClasses;
2076
2077	// Texture view classes
2078	textureFormatViewClasses[VIEWCLASS_128_BITS]		= vector<deUint32>();
2079	textureFormatViewClasses[VIEWCLASS_96_BITS]			= vector<deUint32>();
2080	textureFormatViewClasses[VIEWCLASS_64_BITS]			= vector<deUint32>();
2081	textureFormatViewClasses[VIEWCLASS_48_BITS]			= vector<deUint32>();
2082	textureFormatViewClasses[VIEWCLASS_32_BITS]			= vector<deUint32>();
2083	textureFormatViewClasses[VIEWCLASS_24_BITS]			= vector<deUint32>();
2084	textureFormatViewClasses[VIEWCLASS_16_BITS]			= vector<deUint32>();
2085	textureFormatViewClasses[VIEWCLASS_8_BITS]			= vector<deUint32>();
2086
2087	// 128bit / VIEWCLASS_128_BITS
2088	textureFormatViewClasses[VIEWCLASS_128_BITS].push_back(GL_RGBA32F);
2089	textureFormatViewClasses[VIEWCLASS_128_BITS].push_back(GL_RGBA32I);
2090	textureFormatViewClasses[VIEWCLASS_128_BITS].push_back(GL_RGBA32UI);
2091
2092	// 96bit / VIEWCLASS_96_BITS
2093	textureFormatViewClasses[VIEWCLASS_96_BITS].push_back(GL_RGB32F);
2094	textureFormatViewClasses[VIEWCLASS_96_BITS].push_back(GL_RGB32I);
2095	textureFormatViewClasses[VIEWCLASS_96_BITS].push_back(GL_RGB32UI);
2096
2097	// 64bit / VIEWCLASS_64_BITS
2098	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RG32F);
2099	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RG32I);
2100	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RG32UI);
2101
2102	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RGBA16F);
2103	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RGBA16I);
2104	textureFormatViewClasses[VIEWCLASS_64_BITS].push_back(GL_RGBA16UI);
2105
2106	// 48bit / VIEWCLASS_48_BITS
2107	textureFormatViewClasses[VIEWCLASS_48_BITS].push_back(GL_RGB16F);
2108	textureFormatViewClasses[VIEWCLASS_48_BITS].push_back(GL_RGB16I);
2109	textureFormatViewClasses[VIEWCLASS_48_BITS].push_back(GL_RGB16UI);
2110
2111	// 32bit / VIEWCLASS_32_BITS
2112	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_R32F);
2113	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_R32I);
2114	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_R32UI);
2115
2116	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RG16F);
2117	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RG16I);
2118	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RG16UI);
2119
2120	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGBA8);
2121	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGBA8I);
2122	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGBA8UI);
2123
2124	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_R11F_G11F_B10F);
2125	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGB10_A2UI);
2126	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGB10_A2);
2127	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGBA8_SNORM);
2128	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_SRGB8_ALPHA8);
2129	textureFormatViewClasses[VIEWCLASS_32_BITS].push_back(GL_RGB9_E5);
2130
2131	// 24bit / VIEWCLASS_24_BITS
2132	textureFormatViewClasses[VIEWCLASS_24_BITS].push_back(GL_RGB8);
2133	textureFormatViewClasses[VIEWCLASS_24_BITS].push_back(GL_RGB8I);
2134	textureFormatViewClasses[VIEWCLASS_24_BITS].push_back(GL_RGB8UI);
2135	textureFormatViewClasses[VIEWCLASS_24_BITS].push_back(GL_RGB8_SNORM);
2136	textureFormatViewClasses[VIEWCLASS_24_BITS].push_back(GL_SRGB8);
2137
2138	// 16bit / VIEWCLASS_16_BITS
2139	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_R16F);
2140	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_R16I);
2141	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_R16UI);
2142
2143	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_RG8);
2144	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_RG8I);
2145	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_RG8UI);
2146	textureFormatViewClasses[VIEWCLASS_16_BITS].push_back(GL_RG8_SNORM);
2147
2148	// 8bit / VIEWCLASS_8_BITS
2149	textureFormatViewClasses[VIEWCLASS_8_BITS].push_back(GL_R8);
2150	textureFormatViewClasses[VIEWCLASS_8_BITS].push_back(GL_R8I);
2151	textureFormatViewClasses[VIEWCLASS_8_BITS].push_back(GL_R8UI);
2152	textureFormatViewClasses[VIEWCLASS_8_BITS].push_back(GL_R8_SNORM);
2153
2154	// Compressed texture view classes
2155	compressedTextureFormatViewClasses[VIEWCLASS_EAC_R11]			= vector<deUint32>();
2156	compressedTextureFormatViewClasses[VIEWCLASS_EAC_RG11]			= vector<deUint32>();
2157	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGB]			= vector<deUint32>();
2158	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGBA]			= vector<deUint32>();
2159	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_EAC_RGBA]		= vector<deUint32>();
2160	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_4x4_RGBA]		= vector<deUint32>();
2161	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x4_RGBA]		= vector<deUint32>();
2162	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x5_RGBA]		= vector<deUint32>();
2163	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x5_RGBA]		= vector<deUint32>();
2164	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x6_RGBA]		= vector<deUint32>();
2165	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x5_RGBA]		= vector<deUint32>();
2166	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x6_RGBA]		= vector<deUint32>();
2167	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x8_RGBA]		= vector<deUint32>();
2168	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x5_RGBA]	= vector<deUint32>();
2169	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x6_RGBA]	= vector<deUint32>();
2170	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x8_RGBA]	= vector<deUint32>();
2171	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x10_RGBA]	= vector<deUint32>();
2172	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x10_RGBA]	= vector<deUint32>();
2173	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x12_RGBA]	= vector<deUint32>();
2174
2175	// VIEWCLASS_EAC_R11
2176	compressedTextureFormatViewClasses[VIEWCLASS_EAC_R11].push_back(GL_COMPRESSED_R11_EAC);
2177	compressedTextureFormatViewClasses[VIEWCLASS_EAC_R11].push_back(GL_COMPRESSED_SIGNED_R11_EAC);
2178
2179	// VIEWCLASS_EAC_RG11
2180	compressedTextureFormatViewClasses[VIEWCLASS_EAC_RG11].push_back(GL_COMPRESSED_RG11_EAC);
2181	compressedTextureFormatViewClasses[VIEWCLASS_EAC_RG11].push_back(GL_COMPRESSED_SIGNED_RG11_EAC);
2182
2183	// VIEWCLASS_ETC2_RGB
2184	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGB].push_back(GL_COMPRESSED_RGB8_ETC2);
2185	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGB].push_back(GL_COMPRESSED_SRGB8_ETC2);
2186
2187	// VIEWCLASS_ETC2_RGBA
2188	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGBA].push_back(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
2189	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_RGBA].push_back(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
2190
2191	// VIEWCLASS_ETC2_EAC_RGBA
2192	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_EAC_RGBA].push_back(GL_COMPRESSED_RGBA8_ETC2_EAC);
2193	compressedTextureFormatViewClasses[VIEWCLASS_ETC2_EAC_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
2194
2195	// VIEWCLASS_ASTC_4x4_RGBA
2196	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_4x4_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_4x4_KHR);
2197	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_4x4_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR);
2198
2199	// VIEWCLASS_ASTC_5x4_RGBA
2200	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x4_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_5x4_KHR);
2201	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x4_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR);
2202
2203	// VIEWCLASS_ASTC_5x5_RGBA
2204	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x5_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_5x5_KHR);
2205	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_5x5_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR);
2206
2207	// VIEWCLASS_ASTC_6x5_RGBA
2208	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x5_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_6x5_KHR);
2209	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x5_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR);
2210
2211	// VIEWCLASS_ASTC_6x6_RGBA
2212	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x6_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_6x6_KHR);
2213	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_6x6_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR);
2214
2215	// VIEWCLASS_ASTC_8x5_RGBA
2216	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x5_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_8x5_KHR);
2217	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x5_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR);
2218
2219	// VIEWCLASS_ASTC_8x6_RGBA
2220	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x6_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_8x6_KHR);
2221	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x6_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR);
2222
2223	// VIEWCLASS_ASTC_8x8_RGBA
2224	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x8_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_8x8_KHR);
2225	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_8x8_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR);
2226
2227	// VIEWCLASS_ASTC_10x5_RGBA
2228	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x5_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_10x5_KHR);
2229	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x5_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR);
2230
2231	// VIEWCLASS_ASTC_10x6_RGBA
2232	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x6_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_10x6_KHR);
2233	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x6_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR);
2234
2235	// VIEWCLASS_ASTC_10x8_RGBA
2236	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x8_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_10x8_KHR);
2237	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x8_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR);
2238
2239	// VIEWCLASS_ASTC_10x10_RGBA
2240	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x10_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_10x10_KHR);
2241	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_10x10_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR);
2242
2243	// VIEWCLASS_ASTC_12x10_RGBA
2244	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x10_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_12x10_KHR);
2245	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x10_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR);
2246
2247	// VIEWCLASS_ASTC_12x12_RGBA
2248	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x12_RGBA].push_back(GL_COMPRESSED_RGBA_ASTC_12x12_KHR);
2249	compressedTextureFormatViewClasses[VIEWCLASS_ASTC_12x12_RGBA].push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR);
2250
2251	// Mixed view classes
2252	mixedViewClasses[VIEWCLASS_128_BITS] = pair<vector<deUint32>, vector<deUint32> >();
2253	mixedViewClasses[VIEWCLASS_64_BITS] = pair<vector<deUint32>, vector<deUint32> >();
2254
2255	// 128 bits
2256
2257	// Non compressed
2258	mixedViewClasses[VIEWCLASS_128_BITS].first.push_back(GL_RGBA32F);
2259	mixedViewClasses[VIEWCLASS_128_BITS].first.push_back(GL_RGBA32UI);
2260	mixedViewClasses[VIEWCLASS_128_BITS].first.push_back(GL_RGBA32I);
2261
2262	// Compressed
2263	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA8_ETC2_EAC);
2264	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
2265	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RG11_EAC);
2266	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SIGNED_RG11_EAC);
2267	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_4x4_KHR);
2268	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_5x4_KHR);
2269	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_5x5_KHR);
2270	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_6x5_KHR);
2271	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_6x6_KHR);
2272	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_8x5_KHR);
2273	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_8x6_KHR);
2274	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_8x8_KHR);
2275	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_10x5_KHR);
2276	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_10x6_KHR);
2277	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_10x8_KHR);
2278	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_10x10_KHR);
2279	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_12x10_KHR);
2280	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_RGBA_ASTC_12x12_KHR);
2281	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR);
2282	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR);
2283	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR);
2284	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR);
2285	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR);
2286	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR);
2287	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR);
2288	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR);
2289	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR);
2290	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR);
2291	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR);
2292	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR);
2293	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR);
2294	mixedViewClasses[VIEWCLASS_128_BITS].second.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR);
2295
2296	// 64 bits
2297
2298	// Non compressed
2299	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RGBA16F);
2300	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RGBA16UI);
2301	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RGBA16I);
2302
2303	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RG32F);
2304	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RG32UI);
2305	mixedViewClasses[VIEWCLASS_64_BITS].first.push_back(GL_RG32I);
2306
2307	// Compressed
2308	mixedViewClasses[VIEWCLASS_64_BITS].second.push_back(GL_COMPRESSED_R11_EAC);
2309	mixedViewClasses[VIEWCLASS_64_BITS].second.push_back(GL_COMPRESSED_SIGNED_R11_EAC);
2310
2311	for (map<ViewClass, vector<deUint32> >::const_iterator viewClassIter = textureFormatViewClasses.begin(); viewClassIter != textureFormatViewClasses.end(); ++viewClassIter)
2312	{
2313		const vector<deUint32>&	formats		= viewClassIter->second;
2314		const ViewClass			viewClass	= viewClassIter->first;
2315		TestCaseGroup* const	viewGroup	= new TestCaseGroup(m_context, viewClassToName(viewClass), viewClassToName(viewClass));
2316
2317		nonCompressedGroup->addChild(viewGroup);
2318
2319		for (int srcFormatNdx = 0; srcFormatNdx < (int)formats.size(); srcFormatNdx++)
2320		for (int dstFormatNdx = 0; dstFormatNdx < (int)formats.size(); dstFormatNdx++)
2321		{
2322			const deUint32 srcFormat = formats[srcFormatNdx];
2323			const deUint32 dstFormat = formats[dstFormatNdx];
2324
2325			if (srcFormat != dstFormat && isFloatFormat(srcFormat) && isFloatFormat(dstFormat))
2326				continue;
2327
2328			addCopyTests(viewGroup, srcFormat, dstFormat);
2329		}
2330	}
2331
2332	for (map<ViewClass, vector<deUint32> >::const_iterator viewClassIter = compressedTextureFormatViewClasses.begin(); viewClassIter != compressedTextureFormatViewClasses.end(); ++viewClassIter)
2333	{
2334		const vector<deUint32>&	formats		= viewClassIter->second;
2335		const ViewClass			viewClass	= viewClassIter->first;
2336		TestCaseGroup* const	viewGroup	= new TestCaseGroup(m_context, viewClassToName(viewClass), viewClassToName(viewClass));
2337
2338		compressedGroup->addChild(viewGroup);
2339
2340		for (int srcFormatNdx = 0; srcFormatNdx < (int)formats.size(); srcFormatNdx++)
2341		for (int dstFormatNdx = 0; dstFormatNdx < (int)formats.size(); dstFormatNdx++)
2342		{
2343			const deUint32 srcFormat = formats[srcFormatNdx];
2344			const deUint32 dstFormat = formats[dstFormatNdx];
2345
2346			if (srcFormat != dstFormat && isFloatFormat(srcFormat) && isFloatFormat(dstFormat))
2347				continue;
2348
2349			addCopyTests(viewGroup, srcFormat, dstFormat);
2350		}
2351	}
2352
2353	for (map<ViewClass, pair<vector<deUint32>, vector<deUint32> > >::const_iterator iter = mixedViewClasses.begin(); iter != mixedViewClasses.end(); ++iter)
2354	{
2355		const ViewClass			viewClass				= iter->first;
2356		const string			viewClassName			= string(viewClassToName(viewClass)) + "_mixed";
2357		TestCaseGroup* const	viewGroup				= new TestCaseGroup(m_context, viewClassName.c_str(), viewClassName.c_str());
2358
2359		const vector<deUint32>	nonCompressedFormats	= iter->second.first;
2360		const vector<deUint32>	compressedFormats		= iter->second.second;
2361
2362		mixedGroup->addChild(viewGroup);
2363
2364		for (int srcFormatNdx = 0; srcFormatNdx < (int)nonCompressedFormats.size(); srcFormatNdx++)
2365		for (int dstFormatNdx = 0; dstFormatNdx < (int)compressedFormats.size(); dstFormatNdx++)
2366		{
2367			const deUint32 srcFormat = nonCompressedFormats[srcFormatNdx];
2368			const deUint32 dstFormat = compressedFormats[dstFormatNdx];
2369
2370			if (srcFormat != dstFormat && isFloatFormat(srcFormat) && isFloatFormat(dstFormat))
2371				continue;
2372
2373			addCopyTests(viewGroup, srcFormat, dstFormat);
2374			addCopyTests(viewGroup, dstFormat, srcFormat);
2375		}
2376	}
2377}
2378
2379} // anonymous
2380
2381TestCaseGroup* createCopyImageTests (Context& context)
2382{
2383	return new CopyImageTests(context);
2384}
2385
2386} // Functional
2387} // gles31
2388} // deqp
2389