summaryrefslogtreecommitdiff
path: root/modules/gles31/functional/es31fShaderMultisampleInterpolationTests.cpp
blob: 7b8d53ae6a0ca9f9bb0c424aaf41ccbeef22e3c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
/*-------------------------------------------------------------------------
 * drawElements Quality Program OpenGL ES 3.1 Module
 * -------------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *//*!
 * \file
 * \brief Multisample interpolation tests
 *//*--------------------------------------------------------------------*/

#include "es31fShaderMultisampleInterpolationTests.hpp"
#include "es31fMultisampleShaderRenderCase.hpp"
#include "tcuTestLog.hpp"
#include "tcuRGBA.hpp"
#include "tcuSurface.hpp"
#include "tcuRenderTarget.hpp"
#include "gluContextInfo.hpp"
#include "gluShaderProgram.hpp"
#include "gluRenderContext.hpp"
#include "glwFunctions.hpp"
#include "glwEnums.hpp"
#include "deStringUtil.hpp"
#include "deMath.h"

#include <map>

namespace deqp
{
namespace gles31
{
namespace Functional
{
namespace
{


static bool verifyGreenImage (const tcu::Surface& image, tcu::TestLog& log)
{
	bool error = false;

	log << tcu::TestLog::Message << "Verifying result image, expecting green." << tcu::TestLog::EndMessage;

	// all pixels must be green

	for (int y = 0; y < image.getHeight(); ++y)
	for (int x = 0; x < image.getWidth(); ++x)
	{
		const tcu::RGBA color			= image.getPixel(x, y);
		const int		greenThreshold	= 8;

		if (color.getRed() > 0 || color.getGreen() < 255-greenThreshold || color.getBlue() > 0)
			error = true;
	}

	if (error)
		log	<< tcu::TestLog::Image("ResultImage", "Result Image", image.getAccess())
			<< tcu::TestLog::Message
			<< "Image verification failed."
			<< tcu::TestLog::EndMessage;
	else
		log	<< tcu::TestLog::Image("ResultImage", "Result Image", image.getAccess())
			<< tcu::TestLog::Message
			<< "Image verification passed."
			<< tcu::TestLog::EndMessage;

	return !error;
}

class MultisampleShadeCountRenderCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
						MultisampleShadeCountRenderCase		(Context& context, const char* name, const char* description, int numSamples, RenderTarget target);
	virtual				~MultisampleShadeCountRenderCase	(void);

	void				init								(void);

private:
	enum
	{
		RENDER_SIZE = 128
	};

	virtual std::string	getIterationDescription				(int iteration) const;
	bool				verifyImage							(const tcu::Surface& resultImage);
};

MultisampleShadeCountRenderCase::MultisampleShadeCountRenderCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target)
	: MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE, MultisampleShaderRenderUtil::MultisampleRenderCase::FLAG_PER_ITERATION_SHADER)
{
	m_numIterations = -1; // must be set by deriving class
}

MultisampleShadeCountRenderCase::~MultisampleShadeCountRenderCase (void)
{
}

void MultisampleShadeCountRenderCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

std::string	MultisampleShadeCountRenderCase::getIterationDescription (int iteration) const
{
	// must be overriden
	DE_UNREF(iteration);
	DE_ASSERT(false);
	return "";
}

bool MultisampleShadeCountRenderCase::verifyImage (const tcu::Surface& resultImage)
{
	const bool				isSingleSampleTarget	= (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) || (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);
	const int				numShadesRequired		= (isSingleSampleTarget) ? (2) : (m_numTargetSamples + 1);
	const int				rareThreshold			= 100;
	int						rareCount				= 0;
	std::map<deUint32, int>	shadeFrequency;

	m_testCtx.getLog()
		<< tcu::TestLog::Image("ResultImage", "Result Image", resultImage.getAccess())
		<< tcu::TestLog::Message
		<< "Verifying image has (at least) " << numShadesRequired << " different shades.\n"
		<< "Excluding pixels with no full coverage (pixels on the shared edge of the triangle pair)."
		<< tcu::TestLog::EndMessage;

	for (int y = 0; y < RENDER_SIZE; ++y)
	for (int x = 0; x < RENDER_SIZE; ++x)
	{
		const tcu::RGBA	color	= resultImage.getPixel(x, y);
		const deUint32	packed	= ((deUint32)color.getRed()) + ((deUint32)color.getGreen() << 8) + ((deUint32)color.getGreen() << 16);

		// on the triangle edge, skip
		if (x == y)
			continue;

		if (shadeFrequency.find(packed) == shadeFrequency.end())
			shadeFrequency[packed] = 1;
		else
			shadeFrequency[packed] = shadeFrequency[packed] + 1;
	}

	for (std::map<deUint32, int>::const_iterator it = shadeFrequency.begin(); it != shadeFrequency.end(); ++it)
		if (it->second < rareThreshold)
			rareCount++;

	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Found " << (int)shadeFrequency.size() << " different shades.\n"
		<< "\tRare (less than " << rareThreshold << " pixels): " << rareCount << "\n"
		<< "\tCommon: " << (int)shadeFrequency.size() - rareCount << "\n"
		<< tcu::TestLog::EndMessage;

	if ((int)shadeFrequency.size() < numShadesRequired)
	{
		m_testCtx.getLog() << tcu::TestLog::Message << "Image verification failed." << tcu::TestLog::EndMessage;
		return false;
	}
	return true;
}

class SampleQualifierRenderCase : public MultisampleShadeCountRenderCase
{
public:
				SampleQualifierRenderCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target);
				~SampleQualifierRenderCase	(void);

	void		init						(void);

private:
	std::string	genVertexSource				(int numTargetSamples) const;
	std::string	genFragmentSource			(int numTargetSamples) const;
	std::string	getIterationDescription		(int iteration) const;
};

SampleQualifierRenderCase::SampleQualifierRenderCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target)
	: MultisampleShadeCountRenderCase(context, name, description, numSamples, target)
{
	m_numIterations = 6; // float, vec2, .3, .4, array, struct
}

SampleQualifierRenderCase::~SampleQualifierRenderCase (void)
{
}

void SampleQualifierRenderCase::init (void)
{
	const bool isSingleSampleTarget = (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) || (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);

	// test purpose and expectations
	if (isSingleSampleTarget)
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Verifying that a sample-qualified varying is given different values for different samples.\n"
			<< "	Render high-frequency function, map result to black/white.\n"
			<< "	=> Resulting image image should contain both black and white pixels.\n"
			<< tcu::TestLog::EndMessage;
	}
	else
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Verifying that a sample-qualified varying is given different values for different samples.\n"
			<< "	Render high-frequency function, map result to black/white.\n"
			<< "	=> Resulting image should contain n+1 shades of gray, n = sample count.\n"
			<< tcu::TestLog::EndMessage;
	}

	MultisampleShadeCountRenderCase::init();
}

