Hash :
ef406f1b
Author :
Date :
2021-07-16T12:19:23
FrameCapture: Capture GLES1 matrix stack. Capture the modelview and projection matrix stack. This is required for GLES1 applications that do not reset the stack every frame. Bug: angleproject:6181 Change-Id: I71befc15ca287cf91fcebf9d972c7badaeb23605 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3035050 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com> Commit-Queue: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
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 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385
//
// Copyright 2019 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.
//
// FrameCapture.cpp:
// ANGLE Frame capture implementation.
//
#include "libANGLE/capture/FrameCapture.h"
#include <cerrno>
#include <cstring>
#include <fstream>
#include <string>
#include "sys/stat.h"
#include "common/angle_version.h"
#include "common/mathutil.h"
#include "common/string_utils.h"
#include "common/system_utils.h"
#include "libANGLE/Config.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/Fence.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/GLES1Renderer.h"
#include "libANGLE/Query.h"
#include "libANGLE/ResourceMap.h"
#include "libANGLE/Shader.h"
#include "libANGLE/Surface.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/capture/capture_gles_1_0_autogen.h"
#include "libANGLE/capture/capture_gles_2_0_autogen.h"
#include "libANGLE/capture/capture_gles_3_0_autogen.h"
#include "libANGLE/capture/capture_gles_3_1_autogen.h"
#include "libANGLE/capture/capture_gles_3_2_autogen.h"
#include "libANGLE/capture/capture_gles_ext_autogen.h"
#include "libANGLE/capture/frame_capture_utils.h"
#include "libANGLE/capture/gl_enum_utils.h"
#include "libANGLE/queryconversions.h"
#include "libANGLE/queryutils.h"
#define USE_SYSTEM_ZLIB
#include "compression_utils_portable.h"
#if !ANGLE_CAPTURE_ENABLED
# error Frame capture must be enabled to include this file.
#endif // !ANGLE_CAPTURE_ENABLED
namespace angle
{
namespace
{
constexpr char kEnabledVarName[] = "ANGLE_CAPTURE_ENABLED";
constexpr char kOutDirectoryVarName[] = "ANGLE_CAPTURE_OUT_DIR";
constexpr char kFrameStartVarName[] = "ANGLE_CAPTURE_FRAME_START";
constexpr char kFrameEndVarName[] = "ANGLE_CAPTURE_FRAME_END";
constexpr char kCaptureTriggerVarName[] = "ANGLE_CAPTURE_TRIGGER";
constexpr char kCaptureLabel[] = "ANGLE_CAPTURE_LABEL";
constexpr char kCompression[] = "ANGLE_CAPTURE_COMPRESSION";
constexpr char kSerializeStateEnabledVarName[] = "ANGLE_CAPTURE_SERIALIZE_STATE";
constexpr size_t kBinaryAlignment = 16;
constexpr size_t kFunctionSizeLimit = 5000;
// Limit based on MSVC Compiler Error C2026
constexpr size_t kStringLengthLimit = 16380;
// Android debug properties that correspond to the above environment variables
constexpr char kAndroidCaptureEnabled[] = "debug.angle.capture.enabled";
constexpr char kAndroidOutDir[] = "debug.angle.capture.out_dir";
constexpr char kAndroidFrameStart[] = "debug.angle.capture.frame_start";
constexpr char kAndroidFrameEnd[] = "debug.angle.capture.frame_end";
constexpr char kAndroidCaptureTrigger[] = "debug.angle.capture.trigger";
constexpr char kAndroidCaptureLabel[] = "debug.angle.capture.label";
constexpr char kAndroidCompression[] = "debug.angle.capture.compression";
std::string GetDefaultOutDirectory()
{
#if defined(ANGLE_PLATFORM_ANDROID)
std::string path = "/sdcard/Android/data/";
// Linux interface to get application id of the running process
FILE *cmdline = fopen("/proc/self/cmdline", "r");
char applicationId[512];
if (cmdline)
{
fread(applicationId, 1, sizeof(applicationId), cmdline);
fclose(cmdline);
// Some package may have application id as <app_name>:<cmd_name>
char *colonSep = strchr(applicationId, ':');
if (colonSep)
{
*colonSep = '\0';
}
}
else
{
ERR() << "not able to lookup application id";
}
constexpr char kAndroidOutputSubdir[] = "/angle_capture/";
path += std::string(applicationId) + kAndroidOutputSubdir;
// Check for existance of output path
struct stat dir_stat;
if (stat(path.c_str(), &dir_stat) == -1)
{
ERR() << "Output directory '" << path
<< "' does not exist. Create it over adb using mkdir.";
}
return path;
#else
return std::string("./");
#endif // defined(ANGLE_PLATFORM_ANDROID)
}
std::string GetCaptureTrigger()
{
return GetEnvironmentVarOrUnCachedAndroidProperty(kCaptureTriggerVarName,
kAndroidCaptureTrigger);
}
std::ostream &operator<<(std::ostream &os, gl::ContextID contextId)
{
os << static_cast<int>(contextId.value);
return os;
}
constexpr static gl::ContextID kSharedContextId = {0};
struct FmtCapturePrefix
{
FmtCapturePrefix(gl::ContextID contextIdIn, const std::string &captureLabelIn)
: contextId(contextIdIn), captureLabel(captureLabelIn)
{}
gl::ContextID contextId;
const std::string &captureLabel;
};
std::ostream &operator<<(std::ostream &os, const FmtCapturePrefix &fmt)
{
if (fmt.captureLabel.empty())
{
os << "angle";
}
else
{
os << fmt.captureLabel;
}
if (fmt.contextId != kSharedContextId)
{
os << "_capture_context" << fmt.contextId;
}
return os;
}
enum class ReplayFunc
{
Replay,
Setup,
Reset,
};
constexpr uint32_t kNoPartId = std::numeric_limits<uint32_t>::max();
struct FmtReplayFunction
{
FmtReplayFunction(gl::ContextID contextIdIn,
uint32_t frameIndexIn,
uint32_t partIdIn = kNoPartId)
: contextId(contextIdIn), frameIndex(frameIndexIn), partId(partIdIn)
{}
gl::ContextID contextId;
uint32_t frameIndex;
uint32_t partId;
};
std::ostream &operator<<(std::ostream &os, const FmtReplayFunction &fmt)
{
os << "ReplayContext";
if (fmt.contextId == kSharedContextId)
{
os << "Shared";
}
else
{
os << fmt.contextId;
}
os << "Frame" << fmt.frameIndex;
if (fmt.partId != kNoPartId)
{
os << "Part" << fmt.partId;
}
os << "()";
return os;
}
struct FmtSetupFunction
{
FmtSetupFunction(uint32_t partIdIn, gl::ContextID contextIdIn)
: partId(partIdIn), contextId(contextIdIn)
{}
uint32_t partId;
gl::ContextID contextId;
};
std::ostream &operator<<(std::ostream &os, const FmtSetupFunction &fmt)
{
os << "SetupReplayContext";
if (fmt.contextId == kSharedContextId)
{
os << "Shared";
}
else
{
os << fmt.contextId;
}
if (fmt.partId != kNoPartId)
{
os << "Part" << fmt.partId;
}
os << "()";
return os;
}
struct FmtResetFunction
{
FmtResetFunction() {}
};
std::ostream &operator<<(std::ostream &os, const FmtResetFunction &fmt)
{
os << "ResetReplay()";
return os;
}
struct FmtFunction
{
FmtFunction(ReplayFunc funcTypeIn,
gl::ContextID contextIdIn,
uint32_t frameIndexIn,
uint32_t partIdIn)
: funcType(funcTypeIn), contextId(contextIdIn), frameIndex(frameIndexIn), partId(partIdIn)
{}
ReplayFunc funcType;
gl::ContextID contextId;
uint32_t frameIndex;
uint32_t partId;
};
std::ostream &operator<<(std::ostream &os, const FmtFunction &fmt)
{
switch (fmt.funcType)
{
case ReplayFunc::Replay:
os << FmtReplayFunction(fmt.contextId, fmt.frameIndex, fmt.partId);
break;
case ReplayFunc::Setup:
os << FmtSetupFunction(fmt.partId, fmt.contextId);
break;
case ReplayFunc::Reset:
os << FmtResetFunction();
break;
default:
UNREACHABLE();
break;
}
return os;
}
struct FmtGetSerializedContextStateFunction
{
FmtGetSerializedContextStateFunction(gl::ContextID contextIdIn, uint32_t frameIndexIn)
: contextId(contextIdIn), frameIndex(frameIndexIn)
{}
gl::ContextID contextId;
uint32_t frameIndex;
};
std::ostream &operator<<(std::ostream &os, const FmtGetSerializedContextStateFunction &fmt)
{
os << "GetSerializedContext" << fmt.contextId << "StateFrame" << fmt.frameIndex << "Data()";
return os;
}
std::string GetCaptureFileName(gl::ContextID contextId,
const std::string &captureLabel,
uint32_t frameIndex,
const char *suffix)
{
std::stringstream fnameStream;
fnameStream << FmtCapturePrefix(contextId, captureLabel) << "_frame" << std::setfill('0')
<< std::setw(3) << frameIndex << suffix;
return fnameStream.str();
}
std::string GetCaptureFilePath(const std::string &outDir,
gl::ContextID contextId,
const std::string &captureLabel,
uint32_t frameIndex,
const char *suffix)
{
return outDir + GetCaptureFileName(contextId, captureLabel, frameIndex, suffix);
}
void WriteParamStaticVarName(const CallCapture &call,
const ParamCapture ¶m,
int counter,
std::ostream &out)
{
out << call.name() << "_" << param.name << "_" << counter;
}
void WriteGLFloatValue(std::ostream &out, GLfloat value)
{
// Check for non-representable values
ASSERT(std::numeric_limits<float>::has_infinity);
ASSERT(std::numeric_limits<float>::has_quiet_NaN);
if (std::isinf(value))
{
float negativeInf = -std::numeric_limits<float>::infinity();
if (value == negativeInf)
{
out << "-";
}
out << "std::numeric_limits<float>::infinity()";
}
else if (std::isnan(value))
{
out << "std::numeric_limits<float>::quiet_NaN()";
}
else
{
out << std::setprecision(16);
out << value;
}
}
template <typename T, typename CastT = T>
void WriteInlineData(const std::vector<uint8_t> &vec, std::ostream &out)
{
const T *data = reinterpret_cast<const T *>(vec.data());
size_t count = vec.size() / sizeof(T);
if (data == nullptr)
{
return;
}
out << static_cast<CastT>(data[0]);
for (size_t dataIndex = 1; dataIndex < count; ++dataIndex)
{
out << ", " << static_cast<CastT>(data[dataIndex]);
}
}
template <>
void WriteInlineData<GLchar>(const std::vector<uint8_t> &vec, std::ostream &out)
{
const GLchar *data = reinterpret_cast<const GLchar *>(vec.data());
size_t count = vec.size() / sizeof(GLchar);
if (data == nullptr || data[0] == '\0')
{
return;
}
out << "\"";
for (size_t dataIndex = 0; dataIndex < count; ++dataIndex)
{
if (data[dataIndex] == '\0')
break;
out << static_cast<GLchar>(data[dataIndex]);
}
out << "\"";
}
void WriteStringParamReplay(std::ostream &out, const ParamCapture ¶m)
{
const std::vector<uint8_t> &data = param.data[0];
// null terminate C style string
ASSERT(data.size() > 0 && data.back() == '\0');
std::string str(data.begin(), data.end() - 1);
out << "\"" << str << "\"";
}
void WriteStringPointerParamReplay(DataTracker *dataTracker,
std::ostream &out,
std::ostream &header,
const CallCapture &call,
const ParamCapture ¶m)
{
// Concatenate the strings to ensure we get an accurate counter
std::vector<std::string> strings;
for (const std::vector<uint8_t> &data : param.data)
{
// null terminate C style string
ASSERT(data.size() > 0 && data.back() == '\0');
strings.emplace_back(data.begin(), data.end() - 1);
}
int counter = dataTracker->getStringCounters().getStringCounter(strings);
if (counter == kStringsNotFound)
{
// This is a unique set of strings, so set up their declaration and update the counter
counter = dataTracker->getCounters().getAndIncrement(call.entryPoint, param.name);
dataTracker->getStringCounters().setStringCounter(strings, counter);
header << "const char* const ";
WriteParamStaticVarName(call, param, counter, header);
header << "[] = { \n";
for (const std::string &str : strings)
{
// Break up long strings for MSVC
size_t copyLength = 0;
std::string separator;
for (size_t i = 0; i < str.length(); i += kStringLengthLimit)
{
if ((str.length() - i) <= kStringLengthLimit)
{
copyLength = str.length() - i;
separator = ",";
}
else
{
copyLength = kStringLengthLimit;
separator = "";
}
header << " R\"(" << str.substr(i, copyLength) << ")\"" << separator << "\n";
}
}
header << " };\n";
}
ASSERT(counter >= 0);
WriteParamStaticVarName(call, param, counter, out);
}
template <typename ParamT>
void WriteResourceIDPointerParamReplay(DataTracker *dataTracker,
std::ostream &out,
std::ostream &header,
const CallCapture &call,
const ParamCapture ¶m)
{
int counter = dataTracker->getCounters().getAndIncrement(call.entryPoint, param.name);
header << "const GLuint ";
WriteParamStaticVarName(call, param, counter, header);
header << "[] = { ";
const ResourceIDType resourceIDType = GetResourceIDTypeFromParamType(param.type);
ASSERT(resourceIDType != ResourceIDType::InvalidEnum);
const char *name = GetResourceIDTypeName(resourceIDType);
ASSERT(param.dataNElements > 0);
ASSERT(param.data.size() == 1);
const ParamT *returnedIDs = reinterpret_cast<const ParamT *>(param.data[0].data());
for (GLsizei resIndex = 0; resIndex < param.dataNElements; ++resIndex)
{
ParamT id = returnedIDs[resIndex];
if (resIndex > 0)
{
header << ", ";
}
header << "g" << name << "Map[" << id.value << "]";
}
header << " };\n ";
WriteParamStaticVarName(call, param, counter, out);
}
void WriteBinaryParamReplay(DataTracker *dataTracker,
std::ostream &out,
std::ostream &header,
const CallCapture &call,
const ParamCapture ¶m,
std::vector<uint8_t> *binaryData)
{
int counter = dataTracker->getCounters().getAndIncrement(call.entryPoint, param.name);
ASSERT(param.data.size() == 1);
const std::vector<uint8_t> &data = param.data[0];
ParamType overrideType = param.type;
if (param.type == ParamType::TGLvoidConstPointer || param.type == ParamType::TvoidConstPointer)
{
overrideType = ParamType::TGLubyteConstPointer;
}
if (overrideType == ParamType::TGLenumConstPointer || overrideType == ParamType::TGLcharPointer)
{
// Inline if data are of type string or enum
std::string paramTypeString = ParamTypeToString(param.type);
header << paramTypeString.substr(0, paramTypeString.length() - 1);
WriteParamStaticVarName(call, param, counter, header);
header << "[] = { ";
if (overrideType == ParamType::TGLenumConstPointer)
{
WriteInlineData<GLuint>(data, header);
}
else
{
ASSERT(overrideType == ParamType::TGLcharPointer);
WriteInlineData<GLchar>(data, header);
}
header << " };\n";
WriteParamStaticVarName(call, param, counter, out);
}
else
{
// Store in binary file if data are not of type string or enum
// Round up to 16-byte boundary for cross ABI safety
size_t offset = rx::roundUpPow2(binaryData->size(), kBinaryAlignment);
binaryData->resize(offset + data.size());
memcpy(binaryData->data() + offset, data.data(), data.size());
out << "reinterpret_cast<" << ParamTypeToString(overrideType) << ">(&gBinaryData[" << offset
<< "])";
}
}
uintptr_t SyncIndexValue(GLsync sync)
{
return reinterpret_cast<uintptr_t>(sync);
}
void WriteCppReplayForCall(const CallCapture &call,
DataTracker *dataTracker,
std::ostream &out,
std::ostream &header,
std::vector<uint8_t> *binaryData)
{
std::ostringstream callOut;
if (call.entryPoint == EntryPoint::GLCreateShader ||
call.entryPoint == EntryPoint::GLCreateProgram ||
call.entryPoint == EntryPoint::GLCreateShaderProgramv)
{
GLuint id = call.params.getReturnValue().value.GLuintVal;
callOut << "gShaderProgramMap[" << id << "] = ";
}
if (call.entryPoint == EntryPoint::GLFenceSync)
{
GLsync sync = call.params.getReturnValue().value.GLsyncVal;
callOut << "gSyncMap[" << SyncIndexValue(sync) << "] = ";
}
// Depending on how a buffer is mapped, we may need to track its location for readback
bool trackBufferPointer = false;
if (call.entryPoint == EntryPoint::GLMapBufferRange ||
call.entryPoint == EntryPoint::GLMapBufferRangeEXT)
{
GLbitfield access =
call.params.getParam("access", ParamType::TGLbitfield, 3).value.GLbitfieldVal;
trackBufferPointer = access & GL_MAP_WRITE_BIT;
}
if (call.entryPoint == EntryPoint::GLMapBuffer || call.entryPoint == EntryPoint::GLMapBufferOES)
{
GLenum access = call.params.getParam("access", ParamType::TGLenum, 1).value.GLenumVal;
trackBufferPointer =
access == GL_WRITE_ONLY_OES || access == GL_WRITE_ONLY || access == GL_READ_WRITE;
}
if (trackBufferPointer)
{
// Track the returned pointer so we update its data when unmapped
gl::BufferID bufferID = call.params.getMappedBufferID();
callOut << "gMappedBufferData[";
WriteParamValueReplay<ParamType::TBufferID>(callOut, call, bufferID);
callOut << "] = ";
}
callOut << call.name() << "(";
bool first = true;
for (const ParamCapture ¶m : call.params.getParamCaptures())
{
if (!first)
{
callOut << ", ";
}
if (param.arrayClientPointerIndex != -1 && param.value.voidConstPointerVal != nullptr)
{
callOut << "gClientArrays[" << param.arrayClientPointerIndex << "]";
}
else if (param.readBufferSizeBytes > 0)
{
callOut << "reinterpret_cast<" << ParamTypeToString(param.type) << ">(gReadBuffer)";
}
else if (param.data.empty())
{
if (param.type == ParamType::TGLenum)
{
OutputGLenumString(callOut, param.enumGroup, param.value.GLenumVal);
}
else if (param.type == ParamType::TGLbitfield)
{
OutputGLbitfieldString(callOut, param.enumGroup, param.value.GLbitfieldVal);
}
else if (param.type == ParamType::TGLfloat)
{
WriteGLFloatValue(callOut, param.value.GLfloatVal);
}
else if (param.type == ParamType::TGLsync)
{
callOut << "gSyncMap[" << SyncIndexValue(param.value.GLsyncVal) << "]";
}
else if (param.type == ParamType::TGLuint64 && param.name == "timeout")
{
if (param.value.GLuint64Val == GL_TIMEOUT_IGNORED)
{
callOut << "GL_TIMEOUT_IGNORED";
}
else
{
WriteParamCaptureReplay(callOut, call, param);
}
}
else
{
WriteParamCaptureReplay(callOut, call, param);
}
}
else
{
switch (param.type)
{
case ParamType::TGLcharConstPointer:
WriteStringParamReplay(callOut, param);
break;
case ParamType::TGLcharConstPointerPointer:
WriteStringPointerParamReplay(dataTracker, callOut, header, call, param);
break;
case ParamType::TBufferIDConstPointer:
WriteResourceIDPointerParamReplay<gl::BufferID>(dataTracker, callOut, out, call,
param);
break;
case ParamType::TFenceNVIDConstPointer:
WriteResourceIDPointerParamReplay<gl::FenceNVID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TFramebufferIDConstPointer:
WriteResourceIDPointerParamReplay<gl::FramebufferID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TMemoryObjectIDConstPointer:
WriteResourceIDPointerParamReplay<gl::MemoryObjectID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TProgramPipelineIDConstPointer:
WriteResourceIDPointerParamReplay<gl::ProgramPipelineID>(dataTracker, callOut,
out, call, param);
break;
case ParamType::TQueryIDConstPointer:
WriteResourceIDPointerParamReplay<gl::QueryID>(dataTracker, callOut, out, call,
param);
break;
case ParamType::TRenderbufferIDConstPointer:
WriteResourceIDPointerParamReplay<gl::RenderbufferID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TSamplerIDConstPointer:
WriteResourceIDPointerParamReplay<gl::SamplerID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TSemaphoreIDConstPointer:
WriteResourceIDPointerParamReplay<gl::SemaphoreID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TTextureIDConstPointer:
WriteResourceIDPointerParamReplay<gl::TextureID>(dataTracker, callOut, out,
call, param);
break;
case ParamType::TTransformFeedbackIDConstPointer:
WriteResourceIDPointerParamReplay<gl::TransformFeedbackID>(dataTracker, callOut,
out, call, param);
break;
case ParamType::TVertexArrayIDConstPointer:
WriteResourceIDPointerParamReplay<gl::VertexArrayID>(dataTracker, callOut, out,
call, param);
break;
default:
WriteBinaryParamReplay(dataTracker, callOut, header, call, param, binaryData);
break;
}
}
first = false;
}
callOut << ")";
out << callOut.str();
}
size_t MaxClientArraySize(const gl::AttribArray<size_t> &clientArraySizes)
{
size_t found = 0;
for (size_t size : clientArraySizes)
{
if (size > found)
{
found = size;
}
}
return found;
}
struct SaveFileHelper
{
public:
// We always use ios::binary to avoid inconsistent line endings when captured on Linux vs Win.
SaveFileHelper(const std::string &filePathIn)
: mOfs(filePathIn, std::ios::binary | std::ios::out), mFilePath(filePathIn)
{
if (!mOfs.is_open())
{
FATAL() << "Could not open " << filePathIn;
}
}
~SaveFileHelper() { printf("Saved '%s'.\n", mFilePath.c_str()); }
template <typename T>
SaveFileHelper &operator<<(const T &value)
{
mOfs << value;
if (mOfs.bad())
{
FATAL() << "Error writing to " << mFilePath;
}
return *this;
}
void write(const uint8_t *data, size_t size)
{
mOfs.write(reinterpret_cast<const char *>(data), size);
}
private:
std::ofstream mOfs;
std::string mFilePath;
};
std::string GetBinaryDataFilePath(bool compression,
gl::ContextID contextId,
const std::string &captureLabel)
{
std::stringstream fnameStream;
fnameStream << FmtCapturePrefix(contextId, captureLabel) << ".angledata";
if (compression)
{
fnameStream << ".gz";
}
return fnameStream.str();
}
void SaveBinaryData(bool compression,
const std::string &outDir,
gl::ContextID contextId,
const std::string &captureLabel,
const std::vector<uint8_t> &binaryData)
{
std::string binaryDataFileName = GetBinaryDataFilePath(compression, contextId, captureLabel);
std::string dataFilepath = outDir + binaryDataFileName;
SaveFileHelper saveData(dataFilepath);
if (compression)
{
// Save compressed data.
uLong uncompressedSize = static_cast<uLong>(binaryData.size());
uLong expectedCompressedSize = zlib_internal::GzipExpectedCompressedSize(uncompressedSize);
std::vector<uint8_t> compressedData(expectedCompressedSize, 0);
uLong compressedSize = expectedCompressedSize;
int zResult = zlib_internal::GzipCompressHelper(compressedData.data(), &compressedSize,
binaryData.data(), uncompressedSize,
nullptr, nullptr);
if (zResult != Z_OK)
{
FATAL() << "Error compressing binary data: " << zResult;
}
saveData.write(compressedData.data(), compressedSize);
}
else
{
saveData.write(binaryData.data(), binaryData.size());
}
}
void WriteInitReplayCall(bool compression,
std::ostream &out,
gl::ContextID contextId,
const std::string &captureLabel,
size_t maxClientArraySize,
size_t readBufferSize)
{
std::string binaryDataFileName = GetBinaryDataFilePath(compression, contextId, captureLabel);
out << " InitializeReplay(\"" << binaryDataFileName << "\", " << maxClientArraySize << ", "
<< readBufferSize << ");\n";
}
// TODO (http://anglebug.com/4599): Reset more state on frame loop
void MaybeResetResources(std::stringstream &out,
ResourceIDType resourceIDType,
DataTracker *dataTracker,
std::stringstream &header,
ResourceTracker *resourceTracker,
std::vector<uint8_t> *binaryData)
{
switch (resourceIDType)
{
case ResourceIDType::Buffer:
{
TrackedResource &trackedBuffers =
resourceTracker->getTrackedResource(ResourceIDType::Buffer);
ResourceSet &newBuffers = trackedBuffers.getNewResources();
ResourceCalls &bufferRegenCalls = trackedBuffers.getResourceRegenCalls();
ResourceCalls &bufferRestoreCalls = trackedBuffers.getResourceRestoreCalls();
BufferCalls &bufferMapCalls = resourceTracker->getBufferMapCalls();
BufferCalls &bufferUnmapCalls = resourceTracker->getBufferUnmapCalls();
// If we have any new buffers generated and not deleted during the run, delete them now
if (!newBuffers.empty())
{
out << " const GLuint deleteBuffers[] = {";
ResourceSet::iterator bufferIter = newBuffers.begin();
for (size_t i = 0; bufferIter != newBuffers.end(); ++i, ++bufferIter)
{
if (i > 0)
{
out << ", ";
}
if ((i % 4) == 0)
{
out << "\n ";
}
out << "gBufferMap[" << *bufferIter << "]";
}
out << "};\n";
out << " glDeleteBuffers(" << newBuffers.size() << ", deleteBuffers);\n";
}
// If any of our starting buffers were deleted during the run, recreate them
ResourceSet &buffersToRegen = trackedBuffers.getResourcesToRegen();
for (GLuint id : buffersToRegen)
{
// Emit their regen calls
for (CallCapture &call : bufferRegenCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
// If any of our starting buffers were modified during the run, restore their contents
ResourceSet &buffersToRestore = trackedBuffers.getResourcesToRestore();
for (GLuint id : buffersToRestore)
{
if (resourceTracker->getStartingBuffersMappedCurrent(id))
{
// Some drivers require the buffer to be unmapped before you can update data,
// which violates the spec. See gl::Buffer::bufferDataImpl().
for (CallCapture &call : bufferUnmapCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
// Emit their restore calls
for (CallCapture &call : bufferRestoreCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
// Also note that this buffer has been implicitly unmapped by this call
resourceTracker->setBufferUnmapped(id);
}
}
// Update the map/unmap of buffers to match the starting state
ResourceSet startingBuffers = trackedBuffers.getStartingResources();
for (GLuint id : startingBuffers)
{
// If the buffer was mapped at the start, but is not mapped now, we need to map
if (resourceTracker->getStartingBuffersMappedInitial(id) &&
!resourceTracker->getStartingBuffersMappedCurrent(id))
{
// Emit their map calls
for (CallCapture &call : bufferMapCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
// If the buffer was unmapped at the start, but is mapped now, we need to unmap
if (!resourceTracker->getStartingBuffersMappedInitial(id) &&
resourceTracker->getStartingBuffersMappedCurrent(id))
{
// Emit their unmap calls
for (CallCapture &call : bufferUnmapCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
}
// Restore buffer bindings as seen during MEC
std::vector<CallCapture> &bufferBindingCalls = resourceTracker->getBufferBindingCalls();
for (CallCapture &call : bufferBindingCalls)
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
break;
}
case ResourceIDType::ShaderProgram:
{
ResourceSet &newPrograms =
resourceTracker->getTrackedResource(ResourceIDType::ShaderProgram)
.getNewResources();
// If we have any new programs created and not deleted during the run, delete them now
for (const auto &newProgram : newPrograms)
{
out << " glDeleteProgram(gShaderProgramMap[" << newProgram << "]);\n";
}
// TODO (http://anglebug.com/5968): Handle programs that need regen
// This would only happen if a starting program was deleted during the run
ASSERT(resourceTracker->getTrackedResource(ResourceIDType::ShaderProgram)
.getResourcesToRegen()
.empty());
break;
}
case ResourceIDType::Texture:
{
TrackedResource &trackedTextures =
resourceTracker->getTrackedResource(ResourceIDType::Texture);
ResourceSet &newTextures = trackedTextures.getNewResources();
ResourceCalls &textureRegenCalls = trackedTextures.getResourceRegenCalls();
ResourceCalls &textureRestoreCalls = trackedTextures.getResourceRestoreCalls();
// If we have any new textures generated and not deleted during the run, delete them now
if (!newTextures.empty())
{
out << " const GLuint deleteTextures[] = {";
ResourceSet::iterator textureIter = newTextures.begin();
for (size_t i = 0; textureIter != newTextures.end(); ++i, ++textureIter)
{
if (i > 0)
{
out << ", ";
}
if ((i % 4) == 0)
{
out << "\n ";
}
out << "gTextureMap[" << *textureIter << "]";
}
out << "};\n";
out << " glDeleteTextures(" << newTextures.size() << ", deleteTextures);\n";
}
// If any of our starting textures were deleted during the run, regen them
ResourceSet &texturesToRegen = trackedTextures.getResourcesToRegen();
for (GLuint id : texturesToRegen)
{
// Emit their regen calls
for (CallCapture &call : textureRegenCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
// If any of our starting textures were modified during the run, restore their contents
ResourceSet &texturesToRestore = trackedTextures.getResourcesToRestore();
for (GLuint id : texturesToRestore)
{
// Emit their restore calls
for (CallCapture &call : textureRestoreCalls[id])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
break;
}
default:
// TODO (http://anglebug.com/4599): Reset more than just buffers
break;
}
}
void MaybeResetFenceSyncObjects(std::stringstream &out,
DataTracker *dataTracker,
std::stringstream &header,
ResourceTracker *resourceTracker,
std::vector<uint8_t> *binaryData)
{
FenceSyncCalls &fenceSyncRegenCalls = resourceTracker->getFenceSyncRegenCalls();
// If any of our starting fence sync objects were deleted during the run, recreate them
FenceSyncSet &fenceSyncsToRegen = resourceTracker->getFenceSyncsToRegen();
for (const GLsync sync : fenceSyncsToRegen)
{
// Emit their regen calls
for (CallCapture &call : fenceSyncRegenCalls[sync])
{
out << " ";
WriteCppReplayForCall(call, dataTracker, out, header, binaryData);
out << ";\n";
}
}
}
void MaybeResetOpaqueTypeObjects(std::stringstream &out,
DataTracker *dataTracker,
std::stringstream &header,
ResourceTracker *resourceTracker,
std::vector<uint8_t> *binaryData)
{
MaybeResetFenceSyncObjects(out, dataTracker, header, resourceTracker, binaryData);
}
void WriteCppReplayFunctionWithParts(const gl::ContextID contextID,
ReplayFunc replayFunc,
DataTracker *dataTracker,
uint32_t frameIndex,
std::vector<uint8_t> *binaryData,
const std::vector<CallCapture> &calls,
std::stringstream &header,
std::stringstream &callStream,
std::stringstream &out)
{
std::stringstream callStreamParts;
int callCount = 0;
int partCount = 0;
// Setup can get quite large. If over a certain size, break up the function to avoid
// overflowing the stack
if (calls.size() > kFunctionSizeLimit)
{
callStreamParts << "void " << FmtFunction(replayFunc, contextID, frameIndex, ++partCount)
<< "\n";
callStreamParts << "{\n";
}
for (const CallCapture &call : calls)
{
callStreamParts << " ";
WriteCppReplayForCall(call, dataTracker, callStreamParts, header, binaryData);
callStreamParts << ";\n";
if (partCount > 0 && ++callCount % kFunctionSizeLimit == 0)
{
callStreamParts << "}\n";
callStreamParts << "\n";
callStreamParts << "void "
<< FmtFunction(replayFunc, contextID, frameIndex, ++partCount) << "\n";
callStreamParts << "{\n";
}
}
if (partCount > 0)
{
callStreamParts << "}\n";
callStreamParts << "\n";
// Write out the parts
out << callStreamParts.str();
// Write out the calls to the parts
for (int i = 1; i <= partCount; i++)
{
callStream << " " << FmtFunction(replayFunc, contextID, frameIndex, i) << ";\n";
}
}
else
{
// If we didn't chunk it up, write all the calls directly to SetupContext
callStream << callStreamParts.str();
}
}
// Auxiliary contexts are other contexts in the share group that aren't the context calling
// eglSwapBuffers().
void WriteAuxiliaryContextCppSetupReplay(bool compression,
const std::string &outDir,
const gl::Context *context,
const std::string &captureLabel,
uint32_t frameIndex,
const std::vector<CallCapture> &setupCalls,
std::vector<uint8_t> *binaryData,
bool serializeStateEnabled,
const FrameCaptureShared &frameCaptureShared)
{
ASSERT(frameCaptureShared.getWindowSurfaceContextID() != context->id());
DataTracker dataTracker;
std::stringstream out;
std::stringstream include;
std::stringstream header;
include << "#include \"" << FmtCapturePrefix(context->id(), captureLabel) << ".h\"\n";
include << "#include \"angle_trace_gl.h\"\n";
include << "";
include << "\n";
include << "namespace\n";
include << "{\n";
if (!captureLabel.empty())
{
header << "namespace " << captureLabel << "\n";
header << "{\n";
out << "namespace " << captureLabel << "\n";
out << "{\n";
}
std::stringstream setupCallStream;
header << "void " << FmtSetupFunction(kNoPartId, context->id()) << ";\n";
setupCallStream << "void " << FmtSetupFunction(kNoPartId, context->id()) << "\n";
setupCallStream << "{\n";
WriteCppReplayFunctionWithParts(context->id(), ReplayFunc::Setup, &dataTracker, frameIndex,
binaryData, setupCalls, include, setupCallStream, out);
out << setupCallStream.str();
out << "}\n";
out << "\n";
if (!captureLabel.empty())
{
header << "} // namespace " << captureLabel << "\n";
out << "} // namespace " << captureLabel << "\n";
}
include << "} // namespace\n";
// Write out the source file.
{
std::string outString = out.str();
std::string headerString = include.str();
std::string cppFilePath =
GetCaptureFilePath(outDir, context->id(), captureLabel, frameIndex, ".cpp");
SaveFileHelper saveCpp(cppFilePath);
saveCpp << headerString << "\n" << outString;
}
// Write out the header file.
{
std::string headerContents = header.str();
std::stringstream headerPathStream;
headerPathStream << outDir << FmtCapturePrefix(context->id(), captureLabel) << ".h";
std::string headerPath = headerPathStream.str();
SaveFileHelper saveHeader(headerPath);
saveHeader << headerContents;
}
}
void WriteWindowSurfaceContextCppReplay(bool compression,
const std::string &outDir,
const gl::Context *context,
const std::string &captureLabel,
uint32_t frameIndex,
uint32_t frameCount,
const std::vector<CallCapture> &frameCalls,
const std::vector<CallCapture> &setupCalls,
ResourceTracker *resourceTracker,
std::vector<uint8_t> *binaryData,
bool serializeStateEnabled,
const FrameCaptureShared &frameCaptureShared)
{
ASSERT(frameCaptureShared.getWindowSurfaceContextID() == context->id());
DataTracker dataTracker;
std::stringstream out;
std::stringstream header;
egl::ShareGroup *shareGroup = context->getShareGroup();
egl::ContextSet *shareContextSet = shareGroup->getContexts();
header << "#include \"" << FmtCapturePrefix(kSharedContextId, captureLabel) << ".h\"\n";
for (gl::Context *shareContext : *shareContextSet)
{
header << "#include \"" << FmtCapturePrefix(shareContext->id(), captureLabel) << ".h\"\n";
}
header << "#include \"angle_trace_gl.h\"\n";
header << "";
header << "\n";
header << "namespace\n";
header << "{\n";
if (frameIndex == 1 || frameIndex == frameCount)
{
out << "extern \"C\" {\n";
}
if (frameIndex == 1)
{
std::stringstream setupCallStream;
setupCallStream << "void " << FmtSetupFunction(kNoPartId, context->id()) << "\n";
setupCallStream << "{\n";
WriteCppReplayFunctionWithParts(context->id(), ReplayFunc::Setup, &dataTracker, frameIndex,
binaryData, setupCalls, header, setupCallStream, out);
out << setupCallStream.str();
out << "}\n";
out << "\n";
out << "void SetupReplay()\n";
out << "{\n";
out << " " << captureLabel << "::InitReplay();\n";
// Setup all of the shared objects.
out << " " << captureLabel << "::" << FmtSetupFunction(kNoPartId, kSharedContextId)
<< ";\n";
// Setup the presentation (this) context before any other contexts in the share group.
out << " " << FmtSetupFunction(kNoPartId, context->id()) << ";\n";
out << "}\n";
out << "\n";
}
if (frameIndex == frameCount)
{
// Emit code to reset back to starting state
out << "void " << FmtResetFunction() << "\n";
out << "{\n";
// TODO(http://anglebug.com/5878): Look at moving this into the shared context file since
// it's resetting shared objects.
std::stringstream restoreCallStream;
for (ResourceIDType resourceType : AllEnums<ResourceIDType>())
{
MaybeResetResources(restoreCallStream, resourceType, &dataTracker, header,
resourceTracker, binaryData);
}
// Reset opaque type objects that don't have IDs, so are not ResourceIDTypes.
MaybeResetOpaqueTypeObjects(restoreCallStream, &dataTracker, header, resourceTracker,
binaryData);
out << restoreCallStream.str();
out << "}\n";
}
if (frameIndex == 1 || frameIndex == frameCount)
{
out << "} // extern \"C\"\n";
out << "\n";
}
if (!captureLabel.empty())
{
out << "namespace " << captureLabel << "\n";
out << "{\n";
}
if (!frameCalls.empty())
{
std::stringstream callStream;
callStream << "void " << FmtReplayFunction(context->id(), frameIndex) << "\n";
callStream << "{\n";
WriteCppReplayFunctionWithParts(context->id(), ReplayFunc::Replay, &dataTracker, frameIndex,
binaryData, frameCalls, header, callStream, out);
out << callStream.str();
out << "}\n";
}
if (serializeStateEnabled)
{
std::string serializedContextString;
if (SerializeContextToString(const_cast<gl::Context *>(context),
&serializedContextString) == Result::Continue)
{
out << "const char *" << FmtGetSerializedContextStateFunction(context->id(), frameIndex)
<< "\n";
out << "{\n";
out << " return R\"(" << serializedContextString << ")\";\n";
out << "}\n";
out << "\n";
}
}
if (!captureLabel.empty())
{
out << "} // namespace " << captureLabel << "\n";
}
header << "} // namespace\n";
{
std::string outString = out.str();
std::string headerString = header.str();
std::string cppFilePath =
GetCaptureFilePath(outDir, context->id(), captureLabel, frameIndex, ".cpp");
SaveFileHelper saveCpp(cppFilePath);
saveCpp << headerString << "\n" << outString;
}
}
void WriteSharedContextCppReplay(bool compression,
const std::string &outDir,
const std::string &captureLabel,
uint32_t frameIndex,
uint32_t frameCount,
const std::vector<CallCapture> &setupCalls,
ResourceTracker *resourceTracker,
std::vector<uint8_t> *binaryData,
bool serializeStateEnabled,
const FrameCaptureShared &frameCaptureShared)
{
DataTracker dataTracker;
std::stringstream out;
std::stringstream include;
std::stringstream header;
include << "#include \"" << FmtCapturePrefix(kSharedContextId, captureLabel) << ".h\"\n";
include << "#include \"angle_trace_gl.h\"\n";
include << "";
include << "\n";
include << "namespace\n";
include << "{\n";
if (!captureLabel.empty())
{
header << "namespace " << captureLabel << "\n";
header << "{\n";
out << "namespace " << captureLabel << "\n";
out << "{\n";
}
std::stringstream setupCallStream;
header << "void " << FmtSetupFunction(kNoPartId, kSharedContextId) << ";\n";
setupCallStream << "void " << FmtSetupFunction(kNoPartId, kSharedContextId) << "\n";
setupCallStream << "{\n";
WriteCppReplayFunctionWithParts(kSharedContextId, ReplayFunc::Setup, &dataTracker, frameIndex,
binaryData, setupCalls, include, setupCallStream, out);
out << setupCallStream.str();
out << "}\n";
out << "\n";
if (!captureLabel.empty())
{
header << "} // namespace " << captureLabel << "\n";
out << "} // namespace " << captureLabel << "\n";
}
include << "} // namespace\n";
// Write out the source file.
{
std::string outString = out.str();
std::string headerString = include.str();
std::string cppFilePath =
GetCaptureFilePath(outDir, kSharedContextId, captureLabel, frameIndex, ".cpp");
SaveFileHelper saveCpp(cppFilePath);
saveCpp << headerString << "\n" << outString;
}
// Write out the header file.
{
std::string headerContents = header.str();
std::stringstream headerPathStream;
headerPathStream << outDir << FmtCapturePrefix(kSharedContextId, captureLabel) << ".h";
std::string headerPath = headerPathStream.str();
SaveFileHelper saveHeader(headerPath);
saveHeader << headerContents;
}
}
ProgramSources GetAttachedProgramSources(const gl::Program *program)
{
ProgramSources sources;
for (gl::ShaderType shaderType : gl::AllShaderTypes())
{
const gl::Shader *shader = program->getAttachedShader(shaderType);
if (shader)
{
sources[shaderType] = shader->getSourceString();
}
}
return sources;
}
template <typename IDType>
void CaptureUpdateResourceIDs(const CallCapture &call,
const ParamCapture ¶m,
std::vector<CallCapture> *callsOut)
{
GLsizei n = call.params.getParamFlexName("n", "count", ParamType::TGLsizei, 0).value.GLsizeiVal;
ASSERT(param.data.size() == 1);
ResourceIDType resourceIDType = GetResourceIDTypeFromParamType(param.type);
ASSERT(resourceIDType != ResourceIDType::InvalidEnum);
const char *resourceName = GetResourceIDTypeName(resourceIDType);
std::stringstream updateFuncNameStr;
updateFuncNameStr << "Update" << resourceName << "ID";
std::string updateFuncName = updateFuncNameStr.str();
const IDType *returnedIDs = reinterpret_cast<const IDType *>(param.data[0].data());
for (GLsizei idIndex = 0; idIndex < n; ++idIndex)
{
IDType id = returnedIDs[idIndex];
GLsizei readBufferOffset = idIndex * sizeof(gl::RenderbufferID);
ParamBuffer params;
params.addValueParam("id", ParamType::TGLuint, id.value);
params.addValueParam("readBufferOffset", ParamType::TGLsizei, readBufferOffset);
callsOut->emplace_back(updateFuncName, std::move(params));
}
}
void CaptureUpdateUniformLocations(const gl::Program *program, std::vector<CallCapture> *callsOut)
{
const std::vector<gl::LinkedUniform> &uniforms = program->getState().getUniforms();
const std::vector<gl::VariableLocation> &locations = program->getUniformLocations();
for (GLint location = 0; location < static_cast<GLint>(locations.size()); ++location)
{
const gl::VariableLocation &locationVar = locations[location];
// This handles the case where the application calls glBindUniformLocationCHROMIUM
// on an unused uniform. We must still store a -1 into gUniformLocations in case the
// application attempts to call a glUniform* call. To do this we'll pass in a blank name to
// force glGetUniformLocation to return -1.
std::string name;
ParamBuffer params;
params.addValueParam("program", ParamType::TShaderProgramID, program->id());
if (locationVar.index >= uniforms.size())
{
name = "";
}
else
{
const gl::LinkedUniform &uniform = uniforms[locationVar.index];
name = uniform.name;
if (uniform.isArray())
{
if (locationVar.arrayIndex > 0)
{
// Non-sequential array uniform locations are not currently handled.
// In practice array locations shouldn't ever be non-sequential.
ASSERT(uniform.location == -1 ||
location == uniform.location + static_cast<int>(locationVar.arrayIndex));
continue;
}
if (uniform.isArrayOfArrays())
{
UNIMPLEMENTED();
}
name = gl::StripLastArrayIndex(name);
}
}
ParamCapture nameParam("name", ParamType::TGLcharConstPointer);
CaptureString(name.c_str(), &nameParam);
params.addParam(std::move(nameParam));
params.addValueParam("location", ParamType::TGLint, location);
callsOut->emplace_back("UpdateUniformLocation", std::move(params));
}
}
void CaptureUpdateUniformBlockIndexes(const gl::Program *program,
std::vector<CallCapture> *callsOut)
{
const std::vector<gl::InterfaceBlock> &uniformBlocks = program->getState().getUniformBlocks();
for (GLuint index = 0; index < uniformBlocks.size(); ++index)
{
ParamBuffer params;
std::string name;
params.addValueParam("program", ParamType::TShaderProgramID, program->id());
ParamCapture nameParam("name", ParamType::TGLcharConstPointer);
CaptureString(uniformBlocks[index].name.c_str(), &nameParam);
params.addParam(std::move(nameParam));
params.addValueParam("index", ParamType::TGLuint, index);
callsOut->emplace_back("UpdateUniformBlockIndex", std::move(params));
}
}
void CaptureDeleteUniformLocations(gl::ShaderProgramID program, std::vector<CallCapture> *callsOut)
{
ParamBuffer params;
params.addValueParam("program", ParamType::TShaderProgramID, program);
callsOut->emplace_back("DeleteUniformLocations", std::move(params));
}
void MaybeCaptureUpdateResourceIDs(std::vector<CallCapture> *callsOut)
{
const CallCapture &call = callsOut->back();
switch (call.entryPoint)
{
case EntryPoint::GLGenBuffers:
{
const ParamCapture &buffers =
call.params.getParam("buffersPacked", ParamType::TBufferIDPointer, 1);
CaptureUpdateResourceIDs<gl::BufferID>(call, buffers, callsOut);
break;
}
case EntryPoint::GLGenFencesNV:
{
const ParamCapture &fences =
call.params.getParam("fencesPacked", ParamType::TFenceNVIDPointer, 1);
CaptureUpdateResourceIDs<gl::FenceNVID>(call, fences, callsOut);
break;
}
case EntryPoint::GLGenFramebuffers:
case EntryPoint::GLGenFramebuffersOES:
{
const ParamCapture &framebuffers =
call.params.getParam("framebuffersPacked", ParamType::TFramebufferIDPointer, 1);
CaptureUpdateResourceIDs<gl::FramebufferID>(call, framebuffers, callsOut);
break;
}
case EntryPoint::GLGenProgramPipelines:
{
const ParamCapture &pipelines =
call.params.getParam("pipelinesPacked", ParamType::TProgramPipelineIDPointer, 1);
CaptureUpdateResourceIDs<gl::ProgramPipelineID>(call, pipelines, callsOut);
break;
}
case EntryPoint::GLGenQueries:
case EntryPoint::GLGenQueriesEXT:
{
const ParamCapture &queries =
call.params.getParam("idsPacked", ParamType::TQueryIDPointer, 1);
CaptureUpdateResourceIDs<gl::QueryID>(call, queries, callsOut);
break;
}
case EntryPoint::GLGenRenderbuffers:
case EntryPoint::GLGenRenderbuffersOES:
{
const ParamCapture &renderbuffers =
call.params.getParam("renderbuffersPacked", ParamType::TRenderbufferIDPointer, 1);
CaptureUpdateResourceIDs<gl::RenderbufferID>(call, renderbuffers, callsOut);
break;
}
case EntryPoint::GLGenSamplers:
{
const ParamCapture &samplers =
call.params.getParam("samplersPacked", ParamType::TSamplerIDPointer, 1);
CaptureUpdateResourceIDs<gl::SamplerID>(call, samplers, callsOut);
break;
}
case EntryPoint::GLGenSemaphoresEXT:
{
const ParamCapture &semaphores =
call.params.getParam("semaphoresPacked", ParamType::TSemaphoreIDPointer, 1);
CaptureUpdateResourceIDs<gl::SemaphoreID>(call, semaphores, callsOut);
break;
}
case EntryPoint::GLGenTextures:
{
const ParamCapture &textures =
call.params.getParam("texturesPacked", ParamType::TTextureIDPointer, 1);
CaptureUpdateResourceIDs<gl::TextureID>(call, textures, callsOut);
break;
}
case EntryPoint::GLGenTransformFeedbacks:
{
const ParamCapture &xfbs =
call.params.getParam("idsPacked", ParamType::TTransformFeedbackIDPointer, 1);
CaptureUpdateResourceIDs<gl::TransformFeedbackID>(call, xfbs, callsOut);
break;
}
case EntryPoint::GLGenVertexArrays:
case EntryPoint::GLGenVertexArraysOES:
{
const ParamCapture &vertexArrays =
call.params.getParam("arraysPacked", ParamType::TVertexArrayIDPointer, 1);
CaptureUpdateResourceIDs<gl::VertexArrayID>(call, vertexArrays, callsOut);
break;
}
case EntryPoint::GLCreateMemoryObjectsEXT:
{
const ParamCapture &memoryObjects =
call.params.getParam("memoryObjectsPacked", ParamType::TMemoryObjectIDPointer, 1);
CaptureUpdateResourceIDs<gl::MemoryObjectID>(call, memoryObjects, callsOut);
break;
}
default:
break;
}
}
void CaptureUpdateCurrentProgram(const CallCapture &call, std::vector<CallCapture> *callsOut)
{
const ParamCapture ¶m =
call.params.getParam("programPacked", ParamType::TShaderProgramID, 0);
gl::ShaderProgramID programID = param.value.ShaderProgramIDVal;
ParamBuffer paramBuffer;
paramBuffer.addValueParam("program", ParamType::TShaderProgramID, programID);
callsOut->emplace_back("UpdateCurrentProgram", std::move(paramBuffer));
}
bool IsDefaultCurrentValue(const gl::VertexAttribCurrentValueData ¤tValue)
{
if (currentValue.Type != gl::VertexAttribType::Float)
return false;
return currentValue.Values.FloatValues[0] == 0.0f &&
currentValue.Values.FloatValues[1] == 0.0f &&
currentValue.Values.FloatValues[2] == 0.0f && currentValue.Values.FloatValues[3] == 1.0f;
}
bool IsQueryActive(const gl::State &glState, gl::QueryID &queryID)
{
const gl::ActiveQueryMap &activeQueries = glState.getActiveQueriesForCapture();
for (const auto &activeQueryIter : activeQueries)
{
const gl::Query *activeQuery = activeQueryIter.get();
if (activeQuery && activeQuery->id() == queryID)
{
return true;
}
}
return false;
}
bool IsTextureUpdate(CallCapture &call)
{
switch (call.entryPoint)
{
case EntryPoint::GLCompressedCopyTextureCHROMIUM:
case EntryPoint::GLCompressedTexImage1D:
case EntryPoint::GLCompressedTexImage2D:
case EntryPoint::GLCompressedTexImage2DRobustANGLE:
case EntryPoint::GLCompressedTexImage3D:
case EntryPoint::GLCompressedTexImage3DOES:
case EntryPoint::GLCompressedTexImage3DRobustANGLE:
case EntryPoint::GLCompressedTexSubImage1D:
case EntryPoint::GLCompressedTexSubImage2D:
case EntryPoint::GLCompressedTexSubImage2DRobustANGLE:
case EntryPoint::GLCompressedTexSubImage3D:
case EntryPoint::GLCompressedTexSubImage3DOES:
case EntryPoint::GLCompressedTexSubImage3DRobustANGLE:
case EntryPoint::GLCompressedTextureSubImage1D:
case EntryPoint::GLCompressedTextureSubImage2D:
case EntryPoint::GLCompressedTextureSubImage3D:
case EntryPoint::GLCopyTexImage1D:
case EntryPoint::GLCopyTexImage2D:
case EntryPoint::GLCopyTexSubImage1D:
case EntryPoint::GLCopyTexSubImage2D:
case EntryPoint::GLCopyTexSubImage3D:
case EntryPoint::GLCopyTexSubImage3DOES:
case EntryPoint::GLCopyTexture3DANGLE:
case EntryPoint::GLCopyTextureCHROMIUM:
case EntryPoint::GLCopyTextureSubImage1D:
case EntryPoint::GLCopyTextureSubImage2D:
case EntryPoint::GLCopyTextureSubImage3D:
case EntryPoint::GLTexImage1D:
case EntryPoint::GLTexImage2D:
case EntryPoint::GLTexImage2DExternalANGLE:
case EntryPoint::GLTexImage2DMultisample:
case EntryPoint::GLTexImage2DRobustANGLE:
case EntryPoint::GLTexImage3D:
case EntryPoint::GLTexImage3DMultisample:
case EntryPoint::GLTexImage3DOES:
case EntryPoint::GLTexImage3DRobustANGLE:
case EntryPoint::GLTexSubImage1D:
case EntryPoint::GLTexSubImage2D:
case EntryPoint::GLTexSubImage2DRobustANGLE:
case EntryPoint::GLTexSubImage3D:
case EntryPoint::GLTexSubImage3DOES:
case EntryPoint::GLTexSubImage3DRobustANGLE:
case EntryPoint::GLTextureSubImage1D:
case EntryPoint::GLTextureSubImage2D:
case EntryPoint::GLTextureSubImage3D:
return true;
// Note: CopyImageSubData is handled specially in copyCompressedTextureData
case EntryPoint::GLCopyImageSubData:
case EntryPoint::GLCopyImageSubDataEXT:
case EntryPoint::GLCopyImageSubDataOES:
return false;
default:
return false;
}
}
void Capture(std::vector<CallCapture> *setupCalls, CallCapture &&call)
{
setupCalls->emplace_back(std::move(call));
}
void CaptureFramebufferAttachment(std::vector<CallCapture> *setupCalls,
const gl::State &replayState,
const gl::FramebufferAttachment &attachment)
{
GLuint resourceID = attachment.getResource()->getId();
// TODO(jmadill): Layer attachments. http://anglebug.com/3662
if (attachment.type() == GL_TEXTURE)
{
gl::ImageIndex index = attachment.getTextureImageIndex();
Capture(setupCalls, CaptureFramebufferTexture2D(replayState, true, GL_FRAMEBUFFER,
attachment.getBinding(), index.getTarget(),
{resourceID}, index.getLevelIndex()));
}
else
{
ASSERT(attachment.type() == GL_RENDERBUFFER);
Capture(setupCalls, CaptureFramebufferRenderbuffer(replayState, true, GL_FRAMEBUFFER,
attachment.getBinding(), GL_RENDERBUFFER,
{resourceID}));
}
}
void CaptureUpdateUniformValues(const gl::State &replayState,
const gl::Context *context,
const gl::Program *program,
std::vector<CallCapture> *callsOut)
{
if (!program->isLinked())
{
// We can't populate uniforms if the program hasn't been linked
return;
}
// We need to bind the program and update its uniforms
// TODO (http://anglebug.com/3662): Only bind if different from currently bound
Capture(callsOut, CaptureUseProgram(replayState, true, program->id()));
CaptureUpdateCurrentProgram(callsOut->back(), callsOut);
const std::vector<gl::LinkedUniform> &uniforms = program->getState().getUniforms();
for (const gl::LinkedUniform &uniform : uniforms)
{
std::string uniformName = uniform.name;
int uniformCount = 1;
if (uniform.isArray())
{
if (uniform.isArrayOfArrays())
{
UNIMPLEMENTED();
continue;
}
uniformCount = uniform.arraySizes[0];
uniformName = gl::StripLastArrayIndex(uniformName);
}
gl::UniformLocation uniformLoc = program->getUniformLocation(uniformName);
const gl::UniformTypeInfo *typeInfo = uniform.typeInfo;
int componentCount = typeInfo->componentCount;
int uniformSize = uniformCount * componentCount;
// For arrayed uniforms, we'll need to increment a read location
gl::UniformLocation readLoc = uniformLoc;
// If the uniform is unused, just continue
if (readLoc.value == -1)
{
continue;
}
// Image uniforms are special and cannot be set this way
if (typeInfo->isImageType)
{
continue;
}
// Samplers should be populated with GL_INT, regardless of return type
if (typeInfo->isSampler)
{
std::vector<GLint> uniformBuffer(uniformSize);
for (int index = 0; index < uniformCount; index++, readLoc.value++)
{
program->getUniformiv(context, readLoc,
uniformBuffer.data() + index * componentCount);
}
Capture(callsOut, CaptureUniform1iv(replayState, true, uniformLoc, uniformCount,
uniformBuffer.data()));
continue;
}
switch (typeInfo->componentType)
{
case GL_FLOAT:
{
std::vector<GLfloat> uniformBuffer(uniformSize);
for (int index = 0; index < uniformCount; index++, readLoc.value++)
{
program->getUniformfv(context, readLoc,
uniformBuffer.data() + index * componentCount);
}
switch (typeInfo->type)
{
// Note: All matrix uniforms are populated without transpose
case GL_FLOAT_MAT4x3:
Capture(callsOut, CaptureUniformMatrix4x3fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT4x2:
Capture(callsOut, CaptureUniformMatrix4x2fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT4:
Capture(callsOut,
CaptureUniformMatrix4fv(replayState, true, uniformLoc, uniformCount,
false, uniformBuffer.data()));
break;
case GL_FLOAT_MAT3x4:
Capture(callsOut, CaptureUniformMatrix3x4fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT3x2:
Capture(callsOut, CaptureUniformMatrix3x2fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT3:
Capture(callsOut,
CaptureUniformMatrix3fv(replayState, true, uniformLoc, uniformCount,
false, uniformBuffer.data()));
break;
case GL_FLOAT_MAT2x4:
Capture(callsOut, CaptureUniformMatrix2x4fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT2x3:
Capture(callsOut, CaptureUniformMatrix2x3fv(replayState, true, uniformLoc,
uniformCount, false,
uniformBuffer.data()));
break;
case GL_FLOAT_MAT2:
Capture(callsOut,
CaptureUniformMatrix2fv(replayState, true, uniformLoc, uniformCount,
false, uniformBuffer.data()));
break;
case GL_FLOAT_VEC4:
Capture(callsOut, CaptureUniform4fv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case GL_FLOAT_VEC3:
Capture(callsOut, CaptureUniform3fv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case GL_FLOAT_VEC2:
Capture(callsOut, CaptureUniform2fv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case GL_FLOAT:
Capture(callsOut, CaptureUniform1fv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
default:
UNIMPLEMENTED();
break;
}
break;
}
case GL_INT:
{
std::vector<GLint> uniformBuffer(uniformSize);
for (int index = 0; index < uniformCount; index++, readLoc.value++)
{
program->getUniformiv(context, readLoc,
uniformBuffer.data() + index * componentCount);
}
switch (componentCount)
{
case 4:
Capture(callsOut, CaptureUniform4iv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 3:
Capture(callsOut, CaptureUniform3iv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 2:
Capture(callsOut, CaptureUniform2iv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 1:
Capture(callsOut, CaptureUniform1iv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
default:
UNIMPLEMENTED();
break;
}
break;
}
case GL_BOOL:
case GL_UNSIGNED_INT:
{
std::vector<GLuint> uniformBuffer(uniformSize);
for (int index = 0; index < uniformCount; index++, readLoc.value++)
{
program->getUniformuiv(context, readLoc,
uniformBuffer.data() + index * componentCount);
}
switch (componentCount)
{
case 4:
Capture(callsOut, CaptureUniform4uiv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 3:
Capture(callsOut, CaptureUniform3uiv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 2:
Capture(callsOut, CaptureUniform2uiv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
case 1:
Capture(callsOut, CaptureUniform1uiv(replayState, true, uniformLoc,
uniformCount, uniformBuffer.data()));
break;
default:
UNIMPLEMENTED();
break;
}
break;
}
default:
UNIMPLEMENTED();
break;
}
}
}
void CaptureVertexPointerES1(std::vector<CallCapture> *setupCalls,
gl::State *replayState,
GLuint attribIndex,
const gl::VertexAttribute &attrib,
const gl::VertexBinding &binding)
{
switch (gl::GLES1Renderer::VertexArrayType(attribIndex))
{
case gl::ClientVertexArrayType::Vertex:
Capture(setupCalls,
CaptureVertexPointer(*replayState, true, attrib.format->channelCount,
attrib.format->vertexAttribType, binding.getStride(),
attrib.pointer));
break;
case gl::ClientVertexArrayType::Normal:
Capture(setupCalls,
CaptureNormalPointer(*replayState, true, attrib.format->vertexAttribType,
binding.getStride(), attrib.pointer));
break;
case gl::ClientVertexArrayType::Color:
Capture(setupCalls, CaptureColorPointer(*replayState, true, attrib.format->channelCount,
attrib.format->vertexAttribType,
binding.getStride(), attrib.pointer));
break;
case gl::ClientVertexArrayType::PointSize:
Capture(setupCalls,
CapturePointSizePointerOES(*replayState, true, attrib.format->vertexAttribType,
binding.getStride(), attrib.pointer));
break;
case gl::ClientVertexArrayType::TextureCoord:
Capture(setupCalls,
CaptureTexCoordPointer(*replayState, true, attrib.format->channelCount,
attrib.format->vertexAttribType, binding.getStride(),
attrib.pointer));
break;
default:
UNREACHABLE();
}
}
void CaptureVertexArrayData(std::vector<CallCapture> *setupCalls,
const gl::Context *context,
const gl::VertexArray *vertexArray,
gl::State *replayState)
{
const std::vector<gl::VertexAttribute> &vertexAttribs = vertexArray->getVertexAttributes();
const std::vector<gl::VertexBinding> &vertexBindings = vertexArray->getVertexBindings();
for (GLuint attribIndex = 0; attribIndex < gl::MAX_VERTEX_ATTRIBS; ++attribIndex)
{
const gl::VertexAttribute defaultAttrib(attribIndex);
const gl::VertexBinding defaultBinding;
const gl::VertexAttribute &attrib = vertexAttribs[attribIndex];
const gl::VertexBinding &binding = vertexBindings[attrib.bindingIndex];
if (attrib.enabled != defaultAttrib.enabled)
{
if (context->isGLES1())
{
Capture(setupCalls,
CaptureEnableClientState(*replayState, false,
gl::GLES1Renderer::VertexArrayType(attribIndex)));
}
else
{
Capture(setupCalls,
CaptureEnableVertexAttribArray(*replayState, false, attribIndex));
}
}
if (attrib.format != defaultAttrib.format || attrib.pointer != defaultAttrib.pointer ||
binding.getStride() != defaultBinding.getStride() ||
binding.getBuffer().get() != nullptr)
{
// Each attribute can pull from a separate buffer, so check the binding
gl::Buffer *buffer = binding.getBuffer().get();
if (buffer && buffer != replayState->getArrayBuffer())
{
replayState->setBufferBinding(context, gl::BufferBinding::Array, buffer);
Capture(setupCalls, CaptureBindBuffer(*replayState, true, gl::BufferBinding::Array,
buffer->id()));
}
// Establish the relationship between currently bound buffer and the VAO
if (context->isGLES1())
{
CaptureVertexPointerES1(setupCalls, replayState, attribIndex, attrib, binding);
}
else
{
Capture(setupCalls,
CaptureVertexAttribPointer(
*replayState, true, attribIndex, attrib.format->channelCount,
attrib.format->vertexAttribType, attrib.format->isNorm(),
binding.getStride(), attrib.pointer));
}
}
if (binding.getDivisor() != 0)
{
Capture(setupCalls, CaptureVertexAttribDivisor(*replayState, true, attribIndex,
binding.getDivisor()));
}
}
// The element array buffer is not per attribute, but per VAO
gl::Buffer *elementArrayBuffer = vertexArray->getElementArrayBuffer();
if (elementArrayBuffer)
{
Capture(setupCalls, CaptureBindBuffer(*replayState, true, gl::BufferBinding::ElementArray,
elementArrayBuffer->id()));
}
}
void CaptureTextureStorage(std::vector<CallCapture> *setupCalls,
gl::State *replayState,
const gl::Texture *texture)
{
// Use mip-level 0 for the base dimensions
gl::ImageIndex imageIndex = gl::ImageIndex::MakeFromType(texture->getType(), 0);
const gl::ImageDesc &desc = texture->getTextureState().getImageDesc(imageIndex);
switch (texture->getType())
{
case gl::TextureType::_2D:
case gl::TextureType::CubeMap:
{
Capture(setupCalls, CaptureTexStorage2D(*replayState, true, texture->getType(),
texture->getImmutableLevels(),
desc.format.info->internalFormat,
desc.size.width, desc.size.height));
break;
}
case gl::TextureType::_3D:
case gl::TextureType::_2DArray:
case gl::TextureType::CubeMapArray:
{
Capture(setupCalls, CaptureTexStorage3D(
*replayState, true, texture->getType(),
texture->getImmutableLevels(), desc.format.info->internalFormat,
desc.size.width, desc.size.height, desc.size.depth));
break;
}
case gl::TextureType::Buffer:
{
// Do nothing. This will already be captured as a buffer.
break;
}
default:
UNIMPLEMENTED();
break;
}
}
void CaptureTextureContents(std::vector<CallCapture> *setupCalls,
gl::State *replayState,
const gl::Texture *texture,
const gl::ImageIndex &index,
const gl::ImageDesc &desc,
GLuint size,
const void *data)
{
const gl::InternalFormat &format = *desc.format.info;
if (index.getType() == gl::TextureType::Buffer)
{
// Zero binding size indicates full buffer bound
if (texture->getBuffer().getSize() == 0)
{
Capture(setupCalls,
CaptureTexBufferEXT(*replayState, true, index.getType(), format.internalFormat,
texture->getBuffer().get()->id()));
}
else
{
Capture(setupCalls, CaptureTexBufferRangeEXT(*replayState, true, index.getType(),
format.internalFormat,
texture->getBuffer().get()->id(),
texture->getBuffer().getOffset(),
texture->getBuffer().getSize()));
}
// For buffers, we're done
return;
}
bool is3D =
(index.getType() == gl::TextureType::_3D || index.getType() == gl::TextureType::_2DArray ||
index.getType() == gl::TextureType::CubeMapArray);
if (format.compressed)
{
if (is3D)
{
if (texture->getImmutableFormat())
{
Capture(setupCalls,
CaptureCompressedTexSubImage3D(
*replayState, true, index.getTarget(), index.getLevelIndex(), 0, 0, 0,
desc.size.width, desc.size.height, desc.size.depth,
format.internalFormat, size, data));
}
else
{
Capture(setupCalls,
CaptureCompressedTexImage3D(*replayState, true, index.getTarget(),
index.getLevelIndex(), format.internalFormat,
desc.size.width, desc.size.height,
desc.size.depth, 0, size, data));
}
}
else
{
if (texture->getImmutableFormat())
{
Capture(setupCalls,
CaptureCompressedTexSubImage2D(
*replayState, true, index.getTarget(), index.getLevelIndex(), 0, 0,
desc.size.width, desc.size.height, format.internalFormat, size, data));
}
else
{
Capture(setupCalls, CaptureCompressedTexImage2D(
*replayState, true, index.getTarget(),
index.getLevelIndex(), format.internalFormat,
desc.size.width, desc.size.height, 0, size, data));
}
}
}
else
{
if (is3D)
{
if (texture->getImmutableFormat())
{
Capture(setupCalls,
CaptureTexSubImage3D(*replayState, true, index.getTarget(),
index.getLevelIndex(), 0, 0, 0, desc.size.width,
desc.size.height, desc.size.depth, format.format,
format.type, data));
}
else
{
Capture(
setupCalls,
CaptureTexImage3D(*replayState, true, index.getTarget(), index.getLevelIndex(),
format.internalFormat, desc.size.width, desc.size.height,
desc.size.depth, 0, format.format, format.type, data));
}
}
else
{
if (texture->getImmutableFormat())
{
Capture(setupCalls,
CaptureTexSubImage2D(*replayState, true, index.getTarget(),
index.getLevelIndex(), 0, 0, desc.size.width,
desc.size.height, format.format, format.type, data));
}
else
{
Capture(setupCalls, CaptureTexImage2D(*replayState, true, index.getTarget(),
index.getLevelIndex(), format.internalFormat,
desc.size.width, desc.size.height, 0,
format.format, format.type, data));
}
}
}
}
// TODO(http://anglebug.com/4599): Improve reset/restore call generation
// There are multiple ways to track reset calls for individual resources. For now, we are tracking
// separate lists of instructions that mirror the calls created during mid-execution setup. Other
// methods could involve passing the original CallCaptures to this function, or tracking the
// indices of original setup calls.
void CaptureBufferResetCalls(const gl::State &replayState,
ResourceTracker *resourceTracker,
gl::BufferID *id,
const gl::Buffer *buffer)
{
GLuint bufferID = (*id).value;
// Track this as a starting resource that may need to be restored.
TrackedResource &trackedBuffers = resourceTracker->getTrackedResource(ResourceIDType::Buffer);
ResourceSet &startingBuffers = trackedBuffers.getStartingResources();
startingBuffers.insert(bufferID);
// Track calls to regenerate a given buffer
ResourceCalls &bufferRegenCalls = trackedBuffers.getResourceRegenCalls();
Capture(&bufferRegenCalls[bufferID], CaptureDeleteBuffers(replayState, true, 1, id));
Capture(&bufferRegenCalls[bufferID], CaptureGenBuffers(replayState, true, 1, id));
MaybeCaptureUpdateResourceIDs(&bufferRegenCalls[bufferID]);
// Track calls to restore a given buffer's contents
ResourceCalls &bufferRestoreCalls = trackedBuffers.getResourceRestoreCalls();
Capture(&bufferRestoreCalls[bufferID],
CaptureBindBuffer(replayState, true, gl::BufferBinding::Array, *id));
Capture(&bufferRestoreCalls[bufferID],
CaptureBufferData(replayState, true, gl::BufferBinding::Array,
static_cast<GLsizeiptr>(buffer->getSize()), buffer->getMapPointer(),
buffer->getUsage()));
if (buffer->isMapped())
{
// Track calls to remap a buffer that started as mapped
BufferCalls &bufferMapCalls = resourceTracker->getBufferMapCalls();
Capture(&bufferMapCalls[bufferID],
CaptureBindBuffer(replayState, true, gl::BufferBinding::Array, *id));
void *dontCare = nullptr;
Capture(&bufferMapCalls[bufferID],
CaptureMapBufferRange(replayState, true, gl::BufferBinding::Array,
static_cast<GLsizeiptr>(buffer->getMapOffset()),
static_cast<GLsizeiptr>(buffer->getMapLength()),
buffer->getAccessFlags(), dontCare));
// Track the bufferID that was just mapped
bufferMapCalls[bufferID].back().params.setMappedBufferID(buffer->id());
}
// Track calls unmap a buffer that started as unmapped
BufferCalls &bufferUnmapCalls = resourceTracker->getBufferUnmapCalls();
Capture(&bufferUnmapCalls[bufferID],
CaptureBindBuffer(replayState, true, gl::BufferBinding::Array, *id));
Capture(&bufferUnmapCalls[bufferID],
CaptureUnmapBuffer(replayState, true, gl::BufferBinding::Array, GL_TRUE));
}
void CaptureFenceSyncResetCalls(const gl::State &replayState,
ResourceTracker *resourceTracker,
GLsync syncID,
const gl::Sync *sync)
{
// Track calls to regenerate a given fence sync
FenceSyncCalls &fenceSyncRegenCalls = resourceTracker->getFenceSyncRegenCalls();
Capture(&fenceSyncRegenCalls[syncID],
CaptureFenceSync(replayState, true, sync->getCondition(), sync->getFlags(), syncID));
MaybeCaptureUpdateResourceIDs(&fenceSyncRegenCalls[syncID]);
}
void CaptureBufferBindingResetCalls(const gl::State &replayState,
ResourceTracker *resourceTracker,
gl::BufferBinding binding,
gl::BufferID id)
{
std::vector<CallCapture> &bufferBindingCalls = resourceTracker->getBufferBindingCalls();
Capture(&bufferBindingCalls, CaptureBindBuffer(replayState, true, binding, id));
}
void CaptureIndexedBuffers(const gl::State &glState,
const gl::BufferVector &indexedBuffers,
gl::BufferBinding binding,
std::vector<CallCapture> *setupCalls)
{
for (unsigned int index = 0; index < indexedBuffers.size(); ++index)
{
const gl::OffsetBindingPointer<gl::Buffer> &buffer = indexedBuffers[index];
if (buffer.get() == nullptr)
{
continue;
}
GLintptr offset = buffer.getOffset();
GLsizeiptr size = buffer.getSize();
gl::BufferID bufferID = buffer.get()->id();
// Context::bindBufferBase() calls Context::bindBufferRange() with size and offset = 0.
if ((offset == 0) && (size == 0))
{
Capture(setupCalls, CaptureBindBufferBase(glState, true, binding, index, bufferID));
}
else
{
Capture(setupCalls,
CaptureBindBufferRange(glState, true, binding, index, bufferID, offset, size));
}
}
}
void CaptureDefaultVertexAttribs(const gl::State &replayState,
const gl::State &apiState,
std::vector<CallCapture> *setupCalls)
{
const std::vector<gl::VertexAttribCurrentValueData> ¤tValues =
apiState.getVertexAttribCurrentValues();
for (GLuint attribIndex = 0; attribIndex < gl::MAX_VERTEX_ATTRIBS; ++attribIndex)
{
const gl::VertexAttribCurrentValueData &defaultValue = currentValues[attribIndex];
if (!IsDefaultCurrentValue(defaultValue))
{
Capture(setupCalls, CaptureVertexAttrib4fv(replayState, true, attribIndex,
defaultValue.Values.FloatValues));
}
}
}
// Capture the setup of the state that's shared by all of the contexts in the share group:
// OpenGL ES Version 3.2 (October 22, 2019)
// Chapter 5 Shared Objects and Multiple Contexts
// Objects that can be shared between contexts include buffer objects, program
// and shader objects, renderbuffer objects, sampler objects, sync objects, and texture
// objects (except for the texture objects named zero).
// Objects which contain references to other objects include framebuffer, program
// pipeline, transform feedback, and vertex array objects. Such objects are called
// container objects and are not shared.
void CaptureSharedContextMidExecutionSetup(const gl::Context *context,
std::vector<CallCapture> *setupCalls,
ResourceTracker *resourceTracker)
{
FrameCaptureShared *frameCaptureShared = context->getShareGroup()->getFrameCaptureShared();
const gl::State &apiState = context->getState();
gl::State replayState(nullptr, nullptr, nullptr, nullptr, nullptr, EGL_OPENGL_ES_API,
apiState.getClientVersion(), false, true, true, true, false,
EGL_CONTEXT_PRIORITY_MEDIUM_IMG, apiState.hasProtectedContent());
// Small helper function to make the code more readable.
auto cap = [frameCaptureShared, setupCalls](CallCapture &&call) {
frameCaptureShared->updateReadBufferSize(call.params.getReadBufferSize());
setupCalls->emplace_back(std::move(call));
};
// Capture Buffer data.
const gl::BufferManager &buffers = apiState.getBufferManagerForCapture();
for (const auto &bufferIter : buffers)
{
gl::BufferID id = {bufferIter.first};
gl::Buffer *buffer = bufferIter.second;
if (id.value == 0)
{
continue;
}
// glBufferData. Would possibly be better implemented using a getData impl method.
// Saving buffers that are mapped during a swap is not yet handled.
if (buffer->getSize() == 0)
{
continue;
}
// Remember if the buffer was already mapped
GLboolean bufferMapped = buffer->isMapped();
// If needed, map the buffer so we can capture its contents
if (!bufferMapped)
{
(void)buffer->mapRange(context, 0, static_cast<GLsizeiptr>(buffer->getSize()),
GL_MAP_READ_BIT);
}
// Generate binding.
cap(CaptureGenBuffers(replayState, true, 1, &id));
MaybeCaptureUpdateResourceIDs(setupCalls);
// Always use the array buffer binding point to upload data to keep things simple.
if (buffer != replayState.getArrayBuffer())
{
replayState.setBufferBinding(context, gl::BufferBinding::Array, buffer);
cap(CaptureBindBuffer(replayState, true, gl::BufferBinding::Array, id));
}
if (buffer->isImmutable())
{
cap(CaptureBufferStorageEXT(replayState, true, gl::BufferBinding::Array,
static_cast<GLsizeiptr>(buffer->getSize()),
buffer->getMapPointer(),
buffer->getStorageExtUsageFlags()));
}
else
{
cap(CaptureBufferData(replayState, true, gl::BufferBinding::Array,
static_cast<GLsizeiptr>(buffer->getSize()),
buffer->getMapPointer(), buffer->getUsage()));
}
if (bufferMapped)
{
void *dontCare = nullptr;
Capture(setupCalls,
CaptureMapBufferRange(replayState, true, gl::BufferBinding::Array,
static_cast<GLsizeiptr>(buffer->getMapOffset()),
static_cast<GLsizeiptr>(buffer->getMapLength()),
buffer->getAccessFlags(), dontCare));
resourceTracker->setStartingBufferMapped(buffer->id().value, true);
frameCaptureShared->trackBufferMapping(
&setupCalls->back(), buffer->id(), static_cast<GLsizeiptr>(buffer->getMapOffset()),
static_cast<GLsizeiptr>(buffer->getMapLength()),
(buffer->getAccessFlags() & GL_MAP_WRITE_BIT) != 0);
}
else
{
resourceTracker->setStartingBufferMapped(buffer->id().value, false);
}
// Generate the calls needed to restore this buffer to original state for frame looping
CaptureBufferResetCalls(replayState, resourceTracker, &id, buffer);
// Unmap the buffer if it wasn't already mapped
if (!bufferMapped)
{
GLboolean dontCare;
(void)buffer->unmap(context, &dontCare);
}
}
// Set a unpack alignment of 1. Otherwise, computeRowPitch() will compute the wrong value,
// leading to a crash in memcpy() when capturing the texture contents.
gl::PixelUnpackState ¤tUnpackState = replayState.getUnpackState();
if (currentUnpackState.alignment != 1)
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_ALIGNMENT, 1));
currentUnpackState.alignment = 1;
}
// Capture Texture setup and data.
const gl::TextureManager &textures = apiState.getTextureManagerForCapture();
for (const auto &textureIter : textures)
{
gl::TextureID id = {textureIter.first};
gl::Texture *texture = textureIter.second;
if (id.value == 0)
{
continue;
}
// Track this as a starting resource that may need to be restored.
TrackedResource &trackedTextures =
resourceTracker->getTrackedResource(ResourceIDType::Texture);
ResourceSet &startingTextures = trackedTextures.getStartingResources();
startingTextures.insert(id.value);
// For the initial texture creation calls, track in the generate list
ResourceCalls &textureRegenCalls = trackedTextures.getResourceRegenCalls();
CallVector texGenCalls({setupCalls, &textureRegenCalls[id.value]});
// For reset only, delete the texture before genning
Capture(&textureRegenCalls[id.value], CaptureDeleteTextures(replayState, true, 1, &id));
// Gen the Texture.
for (std::vector<CallCapture> *calls : texGenCalls)
{
Capture(calls, CaptureGenTextures(replayState, true, 1, &id));
MaybeCaptureUpdateResourceIDs(calls);
}
// For the remaining texture setup calls, track in the restore list
ResourceCalls &textureRestoreCalls = trackedTextures.getResourceRestoreCalls();
CallVector texCalls({setupCalls, &textureRestoreCalls[id.value]});
for (std::vector<CallCapture> *calls : texCalls)
{
Capture(calls, CaptureBindTexture(replayState, true, texture->getType(), id));
}
// Capture sampler parameter states.
// TODO(jmadill): More sampler / texture states. http://anglebug.com/3662
gl::SamplerState defaultSamplerState =
gl::SamplerState::CreateDefaultForTarget(texture->getType());
const gl::SamplerState &textureSamplerState = texture->getSamplerState();
auto capTexParam = [&replayState, texture, &texCalls](GLenum pname, GLint param) {
for (std::vector<CallCapture> *calls : texCalls)
{
Capture(calls,
CaptureTexParameteri(replayState, true, texture->getType(), pname, param));
}
};
auto capTexParamf = [&replayState, texture, &texCalls](GLenum pname, GLfloat param) {
for (std::vector<CallCapture> *calls : texCalls)
{
Capture(calls,
CaptureTexParameterf(replayState, true, texture->getType(), pname, param));
}
};
if (textureSamplerState.getMinFilter() != defaultSamplerState.getMinFilter())
{
capTexParam(GL_TEXTURE_MIN_FILTER, textureSamplerState.getMinFilter());
}
if (textureSamplerState.getMagFilter() != defaultSamplerState.getMagFilter())
{
capTexParam(GL_TEXTURE_MAG_FILTER, textureSamplerState.getMagFilter());
}
if (textureSamplerState.getWrapR() != defaultSamplerState.getWrapR())
{
capTexParam(GL_TEXTURE_WRAP_R, textureSamplerState.getWrapR());
}
if (textureSamplerState.getWrapS() != defaultSamplerState.getWrapS())
{
capTexParam(GL_TEXTURE_WRAP_S, textureSamplerState.getWrapS());
}
if (textureSamplerState.getWrapT() != defaultSamplerState.getWrapT())
{
capTexParam(GL_TEXTURE_WRAP_T, textureSamplerState.getWrapT());
}
if (textureSamplerState.getMinLod() != defaultSamplerState.getMinLod())
{
capTexParamf(GL_TEXTURE_MIN_LOD, textureSamplerState.getMinLod());
}
if (textureSamplerState.getMaxLod() != defaultSamplerState.getMaxLod())
{
capTexParamf(GL_TEXTURE_MAX_LOD, textureSamplerState.getMaxLod());
}
if (textureSamplerState.getCompareMode() != defaultSamplerState.getCompareMode())
{
capTexParam(GL_TEXTURE_COMPARE_MODE, textureSamplerState.getCompareMode());
}
if (textureSamplerState.getCompareFunc() != defaultSamplerState.getCompareFunc())
{
capTexParam(GL_TEXTURE_COMPARE_FUNC, textureSamplerState.getCompareFunc());
}
// Texture parameters
if (texture->getSwizzleRed() != GL_RED)
{
capTexParam(GL_TEXTURE_SWIZZLE_R, texture->getSwizzleRed());
}
if (texture->getSwizzleGreen() != GL_GREEN)
{
capTexParam(GL_TEXTURE_SWIZZLE_G, texture->getSwizzleGreen());
}
if (texture->getSwizzleBlue() != GL_BLUE)
{
capTexParam(GL_TEXTURE_SWIZZLE_B, texture->getSwizzleBlue());
}
if (texture->getSwizzleAlpha() != GL_ALPHA)
{
capTexParam(GL_TEXTURE_SWIZZLE_A, texture->getSwizzleAlpha());
}
if (texture->getBaseLevel() != 0)
{
capTexParam(GL_TEXTURE_BASE_LEVEL, texture->getBaseLevel());
}
if (texture->getMaxLevel() != 1000)
{
capTexParam(GL_TEXTURE_MAX_LEVEL, texture->getMaxLevel());
}
// If the texture is immutable, initialize it with TexStorage
if (texture->getImmutableFormat())
{
for (std::vector<CallCapture> *calls : texCalls)
{
CaptureTextureStorage(calls, &replayState, texture);
}
}
// Iterate texture levels and layers.
gl::ImageIndexIterator imageIter = gl::ImageIndexIterator::MakeGeneric(
texture->getType(), 0, texture->getMipmapMaxLevel() + 1, gl::ImageIndex::kEntireLevel,
gl::ImageIndex::kEntireLevel);
while (imageIter.hasNext())
{
gl::ImageIndex index = imageIter.next();
const gl::ImageDesc &desc = texture->getTextureState().getImageDesc(index);
if (desc.size.empty())
{
continue;
}
const gl::InternalFormat &format = *desc.format.info;
// Check for supported textures
ASSERT(index.getType() == gl::TextureType::_2D ||
index.getType() == gl::TextureType::_3D ||
index.getType() == gl::TextureType::_2DArray ||
index.getType() == gl::TextureType::Buffer ||
index.getType() == gl::TextureType::CubeMap ||
index.getType() == gl::TextureType::CubeMapArray);
if (index.getType() == gl::TextureType::Buffer)
{
// The buffer contents are already backed up, but we need to emit the TexBuffer
// binding calls
for (std::vector<CallCapture> *calls : texCalls)
{
CaptureTextureContents(calls, &replayState, texture, index, desc, 0, 0);
}
continue;
}
if (format.compressed)
{
// For compressed images, we've tracked a copy of the incoming data, so we can
// use that rather than try to read data back that may have been converted.
const std::vector<uint8_t> &capturedTextureLevel =
context->getShareGroup()->getFrameCaptureShared()->retrieveCachedTextureLevel(
texture->id(), index.getTarget(), index.getLevelIndex());
// Use the shadow copy of the data to populate the call
for (std::vector<CallCapture> *calls : texCalls)
{
CaptureTextureContents(calls, &replayState, texture, index, desc,
static_cast<GLuint>(capturedTextureLevel.size()),
capturedTextureLevel.data());
}
}
else
{
// Use ANGLE_get_image to read back pixel data.
if (context->getExtensions().getImageANGLE)
{
GLenum getFormat = format.format;
GLenum getType = format.type;
angle::MemoryBuffer data;
const gl::Extents size(desc.size.width, desc.size.height, desc.size.depth);
const gl::PixelUnpackState &unpack = apiState.getUnpackState();
GLuint endByte = 0;
bool unpackSize =
format.computePackUnpackEndByte(getType, size, unpack, true, &endByte);
ASSERT(unpackSize);
bool result = data.resize(endByte);
ASSERT(result);
gl::PixelPackState packState;
packState.alignment = 1;
(void)texture->getTexImage(context, packState, nullptr, index.getTarget(),
index.getLevelIndex(), getFormat, getType,
data.data());
for (std::vector<CallCapture> *calls : texCalls)
{
CaptureTextureContents(calls, &replayState, texture, index, desc,
static_cast<GLuint>(data.size()), data.data());
}
}
else
{
for (std::vector<CallCapture> *calls : texCalls)
{
CaptureTextureContents(calls, &replayState, texture, index, desc, 0,
nullptr);
}
}
}
}
}
// Capture Renderbuffers.
const gl::RenderbufferManager &renderbuffers = apiState.getRenderbufferManagerForCapture();
for (const auto &renderbufIter : renderbuffers)
{
gl::RenderbufferID id = {renderbufIter.first};
const gl::Renderbuffer *renderbuffer = renderbufIter.second;
// Generate renderbuffer id.
cap(CaptureGenRenderbuffers(replayState, true, 1, &id));
MaybeCaptureUpdateResourceIDs(setupCalls);
cap(CaptureBindRenderbuffer(replayState, true, GL_RENDERBUFFER, id));
GLenum internalformat = renderbuffer->getFormat().info->internalFormat;
if (renderbuffer->getSamples() > 0)
{
// Note: We could also use extensions if available.
cap(CaptureRenderbufferStorageMultisample(
replayState, true, GL_RENDERBUFFER, renderbuffer->getSamples(), internalformat,
renderbuffer->getWidth(), renderbuffer->getHeight()));
}
else
{
cap(CaptureRenderbufferStorage(replayState, true, GL_RENDERBUFFER, internalformat,
renderbuffer->getWidth(), renderbuffer->getHeight()));
}
// TODO(jmadill): Capture renderbuffer contents. http://anglebug.com/3662
}
// Capture Shaders and Programs.
const gl::ShaderProgramManager &shadersAndPrograms =
apiState.getShaderProgramManagerForCapture();
const gl::ResourceMap<gl::Shader, gl::ShaderProgramID> &shaders =
shadersAndPrograms.getShadersForCapture();
const gl::ResourceMap<gl::Program, gl::ShaderProgramID> &programs =
shadersAndPrograms.getProgramsForCaptureAndPerf();
// Capture Program binary state. Use max ID as a temporary shader ID.
gl::ShaderProgramID tempShaderID = {resourceTracker->getMaxShaderPrograms()};
for (const auto &programIter : programs)
{
gl::ShaderProgramID id = {programIter.first};
const gl::Program *program = programIter.second;
// Unlinked programs don't have an executable. Thus they don't need to be captured.
// Programs are shared by contexts in the share group and only need to be captured once.
if (!program->isLinked())
{
continue;
}
// Get last linked shader source.
const ProgramSources &linkedSources =
context->getShareGroup()->getFrameCaptureShared()->getProgramSources(id);
cap(CaptureCreateProgram(replayState, true, id.value));
// Compile with last linked sources.
for (gl::ShaderType shaderType : program->getExecutable().getLinkedShaderStages())
{
const std::string &sourceString = linkedSources[shaderType];
const char *sourcePointer = sourceString.c_str();
// Compile and attach the temporary shader. Then free it immediately.
cap(CaptureCreateShader(replayState, true, shaderType, tempShaderID.value));
cap(CaptureShaderSource(replayState, true, tempShaderID, 1, &sourcePointer, nullptr));
cap(CaptureCompileShader(replayState, true, tempShaderID));
cap(CaptureAttachShader(replayState, true, id, tempShaderID));
cap(CaptureDeleteShader(replayState, true, tempShaderID));
}
// Gather XFB varyings
std::vector<std::string> xfbVaryings;
for (const gl::TransformFeedbackVarying &xfbVarying :
program->getState().getLinkedTransformFeedbackVaryings())
{
xfbVaryings.push_back(xfbVarying.nameWithArrayIndex());
}
if (!xfbVaryings.empty())
{
std::vector<const char *> varyingsStrings;
for (const std::string &varyingString : xfbVaryings)
{
varyingsStrings.push_back(varyingString.data());
}
GLenum xfbMode = program->getState().getTransformFeedbackBufferMode();
cap(CaptureTransformFeedbackVaryings(replayState, true, id,
static_cast<GLint>(xfbVaryings.size()),
varyingsStrings.data(), xfbMode));
}
// Force the attributes to be bound the same way as in the existing program.
// This can affect attributes that are optimized out in some implementations.
for (const sh::ShaderVariable &attrib : program->getState().getProgramInputs())
{
if (gl::IsBuiltInName(attrib.name))
{
// Don't try to bind built-in attributes
continue;
}
// Separable programs may not have a VS, meaning it may not have attributes.
if (program->getExecutable().hasLinkedShaderStage(gl::ShaderType::Vertex))
{
ASSERT(attrib.location != -1);
cap(CaptureBindAttribLocation(replayState, true, id,
static_cast<GLuint>(attrib.location),
attrib.name.c_str()));
}
}
if (program->isSeparable())
{
// MEC manually recreates separable programs, rather than attempting to recreate a call
// to glCreateShaderProgramv(), so insert a call to mark it separable.
cap(CaptureProgramParameteri(replayState, true, id, GL_PROGRAM_SEPARABLE, GL_TRUE));
}
cap(CaptureLinkProgram(replayState, true, id));
CaptureUpdateUniformLocations(program, setupCalls);
CaptureUpdateUniformValues(replayState, context, program, setupCalls);
CaptureUpdateUniformBlockIndexes(program, setupCalls);
// Capture uniform block bindings for each program
for (unsigned int uniformBlockIndex = 0;
uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++)
{
GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex);
cap(CaptureUniformBlockBinding(replayState, true, id, {uniformBlockIndex},
blockBinding));
}
resourceTracker->onShaderProgramAccess(id);
resourceTracker->getTrackedResource(ResourceIDType::ShaderProgram)
.getStartingResources()
.insert(id.value);
}
// Handle shaders.
for (const auto &shaderIter : shaders)
{
gl::ShaderProgramID id = {shaderIter.first};
gl::Shader *shader = shaderIter.second;
// Skip shaders scheduled for deletion.
// Shaders are shared by contexts in the share group and only need to be captured once.
if (shader->hasBeenDeleted())
{
continue;
}
cap(CaptureCreateShader(replayState, true, shader->getType(), id.value));
std::string shaderSource = shader->getSourceString();
const char *sourcePointer = shaderSource.empty() ? nullptr : shaderSource.c_str();
// This does not handle some more tricky situations like attaching shaders to a non-linked
// program. Or attaching uncompiled shaders. Or attaching and then deleting a shader.
// TODO(jmadill): Handle trickier program uses. http://anglebug.com/3662
if (shader->isCompiled())
{
const std::string &capturedSource =
context->getShareGroup()->getFrameCaptureShared()->getShaderSource(id);
if (capturedSource != shaderSource)
{
ASSERT(!capturedSource.empty());
sourcePointer = capturedSource.c_str();
}
cap(CaptureShaderSource(replayState, true, id, 1, &sourcePointer, nullptr));
cap(CaptureCompileShader(replayState, true, id));
}
if (sourcePointer && (!shader->isCompiled() || sourcePointer != shaderSource.c_str()))
{
cap(CaptureShaderSource(replayState, true, id, 1, &sourcePointer, nullptr));
}
}
// Capture Sampler Objects
const gl::SamplerManager &samplers = apiState.getSamplerManagerForCapture();
for (const auto &samplerIter : samplers)
{
gl::SamplerID samplerID = {samplerIter.first};
// Don't gen the sampler if we've seen it before, since they are shared across the context
// share group.
cap(CaptureGenSamplers(replayState, true, 1, &samplerID));
MaybeCaptureUpdateResourceIDs(setupCalls);
gl::Sampler *sampler = samplerIter.second;
if (!sampler)
{
continue;
}
gl::SamplerState defaultSamplerState;
if (sampler->getMinFilter() != defaultSamplerState.getMinFilter())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_MIN_FILTER,
sampler->getMinFilter()));
}
if (sampler->getMagFilter() != defaultSamplerState.getMagFilter())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_MAG_FILTER,
sampler->getMagFilter()));
}
if (sampler->getWrapS() != defaultSamplerState.getWrapS())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_WRAP_S,
sampler->getWrapS()));
}
if (sampler->getWrapR() != defaultSamplerState.getWrapR())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_WRAP_R,
sampler->getWrapR()));
}
if (sampler->getWrapT() != defaultSamplerState.getWrapT())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_WRAP_T,
sampler->getWrapT()));
}
if (sampler->getMinLod() != defaultSamplerState.getMinLod())
{
cap(CaptureSamplerParameterf(replayState, true, samplerID, GL_TEXTURE_MIN_LOD,
sampler->getMinLod()));
}
if (sampler->getMaxLod() != defaultSamplerState.getMaxLod())
{
cap(CaptureSamplerParameterf(replayState, true, samplerID, GL_TEXTURE_MAX_LOD,
sampler->getMaxLod()));
}
if (sampler->getCompareMode() != defaultSamplerState.getCompareMode())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_COMPARE_MODE,
sampler->getCompareMode()));
}
if (sampler->getCompareFunc() != defaultSamplerState.getCompareFunc())
{
cap(CaptureSamplerParameteri(replayState, true, samplerID, GL_TEXTURE_COMPARE_FUNC,
sampler->getCompareFunc()));
}
}
// Capture Sync Objects
const gl::SyncManager &syncs = apiState.getSyncManagerForCapture();
for (const auto &syncIter : syncs)
{
GLsync syncID = gl::bitCast<GLsync>(static_cast<size_t>(syncIter.first));
const gl::Sync *sync = syncIter.second;
if (!sync)
{
continue;
}
cap(CaptureFenceSync(replayState, true, sync->getCondition(), sync->getFlags(), syncID));
CaptureFenceSyncResetCalls(replayState, resourceTracker, syncID, sync);
resourceTracker->getStartingFenceSyncs().insert(syncID);
}
// Allow the replayState object to be destroyed conveniently.
replayState.setBufferBinding(context, gl::BufferBinding::Array, nullptr);
}
void CaptureMidExecutionSetup(const gl::Context *context,
std::vector<CallCapture> *setupCalls,
ResourceTracker *resourceTracker)
{
const gl::State &apiState = context->getState();
gl::State replayState(nullptr, nullptr, nullptr, nullptr, nullptr, EGL_OPENGL_ES_API,
context->getState().getClientVersion(), false, true, true, true, false,
EGL_CONTEXT_PRIORITY_MEDIUM_IMG, apiState.hasProtectedContent());
// Small helper function to make the code more readable.
auto cap = [setupCalls](CallCapture &&call) { setupCalls->emplace_back(std::move(call)); };
// Currently this code assumes we can use create-on-bind. It does not support 'Gen' usage.
// TODO(jmadill): Use handle mapping for captured objects. http://anglebug.com/3662
// Vertex input states. Only handles GLES 2.0 states right now.
// Must happen after buffer data initialization.
// TODO(http://anglebug.com/3662): Complete state capture.
// Capture default vertex attribs. Do not capture on GLES1.
if (!context->isGLES1())
{
CaptureDefaultVertexAttribs(replayState, apiState, setupCalls);
}
// Capture vertex array objects
const gl::VertexArrayMap &vertexArrayMap = context->getVertexArraysForCapture();
gl::VertexArrayID boundVertexArrayID = {0};
for (const auto &vertexArrayIter : vertexArrayMap)
{
gl::VertexArrayID vertexArrayID = {vertexArrayIter.first};
if (vertexArrayID.value != 0)
{
cap(CaptureGenVertexArrays(replayState, true, 1, &vertexArrayID));
MaybeCaptureUpdateResourceIDs(setupCalls);
}
if (vertexArrayIter.second)
{
const gl::VertexArray *vertexArray = vertexArrayIter.second;
// Bind the vertexArray (unless default) and populate it
if (vertexArrayID.value != 0)
{
cap(CaptureBindVertexArray(replayState, true, vertexArrayID));
boundVertexArrayID = vertexArrayID;
}
CaptureVertexArrayData(setupCalls, context, vertexArray, &replayState);
}
}
// Bind the current vertex array
const gl::VertexArray *currentVertexArray = apiState.getVertexArray();
if (currentVertexArray->id() != boundVertexArrayID)
{
cap(CaptureBindVertexArray(replayState, true, currentVertexArray->id()));
}
// Capture indexed buffer bindings.
const gl::BufferVector &uniformIndexedBuffers =
apiState.getOffsetBindingPointerUniformBuffers();
const gl::BufferVector &atomicCounterIndexedBuffers =
apiState.getOffsetBindingPointerAtomicCounterBuffers();
const gl::BufferVector &shaderStorageIndexedBuffers =
apiState.getOffsetBindingPointerShaderStorageBuffers();
CaptureIndexedBuffers(replayState, uniformIndexedBuffers, gl::BufferBinding::Uniform,
setupCalls);
CaptureIndexedBuffers(replayState, atomicCounterIndexedBuffers,
gl::BufferBinding::AtomicCounter, setupCalls);
CaptureIndexedBuffers(replayState, shaderStorageIndexedBuffers,
gl::BufferBinding::ShaderStorage, setupCalls);
// Capture Buffer bindings.
const gl::BoundBufferMap &boundBuffers = apiState.getBoundBuffersForCapture();
for (gl::BufferBinding binding : angle::AllEnums<gl::BufferBinding>())
{
gl::BufferID bufferID = boundBuffers[binding].id();
// Filter out redundant buffer binding commands. Note that the code in the previous section
// only binds to ARRAY_BUFFER. Therefore we only check the array binding against the binding
// we set earlier.
bool isArray = binding == gl::BufferBinding::Array;
const gl::Buffer *arrayBuffer = replayState.getArrayBuffer();
if ((isArray && arrayBuffer && arrayBuffer->id() != bufferID) ||
(!isArray && bufferID.value != 0))
{
cap(CaptureBindBuffer(replayState, true, binding, bufferID));
}
// Restore all buffer bindings for Reset
if (bufferID.value != 0)
{
CaptureBufferBindingResetCalls(replayState, resourceTracker, binding, bufferID);
}
}
// Set a unpack alignment of 1. Otherwise, computeRowPitch() will compute the wrong value,
// leading to a crash in memcpy() when capturing the texture contents.
gl::PixelUnpackState ¤tUnpackState = replayState.getUnpackState();
if (currentUnpackState.alignment != 1)
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_ALIGNMENT, 1));
currentUnpackState.alignment = 1;
}
// Capture Texture setup and data.
const gl::TextureBindingMap &boundTextures = apiState.getBoundTexturesForCapture();
// Set Texture bindings.
size_t currentActiveTexture = 0;
gl::TextureTypeMap<gl::TextureID> currentTextureBindings;
for (gl::TextureType textureType : angle::AllEnums<gl::TextureType>())
{
const gl::TextureBindingVector &bindings = boundTextures[textureType];
for (size_t bindingIndex = 0; bindingIndex < bindings.size(); ++bindingIndex)
{
gl::TextureID textureID = bindings[bindingIndex].id();
if (textureID.value != 0)
{
if (currentActiveTexture != bindingIndex)
{
cap(CaptureActiveTexture(replayState, true,
GL_TEXTURE0 + static_cast<GLenum>(bindingIndex)));
currentActiveTexture = bindingIndex;
}
if (currentTextureBindings[textureType] != textureID)
{
cap(CaptureBindTexture(replayState, true, textureType, textureID));
currentTextureBindings[textureType] = textureID;
}
}
}
}
// Set active Texture.
size_t stateActiveTexture = apiState.getActiveSampler();
if (currentActiveTexture != stateActiveTexture)
{
cap(CaptureActiveTexture(replayState, true,
GL_TEXTURE0 + static_cast<GLenum>(stateActiveTexture)));
}
// Set Renderbuffer binding.
const gl::RenderbufferManager &renderbuffers = apiState.getRenderbufferManagerForCapture();
gl::RenderbufferID currentRenderbuffer = {0};
for (const auto &renderbufIter : renderbuffers)
{
currentRenderbuffer = renderbufIter.second->id();
}
if (currentRenderbuffer != apiState.getRenderbufferId())
{
cap(CaptureBindRenderbuffer(replayState, true, GL_RENDERBUFFER,
apiState.getRenderbufferId()));
}
// Capture Framebuffers.
const gl::FramebufferManager &framebuffers = apiState.getFramebufferManagerForCapture();
gl::FramebufferID currentDrawFramebuffer = {0};
gl::FramebufferID currentReadFramebuffer = {0};
for (const auto &framebufferIter : framebuffers)
{
gl::FramebufferID id = {framebufferIter.first};
const gl::Framebuffer *framebuffer = framebufferIter.second;
// The default Framebuffer exists (by default).
if (framebuffer->isDefault())
{
continue;
}
cap(CaptureGenFramebuffers(replayState, true, 1, &id));
MaybeCaptureUpdateResourceIDs(setupCalls);
cap(CaptureBindFramebuffer(replayState, true, GL_FRAMEBUFFER, id));
currentDrawFramebuffer = currentReadFramebuffer = id;
// Color Attachments.
for (const gl::FramebufferAttachment &colorAttachment : framebuffer->getColorAttachments())
{
if (!colorAttachment.isAttached())
{
continue;
}
CaptureFramebufferAttachment(setupCalls, replayState, colorAttachment);
}
const gl::FramebufferAttachment *depthAttachment = framebuffer->getDepthAttachment();
if (depthAttachment)
{
ASSERT(depthAttachment->getBinding() == GL_DEPTH_ATTACHMENT ||
depthAttachment->getBinding() == GL_DEPTH_STENCIL_ATTACHMENT);
CaptureFramebufferAttachment(setupCalls, replayState, *depthAttachment);
}
const gl::FramebufferAttachment *stencilAttachment = framebuffer->getStencilAttachment();
if (stencilAttachment)
{
ASSERT(stencilAttachment->getBinding() == GL_STENCIL_ATTACHMENT ||
depthAttachment->getBinding() == GL_DEPTH_STENCIL_ATTACHMENT);
CaptureFramebufferAttachment(setupCalls, replayState, *stencilAttachment);
}
const std::vector<GLenum> &drawBufferStates = framebuffer->getDrawBufferStates();
cap(CaptureDrawBuffers(replayState, true, static_cast<GLsizei>(drawBufferStates.size()),
drawBufferStates.data()));
}
// Capture framebuffer bindings.
gl::FramebufferID stateReadFramebuffer = apiState.getReadFramebuffer()->id();
gl::FramebufferID stateDrawFramebuffer = apiState.getDrawFramebuffer()->id();
if (stateDrawFramebuffer == stateReadFramebuffer)
{
if (currentDrawFramebuffer != stateDrawFramebuffer ||
currentReadFramebuffer != stateReadFramebuffer)
{
cap(CaptureBindFramebuffer(replayState, true, GL_FRAMEBUFFER, stateDrawFramebuffer));
currentDrawFramebuffer = currentReadFramebuffer = stateDrawFramebuffer;
}
}
else
{
if (currentDrawFramebuffer != stateDrawFramebuffer)
{
cap(CaptureBindFramebuffer(replayState, true, GL_DRAW_FRAMEBUFFER,
currentDrawFramebuffer));
currentDrawFramebuffer = stateDrawFramebuffer;
}
if (currentReadFramebuffer != stateReadFramebuffer)
{
cap(CaptureBindFramebuffer(replayState, true, GL_READ_FRAMEBUFFER,
replayState.getReadFramebuffer()->id()));
currentReadFramebuffer = stateReadFramebuffer;
}
}
// Capture Program Pipelines
const gl::ProgramPipelineManager *programPipelineManager =
apiState.getProgramPipelineManagerForCapture();
for (const auto &ppoIterator : *programPipelineManager)
{
gl::ProgramPipeline *pipeline = ppoIterator.second;
gl::ProgramPipelineID id = {ppoIterator.first};
cap(CaptureGenProgramPipelines(replayState, true, 1, &id));
MaybeCaptureUpdateResourceIDs(setupCalls);
// PPOs can contain graphics and compute programs, so loop through all shader types rather
// than just the linked ones since getLinkedShaderStages() will return either only graphics
// or compute stages.
for (gl::ShaderType shaderType : gl::AllShaderTypes())
{
gl::Program *program = pipeline->getShaderProgram(shaderType);
if (!program)
{
continue;
}
ASSERT(program->isLinked());
GLbitfield gLbitfield = GetBitfieldFromShaderType(shaderType);
cap(CaptureUseProgramStages(replayState, true, pipeline->id(), gLbitfield,
program->id()));
}
gl::Program *program = pipeline->getActiveShaderProgram();
if (program)
{
cap(CaptureActiveShaderProgram(replayState, true, id, program->id()));
}
}
// For now we assume the installed program executable is the same as the current program.
// TODO(jmadill): Handle installed program executable. http://anglebug.com/3662
if (apiState.getProgram() && !context->isGLES1())
{
cap(CaptureUseProgram(replayState, true, apiState.getProgram()->id()));
CaptureUpdateCurrentProgram(setupCalls->back(), setupCalls);
}
else if (apiState.getProgramPipeline())
{
// glUseProgram() is called above to update the necessary uniform values for each program
// that's being recreated. If there is no program currently bound, then we need to unbind
// the last bound program so the PPO will be used instead:
// 7.4 Program Pipeline Objects
// If no current program object has been established by UseProgram, the program objects used
// for each shader stage and for uniform updates are taken from the bound program pipeline
// object, if any. If there is a current program object established by UseProgram, the bound
// program pipeline object has no effect on rendering or uniform updates.
cap(CaptureUseProgram(replayState, true, {0}));
CaptureUpdateCurrentProgram(setupCalls->back(), setupCalls);
cap(CaptureBindProgramPipeline(replayState, true, apiState.getProgramPipeline()->id()));
}
// TODO(http://anglebug.com/3662): ES 3.x objects.
// Create existing queries. Note that queries may be genned and not yet started. In that
// case the queries will exist in the query map as nullptr entries.
const gl::QueryMap &queryMap = context->getQueriesForCapture();
for (gl::QueryMap::Iterator queryIter = queryMap.beginWithNull();
queryIter != queryMap.endWithNull(); ++queryIter)
{
ASSERT(queryIter->first);
gl::QueryID queryID = {queryIter->first};
cap(CaptureGenQueries(replayState, true, 1, &queryID));
MaybeCaptureUpdateResourceIDs(setupCalls);
gl::Query *query = queryIter->second;
if (query)
{
gl::QueryType queryType = query->getType();
// Begin the query to generate the object
cap(CaptureBeginQuery(replayState, true, queryType, queryID));
// End the query if it was not active
if (!IsQueryActive(apiState, queryID))
{
cap(CaptureEndQuery(replayState, true, queryType));
}
}
}
// Transform Feedback
const gl::TransformFeedbackMap &xfbMap = context->getTransformFeedbacksForCapture();
for (const auto &xfbIter : xfbMap)
{
gl::TransformFeedbackID xfbID = {xfbIter.first};
// Do not capture the default XFB object.
if (xfbID.value == 0)
{
continue;
}
cap(CaptureGenTransformFeedbacks(replayState, true, 1, &xfbID));
MaybeCaptureUpdateResourceIDs(setupCalls);
gl::TransformFeedback *xfb = xfbIter.second;
if (!xfb)
{
// The object was never created
continue;
}
// Bind XFB to create the object
cap(CaptureBindTransformFeedback(replayState, true, GL_TRANSFORM_FEEDBACK, xfbID));
// Bind the buffers associated with this XFB object
for (size_t i = 0; i < xfb->getIndexedBufferCount(); ++i)
{
const gl::OffsetBindingPointer<gl::Buffer> &xfbBuffer = xfb->getIndexedBuffer(i);
// Note: Buffers bound with BindBufferBase can be used with BindBuffer
cap(CaptureBindBufferRange(replayState, true, gl::BufferBinding::TransformFeedback, 0,
xfbBuffer.id(), xfbBuffer.getOffset(), xfbBuffer.getSize()));
}
if (xfb->isActive() || xfb->isPaused())
{
// We don't support active XFB in MEC yet
UNIMPLEMENTED();
}
}
// Bind the current XFB buffer after populating XFB objects
gl::TransformFeedback *currentXFB = apiState.getCurrentTransformFeedback();
if (currentXFB)
{
cap(CaptureBindTransformFeedback(replayState, true, GL_TRANSFORM_FEEDBACK,
currentXFB->id()));
}
// Bind samplers
const gl::SamplerBindingVector &samplerBindings = apiState.getSamplers();
for (GLuint bindingIndex = 0; bindingIndex < static_cast<GLuint>(samplerBindings.size());
++bindingIndex)
{
gl::SamplerID samplerID = samplerBindings[bindingIndex].id();
if (samplerID.value != 0)
{
cap(CaptureBindSampler(replayState, true, bindingIndex, samplerID));
}
}
// Capture Image Texture bindings
const std::vector<gl::ImageUnit> &imageUnits = apiState.getImageUnits();
for (GLuint bindingIndex = 0; bindingIndex < static_cast<GLuint>(imageUnits.size());
++bindingIndex)
{
const gl::ImageUnit &imageUnit = imageUnits[bindingIndex];
if (imageUnit.texture == 0)
{
continue;
}
cap(CaptureBindImageTexture(replayState, true, bindingIndex, imageUnit.texture.id(),
imageUnit.level, imageUnit.layered, imageUnit.layer,
imageUnit.access, imageUnit.format));
}
// Capture GL Context states.
// TODO(http://anglebug.com/3662): Complete state capture.
auto capCap = [cap, &replayState](GLenum capEnum, bool capValue) {
if (capValue)
{
cap(CaptureEnable(replayState, true, capEnum));
}
else
{
cap(CaptureDisable(replayState, true, capEnum));
}
};
// Capture GLES1 context states.
if (context->isGLES1())
{
const bool currentTextureState = apiState.getEnableFeature(GL_TEXTURE_2D);
const bool defaultTextureState = replayState.getEnableFeature(GL_TEXTURE_2D);
if (currentTextureState != defaultTextureState)
{
capCap(GL_TEXTURE_2D, currentTextureState);
}
cap(CaptureMatrixMode(replayState, true, gl::MatrixType::Projection));
for (angle::Mat4 projectionMatrix :
apiState.gles1().getMatrixStack(gl::MatrixType::Projection))
{
cap(CapturePushMatrix(replayState, true));
cap(CaptureLoadMatrixf(replayState, true, projectionMatrix.elements().data()));
}
cap(CaptureMatrixMode(replayState, true, gl::MatrixType::Modelview));
for (angle::Mat4 modelViewMatrix :
apiState.gles1().getMatrixStack(gl::MatrixType::Modelview))
{
cap(CapturePushMatrix(replayState, true));
cap(CaptureLoadMatrixf(replayState, true, modelViewMatrix.elements().data()));
}
gl::MatrixType currentMatrixMode = apiState.gles1().getMatrixMode();
if (currentMatrixMode != gl::MatrixType::Modelview)
{
cap(CaptureMatrixMode(replayState, true, currentMatrixMode));
}
}
// Rasterizer state. Missing ES 3.x features.
const gl::RasterizerState &defaultRasterState = replayState.getRasterizerState();
const gl::RasterizerState ¤tRasterState = apiState.getRasterizerState();
if (currentRasterState.cullFace != defaultRasterState.cullFace)
{
capCap(GL_CULL_FACE, currentRasterState.cullFace);
}
if (currentRasterState.cullMode != defaultRasterState.cullMode)
{
cap(CaptureCullFace(replayState, true, currentRasterState.cullMode));
}
if (currentRasterState.frontFace != defaultRasterState.frontFace)
{
cap(CaptureFrontFace(replayState, true, currentRasterState.frontFace));
}
if (currentRasterState.polygonOffsetFill != defaultRasterState.polygonOffsetFill)
{
capCap(GL_POLYGON_OFFSET_FILL, currentRasterState.polygonOffsetFill);
}
if (currentRasterState.polygonOffsetFactor != defaultRasterState.polygonOffsetFactor ||
currentRasterState.polygonOffsetUnits != defaultRasterState.polygonOffsetUnits)
{
cap(CapturePolygonOffset(replayState, true, currentRasterState.polygonOffsetFactor,
currentRasterState.polygonOffsetUnits));
}
// pointDrawMode/multiSample are only used in the D3D back-end right now.
if (currentRasterState.rasterizerDiscard != defaultRasterState.rasterizerDiscard)
{
capCap(GL_RASTERIZER_DISCARD, currentRasterState.rasterizerDiscard);
}
if (currentRasterState.dither != defaultRasterState.dither)
{
capCap(GL_DITHER, currentRasterState.dither);
}
// Depth/stencil state.
const gl::DepthStencilState &defaultDSState = replayState.getDepthStencilState();
const gl::DepthStencilState ¤tDSState = apiState.getDepthStencilState();
if (defaultDSState.depthFunc != currentDSState.depthFunc)
{
cap(CaptureDepthFunc(replayState, true, currentDSState.depthFunc));
}
if (defaultDSState.depthMask != currentDSState.depthMask)
{
cap(CaptureDepthMask(replayState, true, gl::ConvertToGLBoolean(currentDSState.depthMask)));
}
if (defaultDSState.depthTest != currentDSState.depthTest)
{
capCap(GL_DEPTH_TEST, currentDSState.depthTest);
}
if (defaultDSState.stencilTest != currentDSState.stencilTest)
{
capCap(GL_STENCIL_TEST, currentDSState.stencilTest);
}
if (currentDSState.stencilFunc == currentDSState.stencilBackFunc &&
currentDSState.stencilMask == currentDSState.stencilBackMask)
{
// Front and back are equal
if (defaultDSState.stencilFunc != currentDSState.stencilFunc ||
defaultDSState.stencilMask != currentDSState.stencilMask ||
apiState.getStencilRef() != 0)
{
cap(CaptureStencilFunc(replayState, true, currentDSState.stencilFunc,
apiState.getStencilRef(), currentDSState.stencilMask));
}
}
else
{
// Front and back are separate
if (defaultDSState.stencilFunc != currentDSState.stencilFunc ||
defaultDSState.stencilMask != currentDSState.stencilMask ||
apiState.getStencilRef() != 0)
{
cap(CaptureStencilFuncSeparate(replayState, true, GL_FRONT, currentDSState.stencilFunc,
apiState.getStencilRef(), currentDSState.stencilMask));
}
if (defaultDSState.stencilBackFunc != currentDSState.stencilBackFunc ||
defaultDSState.stencilBackMask != currentDSState.stencilBackMask ||
apiState.getStencilBackRef() != 0)
{
cap(CaptureStencilFuncSeparate(
replayState, true, GL_BACK, currentDSState.stencilBackFunc,
apiState.getStencilBackRef(), currentDSState.stencilBackMask));
}
}
if (currentDSState.stencilFail == currentDSState.stencilBackFail &&
currentDSState.stencilPassDepthFail == currentDSState.stencilBackPassDepthFail &&
currentDSState.stencilPassDepthPass == currentDSState.stencilBackPassDepthPass)
{
// Front and back are equal
if (defaultDSState.stencilFail != currentDSState.stencilFail ||
defaultDSState.stencilPassDepthFail != currentDSState.stencilPassDepthFail ||
defaultDSState.stencilPassDepthPass != currentDSState.stencilPassDepthPass)
{
cap(CaptureStencilOp(replayState, true, currentDSState.stencilFail,
currentDSState.stencilPassDepthFail,
currentDSState.stencilPassDepthPass));
}
}
else
{
// Front and back are separate
if (defaultDSState.stencilFail != currentDSState.stencilFail ||
defaultDSState.stencilPassDepthFail != currentDSState.stencilPassDepthFail ||
defaultDSState.stencilPassDepthPass != currentDSState.stencilPassDepthPass)
{
cap(CaptureStencilOpSeparate(replayState, true, GL_FRONT, currentDSState.stencilFail,
currentDSState.stencilPassDepthFail,
currentDSState.stencilPassDepthPass));
}
if (defaultDSState.stencilBackFail != currentDSState.stencilBackFail ||
defaultDSState.stencilBackPassDepthFail != currentDSState.stencilBackPassDepthFail ||
defaultDSState.stencilBackPassDepthPass != currentDSState.stencilBackPassDepthPass)
{
cap(CaptureStencilOpSeparate(replayState, true, GL_BACK, currentDSState.stencilBackFail,
currentDSState.stencilBackPassDepthFail,
currentDSState.stencilBackPassDepthPass));
}
}
if (currentDSState.stencilWritemask == currentDSState.stencilBackWritemask)
{
// Front and back are equal
if (defaultDSState.stencilWritemask != currentDSState.stencilWritemask)
{
cap(CaptureStencilMask(replayState, true, currentDSState.stencilWritemask));
}
}
else
{
// Front and back are separate
if (defaultDSState.stencilWritemask != currentDSState.stencilWritemask)
{
cap(CaptureStencilMaskSeparate(replayState, true, GL_FRONT,
currentDSState.stencilWritemask));
}
if (defaultDSState.stencilBackWritemask != currentDSState.stencilBackWritemask)
{
cap(CaptureStencilMaskSeparate(replayState, true, GL_BACK,
currentDSState.stencilBackWritemask));
}
}
// Blend state.
const gl::BlendState &defaultBlendState = replayState.getBlendState();
const gl::BlendState ¤tBlendState = apiState.getBlendState();
if (currentBlendState.blend != defaultBlendState.blend)
{
capCap(GL_BLEND, currentBlendState.blend);
}
if (currentBlendState.sourceBlendRGB != defaultBlendState.sourceBlendRGB ||
currentBlendState.destBlendRGB != defaultBlendState.destBlendRGB ||
currentBlendState.sourceBlendAlpha != defaultBlendState.sourceBlendAlpha ||
currentBlendState.destBlendAlpha != defaultBlendState.destBlendAlpha)
{
if (currentBlendState.sourceBlendRGB == currentBlendState.sourceBlendAlpha &&
currentBlendState.destBlendRGB == currentBlendState.destBlendAlpha)
{
// Color and alpha are equal
cap(CaptureBlendFunc(replayState, true, currentBlendState.sourceBlendRGB,
currentBlendState.destBlendRGB));
}
else
{
// Color and alpha are separate
cap(CaptureBlendFuncSeparate(
replayState, true, currentBlendState.sourceBlendRGB, currentBlendState.destBlendRGB,
currentBlendState.sourceBlendAlpha, currentBlendState.destBlendAlpha));
}
}
if (currentBlendState.blendEquationRGB != defaultBlendState.blendEquationRGB ||
currentBlendState.blendEquationAlpha != defaultBlendState.blendEquationAlpha)
{
cap(CaptureBlendEquationSeparate(replayState, true, currentBlendState.blendEquationRGB,
currentBlendState.blendEquationAlpha));
}
if (currentBlendState.colorMaskRed != defaultBlendState.colorMaskRed ||
currentBlendState.colorMaskGreen != defaultBlendState.colorMaskGreen ||
currentBlendState.colorMaskBlue != defaultBlendState.colorMaskBlue ||
currentBlendState.colorMaskAlpha != defaultBlendState.colorMaskAlpha)
{
cap(CaptureColorMask(replayState, true,
gl::ConvertToGLBoolean(currentBlendState.colorMaskRed),
gl::ConvertToGLBoolean(currentBlendState.colorMaskGreen),
gl::ConvertToGLBoolean(currentBlendState.colorMaskBlue),
gl::ConvertToGLBoolean(currentBlendState.colorMaskAlpha)));
}
const gl::ColorF ¤tBlendColor = apiState.getBlendColor();
if (currentBlendColor != gl::ColorF())
{
cap(CaptureBlendColor(replayState, true, currentBlendColor.red, currentBlendColor.green,
currentBlendColor.blue, currentBlendColor.alpha));
}
// Pixel storage states.
gl::PixelPackState ¤tPackState = replayState.getPackState();
if (currentPackState.alignment != apiState.getPackAlignment())
{
cap(CapturePixelStorei(replayState, true, GL_PACK_ALIGNMENT, apiState.getPackAlignment()));
currentPackState.alignment = apiState.getPackAlignment();
}
if (currentPackState.rowLength != apiState.getPackRowLength())
{
cap(CapturePixelStorei(replayState, true, GL_PACK_ROW_LENGTH, apiState.getPackRowLength()));
currentPackState.rowLength = apiState.getPackRowLength();
}
if (currentPackState.skipRows != apiState.getPackSkipRows())
{
cap(CapturePixelStorei(replayState, true, GL_PACK_SKIP_ROWS, apiState.getPackSkipRows()));
currentPackState.skipRows = apiState.getPackSkipRows();
}
if (currentPackState.skipPixels != apiState.getPackSkipPixels())
{
cap(CapturePixelStorei(replayState, true, GL_PACK_SKIP_PIXELS,
apiState.getPackSkipPixels()));
currentPackState.skipPixels = apiState.getPackSkipPixels();
}
// We set unpack alignment above, no need to change it here
ASSERT(currentUnpackState.alignment == 1);
if (currentUnpackState.rowLength != apiState.getUnpackRowLength())
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_ROW_LENGTH,
apiState.getUnpackRowLength()));
currentUnpackState.rowLength = apiState.getUnpackRowLength();
}
if (currentUnpackState.skipRows != apiState.getUnpackSkipRows())
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_SKIP_ROWS,
apiState.getUnpackSkipRows()));
currentUnpackState.skipRows = apiState.getUnpackSkipRows();
}
if (currentUnpackState.skipPixels != apiState.getUnpackSkipPixels())
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_SKIP_PIXELS,
apiState.getUnpackSkipPixels()));
currentUnpackState.skipPixels = apiState.getUnpackSkipPixels();
}
if (currentUnpackState.imageHeight != apiState.getUnpackImageHeight())
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_IMAGE_HEIGHT,
apiState.getUnpackImageHeight()));
currentUnpackState.imageHeight = apiState.getUnpackImageHeight();
}
if (currentUnpackState.skipImages != apiState.getUnpackSkipImages())
{
cap(CapturePixelStorei(replayState, true, GL_UNPACK_SKIP_IMAGES,
apiState.getUnpackSkipImages()));
currentUnpackState.skipImages = apiState.getUnpackSkipImages();
}
// Clear state. Missing ES 3.x features.
// TODO(http://anglebug.com/3662): Complete state capture.
const gl::ColorF ¤tClearColor = apiState.getColorClearValue();
if (currentClearColor != gl::ColorF())
{
cap(CaptureClearColor(replayState, true, currentClearColor.red, currentClearColor.green,
currentClearColor.blue, currentClearColor.alpha));
}
if (apiState.getDepthClearValue() != 1.0f)
{
cap(CaptureClearDepthf(replayState, true, apiState.getDepthClearValue()));
}
if (apiState.getStencilClearValue() != 0)
{
cap(CaptureClearStencil(replayState, true, apiState.getStencilClearValue()));
}
// Viewport / scissor / clipping planes.
const gl::Rectangle ¤tViewport = apiState.getViewport();
if (currentViewport != gl::Rectangle())
{
cap(CaptureViewport(replayState, true, currentViewport.x, currentViewport.y,
currentViewport.width, currentViewport.height));
}
if (apiState.getNearPlane() != 0.0f || apiState.getFarPlane() != 1.0f)
{
cap(CaptureDepthRangef(replayState, true, apiState.getNearPlane(), apiState.getFarPlane()));
}
if (apiState.isScissorTestEnabled())
{
capCap(GL_SCISSOR_TEST, apiState.isScissorTestEnabled());
}
const gl::Rectangle ¤tScissor = apiState.getScissor();
if (currentScissor != gl::Rectangle())
{
cap(CaptureScissor(replayState, true, currentScissor.x, currentScissor.y,
currentScissor.width, currentScissor.height));
}
// Allow the replayState object to be destroyed conveniently.
replayState.setBufferBinding(context, gl::BufferBinding::Array, nullptr);
}
bool SkipCall(EntryPoint entryPoint)
{
switch (entryPoint)
{
case EntryPoint::GLDebugMessageCallback:
case EntryPoint::GLDebugMessageCallbackKHR:
case EntryPoint::GLDebugMessageControl:
case EntryPoint::GLDebugMessageControlKHR:
case EntryPoint::GLDebugMessageInsert:
case EntryPoint::GLDebugMessageInsertKHR:
case EntryPoint::GLGetDebugMessageLog:
case EntryPoint::GLGetDebugMessageLogKHR:
case EntryPoint::GLGetObjectLabelEXT:
case EntryPoint::GLGetObjectLabelKHR:
case EntryPoint::GLGetObjectPtrLabelKHR:
case EntryPoint::GLGetPointervKHR:
case EntryPoint::GLInsertEventMarkerEXT:
case EntryPoint::GLLabelObjectEXT:
case EntryPoint::GLObjectLabelKHR:
case EntryPoint::GLObjectPtrLabelKHR:
case EntryPoint::GLPopDebugGroupKHR:
case EntryPoint::GLPopGroupMarkerEXT:
case EntryPoint::GLPushDebugGroupKHR:
case EntryPoint::GLPushGroupMarkerEXT:
// Purposefully skip entry points from:
// - KHR_debug
// - EXT_debug_label
// - EXT_debug_marker
// There is no need to capture these for replaying a trace in our harness
return true;
case EntryPoint::GLGetActiveUniform:
case EntryPoint::GLGetActiveUniformsiv:
// Skip these calls because:
// - We don't use the return values.
// - Active uniform counts can vary between platforms due to cross stage optimizations
// and asking about uniforms above GL_ACTIVE_UNIFORMS triggers errors.
return true;
default:
break;
}
return false;
}
bool FindShaderProgramIDInCall(const CallCapture &call, gl::ShaderProgramID *idOut)
{
for (const ParamCapture ¶m : call.params.getParamCaptures())
{
if (param.type == ParamType::TShaderProgramID && param.name == "programPacked")
{
*idOut = param.value.ShaderProgramIDVal;
return true;
}
}
return false;
}
GLint GetAdjustedTextureCacheLevel(gl::TextureTarget target, GLint level)
{
GLint adjustedLevel = level;
// If target is a cube, we need to maintain 6 images per level
if (IsCubeMapFaceTarget(target))
{
adjustedLevel *= 6;
adjustedLevel += CubeMapTextureTargetToFaceIndex(target);
}
return adjustedLevel;
}
} // namespace
ParamCapture::ParamCapture() : type(ParamType::TGLenum), enumGroup(gl::GLenumGroup::DefaultGroup) {}
ParamCapture::ParamCapture(const char *nameIn, ParamType typeIn)
: name(nameIn), type(typeIn), enumGroup(gl::GLenumGroup::DefaultGroup)
{}
ParamCapture::~ParamCapture() = default;
ParamCapture::ParamCapture(ParamCapture &&other)
: type(ParamType::TGLenum), enumGroup(gl::GLenumGroup::DefaultGroup)
{
*this = std::move(other);
}
ParamCapture &ParamCapture::operator=(ParamCapture &&other)
{
std::swap(name, other.name);
std::swap(type, other.type);
std::swap(value, other.value);
std::swap(enumGroup, other.enumGroup);
std::swap(data, other.data);
std::swap(arrayClientPointerIndex, other.arrayClientPointerIndex);
std::swap(readBufferSizeBytes, other.readBufferSizeBytes);
std::swap(dataNElements, other.dataNElements);
return *this;
}
ParamBuffer::ParamBuffer() {}
ParamBuffer::~ParamBuffer() = default;
ParamBuffer::ParamBuffer(ParamBuffer &&other)
{
*this = std::move(other);
}
ParamBuffer &ParamBuffer::operator=(ParamBuffer &&other)
{
std::swap(mParamCaptures, other.mParamCaptures);
std::swap(mClientArrayDataParam, other.mClientArrayDataParam);
std::swap(mReadBufferSize, other.mReadBufferSize);
std::swap(mReturnValueCapture, other.mReturnValueCapture);
std::swap(mMappedBufferID, other.mMappedBufferID);
return *this;
}
ParamCapture &ParamBuffer::getParam(const char *paramName, ParamType paramType, int index)
{
ParamCapture &capture = mParamCaptures[index];
ASSERT(capture.name == paramName);
ASSERT(capture.type == paramType);
return capture;
}
const ParamCapture &ParamBuffer::getParam(const char *paramName,
ParamType paramType,
int index) const
{
return const_cast<ParamBuffer *>(this)->getParam(paramName, paramType, index);
}
ParamCapture &ParamBuffer::getParamFlexName(const char *paramName1,
const char *paramName2,
ParamType paramType,
int index)
{
ParamCapture &capture = mParamCaptures[index];
ASSERT(capture.name == paramName1 || capture.name == paramName2);
ASSERT(capture.type == paramType);
return capture;
}
const ParamCapture &ParamBuffer::getParamFlexName(const char *paramName1,
const char *paramName2,
ParamType paramType,
int index) const
{
return const_cast<ParamBuffer *>(this)->getParamFlexName(paramName1, paramName2, paramType,
index);
}
void ParamBuffer::addParam(ParamCapture &¶m)
{
if (param.arrayClientPointerIndex != -1)
{
ASSERT(mClientArrayDataParam == -1);
mClientArrayDataParam = static_cast<int>(mParamCaptures.size());
}
mReadBufferSize = std::max(param.readBufferSizeBytes, mReadBufferSize);
mParamCaptures.emplace_back(std::move(param));
}
void ParamBuffer::addReturnValue(ParamCapture &&returnValue)
{
mReturnValueCapture = std::move(returnValue);
}
ParamCapture &ParamBuffer::getClientArrayPointerParameter()
{
ASSERT(hasClientArrayData());
return mParamCaptures[mClientArrayDataParam];
}
CallCapture::CallCapture(EntryPoint entryPointIn, ParamBuffer &¶msIn)
: entryPoint(entryPointIn), params(std::move(paramsIn))
{}
CallCapture::CallCapture(const std::string &customFunctionNameIn, ParamBuffer &¶msIn)
: entryPoint(EntryPoint::GLInvalid),
customFunctionName(customFunctionNameIn),
params(std::move(paramsIn))
{}
CallCapture::~CallCapture() = default;
CallCapture::CallCapture(CallCapture &&other)
{
*this = std::move(other);
}
CallCapture &CallCapture::operator=(CallCapture &&other)
{
std::swap(entryPoint, other.entryPoint);
std::swap(customFunctionName, other.customFunctionName);
std::swap(params, other.params);
return *this;
}
const char *CallCapture::name() const
{
if (entryPoint == EntryPoint::GLInvalid)
{
ASSERT(!customFunctionName.empty());
return customFunctionName.c_str();
}
return angle::GetEntryPointName(entryPoint);
}
ReplayContext::ReplayContext(size_t readBufferSizebytes,
const gl::AttribArray<size_t> &clientArraysSizebytes)
{
mReadBuffer.resize(readBufferSizebytes);
for (uint32_t i = 0; i < clientArraysSizebytes.size(); i++)
{
mClientArraysBuffer[i].resize(clientArraysSizebytes[i]);
}
}
ReplayContext::~ReplayContext() {}
FrameCapture::FrameCapture() = default;
FrameCapture::~FrameCapture() = default;
void FrameCapture::reset()
{
mSetupCalls.clear();
}
FrameCaptureShared::FrameCaptureShared()
: mEnabled(true),
mSerializeStateEnabled(false),
mCompression(true),
mClientVertexArrayMap{},
mFrameIndex(1),
mCaptureStartFrame(1),
mCaptureEndFrame(10),
mClientArraySizes{},
mReadBufferSize(0),
mHasResourceType{},
mCaptureTrigger(0),
mWindowSurfaceContextID({0})
{
reset();
std::string enabledFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kEnabledVarName, kAndroidCaptureEnabled);
if (enabledFromEnv == "0")
{
mEnabled = false;
}
std::string pathFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kOutDirectoryVarName, kAndroidOutDir);
if (pathFromEnv.empty())
{
mOutDirectory = GetDefaultOutDirectory();
}
else
{
mOutDirectory = pathFromEnv;
}
// Ensure the capture path ends with a slash.
if (mOutDirectory.back() != '\\' && mOutDirectory.back() != '/')
{
mOutDirectory += '/';
}
std::string startFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kFrameStartVarName, kAndroidFrameStart);
if (!startFromEnv.empty())
{
mCaptureStartFrame = atoi(startFromEnv.c_str());
}
std::string endFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kFrameEndVarName, kAndroidFrameEnd);
if (!endFromEnv.empty())
{
mCaptureEndFrame = atoi(endFromEnv.c_str());
}
std::string captureTriggerFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kCaptureTriggerVarName, kAndroidCaptureTrigger);
if (!captureTriggerFromEnv.empty())
{
mCaptureTrigger = atoi(captureTriggerFromEnv.c_str());
// If the trigger has been populated, ignore the other frame range variables by setting them
// to unreasonable values. This isn't perfect, but it is effective.
mCaptureStartFrame = mCaptureEndFrame = std::numeric_limits<uint32_t>::max();
INFO() << "Capture trigger detected, disabling capture start/end frame.";
}
std::string labelFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kCaptureLabel, kAndroidCaptureLabel);
if (!labelFromEnv.empty())
{
// Optional label to provide unique file names and namespaces
mCaptureLabel = labelFromEnv;
}
std::string compressionFromEnv =
GetEnvironmentVarOrUnCachedAndroidProperty(kCompression, kAndroidCompression);
if (compressionFromEnv == "0")
{
mCompression = false;
}
std::string serializeStateEnabledFromEnv =
angle::GetEnvironmentVar(kSerializeStateEnabledVarName);
if (serializeStateEnabledFromEnv == "1")
{
mSerializeStateEnabled = true;
}
}
FrameCaptureShared::~FrameCaptureShared() = default;
void FrameCaptureShared::copyCompressedTextureData(const gl::Context *context,
const CallCapture &call)
{
// For compressed textures, we need to copy the source data that was already captured into a new
// cached texture entry for use during mid-execution capture, rather than reading it back with
// ANGLE_get_image.
GLenum srcTarget = call.params.getParam("srcTarget", ParamType::TGLenum, 1).value.GLenumVal;
GLenum dstTarget = call.params.getParam("dstTarget", ParamType::TGLenum, 7).value.GLenumVal;
// TODO(anglebug.com/6104): Type of incoming ID varies based on target type, but we're only
// handling textures for now. If either of these asserts fire, then we need to add renderbuffer
// support.
ASSERT(srcTarget == GL_TEXTURE_2D || srcTarget == GL_TEXTURE_2D_ARRAY ||
srcTarget == GL_TEXTURE_3D || srcTarget == GL_TEXTURE_CUBE_MAP);
ASSERT(dstTarget == GL_TEXTURE_2D || dstTarget == GL_TEXTURE_2D_ARRAY ||
dstTarget == GL_TEXTURE_3D || dstTarget == GL_TEXTURE_CUBE_MAP);
gl::TextureID srcName =
call.params.getParam("srcName", ParamType::TTextureID, 0).value.TextureIDVal;
GLint srcLevel = call.params.getParam("srcLevel", ParamType::TGLint, 2).value.GLintVal;
gl::TextureID dstName =
call.params.getParam("dstName", ParamType::TTextureID, 6).value.TextureIDVal;
GLint dstLevel = call.params.getParam("dstLevel", ParamType::TGLint, 8).value.GLintVal;
// Look up the texture type
gl::TextureTarget dstTargetPacked = gl::PackParam<gl::TextureTarget>(dstTarget);
gl::TextureType dstTextureType = gl::TextureTargetToType(dstTargetPacked);
// Look up the currently bound texture
gl::Texture *dstTexture = context->getState().getTargetTexture(dstTextureType);
ASSERT(dstTexture);
const gl::InternalFormat &dstFormat = *dstTexture->getFormat(dstTargetPacked, dstLevel).info;
if (dstFormat.compressed)
{
context->getShareGroup()->getFrameCaptureShared()->copyCachedTextureLevel(
context, srcName, srcLevel, dstName, dstLevel, call);
}
// Also track that the destination texture has been updated
mResourceTracker.getTrackedResource(ResourceIDType::Texture).setModifiedResource(dstName.value);
}
void FrameCaptureShared::captureCompressedTextureData(const gl::Context *context,
const CallCapture &call)
{
// For compressed textures, track a shadow copy of the data
// for use during mid-execution capture, rather than reading it back
// with ANGLE_get_image
// Storing the compressed data is handled the same for all entry points,
// they just have slightly different parameter locations
int dataParamOffset = -1;
int xoffsetParamOffset = -1;
int yoffsetParamOffset = -1;
int zoffsetParamOffset = -1;
int widthParamOffset = -1;
int heightParamOffset = -1;
int depthParamOffset = -1;
switch (call.entryPoint)
{
case EntryPoint::GLCompressedTexSubImage3D:
xoffsetParamOffset = 2;
yoffsetParamOffset = 3;
zoffsetParamOffset = 4;
widthParamOffset = 5;
heightParamOffset = 6;
depthParamOffset = 7;
dataParamOffset = 10;
break;
case EntryPoint::GLCompressedTexImage3D:
widthParamOffset = 3;
heightParamOffset = 4;
depthParamOffset = 5;
dataParamOffset = 8;
break;
case EntryPoint::GLCompressedTexSubImage2D:
xoffsetParamOffset = 2;
yoffsetParamOffset = 3;
widthParamOffset = 4;
heightParamOffset = 5;
dataParamOffset = 8;
break;
case EntryPoint::GLCompressedTexImage2D:
widthParamOffset = 3;
heightParamOffset = 4;
dataParamOffset = 7;
break;
default:
// There should be no other callers of this function
ASSERT(0);
break;
}
gl::Buffer *pixelUnpackBuffer =
context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
const uint8_t *data = static_cast<const uint8_t *>(
call.params.getParam("data", ParamType::TvoidConstPointer, dataParamOffset)
.value.voidConstPointerVal);
GLsizei imageSize = call.params.getParam("imageSize", ParamType::TGLsizei, dataParamOffset - 1)
.value.GLsizeiVal;
const uint8_t *pixelData = nullptr;
if (pixelUnpackBuffer)
{
// If using pixel unpack buffer, map the buffer and track its data
ASSERT(!pixelUnpackBuffer->isMapped());
(void)pixelUnpackBuffer->mapRange(context, reinterpret_cast<GLintptr>(data), imageSize,
GL_MAP_READ_BIT);
pixelData = reinterpret_cast<const uint8_t *>(pixelUnpackBuffer->getMapPointer());
}
else
{
pixelData = data;
}
if (!pixelData)
{
// If no pointer was provided and we weren't able to map the buffer, there is no data to
// capture
return;
}
// Look up the texture type
gl::TextureTarget targetPacked =
call.params.getParam("targetPacked", ParamType::TTextureTarget, 0).value.TextureTargetVal;
gl::TextureType textureType = gl::TextureTargetToType(targetPacked);
// Create a copy of the incoming data
std::vector<uint8_t> compressedData;
compressedData.assign(pixelData, pixelData + imageSize);
// Look up the currently bound texture
gl::Texture *texture = context->getState().getTargetTexture(textureType);
ASSERT(texture);
// Record the data, indexed by textureID and level
GLint level = call.params.getParam("level", ParamType::TGLint, 1).value.GLintVal;
std::vector<uint8_t> &levelData =
context->getShareGroup()->getFrameCaptureShared()->getCachedTextureLevelData(
texture, targetPacked, level, call.entryPoint);
// Unpack the various pixel rectangle parameters.
ASSERT(widthParamOffset != -1);
ASSERT(heightParamOffset != -1);
GLsizei pixelWidth =
call.params.getParam("width", ParamType::TGLsizei, widthParamOffset).value.GLsizeiVal;
GLsizei pixelHeight =
call.params.getParam("height", ParamType::TGLsizei, heightParamOffset).value.GLsizeiVal;
GLsizei pixelDepth = 1;
if (depthParamOffset != -1)
{
pixelDepth =
call.params.getParam("depth", ParamType::TGLsizei, depthParamOffset).value.GLsizeiVal;
}
GLint xoffset = 0;
GLint yoffset = 0;
GLint zoffset = 0;
if (xoffsetParamOffset != -1)
{
xoffset =
call.params.getParam("xoffset", ParamType::TGLint, xoffsetParamOffset).value.GLintVal;
}
if (yoffsetParamOffset != -1)
{
yoffset =
call.params.getParam("yoffset", ParamType::TGLint, yoffsetParamOffset).value.GLintVal;
}
if (zoffsetParamOffset != -1)
{
zoffset =
call.params.getParam("zoffset", ParamType::TGLint, zoffsetParamOffset).value.GLintVal;
}
// Get the format of the texture for use with the compressed block size math.
const gl::InternalFormat &format = *texture->getFormat(targetPacked, level).info;
// Divide dimensions according to block size.
const gl::Extents &levelExtents = texture->getExtents(targetPacked, level);
// Scale down the width/height pixel offsets to reflect block size
int blockWidth = static_cast<int>(format.compressedBlockWidth);
int blockHeight = static_cast<int>(format.compressedBlockHeight);
ASSERT(format.compressedBlockDepth == 1);
// Round the incoming width and height up to align with block size
pixelWidth = rx::roundUp(pixelWidth, blockWidth);
pixelHeight = rx::roundUp(pixelHeight, blockHeight);
// Scale the width, height, and offsets
pixelWidth /= blockWidth;
pixelHeight /= blockHeight;
xoffset /= blockWidth;
yoffset /= blockHeight;
GLint pixelBytes = static_cast<GLint>(format.pixelBytes);
// Also round the texture's width and height up to reflect block size
int levelWidth = rx::roundUp(levelExtents.width, blockWidth);
int levelHeight = rx::roundUp(levelExtents.height, blockHeight);
GLint pixelRowPitch = pixelWidth * pixelBytes;
GLint pixelDepthPitch = pixelRowPitch * pixelHeight;
GLint levelRowPitch = (levelWidth / blockWidth) * pixelBytes;
GLint levelDepthPitch = (levelHeight / blockHeight) * levelRowPitch;
for (GLint zindex = 0; zindex < pixelDepth; ++zindex)
{
GLint z = zindex + zoffset;
for (GLint yindex = 0; yindex < pixelHeight; ++yindex)
{
GLint y = yindex + yoffset;
GLint pixelOffset = zindex * pixelDepthPitch + yindex * pixelRowPitch;
GLint levelOffset = z * levelDepthPitch + y * levelRowPitch + xoffset * pixelBytes;
ASSERT(static_cast<size_t>(levelOffset + pixelRowPitch) <= levelData.size());
memcpy(&levelData[levelOffset], &pixelData[pixelOffset], pixelRowPitch);
}
}
if (pixelUnpackBuffer)
{
GLboolean success;
(void)pixelUnpackBuffer->unmap(context, &success);
ASSERT(success);
}
}
void FrameCaptureShared::trackBufferMapping(CallCapture *call,
gl::BufferID id,
GLintptr offset,
GLsizeiptr length,
bool writable)
{
// Track that the buffer was mapped
mResourceTracker.setBufferMapped(id.value);
if (writable)
{
// If this buffer was mapped writable, we don't have any visibility into what
// happens to it. Therefore, remember the details about it, and we'll read it back
// on Unmap to repopulate it during replay.
mBufferDataMap[id] = std::make_pair(offset, length);
// Track that this buffer was potentially modified
mResourceTracker.getTrackedResource(ResourceIDType::Buffer).setModifiedResource(id.value);
// Track the bufferID that was just mapped for use when writing return value
call->params.setMappedBufferID(id);
}
}
void FrameCaptureShared::trackTextureUpdate(const gl::Context *context, const CallCapture &call)
{
int index = 0;
std::string paramName = "targetPacked";
// Some calls provide the textureID directly
switch (call.entryPoint)
{
case EntryPoint::GLCompressedCopyTextureCHROMIUM:
index = 1;
paramName = "destIdPacked";
break;
case EntryPoint::GLCopyTextureCHROMIUM:
case EntryPoint::GLCopySubTextureCHROMIUM:
index = 3;
paramName = "destIdPacked";
break;
default:
break;
}
// For the rest, look it up based on the currently bound texture
GLuint id = 0;
if (index == 0)
{
gl::TextureTarget targetPacked =
call.params.getParam(paramName.c_str(), ParamType::TTextureTarget, index)
.value.TextureTargetVal;
gl::TextureType textureType = gl::TextureTargetToType(targetPacked);
gl::Texture *texture = context->getState().getTargetTexture(textureType);
id = texture->id().value;
}
else
{
gl::TextureID destIDPacked =
call.params.getParam(paramName.c_str(), ParamType::TTextureID, index)
.value.TextureIDVal;
id = destIDPacked.value;
}
// Mark it as modified
mResourceTracker.getTrackedResource(ResourceIDType::Texture).setModifiedResource(id);
}
void FrameCaptureShared::updateCopyImageSubData(CallCapture &call)
{
// This call modifies srcName and dstName to no longer be object IDs (GLuint), but actual
// packed types that can remapped using gTextureMap and gRenderbufferMap
GLint srcName = call.params.getParam("srcName", ParamType::TGLuint, 0).value.GLuintVal;
GLenum srcTarget = call.params.getParam("srcTarget", ParamType::TGLenum, 1).value.GLenumVal;
switch (srcTarget)
{
case GL_RENDERBUFFER:
{
// Convert the GLuint to RenderbufferID
gl::RenderbufferID srcRenderbufferID = {static_cast<GLuint>(srcName)};
call.params.setValueParamAtIndex("srcName", ParamType::TRenderbufferID,
srcRenderbufferID, 0);
break;
}
case GL_TEXTURE_2D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_3D:
case GL_TEXTURE_CUBE_MAP:
{
// Convert the GLuint to TextureID
gl::TextureID srcTextureID = {static_cast<GLuint>(srcName)};
call.params.setValueParamAtIndex("srcName", ParamType::TTextureID, srcTextureID, 0);
break;
}
default:
ERR() << "Unhandled srcTarget = " << srcTarget;
UNREACHABLE();
break;
}
// Change dstName to the appropriate type based on dstTarget
GLint dstName = call.params.getParam("dstName", ParamType::TGLuint, 6).value.GLuintVal;
GLenum dstTarget = call.params.getParam("dstTarget", ParamType::TGLenum, 7).value.GLenumVal;
switch (dstTarget)
{
case GL_RENDERBUFFER:
{
// Convert the GLuint to RenderbufferID
gl::RenderbufferID dstRenderbufferID = {static_cast<GLuint>(dstName)};
call.params.setValueParamAtIndex("dstName", ParamType::TRenderbufferID,
dstRenderbufferID, 6);
break;
}
case GL_TEXTURE_2D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_3D:
case GL_TEXTURE_CUBE_MAP:
{
// Convert the GLuint to TextureID
gl::TextureID dstTextureID = {static_cast<GLuint>(dstName)};
call.params.setValueParamAtIndex("dstName", ParamType::TTextureID, dstTextureID, 6);
break;
}
default:
ERR() << "Unhandled dstTarget = " << dstTarget;
UNREACHABLE();
break;
}
}
void FrameCaptureShared::maybeOverrideEntryPoint(const gl::Context *context, CallCapture &call)
{
switch (call.entryPoint)
{
case EntryPoint::GLEGLImageTargetTexture2DOES:
{
// We don't support reading EGLImages. Instead, just pull from a tiny null texture.
// TODO (anglebug.com/4964): Read back the image data and populate the texture.
std::vector<uint8_t> pixelData = {0, 0, 0, 0};
call = CaptureTexSubImage2D(context->getState(), true, gl::TextureTarget::_2D, 0, 0, 0,
1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
break;
}
case EntryPoint::GLEGLImageTargetRenderbufferStorageOES:
{
UNIMPLEMENTED();
break;
}
case EntryPoint::GLCopyImageSubData:
case EntryPoint::GLCopyImageSubDataEXT:
case EntryPoint::GLCopyImageSubDataOES:
{
// We must look at the src and dst target types to determine which remap table to use
updateCopyImageSubData(call);
break;
}
default:
break;
}
}
void FrameCaptureShared::maybeCaptureDrawArraysClientData(const gl::Context *context,
CallCapture &call,
size_t instanceCount)
{
if (!context->getStateCache().hasAnyActiveClientAttrib())
{
return;
}
// Get counts from paramBuffer.
GLint firstVertex =
call.params.getParamFlexName("first", "start", ParamType::TGLint, 1).value.GLintVal;
GLsizei drawCount = call.params.getParam("count", ParamType::TGLsizei, 2).value.GLsizeiVal;
captureClientArraySnapshot(context, firstVertex + drawCount, instanceCount);
}
void FrameCaptureShared::maybeCaptureDrawElementsClientData(const gl::Context *context,
CallCapture &call,
size_t instanceCount)
{
if (!context->getStateCache().hasAnyActiveClientAttrib())
{
return;
}
// if the count is zero then the index evaluation is not valid and we wouldn't be drawing
// anything anyway, so skip capturing
GLsizei count = call.params.getParam("count", ParamType::TGLsizei, 1).value.GLsizeiVal;
if (count == 0)
{
return;
}
gl::DrawElementsType drawElementsType =
call.params.getParam("typePacked", ParamType::TDrawElementsType, 2)
.value.DrawElementsTypeVal;
const void *indices =
call.params.getParam("indices", ParamType::TvoidConstPointer, 3).value.voidConstPointerVal;
gl::IndexRange indexRange;
bool restart = context->getState().isPrimitiveRestartEnabled();
gl::Buffer *elementArrayBuffer = context->getState().getVertexArray()->getElementArrayBuffer();
if (elementArrayBuffer)
{
size_t offset = reinterpret_cast<size_t>(indices);
(void)elementArrayBuffer->getIndexRange(context, drawElementsType, offset, count, restart,
&indexRange);
}
else
{
ASSERT(indices);
indexRange = gl::ComputeIndexRange(drawElementsType, indices, count, restart);
}
// index starts from 0
captureClientArraySnapshot(context, indexRange.end + 1, instanceCount);
}
void FrameCaptureShared::maybeCapturePreCallUpdates(const gl::Context *context, CallCapture &call)
{
switch (call.entryPoint)
{
case EntryPoint::GLVertexAttribPointer:
case EntryPoint::GLVertexPointer:
case EntryPoint::GLColorPointer:
case EntryPoint::GLTexCoordPointer:
case EntryPoint::GLNormalPointer:
case EntryPoint::GLPointSizePointerOES:
{
// Get array location
GLuint index = 0;
if (call.entryPoint == EntryPoint::GLVertexAttribPointer)
{
index = call.params.getParam("index", ParamType::TGLuint, 0).value.GLuintVal;
}
else
{
gl::ClientVertexArrayType type;
switch (call.entryPoint)
{
case EntryPoint::GLVertexPointer:
type = gl::ClientVertexArrayType::Vertex;
break;
case EntryPoint::GLColorPointer:
type = gl::ClientVertexArrayType::Color;
break;
case EntryPoint::GLTexCoordPointer:
type = gl::ClientVertexArrayType::TextureCoord;
break;
case EntryPoint::GLNormalPointer:
type = gl::ClientVertexArrayType::Normal;
break;
case EntryPoint::GLPointSizePointerOES:
type = gl::ClientVertexArrayType::PointSize;
break;
default:
UNREACHABLE();
type = gl::ClientVertexArrayType::InvalidEnum;
}
index = gl::GLES1Renderer::VertexArrayIndex(type, context->getState().gles1());
}
if (call.params.hasClientArrayData())
{
mClientVertexArrayMap[index] = static_cast<int>(mFrameCalls.size());
}
else
{
mClientVertexArrayMap[index] = -1;
}
break;
}
case EntryPoint::GLGenTextures:
{
GLsizei count = call.params.getParam("n", ParamType::TGLsizei, 0).value.GLsizeiVal;
const gl::TextureID *textureIDs =
call.params.getParam("texturesPacked", ParamType::TTextureIDPointer, 1)
.value.TextureIDPointerVal;
for (GLsizei i = 0; i < count; i++)
{
// If we're capturing, track what new textures have been genned
if (isCaptureActive())
{
mResourceTracker.getTrackedResource(ResourceIDType::Texture)
.setGennedResource(textureIDs[i].value);
}
}
break;
}
case EntryPoint::GLDeleteBuffers:
{
GLsizei count = call.params.getParam("n", ParamType::TGLsizei, 0).value.GLsizeiVal;
const gl::BufferID *bufferIDs =
call.params.getParam("buffersPacked", ParamType::TBufferIDConstPointer, 1)
.value.BufferIDConstPointerVal;
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
for (GLsizei i = 0; i < count; i++)
{
// For each buffer being deleted, check our backup of data and remove it
const auto &bufferDataInfo = mBufferDataMap.find(bufferIDs[i]);
if (bufferDataInfo != mBufferDataMap.end())
{
mBufferDataMap.erase(bufferDataInfo);
}
// If we're capturing, track what buffers have been deleted
if (frameCaptureShared->isCaptureActive())
{
resourceTracker.getTrackedResource(ResourceIDType::Buffer)
.setDeletedResource(bufferIDs[i].value);
}
}
break;
}
case EntryPoint::GLGenBuffers:
{
GLsizei count = call.params.getParam("n", ParamType::TGLsizei, 0).value.GLsizeiVal;
const gl::BufferID *bufferIDs =
call.params.getParam("buffersPacked", ParamType::TBufferIDPointer, 1)
.value.BufferIDPointerVal;
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
for (GLsizei i = 0; i < count; i++)
{
// If we're capturing, track what new buffers have been genned
if (frameCaptureShared->isCaptureActive())
{
resourceTracker.getTrackedResource(ResourceIDType::Buffer)
.setGennedResource(bufferIDs[i].value);
}
}
break;
}
case EntryPoint::GLDeleteSync:
{
GLsync sync = call.params.getParam("sync", ParamType::TGLsync, 0).value.GLsyncVal;
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
// If we're capturing, track which fence sync has been deleted
if (frameCaptureShared->isCaptureActive())
{
resourceTracker.setDeletedFenceSync(sync);
}
break;
}
case EntryPoint::GLDrawArrays:
{
maybeCaptureDrawArraysClientData(context, call, 1);
break;
}
case EntryPoint::GLDrawArraysInstanced:
case EntryPoint::GLDrawArraysInstancedANGLE:
case EntryPoint::GLDrawArraysInstancedEXT:
{
GLsizei instancecount =
call.params.getParamFlexName("instancecount", "primcount", ParamType::TGLsizei, 3)
.value.GLsizeiVal;
maybeCaptureDrawArraysClientData(context, call, instancecount);
break;
}
case EntryPoint::GLDrawElements:
{
maybeCaptureDrawElementsClientData(context, call, 1);
break;
}
case EntryPoint::GLDrawElementsInstanced:
case EntryPoint::GLDrawElementsInstancedANGLE:
case EntryPoint::GLDrawElementsInstancedEXT:
{
GLsizei instancecount =
call.params.getParamFlexName("instancecount", "primcount", ParamType::TGLsizei, 4)
.value.GLsizeiVal;
maybeCaptureDrawElementsClientData(context, call, instancecount);
break;
}
case EntryPoint::GLCreateShaderProgramv:
{
// Refresh the cached shader sources.
// The command CreateShaderProgramv() creates a stand-alone program from an array of
// null-terminated source code strings for a single shader type, so we need update the
// Shader and Program sources, similar to GLCompileShader + GLLinkProgram handling.
gl::ShaderProgramID programID = {call.params.getReturnValue().value.GLuintVal};
const ParamCapture ¶mCapture =
call.params.getParam("typePacked", ParamType::TShaderType, 0);
gl::ShaderType shaderType = paramCapture.value.ShaderTypeVal;
gl::Program *program = context->getProgramResolveLink(programID);
ASSERT(program);
const gl::Shader *shader = program->getAttachedShader(shaderType);
ASSERT(shader);
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
frameCaptureShared->setShaderSource(shader->getHandle(), shader->getSourceString());
frameCaptureShared->setProgramSources(programID, GetAttachedProgramSources(program));
if (isCaptureActive())
{
frameCaptureShared->getResourceTracker()
.getTrackedResource(ResourceIDType::ShaderProgram)
.setGennedResource(programID.value);
}
break;
}
case EntryPoint::GLCreateProgram:
{
// If we're capturing, track which programs have been created
if (isCaptureActive())
{
gl::ShaderProgramID programID = {call.params.getReturnValue().value.GLuintVal};
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
resourceTracker.getTrackedResource(ResourceIDType::ShaderProgram)
.setGennedResource(programID.value);
}
break;
}
case EntryPoint::GLDeleteProgram:
{
// If we're capturing, track which programs have been deleted
if (isCaptureActive())
{
const ParamCapture ¶m =
call.params.getParam("programPacked", ParamType::TShaderProgramID, 0);
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
resourceTracker.getTrackedResource(ResourceIDType::ShaderProgram)
.setDeletedResource(param.value.ShaderProgramIDVal.value);
}
break;
}
case EntryPoint::GLCompileShader:
{
// Refresh the cached shader sources.
gl::ShaderProgramID shaderID =
call.params.getParam("shaderPacked", ParamType::TShaderProgramID, 0)
.value.ShaderProgramIDVal;
const gl::Shader *shader = context->getShader(shaderID);
context->getShareGroup()->getFrameCaptureShared()->setShaderSource(
shaderID, shader->getSourceString());
break;
}
case EntryPoint::GLLinkProgram:
{
// Refresh the cached program sources.
gl::ShaderProgramID programID =
call.params.getParam("programPacked", ParamType::TShaderProgramID, 0)
.value.ShaderProgramIDVal;
const gl::Program *program = context->getProgramResolveLink(programID);
context->getShareGroup()->getFrameCaptureShared()->setProgramSources(
programID, GetAttachedProgramSources(program));
break;
}
case EntryPoint::GLCompressedTexImage1D:
case EntryPoint::GLCompressedTexSubImage1D:
{
UNIMPLEMENTED();
break;
}
case EntryPoint::GLCompressedTexImage2D:
case EntryPoint::GLCompressedTexImage3D:
case EntryPoint::GLCompressedTexSubImage2D:
case EntryPoint::GLCompressedTexSubImage3D:
{
captureCompressedTextureData(context, call);
break;
}
case EntryPoint::GLCopyImageSubData:
case EntryPoint::GLCopyImageSubDataEXT:
case EntryPoint::GLCopyImageSubDataOES:
{
// glCopyImageSubData supports copying compressed and uncompressed texture formats.
copyCompressedTextureData(context, call);
break;
}
case EntryPoint::GLDeleteTextures:
{
// Free any TextureLevelDataMap entries being tracked for this texture
// This is to cover the scenario where a texture has been created, its
// levels cached, then texture deleted and recreated, receiving the same ID
// Look up how many textures are being deleted
GLsizei n = call.params.getParam("n", ParamType::TGLsizei, 0).value.GLsizeiVal;
// Look up the pointer to list of textures
const gl::TextureID *textureIDs =
call.params.getParam("texturesPacked", ParamType::TTextureIDConstPointer, 1)
.value.TextureIDConstPointerVal;
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
// For each texture listed for deletion
for (int32_t i = 0; i < n; ++i)
{
// Look it up in the cache, and delete it if found
context->getShareGroup()->getFrameCaptureShared()->deleteCachedTextureLevelData(
textureIDs[i]);
// If we're capturing, track what textures have been deleted
if (isCaptureActive())
{
resourceTracker.getTrackedResource(ResourceIDType::Texture)
.setDeletedResource(textureIDs[i].value);
}
}
break;
}
case EntryPoint::GLMapBuffer:
case EntryPoint::GLMapBufferOES:
{
gl::BufferBinding target =
call.params.getParam("targetPacked", ParamType::TBufferBinding, 0)
.value.BufferBindingVal;
GLbitfield access =
call.params.getParam("access", ParamType::TGLenum, 1).value.GLenumVal;
gl::Buffer *buffer = context->getState().getTargetBuffer(target);
GLintptr offset = 0;
GLsizeiptr length = static_cast<GLsizeiptr>(buffer->getSize());
bool writable =
access == GL_WRITE_ONLY_OES || access == GL_WRITE_ONLY || access == GL_READ_WRITE;
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
frameCaptureShared->trackBufferMapping(&call, buffer->id(), offset, length, writable);
break;
}
case EntryPoint::GLUnmapNamedBuffer:
{
UNIMPLEMENTED();
break;
}
case EntryPoint::GLMapBufferRange:
case EntryPoint::GLMapBufferRangeEXT:
{
GLintptr offset =
call.params.getParam("offset", ParamType::TGLintptr, 1).value.GLintptrVal;
GLsizeiptr length =
call.params.getParam("length", ParamType::TGLsizeiptr, 2).value.GLsizeiptrVal;
GLbitfield access =
call.params.getParam("access", ParamType::TGLbitfield, 3).value.GLbitfieldVal;
gl::BufferBinding target =
call.params.getParam("targetPacked", ParamType::TBufferBinding, 0)
.value.BufferBindingVal;
gl::Buffer *buffer = context->getState().getTargetBuffer(target);
FrameCaptureShared *frameCaptureShared =
context->getShareGroup()->getFrameCaptureShared();
frameCaptureShared->trackBufferMapping(&call, buffer->id(), offset, length,
access & GL_MAP_WRITE_BIT);
break;
}
case EntryPoint::GLUnmapBuffer:
case EntryPoint::GLUnmapBufferOES:
{
// See if we need to capture the buffer contents
captureMappedBufferSnapshot(context, call);
// Track that the buffer was unmapped, for use during state reset
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
gl::BufferBinding target =
call.params.getParam("targetPacked", ParamType::TBufferBinding, 0)
.value.BufferBindingVal;
gl::Buffer *buffer = context->getState().getTargetBuffer(target);
resourceTracker.setBufferUnmapped(buffer->id().value);
break;
}
case EntryPoint::GLBufferData:
case EntryPoint::GLBufferSubData:
{
gl::BufferBinding target =
call.params.getParam("targetPacked", ParamType::TBufferBinding, 0)
.value.BufferBindingVal;
gl::Buffer *buffer = context->getState().getTargetBuffer(target);
// Track that this buffer's contents have been modified
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
resourceTracker.getTrackedResource(ResourceIDType::Buffer)
.setModifiedResource(buffer->id().value);
// BufferData is equivalent to UnmapBuffer, for what we're tracking.
// From the ES 3.1 spec in BufferData section:
// If any portion of the buffer object is mapped in the current context or any
// context current to another thread, it is as though UnmapBuffer (see section
// 6.3.1) is executed in each such context prior to deleting the existing data
// store.
// Track that the buffer was unmapped, for use during state reset
resourceTracker.setBufferUnmapped(buffer->id().value);
break;
}
default:
break;
}
if (IsTextureUpdate(call))
{
// If this call modified texture contents, track it for possible reset
trackTextureUpdate(context, call);
}
updateReadBufferSize(call.params.getReadBufferSize());
gl::ShaderProgramID shaderProgramID;
if (FindShaderProgramIDInCall(call, &shaderProgramID))
{
ResourceTracker &resourceTracker = context->getFrameCaptureSharedResourceTracker();
resourceTracker.onShaderProgramAccess(shaderProgramID);
}
}
void FrameCaptureShared::captureCall(const gl::Context *context,
CallCapture &&call,
bool isCallValid)
{
if (SkipCall(call.entryPoint))
{
return;
}
if (isCallValid)
{
maybeOverrideEntryPoint(context, call);
maybeCapturePreCallUpdates(context, call);
mFrameCalls.emplace_back(std::move(call));
maybeCapturePostCallUpdates(context);
}
else
{
INFO() << "FrameCapture: Not capturing invalid call to "
<< GetEntryPointName(call.entryPoint);
}
}
void FrameCaptureShared::maybeCapturePostCallUpdates(const gl::Context *context)
{
// Process resource ID updates.
MaybeCaptureUpdateResourceIDs(&mFrameCalls);
const CallCapture &lastCall = mFrameCalls.back();
switch (lastCall.entryPoint)
{
case EntryPoint::GLCreateShaderProgramv:
{
gl::ShaderProgramID programId;
programId.value = lastCall.params.getReturnValue().value.GLuintVal;
const gl::Program *program = context->getProgramResolveLink(programId);
CaptureUpdateUniformLocations(program, &mFrameCalls);
CaptureUpdateUniformBlockIndexes(program, &mFrameCalls);
break;
}
case EntryPoint::GLLinkProgram:
{
const ParamCapture ¶m =
lastCall.params.getParam("programPacked", ParamType::TShaderProgramID, 0);
const gl::Program *program =
context->getProgramResolveLink(param.value.ShaderProgramIDVal);
CaptureUpdateUniformLocations(program, &mFrameCalls);
CaptureUpdateUniformBlockIndexes(program, &mFrameCalls);
break;
}
case EntryPoint::GLUseProgram:
CaptureUpdateCurrentProgram(lastCall, &mFrameCalls);
break;
case EntryPoint::GLDeleteProgram:
{
const ParamCapture ¶m =
lastCall.params.getParam("programPacked", ParamType::TShaderProgramID, 0);
CaptureDeleteUniformLocations(param.value.ShaderProgramIDVal, &mFrameCalls);
break;
}
default:
break;
}
}
void FrameCaptureShared::captureClientArraySnapshot(const gl::Context *context,
size_t vertexCount,
size_t instanceCount)
{
const gl::VertexArray *vao = context->getState().getVertexArray();
// Capture client array data.
for (size_t attribIndex : context->getStateCache().getActiveClientAttribsMask())
{
const gl::VertexAttribute &attrib = vao->getVertexAttribute(attribIndex);
const gl::VertexBinding &binding = vao->getVertexBinding(attrib.bindingIndex);
int callIndex = mClientVertexArrayMap[attribIndex];
if (callIndex != -1)
{
size_t count = vertexCount;
if (binding.getDivisor() > 0)
{
count = rx::UnsignedCeilDivide(static_cast<uint32_t>(instanceCount),
binding.getDivisor());
}
// The last capture element doesn't take up the full stride.
size_t bytesToCapture = (count - 1) * binding.getStride() + attrib.format->pixelBytes;
CallCapture &call = mFrameCalls[callIndex];
ParamCapture ¶m = call.params.getClientArrayPointerParameter();
ASSERT(param.type == ParamType::TvoidConstPointer);
ParamBuffer updateParamBuffer;
updateParamBuffer.addValueParam<GLint>("arrayIndex", ParamType::TGLint,
static_cast<uint32_t>(attribIndex));
ParamCapture updateMemory("pointer", ParamType::TvoidConstPointer);
CaptureMemory(param.value.voidConstPointerVal, bytesToCapture, &updateMemory);
updateParamBuffer.addParam(std::move(updateMemory));
updateParamBuffer.addValueParam<GLuint64>("size", ParamType::TGLuint64, bytesToCapture);
mFrameCalls.emplace_back("UpdateClientArrayPointer", std::move(updateParamBuffer));
mClientArraySizes[attribIndex] =
std::max(mClientArraySizes[attribIndex], bytesToCapture);
}
}
}
void FrameCaptureShared::captureMappedBufferSnapshot(const gl::Context *context,
const CallCapture &call)
{
// If the buffer was mapped writable, we need to restore its data, since we have no visibility
// into what the client did to the buffer while mapped
// This sequence will result in replay calls like this:
// ...
// gMappedBufferData[gBufferMap[42]] = glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, 65536,
// GL_MAP_WRITE_BIT);
// ...
// UpdateClientBufferData(42, &gBinaryData[164631024], 65536);
// glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
// ...
// Re-map the buffer, using the info we tracked about the buffer
gl::BufferBinding target =
call.params.getParam("targetPacked", ParamType::TBufferBinding, 0).value.BufferBindingVal;
FrameCaptureShared *frameCaptureShared = context->getShareGroup()->getFrameCaptureShared();
gl::Buffer *buffer = context->getState().getTargetBuffer(target);
if (!frameCaptureShared->hasBufferData(buffer->id()))
{
// This buffer was not marked writable, so we did not back it up
return;
}
std::pair<GLintptr, GLsizeiptr> bufferDataOffsetAndLength =
frameCaptureShared->getBufferDataOffsetAndLength(buffer->id());
GLintptr offset = bufferDataOffsetAndLength.first;
GLsizeiptr length = bufferDataOffsetAndLength.second;
// Map the buffer so we can copy its contents out
ASSERT(!buffer->isMapped());
angle::Result result = buffer->mapRange(context, offset, length, GL_MAP_READ_BIT);
if (result != angle::Result::Continue)
{
ERR() << "Failed to mapRange of buffer" << std::endl;
}
const uint8_t *data = reinterpret_cast<const uint8_t *>(buffer->getMapPointer());
// Create the parameters to our helper for use during replay
ParamBuffer dataParamBuffer;
// Pass in the target buffer ID
dataParamBuffer.addValueParam("dest", ParamType::TGLuint, buffer->id().value);
// Capture the current buffer data with a binary param
ParamCapture captureData("source", ParamType::TvoidConstPointer);
CaptureMemory(data, length, &captureData);
dataParamBuffer.addParam(std::move(captureData));
// Also track its size for use with memcpy
dataParamBuffer.addValueParam<GLsizeiptr>("size", ParamType::TGLsizeiptr, length);
// Call the helper that populates the buffer with captured data
mFrameCalls.emplace_back("UpdateClientBufferData", std::move(dataParamBuffer));
// Unmap the buffer and move on
GLboolean dontCare;
(void)buffer->unmap(context, &dontCare);
}
void FrameCaptureShared::checkForCaptureTrigger()
{
// If the capture trigger has not been set, move on
if (mCaptureTrigger == 0)
{
return;
}
// Otherwise, poll the value for a change
std::string captureTriggerStr = GetCaptureTrigger();
if (captureTriggerStr.empty())
{
return;
}
// If the value has changed, use the original value as the frame count
// TODO (anglebug.com/4949): Improve capture at unknown frame time. It is good to
// avoid polling if the feature is not enabled, but not entirely intuitive to set
// a value to zero when you want to trigger it.
uint32_t captureTrigger = atoi(captureTriggerStr.c_str());
if (captureTrigger != mCaptureTrigger)
{
// Start mid-execution capture for the next frame
mCaptureStartFrame = mFrameIndex + 1;
// Use the original trigger value as the frame count
mCaptureEndFrame = mCaptureStartFrame + (mCaptureTrigger - 1);
INFO() << "Capture triggered after frame " << mFrameIndex << " for " << mCaptureTrigger
<< " frames";
// Stop polling
mCaptureTrigger = 0;
}
}
void FrameCaptureShared::setupSharedAndAuxReplay(const gl::Context *context,
bool isMidExecutionCapture)
{
// Make sure all pending work for every Context in the share group has completed so all data
// (buffers, textures, etc.) has been updated and no resources are in use.
egl::ShareGroup *shareGroup = context->getShareGroup();
const egl::ContextSet *shareContextSet = shareGroup->getContexts();
for (gl::Context *shareContext : *shareContextSet)
{
shareContext->finish();
}
clearSetupCalls();
if (isMidExecutionCapture)
{
CaptureSharedContextMidExecutionSetup(context, &mSetupCalls, &mResourceTracker);
}
WriteSharedContextCppReplay(mCompression, mOutDirectory, mCaptureLabel, 1, 1, mSetupCalls,
&mResourceTracker, &mBinaryData, mSerializeStateEnabled, *this);
for (const gl::Context *shareContext : *shareContextSet)
{
FrameCapture *frameCapture = shareContext->getFrameCapture();
frameCapture->clearSetupCalls();
if (isMidExecutionCapture)
{
CaptureMidExecutionSetup(shareContext, &frameCapture->getSetupCalls(),
&mResourceTracker);
}
if (!frameCapture->getSetupCalls().empty() && shareContext->id() != context->id())
{
// The presentation context's setup functions will be written later as part of the
// WriteWindowSurfaceContextCppReplay() output.
WriteAuxiliaryContextCppSetupReplay(mCompression, mOutDirectory, shareContext,
mCaptureLabel, 1, frameCapture->getSetupCalls(),
&mBinaryData, mSerializeStateEnabled, *this);
}
}
}
void FrameCaptureShared::onEndFrame(const gl::Context *context)
{
if (!enabled() || mFrameIndex > mCaptureEndFrame)
{
setCaptureInactive();
return;
}
FrameCapture *frameCapture = context->getFrameCapture();
// Count resource IDs. This is also done on every frame. It could probably be done by
// checking the GL state instead of the calls.
for (const CallCapture &call : mFrameCalls)
{
for (const ParamCapture ¶m : call.params.getParamCaptures())
{
ResourceIDType idType = GetResourceIDTypeFromParamType(param.type);
if (idType != ResourceIDType::InvalidEnum)
{
mHasResourceType.set(idType);
}
}
}
// On Android, we can trigger a capture during the run
checkForCaptureTrigger();
// Done after checkForCaptureTrigger(), since that can modify mCaptureStartFrame.
if (mFrameIndex >= mCaptureStartFrame)
{
setCaptureActive();
// Assume that the context performing the swap is the "main" context.
mWindowSurfaceContextID = context->id();
}
else
{
reset();
mFrameIndex++;
// When performing a mid-execution capture, setup the replay before capturing calls for the
// first frame.
if (mFrameIndex == mCaptureStartFrame)
{
setupSharedAndAuxReplay(context, true);
}
// Not capturing yet, so return.
return;
}
if (mIsFirstFrame)
{
mCaptureStartFrame = mFrameIndex;
// When *not* performing a mid-execution capture, setup the replay with the first frame.
if (mCaptureStartFrame == 1)
{
setupSharedAndAuxReplay(context, false);
}
}
if (!mFrameCalls.empty())
{
mActiveFrameIndices.push_back(getReplayFrameIndex());
}
// Note that we currently capture before the start frame to collect shader and program sources.
// For simplicity, it's currently a requirement that the same context is used to perform the
// swap every frame.
ASSERT(mWindowSurfaceContextID == context->id());
// Make sure all pending work for every Context in the share group has completed so all data
// (buffers, textures, etc.) has been updated and no resources are in use.
egl::ShareGroup *shareGroup = context->getShareGroup();
const egl::ContextSet *shareContextSet = shareGroup->getContexts();
for (gl::Context *shareContext : *shareContextSet)
{
shareContext->finish();
}
WriteWindowSurfaceContextCppReplay(mCompression, mOutDirectory, context, mCaptureLabel,
getReplayFrameIndex(), getFrameCount(), mFrameCalls,
frameCapture->getSetupCalls(), &mResourceTracker,
&mBinaryData, mSerializeStateEnabled, *this);
if (mFrameIndex == mCaptureEndFrame)
{
// Save the index files after the last frame.
writeCppReplayIndexFiles(context, false);
SaveBinaryData(mCompression, mOutDirectory, kSharedContextId, mCaptureLabel, mBinaryData);
mBinaryData.clear();
mWroteIndexFile = true;
}
reset();
mFrameIndex++;
mIsFirstFrame = false;
}
void FrameCaptureShared::onDestroyContext(const gl::Context *context)
{
if (!mEnabled)
{
return;
}
if (!mWroteIndexFile && mFrameIndex > mCaptureStartFrame)
{
// If context is destroyed before end frame is reached and at least
// 1 frame has been recorded, then write the index files.
// It doesnt make sense to write the index files when no frame has been recorded
mFrameIndex -= 1;
mCaptureEndFrame = mFrameIndex;
writeCppReplayIndexFiles(context, true);
SaveBinaryData(mCompression, mOutDirectory, kSharedContextId, mCaptureLabel, mBinaryData);
mBinaryData.clear();
mWroteIndexFile = true;
}
}
void FrameCaptureShared::onMakeCurrent(const gl::Context *context, const egl::Surface *drawSurface)
{
if (!drawSurface)
{
return;
}
// Track the width and height of the draw surface as provided to makeCurrent
mDrawSurfaceDimensions[context->id()] =
gl::Extents(drawSurface->getWidth(), drawSurface->getHeight(), 1);
}
DataCounters::DataCounters() = default;
DataCounters::~DataCounters() = default;
int DataCounters::getAndIncrement(EntryPoint entryPoint, const std::string ¶mName)
{
Counter counterKey = {entryPoint, paramName};
return mData[counterKey]++;
}
DataTracker::DataTracker() = default;
DataTracker::~DataTracker() = default;
StringCounters::StringCounters() = default;
StringCounters::~StringCounters() = default;
int StringCounters::getStringCounter(std::vector<std::string> &strings)
{
const auto &id = mStringCounterMap.find(strings);
if (id == mStringCounterMap.end())
{
return kStringsNotFound;
}
else
{
return mStringCounterMap[strings];
}
}
void StringCounters::setStringCounter(std::vector<std::string> &strings, int &counter)
{
ASSERT(counter >= 0);
mStringCounterMap[strings] = counter;
}
TrackedResource::TrackedResource() = default;
TrackedResource::~TrackedResource() = default;
ResourceTracker::ResourceTracker() = default;
ResourceTracker::~ResourceTracker() = default;
void ResourceTracker::setDeletedFenceSync(GLsync sync)
{
ASSERT(sync != nullptr);
if (mStartingFenceSyncs.find(sync) == mStartingFenceSyncs.end())
{
// This is a fence sync created after MEC was initialized. Ignore it.
return;
}
// In this case, the app is deleting a fence sync we started with, we need to regen on loop.
mFenceSyncsToRegen.insert(sync);
}
void TrackedResource::setGennedResource(GLuint id)
{
if (mStartingResources.find(id) == mStartingResources.end())
{
// This is a resource created after MEC was initialized, track it
mNewResources.insert(id);
return;
}
}
void TrackedResource::setDeletedResource(GLuint id)
{
if (id == 0)
{
// Ignore ID 0
return;
}
if (mNewResources.find(id) != mNewResources.end())
{
// This is a resource created after MEC was initialized, just clear it, since there will be
// no actions required for it to return to starting state.
mNewResources.erase(id);
return;
}
if (mStartingResources.find(id) != mStartingResources.end())
{
// In this case, the app is deleting a resource we started with, we need to regen on loop
mResourcesToRegen.insert(id);
// Also restore its contents
mResourcesToRestore.insert(id);
}
// If none of the above is true, the app is deleting a resource that was never genned.
}
void TrackedResource::setModifiedResource(GLuint id)
{
// If this was a starting resource, we need to track it for restore
if (mStartingResources.find(id) != mStartingResources.end())
{
mResourcesToRestore.insert(id);
}
}
void ResourceTracker::setBufferMapped(GLuint id)
{
// If this was a starting buffer, we may need to restore it to original state during Reset
TrackedResource &trackedBuffers = getTrackedResource(ResourceIDType::Buffer);
if (trackedBuffers.getStartingResources().find(id) !=
trackedBuffers.getStartingResources().end())
{
// Track that its current state is mapped (true)
mStartingBuffersMappedCurrent[id] = true;
}
}
void ResourceTracker::setBufferUnmapped(GLuint id)
{
// If this was a starting buffer, we may need to restore it to original state during Reset
TrackedResource &trackedBuffers = getTrackedResource(ResourceIDType::Buffer);
if (trackedBuffers.getStartingResources().find(id) !=
trackedBuffers.getStartingResources().end())
{
// Track that its current state is unmapped (false)
mStartingBuffersMappedCurrent[id] = false;
}
}
bool ResourceTracker::getStartingBuffersMappedCurrent(GLuint id) const
{
const auto &foundBool = mStartingBuffersMappedCurrent.find(id);
ASSERT(foundBool != mStartingBuffersMappedCurrent.end());
return foundBool->second;
}
bool ResourceTracker::getStartingBuffersMappedInitial(GLuint id) const
{
const auto &foundBool = mStartingBuffersMappedInitial.find(id);
ASSERT(foundBool != mStartingBuffersMappedInitial.end());
return foundBool->second;
}
void ResourceTracker::onShaderProgramAccess(gl::ShaderProgramID shaderProgramID)
{
mMaxShaderPrograms = std::max(mMaxShaderPrograms, shaderProgramID.value + 1);
}
bool FrameCaptureShared::isCapturing() const
{
// Currently we will always do a capture up until the last frame. In the future we could improve
// mid execution capture by only capturing between the start and end frames. The only necessary
// reason we need to capture before the start is for attached program and shader sources.
return mEnabled && mFrameIndex <= mCaptureEndFrame;
}
uint32_t FrameCaptureShared::getFrameCount() const
{
return mCaptureEndFrame - mCaptureStartFrame + 1;
}
uint32_t FrameCaptureShared::getReplayFrameIndex() const
{
return mFrameIndex - mCaptureStartFrame + 1;
}
void FrameCaptureShared::replay(gl::Context *context)
{
ReplayContext replayContext(mReadBufferSize, mClientArraySizes);
for (const CallCapture &call : mFrameCalls)
{
INFO() << "frame index: " << mFrameIndex << " " << call.name();
if (call.entryPoint == EntryPoint::GLInvalid)
{
if (call.customFunctionName == "UpdateClientArrayPointer")
{
GLint arrayIndex =
call.params.getParam("arrayIndex", ParamType::TGLint, 0).value.GLintVal;
ASSERT(arrayIndex < gl::MAX_VERTEX_ATTRIBS);
const ParamCapture &pointerParam =
call.params.getParam("pointer", ParamType::TvoidConstPointer, 1);
ASSERT(pointerParam.data.size() == 1);
const void *pointer = pointerParam.data[0].data();
size_t size = static_cast<size_t>(
call.params.getParam("size", ParamType::TGLuint64, 2).value.GLuint64Val);
std::vector<uint8_t> &curClientArrayBuffer =
replayContext.getClientArraysBuffer()[arrayIndex];
ASSERT(curClientArrayBuffer.size() >= size);
memcpy(curClientArrayBuffer.data(), pointer, size);
}
continue;
}
ReplayCall(context, &replayContext, call);
}
}
void FrameCaptureShared::writeCppReplayIndexFiles(const gl::Context *context,
bool writeResetContextCall)
{
const gl::ContextID contextId = context->id();
const egl::Config *config = context->getConfig();
const egl::AttributeMap &attributes = context->getDisplay()->getAttributeMap();
unsigned frameCount = getFrameCount();
std::stringstream header;
std::stringstream source;
header << "#pragma once\n";
header << "\n";
header << "#include <EGL/egl.h>\n";
header << "#include <cstdint>\n";
header << "\n";
if (!mCaptureLabel.empty())
{
header << "namespace " << mCaptureLabel << "\n";
header << "{\n";
}
header << "// Begin Trace Metadata\n";
header << "#define ANGLE_REPLAY_VERSION";
if (!mCaptureLabel.empty())
{
std::string captureLabelUpper = mCaptureLabel;
angle::ToUpper(&captureLabelUpper);
header << "_" << captureLabelUpper;
}
header << " " << ANGLE_REVISION << "\n";
header << "constexpr uint32_t kReplayContextClientMajorVersion = "
<< context->getClientMajorVersion() << ";\n";
header << "constexpr uint32_t kReplayContextClientMinorVersion = "
<< context->getClientMinorVersion() << ";\n";
header << "constexpr EGLint kReplayPlatformType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_TYPE_ANGLE) << ";\n";
header << "constexpr EGLint kReplayDeviceType = "
<< attributes.getAsInt(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE) << ";\n";
header << "constexpr uint32_t kReplayFrameStart = 1;\n";
header << "constexpr uint32_t kReplayFrameEnd = " << frameCount << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceWidth = "
<< mDrawSurfaceDimensions.at(contextId).width << ";\n";
header << "constexpr EGLint kReplayDrawSurfaceHeight = "
<< mDrawSurfaceDimensions.at(contextId).height << ";\n";
header << "constexpr EGLint kDefaultFramebufferRedBits = "
<< (config ? std::to_string(config->redSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferGreenBits = "
<< (config ? std::to_string(config->greenSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferBlueBits = "
<< (config ? std::to_string(config->blueSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferAlphaBits = "
<< (config ? std::to_string(config->alphaSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferDepthBits = "
<< (config ? std::to_string(config->depthSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr EGLint kDefaultFramebufferStencilBits = "
<< (config ? std::to_string(config->stencilSize) : "EGL_DONT_CARE") << ";\n";
header << "constexpr bool kIsBinaryDataCompressed = " << (mCompression ? "true" : "false")
<< ";\n";
header << "constexpr bool kAreClientArraysEnabled = "
<< (context->getState().areClientArraysEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kbindGeneratesResources = "
<< (context->getState().isBindGeneratesResourceEnabled() ? "true" : "false") << ";\n";
header << "constexpr bool kWebGLCompatibility = "
<< (context->getState().getExtensions().webglCompatibility ? "true" : "false") << ";\n";
header << "constexpr bool kRobustResourceInit = "
<< (context->getState().isRobustResourceInitEnabled() ? "true" : "false") << ";\n";
header << "// End Trace Metadata\n";
header << "\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "void " << FmtReplayFunction(contextId, frameIndex) << ";\n";
}
header << "\n";
if (mSerializeStateEnabled)
{
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
header << "const char *" << FmtGetSerializedContextStateFunction(contextId, frameIndex)
<< ";\n";
}
header << "\n";
}
header << "void InitReplay();\n";
source << "#include \"" << FmtCapturePrefix(contextId, mCaptureLabel) << ".h\"\n";
source << "#include \"trace_fixture.h\"\n";
source << "#include \"angle_trace_gl.h\"\n";
source << "\n";
if (!mCaptureLabel.empty())
{
source << "using namespace " << mCaptureLabel << ";\n";
source << "\n";
}
source << "void " << mCaptureLabel << "::InitReplay()\n";
source << "{\n";
WriteInitReplayCall(mCompression, source, kSharedContextId, mCaptureLabel,
MaxClientArraySize(mClientArraySizes), mReadBufferSize);
source << "}\n";
source << "extern \"C\" {\n";
source << "void ReplayFrame(uint32_t frameIndex)\n";
source << "{\n";
source << " switch (frameIndex)\n";
source << " {\n";
for (uint32_t frameIndex : mActiveFrameIndices)
{
source << " case " << frameIndex << ":\n";
source << " " << FmtReplayFunction(contextId, frameIndex) << ";\n";
source << " break;\n";
}
source << " default:\n";
source << " break;\n";
source << " }\n";
source << "}\n";
source << "\n";
if (writeResetContextCall)
{
source << "void ResetReplay()\n";
source << "{\n";
source << " // Reset context is empty because context is destroyed before end "
"frame is reached\n";
source << "}\n";
source << "\n";
}
if (mSerializeStateEnabled)
{
source << "const char *GetSerializedContextState(uint32_t frameIndex)\n";
source << "{\n";
source << " switch (frameIndex)\n";
source << " {\n";
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
source << " case " << frameIndex << ":\n";
source << " return "
<< FmtGetSerializedContextStateFunction(contextId, frameIndex) << ";\n";
}
source << " default:\n";
source << " return nullptr;\n";
source << " }\n";
source << "}\n";
source << "\n";
}
source << "} // extern \"C\"\n";
if (!mCaptureLabel.empty())
{
header << "} // namespace " << mCaptureLabel << "\n";
}
{
std::string headerContents = header.str();
std::stringstream headerPathStream;
headerPathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel) << ".h";
std::string headerPath = headerPathStream.str();
SaveFileHelper saveHeader(headerPath);
saveHeader << headerContents;
}
{
std::string sourceContents = source.str();
std::stringstream sourcePathStream;
sourcePathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel) << ".cpp";
std::string sourcePath = sourcePathStream.str();
SaveFileHelper saveSource(sourcePath);
saveSource << sourceContents;
}
{
std::stringstream indexPathStream;
indexPathStream << mOutDirectory << FmtCapturePrefix(contextId, mCaptureLabel)
<< "_files.txt";
std::string indexPath = indexPathStream.str();
SaveFileHelper saveIndex(indexPath);
for (uint32_t frameIndex = 1; frameIndex <= frameCount; ++frameIndex)
{
saveIndex << GetCaptureFileName(contextId, mCaptureLabel, frameIndex, ".cpp") << "\n";
}
egl::ShareGroup *shareGroup = context->getShareGroup();
egl::ContextSet *shareContextSet = shareGroup->getContexts();
for (gl::Context *shareContext : *shareContextSet)
{
if (shareContext->id() == contextId)
{
// We already listed all of the "main" context's files, so skip it here.
continue;
}
saveIndex << GetCaptureFileName(shareContext->id(), mCaptureLabel, 1, ".cpp") << "\n";
}
saveIndex << GetCaptureFileName(kSharedContextId, mCaptureLabel, 1, ".cpp") << "\n";
}
}
void FrameCaptureShared::reset()
{
mFrameCalls.clear();
mClientVertexArrayMap.fill(-1);
// Do not reset replay-specific settings like the maximum read buffer size, client array sizes,
// or the 'has seen' type map. We could refine this into per-frame and per-capture maximums if
// necessary.
}
const std::string &FrameCaptureShared::getShaderSource(gl::ShaderProgramID id) const
{
const auto &foundSources = mCachedShaderSource.find(id);
ASSERT(foundSources != mCachedShaderSource.end());
return foundSources->second;
}
void FrameCaptureShared::setShaderSource(gl::ShaderProgramID id, std::string source)
{
mCachedShaderSource[id] = source;
}
const ProgramSources &FrameCaptureShared::getProgramSources(gl::ShaderProgramID id) const
{
const auto &foundSources = mCachedProgramSources.find(id);
ASSERT(foundSources != mCachedProgramSources.end());
return foundSources->second;
}
void FrameCaptureShared::setProgramSources(gl::ShaderProgramID id, ProgramSources sources)
{
mCachedProgramSources[id] = sources;
}
const std::vector<uint8_t> &FrameCaptureShared::retrieveCachedTextureLevel(gl::TextureID id,
gl::TextureTarget target,
GLint level)
{
// Look up the data for the requested texture
const auto &foundTextureLevels = mCachedTextureLevelData.find(id);
ASSERT(foundTextureLevels != mCachedTextureLevelData.end());
GLint adjustedLevel = GetAdjustedTextureCacheLevel(target, level);
const auto &foundTextureLevel = foundTextureLevels->second.find(adjustedLevel);
ASSERT(foundTextureLevel != foundTextureLevels->second.end());
const std::vector<uint8_t> &capturedTextureLevel = foundTextureLevel->second;
return capturedTextureLevel;
}
void FrameCaptureShared::copyCachedTextureLevel(const gl::Context *context,
gl::TextureID srcID,
GLint srcLevel,
gl::TextureID dstID,
GLint dstLevel,
const CallCapture &call)
{
// TODO(http://anglebug.com/5604): Add support for partial level copies.
ASSERT(call.params.getParam("srcX", ParamType::TGLint, 3).value.GLintVal == 0);
ASSERT(call.params.getParam("srcY", ParamType::TGLint, 4).value.GLintVal == 0);
ASSERT(call.params.getParam("srcZ", ParamType::TGLint, 5).value.GLintVal == 0);
ASSERT(call.params.getParam("dstX", ParamType::TGLint, 9).value.GLintVal == 0);
ASSERT(call.params.getParam("dstY", ParamType::TGLint, 10).value.GLintVal == 0);
ASSERT(call.params.getParam("dstZ", ParamType::TGLint, 11).value.GLintVal == 0);
GLenum srcTarget = call.params.getParam("srcTarget", ParamType::TGLenum, 1).value.GLenumVal;
GLsizei srcWidth = call.params.getParam("srcWidth", ParamType::TGLsizei, 12).value.GLsizeiVal;
GLsizei srcHeight = call.params.getParam("srcHeight", ParamType::TGLsizei, 13).value.GLsizeiVal;
GLsizei srcDepth = call.params.getParam("srcDepth", ParamType::TGLsizei, 14).value.GLsizeiVal;
gl::Texture *srcTexture = context->getTexture({srcID});
gl::TextureTarget srcTargetPacked = gl::PackParam<gl::TextureTarget>(srcTarget);
const gl::Extents &srcExtents = srcTexture->getExtents(srcTargetPacked, srcLevel);
ASSERT(srcExtents.width == srcWidth && srcExtents.height == srcHeight &&
srcExtents.depth == srcDepth);
// Look up the data for the source texture
const auto &foundSrcTextureLevels = mCachedTextureLevelData.find(srcID);
ASSERT(foundSrcTextureLevels != mCachedTextureLevelData.end());
// For that texture, look up the data for the given level
const auto &foundSrcTextureLevel = foundSrcTextureLevels->second.find(srcLevel);
ASSERT(foundSrcTextureLevel != foundSrcTextureLevels->second.end());
const std::vector<uint8_t> &srcTextureLevel = foundSrcTextureLevel->second;
auto foundDstTextureLevels = mCachedTextureLevelData.find(dstID);
if (foundDstTextureLevels == mCachedTextureLevelData.end())
{
// Initialize the texture ID data.
auto emplaceResult = mCachedTextureLevelData.emplace(dstID, TextureLevels());
ASSERT(emplaceResult.second);
foundDstTextureLevels = emplaceResult.first;
}
TextureLevels &foundDstLevels = foundDstTextureLevels->second;
TextureLevels::iterator foundDstLevel = foundDstLevels.find(dstLevel);
if (foundDstLevel != foundDstLevels.end())
{
// If we have a cache for this level, remove it since we're recreating it.
foundDstLevels.erase(dstLevel);
}
// Initialize destination texture data and copy the source into it.
std::vector<uint8_t> dstTextureLevel = srcTextureLevel;
auto emplaceResult = foundDstLevels.emplace(dstLevel, std::move(dstTextureLevel));
ASSERT(emplaceResult.second);
}
std::vector<uint8_t> &FrameCaptureShared::getCachedTextureLevelData(gl::Texture *texture,
gl::TextureTarget target,
GLint textureLevel,
EntryPoint entryPoint)
{
auto foundTextureLevels = mCachedTextureLevelData.find(texture->id());
if (foundTextureLevels == mCachedTextureLevelData.end())
{
// Initialize the texture ID data.
auto emplaceResult = mCachedTextureLevelData.emplace(texture->id(), TextureLevels());
ASSERT(emplaceResult.second);
foundTextureLevels = emplaceResult.first;
}
// For this texture, look up the adjusted level, which may not match 1:1 due to cubes
GLint adjustedLevel = GetAdjustedTextureCacheLevel(target, textureLevel);
TextureLevels &foundLevels = foundTextureLevels->second;
TextureLevels::iterator foundLevel = foundLevels.find(adjustedLevel);
if (foundLevel != foundLevels.end())
{
if (entryPoint == EntryPoint::GLCompressedTexImage2D ||
entryPoint == EntryPoint::GLCompressedTexImage3D)
{
// Delete the cached entry in case the caller is respecifying the level.
foundLevels.erase(adjustedLevel);
}
else
{
ASSERT(entryPoint == EntryPoint::GLCompressedTexSubImage2D ||
entryPoint == EntryPoint::GLCompressedTexSubImage3D);
// If we have a cache for this level, return it now
return foundLevel->second;
}
}
// Otherwise, create an appropriately sized cache for this level
// Get the format of the texture for use with the compressed block size math.
const gl::InternalFormat &format = *texture->getFormat(target, textureLevel).info;
// Divide dimensions according to block size.
const gl::Extents &levelExtents = texture->getExtents(target, textureLevel);
// Calculate the size needed to store the compressed level
GLuint sizeInBytes;
bool result = format.computeCompressedImageSize(levelExtents, &sizeInBytes);
ASSERT(result);
// Initialize texture rectangle data. Default init to zero for stability.
std::vector<uint8_t> newPixelData(sizeInBytes, 0);
auto emplaceResult = foundLevels.emplace(adjustedLevel, std::move(newPixelData));
ASSERT(emplaceResult.second);
// Using the level entry we just created, return the location (a byte vector) where compressed
// texture level data should be stored
return emplaceResult.first->second;
}
void FrameCaptureShared::deleteCachedTextureLevelData(gl::TextureID id)
{
const auto &foundTextureLevels = mCachedTextureLevelData.find(id);
if (foundTextureLevels != mCachedTextureLevelData.end())
{
// Delete all texture levels at once
mCachedTextureLevelData.erase(foundTextureLevels);
}
}
void CaptureMemory(const void *source, size_t size, ParamCapture *paramCapture)
{
std::vector<uint8_t> data(size);
memcpy(data.data(), source, size);
paramCapture->data.emplace_back(std::move(data));
}
void CaptureString(const GLchar *str, ParamCapture *paramCapture)
{
// include the '\0' suffix
CaptureMemory(str, strlen(str) + 1, paramCapture);
}
void CaptureStringLimit(const GLchar *str, uint32_t limit, ParamCapture *paramCapture)
{
// Write the incoming string up to limit, including null terminator
size_t length = strlen(str) + 1;
if (length > limit)
{
// If too many characters, resize the string to fit in the limit
std::string newStr = str;
newStr.resize(limit - 1);
CaptureString(newStr.c_str(), paramCapture);
}
else
{
CaptureMemory(str, length, paramCapture);
}
}
void CaptureVertexPointerGLES1(const gl::State &glState,
gl::ClientVertexArrayType type,
const void *pointer,
ParamCapture *paramCapture)
{
paramCapture->value.voidConstPointerVal = pointer;
if (!glState.getTargetBuffer(gl::BufferBinding::Array))
{
paramCapture->arrayClientPointerIndex =
gl::GLES1Renderer::VertexArrayIndex(type, glState.gles1());
}
}
gl::Program *GetProgramForCapture(const gl::State &glState, gl::ShaderProgramID handle)
{
gl::Program *program = glState.getShaderProgramManagerForCapture().getProgram(handle);
return program;
}
void CaptureGetActiveUniformBlockivParameters(const gl::State &glState,
gl::ShaderProgramID handle,
gl::UniformBlockIndex uniformBlockIndex,
GLenum pname,
ParamCapture *paramCapture)
{
int numParams = 1;
// From the OpenGL ES 3.0 spec:
// If pname is UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, then a list of the
// active uniform indices for the uniform block identified by uniformBlockIndex is
// returned. The number of elements that will be written to params is the value of
// UNIFORM_BLOCK_ACTIVE_UNIFORMS for uniformBlockIndex
if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES)
{
gl::Program *program = GetProgramForCapture(glState, handle);
if (program)
{
gl::QueryActiveUniformBlockiv(program, uniformBlockIndex,
GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &numParams);
}
}
paramCapture->readBufferSizeBytes = sizeof(GLint) * numParams;
}
void CaptureGetParameter(const gl::State &glState,
GLenum pname,
size_t typeSize,
ParamCapture *paramCapture)
{
// kMaxReportedCapabilities is the biggest array we'll need to hold data from glGet calls.
// This value needs to be updated if any new extensions are introduced that would allow for
// more compressed texture formats. The current value is taken from:
// http://opengles.gpuinfo.org/displaycapability.php?name=GL_NUM_COMPRESSED_TEXTURE_FORMATS&esversion=2
constexpr unsigned int kMaxReportedCapabilities = 69;
paramCapture->readBufferSizeBytes = typeSize * kMaxReportedCapabilities;
}
void CaptureGenHandlesImpl(GLsizei n, GLuint *handles, ParamCapture *paramCapture)
{
paramCapture->readBufferSizeBytes = sizeof(GLuint) * n;
CaptureMemory(handles, paramCapture->readBufferSizeBytes, paramCapture);
}
void CaptureShaderStrings(GLsizei count,
const GLchar *const *strings,
const GLint *length,
ParamCapture *paramCapture)
{
for (GLsizei index = 0; index < count; ++index)
{
size_t len = ((length && length[index] >= 0) ? length[index] : strlen(strings[index]));
// includes the '\0' suffix
std::vector<uint8_t> data(len + 1, 0);
memcpy(data.data(), strings[index], len);
paramCapture->data.emplace_back(std::move(data));
}
}
template <>
void WriteParamValueReplay<ParamType::TGLboolean>(std::ostream &os,
const CallCapture &call,
GLboolean value)
{
switch (value)
{
case GL_TRUE:
os << "GL_TRUE";
break;
case GL_FALSE:
os << "GL_FALSE";
break;
default:
os << "0x" << std::hex << std::uppercase << GLint(value);
}
}
template <>
void WriteParamValueReplay<ParamType::TvoidConstPointer>(std::ostream &os,
const CallCapture &call,
const void *value)
{
if (value == 0)
{
os << "nullptr";
}
else
{
os << "reinterpret_cast<const void *>("
<< static_cast<int>(reinterpret_cast<uintptr_t>(value)) << ")";
}
}
template <>
void WriteParamValueReplay<ParamType::TGLfloatConstPointer>(std::ostream &os,
const CallCapture &call,
const GLfloat *value)
{
if (value == 0)
{
os << "nullptr";
}
else
{
os << "reinterpret_cast<const GLfloat *>("
<< static_cast<int>(reinterpret_cast<uintptr_t>(value)) << ")";
}
}
template <>
void WriteParamValueReplay<ParamType::TGLuintConstPointer>(std::ostream &os,
const CallCapture &call,
const GLuint *value)
{
if (value == 0)
{
os << "nullptr";
}
else
{
os << "reinterpret_cast<const GLuint *>("
<< static_cast<int>(reinterpret_cast<uintptr_t>(value)) << ")";
}
}
template <>
void WriteParamValueReplay<ParamType::TGLDEBUGPROCKHR>(std::ostream &os,
const CallCapture &call,
GLDEBUGPROCKHR value)
{}
template <>
void WriteParamValueReplay<ParamType::TGLDEBUGPROC>(std::ostream &os,
const CallCapture &call,
GLDEBUGPROC value)
{}
template <>
void WriteParamValueReplay<ParamType::TBufferID>(std::ostream &os,
const CallCapture &call,
gl::BufferID value)
{
os << "gBufferMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TFenceNVID>(std::ostream &os,
const CallCapture &call,
gl::FenceNVID value)
{
os << "gFenceNVMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TFramebufferID>(std::ostream &os,
const CallCapture &call,
gl::FramebufferID value)
{
os << "gFramebufferMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TMemoryObjectID>(std::ostream &os,
const CallCapture &call,
gl::MemoryObjectID value)
{
os << "gMemoryObjectMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TProgramPipelineID>(std::ostream &os,
const CallCapture &call,
gl::ProgramPipelineID value)
{
os << "gProgramPipelineMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TQueryID>(std::ostream &os,
const CallCapture &call,
gl::QueryID value)
{
os << "gQueryMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TRenderbufferID>(std::ostream &os,
const CallCapture &call,
gl::RenderbufferID value)
{
os << "gRenderbufferMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TSamplerID>(std::ostream &os,
const CallCapture &call,
gl::SamplerID value)
{
os << "gSamplerMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TSemaphoreID>(std::ostream &os,
const CallCapture &call,
gl::SemaphoreID value)
{
os << "gSemaphoreMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TShaderProgramID>(std::ostream &os,
const CallCapture &call,
gl::ShaderProgramID value)
{
os << "gShaderProgramMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TGLsync>(std::ostream &os,
const CallCapture &call,
GLsync value)
{
os << "gSyncMap[" << SyncIndexValue(value) << "]";
}
template <>
void WriteParamValueReplay<ParamType::TTextureID>(std::ostream &os,
const CallCapture &call,
gl::TextureID value)
{
os << "gTextureMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TTransformFeedbackID>(std::ostream &os,
const CallCapture &call,
gl::TransformFeedbackID value)
{
os << "gTransformFeedbackMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TVertexArrayID>(std::ostream &os,
const CallCapture &call,
gl::VertexArrayID value)
{
os << "gVertexArrayMap[" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TUniformLocation>(std::ostream &os,
const CallCapture &call,
gl::UniformLocation value)
{
if (value.value == -1)
{
os << "-1";
return;
}
os << "gUniformLocations[";
// Find the program from the call parameters.
gl::ShaderProgramID programID;
if (FindShaderProgramIDInCall(call, &programID))
{
os << "gShaderProgramMap[" << programID.value << "]";
}
else
{
os << "gCurrentProgram";
}
os << "][" << value.value << "]";
}
template <>
void WriteParamValueReplay<ParamType::TUniformBlockIndex>(std::ostream &os,
const CallCapture &call,
gl::UniformBlockIndex value)
{
// Find the program from the call parameters.
gl::ShaderProgramID programID;
bool foundProgram = FindShaderProgramIDInCall(call, &programID);
ASSERT(foundProgram);
os << "gUniformBlockIndexes[gShaderProgramMap[" << programID.value << "]][" << value.value
<< "]";
}
template <>
void WriteParamValueReplay<ParamType::TGLeglImageOES>(std::ostream &os,
const CallCapture &call,
GLeglImageOES value)
{
uint64_t pointerValue = reinterpret_cast<uint64_t>(value);
os << "reinterpret_cast<EGLImageKHR>(" << pointerValue << "ul)";
}
template <>
void WriteParamValueReplay<ParamType::TGLubyte>(std::ostream &os,
const CallCapture &call,
GLubyte value)
{
const int v = value;
os << v;
}
} // namespace angle