Hash :
454efd1d
Author :
Date :
2022-04-26T23:57:46
Add forceDepthAttachmentInitOnClear frontend workaround AMD on D3D11 skips depth buffer updates in some cases. Bug: angleproject:7246 Bug: angleproject:7200 Change-Id: I27bbea30fbf4173470063a670b9c43a805286c39 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3608092 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.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
//
// Copyright 2012 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.
//
// renderer11_utils.cpp: Conversion functions and other utility routines
// specific to the D3D11 renderer.
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include <versionhelpers.h>
#include <algorithm>
#include "common/debug.h"
#include "libANGLE/Buffer.h"
#include "libANGLE/Context.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/Program.h"
#include "libANGLE/State.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/driver_utils.h"
#include "libANGLE/renderer/dxgi_support_table.h"
#include "platform/FeaturesD3D_autogen.h"
#include "platform/PlatformMethods.h"
namespace rx
{
namespace d3d11_gl
{
namespace
{
// TODO(xinghua.cao@intel.com): Get a more accurate limit.
static D3D_FEATURE_LEVEL kMinimumFeatureLevelForES31 = D3D_FEATURE_LEVEL_11_0;
// Helper functor for querying DXGI support. Saves passing the parameters repeatedly.
class DXGISupportHelper : angle::NonCopyable
{
public:
DXGISupportHelper(ID3D11Device *device, D3D_FEATURE_LEVEL featureLevel)
: mDevice(device), mFeatureLevel(featureLevel)
{}
bool query(DXGI_FORMAT dxgiFormat, UINT supportMask)
{
if (dxgiFormat == DXGI_FORMAT_UNKNOWN)
return false;
auto dxgiSupport = d3d11::GetDXGISupport(dxgiFormat, mFeatureLevel);
UINT supportedBits = dxgiSupport.alwaysSupportedFlags;
if ((dxgiSupport.optionallySupportedFlags & supportMask) != 0)
{
UINT formatSupport;
if (SUCCEEDED(mDevice->CheckFormatSupport(dxgiFormat, &formatSupport)))
{
supportedBits |= (formatSupport & supportMask);
}
else
{
// TODO(jmadill): find out why we fail this call sometimes in FL9_3
// ERR() << "Error checking format support for format 0x" << std::hex << dxgiFormat;
}
}
return ((supportedBits & supportMask) == supportMask);
}
private:
ID3D11Device *mDevice;
D3D_FEATURE_LEVEL mFeatureLevel;
};
gl::TextureCaps GenerateTextureFormatCaps(gl::Version maxClientVersion,
GLenum internalFormat,
ID3D11Device *device,
const Renderer11DeviceCaps &renderer11DeviceCaps)
{
gl::TextureCaps textureCaps;
DXGISupportHelper support(device, renderer11DeviceCaps.featureLevel);
const d3d11::Format &formatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps);
const gl::InternalFormat &internalFormatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
UINT texSupportMask = D3D11_FORMAT_SUPPORT_TEXTURE2D;
if (internalFormatInfo.depthBits == 0 && internalFormatInfo.stencilBits == 0)
{
texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURECUBE;
if (maxClientVersion.major > 2)
{
texSupportMask |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
}
}
textureCaps.texturable = support.query(formatInfo.texFormat, texSupportMask);
textureCaps.filterable =
support.query(formatInfo.srvFormat, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE);
textureCaps.textureAttachment =
(support.query(formatInfo.rtvFormat, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) ||
(support.query(formatInfo.dsvFormat, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL));
textureCaps.renderbuffer = textureCaps.textureAttachment;
textureCaps.blendable = textureCaps.renderbuffer;
DXGI_FORMAT renderFormat = DXGI_FORMAT_UNKNOWN;
if (formatInfo.dsvFormat != DXGI_FORMAT_UNKNOWN)
{
renderFormat = formatInfo.dsvFormat;
}
else if (formatInfo.rtvFormat != DXGI_FORMAT_UNKNOWN)
{
renderFormat = formatInfo.rtvFormat;
}
if (renderFormat != DXGI_FORMAT_UNKNOWN &&
support.query(renderFormat, D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET))
{
// Assume 1x
textureCaps.sampleCounts.insert(1);
for (unsigned int sampleCount = 2; sampleCount <= D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT;
sampleCount *= 2)
{
UINT qualityCount = 0;
if (SUCCEEDED(device->CheckMultisampleQualityLevels(renderFormat, sampleCount,
&qualityCount)))
{
// Assume we always support lower sample counts
if (qualityCount == 0)
{
break;
}
textureCaps.sampleCounts.insert(sampleCount);
}
}
}
return textureCaps;
}
bool GetNPOTTextureSupport(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
float GetMaximumAnisotropy(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_MAX_MAXANISOTROPY;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_MAX_MAXANISOTROPY;
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
return 16;
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_DEFAULT_MAX_ANISOTROPY;
default:
UNREACHABLE();
return 0;
}
}
bool GetOcclusionQuerySupport(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx
// ID3D11Device::CreateQuery
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
return true;
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
bool GetEventQuerySupport(D3D_FEATURE_LEVEL featureLevel)
{
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx
// ID3D11Device::CreateQuery
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return true;
default:
UNREACHABLE();
return false;
}
}
bool GetInstancingSupport(D3D_FEATURE_LEVEL featureLevel)
{
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx
// ID3D11Device::CreateInputLayout
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
// Feature Level 9_3 supports instancing, but slot 0 in the input layout must not be
// instanced.
// D3D9 has a similar restriction, where stream 0 must not be instanced.
// This restriction can be worked around by remapping any non-instanced slot to slot
// 0.
// This works because HLSL uses shader semantics to match the vertex inputs to the
// elements in the input layout, rather than the slots.
// Note that we only support instancing via ANGLE_instanced_array on 9_3, since 9_3
// doesn't support OpenGL ES 3.0
case D3D_FEATURE_LEVEL_9_3:
return true;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
bool GetFramebufferMultisampleSupport(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
bool GetFramebufferBlitSupport(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
bool GetDerivativeInstructionSupport(D3D_FEATURE_LEVEL featureLevel)
{
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb509588.aspx states that
// shader model
// ps_2_x is required for the ddx (and other derivative functions).
// http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx states that
// feature level
// 9.3 supports shader model ps_2_x.
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_9_3:
return true;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
bool GetShaderTextureLODSupport(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return true;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return false;
default:
UNREACHABLE();
return false;
}
}
int GetMaximumSimultaneousRenderTargets(D3D_FEATURE_LEVEL featureLevel)
{
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476150.aspx
// ID3D11Device::CreateInputLayout
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT;
case D3D_FEATURE_LEVEL_9_3:
return D3D_FL9_3_SIMULTANEOUS_RENDER_TARGET_COUNT;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_SIMULTANEOUS_RENDER_TARGET_COUNT;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximum2DTextureSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
case D3D_FEATURE_LEVEL_9_3:
return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumCubeMapTextureSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_TEXTURECUBE_DIMENSION;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_TEXTURECUBE_DIMENSION;
case D3D_FEATURE_LEVEL_9_3:
return D3D_FL9_3_REQ_TEXTURECUBE_DIMENSION;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_REQ_TEXTURECUBE_DIMENSION;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximum2DTextureArraySize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximum3DTextureSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_REQ_TEXTURE3D_U_V_OR_W_DIMENSION;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumViewportSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_VIEWPORT_BOUNDS_MAX;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_VIEWPORT_BOUNDS_MAX;
// No constants for D3D11 Feature Level 9 viewport size limits, use the maximum
// texture sizes
case D3D_FEATURE_LEVEL_9_3:
return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumDrawIndexedIndexCount(D3D_FEATURE_LEVEL featureLevel)
{
// D3D11 allows up to 2^32 elements, but we report max signed int for convenience since
// that's what's
// returned from glGetInteger
static_assert(D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32,
"Unexpected D3D11 constant value.");
static_assert(D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP == 32,
"Unexpected D3D11 constant value.");
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return std::numeric_limits<GLint>::max();
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
return D3D_FL9_2_IA_PRIMITIVE_MAX_COUNT;
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_IA_PRIMITIVE_MAX_COUNT;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumDrawVertexCount(D3D_FEATURE_LEVEL featureLevel)
{
// D3D11 allows up to 2^32 elements, but we report max signed int for convenience since
// that's what's
// returned from glGetInteger
static_assert(D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
static_assert(D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP == 32, "Unexpected D3D11 constant value.");
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return std::numeric_limits<GLint>::max();
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
return D3D_FL9_2_IA_PRIMITIVE_MAX_COUNT;
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_IA_PRIMITIVE_MAX_COUNT;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumVertexInputSlots(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_STANDARD_VERTEX_ELEMENT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
return D3D10_1_STANDARD_VERTEX_ELEMENT_COUNT;
case D3D_FEATURE_LEVEL_10_0:
return D3D10_STANDARD_VERTEX_ELEMENT_COUNT;
// From http://http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876.aspx
// "Max Input Slots"
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 16;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumVertexUniformVectors(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT;
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx
// ID3D11DeviceContext::VSSetConstantBuffers
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 255 - d3d11_gl::GetReservedVertexUniformVectors(featureLevel);
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumVertexUniformBlocks(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT -
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT -
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT;
// Uniform blocks not supported on D3D11 Feature Level 9
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetReservedVertexOutputVectors(D3D_FEATURE_LEVEL featureLevel)
{
// According to The OpenGL ES Shading Language specifications
// (Language Version 1.00 section 10.16, Language Version 3.10 section 12.21)
// built-in special variables (e.g. gl_FragCoord, or gl_PointCoord)
// which are statically used in the shader should be included in the variable packing
// algorithm.
// Therefore, we should not reserve output vectors for them.
switch (featureLevel)
{
// We must reserve one output vector for dx_Position.
// We also reserve one for gl_Position, which we unconditionally output on Feature
// Levels 10_0+,
// even if it's unused in the shader (e.g. for transform feedback). TODO: This could
// be improved.
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 2;
// Just reserve dx_Position on Feature Level 9, since we don't ever need to output
// gl_Position.
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 1;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumVertexOutputVectors(D3D_FEATURE_LEVEL featureLevel)
{
static_assert(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT,
"Unexpected D3D11 constant value.");
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel);
case D3D_FEATURE_LEVEL_10_1:
return D3D10_1_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel);
case D3D_FEATURE_LEVEL_10_0:
return D3D10_VS_OUTPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel);
// Use Shader Model 2.X limits
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 8 - GetReservedVertexOutputVectors(featureLevel);
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumVertexTextureUnits(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT;
// Vertex textures not supported on D3D11 Feature Level 9 according to
// http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx
// ID3D11DeviceContext::VSSetSamplers and ID3D11DeviceContext::VSSetShaderResources
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumPixelUniformVectors(D3D_FEATURE_LEVEL featureLevel)
{
// TODO(geofflang): Remove hard-coded limit once the gl-uniform-arrays test can pass
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return 1024; // D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 1024; // D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT;
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx
// ID3D11DeviceContext::PSSetConstantBuffers
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 32 - d3d11_gl::GetReservedFragmentUniformVectors(featureLevel);
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumPixelUniformBlocks(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT -
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT -
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT;
// Uniform blocks not supported on D3D11 Feature Level 9
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumPixelInputVectors(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_PS_INPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel);
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_PS_INPUT_REGISTER_COUNT - GetReservedVertexOutputVectors(featureLevel);
// Use Shader Model 2.X limits
case D3D_FEATURE_LEVEL_9_3:
return 8 - GetReservedVertexOutputVectors(featureLevel);
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 8 - GetReservedVertexOutputVectors(featureLevel);
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumPixelTextureUnits(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT;
// http://msdn.microsoft.com/en-us/library/windows/desktop/ff476149.aspx
// ID3D11DeviceContext::PSSetShaderResources
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 16;
default:
UNREACHABLE();
return 0;
}
}
std::array<GLint, 3> GetMaxComputeWorkGroupCount(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return {{D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION,
D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION,
D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION}};
default:
return {{0, 0, 0}};
}
}
std::array<GLint, 3> GetMaxComputeWorkGroupSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return {{D3D11_CS_THREAD_GROUP_MAX_X, D3D11_CS_THREAD_GROUP_MAX_Y,
D3D11_CS_THREAD_GROUP_MAX_Z}};
default:
return {{0, 0, 0}};
}
}
int GetMaxComputeWorkGroupInvocations(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP;
default:
return 0;
}
}
int GetMaxComputeSharedMemorySize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
// In D3D11 the maximum total size of all variables with the groupshared storage class is
// 32kb.
// https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-variable-syntax
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return 32768;
default:
return 0;
}
}
int GetMaximumComputeUniformVectors(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT;
default:
return 0;
}
}
int GetMaximumComputeUniformBlocks(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT -
d3d11::RESERVED_CONSTANT_BUFFER_SLOT_COUNT;
default:
return 0;
}
}
int GetMaximumComputeTextureUnits(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT;
default:
return 0;
}
}
void SetUAVRelatedResourceLimits(D3D_FEATURE_LEVEL featureLevel, gl::Caps *caps)
{
ASSERT(caps);
GLuint reservedUAVsForAtomicCounterBuffers = 0u;
// For pixel shaders, the render targets and unordered access views share the same resource
// slots when being written out.
// https://msdn.microsoft.com/en-us/library/windows/desktop/ff476465(v=vs.85).aspx
GLuint maxNumRTVsAndUAVs = 0u;
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
// Currently we allocate 4 UAV slots for atomic counter buffers on feature level 11_1.
reservedUAVsForAtomicCounterBuffers = 4u;
maxNumRTVsAndUAVs = D3D11_1_UAV_SLOT_COUNT;
break;
case D3D_FEATURE_LEVEL_11_0:
// Currently we allocate 1 UAV slot for atomic counter buffers on feature level 11_0.
reservedUAVsForAtomicCounterBuffers = 1u;
maxNumRTVsAndUAVs = D3D11_PS_CS_UAV_REGISTER_COUNT;
break;
default:
return;
}
// Set limits on atomic counter buffers in fragment shaders and compute shaders.
caps->maxCombinedAtomicCounterBuffers = reservedUAVsForAtomicCounterBuffers;
caps->maxShaderAtomicCounterBuffers[gl::ShaderType::Compute] =
reservedUAVsForAtomicCounterBuffers;
caps->maxShaderAtomicCounterBuffers[gl::ShaderType::Fragment] =
reservedUAVsForAtomicCounterBuffers;
caps->maxAtomicCounterBufferBindings = reservedUAVsForAtomicCounterBuffers;
// Setting MAX_COMPUTE_ATOMIC_COUNTERS to a conservative number of 1024 * the number of UAV
// reserved for atomic counters. It could theoretically be set to max buffer size / 4 but that
// number could cause problems.
caps->maxCombinedAtomicCounters = reservedUAVsForAtomicCounterBuffers * 1024;
caps->maxShaderAtomicCounters[gl::ShaderType::Compute] = caps->maxCombinedAtomicCounters;
// See
// https://docs.microsoft.com/en-us/windows/desktop/direct3d11/overviews-direct3d-11-resources-limits
// Resource size (in MB) for any of the preceding resources is min(max(128,0.25f * (amount of
// dedicated VRAM)), 2048) MB. So we set it to 128MB to keep same with GL backend.
caps->maxShaderStorageBlockSize =
D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM * 1024 * 1024;
// Allocate the remaining slots for images and shader storage blocks.
// The maximum number of fragment shader outputs depends on the current context version, so we
// will not set it here. See comments in Context11::initialize().
caps->maxCombinedShaderOutputResources =
maxNumRTVsAndUAVs - reservedUAVsForAtomicCounterBuffers;
// Set limits on images and shader storage blocks in fragment shaders and compute shaders.
caps->maxCombinedShaderStorageBlocks = caps->maxCombinedShaderOutputResources;
caps->maxShaderStorageBlocks[gl::ShaderType::Compute] = caps->maxCombinedShaderOutputResources;
caps->maxShaderStorageBlocks[gl::ShaderType::Fragment] = caps->maxCombinedShaderOutputResources;
caps->maxShaderStorageBufferBindings = caps->maxCombinedShaderOutputResources;
caps->maxImageUnits = caps->maxCombinedShaderOutputResources;
caps->maxCombinedImageUniforms = caps->maxCombinedShaderOutputResources;
caps->maxShaderImageUniforms[gl::ShaderType::Compute] = caps->maxCombinedShaderOutputResources;
caps->maxShaderImageUniforms[gl::ShaderType::Fragment] = caps->maxCombinedShaderOutputResources;
// On feature level 11_1, UAVs are also available in vertex shaders and geometry shaders.
if (featureLevel == D3D_FEATURE_LEVEL_11_1)
{
caps->maxShaderAtomicCounterBuffers[gl::ShaderType::Vertex] =
caps->maxCombinedAtomicCounterBuffers;
caps->maxShaderAtomicCounterBuffers[gl::ShaderType::Geometry] =
caps->maxCombinedAtomicCounterBuffers;
caps->maxShaderImageUniforms[gl::ShaderType::Vertex] =
caps->maxCombinedShaderOutputResources;
caps->maxShaderStorageBlocks[gl::ShaderType::Vertex] =
caps->maxCombinedShaderOutputResources;
caps->maxShaderImageUniforms[gl::ShaderType::Geometry] =
caps->maxCombinedShaderOutputResources;
caps->maxShaderStorageBlocks[gl::ShaderType::Geometry] =
caps->maxCombinedShaderOutputResources;
}
}
int GetMinimumTexelOffset(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE;
// Sampling functions with offsets are not available below shader model 4.0.
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumTexelOffset(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE;
// Sampling functions with offsets are not available below shader model 4.0.
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMinimumTextureGatherOffset(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
// https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/gather4-po--sm5---asm-
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return -32;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumTextureGatherOffset(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
// https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/gather4-po--sm5---asm-
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return 31;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
size_t GetMaximumConstantBufferSize(D3D_FEATURE_LEVEL featureLevel)
{
// Returns a size_t despite the limit being a GLuint64 because size_t is the maximum
// size of
// any buffer that could be allocated.
const size_t bytesPerComponent = 4 * sizeof(float);
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * bytesPerComponent;
// Limits from http://msdn.microsoft.com/en-us/library/windows/desktop/ff476501.aspx
// remarks section
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 4096 * bytesPerComponent;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumStreamOutputBuffers(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_SO_BUFFER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_1:
return D3D10_1_SO_BUFFER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_10_0:
return D3D10_SO_BUFFER_SLOT_COUNT;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumStreamOutputInterleavedComponents(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return GetMaximumVertexOutputVectors(featureLevel) * 4;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumStreamOutputSeparateComponents(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return GetMaximumStreamOutputInterleavedComponents(featureLevel) /
GetMaximumStreamOutputBuffers(featureLevel);
// D3D 10 and 10.1 only allow one output per output slot if an output slot other
// than zero is used.
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 4;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
int GetMaximumRenderToBufferWindowSize(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return D3D10_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH;
// REQ_RENDER_TO_BUFFER_WINDOW_WIDTH not supported on D3D11 Feature Level 9,
// use the maximum texture sizes
case D3D_FEATURE_LEVEL_9_3:
return D3D_FL9_3_REQ_TEXTURE2D_U_OR_V_DIMENSION;
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return D3D_FL9_1_REQ_TEXTURE2D_U_OR_V_DIMENSION;
default:
UNREACHABLE();
return 0;
}
}
IntelDriverVersion GetIntelDriverVersion(const Optional<LARGE_INTEGER> driverVersion)
{
if (!driverVersion.valid())
return IntelDriverVersion(0);
DWORD lowPart = driverVersion.value().LowPart;
return IntelDriverVersion(HIWORD(lowPart) * 10000 + LOWORD(lowPart));
}
} // anonymous namespace
unsigned int GetReservedVertexUniformVectors(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 0;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 3; // dx_ViewAdjust, dx_ViewCoords and dx_ViewScale
default:
UNREACHABLE();
return 0;
}
}
unsigned int GetReservedFragmentUniformVectors(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 0;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 3;
default:
UNREACHABLE();
return 0;
}
}
gl::Version GetMaximumClientVersion(const Renderer11DeviceCaps &caps)
{
switch (caps.featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return gl::Version(3, 1);
case D3D_FEATURE_LEVEL_10_1:
return gl::Version(3, 0);
case D3D_FEATURE_LEVEL_10_0:
if (caps.allowES3OnFL10_0)
{
return gl::Version(3, 0);
}
else
{
return gl::Version(2, 0);
}
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return gl::Version(2, 0);
default:
UNREACHABLE();
return gl::Version(0, 0);
}
}
D3D_FEATURE_LEVEL GetMinimumFeatureLevelForES31()
{
return kMinimumFeatureLevelForES31;
}
unsigned int GetMaxViewportAndScissorRectanglesPerPipeline(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 1;
default:
UNREACHABLE();
return 0;
}
}
bool IsMultiviewSupported(D3D_FEATURE_LEVEL featureLevel)
{
// The ANGLE_multiview extension can always be supported in D3D11 through geometry shaders.
switch (featureLevel)
{
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
return true;
default:
return false;
}
}
int GetMaxSampleMaskWords(D3D_FEATURE_LEVEL featureLevel)
{
switch (featureLevel)
{
// D3D10+ only allows 1 sample mask.
case D3D_FEATURE_LEVEL_11_1:
case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_10_0:
return 1;
case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_9_2:
case D3D_FEATURE_LEVEL_9_1:
return 0;
default:
UNREACHABLE();
return 0;
}
}
void GenerateCaps(ID3D11Device *device,
ID3D11DeviceContext *deviceContext,
const Renderer11DeviceCaps &renderer11DeviceCaps,
const angle::FeaturesD3D &features,
const char *description,
gl::Caps *caps,
gl::TextureCapsMap *textureCapsMap,
gl::Extensions *extensions,
gl::Limitations *limitations)
{
D3D_FEATURE_LEVEL featureLevel = renderer11DeviceCaps.featureLevel;
const gl::FormatSet &allFormats = gl::GetAllSizedInternalFormats();
for (GLenum internalFormat : allFormats)
{
gl::TextureCaps textureCaps =
GenerateTextureFormatCaps(GetMaximumClientVersion(renderer11DeviceCaps), internalFormat,
device, renderer11DeviceCaps);
textureCapsMap->insert(internalFormat, textureCaps);
if (gl::GetSizedInternalFormatInfo(internalFormat).compressed)
{
caps->compressedTextureFormats.push_back(internalFormat);
}
}
// GL core feature limits
// Reserve MAX_UINT for D3D11's primitive restart.
caps->maxElementIndex = static_cast<GLint64>(std::numeric_limits<unsigned int>::max() - 1);
caps->max3DTextureSize = GetMaximum3DTextureSize(featureLevel);
caps->max2DTextureSize = GetMaximum2DTextureSize(featureLevel);
caps->maxCubeMapTextureSize = GetMaximumCubeMapTextureSize(featureLevel);
caps->maxArrayTextureLayers = GetMaximum2DTextureArraySize(featureLevel);
// Unimplemented, set to minimum required
caps->maxLODBias = 2.0f;
// No specific limits on render target size, maximum 2D texture size is equivalent
caps->maxRenderbufferSize = caps->max2DTextureSize;
// Maximum draw buffers and color attachments are the same, max color attachments could
// eventually be increased to 16
caps->maxDrawBuffers = GetMaximumSimultaneousRenderTargets(featureLevel);
caps->maxColorAttachments = GetMaximumSimultaneousRenderTargets(featureLevel);
// D3D11 has the same limit for viewport width and height
caps->maxViewportWidth = GetMaximumViewportSize(featureLevel);
caps->maxViewportHeight = caps->maxViewportWidth;
// Choose a reasonable maximum, enforced in the shader.
caps->minAliasedPointSize = 1.0f;
caps->maxAliasedPointSize = 1024.0f;
// Wide lines not supported
caps->minAliasedLineWidth = 1.0f;
caps->maxAliasedLineWidth = 1.0f;
// Primitive count limits
caps->maxElementsIndices = GetMaximumDrawIndexedIndexCount(featureLevel);
caps->maxElementsVertices = GetMaximumDrawVertexCount(featureLevel);
// Program and shader binary formats (no supported shader binary formats)
caps->programBinaryFormats.push_back(GL_PROGRAM_BINARY_ANGLE);
caps->vertexHighpFloat.setIEEEFloat();
caps->vertexMediumpFloat.setIEEEFloat();
caps->vertexLowpFloat.setIEEEFloat();
caps->fragmentHighpFloat.setIEEEFloat();
caps->fragmentMediumpFloat.setIEEEFloat();
caps->fragmentLowpFloat.setIEEEFloat();
// 32-bit integers are natively supported
caps->vertexHighpInt.setTwosComplementInt(32);
caps->vertexMediumpInt.setTwosComplementInt(32);
caps->vertexLowpInt.setTwosComplementInt(32);
caps->fragmentHighpInt.setTwosComplementInt(32);
caps->fragmentMediumpInt.setTwosComplementInt(32);
caps->fragmentLowpInt.setTwosComplementInt(32);
// We do not wait for server fence objects internally, so report a max timeout of zero.
caps->maxServerWaitTimeout = 0;
// Vertex shader limits
caps->maxVertexAttributes = GetMaximumVertexInputSlots(featureLevel);
caps->maxVertexUniformVectors = GetMaximumVertexUniformVectors(featureLevel);
if (features.skipVSConstantRegisterZero.enabled)
{
caps->maxVertexUniformVectors -= 1;
}
caps->maxShaderUniformComponents[gl::ShaderType::Vertex] = caps->maxVertexUniformVectors * 4;
caps->maxShaderUniformBlocks[gl::ShaderType::Vertex] =
GetMaximumVertexUniformBlocks(featureLevel);
caps->maxVertexOutputComponents = GetMaximumVertexOutputVectors(featureLevel) * 4;
caps->maxShaderTextureImageUnits[gl::ShaderType::Vertex] =
GetMaximumVertexTextureUnits(featureLevel);
// Vertex Attribute Bindings are emulated on D3D11.
caps->maxVertexAttribBindings = caps->maxVertexAttributes;
// Experimental testing confirmed there is no explicit limit on maximum buffer offset in D3D11.
caps->maxVertexAttribRelativeOffset = std::numeric_limits<GLint>::max();
// Experimental testing confirmed 2048 is the maximum stride that D3D11 can support on all
// platforms.
caps->maxVertexAttribStride = 2048;
// Fragment shader limits
caps->maxFragmentUniformVectors = GetMaximumPixelUniformVectors(featureLevel);
caps->maxShaderUniformComponents[gl::ShaderType::Fragment] =
caps->maxFragmentUniformVectors * 4;
caps->maxShaderUniformBlocks[gl::ShaderType::Fragment] =
GetMaximumPixelUniformBlocks(featureLevel);
caps->maxFragmentInputComponents = GetMaximumPixelInputVectors(featureLevel) * 4;
caps->maxShaderTextureImageUnits[gl::ShaderType::Fragment] =
GetMaximumPixelTextureUnits(featureLevel);
caps->minProgramTexelOffset = GetMinimumTexelOffset(featureLevel);
caps->maxProgramTexelOffset = GetMaximumTexelOffset(featureLevel);
// Compute shader limits
caps->maxComputeWorkGroupCount = GetMaxComputeWorkGroupCount(featureLevel);
caps->maxComputeWorkGroupSize = GetMaxComputeWorkGroupSize(featureLevel);
caps->maxComputeWorkGroupInvocations = GetMaxComputeWorkGroupInvocations(featureLevel);
caps->maxComputeSharedMemorySize = GetMaxComputeSharedMemorySize(featureLevel);
caps->maxShaderUniformComponents[gl::ShaderType::Compute] =
GetMaximumComputeUniformVectors(featureLevel) * 4;
caps->maxShaderUniformBlocks[gl::ShaderType::Compute] =
GetMaximumComputeUniformBlocks(featureLevel);
caps->maxShaderTextureImageUnits[gl::ShaderType::Compute] =
GetMaximumComputeTextureUnits(featureLevel);
SetUAVRelatedResourceLimits(featureLevel, caps);
// Aggregate shader limits
caps->maxUniformBufferBindings = caps->maxShaderUniformBlocks[gl::ShaderType::Vertex] +
caps->maxShaderUniformBlocks[gl::ShaderType::Fragment];
caps->maxUniformBlockSize = static_cast<GLuint64>(GetMaximumConstantBufferSize(featureLevel));
// TODO(oetuaho): Get a more accurate limit. For now using the minimum requirement for GLES 3.1.
caps->maxUniformLocations = 1024;
// With DirectX 11.1, constant buffer offset and size must be a multiple of 16 constants of 16
// bytes each.
// https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx
// With DirectX 11.0, we emulate UBO offsets using copies of ranges of the UBO however
// we still keep the same alignment as 11.1 for consistency.
caps->uniformBufferOffsetAlignment = 256;
caps->maxCombinedUniformBlocks = caps->maxShaderUniformBlocks[gl::ShaderType::Vertex] +
caps->maxShaderUniformBlocks[gl::ShaderType::Fragment];
// A shader storage block will be translated to a structure in HLSL. So We reference the HLSL
// structure packing rules
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb509632(v=vs.85).aspx. The
// resulting size of any structure will always be evenly divisible by sizeof(four-component
// vector).
caps->shaderStorageBufferOffsetAlignment = 16;
for (gl::ShaderType shaderType : gl::AllShaderTypes())
{
caps->maxCombinedShaderUniformComponents[shaderType] =
static_cast<GLint64>(caps->maxShaderUniformBlocks[shaderType]) *
static_cast<GLint64>(caps->maxUniformBlockSize / 4) +
static_cast<GLint64>(caps->maxShaderUniformComponents[shaderType]);
}
caps->maxVaryingComponents = GetMaximumVertexOutputVectors(featureLevel) * 4;
caps->maxVaryingVectors = GetMaximumVertexOutputVectors(featureLevel);
caps->maxCombinedTextureImageUnits = caps->maxShaderTextureImageUnits[gl::ShaderType::Vertex] +
caps->maxShaderTextureImageUnits[gl::ShaderType::Fragment];
// Transform feedback limits
caps->maxTransformFeedbackInterleavedComponents =
GetMaximumStreamOutputInterleavedComponents(featureLevel);
caps->maxTransformFeedbackSeparateAttributes = GetMaximumStreamOutputBuffers(featureLevel);
caps->maxTransformFeedbackSeparateComponents =
GetMaximumStreamOutputSeparateComponents(featureLevel);
// Defer the computation of multisample limits to Context::updateCaps() where max*Samples values
// are determined according to available sample counts for each individual format.
caps->maxSamples = std::numeric_limits<GLint>::max();
caps->maxColorTextureSamples = std::numeric_limits<GLint>::max();
caps->maxDepthTextureSamples = std::numeric_limits<GLint>::max();
caps->maxIntegerSamples = std::numeric_limits<GLint>::max();
// Sample mask words limits
caps->maxSampleMaskWords = GetMaxSampleMaskWords(featureLevel);
// Framebuffer limits
caps->maxFramebufferSamples = std::numeric_limits<GLint>::max();
caps->maxFramebufferWidth = GetMaximumRenderToBufferWindowSize(featureLevel);
caps->maxFramebufferHeight = caps->maxFramebufferWidth;
// Texture gather offset limits
caps->minProgramTextureGatherOffset = GetMinimumTextureGatherOffset(featureLevel);
caps->maxProgramTextureGatherOffset = GetMaximumTextureGatherOffset(featureLevel);
caps->maxTextureAnisotropy = GetMaximumAnisotropy(featureLevel);
caps->queryCounterBitsTimeElapsed = 64;
caps->queryCounterBitsTimestamp = 0; // Timestamps cannot be supported due to D3D11 limitations
caps->maxDualSourceDrawBuffers = 1;
// GL extension support
extensions->setTextureExtensionSupport(*textureCapsMap);
// Explicitly disable GL_OES_compressed_ETC1_RGB8_texture because it's emulated and never
// becomes core. WebGL doesn't want to expose it unless there is native support.
extensions->compressedETC1RGB8TextureOES = false;
extensions->compressedETC1RGB8SubTextureEXT = false;
extensions->elementIndexUintOES = true;
extensions->getProgramBinaryOES = true;
extensions->rgb8Rgba8OES = true;
extensions->readFormatBgraEXT = true;
extensions->pixelBufferObjectNV = true;
extensions->mapbufferOES = true;
extensions->mapBufferRangeEXT = true;
extensions->textureNpotOES = GetNPOTTextureSupport(featureLevel);
extensions->drawBuffersEXT = GetMaximumSimultaneousRenderTargets(featureLevel) > 1;
extensions->drawBuffersIndexedEXT =
(renderer11DeviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_1);
extensions->drawBuffersIndexedOES = extensions->drawBuffersIndexedEXT;
extensions->textureStorageEXT = true;
extensions->textureFilterAnisotropicEXT = true;
extensions->occlusionQueryBooleanEXT = GetOcclusionQuerySupport(featureLevel);
extensions->fenceNV = GetEventQuerySupport(featureLevel);
extensions->disjointTimerQueryEXT = true;
extensions->robustnessEXT = true;
// Direct3D guarantees to return zero for any resource that is accessed out of bounds.
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ff476332(v=vs.85).aspx
// and https://msdn.microsoft.com/en-us/library/windows/desktop/ff476900(v=vs.85).aspx
extensions->robustBufferAccessBehaviorKHR = true;
extensions->blendMinmaxEXT = true;
// https://docs.microsoft.com/en-us/windows/desktop/direct3ddxgi/format-support-for-direct3d-11-0-feature-level-hardware
extensions->floatBlendEXT = true;
extensions->framebufferBlitANGLE = GetFramebufferBlitSupport(featureLevel);
extensions->framebufferBlitNV = extensions->framebufferBlitANGLE;
extensions->framebufferMultisampleANGLE = GetFramebufferMultisampleSupport(featureLevel);
extensions->instancedArraysANGLE = GetInstancingSupport(featureLevel);
extensions->instancedArraysEXT = GetInstancingSupport(featureLevel);
extensions->packReverseRowOrderANGLE = true;
extensions->standardDerivativesOES = GetDerivativeInstructionSupport(featureLevel);
extensions->shaderTextureLodEXT = GetShaderTextureLODSupport(featureLevel);
extensions->fragDepthEXT = true;
extensions->multiviewOVR = IsMultiviewSupported(featureLevel);
extensions->multiview2OVR = IsMultiviewSupported(featureLevel);
if (extensions->multiviewOVR || extensions->multiview2OVR)
{
caps->maxViews = std::min(static_cast<GLuint>(GetMaximum2DTextureArraySize(featureLevel)),
GetMaxViewportAndScissorRectanglesPerPipeline(featureLevel));
}
extensions->textureUsageANGLE = true; // This could be false since it has no effect in D3D11
extensions->discardFramebufferEXT = true;
extensions->translatedShaderSourceANGLE = true;
extensions->fboRenderMipmapOES = true;
extensions->debugMarkerEXT = true;
extensions->EGLImageOES = true;
extensions->EGLImageExternalOES = true;
extensions->EGLImageExternalWrapModesEXT = true;
extensions->EGLImageExternalEssl3OES = true;
extensions->EGLStreamConsumerExternalNV = true;
extensions->unpackSubimageEXT = true;
extensions->packSubimageNV = true;
extensions->lossyEtcDecodeANGLE = true;
extensions->syncQueryCHROMIUM = GetEventQuerySupport(featureLevel);
extensions->copyTextureCHROMIUM = true;
extensions->copyCompressedTextureCHROMIUM = true;
extensions->textureStorageMultisample2dArrayOES = true;
extensions->multiviewMultisampleANGLE =
((extensions->multiviewOVR || extensions->multiview2OVR) &&
extensions->textureStorageMultisample2dArrayOES);
extensions->copyTexture3dANGLE = true;
extensions->textureBorderClampOES = true;
extensions->multiDrawIndirectEXT = true;
extensions->textureMultisampleANGLE = true;
extensions->provokingVertexANGLE = true;
extensions->blendFuncExtendedEXT = true;
// http://anglebug.com/4926
extensions->texture3DOES = false;
extensions->baseVertexBaseInstanceANGLE = true;
extensions->baseVertexBaseInstanceShaderBuiltinANGLE = true;
extensions->drawElementsBaseVertexOES = true;
extensions->drawElementsBaseVertexEXT = true;
if (!strstr(description, "Adreno"))
{
extensions->multisampledRenderToTextureEXT = true;
}
extensions->videoTextureWEBGL = true;
// D3D11 cannot support reading depth texture as a luminance texture.
// It treats it as a red-channel-only texture.
extensions->depthTextureOES = false;
// readPixels on depth & stencil not working with D3D11 backend.
extensions->readDepthNV = false;
extensions->readStencilNV = false;
extensions->depthBufferFloat2NV = false;
// GL_EXT_clip_control
extensions->clipControlEXT = (renderer11DeviceCaps.featureLevel >= D3D_FEATURE_LEVEL_9_3);
// GL_KHR_parallel_shader_compile
extensions->parallelShaderCompileKHR = true;
// D3D11 Feature Level 10_0+ uses SV_IsFrontFace in HLSL to emulate gl_FrontFacing.
// D3D11 Feature Level 9_3 doesn't support SV_IsFrontFace, and has no equivalent, so can't
// support gl_FrontFacing.
limitations->noFrontFacingSupport =
(renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3);
// D3D11 Feature Level 9_3 doesn't support alpha-to-coverage
limitations->noSampleAlphaToCoverageSupport =
(renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3);
// D3D11 Feature Levels 9_3 and below do not support non-constant loop indexing and require
// additional
// pre-validation of the shader at compile time to produce a better error message.
limitations->shadersRequireIndexedLoopValidation =
(renderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3);
// D3D11 has no concept of separate masks and refs for front and back faces in the depth stencil
// state.
limitations->noSeparateStencilRefsAndMasks = true;
// D3D11 cannot support constant color and alpha blend funcs together
limitations->noSimultaneousConstantColorAndAlphaBlendFunc = true;
// D3D11 does not support multiple transform feedback outputs writing to the same buffer.
limitations->noDoubleBoundTransformFeedbackBuffers = true;
// D3D11 does not support vertex attribute aliasing
limitations->noVertexAttributeAliasing = true;
// D3D11 does not support compressed textures where the base mip level is not a multiple of 4
limitations->compressedBaseMipLevelMultipleOfFour = true;
#ifdef ANGLE_ENABLE_WINDOWS_UWP
// Setting a non-zero divisor on attribute zero doesn't work on certain Windows Phone 8-era
// devices. We should prevent developers from doing this on ALL Windows Store devices. This will
// maintain consistency across all Windows devices. We allow non-zero divisors on attribute zero
// if the Client Version >= 3, since devices affected by this issue don't support ES3+.
limitations->attributeZeroRequiresZeroDivisorInEXT = true;
#endif
}
} // namespace d3d11_gl
namespace gl_d3d11
{
D3D11_BLEND ConvertBlendFunc(GLenum glBlend, bool isAlpha)
{
D3D11_BLEND d3dBlend = D3D11_BLEND_ZERO;
switch (glBlend)
{
case GL_ZERO:
d3dBlend = D3D11_BLEND_ZERO;
break;
case GL_ONE:
d3dBlend = D3D11_BLEND_ONE;
break;
case GL_SRC_COLOR:
d3dBlend = (isAlpha ? D3D11_BLEND_SRC_ALPHA : D3D11_BLEND_SRC_COLOR);
break;
case GL_ONE_MINUS_SRC_COLOR:
d3dBlend = (isAlpha ? D3D11_BLEND_INV_SRC_ALPHA : D3D11_BLEND_INV_SRC_COLOR);
break;
case GL_DST_COLOR:
d3dBlend = (isAlpha ? D3D11_BLEND_DEST_ALPHA : D3D11_BLEND_DEST_COLOR);
break;
case GL_ONE_MINUS_DST_COLOR:
d3dBlend = (isAlpha ? D3D11_BLEND_INV_DEST_ALPHA : D3D11_BLEND_INV_DEST_COLOR);
break;
case GL_SRC_ALPHA:
d3dBlend = D3D11_BLEND_SRC_ALPHA;
break;
case GL_ONE_MINUS_SRC_ALPHA:
d3dBlend = D3D11_BLEND_INV_SRC_ALPHA;
break;
case GL_DST_ALPHA:
d3dBlend = D3D11_BLEND_DEST_ALPHA;
break;
case GL_ONE_MINUS_DST_ALPHA:
d3dBlend = D3D11_BLEND_INV_DEST_ALPHA;
break;
case GL_CONSTANT_COLOR:
d3dBlend = D3D11_BLEND_BLEND_FACTOR;
break;
case GL_ONE_MINUS_CONSTANT_COLOR:
d3dBlend = D3D11_BLEND_INV_BLEND_FACTOR;
break;
case GL_CONSTANT_ALPHA:
d3dBlend = D3D11_BLEND_BLEND_FACTOR;
break;
case GL_ONE_MINUS_CONSTANT_ALPHA:
d3dBlend = D3D11_BLEND_INV_BLEND_FACTOR;
break;
case GL_SRC_ALPHA_SATURATE:
d3dBlend = D3D11_BLEND_SRC_ALPHA_SAT;
break;
case GL_SRC1_COLOR_EXT:
d3dBlend = (isAlpha ? D3D11_BLEND_SRC1_ALPHA : D3D11_BLEND_SRC1_COLOR);
break;
case GL_SRC1_ALPHA_EXT:
d3dBlend = D3D11_BLEND_SRC1_ALPHA;
break;
case GL_ONE_MINUS_SRC1_COLOR_EXT:
d3dBlend = (isAlpha ? D3D11_BLEND_INV_SRC1_ALPHA : D3D11_BLEND_INV_SRC1_COLOR);
break;
case GL_ONE_MINUS_SRC1_ALPHA_EXT:
d3dBlend = D3D11_BLEND_INV_SRC1_ALPHA;
break;
default:
UNREACHABLE();
}
return d3dBlend;
}
D3D11_BLEND_OP ConvertBlendOp(GLenum glBlendOp)
{
D3D11_BLEND_OP d3dBlendOp = D3D11_BLEND_OP_ADD;
switch (glBlendOp)
{
case GL_FUNC_ADD:
d3dBlendOp = D3D11_BLEND_OP_ADD;
break;
case GL_FUNC_SUBTRACT:
d3dBlendOp = D3D11_BLEND_OP_SUBTRACT;
break;
case GL_FUNC_REVERSE_SUBTRACT:
d3dBlendOp = D3D11_BLEND_OP_REV_SUBTRACT;
break;
case GL_MIN:
d3dBlendOp = D3D11_BLEND_OP_MIN;
break;
case GL_MAX:
d3dBlendOp = D3D11_BLEND_OP_MAX;
break;
default:
UNREACHABLE();
}
return d3dBlendOp;
}
UINT8 ConvertColorMask(bool red, bool green, bool blue, bool alpha)
{
UINT8 mask = 0;
if (red)
{
mask |= D3D11_COLOR_WRITE_ENABLE_RED;
}
if (green)
{
mask |= D3D11_COLOR_WRITE_ENABLE_GREEN;
}
if (blue)
{
mask |= D3D11_COLOR_WRITE_ENABLE_BLUE;
}
if (alpha)
{
mask |= D3D11_COLOR_WRITE_ENABLE_ALPHA;
}
return mask;
}
D3D11_CULL_MODE ConvertCullMode(bool cullEnabled, gl::CullFaceMode cullMode)
{
D3D11_CULL_MODE cull = D3D11_CULL_NONE;
if (cullEnabled)
{
switch (cullMode)
{
case gl::CullFaceMode::Front:
cull = D3D11_CULL_FRONT;
break;
case gl::CullFaceMode::Back:
cull = D3D11_CULL_BACK;
break;
case gl::CullFaceMode::FrontAndBack:
cull = D3D11_CULL_NONE;
break;
default:
UNREACHABLE();
}
}
else
{
cull = D3D11_CULL_NONE;
}
return cull;
}
D3D11_COMPARISON_FUNC ConvertComparison(GLenum comparison)
{
D3D11_COMPARISON_FUNC d3dComp = D3D11_COMPARISON_NEVER;
switch (comparison)
{
case GL_NEVER:
d3dComp = D3D11_COMPARISON_NEVER;
break;
case GL_ALWAYS:
d3dComp = D3D11_COMPARISON_ALWAYS;
break;
case GL_LESS:
d3dComp = D3D11_COMPARISON_LESS;
break;
case GL_LEQUAL:
d3dComp = D3D11_COMPARISON_LESS_EQUAL;
break;
case GL_EQUAL:
d3dComp = D3D11_COMPARISON_EQUAL;
break;
case GL_GREATER:
d3dComp = D3D11_COMPARISON_GREATER;
break;
case GL_GEQUAL:
d3dComp = D3D11_COMPARISON_GREATER_EQUAL;
break;
case GL_NOTEQUAL:
d3dComp = D3D11_COMPARISON_NOT_EQUAL;
break;
default:
UNREACHABLE();
}
return d3dComp;
}
D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled)
{
return depthWriteEnabled ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
}
UINT8 ConvertStencilMask(GLuint stencilmask)
{
return static_cast<UINT8>(stencilmask);
}
D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp)
{
D3D11_STENCIL_OP d3dStencilOp = D3D11_STENCIL_OP_KEEP;
switch (stencilOp)
{
case GL_ZERO:
d3dStencilOp = D3D11_STENCIL_OP_ZERO;
break;
case GL_KEEP:
d3dStencilOp = D3D11_STENCIL_OP_KEEP;
break;
case GL_REPLACE:
d3dStencilOp = D3D11_STENCIL_OP_REPLACE;
break;
case GL_INCR:
d3dStencilOp = D3D11_STENCIL_OP_INCR_SAT;
break;
case GL_DECR:
d3dStencilOp = D3D11_STENCIL_OP_DECR_SAT;
break;
case GL_INVERT:
d3dStencilOp = D3D11_STENCIL_OP_INVERT;
break;
case GL_INCR_WRAP:
d3dStencilOp = D3D11_STENCIL_OP_INCR;
break;
case GL_DECR_WRAP:
d3dStencilOp = D3D11_STENCIL_OP_DECR;
break;
default:
UNREACHABLE();
}
return d3dStencilOp;
}
D3D11_FILTER ConvertFilter(GLenum minFilter,
GLenum magFilter,
float maxAnisotropy,
GLenum comparisonMode)
{
bool comparison = comparisonMode != GL_NONE;
if (maxAnisotropy > 1.0f)
{
return D3D11_ENCODE_ANISOTROPIC_FILTER(static_cast<D3D11_COMPARISON_FUNC>(comparison));
}
else
{
D3D11_FILTER_TYPE dxMin = D3D11_FILTER_TYPE_POINT;
D3D11_FILTER_TYPE dxMip = D3D11_FILTER_TYPE_POINT;
switch (minFilter)
{
case GL_NEAREST:
dxMin = D3D11_FILTER_TYPE_POINT;
dxMip = D3D11_FILTER_TYPE_POINT;
break;
case GL_LINEAR:
dxMin = D3D11_FILTER_TYPE_LINEAR;
dxMip = D3D11_FILTER_TYPE_POINT;
break;
case GL_NEAREST_MIPMAP_NEAREST:
dxMin = D3D11_FILTER_TYPE_POINT;
dxMip = D3D11_FILTER_TYPE_POINT;
break;
case GL_LINEAR_MIPMAP_NEAREST:
dxMin = D3D11_FILTER_TYPE_LINEAR;
dxMip = D3D11_FILTER_TYPE_POINT;
break;
case GL_NEAREST_MIPMAP_LINEAR:
dxMin = D3D11_FILTER_TYPE_POINT;
dxMip = D3D11_FILTER_TYPE_LINEAR;
break;
case GL_LINEAR_MIPMAP_LINEAR:
dxMin = D3D11_FILTER_TYPE_LINEAR;
dxMip = D3D11_FILTER_TYPE_LINEAR;
break;
default:
UNREACHABLE();
}
D3D11_FILTER_TYPE dxMag = D3D11_FILTER_TYPE_POINT;
switch (magFilter)
{
case GL_NEAREST:
dxMag = D3D11_FILTER_TYPE_POINT;
break;
case GL_LINEAR:
dxMag = D3D11_FILTER_TYPE_LINEAR;
break;
default:
UNREACHABLE();
}
return D3D11_ENCODE_BASIC_FILTER(dxMin, dxMag, dxMip,
static_cast<D3D11_COMPARISON_FUNC>(comparison));
}
}
D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap)
{
switch (wrap)
{
case GL_REPEAT:
return D3D11_TEXTURE_ADDRESS_WRAP;
case GL_CLAMP_TO_EDGE:
return D3D11_TEXTURE_ADDRESS_CLAMP;
case GL_CLAMP_TO_BORDER:
return D3D11_TEXTURE_ADDRESS_BORDER;
case GL_MIRRORED_REPEAT:
return D3D11_TEXTURE_ADDRESS_MIRROR;
default:
UNREACHABLE();
}
return D3D11_TEXTURE_ADDRESS_WRAP;
}
UINT ConvertMaxAnisotropy(float maxAnisotropy, D3D_FEATURE_LEVEL featureLevel)
{
return static_cast<UINT>(std::min(maxAnisotropy, d3d11_gl::GetMaximumAnisotropy(featureLevel)));
}
D3D11_QUERY ConvertQueryType(gl::QueryType type)
{
switch (type)
{
case gl::QueryType::AnySamples:
case gl::QueryType::AnySamplesConservative:
return D3D11_QUERY_OCCLUSION;
case gl::QueryType::TransformFeedbackPrimitivesWritten:
return D3D11_QUERY_SO_STATISTICS;
case gl::QueryType::TimeElapsed:
// Two internal queries are also created for begin/end timestamps
return D3D11_QUERY_TIMESTAMP_DISJOINT;
case gl::QueryType::CommandsCompleted:
return D3D11_QUERY_EVENT;
default:
UNREACHABLE();
return D3D11_QUERY_EVENT;
}
}
// Get the D3D11 write mask covering all color channels of a given format
UINT8 GetColorMask(const gl::InternalFormat &format)
{
return ConvertColorMask(format.redBits > 0, format.greenBits > 0, format.blueBits > 0,
format.alphaBits > 0);
}
} // namespace gl_d3d11
namespace d3d11
{
ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device)
{
// Note that this function returns an ANGLED3D11DeviceType rather than a D3D_DRIVER_TYPE value,
// since it is difficult to tell Software and Reference devices apart
IDXGIDevice *dxgiDevice = nullptr;
IDXGIAdapter *dxgiAdapter = nullptr;
IDXGIAdapter2 *dxgiAdapter2 = nullptr;
ANGLED3D11DeviceType retDeviceType = ANGLE_D3D11_DEVICE_TYPE_UNKNOWN;
HRESULT hr = device->QueryInterface(__uuidof(IDXGIDevice), (void **)&dxgiDevice);
if (SUCCEEDED(hr))
{
hr = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&dxgiAdapter);
if (SUCCEEDED(hr))
{
std::wstring adapterString;
HRESULT adapter2hr =
dxgiAdapter->QueryInterface(__uuidof(dxgiAdapter2), (void **)&dxgiAdapter2);
if (SUCCEEDED(adapter2hr))
{
// On D3D_FEATURE_LEVEL_9_*, IDXGIAdapter::GetDesc returns "Software Adapter"
// for the description string. Try to use IDXGIAdapter2::GetDesc2 to get the
// actual hardware values if possible.
DXGI_ADAPTER_DESC2 adapterDesc2;
dxgiAdapter2->GetDesc2(&adapterDesc2);
adapterString = std::wstring(adapterDesc2.Description);
}
else
{
DXGI_ADAPTER_DESC adapterDesc;
dxgiAdapter->GetDesc(&adapterDesc);
adapterString = std::wstring(adapterDesc.Description);
}
// Both Reference and Software adapters will be 'Software Adapter'
const bool isSoftwareDevice =
(adapterString.find(std::wstring(L"Software Adapter")) != std::string::npos);
const bool isNullDevice = (adapterString == L"");
const bool isWARPDevice =
(adapterString.find(std::wstring(L"Basic Render")) != std::string::npos);
if (isSoftwareDevice || isNullDevice)
{
ASSERT(!isWARPDevice);
retDeviceType = ANGLE_D3D11_DEVICE_TYPE_SOFTWARE_REF_OR_NULL;
}
else if (isWARPDevice)
{
retDeviceType = ANGLE_D3D11_DEVICE_TYPE_WARP;
}
else
{
retDeviceType = ANGLE_D3D11_DEVICE_TYPE_HARDWARE;
}
}
}
SafeRelease(dxgiDevice);
SafeRelease(dxgiAdapter);
SafeRelease(dxgiAdapter2);
return retDeviceType;
}
void MakeValidSize(bool isImage,
DXGI_FORMAT format,
GLsizei *requestWidth,
GLsizei *requestHeight,
int *levelOffset)
{
const DXGIFormatSize &dxgiFormatInfo = d3d11::GetDXGIFormatSizeInfo(format);
bool validFormat = format != DXGI_FORMAT_UNKNOWN;
bool validImage = isImage && validFormat;
int upsampleCount = 0;
// Don't expand the size of full textures that are at least (blockWidth x blockHeight) already.
if (validImage || *requestWidth < static_cast<GLsizei>(dxgiFormatInfo.blockWidth) ||
*requestHeight < static_cast<GLsizei>(dxgiFormatInfo.blockHeight))
{
while (*requestWidth % dxgiFormatInfo.blockWidth != 0 ||
*requestHeight % dxgiFormatInfo.blockHeight != 0)
{
*requestWidth <<= 1;
*requestHeight <<= 1;
upsampleCount++;
}
}
else if (validFormat)
{
if (*requestWidth % dxgiFormatInfo.blockWidth != 0)
{
*requestWidth = roundUp(*requestWidth, static_cast<GLsizei>(dxgiFormatInfo.blockWidth));
}
if (*requestHeight % dxgiFormatInfo.blockHeight != 0)
{
*requestHeight =
roundUp(*requestHeight, static_cast<GLsizei>(dxgiFormatInfo.blockHeight));
}
}
if (levelOffset)
{
*levelOffset = upsampleCount;
}
}
angle::Result GenerateInitialTextureData(
const gl::Context *context,
GLint internalFormat,
const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint width,
GLuint height,
GLuint depth,
GLuint mipLevels,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData)
{
const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps);
ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr);
const d3d11::DXGIFormatSize &dxgiFormatInfo =
d3d11::GetDXGIFormatSizeInfo(d3dFormatInfo.texFormat);
using CheckedSize = angle::CheckedNumeric<size_t>;
CheckedSize rowPitch = CheckedSize(dxgiFormatInfo.pixelBytes) * CheckedSize(width);
CheckedSize depthPitch = rowPitch * CheckedSize(height);
CheckedSize maxImageSize = depthPitch * CheckedSize(depth);
Context11 *context11 = GetImplAs<Context11>(context);
ANGLE_CHECK_GL_ALLOC(context11, maxImageSize.IsValid());
angle::MemoryBuffer *scratchBuffer = nullptr;
ANGLE_CHECK_GL_ALLOC(context11,
context->getScratchBuffer(maxImageSize.ValueOrDie(), &scratchBuffer));
d3dFormatInfo.dataInitializerFunction(width, height, depth, scratchBuffer->data(),
rowPitch.ValueOrDie(), depthPitch.ValueOrDie());
for (unsigned int i = 0; i < mipLevels; i++)
{
unsigned int mipWidth = std::max(width >> i, 1U);
unsigned int mipHeight = std::max(height >> i, 1U);
using CheckedUINT = angle::CheckedNumeric<UINT>;
CheckedUINT mipRowPitch = CheckedUINT(dxgiFormatInfo.pixelBytes) * CheckedUINT(mipWidth);
CheckedUINT mipDepthPitch = mipRowPitch * CheckedUINT(mipHeight);
ANGLE_CHECK_GL_ALLOC(context11, mipRowPitch.IsValid() && mipDepthPitch.IsValid());
outSubresourceData->at(i).pSysMem = scratchBuffer->data();
outSubresourceData->at(i).SysMemPitch = mipRowPitch.ValueOrDie();
outSubresourceData->at(i).SysMemSlicePitch = mipDepthPitch.ValueOrDie();
}
return angle::Result::Continue;
}
UINT GetPrimitiveRestartIndex()
{
return std::numeric_limits<UINT>::max();
}
void SetPositionTexCoordVertex(PositionTexCoordVertex *vertex, float x, float y, float u, float v)
{
vertex->x = x;
vertex->y = y;
vertex->u = u;
vertex->v = v;
}
void SetPositionLayerTexCoord3DVertex(PositionLayerTexCoord3DVertex *vertex,
float x,
float y,
unsigned int layer,
float u,
float v,
float s)
{
vertex->x = x;
vertex->y = y;
vertex->l = layer;
vertex->u = u;
vertex->v = v;
vertex->s = s;
}
BlendStateKey::BlendStateKey()
{
memset(this, 0, sizeof(BlendStateKey));
blendStateExt = gl::BlendStateExt();
}
BlendStateKey::BlendStateKey(const BlendStateKey &other)
{
memcpy(this, &other, sizeof(BlendStateKey));
}
bool operator==(const BlendStateKey &a, const BlendStateKey &b)
{
return memcmp(&a, &b, sizeof(BlendStateKey)) == 0;
}
bool operator!=(const BlendStateKey &a, const BlendStateKey &b)
{
return !(a == b);
}
RasterizerStateKey::RasterizerStateKey()
{
memset(this, 0, sizeof(RasterizerStateKey));
}
bool operator==(const RasterizerStateKey &a, const RasterizerStateKey &b)
{
return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0;
}
bool operator!=(const RasterizerStateKey &a, const RasterizerStateKey &b)
{
return !(a == b);
}
HRESULT SetDebugName(ID3D11DeviceChild *resource,
const char *internalName,
const std::string *khrDebugName)
{
// Prepend ANGLE to separate names from other components in the same process.
std::string d3dName = "ANGLE";
bool sendNameToD3D = false;
if (internalName && internalName[0] != '\0')
{
d3dName += std::string("_") + internalName;
sendNameToD3D = true;
}
if (khrDebugName && !khrDebugName->empty())
{
d3dName += std::string("_") + *khrDebugName;
sendNameToD3D = true;
}
// If both internalName and khrDebugName are empty, avoid sending the string to d3d.
if (sendNameToD3D)
{
return resource->SetPrivateData(WKPDID_D3DDebugObjectName,
static_cast<UINT>(d3dName.size()), d3dName.c_str());
}
return S_OK;
}
// Keep this in cpp file where it has visibility of Renderer11.h, otherwise calling
// allocateResource is only compatible with Clang and MSVS, which support calling a
// method on a forward declared class in a template.
template <ResourceType ResourceT>
angle::Result LazyResource<ResourceT>::resolveImpl(d3d::Context *context,
Renderer11 *renderer,
const GetDescType<ResourceT> &desc,
GetInitDataType<ResourceT> *initData,
const char *name)
{
if (!mResource.valid())
{
ANGLE_TRY(renderer->allocateResource(context, desc, initData, &mResource));
mResource.setInternalName(name);
}
return angle::Result::Continue;
}
template angle::Result LazyResource<ResourceType::BlendState>::resolveImpl(
d3d::Context *context,
Renderer11 *renderer,
const D3D11_BLEND_DESC &desc,
void *initData,
const char *name);
template angle::Result LazyResource<ResourceType::ComputeShader>::resolveImpl(
d3d::Context *context,
Renderer11 *renderer,
const ShaderData &desc,
void *initData,
const char *name);
template angle::Result LazyResource<ResourceType::GeometryShader>::resolveImpl(
d3d::Context *context,
Renderer11 *renderer,
const ShaderData &desc,
const std::vector<D3D11_SO_DECLARATION_ENTRY> *initData,
const char *name);
template angle::Result LazyResource<ResourceType::InputLayout>::resolveImpl(
d3d::Context *context,
Renderer11 *renderer,
const InputElementArray &desc,
const ShaderData *initData,
const char *name);
template angle::Result LazyResource<ResourceType::PixelShader>::resolveImpl(d3d::Context *context,
Renderer11 *renderer,
const ShaderData &desc,
void *initData,
const char *name);
template angle::Result LazyResource<ResourceType::VertexShader>::resolveImpl(d3d::Context *context,
Renderer11 *renderer,
const ShaderData &desc,
void *initData,
const char *name);
LazyInputLayout::LazyInputLayout(const D3D11_INPUT_ELEMENT_DESC *inputDesc,
size_t inputDescLen,
const BYTE *byteCode,
size_t byteCodeLen,
const char *debugName)
: mInputDesc(inputDesc, inputDescLen), mByteCode(byteCode, byteCodeLen), mDebugName(debugName)
{}
LazyInputLayout::~LazyInputLayout() {}
angle::Result LazyInputLayout::resolve(d3d::Context *context, Renderer11 *renderer)
{
return resolveImpl(context, renderer, mInputDesc, &mByteCode, mDebugName);
}
LazyBlendState::LazyBlendState(const D3D11_BLEND_DESC &desc, const char *debugName)
: mDesc(desc), mDebugName(debugName)
{}
angle::Result LazyBlendState::resolve(d3d::Context *context, Renderer11 *renderer)
{
return resolveImpl(context, renderer, mDesc, nullptr, mDebugName);
}
void InitializeFeatures(const Renderer11DeviceCaps &deviceCaps,
const DXGI_ADAPTER_DESC &adapterDesc,
angle::FeaturesD3D *features)
{
bool isNvidia = IsNvidia(adapterDesc.VendorId);
bool isIntel = IsIntel(adapterDesc.VendorId);
bool isSkylake = false;
bool isBroadwell = false;
bool isHaswell = false;
bool isIvyBridge = false;
bool isAMD = IsAMD(adapterDesc.VendorId);
bool isFeatureLevel9_3 = (deviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3);
IntelDriverVersion capsVersion = IntelDriverVersion(0);
if (isIntel)
{
capsVersion = d3d11_gl::GetIntelDriverVersion(deviceCaps.driverVersion);
isSkylake = IsSkylake(adapterDesc.DeviceId);
isBroadwell = IsBroadwell(adapterDesc.DeviceId);
isHaswell = IsHaswell(adapterDesc.DeviceId);
isIvyBridge = IsIvyBridge(adapterDesc.DeviceId);
}
if (isNvidia)
{
// TODO(jmadill): Narrow problematic driver range.
bool driverVersionValid = deviceCaps.driverVersion.valid();
if (driverVersionValid)
{
WORD part1 = HIWORD(deviceCaps.driverVersion.value().LowPart);
WORD part2 = LOWORD(deviceCaps.driverVersion.value().LowPart);
// Disable the workaround to fix a second driver bug on newer NVIDIA.
ANGLE_FEATURE_CONDITION(
features, depthStencilBlitExtraCopy,
(part1 <= 13u && part2 < 6881) && isNvidia && driverVersionValid);
}
else
{
ANGLE_FEATURE_CONDITION(features, depthStencilBlitExtraCopy,
isNvidia && !driverVersionValid);
}
}
ANGLE_FEATURE_CONDITION(features, mrtPerfWorkaround, true);
ANGLE_FEATURE_CONDITION(features, zeroMaxLodWorkaround, isFeatureLevel9_3);
ANGLE_FEATURE_CONDITION(features, useInstancedPointSpriteEmulation, isFeatureLevel9_3);
ANGLE_FEATURE_CONDITION(features, allowES3OnFL100, false);
// TODO(jmadill): Disable workaround when we have a fixed compiler DLL.
ANGLE_FEATURE_CONDITION(features, expandIntegerPowExpressions, true);
ANGLE_FEATURE_CONDITION(features, flushAfterEndingTransformFeedback, isNvidia);
ANGLE_FEATURE_CONDITION(features, getDimensionsIgnoresBaseLevel, isNvidia);
ANGLE_FEATURE_CONDITION(features, skipVSConstantRegisterZero, isNvidia);
ANGLE_FEATURE_CONDITION(features, forceAtomicValueResolution, isNvidia);
ANGLE_FEATURE_CONDITION(features, preAddTexelFetchOffsets, isIntel);
ANGLE_FEATURE_CONDITION(features, useSystemMemoryForConstantBuffers, isIntel);
ANGLE_FEATURE_CONDITION(features, callClearTwice,
isIntel && isSkylake && capsVersion >= IntelDriverVersion(160000) &&
capsVersion < IntelDriverVersion(164771));
ANGLE_FEATURE_CONDITION(features, emulateIsnanFloat,
isIntel && isSkylake && capsVersion >= IntelDriverVersion(160000) &&
capsVersion < IntelDriverVersion(164542));
ANGLE_FEATURE_CONDITION(features, rewriteUnaryMinusOperator,
isIntel && (isBroadwell || isHaswell) &&
capsVersion >= IntelDriverVersion(150000) &&
capsVersion < IntelDriverVersion(154624));
ANGLE_FEATURE_CONDITION(features, addMockTextureNoRenderTarget,
isIntel && capsVersion >= IntelDriverVersion(160000) &&
capsVersion < IntelDriverVersion(164815));
// Haswell/Ivybridge drivers occasionally corrupt (small?) (vertex?) texture data uploads.
ANGLE_FEATURE_CONDITION(features, setDataFasterThanImageUpload,
!(isIvyBridge || isBroadwell || isHaswell));
ANGLE_FEATURE_CONDITION(features, disableB5G6R5Support,
(isIntel && capsVersion >= IntelDriverVersion(150000) &&
capsVersion < IntelDriverVersion(154539)) ||
isAMD);
// TODO(jmadill): Disable when we have a fixed driver version.
// The tiny stencil texture workaround involves using CopySubresource or UpdateSubresource on a
// depth stencil texture. This is not allowed until feature level 10.1 but since it is not
// possible to support ES3 on these devices, there is no need for the workaround to begin with
// (anglebug.com/1572).
ANGLE_FEATURE_CONDITION(features, emulateTinyStencilTextures,
isAMD && !(deviceCaps.featureLevel < D3D_FEATURE_LEVEL_10_1));
// If the VPAndRTArrayIndexFromAnyShaderFeedingRasterizer feature is not available, we have to
// select the viewport / RT array index in the geometry shader.
ANGLE_FEATURE_CONDITION(features, selectViewInGeometryShader,
!deviceCaps.supportsVpRtIndexWriteFromVertexShader);
// NVidia drivers have no trouble clearing textures without showing corruption.
// Intel and AMD drivers that have trouble have been blocklisted by Chromium. In the case of
// Intel, they've been blocklisted to the DX9 runtime.
ANGLE_FEATURE_CONDITION(features, allowClearForRobustResourceInit, true);
// Allow translating uniform block to StructuredBuffer on Windows 10. This is targeted
// to work around a slow fxc compile performance issue with dynamic uniform indexing.
ANGLE_FEATURE_CONDITION(features, allowTranslateUniformBlockToStructuredBuffer,
IsWin10OrGreater());
}
void InitializeFrontendFeatures(const DXGI_ADAPTER_DESC &adapterDesc,
angle::FrontendFeatures *features)
{
bool isAMD = IsAMD(adapterDesc.VendorId);
ANGLE_FEATURE_CONDITION(features, forceDepthAttachmentInitOnClear, isAMD);
}
void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t byteWidth)
{
constantBufferDescription->ByteWidth = static_cast<UINT>(byteWidth);
constantBufferDescription->Usage = D3D11_USAGE_DYNAMIC;
constantBufferDescription->BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constantBufferDescription->CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
constantBufferDescription->MiscFlags = 0;
constantBufferDescription->StructureByteStride = 0;
}
} // namespace d3d11
// TextureHelper11 implementation.
TextureHelper11::TextureHelper11() : mFormatSet(nullptr), mSampleCount(0) {}
TextureHelper11::TextureHelper11(TextureHelper11 &&toCopy) : TextureHelper11()
{
*this = std::move(toCopy);
}
TextureHelper11::TextureHelper11(const TextureHelper11 &other)
: mFormatSet(other.mFormatSet), mExtents(other.mExtents), mSampleCount(other.mSampleCount)
{
mData = other.mData;
}
TextureHelper11::~TextureHelper11() {}
void TextureHelper11::getDesc(D3D11_TEXTURE2D_DESC *desc) const
{
static_cast<ID3D11Texture2D *>(mData->object)->GetDesc(desc);
}
void TextureHelper11::getDesc(D3D11_TEXTURE3D_DESC *desc) const
{
static_cast<ID3D11Texture3D *>(mData->object)->GetDesc(desc);
}
void TextureHelper11::initDesc(const D3D11_TEXTURE2D_DESC &desc2D)
{
mData->resourceType = ResourceType::Texture2D;
mExtents.width = static_cast<int>(desc2D.Width);
mExtents.height = static_cast<int>(desc2D.Height);
mExtents.depth = 1;
mSampleCount = desc2D.SampleDesc.Count;
}
void TextureHelper11::initDesc(const D3D11_TEXTURE3D_DESC &desc3D)
{
mData->resourceType = ResourceType::Texture3D;
mExtents.width = static_cast<int>(desc3D.Width);
mExtents.height = static_cast<int>(desc3D.Height);
mExtents.depth = static_cast<int>(desc3D.Depth);
mSampleCount = 1;
}
TextureHelper11 &TextureHelper11::operator=(TextureHelper11 &&other)
{
std::swap(mData, other.mData);
std::swap(mExtents, other.mExtents);
std::swap(mFormatSet, other.mFormatSet);
std::swap(mSampleCount, other.mSampleCount);
return *this;
}
TextureHelper11 &TextureHelper11::operator=(const TextureHelper11 &other)
{
mData = other.mData;
mExtents = other.mExtents;
mFormatSet = other.mFormatSet;
mSampleCount = other.mSampleCount;
return *this;
}
bool TextureHelper11::operator==(const TextureHelper11 &other) const
{
return mData->object == other.mData->object;
}
bool TextureHelper11::operator!=(const TextureHelper11 &other) const
{
return mData->object != other.mData->object;
}
bool UsePresentPathFast(const Renderer11 *renderer,
const gl::FramebufferAttachment *framebufferAttachment)
{
if (framebufferAttachment == nullptr)
{
return false;
}
return (framebufferAttachment->type() == GL_FRAMEBUFFER_DEFAULT &&
renderer->presentPathFastEnabled());
}
bool UsePrimitiveRestartWorkaround(bool primitiveRestartFixedIndexEnabled,
gl::DrawElementsType type)
{
// We should never have to deal with primitive restart workaround issue with GL_UNSIGNED_INT
// indices, since we restrict it via MAX_ELEMENT_INDEX.
return (!primitiveRestartFixedIndexEnabled && type == gl::DrawElementsType::UnsignedShort);
}
IndexStorageType ClassifyIndexStorage(const gl::State &glState,
const gl::Buffer *elementArrayBuffer,
gl::DrawElementsType elementType,
gl::DrawElementsType destElementType,
unsigned int offset)
{
// No buffer bound means we are streaming from a client pointer.
if (!elementArrayBuffer || !IsOffsetAligned(elementType, offset))
{
return IndexStorageType::Dynamic;
}
// The buffer can be used directly if the storage supports it and no translation needed.
BufferD3D *bufferD3D = GetImplAs<BufferD3D>(elementArrayBuffer);
if (bufferD3D->supportsDirectBinding() && destElementType == elementType)
{
return IndexStorageType::Direct;
}
// Use a static copy when available.
StaticIndexBufferInterface *staticBuffer = bufferD3D->getStaticIndexBuffer();
if (staticBuffer != nullptr)
{
return IndexStorageType::Static;
}
// Static buffer not available, fall back to streaming.
return IndexStorageType::Dynamic;
}
} // namespace rx