std::string	SampleQualifierRenderCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"in highp vec4 a_position;\n";

	if (m_iteration == 0)
		buf << "sample out highp float v_input;\n";
	else if (m_iteration == 1)
		buf << "sample out highp vec2 v_input;\n";
	else if (m_iteration == 2)
		buf << "sample out highp vec3 v_input;\n";
	else if (m_iteration == 3)
		buf << "sample out highp vec4 v_input;\n";
	else if (m_iteration == 4)
		buf << "sample out highp float[2] v_input;\n";
	else if (m_iteration == 5)
		buf << "struct VaryingStruct { highp float a; highp float b; };\n"
			   "sample out VaryingStruct v_input;\n";
	else
		DE_ASSERT(false);

	buf <<	"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n";

	if (m_iteration == 0)
		buf << "	v_input = a_position.x + exp(a_position.y) + step(0.9, a_position.x)*step(a_position.y, -0.9)*8.0;\n";
	else if (m_iteration == 1)
		buf << "	v_input = a_position.xy;\n";
	else if (m_iteration == 2)
		buf << "	v_input = vec3(a_position.xy, a_position.x * 2.0 - a_position.y);\n";
	else if (m_iteration == 3)
		buf << "	v_input = vec4(a_position.xy, a_position.x * 2.0 - a_position.y, a_position.x*a_position.y);\n";
	else if (m_iteration == 4)
		buf << "	v_input[0] = a_position.x;\n"
			   "	v_input[1] = a_position.y;\n";
	else if (m_iteration == 5)
		buf << "	v_input.a = a_position.x;\n"
			   "	v_input.b = a_position.y;\n";
	else
		DE_ASSERT(false);

	buf <<	"}";

	return buf.str();
}

std::string	SampleQualifierRenderCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n";

	if (m_iteration == 0)
		buf << "sample in highp float v_input;\n";
	else if (m_iteration == 1)
		buf << "sample in highp vec2 v_input;\n";
	else if (m_iteration == 2)
		buf << "sample in highp vec3 v_input;\n";
	else if (m_iteration == 3)
		buf << "sample in highp vec4 v_input;\n";
	else if (m_iteration == 4)
		buf << "sample in highp float[2] v_input;\n";
	else if (m_iteration == 5)
		buf << "struct VaryingStruct { highp float a; highp float b; };\n"
			   "sample in VaryingStruct v_input;\n";
	else
		DE_ASSERT(false);

	buf <<	"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n";

	if (m_iteration == 0)
		buf << "	highp float field = exp(v_input) + v_input*v_input;\n";
	else if (m_iteration == 1)
		buf << "	highp float field = dot(v_input.xy, v_input.xy) + dot(21.0 * v_input.xx, sin(3.1 * v_input.xy));\n";
	else if (m_iteration == 2)
		buf << "	highp float field = dot(v_input.xy, v_input.xy) + dot(21.0 * v_input.zx, sin(3.1 * v_input.zy));\n";
	else if (m_iteration == 3)
		buf << "	highp float field = dot(v_input.xy, v_input.zw) + dot(21.0 * v_input.zy, sin(3.1 * v_input.zw));\n";
	else if (m_iteration == 4)
		buf << "	highp float field = dot(vec2(v_input[0], v_input[1]), vec2(v_input[0], v_input[1])) + dot(21.0 * vec2(v_input[0]), sin(3.1 * vec2(v_input[0], v_input[1])));\n";
	else if (m_iteration == 5)
		buf << "	highp float field = dot(vec2(v_input.a, v_input.b), vec2(v_input.a, v_input.b)) + dot(21.0 * vec2(v_input.a), sin(3.1 * vec2(v_input.a, v_input.b)));\n";
	else
		DE_ASSERT(false);

	buf <<	"	fragColor = vec4(1.0, 1.0, 1.0, 1.0);\n"
			"\n"
			"	if (fract(field) > 0.5)\n"
			"		fragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
			"}";

	return buf.str();
}

std::string	SampleQualifierRenderCase::getIterationDescription (int iteration) const
{
	if (iteration == 0)
		return "Test with float varying";
	else if (iteration == 1)
		return "Test with vec2 varying";
	else if (iteration == 2)
		return "Test with vec3 varying";
	else if (iteration == 3)
		return "Test with vec4 varying";
	else if (iteration == 4)
		return "Test with array varying";
	else if (iteration == 5)
		return "Test with struct varying";

	DE_ASSERT(false);
	return "";
}

class InterpolateAtSampleRenderCase : public MultisampleShadeCountRenderCase
{
public:
	enum IndexingMode
	{
		INDEXING_STATIC,
		INDEXING_DYNAMIC,

		INDEXING_LAST
	};
						InterpolateAtSampleRenderCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target, IndexingMode mode);
						~InterpolateAtSampleRenderCase	(void);

	void				init							(void);
	void				preDraw							(void);

private:
	std::string			genVertexSource					(int numTargetSamples) const;
	std::string			genFragmentSource				(int numTargetSamples) const;
	std::string			getIterationDescription			(int iteration) const;

	const IndexingMode	m_indexMode;
};

InterpolateAtSampleRenderCase::InterpolateAtSampleRenderCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target, IndexingMode mode)
	: MultisampleShadeCountRenderCase	(context, name, description, numSamples, target)
	, m_indexMode						(mode)
{
	DE_ASSERT(mode < INDEXING_LAST);

	m_numIterations = 5; // float, vec2, .3, .4, array
}

InterpolateAtSampleRenderCase::~InterpolateAtSampleRenderCase (void)
{
}

void InterpolateAtSampleRenderCase::init (void)
{
	const bool isSingleSampleTarget = (m_renderTarget != TARGET_DEFAULT && m_numRequestedSamples == 0) || (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() <= 1);

	// test purpose and expectations
	if (isSingleSampleTarget)
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Verifying that a interpolateAtSample returns different values for different samples.\n"
			<< "	Render high-frequency function, map result to black/white.\n"
			<< "	=> Resulting image image should contain both black and white pixels.\n"
			<< tcu::TestLog::EndMessage;
	}
	else
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Verifying that a interpolateAtSample returns different values for different samples.\n"
			<< "	Render high-frequency function, map result to black/white.\n"
			<< "	=> Resulting image should contain n+1 shades of gray, n = sample count.\n"
			<< tcu::TestLog::EndMessage;
	}

	MultisampleShadeCountRenderCase::init();
}

