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
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
|
/*-------------------------------------------------------------------------
* drawElements Quality Program OpenGL ES 2.0 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 Shader operator performance tests.
*//*--------------------------------------------------------------------*/
#include "es2pShaderOperatorTests.hpp"
#include "glsCalibration.hpp"
#include "gluShaderUtil.hpp"
#include "gluShaderProgram.hpp"
#include "gluPixelTransfer.hpp"
#include "tcuTestLog.hpp"
#include "tcuRenderTarget.hpp"
#include "tcuCommandLine.hpp"
#include "tcuSurface.hpp"
#include "deStringUtil.hpp"
#include "deSharedPtr.hpp"
#include "deClock.h"
#include "deMath.h"
#include "glwEnums.hpp"
#include "glwFunctions.hpp"
#include <map>
#include <algorithm>
#include <limits>
#include <set>
namespace deqp
{
namespace gles2
{
namespace Performance
{
using namespace gls;
using namespace glu;
using tcu::Vec2;
using tcu::Vec4;
using tcu::TestLog;
using de::SharedPtr;
using std::string;
using std::vector;
#define MEASUREMENT_FAIL() throw tcu::InternalError("Unable to get sensible measurements for estimation", DE_NULL, __FILE__, __LINE__)
// Number of measurements in OperatorPerformanceCase for each workload size, unless specified otherwise by a command line argument.
static const int DEFAULT_NUM_MEASUREMENTS_PER_WORKLOAD = 3;
// How many different workload sizes are used by OperatorPerformanceCase.
static const int NUM_WORKLOADS = 8;
// Maximum workload size that can be attempted. In a sensible case, this most likely won't be reached.
static const int MAX_WORKLOAD_SIZE = 1<<29;
// BinaryOpCase-specific constants for shader generation.
static const int BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS = 4;
static const int BINARY_OPERATOR_CASE_SMALL_PROGRAM_UNROLL_AMOUNT = 2;
static const int BINARY_OPERATOR_CASE_BIG_PROGRAM_UNROLL_AMOUNT = 4;
// FunctionCase-specific constants for shader generation.
static const int FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS = 4;
static const char* const s_swizzles[][4] =
{
{ "x", "yx", "yzx", "wzyx" },
{ "y", "zy", "wyz", "xwzy" },
{ "z", "wy", "zxy", "yzwx" },
{ "w", "xw", "yxw", "zyxw" }
};
template <int N>
static tcu::Vector<float, N> mean (const vector<tcu::Vector<float, N> >& data)
{
tcu::Vector<float, N> sum(0.0f);
for (int i = 0; i < (int)data.size(); i++)
sum += data[i];
return sum / tcu::Vector<float, N>((float)data.size());
}
static void uniformNfv (const glw::Functions& gl, int n, int location, int count, const float* data)
{
switch (n)
{
case 1: gl.uniform1fv(location, count, data); break;
case 2: gl.uniform2fv(location, count, data); break;
case 3: gl.uniform3fv(location, count, data); break;
case 4: gl.uniform4fv(location, count, data); break;
default: DE_ASSERT(false);
}
}
static void uniformNiv (const glw::Functions& gl, int n, int location, int count, const int* data)
{
switch (n)
{
case 1: gl.uniform1iv(location, count, data); break;
case 2: gl.uniform2iv(location, count, data); break;
case 3: gl.uniform3iv(location, count, data); break;
case 4: gl.uniform4iv(location, count, data); break;
default: DE_ASSERT(false);
}
}
static void uniformMatrixNfv (const glw::Functions& gl, int n, int location, int count, const float* data)
{
switch (n)
{
case 2: gl.uniformMatrix2fv(location, count, GL_FALSE, &data[0]); break;
case 3: gl.uniformMatrix3fv(location, count, GL_FALSE, &data[0]); break;
case 4: gl.uniformMatrix4fv(location, count, GL_FALSE, &data[0]); break;
default: DE_ASSERT(false);
}
}
static glu::DataType getDataTypeFloatOrVec (int size)
{
return size == 1 ? glu::TYPE_FLOAT : glu::getDataTypeFloatVec(size);
}
static int getIterationCountOrDefault (const tcu::CommandLine& cmdLine, int def)
{
const int cmdLineVal = cmdLine.getTestIterationCount();
return cmdLineVal > 0 ? cmdLineVal : def;
}
static string lineParamsString (const LineParameters& params)
{
return "y = " + de::toString(params.offset) + " + " + de::toString(params.coefficient) + "*x";
}
namespace
{
/*--------------------------------------------------------------------*//*!
* \brief Abstract class for measuring shader operator performance.
*
* This class draws multiple times with different workload sizes (set
* via a uniform, by subclass). Time for each frame is measured, and the
* slope of the workload size vs frame time data is estimated. This slope
* tells us the estimated increase in frame time caused by a workload
* increase of 1 unit (what 1 workload unit means is up to subclass).
*
* Generally, the shaders contain not just the operation we're interested
* in (e.g. addition) but also some other stuff (e.g. loop overhead). To
* eliminate this cost, we actually do the stuff described in the above
* paragraph with multiple programs (usually two), which contain different
* kinds of workload (e.g. different loop contents). Then we can (in
* theory) compute the cost of just one operation in a subclass-dependent
* manner.
*
* At this point, the result tells us the increase in frame time caused
* by the addition of one operation. Dividing this by the amount of
* draw calls in a frame, and further by the amount of vertices or
* fragments in a draw call, we get the time cost of one operation.
*
* In reality, there sometimes isn't just a trivial linear dependence
* between workload size and frame time. Instead, there tends to be some
* amount of initial "free" operations. That is, it may be that all
* workload sizes below some positive integer C yield the same frame time,
* and only workload sizes beyond C increase the frame time in a supposedly
* linear manner. Graphically, this means that there graph consists of two
* parts: a horizontal left part, and a linearly increasing right part; the
* right part starts where the left parts ends. The principal task of these
* tests is to look at the slope of the increasing right part. Additionally
* an estimate for the amount of initial free operations is calculated.
* Note that it is also normal to get graphs where the horizontal left part
* is of zero width, i.e. there are no free operations.
*//*--------------------------------------------------------------------*/
class OperatorPerformanceCase : public tcu::TestCase
{
public:
enum CaseType
{
CASETYPE_VERTEX = 0,
CASETYPE_FRAGMENT,
CASETYPE_LAST
};
struct InitialCalibration
{
int initialNumCalls;
InitialCalibration (void) : initialNumCalls(1) {}
};
typedef SharedPtr<InitialCalibration> InitialCalibrationStorage;
OperatorPerformanceCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description,
CaseType caseType, int numWorkloads, const InitialCalibrationStorage& initialCalibrationStorage);
~OperatorPerformanceCase (void);
void init (void);
void deinit (void);
IterateResult iterate (void);
struct AttribSpec
{
AttribSpec (const char* name_, const tcu::Vec4& p00_, const tcu::Vec4& p01_, const tcu::Vec4& p10_, const tcu::Vec4& p11_)
: name (name_)
, p00 (p00_)
, p01 (p01_)
, p10 (p10_)
, p11 (p11_)
{
}
AttribSpec (void) {}
std::string name;
tcu::Vec4 p00; //!< Bottom left.
tcu::Vec4 p01; //!< Bottom right.
tcu::Vec4 p10; //!< Top left.
tcu::Vec4 p11; //!< Top right.
};
protected:
struct ProgramContext
{
string vertShaderSource;
string fragShaderSource;
vector<AttribSpec> attributes;
string description;
ProgramContext (void) {}
ProgramContext (const string& vs, const string& fs, const vector<AttribSpec>& attrs, const string& desc)
: vertShaderSource(vs), fragShaderSource(fs), attributes(attrs), description(desc) {}
};
virtual vector<ProgramContext> generateProgramData (void) const = 0;
//! Sets program-specific uniforms that don't depend on the workload size.
virtual void setGeneralUniforms (deUint32 program) const = 0;
//! Sets the uniform(s) that specifies the workload size in the shader.
virtual void setWorkloadSizeUniform (deUint32 program, int workload) const = 0;
//! Computes the cost of a single operation, given the workload costs per program.
virtual float computeSingleOperationTime (const vector<float>& perProgramWorkloadCosts) const = 0;
//! Logs a human-readable description of what computeSingleOperationTime does.
virtual void logSingleOperationCalculationInfo (void) const = 0;
glu::RenderContext& m_renderCtx;
CaseType m_caseType;
private:
enum State
{
STATE_CALIBRATING = 0, //!< Calibrate draw call count, using first program in m_programs, with workload size 1.
STATE_FIND_HIGH_WORKLOAD, //!< Find an appropriate lower bound for the highest workload size we intend to use (one with high-enough frame time compared to workload size 1) for each program.
STATE_MEASURING, //!< Do actual measurements, for each program in m_programs.
STATE_REPORTING, //!< Measurements are done; calculate results and log.
STATE_FINISHED, //!< All done.
STATE_LAST
};
struct WorkloadRecord
{
int workloadSize;
vector<float> frameTimes; //!< In microseconds.
WorkloadRecord (int workloadSize_) : workloadSize(workloadSize_) {}
bool operator< (const WorkloadRecord& other) const { return this->workloadSize < other.workloadSize; }
void addFrameTime (float time) { frameTimes.push_back(time); }
float getMedianTime (void) const
{
vector<float> times = frameTimes;
std::sort(times.begin(), times.end());
return times.size() % 2 == 0 ?
(times[times.size()/2-1] + times[times.size()/2])*0.5f :
times[times.size()/2];
}
};
void prepareProgram (int progNdx); //!< Sets attributes and uniforms for m_programs[progNdx].
void prepareWorkload (int progNdx, int workload); //!< Calls setWorkloadSizeUniform and draws, in case the implementation does some draw-time compilation.
void prepareNextRound (void); //!< Increases workload and/or updates m_state.
void render (int numDrawCalls);
deUint64 renderAndMeasure (int numDrawCalls);
void adjustAndLogGridAndViewport (void); //!< Log grid and viewport sizes, after possibly reducing them to reduce draw time.
vector<Vec2> getWorkloadMedianDataPoints (int progNdx) const; //!< [ Vec2(r.workloadSize, r.getMedianTime()) for r in m_workloadRecords[progNdx] ]
const int m_numMeasurementsPerWorkload;
const int m_numWorkloads; //!< How many different workload sizes are used for measurement for each program.
int m_workloadNdx; //!< Runs from 0 to m_numWorkloads-1.
int m_workloadMeasurementNdx;
vector<vector<WorkloadRecord> > m_workloadRecordsFindHigh; //!< The measurements done during STATE_FIND_HIGH_WORKLOAD.
vector<vector<WorkloadRecord> > m_workloadRecords; //!< The measurements of each program in m_programs. Generated during STATE_MEASURING, into index specified by m_measureProgramNdx.
State m_state;
int m_measureProgramNdx; //!< When m_state is STATE_FIND_HIGH_WORKLOAD or STATE_MEASURING, this tells which program in m_programs is being measured.
vector<int> m_highWorkloadSizes; //!< The first workload size encountered during STATE_FIND_HIGH_WORKLOAD that was determined suitable, for each program.
TheilSenCalibrator m_calibrator;
InitialCalibrationStorage m_initialCalibrationStorage;
int m_viewportWidth;
int m_viewportHeight;
int m_gridSizeX;
int m_gridSizeY;
vector<ProgramContext> m_programData;
vector<SharedPtr<ShaderProgram> > m_programs;
std::vector<deUint32> m_attribBuffers;
};
static inline float triangleInterpolate (float v0, float v1, float v2, float x, float y)
{
return v0 + (v2-v0)*x + (v1-v0)*y;
}
static inline float triQuadInterpolate (float x, float y, const tcu::Vec4& quad)
{
// \note Top left fill rule.
if (x + y < 1.0f)
return triangleInterpolate(quad.x(), quad.y(), quad.z(), x, y);
else
return triangleInterpolate(quad.w(), quad.z(), quad.y(), 1.0f-x, 1.0f-y);
}
static inline int getNumVertices (int gridSizeX, int gridSizeY)
{
return gridSizeX * gridSizeY * 2 * 3;
}
static void generateVertices (std::vector<float>& dst, int gridSizeX, int gridSizeY, const OperatorPerformanceCase::AttribSpec& spec)
{
const int numComponents = 4;
DE_ASSERT(gridSizeX >= 1 && gridSizeY >= 1);
dst.resize(getNumVertices(gridSizeX, gridSizeY) * numComponents);
{
int dstNdx = 0;
for (int baseY = 0; baseY < gridSizeY; baseY++)
for (int baseX = 0; baseX < gridSizeX; baseX++)
{
const float xf0 = (float)(baseX + 0) / (float)gridSizeX;
const float yf0 = (float)(baseY + 0) / (float)gridSizeY;
const float xf1 = (float)(baseX + 1) / (float)gridSizeX;
const float yf1 = (float)(baseY + 1) / (float)gridSizeY;
#define ADD_VERTEX(XF, YF) \
for (int compNdx = 0; compNdx < numComponents; compNdx++) \
dst[dstNdx++] = triQuadInterpolate((XF), (YF), tcu::Vec4(spec.p00[compNdx], spec.p01[compNdx], spec.p10[compNdx], spec.p11[compNdx]))
ADD_VERTEX(xf0, yf0);
ADD_VERTEX(xf1, yf0);
ADD_VERTEX(xf0, yf1);
ADD_VERTEX(xf1, yf0);
ADD_VERTEX(xf1, yf1);
ADD_VERTEX(xf0, yf1);
#undef ADD_VERTEX
}
}
}
static float intersectionX (const gls::LineParameters& a, const gls::LineParameters& b)
{
return (a.offset - b.offset) / (b.coefficient - a.coefficient);
}
static int numDistinctX (const vector<Vec2>& data)
{
std::set<float> xs;
for (int i = 0; i < (int)data.size(); i++)
xs.insert(data[i].x());
return (int)xs.size();
}
static gls::LineParameters simpleLinearRegression (const vector<Vec2>& data)
{
const Vec2 mid = mean(data);
float slopeNumerator = 0.0f;
float slopeDenominator = 0.0f;
for (int i = 0; i < (int)data.size(); i++)
{
const Vec2 diff = data[i] - mid;
slopeNumerator += diff.x()*diff.y();
slopeDenominator += diff.x()*diff.x();
}
const float slope = slopeNumerator / slopeDenominator;
const float offset = mid.y() - slope*mid.x();
return gls::LineParameters(offset, slope);
}
static float simpleLinearRegressionError (const vector<Vec2>& data)
{
if (numDistinctX(data) <= 2)
return 0.0f;
else
{
const gls::LineParameters estimator = simpleLinearRegression(data);
float error = 0.0f;
for (int i = 0; i < (int)data.size(); i++)
{
const float estY = estimator.offset + estimator.coefficient*data[i].x();
const float diff = estY - data[i].y();
error += diff*diff;
}
return error / (float)data.size();
}
}
static float verticalVariance (const vector<Vec2>& data)
{
if (numDistinctX(data) <= 2)
return 0.0f;
else
{
const float meanY = mean(data).y();
float error = 0.0f;
for (int i = 0; i < (int)data.size(); i++)
{
const float diff = meanY - data[i].y();
error += diff*diff;
}
return error / (float)data.size();
}
}
/*--------------------------------------------------------------------*//*!
* \brief Find the x coord that divides the input data into two slopes.
*
* The operator performance measurements tend to produce results where
* we get small operation counts "for free" (e.g. because the operations
* are performed during some memory transfer overhead or something),
* resulting in a curve with two parts: an initial horizontal line segment,
* and a rising line.
*
* This function finds the x coordinate that divides the input data into
* two parts such that the sum of the mean square errors for the
* least-squares estimated lines for the two parts is minimized, under the
* additional condition that the left line is horizontal.
*
* This function returns a number X s.t. { pt | pt is in data, pt.x >= X }
* is the right line, and the rest of data is the left line.
*//*--------------------------------------------------------------------*/
static float findSlopePivotX (const vector<Vec2>& data)
{
std::set<float> xCoords;
for (int i = 0; i < (int)data.size(); i++)
xCoords.insert(data[i].x());
float lowestError = std::numeric_limits<float>::infinity();
float bestPivotX = -std::numeric_limits<float>::infinity();
for (std::set<float>::const_iterator pivotX = xCoords.begin(); pivotX != xCoords.end(); ++pivotX)
{
vector<Vec2> leftData;
vector<Vec2> rightData;
for (int i = 0; i < (int)data.size(); i++)
{
if (data[i].x() < *pivotX)
leftData.push_back(data[i]);
else
rightData.push_back(data[i]);
}
if (numDistinctX(rightData) < 3) // We don't trust the right data if there's too little of it.
break;
{
const float totalError = verticalVariance(leftData) + simpleLinearRegressionError(rightData);
if (totalError < lowestError)
{
lowestError = totalError;
bestPivotX = *pivotX;
}
}
}
DE_ASSERT(lowestError < std::numeric_limits<float>::infinity());
return bestPivotX;
}
struct SegmentedEstimator
{
float pivotX; //!< Value returned by findSlopePivotX, or -infinity if only single line.
gls::LineParameters left;
gls::LineParameters right;
SegmentedEstimator (const gls::LineParameters& l, const gls::LineParameters& r, float pivotX_) : pivotX(pivotX_), left(l), right(r) {}
};
/*--------------------------------------------------------------------*//*!
* \brief Compute line estimators for (potentially) two-segment data.
*
* Splits the given data into left and right parts (using findSlopePivotX)
* and returns the line estimates for them.
*
* Sometimes, however (especially in fragment shader cases) the data is
* in fact not segmented, but a straight line. This function attempts to
* detect if this the case, and if so, sets left.offset = right.offset and
* left.slope = 0, meaning essentially that the initial "flat" part of the
* data has zero width.
*//*--------------------------------------------------------------------*/
static SegmentedEstimator computeSegmentedEstimator (const vector<Vec2>& data)
{
const float pivotX = findSlopePivotX(data);
vector<Vec2> leftData;
vector<Vec2> rightData;
for (int i = 0; i < (int)data.size(); i++)
{
if (data[i].x() < pivotX)
leftData.push_back(data[i]);
else
rightData.push_back(data[i]);
}
{
const gls::LineParameters leftLine = gls::theilSenEstimator(leftData);
const gls::LineParameters rightLine = gls::theilSenEstimator(rightData);
if (numDistinctX(leftData) < 2 || leftLine.coefficient > rightLine.coefficient*0.5f)
{
// Left data doesn't seem credible; assume the data is just a single line.
const gls::LineParameters entireLine = gls::theilSenEstimator(data);
return SegmentedEstimator(gls::LineParameters(entireLine.offset, 0.0f), entireLine, -std::numeric_limits<float>::infinity());
}
else
return SegmentedEstimator(leftLine, rightLine, pivotX);
}
}
OperatorPerformanceCase::OperatorPerformanceCase (tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* description,
CaseType caseType, int numWorkloads, const InitialCalibrationStorage& initialCalibrationStorage)
: tcu::TestCase (testCtx, tcu::NODETYPE_PERFORMANCE, name, description)
, m_renderCtx (renderCtx)
, m_caseType (caseType)
, m_numMeasurementsPerWorkload (getIterationCountOrDefault(m_testCtx.getCommandLine(), DEFAULT_NUM_MEASUREMENTS_PER_WORKLOAD))
, m_numWorkloads (numWorkloads)
, m_workloadNdx (-1)
, m_workloadMeasurementNdx (-1)
, m_state (STATE_LAST)
, m_measureProgramNdx (-1)
, m_initialCalibrationStorage (initialCalibrationStorage)
, m_viewportWidth (caseType == CASETYPE_VERTEX ? 32 : renderCtx.getRenderTarget().getWidth())
, m_viewportHeight (caseType == CASETYPE_VERTEX ? 32 : renderCtx.getRenderTarget().getHeight())
, m_gridSizeX (caseType == CASETYPE_FRAGMENT ? 1 : 100)
, m_gridSizeY (caseType == CASETYPE_FRAGMENT ? 1 : 100)
{
DE_ASSERT(m_numWorkloads > 0);
}
OperatorPerformanceCase::~OperatorPerformanceCase (void)
{
if (!m_attribBuffers.empty())
{
m_renderCtx.getFunctions().deleteBuffers((glw::GLsizei)m_attribBuffers.size(), &m_attribBuffers[0]);
m_attribBuffers.clear();
}
}
static void logRenderTargetInfo (TestLog& log, const tcu::RenderTarget& renderTarget)
{
log << TestLog::Section("RenderTarget", "Render target")
<< TestLog::Message << "size: " << renderTarget.getWidth() << "x" << renderTarget.getHeight() << TestLog::EndMessage
<< TestLog::Message << "bits:"
<< " R" << renderTarget.getPixelFormat().redBits
<< " G" << renderTarget.getPixelFormat().greenBits
<< " B" << renderTarget.getPixelFormat().blueBits
<< " A" << renderTarget.getPixelFormat().alphaBits
<< " D" << renderTarget.getDepthBits()
<< " S" << renderTarget.getStencilBits()
<< TestLog::EndMessage;
if (renderTarget.getNumSamples() != 0)
log << TestLog::Message << renderTarget.getNumSamples() << "x MSAA" << TestLog::EndMessage;
else
log << TestLog::Message << "No MSAA" << TestLog::EndMessage;
log << TestLog::EndSection;
}
vector<Vec2> OperatorPerformanceCase::getWorkloadMedianDataPoints (int progNdx) const
{
const vector<WorkloadRecord>& records = m_workloadRecords[progNdx];
vector<Vec2> result;
for (int i = 0; i < (int)records.size(); i++)
result.push_back(Vec2((float)records[i].workloadSize, records[i].getMedianTime()));
return result;
}
void OperatorPerformanceCase::prepareProgram (int progNdx)
{
DE_ASSERT(progNdx < (int)m_programs.size());
DE_ASSERT(m_programData.size() == m_programs.size());
const glw::Functions& gl = m_renderCtx.getFunctions();
const ShaderProgram& program = *m_programs[progNdx];
vector<AttribSpec> attributes = m_programData[progNdx].attributes;
attributes.push_back(AttribSpec("a_position",
Vec4(-1.0f, -1.0f, 0.0f, 1.0f),
Vec4( 1.0f, -1.0f, 0.0f, 1.0f),
Vec4(-1.0f, 1.0f, 0.0f, 1.0f),
Vec4( 1.0f, 1.0f, 0.0f, 1.0f)));
DE_ASSERT(program.isOk());
// Generate vertices.
if (!m_attribBuffers.empty())
gl.deleteBuffers((glw::GLsizei)m_attribBuffers.size(), &m_attribBuffers[0]);
m_attribBuffers.resize(attributes.size(), 0);
gl.genBuffers((glw::GLsizei)m_attribBuffers.size(), &m_attribBuffers[0]);
GLU_EXPECT_NO_ERROR(gl.getError(), "glGenBuffers()");
for (int attribNdx = 0; attribNdx < (int)attributes.size(); attribNdx++)
{
std::vector<float> vertices;
generateVertices(vertices, m_gridSizeX, m_gridSizeY, attributes[attribNdx]);
gl.bindBuffer(GL_ARRAY_BUFFER, m_attribBuffers[attribNdx]);
gl.bufferData(GL_ARRAY_BUFFER, (glw::GLsizeiptr)(vertices.size()*sizeof(float)), &vertices[0], GL_STATIC_DRAW);
GLU_EXPECT_NO_ERROR(gl.getError(), "Upload buffer data");
}
// Setup attribute bindings.
for (int attribNdx = 0; attribNdx < (int)attributes.size(); attribNdx++)
{
int location = gl.getAttribLocation(program.getProgram(), attributes[attribNdx].name.c_str());
if (location >= 0)
{
gl.enableVertexAttribArray(location);
gl.bindBuffer(GL_ARRAY_BUFFER, m_attribBuffers[attribNdx]);
gl.vertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, 0, DE_NULL);
}
}
GLU_EXPECT_NO_ERROR(gl.getError(), "Setup vertex input state");
gl.useProgram(program.getProgram());
setGeneralUniforms(program.getProgram());
gl.viewport(0, 0, m_viewportWidth, m_viewportHeight);
}
void OperatorPerformanceCase::prepareWorkload (int progNdx, int workload)
{
setWorkloadSizeUniform(m_programs[progNdx]->getProgram(), workload);
render(m_calibrator.getCallCount());
}
void OperatorPerformanceCase::prepareNextRound (void)
{
DE_ASSERT(m_state == STATE_CALIBRATING ||
m_state == STATE_FIND_HIGH_WORKLOAD ||
m_state == STATE_MEASURING);
TestLog& log = m_testCtx.getLog();
if (m_state == STATE_CALIBRATING && m_calibrator.getState() == TheilSenCalibrator::STATE_FINISHED)
{
m_measureProgramNdx = 0;
m_state = STATE_FIND_HIGH_WORKLOAD;
}
if (m_state == STATE_CALIBRATING)
prepareWorkload(0, 1);
else if (m_state == STATE_FIND_HIGH_WORKLOAD)
{
vector<WorkloadRecord>& records = m_workloadRecordsFindHigh[m_measureProgramNdx];
if (records.empty() || records.back().getMedianTime() < 2.0f*records[0].getMedianTime())
{
int workloadSize;
if (records.empty())
workloadSize = 1;
else
{
workloadSize = records.back().workloadSize*2;
if (workloadSize > MAX_WORKLOAD_SIZE)
{
log << TestLog::Message << "Even workload size " << records.back().workloadSize
<< " doesn't give high enough frame time for program " << m_measureProgramNdx
<< ". Can't get sensible result." << TestLog::EndMessage;
MEASUREMENT_FAIL();
}
}
records.push_back(WorkloadRecord(workloadSize));
prepareWorkload(0, workloadSize);
m_workloadMeasurementNdx = 0;
}
else
{
m_highWorkloadSizes[m_measureProgramNdx] = records.back().workloadSize;
m_measureProgramNdx++;
if (m_measureProgramNdx >= (int)m_programs.size())
{
m_state = STATE_MEASURING;
m_workloadNdx = -1;
m_measureProgramNdx = 0;
}
prepareProgram(m_measureProgramNdx);
prepareNextRound();
}
}
else
{
m_workloadNdx++;
if (m_workloadNdx < m_numWorkloads)
{
DE_ASSERT(m_numWorkloads > 1);
const int highWorkload = m_highWorkloadSizes[m_measureProgramNdx];
const int workload = highWorkload > m_numWorkloads ?
1 + m_workloadNdx*(highWorkload-1)/(m_numWorkloads-1) :
1 + m_workloadNdx;
prepareWorkload(m_measureProgramNdx, workload);
m_workloadMeasurementNdx = 0;
m_workloadRecords[m_measureProgramNdx].push_back(WorkloadRecord(workload));
}
else
{
m_measureProgramNdx++;
if (m_measureProgramNdx < (int)m_programs.size())
{
m_workloadNdx = -1;
m_workloadMeasurementNdx = 0;
prepareProgram(m_measureProgramNdx);
prepareNextRound();
}
else
m_state = STATE_REPORTING;
}
}
}
void OperatorPerformanceCase::init (void)
{
TestLog& log = m_testCtx.getLog();
const glw::Functions& gl = m_renderCtx.getFunctions();
// Validate that we have sane grid and viewport setup.
DE_ASSERT(de::inBounds(m_gridSizeX, 1, 256) && de::inBounds(m_gridSizeY, 1, 256));
TCU_CHECK(de::inRange(m_viewportWidth, 1, m_renderCtx.getRenderTarget().getWidth()) &&
de::inRange(m_viewportHeight, 1, m_renderCtx.getRenderTarget().getHeight()));
logRenderTargetInfo(log, m_renderCtx.getRenderTarget());
log << TestLog::Message << "Using additive blending." << TestLog::EndMessage;
gl.enable(GL_BLEND);
gl.blendEquation(GL_FUNC_ADD);
gl.blendFunc(GL_ONE, GL_ONE);
// Generate programs.
DE_ASSERT(m_programs.empty());
m_programData = generateProgramData();
DE_ASSERT(!m_programData.empty());
for (int progNdx = 0; progNdx < (int)m_programData.size(); progNdx++)
{
const string& vert = m_programData[progNdx].vertShaderSource;
const string& frag = m_programData[progNdx].fragShaderSource;
m_programs.push_back(SharedPtr<ShaderProgram>(new ShaderProgram(m_renderCtx, glu::makeVtxFragSources(vert, frag))));
if (!m_programs.back()->isOk())
{
log << *m_programs.back();
TCU_FAIL("Compile failed");
}
}
// Log all programs.
for (int progNdx = 0; progNdx < (int)m_programs.size(); progNdx++)
log << TestLog::Section("Program" + de::toString(progNdx), "Program " + de::toString(progNdx))
<< TestLog::Message << m_programData[progNdx].description << TestLog::EndMessage
<< *m_programs[progNdx]
<< TestLog::EndSection;
m_highWorkloadSizes.resize(m_programData.size());
m_workloadRecordsFindHigh.resize(m_programData.size());
m_workloadRecords.resize(m_programData.size());
m_calibrator.clear(CalibratorParameters(m_initialCalibrationStorage->initialNumCalls, 10 /* calibrate iteration frames */, 2000.0f /* calibrate iteration shortcut threshold (ms) */, 16 /* max calibrate iterations */,
1000.0f/30.0f /* frame time (ms) */, 1000.0f/60.0f /* frame time cap (ms) */, 1000.0f /* target measure duration (ms) */));
m_state = STATE_CALIBRATING;
prepareProgram(0);
prepareNextRound();
}
void OperatorPerformanceCase::deinit (void)
{
if (!m_attribBuffers.empty())
{
m_renderCtx.getFunctions().deleteBuffers((glw::GLsizei)m_attribBuffers.size(), &m_attribBuffers[0]);
m_attribBuffers.clear();
}
m_programs.clear();
}
void OperatorPerformanceCase::render (int numDrawCalls)
{
const glw::Functions& gl = m_renderCtx.getFunctions();
const int numVertices = getNumVertices(m_gridSizeX, m_gridSizeY);
for (int callNdx = 0; callNdx < numDrawCalls; callNdx++)
gl.drawArrays(GL_TRIANGLES, 0, numVertices);
glu::readPixels(m_renderCtx, 0, 0, tcu::Surface(1, 1).getAccess()); // \note Serves as a more reliable replacement for glFinish().
}
deUint64 OperatorPerformanceCase::renderAndMeasure (int numDrawCalls)
{
const deUint64 startTime = deGetMicroseconds();
render(numDrawCalls);
return deGetMicroseconds() - startTime;
}
void OperatorPerformanceCase::adjustAndLogGridAndViewport (void)
{
TestLog& log = m_testCtx.getLog();
// If call count is just 1, and the target frame time still wasn't reached, reduce grid or viewport size.
if (m_calibrator.getCallCount() == 1)
{
const gls::MeasureState& calibratorMeasure = m_calibrator.getMeasureState();
const float drawCallTime = (float)calibratorMeasure.getTotalTime() / (float)calibratorMeasure.frameTimes.size();
const float targetDrawCallTime = m_calibrator.getParameters().targetFrameTimeUs;
const float targetRatio = targetDrawCallTime / drawCallTime;
if (targetRatio < 0.95f)
{
// Reduce grid or viewport size assuming draw call time scales proportionally.
if (m_caseType == CASETYPE_VERTEX)
{
const float targetRatioSqrt = deFloatSqrt(targetRatio);
m_gridSizeX = (int)(targetRatioSqrt * (float)m_gridSizeX);
m_gridSizeY = (int)(targetRatioSqrt * (float)m_gridSizeY);
TCU_CHECK_MSG(m_gridSizeX >= 1 && m_gridSizeY >= 1, "Can't decrease grid size enough to achieve low-enough draw times");
log << TestLog::Message << "Note: triangle grid size reduced from original; it's now smaller than during calibration." << TestLog::EndMessage;
}
else
{
const float targetRatioSqrt = deFloatSqrt(targetRatio);
m_viewportWidth = (int)(targetRatioSqrt * (float)m_viewportWidth);
m_viewportHeight = (int)(targetRatioSqrt * (float)m_viewportHeight);
TCU_CHECK_MSG(m_viewportWidth >= 1 && m_viewportHeight >= 1, "Can't decrease viewport size enough to achieve low-enough draw times");
log << TestLog::Message << "Note: viewport size reduced from original; it's now smaller than during calibration." << TestLog::EndMessage;
}
}
}
prepareProgram(0);
// Log grid and viewport sizes.
log << TestLog::Message << "Grid size: " << m_gridSizeX << "x" << m_gridSizeY << TestLog::EndMessage;
log << TestLog::Message << "Viewport: " << m_viewportWidth << "x" << m_viewportHeight << TestLog::EndMessage;
}
OperatorPerformanceCase::IterateResult OperatorPerformanceCase::iterate (void)
{
const TheilSenCalibrator::State calibratorState = m_calibrator.getState();
if (calibratorState != TheilSenCalibrator::STATE_FINISHED)
{
if (calibratorState == TheilSenCalibrator::STATE_RECOMPUTE_PARAMS)
m_calibrator.recomputeParameters();
else if (calibratorState == TheilSenCalibrator::STATE_MEASURE)
m_calibrator.recordIteration(renderAndMeasure(m_calibrator.getCallCount()));
else
DE_ASSERT(false);
if (m_calibrator.getState() == TheilSenCalibrator::STATE_FINISHED)
{
logCalibrationInfo(m_testCtx.getLog(), m_calibrator);
adjustAndLogGridAndViewport();
prepareNextRound();
m_initialCalibrationStorage->initialNumCalls = m_calibrator.getCallCount();
}
}
else if (m_state == STATE_FIND_HIGH_WORKLOAD || m_state == STATE_MEASURING)
{
if (m_workloadMeasurementNdx < m_numMeasurementsPerWorkload)
{
vector<WorkloadRecord>& records = m_state == STATE_FIND_HIGH_WORKLOAD ? m_workloadRecordsFindHigh[m_measureProgramNdx] : m_workloadRecords[m_measureProgramNdx];
records.back().addFrameTime((float)renderAndMeasure(m_calibrator.getCallCount()));
m_workloadMeasurementNdx++;
}
else
prepareNextRound();
}
else
{
DE_ASSERT(m_state == STATE_REPORTING);
TestLog& log = m_testCtx.getLog();
const int drawCallCount = m_calibrator.getCallCount();
{
// Compute per-program estimators for measurements.
vector<SegmentedEstimator> estimators;
for (int progNdx = 0; progNdx < (int)m_programs.size(); progNdx++)
estimators.push_back(computeSegmentedEstimator(getWorkloadMedianDataPoints(progNdx)));
// Log measurements and their estimators for all programs.
for (int progNdx = 0; progNdx < (int)m_programs.size(); progNdx++)
{
const SegmentedEstimator& estimator = estimators[progNdx];
const string progNdxStr = de::toString(progNdx);
vector<WorkloadRecord> records = m_workloadRecords[progNdx];
std::sort(records.begin(), records.end());
{
const tcu::ScopedLogSection section(log,
"Program" + progNdxStr + "Measurements",
"Measurements for program " + progNdxStr);
// Sample list of individual frame times.
log << TestLog::SampleList("Program" + progNdxStr + "IndividualFrameTimes", "Individual frame times")
<< TestLog::SampleInfo << TestLog::ValueInfo("Workload", "Workload", "", QP_SAMPLE_VALUE_TAG_PREDICTOR)
<< TestLog::ValueInfo("FrameTime", "Frame time", "us", QP_SAMPLE_VALUE_TAG_RESPONSE)
<< TestLog::EndSampleInfo;
for (int i = 0; i < (int)records.size(); i++)
for (int j = 0; j < (int)records[i].frameTimes.size(); j++)
log << TestLog::Sample << records[i].workloadSize << records[i].frameTimes[j] << TestLog::EndSample;
log << TestLog::EndSampleList;
// Sample list of median frame times.
log << TestLog::SampleList("Program" + progNdxStr + "MedianFrameTimes", "Median frame times")
<< TestLog::SampleInfo << TestLog::ValueInfo("Workload", "Workload", "", QP_SAMPLE_VALUE_TAG_PREDICTOR)
<< TestLog::ValueInfo("MedianFrameTime", "Median frame time", "us", QP_SAMPLE_VALUE_TAG_RESPONSE)
<< TestLog::EndSampleInfo;
for (int i = 0; i < (int)records.size(); i++)
log << TestLog::Sample << records[i].workloadSize << records[i].getMedianTime() << TestLog::EndSample;
log << TestLog::EndSampleList;
log << TestLog::Float("Program" + progNdxStr + "WorkloadCostEstimate", "Workload cost estimate", "us / workload", QP_KEY_TAG_TIME, estimator.right.coefficient);
if (estimator.pivotX > -std::numeric_limits<float>::infinity())
log << TestLog::Message << "Note: the data points with x coordinate greater than or equal to " << estimator.pivotX
<< " seem to form a rising line, and the rest of data points seem to form a near-horizontal line" << TestLog::EndMessage
<< TestLog::Message << "Note: the left line is estimated to be " << lineParamsString(estimator.left)
<< " and the right line " << lineParamsString(estimator.right) << TestLog::EndMessage;
else
log << TestLog::Message << "Note: the data seem to form a single line: " << lineParamsString(estimator.right) << TestLog::EndMessage;
}
}
for (int progNdx = 0; progNdx < (int)m_programs.size(); progNdx++)
{
if (estimators[progNdx].right.coefficient <= 0.0f)
{
log << TestLog::Message << "Slope of measurements for program " << progNdx << " isn't positive. Can't get sensible result." << TestLog::EndMessage;
MEASUREMENT_FAIL();
}
}
// \note For each estimator, .right.coefficient is the increase in draw time (in microseconds) when
// incrementing shader workload size by 1, when D draw calls are done, with a vertex/fragment count
// of R.
//
// The measurements of any single program can't tell us the final result (time of single operation),
// so we use computeSingleOperationTime to compute it from multiple programs' measurements in a
// subclass-defined manner.
//
// After that, microseconds per operation can be calculated as singleOperationTime / (D * R).
{
vector<float> perProgramSlopes;
for (int i = 0; i < (int)m_programs.size(); i++)
perProgramSlopes.push_back(estimators[i].right.coefficient);
logSingleOperationCalculationInfo();
const float maxSlope = *std::max_element(perProgramSlopes.begin(), perProgramSlopes.end());
const float usecsPerFramePerOp = computeSingleOperationTime(perProgramSlopes);
const int vertexOrFragmentCount = m_caseType == CASETYPE_VERTEX ?
getNumVertices(m_gridSizeX, m_gridSizeY) :
m_viewportWidth*m_viewportHeight;
const double usecsPerDrawCallPerOp = usecsPerFramePerOp / (double)drawCallCount;
const double usecsPerSingleOp = usecsPerDrawCallPerOp / (double)vertexOrFragmentCount;
const double megaOpsPerSecond = (double)(drawCallCount*vertexOrFragmentCount) / usecsPerFramePerOp;
const int numFreeOps = de::max(0, (int)deFloatFloor(intersectionX(estimators[0].left,
LineParameters(estimators[0].right.offset,
usecsPerFramePerOp))));
log << TestLog::Integer("VertexOrFragmentCount",
"R = " + string(m_caseType == CASETYPE_VERTEX ? "Vertex" : "Fragment") + " count",
"", QP_KEY_TAG_NONE, vertexOrFragmentCount)
<< TestLog::Integer("DrawCallsPerFrame", "D = Draw calls per frame", "", QP_KEY_TAG_NONE, drawCallCount)
<< TestLog::Integer("VerticesOrFragmentsPerFrame",
"R*D = " + string(m_caseType == CASETYPE_VERTEX ? "Vertices" : "Fragments") + " per frame",
"", QP_KEY_TAG_NONE, vertexOrFragmentCount*drawCallCount)
<< TestLog::Float("TimePerFramePerOp",
"Estimated cost of R*D " + string(m_caseType == CASETYPE_VERTEX ? "vertices" : "fragments")
+ " (i.e. one frame) with one shader operation",
"us", QP_KEY_TAG_TIME, (float)usecsPerFramePerOp)
<< TestLog::Float("TimePerDrawcallPerOp",
"Estimated cost of one draw call with one shader operation",
"us", QP_KEY_TAG_TIME, (float)usecsPerDrawCallPerOp)
<< TestLog::Float("TimePerSingleOp",
"Estimated cost of a single shader operation",
"us", QP_KEY_TAG_TIME, (float)usecsPerSingleOp);
// \note Sometimes, when the operation is free or very cheap, it can happen that the shader with the operation runs,
// for some reason, a bit faster than the shader without the operation, and thus we get a negative result. The
// following threshold values for accepting a negative or almost-zero result are rather quick and dirty.
if (usecsPerFramePerOp <= -0.1f*maxSlope)
{
log << TestLog::Message << "Got strongly negative result." << TestLog::EndMessage;
MEASUREMENT_FAIL();
}
else if (usecsPerFramePerOp <= 0.001*maxSlope)
{
log << TestLog::Message << "Cost of operation seems to be approximately zero." << TestLog::EndMessage;
m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
}
else
{
log << TestLog::Float("OpsPerSecond",
"Operations per second",
"Million/s", QP_KEY_TAG_PERFORMANCE, (float)megaOpsPerSecond)
<< TestLog::Integer("NumFreeOps",
"Estimated number of \"free\" operations",
"", QP_KEY_TAG_PERFORMANCE, numFreeOps);
m_testCtx.setTestResult(QP_TEST_RESULT_PASS, de::floatToString((float)megaOpsPerSecond, 2).c_str());
}
m_state = STATE_FINISHED;
}
}
return STOP;
}
return CONTINUE;
}
// Binary operator case.
class BinaryOpCase : public OperatorPerformanceCase
{
public:
BinaryOpCase (Context& context, const char* name, const char* description, const char* op,
glu::DataType type, glu::Precision precision, bool useSwizzle, bool isVertex, const InitialCalibrationStorage& initialCalibration);
protected:
vector<ProgramContext> generateProgramData (void) const;
void setGeneralUniforms (deUint32 program) const;
void setWorkloadSizeUniform (deUint32 program, int numOperations) const;
float computeSingleOperationTime (const vector<float>& perProgramOperationCosts) const;
void logSingleOperationCalculationInfo (void) const;
private:
enum ProgramID
{
// \note 0-based sequential numbering is relevant, because these are also used as vector indices.
// \note The first program should be the heaviest, because OperatorPerformanceCase uses it to reduce grid/viewport size when going too slow.
PROGRAM_WITH_BIGGER_LOOP = 0,
PROGRAM_WITH_SMALLER_LOOP,
PROGRAM_LAST
};
ProgramContext generateSingleProgramData (ProgramID) const;
const string m_op;
const glu::DataType m_type;
const glu::Precision m_precision;
const bool m_useSwizzle;
};
BinaryOpCase::BinaryOpCase (Context& context, const char* name, const char* description, const char* op,
glu::DataType type, glu::Precision precision, bool useSwizzle, bool isVertex, const InitialCalibrationStorage& initialCalibration)
: OperatorPerformanceCase (context.getTestContext(), context.getRenderContext(), name, description,
isVertex ? CASETYPE_VERTEX : CASETYPE_FRAGMENT, NUM_WORKLOADS, initialCalibration)
, m_op (op)
, m_type (type)
, m_precision (precision)
, m_useSwizzle (useSwizzle)
{
}
BinaryOpCase::ProgramContext BinaryOpCase::generateSingleProgramData (ProgramID programID) const
{
DE_ASSERT(glu::isDataTypeFloatOrVec(m_type) || glu::isDataTypeIntOrIVec(m_type));
const bool isVertexCase = m_caseType == CASETYPE_VERTEX;
const char* const precision = glu::getPrecisionName(m_precision);
const char* const inputPrecision = glu::isDataTypeIntOrIVec(m_type) && m_precision == glu::PRECISION_LOWP ? "mediump" : precision;
const char* const typeName = getDataTypeName(m_type);
std::ostringstream vtx;
std::ostringstream frag;
std::ostringstream& op = isVertexCase ? vtx : frag;
// Attributes.
vtx << "attribute highp vec4 a_position;\n";
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS+1; i++)
vtx << "attribute " << inputPrecision << " vec4 a_in" << i << ";\n";
if (isVertexCase)
{
vtx << "varying mediump vec4 v_color;\n";
frag << "varying mediump vec4 v_color;\n";
}
else
{
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS+1; i++)
{
vtx << "varying " << inputPrecision << " vec4 v_in" << i << ";\n";
frag << "varying " << inputPrecision << " vec4 v_in" << i << ";\n";
}
}
op << "uniform mediump int u_numLoopIterations;\n";
if (isVertexCase)
op << "uniform mediump float u_zero;\n";
vtx << "\n";
vtx << "void main()\n";
vtx << "{\n";
if (!isVertexCase)
vtx << "\tgl_Position = a_position;\n";
frag << "\n";
frag << "void main()\n";
frag << "{\n";
// Expression inputs.
const char* const prefix = isVertexCase ? "a_" : "v_";
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS+1; i++)
{
const int inSize = getDataTypeScalarSize(m_type);
const bool isInt = de::inRange<int>(m_type, TYPE_INT, TYPE_INT_VEC4);
const bool cast = isInt || (!m_useSwizzle && m_type != TYPE_FLOAT_VEC4);
op << "\t" << precision << " " << typeName << " in" << i << " = ";
if (cast)
op << typeName << "(";
op << prefix << "in" << i;
if (m_useSwizzle)
op << "." << s_swizzles[i % DE_LENGTH_OF_ARRAY(s_swizzles)][inSize-1];
if (cast)
op << ")";
op << ";\n";
}
// Operation accumulation variables.
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS; i++)
{
op << "\t" << precision << " " << typeName << " acc" << i << "a" << " = in" << i+0 << ";\n";
op << "\t" << precision << " " << typeName << " acc" << i << "b" << " = in" << i+1 << ";\n";
}
// Loop, with expressions in it.
op << "\tfor (int i = 0; i < u_numLoopIterations; i++)\n";
op << "\t{\n";
{
const int unrollAmount = programID == PROGRAM_WITH_SMALLER_LOOP ? BINARY_OPERATOR_CASE_SMALL_PROGRAM_UNROLL_AMOUNT : BINARY_OPERATOR_CASE_BIG_PROGRAM_UNROLL_AMOUNT;
for (int unrollNdx = 0; unrollNdx < unrollAmount; unrollNdx++)
{
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS; i++)
{
if (i > 0 || unrollNdx > 0)
op << "\n";
op << "\t\tacc" << i << "a = acc" << i << "b " << m_op << " acc" << i << "a" << ";\n";
op << "\t\tacc" << i << "b = acc" << i << "a " << m_op << " acc" << i << "b" << ";\n";
}
}
}
op << "\t}\n";
op << "\n";
// Result variable (sum of accumulation variables).
op << "\t" << precision << " " << typeName << " res =";
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS; i++)
op << (i > 0 ? " "+m_op : "") << " acc" << i << "b";
op << ";\n";
// Convert to color.
op << "\tmediump vec4 color = ";
if (m_type == TYPE_FLOAT_VEC4)
op << "res";
else
{
int size = getDataTypeScalarSize(m_type);
op << "vec4(res";
for (int i = size; i < 4; i++)
op << ", " << (i == 3 ? "1.0" : "0.0");
op << ")";
}
op << ";\n";
op << "\t" << (isVertexCase ? "v_color" : "gl_FragColor") << " = color;\n";
if (isVertexCase)
{
vtx << " gl_Position = a_position + u_zero*color;\n";
frag << " gl_FragColor = v_color;\n";
}
else
{
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS+1; i++)
vtx << " v_in" << i << " = a_in" << i << ";\n";
}
vtx << "}\n";
frag << "}\n";
{
vector<AttribSpec> attributes;
for (int i = 0; i < BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS+1; i++)
attributes.push_back(AttribSpec(("a_in" + de::toString(i)).c_str(),
Vec4(2.0f, 2.0f, 2.0f, 1.0f).swizzle((i+0)%4, (i+1)%4, (i+2)%4, (i+3)%4),
Vec4(1.0f, 2.0f, 1.0f, 2.0f).swizzle((i+0)%4, (i+1)%4, (i+2)%4, (i+3)%4),
Vec4(2.0f, 1.0f, 2.0f, 2.0f).swizzle((i+0)%4, (i+1)%4, (i+2)%4, (i+3)%4),
Vec4(1.0f, 1.0f, 2.0f, 1.0f).swizzle((i+0)%4, (i+1)%4, (i+2)%4, (i+3)%4)));
{
string description = "This is the program with the ";
description += programID == PROGRAM_WITH_SMALLER_LOOP ? "smaller"
: programID == PROGRAM_WITH_BIGGER_LOOP ? "bigger"
: DE_NULL;
description += " loop.\n"
"Note: workload size for this program means the number of loop iterations.";
return ProgramContext(vtx.str(), frag.str(), attributes, description);
}
}
}
vector<BinaryOpCase::ProgramContext> BinaryOpCase::generateProgramData (void) const
{
vector<ProgramContext> progData;
for (int i = 0; i < PROGRAM_LAST; i++)
progData.push_back(generateSingleProgramData((ProgramID)i));
return progData;
}
void BinaryOpCase::setGeneralUniforms (deUint32 program) const
{
const glw::Functions& gl = m_renderCtx.getFunctions();
gl.uniform1f(gl.getUniformLocation(program, "u_zero"), 0.0f);
}
void BinaryOpCase::setWorkloadSizeUniform (deUint32 program, int numLoopIterations) const
{
const glw::Functions& gl = m_renderCtx.getFunctions();
gl.uniform1i(gl.getUniformLocation(program, "u_numLoopIterations"), numLoopIterations);
}
float BinaryOpCase::computeSingleOperationTime (const vector<float>& perProgramOperationCosts) const
{
DE_ASSERT(perProgramOperationCosts.size() == PROGRAM_LAST);
const int baseNumOpsInsideLoop = 2 * BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS;
const int numOpsInsideLoopInSmallProgram = baseNumOpsInsideLoop * BINARY_OPERATOR_CASE_SMALL_PROGRAM_UNROLL_AMOUNT;
const int numOpsInsideLoopInBigProgram = baseNumOpsInsideLoop * BINARY_OPERATOR_CASE_BIG_PROGRAM_UNROLL_AMOUNT;
DE_STATIC_ASSERT(numOpsInsideLoopInBigProgram > numOpsInsideLoopInSmallProgram);
const int opDiff = numOpsInsideLoopInBigProgram - numOpsInsideLoopInSmallProgram;
const float programOperationCostDiff = perProgramOperationCosts[PROGRAM_WITH_BIGGER_LOOP] - perProgramOperationCosts[PROGRAM_WITH_SMALLER_LOOP];
return programOperationCostDiff / (float)opDiff;
}
void BinaryOpCase::logSingleOperationCalculationInfo (void) const
{
const int baseNumOpsInsideLoop = 2 * BINARY_OPERATOR_CASE_NUM_INDEPENDENT_CALCULATIONS;
const int numOpsInsideLoopInSmallProgram = baseNumOpsInsideLoop * BINARY_OPERATOR_CASE_SMALL_PROGRAM_UNROLL_AMOUNT;
const int numOpsInsideLoopInBigProgram = baseNumOpsInsideLoop * BINARY_OPERATOR_CASE_BIG_PROGRAM_UNROLL_AMOUNT;
const int opDiff = numOpsInsideLoopInBigProgram - numOpsInsideLoopInSmallProgram;
const char* const opName = m_op == "+" ? "addition"
: m_op == "-" ? "subtraction"
: m_op == "*" ? "multiplication"
: m_op == "/" ? "division"
: DE_NULL;
DE_ASSERT(opName != DE_NULL);
m_testCtx.getLog() << TestLog::Message << "Note: the bigger program contains " << opDiff << " more "
<< opName << " operations in one loop iteration than the small program; "
<< "cost of one operation is calculated as (cost_of_bigger_workload - cost_of_smaller_workload) / " << opDiff
<< TestLog::EndMessage;
}
// Built-in function case.
class FunctionCase : public OperatorPerformanceCase
{
public:
enum
{
MAX_PARAMS = 3
};
FunctionCase (Context& context,
const char* name,
const char* description,
const char* func,
glu::DataType returnType,
const glu::DataType paramTypes[MAX_PARAMS],
const Vec4& attribute,
int modifyParamNdx, //!< Add a compile-time constant (2.0) to the parameter at this index. This is ignored if negative.
bool useNearlyConstantINputs, //!< Function inputs shouldn't be much bigger than 'attribute'.
glu::Precision precision,
bool isVertex,
const InitialCalibrationStorage& initialCalibration);
protected:
vector<ProgramContext> generateProgramData (void) const;
void setGeneralUniforms (deUint32 program) const;
void setWorkloadSizeUniform (deUint32 program, int numOperations) const;
float computeSingleOperationTime (const vector<float>& perProgramOperationCosts) const;
void logSingleOperationCalculationInfo (void) const;
private:
enum ProgramID
{
// \note 0-based sequential numbering is relevant, because these are also used as vector indices.
// \note The first program should be the heaviest, because OperatorPerformanceCase uses it to reduce grid/viewport size when going too slow.
PROGRAM_WITH_FUNCTION_CALLS = 0,
PROGRAM_WITHOUT_FUNCTION_CALLS,
PROGRAM_LAST
};
//! Forms a "sum" expression from aExpr and bExpr; for booleans, this is "equal(a,b)", otherwise actual sum.
static string sumExpr (const string& aExpr, const string& bExpr, glu::DataType type);
//! Forms an expression used to increment an input value in the shader. If type is boolean, this is just
//! baseExpr; otherwise, baseExpr is modified by multiplication or division by a loop index,
//! to prevent simple compiler optimizations. See m_useNearlyConstantInputs for more explanation.
static string incrementExpr (const string& baseExpr, glu::DataType type, bool divide);
ProgramContext generateSingleProgramData (ProgramID) const;
const string m_func;
const glu::DataType m_returnType;
glu::DataType m_paramTypes[MAX_PARAMS];
// \note m_modifyParamNdx, if not negative, specifies the index of the parameter to which a
// compile-time constant (2.0) is added. This is a quick and dirty way to deal with
// functions like clamp or smoothstep that require that a certain parameter is
// greater than a certain other parameter.
const int m_modifyParamNdx;
// \note m_useNearlyConstantInputs determines whether the inputs given to the function
// should increase (w.r.t m_attribute) only by very small amounts. This is relevant
// for functions like asin, which requires its inputs to be in a specific range.
// In practice, this affects whether expressions used to increment the input
// variables use division instead of multiplication; normally, multiplication is used,
// but it's hard to keep the increments very small that way, and division shouldn't
// be the default, since for many functions (probably not asin, luckily), division
// is too heavy and dominates time-wise.
const bool m_useNearlyConstantInputs;
const Vec4 m_attribute;
const glu::Precision m_precision;
};
FunctionCase::FunctionCase (Context& context,
const char* name,
const char* description,
const char* func,
glu::DataType returnType,
const glu::DataType paramTypes[MAX_PARAMS],
const Vec4& attribute,
int modifyParamNdx,
bool useNearlyConstantInputs,
glu::Precision precision,
bool isVertex,
const InitialCalibrationStorage& initialCalibration)
: OperatorPerformanceCase (context.getTestContext(), context.getRenderContext(), name, description,
isVertex ? CASETYPE_VERTEX : CASETYPE_FRAGMENT, NUM_WORKLOADS, initialCalibration)
, m_func (func)
, m_returnType (returnType)
, m_modifyParamNdx (modifyParamNdx)
, m_useNearlyConstantInputs (useNearlyConstantInputs)
, m_attribute (attribute)
, m_precision (precision)
{
for (int i = 0; i < MAX_PARAMS; i++)
m_paramTypes[i] = paramTypes[i];
}
string FunctionCase::sumExpr (const string& aExpr, const string& bExpr, glu::DataType type)
{
if (glu::isDataTypeBoolOrBVec(type))
{
if (type == glu::TYPE_BOOL)
return "(" + aExpr + " == " + bExpr + ")";
else
return "equal(" + aExpr + ", " + bExpr + ")";
}
else
return "(" + aExpr + " + " + bExpr + ")";
}
string FunctionCase::incrementExpr (const string& baseExpr, glu::DataType type, bool divide)
{
const string mulOrDiv = divide ? "/" : "*";
return glu::isDataTypeBoolOrBVec(type) ? baseExpr
: glu::isDataTypeIntOrIVec(type) ? "(" + baseExpr + mulOrDiv + "(i+1))"
: "(" + baseExpr + mulOrDiv + "float(i+1))";
}
FunctionCase::ProgramContext FunctionCase::generateSingleProgramData (ProgramID programID) const
{
const bool isVertexCase = m_caseType == CASETYPE_VERTEX;
const char* const precision = glu::getPrecisionName(m_precision);
const char* const returnTypeName = getDataTypeName(m_returnType);
const string returnPrecisionMaybe = glu::isDataTypeBoolOrBVec(m_returnType) ? "" : string() + precision + " ";
const char* inputPrecision = DE_NULL;
const bool isMatrixReturn = isDataTypeMatrix(m_returnType);
int numParams = 0;
const char* paramTypeNames[MAX_PARAMS];
string paramPrecisionsMaybe[MAX_PARAMS];
for (int i = 0; i < MAX_PARAMS; i++)
{
paramTypeNames[i] = getDataTypeName(m_paramTypes[i]);
paramPrecisionsMaybe[i] = glu::isDataTypeBoolOrBVec(m_paramTypes[i]) ? "" : string() + precision + " ";
if (inputPrecision == DE_NULL && isDataTypeIntOrIVec(m_paramTypes[i]) && m_precision == glu::PRECISION_LOWP)
inputPrecision = "mediump";
if (m_paramTypes[i] != TYPE_INVALID)
numParams = i+1;
}
DE_ASSERT(numParams > 0);
if (inputPrecision == DE_NULL)
inputPrecision = precision;
int numAttributes = FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS + numParams - 1;
std::ostringstream vtx;
std::ostringstream frag;
std::ostringstream& op = isVertexCase ? vtx : frag;
// Attributes.
vtx << "attribute highp vec4 a_position;\n";
for (int i = 0; i < numAttributes; i++)
vtx << "attribute " << inputPrecision << " vec4 a_in" << i << ";\n";
if (isVertexCase)
{
vtx << "varying mediump vec4 v_color;\n";
frag << "varying mediump vec4 v_color;\n";
}
else
{
for (int i = 0; i < numAttributes; i++)
{
vtx << "varying " << inputPrecision << " vec4 v_in" << i << ";\n";
frag << "varying " << inputPrecision << " vec4 v_in" << i << ";\n";
}
}
op << "uniform mediump int u_numLoopIterations;\n";
if (isVertexCase)
op << "uniform mediump float u_zero;\n";
for (int paramNdx = 0; paramNdx < numParams; paramNdx++)
op << "uniform " << paramPrecisionsMaybe[paramNdx] << paramTypeNames[paramNdx] << " u_inc" << (char)('A'+paramNdx) << ";\n";
vtx << "\n";
vtx << "void main()\n";
vtx << "{\n";
if (!isVertexCase)
vtx << "\tgl_Position = a_position;\n";
frag << "\n";
frag << "void main()\n";
frag << "{\n";
// Function call input and return value accumulation variables.
{
const char* const inPrefix = isVertexCase ? "a_" : "v_";
for (int calcNdx = 0; calcNdx < FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS; calcNdx++)
{
for (int paramNdx = 0; paramNdx < numParams; paramNdx++)
{
const glu::DataType paramType = m_paramTypes[paramNdx];
const bool mustCast = paramType != glu::TYPE_FLOAT_VEC4;
op << "\t" << paramPrecisionsMaybe[paramNdx] << paramTypeNames[paramNdx] << " in" << calcNdx << (char)('a'+paramNdx) << " = ";
if (mustCast)
op << paramTypeNames[paramNdx] << "(";
if (glu::isDataTypeMatrix(paramType))
{
static const char* const swizzles[3] = { "x", "xy", "xyz" };
const int numRows = glu::getDataTypeMatrixNumRows(paramType);
const int numCols = glu::getDataTypeMatrixNumColumns(paramType);
const string swizzle = numRows < 4 ? string() + "." + swizzles[numRows-1] : "";
for (int i = 0; i < numCols; i++)
op << (i > 0 ? ", " : "") << inPrefix << "in" << calcNdx+paramNdx << swizzle;
}
else
{
op << inPrefix << "in" << calcNdx+paramNdx;
if (paramNdx == m_modifyParamNdx)
{
DE_ASSERT(glu::isDataTypeFloatOrVec(paramType));
op << " + 2.0";
}
}
if (mustCast)
op << ")";
op << ";\n";
}
op << "\t" << returnPrecisionMaybe << returnTypeName << " res" << calcNdx << " = " << returnTypeName << "(0);\n";
}
}
// Loop with expressions in it.
op << "\tfor (int i = 0; i < u_numLoopIterations; i++)\n";
op << "\t{\n";
for (int calcNdx = 0; calcNdx < FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS; calcNdx++)
{
if (calcNdx > 0)
op << "\n";
op << "\t\t{\n";
for (int inputNdx = 0; inputNdx < numParams; inputNdx++)
{
const string inputName = "in" + de::toString(calcNdx) + (char)('a'+inputNdx);
const string incName = string() + "u_inc" + (char)('A'+inputNdx);
const string incExpr = incrementExpr(incName, m_paramTypes[inputNdx], m_useNearlyConstantInputs);
op << "\t\t\t" << inputName << " = " << sumExpr(inputName, incExpr, m_paramTypes[inputNdx]) << ";\n";
}
op << "\t\t\t" << returnPrecisionMaybe << returnTypeName << " eval" << calcNdx << " = ";
if (programID == PROGRAM_WITH_FUNCTION_CALLS)
{
op << m_func << "(";
for (int paramNdx = 0; paramNdx < numParams; paramNdx++)
{
if (paramNdx > 0)
op << ", ";
op << "in" << calcNdx << (char)('a'+paramNdx);
}
op << ")";
}
else
{
DE_ASSERT(programID == PROGRAM_WITHOUT_FUNCTION_CALLS);
op << returnTypeName << "(1)";
}
op << ";\n";
{
const string resName = "res" + de::toString(calcNdx);
const string evalName = "eval" + de::toString(calcNdx);
const string incExpr = incrementExpr(evalName, m_returnType, m_useNearlyConstantInputs);
op << "\t\t\tres" << calcNdx << " = " << sumExpr(resName, incExpr, m_returnType) << ";\n";
}
op << "\t\t}\n";
}
op << "\t}\n";
op << "\n";
// Result variables.
for (int inputNdx = 0; inputNdx < numParams; inputNdx++)
{
op << "\t" << paramPrecisionsMaybe[inputNdx] << paramTypeNames[inputNdx] << " sumIn" << (char)('A'+inputNdx) << " = ";
{
string expr = string() + "in0" + (char)('a'+inputNdx);
for (int i = 1; i < FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS; i++)
expr = sumExpr(expr, string() + "in" + de::toString(i) + (char)('a'+inputNdx), m_paramTypes[inputNdx]);
op << expr;
}
op << ";\n";
}
op << "\t" << returnPrecisionMaybe << returnTypeName << " sumRes = ";
{
string expr = "res0";
for (int i = 1; i < FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS; i++)
expr = sumExpr(expr, "res" + de::toString(i), m_returnType);
op << expr;
}
op << ";\n";
{
glu::DataType finalResultDataType = glu::TYPE_LAST;
if (glu::isDataTypeMatrix(m_returnType))
{
finalResultDataType = m_returnType;
op << "\t" << precision << " " << returnTypeName << " finalRes = ";
for (int inputNdx = 0; inputNdx < numParams; inputNdx++)
{
DE_ASSERT(m_paramTypes[inputNdx] == m_returnType);
op << "sumIn" << (char)('A'+inputNdx) << " + ";
}
op << "sumRes;\n";
}
else
{
int numFinalResComponents = glu::getDataTypeScalarSize(m_returnType);
for (int inputNdx = 0; inputNdx < numParams; inputNdx++)
numFinalResComponents = de::max(numFinalResComponents, glu::getDataTypeScalarSize(m_paramTypes[inputNdx]));
finalResultDataType = getDataTypeFloatOrVec(numFinalResComponents);
{
const string finalResType = glu::getDataTypeName(finalResultDataType);
op << "\t" << precision << " " << finalResType << " finalRes = ";
for (int inputNdx = 0; inputNdx < numParams; inputNdx++)
op << finalResType << "(sumIn" << (char)('A'+inputNdx) << ") + ";
op << finalResType << "(sumRes);\n";
}
}
// Convert to color.
op << "\tmediump vec4 color = ";
if (finalResultDataType == TYPE_FLOAT_VEC4)
op << "finalRes";
else
{
int size = isMatrixReturn ? getDataTypeMatrixNumRows(finalResultDataType) : getDataTypeScalarSize(finalResultDataType);
op << "vec4(";
if (isMatrixReturn)
{
for (int i = 0; i < getDataTypeMatrixNumColumns(finalResultDataType); i++)
{
if (i > 0)
op << " + ";
op << "finalRes[" << i << "]";
}
}
else
op << "finalRes";
for (int i = size; i < 4; i++)
op << ", " << (i == 3 ? "1.0" : "0.0");
op << ")";
}
op << ";\n";
op << "\t" << (isVertexCase ? "v_color" : "gl_FragColor") << " = color;\n";
if (isVertexCase)
{
vtx << " gl_Position = a_position + u_zero*color;\n";
frag << " gl_FragColor = v_color;\n";
}
else
{
for (int i = 0; i < numAttributes; i++)
vtx << " v_in" << i << " = a_in" << i << ";\n";
}
vtx << "}\n";
frag << "}\n";
}
{
vector<AttribSpec> attributes;
for (int i = 0; i < numAttributes; i++)
attributes.push_back(AttribSpec(("a_in" + de::toString(i)).c_str(),
m_attribute.swizzle((i+0)%4, (i+1)%4, (i+2)%4, (i+3)%4),
m_attribute.swizzle((i+1)%4, (i+2)%4, (i+3)%4, (i+0)%4),
m_attribute.swizzle((i+2)%4, (i+3)%4, (i+0)%4, (i+1)%4),
m_attribute.swizzle((i+3)%4, (i+0)%4, (i+1)%4, (i+2)%4)));
{
string description = "This is the program ";
description += programID == PROGRAM_WITHOUT_FUNCTION_CALLS ? "without"
: programID == PROGRAM_WITH_FUNCTION_CALLS ? "with"
: DE_NULL;
description += " '" + m_func + "' function calls.\n"
"Note: workload size for this program means the number of loop iterations.";
return ProgramContext(vtx.str(), frag.str(), attributes, description);
}
}
}
vector<FunctionCase::ProgramContext> FunctionCase::generateProgramData (void) const
{
vector<ProgramContext> progData;
for (int i = 0; i < PROGRAM_LAST; i++)
progData.push_back(generateSingleProgramData((ProgramID)i));
return progData;
}
void FunctionCase::setGeneralUniforms (deUint32 program) const
{
const glw::Functions& gl = m_renderCtx.getFunctions();
gl.uniform1f(gl.getUniformLocation(program, "u_zero"), 0.0f);
for (int paramNdx = 0; paramNdx < MAX_PARAMS; paramNdx++)
{
if (m_paramTypes[paramNdx] != glu::TYPE_INVALID)
{
const glu::DataType paramType = m_paramTypes[paramNdx];
const int scalarSize = glu::getDataTypeScalarSize(paramType);
const int location = gl.getUniformLocation(program, (string() + "u_inc" + (char)('A'+paramNdx)).c_str());
if (glu::isDataTypeFloatOrVec(paramType))
{
float values[4];
for (int i = 0; i < DE_LENGTH_OF_ARRAY(values); i++)
values[i] = (float)paramNdx*0.01f + (float)i*0.001f; // Arbitrary small values.
uniformNfv(gl, scalarSize, location, 1, &values[0]);
}
else if (glu::isDataTypeIntOrIVec(paramType))
{
int values[4];
for (int i = 0; i < DE_LENGTH_OF_ARRAY(values); i++)
values[i] = paramNdx*100 + i; // Arbitrary values.
uniformNiv(gl, scalarSize, location, 1, &values[0]);
}
else if (glu::isDataTypeBoolOrBVec(paramType))
{
int values[4];
for (int i = 0; i < DE_LENGTH_OF_ARRAY(values); i++)
values[i] = (paramNdx >> i) & 1; // Arbitrary values.
uniformNiv(gl, scalarSize, location, 1, &values[0]);
}
else if (glu::isDataTypeMatrix(paramType))
{
const int size = glu::getDataTypeMatrixNumRows(paramType);
DE_ASSERT(size == glu::getDataTypeMatrixNumColumns(paramType));
float values[4*4];
for (int i = 0; i < DE_LENGTH_OF_ARRAY(values); i++)
values[i] = (float)paramNdx*0.01f + (float)i*0.001f; // Arbitrary values.
uniformMatrixNfv(gl, size, location, 1, &values[0]);
}
else
DE_ASSERT(false);
}
}
}
void FunctionCase::setWorkloadSizeUniform (deUint32 program, int numLoopIterations) const
{
const glw::Functions& gl = m_renderCtx.getFunctions();
const int loc = gl.getUniformLocation(program, "u_numLoopIterations");
gl.uniform1i(loc, numLoopIterations);
}
float FunctionCase::computeSingleOperationTime (const vector<float>& perProgramOperationCosts) const
{
DE_ASSERT(perProgramOperationCosts.size() == PROGRAM_LAST);
const int numFunctionCalls = FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS;
const float programOperationCostDiff = perProgramOperationCosts[PROGRAM_WITH_FUNCTION_CALLS] - perProgramOperationCosts[PROGRAM_WITHOUT_FUNCTION_CALLS];
return programOperationCostDiff / (float)numFunctionCalls;
}
void FunctionCase::logSingleOperationCalculationInfo (void) const
{
const int numFunctionCalls = FUNCTION_CASE_NUM_INDEPENDENT_CALCULATIONS;
m_testCtx.getLog() << TestLog::Message << "Note: program " << (int)PROGRAM_WITH_FUNCTION_CALLS << " contains "
<< numFunctionCalls << " calls to '" << m_func << "' in one loop iteration; "
<< "cost of one operation is calculated as "
<< "(cost_of_workload_with_calls - cost_of_workload_without_calls) / " << numFunctionCalls << TestLog::EndMessage;
}
} // anonymous
ShaderOperatorTests::ShaderOperatorTests (Context& context)
: TestCaseGroup(context, "operator", "Operator Performance Tests")
{
}
ShaderOperatorTests::~ShaderOperatorTests (void)
{
}
void ShaderOperatorTests::init (void)
{
// Binary operator cases
static const DataType binaryOpTypes[] =
{
TYPE_FLOAT,
TYPE_FLOAT_VEC2,
TYPE_FLOAT_VEC3,
TYPE_FLOAT_VEC4,
TYPE_INT,
TYPE_INT_VEC2,
TYPE_INT_VEC3,
TYPE_INT_VEC4,
};
static const Precision precisions[] =
{
PRECISION_LOWP,
PRECISION_MEDIUMP,
PRECISION_HIGHP
};
static const struct
{
const char* name;
const char* op;
bool swizzle;
} binaryOps[] =
{
{ "add", "+", false },
{ "sub", "-", true },
{ "mul", "*", false },
{ "div", "/", true }
};
tcu::TestCaseGroup* const binaryOpsGroup = new tcu::TestCaseGroup(m_testCtx, "binary_operator", "Binary Operator Performance Tests");
addChild(binaryOpsGroup);
for (int opNdx = 0; opNdx < DE_LENGTH_OF_ARRAY(binaryOps); opNdx++)
{
tcu::TestCaseGroup* const opGroup = new tcu::TestCaseGroup(m_testCtx, binaryOps[opNdx].name, "");
binaryOpsGroup->addChild(opGroup);
for (int isFrag = 0; isFrag <= 1; isFrag++)
{
const BinaryOpCase::InitialCalibrationStorage shaderGroupCalibrationStorage (new BinaryOpCase::InitialCalibration);
const bool isVertex = isFrag == 0;
tcu::TestCaseGroup* const shaderGroup = new tcu::TestCaseGroup(m_testCtx, isVertex ? "vertex" : "fragment", "");
opGroup->addChild(shaderGroup);
for (int typeNdx = 0; typeNdx < DE_LENGTH_OF_ARRAY(binaryOpTypes); typeNdx++)
{
for (int precNdx = 0; precNdx < DE_LENGTH_OF_ARRAY(precisions); precNdx++)
{
const DataType type = binaryOpTypes[typeNdx];
const Precision precision = precisions[precNdx];
const char* const op = binaryOps[opNdx].op;
const bool useSwizzle = binaryOps[opNdx].swizzle;
std::ostringstream name;
name << getPrecisionName(precision) << "_" << getDataTypeName(type);
shaderGroup->addChild(new BinaryOpCase(m_context, name.str().c_str(), "", op, type, precision, useSwizzle, isVertex, shaderGroupCalibrationStorage));
}
}
}
}
// Built-in function cases.
// Non-specific (i.e. includes gentypes) parameter types for the functions.
enum ValueType
{
VALUE_NONE = 0,
VALUE_FLOAT = (1<<0), // float scalar
VALUE_FLOAT_VEC = (1<<1), // float vector
VALUE_FLOAT_VEC34 = (1<<2), // float vector of size 3 or 4
VALUE_FLOAT_GENTYPE = (1<<3), // float scalar/vector
VALUE_VEC3 = (1<<4), // vec3 only
VALUE_VEC4 = (1<<5), // vec4 only
VALUE_MATRIX = (1<<6), // matrix
VALUE_BOOL = (1<<7), // boolean scalar
VALUE_BOOL_VEC = (1<<8), // boolean vector
VALUE_BOOL_GENTYPE = (1<<9), // boolean scalar/vector
VALUE_INT = (1<<10), // int scalar
VALUE_INT_VEC = (1<<11), // int vector
VALUE_INT_GENTYPE = (1<<12), // int scalar/vector
// Shorthands.
N = VALUE_NONE,
F = VALUE_FLOAT,
FV = VALUE_FLOAT_VEC,
VL = VALUE_FLOAT_VEC34, // L for "large"
GT = VALUE_FLOAT_GENTYPE,
V3 = VALUE_VEC3,
V4 = VALUE_VEC4,
M = VALUE_MATRIX,
B = VALUE_BOOL,
BV = VALUE_BOOL_VEC,
BGT = VALUE_BOOL_GENTYPE,
I = VALUE_INT,
IV = VALUE_INT_VEC,
IGT = VALUE_INT_GENTYPE,
VALUE_ANY_FLOAT = VALUE_FLOAT | VALUE_FLOAT_VEC | VALUE_FLOAT_GENTYPE | VALUE_VEC3 | VALUE_VEC4 | VALUE_FLOAT_VEC34,
VALUE_ANY_INT = VALUE_INT | VALUE_INT_VEC | VALUE_INT_GENTYPE,
VALUE_ANY_BOOL = VALUE_BOOL | VALUE_BOOL_VEC | VALUE_BOOL_GENTYPE,
VALUE_ANY_GENTYPE = VALUE_FLOAT_VEC | VALUE_FLOAT_GENTYPE | VALUE_FLOAT_VEC34 |
VALUE_BOOL_VEC | VALUE_BOOL_GENTYPE |
VALUE_INT_VEC | VALUE_INT_GENTYPE |
VALUE_MATRIX
};
enum PrecisionMask
{
PRECMASK_NA = 0, //!< Precision not applicable (booleans)
PRECMASK_LOWP = (1<<PRECISION_LOWP),
PRECMASK_MEDIUMP = (1<<PRECISION_MEDIUMP),
PRECMASK_HIGHP = (1<<PRECISION_HIGHP),
PRECMASK_MEDIUMP_HIGHP = (1<<PRECISION_MEDIUMP) | (1<<PRECISION_HIGHP),
PRECMASK_ALL = (1<<PRECISION_LOWP) | (1<<PRECISION_MEDIUMP) | (1<<PRECISION_HIGHP)
};
static const DataType floatTypes[] =
{
TYPE_FLOAT,
TYPE_FLOAT_VEC2,
TYPE_FLOAT_VEC3,
TYPE_FLOAT_VEC4
};
static const DataType intTypes[] =
{
TYPE_INT,
TYPE_INT_VEC2,
TYPE_INT_VEC3,
TYPE_INT_VEC4
};
static const DataType boolTypes[] =
{
TYPE_BOOL,
TYPE_BOOL_VEC2,
TYPE_BOOL_VEC3,
TYPE_BOOL_VEC4
};
static const DataType matrixTypes[] =
{
TYPE_FLOAT_MAT2,
TYPE_FLOAT_MAT3,
TYPE_FLOAT_MAT4
};
tcu::TestCaseGroup* const angleAndTrigonometryGroup = new tcu::TestCaseGroup(m_testCtx, "angle_and_trigonometry", "Built-In Angle and Trigonometry Function Performance Tests");
tcu::TestCaseGroup* const exponentialGroup = new tcu::TestCaseGroup(m_testCtx, "exponential", "Built-In Exponential Function Performance Tests");
tcu::TestCaseGroup* const commonFunctionsGroup = new tcu::TestCaseGroup(m_testCtx, "common_functions", "Built-In Common Function Performance Tests");
tcu::TestCaseGroup* const geometricFunctionsGroup = new tcu::TestCaseGroup(m_testCtx, "geometric", "Built-In Geometric Function Performance Tests");
tcu::TestCaseGroup* const matrixFunctionsGroup = new tcu::TestCaseGroup(m_testCtx, "matrix", "Built-In Matrix Function Performance Tests");
tcu::TestCaseGroup* const floatCompareGroup = new tcu::TestCaseGroup(m_testCtx, "float_compare", "Built-In Floating Point Comparison Function Performance Tests");
tcu::TestCaseGroup* const intCompareGroup = new tcu::TestCaseGroup(m_testCtx, "int_compare", "Built-In Integer Comparison Function Performance Tests");
tcu::TestCaseGroup* const boolCompareGroup = new tcu::TestCaseGroup(m_testCtx, "bool_compare", "Built-In Boolean Comparison Function Performance Tests");
addChild(angleAndTrigonometryGroup);
addChild(exponentialGroup);
addChild(commonFunctionsGroup);
addChild(geometricFunctionsGroup);
addChild(matrixFunctionsGroup);
addChild(floatCompareGroup);
addChild(intCompareGroup);
addChild(boolCompareGroup);
// Some attributes to be used as parameters for the functions.
const Vec4 attrPos = Vec4( 2.3f, 1.9f, 0.8f, 0.7f);
const Vec4 attrNegPos = Vec4(-1.3f, 2.5f, -3.5f, 4.3f);
const Vec4 attrSmall = Vec4(-0.9f, 0.8f, -0.4f, 0.2f);
// Function name, return type and parameter type information; also, what attribute should be used in the test.
// \note Different versions of the same function (i.e. with the same group name) can be defined by putting them successively in this array.
// \note In order to reduce case count and thus total execution time, we don't test all input type combinations for every function.
static const struct
{
tcu::TestCaseGroup* parentGroup;
const char* groupName;
const char* func;
const ValueType types[FunctionCase::MAX_PARAMS + 1]; // Return type and parameter types, in that order.
const Vec4& attribute;
int modifyParamNdx;
bool useNearlyConstantInputs;
bool booleanCase;
PrecisionMask precMask;
} functionCaseGroups[] =
{
{ angleAndTrigonometryGroup, "radians", "radians", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "degrees", "degrees", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "sin", "sin", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "cos", "cos", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "tan", "tan", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "asin", "asin", { F, F, N, N }, attrSmall, -1, true, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "acos", "acos", { F, F, N, N }, attrSmall, -1, true, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "atan2", "atan", { F, F, F, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ angleAndTrigonometryGroup, "atan", "atan", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "pow", "pow", { F, F, F, N }, attrPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "exp", "exp", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "log", "log", { F, F, N, N }, attrPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "exp2", "exp2", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "log2", "log2", { F, F, N, N }, attrPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "sqrt", "sqrt", { F, F, N, N }, attrPos, -1, false, false, PRECMASK_ALL },
{ exponentialGroup, "inversesqrt", "inversesqrt", { F, F, N, N }, attrPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "abs", "abs", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "abs", "abs", { V4, V4, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "sign", "sign", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "sign", "sign", { V4, V4, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "floor", "floor", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "floor", "floor", { V4, V4, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "ceil", "ceil", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "ceil", "ceil", { V4, V4, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "fract", "fract", { F, F, N, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "fract", "fract", { V4, V4, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "mod", "mod", { GT, GT, GT, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "min", "min", { F, F, F, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "min", "min", { V4, V4, V4, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "max", "max", { F, F, F, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "max", "max", { V4, V4, V4, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "clamp", "clamp", { F, F, F, F }, attrSmall, 2, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "clamp", "clamp", { V4, V4, V4, V4 }, attrSmall, 2, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "mix", "mix", { F, F, F, F }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "mix", "mix", { V4, V4, V4, V4 }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "step", "step", { F, F, F, N }, attrNegPos, -1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "step", "step", { V4, V4, V4, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ commonFunctionsGroup, "smoothstep", "smoothstep", { F, F, F, F }, attrSmall, 1, false, false, PRECMASK_MEDIUMP_HIGHP },
{ commonFunctionsGroup, "smoothstep", "smoothstep", { V4, V4, V4, V4 }, attrSmall, 1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "length", "length", { F, VL, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "distance", "distance", { F, VL, VL, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "dot", "dot", { F, VL, VL, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "cross", "cross", { V3, V3, V3, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "normalize", "normalize", { VL, VL, N, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "faceforward", "faceforward", { VL, VL, VL, VL }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "reflect", "reflect", { VL, VL, VL, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ geometricFunctionsGroup, "refract", "refract", { VL, VL, VL, F }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ matrixFunctionsGroup, "matrixCompMult", "matrixCompMult", { M, M, M, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "lessThan", "lessThan", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "lessThanEqual", "lessThanEqual", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "greaterThan", "greaterThan", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "greaterThanEqual", "greaterThanEqual", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "equal", "equal", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ floatCompareGroup, "notEqual", "notEqual", { BV, FV, FV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "lessThan", "lessThan", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "lessThanEqual", "lessThanEqual", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "greaterThan", "greaterThan", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "greaterThanEqual", "greaterThanEqual", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "equal", "equal", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ intCompareGroup, "notEqual", "notEqual", { BV, IV, IV, N }, attrNegPos, -1, false, false, PRECMASK_ALL },
{ boolCompareGroup, "equal", "equal", { BV, BV, BV, N }, attrNegPos, -1, false, true, PRECMASK_MEDIUMP },
{ boolCompareGroup, "notEqual", "notEqual", { BV, BV, BV, N }, attrNegPos, -1, false, true, PRECMASK_MEDIUMP },
{ boolCompareGroup, "any", "any", { B, BV, N, N }, attrNegPos, -1, false, true, PRECMASK_MEDIUMP },
{ boolCompareGroup, "all", "all", { B, BV, N, N }, attrNegPos, -1, false, true, PRECMASK_MEDIUMP },
{ boolCompareGroup, "not", "not", { BV, BV, N, N }, attrNegPos, -1, false, true, PRECMASK_MEDIUMP }
};
// vertexSubGroup and fragmentSubGroup are the groups where the various vertex/fragment cases of a single function are added.
// \note These are defined here so that different versions (different entries in the functionCaseGroups array) of the same function can be put in the same group.
tcu::TestCaseGroup* vertexSubGroup = DE_NULL;
tcu::TestCaseGroup* fragmentSubGroup = DE_NULL;
FunctionCase::InitialCalibrationStorage vertexSubGroupCalibrationStorage;
FunctionCase::InitialCalibrationStorage fragmentSubGroupCalibrationStorage;
for (int funcNdx = 0; funcNdx < DE_LENGTH_OF_ARRAY(functionCaseGroups); funcNdx++)
{
tcu::TestCaseGroup* const parentGroup = functionCaseGroups[funcNdx].parentGroup;
const char* const groupName = functionCaseGroups[funcNdx].groupName;
const char* const groupFunc = functionCaseGroups[funcNdx].func;
const ValueType* const funcTypes = functionCaseGroups[funcNdx].types;
const Vec4& groupAttribute = functionCaseGroups[funcNdx].attribute;
const int modifyParamNdx = functionCaseGroups[funcNdx].modifyParamNdx;
const bool useNearlyConstantInputs = functionCaseGroups[funcNdx].useNearlyConstantInputs;
const bool booleanCase = functionCaseGroups[funcNdx].booleanCase;
const PrecisionMask precMask = functionCaseGroups[funcNdx].precMask;
// If this is a new function and not just a different version of the previously defined function, create a new group.
if (funcNdx == 0 || parentGroup != functionCaseGroups[funcNdx-1].parentGroup || string(groupName) != functionCaseGroups[funcNdx-1].groupName)
{
tcu::TestCaseGroup* const funcGroup = new tcu::TestCaseGroup(m_testCtx, groupName, "");
functionCaseGroups[funcNdx].parentGroup->addChild(funcGroup);
vertexSubGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "");
fragmentSubGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "");
funcGroup->addChild(vertexSubGroup);
funcGroup->addChild(fragmentSubGroup);
vertexSubGroupCalibrationStorage = FunctionCase::InitialCalibrationStorage(new FunctionCase::InitialCalibration);
fragmentSubGroupCalibrationStorage = FunctionCase::InitialCalibrationStorage(new FunctionCase::InitialCalibration);
}
DE_ASSERT(vertexSubGroup != DE_NULL);
DE_ASSERT(fragmentSubGroup != DE_NULL);
// Find the type size range of parameters (e.g. from 2 to 4 in case of vectors).
int genTypeFirstSize = 1;
int genTypeLastSize = 1;
// Find the first return value or parameter with a gentype (if any) and set sizes accordingly.
// \note Assumes only matching sizes gentypes are to be found, e.g. no "genType func (vec param)"
for (int i = 0; i < FunctionCase::MAX_PARAMS + 1 && genTypeLastSize == 1; i++)
{
switch (funcTypes[i])
{
case VALUE_FLOAT_VEC:
case VALUE_BOOL_VEC:
case VALUE_INT_VEC: // \note Fall-through.
genTypeFirstSize = 2;
genTypeLastSize = 4;
break;
case VALUE_FLOAT_VEC34:
genTypeFirstSize = 3;
genTypeLastSize = 4;
break;
case VALUE_FLOAT_GENTYPE:
case VALUE_BOOL_GENTYPE:
case VALUE_INT_GENTYPE: // \note Fall-through.
genTypeFirstSize = 1;
genTypeLastSize = 4;
break;
case VALUE_MATRIX:
genTypeFirstSize = 2;
genTypeLastSize = 4;
break;
// If none of the above, keep looping.
default:
break;
}
}
// Create a case for each possible size of the gentype.
for (int curSize = genTypeFirstSize; curSize <= genTypeLastSize; curSize++)
{
// Determine specific types for return value and the parameters, according to curSize. Non-gentypes not affected by curSize.
DataType types[FunctionCase::MAX_PARAMS + 1];
for (int i = 0; i < FunctionCase::MAX_PARAMS + 1; i++)
{
if (funcTypes[i] == VALUE_NONE)
types[i] = TYPE_INVALID;
else
{
int isFloat = funcTypes[i] & VALUE_ANY_FLOAT;
int isBool = funcTypes[i] & VALUE_ANY_BOOL;
int isInt = funcTypes[i] & VALUE_ANY_INT;
int isMat = funcTypes[i] == VALUE_MATRIX;
int inSize = (funcTypes[i] & VALUE_ANY_GENTYPE) ? curSize
: funcTypes[i] == VALUE_VEC3 ? 3
: funcTypes[i] == VALUE_VEC4 ? 4
: 1;
int typeArrayNdx = isMat ? inSize - 2 : inSize - 1; // \note No matrices of size 1.
types[i] = isFloat ? floatTypes[typeArrayNdx]
: isBool ? boolTypes[typeArrayNdx]
: isInt ? intTypes[typeArrayNdx]
: isMat ? matrixTypes[typeArrayNdx]
: TYPE_LAST;
}
DE_ASSERT(types[i] != TYPE_LAST);
}
// Array for just the parameter types.
DataType paramTypes[FunctionCase::MAX_PARAMS];
for (int i = 0; i < FunctionCase::MAX_PARAMS; i++)
paramTypes[i] = types[i+1];
for (int prec = (int)PRECISION_LOWP; prec < (int)PRECISION_LAST; prec++)
{
if ((precMask & (1 << prec)) == 0)
continue;
const string precisionPrefix = booleanCase ? "" : (string(getPrecisionName((Precision)prec)) + "_");
std::ostringstream caseName;
caseName << precisionPrefix;
// Write the name of each distinct parameter data type into the test case name.
for (int i = 1; i < FunctionCase::MAX_PARAMS + 1 && types[i] != TYPE_INVALID; i++)
{
if (i == 1 || types[i] != types[i-1])
{
if (i > 1)
caseName << "_";
caseName << getDataTypeName(types[i]);
}
}
for (int fragI = 0; fragI <= 1; fragI++)
{
const bool vert = fragI == 0;
tcu::TestCaseGroup* const group = vert ? vertexSubGroup : fragmentSubGroup;
group->addChild (new FunctionCase(m_context,
caseName.str().c_str(), "",
groupFunc,
types[0], paramTypes,
groupAttribute, modifyParamNdx, useNearlyConstantInputs,
(Precision)prec, vert,
vert ? vertexSubGroupCalibrationStorage : fragmentSubGroupCalibrationStorage));
}
}
}
}
}
} // Performance
} // gles2
} // deqp
|