Hash :
c1776c61
Author :
Date :
2019-11-13T11:36:35
Vulkan:Add Swiftshader configs Add Swiftshader configs to existing test instantiation macros for all ESX variants. This causes Swiftshader to be used to run end2end tests. Added detection code to know when tests are running on Swiftshader and skipping a number of fails initially. Note that when running ANGLE end2end tests within Chromium build on Win32 bots there were crashes with Swiftshader config for tests that should have been skipped. Due to this, just skipping Swiftshader configs on Win32 for now. Bug: angleproject:4081 Bug: angleproject:4092 Change-Id: I32527a62304c5fad90f645b372edf9411ca2b212 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1914126 Commit-Queue: Tobin Ehlis <tobine@google.com> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
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
//
// Copyright 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderStorageBufferTest:
// Various tests related for shader storage buffers.
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
using namespace angle;
namespace
{
struct MatrixCase
{
MatrixCase(unsigned cols,
unsigned rows,
unsigned matrixStride,
const char *computeShaderSource,
const float *inputData)
: mColumns(cols),
mRows(rows),
mMatrixStride(matrixStride),
mComputeShaderSource(computeShaderSource),
mInputdata(inputData)
{}
unsigned int mColumns;
unsigned int mRows;
unsigned int mMatrixStride;
const char *mComputeShaderSource;
const float *mInputdata;
const unsigned int kBytesPerComponent = sizeof(float);
};
struct VectorCase
{
VectorCase(unsigned components,
const char *computeShaderSource,
const GLuint *inputData,
const GLuint *expectedData)
: mComponents(components),
mComputeShaderSource(computeShaderSource),
mInputdata(inputData),
mExpectedData(expectedData)
{}
unsigned int mComponents;
const char *mComputeShaderSource;
const GLuint *mInputdata;
const GLuint *mExpectedData;
const unsigned int kBytesPerComponent = sizeof(GLuint);
};
class ShaderStorageBufferTest31 : public ANGLETest
{
protected:
ShaderStorageBufferTest31()
{
setWindowWidth(128);
setWindowHeight(128);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
// Test flakiness was noticed when reusing displays.
forceNewDisplay();
}
void runMatrixTest(const MatrixCase &matrixCase)
{
ANGLE_GL_COMPUTE_PROGRAM(program, matrixCase.mComputeShaderSource);
glUseProgram(program);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, matrixCase.mRows * matrixCase.mMatrixStride,
matrixCase.mInputdata, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, matrixCase.mRows * matrixCase.mMatrixStride, nullptr,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLfloat *ptr = reinterpret_cast<const GLfloat *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0,
matrixCase.mRows * matrixCase.mMatrixStride, GL_MAP_READ_BIT));
for (unsigned int row = 0; row < matrixCase.mRows; row++)
{
for (unsigned int col = 0; col < matrixCase.mColumns; col++)
{
GLfloat expected = matrixCase.mInputdata[row * (matrixCase.mMatrixStride /
matrixCase.kBytesPerComponent) +
col];
GLfloat actual =
*(ptr + row * (matrixCase.mMatrixStride / matrixCase.kBytesPerComponent) + col);
EXPECT_EQ(expected, actual) << " at row " << row << " and column " << col;
}
}
EXPECT_GL_NO_ERROR();
}
void runVectorTest(const VectorCase &vectorCase)
{
ANGLE_GL_COMPUTE_PROGRAM(program, vectorCase.mComputeShaderSource);
glUseProgram(program);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER,
vectorCase.mComponents * vectorCase.kBytesPerComponent, vectorCase.mInputdata,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER,
vectorCase.mComponents * vectorCase.kBytesPerComponent, nullptr,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, vectorCase.mComponents * vectorCase.kBytesPerComponent,
GL_MAP_READ_BIT));
for (unsigned int idx = 0; idx < vectorCase.mComponents; idx++)
{
EXPECT_EQ(vectorCase.mExpectedData[idx], *(ptr + idx));
}
EXPECT_GL_NO_ERROR();
}
};
// Matched block names within a shader interface must match in terms of having the same number of
// declarations with the same sequence of types.
TEST_P(ShaderStorageBufferTest31, MatchedBlockNameWithDifferentMemberType)
{
constexpr char kVS[] =
"#version 310 es\n"
"buffer blockName {\n"
" float data;\n"
"};\n"
"void main()\n"
"{\n"
"}\n";
constexpr char kFS[] =
"#version 310 es\n"
"buffer blockName {\n"
" uint data;\n"
"};\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(kVS, kFS);
EXPECT_EQ(0u, program);
}
// Linking should fail if blocks in vertex shader exceed GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS.
TEST_P(ShaderStorageBufferTest31, ExceedMaxVertexShaderStorageBlocks)
{
std::ostringstream instanceCount;
GLint maxVertexShaderStorageBlocks = 0;
glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &maxVertexShaderStorageBlocks);
EXPECT_GL_NO_ERROR();
instanceCount << maxVertexShaderStorageBlocks;
const std::string &vertexShaderSource =
"#version 310 es\n"
"layout(shared) buffer blockName {\n"
" uint data;\n"
"} instance[" +
instanceCount.str() +
" + 1];\n"
"void main()\n"
"{\n"
"}\n";
constexpr char kFS[] =
"#version 310 es\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(vertexShaderSource.c_str(), kFS);
EXPECT_EQ(0u, program);
}
// Linking should fail if the sum of the number of active shader storage blocks exceeds
// MAX_COMBINED_SHADER_STORAGE_BLOCKS.
TEST_P(ShaderStorageBufferTest31, ExceedMaxCombinedShaderStorageBlocks)
{
std::ostringstream vertexInstanceCount;
GLint maxVertexShaderStorageBlocks = 0;
glGetIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &maxVertexShaderStorageBlocks);
vertexInstanceCount << maxVertexShaderStorageBlocks;
GLint maxFragmentShaderStorageBlocks = 0;
glGetIntegerv(GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS, &maxFragmentShaderStorageBlocks);
GLint maxCombinedShaderStorageBlocks = 0;
glGetIntegerv(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, &maxCombinedShaderStorageBlocks);
EXPECT_GL_NO_ERROR();
ASSERT_GE(maxCombinedShaderStorageBlocks, maxVertexShaderStorageBlocks);
ASSERT_GE(maxCombinedShaderStorageBlocks, maxFragmentShaderStorageBlocks);
// As SPEC allows MAX_VERTEX_SHADER_STORAGE_BLOCKS and MAX_FRAGMENT_SHADER_STORAGE_BLOCKS to be
// 0, in this situation we should skip this test to prevent these unexpected compile errors.
ANGLE_SKIP_TEST_IF(maxVertexShaderStorageBlocks == 0 || maxFragmentShaderStorageBlocks == 0);
GLint fragmentShaderStorageBlocks =
maxCombinedShaderStorageBlocks - maxVertexShaderStorageBlocks + 1;
ANGLE_SKIP_TEST_IF(fragmentShaderStorageBlocks > maxFragmentShaderStorageBlocks);
std::ostringstream fragmentInstanceCount;
fragmentInstanceCount << fragmentShaderStorageBlocks;
const std::string &vertexShaderSource =
"#version 310 es\n"
"layout(shared) buffer blockName0 {\n"
" uint data;\n"
"} instance0[" +
vertexInstanceCount.str() +
"];\n"
"void main()\n"
"{\n"
"}\n";
const std::string &fragmentShaderSource =
"#version 310 es\n"
"layout(shared) buffer blockName1 {\n"
" uint data;\n"
"} instance1[" +
fragmentInstanceCount.str() +
"];\n"
"void main()\n"
"{\n"
"}\n";
GLuint program = CompileProgram(vertexShaderSource.c_str(), fragmentShaderSource.c_str());
EXPECT_EQ(0u, program);
}
// Test shader storage buffer read write.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWrite)
{
constexpr char kCS[] =
"#version 310 es\n"
"layout(local_size_x=1, local_size_y=1, local_size_z=1) in;\n"
"layout(std140, binding = 1) buffer blockName {\n"
" uint data[2];\n"
"} instanceName;\n"
"void main()\n"
"{\n"
" instanceName.data[0] = 3u;\n"
" instanceName.data[1] = 4u;\n"
"}\n";
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program.get());
constexpr unsigned int kElementCount = 2;
// The array stride are rounded up to the base alignment of a vec4 for std140 layout.
constexpr unsigned int kArrayStride = 16;
// Create shader storage buffer
GLBuffer shaderStorageBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, kElementCount * kArrayStride, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer);
// Dispath compute
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
constexpr unsigned int kExpectedValues[2] = {3u, 4u};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
void *ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kElementCount * kArrayStride,
GL_MAP_READ_BIT);
for (unsigned int idx = 0; idx < kElementCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx],
*(reinterpret_cast<const GLuint *>(reinterpret_cast<const GLbyte *>(ptr) +
idx * kArrayStride)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
EXPECT_GL_NO_ERROR();
}
// Tests modifying an existing shader storage buffer
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWriteSame)
{
// Missing PBO support in Vulkan. http://anglebug.com/3210
ANGLE_SKIP_TEST_IF(IsVulkan());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer block {
uint data;
} instance;
void main()
{
uint temp = instance.data;
instance.data = temp + 1u;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
constexpr unsigned int kInitialData = 123u;
// Create shader storage buffer
GLBuffer shaderStorageBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBytesPerComponent, &kInitialData, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer);
glDispatchCompute(1, 1, 1);
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
const void *bufferData =
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT);
constexpr unsigned int kExpectedData = 124u;
EXPECT_EQ(kExpectedData, *static_cast<const GLuint *>(bufferData));
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
// Running shader twice to make sure that the buffer gets updated correctly 123->124->125
glDispatchCompute(1, 1, 1);
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_PIXEL_BUFFER_BARRIER_BIT);
bufferData = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT);
constexpr unsigned int kExpectedData2 = 125u;
EXPECT_EQ(kExpectedData2, *static_cast<const GLuint *>(bufferData));
// Verify re-using the SSBO buffer with a PBO contains expected data.
// This will read-back from FBO using a PBO into the same SSBO buffer.
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_PIXEL_PACK_BUFFER, shaderStorageBuffer);
glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0);
EXPECT_GL_NO_ERROR();
void *mappedPtr =
glMapBufferRange(GL_PIXEL_PACK_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT);
GLColor *dataColor = static_cast<GLColor *>(mappedPtr);
EXPECT_GL_NO_ERROR();
EXPECT_EQ(GLColor::red, dataColor[0]);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
EXPECT_GL_NO_ERROR();
// Verify that binding the buffer back to the SSBO keeps the expected data.
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
const GLColor *ptr = reinterpret_cast<GLColor *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(GLColor::red, *ptr);
EXPECT_GL_NO_ERROR();
}
// Tests reading and writing to a shader storage buffer bound at an offset.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferReadWriteOffset)
{
// http://anglebug.com/4092
ANGLE_SKIP_TEST_IF(isSwiftshader());
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer block0 {
uint data[2];
} instance0;
void main()
{
instance0.data[0] = 3u;
instance0.data[1] = 4u;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program);
constexpr unsigned int kElementCount = 2;
// The array stride are rounded up to the base alignment of a vec4 for std140 layout.
constexpr unsigned int kArrayStride = 16;
// Create shader storage buffer
GLBuffer shaderStorageBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
int bufferAlignOffset;
glGetIntegerv(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &bufferAlignOffset);
constexpr int kBufferSize = kElementCount * kArrayStride;
const int kBufferOffset = kBufferSize + (kBufferSize % bufferAlignOffset);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBufferOffset + kBufferSize, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer at an offset
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer, kBufferOffset, kBufferSize);
EXPECT_GL_NO_ERROR();
glDispatchCompute(1, 1, 1);
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
// Bind the buffer at a separate location
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer, 0, kBufferSize);
EXPECT_GL_NO_ERROR();
glDispatchCompute(1, 1, 1);
glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT);
// Read back shader storage buffer
constexpr unsigned int kExpectedValues[2] = {3u, 4u};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
void *ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBufferSize, GL_MAP_READ_BIT);
for (unsigned int idx = 0; idx < kElementCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx],
*(reinterpret_cast<const GLuint *>(reinterpret_cast<const GLbyte *>(ptr) +
idx * kArrayStride)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, kBufferOffset, kBufferSize, GL_MAP_READ_BIT);
for (unsigned int idx = 0; idx < kElementCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx],
*(reinterpret_cast<const GLuint *>(reinterpret_cast<const GLbyte *>(ptr) +
idx * kArrayStride)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
EXPECT_GL_NO_ERROR();
}
// Test that access/write to vector data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferVector)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
uvec2 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
uvec2 data;
} instanceOut;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
constexpr unsigned int kComponentCount = 2;
constexpr GLuint kInputValues[kComponentCount] = {3u, 4u};
VectorCase vectorCase(kComponentCount, kComputeShaderSource, kInputValues, kInputValues);
runVectorTest(vectorCase);
}
// Test that the shader works well with an active SSBO but not statically used.
TEST_P(ShaderStorageBufferTest31, ActiveSSBOButNotStaticallyUsed)
{
// http://anglebug.com/3725
ANGLE_SKIP_TEST_IF(IsAndroid() && IsPixel2() && IsVulkan());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
uvec2 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
uvec2 data;
} instanceOut;
layout(std140, binding = 2) buffer blockC {
uvec2 data;
} instanceC;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
GLBuffer shaderStorageBufferC;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBufferC);
glBufferData(GL_SHADER_STORAGE_BUFFER, 32, nullptr, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, shaderStorageBufferC);
constexpr unsigned int kComponentCount = 2;
constexpr GLuint kInputValues[kComponentCount] = {3u, 4u};
VectorCase vectorCase(kComponentCount, kComputeShaderSource, kInputValues, kInputValues);
runVectorTest(vectorCase);
}
// Test that access/write to swizzle scalar data in shader storage block.
TEST_P(ShaderStorageBufferTest31, ScalarSwizzleTest)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
uvec2 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
uvec2 data;
} instanceOut;
void main()
{
instanceOut.data.x = instanceIn.data.y;
instanceOut.data.y = instanceIn.data.x;
}
)";
constexpr unsigned int kComponentCount = 2;
constexpr GLuint kInputValues[kComponentCount] = {3u, 4u};
constexpr GLuint kExpectedValues[kComponentCount] = {4u, 3u};
VectorCase vectorCase(kComponentCount, kComputeShaderSource, kInputValues, kExpectedValues);
runVectorTest(vectorCase);
}
// Test that access/write to swizzle vector data in shader storage block.
TEST_P(ShaderStorageBufferTest31, VectorSwizzleTest)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
uvec2 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
uvec2 data;
} instanceOut;
void main()
{
instanceOut.data.yx = instanceIn.data.xy;
}
)";
constexpr unsigned int kComponentCount = 2;
constexpr GLuint kInputValues[kComponentCount] = {3u, 4u};
constexpr GLuint kExpectedValues[kComponentCount] = {4u, 3u};
VectorCase vectorCase(kComponentCount, kComputeShaderSource, kInputValues, kExpectedValues);
runVectorTest(vectorCase);
}
// Test that access/write to swizzle vector data in column_major matrix in shader storage block.
TEST_P(ShaderStorageBufferTest31, VectorSwizzleInColumnMajorMatrixTest)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(column_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(column_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0].xyz = instanceIn.data[0].xyz;
instanceOut.data[1].xyz = instanceIn.data[1].xyz;
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kColumns * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.3, 0.0, 0.4, 0.5, 0.6, 0.0};
MatrixCase matrixCase(kRows, kColumns, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to swizzle vector data in row_major matrix in shader storage block.
TEST_P(ShaderStorageBufferTest31, VectorSwizzleInRowMajorMatrixTest)
{
ANGLE_SKIP_TEST_IF(IsAndroid());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(row_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(row_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0].xyz = instanceIn.data[0].xyz;
instanceOut.data[1].xyz = instanceIn.data[1].xyz;
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
// std140 layout requires that base alignment and stride of arrays of scalars and vectors are
// rounded up a multiple of the base alignment of a vec4.
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kRows * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.0, 0.0, 0.3, 0.4, 0.0, 0.0, 0.5, 0.6, 0.0, 0.0};
MatrixCase matrixCase(kColumns, kRows, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to scalar data in matrix in shader storage block with row major.
TEST_P(ShaderStorageBufferTest31, ScalarDataInMatrixInSSBOWithRowMajorQualifier)
{
// TODO(jiajia.qin@intel.com): Figure out why it fails on Intel Linux platform.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
ANGLE_SKIP_TEST_IF(IsAndroid());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(row_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(row_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0][0] = instanceIn.data[0][0];
instanceOut.data[0][1] = instanceIn.data[0][1];
instanceOut.data[0][2] = instanceIn.data[0][2];
instanceOut.data[1][0] = instanceIn.data[1][0];
instanceOut.data[1][1] = instanceIn.data[1][1];
instanceOut.data[1][2] = instanceIn.data[1][2];
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
// std140 layout requires that base alignment and stride of arrays of scalars and vectors are
// rounded up a multiple of the base alignment of a vec4.
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kRows * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.0, 0.0, 0.3, 0.4, 0.0, 0.0, 0.5, 0.6, 0.0, 0.0};
MatrixCase matrixCase(kColumns, kRows, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
TEST_P(ShaderStorageBufferTest31, VectorDataInMatrixInSSBOWithRowMajorQualifier)
{
ANGLE_SKIP_TEST_IF(IsAndroid());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(row_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(row_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
// std140 layout requires that base alignment and stride of arrays of scalars and vectors are
// rounded up a multiple of the base alignment of a vec4.
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kRows * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.0, 0.0, 0.3, 0.4, 0.0, 0.0, 0.5, 0.6, 0.0, 0.0};
MatrixCase matrixCase(kColumns, kRows, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
TEST_P(ShaderStorageBufferTest31, MatrixDataInSSBOWithRowMajorQualifier)
{
ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(row_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(row_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data = instanceIn.data;
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
// std140 layout requires that base alignment and stride of arrays of scalars and vectors are
// rounded up a multiple of the base alignment of a vec4.
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kRows * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.0, 0.0, 0.3, 0.4, 0.0, 0.0, 0.5, 0.6, 0.0, 0.0};
MatrixCase matrixCase(kColumns, kRows, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to scalar data in structure matrix in shader storage block with row major.
TEST_P(ShaderStorageBufferTest31, ScalarDataInMatrixInStructureInSSBOWithRowMajorQualifier)
{
// TODO(jiajia.qin@intel.com): Figure out why it fails on Intel Linux platform.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
ANGLE_SKIP_TEST_IF(IsAndroid());
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
struct S
{
mat2x3 data;
};
layout(std140, binding = 0) buffer blockIn {
layout(row_major) S s;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(row_major) S s;
} instanceOut;
void main()
{
instanceOut.s.data[0][0] = instanceIn.s.data[0][0];
instanceOut.s.data[0][1] = instanceIn.s.data[0][1];
instanceOut.s.data[0][2] = instanceIn.s.data[0][2];
instanceOut.s.data[1][0] = instanceIn.s.data[1][0];
instanceOut.s.data[1][1] = instanceIn.s.data[1][1];
instanceOut.s.data[1][2] = instanceIn.s.data[1][2];
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
// std140 layout requires that base alignment and stride of arrays of scalars and vectors are
// rounded up a multiple of the base alignment of a vec4.
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kRows * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.0, 0.0, 0.3, 0.4, 0.0, 0.0, 0.5, 0.6, 0.0, 0.0};
MatrixCase matrixCase(kColumns, kRows, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to column major matrix data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ScalarDataInMatrixInSSBO)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0][0] = instanceIn.data[0][0];
instanceOut.data[0][1] = instanceIn.data[0][1];
instanceOut.data[0][2] = instanceIn.data[0][2];
instanceOut.data[1][0] = instanceIn.data[1][0];
instanceOut.data[1][1] = instanceIn.data[1][1];
instanceOut.data[1][2] = instanceIn.data[1][2];
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kColumns * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.3, 0.0, 0.4, 0.5, 0.6, 0.0};
MatrixCase matrixCase(kRows, kColumns, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
TEST_P(ShaderStorageBufferTest31, VectorDataInMatrixInSSBOWithColumnMajorQualifier)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(column_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(column_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kColumns * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.3, 0.0, 0.4, 0.5, 0.6, 0.0};
MatrixCase matrixCase(kRows, kColumns, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
TEST_P(ShaderStorageBufferTest31, MatrixDataInSSBOWithColumnMajorQualifier)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 0) buffer blockIn {
layout(column_major) mat2x3 data;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
layout(column_major) mat2x3 data;
} instanceOut;
void main()
{
instanceOut.data = instanceIn.data;
}
)";
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 3;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kMatrixStride = 16;
constexpr float kInputDada[kColumns * (kMatrixStride / kBytesPerComponent)] = {
0.1, 0.2, 0.3, 0.0, 0.4, 0.5, 0.6, 0.0};
MatrixCase matrixCase(kRows, kColumns, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to structure data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferStructureArray)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
struct S
{
uvec2 uvData;
uint uiData[2];
};
layout(std140, binding = 0) buffer blockIn {
S s[2];
uint lastData;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
S s[2];
uint lastData;
} instanceOut;
void main()
{
instanceOut.s[0].uvData = instanceIn.s[0].uvData;
instanceOut.s[0].uiData[0] = instanceIn.s[0].uiData[0];
instanceOut.s[0].uiData[1] = instanceIn.s[0].uiData[1];
instanceOut.s[1].uvData = instanceIn.s[1].uvData;
instanceOut.s[1].uiData[0] = instanceIn.s[1].uiData[0];
instanceOut.s[1].uiData[1] = instanceIn.s[1].uiData[1];
instanceOut.lastData = instanceIn.lastData;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
std::array<GLuint, 4> kUVData = {{
1u,
2u,
0u,
0u,
}};
std::array<GLuint, 8> kUIData = {{
3u,
0u,
0u,
0u,
4u,
0u,
0u,
0u,
}};
GLuint kLastData = 5u;
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
constexpr unsigned int kStructureStride = 48;
constexpr unsigned int totalSize = kStructureStride * 2 + sizeof(kLastData);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, totalSize, nullptr, GL_STATIC_DRAW);
GLint offset = 0;
// upload data to instanceIn.s[0]
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUVData.size() * kBytesPerComponent,
kUVData.data());
offset += (kUVData.size() * kBytesPerComponent);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUIData.size() * kBytesPerComponent,
kUIData.data());
offset += (kUIData.size() * kBytesPerComponent);
// upload data to instanceIn.s[1]
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUVData.size() * kBytesPerComponent,
kUVData.data());
offset += (kUVData.size() * kBytesPerComponent);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUIData.size() * kBytesPerComponent,
kUIData.data());
offset += (kUIData.size() * kBytesPerComponent);
// upload data to instanceIn.lastData
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, sizeof(kLastData), &kLastData);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, totalSize, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
constexpr float kExpectedValues[5] = {1u, 2u, 3u, 4u, 5u};
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, totalSize, GL_MAP_READ_BIT));
// instanceOut.s[0]
EXPECT_EQ(kExpectedValues[0], *ptr);
EXPECT_EQ(kExpectedValues[1], *(ptr + 1));
EXPECT_EQ(kExpectedValues[2], *(ptr + 4));
EXPECT_EQ(kExpectedValues[3], *(ptr + 8));
// instanceOut.s[1]
ptr += kStructureStride / kBytesPerComponent;
EXPECT_EQ(kExpectedValues[0], *ptr);
EXPECT_EQ(kExpectedValues[1], *(ptr + 1));
EXPECT_EQ(kExpectedValues[2], *(ptr + 4));
EXPECT_EQ(kExpectedValues[3], *(ptr + 8));
// instanceOut.lastData
ptr += kStructureStride / kBytesPerComponent;
EXPECT_EQ(kExpectedValues[4], *(ptr));
EXPECT_GL_NO_ERROR();
}
// Test that access/write to array of array structure data in shader storage buffer.
TEST_P(ShaderStorageBufferTest31, ShaderStorageBufferStructureArrayOfArray)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
struct S
{
uvec2 uvData;
uint uiData[2];
};
layout(std140, binding = 0) buffer blockIn {
S s[3][2];
uint lastData;
} instanceIn;
layout(std140, binding = 1) buffer blockOut {
S s[3][2];
uint lastData;
} instanceOut;
void main()
{
instanceOut.s[1][0].uvData = instanceIn.s[1][0].uvData;
instanceOut.s[1][0].uiData[0] = instanceIn.s[1][0].uiData[0];
instanceOut.s[1][0].uiData[1] = instanceIn.s[1][0].uiData[1];
instanceOut.s[1][1].uvData = instanceIn.s[1][1].uvData;
instanceOut.s[1][1].uiData[0] = instanceIn.s[1][1].uiData[0];
instanceOut.s[1][1].uiData[1] = instanceIn.s[1][1].uiData[1];
instanceOut.lastData = instanceIn.lastData;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
std::array<GLuint, 4> kUVData = {{
1u,
2u,
0u,
0u,
}};
std::array<GLuint, 8> kUIData = {{
3u,
0u,
0u,
0u,
4u,
0u,
0u,
0u,
}};
GLuint kLastData = 5u;
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
constexpr unsigned int kStructureStride = 48;
constexpr unsigned int kStructureArrayDimension0 = 3;
constexpr unsigned int kStructureArrayDimension1 = 2;
constexpr unsigned int kLastDataOffset =
kStructureStride * kStructureArrayDimension0 * kStructureArrayDimension1;
constexpr unsigned int totalSize = kLastDataOffset + sizeof(kLastData);
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, totalSize, nullptr, GL_STATIC_DRAW);
// offset of instanceIn.s[1][0]
GLint offset = kStructureStride * (kStructureArrayDimension1 * 1 + 0);
GLuint uintOffset = offset / kBytesPerComponent;
// upload data to instanceIn.s[1][0]
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUVData.size() * kBytesPerComponent,
kUVData.data());
offset += (kUVData.size() * kBytesPerComponent);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUIData.size() * kBytesPerComponent,
kUIData.data());
offset += (kUIData.size() * kBytesPerComponent);
// upload data to instanceIn.s[1][1]
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUVData.size() * kBytesPerComponent,
kUVData.data());
offset += (kUVData.size() * kBytesPerComponent);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kUIData.size() * kBytesPerComponent,
kUIData.data());
// upload data to instanceIn.lastData
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kLastDataOffset, sizeof(kLastData), &kLastData);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, totalSize, nullptr, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
constexpr float kExpectedValues[5] = {1u, 2u, 3u, 4u, 5u};
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, totalSize, GL_MAP_READ_BIT));
// instanceOut.s[0][0]
EXPECT_EQ(kExpectedValues[0], *(ptr + uintOffset));
EXPECT_EQ(kExpectedValues[1], *(ptr + uintOffset + 1));
EXPECT_EQ(kExpectedValues[2], *(ptr + uintOffset + 4));
EXPECT_EQ(kExpectedValues[3], *(ptr + uintOffset + 8));
// instanceOut.s[0][1]
EXPECT_EQ(kExpectedValues[0], *(ptr + uintOffset + 12));
EXPECT_EQ(kExpectedValues[1], *(ptr + uintOffset + 13));
EXPECT_EQ(kExpectedValues[2], *(ptr + uintOffset + 16));
EXPECT_EQ(kExpectedValues[3], *(ptr + uintOffset + 20));
// instanceOut.lastData
EXPECT_EQ(kExpectedValues[4], *(ptr + (kLastDataOffset / kBytesPerComponent)));
EXPECT_GL_NO_ERROR();
}
// Test that access/write to vector data in std430 shader storage block.
TEST_P(ShaderStorageBufferTest31, VectorArrayInSSBOWithStd430Qualifier)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std430, binding = 0) buffer blockIn {
uvec2 data[2];
} instanceIn;
layout(std430, binding = 1) buffer blockOut {
uvec2 data[2];
} instanceOut;
void main()
{
instanceOut.data[0] = instanceIn.data[0];
instanceOut.data[1] = instanceIn.data[1];
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kElementCount = 2;
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kArrayStride = 8;
constexpr unsigned int kComponentCount = kArrayStride / kBytesPerComponent;
constexpr unsigned int kExpectedValues[kElementCount][kComponentCount] = {{1u, 2u}, {3u, 4u}};
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kElementCount * kArrayStride, kExpectedValues,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kElementCount * kArrayStride, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, kElementCount * kArrayStride, GL_MAP_READ_BIT));
for (unsigned int idx = 0; idx < kElementCount; idx++)
{
for (unsigned int idy = 0; idy < kComponentCount; idy++)
{
EXPECT_EQ(kExpectedValues[idx][idy], *(ptr + idx * kComponentCount + idy));
}
}
EXPECT_GL_NO_ERROR();
}
// Test that access/write to matrix data in std430 shader storage block.
TEST_P(ShaderStorageBufferTest31, MatrixInSSBOWithStd430Qualifier)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std430, binding = 0) buffer blockIn {
mat2 data;
} instanceIn;
layout(std430, binding = 1) buffer blockOut {
mat2 data;
} instanceOut;
void main()
{
instanceOut.data = instanceIn.data;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kColumns = 2;
constexpr unsigned int kRows = 2;
constexpr unsigned int kBytesPerComponent = sizeof(float);
constexpr unsigned int kMatrixStride = kRows * kBytesPerComponent;
constexpr float kInputDada[kColumns * kRows] = {0.1, 0.2, 0.4, 0.5};
MatrixCase matrixCase(kRows, kColumns, kMatrixStride, kComputeShaderSource, kInputDada);
runMatrixTest(matrixCase);
}
// Test that access/write to structure data in std430 shader storage block.
TEST_P(ShaderStorageBufferTest31, StructureInSSBOWithStd430Qualifier)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
struct S
{
uvec2 u;
};
layout(std430, binding = 0) buffer blockIn {
uint i1;
S s;
uint i2;
} instanceIn;
layout(std430, binding = 1) buffer blockOut {
uint i1;
S s;
uint i2;
} instanceOut;
void main()
{
instanceOut.i1 = instanceIn.i1;
instanceOut.s.u = instanceIn.s.u;
instanceOut.i2 = instanceIn.i2;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
GLuint kI1Data = 1u;
std::array<GLuint, 2> kUData = {{
2u,
3u,
}};
GLuint kI2Data = 4u;
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
constexpr unsigned int kStructureStartOffset = 8;
constexpr unsigned int kStructureSize = 8;
constexpr unsigned int kTotalSize = kStructureStartOffset + kStructureSize + kBytesPerComponent;
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
// upload data to instanceIn.i1
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, &kI1Data);
// upload data to instanceIn.s.u
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kStructureStartOffset, kStructureSize, kUData.data());
// upload data to instanceIn.i2
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kStructureStartOffset + kStructureSize,
kBytesPerComponent, &kI2Data);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
GLuint kExpectedValues[4] = {1u, 2u, 3u, 4u};
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kTotalSize, GL_MAP_READ_BIT));
EXPECT_EQ(kExpectedValues[0], *ptr);
ptr += (kStructureStartOffset / kBytesPerComponent);
EXPECT_EQ(kExpectedValues[1], *ptr);
EXPECT_EQ(kExpectedValues[2], *(ptr + 1));
ptr += (kStructureSize / kBytesPerComponent);
EXPECT_EQ(kExpectedValues[3], *ptr);
EXPECT_GL_NO_ERROR();
}
// Test that access/write to structure of structure data in std430 shader storage block.
TEST_P(ShaderStorageBufferTest31, StructureOfStructureInSSBOWithStd430Qualifier)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
struct S2
{
uvec3 u2;
};
struct S1
{
uvec2 u1;
S2 s2;
};
layout(std430, binding = 0) buffer blockIn {
uint i1;
S1 s1;
uint i2;
} instanceIn;
layout(std430, binding = 1) buffer blockOut {
uint i1;
S1 s1;
uint i2;
} instanceOut;
void main()
{
instanceOut.i1 = instanceIn.i1;
instanceOut.s1.u1 = instanceIn.s1.u1;
instanceOut.s1.s2.u2 = instanceIn.s1.s2.u2;
instanceOut.i2 = instanceIn.i2;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
constexpr unsigned int kStructureS1StartOffset = 16;
constexpr unsigned int kStructureS2StartOffset = 32;
constexpr unsigned int kStructureS1Size = 32;
constexpr unsigned int kTotalSize =
kStructureS1StartOffset + kStructureS1Size + kBytesPerComponent;
GLuint kI1Data = 1u;
std::array<GLuint, 2> kU1Data = {{2u, 3u}};
std::array<GLuint, 3> kU2Data = {{4u, 5u, 6u}};
GLuint kI2Data = 7u;
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
// upload data to instanceIn.i1
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, &kI1Data);
// upload data to instanceIn.s1.u1
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kStructureS1StartOffset,
kU1Data.size() * kBytesPerComponent, kU1Data.data());
// upload data to instanceIn.s1.s2.u2
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kStructureS2StartOffset,
kU2Data.size() * kBytesPerComponent, kU2Data.data());
// upload data to instanceIn.i2
glBufferSubData(GL_SHADER_STORAGE_BUFFER, kStructureS1StartOffset + kStructureS1Size,
kBytesPerComponent, &kI2Data);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
GLuint kExpectedValues[7] = {1u, 2u, 3u, 4u, 5u, 6u, 7u};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kTotalSize, GL_MAP_READ_BIT));
EXPECT_EQ(kExpectedValues[0], *ptr);
ptr += (kStructureS1StartOffset / kBytesPerComponent);
EXPECT_EQ(kExpectedValues[1], *ptr);
EXPECT_EQ(kExpectedValues[2], *(ptr + 1));
ptr += ((kStructureS2StartOffset - kStructureS1StartOffset) / kBytesPerComponent);
EXPECT_EQ(kExpectedValues[3], *ptr);
EXPECT_EQ(kExpectedValues[4], *(ptr + 1));
EXPECT_EQ(kExpectedValues[5], *(ptr + 2));
ptr += ((kStructureS1Size - kStructureS2StartOffset) / kBytesPerComponent);
EXPECT_EQ(kExpectedValues[6], *(ptr + 4));
EXPECT_GL_NO_ERROR();
}
// Test atomic memory functions.
TEST_P(ShaderStorageBufferTest31, AtomicMemoryFunctions)
{
constexpr char kCS[] = R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std140, binding = 1) buffer blockName {
uint data[2];
} instanceName;
void main()
{
instanceName.data[0] = 0u;
instanceName.data[1] = 0u;
atomicAdd(instanceName.data[0], 5u);
atomicMax(instanceName.data[1], 7u);
})";
ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
glUseProgram(program.get());
constexpr unsigned int kElementCount = 2;
// The array stride are rounded up to the base alignment of a vec4 for std140 layout.
constexpr unsigned int kArrayStride = 16;
// Create shader storage buffer
GLBuffer shaderStorageBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, kElementCount * kArrayStride, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer);
// Dispath compute
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
constexpr unsigned int kExpectedValues[2] = {5u, 7u};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
void *ptr = glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kElementCount * kArrayStride,
GL_MAP_READ_BIT);
for (unsigned int idx = 0; idx < kElementCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx],
*(reinterpret_cast<const GLuint *>(reinterpret_cast<const GLbyte *>(ptr) +
idx * kArrayStride)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
EXPECT_GL_NO_ERROR();
}
// Test multiple storage buffers work correctly when program switching. In angle, storage buffer
// bindings are updated accord to current program. If switch program, need to update storage buffer
// bindings again.
TEST_P(ShaderStorageBufferTest31, MultiStorageBuffersForMultiPrograms)
{
constexpr char kCS1[] = R"(#version 310 es
layout(local_size_x=3, local_size_y=1, local_size_z=1) in;
layout(binding = 1) buffer Output {
uint result1[];
} sb_out1;
void main()
{
highp uint offset = gl_LocalInvocationID.x;
sb_out1.result1[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 1u;
})";
constexpr char kCS2[] = R"(#version 310 es
layout(local_size_x=3, local_size_y=1, local_size_z=1) in;
layout(binding = 2) buffer Output {
uint result2[];
} sb_out2;
void main()
{
highp uint offset = gl_LocalInvocationID.x;
sb_out2.result2[gl_LocalInvocationIndex] = gl_LocalInvocationIndex + 2u;
})";
constexpr unsigned int numInvocations = 3;
int arrayStride1 = 0, arrayStride2 = 0;
GLenum props[] = {GL_ARRAY_STRIDE};
GLBuffer shaderStorageBuffer1, shaderStorageBuffer2;
ANGLE_GL_COMPUTE_PROGRAM(program1, kCS1);
ANGLE_GL_COMPUTE_PROGRAM(program2, kCS2);
EXPECT_GL_NO_ERROR();
unsigned int outVarIndex1 =
glGetProgramResourceIndex(program1.get(), GL_BUFFER_VARIABLE, "Output.result1");
glGetProgramResourceiv(program1.get(), GL_BUFFER_VARIABLE, outVarIndex1, 1, props, 1, 0,
&arrayStride1);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer1);
glBufferData(GL_SHADER_STORAGE_BUFFER, numInvocations * arrayStride1, nullptr, GL_STREAM_READ);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer1);
EXPECT_GL_NO_ERROR();
unsigned int outVarIndex2 =
glGetProgramResourceIndex(program2.get(), GL_BUFFER_VARIABLE, "Output.result2");
glGetProgramResourceiv(program2.get(), GL_BUFFER_VARIABLE, outVarIndex2, 1, props, 1, 0,
&arrayStride2);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer2);
glBufferData(GL_SHADER_STORAGE_BUFFER, numInvocations * arrayStride2, nullptr, GL_STREAM_READ);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, shaderStorageBuffer2);
EXPECT_GL_NO_ERROR();
glUseProgram(program1.get());
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glUseProgram(program2.get());
glDispatchCompute(1, 1, 1);
EXPECT_GL_NO_ERROR();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer1);
const void *ptr1 =
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 3 * arrayStride1, GL_MAP_READ_BIT);
for (unsigned int idx = 0; idx < numInvocations; idx++)
{
EXPECT_EQ(idx + 1, *((const GLuint *)((const GLbyte *)ptr1 + idx * arrayStride1)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
EXPECT_GL_NO_ERROR();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer2);
const void *ptr2 =
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 3 * arrayStride2, GL_MAP_READ_BIT);
EXPECT_GL_NO_ERROR();
for (unsigned int idx = 0; idx < numInvocations; idx++)
{
EXPECT_EQ(idx + 2, *((const GLuint *)((const GLbyte *)ptr2 + idx * arrayStride2)));
}
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
EXPECT_GL_NO_ERROR();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
EXPECT_GL_NO_ERROR();
}
// Test that function calling is supported in SSBO access chain.
TEST_P(ShaderStorageBufferTest31, FunctionCallInSSBOAccessChain)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=4) in;
highp uint getIndex (in highp uvec2 localID, uint element)
{
return localID.x + element;
}
layout(binding=0, std430) buffer Storage
{
highp uint values[];
} sb_store;
void main()
{
sb_store.values[getIndex(gl_LocalInvocationID.xy, 0u)] = gl_LocalInvocationIndex;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
}
// Test that unary operator is supported in SSBO access chain.
TEST_P(ShaderStorageBufferTest31, UnaryOperatorInSSBOAccessChain)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=4) in;
layout(binding=0, std430) buffer Storage
{
highp uint values[];
} sb_store;
void main()
{
uint invocationNdx = gl_LocalInvocationIndex;
sb_store.values[++invocationNdx] = invocationNdx;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
}
// Test that ternary operator is supported in SSBO access chain.
TEST_P(ShaderStorageBufferTest31, TernaryOperatorInSSBOAccessChain)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=4) in;
layout(binding=0, std430) buffer Storage
{
highp uint values[];
} sb_store;
void main()
{
sb_store.values[gl_LocalInvocationIndex > 2u ? gl_NumWorkGroups.x : gl_NumWorkGroups.y]
= gl_LocalInvocationIndex;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
}
// Tests that alignment is correct for bools inside a SSB and that the values
// are written correctly by a trivial shader. Currently tests only the alignment
// of the initial block.
TEST_P(ShaderStorageBufferTest31, LoadAndStoreBooleanValue)
{
// TODO(jiajia.qin@intel.com): Figure out why it fails on Intel Linux platform.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
bool b1;
bool b2;
bool b3;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
bool b1;
bool b2;
bool b3;
} sb_store;
void main()
{
sb_store.b1 = sb_load.b1;
sb_store.b2 = sb_load.b2;
sb_store.b3 = sb_load.b3;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
constexpr GLuint kB1Value = 1u;
constexpr GLuint kB2Value[2] = {0u, 1u};
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, 3 * kBytesPerComponent, nullptr, GL_STATIC_DRAW);
GLint offset = 0;
// upload data to sb_load.b1
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kBytesPerComponent, &kB1Value);
offset += kBytesPerComponent;
// upload data to sb_load.b2
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, 2 * kBytesPerComponent, kB2Value);
constexpr GLuint kStoreBufferContents[3] = {0x1BCD1234, 0x2BCD1234, 0x3BCD1234};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, 3 * kBytesPerComponent, kStoreBufferContents,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 3 * kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(kB1Value, ptr[0]);
EXPECT_EQ(kB2Value[0], ptr[1]);
EXPECT_EQ(kB2Value[1], ptr[2]);
EXPECT_GL_NO_ERROR();
}
// Tests that alignment is correct for bvecs3 inside a SSB and that the
// values are written correctly by a trivial shader. Currently tests only the
// alignment of the initial block.
TEST_P(ShaderStorageBufferTest31, LoadAndStoreBooleanVec3)
{
// TODO(jiajia.qin@intel.com): Figure out why it fails on Intel Linux platform.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
bvec3 b;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
bvec3 b;
} sb_store;
void main()
{
sb_store.b = sb_load.b;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
constexpr GLuint kBValues[3] = {1u, 0u, 1u};
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, 3 * kBytesPerComponent, nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, 3 * kBytesPerComponent, &kBValues);
constexpr GLuint kStoreBufferContents[3] = {0x1BCD1234, 0x2BCD1234, 0x3BCD1234};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, 3 * kBytesPerComponent, kStoreBufferContents,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 3 * kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(kBValues[0], ptr[0]);
EXPECT_EQ(kBValues[1], ptr[1]);
EXPECT_EQ(kBValues[2], ptr[2]);
EXPECT_GL_NO_ERROR();
}
// Tests that alignment is correct for bool + bvecs2 inside a SSB and that the
// values are written correctly by a trivial shader. Currently tests only the
// alignment of the initial block. Compare to LoadAndStoreBooleanVec3 to see how
// the alignment rules affect the memory layout.
TEST_P(ShaderStorageBufferTest31, LoadAndStoreBooleanVarAndVec2)
{
// TODO(jiajia.qin@intel.com): Figure out why it fails on Intel Linux platform.
// http://anglebug.com/1951
ANGLE_SKIP_TEST_IF(IsIntel() && IsLinux());
ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
bool b1;
bvec2 b2;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
bool b1;
bvec2 b2;
} sb_store;
void main()
{
sb_store.b1 = sb_load.b1;
sb_store.b2 = sb_load.b2;
}
)";
// https://www.khronos.org/registry/OpenGL/specs/es/3.1/es_spec_3.1.pdf
// 7.6.2.2 Standard Uniform Block Layout
// ... A structure and each structure member have a base offset and a base
// alignment, from which an aligned offset is computed by rounding the base
// offset up to a multiple of the base alignment. The base offset of the
// first member of a structure is taken from the aligned offset of the
// structure itself. ... The members of a toplevel uniform block are laid
// out in buffer storage by treating the uniform block as a structure with a
// base offset of zero.
// 1. If the member is a scalar consuming N basic machine units, the base
// alignment is N.
// 2. If the member is a two- or four-component vector with components
// consuming N basic machine units, the base alignment is 2N or 4N,
// respectively
// b1 N == 4, basic offset 0, alignment 4, is at 0..3
// b2 N == 4, basic offset 4, alignment 2*4 = 8, is at 8..16.
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
constexpr GLuint kAlignPadding = 0x1abcd789u;
constexpr GLuint kBValues[] = {1u, kAlignPadding, 0u, 1u};
constexpr unsigned int kSsbSize = sizeof(kBValues);
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kSsbSize, nullptr, GL_STATIC_DRAW);
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, kSsbSize, &kBValues);
constexpr GLuint kStoreBufferContents[4] = {0x1BCD1234, 0x2BCD1234, 0x3BCD1234, 0x3BCD1277};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kSsbSize, kStoreBufferContents, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kSsbSize, GL_MAP_READ_BIT));
EXPECT_EQ(kBValues[0], ptr[0]);
// Index 1 is padding.
EXPECT_EQ(kBValues[2], ptr[2]);
EXPECT_EQ(kBValues[3], ptr[3]);
EXPECT_GL_NO_ERROR();
}
// Test that non-structure array of arrays is supported in SSBO.
TEST_P(ShaderStorageBufferTest31, SimpleArrayOfArrays)
{
constexpr char kComputeShaderSource[] = R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
uint a[2][2][2];
uint b;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
uint a[2][2][2];
uint b;
} sb_store;
void main()
{
sb_store.a[0][0][0] = sb_load.a[0][0][0];
sb_store.a[0][0][1] = sb_load.a[0][0][1];
sb_store.a[0][1][0] = sb_load.a[0][1][0];
sb_store.a[0][1][1] = sb_load.a[0][1][1];
sb_store.a[1][0][0] = sb_load.a[1][0][0];
sb_store.a[1][0][1] = sb_load.a[1][0][1];
sb_store.a[1][1][0] = sb_load.a[1][1][0];
sb_store.a[1][1][1] = sb_load.a[1][1][1];
sb_store.b = sb_load.b;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(GLuint);
// The array stride are rounded up to the base alignment of a vec4 for std140 layout.
constexpr unsigned int kArrayStride = 16;
constexpr unsigned int kDimension0 = 2;
constexpr unsigned int kDimension1 = 2;
constexpr unsigned int kDimension2 = 2;
constexpr unsigned int kAElementCount = kDimension0 * kDimension1 * kDimension2;
constexpr unsigned int kAComponentCountPerDimension = kArrayStride / kBytesPerComponent;
constexpr unsigned int kTotalSize = kArrayStride * kAElementCount + kBytesPerComponent;
constexpr GLuint kInputADatas[kAElementCount * kAComponentCountPerDimension] = {
1u, 0u, 0u, 0u, 2u, 0u, 0u, 0u, 3u, 0u, 0u, 0u, 4u, 0u, 0u, 0u,
5u, 0u, 0u, 0u, 6u, 0u, 0u, 0u, 7u, 0u, 0u, 0u, 8u, 0u, 0u, 0u};
constexpr GLuint kInputBData = 9u;
// Create shader storage buffer
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
GLint offset = 0;
// upload data to sb_load.a
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kAElementCount * kArrayStride, kInputADatas);
offset += (kAElementCount * kArrayStride);
// upload data to sb_load.b
glBufferSubData(GL_SHADER_STORAGE_BUFFER, offset, kBytesPerComponent, &kInputBData);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kTotalSize, nullptr, GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
constexpr GLuint kExpectedADatas[kAElementCount] = {1u, 2u, 3u, 4u, 5u, 6u, 7u, 8u};
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kTotalSize, GL_MAP_READ_BIT));
for (unsigned i = 0u; i < kDimension0; i++)
{
for (unsigned j = 0u; j < kDimension1; j++)
{
for (unsigned k = 0u; k < kDimension2; k++)
{
unsigned index = i * (kDimension1 * kDimension2) + j * kDimension2 + k;
EXPECT_EQ(kExpectedADatas[index],
*(ptr + index * (kArrayStride / kBytesPerComponent)));
}
}
}
ptr += (kAElementCount * (kArrayStride / kBytesPerComponent));
EXPECT_EQ(kInputBData, *ptr);
EXPECT_GL_NO_ERROR();
}
// Test that the length of unsized array is supported.
TEST_P(ShaderStorageBufferTest31, UnsizedArrayLength)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout (local_size_x=1) in;
layout(std430, binding = 0) buffer Storage0 {
uint buf1[2];
uint buf2[];
} sb_load;
layout(std430, binding = 1) buffer Storage1 {
int unsizedArrayLength;
uint buf1[2];
uint buf2[];
} sb_store;
void main()
{
sb_store.unsizedArrayLength = sb_store.buf2.length();
for (int i = 0; i < sb_load.buf1.length(); i++) {
sb_store.buf1[i] = sb_load.buf1[i];
}
for (int i = 0; i < sb_load.buf2.length(); i++) {
sb_store.buf2[i] = sb_load.buf2[i];
}
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kLoadBlockElementCount = 5;
constexpr unsigned int kStoreBlockElementCount = 6;
constexpr unsigned int kInputValues[kLoadBlockElementCount] = {1u, 2u, 3u, 4u, 5u};
constexpr unsigned int kExpectedValues[kStoreBlockElementCount] = {3u, 1u, 2u, 3u, 4u, 5u};
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kLoadBlockElementCount * kBytesPerComponent,
&kInputValues, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kStoreBlockElementCount * kBytesPerComponent, nullptr,
GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kStoreBlockElementCount * kBytesPerComponent,
GL_MAP_READ_BIT));
for (unsigned int i = 0; i < kStoreBlockElementCount; i++)
{
EXPECT_EQ(kExpectedValues[i], *(ptr + i));
}
EXPECT_GL_NO_ERROR();
}
// Test that compond assignment operator for buffer variable is correctly handled.
TEST_P(ShaderStorageBufferTest31, CompoundAssignmentOperator)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
uint b;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
uint b;
} sb_store;
void main()
{
uint temp = 2u;
temp += sb_load.b;
sb_store.b += temp;
sb_store.b += sb_load.b;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kInputValue = 1u;
constexpr unsigned int kExpectedValue = 5u;
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBytesPerComponent, &kInputValue, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBytesPerComponent, &kInputValue, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(kExpectedValue, *ptr);
EXPECT_GL_NO_ERROR();
}
// Test that readonly binary operator for buffer variable is correctly handled.
TEST_P(ShaderStorageBufferTest31, ReadonlyBinaryOperator)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
layout(std430, binding = 0) buffer blockIn1 {
uvec2 data1;
};
layout(std430, binding = 1) buffer blockIn2 {
uvec2 data2;
};
layout(std430, binding = 2) buffer blockIn3 {
uvec2 data;
} instanceIn3;
layout(std430, binding = 3) buffer blockOut {
uvec2 data;
} instanceOut;
void main()
{
instanceOut.data = data1 + data2 + instanceIn3.data;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kComponentCount = 2;
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kInputValues1[kComponentCount] = {1u, 2u};
constexpr unsigned int kInputValues2[kComponentCount] = {3u, 4u};
constexpr unsigned int kInputValues3[kComponentCount] = {5u, 6u};
// Create shader storage buffer
GLBuffer shaderStorageBuffer[4];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, kInputValues1,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, kInputValues2,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[2]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, kInputValues3,
GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[3]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kComponentCount * kBytesPerComponent, nullptr,
GL_STATIC_DRAW);
// Bind shader storage buffer
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, shaderStorageBuffer[2]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, shaderStorageBuffer[3]);
glDispatchCompute(1, 1, 1);
glFinish();
// Read back shader storage buffer
constexpr unsigned int kExpectedValues[kComponentCount] = {9u, 12u};
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[3]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(glMapBufferRange(
GL_SHADER_STORAGE_BUFFER, 0, kComponentCount * kBytesPerComponent, GL_MAP_READ_BIT));
for (unsigned int idx = 0; idx < kComponentCount; idx++)
{
EXPECT_EQ(kExpectedValues[idx], *(ptr + idx));
}
EXPECT_GL_NO_ERROR();
}
// Test that ssbo as an argument of a function can be translated.
TEST_P(ShaderStorageBufferTest31, SSBOAsFunctionArgument)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout(local_size_x = 1) in;
layout(std430, binding = 0) buffer Block
{
uint var1;
uint var2;
};
bool compare(uint a, uint b)
{
return a == b;
}
uint increase(inout uint a)
{
a++;
return a;
}
void main(void)
{
bool isEqual = compare(var1, 2u);
if (isEqual)
{
var2 += increase(var1);
}
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned int kInputValues[2] = {2u, 2u};
constexpr unsigned int kExpectedValues[2] = {3u, 5u};
GLBuffer shaderStorageBuffer;
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, 2 * kBytesPerComponent, &kInputValues, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer);
glDispatchCompute(1, 1, 1);
glFinish();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, 2 * kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(kExpectedValues[0], *ptr);
EXPECT_EQ(kExpectedValues[1], *(ptr + 1));
EXPECT_GL_NO_ERROR();
}
// Test that ssbo as unary operand works well.
TEST_P(ShaderStorageBufferTest31, SSBOAsUnaryOperand)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout (local_size_x=1) in;
layout(binding=0, std140) buffer Storage0
{
uint b;
} sb_load;
layout(binding=1, std140) buffer Storage1
{
uint i;
} sb_store;
void main()
{
sb_store.i = +sb_load.b;
++sb_store.i;
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
glUseProgram(program);
constexpr unsigned int kBytesPerComponent = sizeof(unsigned int);
constexpr unsigned kInputValue = 1u;
constexpr unsigned int kExpectedValue = 2u;
GLBuffer shaderStorageBuffer[2];
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[0]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBytesPerComponent, &kInputValue, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
glBufferData(GL_SHADER_STORAGE_BUFFER, kBytesPerComponent, &kInputValue, GL_STATIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, shaderStorageBuffer[0]);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, shaderStorageBuffer[1]);
glDispatchCompute(1, 1, 1);
glFinish();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, shaderStorageBuffer[1]);
const GLuint *ptr = reinterpret_cast<const GLuint *>(
glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kBytesPerComponent, GL_MAP_READ_BIT));
EXPECT_EQ(kExpectedValue, *ptr);
EXPECT_GL_NO_ERROR();
}
// Test that uniform can be used as the index of buffer variable.
TEST_P(ShaderStorageBufferTest31, UniformUsedAsIndexOfBufferVariable)
{
constexpr char kComputeShaderSource[] =
R"(#version 310 es
layout (local_size_x=4) in;
layout(std140, binding = 0) uniform CB
{
uint index;
} cb;
layout(binding=0, std140) buffer Storage0
{
uint data[];
} sb_load;
layout(binding=1, std140) buffer Storage1
{
uint data[];
} sb_store;
void main()
{
sb_store.data[gl_LocalInvocationIndex] = sb_load.data[gl_LocalInvocationID.x + cb.index];
}
)";
ANGLE_GL_COMPUTE_PROGRAM(program, kComputeShaderSource);
EXPECT_GL_NO_ERROR();
}
ANGLE_INSTANTIATE_TEST_ES31(ShaderStorageBufferTest31);
} // namespace