void InterpolateAtSampleRenderCase::preDraw (void)
{
	if (m_indexMode == INDEXING_DYNAMIC)
	{
		const deInt32			range		= m_numTargetSamples;
		const deInt32			offset		= 1;
		const glw::Functions&	gl			= m_context.getRenderContext().getFunctions();
		const deInt32			offsetLoc	= gl.getUniformLocation(m_program->getProgram(), "u_offset");
		const deInt32			rangeLoc	= gl.getUniformLocation(m_program->getProgram(), "u_range");

		if (offsetLoc == -1)
			throw tcu::TestError("Location of u_offset was -1");
		if (rangeLoc == -1)
			throw tcu::TestError("Location of u_range was -1");

		gl.uniform1i(offsetLoc, 0);
		gl.uniform1i(rangeLoc, m_numTargetSamples);
		GLU_EXPECT_NO_ERROR(gl.getError(), "set uniforms");

		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Set u_offset = " << offset << "\n"
			<< "Set u_range = " << range
			<< tcu::TestLog::EndMessage;
	}
}

std::string InterpolateAtSampleRenderCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"in highp vec4 a_position;\n";

	if (m_iteration == 0)
		buf << "out highp float v_input;\n";
	else if (m_iteration == 1)
		buf << "out highp vec2 v_input;\n";
	else if (m_iteration == 2)
		buf << "out highp vec3 v_input;\n";
	else if (m_iteration == 3)
		buf << "out highp vec4 v_input;\n";
	else if (m_iteration == 4)
		buf << "out highp vec2[2] v_input;\n";
	else
		DE_ASSERT(false);

	buf <<	"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n";

	if (m_iteration == 0)
		buf << "	v_input = a_position.x + exp(a_position.y) + step(0.9, a_position.x)*step(a_position.y, -0.9)*8.0;\n";
	else if (m_iteration == 1)
		buf << "	v_input = a_position.xy;\n";
	else if (m_iteration == 2)
		buf << "	v_input = vec3(a_position.xy, a_position.x * 2.0 - a_position.y);\n";
	else if (m_iteration == 3)
		buf << "	v_input = vec4(a_position.xy, a_position.x * 2.0 - a_position.y, a_position.x*a_position.y);\n";
	else if (m_iteration == 4)
		buf << "	v_input[0] = a_position.yx + vec2(0.5, 0.5);\n"
			   "	v_input[1] = a_position.xy;\n";
	else
		DE_ASSERT(false);

	buf <<	"}";

	return buf.str();
}

std::string InterpolateAtSampleRenderCase::genFragmentSource (int numTargetSamples) const
{
	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n";

	if (m_iteration == 0)
		buf << "in highp float v_input;\n";
	else if (m_iteration == 1)
		buf << "in highp vec2 v_input;\n";
	else if (m_iteration == 2)
		buf << "in highp vec3 v_input;\n";
	else if (m_iteration == 3)
		buf << "in highp vec4 v_input;\n";
	else if (m_iteration == 4)
		buf << "in highp vec2[2] v_input;\n";
	else
		DE_ASSERT(false);

	buf << "layout(location = 0) out mediump vec4 fragColor;\n";

	if (m_indexMode == INDEXING_DYNAMIC)
		buf <<	"uniform highp int u_offset;\n"
				"uniform highp int u_range;\n";

	buf <<	"void main (void)\n"
			"{\n"
			"	mediump int coverage = 0;\n"
			"\n";

	if (m_indexMode == INDEXING_STATIC)
	{
		for (int ndx = 0; ndx < numTargetSamples; ++ndx)
		{
			if (m_iteration == 0)
				buf <<	"	highp float sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
			else if (m_iteration == 1)
				buf <<	"	highp vec2 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
			else if (m_iteration == 2)
				buf <<	"	highp vec3 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
			else if (m_iteration == 3)
				buf <<	"	highp vec4 sampleInput" << ndx << " = interpolateAtSample(v_input, " << ndx << ");\n";
			else if (m_iteration == 4)
				buf <<	"	highp vec2 sampleInput" << ndx << " = interpolateAtSample(v_input[1], " << ndx << ");\n";
			else
				DE_ASSERT(false);
		}
		buf <<	"\n";

		for (int ndx = 0; ndx < numTargetSamples; ++ndx)
		{
			if (m_iteration == 0)
				buf << "	highp float field" << ndx << " = exp(sampleInput" << ndx << ") + sampleInput" << ndx << "*sampleInput" << ndx << ";\n";
			else if (m_iteration == 1 || m_iteration == 4)
				buf << "	highp float field" << ndx << " = dot(sampleInput" << ndx << ", sampleInput" << ndx << ") + dot(21.0 * sampleInput" << ndx << ".xx, sin(3.1 * sampleInput" << ndx << "));\n";
			else if (m_iteration == 2)
				buf << "	highp float field" << ndx << " = dot(sampleInput" << ndx << ".xy, sampleInput" << ndx << ".xy) + dot(21.0 * sampleInput" << ndx << ".zx, sin(3.1 * sampleInput" << ndx << ".zy));\n";
			else if (m_iteration == 3)
				buf << "	highp float field" << ndx << " = dot(sampleInput" << ndx << ".xy, sampleInput" << ndx << ".zw) + dot(21.0 * sampleInput" << ndx << ".zy, sin(3.1 * sampleInput" << ndx << ".zw));\n";
			else
				DE_ASSERT(false);
		}
		buf <<	"\n";

		for (int ndx = 0; ndx < numTargetSamples; ++ndx)
			buf <<	"	if (fract(field" << ndx << ") <= 0.5)\n"
					"		++coverage;\n";
	}
	else if (m_indexMode == INDEXING_DYNAMIC)
	{
		buf <<	"	for (int ndx = 0; ndx < " << numTargetSamples << "; ++ndx)\n"
				"	{\n";

		if (m_iteration == 0)
			buf <<	"		highp float sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
		else if (m_iteration == 1)
			buf <<	"		highp vec2 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
		else if (m_iteration == 2)
			buf <<	"		highp vec3 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
		else if (m_iteration == 3)
			buf <<	"		highp vec4 sampleInput = interpolateAtSample(v_input, (u_offset + ndx) % u_range);\n";
		else if (m_iteration == 4)
			buf <<	"		highp vec2 sampleInput = interpolateAtSample(v_input[1], (u_offset + ndx) % u_range);\n";
		else
			DE_ASSERT(false);

		if (m_iteration == 0)
			buf << "		highp float field = exp(sampleInput) + sampleInput*sampleInput;\n";
		else if (m_iteration == 1 || m_iteration == 4)
			buf << "		highp float field = dot(sampleInput, sampleInput) + dot(21.0 * sampleInput.xx, sin(3.1 * sampleInput));\n";
		else if (m_iteration == 2)
			buf << "		highp float field = dot(sampleInput.xy, sampleInput.xy) + dot(21.0 * sampleInput.zx, sin(3.1 * sampleInput.zy));\n";
		else if (m_iteration == 3)
			buf << "		highp float field = dot(sampleInput.xy, sampleInput.zw) + dot(21.0 * sampleInput.zy, sin(3.1 * sampleInput.zw));\n";
		else
			DE_ASSERT(false);

		buf <<	"		if (fract(field) <= 0.5)\n"
				"			++coverage;\n"
				"	}\n";
	}

	buf <<	"	fragColor = vec4(vec3(float(coverage) / float(" << numTargetSamples << ")), 1.0);\n"
			"}";

	return buf.str();
}

