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
|
/* Copyright (c) 2015-2023 The Khronos Group Inc.
* Copyright (c) 2015-2023 Valve Corporation
* Copyright (c) 2015-2023 LunarG, Inc.
* Copyright (C) 2015-2022 Google Inc.
* Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
* Modifications Copyright (C) 2022 RasterGrid Kft.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Author: Mark Lobodzinski <mark@lunarg.com>
* Author: Dave Houlton <daveh@lunarg.com>
* Shannon McPherson <shannon@lunarg.com>
* Author: Tobias Hector <tobias.hector@amd.com>
* Author: Daniel Rakos <daniel.rakos@rastergrid.com>
*/
#include <algorithm>
#include <cmath>
#include "vk_enum_string_helper.h"
#include "vk_format_utils.h"
#include "vk_layer_data.h"
#include "vk_layer_utils.h"
#include "vk_layer_logging.h"
#include "vk_typemap_helper.h"
#include "chassis.h"
#include "state_tracker.h"
#include "shader_validation.h"
#include "sync_utils.h"
#include "cmd_buffer_state.h"
#include "render_pass_state.h"
// NOTE: Beware the lifespan of the rp_begin when holding the return. If the rp_begin isn't a "safe" copy, "IMAGELESS"
// attachments won't persist past the API entry point exit.
static std::pair<uint32_t, const VkImageView *> GetFramebufferAttachments(const VkRenderPassBeginInfo &rp_begin,
const FRAMEBUFFER_STATE &fb_state) {
const VkImageView *attachments = fb_state.createInfo.pAttachments;
uint32_t count = fb_state.createInfo.attachmentCount;
if (fb_state.createInfo.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) {
const auto *framebuffer_attachments = LvlFindInChain<VkRenderPassAttachmentBeginInfo>(rp_begin.pNext);
if (framebuffer_attachments) {
attachments = framebuffer_attachments->pAttachments;
count = framebuffer_attachments->attachmentCount;
}
}
return std::make_pair(count, attachments);
}
template <typename ImageViewPointer, typename Get>
std::vector<ImageViewPointer> GetAttachmentViewsImpl(const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state,
const Get &get_fn) {
std::vector<ImageViewPointer> views;
const auto count_attachment = GetFramebufferAttachments(rp_begin, fb_state);
const auto attachment_count = count_attachment.first;
const auto *attachments = count_attachment.second;
views.resize(attachment_count, nullptr);
for (uint32_t i = 0; i < attachment_count; i++) {
if (attachments[i] != VK_NULL_HANDLE) {
views[i] = get_fn(attachments[i]);
}
}
return views;
}
std::vector<std::shared_ptr<const IMAGE_VIEW_STATE>> ValidationStateTracker::GetAttachmentViews(
const VkRenderPassBeginInfo &rp_begin, const FRAMEBUFFER_STATE &fb_state) const {
auto get_fn = [this](VkImageView handle) { return this->Get<IMAGE_VIEW_STATE>(handle); };
return GetAttachmentViewsImpl<std::shared_ptr<const IMAGE_VIEW_STATE>>(rp_begin, fb_state, get_fn);
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
// Android-specific validation that uses types defined only with VK_USE_PLATFORM_ANDROID_KHR
// This could also move into a seperate core_validation_android.cpp file... ?
template <typename CreateInfo>
VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
VkFormatFeatureFlags format_features = 0;
const VkExternalFormatANDROID *ext_fmt_android = LvlFindInChain<VkExternalFormatANDROID>(create_info->pNext);
if (ext_fmt_android && (0 != ext_fmt_android->externalFormat)) {
// VUID 01894 will catch if not found in map
auto it = ahb_ext_formats_map.find(ext_fmt_android->externalFormat);
if (it != ahb_ext_formats_map.end()) {
format_features = it->second;
}
}
return format_features;
}
void ValidationStateTracker::PostCallRecordGetAndroidHardwareBufferPropertiesANDROID(
VkDevice device, const struct AHardwareBuffer *buffer, VkAndroidHardwareBufferPropertiesANDROID *pProperties, VkResult result) {
if (VK_SUCCESS != result) return;
auto ahb_format_props2 = LvlFindInChain<VkAndroidHardwareBufferFormatProperties2ANDROID>(pProperties->pNext);
if (ahb_format_props2) {
ahb_ext_formats_map.insert(ahb_format_props2->externalFormat, ahb_format_props2->formatFeatures);
} else {
auto ahb_format_props = LvlFindInChain<VkAndroidHardwareBufferFormatPropertiesANDROID>(pProperties->pNext);
if (ahb_format_props) {
ahb_ext_formats_map.insert(ahb_format_props->externalFormat,
static_cast<VkFormatFeatureFlags2KHR>(ahb_format_props->formatFeatures));
}
}
}
#else
template <typename CreateInfo>
VkFormatFeatureFlags2KHR ValidationStateTracker::GetExternalFormatFeaturesANDROID(const CreateInfo *create_info) const {
return 0;
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
VkFormatFeatureFlags2KHR GetImageFormatFeatures(VkPhysicalDevice physical_device, bool has_format_feature2, bool has_drm_modifiers,
VkDevice device, VkImage image, VkFormat format, VkImageTiling tiling) {
VkFormatFeatureFlags2KHR format_features = 0;
// Add feature support according to Image Format Features (vkspec.html#resources-image-format-features)
// if format is AHB external format then the features are already set
if (has_format_feature2) {
auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(has_drm_modifiers ? &fmt_drm_props : nullptr);
auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
VkImageDrmFormatModifierPropertiesEXT drm_format_props = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
// Find the image modifier
DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_props);
std::vector<VkDrmFormatModifierProperties2EXT> drm_mod_props;
drm_mod_props.resize(fmt_drm_props.drmFormatModifierCount);
fmt_drm_props.pDrmFormatModifierProperties = &drm_mod_props[0];
// Second query to have all the modifiers filled
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
// Look for the image modifier in the list
for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
if (fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_props.drmFormatModifier) {
format_features = fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
break;
}
}
} else {
format_features =
(tiling == VK_IMAGE_TILING_LINEAR) ? fmt_props_3.linearTilingFeatures : fmt_props_3.optimalTilingFeatures;
}
} else if (tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT) {
VkImageDrmFormatModifierPropertiesEXT drm_format_properties = LvlInitStruct<VkImageDrmFormatModifierPropertiesEXT>();
DispatchGetImageDrmFormatModifierPropertiesEXT(device, image, &drm_format_properties);
VkFormatProperties2 format_properties_2 = LvlInitStruct<VkFormatProperties2>();
VkDrmFormatModifierPropertiesListEXT drm_properties_list = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
format_properties_2.pNext = (void *)&drm_properties_list;
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
drm_properties.resize(drm_properties_list.drmFormatModifierCount);
drm_properties_list.pDrmFormatModifierProperties = &drm_properties[0];
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &format_properties_2);
for (uint32_t i = 0; i < drm_properties_list.drmFormatModifierCount; i++) {
if (drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifier == drm_format_properties.drmFormatModifier) {
format_features = drm_properties_list.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
break;
}
}
} else {
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
format_features =
(tiling == VK_IMAGE_TILING_LINEAR) ? format_properties.linearTilingFeatures : format_properties.optimalTilingFeatures;
}
return format_features;
}
std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
VkFormatFeatureFlags2KHR features) {
std::shared_ptr<IMAGE_STATE> state;
if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) {
if (pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) {
state = std::make_shared<IMAGE_STATE_SPARSE<true>>(this, img, pCreateInfo, features);
} else {
state = std::make_shared<IMAGE_STATE_SPARSE<false>>(this, img, pCreateInfo, features);
}
} else if (pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT) {
uint32_t plane_count = FormatPlaneCount(pCreateInfo->format);
switch (plane_count) {
case 3:
state = std::make_shared<IMAGE_STATE_MULTIPLANAR<3>>(this, img, pCreateInfo, features);
break;
case 2:
state = std::make_shared<IMAGE_STATE_MULTIPLANAR<2>>(this, img, pCreateInfo, features);
break;
case 1:
state = std::make_shared<IMAGE_STATE_MULTIPLANAR<1>>(this, img, pCreateInfo, features);
break;
default:
// Not supported
assert(false);
}
} else {
state = std::make_shared<IMAGE_STATE_LINEAR>(this, img, pCreateInfo, features);
}
return state;
}
std::shared_ptr<IMAGE_STATE> ValidationStateTracker::CreateImageState(VkImage img, const VkImageCreateInfo *pCreateInfo,
VkSwapchainKHR swapchain, uint32_t swapchain_index,
VkFormatFeatureFlags2KHR features) {
return std::make_shared<IMAGE_STATE_NO_BINDING>(this, img, pCreateInfo, swapchain, swapchain_index, features);
}
void ValidationStateTracker::PostCallRecordCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImage *pImage, VkResult result) {
if (VK_SUCCESS != result) return;
VkFormatFeatureFlags2KHR format_features = 0;
if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
format_features = GetExternalFormatFeaturesANDROID(pCreateInfo);
}
if (format_features == 0) {
format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device, *pImage,
pCreateInfo->format, pCreateInfo->tiling);
}
Add(CreateImageState(*pImage, pCreateInfo, format_features));
}
void ValidationStateTracker::PreCallRecordDestroyImage(VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator) {
Destroy<IMAGE_STATE>(image);
}
void ValidationStateTracker::PreCallRecordCmdClearColorImage(VkCommandBuffer commandBuffer, VkImage image,
VkImageLayout imageLayout, const VkClearColorValue *pColor,
uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordTransferCmd(CMD_CLEARCOLORIMAGE, Get<IMAGE_STATE>(image));
}
}
void ValidationStateTracker::PreCallRecordCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, VkImage image,
VkImageLayout imageLayout,
const VkClearDepthStencilValue *pDepthStencil,
uint32_t rangeCount, const VkImageSubresourceRange *pRanges) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordTransferCmd(CMD_CLEARDEPTHSTENCILIMAGE, Get<IMAGE_STATE>(image));
}
}
void ValidationStateTracker::PreCallRecordCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
uint32_t regionCount, const VkImageCopy *pRegions) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
}
void ValidationStateTracker::PreCallRecordCmdCopyImage2KHR(VkCommandBuffer commandBuffer,
const VkCopyImageInfo2KHR *pCopyImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGE2KHR, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdCopyImage2(VkCommandBuffer commandBuffer, const VkCopyImageInfo2 *pCopyImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGE2, Get<IMAGE_STATE>(pCopyImageInfo->srcImage),
Get<IMAGE_STATE>(pCopyImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdResolveImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage,
VkImageLayout dstImageLayout, uint32_t regionCount,
const VkImageResolve *pRegions) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_RESOLVEIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
}
void ValidationStateTracker::PreCallRecordCmdResolveImage2KHR(VkCommandBuffer commandBuffer,
const VkResolveImageInfo2KHR *pResolveImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_RESOLVEIMAGE2KHR, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdResolveImage2(VkCommandBuffer commandBuffer,
const VkResolveImageInfo2 *pResolveImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_RESOLVEIMAGE2, Get<IMAGE_STATE>(pResolveImageInfo->srcImage),
Get<IMAGE_STATE>(pResolveImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkImage dstImage, VkImageLayout dstImageLayout,
uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_BLITIMAGE, Get<IMAGE_STATE>(srcImage), Get<IMAGE_STATE>(dstImage));
}
void ValidationStateTracker::PreCallRecordCmdBlitImage2KHR(VkCommandBuffer commandBuffer,
const VkBlitImageInfo2KHR *pBlitImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_BLITIMAGE2KHR, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdBlitImage2(VkCommandBuffer commandBuffer, const VkBlitImageInfo2 *pBlitImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_BLITIMAGE2, Get<IMAGE_STATE>(pBlitImageInfo->srcImage),
Get<IMAGE_STATE>(pBlitImageInfo->dstImage));
}
void ValidationStateTracker::PostCallRecordCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer,
VkResult result) {
if (result != VK_SUCCESS) return;
std::shared_ptr<BUFFER_STATE> buffer_state;
if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) {
if (pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) {
buffer_state = std::make_shared<BUFFER_STATE_SPARSE<true>>(this, *pBuffer, pCreateInfo);
} else {
buffer_state = std::make_shared<BUFFER_STATE_SPARSE<false>>(this, *pBuffer, pCreateInfo);
}
} else {
buffer_state = std::make_shared<BUFFER_STATE_LINEAR>(this, *pBuffer, pCreateInfo);
}
if (pCreateInfo) {
const auto *opaque_capture_address = LvlFindInChain<VkBufferOpaqueCaptureAddressCreateInfo>(pCreateInfo->pNext);
if (opaque_capture_address && (opaque_capture_address->opaqueCaptureAddress != 0)) {
WriteLockGuard guard(buffer_address_lock_);
// address is used for GPU-AV and ray tracing buffer validation
buffer_state->deviceAddress = opaque_capture_address->opaqueCaptureAddress;
const auto address_range = buffer_state->DeviceAddressRange();
buffer_address_map_.split_and_merge_insert(
{address_range, {buffer_state}}, [](auto ¤t_buffer_list, const auto &new_buffer) {
assert(!current_buffer_list.empty());
const auto buffer_found_it = std::find(current_buffer_list.begin(), current_buffer_list.end(), new_buffer[0]);
if (buffer_found_it == current_buffer_list.end()) {
current_buffer_list.emplace_back(new_buffer[0]);
}
});
}
const VkBufferUsageFlags descriptor_buffer_usages =
VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT |
VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT;
if ((pCreateInfo->usage & descriptor_buffer_usages) != 0) {
descriptorBufferAddressSpaceSize += pCreateInfo->size;
if ((pCreateInfo->usage & VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT) != 0)
resourceDescriptorBufferAddressSpaceSize += pCreateInfo->size;
if ((pCreateInfo->usage & VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT) != 0)
samplerDescriptorBufferAddressSpaceSize += pCreateInfo->size;
}
}
Add(std::move(buffer_state));
}
void ValidationStateTracker::PostCallRecordCreateBufferView(VkDevice device, const VkBufferViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkBufferView *pView,
VkResult result) {
if (result != VK_SUCCESS) return;
auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
VkFormatFeatureFlags2KHR buffer_features;
if (has_format_feature2) {
auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>();
auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
DispatchGetPhysicalDeviceFormatProperties2(physical_device, pCreateInfo->format, &fmt_props_2);
buffer_features = fmt_props_3.bufferFeatures;
} else {
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, pCreateInfo->format, &format_properties);
buffer_features = format_properties.bufferFeatures;
}
Add(std::make_shared<BUFFER_VIEW_STATE>(buffer_state, *pView, pCreateInfo, buffer_features));
}
void ValidationStateTracker::PostCallRecordCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkImageView *pView,
VkResult result) {
if (result != VK_SUCCESS) return;
auto image_state = Get<IMAGE_STATE>(pCreateInfo->image);
VkFormatFeatureFlags2KHR format_features = 0;
if (image_state->HasAHBFormat() == true) {
// The ImageView uses same Image's format feature since they share same AHB
format_features = image_state->format_features;
} else {
format_features = GetImageFormatFeatures(physical_device, has_format_feature2,
IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
image_state->image(), pCreateInfo->format, image_state->createInfo.tiling);
}
// filter_cubic_props is used in CmdDraw validation. But it takes a lot of performance if it does in CmdDraw.
auto filter_cubic_props = LvlInitStruct<VkFilterCubicImageViewImageFormatPropertiesEXT>();
if (IsExtEnabled(device_extensions.vk_ext_filter_cubic)) {
auto imageview_format_info = LvlInitStruct<VkPhysicalDeviceImageViewImageFormatInfoEXT>();
imageview_format_info.imageViewType = pCreateInfo->viewType;
auto image_format_info = LvlInitStruct<VkPhysicalDeviceImageFormatInfo2>(&imageview_format_info);
image_format_info.type = image_state->createInfo.imageType;
image_format_info.format = image_state->createInfo.format;
image_format_info.tiling = image_state->createInfo.tiling;
auto usage_create_info = LvlFindInChain<VkImageViewUsageCreateInfo>(pCreateInfo->pNext);
image_format_info.usage = usage_create_info ? usage_create_info->usage : image_state->createInfo.usage;
image_format_info.flags = image_state->createInfo.flags;
auto image_format_properties = LvlInitStruct<VkImageFormatProperties2>(&filter_cubic_props);
DispatchGetPhysicalDeviceImageFormatProperties2(physical_device, &image_format_info, &image_format_properties);
}
Add(std::make_shared<IMAGE_VIEW_STATE>(image_state, *pView, pCreateInfo, format_features, filter_cubic_props));
}
void ValidationStateTracker::PreCallRecordCmdCopyBuffer(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkBuffer dstBuffer,
uint32_t regionCount, const VkBufferCopy *pRegions) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFER, Get<BUFFER_STATE>(srcBuffer), Get<BUFFER_STATE>(dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer,
const VkCopyBufferInfo2KHR *pCopyBufferInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFER2KHR, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyBuffer2(VkCommandBuffer commandBuffer, const VkCopyBufferInfo2 *pCopyBufferInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFER2, Get<BUFFER_STATE>(pCopyBufferInfo->srcBuffer),
Get<BUFFER_STATE>(pCopyBufferInfo->dstBuffer));
}
void ValidationStateTracker::PreCallRecordDestroyImageView(VkDevice device, VkImageView imageView,
const VkAllocationCallbacks *pAllocator) {
Destroy<IMAGE_VIEW_STATE>(imageView);
}
void ValidationStateTracker::PreCallRecordDestroyBuffer(VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
if (buffer_state) {
WriteLockGuard guard(buffer_address_lock_);
const VkBufferUsageFlags descriptor_buffer_usages =
VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT;
if ((buffer_state->createInfo.usage & descriptor_buffer_usages) != 0) {
descriptorBufferAddressSpaceSize -= buffer_state->createInfo.size;
if (buffer_state->createInfo.usage & VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT)
resourceDescriptorBufferAddressSpaceSize -= buffer_state->createInfo.size;
if (buffer_state->createInfo.usage & VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT)
samplerDescriptorBufferAddressSpaceSize -= buffer_state->createInfo.size;
}
if (buffer_state->deviceAddress != 0) {
const auto address_range = buffer_state->DeviceAddressRange();
buffer_address_map_.erase_range_or_touch(address_range, [&buffer_state](auto &buffers) {
assert(!buffers.empty());
const auto buffer_found_it = std::find(buffers.begin(), buffers.end(), buffer_state);
assert(buffer_found_it != buffers.end());
// If buffer list only has one element, remove range map entry.
// Else, remove target buffer from buffer list.
if (buffer_found_it != buffers.end()) {
if (buffers.size() == 1) {
return true;
} else {
assert(!buffers.empty());
size_t i = std::distance(buffers.begin(), buffer_found_it);
std::swap(buffers[i], buffers[buffers.size() - 1]);
buffers.resize(buffers.size() - 1);
return false;
}
}
return false;
});
}
}
Destroy<BUFFER_STATE>(buffer);
}
void ValidationStateTracker::PreCallRecordDestroyBufferView(VkDevice device, VkBufferView bufferView,
const VkAllocationCallbacks *pAllocator) {
Destroy<BUFFER_VIEW_STATE>(bufferView);
}
void ValidationStateTracker::PreCallRecordCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
VkDeviceSize size, uint32_t data) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_FILLBUFFER, Get<BUFFER_STATE>(dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage,
VkImageLayout srcImageLayout, VkBuffer dstBuffer,
uint32_t regionCount, const VkBufferImageCopy *pRegions) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGETOBUFFER, Get<IMAGE_STATE>(srcImage), Get<BUFFER_STATE>(dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer,
const VkCopyImageToBufferInfo2KHR *pCopyImageToBufferInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2KHR, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer,
const VkCopyImageToBufferInfo2 *pCopyImageToBufferInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYIMAGETOBUFFER2, Get<IMAGE_STATE>(pCopyImageToBufferInfo->srcImage),
Get<BUFFER_STATE>(pCopyImageToBufferInfo->dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage,
VkImageLayout dstImageLayout, uint32_t regionCount,
const VkBufferImageCopy *pRegions) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE, Get<BUFFER_STATE>(srcBuffer), Get<IMAGE_STATE>(dstImage));
}
void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer,
const VkCopyBufferToImageInfo2KHR *pCopyBufferToImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2KHR, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
}
void ValidationStateTracker::PreCallRecordCmdCopyBufferToImage2(VkCommandBuffer commandBuffer,
const VkCopyBufferToImageInfo2 *pCopyBufferToImageInfo) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_COPYBUFFERTOIMAGE2, Get<BUFFER_STATE>(pCopyBufferToImageInfo->srcBuffer),
Get<IMAGE_STATE>(pCopyBufferToImageInfo->dstImage));
}
// Gets union of all features defined by Potential Format Features
// except, does not handle the external format case for AHB as that only can be used for sampled images
VkFormatFeatureFlags2KHR ValidationStateTracker::GetPotentialFormatFeatures(VkFormat format) const {
VkFormatFeatureFlags2KHR format_features = 0;
if (format != VK_FORMAT_UNDEFINED) {
if (has_format_feature2) {
auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesList2EXT>();
auto fmt_props_3 = LvlInitStruct<VkFormatProperties3KHR>(
IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier) ? &fmt_drm_props : nullptr);
auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_props_3);
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
format_features |= fmt_props_3.linearTilingFeatures;
format_features |= fmt_props_3.optimalTilingFeatures;
if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
std::vector<VkDrmFormatModifierProperties2EXT> drm_properties;
drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
}
}
} else {
VkFormatProperties format_properties;
DispatchGetPhysicalDeviceFormatProperties(physical_device, format, &format_properties);
format_features |= format_properties.linearTilingFeatures;
format_features |= format_properties.optimalTilingFeatures;
if (IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier)) {
auto fmt_drm_props = LvlInitStruct<VkDrmFormatModifierPropertiesListEXT>();
auto fmt_props_2 = LvlInitStruct<VkFormatProperties2>(&fmt_drm_props);
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
std::vector<VkDrmFormatModifierPropertiesEXT> drm_properties;
drm_properties.resize(fmt_drm_props.drmFormatModifierCount);
fmt_drm_props.pDrmFormatModifierProperties = drm_properties.data();
DispatchGetPhysicalDeviceFormatProperties2(physical_device, format, &fmt_props_2);
for (uint32_t i = 0; i < fmt_drm_props.drmFormatModifierCount; i++) {
format_features |= fmt_drm_props.pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
}
}
}
}
return format_features;
}
void ValidationStateTracker::PostCallRecordCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDevice *pDevice,
VkResult result) {
if (VK_SUCCESS != result) return;
// The current object represents the VkInstance, look up / create the object for the device.
ValidationObject *device_object = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
ValidationObject *validation_data = GetValidationObject(device_object->object_dispatch, this->container_type);
ValidationStateTracker *device_state = static_cast<ValidationStateTracker *>(validation_data);
device_state->instance_state = this;
// Save local link to this device's physical device state
device_state->physical_device_state = Get<PHYSICAL_DEVICE_STATE>(gpu).get();
// finish setup in the object representing the device
device_state->CreateDevice(pCreateInfo);
}
std::shared_ptr<QUEUE_STATE> ValidationStateTracker::CreateQueue(VkQueue q, uint32_t index, VkDeviceQueueCreateFlags flags, const VkQueueFamilyProperties &queueFamilyProperties) {
return std::make_shared<QUEUE_STATE>(*this, q, index, flags, queueFamilyProperties);
}
void ValidationStateTracker::CreateDevice(const VkDeviceCreateInfo *pCreateInfo) {
const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
if (nullptr == enabled_features_found) {
const auto *features2 = LvlFindInChain<VkPhysicalDeviceFeatures2>(pCreateInfo->pNext);
if (features2) {
enabled_features_found = &(features2->features);
}
}
if (nullptr == enabled_features_found) {
enabled_features.core = {};
} else {
enabled_features.core = *enabled_features_found;
}
const auto *vulkan_13_features = LvlFindInChain<VkPhysicalDeviceVulkan13Features>(pCreateInfo->pNext);
if (vulkan_13_features) {
enabled_features.core13 = *vulkan_13_features;
} else {
enabled_features.core13 = {};
const auto *image_robustness_features = LvlFindInChain<VkPhysicalDeviceImageRobustnessFeatures>(pCreateInfo->pNext);
if (image_robustness_features) {
enabled_features.core13.robustImageAccess = image_robustness_features->robustImageAccess;
}
const auto *inline_uniform_block_features = LvlFindInChain<VkPhysicalDeviceInlineUniformBlockFeatures>(pCreateInfo->pNext);
if (inline_uniform_block_features) {
enabled_features.core13.inlineUniformBlock = inline_uniform_block_features->inlineUniformBlock;
enabled_features.core13.descriptorBindingInlineUniformBlockUpdateAfterBind =
inline_uniform_block_features->descriptorBindingInlineUniformBlockUpdateAfterBind;
}
const auto *pipeline_creation_cache_control_features =
LvlFindInChain<VkPhysicalDevicePipelineCreationCacheControlFeatures>(pCreateInfo->pNext);
if (pipeline_creation_cache_control_features) {
enabled_features.core13.pipelineCreationCacheControl =
pipeline_creation_cache_control_features->pipelineCreationCacheControl;
}
const auto *private_data_features = LvlFindInChain<VkPhysicalDevicePrivateDataFeatures>(pCreateInfo->pNext);
if (private_data_features) {
enabled_features.core13.privateData = private_data_features->privateData;
}
const auto *demote_to_helper_invocation_features =
LvlFindInChain<VkPhysicalDeviceShaderDemoteToHelperInvocationFeatures>(pCreateInfo->pNext);
if (demote_to_helper_invocation_features) {
enabled_features.core13.shaderDemoteToHelperInvocation =
demote_to_helper_invocation_features->shaderDemoteToHelperInvocation;
}
const auto *terminate_invocation_features =
LvlFindInChain<VkPhysicalDeviceShaderTerminateInvocationFeatures>(pCreateInfo->pNext);
if (terminate_invocation_features) {
enabled_features.core13.shaderTerminateInvocation = terminate_invocation_features->shaderTerminateInvocation;
}
const auto *subgroup_size_control_features =
LvlFindInChain<VkPhysicalDeviceSubgroupSizeControlFeatures>(pCreateInfo->pNext);
if (subgroup_size_control_features) {
enabled_features.core13.subgroupSizeControl = subgroup_size_control_features->subgroupSizeControl;
enabled_features.core13.computeFullSubgroups = subgroup_size_control_features->computeFullSubgroups;
}
const auto *synchronization2_features = LvlFindInChain<VkPhysicalDeviceSynchronization2Features>(pCreateInfo->pNext);
if (synchronization2_features) {
enabled_features.core13.synchronization2 = synchronization2_features->synchronization2;
}
const auto *texture_compression_astchdr_features =
LvlFindInChain<VkPhysicalDeviceTextureCompressionASTCHDRFeatures>(pCreateInfo->pNext);
if (texture_compression_astchdr_features) {
enabled_features.core13.textureCompressionASTC_HDR = texture_compression_astchdr_features->textureCompressionASTC_HDR;
}
const auto *initialize_workgroup_memory_features =
LvlFindInChain<VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeatures>(pCreateInfo->pNext);
if (initialize_workgroup_memory_features) {
enabled_features.core13.shaderZeroInitializeWorkgroupMemory =
initialize_workgroup_memory_features->shaderZeroInitializeWorkgroupMemory;
}
const auto *dynamic_rendering_features = LvlFindInChain<VkPhysicalDeviceDynamicRenderingFeatures>(pCreateInfo->pNext);
if (dynamic_rendering_features) {
enabled_features.core13.dynamicRendering = dynamic_rendering_features->dynamicRendering;
}
const auto *shader_integer_dot_product_features =
LvlFindInChain<VkPhysicalDeviceShaderIntegerDotProductFeaturesKHR>(pCreateInfo->pNext);
if (shader_integer_dot_product_features) {
enabled_features.core13.shaderIntegerDotProduct = shader_integer_dot_product_features->shaderIntegerDotProduct;
}
const auto *maintenance4_features = LvlFindInChain<VkPhysicalDeviceMaintenance4FeaturesKHR>(pCreateInfo->pNext);
if (maintenance4_features) {
enabled_features.core13.maintenance4 = maintenance4_features->maintenance4;
}
}
const auto *vulkan_12_features = LvlFindInChain<VkPhysicalDeviceVulkan12Features>(pCreateInfo->pNext);
if (vulkan_12_features) {
enabled_features.core12 = *vulkan_12_features;
} else {
// Set Extension Feature Aliases to false as there is no struct to check
enabled_features.core12.drawIndirectCount = VK_FALSE;
enabled_features.core12.samplerMirrorClampToEdge = VK_FALSE;
enabled_features.core12.descriptorIndexing = VK_FALSE;
enabled_features.core12.samplerFilterMinmax = VK_FALSE;
enabled_features.core12.shaderOutputLayer = VK_FALSE;
enabled_features.core12.shaderOutputViewportIndex = VK_FALSE;
enabled_features.core12.subgroupBroadcastDynamicId = VK_FALSE;
// These structs are only allowed in pNext chain if there is no VkPhysicalDeviceVulkan12Features
const auto *eight_bit_storage_features = LvlFindInChain<VkPhysicalDevice8BitStorageFeatures>(pCreateInfo->pNext);
if (eight_bit_storage_features) {
enabled_features.core12.storageBuffer8BitAccess = eight_bit_storage_features->storageBuffer8BitAccess;
enabled_features.core12.uniformAndStorageBuffer8BitAccess =
eight_bit_storage_features->uniformAndStorageBuffer8BitAccess;
enabled_features.core12.storagePushConstant8 = eight_bit_storage_features->storagePushConstant8;
}
const auto *float16_int8_features = LvlFindInChain<VkPhysicalDeviceShaderFloat16Int8Features>(pCreateInfo->pNext);
if (float16_int8_features) {
enabled_features.core12.shaderFloat16 = float16_int8_features->shaderFloat16;
enabled_features.core12.shaderInt8 = float16_int8_features->shaderInt8;
}
const auto *descriptor_indexing_features = LvlFindInChain<VkPhysicalDeviceDescriptorIndexingFeatures>(pCreateInfo->pNext);
if (descriptor_indexing_features) {
enabled_features.core12.shaderInputAttachmentArrayDynamicIndexing =
descriptor_indexing_features->shaderInputAttachmentArrayDynamicIndexing;
enabled_features.core12.shaderUniformTexelBufferArrayDynamicIndexing =
descriptor_indexing_features->shaderUniformTexelBufferArrayDynamicIndexing;
enabled_features.core12.shaderStorageTexelBufferArrayDynamicIndexing =
descriptor_indexing_features->shaderStorageTexelBufferArrayDynamicIndexing;
enabled_features.core12.shaderUniformBufferArrayNonUniformIndexing =
descriptor_indexing_features->shaderUniformBufferArrayNonUniformIndexing;
enabled_features.core12.shaderSampledImageArrayNonUniformIndexing =
descriptor_indexing_features->shaderSampledImageArrayNonUniformIndexing;
enabled_features.core12.shaderStorageBufferArrayNonUniformIndexing =
descriptor_indexing_features->shaderStorageBufferArrayNonUniformIndexing;
enabled_features.core12.shaderStorageImageArrayNonUniformIndexing =
descriptor_indexing_features->shaderStorageImageArrayNonUniformIndexing;
enabled_features.core12.shaderInputAttachmentArrayNonUniformIndexing =
descriptor_indexing_features->shaderInputAttachmentArrayNonUniformIndexing;
enabled_features.core12.shaderUniformTexelBufferArrayNonUniformIndexing =
descriptor_indexing_features->shaderUniformTexelBufferArrayNonUniformIndexing;
enabled_features.core12.shaderStorageTexelBufferArrayNonUniformIndexing =
descriptor_indexing_features->shaderStorageTexelBufferArrayNonUniformIndexing;
enabled_features.core12.descriptorBindingUniformBufferUpdateAfterBind =
descriptor_indexing_features->descriptorBindingUniformBufferUpdateAfterBind;
enabled_features.core12.descriptorBindingSampledImageUpdateAfterBind =
descriptor_indexing_features->descriptorBindingSampledImageUpdateAfterBind;
enabled_features.core12.descriptorBindingStorageImageUpdateAfterBind =
descriptor_indexing_features->descriptorBindingStorageImageUpdateAfterBind;
enabled_features.core12.descriptorBindingStorageBufferUpdateAfterBind =
descriptor_indexing_features->descriptorBindingStorageBufferUpdateAfterBind;
enabled_features.core12.descriptorBindingUniformTexelBufferUpdateAfterBind =
descriptor_indexing_features->descriptorBindingUniformTexelBufferUpdateAfterBind;
enabled_features.core12.descriptorBindingStorageTexelBufferUpdateAfterBind =
descriptor_indexing_features->descriptorBindingStorageTexelBufferUpdateAfterBind;
enabled_features.core12.descriptorBindingUpdateUnusedWhilePending =
descriptor_indexing_features->descriptorBindingUpdateUnusedWhilePending;
enabled_features.core12.descriptorBindingPartiallyBound = descriptor_indexing_features->descriptorBindingPartiallyBound;
enabled_features.core12.descriptorBindingVariableDescriptorCount =
descriptor_indexing_features->descriptorBindingVariableDescriptorCount;
enabled_features.core12.runtimeDescriptorArray = descriptor_indexing_features->runtimeDescriptorArray;
}
const auto *scalar_block_layout_features = LvlFindInChain<VkPhysicalDeviceScalarBlockLayoutFeatures>(pCreateInfo->pNext);
if (scalar_block_layout_features) {
enabled_features.core12.scalarBlockLayout = scalar_block_layout_features->scalarBlockLayout;
}
const auto *imageless_framebuffer_features =
LvlFindInChain<VkPhysicalDeviceImagelessFramebufferFeatures>(pCreateInfo->pNext);
if (imageless_framebuffer_features) {
enabled_features.core12.imagelessFramebuffer = imageless_framebuffer_features->imagelessFramebuffer;
}
const auto *uniform_buffer_standard_layout_features =
LvlFindInChain<VkPhysicalDeviceUniformBufferStandardLayoutFeatures>(pCreateInfo->pNext);
if (uniform_buffer_standard_layout_features) {
enabled_features.core12.uniformBufferStandardLayout =
uniform_buffer_standard_layout_features->uniformBufferStandardLayout;
}
const auto *subgroup_extended_types_features =
LvlFindInChain<VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures>(pCreateInfo->pNext);
if (subgroup_extended_types_features) {
enabled_features.core12.shaderSubgroupExtendedTypes = subgroup_extended_types_features->shaderSubgroupExtendedTypes;
}
const auto *separate_depth_stencil_layouts_features =
LvlFindInChain<VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures>(pCreateInfo->pNext);
if (separate_depth_stencil_layouts_features) {
enabled_features.core12.separateDepthStencilLayouts =
separate_depth_stencil_layouts_features->separateDepthStencilLayouts;
}
const auto *host_query_reset_features = LvlFindInChain<VkPhysicalDeviceHostQueryResetFeatures>(pCreateInfo->pNext);
if (host_query_reset_features) {
enabled_features.core12.hostQueryReset = host_query_reset_features->hostQueryReset;
}
const auto *timeline_semaphore_features = LvlFindInChain<VkPhysicalDeviceTimelineSemaphoreFeatures>(pCreateInfo->pNext);
if (timeline_semaphore_features) {
enabled_features.core12.timelineSemaphore = timeline_semaphore_features->timelineSemaphore;
}
const auto *buffer_device_address = LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeatures>(pCreateInfo->pNext);
if (buffer_device_address) {
enabled_features.core12.bufferDeviceAddress = buffer_device_address->bufferDeviceAddress;
enabled_features.core12.bufferDeviceAddressCaptureReplay = buffer_device_address->bufferDeviceAddressCaptureReplay;
enabled_features.core12.bufferDeviceAddressMultiDevice = buffer_device_address->bufferDeviceAddressMultiDevice;
}
const auto *atomic_int64_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicInt64Features>(pCreateInfo->pNext);
if (atomic_int64_features) {
enabled_features.core12.shaderBufferInt64Atomics = atomic_int64_features->shaderBufferInt64Atomics;
enabled_features.core12.shaderSharedInt64Atomics = atomic_int64_features->shaderSharedInt64Atomics;
}
const auto *memory_model_features = LvlFindInChain<VkPhysicalDeviceVulkanMemoryModelFeatures>(pCreateInfo->pNext);
if (memory_model_features) {
enabled_features.core12.vulkanMemoryModel = memory_model_features->vulkanMemoryModel;
enabled_features.core12.vulkanMemoryModelDeviceScope = memory_model_features->vulkanMemoryModelDeviceScope;
enabled_features.core12.vulkanMemoryModelAvailabilityVisibilityChains =
memory_model_features->vulkanMemoryModelAvailabilityVisibilityChains;
}
}
const auto *vulkan_11_features = LvlFindInChain<VkPhysicalDeviceVulkan11Features>(pCreateInfo->pNext);
if (vulkan_11_features) {
enabled_features.core11 = *vulkan_11_features;
} else {
// These structs are only allowed in pNext chain if there is no vkPhysicalDeviceVulkan11Features
const auto *sixteen_bit_storage_features = LvlFindInChain<VkPhysicalDevice16BitStorageFeatures>(pCreateInfo->pNext);
if (sixteen_bit_storage_features) {
enabled_features.core11.storageBuffer16BitAccess = sixteen_bit_storage_features->storageBuffer16BitAccess;
enabled_features.core11.uniformAndStorageBuffer16BitAccess =
sixteen_bit_storage_features->uniformAndStorageBuffer16BitAccess;
enabled_features.core11.storagePushConstant16 = sixteen_bit_storage_features->storagePushConstant16;
enabled_features.core11.storageInputOutput16 = sixteen_bit_storage_features->storageInputOutput16;
}
const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
if (multiview_features) {
enabled_features.core11.multiview = multiview_features->multiview;
enabled_features.core11.multiviewGeometryShader = multiview_features->multiviewGeometryShader;
enabled_features.core11.multiviewTessellationShader = multiview_features->multiviewTessellationShader;
}
const auto *variable_pointers_features = LvlFindInChain<VkPhysicalDeviceVariablePointersFeatures>(pCreateInfo->pNext);
if (variable_pointers_features) {
enabled_features.core11.variablePointersStorageBuffer = variable_pointers_features->variablePointersStorageBuffer;
enabled_features.core11.variablePointers = variable_pointers_features->variablePointers;
}
const auto *protected_memory_features = LvlFindInChain<VkPhysicalDeviceProtectedMemoryFeatures>(pCreateInfo->pNext);
if (protected_memory_features) {
enabled_features.core11.protectedMemory = protected_memory_features->protectedMemory;
}
const auto *ycbcr_conversion_features = LvlFindInChain<VkPhysicalDeviceSamplerYcbcrConversionFeatures>(pCreateInfo->pNext);
if (ycbcr_conversion_features) {
enabled_features.core11.samplerYcbcrConversion = ycbcr_conversion_features->samplerYcbcrConversion;
}
const auto *shader_draw_parameters_features =
LvlFindInChain<VkPhysicalDeviceShaderDrawParametersFeatures>(pCreateInfo->pNext);
if (shader_draw_parameters_features) {
enabled_features.core11.shaderDrawParameters = shader_draw_parameters_features->shaderDrawParameters;
}
}
const auto *device_group_ci = LvlFindInChain<VkDeviceGroupDeviceCreateInfo>(pCreateInfo->pNext);
if (device_group_ci) {
physical_device_count = device_group_ci->physicalDeviceCount;
if (physical_device_count == 0) {
physical_device_count =
1; // see https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkDeviceGroupDeviceCreateInfo.html
}
device_group_create_info = *device_group_ci;
} else {
device_group_create_info = LvlInitStruct<VkDeviceGroupDeviceCreateInfo>();
device_group_create_info.physicalDeviceCount = 1; // see previous VkDeviceGroupDeviceCreateInfo link
device_group_create_info.pPhysicalDevices = &physical_device;
physical_device_count = 1;
}
// Features from other extensions passesd in create info
{
const auto *exclusive_scissor_features = LvlFindInChain<VkPhysicalDeviceExclusiveScissorFeaturesNV>(pCreateInfo->pNext);
if (exclusive_scissor_features) {
enabled_features.exclusive_scissor_features = *exclusive_scissor_features;
}
const auto *shading_rate_image_features = LvlFindInChain<VkPhysicalDeviceShadingRateImageFeaturesNV>(pCreateInfo->pNext);
if (shading_rate_image_features) {
enabled_features.shading_rate_image_features = *shading_rate_image_features;
}
const auto *mesh_shader_features_NV = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesNV>(pCreateInfo->pNext);
if (mesh_shader_features_NV) {
enabled_features.mesh_shader_features.sType = mesh_shader_features_NV->sType;
enabled_features.mesh_shader_features.pNext = mesh_shader_features_NV->pNext;
enabled_features.mesh_shader_features.meshShader = mesh_shader_features_NV->meshShader;
enabled_features.mesh_shader_features.taskShader = mesh_shader_features_NV->taskShader;
}
const auto *mesh_shader_features = LvlFindInChain<VkPhysicalDeviceMeshShaderFeaturesEXT>(pCreateInfo->pNext);
if (mesh_shader_features) {
enabled_features.mesh_shader_features = *mesh_shader_features;
}
const auto *descriptor_buffer_features = LvlFindInChain<VkPhysicalDeviceDescriptorBufferFeaturesEXT>(pCreateInfo->pNext);
if (descriptor_buffer_features) {
enabled_features.descriptor_buffer_features = *descriptor_buffer_features;
}
const auto *transform_feedback_features = LvlFindInChain<VkPhysicalDeviceTransformFeedbackFeaturesEXT>(pCreateInfo->pNext);
if (transform_feedback_features) {
enabled_features.transform_feedback_features = *transform_feedback_features;
}
const auto *vtx_attrib_div_features = LvlFindInChain<VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT>(pCreateInfo->pNext);
if (vtx_attrib_div_features) {
enabled_features.vtx_attrib_divisor_features = *vtx_attrib_div_features;
}
const auto *buffer_device_address_ext_features =
LvlFindInChain<VkPhysicalDeviceBufferDeviceAddressFeaturesEXT>(pCreateInfo->pNext);
if (buffer_device_address_ext_features) {
enabled_features.buffer_device_address_ext_features = *buffer_device_address_ext_features;
}
const auto *cooperative_matrix_features = LvlFindInChain<VkPhysicalDeviceCooperativeMatrixFeaturesNV>(pCreateInfo->pNext);
if (cooperative_matrix_features) {
enabled_features.cooperative_matrix_features = *cooperative_matrix_features;
}
const auto *compute_shader_derivatives_features =
LvlFindInChain<VkPhysicalDeviceComputeShaderDerivativesFeaturesNV>(pCreateInfo->pNext);
if (compute_shader_derivatives_features) {
enabled_features.compute_shader_derivatives_features = *compute_shader_derivatives_features;
}
const auto *fragment_shader_barycentric_features =
LvlFindInChain<VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV>(pCreateInfo->pNext);
if (fragment_shader_barycentric_features) {
enabled_features.fragment_shader_barycentric_features = *fragment_shader_barycentric_features;
}
const auto *shader_image_footprint_features =
LvlFindInChain<VkPhysicalDeviceShaderImageFootprintFeaturesNV>(pCreateInfo->pNext);
if (shader_image_footprint_features) {
enabled_features.shader_image_footprint_features = *shader_image_footprint_features;
}
const auto *fragment_shader_interlock_features =
LvlFindInChain<VkPhysicalDeviceFragmentShaderInterlockFeaturesEXT>(pCreateInfo->pNext);
if (fragment_shader_interlock_features) {
enabled_features.fragment_shader_interlock_features = *fragment_shader_interlock_features;
}
const auto *texel_buffer_alignment_features =
LvlFindInChain<VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT>(pCreateInfo->pNext);
if (texel_buffer_alignment_features) {
enabled_features.texel_buffer_alignment_features = *texel_buffer_alignment_features;
}
const auto *pipeline_exe_props_features =
LvlFindInChain<VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR>(pCreateInfo->pNext);
if (pipeline_exe_props_features) {
enabled_features.pipeline_exe_props_features = *pipeline_exe_props_features;
}
const auto *dedicated_allocation_image_aliasing_features =
LvlFindInChain<VkPhysicalDeviceDedicatedAllocationImageAliasingFeaturesNV>(pCreateInfo->pNext);
if (dedicated_allocation_image_aliasing_features) {
enabled_features.dedicated_allocation_image_aliasing_features = *dedicated_allocation_image_aliasing_features;
}
const auto *performance_query_features = LvlFindInChain<VkPhysicalDevicePerformanceQueryFeaturesKHR>(pCreateInfo->pNext);
if (performance_query_features) {
enabled_features.performance_query_features = *performance_query_features;
}
const auto *device_coherent_memory_features = LvlFindInChain<VkPhysicalDeviceCoherentMemoryFeaturesAMD>(pCreateInfo->pNext);
if (device_coherent_memory_features) {
enabled_features.device_coherent_memory_features = *device_coherent_memory_features;
}
const auto *ycbcr_image_array_features = LvlFindInChain<VkPhysicalDeviceYcbcrImageArraysFeaturesEXT>(pCreateInfo->pNext);
if (ycbcr_image_array_features) {
enabled_features.ycbcr_image_array_features = *ycbcr_image_array_features;
}
const auto *ray_query_features = LvlFindInChain<VkPhysicalDeviceRayQueryFeaturesKHR>(pCreateInfo->pNext);
if (ray_query_features) {
enabled_features.ray_query_features = *ray_query_features;
}
const auto *ray_tracing_pipeline_features =
LvlFindInChain<VkPhysicalDeviceRayTracingPipelineFeaturesKHR>(pCreateInfo->pNext);
if (ray_tracing_pipeline_features) {
enabled_features.ray_tracing_pipeline_features = *ray_tracing_pipeline_features;
}
const auto *ray_tracing_acceleration_structure_features =
LvlFindInChain<VkPhysicalDeviceAccelerationStructureFeaturesKHR>(pCreateInfo->pNext);
if (ray_tracing_acceleration_structure_features) {
enabled_features.ray_tracing_acceleration_structure_features = *ray_tracing_acceleration_structure_features;
}
const auto *robustness2_features = LvlFindInChain<VkPhysicalDeviceRobustness2FeaturesEXT>(pCreateInfo->pNext);
if (robustness2_features) {
enabled_features.robustness2_features = *robustness2_features;
}
const auto *fragment_density_map_features =
LvlFindInChain<VkPhysicalDeviceFragmentDensityMapFeaturesEXT>(pCreateInfo->pNext);
if (fragment_density_map_features) {
enabled_features.fragment_density_map_features = *fragment_density_map_features;
}
const auto *fragment_density_map_features2 =
LvlFindInChain<VkPhysicalDeviceFragmentDensityMap2FeaturesEXT>(pCreateInfo->pNext);
if (fragment_density_map_features2) {
enabled_features.fragment_density_map2_features = *fragment_density_map_features2;
}
const auto *fragment_density_map_offset_features =
LvlFindInChain<VkPhysicalDeviceFragmentDensityMapOffsetFeaturesQCOM>(pCreateInfo->pNext);
if (fragment_density_map_offset_features) {
enabled_features.fragment_density_map_offset_features = *fragment_density_map_offset_features;
}
const auto *astc_decode_features = LvlFindInChain<VkPhysicalDeviceASTCDecodeFeaturesEXT>(pCreateInfo->pNext);
if (astc_decode_features) {
enabled_features.astc_decode_features = *astc_decode_features;
}
const auto *custom_border_color_features = LvlFindInChain<VkPhysicalDeviceCustomBorderColorFeaturesEXT>(pCreateInfo->pNext);
if (custom_border_color_features) {
enabled_features.custom_border_color_features = *custom_border_color_features;
}
const auto *fragment_shading_rate_features =
LvlFindInChain<VkPhysicalDeviceFragmentShadingRateFeaturesKHR>(pCreateInfo->pNext);
if (fragment_shading_rate_features) {
enabled_features.fragment_shading_rate_features = *fragment_shading_rate_features;
}
const auto *fragment_shading_rate_enums_features =
LvlFindInChain<VkPhysicalDeviceFragmentShadingRateEnumsFeaturesNV>(pCreateInfo->pNext);
if (fragment_shading_rate_enums_features) {
enabled_features.fragment_shading_rate_enums_features = *fragment_shading_rate_enums_features;
}
const auto *extended_dynamic_state_features =
LvlFindInChain<VkPhysicalDeviceExtendedDynamicStateFeaturesEXT>(pCreateInfo->pNext);
if (extended_dynamic_state_features) {
enabled_features.extended_dynamic_state_features = *extended_dynamic_state_features;
}
const auto *extended_dynamic_state2_features =
LvlFindInChain<VkPhysicalDeviceExtendedDynamicState2FeaturesEXT>(pCreateInfo->pNext);
if (extended_dynamic_state2_features) {
enabled_features.extended_dynamic_state2_features = *extended_dynamic_state2_features;
}
const auto *extended_dynamic_state3_features =
LvlFindInChain<VkPhysicalDeviceExtendedDynamicState3FeaturesEXT>(pCreateInfo->pNext);
if (extended_dynamic_state3_features) {
enabled_features.extended_dynamic_state3_features = *extended_dynamic_state3_features;
}
const auto *depth_clip_enable_features = LvlFindInChain<VkPhysicalDeviceDepthClipEnableFeaturesEXT>(pCreateInfo->pNext);
if (depth_clip_enable_features) {
enabled_features.depth_clip_enable_features = *depth_clip_enable_features;
}
const auto *depth_clip_control_features = LvlFindInChain<VkPhysicalDeviceDepthClipControlFeaturesEXT>(pCreateInfo->pNext);
if (depth_clip_control_features) {
enabled_features.depth_clip_control_features = *depth_clip_control_features;
}
const auto *line_rasterization_features = LvlFindInChain<VkPhysicalDeviceLineRasterizationFeaturesEXT>(pCreateInfo->pNext);
if (line_rasterization_features) {
enabled_features.line_rasterization_features = *line_rasterization_features;
}
const auto *multiview_features = LvlFindInChain<VkPhysicalDeviceMultiviewFeatures>(pCreateInfo->pNext);
if (multiview_features) {
enabled_features.multiview_features = *multiview_features;
}
const auto *portability_features = LvlFindInChain<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(pCreateInfo->pNext);
if (portability_features) {
enabled_features.portability_subset_features = *portability_features;
}
const auto *shader_integer_functions2_features =
LvlFindInChain<VkPhysicalDeviceShaderIntegerFunctions2FeaturesINTEL>(pCreateInfo->pNext);
if (shader_integer_functions2_features) {
enabled_features.shader_integer_functions2_features = *shader_integer_functions2_features;
}
const auto *shader_sm_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderSMBuiltinsFeaturesNV>(pCreateInfo->pNext);
if (shader_sm_builtins_features) {
enabled_features.shader_sm_builtins_features = *shader_sm_builtins_features;
}
const auto *shader_atomic_float_features = LvlFindInChain<VkPhysicalDeviceShaderAtomicFloatFeaturesEXT>(pCreateInfo->pNext);
if (shader_atomic_float_features) {
enabled_features.shader_atomic_float_features = *shader_atomic_float_features;
}
const auto *shader_image_atomic_int64_features =
LvlFindInChain<VkPhysicalDeviceShaderImageAtomicInt64FeaturesEXT>(pCreateInfo->pNext);
if (shader_image_atomic_int64_features) {
enabled_features.shader_image_atomic_int64_features = *shader_image_atomic_int64_features;
}
const auto *shader_clock_features = LvlFindInChain<VkPhysicalDeviceShaderClockFeaturesKHR>(pCreateInfo->pNext);
if (shader_clock_features) {
enabled_features.shader_clock_features = *shader_clock_features;
}
const auto *conditional_rendering_features =
LvlFindInChain<VkPhysicalDeviceConditionalRenderingFeaturesEXT>(pCreateInfo->pNext);
if (conditional_rendering_features) {
enabled_features.conditional_rendering_features = *conditional_rendering_features;
}
const auto *workgroup_memory_explicit_layout_features =
LvlFindInChain<VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR>(pCreateInfo->pNext);
if (workgroup_memory_explicit_layout_features) {
enabled_features.workgroup_memory_explicit_layout_features = *workgroup_memory_explicit_layout_features;
}
const auto *provoking_vertex_features = LvlFindInChain<VkPhysicalDeviceProvokingVertexFeaturesEXT>(pCreateInfo->pNext);
if (provoking_vertex_features) {
enabled_features.provoking_vertex_features = *provoking_vertex_features;
}
const auto *vertex_input_dynamic_state_features =
LvlFindInChain<VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT>(pCreateInfo->pNext);
if (vertex_input_dynamic_state_features) {
enabled_features.vertex_input_dynamic_state_features = *vertex_input_dynamic_state_features;
}
const auto *inherited_viewport_scissor_features =
LvlFindInChain<VkPhysicalDeviceInheritedViewportScissorFeaturesNV>(pCreateInfo->pNext);
if (inherited_viewport_scissor_features) {
enabled_features.inherited_viewport_scissor_features = *inherited_viewport_scissor_features;
}
const auto *multi_draw_features = LvlFindInChain<VkPhysicalDeviceMultiDrawFeaturesEXT>(pCreateInfo->pNext);
if (multi_draw_features) {
enabled_features.multi_draw_features = *multi_draw_features;
}
const auto *color_write_features = LvlFindInChain<VkPhysicalDeviceColorWriteEnableFeaturesEXT>(pCreateInfo->pNext);
if (color_write_features) {
enabled_features.color_write_features = *color_write_features;
}
const auto *shader_atomic_float2_features =
LvlFindInChain<VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT>(pCreateInfo->pNext);
if (shader_atomic_float2_features) {
enabled_features.shader_atomic_float2_features = *shader_atomic_float2_features;
}
const auto *present_id_features = LvlFindInChain<VkPhysicalDevicePresentIdFeaturesKHR>(pCreateInfo->pNext);
if (present_id_features) {
enabled_features.present_id_features = *present_id_features;
}
const auto *present_wait_features = LvlFindInChain<VkPhysicalDevicePresentWaitFeaturesKHR>(pCreateInfo->pNext);
if (present_wait_features) {
enabled_features.present_wait_features = *present_wait_features;
}
const auto *ray_tracing_motion_blur_features =
LvlFindInChain<VkPhysicalDeviceRayTracingMotionBlurFeaturesNV>(pCreateInfo->pNext);
if (ray_tracing_motion_blur_features) {
enabled_features.ray_tracing_motion_blur_features = *ray_tracing_motion_blur_features;
}
const auto *primitive_topology_list_restart_features =
LvlFindInChain<VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(pCreateInfo->pNext);
if (primitive_topology_list_restart_features) {
enabled_features.primitive_topology_list_restart_features = *primitive_topology_list_restart_features;
}
const auto *rgba10x6_formats_features = LvlFindInChain<VkPhysicalDeviceRGBA10X6FormatsFeaturesEXT>(pCreateInfo->pNext);
if (rgba10x6_formats_features) {
enabled_features.rgba10x6_formats_features = *rgba10x6_formats_features;
}
const auto *image_view_min_lod_features = LvlFindInChain<VkPhysicalDeviceImageViewMinLodFeaturesEXT>(pCreateInfo->pNext);
if (image_view_min_lod_features) {
enabled_features.image_view_min_lod_features = *image_view_min_lod_features;
}
const auto *primitives_generated_query_features =
LvlFindInChain<VkPhysicalDevicePrimitivesGeneratedQueryFeaturesEXT>(pCreateInfo->pNext);
if (primitives_generated_query_features) {
enabled_features.primitives_generated_query_features = *primitives_generated_query_features;
}
const auto image_2d_view_of_3d_features = LvlFindInChain<VkPhysicalDeviceImage2DViewOf3DFeaturesEXT>(pCreateInfo->pNext);
if (image_2d_view_of_3d_features) {
enabled_features.image_2d_view_of_3d_features = *image_2d_view_of_3d_features;
}
const auto graphics_pipeline_library_features =
LvlFindInChain<VkPhysicalDeviceGraphicsPipelineLibraryFeaturesEXT>(pCreateInfo->pNext);
if (graphics_pipeline_library_features) {
enabled_features.graphics_pipeline_library_features = *graphics_pipeline_library_features;
}
const auto shader_subgroup_uniform_control_flow_features =
LvlFindInChain<VkPhysicalDeviceShaderSubgroupUniformControlFlowFeaturesKHR>(pCreateInfo->pNext);
if (shader_subgroup_uniform_control_flow_features) {
enabled_features.shader_subgroup_uniform_control_flow_features = *shader_subgroup_uniform_control_flow_features;
}
const auto ray_tracing_maintenance1_features =
LvlFindInChain<VkPhysicalDeviceRayTracingMaintenance1FeaturesKHR>(pCreateInfo->pNext);
if (ray_tracing_maintenance1_features) {
enabled_features.ray_tracing_maintenance1_features= *ray_tracing_maintenance1_features;
}
const auto non_seamless_cube_map_features =
LvlFindInChain<VkPhysicalDeviceNonSeamlessCubeMapFeaturesEXT>(pCreateInfo->pNext);
if (non_seamless_cube_map_features) {
enabled_features.non_seamless_cube_map_features = *non_seamless_cube_map_features;
}
const auto multisampled_render_to_single_sampled_features =
LvlFindInChain<VkPhysicalDeviceMultisampledRenderToSingleSampledFeaturesEXT>(pCreateInfo->pNext);
if (multisampled_render_to_single_sampled_features) {
enabled_features.multisampled_render_to_single_sampled_features = *multisampled_render_to_single_sampled_features;
}
const auto shader_module_identifier_features =
LvlFindInChain<VkPhysicalDeviceShaderModuleIdentifierFeaturesEXT>(pCreateInfo->pNext);
if (shader_module_identifier_features) {
enabled_features.shader_module_identifier_features = *shader_module_identifier_features;
}
const auto attachment_feedback_loop_layout =
LvlFindInChain<VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT>(pCreateInfo->pNext);
if (attachment_feedback_loop_layout) {
enabled_features.attachment_feedback_loop_layout_features = *attachment_feedback_loop_layout;
}
const auto pipeline_protected_access_features =
LvlFindInChain<VkPhysicalDevicePipelineProtectedAccessFeaturesEXT>(pCreateInfo->pNext);
if (pipeline_protected_access_features) {
enabled_features.pipeline_protected_access_features = *pipeline_protected_access_features;
}
const auto linear_color_attachment_features =
LvlFindInChain<VkPhysicalDeviceLinearColorAttachmentFeaturesNV>(pCreateInfo->pNext);
if (linear_color_attachment_features) {
enabled_features.linear_color_attachment_features = *linear_color_attachment_features;
}
const auto shader_core_builtins_features = LvlFindInChain<VkPhysicalDeviceShaderCoreBuiltinsFeaturesARM>(pCreateInfo->pNext);
if (shader_core_builtins_features) {
enabled_features.shader_core_builtins_features= *shader_core_builtins_features;
}
}
// Store physical device properties and physical device mem limits into CoreChecks structs
DispatchGetPhysicalDeviceMemoryProperties(physical_device, &phys_dev_mem_props);
DispatchGetPhysicalDeviceProperties(physical_device, &phys_dev_props);
{
uint32_t n_props = 0;
std::vector<VkExtensionProperties> props;
instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, NULL);
props.resize(n_props);
instance_dispatch_table.EnumerateDeviceExtensionProperties(physical_device, NULL, &n_props, props.data());
for (const auto &ext_prop : props) {
phys_dev_extensions.insert(ext_prop.extensionName);
}
// Even if VK_KHR_format_feature_flags2 is available, we need to have
// a path to grab that information from the physical device. This
// requires to have VK_KHR_get_physical_device_properties2 enabled or
// Vulkan 1.1 (which made this core).
has_format_feature2 =
(api_version >= VK_API_VERSION_1_1 || IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) &&
phys_dev_extensions.find(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME) != phys_dev_extensions.end();
}
const auto &dev_ext = device_extensions;
auto *phys_dev_props = &phys_dev_ext_props;
// Vulkan 1.2 / 1.3 can get properties from single struct, otherwise need to add to it per extension
if (dev_ext.vk_feature_version_1_2 || dev_ext.vk_feature_version_1_3) {
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core11);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_2, &phys_dev_props_core12);
if (dev_ext.vk_feature_version_1_3)
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_feature_version_1_3, &phys_dev_props_core13);
} else {
// VkPhysicalDeviceVulkan11Properties
//
// Can ingnore VkPhysicalDeviceIDProperties as it has no validation purpose
if (dev_ext.vk_khr_multiview) {
auto multiview_props = LvlInitStruct<VkPhysicalDeviceMultiviewProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &multiview_props);
phys_dev_props_core11.maxMultiviewViewCount = multiview_props.maxMultiviewViewCount;
phys_dev_props_core11.maxMultiviewInstanceIndex = multiview_props.maxMultiviewInstanceIndex;
}
if (dev_ext.vk_khr_maintenance3) {
auto maintenance3_props = LvlInitStruct<VkPhysicalDeviceMaintenance3Properties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_maintenance3, &maintenance3_props);
phys_dev_props_core11.maxPerSetDescriptors = maintenance3_props.maxPerSetDescriptors;
phys_dev_props_core11.maxMemoryAllocationSize = maintenance3_props.maxMemoryAllocationSize;
}
// Some 1.1 properties were added to core without previous extensions
if (api_version >= VK_API_VERSION_1_1) {
auto subgroup_prop = LvlInitStruct<VkPhysicalDeviceSubgroupProperties>();
auto protected_memory_prop = LvlInitStruct<VkPhysicalDeviceProtectedMemoryProperties>(&subgroup_prop);
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&protected_memory_prop);
instance_dispatch_table.GetPhysicalDeviceProperties2(physical_device, &prop2);
phys_dev_props_core11.subgroupSize = subgroup_prop.subgroupSize;
phys_dev_props_core11.subgroupSupportedStages = subgroup_prop.supportedStages;
phys_dev_props_core11.subgroupSupportedOperations = subgroup_prop.supportedOperations;
phys_dev_props_core11.subgroupQuadOperationsInAllStages = subgroup_prop.quadOperationsInAllStages;
phys_dev_props_core11.protectedNoFault = protected_memory_prop.protectedNoFault;
}
// VkPhysicalDeviceVulkan12Properties
//
// Can ingnore VkPhysicalDeviceDriverProperties as it has no validation purpose
if (dev_ext.vk_ext_descriptor_indexing) {
auto descriptor_indexing_prop = LvlInitStruct<VkPhysicalDeviceDescriptorIndexingProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_indexing, &descriptor_indexing_prop);
phys_dev_props_core12.maxUpdateAfterBindDescriptorsInAllPools =
descriptor_indexing_prop.maxUpdateAfterBindDescriptorsInAllPools;
phys_dev_props_core12.shaderUniformBufferArrayNonUniformIndexingNative =
descriptor_indexing_prop.shaderUniformBufferArrayNonUniformIndexingNative;
phys_dev_props_core12.shaderSampledImageArrayNonUniformIndexingNative =
descriptor_indexing_prop.shaderSampledImageArrayNonUniformIndexingNative;
phys_dev_props_core12.shaderStorageBufferArrayNonUniformIndexingNative =
descriptor_indexing_prop.shaderStorageBufferArrayNonUniformIndexingNative;
phys_dev_props_core12.shaderStorageImageArrayNonUniformIndexingNative =
descriptor_indexing_prop.shaderStorageImageArrayNonUniformIndexingNative;
phys_dev_props_core12.shaderInputAttachmentArrayNonUniformIndexingNative =
descriptor_indexing_prop.shaderInputAttachmentArrayNonUniformIndexingNative;
phys_dev_props_core12.robustBufferAccessUpdateAfterBind = descriptor_indexing_prop.robustBufferAccessUpdateAfterBind;
phys_dev_props_core12.quadDivergentImplicitLod = descriptor_indexing_prop.quadDivergentImplicitLod;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSamplers =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSamplers;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindUniformBuffers =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindUniformBuffers;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageBuffers =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageBuffers;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindSampledImages =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindSampledImages;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindStorageImages =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindStorageImages;
phys_dev_props_core12.maxPerStageDescriptorUpdateAfterBindInputAttachments =
descriptor_indexing_prop.maxPerStageDescriptorUpdateAfterBindInputAttachments;
phys_dev_props_core12.maxPerStageUpdateAfterBindResources =
descriptor_indexing_prop.maxPerStageUpdateAfterBindResources;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSamplers =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSamplers;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffers =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffers;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindUniformBuffersDynamic;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffers =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffers;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageBuffersDynamic;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindSampledImages =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindSampledImages;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindStorageImages =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindStorageImages;
phys_dev_props_core12.maxDescriptorSetUpdateAfterBindInputAttachments =
descriptor_indexing_prop.maxDescriptorSetUpdateAfterBindInputAttachments;
}
if (dev_ext.vk_khr_depth_stencil_resolve) {
auto depth_stencil_resolve_props = LvlInitStruct<VkPhysicalDeviceDepthStencilResolveProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_depth_stencil_resolve, &depth_stencil_resolve_props);
phys_dev_props_core12.supportedDepthResolveModes = depth_stencil_resolve_props.supportedDepthResolveModes;
phys_dev_props_core12.supportedStencilResolveModes = depth_stencil_resolve_props.supportedStencilResolveModes;
phys_dev_props_core12.independentResolveNone = depth_stencil_resolve_props.independentResolveNone;
phys_dev_props_core12.independentResolve = depth_stencil_resolve_props.independentResolve;
}
if (dev_ext.vk_khr_timeline_semaphore) {
auto timeline_semaphore_props = LvlInitStruct<VkPhysicalDeviceTimelineSemaphoreProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_timeline_semaphore, &timeline_semaphore_props);
phys_dev_props_core12.maxTimelineSemaphoreValueDifference =
timeline_semaphore_props.maxTimelineSemaphoreValueDifference;
}
if (dev_ext.vk_ext_sampler_filter_minmax) {
auto sampler_filter_minmax_props = LvlInitStruct<VkPhysicalDeviceSamplerFilterMinmaxProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sampler_filter_minmax, &sampler_filter_minmax_props);
phys_dev_props_core12.filterMinmaxSingleComponentFormats =
sampler_filter_minmax_props.filterMinmaxSingleComponentFormats;
phys_dev_props_core12.filterMinmaxImageComponentMapping = sampler_filter_minmax_props.filterMinmaxImageComponentMapping;
}
if (dev_ext.vk_khr_shader_float_controls) {
auto float_controls_props = LvlInitStruct<VkPhysicalDeviceFloatControlsProperties>();
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_shader_float_controls, &float_controls_props);
phys_dev_props_core12.denormBehaviorIndependence = float_controls_props.denormBehaviorIndependence;
phys_dev_props_core12.roundingModeIndependence = float_controls_props.roundingModeIndependence;
phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16 =
float_controls_props.shaderSignedZeroInfNanPreserveFloat16;
phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32 =
float_controls_props.shaderSignedZeroInfNanPreserveFloat32;
phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64 =
float_controls_props.shaderSignedZeroInfNanPreserveFloat64;
phys_dev_props_core12.shaderDenormPreserveFloat16 = float_controls_props.shaderDenormPreserveFloat16;
phys_dev_props_core12.shaderDenormPreserveFloat32 = float_controls_props.shaderDenormPreserveFloat32;
phys_dev_props_core12.shaderDenormPreserveFloat64 = float_controls_props.shaderDenormPreserveFloat64;
phys_dev_props_core12.shaderDenormFlushToZeroFloat16 = float_controls_props.shaderDenormFlushToZeroFloat16;
phys_dev_props_core12.shaderDenormFlushToZeroFloat32 = float_controls_props.shaderDenormFlushToZeroFloat32;
phys_dev_props_core12.shaderDenormFlushToZeroFloat64 = float_controls_props.shaderDenormFlushToZeroFloat64;
phys_dev_props_core12.shaderRoundingModeRTEFloat16 = float_controls_props.shaderRoundingModeRTEFloat16;
phys_dev_props_core12.shaderRoundingModeRTEFloat32 = float_controls_props.shaderRoundingModeRTEFloat32;
phys_dev_props_core12.shaderRoundingModeRTEFloat64 = float_controls_props.shaderRoundingModeRTEFloat64;
phys_dev_props_core12.shaderRoundingModeRTZFloat16 = float_controls_props.shaderRoundingModeRTZFloat16;
phys_dev_props_core12.shaderRoundingModeRTZFloat32 = float_controls_props.shaderRoundingModeRTZFloat32;
phys_dev_props_core12.shaderRoundingModeRTZFloat64 = float_controls_props.shaderRoundingModeRTZFloat64;
}
}
// Extensions with properties to extract to DeviceExtensionProperties
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_push_descriptor, &phys_dev_props->push_descriptor_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_shading_rate_image, &phys_dev_props->shading_rate_image_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_mesh_shader, &phys_dev_props->mesh_shader_props_nv);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_mesh_shader, &phys_dev_props->mesh_shader_props_ext);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_inline_uniform_block,
&phys_dev_props->inline_uniform_block_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_vertex_attribute_divisor,
&phys_dev_props->vtx_attrib_divisor_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_transform_feedback, &phys_dev_props->transform_feedback_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_nv_ray_tracing, &phys_dev_props->ray_tracing_props_nv);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_ray_tracing_pipeline, &phys_dev_props->ray_tracing_props_khr);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_acceleration_structure, &phys_dev_props->acc_structure_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_texel_buffer_alignment,
&phys_dev_props->texel_buffer_alignment_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map,
&phys_dev_props->fragment_density_map_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_fragment_density_map2,
&phys_dev_props->fragment_density_map2_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_qcom_fragment_density_map_offset,
&phys_dev_props->fragment_density_map_offset_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_performance_query, &phys_dev_props->performance_query_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_sample_locations, &phys_dev_props->sample_locations_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_custom_border_color, &phys_dev_props->custom_border_color_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_multiview, &phys_dev_props->multiview_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_portability_subset, &phys_dev_props->portability_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_khr_fragment_shading_rate,
&phys_dev_props->fragment_shading_rate_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_provoking_vertex, &phys_dev_props->provoking_vertex_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_multi_draw, &phys_dev_props->multi_draw_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_discard_rectangles, &phys_dev_props->discard_rectangle_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_blend_operation_advanced,
&phys_dev_props->blend_operation_advanced_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_conservative_rasterization,
&phys_dev_props->conservative_rasterization_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_subgroup_size_control,
&phys_dev_props->subgroup_size_control_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_buffer,
&phys_dev_props->descriptor_buffer_props);
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_descriptor_buffer_density,
&phys_dev_props->descriptor_buffer_density_props);
if (api_version >= VK_API_VERSION_1_1) {
GetPhysicalDeviceExtProperties(physical_device, &phys_dev_props->subgroup_props);
}
GetPhysicalDeviceExtProperties(physical_device, dev_ext.vk_ext_extended_dynamic_state3,
&phys_dev_props->extended_dynamic_state3_props);
if (IsExtEnabled(dev_ext.vk_nv_cooperative_matrix)) {
// Get the needed cooperative_matrix properties
auto cooperative_matrix_props = LvlInitStruct<VkPhysicalDeviceCooperativeMatrixPropertiesNV>();
auto prop2 = LvlInitStruct<VkPhysicalDeviceProperties2>(&cooperative_matrix_props);
instance_dispatch_table.GetPhysicalDeviceProperties2KHR(physical_device, &prop2);
phys_dev_ext_props.cooperative_matrix_props = cooperative_matrix_props;
uint32_t num_cooperative_matrix_properties = 0;
instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
NULL);
cooperative_matrix_properties.resize(num_cooperative_matrix_properties, LvlInitStruct<VkCooperativeMatrixPropertiesNV>());
instance_dispatch_table.GetPhysicalDeviceCooperativeMatrixPropertiesNV(physical_device, &num_cooperative_matrix_properties,
cooperative_matrix_properties.data());
}
// Store queue family data
if (pCreateInfo->pQueueCreateInfos != nullptr) {
uint32_t num_queue_families = 0;
instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
const VkDeviceQueueCreateInfo &queue_create_info = pCreateInfo->pQueueCreateInfos[i];
queue_family_index_set.insert(queue_create_info.queueFamilyIndex);
device_queue_info_list.push_back(
{i, queue_create_info.queueFamilyIndex, queue_create_info.flags, queue_create_info.queueCount});
}
for (const auto &queue_info : device_queue_info_list) {
for (uint32_t i = 0; i < queue_info.queue_count; i++) {
VkQueue queue = VK_NULL_HANDLE;
// vkGetDeviceQueue2() was added in vulkan 1.1, and there was never a KHR version of it.
if (api_version >= VK_API_VERSION_1_1 && queue_info.flags != 0) {
auto get_info = LvlInitStruct<VkDeviceQueueInfo2>();
get_info.flags = queue_info.flags;
get_info.queueFamilyIndex = queue_info.queue_family_index;
get_info.queueIndex = i;
DispatchGetDeviceQueue2(device, &get_info, &queue);
} else {
DispatchGetDeviceQueue(device, queue_info.queue_family_index, i, &queue);
}
assert(queue != VK_NULL_HANDLE);
Add(CreateQueue(queue, queue_info.queue_family_index, queue_info.flags,
queue_family_properties_list[queue_info.queue_family_index]));
}
}
}
// Query queue family extension properties
{
uint32_t queue_family_count = (uint32_t)physical_device_state->queue_family_properties.size();
auto &ext_props = queue_family_ext_props;
ext_props.resize(queue_family_count);
std::vector<VkQueueFamilyProperties2> props(queue_family_count, LvlInitStruct<VkQueueFamilyProperties2>());
if (dev_ext.vk_khr_video_queue) {
for (uint32_t i = 0; i < queue_family_count; ++i) {
ext_props[i].query_result_status_props = LvlInitStruct<VkQueueFamilyQueryResultStatusPropertiesKHR>();
ext_props[i].video_props = LvlInitStruct<VkQueueFamilyVideoPropertiesKHR>(&ext_props[i].query_result_status_props);
props[i].pNext = &ext_props[i].video_props;
}
}
if (api_version >= VK_API_VERSION_1_1) {
DispatchGetPhysicalDeviceQueueFamilyProperties2(physical_device, &queue_family_count, props.data());
} else if (IsExtEnabled(instance_extensions.vk_khr_get_physical_device_properties2)) {
DispatchGetPhysicalDeviceQueueFamilyProperties2KHR(physical_device, &queue_family_count, props.data());
}
}
}
void ValidationStateTracker::PreCallRecordDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
if (!device) return;
command_pool_map_.clear();
assert(command_buffer_map_.empty());
pipeline_map_.clear();
render_pass_map_.clear();
// This will also delete all sets in the pool & remove them from setMap
descriptor_pool_map_.clear();
// All sets should be removed
assert(descriptor_set_map_.empty());
desc_template_map_.clear();
descriptor_set_layout_map_.clear();
// Because swapchains are associated with Surfaces, which are at instance level,
// they need to be explicitly destroyed here to avoid continued references to
// the device we're destroying.
for (auto &entry : swapchain_map_.snapshot()) {
entry.second->Destroy();
}
swapchain_map_.clear();
image_view_map_.clear();
image_map_.clear();
buffer_view_map_.clear();
buffer_map_.clear();
// Queues persist until device is destroyed
for (auto &entry : queue_map_.snapshot()) {
entry.second->Destroy();
}
queue_map_.clear();
}
void ValidationStateTracker::PreCallRecordQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo *pSubmits,
VkFence fence) {
auto queue_state = Get<QUEUE_STATE>(queue);
uint64_t early_retire_seq = 0;
if (submitCount == 0) {
CB_SUBMISSION submission;
submission.AddFence(Get<FENCE_STATE>(fence));
early_retire_seq = queue_state->Submit(std::move(submission));
}
// Now process each individual submit
for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
CB_SUBMISSION submission;
const VkSubmitInfo *submit = &pSubmits[submit_idx];
auto *timeline_semaphore_submit = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(submit->pNext);
for (uint32_t i = 0; i < submit->waitSemaphoreCount; ++i) {
uint64_t value{0};
if (timeline_semaphore_submit && timeline_semaphore_submit->pWaitSemaphoreValues != nullptr &&
(i < timeline_semaphore_submit->waitSemaphoreValueCount)) {
value = timeline_semaphore_submit->pWaitSemaphoreValues[i];
}
submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(submit->pWaitSemaphores[i]), value);
}
for (uint32_t i = 0; i < submit->signalSemaphoreCount; ++i) {
uint64_t value{0};
if (timeline_semaphore_submit && timeline_semaphore_submit->pSignalSemaphoreValues != nullptr &&
(i < timeline_semaphore_submit->signalSemaphoreValueCount)) {
value = timeline_semaphore_submit->pSignalSemaphoreValues[i];
}
submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(submit->pSignalSemaphores[i]), value);
}
const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
for (uint32_t i = 0; i < submit->commandBufferCount; i++) {
auto cb_state = Get<CMD_BUFFER_STATE>(submit->pCommandBuffers[i]);
if (cb_state) {
submission.AddCommandBuffer(std::move(cb_state));
}
}
if (submit_idx == (submitCount - 1) && fence != VK_NULL_HANDLE) {
submission.AddFence(Get<FENCE_STATE>(fence));
}
auto submit_seq = queue_state->Submit(std::move(submission));
early_retire_seq = std::max(early_retire_seq, submit_seq);
}
if (early_retire_seq) {
queue_state->NotifyAndWait(early_retire_seq);
}
}
void ValidationStateTracker::RecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
VkFence fence) {
auto queue_state = Get<QUEUE_STATE>(queue);
uint64_t early_retire_seq = 0;
if (submitCount == 0) {
CB_SUBMISSION submission;
submission.AddFence(Get<FENCE_STATE>(fence));
early_retire_seq = queue_state->Submit(std::move(submission));
}
for (uint32_t submit_idx = 0; submit_idx < submitCount; submit_idx++) {
CB_SUBMISSION submission;
const VkSubmitInfo2KHR *submit = &pSubmits[submit_idx];
for (uint32_t i = 0; i < submit->waitSemaphoreInfoCount; ++i) {
const auto &sem_info = submit->pWaitSemaphoreInfos[i];
submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
}
for (uint32_t i = 0; i < submit->signalSemaphoreInfoCount; ++i) {
const auto &sem_info = submit->pSignalSemaphoreInfos[i];
submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(sem_info.semaphore), sem_info.value);
}
const auto perf_submit = LvlFindInChain<VkPerformanceQuerySubmitInfoKHR>(submit->pNext);
submission.perf_submit_pass = perf_submit ? perf_submit->counterPassIndex : 0;
for (uint32_t i = 0; i < submit->commandBufferInfoCount; i++) {
submission.AddCommandBuffer(GetWrite<CMD_BUFFER_STATE>(submit->pCommandBufferInfos[i].commandBuffer));
}
if (submit_idx == (submitCount - 1)) {
submission.AddFence(Get<FENCE_STATE>(fence));
}
auto submit_seq = queue_state->Submit(std::move(submission));
early_retire_seq = std::max(early_retire_seq, submit_seq);
}
if (early_retire_seq) {
queue_state->NotifyAndWait(early_retire_seq);
}
}
void ValidationStateTracker::PreCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR *pSubmits,
VkFence fence) {
RecordQueueSubmit2(queue, submitCount, pSubmits, fence);
}
void ValidationStateTracker::PreCallRecordQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2 *pSubmits,
VkFence fence) {
RecordQueueSubmit2(queue, submitCount, pSubmits, fence);
}
void ValidationStateTracker::PostCallRecordAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo,
const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory,
VkResult result) {
if (VK_SUCCESS != result) {
return;
}
const auto &memory_type = phys_dev_mem_props.memoryTypes[pAllocateInfo->memoryTypeIndex];
const auto &memory_heap = phys_dev_mem_props.memoryHeaps[memory_type.heapIndex];
auto fake_address = fake_memory.Alloc(pAllocateInfo->allocationSize);
std::optional<DedicatedBinding> dedicated_binding;
auto dedicated = LvlFindInChain<VkMemoryDedicatedAllocateInfo>(pAllocateInfo->pNext);
if (dedicated) {
if (dedicated->buffer) {
auto buffer_state = Get<BUFFER_STATE>(dedicated->buffer);
assert(buffer_state);
if (!buffer_state) {
return;
}
dedicated_binding.emplace(dedicated->buffer, buffer_state->createInfo);
} else if (dedicated->image) {
auto image_state = Get<IMAGE_STATE>(dedicated->image);
assert(image_state);
if (!image_state) {
return;
}
dedicated_binding.emplace(dedicated->image, image_state->createInfo);
}
}
Add(CreateDeviceMemoryState(*pMemory, pAllocateInfo, fake_address, memory_type, memory_heap, std::move(dedicated_binding),
physical_device_count));
return;
}
void ValidationStateTracker::PreCallRecordFreeMemory(VkDevice device, VkDeviceMemory mem, const VkAllocationCallbacks *pAllocator) {
auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
if (mem_info) {
fake_memory.Free(mem_info->fake_base_address);
}
Destroy<DEVICE_MEMORY_STATE>(mem);
}
void ValidationStateTracker::PreCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo *pBindInfo,
VkFence fence) {
auto queue_state = Get<QUEUE_STATE>(queue);
uint64_t early_retire_seq = 0;
for (uint32_t bind_idx = 0; bind_idx < bindInfoCount; ++bind_idx) {
const VkBindSparseInfo &bind_info = pBindInfo[bind_idx];
// Track objects tied to memory
for (uint32_t j = 0; j < bind_info.bufferBindCount; j++) {
for (uint32_t k = 0; k < bind_info.pBufferBinds[j].bindCount; k++) {
auto sparse_binding = bind_info.pBufferBinds[j].pBinds[k];
auto buffer_state = Get<BUFFER_STATE>(bind_info.pBufferBinds[j].buffer);
auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
if (buffer_state) {
buffer_state->BindMemory(buffer_state.get(), mem_state, sparse_binding.memoryOffset,
sparse_binding.resourceOffset, sparse_binding.size);
}
}
}
for (uint32_t j = 0; j < bind_info.imageOpaqueBindCount; j++) {
for (uint32_t k = 0; k < bind_info.pImageOpaqueBinds[j].bindCount; k++) {
auto sparse_binding = bind_info.pImageOpaqueBinds[j].pBinds[k];
auto image_state = Get<IMAGE_STATE>(bind_info.pImageOpaqueBinds[j].image);
auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
if (image_state) {
// An Android special image cannot get VkSubresourceLayout until the image binds a memory.
// See: VUID-vkGetImageSubresourceLayout-image-01895
if (!image_state->fragment_encoder) {
image_state->fragment_encoder =
std::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
}
image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset,
sparse_binding.resourceOffset, sparse_binding.size);
}
}
}
for (uint32_t j = 0; j < bind_info.imageBindCount; j++) {
for (uint32_t k = 0; k < bind_info.pImageBinds[j].bindCount; k++) {
auto sparse_binding = bind_info.pImageBinds[j].pBinds[k];
// TODO: This size is broken for non-opaque bindings, need to update to comprehend full sparse binding data
VkDeviceSize size = sparse_binding.extent.depth * sparse_binding.extent.height * sparse_binding.extent.width * 4;
VkDeviceSize offset = sparse_binding.offset.z * sparse_binding.offset.y * sparse_binding.offset.x * 4;
auto image_state = Get<IMAGE_STATE>(bind_info.pImageBinds[j].image);
auto mem_state = Get<DEVICE_MEMORY_STATE>(sparse_binding.memory);
if (image_state) {
// An Android special image cannot get VkSubresourceLayout until the image binds a memory.
// See: VUID-vkGetImageSubresourceLayout-image-01895
if (!image_state->fragment_encoder) {
image_state->fragment_encoder =
std::make_unique<const subresource_adapter::ImageRangeEncoder>(*image_state);
}
image_state->BindMemory(image_state.get(), mem_state, sparse_binding.memoryOffset, offset, size);
}
}
}
auto timeline_info = LvlFindInChain<VkTimelineSemaphoreSubmitInfo>(bind_info.pNext);
CB_SUBMISSION submission;
for (uint32_t i = 0; i < bind_info.waitSemaphoreCount; ++i) {
uint64_t payload = 0;
if (timeline_info && i < timeline_info->waitSemaphoreValueCount) {
payload = timeline_info->pWaitSemaphoreValues[i];
}
submission.AddWaitSemaphore(Get<SEMAPHORE_STATE>(bind_info.pWaitSemaphores[i]), payload);
}
for (uint32_t i = 0; i < bind_info.signalSemaphoreCount; ++i) {
uint64_t payload = 0;
if (timeline_info && i < timeline_info->signalSemaphoreValueCount) {
payload = timeline_info->pSignalSemaphoreValues[i];
}
submission.AddSignalSemaphore(Get<SEMAPHORE_STATE>(bind_info.pSignalSemaphores[i]), payload);
}
if (bind_idx == (bindInfoCount - 1)) {
submission.AddFence(Get<FENCE_STATE>(fence));
}
auto submit_seq = queue_state->Submit(std::move(submission));
early_retire_seq = std::max(early_retire_seq, submit_seq);
}
if (early_retire_seq) {
queue_state->NotifyAndWait(early_retire_seq);
}
}
void ValidationStateTracker::PostCallRecordCreateSemaphore(VkDevice device, const VkSemaphoreCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSemaphore *pSemaphore,
VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<SEMAPHORE_STATE>(*this, *pSemaphore, pCreateInfo));
}
void ValidationStateTracker::RecordImportSemaphoreState(VkSemaphore semaphore, VkExternalSemaphoreHandleTypeFlagBits handle_type,
VkSemaphoreImportFlags flags) {
auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
if (semaphore_state) {
semaphore_state->Import(handle_type, flags);
}
}
void ValidationStateTracker::PreCallRecordSignalSemaphore(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo) {
auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
if (semaphore_state) {
auto value = pSignalInfo->value; // const workaround
semaphore_state->EnqueueSignal(nullptr, 0, value);
}
}
void ValidationStateTracker::PreCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo) {
PreCallRecordSignalSemaphore(device, pSignalInfo);
}
void ValidationStateTracker::PostCallRecordSignalSemaphore(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
VkResult result) {
if (result != VK_SUCCESS) return;
auto semaphore_state = Get<SEMAPHORE_STATE>(pSignalInfo->semaphore);
if (semaphore_state) {
semaphore_state->Retire(nullptr, pSignalInfo->value);
}
}
void ValidationStateTracker::PostCallRecordSignalSemaphoreKHR(VkDevice device, const VkSemaphoreSignalInfo *pSignalInfo,
VkResult result) {
PostCallRecordSignalSemaphore(device, pSignalInfo, result);
}
void ValidationStateTracker::RecordMappedMemory(VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size, void **ppData) {
auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
if (mem_info) {
mem_info->mapped_range.offset = offset;
mem_info->mapped_range.size = size;
mem_info->p_driver_data = *ppData;
}
}
void ValidationStateTracker::PostCallRecordWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
VkBool32 waitAll, uint64_t timeout, VkResult result) {
if (VK_SUCCESS != result) return;
// When we know that all fences are complete we can clean/remove their CBs
if ((VK_TRUE == waitAll) || (1 == fenceCount)) {
for (uint32_t i = 0; i < fenceCount; i++) {
auto fence_state = Get<FENCE_STATE>(pFences[i]);
if (fence_state) {
fence_state->NotifyAndWait();
}
}
}
// NOTE : Alternate case not handled here is when some fences have completed. In
// this case for app to guarantee which fences completed it will have to call
// vkGetFenceStatus() at which point we'll clean/remove their CBs if complete.
}
void ValidationStateTracker::PreRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout) {
for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
if (semaphore_state) {
auto value = pWaitInfo->pValues[i]; // const workaround
semaphore_state->EnqueueWait(nullptr, 0, value);
}
}
}
void ValidationStateTracker::PreCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout) {
PreRecordWaitSemaphores(device, pWaitInfo, timeout);
}
void ValidationStateTracker::PreCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
uint64_t timeout) {
PreRecordWaitSemaphores(device, pWaitInfo, timeout);
}
void ValidationStateTracker::PostRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
VkResult result) {
if (VK_SUCCESS != result) return;
// Same logic as vkWaitForFences(). If some semaphores are not signaled, we will get their status when
// the application calls vkGetSemaphoreCounterValue() on each of them.
if ((pWaitInfo->flags & VK_SEMAPHORE_WAIT_ANY_BIT) == 0 || pWaitInfo->semaphoreCount == 1) {
for (uint32_t i = 0; i < pWaitInfo->semaphoreCount; i++) {
auto semaphore_state = Get<SEMAPHORE_STATE>(pWaitInfo->pSemaphores[i]);
if (semaphore_state) {
semaphore_state->NotifyAndWait(pWaitInfo->pValues[i]);
}
}
}
}
void ValidationStateTracker::PostCallRecordWaitSemaphores(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo, uint64_t timeout,
VkResult result) {
PostRecordWaitSemaphores(device, pWaitInfo, timeout, result);
}
void ValidationStateTracker::PostCallRecordWaitSemaphoresKHR(VkDevice device, const VkSemaphoreWaitInfo *pWaitInfo,
uint64_t timeout, VkResult result) {
PostRecordWaitSemaphores(device, pWaitInfo, timeout, result);
}
void ValidationStateTracker::RecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
VkResult result) {
if (VK_SUCCESS != result) return;
auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
if (semaphore_state) {
semaphore_state->NotifyAndWait(*pValue);
}
}
void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValue(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
VkResult result) {
RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
}
void ValidationStateTracker::PostCallRecordGetSemaphoreCounterValueKHR(VkDevice device, VkSemaphore semaphore, uint64_t *pValue,
VkResult result) {
RecordGetSemaphoreCounterValue(device, semaphore, pValue, result);
}
void ValidationStateTracker::PostCallRecordGetFenceStatus(VkDevice device, VkFence fence, VkResult result) {
if (VK_SUCCESS != result) return;
auto fence_state = Get<FENCE_STATE>(fence);
if (fence_state) {
fence_state->NotifyAndWait();
}
}
void ValidationStateTracker::RecordGetDeviceQueueState(uint32_t queue_family_index, VkDeviceQueueCreateFlags flags, VkQueue queue) {
if (Get<QUEUE_STATE>(queue) == nullptr) {
uint32_t num_queue_families = 0;
instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, nullptr);
std::vector<VkQueueFamilyProperties> queue_family_properties_list(num_queue_families);
instance_dispatch_table.GetPhysicalDeviceQueueFamilyProperties(physical_device, &num_queue_families, queue_family_properties_list.data());
Add(CreateQueue(queue, queue_family_index, flags, queue_family_properties_list[queue_family_index]));
}
}
void ValidationStateTracker::PostCallRecordGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex,
VkQueue *pQueue) {
RecordGetDeviceQueueState(queueFamilyIndex, {}, *pQueue);
}
void ValidationStateTracker::PostCallRecordGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2 *pQueueInfo, VkQueue *pQueue) {
RecordGetDeviceQueueState(pQueueInfo->queueFamilyIndex, pQueueInfo->flags, *pQueue);
}
void ValidationStateTracker::PostCallRecordQueueWaitIdle(VkQueue queue, VkResult result) {
if (VK_SUCCESS != result) return;
auto queue_state = Get<QUEUE_STATE>(queue);
if (queue_state) {
queue_state->NotifyAndWait();
}
}
void ValidationStateTracker::PostCallRecordDeviceWaitIdle(VkDevice device, VkResult result) {
if (VK_SUCCESS != result) return;
for (auto &queue : queue_map_.snapshot()) {
queue.second->NotifyAndWait();
}
}
void ValidationStateTracker::PreCallRecordDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks *pAllocator) {
Destroy<FENCE_STATE>(fence);
}
void ValidationStateTracker::PreCallRecordDestroySemaphore(VkDevice device, VkSemaphore semaphore,
const VkAllocationCallbacks *pAllocator) {
Destroy<SEMAPHORE_STATE>(semaphore);
}
void ValidationStateTracker::PreCallRecordDestroyEvent(VkDevice device, VkEvent event, const VkAllocationCallbacks *pAllocator) {
Destroy<EVENT_STATE>(event);
}
void ValidationStateTracker::PreCallRecordDestroyQueryPool(VkDevice device, VkQueryPool queryPool,
const VkAllocationCallbacks *pAllocator) {
Destroy<QUERY_POOL_STATE>(queryPool);
}
void ValidationStateTracker::UpdateBindBufferMemoryState(VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memoryOffset) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
if (buffer_state) {
// Track objects tied to memory
auto mem_state = Get<DEVICE_MEMORY_STATE>(mem);
if (mem_state) {
buffer_state->BindMemory(buffer_state.get(), mem_state, memoryOffset, 0u, buffer_state->requirements.size);
}
}
}
void ValidationStateTracker::PostCallRecordBindBufferMemory(VkDevice device, VkBuffer buffer, VkDeviceMemory mem,
VkDeviceSize memoryOffset, VkResult result) {
if (VK_SUCCESS != result) return;
UpdateBindBufferMemoryState(buffer, mem, memoryOffset);
}
void ValidationStateTracker::PostCallRecordBindBufferMemory2(VkDevice device, uint32_t bindInfoCount,
const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
for (uint32_t i = 0; i < bindInfoCount; i++) {
UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
}
}
void ValidationStateTracker::PostCallRecordBindBufferMemory2KHR(VkDevice device, uint32_t bindInfoCount,
const VkBindBufferMemoryInfo *pBindInfos, VkResult result) {
for (uint32_t i = 0; i < bindInfoCount; i++) {
UpdateBindBufferMemoryState(pBindInfos[i].buffer, pBindInfos[i].memory, pBindInfos[i].memoryOffset);
}
}
void ValidationStateTracker::RecordGetBufferMemoryRequirementsState(VkBuffer buffer) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
if (buffer_state) {
buffer_state->memory_requirements_checked = true;
}
}
void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements(VkDevice device, VkBuffer buffer,
VkMemoryRequirements *pMemoryRequirements) {
RecordGetBufferMemoryRequirementsState(buffer);
}
void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2(VkDevice device,
const VkBufferMemoryRequirementsInfo2 *pInfo,
VkMemoryRequirements2 *pMemoryRequirements) {
RecordGetBufferMemoryRequirementsState(pInfo->buffer);
}
void ValidationStateTracker::PostCallRecordGetBufferMemoryRequirements2KHR(VkDevice device,
const VkBufferMemoryRequirementsInfo2 *pInfo,
VkMemoryRequirements2 *pMemoryRequirements) {
RecordGetBufferMemoryRequirementsState(pInfo->buffer);
}
void ValidationStateTracker::RecordGetImageMemoryRequirementsState(VkImage image, const VkImageMemoryRequirementsInfo2 *pInfo) {
const VkImagePlaneMemoryRequirementsInfo *plane_info =
(pInfo == nullptr) ? nullptr : LvlFindInChain<VkImagePlaneMemoryRequirementsInfo>(pInfo->pNext);
auto image_state = Get<IMAGE_STATE>(image);
if (image_state) {
if (plane_info != nullptr) {
// Multi-plane image
if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_0_BIT) {
image_state->memory_requirements_checked[0] = true;
} else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_1_BIT) {
image_state->memory_requirements_checked[1] = true;
} else if (plane_info->planeAspect == VK_IMAGE_ASPECT_PLANE_2_BIT) {
image_state->memory_requirements_checked[2] = true;
}
} else if (!image_state->disjoint) {
// Single Plane image
image_state->memory_requirements_checked[0] = true;
}
}
}
void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements(VkDevice device, VkImage image,
VkMemoryRequirements *pMemoryRequirements) {
RecordGetImageMemoryRequirementsState(image, nullptr);
}
void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2(VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
VkMemoryRequirements2 *pMemoryRequirements) {
RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
}
void ValidationStateTracker::PostCallRecordGetImageMemoryRequirements2KHR(VkDevice device,
const VkImageMemoryRequirementsInfo2 *pInfo,
VkMemoryRequirements2 *pMemoryRequirements) {
RecordGetImageMemoryRequirementsState(pInfo->image, pInfo);
}
void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements(
VkDevice device, VkImage image, uint32_t *pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements *pSparseMemoryRequirements) {
auto image_state = Get<IMAGE_STATE>(image);
image_state->get_sparse_reqs_called = true;
}
void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2(
VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
auto image_state = Get<IMAGE_STATE>(pInfo->image);
image_state->get_sparse_reqs_called = true;
}
void ValidationStateTracker::PostCallRecordGetImageSparseMemoryRequirements2KHR(
VkDevice device, const VkImageSparseMemoryRequirementsInfo2 *pInfo, uint32_t *pSparseMemoryRequirementCount,
VkSparseImageMemoryRequirements2 *pSparseMemoryRequirements) {
auto image_state = Get<IMAGE_STATE>(pInfo->image);
image_state->get_sparse_reqs_called = true;
}
void ValidationStateTracker::PreCallRecordDestroyShaderModule(VkDevice device, VkShaderModule shaderModule,
const VkAllocationCallbacks *pAllocator) {
Destroy<SHADER_MODULE_STATE>(shaderModule);
}
void ValidationStateTracker::PreCallRecordDestroyPipeline(VkDevice device, VkPipeline pipeline,
const VkAllocationCallbacks *pAllocator) {
Destroy<PIPELINE_STATE>(pipeline);
}
void ValidationStateTracker::PreCallRecordDestroyPipelineLayout(VkDevice device, VkPipelineLayout pipelineLayout,
const VkAllocationCallbacks *pAllocator) {
Destroy<PIPELINE_LAYOUT_STATE>(pipelineLayout);
}
void ValidationStateTracker::PreCallRecordDestroySampler(VkDevice device, VkSampler sampler,
const VkAllocationCallbacks *pAllocator) {
if (!sampler) return;
auto sampler_state = Get<SAMPLER_STATE>(sampler);
// Any bound cmd buffers are now invalid
if (sampler_state) {
if (sampler_state->createInfo.borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
sampler_state->createInfo.borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
custom_border_color_sampler_count--;
}
}
Destroy<SAMPLER_STATE>(sampler);
}
void ValidationStateTracker::PreCallRecordDestroyDescriptorSetLayout(VkDevice device, VkDescriptorSetLayout descriptorSetLayout,
const VkAllocationCallbacks *pAllocator) {
Destroy<cvdescriptorset::DescriptorSetLayout>(descriptorSetLayout);
}
void ValidationStateTracker::PreCallRecordDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
const VkAllocationCallbacks *pAllocator) {
Destroy<DESCRIPTOR_POOL_STATE>(descriptorPool);
}
void ValidationStateTracker::PreCallRecordFreeCommandBuffers(VkDevice device, VkCommandPool commandPool,
uint32_t commandBufferCount, const VkCommandBuffer *pCommandBuffers) {
auto pool = Get<COMMAND_POOL_STATE>(commandPool);
if (pool) {
pool->Free(commandBufferCount, pCommandBuffers);
}
}
void ValidationStateTracker::PostCallRecordCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool,
VkResult result) {
if (VK_SUCCESS != result) return;
auto queue_flags = physical_device_state->queue_family_properties[pCreateInfo->queueFamilyIndex].queueFlags;
Add(std::make_shared<COMMAND_POOL_STATE>(this, *pCommandPool, pCreateInfo, queue_flags));
}
void ValidationStateTracker::PostCallRecordCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool,
VkResult result) {
if (VK_SUCCESS != result) return;
uint32_t index_count = 0, n_perf_pass = 0;
bool has_cb = false, has_rb = false;
if (pCreateInfo->queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
const auto *perf = LvlFindInChain<VkQueryPoolPerformanceCreateInfoKHR>(pCreateInfo->pNext);
index_count = perf->counterIndexCount;
const QUEUE_FAMILY_PERF_COUNTERS &counters = *physical_device_state->perf_counters[perf->queueFamilyIndex];
for (uint32_t i = 0; i < perf->counterIndexCount; i++) {
const auto &counter = counters.counters[perf->pCounterIndices[i]];
switch (counter.scope) {
case VK_QUERY_SCOPE_COMMAND_BUFFER_KHR:
has_cb = true;
break;
case VK_QUERY_SCOPE_RENDER_PASS_KHR:
has_rb = true;
break;
default:
break;
}
}
DispatchGetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(physical_device_state->PhysDev(), perf, &n_perf_pass);
}
Add(std::make_shared<QUERY_POOL_STATE>(
*pQueryPool, pCreateInfo, index_count, n_perf_pass, has_cb, has_rb,
video_profile_cache_.Get(this, LvlFindInChain<VkVideoProfileInfoKHR>(pCreateInfo->pNext))));
}
void ValidationStateTracker::PreCallRecordDestroyCommandPool(VkDevice device, VkCommandPool commandPool,
const VkAllocationCallbacks *pAllocator) {
Destroy<COMMAND_POOL_STATE>(commandPool);
}
void ValidationStateTracker::PostCallRecordResetCommandPool(VkDevice device, VkCommandPool commandPool,
VkCommandPoolResetFlags flags, VkResult result) {
if (VK_SUCCESS != result) return;
// Reset all of the CBs allocated from this pool
auto pool = Get<COMMAND_POOL_STATE>(commandPool);
if (pool) {
pool->Reset();
}
}
void ValidationStateTracker::PostCallRecordResetFences(VkDevice device, uint32_t fenceCount, const VkFence *pFences,
VkResult result) {
for (uint32_t i = 0; i < fenceCount; ++i) {
auto fence_state = Get<FENCE_STATE>(pFences[i]);
if (fence_state) {
fence_state->Reset();
}
}
}
void ValidationStateTracker::PreCallRecordDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
const VkAllocationCallbacks *pAllocator) {
Destroy<FRAMEBUFFER_STATE>(framebuffer);
}
void ValidationStateTracker::PreCallRecordDestroyRenderPass(VkDevice device, VkRenderPass renderPass,
const VkAllocationCallbacks *pAllocator) {
Destroy<RENDER_PASS_STATE>(renderPass);
}
void ValidationStateTracker::PostCallRecordCreateFence(VkDevice device, const VkFenceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkFence *pFence, VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<FENCE_STATE>(*this, *pFence, pCreateInfo));
}
std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateGraphicsPipelineState(
const VkGraphicsPipelineCreateInfo *pCreateInfo, std::shared_ptr<const RENDER_PASS_STATE> &&render_pass,
std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout, CreateShaderModuleStates *csm_states) const {
return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(render_pass), std::move(layout), csm_states);
}
bool ValidationStateTracker::PreCallValidateCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
const VkGraphicsPipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
void *cgpl_state_data) const {
bool skip = false;
// Set up the state that CoreChecks, gpu_validation and later StateTracker Record will use.
create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
cgpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
cgpl_state->pipe_state.reserve(count);
for (uint32_t i = 0; i < count; i++) {
const auto &create_info = pCreateInfos[i];
auto layout_state = Get<PIPELINE_LAYOUT_STATE>(create_info.layout);
std::shared_ptr<const RENDER_PASS_STATE> render_pass;
if (pCreateInfos[i].renderPass != VK_NULL_HANDLE) {
render_pass = Get<RENDER_PASS_STATE>(create_info.renderPass);
} else if (enabled_features.core13.dynamicRendering) {
auto dynamic_rendering = LvlFindInChain<VkPipelineRenderingCreateInfo>(create_info.pNext);
render_pass = std::make_shared<RENDER_PASS_STATE>(dynamic_rendering);
} else {
const bool is_graphics_lib = GetGraphicsLibType(create_info) != static_cast<VkGraphicsPipelineLibraryFlagsEXT>(0);
const bool has_link_info = LvlFindInChain<VkPipelineLibraryCreateInfoKHR>(create_info.pNext) != nullptr;
if (!is_graphics_lib && !has_link_info) {
skip = true;
}
}
auto csm_states = (cgpl_state->shader_states.size() > i) ? &cgpl_state->shader_states[i] : nullptr;
cgpl_state->pipe_state.push_back(
CreateGraphicsPipelineState(&create_info, std::move(render_pass), std::move(layout_state), csm_states));
}
return skip;
}
void ValidationStateTracker::PostCallRecordCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
const VkGraphicsPipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
VkResult result, void *cgpl_state_data) {
create_graphics_pipeline_api_state *cgpl_state = reinterpret_cast<create_graphics_pipeline_api_state *>(cgpl_state_data);
// This API may create pipelines regardless of the return value
for (uint32_t i = 0; i < count; i++) {
if (pPipelines[i] != VK_NULL_HANDLE) {
(cgpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Add(std::move((cgpl_state->pipe_state)[i]));
}
}
cgpl_state->pipe_state.clear();
}
std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateComputePipelineState(
const VkComputePipelineCreateInfo *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
}
bool ValidationStateTracker::PreCallValidateCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
const VkComputePipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
void *ccpl_state_data) const {
auto *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
ccpl_state->pCreateInfos = pCreateInfos; // GPU validation can alter this, so we have to set a default value for the Chassis
ccpl_state->pipe_state.reserve(count);
for (uint32_t i = 0; i < count; i++) {
// Create and initialize internal tracking data structure
ccpl_state->pipe_state.push_back(
CreateComputePipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
}
return false;
}
void ValidationStateTracker::PostCallRecordCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t count,
const VkComputePipelineCreateInfo *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines,
VkResult result, void *ccpl_state_data) {
create_compute_pipeline_api_state *ccpl_state = reinterpret_cast<create_compute_pipeline_api_state *>(ccpl_state_data);
// This API may create pipelines regardless of the return value
for (uint32_t i = 0; i < count; i++) {
if (pPipelines[i] != VK_NULL_HANDLE) {
(ccpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Add(std::move((ccpl_state->pipe_state)[i]));
}
}
ccpl_state->pipe_state.clear();
}
std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
const VkRayTracingPipelineCreateInfoNV *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
}
bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesNV(VkDevice device, VkPipelineCache pipelineCache,
uint32_t count,
const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
const VkAllocationCallbacks *pAllocator,
VkPipeline *pPipelines, void *crtpl_state_data) const {
auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
crtpl_state->pipe_state.reserve(count);
for (uint32_t i = 0; i < count; i++) {
// Create and initialize internal tracking data structure
crtpl_state->pipe_state.push_back(
CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
}
return false;
}
void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesNV(
VkDevice device, VkPipelineCache pipelineCache, uint32_t count, const VkRayTracingPipelineCreateInfoNV *pCreateInfos,
const VkAllocationCallbacks *pAllocator, VkPipeline *pPipelines, VkResult result, void *crtpl_state_data) {
auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_api_state *>(crtpl_state_data);
// This API may create pipelines regardless of the return value
for (uint32_t i = 0; i < count; i++) {
if (pPipelines[i] != VK_NULL_HANDLE) {
(crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Add(std::move((crtpl_state->pipe_state)[i]));
}
}
crtpl_state->pipe_state.clear();
}
std::shared_ptr<PIPELINE_STATE> ValidationStateTracker::CreateRayTracingPipelineState(
const VkRayTracingPipelineCreateInfoKHR *pCreateInfo, std::shared_ptr<const PIPELINE_LAYOUT_STATE> &&layout) const {
return std::make_shared<PIPELINE_STATE>(this, pCreateInfo, std::move(layout));
}
bool ValidationStateTracker::PreCallValidateCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
VkPipelineCache pipelineCache, uint32_t count,
const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
const VkAllocationCallbacks *pAllocator,
VkPipeline *pPipelines, void *crtpl_state_data) const {
auto crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
crtpl_state->pipe_state.reserve(count);
for (uint32_t i = 0; i < count; i++) {
// Create and initialize internal tracking data structure
crtpl_state->pipe_state.push_back(
CreateRayTracingPipelineState(&pCreateInfos[i], Get<PIPELINE_LAYOUT_STATE>(pCreateInfos[i].layout)));
}
return false;
}
void ValidationStateTracker::PostCallRecordCreateRayTracingPipelinesKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
VkPipelineCache pipelineCache, uint32_t count,
const VkRayTracingPipelineCreateInfoKHR *pCreateInfos,
const VkAllocationCallbacks *pAllocator,
VkPipeline *pPipelines, VkResult result,
void *crtpl_state_data) {
auto *crtpl_state = reinterpret_cast<create_ray_tracing_pipeline_khr_api_state *>(crtpl_state_data);
const bool operation_is_deferred = (deferredOperation != VK_NULL_HANDLE && result == VK_OPERATION_DEFERRED_KHR);
// This API may create pipelines regardless of the return value
if (!operation_is_deferred) {
for (uint32_t i = 0; i < count; i++) {
if (pPipelines[i] != VK_NULL_HANDLE) {
(crtpl_state->pipe_state)[i]->SetHandle(pPipelines[i]);
Add(std::move((crtpl_state->pipe_state)[i]));
}
}
} else {
auto layer_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
if (wrap_handles) {
deferredOperation = layer_data->Unwrap(deferredOperation);
}
std::vector<std::function<void(const std::vector<VkPipeline> &)>> cleanup_fn;
auto find_res = layer_data->deferred_operation_post_check.pop(deferredOperation);
if (find_res->first) {
cleanup_fn = std::move(find_res->second);
}
auto &pipeline_states = crtpl_state->pipe_state;
// Mutable lambda because we want to move the shared pointer contained in the copied vector
cleanup_fn.emplace_back([this, pipeline_states](const std::vector<VkPipeline> &pipelines) mutable {
for (size_t i = 0; i < pipeline_states.size(); ++i) {
pipeline_states[i]->SetHandle(pipelines[i]);
this->Add(std::move(pipeline_states[i]));
}
});
layer_data->deferred_operation_post_check.insert(deferredOperation, cleanup_fn);
}
crtpl_state->pipe_state.clear();
}
void ValidationStateTracker::PostCallRecordCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSampler *pSampler,
VkResult result) {
Add(std::make_shared<SAMPLER_STATE>(pSampler, pCreateInfo));
if (pCreateInfo->borderColor == VK_BORDER_COLOR_INT_CUSTOM_EXT ||
pCreateInfo->borderColor == VK_BORDER_COLOR_FLOAT_CUSTOM_EXT) {
custom_border_color_sampler_count++;
}
}
void ValidationStateTracker::PostCallRecordCreateDescriptorSetLayout(VkDevice device,
const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkDescriptorSetLayout *pSetLayout, VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<cvdescriptorset::DescriptorSetLayout>(pCreateInfo, *pSetLayout));
}
void ValidationStateTracker::PostCallRecordGetDescriptorSetLayoutSizeEXT(VkDevice device, VkDescriptorSetLayout layout,
VkDeviceSize *pLayoutSizeInBytes) {
auto descriptor_set_layout = Get<cvdescriptorset::DescriptorSetLayout>(layout);
descriptor_set_layout->SetLayoutSizeInBytes(pLayoutSizeInBytes);
}
void ValidationStateTracker::PostCallRecordCreatePipelineLayout(VkDevice device, const VkPipelineLayoutCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkPipelineLayout *pPipelineLayout, VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<PIPELINE_LAYOUT_STATE>(this, *pPipelineLayout, pCreateInfo));
}
std::shared_ptr<DESCRIPTOR_POOL_STATE> ValidationStateTracker::CreateDescriptorPoolState(
VkDescriptorPool pool, const VkDescriptorPoolCreateInfo *pCreateInfo) {
return std::make_shared<DESCRIPTOR_POOL_STATE>(this, pool, pCreateInfo);
}
void ValidationStateTracker::PostCallRecordCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkDescriptorPool *pDescriptorPool, VkResult result) {
if (VK_SUCCESS != result) return;
Add(CreateDescriptorPoolState(*pDescriptorPool, pCreateInfo));
}
void ValidationStateTracker::PostCallRecordResetDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool,
VkDescriptorPoolResetFlags flags, VkResult result) {
if (VK_SUCCESS != result) return;
auto pool = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
if (pool) {
pool->Reset();
}
}
bool ValidationStateTracker::PreCallValidateAllocateDescriptorSets(VkDevice device,
const VkDescriptorSetAllocateInfo *pAllocateInfo,
VkDescriptorSet *pDescriptorSets, void *ads_state_data) const {
// Always update common data
cvdescriptorset::AllocateDescriptorSetsData *ads_state =
reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
UpdateAllocateDescriptorSetsData(pAllocateInfo, ads_state);
return false;
}
// Allocation state was good and call down chain was made so update state based on allocating descriptor sets
void ValidationStateTracker::PostCallRecordAllocateDescriptorSets(VkDevice device, const VkDescriptorSetAllocateInfo *pAllocateInfo,
VkDescriptorSet *pDescriptorSets, VkResult result,
void *ads_state_data) {
if (VK_SUCCESS != result) return;
// All the updates are contained in a single cvdescriptorset function
cvdescriptorset::AllocateDescriptorSetsData *ads_state =
reinterpret_cast<cvdescriptorset::AllocateDescriptorSetsData *>(ads_state_data);
auto pool_state = Get<DESCRIPTOR_POOL_STATE>(pAllocateInfo->descriptorPool);
if (pool_state) {
pool_state->Allocate(pAllocateInfo, pDescriptorSets, ads_state);
}
}
void ValidationStateTracker::PreCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t count,
const VkDescriptorSet *pDescriptorSets) {
auto pool_state = Get<DESCRIPTOR_POOL_STATE>(descriptorPool);
if (pool_state) {
pool_state->Free(count, pDescriptorSets);
}
}
void ValidationStateTracker::PreCallRecordUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount,
const VkWriteDescriptorSet *pDescriptorWrites,
uint32_t descriptorCopyCount,
const VkCopyDescriptorSet *pDescriptorCopies) {
cvdescriptorset::PerformUpdateDescriptorSets(this, descriptorWriteCount, pDescriptorWrites, descriptorCopyCount,
pDescriptorCopies);
}
void ValidationStateTracker::PostCallRecordAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pCreateInfo,
VkCommandBuffer *pCommandBuffers, VkResult result) {
if (VK_SUCCESS != result) return;
auto pool = Get<COMMAND_POOL_STATE>(pCreateInfo->commandPool);
if (pool) {
pool->Allocate(pCreateInfo, pCommandBuffers);
}
}
void ValidationStateTracker::PreCallRecordBeginCommandBuffer(VkCommandBuffer commandBuffer,
const VkCommandBufferBeginInfo *pBeginInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (!cb_state) return;
cb_state->Begin(pBeginInfo);
}
void ValidationStateTracker::PostCallRecordEndCommandBuffer(VkCommandBuffer commandBuffer, VkResult result) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (!cb_state) return;
cb_state->End(result);
}
void ValidationStateTracker::PostCallRecordResetCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferResetFlags flags,
VkResult result) {
if (VK_SUCCESS == result) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->Reset();
}
}
}
// Validation cache:
// CV is the bottommost implementor of this extension. Don't pass calls down.
void ValidationStateTracker::PreCallRecordCmdBindPipeline(VkCommandBuffer commandBuffer, VkPipelineBindPoint pipelineBindPoint,
VkPipeline pipeline) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
assert(cb_state);
cb_state->RecordCmd(CMD_BINDPIPELINE);
auto pipe_state = Get<PIPELINE_STATE>(pipeline);
if (VK_PIPELINE_BIND_POINT_GRAPHICS == pipelineBindPoint) {
const auto *raster_state = pipe_state->RasterizationState();
const bool rasterization_enabled = raster_state && !raster_state->rasterizerDiscardEnable;
const auto *viewport_state = pipe_state->ViewportState();
const auto *dynamic_state = pipe_state->DynamicState();
cb_state->status &= ~cb_state->static_status;
cb_state->static_status = MakeStaticStateMask(dynamic_state ? dynamic_state->ptr() : nullptr);
cb_state->status |= cb_state->static_status;
cb_state->dynamic_status = ~CBDynamicFlags(0);
cb_state->dynamic_status &= ~cb_state->static_status;
// Used to calculate CMD_BUFFER_STATE::usedViewportScissorCount upon draw command with this graphics pipeline.
// If rasterization disabled (no viewport/scissors used), or the actual number of viewports/scissors is dynamic (unknown at
// this time), then these are set to 0 to disable this checking.
auto has_dynamic_viewport_count = cb_state->dynamic_status[CB_DYNAMIC_VIEWPORT_WITH_COUNT_SET];
auto has_dynamic_scissor_count = cb_state->dynamic_status[CB_DYNAMIC_SCISSOR_WITH_COUNT_SET];
cb_state->pipelineStaticViewportCount =
has_dynamic_viewport_count || !rasterization_enabled ? 0 : viewport_state->viewportCount;
cb_state->pipelineStaticScissorCount =
has_dynamic_scissor_count || !rasterization_enabled ? 0 : viewport_state->scissorCount;
// Trash dynamic viewport/scissor state if pipeline defines static state and enabled rasterization.
// akeley98 NOTE: There's a bit of an ambiguity in the spec, whether binding such a pipeline overwrites
// the entire viewport (scissor) array, or only the subsection defined by the viewport (scissor) count.
// I am taking the latter interpretation based on the implementation details of NVIDIA's Vulkan driver.
if (!has_dynamic_viewport_count) {
cb_state->trashedViewportCount = true;
if (rasterization_enabled && (cb_state->static_status[CB_DYNAMIC_VIEWPORT_SET])) {
cb_state->trashedViewportMask |= (uint32_t(1) << viewport_state->viewportCount) - 1u;
// should become = ~uint32_t(0) if the other interpretation is correct.
}
}
if (!has_dynamic_scissor_count) {
cb_state->trashedScissorCount = true;
if (rasterization_enabled && (cb_state->static_status[CB_DYNAMIC_SCISSOR_SET])) {
cb_state->trashedScissorMask |= (uint32_t(1) << viewport_state->scissorCount) - 1u;
// should become = ~uint32_t(0) if the other interpretation is correct.
}
}
}
cb_state->BindPipeline(ConvertToLvlBindPoint(pipelineBindPoint), pipe_state.get());
if (!disabled[command_buffer_state]) {
cb_state->AddChild(pipe_state);
}
}
void ValidationStateTracker::PostCallRecordCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport,
uint32_t viewportCount, const VkViewport *pViewports) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETVIEWPORT, CB_DYNAMIC_VIEWPORT_SET);
uint32_t bits = ((1u << viewportCount) - 1u) << firstViewport;
cb_state->viewportMask |= bits;
cb_state->trashedViewportMask &= ~bits;
cb_state->dynamicViewports.resize(std::max(size_t(firstViewport + viewportCount), cb_state->dynamicViewports.size()));
for (size_t i = 0; i < viewportCount; ++i) {
cb_state->dynamicViewports[firstViewport + i] = pViewports[i];
}
}
void ValidationStateTracker::PostCallRecordCmdSetExclusiveScissorNV(VkCommandBuffer commandBuffer, uint32_t firstExclusiveScissor,
uint32_t exclusiveScissorCount,
const VkRect2D *pExclusiveScissors) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETEXCLUSIVESCISSORNV, CB_DYNAMIC_EXCLUSIVE_SCISSOR_NV_SET);
// TODO: We don't have VUIDs for validating that all exclusive scissors have been set.
// cb_state->exclusiveScissorMask |= ((1u << exclusiveScissorCount) - 1u) << firstExclusiveScissor;
}
void ValidationStateTracker::PreCallRecordCmdBindShadingRateImageNV(VkCommandBuffer commandBuffer, VkImageView imageView,
VkImageLayout imageLayout) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_BINDSHADINGRATEIMAGENV);
if (imageView != VK_NULL_HANDLE) {
auto view_state = Get<IMAGE_VIEW_STATE>(imageView);
cb_state->AddChild(view_state);
}
}
void ValidationStateTracker::PostCallRecordCmdSetViewportShadingRatePaletteNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
uint32_t viewportCount,
const VkShadingRatePaletteNV *pShadingRatePalettes) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETVIEWPORTSHADINGRATEPALETTENV, CB_DYNAMIC_VIEWPORT_SHADING_RATE_PALETTE_NV_SET);
// TODO: We don't have VUIDs for validating that all shading rate palettes have been set.
// cb_state->shadingRatePaletteMask |= ((1u << viewportCount) - 1u) << firstViewport;
}
void ValidationStateTracker::PostCallRecordCreateAccelerationStructureNV(VkDevice device,
const VkAccelerationStructureCreateInfoNV *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkAccelerationStructureNV *pAccelerationStructure,
VkResult result) {
if (VK_SUCCESS != result) return;
std::shared_ptr<ACCELERATION_STRUCTURE_STATE> state =
std::make_shared<ACCELERATION_STRUCTURE_STATE_LINEAR>(device, *pAccelerationStructure, pCreateInfo);
Add(std::move(state));
}
void ValidationStateTracker::PostCallRecordCreateAccelerationStructureKHR(VkDevice device,
const VkAccelerationStructureCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkAccelerationStructureKHR *pAccelerationStructure,
VkResult result) {
if (VK_SUCCESS != result) return;
auto buffer_state = Get<BUFFER_STATE>(pCreateInfo->buffer);
Add(std::make_shared<ACCELERATION_STRUCTURE_STATE_KHR>(*pAccelerationStructure, pCreateInfo, std::move(buffer_state)));
}
void ValidationStateTracker::PostCallRecordBuildAccelerationStructuresKHR(
VkDevice device, VkDeferredOperationKHR deferredOperation, uint32_t infoCount,
const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos, VkResult result) {
for (uint32_t i = 0; i < infoCount; ++i) {
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfos[i].dstAccelerationStructure);
if (dst_as_state != nullptr) {
dst_as_state->Build(&pInfos[i], true, *ppBuildRangeInfos);
}
}
}
// helper method for device side acceleration structure builds
void ValidationStateTracker::RecordDeviceAccelerationStructureBuildInfo(CMD_BUFFER_STATE &cb_state,
const VkAccelerationStructureBuildGeometryInfoKHR &info) {
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.dstAccelerationStructure);
if (dst_as_state) {
dst_as_state->Build(&info, false, nullptr);
}
if (disabled[command_buffer_state]) {
return;
}
if (dst_as_state) {
cb_state.AddChild(dst_as_state);
}
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(info.srcAccelerationStructure);
if (src_as_state) {
cb_state.AddChild(src_as_state);
}
auto scratch_buffers = GetBuffersByAddress(info.scratchData.deviceAddress);
if (!scratch_buffers.empty()) {
cb_state.AddChildren(scratch_buffers);
}
for (uint32_t i = 0; i < info.geometryCount; i++) {
// only one of pGeometries and ppGeometries can be non-null
const auto &geom = info.pGeometries ? info.pGeometries[i] : *info.ppGeometries[i];
switch (geom.geometryType) {
case VK_GEOMETRY_TYPE_TRIANGLES_KHR: {
auto vertex_buffers = GetBuffersByAddress(geom.geometry.triangles.vertexData.deviceAddress);
if (!vertex_buffers.empty()) {
cb_state.AddChildren(vertex_buffers);
}
auto index_buffers = GetBuffersByAddress(geom.geometry.triangles.indexData.deviceAddress);
if (!index_buffers.empty()) {
cb_state.AddChildren(index_buffers);
}
auto transform_buffers = GetBuffersByAddress(geom.geometry.triangles.transformData.deviceAddress);
if (!transform_buffers.empty()) {
cb_state.AddChildren(transform_buffers);
}
const auto *motion_data = LvlFindInChain<VkAccelerationStructureGeometryMotionTrianglesDataNV>(info.pNext);
if (motion_data) {
auto motion_buffers = GetBuffersByAddress(motion_data->vertexData.deviceAddress);
if (!motion_buffers.empty()) {
cb_state.AddChildren(motion_buffers);
}
}
} break;
case VK_GEOMETRY_TYPE_AABBS_KHR: {
auto data_buffers = GetBuffersByAddress(geom.geometry.aabbs.data.deviceAddress);
if (!data_buffers.empty()) {
cb_state.AddChildren(data_buffers);
}
} break;
case VK_GEOMETRY_TYPE_INSTANCES_KHR: {
// NOTE: if arrayOfPointers is true, we don't track the pointers in the array. That would
// require that data buffer be mapped to the CPU so that we could walk through it. We can't
// easily ensure that's true.
auto data_buffers = GetBuffersByAddress(geom.geometry.instances.data.deviceAddress);
if (!data_buffers.empty()) {
cb_state.AddChildren(data_buffers);
}
} break;
default:
break;
}
}
}
void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresKHR(
VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (!cb_state) {
return;
}
cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESKHR);
for (uint32_t i = 0; i < infoCount; i++) {
RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
}
cb_state->has_build_as_cmd = true;
}
void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructuresIndirectKHR(
VkCommandBuffer commandBuffer, uint32_t infoCount, const VkAccelerationStructureBuildGeometryInfoKHR *pInfos,
const VkDeviceAddress *pIndirectDeviceAddresses, const uint32_t *pIndirectStrides,
const uint32_t *const *ppMaxPrimitiveCounts) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (!cb_state) {
return;
}
cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURESINDIRECTKHR);
for (uint32_t i = 0; i < infoCount; i++) {
RecordDeviceAccelerationStructureBuildInfo(*cb_state, pInfos[i]);
if (!disabled[command_buffer_state]) {
auto indirect_buffer = GetBuffersByAddress(pIndirectDeviceAddresses[i]);
if (!indirect_buffer.empty()) {
cb_state->AddChildren(indirect_buffer);
}
}
}
cb_state->has_build_as_cmd = true;
}
void ValidationStateTracker::PostCallRecordGetAccelerationStructureMemoryRequirementsNV(
VkDevice device, const VkAccelerationStructureMemoryRequirementsInfoNV *pInfo, VkMemoryRequirements2 *pMemoryRequirements) {
auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(pInfo->accelerationStructure);
if (as_state != nullptr) {
if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_OBJECT_NV) {
as_state->memory_requirements_checked = true;
} else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_BUILD_SCRATCH_NV) {
as_state->build_scratch_memory_requirements_checked = true;
} else if (pInfo->type == VK_ACCELERATION_STRUCTURE_MEMORY_REQUIREMENTS_TYPE_UPDATE_SCRATCH_NV) {
as_state->update_scratch_memory_requirements_checked = true;
}
}
}
void ValidationStateTracker::PostCallRecordBindAccelerationStructureMemoryNV(
VkDevice device, uint32_t bindInfoCount, const VkBindAccelerationStructureMemoryInfoNV *pBindInfos, VkResult result) {
if (VK_SUCCESS != result) return;
for (uint32_t i = 0; i < bindInfoCount; i++) {
const VkBindAccelerationStructureMemoryInfoNV &info = pBindInfos[i];
auto as_state = Get<ACCELERATION_STRUCTURE_STATE>(info.accelerationStructure);
if (as_state) {
// Track objects tied to memory
auto mem_state = Get<DEVICE_MEMORY_STATE>(info.memory);
if (mem_state) {
as_state->BindMemory(as_state.get(), mem_state, info.memoryOffset, 0u, as_state->memory_requirements.size);
}
// GPU validation of top level acceleration structure building needs acceleration structure handles.
// XXX TODO: Query device address for KHR extension
if (enabled[gpu_validation]) {
DispatchGetAccelerationStructureHandleNV(device, info.accelerationStructure, 8, &as_state->opaque_handle);
}
}
}
}
void ValidationStateTracker::PostCallRecordCmdBuildAccelerationStructureNV(
VkCommandBuffer commandBuffer, const VkAccelerationStructureInfoNV *pInfo, VkBuffer instanceData, VkDeviceSize instanceOffset,
VkBool32 update, VkAccelerationStructureNV dst, VkAccelerationStructureNV src, VkBuffer scratch, VkDeviceSize scratchOffset) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (!cb_state) {
return;
}
cb_state->RecordCmd(CMD_BUILDACCELERATIONSTRUCTURENV);
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
if (dst_as_state) {
dst_as_state->Build(pInfo);
if (!disabled[command_buffer_state]) {
cb_state->AddChild(dst_as_state);
}
}
if (!disabled[command_buffer_state]) {
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
if (src_as_state) {
cb_state->AddChild(src_as_state);
}
auto instance_buffer = Get<BUFFER_STATE>(instanceData);
if (instance_buffer) {
cb_state->AddChild(instance_buffer);
}
auto scratch_buffer = Get<BUFFER_STATE>(scratch);
if (scratch_buffer) {
cb_state->AddChild(scratch_buffer);
}
for (uint32_t i = 0; i < pInfo->geometryCount; i++) {
const auto& geom = pInfo->pGeometries[i];
auto vertex_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.vertexData);
if (vertex_buffer) {
cb_state->AddChild(vertex_buffer);
}
auto index_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.indexData);
if (index_buffer) {
cb_state->AddChild(index_buffer);
}
auto transform_buffer = Get<BUFFER_STATE>(geom.geometry.triangles.transformData);
if (transform_buffer) {
cb_state->AddChild(transform_buffer);
}
auto aabb_buffer = Get<BUFFER_STATE>(geom.geometry.aabbs.aabbData);
if (aabb_buffer) {
cb_state->AddChild(aabb_buffer);
}
}
}
cb_state->has_build_as_cmd = true;
}
void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureNV(VkCommandBuffer commandBuffer,
VkAccelerationStructureNV dst,
VkAccelerationStructureNV src,
VkCopyAccelerationStructureModeNV mode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE>(src);
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE>(dst);
if (!disabled[command_buffer_state]) {
cb_state->RecordTransferCmd(CMD_COPYACCELERATIONSTRUCTURENV, src_as_state, dst_as_state);
}
if (dst_as_state != nullptr && src_as_state != nullptr) {
dst_as_state->built = true;
dst_as_state->build_info = src_as_state->build_info;
}
}
}
void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureKHR(VkDevice device,
VkAccelerationStructureKHR accelerationStructure,
const VkAllocationCallbacks *pAllocator) {
Destroy<ACCELERATION_STRUCTURE_STATE_KHR>(accelerationStructure);
}
void ValidationStateTracker::PreCallRecordDestroyAccelerationStructureNV(VkDevice device,
VkAccelerationStructureNV accelerationStructure,
const VkAllocationCallbacks *pAllocator) {
Destroy<ACCELERATION_STRUCTURE_STATE>(accelerationStructure);
}
void ValidationStateTracker::PostCallRecordCmdSetViewportWScalingNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
uint32_t viewportCount,
const VkViewportWScalingNV *pViewportWScalings) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGNV, CB_DYNAMIC_VIEWPORT_W_SCALING_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLINEWIDTH, CB_DYNAMIC_LINE_WIDTH_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLineStippleEXT(VkCommandBuffer commandBuffer, uint32_t lineStippleFactor,
uint16_t lineStipplePattern) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLINESTIPPLEEXT, CB_DYNAMIC_LINE_STIPPLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBias(VkCommandBuffer commandBuffer, float depthBiasConstantFactor,
float depthBiasClamp, float depthBiasSlopeFactor) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHBIAS, CB_DYNAMIC_DEPTH_BIAS_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor,
uint32_t scissorCount, const VkRect2D *pScissors) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSCISSOR, CB_DYNAMIC_SCISSOR_SET);
uint32_t bits = ((1u << scissorCount) - 1u) << firstScissor;
cb_state->scissorMask |= bits;
cb_state->trashedScissorMask &= ~bits;
}
void ValidationStateTracker::PostCallRecordCmdSetBlendConstants(VkCommandBuffer commandBuffer, const float blendConstants[4]) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETBLENDCONSTANTS, CB_DYNAMIC_BLEND_CONSTANTS_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBounds(VkCommandBuffer commandBuffer, float minDepthBounds,
float maxDepthBounds) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHBOUNDS, CB_DYNAMIC_DEPTH_BOUNDS_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetStencilCompareMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
uint32_t compareMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSTENCILCOMPAREMASK, CB_DYNAMIC_STENCIL_COMPARE_MASK_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetStencilWriteMask(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
uint32_t writeMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSTENCILWRITEMASK, CB_DYNAMIC_STENCIL_WRITE_MASK_SET);
if (faceMask == VK_STENCIL_FACE_FRONT_BIT || faceMask == VK_STENCIL_FACE_FRONT_AND_BACK) {
cb_state->dynamic_state_value.write_mask_front = writeMask;
}
if (faceMask == VK_STENCIL_FACE_BACK_BIT || faceMask == VK_STENCIL_FACE_FRONT_AND_BACK) {
cb_state->dynamic_state_value.write_mask_back = writeMask;
}
}
void ValidationStateTracker::PostCallRecordCmdSetStencilReference(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
uint32_t reference) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSTENCILREFERENCE, CB_DYNAMIC_STENCIL_REFERENCE_SET);
}
// Update the bound state for the bind point, including the effects of incompatible pipeline layouts
void ValidationStateTracker::PreCallRecordCmdBindDescriptorSets(VkCommandBuffer commandBuffer,
VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
uint32_t firstSet, uint32_t setCount,
const VkDescriptorSet *pDescriptorSets, uint32_t dynamicOffsetCount,
const uint32_t *pDynamicOffsets) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
if (!cb_state || !pipeline_layout) {
return;
}
cb_state->RecordCmd(CMD_BINDDESCRIPTORSETS);
std::shared_ptr<cvdescriptorset::DescriptorSet> no_push_desc;
cb_state->UpdateLastBoundDescriptorSets(pipelineBindPoint, *pipeline_layout, firstSet, setCount, pDescriptorSets, no_push_desc,
dynamicOffsetCount, pDynamicOffsets);
}
void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer,
VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout,
uint32_t set, uint32_t descriptorWriteCount,
const VkWriteDescriptorSet *pDescriptorWrites) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
cb_state->PushDescriptorSetState(pipelineBindPoint, *pipeline_layout, set, descriptorWriteCount, pDescriptorWrites);
}
void ValidationStateTracker::PreCallRecordCmdBindDescriptorBuffersEXT(VkCommandBuffer commandBuffer, uint32_t bufferCount,
const VkDescriptorBufferBindingInfoEXT *pBindingInfos) {
auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->descriptor_buffer_binding_info.resize(bufferCount);
std::copy(pBindingInfos, pBindingInfos + bufferCount, cb_state->descriptor_buffer_binding_info.data());
}
void ValidationStateTracker::PreCallRecordCmdSetDescriptorBufferOffsetsEXT(VkCommandBuffer commandBuffer,
VkPipelineBindPoint pipelineBindPoint,
VkPipelineLayout layout, uint32_t firstSet,
uint32_t setCount, const uint32_t *pBufferIndices,
const VkDeviceSize *pOffsets) {
auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
auto pipeline_layout = Get<PIPELINE_LAYOUT_STATE>(layout);
cb_state->UpdateLastBoundDescriptorBuffers(pipelineBindPoint, *pipeline_layout, firstSet, setCount, pBufferIndices, pOffsets);
}
void ValidationStateTracker::PostCallRecordCmdPushConstants(VkCommandBuffer commandBuffer, VkPipelineLayout layout,
VkShaderStageFlags stageFlags, uint32_t offset, uint32_t size,
const void *pValues) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordCmd(CMD_PUSHCONSTANTS);
auto layout_state = Get<PIPELINE_LAYOUT_STATE>(layout);
cb_state->ResetPushConstantDataIfIncompatible(layout_state.get());
auto &push_constant_data = cb_state->push_constant_data;
assert((offset + size) <= static_cast<uint32_t>(push_constant_data.size()));
std::memcpy(push_constant_data.data() + offset, pValues, static_cast<std::size_t>(size));
cb_state->push_constant_pipeline_layout_set = layout;
auto flags = stageFlags;
uint32_t bit_shift = 0;
while (flags) {
if (flags & 1) {
VkShaderStageFlagBits flag = static_cast<VkShaderStageFlagBits>(1 << bit_shift);
const auto it = cb_state->push_constant_data_update.find(flag);
if (it != cb_state->push_constant_data_update.end()) {
std::memset(it->second.data() + offset, PC_Byte_Updated, static_cast<std::size_t>(size));
}
}
flags = flags >> 1;
++bit_shift;
}
}
}
void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkIndexType indexType) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
cb_state->index_buffer_binding.offset = offset;
cb_state->index_buffer_binding.index_type = indexType;
// Add binding for this index buffer to this commandbuffer
if (!disabled[command_buffer_state]) {
cb_state->AddChild(cb_state->index_buffer_binding.buffer_state);
}
}
void ValidationStateTracker::PreCallRecordCmdBindVertexBuffers(VkCommandBuffer commandBuffer, uint32_t firstBinding,
uint32_t bindingCount, const VkBuffer *pBuffers,
const VkDeviceSize *pOffsets) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_BINDVERTEXBUFFERS);
uint32_t end = firstBinding + bindingCount;
if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
}
for (uint32_t i = 0; i < bindingCount; ++i) {
auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
vertex_buffer_binding.offset = pOffsets[i];
vertex_buffer_binding.size = VK_WHOLE_SIZE;
vertex_buffer_binding.stride = 0;
// Add binding for this vertex buffer to this commandbuffer
if (pBuffers[i] && !disabled[command_buffer_state]) {
cb_state->AddChild(vertex_buffer_binding.buffer_state);
}
}
}
void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer,
VkDeviceSize dstOffset, VkDeviceSize dataSize, const void *pData) {
if (disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordTransferCmd(CMD_UPDATEBUFFER, Get<BUFFER_STATE>(dstBuffer));
}
void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags stageMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
}
void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
const VkDependencyInfoKHR *pDependencyInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
cb_state->RecordBarriers(*pDependencyInfo);
}
void ValidationStateTracker::PreCallRecordCmdSetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
const VkDependencyInfo* pDependencyInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);
cb_state->RecordSetEvent(CMD_SETEVENT2, event, stage_masks.src);
cb_state->RecordBarriers(*pDependencyInfo);
}
void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags stageMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
}
void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags2KHR stageMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
}
void ValidationStateTracker::PreCallRecordCmdResetEvent2(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags2 stageMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordResetEvent(CMD_RESETEVENT2, event, stageMask);
}
void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
VkPipelineStageFlags sourceStageMask, VkPipelineStageFlags dstStageMask,
uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents, sourceStageMask);
cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
}
void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
for (uint32_t i = 0; i < eventCount; i++) {
const auto &dep_info = pDependencyInfos[i];
auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, 1, &pEvents[i], stage_masks.src);
cb_state->RecordBarriers(dep_info);
}
}
void ValidationStateTracker::PreCallRecordCmdWaitEvents2(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
const VkDependencyInfo *pDependencyInfos) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
for (uint32_t i = 0; i < eventCount; i++) {
const auto &dep_info = pDependencyInfos[i];
auto stage_masks = sync_utils::GetGlobalStageMasks(dep_info);
cb_state->RecordWaitEvents(CMD_WAITEVENTS2, 1, &pEvents[i], stage_masks.src);
cb_state->RecordBarriers(dep_info);
}
}
void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_PIPELINEBARRIER);
cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
}
void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
const VkDependencyInfoKHR *pDependencyInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
cb_state->RecordBarriers(*pDependencyInfo);
}
void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2(VkCommandBuffer commandBuffer,
const VkDependencyInfo *pDependencyInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_PIPELINEBARRIER2);
cb_state->RecordBarriers(*pDependencyInfo);
}
void ValidationStateTracker::PostCallRecordCmdBeginQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot,
VkFlags flags) {
if (disabled[query_validation]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
uint32_t num_queries = 1;
// If render pass instance has multiview enabled, query uses N consecutive query indices
if (cb_state->activeRenderPass) {
uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
num_queries = std::max(num_queries, bits);
}
for (uint32_t i = 0; i < num_queries; ++i) {
QueryObject query = {queryPool, slot};
cb_state->RecordCmd(CMD_BEGINQUERY);
if (!disabled[query_validation]) {
cb_state->BeginQuery(query);
}
if (!disabled[command_buffer_state]) {
auto pool_state = Get<QUERY_POOL_STATE>(query.pool);
cb_state->AddChild(pool_state);
}
}
}
void ValidationStateTracker::PostCallRecordCmdEndQuery(VkCommandBuffer commandBuffer, VkQueryPool queryPool, uint32_t slot) {
if (disabled[query_validation]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
uint32_t num_queries = 1;
// If render pass instance has multiview enabled, query uses N consecutive query indices
if (cb_state->activeRenderPass) {
uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
num_queries = std::max(num_queries, bits);
}
for (uint32_t i = 0; i < num_queries; ++i) {
QueryObject query_obj = {queryPool, slot + i};
cb_state->RecordCmd(CMD_ENDQUERY);
if (!disabled[query_validation]) {
cb_state->EndQuery(query_obj);
}
if (!disabled[command_buffer_state]) {
auto pool_state = Get<QUERY_POOL_STATE>(query_obj.pool);
cb_state->AddChild(pool_state);
}
}
}
void ValidationStateTracker::PostCallRecordCmdResetQueryPool(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
uint32_t firstQuery, uint32_t queryCount) {
if (disabled[query_validation]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_RESETQUERYPOOL);
cb_state->ResetQueryPool(queryPool, firstQuery, queryCount);
if (!disabled[command_buffer_state]) {
auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
cb_state->AddChild(pool_state);
}
}
void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
uint32_t firstQuery, uint32_t queryCount, VkBuffer dstBuffer,
VkDeviceSize dstOffset, VkDeviceSize stride,
VkQueryResultFlags flags) {
if (disabled[query_validation] || disabled[command_buffer_state]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_COPYQUERYPOOLRESULTS);
auto dst_buff_state = Get<BUFFER_STATE>(dstBuffer);
cb_state->AddChild(dst_buff_state);
auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
cb_state->AddChild(pool_state);
}
void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
VkQueryPool queryPool, uint32_t slot) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
}
void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
uint32_t slot) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
}
void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2(VkCommandBuffer commandBuffer, VkPipelineStageFlags2 pipelineStage,
VkQueryPool queryPool, uint32_t slot) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2, pipelineStage, queryPool, slot);
}
void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
VkCommandBuffer commandBuffer, uint32_t accelerationStructureCount, const VkAccelerationStructureKHR *pAccelerationStructures,
VkQueryType queryType, VkQueryPool queryPool, uint32_t firstQuery) {
if (disabled[query_validation]) return;
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_WRITEACCELERATIONSTRUCTURESPROPERTIESKHR);
if (!disabled[command_buffer_state]) {
auto pool_state = Get<QUERY_POOL_STATE>(queryPool);
cb_state->AddChild(pool_state);
}
cb_state->EndQueries(queryPool, firstQuery, accelerationStructureCount);
}
void ValidationStateTracker::PostCallRecordCreateVideoSessionKHR(VkDevice device, const VkVideoSessionCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkVideoSessionKHR *pVideoSession, VkResult result) {
if (VK_SUCCESS != result) return;
auto profile_desc = video_profile_cache_.Get(this, pCreateInfo->pVideoProfile);
Add(std::make_shared<VIDEO_SESSION_STATE>(this, *pVideoSession, pCreateInfo, std::move(profile_desc)));
}
void ValidationStateTracker::PostCallRecordGetVideoSessionMemoryRequirementsKHR(
VkDevice device, VkVideoSessionKHR videoSession, uint32_t *pMemoryRequirementsCount,
VkVideoSessionMemoryRequirementsKHR *pMemoryRequirements, VkResult result) {
if (VK_SUCCESS != result) return;
auto vs_state = Get<VIDEO_SESSION_STATE>(videoSession);
assert(vs_state);
if (pMemoryRequirements != nullptr) {
if (*pMemoryRequirementsCount > vs_state->memory_bindings_queried) {
vs_state->memory_bindings_queried = *pMemoryRequirementsCount;
}
} else {
vs_state->memory_binding_count_queried = true;
}
}
void ValidationStateTracker::PostCallRecordBindVideoSessionMemoryKHR(VkDevice device, VkVideoSessionKHR videoSession,
uint32_t bindSessionMemoryInfoCount,
const VkBindVideoSessionMemoryInfoKHR *pBindSessionMemoryInfos,
VkResult result) {
if (VK_SUCCESS != result) return;
auto vs_state = Get<VIDEO_SESSION_STATE>(videoSession);
assert(vs_state);
for (uint32_t i = 0; i < bindSessionMemoryInfoCount; ++i) {
vs_state->BindMemoryBindingIndex(pBindSessionMemoryInfos[i].memoryBindIndex);
}
}
void ValidationStateTracker::PreCallRecordDestroyVideoSessionKHR(VkDevice device, VkVideoSessionKHR videoSession,
const VkAllocationCallbacks *pAllocator) {
Destroy<VIDEO_SESSION_STATE>(videoSession);
}
void ValidationStateTracker::PostCallRecordCreateVideoSessionParametersKHR(VkDevice device,
const VkVideoSessionParametersCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkVideoSessionParametersKHR *pVideoSessionParameters,
VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<VIDEO_SESSION_PARAMETERS_STATE>(
*pVideoSessionParameters, pCreateInfo, Get<VIDEO_SESSION_STATE>(pCreateInfo->videoSession),
Get<VIDEO_SESSION_PARAMETERS_STATE>(pCreateInfo->videoSessionParametersTemplate)));
}
void ValidationStateTracker::PostCallRecordUpdateVideoSessionParametersKHR(VkDevice device,
VkVideoSessionParametersKHR videoSessionParameters,
const VkVideoSessionParametersUpdateInfoKHR *pUpdateInfo,
VkResult result) {
if (VK_SUCCESS != result) return;
Get<VIDEO_SESSION_PARAMETERS_STATE>(videoSessionParameters)->Update(pUpdateInfo);
}
void ValidationStateTracker::PreCallRecordDestroyVideoSessionParametersKHR(VkDevice device,
VkVideoSessionParametersKHR videoSessionParameters,
const VkAllocationCallbacks *pAllocator) {
Destroy<VIDEO_SESSION_PARAMETERS_STATE>(videoSessionParameters);
}
void ValidationStateTracker::PostCallRecordCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
VkResult result) {
if (VK_SUCCESS != result) return;
std::vector<std::shared_ptr<IMAGE_VIEW_STATE>> views;
if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
views.resize(pCreateInfo->attachmentCount);
for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
views[i] = Get<IMAGE_VIEW_STATE>(pCreateInfo->pAttachments[i]);
}
}
Add(std::make_shared<FRAMEBUFFER_STATE>(*pFramebuffer, pCreateInfo, Get<RENDER_PASS_STATE>(pCreateInfo->renderPass),
std::move(views)));
}
void ValidationStateTracker::PostCallRecordCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
}
void ValidationStateTracker::PostCallRecordCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
}
void ValidationStateTracker::PostCallRecordCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<RENDER_PASS_STATE>(*pRenderPass, pCreateInfo));
}
void ValidationStateTracker::PreCallRecordCmdBeginRenderPass(VkCommandBuffer commandBuffer,
const VkRenderPassBeginInfo *pRenderPassBegin,
VkSubpassContents contents) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginRenderPass(CMD_BEGINRENDERPASS, pRenderPassBegin, contents);
}
void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer,
const VkRenderPassBeginInfo *pRenderPassBegin,
const VkSubpassBeginInfo *pSubpassBeginInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2KHR, pRenderPassBegin, pSubpassBeginInfo->contents);
}
void ValidationStateTracker::PreCallRecordCmdBeginVideoCodingKHR(VkCommandBuffer commandBuffer,
const VkVideoBeginCodingInfoKHR *pBeginInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginVideoCoding(pBeginInfo);
}
void ValidationStateTracker::PostCallRecordCmdBeginTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
uint32_t counterBufferCount,
const VkBuffer *pCounterBuffers,
const VkDeviceSize *pCounterBufferOffsets) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_BEGINTRANSFORMFEEDBACKEXT);
cb_state->transform_feedback_active = true;
}
void ValidationStateTracker::PostCallRecordCmdEndTransformFeedbackEXT(VkCommandBuffer commandBuffer, uint32_t firstCounterBuffer,
uint32_t counterBufferCount, const VkBuffer *pCounterBuffers,
const VkDeviceSize *pCounterBufferOffsets) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_ENDTRANSFORMFEEDBACKEXT);
cb_state->transform_feedback_active = false;
}
void ValidationStateTracker::PostCallRecordCmdBeginConditionalRenderingEXT(
VkCommandBuffer commandBuffer, const VkConditionalRenderingBeginInfoEXT *pConditionalRenderingBegin) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_BEGINCONDITIONALRENDERINGEXT);
cb_state->conditional_rendering_active = true;
cb_state->conditional_rendering_inside_render_pass = cb_state->activeRenderPass != nullptr;
cb_state->conditional_rendering_subpass = cb_state->activeSubpass;
}
void ValidationStateTracker::PostCallRecordCmdEndConditionalRenderingEXT(VkCommandBuffer commandBuffer) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_ENDCONDITIONALRENDERINGEXT);
cb_state->conditional_rendering_active = false;
cb_state->conditional_rendering_inside_render_pass = false;
cb_state->conditional_rendering_subpass = 0;
}
void ValidationStateTracker::RecordCmdEndRenderingRenderPassState(VkCommandBuffer commandBuffer) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->activeRenderPass = nullptr;
}
void ValidationStateTracker::PreCallRecordCmdBeginRenderingKHR(VkCommandBuffer commandBuffer,
const VkRenderingInfoKHR *pRenderingInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginRendering(CMD_BEGINRENDERINGKHR, pRenderingInfo);
}
void ValidationStateTracker::PreCallRecordCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginRendering(CMD_BEGINRENDERING, pRenderingInfo);
}
void ValidationStateTracker::PreCallRecordCmdEndRenderingKHR(VkCommandBuffer commandBuffer) {
RecordCmdEndRenderingRenderPassState(commandBuffer);
}
void ValidationStateTracker::PreCallRecordCmdEndRendering(VkCommandBuffer commandBuffer) {
RecordCmdEndRenderingRenderPassState(commandBuffer);
}
void ValidationStateTracker::PreCallRecordCmdBeginRenderPass2(VkCommandBuffer commandBuffer,
const VkRenderPassBeginInfo *pRenderPassBegin,
const VkSubpassBeginInfo *pSubpassBeginInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->BeginRenderPass(CMD_BEGINRENDERPASS2, pRenderPassBegin, pSubpassBeginInfo->contents);
}
void ValidationStateTracker::PostCallRecordCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->NextSubpass(CMD_NEXTSUBPASS, contents);
}
void ValidationStateTracker::PostCallRecordCmdNextSubpass2KHR(VkCommandBuffer commandBuffer,
const VkSubpassBeginInfo *pSubpassBeginInfo,
const VkSubpassEndInfo *pSubpassEndInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->NextSubpass(CMD_NEXTSUBPASS2KHR, pSubpassBeginInfo->contents);
}
void ValidationStateTracker::PostCallRecordCmdNextSubpass2(VkCommandBuffer commandBuffer,
const VkSubpassBeginInfo *pSubpassBeginInfo,
const VkSubpassEndInfo *pSubpassEndInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->NextSubpass(CMD_NEXTSUBPASS2, pSubpassBeginInfo->contents);
}
void ValidationStateTracker::PostCallRecordCmdEndRenderPass(VkCommandBuffer commandBuffer) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->EndRenderPass(CMD_ENDRENDERPASS);
}
void ValidationStateTracker::PostCallRecordCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer,
const VkSubpassEndInfo *pSubpassEndInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->EndRenderPass(CMD_ENDRENDERPASS2KHR);
}
void ValidationStateTracker::PostCallRecordCmdEndRenderPass2(VkCommandBuffer commandBuffer,
const VkSubpassEndInfo *pSubpassEndInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->EndRenderPass(CMD_ENDRENDERPASS2);
}
void ValidationStateTracker::PostCallRecordCmdEndVideoCodingKHR(VkCommandBuffer commandBuffer,
const VkVideoEndCodingInfoKHR *pEndCodingInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->EndVideoCoding(pEndCodingInfo);
}
void ValidationStateTracker::PreCallRecordCmdExecuteCommands(VkCommandBuffer commandBuffer, uint32_t commandBuffersCount,
const VkCommandBuffer *pCommandBuffers) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->ExecuteCommands({pCommandBuffers, commandBuffersCount});
}
void ValidationStateTracker::PostCallRecordMapMemory(VkDevice device, VkDeviceMemory mem, VkDeviceSize offset, VkDeviceSize size,
VkFlags flags, void **ppData, VkResult result) {
if (VK_SUCCESS != result) return;
RecordMappedMemory(mem, offset, size, ppData);
}
void ValidationStateTracker::PreCallRecordUnmapMemory(VkDevice device, VkDeviceMemory mem) {
auto mem_info = Get<DEVICE_MEMORY_STATE>(mem);
if (mem_info) {
mem_info->mapped_range = MemRange();
mem_info->p_driver_data = nullptr;
}
}
void ValidationStateTracker::UpdateBindImageMemoryState(const VkBindImageMemoryInfo &bindInfo) {
auto image_state = Get<IMAGE_STATE>(bindInfo.image);
if (image_state) {
// An Android sepcial image cannot get VkSubresourceLayout until the image binds a memory.
// See: VUID-vkGetImageSubresourceLayout-image-01895
image_state->fragment_encoder =
std::unique_ptr<const subresource_adapter::ImageRangeEncoder>(new subresource_adapter::ImageRangeEncoder(*image_state));
const auto swapchain_info = LvlFindInChain<VkBindImageMemorySwapchainInfoKHR>(bindInfo.pNext);
if (swapchain_info) {
auto swapchain = Get<SWAPCHAIN_NODE>(swapchain_info->swapchain);
if (swapchain) {
SWAPCHAIN_IMAGE &swapchain_image = swapchain->images[swapchain_info->imageIndex];
if (!swapchain_image.fake_base_address) {
auto size = image_state->fragment_encoder->TotalSize();
swapchain_image.fake_base_address = fake_memory.Alloc(size);
}
// All images bound to this swapchain and index are aliases
image_state->SetSwapchain(swapchain, swapchain_info->imageIndex);
}
} else {
// Track bound memory range information
auto mem_info = Get<DEVICE_MEMORY_STATE>(bindInfo.memory);
if (mem_info) {
VkDeviceSize plane_index = 0u;
if (image_state->disjoint && image_state->IsExternalAHB() == false) {
auto plane_info = LvlFindInChain<VkBindImagePlaneMemoryInfo>(bindInfo.pNext);
const VkImageAspectFlagBits aspect = plane_info->planeAspect;
switch (aspect) {
case VK_IMAGE_ASPECT_PLANE_0_BIT:
plane_index = 0;
break;
case VK_IMAGE_ASPECT_PLANE_1_BIT:
plane_index = 1;
break;
case VK_IMAGE_ASPECT_PLANE_2_BIT:
plane_index = 2;
break;
default:
assert(false); // parameter validation should have caught this
break;
}
}
image_state->BindMemory(
image_state.get(), mem_info, bindInfo.memoryOffset, plane_index,
image_state->requirements[static_cast<decltype(image_state->requirements)::size_type>(plane_index)].size);
}
}
}
}
void ValidationStateTracker::PostCallRecordBindImageMemory(VkDevice device, VkImage image, VkDeviceMemory mem,
VkDeviceSize memoryOffset, VkResult result) {
if (VK_SUCCESS != result) return;
auto bind_info = LvlInitStruct<VkBindImageMemoryInfo>();
bind_info.image = image;
bind_info.memory = mem;
bind_info.memoryOffset = memoryOffset;
UpdateBindImageMemoryState(bind_info);
}
void ValidationStateTracker::PostCallRecordBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
if (VK_SUCCESS != result) return;
for (uint32_t i = 0; i < bindInfoCount; i++) {
UpdateBindImageMemoryState(pBindInfos[i]);
}
}
void ValidationStateTracker::PostCallRecordBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount,
const VkBindImageMemoryInfo *pBindInfos, VkResult result) {
if (VK_SUCCESS != result) return;
for (uint32_t i = 0; i < bindInfoCount; i++) {
UpdateBindImageMemoryState(pBindInfos[i]);
}
}
void ValidationStateTracker::PreCallRecordSetEvent(VkDevice device, VkEvent event) {
auto event_state = Get<EVENT_STATE>(event);
if (event_state) {
event_state->stageMask = VK_PIPELINE_STAGE_HOST_BIT;
}
}
void ValidationStateTracker::PostCallRecordImportSemaphoreFdKHR(VkDevice device,
const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordImportSemaphoreState(pImportSemaphoreFdInfo->semaphore, pImportSemaphoreFdInfo->handleType,
pImportSemaphoreFdInfo->flags);
}
void ValidationStateTracker::RecordGetExternalSemaphoreState(VkSemaphore semaphore,
VkExternalSemaphoreHandleTypeFlagBits handle_type) {
auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
if (semaphore_state) {
semaphore_state->Export(handle_type);
}
}
#ifdef VK_USE_PLATFORM_WIN32_KHR
void ValidationStateTracker::PostCallRecordImportSemaphoreWin32HandleKHR(
VkDevice device, const VkImportSemaphoreWin32HandleInfoKHR *pImportSemaphoreWin32HandleInfo, VkResult result) {
if (VK_SUCCESS != result) return;
RecordImportSemaphoreState(pImportSemaphoreWin32HandleInfo->semaphore, pImportSemaphoreWin32HandleInfo->handleType,
pImportSemaphoreWin32HandleInfo->flags);
}
void ValidationStateTracker::PostCallRecordGetSemaphoreWin32HandleKHR(VkDevice device,
const VkSemaphoreGetWin32HandleInfoKHR *pGetWin32HandleInfo,
HANDLE *pHandle, VkResult result) {
if (VK_SUCCESS != result) return;
RecordGetExternalSemaphoreState(pGetWin32HandleInfo->semaphore, pGetWin32HandleInfo->handleType);
}
void ValidationStateTracker::PostCallRecordImportFenceWin32HandleKHR(
VkDevice device, const VkImportFenceWin32HandleInfoKHR *pImportFenceWin32HandleInfo, VkResult result) {
if (VK_SUCCESS != result) return;
RecordImportFenceState(pImportFenceWin32HandleInfo->fence, pImportFenceWin32HandleInfo->handleType,
pImportFenceWin32HandleInfo->flags);
}
void ValidationStateTracker::PostCallRecordGetFenceWin32HandleKHR(VkDevice device,
const VkFenceGetWin32HandleInfoKHR *pGetWin32HandleInfo,
HANDLE *pHandle, VkResult result) {
if (VK_SUCCESS != result) return;
RecordGetExternalFenceState(pGetWin32HandleInfo->fence, pGetWin32HandleInfo->handleType);
}
#endif
void ValidationStateTracker::PostCallRecordGetSemaphoreFdKHR(VkDevice device, const VkSemaphoreGetFdInfoKHR *pGetFdInfo, int *pFd,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordGetExternalSemaphoreState(pGetFdInfo->semaphore, pGetFdInfo->handleType);
}
void ValidationStateTracker::RecordImportFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type,
VkFenceImportFlags flags) {
auto fence_node = Get<FENCE_STATE>(fence);
if (fence_node) {
fence_node->Import(handle_type, flags);
}
}
void ValidationStateTracker::PostCallRecordImportFenceFdKHR(VkDevice device, const VkImportFenceFdInfoKHR *pImportFenceFdInfo,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordImportFenceState(pImportFenceFdInfo->fence, pImportFenceFdInfo->handleType, pImportFenceFdInfo->flags);
}
void ValidationStateTracker::RecordGetExternalFenceState(VkFence fence, VkExternalFenceHandleTypeFlagBits handle_type) {
auto fence_state = Get<FENCE_STATE>(fence);
if (fence_state) {
fence_state->Export(handle_type);
}
}
void ValidationStateTracker::PostCallRecordGetFenceFdKHR(VkDevice device, const VkFenceGetFdInfoKHR *pGetFdInfo, int *pFd,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordGetExternalFenceState(pGetFdInfo->fence, pGetFdInfo->handleType);
}
void ValidationStateTracker::PostCallRecordCreateEvent(VkDevice device, const VkEventCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkEvent *pEvent, VkResult result) {
if (VK_SUCCESS != result) return;
Add(std::make_shared<EVENT_STATE>(*pEvent, pCreateInfo));
}
void ValidationStateTracker::RecordCreateSwapchainState(VkResult result, const VkSwapchainCreateInfoKHR *pCreateInfo,
VkSwapchainKHR *pSwapchain, std::shared_ptr<SURFACE_STATE> &&surface_state,
SWAPCHAIN_NODE *old_swapchain_state) {
if (VK_SUCCESS == result) {
if (surface_state->swapchain) {
surface_state->RemoveParent(surface_state->swapchain);
}
auto swapchain = CreateSwapchainState(pCreateInfo, *pSwapchain);
surface_state->AddParent(swapchain.get());
surface_state->swapchain = swapchain.get();
swapchain->surface = std::move(surface_state);
auto swapchain_present_modes_ci = LvlFindInChain<VkSwapchainPresentModesCreateInfoEXT>(pCreateInfo->pNext);
if (swapchain_present_modes_ci) {
const uint32_t present_mode_count = swapchain_present_modes_ci->presentModeCount;
swapchain->present_modes.reserve(present_mode_count);
std::copy(swapchain_present_modes_ci->pPresentModes, swapchain_present_modes_ci->pPresentModes + present_mode_count,
std::back_inserter(swapchain->present_modes));
}
Add(std::move(swapchain));
} else {
surface_state->swapchain = nullptr;
}
// Spec requires that even if CreateSwapchainKHR fails, oldSwapchain is retired
// Retired swapchains remain associated with the surface until they are destroyed.
if (old_swapchain_state) {
old_swapchain_state->retired = true;
}
return;
}
void ValidationStateTracker::PostCallRecordCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain,
VkResult result) {
auto surface_state = Get<SURFACE_STATE>(pCreateInfo->surface);
auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfo->oldSwapchain);
RecordCreateSwapchainState(result, pCreateInfo, pSwapchain, std::move(surface_state), old_swapchain_state.get());
}
void ValidationStateTracker::PreCallRecordDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain,
const VkAllocationCallbacks *pAllocator) {
Destroy<SWAPCHAIN_NODE>(swapchain);
}
void ValidationStateTracker::PostCallRecordCreateDisplayModeKHR(VkPhysicalDevice physicalDevice, VkDisplayKHR display,
const VkDisplayModeCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkDisplayModeKHR *pMode,
VkResult result) {
if (VK_SUCCESS != result) return;
if (!pMode) return;
Add(std::make_shared<DISPLAY_MODE_STATE>(*pMode, physicalDevice));
}
void ValidationStateTracker::PostCallRecordQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo, VkResult result) {
// spec: If vkQueuePresentKHR fails to enqueue the corresponding set of queue operations, it may return
// VK_ERROR_OUT_OF_HOST_MEMORY or VK_ERROR_OUT_OF_DEVICE_MEMORY. If it does, the implementation must ensure that the state and
// contents of any resources or synchronization primitives referenced is unaffected by the call or its failure.
//
// If vkQueuePresentKHR fails in such a way that the implementation is unable to make that guarantee, the implementation must
// return VK_ERROR_DEVICE_LOST.
//
// However, if the presentation request is rejected by the presentation engine with an error VK_ERROR_OUT_OF_DATE_KHR,
// VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT, or VK_ERROR_SURFACE_LOST_KHR, the set of queue operations are still considered
// to be enqueued and thus any semaphore wait operation specified in VkPresentInfoKHR will execute when the corresponding queue
// operation is complete.
//
// NOTE: This is the only queue submit-like call that has its state updated in PostCallRecord(). In part that is because of these
// non-fatal error cases. Also we need a place to handle the swapchain image bookkeeping, which really should be happening once all
// the wait semaphores have completed. Since most of the PostCall queue submit race conditions are related to timeline semaphores,
// and acquire sempaphores are always binary, this seems ok-ish.
if (result == VK_ERROR_OUT_OF_HOST_MEMORY || result == VK_ERROR_OUT_OF_DEVICE_MEMORY || result == VK_ERROR_DEVICE_LOST) {
return;
}
auto queue_state = Get<QUEUE_STATE>(queue);
CB_SUBMISSION submission;
for (uint32_t i = 0; i < pPresentInfo->waitSemaphoreCount; ++i) {
auto semaphore_state = Get<SEMAPHORE_STATE>(pPresentInfo->pWaitSemaphores[i]);
if (semaphore_state) {
submission.AddWaitSemaphore(std::move(semaphore_state), 0);
}
}
const auto *present_id_info = LvlFindInChain<VkPresentIdKHR>(pPresentInfo->pNext);
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
// Note: this is imperfect, in that we can get confused about what did or didn't succeed-- but if the app does that, it's
// confused itself just as much.
auto local_result = pPresentInfo->pResults ? pPresentInfo->pResults[i] : result;
if (local_result != VK_SUCCESS && local_result != VK_SUBOPTIMAL_KHR) continue; // this present didn't actually happen.
// Mark the image as having been released to the WSI
auto swapchain_data = Get<SWAPCHAIN_NODE>(pPresentInfo->pSwapchains[i]);
if (swapchain_data) {
uint64_t present_id = (present_id_info && i < present_id_info->swapchainCount) ? present_id_info->pPresentIds[i] : 0;
swapchain_data->PresentImage(pPresentInfo->pImageIndices[i], present_id);
}
}
auto early_retire_seq = queue_state->Submit(std::move(submission));
if (early_retire_seq) {
queue_state->NotifyAndWait(early_retire_seq);
}
}
void ValidationStateTracker::PostCallRecordCreateSharedSwapchainsKHR(VkDevice device, uint32_t swapchainCount,
const VkSwapchainCreateInfoKHR *pCreateInfos,
const VkAllocationCallbacks *pAllocator,
VkSwapchainKHR *pSwapchains, VkResult result) {
if (pCreateInfos) {
for (uint32_t i = 0; i < swapchainCount; i++) {
auto surface_state = Get<SURFACE_STATE>(pCreateInfos[i].surface);
auto old_swapchain_state = Get<SWAPCHAIN_NODE>(pCreateInfos[i].oldSwapchain);
RecordCreateSwapchainState(result, &pCreateInfos[i], &pSwapchains[i], std::move(surface_state),
old_swapchain_state.get());
}
}
}
void ValidationStateTracker::RecordAcquireNextImageState(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
auto fence_state = Get<FENCE_STATE>(fence);
if (fence_state) {
// Treat as inflight since it is valid to wait on this fence, even in cases where it is technically a temporary
// import
fence_state->EnqueueSignal(nullptr, 0);
}
auto semaphore_state = Get<SEMAPHORE_STATE>(semaphore);
if (semaphore_state) {
// Treat as signaled since it is valid to wait on this semaphore, even in cases where it is technically a
// temporary import
semaphore_state->EnqueueAcquire();
}
// Mark the image as acquired.
auto swapchain_data = Get<SWAPCHAIN_NODE>(swapchain);
if (swapchain_data) {
swapchain_data->AcquireImage(*pImageIndex);
}
}
void ValidationStateTracker::PostCallRecordAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
RecordAcquireNextImageState(device, swapchain, timeout, semaphore, fence, pImageIndex);
}
void ValidationStateTracker::PostCallRecordAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
uint32_t *pImageIndex, VkResult result) {
if ((VK_SUCCESS != result) && (VK_SUBOPTIMAL_KHR != result)) return;
RecordAcquireNextImageState(device, pAcquireInfo->swapchain, pAcquireInfo->timeout, pAcquireInfo->semaphore,
pAcquireInfo->fence, pImageIndex);
}
std::shared_ptr<PHYSICAL_DEVICE_STATE> ValidationStateTracker::CreatePhysicalDeviceState(VkPhysicalDevice phys_dev) {
return std::make_shared<PHYSICAL_DEVICE_STATE>(phys_dev);
}
void ValidationStateTracker::PostCallRecordCreateInstance(const VkInstanceCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkInstance *pInstance,
VkResult result) {
if (result != VK_SUCCESS) {
return;
}
instance_state = this;
uint32_t count = 0;
// this can fail if the allocator fails
result = DispatchEnumeratePhysicalDevices(*pInstance, &count, nullptr);
if (result != VK_SUCCESS) {
return;
}
std::vector<VkPhysicalDevice> physdev_handles(count);
result = DispatchEnumeratePhysicalDevices(*pInstance, &count, physdev_handles.data());
if (result != VK_SUCCESS) {
return;
}
for (auto physdev : physdev_handles) {
Add(CreatePhysicalDeviceState(physdev));
}
#ifdef VK_USE_PLATFORM_METAL_EXT
auto export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(pCreateInfo->pNext);
while (export_metal_object_info) {
export_metal_flags.push_back(export_metal_object_info->exportObjectType);
export_metal_object_info = LvlFindInChain<VkExportMetalObjectCreateInfoEXT>(export_metal_object_info->pNext);
}
#endif // VK_USE_PLATFORM_METAL_EXT
}
// Common function to update state for GetPhysicalDeviceQueueFamilyProperties & 2KHR version
static void StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(PHYSICAL_DEVICE_STATE *pd_state, uint32_t count) {
pd_state->queue_family_known_count = std::max(pd_state->queue_family_known_count, count);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice,
uint32_t *pQueueFamilyPropertyCount,
VkQueueFamilyProperties *pQueueFamilyProperties) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2(
VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceQueueFamilyProperties2KHR(
VkPhysicalDevice physicalDevice, uint32_t *pQueueFamilyPropertyCount, VkQueueFamilyProperties2 *pQueueFamilyProperties) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
StateUpdateCommonGetPhysicalDeviceQueueFamilyProperties(pd_state.get(), *pQueueFamilyPropertyCount);
}
void ValidationStateTracker::PreCallRecordDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
const VkAllocationCallbacks *pAllocator) {
Destroy<SURFACE_STATE>(surface);
}
void ValidationStateTracker::RecordVulkanSurface(VkSurfaceKHR *pSurface) { Add(std::make_shared<SURFACE_STATE>(*pSurface)); }
void ValidationStateTracker::PostCallRecordCreateDisplayPlaneSurfaceKHR(VkInstance instance,
const VkDisplaySurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSurfaceKHR *pSurface, VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#ifdef VK_USE_PLATFORM_ANDROID_KHR
void ValidationStateTracker::PostCallRecordCreateAndroidSurfaceKHR(VkInstance instance,
const VkAndroidSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_ANDROID_KHR
#ifdef VK_USE_PLATFORM_FUCHSIA
void ValidationStateTracker::PostCallRecordCreateImagePipeSurfaceFUCHSIA(VkInstance instance,
const VkImagePipeSurfaceCreateInfoFUCHSIA *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSurfaceKHR *pSurface, VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_FUCHSIA
#ifdef VK_USE_PLATFORM_IOS_MVK
void ValidationStateTracker::PostCallRecordCreateIOSSurfaceMVK(VkInstance instance, const VkIOSSurfaceCreateInfoMVK *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_IOS_MVK
#ifdef VK_USE_PLATFORM_MACOS_MVK
void ValidationStateTracker::PostCallRecordCreateMacOSSurfaceMVK(VkInstance instance,
const VkMacOSSurfaceCreateInfoMVK *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_MACOS_MVK
#ifdef VK_USE_PLATFORM_METAL_EXT
void ValidationStateTracker::PostCallRecordCreateMetalSurfaceEXT(VkInstance instance,
const VkMetalSurfaceCreateInfoEXT *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_METAL_EXT
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
void ValidationStateTracker::PostCallRecordCreateWaylandSurfaceKHR(VkInstance instance,
const VkWaylandSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_USE_PLATFORM_WIN32_KHR
void ValidationStateTracker::PostCallRecordCreateWin32SurfaceKHR(VkInstance instance,
const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_USE_PLATFORM_XCB_KHR
void ValidationStateTracker::PostCallRecordCreateXcbSurfaceKHR(VkInstance instance, const VkXcbSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_XCB_KHR
#ifdef VK_USE_PLATFORM_XLIB_KHR
void ValidationStateTracker::PostCallRecordCreateXlibSurfaceKHR(VkInstance instance, const VkXlibSurfaceCreateInfoKHR *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
#endif // VK_USE_PLATFORM_XLIB_KHR
void ValidationStateTracker::PostCallRecordCreateHeadlessSurfaceEXT(VkInstance instance,
const VkHeadlessSurfaceCreateInfoEXT *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordVulkanSurface(pSurface);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface,
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities,
VkResult result) {
if (VK_SUCCESS != result) return;
auto surface_state = Get<SURFACE_STATE>(surface);
surface_state->SetCapabilities(physicalDevice, *pSurfaceCapabilities);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2KHR(
VkPhysicalDevice physicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
VkSurfaceCapabilities2KHR *pSurfaceCapabilities, VkResult result) {
if (VK_SUCCESS != result) return;
if (pSurfaceInfo->surface) {
auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
const VkSurfacePresentModeEXT *surface_present_mode = LvlFindInChain<VkSurfacePresentModeEXT>(pSurfaceInfo->pNext);
if ((!IsExtEnabled(device_extensions.vk_ext_surface_maintenance1)) || (!surface_present_mode)) {
surface_state->SetCapabilities(physicalDevice, pSurfaceCapabilities->surfaceCapabilities);
} else {
const VkSurfacePresentScalingCapabilitiesEXT *present_scaling_caps =
LvlFindInChain<VkSurfacePresentScalingCapabilitiesEXT>(pSurfaceCapabilities->pNext);
const VkSurfacePresentModeCompatibilityEXT *compatible_modes =
LvlFindInChain<VkSurfacePresentModeCompatibilityEXT>(pSurfaceCapabilities->pNext);
if (compatible_modes && compatible_modes->pPresentModes) {
surface_state->SetCompatibleModes(
physicalDevice, surface_present_mode->presentMode,
layer_data::span<const VkPresentModeKHR>(compatible_modes->pPresentModes,
compatible_modes->presentModeCount));
}
if (present_scaling_caps) {
surface_state->SetPresentModeCapabilities(physicalDevice, surface_present_mode->presentMode,
pSurfaceCapabilities->surfaceCapabilities, *present_scaling_caps);
}
}
} else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query) &&
LvlFindInChain<VkSurfaceProtectedCapabilitiesKHR>(pSurfaceCapabilities->pNext)) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
pd_state->surfaceless_query_state.capabilities = pSurfaceCapabilities->surfaceCapabilities;
}
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface,
VkSurfaceCapabilities2EXT *pSurfaceCapabilities,
VkResult result) {
auto surface_state = Get<SURFACE_STATE>(surface);
VkSurfaceCapabilitiesKHR caps{
pSurfaceCapabilities->minImageCount, pSurfaceCapabilities->maxImageCount,
pSurfaceCapabilities->currentExtent, pSurfaceCapabilities->minImageExtent,
pSurfaceCapabilities->maxImageExtent, pSurfaceCapabilities->maxImageArrayLayers,
pSurfaceCapabilities->supportedTransforms, pSurfaceCapabilities->currentTransform,
pSurfaceCapabilities->supportedCompositeAlpha, pSurfaceCapabilities->supportedUsageFlags,
};
surface_state->SetCapabilities(physicalDevice, caps);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex, VkSurfaceKHR surface,
VkBool32 *pSupported, VkResult result) {
if (VK_SUCCESS != result) return;
auto surface_state = Get<SURFACE_STATE>(surface);
surface_state->SetQueueSupport(physicalDevice, queueFamilyIndex, (*pSupported == VK_TRUE));
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
VkSurfaceKHR surface,
uint32_t *pPresentModeCount,
VkPresentModeKHR *pPresentModes,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
if (pPresentModes) {
if (surface) {
auto surface_state = Get<SURFACE_STATE>(surface);
surface_state->SetPresentModes(physicalDevice,
layer_data::span<const VkPresentModeKHR>(pPresentModes, *pPresentModeCount));
} else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
pd_state->surfaceless_query_state.present_modes =
std::vector<VkPresentModeKHR>(pPresentModes, pPresentModes + *pPresentModeCount);
}
}
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
uint32_t *pSurfaceFormatCount,
VkSurfaceFormatKHR *pSurfaceFormats,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
if (pSurfaceFormats) {
if (surface) {
auto surface_state = Get<SURFACE_STATE>(surface);
surface_state->SetFormats(physicalDevice,
std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount));
} else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
pd_state->surfaceless_query_state.formats =
std::vector<VkSurfaceFormatKHR>(pSurfaceFormats, pSurfaceFormats + *pSurfaceFormatCount);
}
}
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
uint32_t *pSurfaceFormatCount,
VkSurfaceFormat2KHR *pSurfaceFormats,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
if (pSurfaceFormats) {
std::vector<VkSurfaceFormatKHR> fmts(*pSurfaceFormatCount);
for (uint32_t i = 0; i < *pSurfaceFormatCount; i++) {
fmts[i] = pSurfaceFormats[i].surfaceFormat;
}
if (pSurfaceInfo->surface) {
auto surface_state = Get<SURFACE_STATE>(pSurfaceInfo->surface);
surface_state->SetFormats(physicalDevice, std::move(fmts));
} else if (IsExtEnabled(instance_extensions.vk_google_surfaceless_query)) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
pd_state->surfaceless_query_state.formats = std::move(fmts);
}
}
}
void ValidationStateTracker::PreCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
const VkDebugUtilsLabelEXT *pLabelInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_BEGINDEBUGUTILSLABELEXT);
BeginCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
}
void ValidationStateTracker::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_ENDDEBUGUTILSLABELEXT);
EndCmdDebugUtilsLabel(report_data, commandBuffer);
}
void ValidationStateTracker::PreCallRecordCmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
const VkDebugUtilsLabelEXT *pLabelInfo) {
InsertCmdDebugUtilsLabel(report_data, commandBuffer, pLabelInfo);
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_INSERTDEBUGUTILSLABELEXT);
// Squirrel away an easily accessible copy.
cb_state->debug_label = LoggingLabel(pLabelInfo);
}
void ValidationStateTracker::RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(VkPhysicalDevice physicalDevice,
uint32_t queueFamilyIndex,
uint32_t *pCounterCount,
VkPerformanceCounterKHR *pCounters) {
if (NULL == pCounters) return;
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
assert(pd_state);
std::unique_ptr<QUEUE_FAMILY_PERF_COUNTERS> queue_family_counters(new QUEUE_FAMILY_PERF_COUNTERS());
queue_family_counters->counters.resize(*pCounterCount);
for (uint32_t i = 0; i < *pCounterCount; i++) queue_family_counters->counters[i] = pCounters[i];
pd_state->perf_counters[queueFamilyIndex] = std::move(queue_family_counters);
}
void ValidationStateTracker::PostCallRecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, uint32_t *pCounterCount, VkPerformanceCounterKHR *pCounters,
VkPerformanceCounterDescriptionKHR *pCounterDescriptions, VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
RecordEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCounters(physicalDevice, queueFamilyIndex, pCounterCount, pCounters);
}
void ValidationStateTracker::PostCallRecordAcquireProfilingLockKHR(VkDevice device, const VkAcquireProfilingLockInfoKHR *pInfo,
VkResult result) {
if (result == VK_SUCCESS) performance_lock_acquired = true;
}
void ValidationStateTracker::PostCallRecordReleaseProfilingLockKHR(VkDevice device) {
performance_lock_acquired = false;
for (auto &cmd_buffer : command_buffer_map_.snapshot()) {
cmd_buffer.second->performance_lock_released = true;
}
}
void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplate(VkDevice device,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const VkAllocationCallbacks *pAllocator) {
Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
}
void ValidationStateTracker::PreCallRecordDestroyDescriptorUpdateTemplateKHR(VkDevice device,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const VkAllocationCallbacks *pAllocator) {
Destroy<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
}
void ValidationStateTracker::RecordCreateDescriptorUpdateTemplateState(const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate) {
Add(std::make_shared<UPDATE_TEMPLATE_STATE>(*pDescriptorUpdateTemplate, pCreateInfo));
}
void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplate(VkDevice device,
const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
}
void ValidationStateTracker::PostCallRecordCreateDescriptorUpdateTemplateKHR(
VkDevice device, const VkDescriptorUpdateTemplateCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
VkDescriptorUpdateTemplate *pDescriptorUpdateTemplate, VkResult result) {
if (VK_SUCCESS != result) return;
RecordCreateDescriptorUpdateTemplateState(pCreateInfo, pDescriptorUpdateTemplate);
}
void ValidationStateTracker::RecordUpdateDescriptorSetWithTemplateState(VkDescriptorSet descriptorSet,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData) {
auto const template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
assert(template_state);
if (template_state) {
// TODO: Record template push descriptor updates
if (template_state->create_info.templateType == VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET) {
PerformUpdateDescriptorSetsWithTemplateKHR(descriptorSet, template_state.get(), pData);
}
}
}
void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplate(VkDevice device, VkDescriptorSet descriptorSet,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData) {
RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
}
void ValidationStateTracker::PreCallRecordUpdateDescriptorSetWithTemplateKHR(VkDevice device, VkDescriptorSet descriptorSet,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
const void *pData) {
RecordUpdateDescriptorSetWithTemplateState(descriptorSet, descriptorUpdateTemplate, pData);
}
void ValidationStateTracker::PreCallRecordCmdPushDescriptorSetWithTemplateKHR(VkCommandBuffer commandBuffer,
VkDescriptorUpdateTemplate descriptorUpdateTemplate,
VkPipelineLayout layout, uint32_t set,
const void *pData) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto template_state = Get<UPDATE_TEMPLATE_STATE>(descriptorUpdateTemplate);
auto layout_data = Get<PIPELINE_LAYOUT_STATE>(layout);
if (!cb_state || !template_state || !layout_data) {
return;
}
cb_state->RecordCmd(CMD_PUSHDESCRIPTORSETWITHTEMPLATEKHR);
auto dsl = layout_data->GetDsl(set);
const auto &template_ci = template_state->create_info;
// Decode the template into a set of write updates
cvdescriptorset::DecodedTemplateUpdate decoded_template(this, VK_NULL_HANDLE, template_state.get(), pData,
dsl->GetDescriptorSetLayout());
cb_state->PushDescriptorSetState(template_ci.pipelineBindPoint, *layout_data, set,
static_cast<uint32_t>(decoded_template.desc_writes.size()),
decoded_template.desc_writes.data());
}
void ValidationStateTracker::RecordGetPhysicalDeviceDisplayPlanePropertiesState(VkPhysicalDevice physicalDevice,
uint32_t *pPropertyCount, void *pProperties) {
auto pd_state = Get<PHYSICAL_DEVICE_STATE>(physicalDevice);
if (*pPropertyCount) {
pd_state->display_plane_property_count = *pPropertyCount;
}
if (*pPropertyCount || pProperties) {
pd_state->vkGetPhysicalDeviceDisplayPlanePropertiesKHR_called = true;
}
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physicalDevice,
uint32_t *pPropertyCount,
VkDisplayPlanePropertiesKHR *pProperties,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
}
void ValidationStateTracker::PostCallRecordGetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physicalDevice,
uint32_t *pPropertyCount,
VkDisplayPlaneProperties2KHR *pProperties,
VkResult result) {
if ((VK_SUCCESS != result) && (VK_INCOMPLETE != result)) return;
RecordGetPhysicalDeviceDisplayPlanePropertiesState(physicalDevice, pPropertyCount, pProperties);
}
void ValidationStateTracker::PostCallRecordCmdBeginQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
uint32_t query, VkQueryControlFlags flags, uint32_t index) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
uint32_t num_queries = 1;
// If render pass instance has multiview enabled, query uses N consecutive query indices
if (cb_state->activeRenderPass) {
uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
num_queries = std::max(num_queries, bits);
}
for (uint32_t i = 0; i < num_queries; ++i) {
QueryObject query_obj = {queryPool, query, index + i};
cb_state->RecordCmd(CMD_BEGINQUERYINDEXEDEXT);
cb_state->BeginQuery(query_obj);
}
}
void ValidationStateTracker::PostCallRecordCmdEndQueryIndexedEXT(VkCommandBuffer commandBuffer, VkQueryPool queryPool,
uint32_t query, uint32_t index) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
uint32_t num_queries = 1;
// If render pass instance has multiview enabled, query uses N consecutive query indices
if (cb_state->activeRenderPass) {
uint32_t bits = cb_state->activeRenderPass->GetViewMaskBits(cb_state->activeSubpass);
num_queries = std::max(num_queries, bits);
}
for (uint32_t i = 0; i < num_queries; ++i) {
QueryObject query_obj = {queryPool, query, index + i};
cb_state->RecordCmd(CMD_ENDQUERYINDEXEDEXT);
cb_state->EndQuery(query_obj);
}
}
void ValidationStateTracker::RecordCreateSamplerYcbcrConversionState(const VkSamplerYcbcrConversionCreateInfo *create_info,
VkSamplerYcbcrConversion ycbcr_conversion) {
VkFormatFeatureFlags2KHR format_features = 0;
if (create_info->format != VK_FORMAT_UNDEFINED) {
format_features = GetPotentialFormatFeatures(create_info->format);
} else if (IsExtEnabled(device_extensions.vk_android_external_memory_android_hardware_buffer)) {
// If format is VK_FORMAT_UNDEFINED, format_features will be set by external AHB features
format_features = GetExternalFormatFeaturesANDROID(create_info);
}
Add(std::make_shared<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcr_conversion, create_info, format_features));
}
void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversion(VkDevice device,
const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSamplerYcbcrConversion *pYcbcrConversion,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
}
void ValidationStateTracker::PostCallRecordCreateSamplerYcbcrConversionKHR(VkDevice device,
const VkSamplerYcbcrConversionCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkSamplerYcbcrConversion *pYcbcrConversion,
VkResult result) {
if (VK_SUCCESS != result) return;
RecordCreateSamplerYcbcrConversionState(pCreateInfo, *pYcbcrConversion);
}
void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversion(VkDevice device, VkSamplerYcbcrConversion ycbcrConversion,
const VkAllocationCallbacks *pAllocator) {
Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
}
void ValidationStateTracker::PostCallRecordDestroySamplerYcbcrConversionKHR(VkDevice device,
VkSamplerYcbcrConversion ycbcrConversion,
const VkAllocationCallbacks *pAllocator) {
Destroy<SAMPLER_YCBCR_CONVERSION_STATE>(ycbcrConversion);
}
void ValidationStateTracker::RecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
uint32_t queryCount) {
// Do nothing if the feature is not enabled.
if (!enabled_features.core12.hostQueryReset) return;
// Do nothing if the query pool has been destroyed.
auto query_pool_state = Get<QUERY_POOL_STATE>(queryPool);
if (!query_pool_state) return;
// Reset the state of existing entries.
const uint32_t max_query_count = std::min(queryCount, query_pool_state->createInfo.queryCount - firstQuery);
for (uint32_t i = 0; i < max_query_count; ++i) {
auto query_index = firstQuery + i;
query_pool_state->SetQueryState(query_index, 0, QUERYSTATE_RESET);
if (query_pool_state->createInfo.queryType == VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR) {
for (uint32_t pass_index = 0; pass_index < query_pool_state->n_performance_passes; pass_index++) {
query_pool_state->SetQueryState(query_index, pass_index, QUERYSTATE_RESET);
}
}
}
}
void ValidationStateTracker::PostCallRecordResetQueryPoolEXT(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
uint32_t queryCount) {
RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
}
void ValidationStateTracker::PostCallRecordResetQueryPool(VkDevice device, VkQueryPool queryPool, uint32_t firstQuery,
uint32_t queryCount) {
RecordResetQueryPool(device, queryPool, firstQuery, queryCount);
}
void ValidationStateTracker::PerformUpdateDescriptorSetsWithTemplateKHR(VkDescriptorSet descriptorSet,
const UPDATE_TEMPLATE_STATE *template_state,
const void *pData) {
// Translate the templated update into a normal update for validation...
cvdescriptorset::DecodedTemplateUpdate decoded_update(this, descriptorSet, template_state, pData);
cvdescriptorset::PerformUpdateDescriptorSets(this, static_cast<uint32_t>(decoded_update.desc_writes.size()),
decoded_update.desc_writes.data(), 0, NULL);
}
// Update the common AllocateDescriptorSetsData
void ValidationStateTracker::UpdateAllocateDescriptorSetsData(const VkDescriptorSetAllocateInfo *p_alloc_info,
cvdescriptorset::AllocateDescriptorSetsData *ds_data) const {
for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
auto layout = Get<cvdescriptorset::DescriptorSetLayout>(p_alloc_info->pSetLayouts[i]);
if (layout) {
ds_data->layout_nodes[i] = layout;
// Count total descriptors required per type
for (uint32_t j = 0; j < layout->GetBindingCount(); ++j) {
const auto &binding_layout = layout->GetDescriptorSetLayoutBindingPtrFromIndex(j);
uint32_t type_index = static_cast<uint32_t>(binding_layout->descriptorType);
ds_data->required_descriptors_by_type[type_index] += binding_layout->descriptorCount;
}
}
// Any unknown layouts will be flagged as errors during ValidateAllocateDescriptorSets() call
}
}
void ValidationStateTracker::PostCallRecordCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
uint32_t firstVertex, uint32_t firstInstance) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAW);
}
void ValidationStateTracker::PostCallRecordCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
uint32_t firstInstance, uint32_t stride) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWMULTIEXT);
}
void ValidationStateTracker::PostCallRecordCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount,
uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
uint32_t firstInstance) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWINDEXED);
}
void ValidationStateTracker::PostCallRecordCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
const VkMultiDrawIndexedInfoEXT *pIndexInfo,
uint32_t instanceCount, uint32_t firstInstance, uint32_t stride,
const int32_t *pVertexOffset) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWMULTIINDEXEDEXT);
}
void ValidationStateTracker::PostCallRecordCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
uint32_t count, uint32_t stride) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto buffer_state = Get<BUFFER_STATE>(buffer);
cb_state->UpdateDrawCmd(CMD_DRAWINDIRECT);
if (!disabled[command_buffer_state]) {
cb_state->AddChild(buffer_state);
}
}
void ValidationStateTracker::PostCallRecordCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, uint32_t count, uint32_t stride) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
auto buffer_state = Get<BUFFER_STATE>(buffer);
cb_state->UpdateDrawCmd(CMD_DRAWINDEXEDINDIRECT);
if (!disabled[command_buffer_state]) {
cb_state->AddChild(buffer_state);
}
}
void ValidationStateTracker::PostCallRecordCmdDispatch(VkCommandBuffer commandBuffer, uint32_t x, uint32_t y, uint32_t z) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDispatchCmd(CMD_DISPATCH);
}
void ValidationStateTracker::PostCallRecordCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDispatchCmd(CMD_DISPATCHINDIRECT);
if (!disabled[command_buffer_state]) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
cb_state->AddChild(buffer_state);
}
}
void ValidationStateTracker::PostCallRecordCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
uint32_t, uint32_t) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDispatchCmd(CMD_DISPATCHBASEKHR);
}
void ValidationStateTracker::PostCallRecordCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t, uint32_t, uint32_t, uint32_t,
uint32_t, uint32_t) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDispatchCmd(CMD_DISPATCHBASE);
}
void ValidationStateTracker::RecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(cmd_type);
if (!disabled[command_buffer_state]) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
cb_state->AddChild(buffer_state);
cb_state->AddChild(count_buffer_state);
}
}
void ValidationStateTracker::PreCallRecordCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, VkBuffer countBuffer,
VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride) {
RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
CMD_DRAWINDIRECTCOUNTKHR);
}
void ValidationStateTracker::PreCallRecordCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset,
uint32_t maxDrawCount, uint32_t stride) {
RecordCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
CMD_DRAWINDIRECTCOUNT);
}
void ValidationStateTracker::RecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset,
uint32_t maxDrawCount, uint32_t stride, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(cmd_type);
if (!disabled[command_buffer_state]) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
cb_state->AddChild(buffer_state);
cb_state->AddChild(count_buffer_state);
}
}
void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, VkBuffer countBuffer,
VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride) {
RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
CMD_DRAWINDEXEDINDIRECTCOUNTKHR);
}
void ValidationStateTracker::PreCallRecordCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, VkBuffer countBuffer,
VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride) {
RecordCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
CMD_DRAWINDEXEDINDIRECTCOUNT);
}
void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount,
uint32_t firstTask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSNV);
}
void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, uint32_t drawCount, uint32_t stride) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTNV);
auto buffer_state = Get<BUFFER_STATE>(buffer);
if (!disabled[command_buffer_state] && buffer_state) {
cb_state->AddChild(buffer_state);
}
}
void ValidationStateTracker::PreCallRecordCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, VkBuffer countBuffer,
VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateDrawCmd(CMD_DRAWMESHTASKSINDIRECTCOUNTNV);
if (!disabled[command_buffer_state]) {
auto buffer_state = Get<BUFFER_STATE>(buffer);
auto count_buffer_state = Get<BUFFER_STATE>(countBuffer);
if (buffer_state) {
cb_state->AddChild(buffer_state);
}
if (count_buffer_state) {
cb_state->AddChild(count_buffer_state);
}
}
}
void ValidationStateTracker::PostCallRecordCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
uint32_t width, uint32_t height, uint32_t depth) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateTraceRayCmd(CMD_TRACERAYSNV);
}
void ValidationStateTracker::PostCallRecordCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
uint32_t height, uint32_t depth) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateTraceRayCmd(CMD_TRACERAYSKHR);
}
void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
VkDeviceAddress indirectDeviceAddress) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECTKHR);
}
std::shared_ptr<SHADER_MODULE_STATE> ValidationStateTracker::CreateShaderModuleState(const VkShaderModuleCreateInfo &create_info,
uint32_t unique_shader_id,
VkShaderModule handle) const {
spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
const bool is_spirv = (create_info.pCode[0] == spv::MagicNumber);
return is_spirv ? std::make_shared<SHADER_MODULE_STATE>(create_info, handle, spirv_environment, unique_shader_id)
: std::make_shared<SHADER_MODULE_STATE>();
}
void ValidationStateTracker::PostCallRecordCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer,
VkDeviceAddress indirectDeviceAddress) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->UpdateTraceRayCmd(CMD_TRACERAYSINDIRECT2KHR);
}
void ValidationStateTracker::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator,
VkShaderModule *pShaderModule, VkResult result,
void *csm_state_data) {
if (VK_SUCCESS != result) return;
create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data);
Add(CreateShaderModuleState(*pCreateInfo, csm_state->unique_shader_id, *pShaderModule));
}
void ValidationStateTracker::PostCallRecordGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages,
VkResult result) {
if ((result != VK_SUCCESS) && (result != VK_INCOMPLETE)) return;
auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
if (*pSwapchainImageCount > swapchain_state->images.size()) swapchain_state->images.resize(*pSwapchainImageCount);
if (pSwapchainImages) {
for (uint32_t i = 0; i < *pSwapchainImageCount; ++i) {
SWAPCHAIN_IMAGE &swapchain_image = swapchain_state->images[i];
if (swapchain_image.image_state) continue; // Already retrieved this.
auto format_features = GetImageFormatFeatures(
physical_device, has_format_feature2, IsExtEnabled(device_extensions.vk_ext_image_drm_format_modifier), device,
pSwapchainImages[i], swapchain_state->image_create_info.format, swapchain_state->image_create_info.tiling);
auto image_state =
CreateImageState(pSwapchainImages[i], swapchain_state->image_create_info.ptr(), swapchain, i, format_features);
if (!swapchain_image.fake_base_address) {
auto size = image_state->fragment_encoder->TotalSize();
swapchain_image.fake_base_address = fake_memory.Alloc(size);
}
image_state->SetSwapchain(swapchain_state, i);
swapchain_image.image_state = image_state.get();
Add(std::move(image_state));
}
}
if (*pSwapchainImageCount) {
swapchain_state->get_swapchain_image_count = *pSwapchainImageCount;
}
}
void ValidationStateTracker::PostCallRecordCopyAccelerationStructureKHR(VkDevice device, VkDeferredOperationKHR deferredOperation,
const VkCopyAccelerationStructureInfoKHR *pInfo,
VkResult result) {
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
if (dst_as_state != nullptr && src_as_state != nullptr) {
dst_as_state->built = true;
dst_as_state->build_info_khr = src_as_state->build_info_khr;
}
}
void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
const VkCopyAccelerationStructureInfoKHR *pInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTUREKHR);
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
if (dst_as_state != nullptr && src_as_state != nullptr) {
dst_as_state->built = true;
dst_as_state->build_info_khr = src_as_state->build_info_khr;
if (!disabled[command_buffer_state]) {
cb_state->AddChild(dst_as_state);
cb_state->AddChild(src_as_state);
}
}
}
}
void ValidationStateTracker::PostCallRecordCmdCopyAccelerationStructureToMemoryKHR(
VkCommandBuffer commandBuffer, const VkCopyAccelerationStructureToMemoryInfoKHR *pInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordCmd(CMD_COPYACCELERATIONSTRUCTURETOMEMORYKHR);
auto src_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->src);
if (!disabled[command_buffer_state]) {
cb_state->AddChild(src_as_state);
}
auto dst_buffers = GetBuffersByAddress(pInfo->dst.deviceAddress);
if (!dst_buffers.empty()) {
cb_state->AddChildren(dst_buffers);
}
}
}
void ValidationStateTracker::PostCallRecordCmdCopyMemoryToAccelerationStructureKHR(
VkCommandBuffer commandBuffer, const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (cb_state) {
cb_state->RecordCmd(CMD_COPYMEMORYTOACCELERATIONSTRUCTUREKHR);
if (!disabled[command_buffer_state]) {
auto src_buffers = GetBuffersByAddress(pInfo->src.deviceAddress);
if (!src_buffers.empty()) {
cb_state->AddChildren(src_buffers);
}
auto dst_as_state = Get<ACCELERATION_STRUCTURE_STATE_KHR>(pInfo->dst);
cb_state->AddChild(dst_as_state);
}
}
}
void ValidationStateTracker::RecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_CULL_MODE_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
RecordCmdSetCullMode(commandBuffer, cullMode, CMD_SETCULLMODEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode) {
RecordCmdSetCullMode(commandBuffer, cullMode, CMD_SETCULLMODE);
}
void ValidationStateTracker::RecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_FRONT_FACE_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetFrontFaceEXT(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
RecordCmdSetFrontFace(commandBuffer, frontFace, CMD_SETFRONTFACEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetFrontFace(VkCommandBuffer commandBuffer, VkFrontFace frontFace) {
RecordCmdSetFrontFace(commandBuffer, frontFace, CMD_SETFRONTFACE);
}
void ValidationStateTracker::RecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer, VkPrimitiveTopology primitiveTopology,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_PRIMITIVE_TOPOLOGY_SET);
cb_state->primitiveTopology = primitiveTopology;
}
void ValidationStateTracker::PostCallRecordCmdSetPrimitiveTopologyEXT(VkCommandBuffer commandBuffer,
VkPrimitiveTopology primitiveTopology) {
RecordCmdSetPrimitiveTopology(commandBuffer, primitiveTopology, CMD_SETPRIMITIVETOPOLOGYEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetPrimitiveTopology(VkCommandBuffer commandBuffer,
VkPrimitiveTopology primitiveTopology) {
RecordCmdSetPrimitiveTopology(commandBuffer, primitiveTopology, CMD_SETPRIMITIVETOPOLOGY);
}
void ValidationStateTracker::RecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
const VkViewport *pViewports, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_VIEWPORT_WITH_COUNT_SET);
uint32_t bits = (1u << viewportCount) - 1u;
cb_state->viewportWithCountMask |= bits;
cb_state->trashedViewportMask &= ~bits;
cb_state->viewportWithCountCount = viewportCount;
cb_state->trashedViewportCount = false;
cb_state->dynamicViewports.resize(std::max(size_t(viewportCount), cb_state->dynamicViewports.size()));
for (size_t i = 0; i < viewportCount; ++i) {
cb_state->dynamicViewports[i] = pViewports[i];
}
}
void ValidationStateTracker::PostCallRecordCmdSetViewportWithCountEXT(VkCommandBuffer commandBuffer, uint32_t viewportCount,
const VkViewport *pViewports) {
RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNTEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetViewportWithCount(VkCommandBuffer commandBuffer, uint32_t viewportCount,
const VkViewport *pViewports) {
RecordCmdSetViewportWithCount(commandBuffer, viewportCount, pViewports, CMD_SETVIEWPORTWITHCOUNT);
}
void ValidationStateTracker::RecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
const VkRect2D *pScissors, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_SCISSOR_WITH_COUNT_SET);
uint32_t bits = (1u << scissorCount) - 1u;
cb_state->scissorWithCountMask |= bits;
cb_state->trashedScissorMask &= ~bits;
cb_state->scissorWithCountCount = scissorCount;
cb_state->trashedScissorCount = false;
}
void ValidationStateTracker::PostCallRecordCmdSetScissorWithCountEXT(VkCommandBuffer commandBuffer, uint32_t scissorCount,
const VkRect2D *pScissors) {
RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNTEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetScissorWithCount(VkCommandBuffer commandBuffer, uint32_t scissorCount,
const VkRect2D *pScissors) {
RecordCmdSetScissorWithCount(commandBuffer, scissorCount, pScissors, CMD_SETSCISSORWITHCOUNT);
}
void ValidationStateTracker::RecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
uint32_t bindingCount, const VkBuffer *pBuffers,
const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
const VkDeviceSize *pStrides, CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
if (pStrides) {
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE_SET);
}
uint32_t end = firstBinding + bindingCount;
if (cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.size() < end) {
cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings.resize(end);
}
for (uint32_t i = 0; i < bindingCount; ++i) {
auto &vertex_buffer_binding = cb_state->current_vertex_buffer_binding_info.vertex_buffer_bindings[i + firstBinding];
vertex_buffer_binding.buffer_state = Get<BUFFER_STATE>(pBuffers[i]);
vertex_buffer_binding.offset = pOffsets[i];
vertex_buffer_binding.size = (pSizes) ? pSizes[i] : VK_WHOLE_SIZE;
vertex_buffer_binding.stride = (pStrides) ? pStrides[i] : 0;
// Add binding for this vertex buffer to this commandbuffer
if (!disabled[command_buffer_state] && pBuffers[i]) {
cb_state->AddChild(vertex_buffer_binding.buffer_state);
}
}
}
void ValidationStateTracker::PostCallRecordCmdBindVertexBuffers2EXT(VkCommandBuffer commandBuffer, uint32_t firstBinding,
uint32_t bindingCount, const VkBuffer *pBuffers,
const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
const VkDeviceSize *pStrides) {
RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
CMD_BINDVERTEXBUFFERS2EXT);
}
void ValidationStateTracker::PostCallRecordCmdBindVertexBuffers2(VkCommandBuffer commandBuffer, uint32_t firstBinding,
uint32_t bindingCount, const VkBuffer *pBuffers,
const VkDeviceSize *pOffsets, const VkDeviceSize *pSizes,
const VkDeviceSize *pStrides) {
RecordCmdBindVertexBuffers2(commandBuffer, firstBinding, bindingCount, pBuffers, pOffsets, pSizes, pStrides,
CMD_BINDVERTEXBUFFERS2);
}
void ValidationStateTracker::RecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_DEPTH_TEST_ENABLE_SET);
cb_state->dynamic_state_value.depth_test_enable = depthTestEnable;
}
void ValidationStateTracker::PostCallRecordCmdSetDepthTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
RecordCmdSetDepthTestEnable(commandBuffer, depthTestEnable, CMD_SETDEPTHTESTENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthTestEnable) {
RecordCmdSetDepthTestEnable(commandBuffer, depthTestEnable, CMD_SETDEPTHTESTENABLE);
}
void ValidationStateTracker::RecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_DEPTH_WRITE_ENABLE_SET);
cb_state->dynamic_state_value.depth_write_enable = depthWriteEnable;
}
void ValidationStateTracker::PostCallRecordCmdSetDepthWriteEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
RecordCmdSetDepthWriteEnable(commandBuffer, depthWriteEnable, CMD_SETDEPTHWRITEENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthWriteEnable(VkCommandBuffer commandBuffer, VkBool32 depthWriteEnable) {
RecordCmdSetDepthWriteEnable(commandBuffer, depthWriteEnable, CMD_SETDEPTHWRITEENABLE);
}
void ValidationStateTracker::RecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHCOMPAREOP, CB_DYNAMIC_DEPTH_COMPARE_OP_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthCompareOpEXT(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
RecordCmdSetDepthCompareOp(commandBuffer, depthCompareOp, CMD_SETDEPTHCOMPAREOPEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthCompareOp(VkCommandBuffer commandBuffer, VkCompareOp depthCompareOp) {
RecordCmdSetDepthCompareOp(commandBuffer, depthCompareOp, CMD_SETDEPTHCOMPAREOP);
}
void ValidationStateTracker::RecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer, VkBool32 depthBoundsTestEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBoundsTestEnableEXT(VkCommandBuffer commandBuffer,
VkBool32 depthBoundsTestEnable) {
RecordCmdSetDepthBoundsTestEnable(commandBuffer, depthBoundsTestEnable, CMD_SETDEPTHBOUNDSTESTENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBoundsTestEnable(VkCommandBuffer commandBuffer,
VkBool32 depthBoundsTestEnable) {
RecordCmdSetDepthBoundsTestEnable(commandBuffer, depthBoundsTestEnable, CMD_SETDEPTHBOUNDSTESTENABLE);
}
void ValidationStateTracker::RecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_STENCIL_TEST_ENABLE_SET);
cb_state->dynamic_state_value.stencil_test_enable = stencilTestEnable;
}
void ValidationStateTracker::PostCallRecordCmdSetStencilTestEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
RecordCmdSetStencilTestEnable(commandBuffer, stencilTestEnable, CMD_SETSTENCILTESTENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetStencilTestEnable(VkCommandBuffer commandBuffer, VkBool32 stencilTestEnable) {
RecordCmdSetStencilTestEnable(commandBuffer, stencilTestEnable, CMD_SETSTENCILTESTENABLE);
}
void ValidationStateTracker::RecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask, VkStencilOp failOp,
VkStencilOp passOp, VkStencilOp depthFailOp, VkCompareOp compareOp,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_STENCIL_OP_SET);
if (faceMask == VK_STENCIL_FACE_FRONT_BIT || faceMask == VK_STENCIL_FACE_FRONT_AND_BACK) {
cb_state->dynamic_state_value.fail_op_front = failOp;
cb_state->dynamic_state_value.pass_op_front = passOp;
cb_state->dynamic_state_value.depth_fail_op_front = depthFailOp;
}
if (faceMask == VK_STENCIL_FACE_BACK_BIT || faceMask == VK_STENCIL_FACE_FRONT_AND_BACK) {
cb_state->dynamic_state_value.fail_op_back = failOp;
cb_state->dynamic_state_value.pass_op_back = passOp;
cb_state->dynamic_state_value.depth_fail_op_back = depthFailOp;
}
}
void ValidationStateTracker::PostCallRecordCmdSetStencilOpEXT(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
VkCompareOp compareOp) {
RecordCmdSetStencilOp(commandBuffer, faceMask, failOp, passOp, depthFailOp, compareOp, CMD_SETSTENCILOPEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetStencilOp(VkCommandBuffer commandBuffer, VkStencilFaceFlags faceMask,
VkStencilOp failOp, VkStencilOp passOp, VkStencilOp depthFailOp,
VkCompareOp compareOp) {
RecordCmdSetStencilOp(commandBuffer, faceMask, failOp, passOp, depthFailOp, compareOp, CMD_SETSTENCILOP);
}
void ValidationStateTracker::PostCallRecordCmdSetDiscardRectangleEXT(VkCommandBuffer commandBuffer, uint32_t firstDiscardRectangle,
uint32_t discardRectangleCount,
const VkRect2D *pDiscardRectangles) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDISCARDRECTANGLEEXT, CB_DYNAMIC_DISCARD_RECTANGLE_EXT_SET);
for (uint32_t i = 0; i < discardRectangleCount; i++) {
cb_state->dynamic_state_value.discard_rectangles.set(firstDiscardRectangle + i);
}
}
void ValidationStateTracker::PostCallRecordCmdSetSampleLocationsEXT(VkCommandBuffer commandBuffer,
const VkSampleLocationsInfoEXT *pSampleLocationsInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSEXT, CB_DYNAMIC_SAMPLE_LOCATIONS_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoarseSampleOrderNV(VkCommandBuffer commandBuffer,
VkCoarseSampleOrderTypeNV sampleOrderType,
uint32_t customSampleOrderCount,
const VkCoarseSampleOrderCustomNV *pCustomSampleOrders) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOARSESAMPLEORDERNV, CB_DYNAMIC_VIEWPORT_COARSE_SAMPLE_ORDER_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetPatchControlPointsEXT(VkCommandBuffer commandBuffer, uint32_t patchControlPoints) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETPATCHCONTROLPOINTSEXT, CB_DYNAMIC_PATCH_CONTROL_POINTS_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLogicOpEXT(VkCommandBuffer commandBuffer, VkLogicOp logicOp) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLOGICOPEXT, CB_DYNAMIC_LOGIC_OP_EXT_SET);
}
void ValidationStateTracker::RecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer, VkBool32 rasterizerDiscardEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_RASTERIZER_DISCARD_ENABLE_SET);
cb_state->rasterization_disabled = rasterizerDiscardEnable == VK_TRUE;
}
void ValidationStateTracker::PostCallRecordCmdSetRasterizerDiscardEnableEXT(VkCommandBuffer commandBuffer,
VkBool32 rasterizerDiscardEnable) {
RecordCmdSetRasterizerDiscardEnable(commandBuffer, rasterizerDiscardEnable, CMD_SETRASTERIZERDISCARDENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetRasterizerDiscardEnable(VkCommandBuffer commandBuffer,
VkBool32 rasterizerDiscardEnable) {
RecordCmdSetRasterizerDiscardEnable(commandBuffer, rasterizerDiscardEnable, CMD_SETRASTERIZERDISCARDENABLE);
}
void ValidationStateTracker::RecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_DEPTH_BIAS_ENABLE_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
RecordCmdSetDepthBiasEnable(commandBuffer, depthBiasEnable, CMD_SETDEPTHBIASENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthBiasEnable(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) {
RecordCmdSetDepthBiasEnable(commandBuffer, depthBiasEnable, CMD_SETDEPTHBIASENABLE);
}
void ValidationStateTracker::RecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer, VkBool32 primitiveRestartEnable,
CMD_TYPE cmd_type) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(cmd_type, CB_DYNAMIC_PRIMITIVE_RESTART_ENABLE_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer,
VkBool32 primitiveRestartEnable) {
RecordCmdSetPrimitiveRestartEnable(commandBuffer, primitiveRestartEnable, CMD_SETPRIMITIVERESTARTENABLEEXT);
}
void ValidationStateTracker::PostCallRecordCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer,
VkBool32 primitiveRestartEnable) {
RecordCmdSetPrimitiveRestartEnable(commandBuffer, primitiveRestartEnable, CMD_SETPRIMITIVERESTARTENABLE);
}
void ValidationStateTracker::PostCallRecordCmdSetVertexInputEXT(
VkCommandBuffer commandBuffer, uint32_t vertexBindingDescriptionCount,
const VkVertexInputBindingDescription2EXT *pVertexBindingDescriptions, uint32_t vertexAttributeDescriptionCount,
const VkVertexInputAttributeDescription2EXT *pVertexAttributeDescriptions) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
CBDynamicFlags status_flags;
status_flags.set(CB_DYNAMIC_VERTEX_INPUT_EXT_SET);
const auto lv_bind_point = ConvertToLvlBindPoint(VK_PIPELINE_BIND_POINT_GRAPHICS);
const auto pipeline_state = cb_state->lastBound[lv_bind_point].pipeline_state;
if (pipeline_state) {
const auto *dynamic_state = pipeline_state->DynamicState();
if (dynamic_state) {
for (uint32_t i = 0; i < dynamic_state->dynamicStateCount; ++i) {
if (dynamic_state->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
status_flags.set(CB_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE_SET);
break;
}
}
}
}
cb_state->RecordStateCmd(CMD_SETVERTEXINPUTEXT, status_flags);
}
void ValidationStateTracker::PostCallRecordCmdSetColorWriteEnableEXT(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkBool32 *pColorWriteEnables) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordColorWriteEnableStateCmd(CMD_SETCOLORWRITEENABLEEXT, CB_DYNAMIC_COLOR_WRITE_ENABLE_EXT_SET, attachmentCount);
}
#ifdef VK_USE_PLATFORM_WIN32_KHR
void ValidationStateTracker::PostCallRecordAcquireFullScreenExclusiveModeEXT(VkDevice device, VkSwapchainKHR swapchain,
VkResult result) {
if (result != VK_SUCCESS) return;
auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
swapchain_state->exclusive_full_screen_access = true;
}
void ValidationStateTracker::PostCallRecordReleaseFullScreenExclusiveModeEXT(VkDevice device, VkSwapchainKHR swapchain,
VkResult result) {
if (result != VK_SUCCESS) return;
auto swapchain_state = Get<SWAPCHAIN_NODE>(swapchain);
swapchain_state->exclusive_full_screen_access = false;
}
#endif
void ValidationStateTracker::PostCallRecordCmdSetTessellationDomainOriginEXT(VkCommandBuffer commandBuffer,
VkTessellationDomainOrigin domainOrigin) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETTESSELLATIONDOMAINORIGINEXT, CB_DYNAMIC_TESSELLATION_DOMAIN_ORIGIN_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthClampEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthClampEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHCLAMPENABLEEXT, CB_DYNAMIC_DEPTH_CLAMP_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetPolygonModeEXT(VkCommandBuffer commandBuffer, VkPolygonMode polygonMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETPOLYGONMODEEXT, CB_DYNAMIC_POLYGON_MODE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetRasterizationSamplesEXT(VkCommandBuffer commandBuffer,
VkSampleCountFlagBits rasterizationSamples) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETRASTERIZATIONSAMPLESEXT, CB_DYNAMIC_RASTERIZATION_SAMPLES_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetSampleMaskEXT(VkCommandBuffer commandBuffer, VkSampleCountFlagBits samples,
const VkSampleMask *pSampleMask) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSAMPLEMASKEXT, CB_DYNAMIC_SAMPLE_MASK_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetAlphaToCoverageEnableEXT(VkCommandBuffer commandBuffer,
VkBool32 alphaToCoverageEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETALPHATOCOVERAGEENABLEEXT, CB_DYNAMIC_ALPHA_TO_COVERAGE_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetAlphaToOneEnableEXT(VkCommandBuffer commandBuffer, VkBool32 alphaToOneEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETALPHATOONEENABLEEXT, CB_DYNAMIC_ALPHA_TO_ONE_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLogicOpEnableEXT(VkCommandBuffer commandBuffer, VkBool32 logicOpEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLOGICOPENABLEEXT, CB_DYNAMIC_LOGIC_OP_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetColorBlendEnableEXT(VkCommandBuffer commandBuffer, uint32_t firstAttachment,
uint32_t attachmentCount, const VkBool32 *pColorBlendEnables) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOLORBLENDENABLEEXT, CB_DYNAMIC_COLOR_BLEND_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetColorBlendEquationEXT(VkCommandBuffer commandBuffer, uint32_t firstAttachment,
uint32_t attachmentCount,
const VkColorBlendEquationEXT *pColorBlendEquations) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOLORBLENDEQUATIONEXT, CB_DYNAMIC_COLOR_BLEND_EQUATION_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetColorWriteMaskEXT(VkCommandBuffer commandBuffer, uint32_t firstAttachment,
uint32_t attachmentCount,
const VkColorComponentFlags *pColorWriteMasks) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOLORWRITEMASKEXT, CB_DYNAMIC_COLOR_WRITE_MASK_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetRasterizationStreamEXT(VkCommandBuffer commandBuffer,
uint32_t rasterizationStream) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETRASTERIZATIONSTREAMEXT, CB_DYNAMIC_RASTERIZATION_STREAM_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetConservativeRasterizationModeEXT(
VkCommandBuffer commandBuffer, VkConservativeRasterizationModeEXT conservativeRasterizationMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCONSERVATIVERASTERIZATIONMODEEXT, CB_DYNAMIC_CONSERVATIVE_RASTERIZATION_MODE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetExtraPrimitiveOverestimationSizeEXT(VkCommandBuffer commandBuffer,
float extraPrimitiveOverestimationSize) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETEXTRAPRIMITIVEOVERESTIMATIONSIZEEXT, CB_DYNAMIC_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthClipEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthClipEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHCLIPENABLEEXT, CB_DYNAMIC_DEPTH_CLIP_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetSampleLocationsEnableEXT(VkCommandBuffer commandBuffer,
VkBool32 sampleLocationsEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSAMPLELOCATIONSENABLEEXT, CB_DYNAMIC_SAMPLE_LOCATIONS_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetColorBlendAdvancedEXT(VkCommandBuffer commandBuffer, uint32_t firstAttachment,
uint32_t attachmentCount,
const VkColorBlendAdvancedEXT *pColorBlendAdvanced) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOLORBLENDADVANCEDEXT, CB_DYNAMIC_COLOR_BLEND_ADVANCED_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetProvokingVertexModeEXT(VkCommandBuffer commandBuffer,
VkProvokingVertexModeEXT provokingVertexMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETPROVOKINGVERTEXMODEEXT, CB_DYNAMIC_PROVOKING_VERTEX_MODE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLineRasterizationModeEXT(VkCommandBuffer commandBuffer,
VkLineRasterizationModeEXT lineRasterizationMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLINERASTERIZATIONMODEEXT, CB_DYNAMIC_LINE_RASTERIZATION_MODE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetLineStippleEnableEXT(VkCommandBuffer commandBuffer, VkBool32 stippledLineEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETLINESTIPPLEENABLEEXT, CB_DYNAMIC_LINE_STIPPLE_ENABLE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetDepthClipNegativeOneToOneEXT(VkCommandBuffer commandBuffer,
VkBool32 negativeOneToOne) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETDEPTHCLIPNEGATIVEONETOONEEXT, CB_DYNAMIC_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE_EXT_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetViewportWScalingEnableNV(VkCommandBuffer commandBuffer,
VkBool32 viewportWScalingEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETVIEWPORTWSCALINGENABLENV, CB_DYNAMIC_VIEWPORT_W_SCALING_ENABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetViewportSwizzleNV(VkCommandBuffer commandBuffer, uint32_t firstViewport,
uint32_t viewportCount,
const VkViewportSwizzleNV *pViewportSwizzles) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETVIEWPORTSWIZZLENV, CB_DYNAMIC_VIEWPORT_SWIZZLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageToColorEnableNV(VkCommandBuffer commandBuffer,
VkBool32 coverageToColorEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGETOCOLORENABLENV, CB_DYNAMIC_COVERAGE_TO_COLOR_ENABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageToColorLocationNV(VkCommandBuffer commandBuffer,
uint32_t coverageToColorLocation) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGETOCOLORLOCATIONNV, CB_DYNAMIC_COVERAGE_TO_COLOR_LOCATION_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageModulationModeNV(VkCommandBuffer commandBuffer,
VkCoverageModulationModeNV coverageModulationMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGEMODULATIONMODENV, CB_DYNAMIC_COVERAGE_MODULATION_MODE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageModulationTableEnableNV(VkCommandBuffer commandBuffer,
VkBool32 coverageModulationTableEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGEMODULATIONTABLEENABLENV, CB_DYNAMIC_COVERAGE_MODULATION_TABLE_ENABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageModulationTableNV(VkCommandBuffer commandBuffer,
uint32_t coverageModulationTableCount,
const float *pCoverageModulationTable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGEMODULATIONTABLENV, CB_DYNAMIC_COVERAGE_MODULATION_TABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetShadingRateImageEnableNV(VkCommandBuffer commandBuffer,
VkBool32 shadingRateImageEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETSHADINGRATEIMAGEENABLENV, CB_DYNAMIC_SHADING_RATE_IMAGE_ENABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetRepresentativeFragmentTestEnableNV(VkCommandBuffer commandBuffer,
VkBool32 representativeFragmentTestEnable) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETREPRESENTATIVEFRAGMENTTESTENABLENV, CB_DYNAMIC_REPRESENTATIVE_FRAGMENT_TEST_ENABLE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdSetCoverageReductionModeNV(VkCommandBuffer commandBuffer,
VkCoverageReductionModeNV coverageReductionMode) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordStateCmd(CMD_SETCOVERAGEREDUCTIONMODENV, CB_DYNAMIC_COVERAGE_REDUCTION_MODE_NV_SET);
}
void ValidationStateTracker::PostCallRecordCmdControlVideoCodingKHR(VkCommandBuffer commandBuffer,
const VkVideoCodingControlInfoKHR *pCodingControlInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->ControlVideoCoding(pCodingControlInfo);
}
void ValidationStateTracker::PostCallRecordCmdDecodeVideoKHR(VkCommandBuffer commandBuffer,
const VkVideoDecodeInfoKHR *pDecodeInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
cb_state->DecodeVideo(pDecodeInfo);
}
void ValidationStateTracker::RecordGetBufferDeviceAddress(const VkBufferDeviceAddressInfo *pInfo, VkDeviceAddress address) {
auto buffer_state = Get<BUFFER_STATE>(pInfo->buffer);
if (buffer_state && address != 0) {
WriteLockGuard guard(buffer_address_lock_);
// address is used for GPU-AV and ray tracing buffer validation
buffer_state->deviceAddress = address;
const auto address_range = buffer_state->DeviceAddressRange();
buffer_address_map_.split_and_merge_insert(
{address_range, {buffer_state}}, [](auto ¤t_buffer_list, const auto &new_buffer) {
assert(!current_buffer_list.empty());
const auto buffer_found_it = std::find(current_buffer_list.begin(), current_buffer_list.end(), new_buffer[0]);
if (buffer_found_it == current_buffer_list.end()) {
current_buffer_list.emplace_back(new_buffer[0]);
}
});
}
}
void ValidationStateTracker::PostCallRecordGetBufferDeviceAddress(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
VkDeviceAddress address) {
RecordGetBufferDeviceAddress(pInfo, address);
}
void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressKHR(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
VkDeviceAddress address) {
RecordGetBufferDeviceAddress(pInfo, address);
}
void ValidationStateTracker::PostCallRecordGetBufferDeviceAddressEXT(VkDevice device, const VkBufferDeviceAddressInfo *pInfo,
VkDeviceAddress address) {
RecordGetBufferDeviceAddress(pInfo, address);
}
std::shared_ptr<SWAPCHAIN_NODE> ValidationStateTracker::CreateSwapchainState(const VkSwapchainCreateInfoKHR *create_info,
VkSwapchainKHR swapchain) {
return std::make_shared<SWAPCHAIN_NODE>(this, create_info, swapchain);
}
std::shared_ptr<CMD_BUFFER_STATE> ValidationStateTracker::CreateCmdBufferState(VkCommandBuffer cb,
const VkCommandBufferAllocateInfo *create_info,
const COMMAND_POOL_STATE *pool) {
return std::make_shared<CMD_BUFFER_STATE>(this, cb, create_info, pool);
}
std::shared_ptr<DEVICE_MEMORY_STATE> ValidationStateTracker::CreateDeviceMemoryState(
VkDeviceMemory mem, const VkMemoryAllocateInfo *p_alloc_info, uint64_t fake_address, const VkMemoryType &memory_type,
const VkMemoryHeap &memory_heap, std::optional<DedicatedBinding> &&dedicated_binding, uint32_t physical_device_count) {
return std::make_shared<DEVICE_MEMORY_STATE>(mem, p_alloc_info, fake_address, memory_type, memory_heap,
std::move(dedicated_binding), physical_device_count);
}
|