std::string InterpolateAtSampleRenderCase::getIterationDescription (int iteration) const
{
	if (iteration == 0)
		return "Test with float varying";
	else if (iteration < 4)
		return "Test with vec" + de::toString(iteration+1) + " varying";
	else if (iteration == 4)
		return "Test with array varying";

	DE_ASSERT(false);
	return "";
}

class SingleSampleInterpolateAtSampleCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
	enum SampleCase
	{
		SAMPLE_0 = 0,
		SAMPLE_N,

		SAMPLE_LAST
	};

						SingleSampleInterpolateAtSampleCase		(Context& context, const char* name, const char* description, int numSamples, RenderTarget target, SampleCase sampleCase);
	virtual				~SingleSampleInterpolateAtSampleCase	(void);

	void				init									(void);

private:
	enum
	{
		RENDER_SIZE = 32
	};

	std::string			genVertexSource							(int numTargetSamples) const;
	std::string			genFragmentSource						(int numTargetSamples) const;
	bool				verifyImage								(const tcu::Surface& resultImage);

	const SampleCase	m_sampleCase;
};

SingleSampleInterpolateAtSampleCase::SingleSampleInterpolateAtSampleCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target, SampleCase sampleCase)
	: MultisampleShaderRenderUtil::MultisampleRenderCase	(context, name, description, numSamples, target, RENDER_SIZE)
	, m_sampleCase											(sampleCase)
{
	DE_ASSERT(numSamples == 0);
	DE_ASSERT(sampleCase < SAMPLE_LAST);
}

SingleSampleInterpolateAtSampleCase::~SingleSampleInterpolateAtSampleCase (void)
{
}

void SingleSampleInterpolateAtSampleCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");
	if (m_renderTarget == TARGET_DEFAULT && m_context.getRenderTarget().getNumSamples() > 1)
		throw tcu::NotSupportedError("Non-multisample framebuffer required");

	// test purpose and expectations
	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Verifying that using interpolateAtSample with multisample buffers not available returns sample evaluated at the center of the pixel.\n"
		<< "	Interpolate varying containing screen space location.\n"
		<< "	=> fract(screen space location) should be (about) (0.5, 0.5)\n"
		<< tcu::TestLog::EndMessage;

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

std::string SingleSampleInterpolateAtSampleCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"in highp vec4 a_position;\n"
			"out highp vec2 v_position;\n"
			"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n"
			"	v_position = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << RENDER_SIZE << ".0, " << RENDER_SIZE << ".0);\n"
			"}\n";

	return buf.str();
}

std::string SingleSampleInterpolateAtSampleCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"in highp vec2 v_position;\n"
			"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n"
			"	const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other errors\n"; // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)

	if (m_sampleCase == SAMPLE_0)
	{
		buf <<	"	highp vec2 samplePosition = interpolateAtSample(v_position, 0);\n"
				"	highp vec2 positionInsideAPixel = fract(samplePosition);\n"
				"\n"
				"	if (abs(positionInsideAPixel.x - 0.5) <= threshold && abs(positionInsideAPixel.y - 0.5) <= threshold)\n"
				"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
				"	else\n"
				"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
				"}\n";
	}
	else if (m_sampleCase == SAMPLE_N)
	{
		buf <<	"	bool allOk = true;\n"
				"	for (int sampleNdx = 159; sampleNdx < 163; ++sampleNdx)\n"
				"	{\n"
				"		highp vec2 samplePosition = interpolateAtSample(v_position, sampleNdx);\n"
				"		highp vec2 positionInsideAPixel = fract(samplePosition);\n"
				"		if (abs(positionInsideAPixel.x - 0.5) > threshold || abs(positionInsideAPixel.y - 0.5) > threshold)\n"
				"			allOk = false;\n"
				"	}\n"
				"\n"
				"	if (allOk)\n"
				"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
				"	else\n"
				"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
				"}\n";
	}
	else
		DE_ASSERT(false);

	return buf.str();
}

bool SingleSampleInterpolateAtSampleCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

class CentroidRenderCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
									CentroidRenderCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target, int renderSize);
	virtual							~CentroidRenderCase	(void);

	void							init				(void);

private:
	void							setupRenderData		(void);
};

CentroidRenderCase::CentroidRenderCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target, int renderSize)
	: MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, renderSize)
{
}

CentroidRenderCase::~CentroidRenderCase (void)
{
}

void CentroidRenderCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

void CentroidRenderCase::setupRenderData (void)
{
	const int				numTriangles	= 200;
	const glw::Functions&	gl				= m_context.getRenderContext().getFunctions();
	std::vector<tcu::Vec4>	data			(numTriangles * 3 * 3);

	m_renderMode = GL_TRIANGLES;
	m_renderCount = numTriangles * 3;
	m_renderSceneDescription = "triangle fan of narrow triangles";

	m_renderAttribs["a_position"].offset = 0;
	m_renderAttribs["a_position"].stride = sizeof(float[4]) * 3;
	m_renderAttribs["a_barycentricsA"].offset = sizeof(float[4]);
	m_renderAttribs["a_barycentricsA"].stride = sizeof(float[4]) * 3;
	m_renderAttribs["a_barycentricsB"].offset = sizeof(float[4]) * 2;
	m_renderAttribs["a_barycentricsB"].stride = sizeof(float[4]) * 3;

	for (int triangleNdx = 0; triangleNdx < numTriangles; ++triangleNdx)
	{
		const float angle		= ((float)triangleNdx) / numTriangles * 2.0f * DE_PI;
		const float nextAngle	= ((float)triangleNdx + 1.0f) / numTriangles * 2.0f * DE_PI;

		data[(triangleNdx * 3 + 0) * 3 + 0] = tcu::Vec4(0.2f, -0.3f, 0.0f, 1.0f);
		data[(triangleNdx * 3 + 0) * 3 + 1] = tcu::Vec4(1.0f,  0.0f, 0.0f, 0.0f);
		data[(triangleNdx * 3 + 0) * 3 + 2] = tcu::Vec4(1.0f,  0.0f, 0.0f, 0.0f);

		data[(triangleNdx * 3 + 1) * 3 + 0] = tcu::Vec4(2.0f * cos(angle), 2.0f * sin(angle), 0.0f, 1.0f);
		data[(triangleNdx * 3 + 1) * 3 + 1] = tcu::Vec4(0.0f,  1.0f, 0.0f, 0.0f);
		data[(triangleNdx * 3 + 1) * 3 + 2] = tcu::Vec4(0.0f,  1.0f, 0.0f, 0.0f);

		data[(triangleNdx * 3 + 2) * 3 + 0] = tcu::Vec4(2.0f * cos(nextAngle), 2.0f * sin(nextAngle), 0.0f, 1.0f);
		data[(triangleNdx * 3 + 2) * 3 + 1] = tcu::Vec4(0.0f,  0.0f, 1.0f, 0.0f);
		data[(triangleNdx * 3 + 2) * 3 + 2] = tcu::Vec4(0.0f,  0.0f, 1.0f, 0.0f);
	}

	gl.bindBuffer(GL_ARRAY_BUFFER, m_buffer);
	gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(data.size() * sizeof(tcu::Vec4)), data[0].getPtr(), GL_STATIC_DRAW);
}

class CentroidQualifierAtSampleCase : public CentroidRenderCase
{
public:
									CentroidQualifierAtSampleCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target);
	virtual							~CentroidQualifierAtSampleCase	(void);

	void							init						(void);

private:
	enum
	{
		RENDER_SIZE = 128
	};

	std::string						genVertexSource				(int numTargetSamples) const;
	std::string						genFragmentSource			(int numTargetSamples) const;
	bool							verifyImage					(const tcu::Surface& resultImage);
};

CentroidQualifierAtSampleCase::CentroidQualifierAtSampleCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target)
	: CentroidRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
{
}

CentroidQualifierAtSampleCase::~CentroidQualifierAtSampleCase (void)
{
}

void CentroidQualifierAtSampleCase::init (void)
{
	// test purpose and expectations
	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Verifying that interpolateAtSample ignores the centroid-qualifier.\n"
		<< "	Draw a fan of narrow triangles (large number of pixels on the edges).\n"
		<< "	Set varyings 'barycentricsA' and 'barycentricsB' to contain barycentric coordinates.\n"
		<< "	Add centroid-qualifier for barycentricsB.\n"
		<< "	=> interpolateAtSample(barycentricsB, N) ~= interpolateAtSample(barycentricsA, N)\n"
		<< tcu::TestLog::EndMessage;

	CentroidRenderCase::init();
}

std::string CentroidQualifierAtSampleCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	return	"#version 310 es\n"
			"in highp vec4 a_position;\n"
			"in highp vec4 a_barycentricsA;\n"
			"in highp vec4 a_barycentricsB;\n"
			"out highp vec3 v_barycentricsA;\n"
			"centroid out highp vec3 v_barycentricsB;\n"
			"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n"
			"	v_barycentricsA = a_barycentricsA.xyz;\n"
			"	v_barycentricsB = a_barycentricsB.xyz;\n"
			"}\n";
}

std::string CentroidQualifierAtSampleCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"in highp vec3 v_barycentricsA;\n"
			"centroid in highp vec3 v_barycentricsB;\n"
			"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n"
			"	const highp float threshold = 0.0005;\n"
			"	bool allOk = true;\n"
			"\n"
			"	for (int sampleNdx = 0; sampleNdx < " << numTargetSamples << "; ++sampleNdx)\n"
			"	{\n"
			"		highp vec3 sampleA = interpolateAtSample(v_barycentricsA, sampleNdx);\n"
			"		highp vec3 sampleB = interpolateAtSample(v_barycentricsB, sampleNdx);\n"
			"		bool valuesEqual = all(lessThan(abs(sampleA - sampleB), vec3(threshold)));\n"
			"		if (!valuesEqual)\n"
			"			allOk = false;\n"
			"	}\n"
			"\n"
			"	if (allOk)\n"
			"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
			"	else\n"
			"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
			"}\n";

	return buf.str();
}

bool CentroidQualifierAtSampleCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

class InterpolateAtSampleIDCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
						InterpolateAtSampleIDCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target);
	virtual				~InterpolateAtSampleIDCase	(void);

	void				init						(void);
private:
	enum
	{
		RENDER_SIZE = 32
	};

	std::string			genVertexSource				(int numTargetSamples) const;
	std::string			genFragmentSource			(int numTargetSamples) const;
	bool				verifyImage					(const tcu::Surface& resultImage);
};

InterpolateAtSampleIDCase::InterpolateAtSampleIDCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target)
	: MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
{
}

InterpolateAtSampleIDCase::~InterpolateAtSampleIDCase (void)
{
}

void InterpolateAtSampleIDCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_sample_variables"))
		throw tcu::NotSupportedError("Test requires GL_OES_sample_variables extension");

	// test purpose and expectations
	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Verifying that interpolateAtSample with the sample set to the current sampleID returns consistent values.\n"
		<< "	Interpolate varying containing screen space location.\n"
		<< "	=> interpolateAtSample(varying, sampleID) = varying"
		<< tcu::TestLog::EndMessage;

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

std::string InterpolateAtSampleIDCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"in highp vec4 a_position;\n"
			"sample out highp vec2 v_screenPosition;\n"
			"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n"
			"	v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << RENDER_SIZE << ".0, " << RENDER_SIZE << ".0);\n"
			"}\n";

	return buf.str();
}

std::string InterpolateAtSampleIDCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	return	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"sample in highp vec2 v_screenPosition;\n"
			"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n"
			"	const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
			"\n"
			"	highp vec2 offsetValue = interpolateAtSample(v_screenPosition, gl_SampleID);\n"
			"	highp vec2 refValue = v_screenPosition;\n"
			"\n"
			"	bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
			"	if (valuesEqual)\n"
			"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
			"	else\n"
			"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
			"}\n";
}

bool InterpolateAtSampleIDCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

class InterpolateAtCentroidCase : public CentroidRenderCase
{
public:
	enum TestType
	{
		TEST_CONSISTENCY = 0,
		TEST_ARRAY_ELEMENT,

		TEST_LAST
	};

									InterpolateAtCentroidCase	(Context& context, const char* name, const char* description, int numSamples, RenderTarget target, TestType type);
	virtual							~InterpolateAtCentroidCase	(void);

	void							init						(void);

private:
	enum
	{
		RENDER_SIZE = 128
	};

	std::string						genVertexSource				(int numTargetSamples) const;
	std::string						genFragmentSource			(int numTargetSamples) const;
	bool							verifyImage					(const tcu::Surface& resultImage);

	const TestType					m_type;
};

InterpolateAtCentroidCase::InterpolateAtCentroidCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target, TestType type)
	: CentroidRenderCase	(context, name, description, numSamples, target, RENDER_SIZE)
	, m_type				(type)
{
}

InterpolateAtCentroidCase::~InterpolateAtCentroidCase (void)
{
}

void InterpolateAtCentroidCase::init (void)
{
	// test purpose and expectations
	if (m_type == TEST_CONSISTENCY)
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Verifying that interpolateAtCentroid does not return different values than a corresponding centroid-qualified varying.\n"
			<< "	Draw a fan of narrow triangles (large number of pixels on the edges).\n"
			<< "	Set varyings 'barycentricsA' and 'barycentricsB' to contain barycentric coordinates.\n"
			<< "	Add centroid-qualifier for barycentricsB.\n"
			<< "	=> interpolateAtCentroid(barycentricsA) ~= barycentricsB\n"
			<< tcu::TestLog::EndMessage;
	}
	else if (m_type == TEST_ARRAY_ELEMENT)
	{
		m_testCtx.getLog()
			<< tcu::TestLog::Message
			<< "Testing interpolateAtCentroid with element of array as an argument."
			<< tcu::TestLog::EndMessage;
	}
	else
		DE_ASSERT(false);

	CentroidRenderCase::init();
}

std::string InterpolateAtCentroidCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	if (m_type == TEST_CONSISTENCY)
		return	"#version 310 es\n"
				"in highp vec4 a_position;\n"
				"in highp vec4 a_barycentricsA;\n"
				"in highp vec4 a_barycentricsB;\n"
				"out highp vec3 v_barycentricsA;\n"
				"centroid out highp vec3 v_barycentricsB;\n"
				"void main (void)\n"
				"{\n"
				"	gl_Position = a_position;\n"
				"	v_barycentricsA = a_barycentricsA.xyz;\n"
				"	v_barycentricsB = a_barycentricsB.xyz;\n"
				"}\n";
	else if (m_type == TEST_ARRAY_ELEMENT)
		return	"#version 310 es\n"
				"in highp vec4 a_position;\n"
				"in highp vec4 a_barycentricsA;\n"
				"in highp vec4 a_barycentricsB;\n"
				"out highp vec3[2] v_barycentrics;\n"
				"void main (void)\n"
				"{\n"
				"	gl_Position = a_position;\n"
				"	v_barycentrics[0] = a_barycentricsA.xyz;\n"
				"	v_barycentrics[1] = a_barycentricsB.xyz;\n"
				"}\n";

	DE_ASSERT(false);
	return "";
}

std::string InterpolateAtCentroidCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	if (m_type == TEST_CONSISTENCY)
		return	"#version 310 es\n"
				"#extension GL_OES_shader_multisample_interpolation : require\n"
				"in highp vec3 v_barycentricsA;\n"
				"centroid in highp vec3 v_barycentricsB;\n"
				"layout(location = 0) out highp vec4 fragColor;\n"
				"void main (void)\n"
				"{\n"
				"	const highp float threshold = 0.0005;\n"
				"\n"
				"	highp vec3 centroidASampled = interpolateAtCentroid(v_barycentricsA);\n"
				"	bool valuesEqual = all(lessThan(abs(centroidASampled - v_barycentricsB), vec3(threshold)));\n"
				"	bool centroidAIsInvalid = any(greaterThan(centroidASampled, vec3(1.0))) ||\n"
				"	                          any(lessThan(centroidASampled, vec3(0.0)));\n"
				"	bool centroidBIsInvalid = any(greaterThan(v_barycentricsB, vec3(1.0))) ||\n"
				"	                          any(lessThan(v_barycentricsB, vec3(0.0)));\n"
				"\n"
				"	if (valuesEqual && !centroidAIsInvalid && !centroidBIsInvalid)\n"
				"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
				"	else if (centroidAIsInvalid || centroidBIsInvalid)\n"
				"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
				"	else\n"
				"		fragColor = vec4(1.0, 1.0, 0.0, 1.0);\n"
				"}\n";
	else if (m_type == TEST_ARRAY_ELEMENT)
		return	"#version 310 es\n"
				"#extension GL_OES_shader_multisample_interpolation : require\n"
				"in highp vec3[2] v_barycentrics;\n"
				"layout(location = 0) out mediump vec4 fragColor;\n"
				"void main (void)\n"
				"{\n"
				"	const highp float threshold = 0.0005;\n"
				"\n"
				"	highp vec3 centroidInterpolated = interpolateAtCentroid(v_barycentrics[1]);\n"
				"	bool centroidIsInvalid = any(greaterThan(centroidInterpolated, vec3(1.0))) ||\n"
				"	                         any(lessThan(centroidInterpolated, vec3(0.0)));\n"
				"\n"
				"	if (!centroidIsInvalid)\n"
				"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
				"	else\n"
				"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
				"}\n";

	DE_ASSERT(false);
	return "";
}

bool InterpolateAtCentroidCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

class InterpolateAtOffsetCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
	enum TestType
	{
		TEST_QUALIFIER_NONE = 0,
		TEST_QUALIFIER_CENTROID,
		TEST_QUALIFIER_SAMPLE,
		TEST_ARRAY_ELEMENT,

		TEST_LAST
	};
						InterpolateAtOffsetCase		(Context& context, const char* name, const char* description, int numSamples, RenderTarget target, TestType testType);
	virtual				~InterpolateAtOffsetCase	(void);

	void				init						(void);
private:
	enum
	{
		RENDER_SIZE = 32
	};

	std::string			genVertexSource				(int numTargetSamples) const;
	std::string			genFragmentSource			(int numTargetSamples) const;
	bool				verifyImage					(const tcu::Surface& resultImage);

	const TestType		m_testType;
};

InterpolateAtOffsetCase::InterpolateAtOffsetCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target, TestType testType)
	: MultisampleShaderRenderUtil::MultisampleRenderCase	(context, name, description, numSamples, target, RENDER_SIZE)
	, m_testType											(testType)
{
	DE_ASSERT(testType < TEST_LAST);
}

InterpolateAtOffsetCase::~InterpolateAtOffsetCase (void)
{
}

void InterpolateAtOffsetCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");

	// test purpose and expectations
	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Verifying that interpolateAtOffset returns correct values.\n"
		<< "	Interpolate varying containing screen space location.\n"
		<< "	=> interpolateAtOffset(varying, offset) should be \"varying value at the pixel center\" + offset"
		<< tcu::TestLog::EndMessage;

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

std::string InterpolateAtOffsetCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;
	buf << "#version 310 es\n"
		<< "#extension GL_OES_shader_multisample_interpolation : require\n"
		<< "in highp vec4 a_position;\n";

	if (m_testType == TEST_QUALIFIER_NONE || m_testType == TEST_QUALIFIER_CENTROID || m_testType == TEST_QUALIFIER_SAMPLE)
	{
		const char* const qualifier = (m_testType == TEST_QUALIFIER_CENTROID) ? ("centroid ") : (m_testType == TEST_QUALIFIER_SAMPLE) ? ("sample ") : ("");
		buf << qualifier << "out highp vec2 v_screenPosition;\n"
			<< qualifier << "out highp vec2 v_offset;\n";
	}
	else if (m_testType == TEST_ARRAY_ELEMENT)
	{
		buf << "out highp vec2[2] v_screenPosition;\n"
			<< "out highp vec2 v_offset;\n";
	}
	else
		DE_ASSERT(false);

	buf	<< "void main (void)\n"
		<< "{\n"
		<< "	gl_Position = a_position;\n";

	if (m_testType != TEST_ARRAY_ELEMENT)
		buf	<< "	v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << RENDER_SIZE << ".0, " << RENDER_SIZE << ".0);\n";
	else
		buf	<< "	v_screenPosition[0] = a_position.xy; // not used\n"
				"	v_screenPosition[1] = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << RENDER_SIZE << ".0, " << RENDER_SIZE << ".0);\n";

	buf	<< "	v_offset = a_position.xy * 0.5f;\n"
		<< "}\n";

	return buf.str();
}

std::string InterpolateAtOffsetCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	const char* const	arrayIndexing = (m_testType == TEST_ARRAY_ELEMENT) ? ("[1]") : ("");
	std::ostringstream	buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n";

	if (m_testType == TEST_QUALIFIER_NONE || m_testType == TEST_QUALIFIER_CENTROID || m_testType == TEST_QUALIFIER_SAMPLE)
	{
		const char* const qualifier = (m_testType == TEST_QUALIFIER_CENTROID) ? ("centroid ") : (m_testType == TEST_QUALIFIER_SAMPLE) ? ("sample ") : ("");
		buf	<< qualifier << "in highp vec2 v_screenPosition;\n"
			<< qualifier << "in highp vec2 v_offset;\n";
	}
	else if (m_testType == TEST_ARRAY_ELEMENT)
	{
		buf << "in highp vec2[2] v_screenPosition;\n"
			<< "in highp vec2 v_offset;\n";
	}
	else
		DE_ASSERT(false);

	buf	<<	"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n"
			"	const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
			"\n"
			"	highp vec2 pixelCenter = floor(v_screenPosition" << arrayIndexing << ") + vec2(0.5, 0.5);\n"
			"	highp vec2 offsetValue = interpolateAtOffset(v_screenPosition" << arrayIndexing << ", v_offset);\n"
			"	highp vec2 refValue = pixelCenter + v_offset;\n"
			"\n"
			"	bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
			"	if (valuesEqual)\n"
			"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
			"	else\n"
			"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
			"}\n";

	return buf.str();
}

bool InterpolateAtOffsetCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

class InterpolateAtSamplePositionCase : public MultisampleShaderRenderUtil::MultisampleRenderCase
{
public:
						InterpolateAtSamplePositionCase		(Context& context, const char* name, const char* description, int numSamples, RenderTarget target);
	virtual				~InterpolateAtSamplePositionCase	(void);

	void				init								(void);
private:
	enum
	{
		RENDER_SIZE = 32
	};

	std::string			genVertexSource						(int numTargetSamples) const;
	std::string			genFragmentSource					(int numTargetSamples) const;
	bool				verifyImage							(const tcu::Surface& resultImage);
};

InterpolateAtSamplePositionCase::InterpolateAtSamplePositionCase (Context& context, const char* name, const char* description, int numSamples, RenderTarget target)
	: MultisampleShaderRenderUtil::MultisampleRenderCase(context, name, description, numSamples, target, RENDER_SIZE)
{
}

InterpolateAtSamplePositionCase::~InterpolateAtSamplePositionCase (void)
{
}

void InterpolateAtSamplePositionCase::init (void)
{
	// requirements
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_shader_multisample_interpolation"))
		throw tcu::NotSupportedError("Test requires GL_OES_shader_multisample_interpolation extension");
	if (!m_context.getContextInfo().isExtensionSupported("GL_OES_sample_variables"))
		throw tcu::NotSupportedError("Test requires GL_OES_sample_variables extension");

	// test purpose and expectations
	m_testCtx.getLog()
		<< tcu::TestLog::Message
		<< "Verifying that interpolateAtOffset with the offset of current sample position returns consistent values.\n"
		<< "	Interpolate varying containing screen space location.\n"
		<< "	=> interpolateAtOffset(varying, currentOffset) = varying"
		<< tcu::TestLog::EndMessage;

	MultisampleShaderRenderUtil::MultisampleRenderCase::init();
}

std::string InterpolateAtSamplePositionCase::genVertexSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	std::ostringstream buf;

	buf <<	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"in highp vec4 a_position;\n"
			"sample out highp vec2 v_screenPosition;\n"
			"void main (void)\n"
			"{\n"
			"	gl_Position = a_position;\n"
			"	v_screenPosition = (a_position.xy + vec2(1.0, 1.0)) / 2.0 * vec2(" << RENDER_SIZE << ".0, " << RENDER_SIZE << ".0);\n"
			"}\n";

	return buf.str();
}

std::string InterpolateAtSamplePositionCase::genFragmentSource (int numTargetSamples) const
{
	DE_UNREF(numTargetSamples);

	return	"#version 310 es\n"
			"#extension GL_OES_shader_multisample_interpolation : require\n"
			"sample in highp vec2 v_screenPosition;\n"
			"layout(location = 0) out mediump vec4 fragColor;\n"
			"void main (void)\n"
			"{\n"
			"	const highp float threshold = 0.15625; // 4 subpixel bits. Assume 3 accurate bits + 0.03125 for other errors\n" // 0.03125 = mediump epsilon when value = 32 (RENDER_SIZE)
			"\n"
			"	highp vec2 offset = gl_SamplePosition - vec2(0.5, 0.5);\n"
			"	highp vec2 offsetValue = interpolateAtOffset(v_screenPosition, offset);\n"
			"	highp vec2 refValue = v_screenPosition;\n"
			"\n"
			"	bool valuesEqual = all(lessThan(abs(offsetValue - refValue), vec2(threshold)));\n"
			"	if (valuesEqual)\n"
			"		fragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
			"	else\n"
			"		fragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
			"}\n";
}

bool InterpolateAtSamplePositionCase::verifyImage (const tcu::Surface& resultImage)
{
	return verifyGreenImage(resultImage, m_testCtx.getLog());
}

} // anonymous

ShaderMultisampleInterpolationTests::ShaderMultisampleInterpolationTests (Context& context)
	: TestCaseGroup(context, "multisample_interpolation", "Test multisample interpolation")
{
}

ShaderMultisampleInterpolationTests::~ShaderMultisampleInterpolationTests (void)
{
}

void ShaderMultisampleInterpolationTests::init (void)
{
	using namespace MultisampleShaderRenderUtil;

	static const struct RenderTarget
	{
		const char*							name;
		const char*							desc;
		int									numSamples;
		MultisampleRenderCase::RenderTarget	target;
	} targets[] =
	{
		{ "default_framebuffer",		"Test with default framebuffer",	0,	MultisampleRenderCase::TARGET_DEFAULT		},
		{ "singlesample_texture",		"Test with singlesample texture",	0,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "multisample_texture_1",		"Test with multisample texture",	1,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "multisample_texture_2",		"Test with multisample texture",	2,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "multisample_texture_4",		"Test with multisample texture",	4,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "multisample_texture_8",		"Test with multisample texture",	8,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "multisample_texture_16",		"Test with multisample texture",	16,	MultisampleRenderCase::TARGET_TEXTURE		},
		{ "singlesample_rbo",			"Test with singlesample rbo",		0,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
		{ "multisample_rbo_1",			"Test with multisample rbo",		1,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
		{ "multisample_rbo_2",			"Test with multisample rbo",		2,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
		{ "multisample_rbo_4",			"Test with multisample rbo",		4,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
		{ "multisample_rbo_8",			"Test with multisample rbo",		8,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
		{ "multisample_rbo_16",			"Test with multisample rbo",		16,	MultisampleRenderCase::TARGET_RENDERBUFFER	},
	};

	// .sample_qualifier
	{
		tcu::TestCaseGroup* const sampleQualifierGroup = new tcu::TestCaseGroup(m_testCtx, "sample_qualifier", "Test sample qualifier");
		addChild(sampleQualifierGroup);

		for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
			sampleQualifierGroup->addChild(new SampleQualifierRenderCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target));
	}

	// .interpolate_at_sample
	{
		tcu::TestCaseGroup* const interpolateAtSampleGroup = new tcu::TestCaseGroup(m_testCtx, "interpolate_at_sample", "Test interpolateAtSample");
		addChild(interpolateAtSampleGroup);

		// .static_sample_number
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "static_sample_number", "Test interpolateAtSample sample number");
			interpolateAtSampleGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtSampleRenderCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, InterpolateAtSampleRenderCase::INDEXING_STATIC));
		}

		// .dynamic_sample_number
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "dynamic_sample_number", "Test interpolateAtSample sample number");
			interpolateAtSampleGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtSampleRenderCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, InterpolateAtSampleRenderCase::INDEXING_DYNAMIC));
		}

		// .non_multisample_buffer
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "non_multisample_buffer", "Test interpolateAtSample with non-multisample buffers");
			interpolateAtSampleGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				if (targets[targetNdx].numSamples == 0)
					group->addChild(new SingleSampleInterpolateAtSampleCase(m_context, std::string("sample_0_").append(targets[targetNdx].name).c_str(), targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, SingleSampleInterpolateAtSampleCase::SAMPLE_0));

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				if (targets[targetNdx].numSamples == 0)
					group->addChild(new SingleSampleInterpolateAtSampleCase(m_context, std::string("sample_n_").append(targets[targetNdx].name).c_str(), targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, SingleSampleInterpolateAtSampleCase::SAMPLE_N));
		}

		// .centroid_qualifier
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "centroid_qualified", "Test interpolateAtSample with centroid qualified varying");
			interpolateAtSampleGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new CentroidQualifierAtSampleCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target));
		}

		// .at_sample_id
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "at_sample_id", "Test interpolateAtOffset at current sample id");
			interpolateAtSampleGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtSampleIDCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target));
		}
	}

	// .interpolate_at_centroid
	{
		tcu::TestCaseGroup* const methodGroup = new tcu::TestCaseGroup(m_testCtx, "interpolate_at_centroid", "Test interpolateAtCentroid");
		addChild(methodGroup);

		// .consistency
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "consistency", "Test interpolateAtCentroid return value is consistent to centroid qualified value");
			methodGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtCentroidCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, InterpolateAtCentroidCase::TEST_CONSISTENCY));
		}

		// .array_element
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "array_element", "Test interpolateAtCentroid with array element");
			methodGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtCentroidCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, InterpolateAtCentroidCase::TEST_ARRAY_ELEMENT));
		}
	}

	// .interpolate_at_offset
	{
		static const struct TestConfig
		{
			const char*							name;
			InterpolateAtOffsetCase::TestType	type;
		} configs[] =
		{
			{ "no_qualifiers",		InterpolateAtOffsetCase::TEST_QUALIFIER_NONE		},
			{ "centroid_qualifier",	InterpolateAtOffsetCase::TEST_QUALIFIER_CENTROID	},
			{ "sample_qualifier",	InterpolateAtOffsetCase::TEST_QUALIFIER_SAMPLE		},
		};

		tcu::TestCaseGroup* const methodGroup = new tcu::TestCaseGroup(m_testCtx, "interpolate_at_offset", "Test interpolateAtOffset");
		addChild(methodGroup);

		// .no_qualifiers
		// .centroid_qualifier
		// .sample_qualifier
		for (int configNdx = 0; configNdx < DE_LENGTH_OF_ARRAY(configs); ++configNdx)
		{
			tcu::TestCaseGroup* const qualifierGroup = new tcu::TestCaseGroup(m_testCtx, configs[configNdx].name, "Test interpolateAtOffset with qualified/non-qualified varying");
			methodGroup->addChild(qualifierGroup);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				qualifierGroup->addChild(new InterpolateAtOffsetCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, configs[configNdx].type));
		}

		// .at_sample_position
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "at_sample_position", "Test interpolateAtOffset at sample position");
			methodGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtSamplePositionCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target));
		}

		// .array_element
		{
			tcu::TestCaseGroup* const group = new tcu::TestCaseGroup(m_testCtx, "array_element", "Test interpolateAtOffset with array element");
			methodGroup->addChild(group);

			for (int targetNdx = 0; targetNdx < DE_LENGTH_OF_ARRAY(targets); ++targetNdx)
				group->addChild(new InterpolateAtOffsetCase(m_context, targets[targetNdx].name, targets[targetNdx].desc, targets[targetNdx].numSamples, targets[targetNdx].target, InterpolateAtOffsetCase::TEST_ARRAY_ELEMENT));
		}
	}
}

} // Functional
} // gles31
} // deqp