1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663
|
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (C) 2015-2025 Google Inc.
* Modifications Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
*
* 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.
*/
#include <algorithm>
#include <assert.h>
#include <sstream>
#include <vector>
#include <vulkan/vk_enum_string_helper.h>
#include <vulkan/utility/vk_format_utils.h>
#include <vulkan/vulkan_core.h>
#include "containers/container_utils.h"
#include "core_checks/cc_state_tracker.h"
#include "core_validation.h"
#include "error_message/error_location.h"
#include "utils/convert_utils.h"
#include "error_message/error_strings.h"
#include "state_tracker/buffer_state.h"
#include "state_tracker/image_state.h"
#include "state_tracker/render_pass_state.h"
#include "state_tracker/cmd_buffer_state.h"
#include "utils/math_utils.h"
#include "utils/image_utils.h"
namespace vvl {
template <typename T>
T GetQuotientCeil(T numerator, T denominator) {
denominator = std::max(denominator, T{1});
return static_cast<T>(std::ceil(static_cast<double>(numerator) / static_cast<double>(denominator)));
}
} // namespace vvl
bool CoreChecks::ValidateAttachmentCompatibility(const VulkanTypedHandle &rp1_object, const vvl::RenderPass &rp1_state,
const VulkanTypedHandle &rp2_object, const vvl::RenderPass &rp2_state,
uint32_t primary_attachment, uint32_t secondary_attachment,
const Location &caller_loc, const Location &attachment_loc,
const char *vuid) const {
bool skip = false;
const auto &primary_pass_ci = rp1_state.create_info;
const auto &secondary_pass_ci = rp2_state.create_info;
if (primary_pass_ci.attachmentCount <= primary_attachment) {
primary_attachment = VK_ATTACHMENT_UNUSED;
}
if (secondary_pass_ci.attachmentCount <= secondary_attachment) {
secondary_attachment = VK_ATTACHMENT_UNUSED;
}
if (primary_attachment == VK_ATTACHMENT_UNUSED && secondary_attachment == VK_ATTACHMENT_UNUSED) {
return skip;
}
if (primary_attachment == VK_ATTACHMENT_UNUSED) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, caller_loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the first is VK_ATTACHMENT_UNUSED while the second is %s.",
attachment_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(),
string_Attachment(secondary_attachment).c_str());
return skip;
}
if (secondary_attachment == VK_ATTACHMENT_UNUSED) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, caller_loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the first is %s while the second is VK_ATTACHMENT_UNUSED.",
attachment_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(),
string_Attachment(primary_attachment).c_str());
return skip;
}
if (primary_pass_ci.pAttachments[primary_attachment].format != secondary_pass_ci.pAttachments[secondary_attachment].format) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, caller_loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"pAttachments[%" PRIu32 "].format (%s) != pAttachments[%" PRIu32 "].format (%s).",
attachment_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(), primary_attachment,
string_VkFormat(primary_pass_ci.pAttachments[primary_attachment].format), secondary_attachment,
string_VkFormat(secondary_pass_ci.pAttachments[secondary_attachment].format));
}
if (primary_pass_ci.pAttachments[primary_attachment].samples != secondary_pass_ci.pAttachments[secondary_attachment].samples) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, caller_loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"pAttachments[%" PRIu32 "].samples (%s) != pAttachments[%" PRIu32 "].samples (%s).",
attachment_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(), primary_attachment,
string_VkSampleCountFlagBits(primary_pass_ci.pAttachments[primary_attachment].samples), secondary_attachment,
string_VkSampleCountFlagBits(secondary_pass_ci.pAttachments[secondary_attachment].samples));
}
if (primary_pass_ci.pAttachments[primary_attachment].flags != secondary_pass_ci.pAttachments[secondary_attachment].flags) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, caller_loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"pAttachments[%" PRIu32 "].flags (%s) != pAttachments[%" PRIu32 "].flags (%s).",
attachment_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(), primary_attachment,
string_VkAttachmentDescriptionFlags(primary_pass_ci.pAttachments[primary_attachment].flags).c_str(),
secondary_attachment,
string_VkAttachmentDescriptionFlags(secondary_pass_ci.pAttachments[secondary_attachment].flags).c_str());
}
return skip;
}
bool CoreChecks::ValidateSubpassCompatibility(const VulkanTypedHandle &rp1_object, const vvl::RenderPass &rp1_state,
const VulkanTypedHandle &rp2_object, const vvl::RenderPass &rp2_state,
const int subpass, const Location &loc, const char *vuid) const {
bool skip = false;
const auto &primary_desc = rp1_state.create_info.pSubpasses[subpass];
const auto &secondary_desc = rp2_state.create_info.pSubpasses[subpass];
const Location subpass_loc(Func::Empty, Field::pSubpasses, subpass);
uint32_t max_input_attachment_count = std::max(primary_desc.inputAttachmentCount, secondary_desc.inputAttachmentCount);
for (uint32_t i = 0; i < max_input_attachment_count; ++i) {
uint32_t primary_input_attach = VK_ATTACHMENT_UNUSED, secondary_input_attach = VK_ATTACHMENT_UNUSED;
if (i < primary_desc.inputAttachmentCount) {
primary_input_attach = primary_desc.pInputAttachments[i].attachment;
}
if (i < secondary_desc.inputAttachmentCount) {
secondary_input_attach = secondary_desc.pInputAttachments[i].attachment;
}
skip |= ValidateAttachmentCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, primary_input_attach,
secondary_input_attach, loc,
subpass_loc.dot(Field::pInputAttachments, i).dot(Field::attachment), vuid);
}
uint32_t max_color_attachment_count = std::max(primary_desc.colorAttachmentCount, secondary_desc.colorAttachmentCount);
for (uint32_t i = 0; i < max_color_attachment_count; ++i) {
uint32_t primary_color_attach = VK_ATTACHMENT_UNUSED, secondary_color_attach = VK_ATTACHMENT_UNUSED;
if (i < primary_desc.colorAttachmentCount) {
primary_color_attach = primary_desc.pColorAttachments[i].attachment;
}
if (i < secondary_desc.colorAttachmentCount) {
secondary_color_attach = secondary_desc.pColorAttachments[i].attachment;
}
skip |= ValidateAttachmentCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, primary_color_attach,
secondary_color_attach, loc,
subpass_loc.dot(Field::pColorAttachments, i).dot(Field::attachment), vuid);
if (rp1_state.create_info.subpassCount > 1) {
uint32_t primary_resolve_attach = VK_ATTACHMENT_UNUSED, secondary_resolve_attach = VK_ATTACHMENT_UNUSED;
if (i < primary_desc.colorAttachmentCount && primary_desc.pResolveAttachments) {
primary_resolve_attach = primary_desc.pResolveAttachments[i].attachment;
}
if (i < secondary_desc.colorAttachmentCount && secondary_desc.pResolveAttachments) {
secondary_resolve_attach = secondary_desc.pResolveAttachments[i].attachment;
}
skip |= ValidateAttachmentCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, primary_resolve_attach,
secondary_resolve_attach, loc,
subpass_loc.dot(Field::pResolveAttachments, i).dot(Field::attachment), vuid);
}
}
uint32_t primary_depthstencil_attach = VK_ATTACHMENT_UNUSED, secondary_depthstencil_attach = VK_ATTACHMENT_UNUSED;
if (primary_desc.pDepthStencilAttachment) {
primary_depthstencil_attach = primary_desc.pDepthStencilAttachment[0].attachment;
}
if (secondary_desc.pDepthStencilAttachment) {
secondary_depthstencil_attach = secondary_desc.pDepthStencilAttachment[0].attachment;
}
skip |= ValidateAttachmentCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, primary_depthstencil_attach,
secondary_depthstencil_attach, loc,
subpass_loc.dot(Field::pDepthStencilAttachment).dot(Field::attachment), vuid);
if (primary_desc.flags != secondary_desc.flags) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"%s != %s",
subpass_loc.dot(Field::flags).Fields().c_str(), FormatHandle(rp1_state).c_str(),
FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(),
string_VkSubpassDescriptionFlags(primary_desc.flags).c_str(),
string_VkSubpassDescriptionFlags(secondary_desc.flags).c_str());
}
// Both renderpasses must agree on Multiview usage
if (primary_desc.viewMask && secondary_desc.viewMask) {
if (primary_desc.viewMask != secondary_desc.viewMask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"0x%" PRIx32 " != 0x%" PRIx32 "",
subpass_loc.dot(Field::viewMask).Fields().c_str(), FormatHandle(rp1_state).c_str(),
FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(),
primary_desc.viewMask, secondary_desc.viewMask);
}
} else if (primary_desc.viewMask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the first uses Multiview (has non-zero viewMasks) while the second one does not.",
subpass_loc.dot(Field::viewMask).Fields().c_str(), FormatHandle(rp1_state).c_str(),
FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str());
} else if (secondary_desc.viewMask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the second uses Multiview (has non-zero viewMasks) while the first one does not.",
subpass_loc.dot(Field::viewMask).Fields().c_str(), FormatHandle(rp1_state).c_str(),
FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str());
}
// Find Fragment Shading Rate attachment entries in render passes if they
// exist.
const auto fsr1 = vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(primary_desc.pNext);
const auto fsr2 = vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(secondary_desc.pNext);
if (fsr1 && fsr2) {
if ((fsr1->shadingRateAttachmentTexelSize.width != fsr2->shadingRateAttachmentTexelSize.width) ||
(fsr1->shadingRateAttachmentTexelSize.height != fsr2->shadingRateAttachmentTexelSize.height)) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"(%s) != (%s).",
subpass_loc.pNext(Struct::VkFragmentShadingRateAttachmentInfoKHR, Field::shadingRateAttachmentTexelSize)
.Fields()
.c_str(),
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkExtent2D(fsr1->shadingRateAttachmentTexelSize).c_str(),
string_VkExtent2D(fsr2->shadingRateAttachmentTexelSize).c_str());
}
} else if (fsr1) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the first uses a VkFragmentShadingRateAttachmentInfoKHR pNext while the second one does not.",
subpass_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str());
} else if (fsr2) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"%s is incompatible between %s (from %s) and %s (from %s), "
"the second uses a VkFragmentShadingRateAttachmentInfoKHR pNext while the first one does not.",
subpass_loc.Fields().c_str(), FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str());
}
return skip;
}
bool CoreChecks::ValidateDependencyCompatibility(const VulkanTypedHandle &rp1_object, const vvl::RenderPass &rp1_state,
const VulkanTypedHandle &rp2_object, const vvl::RenderPass &rp2_state,
const uint32_t dependency, const Location &loc, const char *vuid) const {
bool skip = false;
const auto &primary_dep = rp1_state.create_info.pDependencies[dependency];
const auto &secondary_dep = rp2_state.create_info.pDependencies[dependency];
VkPipelineStageFlags2 primary_src_stage_mask = primary_dep.srcStageMask;
VkPipelineStageFlags2 primary_dst_stage_mask = primary_dep.dstStageMask;
VkAccessFlags2 primary_src_access_mask = primary_dep.srcAccessMask;
VkAccessFlags2 primary_dst_access_mask = primary_dep.dstAccessMask;
VkPipelineStageFlags2 secondary_src_stage_mask = secondary_dep.srcStageMask;
VkPipelineStageFlags2 secondary_dst_stage_mask = secondary_dep.dstStageMask;
VkAccessFlags2 secondary_src_access_mask = secondary_dep.srcAccessMask;
VkAccessFlags2 secondary_dst_access_mask = secondary_dep.dstAccessMask;
if (const auto primary_barrier = vku::FindStructInPNextChain<VkMemoryBarrier2>(rp1_state.create_info.pNext); primary_barrier) {
primary_src_stage_mask = primary_barrier->srcStageMask;
primary_dst_stage_mask = primary_barrier->dstStageMask;
primary_src_access_mask = primary_barrier->srcAccessMask;
primary_dst_access_mask = primary_barrier->dstAccessMask;
}
if (const auto secondary_barrier = vku::FindStructInPNextChain<VkMemoryBarrier2>(rp2_state.create_info.pNext);
secondary_barrier) {
secondary_src_stage_mask = secondary_barrier->srcStageMask;
secondary_dst_stage_mask = secondary_barrier->dstStageMask;
secondary_src_access_mask = secondary_barrier->srcAccessMask;
secondary_dst_access_mask = secondary_barrier->dstAccessMask;
}
if (primary_dep.srcSubpass != secondary_dep.srcSubpass) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].srcSubpass is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 ".",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), primary_dep.srcSubpass, secondary_dep.srcSubpass);
}
if (primary_dep.dstSubpass != secondary_dep.dstSubpass) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].dstSubpass is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 ".",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), primary_dep.dstSubpass, secondary_dep.dstSubpass);
}
if (primary_src_stage_mask != secondary_src_stage_mask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].srcStageMask is incompatible between %s (from %s) and %s (from %s), "
"%s != %s.",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkPipelineStageFlags2(primary_src_stage_mask).c_str(),
string_VkPipelineStageFlags2(secondary_src_stage_mask).c_str());
}
if (primary_dst_stage_mask != secondary_dst_stage_mask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].dstStageMask is incompatible between %s (from %s) and %s (from %s), "
"%s != %s.",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkPipelineStageFlags2(primary_dst_stage_mask).c_str(),
string_VkPipelineStageFlags2(secondary_dst_stage_mask).c_str());
}
if (primary_src_access_mask != secondary_src_access_mask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].srcAccessMask is incompatible between %s (from %s) and %s (from %s), "
"%s != %s.",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkAccessFlags2(primary_src_access_mask).c_str(),
string_VkAccessFlags2(secondary_src_access_mask).c_str());
}
if (primary_dst_access_mask != secondary_dst_access_mask) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].dstAccessMask is incompatible between %s (from %s) and %s (from %s), "
"%s != %s.",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkAccessFlags2(primary_dst_access_mask).c_str(),
string_VkAccessFlags2(secondary_dst_access_mask).c_str());
}
if (primary_dep.dependencyFlags != secondary_dep.dependencyFlags) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].dependencyFlags is incompatible between %s (from %s) and %s (from %s), "
"%s != %s.",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkDependencyFlags(primary_dep.dependencyFlags).c_str(),
string_VkDependencyFlags(secondary_dep.dependencyFlags).c_str());
}
if (primary_dep.viewOffset != secondary_dep.viewOffset) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |=
LogError(vuid, objlist, loc,
"pDependencies[%" PRIu32
"].viewOffset is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 ".",
dependency, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), primary_dep.viewOffset, secondary_dep.viewOffset);
}
return skip;
}
// Verify that given renderPass CreateInfo for primary and secondary command buffers are compatible.
// This function deals directly with the CreateInfo, there are overloaded versions below that can take the renderPass handle and
// will then feed into this function
bool CoreChecks::ValidateRenderPassCompatibility(const VulkanTypedHandle &rp1_object, const vvl::RenderPass &rp1_state,
const VulkanTypedHandle &rp2_object, const vvl::RenderPass &rp2_state,
const Location &loc, const char *vuid) const {
bool skip = false;
// createInfo flags must be identical for the renderpasses to be compatible.
if (rp1_state.create_info.flags != rp2_state.create_info.flags) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"VkRenderPassCreateFlags is incompatible between %s (from %s) and %s (from %s), "
"%s != %s",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), string_VkRenderPassCreateFlags(rp1_state.create_info.flags).c_str(),
string_VkRenderPassCreateFlags(rp2_state.create_info.flags).c_str());
}
if (rp1_state.create_info.subpassCount != rp2_state.create_info.subpassCount) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"subpassCount is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 "",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), rp1_state.create_info.subpassCount, rp2_state.create_info.subpassCount);
} else {
for (uint32_t i = 0; i < rp1_state.create_info.subpassCount; ++i) {
skip |= ValidateSubpassCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, i, loc, vuid);
}
}
if (rp1_state.create_info.dependencyCount != rp2_state.create_info.dependencyCount) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"dependencyCount is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 "",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), rp1_state.create_info.dependencyCount,
rp2_state.create_info.dependencyCount);
} else {
for (uint32_t i = 0; i < rp1_state.create_info.dependencyCount; ++i) {
skip |= ValidateDependencyCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, i, loc, vuid);
}
}
if (rp1_state.create_info.correlatedViewMaskCount != rp2_state.create_info.correlatedViewMaskCount) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"correlatedViewMaskCount is incompatible between %s (from %s) and %s (from %s), "
"%" PRIu32 " != %" PRIu32 "",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str(), rp1_state.create_info.correlatedViewMaskCount,
rp2_state.create_info.correlatedViewMaskCount);
} else {
for (uint32_t i = 0; i < rp1_state.create_info.correlatedViewMaskCount; ++i) {
if (rp1_state.create_info.pCorrelatedViewMasks[i] != rp2_state.create_info.pCorrelatedViewMasks[i]) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"pCorrelatedViewMasks[%" PRIu32
"] is incompatible between %s (from %s) and %s (from %s), "
"0x%" PRIx32 " != 0x%" PRIx32 "",
i, FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(),
FormatHandle(rp2_state).c_str(), FormatHandle(rp2_object).c_str(),
rp1_state.create_info.pCorrelatedViewMasks[i], rp2_state.create_info.pCorrelatedViewMasks[i]);
}
}
}
// Find an entry of the Fragment Density Map type in the pNext chain, if it exists
const auto fdm1 = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rp1_state.create_info.pNext);
const auto fdm2 = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rp2_state.create_info.pNext);
// Both renderpasses must agree on usage of a Fragment Density Map type
if (fdm1 && fdm2) {
uint32_t primary_input_attach = fdm1->fragmentDensityMapAttachment.attachment;
uint32_t secondary_input_attach = fdm2->fragmentDensityMapAttachment.attachment;
Location fdm_loc(Func::Empty, Struct::VkRenderPassFragmentDensityMapCreateInfoEXT);
skip |= ValidateAttachmentCompatibility(rp1_object, rp1_state, rp2_object, rp2_state, primary_input_attach,
secondary_input_attach, loc, fdm_loc.dot(Field::attachment), vuid);
} else if (fdm1) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"RenderPassCreateInfo pNext is incompatible between %s (from %s) and %s (from %s), "
"the first uses a VkRenderPassFragmentDensityMapCreateInfoEXT pNext while the second one does not",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str());
} else if (fdm2) {
const LogObjectList objlist(rp1_object, rp1_state.Handle(), rp2_object, rp2_state.Handle());
skip |= LogError(vuid, objlist, loc,
"RenderPassCreateInfo pNext is incompatible between %s (from %s) and %s (from %s), "
"the second uses a VkRenderPassFragmentDensityMapCreateInfoEXT pNext while the first one does not",
FormatHandle(rp1_state).c_str(), FormatHandle(rp1_object).c_str(), FormatHandle(rp2_state).c_str(),
FormatHandle(rp2_object).c_str());
}
return skip;
}
bool CoreChecks::PreCallValidateDestroyRenderPass(VkDevice device, VkRenderPass renderPass, const VkAllocationCallbacks *pAllocator,
const ErrorObject &error_obj) const {
bool skip = false;
if (auto rp_state = Get<vvl::RenderPass>(renderPass)) {
skip |= ValidateObjectNotInUse(rp_state.get(), error_obj.location, "VUID-vkDestroyRenderPass-renderPass-00873");
}
return skip;
}
// If this is a stencil format, make sure the stencil[Load|Store]Op flag is checked, while if it is a depth/color attachment the
// [load|store]Op flag must be checked
// TODO: The memory valid flag in vvl::DeviceMemory should probably be split to track the validity of stencil memory separately.
template <typename T>
static bool FormatSpecificLoadAndStoreOpSettings(VkFormat format, T color_depth_op, T stencil_op, T op) {
if (color_depth_op != op && stencil_op != op) {
return false;
}
const bool check_color_depth_load_op = !vkuFormatIsStencilOnly(format);
const bool check_stencil_load_op = vkuFormatIsDepthAndStencil(format) || !check_color_depth_load_op;
return ((check_color_depth_load_op && (color_depth_op == op)) || (check_stencil_load_op && (stencil_op == op)));
}
bool CoreChecks::ValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin,
VkSubpassContents contents, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto rp_state = Get<vvl::RenderPass>(pRenderPassBegin->renderPass);
const auto fb_state = Get<vvl::Framebuffer>(pRenderPassBegin->framebuffer);
ASSERT_AND_RETURN_SKIP(rp_state && fb_state);
const Location rp_begin_loc = error_obj.location.dot(Field::pRenderPassBegin);
skip |= ValidateCmd(cb_state, error_obj.location);
uint32_t clear_op_size = 0; // Make sure pClearValues is at least as large as last LOAD_OP_CLEAR
// Handle extension struct from EXT_sample_locations
if (const auto* sample_locations_begin_info =
vku::FindStructInPNextChain<VkRenderPassSampleLocationsBeginInfoEXT>(pRenderPassBegin->pNext)) {
for (uint32_t i = 0; i < sample_locations_begin_info->attachmentInitialSampleLocationsCount; ++i) {
const Location sampler_loc =
rp_begin_loc.pNext(Struct::VkRenderPassSampleLocationsBeginInfoEXT, Field::pAttachmentInitialSampleLocations, i);
const VkAttachmentSampleLocationsEXT &sample_location =
sample_locations_begin_info->pAttachmentInitialSampleLocations[i];
skip |= ValidateSampleLocationsInfo(sample_location.sampleLocationsInfo, sampler_loc.dot(Field::sampleLocationsInfo));
if (sample_location.attachmentIndex >= rp_state->create_info.attachmentCount) {
const LogObjectList objlist(commandBuffer, pRenderPassBegin->renderPass);
skip |= LogError(
"VUID-VkAttachmentSampleLocationsEXT-attachmentIndex-01531", objlist, sampler_loc.dot(Field::attachmentIndex),
"(%" PRIu32 ") is greater than the attachment count of %" PRIu32 " for the render pass being begun.",
sample_location.attachmentIndex, rp_state->create_info.attachmentCount);
}
}
for (uint32_t i = 0; i < sample_locations_begin_info->postSubpassSampleLocationsCount; ++i) {
const Location sampler_loc =
rp_begin_loc.pNext(Struct::VkRenderPassSampleLocationsBeginInfoEXT, Field::pPostSubpassSampleLocations, i);
const VkSubpassSampleLocationsEXT &sample_location = sample_locations_begin_info->pPostSubpassSampleLocations[i];
skip |= ValidateSampleLocationsInfo(sample_location.sampleLocationsInfo, sampler_loc.dot(Field::sampleLocationsInfo));
if (sample_location.subpassIndex >= rp_state->create_info.subpassCount) {
const LogObjectList objlist(commandBuffer, pRenderPassBegin->renderPass);
skip |=
LogError("VUID-VkSubpassSampleLocationsEXT-subpassIndex-01532", objlist, sampler_loc.dot(Field::subpassIndex),
"(%" PRIu32 ") is greater than the subpass count of %" PRIu32 " for the render pass being begun.",
sample_location.subpassIndex, rp_state->create_info.subpassCount);
}
}
}
for (uint32_t i = 0; i < rp_state->create_info.attachmentCount; ++i) {
auto attachment = &rp_state->create_info.pAttachments[i];
if (FormatSpecificLoadAndStoreOpSettings(attachment->format, attachment->loadOp, attachment->stencilLoadOp,
VK_ATTACHMENT_LOAD_OP_CLEAR)) {
clear_op_size = static_cast<uint32_t>(i) + 1;
if (vkuFormatHasDepth(attachment->format) && pRenderPassBegin->pClearValues) {
skip |= ValidateClearDepthStencilValue(commandBuffer, pRenderPassBegin->pClearValues[i].depthStencil,
rp_begin_loc.dot(Field::pClearValues, i).dot(Field::depthStencil));
}
}
}
if (clear_op_size > pRenderPassBegin->clearValueCount) {
const LogObjectList objlist(commandBuffer, pRenderPassBegin->renderPass);
skip |= LogError("VUID-VkRenderPassBeginInfo-clearValueCount-00902", objlist, rp_begin_loc.dot(Field::clearValueCount),
"is %" PRIu32 " but there must be at least %" PRIu32
" entries in pClearValues array to account for the highest index attachment in %s that uses "
"VK_ATTACHMENT_LOAD_OP_CLEAR is %" PRIu32
". Note that the pClearValues array is indexed by "
"attachment number so even if some pClearValues entries between 0 and %" PRIu32
" correspond to attachments "
"that aren't cleared they will be ignored.",
pRenderPassBegin->clearValueCount, clear_op_size, FormatHandle(rp_state->Handle()).c_str(), clear_op_size,
clear_op_size - 1);
}
skip |= VerifyFramebufferAndRenderPassImageViews(*pRenderPassBegin, rp_begin_loc);
skip |= VerifyRenderAreaBounds(*pRenderPassBegin, rp_begin_loc);
skip |= ValidateFramebufferAndRenderPassLayouts(cb_state, *pRenderPassBegin, *rp_state, *fb_state, rp_begin_loc);
if (fb_state->rp_state->VkHandle() != rp_state->VkHandle()) {
skip |= ValidateRenderPassCompatibility(rp_state->Handle(), *rp_state, fb_state->Handle(), *fb_state->rp_state,
error_obj.location, "VUID-VkRenderPassBeginInfo-renderPass-00904");
}
auto device_group_begin_info = vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(pRenderPassBegin->pNext);
const bool non_zero_device_render_area = device_group_begin_info && device_group_begin_info->deviceRenderAreaCount != 0;
if (device_group_begin_info) {
const LogObjectList objlist(commandBuffer, pRenderPassBegin->renderPass);
const Location device_mask_loc = rp_begin_loc.pNext(Struct::VkDeviceGroupRenderPassBeginInfo, Field::deviceMask);
skip |= ValidateDeviceMaskToPhysicalDeviceCount(device_group_begin_info->deviceMask, objlist, device_mask_loc,
"VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00905");
skip |= ValidateDeviceMaskToZero(device_group_begin_info->deviceMask, objlist, device_mask_loc,
"VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00906");
skip |= ValidateDeviceMaskToCommandBuffer(cb_state, device_group_begin_info->deviceMask, objlist, device_mask_loc,
"VUID-VkDeviceGroupRenderPassBeginInfo-deviceMask-00907");
if (device_group_begin_info->deviceRenderAreaCount != 0 &&
device_group_begin_info->deviceRenderAreaCount != device_state->physical_device_count) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-deviceRenderAreaCount-00908", objlist,
rp_begin_loc.pNext(Struct::VkDeviceGroupRenderPassBeginInfo, Field::deviceRenderAreaCount),
"is %" PRIu32 " but the physical device count is %" PRIu32 ".",
device_group_begin_info->deviceRenderAreaCount, device_state->physical_device_count);
}
}
if (!non_zero_device_render_area) {
if (pRenderPassBegin->renderArea.extent.width == 0) {
skip |= LogError("VUID-VkRenderPassBeginInfo-None-08996", commandBuffer,
rp_begin_loc.dot(Field::renderArea).dot(Field::extent).dot(Field::width), "is zero.");
} else if (pRenderPassBegin->renderArea.extent.height == 0) {
skip |= LogError("VUID-VkRenderPassBeginInfo-None-08997", commandBuffer,
rp_begin_loc.dot(Field::renderArea).dot(Field::extent).dot(Field::height), "is zero.");
}
}
if (contents == VK_SUBPASS_CONTENTS_INLINE_AND_SECONDARY_COMMAND_BUFFERS_KHR && !enabled_features.nestedCommandBuffer &&
!enabled_features.maintenance7) {
const char *vuid = error_obj.location.function == Func::vkCmdBeginRenderPass ? "VUID-vkCmdBeginRenderPass-contents-09640"
: "VUID-VkSubpassBeginInfo-contents-09382";
skip |= LogError(vuid, commandBuffer, error_obj.location.dot(Field::contents),
"is VK_SUBPASS_CONTENTS_INLINE_AND_SECONDARY_COMMAND_BUFFERS_KHR, but nestedCommandBuffer nor "
"maintenance7 were not enabled.");
}
if (const auto counters_begin_info =
vku::FindStructInPNextChain<VkRenderPassPerformanceCountersByRegionBeginInfoARM>(pRenderPassBegin->pNext)) {
const LogObjectList objlist(cb_state.Handle(), rp_state->Handle());
uint32_t layer_or_view_count = 0;
if (rp_state->has_multiview_enabled) {
for (uint32_t i = 0; i < rp_state->create_info.subpassCount; ++i) {
uint32_t highest_view_bits = MostSignificantBit(rp_state->create_info.pSubpasses[i].viewMask);
if (highest_view_bits > layer_or_view_count) {
layer_or_view_count = highest_view_bits;
}
}
} else {
layer_or_view_count = fb_state->create_info.layers;
}
skip |= ValidateRenderPassPerformanceCountersByRegionBeginInfo(commandBuffer, *counters_begin_info, objlist,
rp_state->create_info.subpassCount, layer_or_view_count,
pRenderPassBegin->renderArea, rp_begin_loc);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdBeginRenderPass(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin,
VkSubpassContents contents, const ErrorObject &error_obj) const {
return ValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, contents, error_obj);
}
bool CoreChecks::PreCallValidateCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin,
const VkSubpassBeginInfo *pSubpassBeginInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdBeginRenderPass2(commandBuffer, pRenderPassBegin, pSubpassBeginInfo, error_obj);
}
bool CoreChecks::PreCallValidateCmdBeginRenderPass2(VkCommandBuffer commandBuffer, const VkRenderPassBeginInfo *pRenderPassBegin,
const VkSubpassBeginInfo *pSubpassBeginInfo,
const ErrorObject &error_obj) const {
return ValidateCmdBeginRenderPass(commandBuffer, pRenderPassBegin, pSubpassBeginInfo->contents, error_obj);
}
bool CoreChecks::ValidateRenderPassPerformanceCountersByRegionBeginInfo(VkCommandBuffer commandBuffer, const VkRenderPassPerformanceCountersByRegionBeginInfoARM &counters_begin_info,
const LogObjectList &objlist, uint32_t subpass_count,
uint32_t layer_or_view_count, VkRect2D render_area,
const Location &begin_loc) const {
bool skip = false;
if (counters_begin_info.counterAddressCount != subpass_count * layer_or_view_count) {
skip |= LogError("VUID-VkRenderPassPerformanceCountersByRegionBeginInfoARM-counterAddressCount-11815", objlist,
begin_loc.pNext(Struct::VkRenderPassPerformanceCountersByRegionBeginInfoARM, Field::counterAddressCount),
"(%" PRIu32 ") differs from the number of subpasses (%" PRIu32
") times the number of layers in the render pass instance (%" PRIu32 ").",
counters_begin_info.counterAddressCount, subpass_count, layer_or_view_count);
}
VkExtent2D ra_extent = render_area.extent;
VkExtent2D pc_region_size = phys_dev_ext_props.renderpass_counter_by_region_props.performanceCounterRegionSize;
uint32_t row_stride_alignment = phys_dev_ext_props.renderpass_counter_by_region_props.rowStrideAlignment;
uint32_t region_alignment = phys_dev_ext_props.renderpass_counter_by_region_props.regionAlignment;
uint32_t counter_index_count = counters_begin_info.counterIndexCount;
uint32_t counter_buffer_size =
AlignToMultiple(vvl::GetQuotientCeil(ra_extent.width, pc_region_size.width) *
AlignToMultiple(counter_index_count * static_cast<uint32_t>(sizeof(uint32_t)), region_alignment),
row_stride_alignment) *
vvl::GetQuotientCeil(ra_extent.height, pc_region_size.height);
for (uint32_t i = 0; i < counters_begin_info.counterAddressCount; ++i) {
const auto buffer_states = GetBuffersByAddress(counters_begin_info.pCounterAddresses[i]);
for (auto& buffer_state : buffer_states) {
skip |= ValidateMemoryIsBoundToBuffer(commandBuffer, *buffer_state, begin_loc.pNext(Struct::VkRenderPassPerformanceCountersByRegionBeginInfoARM, Field::pCounterAddresses),
"VUID-VkRenderPassPerformanceCountersByRegionBeginInfoARM-pCounterAddresses-11816");
}
auto first_buffer = *buffer_states.begin();
auto buffer_range = first_buffer->DeviceAddressRange();
auto address = counters_begin_info.pCounterAddresses[i];
const vvl::range<VkDeviceSize> counter_address_range(address, address + counter_buffer_size);
if (!buffer_range.includes(counter_address_range)) {
skip |= LogError("VUID-VkRenderPassPerformanceCountersByRegionBeginInfoARM-pCounterAddresses-11817", objlist, begin_loc.pNext(Struct::VkRenderPassPerformanceCountersByRegionBeginInfoARM, Field::pCounterAddresses),
"%s does not fully fit into the address range of the buffer %s.",
string_range_hex(counter_address_range).c_str(), FormatHandle(*first_buffer).c_str());
}
}
if (counters_begin_info.counterIndexCount >
phys_dev_ext_props.renderpass_counter_by_region_props.maxPerRegionPerformanceCounters) {
skip |= LogError(
"VUID-VkRenderPassPerformanceCountersByRegionBeginInfoARM-counterIndexCount-11818", objlist,
begin_loc.pNext(Struct::VkRenderPassPerformanceCountersByRegionBeginInfoARM, Field::counterIndexCount),
"(%" PRIu32
") is greater than VkPhysicalDevicePerformanceCountersByRegionPropertiesARM::maxPerRegionPerformanceCounters (%" PRIu32
").",
counters_begin_info.counterIndexCount,
phys_dev_ext_props.renderpass_counter_by_region_props.maxPerRegionPerformanceCounters);
}
return skip;
}
bool CoreChecks::ValidateCmdEndRenderPass(const vvl::CommandBuffer& cb_state, const ErrorObject &error_obj) const {
bool skip = false;
const bool use_rp2 = error_obj.location.function != Func::vkCmdEndRenderPass;
const char *vuid;
skip |= ValidateCmd(cb_state, error_obj.location);
const auto *rp_state_ptr = cb_state.active_render_pass.get();
if (!rp_state_ptr) return skip;
const auto &rp_state = *rp_state_ptr;
if (!rp_state.UsesDynamicRendering() && (cb_state.GetActiveSubpass() != rp_state.create_info.subpassCount - 1)) {
vuid = use_rp2 ? "VUID-vkCmdEndRenderPass2-None-03103" : "VUID-vkCmdEndRenderPass-None-00910";
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
skip |= LogError(vuid, objlist, error_obj.location, "Called before reaching final subpass.");
}
if (rp_state.UsesDynamicRendering()) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
vuid = use_rp2 ? "VUID-vkCmdEndRenderPass2-None-06171" : "VUID-vkCmdEndRenderPass-None-06170";
skip |= LogError(vuid, objlist, error_obj.location,
"Called when the render pass instance was begun with vkCmdBeginRendering().");
}
if (cb_state.transform_feedback_active) {
vuid = use_rp2 ? "VUID-vkCmdEndRenderPass2-None-02352" : "VUID-vkCmdEndRenderPass-None-02351";
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
skip |= LogError(vuid, objlist, error_obj.location, "transform feedback is active.");
}
for (const auto &query : cb_state.render_pass_queries) {
vuid = use_rp2 ? "VUID-vkCmdEndRenderPass2-None-07005" : "VUID-vkCmdEndRenderPass-None-07004";
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle(), query.pool);
skip |= LogError(vuid, objlist, error_obj.location,
"query %" PRIu32 " from %s was began in subpass %" PRIu32 " but never ended.", query.slot,
FormatHandle(query.pool).c_str(), query.subpass);
}
return skip;
}
bool CoreChecks::ValidateFragmentDensityMapOffsetEnd(const vvl::CommandBuffer &cb_state, const vvl::RenderPass &rp_state,
const VkRenderPassFragmentDensityMapOffsetEndInfoEXT &fdm_offset_end_info,
const Location &end_info_loc) const {
bool skip = false;
if ((!enabled_features.fragmentDensityMapOffset) || (!enabled_features.fragmentDensityMap)) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
skip |=
LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-fragmentDensityMapOffsets-06503", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32 " but must be 0 when fragmentDensityMapOffset or fragmentDensityMap features are not enabled.",
fdm_offset_end_info.fragmentDensityOffsetCount);
}
for (uint32_t i = 0; i < fdm_offset_end_info.fragmentDensityOffsetCount; i++) {
const VkOffset2D &layer_offset = fdm_offset_end_info.pFragmentDensityOffsets[i];
if (layer_offset.x != 0 || layer_offset.y != 0) {
const uint32_t width = phys_dev_ext_props.fragment_density_map_offset_props.fragmentDensityOffsetGranularity.width;
if (SafeModulo(layer_offset.x, width) != 0) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
skip |=
LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-x-06512", objlist,
end_info_loc.dot(Field::pFragmentDensityOffsets, i).dot(Field::x),
"(%" PRIu32 ") is not an integer multiple of fragmentDensityOffsetGranularity.width (%" PRIu32 ").",
layer_offset.x, width);
}
const uint32_t height = phys_dev_ext_props.fragment_density_map_offset_props.fragmentDensityOffsetGranularity.height;
if (SafeModulo(layer_offset.y, height) != 0) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle());
skip |=
LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-y-06513", objlist,
end_info_loc.dot(Field::pFragmentDensityOffsets, i).dot(Field::y),
"(%" PRIu32 ") is not an integer multiple of fragmentDensityOffsetGranularity.height (%" PRIu32 ").",
layer_offset.y, height);
}
}
}
for (uint32_t i = 0; i < cb_state.active_attachments.size(); ++i) {
const AttachmentInfo &attachment_info = cb_state.active_attachments[i];
const vvl::ImageView *attachment = attachment_info.image_view;
if (!attachment) continue; // VK_ATTACHMENT_UNUSED
ASSERT_AND_CONTINUE(attachment->image_state);
const bool has_offset_flag =
(attachment->image_state->create_info.flags & VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT) != 0;
if (has_offset_flag) continue;
if (attachment_info.IsDepthOrStencil()) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pDepthStencilAttachment-06505", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32
" but %s underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, attachment_info.Describe(cb_state, i).c_str(),
FormatHandle(*attachment->image_state).c_str());
}
if (attachment_info.IsInput()) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pInputAttachments-06506", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32
" but %s underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, attachment_info.Describe(cb_state, i).c_str(),
FormatHandle(*attachment->image_state).c_str());
}
if (attachment_info.IsColor()) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pColorAttachments-06507", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32
" but %s underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, attachment_info.Describe(cb_state, i).c_str(),
FormatHandle(*attachment->image_state).c_str());
}
if (attachment_info.IsResolve()) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pResolveAttachments-06508", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32
" but %s underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, attachment_info.Describe(cb_state, i).c_str(),
FormatHandle(*attachment->image_state).c_str());
}
if (attachment_info.IsFragmentDensityMap()) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-fragmentDensityMapAttachment-06504", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32
" but %s underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, attachment_info.Describe(cb_state, i).c_str(),
FormatHandle(*attachment->image_state).c_str());
}
}
// Need to check for Preserve attachments as they are not part of the AttachmentInfo (as it is a rare case with no equivalent in
// dynamic rendering) (Same thing currently with multiView mask)
if (!rp_state.UsesDynamicRendering()) {
const VkRenderPassCreateInfo2 *rpci = rp_state.create_info.ptr();
const VkImageView *image_views = cb_state.active_framebuffer.get()->create_info.pAttachments;
for (uint32_t i = 0; i < rpci->attachmentCount; ++i) {
const auto view_state = Get<vvl::ImageView>(image_views[i]);
ASSERT_AND_CONTINUE(view_state && view_state->image_state);
const bool has_offset_flag =
(view_state->image_state->create_info.flags & VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT) != 0;
// fdm attachment
const auto *fdm_attachment = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rpci->pNext);
const VkSubpassDescription2 &subpass = rpci->pSubpasses[cb_state.GetActiveSubpass()];
if (fdm_attachment && fdm_attachment->fragmentDensityMapAttachment.attachment != VK_ATTACHMENT_UNUSED &&
fdm_attachment->fragmentDensityMapAttachment.attachment == i) {
if (subpass.viewMask == 0) {
if (fdm_offset_end_info.fragmentDensityOffsetCount != 1) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle(), view_state->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-fragmentDensityOffsetCount-06511",
objlist, end_info_loc.dot(Field::fragmentDensityOffsetCount),
"(%" PRIu32 ") should only be 1 when the multiview feature is not enabled.",
fdm_offset_end_info.fragmentDensityOffsetCount);
}
} else if (view_state->normalized_subresource_range.layerCount != fdm_offset_end_info.fragmentDensityOffsetCount) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle(), view_state->Handle());
skip |= LogError(
"VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-fragmentDensityOffsetCount-06510", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"(%" PRIu32 ") does not match the fragmentDensityMapAttachment (pAttachments[%" PRIu32
"] %s) subresourceRange.layerCount (%s) (subpass viewMask is 0x%" PRIx32 ")",
fdm_offset_end_info.fragmentDensityOffsetCount, i, FormatHandle(*view_state).c_str(),
string_LayerCount(view_state->image_state->create_info, view_state->create_info.subresourceRange).c_str(),
subpass.viewMask);
}
}
// Preserve attachments
for (uint32_t k = 0; k < subpass.preserveAttachmentCount; k++) {
const auto attachment = subpass.pPreserveAttachments[k];
if ((attachment != VK_ATTACHMENT_UNUSED) && (attachment == i) && !has_offset_flag) {
const LogObjectList objlist(cb_state.Handle(), rp_state.Handle(), view_state->Handle());
skip |= LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pPreserveAttachments-06509", objlist,
end_info_loc.dot(Field::fragmentDensityOffsetCount),
"is %" PRIu32 " but preserveAttachmentCount[%" PRIu32 "] (pAttachments[%" PRIu32
"] %s) underlying %s was not created with VK_IMAGE_CREATE_FRAGMENT_DENSITY_MAP_OFFSET_BIT_EXT",
fdm_offset_end_info.fragmentDensityOffsetCount, k, i, FormatHandle(*view_state).c_str(),
FormatHandle(*view_state->image_state).c_str());
}
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdEndRenderPass(VkCommandBuffer commandBuffer, const ErrorObject &error_obj) const {
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
return ValidateCmdEndRenderPass(cb_state, error_obj);
}
bool CoreChecks::PreCallValidateCmdEndRenderPass2KHR(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdEndRenderPass2(commandBuffer, pSubpassEndInfo, error_obj);
}
bool CoreChecks::PreCallValidateCmdEndRenderPass2(VkCommandBuffer commandBuffer, const VkSubpassEndInfo *pSubpassEndInfo,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
skip |= ValidateCmdEndRenderPass(cb_state, error_obj);
const auto *rp_state_ptr = cb_state.active_render_pass.get();
if (rp_state_ptr && pSubpassEndInfo) {
const auto *fdm_offset_end_info =
vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapOffsetEndInfoEXT>(pSubpassEndInfo->pNext);
if (fdm_offset_end_info && fdm_offset_end_info->fragmentDensityOffsetCount != 0) {
skip |= ValidateFragmentDensityMapOffsetEnd(
cb_state, *rp_state_ptr, *fdm_offset_end_info,
error_obj.location.dot(Field::pSubpassEndInfo).pNext(Struct::VkRenderPassFragmentDensityMapOffsetEndInfoEXT));
}
}
return skip;
}
bool CoreChecks::VerifyRenderAreaBounds(const VkRenderPassBeginInfo &begin_info, const Location &begin_info_loc) const {
bool skip = false;
const auto *device_group_render_pass_begin_info =
vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(begin_info.pNext);
const uint32_t device_group_area_count =
device_group_render_pass_begin_info ? device_group_render_pass_begin_info->deviceRenderAreaCount : 0;
auto framebuffer_state = Get<vvl::Framebuffer>(begin_info.framebuffer);
ASSERT_AND_RETURN_SKIP(framebuffer_state);
const auto *framebuffer_info = &framebuffer_state->create_info;
// These VUs depend on count being non-zero, or else acts like struct is not there
if (device_group_area_count > 0) {
for (uint32_t i = 0; i < device_group_area_count; ++i) {
const Location render_area_loc =
begin_info_loc.pNext(Struct::VkDeviceGroupRenderPassBeginInfo, Field::pDeviceRenderAreas, i);
const auto &deviceRenderArea = device_group_render_pass_begin_info->pDeviceRenderAreas[i];
if (deviceRenderArea.offset.x < 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06166", begin_info.renderPass,
render_area_loc.dot(Field::offset).dot(Field::x), "is negative (%" PRId32 ").",
deviceRenderArea.offset.x);
}
if (deviceRenderArea.offset.y < 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06167", begin_info.renderPass,
render_area_loc.dot(Field::offset).dot(Field::y), "is negative (%" PRId32 ").",
deviceRenderArea.offset.y);
}
if ((deviceRenderArea.offset.x + deviceRenderArea.extent.width) > framebuffer_info->width) {
const LogObjectList objlist(begin_info.renderPass, framebuffer_state->Handle());
skip |=
LogError("VUID-VkRenderPassBeginInfo-pNext-02856", objlist, render_area_loc,
"offset.x (%" PRId32 ") + extent.width (%" PRIu32 ") is greater than framebuffer width (%" PRIu32 ").",
deviceRenderArea.offset.x, deviceRenderArea.extent.width, framebuffer_info->width);
}
if ((deviceRenderArea.offset.y + deviceRenderArea.extent.height) > framebuffer_info->height) {
const LogObjectList objlist(begin_info.renderPass, framebuffer_state->Handle());
skip |= LogError("VUID-VkRenderPassBeginInfo-pNext-02857", objlist, render_area_loc,
"offset.y (%" PRId32 ") + extent.height (%" PRIu32 ") is greater than framebuffer height (%" PRIu32
").",
deviceRenderArea.offset.y, deviceRenderArea.extent.height, framebuffer_info->height);
}
}
} else {
const Location render_area_loc = begin_info_loc.dot(Field::renderArea);
if (begin_info.renderArea.offset.x < 0) {
skip |= LogError("VUID-VkRenderPassBeginInfo-pNext-02850", begin_info.renderPass,
render_area_loc.dot(Field::offset).dot(Field::x), "is %" PRId32 " (offset can't be negative).",
begin_info.renderArea.offset.x);
}
if (begin_info.renderArea.offset.y < 0) {
skip |= LogError("VUID-VkRenderPassBeginInfo-pNext-02851", begin_info.renderPass,
render_area_loc.dot(Field::offset).dot(Field::y), "is %" PRId32 " (offset can't be negative).",
begin_info.renderArea.offset.y);
}
const auto x_adjusted_extent =
static_cast<int64_t>(begin_info.renderArea.offset.x) + static_cast<int64_t>(begin_info.renderArea.extent.width);
if (x_adjusted_extent > static_cast<int64_t>(framebuffer_info->width)) {
const LogObjectList objlist(begin_info.renderPass, framebuffer_state->Handle());
skip |= LogError("VUID-VkRenderPassBeginInfo-pNext-02852", objlist, render_area_loc,
"offset.x (%" PRId32 ") + extent.width (%" PRIu32 ") is greater than framebuffer width (%" PRIu32 ").",
begin_info.renderArea.offset.x, begin_info.renderArea.extent.width, framebuffer_info->width);
}
const auto y_adjusted_extent =
static_cast<int64_t>(begin_info.renderArea.offset.y) + static_cast<int64_t>(begin_info.renderArea.extent.height);
if (y_adjusted_extent > static_cast<int64_t>(framebuffer_info->height)) {
const LogObjectList objlist(begin_info.renderPass, framebuffer_state->Handle());
skip |=
LogError("VUID-VkRenderPassBeginInfo-pNext-02853", objlist, render_area_loc,
"offset.y (%" PRId32 ") + extent.height (%" PRIu32 ") is greater than framebuffer height (%" PRIu32 ").",
begin_info.renderArea.offset.y, begin_info.renderArea.extent.height, framebuffer_info->height);
}
}
return skip;
}
bool CoreChecks::VerifyFramebufferAndRenderPassImageViews(const VkRenderPassBeginInfo &begin_info,
const Location &begin_info_loc) const {
bool skip = false;
const auto *render_pass_attachment_begin_info = vku::FindStructInPNextChain<VkRenderPassAttachmentBeginInfo>(begin_info.pNext);
if (!render_pass_attachment_begin_info || render_pass_attachment_begin_info->attachmentCount == 0) {
return false;
}
const auto framebuffer_state = Get<vvl::Framebuffer>(begin_info.framebuffer);
ASSERT_AND_RETURN_SKIP(framebuffer_state);
const auto &framebuffer_create_info = framebuffer_state->create_info;
if ((framebuffer_create_info.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
const LogObjectList objlist(begin_info.renderPass, begin_info.framebuffer);
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03207", objlist,
begin_info_loc.pNext(Struct::VkRenderPassAttachmentBeginInfo, Field::attachmentCount),
"is %" PRIu32 ", but the VkFramebuffer create flags (%s) has no VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT.",
render_pass_attachment_begin_info->attachmentCount,
string_VkFramebufferCreateFlags(framebuffer_create_info.flags).c_str());
return skip; // not marked as imageless so ignore rest of checks
}
const auto *framebuffer_attachments_create_info =
vku::FindStructInPNextChain<VkFramebufferAttachmentsCreateInfo>(framebuffer_create_info.pNext);
if (!framebuffer_attachments_create_info) {
return skip;
}
if (framebuffer_attachments_create_info->attachmentImageInfoCount != render_pass_attachment_begin_info->attachmentCount) {
const LogObjectList objlist(begin_info.renderPass, begin_info.framebuffer);
skip |= LogError(
"VUID-VkRenderPassBeginInfo-framebuffer-03208", objlist,
begin_info_loc.pNext(Struct::VkRenderPassAttachmentBeginInfo, Field::attachmentCount),
"is %" PRIu32
", but VkFramebuffer was created with VkFramebufferAttachmentsCreateInfo::attachmentImageInfoCount = %" PRIu32 ".",
render_pass_attachment_begin_info->attachmentCount, framebuffer_attachments_create_info->attachmentImageInfoCount);
return skip; // the indexing below is assuming the counts are matching
}
auto render_pass_state = Get<vvl::RenderPass>(begin_info.renderPass);
ASSERT_AND_RETURN_SKIP(render_pass_state);
const auto *render_pass_create_info = &render_pass_state->create_info;
for (uint32_t i = 0; i < render_pass_attachment_begin_info->attachmentCount; ++i) {
const Location attachment_loc = begin_info_loc.pNext(Struct::VkRenderPassAttachmentBeginInfo, Field::pAttachments, i);
auto image_view_state = Get<vvl::ImageView>(render_pass_attachment_begin_info->pAttachments[i]);
ASSERT_AND_CONTINUE(image_view_state);
const VkImageViewCreateInfo *image_view_create_info = &image_view_state->create_info;
const auto &subresource_range = image_view_state->normalized_subresource_range;
const VkFramebufferAttachmentImageInfo *framebuffer_attachment_image_info =
&framebuffer_attachments_create_info->pAttachmentImageInfos[i];
const auto *image_create_info = &image_view_state->image_state->create_info;
const LogObjectList objlist(begin_info.renderPass, begin_info.framebuffer, image_view_state->Handle(),
image_view_state->image_state->Handle());
if (framebuffer_attachment_image_info->flags != image_create_info->flags) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03209", objlist, attachment_loc.dot(Field::flags),
"is %s, but the VkFramebuffer was created with "
"VkFramebufferAttachmentsCreateInfo::pAttachmentImageInfos[%" PRIu32 "].flags = %s",
string_VkImageCreateFlags(image_create_info->flags).c_str(), i,
string_VkImageCreateFlags(framebuffer_attachment_image_info->flags).c_str());
}
if (framebuffer_attachment_image_info->usage != image_view_state->inherited_usage) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-04627", objlist, attachment_loc.dot(Field::usage),
"is (%s), but the VkFramebuffer was created with "
"vkFramebufferAttachmentsCreateInfo::pAttachmentImageInfos[%" PRIu32 "].usage = %s.\n%s",
string_VkImageUsageFlags(image_create_info->usage).c_str(), i,
string_VkImageUsageFlags(framebuffer_attachment_image_info->usage).c_str(),
image_view_state->DescribeImageUsage(*this).c_str());
}
const auto view_width = std::max(1u, image_create_info->extent.width >> subresource_range.baseMipLevel);
if (framebuffer_attachment_image_info->width != view_width) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03211", objlist, attachment_loc,
"has VkImageView width (%" PRIu32 ") at mip level %" PRIu32 " (%" PRIu32
") != VkFramebufferAttachmentsCreateInfo::pAttachments[%" PRIu32 "].width (%" PRIu32 ").",
image_create_info->extent.width, subresource_range.baseMipLevel, view_width, i,
framebuffer_attachment_image_info->width);
}
const bool is_1d = (image_view_create_info->viewType == VK_IMAGE_VIEW_TYPE_1D) ||
(image_view_create_info->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY);
const auto view_height = (!is_1d) ? std::max(1u, image_create_info->extent.height >> subresource_range.baseMipLevel)
: image_create_info->extent.height;
if (framebuffer_attachment_image_info->height != view_height) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03212", objlist, attachment_loc,
"has VkImageView height (%" PRIu32 ") at mip level %" PRIu32 " (%" PRIu32
") != VkFramebufferAttachmentsCreateInfo::pAttachments[%" PRIu32 "].height (%" PRIu32 ").",
image_create_info->extent.height, subresource_range.baseMipLevel, view_height, i,
framebuffer_attachment_image_info->height);
}
// TODO - Need to understand when this rule actually applies everywhere. There is some special language around
// vk_khr_maintenance9 where this logic isn't true for pipeline barriers
const uint32_t layerCount = image_view_state->create_info.subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS
? image_view_state->create_info.subresourceRange.layerCount
: image_create_info->extent.depth;
if (framebuffer_attachment_image_info->layerCount != layerCount) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03213", objlist, attachment_loc,
"has a subresource range with a layerCount of %" PRIu32
", but VkFramebufferAttachmentsCreateInfo::pAttachments[%" PRIu32 "].layerCount is %" PRIu32 ".",
layerCount, i, framebuffer_attachment_image_info->layerCount);
}
const auto *image_format_list_create_info =
vku::FindStructInPNextChain<VkImageFormatListCreateInfo>(image_create_info->pNext);
if (image_format_list_create_info) {
if (image_format_list_create_info->viewFormatCount != framebuffer_attachment_image_info->viewFormatCount) {
skip |=
LogError("VUID-VkRenderPassBeginInfo-framebuffer-03214", objlist, attachment_loc,
"internal VkImage was created with a VkImageFormatListCreateInfo::viewFormatCount of %" PRIu32
" but VkFramebufferAttachmentsCreateInfo::pAttachments[%" PRIu32 "].viewFormatCount is %" PRIu32 ".",
image_format_list_create_info->viewFormatCount, i, framebuffer_attachment_image_info->viewFormatCount);
}
for (uint32_t j = 0; j < image_format_list_create_info->viewFormatCount; ++j) {
bool format_found = false;
for (uint32_t k = 0; k < framebuffer_attachment_image_info->viewFormatCount; ++k) {
if (image_format_list_create_info->pViewFormats[j] == framebuffer_attachment_image_info->pViewFormats[k]) {
format_found = true;
}
}
if (!format_found) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03215", objlist, attachment_loc,
"internal VkImage was created with VkImageFormatListCreateInfo::pViewFormats[%" PRIu32
"] = %s,"
"but now found in vkFramebufferAttachmentsCreateInfo::pAttachmentImageInfos[%" PRIu32
"].pViewFormats.",
j, string_VkFormat(image_format_list_create_info->pViewFormats[j]), i);
}
}
}
if (render_pass_create_info->pAttachments[i].format != image_view_create_info->format) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-03216", objlist, attachment_loc.dot(Field::format),
"is %s, but the VkRenderPass was created with a pAttachments[%" PRIu32 "].format of %s.",
string_VkFormat(image_view_create_info->format), i,
string_VkFormat(render_pass_create_info->pAttachments[i].format));
} else if (image_view_create_info->format == VK_FORMAT_UNDEFINED) {
// both have external foramts
const uint64_t attachment_external_format = GetExternalFormat(render_pass_create_info->pAttachments[i].pNext);
if (image_view_state->image_state->ahb_format != attachment_external_format) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-09354", objlist, attachment_loc,
"externalFormat is %" PRIu64 ", but the VkRenderPass was created with a pAttachments[%" PRIu32
"] with externalFormat of %" PRIu64 ".",
image_view_state->image_state->ahb_format, i, attachment_external_format);
}
}
const VkSampleCountFlagBits attachment_samples = render_pass_create_info->pAttachments[i].samples;
const auto *ms_render_to_single_sample =
vku::FindStructInPNextChain<VkMultisampledRenderToSingleSampledInfoEXT>(begin_info.pNext);
const bool single_sample_enabled = ms_render_to_single_sample &&
ms_render_to_single_sample->multisampledRenderToSingleSampledEnable &&
(attachment_samples == VK_SAMPLE_COUNT_1_BIT);
if (attachment_samples != image_create_info->samples && !single_sample_enabled) {
skip |= LogError("VUID-VkRenderPassBeginInfo-framebuffer-09047", objlist, attachment_loc,
"internal VkImage was created with %s samples, "
"but the VkRenderPass was created with a pAttachments[%" PRIu32 "].samples of %s.",
string_VkSampleCountFlagBits(image_create_info->samples), i,
string_VkSampleCountFlagBits(render_pass_create_info->pAttachments[i].samples));
}
if (subresource_range.levelCount != 1) {
skip |= LogError("VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03218", objlist, attachment_loc,
"was created with multiple mip levels (%" PRIu32 ").", subresource_range.levelCount);
}
if (IsIdentitySwizzle(image_view_create_info->components) == false) {
skip |= LogError("VUID-VkRenderPassAttachmentBeginInfo-pAttachments-03219", objlist, attachment_loc,
"was created with non-identity swizzle. All "
"framebuffer attachments must have been created with the identity swizzle. Here are the actual "
"swizzle values:\n%s",
string_VkComponentMapping(image_view_create_info->components).c_str());
}
if (image_view_create_info->viewType == VK_IMAGE_VIEW_TYPE_3D) {
skip |= LogError("VUID-VkRenderPassAttachmentBeginInfo-pAttachments-04114", objlist, attachment_loc,
"was created with viewType of VK_IMAGE_VIEW_TYPE_3D.");
}
}
if (enabled_features.externalFormatResolve && !device_state->android_external_format_resolve_null_color_attachment_prop) {
for (const auto [i, subpass] : vvl::enumerate(render_pass_create_info->pSubpasses, render_pass_create_info->subpassCount)) {
if (!subpass.pResolveAttachments || !subpass.pColorAttachments) {
continue;
}
const uint32_t resolve_attachment = subpass.pResolveAttachments[0].attachment;
const uint32_t color_attachment = subpass.pColorAttachments[0].attachment;
if (resolve_attachment == VK_ATTACHMENT_UNUSED || color_attachment == VK_ATTACHMENT_UNUSED) {
continue;
}
const uint64_t attachment_external_format =
GetExternalFormat(render_pass_create_info->pAttachments[resolve_attachment].pNext);
auto it = device_state->ahb_ext_resolve_formats_map.find(attachment_external_format);
if (it != device_state->ahb_ext_resolve_formats_map.end()) {
VkFormat color_format = render_pass_create_info->pAttachments[color_attachment].format;
if (it->second != color_format) {
const LogObjectList objlist(begin_info.renderPass, begin_info.framebuffer);
skip |=
LogError("VUID-VkRenderPassBeginInfo-framebuffer-09353", objlist, begin_info_loc,
"subpass[%" PRIu32 "].pResolveAttachments[0].attachment %" PRIu32 " has externalFormat %" PRIu64
" which corresponds to needing a color attachment format of %s, but the format is %s.",
i, resolve_attachment, attachment_external_format, string_VkFormat(it->second),
string_VkFormat(color_format));
}
}
}
}
return skip;
}
bool CoreChecks::ValidateAttachmentIndex(uint32_t attachment, uint32_t attachment_count, const Location &loc) const {
bool skip = false;
const bool use_rp2 = loc.function != Func::vkCreateRenderPass;
assert(attachment != VK_ATTACHMENT_UNUSED);
if (attachment >= attachment_count) {
const char *vuid =
use_rp2 ? "VUID-VkRenderPassCreateInfo2-attachment-03051" : "VUID-VkRenderPassCreateInfo-attachment-00834";
skip |= LogError(vuid, device, loc.dot(Field::attachment),
"is %" PRIu32 ", but must be less than the total number of attachments (%" PRIu32 ").", attachment,
attachment_count);
}
return skip;
}
enum AttachmentType {
ATTACHMENT_COLOR = 1,
ATTACHMENT_DEPTH = 2,
ATTACHMENT_INPUT = 4,
ATTACHMENT_PRESERVE = 8,
ATTACHMENT_RESOLVE = 16,
};
const char *StringAttachmentType(uint8_t type) {
switch (type) {
case ATTACHMENT_COLOR:
return "color";
case ATTACHMENT_DEPTH:
return "depth";
case ATTACHMENT_INPUT:
return "input";
case ATTACHMENT_PRESERVE:
return "preserve";
case ATTACHMENT_RESOLVE:
return "resolve";
default:
return "(multiple)";
}
}
bool CoreChecks::AddAttachmentUse(std::vector<uint8_t> &attachment_uses, std::vector<VkImageLayout> &attachment_layouts,
uint32_t attachment, uint8_t new_use, VkImageLayout new_layout, const Location &loc) const {
if (attachment >= attachment_uses.size()) return false; /* out of range, but already reported */
bool skip = false;
auto &uses = attachment_uses[attachment];
const bool use_rp2 = loc.function != Func::vkCreateRenderPass;
const char *vuid;
if (uses & new_use) {
if (attachment_layouts[attachment] != new_layout) {
vuid = use_rp2 ? "VUID-VkSubpassDescription2-layout-02528" : "VUID-VkSubpassDescription-layout-02519";
skip |= LogError(vuid, device, loc, "already uses attachment %" PRIu32 " with a different image layout (%s vs %s).",
attachment, string_VkImageLayout(attachment_layouts[attachment]), string_VkImageLayout(new_layout));
}
} else if (((new_use & ATTACHMENT_COLOR) && (uses & ATTACHMENT_DEPTH)) ||
((uses & ATTACHMENT_COLOR) && (new_use & ATTACHMENT_DEPTH))) {
vuid = use_rp2 ? "VUID-VkSubpassDescription2-pDepthStencilAttachment-04440"
: "VUID-VkSubpassDescription-pDepthStencilAttachment-04438";
skip |= LogError(vuid, device, loc, "uses attachment %" PRIu32 " as both %s and %s attachment.", attachment,
StringAttachmentType(uses), StringAttachmentType(new_use));
} else if ((uses && (new_use & ATTACHMENT_PRESERVE)) || (new_use && (uses & ATTACHMENT_PRESERVE))) {
vuid = use_rp2 ? "VUID-VkSubpassDescription2-pPreserveAttachments-03074"
: "VUID-VkSubpassDescription-pPreserveAttachments-00854";
skip |= LogError(vuid, device, loc, "uses attachment %" PRIu32 " as both %s and %s attachment.", attachment,
StringAttachmentType(uses), StringAttachmentType(new_use));
} else {
attachment_layouts[attachment] = new_layout;
uses |= new_use;
}
return skip;
}
// Handles attachment references regardless of type (input, color, depth, etc)
// Input attachments have extra VUs associated with them
bool CoreChecks::ValidateAttachmentReference(VkAttachmentReference2 reference, const VkFormat attachment_format, bool input,
const Location &loc) const {
bool skip = false;
const bool use_rp2 = loc.function != Func::vkCreateRenderPass;
const char *vuid;
// Currently all VUs require attachment to not be UNUSED
assert(reference.attachment != VK_ATTACHMENT_UNUSED);
// currently VkAttachmentReference and VkAttachmentReference2 have no overlapping VUs
const auto *attachment_reference_stencil_layout =
vku::FindStructInPNextChain<VkAttachmentReferenceStencilLayout>(reference.pNext);
switch (reference.layout) {
case VK_IMAGE_LAYOUT_UNDEFINED:
case VK_IMAGE_LAYOUT_PREINITIALIZED:
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR:
case VK_IMAGE_LAYOUT_ZERO_INITIALIZED_EXT:
vuid = (use_rp2) ? "VUID-VkAttachmentReference2-layout-03077" : "VUID-VkAttachmentReference-layout-03077";
skip |= LogError(vuid, device, loc, "is %s.", string_VkImageLayout(reference.layout));
break;
// Only other layouts in VUs to be checked
case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL:
case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL:
case VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL:
case VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL:
// First need to make sure feature bit is enabled and the format is actually a depth and/or stencil
if (!enabled_features.separateDepthStencilLayouts) {
vuid = (use_rp2) ? "VUID-VkAttachmentReference2-separateDepthStencilLayouts-03313"
: "VUID-VkAttachmentReference-separateDepthStencilLayouts-03313";
skip |= LogError(vuid, device, loc, "is %s (and separateDepthStencilLayouts was not enabled).",
string_VkImageLayout(reference.layout));
} else if (IsImageLayoutDepthOnly(reference.layout)) {
if (attachment_reference_stencil_layout) {
// This check doesn't rely on the aspect mask value
const VkImageLayout stencil_layout = attachment_reference_stencil_layout->stencilLayout;
if (stencil_layout == VK_IMAGE_LAYOUT_UNDEFINED || stencil_layout == VK_IMAGE_LAYOUT_PREINITIALIZED ||
stencil_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL ||
stencil_layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
skip |= LogError("VUID-VkAttachmentReferenceStencilLayout-stencilLayout-03318", device,
loc.pNext(Struct::VkAttachmentReferenceStencilLayout, Field::stencilLayout),
"(%s) is not a valid VkImageLayout.", string_VkImageLayout(stencil_layout));
}
}
}
break;
case VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL:
case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL:
if (!enabled_features.synchronization2) {
vuid = (use_rp2) ? "VUID-VkAttachmentReference2-synchronization2-06910"
: "VUID-VkAttachmentReference-synchronization2-06910";
skip |= LogError(vuid, device, loc, "is %s (and synchronization2 was not enabled).",
string_VkImageLayout(reference.layout));
}
break;
case VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT:
if (!enabled_features.attachmentFeedbackLoopLayout) {
vuid = (use_rp2) ? "VUID-VkAttachmentReference2-attachmentFeedbackLoopLayout-07311"
: "VUID-VkAttachmentReference-attachmentFeedbackLoopLayout-07311";
skip |= LogError(vuid, device, loc,
"is VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT, but the "
"attachmentFeedbackLoopLayout feature was not enabled.");
}
break;
case VK_IMAGE_LAYOUT_RENDERING_LOCAL_READ:
if (!enabled_features.dynamicRenderingLocalRead) {
vuid = (use_rp2) ? "VUID-VkAttachmentReference2-dynamicRenderingLocalRead-09546"
: "VUID-VkAttachmentReference-dynamicRenderingLocalRead-09546";
skip |= LogError(vuid, device, loc,
"is VK_IMAGE_LAYOUT_RENDERING_LOCAL_READ, but the "
"dynamicRenderingLocalRead feature was not enabled.");
}
break;
default:
break;
}
return skip;
}
bool CoreChecks::ValidateRenderpassAttachmentUsage(const VkRenderPassCreateInfo2 &create_info,
const Location &create_info_loc) const {
bool skip = false;
const bool use_rp2 = create_info_loc.function != Func::vkCreateRenderPass;
const auto *fragment_density_map_info =
vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(create_info.pNext);
// Track when we're observing the first use of an attachment
std::vector<bool> attach_first_use(create_info.attachmentCount, true);
for (uint32_t i = 0; i < create_info.subpassCount; ++i) {
const Location subpass_loc = create_info_loc.dot(Field::pSubpasses, i);
const VkSubpassDescription2 &subpass = create_info.pSubpasses[i];
const auto ms_render_to_single_sample =
vku::FindStructInPNextChain<VkMultisampledRenderToSingleSampledInfoEXT>(subpass.pNext);
const auto subpass_depth_stencil_resolve =
vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass.pNext);
std::vector<uint8_t> attachment_uses(create_info.attachmentCount);
std::vector<VkImageLayout> attachment_layouts(create_info.attachmentCount);
// Track if attachments are used as input as well as another type
vvl::unordered_set<uint32_t> input_attachments;
if (subpass.pipelineBindPoint != VK_PIPELINE_BIND_POINT_GRAPHICS &&
subpass.pipelineBindPoint != VK_PIPELINE_BIND_POINT_SUBPASS_SHADING_HUAWEI) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pipelineBindPoint-04953"
: "VUID-VkSubpassDescription-pipelineBindPoint-04952";
skip |= LogError(vuid, device, subpass_loc.dot(Field::pipelineBindPoint), "is %s.",
string_VkPipelineBindPoint(subpass.pipelineBindPoint));
}
// Check input attachments first
// - so we can detect first-use-as-input for VU #00349
// - if other color or depth/stencil is also input, it limits valid layouts
for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
auto const &attachment_ref = subpass.pInputAttachments[j];
const uint32_t attachment_index = attachment_ref.attachment;
if (attachment_index == VK_ATTACHMENT_UNUSED) {
continue;
}
const VkImageAspectFlags aspect_mask = attachment_ref.aspectMask;
const Location input_loc = subpass_loc.dot(Field::pInputAttachments, j);
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, attachment_index);
input_attachments.insert(attachment_index);
skip |= ValidateAttachmentIndex(attachment_index, create_info.attachmentCount, input_loc);
if (aspect_mask & VK_IMAGE_ASPECT_METADATA_BIT) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-attachment-02801"
: "VUID-VkInputAttachmentAspectReference-aspectMask-01964";
skip |= LogError(vuid, device, input_loc.dot(Field::aspectMask), "is %s.",
string_VkImageAspectFlags(aspect_mask).c_str());
} else if (aspect_mask & (VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT | VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT |
VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT | VK_IMAGE_ASPECT_MEMORY_PLANE_3_BIT_EXT)) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-attachment-04563"
: "VUID-VkInputAttachmentAspectReference-aspectMask-02250";
skip |= LogError(vuid, device, input_loc.dot(Field::aspectMask), "is %s.",
string_VkImageAspectFlags(aspect_mask).c_str());
}
const VkImageLayout attachment_layout = attachment_ref.layout;
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06912" : "VUID-VkSubpassDescription-attachment-06912";
skip |= LogError(vuid, device, input_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06918" : "VUID-VkSubpassDescription-attachment-06918";
skip |= LogError(vuid, device, input_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (attachment_layout == VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06921" : "VUID-VkSubpassDescription-attachment-06921";
skip |= LogError(vuid, device, input_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (fragment_density_map_info) {
const auto &fdm_attachment_index = fragment_density_map_info->fragmentDensityMapAttachment.attachment;
if ((fdm_attachment_index != VK_ATTACHMENT_UNUSED) && (attachment_index == fdm_attachment_index)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02548", device,
input_loc,
"is also referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment");
}
}
// safe to dereference pCreateInfo->pAttachments[]
if (attachment_index < create_info.attachmentCount) {
const VkAttachmentDescription2 &attachment_description = create_info.pAttachments[attachment_index];
const VkFormat attachment_format = attachment_description.format;
skip |= ValidateAttachmentReference(attachment_ref, attachment_format, true, input_loc);
skip |= AddAttachmentUse(attachment_uses, attachment_layouts, attachment_index, ATTACHMENT_INPUT,
attachment_ref.layout, input_loc);
{
const char *vuid =
use_rp2 ? "VUID-VkRenderPassCreateInfo2-attachment-02525" : "VUID-VkRenderPassCreateInfo-pNext-01963";
// Assuming no disjoint image since there's no handle
skip |= ValidateImageAspectMask(VK_NULL_HANDLE, attachment_format, aspect_mask, false, create_info_loc, vuid);
}
if (attach_first_use[attachment_index]) {
skip |= ValidateLayoutVsAttachmentDescription(subpass.pInputAttachments[j].layout, attachment_index,
attachment_description, input_loc.dot(Field::layout));
const bool used_as_depth = (subpass.pDepthStencilAttachment != NULL &&
subpass.pDepthStencilAttachment->attachment == attachment_index);
bool used_as_color = false;
for (uint32_t k = 0; !used_as_depth && !used_as_color && k < subpass.colorAttachmentCount; ++k) {
used_as_color = (subpass.pColorAttachments[k].attachment == attachment_index);
}
if (!used_as_depth && !used_as_color && attachment_description.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-loadOp-03064" : "VUID-VkSubpassDescription-loadOp-00846";
skip |= LogError(vuid, device, attachment_loc.dot(Field::loadOp), "is VK_ATTACHMENT_LOAD_OP_CLEAR.");
}
}
attach_first_use[attachment_index] = false;
const VkFormatFeatureFlags2 valid_flags =
VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT;
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(attachment_format);
const void *pNext = (use_rp2) ? attachment_description.pNext : nullptr;
if ((format_features & valid_flags) == 0 && GetExternalFormat(pNext) == 0) {
if (!enabled_features.linearColorAttachment) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pInputAttachments-02897"
: "VUID-VkSubpassDescription-pInputAttachments-02647";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"%s (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT\n(supported features: %s).",
string_VkFormat(attachment_format), input_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
} else if ((format_features & VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV) == 0) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-linearColorAttachment-06499"
: "VUID-VkSubpassDescription-linearColorAttachment-06496";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"%s (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV\n(supported features: %s).",
string_VkFormat(attachment_format), input_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
}
}
}
if (use_rp2) {
// These are validated automatically as part of parameter validation for create renderpass 1
// as they are in a struct that only applies to input attachments - not so for v2.
// Check for 0
if (aspect_mask == 0) {
skip |= LogError("VUID-VkSubpassDescription2-attachment-02800", device, input_loc.dot(Field::aspectMask),
"is zero.");
} else {
const VkImageAspectFlags valid_bits =
(VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT |
VK_IMAGE_ASPECT_METADATA_BIT | VK_IMAGE_ASPECT_PLANE_0_BIT | VK_IMAGE_ASPECT_PLANE_1_BIT |
VK_IMAGE_ASPECT_PLANE_2_BIT | VK_IMAGE_ASPECT_MEMORY_PLANE_0_BIT_EXT |
VK_IMAGE_ASPECT_MEMORY_PLANE_1_BIT_EXT | VK_IMAGE_ASPECT_MEMORY_PLANE_2_BIT_EXT |
VK_IMAGE_ASPECT_MEMORY_PLANE_3_BIT_EXT);
// Check for valid aspect mask bits
if (aspect_mask & ~valid_bits) {
skip |= LogError("VUID-VkSubpassDescription2-attachment-02799", device, input_loc.dot(Field::aspectMask),
"(%s) is invalid.", string_VkImageAspectFlags(aspect_mask).c_str());
}
}
}
}
for (uint32_t j = 0; j < subpass.preserveAttachmentCount; ++j) {
const Location preserve_loc = subpass_loc.dot(Field::preserveAttachmentCount, j);
uint32_t attachment = subpass.pPreserveAttachments[j];
if (attachment == VK_ATTACHMENT_UNUSED) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-03073" : "VUID-VkSubpassDescription-attachment-00853";
skip |= LogError(vuid, device, preserve_loc, "must not be VK_ATTACHMENT_UNUSED.");
} else {
skip |= ValidateAttachmentIndex(attachment, create_info.attachmentCount, preserve_loc);
if (attachment < create_info.attachmentCount) {
skip |= AddAttachmentUse(attachment_uses, attachment_layouts, attachment, ATTACHMENT_PRESERVE,
VkImageLayout(0) /* preserve doesn't have any layout */, preserve_loc);
}
if (fragment_density_map_info) {
const uint32_t fdm_attachment_index = fragment_density_map_info->fragmentDensityMapAttachment.attachment;
if ((fdm_attachment_index != VK_ATTACHMENT_UNUSED) && (attachment == fdm_attachment_index)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02548",
device, preserve_loc,
"is also referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment");
}
}
}
}
bool subpass_performs_resolve = false;
for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
if (!subpass.pResolveAttachments) {
continue;
}
auto const &attachment_ref = subpass.pResolveAttachments[j];
if (attachment_ref.attachment == VK_ATTACHMENT_UNUSED) {
continue;
}
const Location resolve_loc = subpass_loc.dot(Field::pResolveAttachments, j);
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, attachment_ref.attachment);
skip |= ValidateAttachmentIndex(attachment_ref.attachment, create_info.attachmentCount, resolve_loc);
const VkImageLayout attachment_layout = attachment_ref.layout;
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06914" : "VUID-VkSubpassDescription-attachment-06914";
skip |= LogError(vuid, device, resolve_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (IsValueIn(attachment_layout, {VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06917" : "VUID-VkSubpassDescription-attachment-06917";
skip |= LogError(vuid, device, resolve_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06920" : "VUID-VkSubpassDescription-attachment-06920";
skip |= LogError(vuid, device, resolve_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (attachment_layout == VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06923" : "VUID-VkSubpassDescription-attachment-06923";
skip |= LogError(vuid, device, resolve_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (fragment_density_map_info) {
const auto &fdm_attachment_index = fragment_density_map_info->fragmentDensityMapAttachment.attachment;
if ((fdm_attachment_index != VK_ATTACHMENT_UNUSED) && (attachment_ref.attachment == fdm_attachment_index)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02548", device,
resolve_loc,
"is also referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment");
}
}
// safe to dereference pCreateInfo->pAttachments[]
if (attachment_ref.attachment < create_info.attachmentCount) {
const VkFormat attachment_format = create_info.pAttachments[attachment_ref.attachment].format;
skip |= ValidateAttachmentReference(attachment_ref, attachment_format, false, resolve_loc);
skip |= AddAttachmentUse(attachment_uses, attachment_layouts, attachment_ref.attachment, ATTACHMENT_RESOLVE,
attachment_ref.layout, resolve_loc);
subpass_performs_resolve = true;
if (create_info.pAttachments[attachment_ref.attachment].samples != VK_SAMPLE_COUNT_1_BIT) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pResolveAttachments-03067"
: "VUID-VkSubpassDescription-pResolveAttachments-00849";
skip |= LogError(vuid, device, attachment_loc.dot(Field::samples), "is %s (referenced by %s).",
string_VkSampleCountFlagBits(create_info.pAttachments[attachment_ref.attachment].samples),
resolve_loc.Fields().c_str());
}
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(attachment_format);
// Can be VK_FORMAT_UNDEFINED with VK_ANDROID_external_format_resolve
if ((format_features & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT) == 0 && attachment_format != VK_FORMAT_UNDEFINED) {
if (!enabled_features.linearColorAttachment) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pResolveAttachments-09343"
: "VUID-VkSubpassDescription-pResolveAttachments-02649";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"%s (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT\n(supported features: %s).",
string_VkFormat(attachment_format), resolve_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
} else if ((format_features & VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV) == 0) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-linearColorAttachment-06501"
: "VUID-VkSubpassDescription-linearColorAttachment-06498";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"%s (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV\n(supported features: %s).",
string_VkFormat(attachment_format), resolve_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
}
}
if ((subpass.flags & VK_SUBPASS_DESCRIPTION_CUSTOM_RESOLVE_BIT_EXT) != 0) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-flags-04907" : "VUID-VkSubpassDescription-flags-03341";
skip |= LogError(vuid, device, resolve_loc,
"contains a reference to attachment %" PRIu32 " instead of being VK_ATTACHMENT_UNUSED.",
attachment_ref.attachment);
}
}
}
if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED) {
const uint32_t attachment = subpass.pDepthStencilAttachment->attachment;
const VkImageLayout image_layout = subpass.pDepthStencilAttachment->layout;
const Location ds_loc = subpass_loc.dot(Field::pDepthStencilAttachment);
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, attachment);
const auto depth_stencil_attachment = create_info.pAttachments[attachment];
skip |= ValidateAttachmentIndex(attachment, create_info.attachmentCount, ds_loc);
const VkImageLayout attachment_layout = subpass.pDepthStencilAttachment->layout;
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06915" : "VUID-VkSubpassDescription-attachment-06915";
skip |=
LogError(vuid, device, ds_loc.dot(Field::layout), "(%s) is invalid.", string_VkImageLayout(attachment_layout));
}
if (use_rp2 && IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL})) {
if (vku::FindStructInPNextChain<VkAttachmentReferenceStencilLayout>(subpass.pDepthStencilAttachment->pNext)) {
const char *vuid = "VUID-VkSubpassDescription2-attachment-06251";
skip |= LogError(vuid, device, ds_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
}
if (fragment_density_map_info) {
const auto &fdm_attachment_index = fragment_density_map_info->fragmentDensityMapAttachment.attachment;
if ((fdm_attachment_index != VK_ATTACHMENT_UNUSED) && (attachment == fdm_attachment_index)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02548", device,
ds_loc,
"is also referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment");
}
}
// safe to dereference pCreateInfo->pAttachments[]
if (attachment < create_info.attachmentCount) {
const VkFormat attachment_format = depth_stencil_attachment.format;
skip |= ValidateAttachmentReference(*subpass.pDepthStencilAttachment, attachment_format, false, ds_loc);
skip |= AddAttachmentUse(attachment_uses, attachment_layouts, attachment, ATTACHMENT_DEPTH, image_layout, ds_loc);
if (attach_first_use[attachment]) {
skip |= ValidateLayoutVsAttachmentDescription(image_layout, attachment, depth_stencil_attachment,
ds_loc.dot(Field::layout));
}
attach_first_use[attachment] = false;
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(attachment_format);
if ((format_features & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pDepthStencilAttachment-02900"
: "VUID-VkSubpassDescription-pDepthStencilAttachment-02650";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"%s (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT\n(supported features: %s).",
string_VkFormat(attachment_format), ds_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
}
if (use_rp2 && enabled_features.multisampledRenderToSingleSampled && ms_render_to_single_sample &&
ms_render_to_single_sample->multisampledRenderToSingleSampledEnable) {
const auto depth_stencil_sample_count = depth_stencil_attachment.samples;
if ((depth_stencil_sample_count == VK_SAMPLE_COUNT_1_BIT) &&
(!subpass_depth_stencil_resolve ||
(subpass_depth_stencil_resolve->pDepthStencilResolveAttachment != VK_NULL_HANDLE &&
subpass_depth_stencil_resolve->pDepthStencilResolveAttachment->attachment != VK_ATTACHMENT_UNUSED))) {
std::stringstream message;
message << "has a VkMultisampledRenderToSingleSampledInfoEXT struct in its "
"VkSubpassDescription2 pNext chain with multisampledRenderToSingleSampled set to "
"VK_TRUE and pDepthStencilAttachment has a sample count of VK_SAMPLE_COUNT_1_BIT ";
if (!subpass_depth_stencil_resolve) {
message << "but there is no VkSubpassDescriptionDepthStencilResolve in the pNext chain of "
"the VkSubpassDescription2 struct for this subpass";
} else {
message << "but the pSubpassResolveAttachment member of the "
"VkSubpassDescriptionDepthStencilResolve in the pNext chain of "
"the VkSubpassDescription2 struct for this subpass is not NULL, and its attachment "
"is not VK_ATTACHMENT_UNUSED";
}
message << "\n" << PrintPNextChain(Struct::VkSubpassDescription2, subpass.pNext);
skip |= LogError("VUID-VkSubpassDescription2-pNext-06871", device, ds_loc, "%s", message.str().c_str());
}
if (subpass_depth_stencil_resolve) {
if (subpass_depth_stencil_resolve->depthResolveMode == VK_RESOLVE_MODE_NONE &&
subpass_depth_stencil_resolve->stencilResolveMode == VK_RESOLVE_MODE_NONE) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pNext-06873", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::depthResolveMode),
"and stencilResolveMode are VK_RESOLVE_MODE_NONE, and "
"VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampled was set to "
"VK_TRUE.");
}
if (vkuFormatHasDepth(attachment_format)) {
if (subpass_depth_stencil_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE &&
!(subpass_depth_stencil_resolve->depthResolveMode &
phys_dev_props_core12.supportedDepthResolveModes)) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pNext-06874", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::depthResolveMode),
"(%s) is not supported in supportedDepthResolveModes (%s), and %s is %s, and "
"VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampled was set to "
"VK_TRUE.",
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->depthResolveMode),
string_VkResolveModeFlags(phys_dev_props_core12.supportedDepthResolveModes).c_str(),
attachment_loc.dot(Field::format).Fields().c_str(), string_VkFormat(attachment_format));
}
}
if (vkuFormatHasStencil(attachment_format)) {
if (subpass_depth_stencil_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE &&
!(subpass_depth_stencil_resolve->stencilResolveMode &
phys_dev_props_core12.supportedStencilResolveModes)) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pNext-06875", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::stencilResolveMode),
"(%s) is not supported in supportedStencilResolveModes (%s), and %s is %s, and "
"VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampled was set to "
"VK_TRUE.",
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->stencilResolveMode),
string_VkResolveModeFlags(phys_dev_props_core12.supportedStencilResolveModes).c_str(),
attachment_loc.dot(Field::format).Fields().c_str(), string_VkFormat(attachment_format));
}
}
if (vkuFormatIsDepthAndStencil(attachment_format)) {
if (phys_dev_props_core12.independentResolve == VK_FALSE &&
phys_dev_props_core12.independentResolveNone == VK_FALSE &&
(subpass_depth_stencil_resolve->stencilResolveMode !=
subpass_depth_stencil_resolve->depthResolveMode)) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pNext-06876", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::depthResolveMode),
"(%s) is different from stencilResolveMode (%s), and %s is %s, and "
"VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampled was set to "
"VK_TRUE.",
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->stencilResolveMode),
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->depthResolveMode),
attachment_loc.dot(Field::format).Fields().c_str(), string_VkFormat(attachment_format));
}
if (phys_dev_props_core12.independentResolve == VK_FALSE &&
phys_dev_props_core12.independentResolveNone == VK_TRUE &&
((subpass_depth_stencil_resolve->stencilResolveMode !=
subpass_depth_stencil_resolve->depthResolveMode) &&
((subpass_depth_stencil_resolve->depthResolveMode != VK_RESOLVE_MODE_NONE) &&
(subpass_depth_stencil_resolve->stencilResolveMode != VK_RESOLVE_MODE_NONE)))) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pNext-06877", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::depthResolveMode),
"(%s) is different from stencilResolveMode (%s), and %s is %s, and "
"VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampled was set to "
"VK_TRUE.",
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->stencilResolveMode),
string_VkResolveModeFlagBits(subpass_depth_stencil_resolve->depthResolveMode),
attachment_loc.dot(Field::format).Fields().c_str(), string_VkFormat(attachment_format));
}
}
}
}
if (IsImageLayoutDepthOnly(subpass.pDepthStencilAttachment->layout)) {
if (vku::FindStructInPNextChain<VkAttachmentReferenceStencilLayout>(subpass.pDepthStencilAttachment->pNext) ==
nullptr) {
if (vkuFormatIsDepthAndStencil(attachment_format)) {
skip |=
LogError("VUID-VkRenderPassCreateInfo2-attachment-06244", device, attachment_loc.dot(Field::format),
"(%s) has both depth and stencil components (referenced by %s).",
string_VkFormat(attachment_format), ds_loc.Fields().c_str());
}
}
if (vkuFormatIsStencilOnly(attachment_format)) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-attachment-06246", device, attachment_loc.dot(Field::format),
"(%s) only has a stencil component (referenced by %s).",
string_VkFormat(attachment_format), ds_loc.Fields().c_str());
}
}
if (IsImageLayoutStencilOnly(subpass.pDepthStencilAttachment->layout)) {
if (!vkuFormatIsStencilOnly(attachment_format)) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-attachment-06245", device, attachment_loc.dot(Field::format),
"(%s) does not only have a stencil component (referenced by %s).",
string_VkFormat(attachment_format), ds_loc.Fields().c_str());
}
}
}
}
uint32_t last_sample_count_attachment = VK_ATTACHMENT_UNUSED;
for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
auto const &attachment_ref = subpass.pColorAttachments[j];
const uint32_t attachment_index = attachment_ref.attachment;
const Location color_loc = subpass_loc.dot(Field::pColorAttachments, j);
if (attachment_index != VK_ATTACHMENT_UNUSED) {
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, attachment_index);
skip |= ValidateAttachmentIndex(attachment_index, create_info.attachmentCount, color_loc);
const VkImageLayout attachment_layout = attachment_ref.layout;
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06913" : "VUID-VkSubpassDescription-attachment-06913";
skip |= LogError(vuid, device, color_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (IsValueIn(attachment_layout, {VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06916" : "VUID-VkSubpassDescription-attachment-06916";
skip |= LogError(vuid, device, color_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (IsValueIn(attachment_layout,
{VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL})) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06919" : "VUID-VkSubpassDescription-attachment-06919";
skip |= LogError(vuid, device, color_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (attachment_layout == VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-attachment-06922" : "VUID-VkSubpassDescription-attachment-06922";
skip |= LogError(vuid, device, color_loc.dot(Field::layout), "(%s) is invalid.",
string_VkImageLayout(attachment_layout));
}
if (fragment_density_map_info) {
const auto &fdm_attachment_index = fragment_density_map_info->fragmentDensityMapAttachment.attachment;
if ((fdm_attachment_index != VK_ATTACHMENT_UNUSED) && (attachment_index == fdm_attachment_index)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02548",
device, color_loc,
"is also referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment");
}
}
// safe to dereference pCreateInfo->pAttachments[]
if (attachment_index < create_info.attachmentCount) {
const VkAttachmentDescription2 &attachment_description = create_info.pAttachments[attachment_index];
const VkFormat attachment_format = attachment_description.format;
skip |= ValidateAttachmentReference(attachment_ref, attachment_format, false, color_loc);
skip |= AddAttachmentUse(attachment_uses, attachment_layouts, attachment_index, ATTACHMENT_COLOR,
attachment_ref.layout, color_loc);
VkSampleCountFlagBits current_sample_count = attachment_description.samples;
if (use_rp2 && enabled_features.multisampledRenderToSingleSampled && ms_render_to_single_sample &&
ms_render_to_single_sample->multisampledRenderToSingleSampledEnable) {
if (current_sample_count != VK_SAMPLE_COUNT_1_BIT &&
current_sample_count != ms_render_to_single_sample->rasterizationSamples) {
skip |= LogError("VUID-VkSubpassDescription2-pNext-06870", device,
create_info_loc.pNext(Struct::VkMultisampledRenderToSingleSampledInfoEXT,
Field::rasterizationSamples),
"(%s) doesn't match %s (%s) (referenced by %s).",
string_VkSampleCountFlagBits(ms_render_to_single_sample->rasterizationSamples),
attachment_loc.dot(Field::samples).Fields().c_str(),
string_VkSampleCountFlagBits(current_sample_count), color_loc.Fields().c_str());
}
}
if (last_sample_count_attachment != VK_ATTACHMENT_UNUSED) {
if (!IsMixSamplingSupported()) {
VkSampleCountFlagBits last_sample_count =
create_info.pAttachments[subpass.pColorAttachments[last_sample_count_attachment].attachment]
.samples;
if (current_sample_count != last_sample_count) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-multisampledRenderToSingleSampled-06872"
: "VUID-VkSubpassDescription-pColorAttachments-09430";
skip |= LogError(vuid, device, attachment_loc.dot(Field::samples),
"is %s, but the pColorAttachments[%" PRIu32 "] has sample count %s.",
string_VkSampleCountFlagBits(current_sample_count), last_sample_count_attachment,
string_VkSampleCountFlagBits(last_sample_count));
}
}
}
last_sample_count_attachment = j;
if (subpass_performs_resolve && current_sample_count == VK_SAMPLE_COUNT_1_BIT &&
!enabled_features.externalFormatResolve) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-externalFormatResolve-09338"
: "VUID-VkSubpassDescription-pResolveAttachments-00848";
skip |= LogError(vuid, device, attachment_loc.dot(Field::samples), "is VK_SAMPLE_COUNT_1_BIT.");
}
if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment != VK_ATTACHMENT_UNUSED &&
subpass.pDepthStencilAttachment->attachment < create_info.attachmentCount) {
const auto depth_stencil_sample_count =
create_info.pAttachments[subpass.pDepthStencilAttachment->attachment].samples;
if (IsExtEnabled(extensions.vk_amd_mixed_attachment_samples)) {
if (current_sample_count > depth_stencil_sample_count) {
const char *vuid =
use_rp2 ? "VUID-VkSubpassDescription2-None-09456" : "VUID-VkSubpassDescription-None-09431";
skip |= LogError(vuid, device, attachment_loc.dot(Field::samples),
"%s) (referenced by %s) is larger than from pCreateInfo->pAttachments[%" PRIu32
"].samples (%s) (referenced by %s).",
string_VkSampleCountFlagBits(current_sample_count), color_loc.Fields().c_str(),
subpass.pDepthStencilAttachment->attachment,
string_VkSampleCountFlagBits(depth_stencil_sample_count),
subpass_loc.dot(Field::pDepthStencilAttachment).Fields().c_str());
break;
}
}
if (!IsMixSamplingSupported() && current_sample_count != depth_stencil_sample_count) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-multisampledRenderToSingleSampled-06872"
: "VUID-VkSubpassDescription-pDepthStencilAttachment-01418";
skip |= LogError(vuid, device, attachment_loc.dot(Field::samples),
"%s) (referenced by %s) is different from pCreateInfo->pAttachments[%" PRIu32
"].samples (%s) (referenced by %s).",
string_VkSampleCountFlagBits(current_sample_count), color_loc.Fields().c_str(),
subpass.pDepthStencilAttachment->attachment,
string_VkSampleCountFlagBits(depth_stencil_sample_count),
subpass_loc.dot(Field::pDepthStencilAttachment).Fields().c_str());
break;
}
}
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(attachment_format);
// Can be VK_FORMAT_UNDEFINED with VK_ANDROID_external_format_resolve
if ((format_features & VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT) == 0 &&
attachment_format != VK_FORMAT_UNDEFINED) {
if (!enabled_features.linearColorAttachment) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-pColorAttachments-02898"
: "VUID-VkSubpassDescription-pColorAttachments-02648";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"(%s) (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT\n(supported features: %s)",
string_VkFormat(attachment_format), color_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
} else if ((format_features & VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV) == 0) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-linearColorAttachment-06500"
: "VUID-VkSubpassDescription-linearColorAttachment-06497";
skip |= LogError(vuid, device, attachment_loc.dot(Field::format),
"(%s) (referenced by %s) doesn't support "
"VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV\n(supported features: %s)",
string_VkFormat(attachment_format), color_loc.Fields().c_str(),
string_VkFormatFeatureFlags2(format_features).c_str());
}
}
if (attach_first_use[attachment_index]) {
skip |= ValidateLayoutVsAttachmentDescription(subpass.pColorAttachments[j].layout, attachment_index,
attachment_description, color_loc.dot(Field::layout));
}
attach_first_use[attachment_index] = false;
}
}
if (subpass_performs_resolve && subpass.pResolveAttachments[j].attachment != VK_ATTACHMENT_UNUSED &&
subpass.pResolveAttachments[j].attachment < create_info.attachmentCount) {
auto const &resolve_attachment_ref = subpass.pResolveAttachments[j];
const uint32_t resolve_attachment_index = resolve_attachment_ref.attachment;
const auto &resolve_desc = create_info.pAttachments[resolve_attachment_index];
const Location &resolve_loc = subpass_loc.dot(Field::pResolveAttachments, j);
if (enabled_features.externalFormatResolve && resolve_desc.format == VK_FORMAT_UNDEFINED) {
if (attachment_index == VK_ATTACHMENT_UNUSED) {
if (!device_state->android_external_format_resolve_null_color_attachment_prop) {
skip |= LogError("VUID-VkSubpassDescription2-nullColorAttachmentWithExternalFormatResolve-09336",
device, resolve_loc.dot(Field::attachment),
"is %" PRIu32 ", pAttachments[%" PRIu32
"].format is VK_FORMAT_UNDEFINED, nullColorAttachmentWithExternalFormatResolve is "
"VK_FALSE, but %s is VK_ATTACHMENT_UNUSED.",
resolve_attachment_index, resolve_attachment_index,
color_loc.dot(Field::attachment).Fields().c_str());
}
} else {
if (device_state->android_external_format_resolve_null_color_attachment_prop) {
skip |= LogError("VUID-VkSubpassDescription2-nullColorAttachmentWithExternalFormatResolve-09337",
device, resolve_loc.dot(Field::attachment),
"is %" PRIu32 ", pAttachments[%" PRIu32
"].format is VK_FORMAT_UNDEFINED, nullColorAttachmentWithExternalFormatResolve is "
"VK_TRUE, but %s is %" PRIu32 ".",
resolve_attachment_index, resolve_attachment_index,
color_loc.dot(Field::attachment).Fields().c_str(), attachment_index);
}
const auto &color_desc = create_info.pAttachments[attachment_index];
if (color_desc.samples != VK_SAMPLE_COUNT_1_BIT) {
skip |= LogError("VUID-VkSubpassDescription2-externalFormatResolve-09345", device,
create_info_loc.dot(Field::pAttachments, attachment_index).dot(Field::samples),
"is %s (referenced by %s).", string_VkSampleCountFlagBits(color_desc.samples),
color_loc.Fields().c_str());
}
}
if (subpass.colorAttachmentCount != 1) {
skip |= LogError("VUID-VkSubpassDescription2-externalFormatResolve-09344", device,
resolve_loc.dot(Field::attachment),
"is %" PRIu32 ", pAttachments[%" PRIu32
"].format is VK_FORMAT_UNDEFINED, but colorAttachmentCount is %" PRIu32 ".",
resolve_attachment_index, resolve_attachment_index, subpass.colorAttachmentCount);
// if this is more then 1, will spam for every instance so just break loop
break;
}
if (subpass.viewMask != 0) {
skip |= LogError("VUID-VkSubpassDescription2-externalFormatResolve-09346", device,
resolve_loc.dot(Field::attachment),
"is %" PRIu32 ", pAttachments[%" PRIu32
"].format is VK_FORMAT_UNDEFINED, but viewMask is 0x%" PRIx32 ".",
resolve_attachment_index, resolve_attachment_index, subpass.viewMask);
}
for (uint32_t k = 0; k < subpass.inputAttachmentCount; ++k) {
const uint32_t input_attachment_index = subpass.pInputAttachments[k].attachment;
if (input_attachment_index == VK_ATTACHMENT_UNUSED) {
continue;
}
if (input_attachment_index == resolve_attachment_index &&
IsAnyPlaneAspect(resolve_attachment_ref.aspectMask)) {
skip |= LogError("VUID-VkSubpassDescription2-externalFormatResolve-09348", device,
resolve_loc.dot(Field::attachment),
"is %" PRIu32 " (reference also by pInputAttachments[%" PRIu32
"]), but the resolve aspectMask is %s.",
resolve_attachment_index, k,
string_VkImageAspectFlags(resolve_attachment_ref.aspectMask).c_str());
} else if (input_attachment_index == attachment_index && IsAnyPlaneAspect(attachment_ref.aspectMask)) {
skip |= LogError("VUID-VkSubpassDescription2-externalFormatResolve-09348", device,
color_loc.dot(Field::attachment),
"is %" PRIu32 " (reference also by pInputAttachments[%" PRIu32
"]), but the resolve aspectMask is %s.",
attachment_index, k, string_VkImageAspectFlags(attachment_ref.aspectMask).c_str());
}
}
const auto *fragment_shading_rate_info =
vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(create_info.pNext);
if (fragment_shading_rate_info && fragment_shading_rate_info->pFragmentShadingRateAttachment &&
fragment_shading_rate_info->pFragmentShadingRateAttachment->attachment != VK_ATTACHMENT_UNUSED) {
skip |= LogError(
"VUID-VkSubpassDescription2-externalFormatResolve-09347", device,
create_info_loc
.pNext(Struct::VkFragmentShadingRateAttachmentInfoKHR, Field::pFragmentShadingRateAttachment)
.dot(Field::attachment),
"is %" PRIu32 ".", fragment_shading_rate_info->pFragmentShadingRateAttachment->attachment);
}
if (fragment_density_map_info &&
fragment_density_map_info->fragmentDensityMapAttachment.attachment != VK_ATTACHMENT_UNUSED) {
skip |= LogError(
"VUID-VkRenderPassCreateInfo2-pResolveAttachments-09331", device,
create_info_loc.dot(Field::pAttachments, attachment_index).dot(Field::format),
"is VK_FORMAT_UNDEFINED (referenced by %s) but %s is %" PRIu32 ".", resolve_loc.Fields().c_str(),
create_info_loc
.pNext(Struct::VkRenderPassFragmentDensityMapCreateInfoEXT, Field::fragmentDensityMapAttachment)
.dot(Field::attachment)
.Fields()
.c_str(),
fragment_density_map_info->fragmentDensityMapAttachment.attachment);
}
} else if (attachment_index == VK_ATTACHMENT_UNUSED) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-externalFormatResolve-09335"
: "VUID-VkSubpassDescription-pResolveAttachments-00847";
skip |= LogError(vuid, device, resolve_loc.dot(Field::attachment),
"is %" PRIu32 ", but %s is VK_ATTACHMENT_UNUSED.", resolve_attachment_index,
color_loc.dot(Field::attachment).Fields().c_str());
} else {
const auto &color_desc = create_info.pAttachments[attachment_index];
if (color_desc.format != resolve_desc.format) {
const char *vuid = use_rp2 ? "VUID-VkSubpassDescription2-externalFormatResolve-09339"
: "VUID-VkSubpassDescription-pResolveAttachments-00850";
skip |= LogError(
vuid, device, create_info_loc.dot(Field::pAttachments, attachment_index).dot(Field::format),
"(%s) (referenced by %s) is different than pAttachments[%" PRIu32 "].format (%s) (referenced by %s).",
string_VkFormat(color_desc.format), color_loc.Fields().c_str(), resolve_attachment_index,
string_VkFormat(resolve_desc.format), resolve_loc.Fields().c_str());
}
}
}
}
if (use_rp2 && enabled_features.multisampledRenderToSingleSampled && ms_render_to_single_sample) {
if (ms_render_to_single_sample->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT) {
skip |=
LogError("VUID-VkMultisampledRenderToSingleSampledInfoEXT-rasterizationSamples-06878", device,
create_info_loc.pNext(Struct::VkMultisampledRenderToSingleSampledInfoEXT, Field::rasterizationSamples),
"is VK_SAMPLE_COUNT_1_BIT, which is not allowed.");
}
}
}
return skip;
}
bool CoreChecks::ValidateRenderPassDAG(const VkRenderPassCreateInfo2 &create_info, const Location &create_info_loc) const {
bool skip = false;
const char *vuid;
const bool use_rp2 = create_info_loc.function != Func::vkCreateRenderPass;
for (uint32_t i = 0; i < create_info.dependencyCount; ++i) {
const Location dependencies_loc = create_info_loc.dot(Field::pDependencies, i);
const VkSubpassDependency2 &dependency = create_info.pDependencies[i];
// The first subpass here serves as a good proxy for "is multiview enabled" - since all view masks need to be non-zero if
// any are, which enables multiview.
if (use_rp2 && (dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT) && (create_info.pSubpasses[0].viewMask == 0)) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-viewMask-03059", device, dependencies_loc,
"specifies the VK_DEPENDENCY_VIEW_LOCAL_BIT, but multiview is not enabled for this render pass.");
} else if (use_rp2 && !(dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT) && dependency.viewOffset != 0) {
skip |= LogError("VUID-VkSubpassDependency2-dependencyFlags-03092", device, dependencies_loc,
"specifies the VK_DEPENDENCY_VIEW_LOCAL_BIT, but also specifies a view offset of %" PRIu32 ".",
dependency.viewOffset);
} else if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL || dependency.dstSubpass == VK_SUBPASS_EXTERNAL) {
if (dependency.srcSubpass == dependency.dstSubpass) {
vuid = use_rp2 ? "VUID-VkSubpassDependency2-srcSubpass-03085" : "VUID-VkSubpassDependency-srcSubpass-00865";
skip |= LogError(vuid, device, dependencies_loc, "srcSubpass and dstSubpass both VK_SUBPASS_EXTERNAL.");
} else if (dependency.dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT) {
if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL) {
vuid = "VUID-VkSubpassDependency-dependencyFlags-02520";
} else { // dependency.dstSubpass == VK_SUBPASS_EXTERNAL
vuid = "VUID-VkSubpassDependency-dependencyFlags-02521";
}
if (use_rp2) {
// Create render pass 2 distinguishes between source and destination external dependencies.
if (dependency.srcSubpass == VK_SUBPASS_EXTERNAL) {
vuid = "VUID-VkSubpassDependency2-dependencyFlags-03090";
} else {
vuid = "VUID-VkSubpassDependency2-dependencyFlags-03091";
}
}
skip |= LogError(vuid, device, dependencies_loc,
"specifies an external dependency but also specifies VK_DEPENDENCY_VIEW_LOCAL_BIT.");
}
} else if (dependency.srcSubpass > dependency.dstSubpass) {
vuid = use_rp2 ? "VUID-VkSubpassDependency2-srcSubpass-03084" : "VUID-VkSubpassDependency-srcSubpass-00864";
skip |= LogError(vuid, device, dependencies_loc,
"specifies a dependency from a later subpass (%" PRIu32 ") to an earlier subpass (%" PRIu32
"), which is "
"disallowed to prevent cyclic dependencies.",
dependency.srcSubpass, dependency.dstSubpass);
} else if (dependency.srcSubpass == dependency.dstSubpass) {
if (dependency.viewOffset != 0) {
vuid = use_rp2 ? "VUID-VkSubpassDependency2-viewOffset-02530" : "VUID-VkRenderPassCreateInfo-pNext-01930";
skip |=
LogError(vuid, device, dependencies_loc,
"specifies a self-dependency but has a non-zero view offset of %" PRIu32 "", dependency.viewOffset);
} else if ((dependency.dependencyFlags | VK_DEPENDENCY_VIEW_LOCAL_BIT) != dependency.dependencyFlags &&
GetBitSetCount(create_info.pSubpasses[dependency.srcSubpass].viewMask) > 1) {
vuid = use_rp2 ? "VUID-VkRenderPassCreateInfo2-pDependencies-03060" : "VUID-VkSubpassDependency-srcSubpass-00872";
skip |= LogError(vuid, device, dependencies_loc,
"specifies a self-dependency for subpass %" PRIu32 " with a viewMask 0x%" PRIx32
", but does not "
"specify VK_DEPENDENCY_VIEW_LOCAL_BIT.",
dependency.srcSubpass, create_info.pSubpasses[dependency.srcSubpass].viewMask);
} else if (HasFramebufferStagePipelineStageFlags(dependency.srcStageMask) &&
HasNonFramebufferStagePipelineStageFlags(dependency.dstStageMask)) {
vuid = use_rp2 ? "VUID-VkSubpassDependency2-srcSubpass-06810" : "VUID-VkSubpassDependency-srcSubpass-06809";
skip |= LogError(vuid, device, dependencies_loc,
"specifies a self-dependency from stage(s) that access framebuffer space %s to stage(s) that "
"access non-framebuffer space %s.",
string_VkPipelineStageFlags(dependency.srcStageMask).c_str(),
string_VkPipelineStageFlags(dependency.dstStageMask).c_str());
} else if ((HasNonFramebufferStagePipelineStageFlags(dependency.srcStageMask) == false) &&
(HasNonFramebufferStagePipelineStageFlags(dependency.dstStageMask) == false) &&
((dependency.dependencyFlags & VK_DEPENDENCY_BY_REGION_BIT) == 0)) {
vuid = use_rp2 ? "VUID-VkSubpassDependency2-srcSubpass-02245" : "VUID-VkSubpassDependency-srcSubpass-02243";
skip |= LogError(vuid, device, dependencies_loc,
"specifies a self-dependency for subpass %" PRIu32
" with both stages including a "
"framebuffer-space stage, but does not specify VK_DEPENDENCY_BY_REGION_BIT in dependencyFlags.",
dependency.srcSubpass);
}
} else if ((dependency.srcSubpass < dependency.dstSubpass) &&
((create_info.pSubpasses[dependency.srcSubpass].flags & VK_SUBPASS_DESCRIPTION_CUSTOM_RESOLVE_BIT_EXT) != 0)) {
vuid = use_rp2 ? "VUID-VkSubpassDescription2-flags-04909" : "VUID-VkSubpassDescription-flags-03343";
skip |= LogError(vuid, device, dependencies_loc,
"specifies that subpass %" PRIu32
" has a dependency on a later subpass"
"and includes VK_SUBPASS_DESCRIPTION_CUSTOM_RESOLVE_BIT_EXT subpass flags.",
dependency.srcSubpass);
}
}
return skip;
}
bool CoreChecks::ValidateCreateRenderPass(const VkRenderPassCreateInfo2 &create_info, const Location &loc) const {
bool skip = false;
const bool use_rp2 = loc.function != Func::vkCreateRenderPass;
const char *vuid;
const Location create_info_loc = loc.dot(Field::pCreateInfo);
skip |= ValidateRenderpassAttachmentUsage(create_info, create_info_loc);
skip |= ValidateRenderPassDAG(create_info, create_info_loc);
// Validate multiview correlation and view masks
bool view_mask_zero = false;
bool view_mask_non_zero = false;
for (uint32_t i = 0; i < create_info.subpassCount; ++i) {
const Location subpass_loc = create_info_loc.dot(Field::pSubpasses, i);
const VkSubpassDescription2 &subpass = create_info.pSubpasses[i];
if (subpass.viewMask != 0) {
view_mask_non_zero = true;
if (!enabled_features.multiview) {
skip |= LogError("VUID-VkSubpassDescription2-multiview-06558", device, subpass_loc.dot(Field::viewMask),
"is 0x%" PRIx32 ", but multiview feature is not enabled.", subpass.viewMask);
}
int highest_view_bit = MostSignificantBit(subpass.viewMask);
if (highest_view_bit > 0 && static_cast<uint32_t>(highest_view_bit) >= phys_dev_props_core11.maxMultiviewViewCount) {
skip |= LogError("VUID-VkSubpassDescription2-viewMask-06706", device, subpass_loc,
"highest bit (%" PRIu32
") is not less than VkPhysicalDeviceMultiviewProperties::maxMultiviewViewCount (%" PRIu32 ").",
highest_view_bit, phys_dev_props_core11.maxMultiviewViewCount);
}
} else {
view_mask_zero = true;
}
if ((subpass.flags & VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVX) != 0 &&
(subpass.flags & VK_SUBPASS_DESCRIPTION_PER_VIEW_ATTRIBUTES_BIT_NVX) == 0) {
vuid = use_rp2 ? "VUID-VkSubpassDescription2-flags-03076" : "VUID-VkSubpassDescription-flags-00856";
skip |= LogError(vuid, device, subpass_loc,
"The flags parameter of subpass description %" PRIu32
" includes "
"VK_SUBPASS_DESCRIPTION_PER_VIEW_POSITION_X_ONLY_BIT_NVX but does not also include "
"VK_SUBPASS_DESCRIPTION_PER_VIEW_ATTRIBUTES_BIT_NVX.",
i);
}
}
if (use_rp2) {
if (view_mask_non_zero && view_mask_zero) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-viewMask-03058", device, loc,
"Some view masks are non-zero whilst others are zero.");
}
if (view_mask_zero && create_info.correlatedViewMaskCount != 0) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-viewMask-03057", device, loc,
"Multiview is not enabled but correlation masks are still provided");
}
}
uint32_t aggregated_cvms = 0;
for (uint32_t i = 0; i < create_info.correlatedViewMaskCount; ++i) {
if (aggregated_cvms & create_info.pCorrelatedViewMasks[i]) {
vuid = use_rp2 ? "VUID-VkRenderPassCreateInfo2-pCorrelatedViewMasks-03056"
: "VUID-VkRenderPassMultiviewCreateInfo-pCorrelationMasks-00841";
skip |= LogError(vuid, device, create_info_loc.dot(Field::pCorrelatedViewMasks, i),
"contains a previously appearing view bit.");
}
aggregated_cvms |= create_info.pCorrelatedViewMasks[i];
}
const auto *fragment_density_map_info =
vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(create_info.pNext);
if (fragment_density_map_info) {
if (fragment_density_map_info->fragmentDensityMapAttachment.attachment != VK_ATTACHMENT_UNUSED) {
const Location fragment_loc =
create_info_loc.pNext(Struct::VkRenderPassFragmentDensityMapCreateInfoEXT, Field::fragmentDensityMapAttachment);
const Location attchment_loc = fragment_loc.dot(Field::attachment);
if (fragment_density_map_info->fragmentDensityMapAttachment.attachment >= create_info.attachmentCount) {
vuid = use_rp2 ? "VUID-VkRenderPassCreateInfo2-fragmentDensityMapAttachment-06472"
: "VUID-VkRenderPassCreateInfo-fragmentDensityMapAttachment-06471";
skip |= LogError(vuid, device, attchment_loc,
"(%" PRIu32 ") must be less than attachmentCount %" PRIu32 " of for this render pass.",
fragment_density_map_info->fragmentDensityMapAttachment.attachment, create_info.attachmentCount);
} else {
if (!(fragment_density_map_info->fragmentDensityMapAttachment.layout ==
VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT ||
fragment_density_map_info->fragmentDensityMapAttachment.layout == VK_IMAGE_LAYOUT_GENERAL)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02549", device,
attchment_loc,
"(%" PRIu32
") layout must be equal to "
"VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT or VK_IMAGE_LAYOUT_GENERAL.",
fragment_density_map_info->fragmentDensityMapAttachment.attachment);
}
if (!(create_info.pAttachments[fragment_density_map_info->fragmentDensityMapAttachment.attachment].loadOp ==
VK_ATTACHMENT_LOAD_OP_LOAD ||
create_info.pAttachments[fragment_density_map_info->fragmentDensityMapAttachment.attachment].loadOp ==
VK_ATTACHMENT_LOAD_OP_DONT_CARE)) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02550", device,
attchment_loc,
"(%" PRIu32
") must reference an attachment with a loadOp "
"equal to VK_ATTACHMENT_LOAD_OP_LOAD or VK_ATTACHMENT_LOAD_OP_DONT_CARE.",
fragment_density_map_info->fragmentDensityMapAttachment.attachment);
}
if (create_info.pAttachments[fragment_density_map_info->fragmentDensityMapAttachment.attachment].storeOp !=
VK_ATTACHMENT_STORE_OP_DONT_CARE) {
skip |= LogError("VUID-VkRenderPassFragmentDensityMapCreateInfoEXT-fragmentDensityMapAttachment-02551", device,
attchment_loc,
"(%" PRIu32
") must reference an attachment with a storeOp "
"equal to VK_ATTACHMENT_STORE_OP_DONT_CARE.",
fragment_density_map_info->fragmentDensityMapAttachment.attachment);
}
}
}
}
auto func_name = use_rp2 ? Func::vkCreateRenderPass2 : Func::vkCreateRenderPass;
auto structure = use_rp2 ? Struct::VkSubpassDependency2 : Struct::VkSubpassDependency;
for (uint32_t i = 0; i < create_info.dependencyCount; ++i) {
auto const &dependency = create_info.pDependencies[i];
Location loc(func_name, structure, Field::pDependencies, i);
skip |= ValidateSubpassDependency(loc, dependency);
}
return skip;
}
bool CoreChecks::PreCallValidateCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
const ErrorObject &error_obj) const {
bool skip = false;
skip |= ValidateDeviceQueueSupport(error_obj.location);
// Handle extension structs from KHR_multiview and KHR_maintenance2 that can only be validated for RP1 (indices out of bounds)
const VkRenderPassMultiviewCreateInfo *multiview_info =
vku::FindStructInPNextChain<VkRenderPassMultiviewCreateInfo>(pCreateInfo->pNext);
if (multiview_info) {
if (multiview_info->subpassCount && multiview_info->subpassCount != pCreateInfo->subpassCount) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-01928", device, error_obj.location,
"Subpass count is %" PRIu32 " but multiview info has a subpass count of %" PRIu32 ".",
pCreateInfo->subpassCount, multiview_info->subpassCount);
} else if (multiview_info->dependencyCount && multiview_info->dependencyCount != pCreateInfo->dependencyCount) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-01929", device, error_obj.location,
"Dependency count is %" PRIu32 " but multiview info has a dependency count of %" PRIu32 ".",
pCreateInfo->dependencyCount, multiview_info->dependencyCount);
}
bool all_zero = true;
bool all_not_zero = true;
for (uint32_t i = 0; i < multiview_info->subpassCount; ++i) {
if (!enabled_features.multiview && multiview_info->pViewMasks[i] != 0) {
skip |= LogError("VUID-VkRenderPassMultiviewCreateInfo-multiview-06555", device, error_obj.location,
"multiview feature is not enabled, but "
"VkRenderPassMultiviewCreateInfo->pViewMask[%" PRIu32 "] is 0x%" PRIx32 ".",
i, multiview_info->pViewMasks[i]);
}
all_zero &= multiview_info->pViewMasks[i] == 0;
all_not_zero &= multiview_info->pViewMasks[i] != 0;
if (MostSignificantBit(multiview_info->pViewMasks[i]) >=
static_cast<int32_t>(phys_dev_props_core11.maxMultiviewViewCount)) {
skip |= LogError("VUID-VkRenderPassMultiviewCreateInfo-pViewMasks-06697", device, error_obj.location,
"Most significant bit in "
"VkRenderPassMultiviewCreateInfo->pViewMask[%" PRIu32 "] (%" PRIu32
") must be less than maxMultiviewViewCount(%" PRIu32 ").",
i, multiview_info->pViewMasks[i], phys_dev_props_core11.maxMultiviewViewCount);
}
}
if (!all_zero && !all_not_zero) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-02513", device, error_obj.location,
"elements of VkRenderPassMultiviewCreateInfo pViewMasks must all be either 0 or not 0.");
}
if (all_zero && multiview_info->correlationMaskCount != 0) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-02515", device, error_obj.location,
"VkRenderPassCreateInfo::correlationMaskCount is %" PRIu32 ", but all elements of pViewMasks are 0.",
multiview_info->correlationMaskCount);
}
for (uint32_t i = 0; i < pCreateInfo->dependencyCount; ++i) {
if ((pCreateInfo->pDependencies[i].dependencyFlags & VK_DEPENDENCY_VIEW_LOCAL_BIT) == 0) {
if (i < multiview_info->dependencyCount && multiview_info->pViewOffsets[i] != 0) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-02512", device,
error_obj.location.dot(Field::pDependencies, i).dot(Field::dependencyFlags),
"does not have VK_DEPENDENCY_VIEW_LOCAL_BIT bit set, but the corresponding "
"VkRenderPassMultiviewCreateInfo::pViewOffsets[%" PRIu32 "] is %" PRId32 ".",
i, multiview_info->pViewOffsets[i]);
}
} else if (all_zero) {
skip |= LogError("VUID-VkRenderPassCreateInfo-pNext-02514", device,
error_obj.location.dot(Field::pDependencies, i).dot(Field::dependencyFlags),
"contains VK_DEPENDENCY_VIEW_LOCAL_BIT bit, but all elements of pViewMasks are 0.");
}
}
}
const VkRenderPassInputAttachmentAspectCreateInfo *input_attachment_aspect_info =
vku::FindStructInPNextChain<VkRenderPassInputAttachmentAspectCreateInfo>(pCreateInfo->pNext);
if (input_attachment_aspect_info) {
for (uint32_t i = 0; i < input_attachment_aspect_info->aspectReferenceCount; ++i) {
uint32_t subpass = input_attachment_aspect_info->pAspectReferences[i].subpass;
uint32_t attachment = input_attachment_aspect_info->pAspectReferences[i].inputAttachmentIndex;
if (subpass >= pCreateInfo->subpassCount) {
skip |= LogError(
"VUID-VkRenderPassCreateInfo-pNext-01926", device,
error_obj.location.pNext(Struct::VkRenderPassInputAttachmentAspectCreateInfo, Field::pAspectReferences, i)
.dot(Field::subpass),
"is %" PRIu32 " which is not less than pCreateInfo->subpassCount (%" PRIu32 ").", subpass,
pCreateInfo->subpassCount);
} else if (pCreateInfo->pSubpasses && attachment >= pCreateInfo->pSubpasses[subpass].inputAttachmentCount) {
skip |= LogError(
"VUID-VkRenderPassCreateInfo-pNext-01927", device,
error_obj.location.pNext(Struct::VkRenderPassInputAttachmentAspectCreateInfo, Field::pAspectReferences, i)
.dot(Field::inputAttachmentIndex),
"is %" PRIu32 " which is not less than pCreateInfo->pSubpasses[%" PRIu32 "].inputAttachmentCount (%" PRIu32
").",
attachment, subpass, pCreateInfo->pSubpasses[subpass].inputAttachmentCount);
}
}
}
if (!skip) {
vku::safe_VkRenderPassCreateInfo2 create_info_2 = ConvertVkRenderPassCreateInfoToV2KHR(*pCreateInfo);
skip |= ValidateCreateRenderPass(*create_info_2.ptr(), error_obj.location);
}
return skip;
}
// VK_KHR_depth_stencil_resolve was added with a requirement on VK_KHR_create_renderpass2 so this will never be able to use
// VkRenderPassCreateInfo
bool CoreChecks::ValidateDepthStencilResolve(const VkRenderPassCreateInfo2 &create_info, const Location &create_info_loc) const {
bool skip = false;
// If the pNext chain in VkSubpassDescription2 includes a VkSubpassDescriptionDepthStencilResolve structure,
// then that structure describes depth/stencil resolve operations for the subpass.
for (uint32_t i = 0; i < create_info.subpassCount; i++) {
const Location subpass_loc = create_info_loc.dot(Field::pSubpasses, i);
const VkSubpassDescription2 &subpass = create_info.pSubpasses[i];
const auto *resolve = vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass.pNext);
// All of the VUs are wrapped in the wording:
// "If pDepthStencilResolveAttachment is not NULL"
if (resolve == nullptr || resolve->pDepthStencilResolveAttachment == nullptr) {
continue;
}
// The spec says
// "If pDepthStencilAttachment is NULL, or if its attachment index is VK_ATTACHMENT_UNUSED, it indicates that no
// depth/stencil attachment will be used in the subpass."
if (subpass.pDepthStencilAttachment == nullptr) {
continue;
} else if (subpass.pDepthStencilAttachment->attachment == VK_ATTACHMENT_UNUSED) {
// while should be ignored, this is an explicit VU and some drivers will crash if this is let through
skip |=
LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03177", device, subpass_loc,
"includes a VkSubpassDescriptionDepthStencilResolve "
"structure with resolve attachment %" PRIu32 ", but pDepthStencilAttachment=VK_ATTACHMENT_UNUSED.",
resolve->pDepthStencilResolveAttachment->attachment);
continue;
}
const uint32_t ds_attachment = subpass.pDepthStencilAttachment->attachment;
const uint32_t resolve_attachment = resolve->pDepthStencilResolveAttachment->attachment;
// ValidateAttachmentIndex() should catch if this is invalid, but skip to avoid crashing
if (ds_attachment >= create_info.attachmentCount) {
continue;
}
// All VUs in VkSubpassDescriptionDepthStencilResolve are wrapped with language saying it is not unused
if (resolve_attachment == VK_ATTACHMENT_UNUSED) {
continue;
}
const Location ds_resolve_loc =
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::pDepthStencilResolveAttachment);
if (resolve_attachment >= create_info.attachmentCount) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pSubpasses-06473", device, ds_resolve_loc,
"must be less than attachmentCount %" PRIu32 " of for this render pass.", create_info.attachmentCount);
// if the index is invalid need to skip everything else to prevent out of bounds index accesses crashing
continue;
}
const VkFormat ds_attachment_format = create_info.pAttachments[ds_attachment].format;
const VkFormat resolve_attachment_format = create_info.pAttachments[resolve_attachment].format;
// "depthResolveMode is ignored if the VkFormat of the pDepthStencilResolveAttachment does not have a depth component"
const bool resolve_has_depth = vkuFormatHasDepth(resolve_attachment_format);
// "stencilResolveMode is ignored if the VkFormat of the pDepthStencilResolveAttachment does not have a stencil component"
const bool resolve_has_stencil = vkuFormatHasStencil(resolve_attachment_format);
if (resolve_has_depth) {
if (!(resolve->depthResolveMode == VK_RESOLVE_MODE_NONE ||
resolve->depthResolveMode & phys_dev_props_core12.supportedDepthResolveModes)) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-depthResolveMode-03183", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::depthResolveMode),
"(%s), must be VK_RESOLVE_MODE_NONE or a value from "
"supportedDepthResolveModes (%s).\npAttachments[%" PRIu32 "].format is %s",
string_VkResolveModeFlagBits(resolve->depthResolveMode),
string_VkResolveModeFlags(phys_dev_props_core12.supportedDepthResolveModes).c_str(),
resolve_attachment, string_VkFormat(resolve_attachment_format));
}
}
if (resolve_has_stencil) {
if (!(resolve->stencilResolveMode == VK_RESOLVE_MODE_NONE ||
resolve->stencilResolveMode & phys_dev_props_core12.supportedStencilResolveModes)) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-stencilResolveMode-03184", device,
subpass_loc.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::stencilResolveMode),
"(%s), must be VK_RESOLVE_MODE_NONE or a value from "
"supportedStencilResolveModes (%s).\npAttachments[%" PRIu32 "].format is %s",
string_VkResolveModeFlagBits(resolve->stencilResolveMode),
string_VkResolveModeFlags(phys_dev_props_core12.supportedStencilResolveModes).c_str(),
resolve_attachment, string_VkFormat(resolve_attachment_format));
}
}
if (resolve_has_depth && resolve_has_stencil) {
if (phys_dev_props_core12.independentResolve == VK_FALSE && phys_dev_props_core12.independentResolveNone == VK_FALSE &&
resolve->depthResolveMode != resolve->stencilResolveMode) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03185", device,
subpass_loc,
"includes a VkSubpassDescriptionDepthStencilResolve "
"structure. The values of depthResolveMode (%s) and stencilResolveMode (%s) must be "
"identical.\npAttachments[%" PRIu32 "].format is %s",
string_VkResolveModeFlagBits(resolve->depthResolveMode),
string_VkResolveModeFlagBits(resolve->stencilResolveMode), resolve_attachment,
string_VkFormat(resolve_attachment_format));
}
if (phys_dev_props_core12.independentResolve == VK_FALSE && phys_dev_props_core12.independentResolveNone == VK_TRUE &&
!(resolve->depthResolveMode == resolve->stencilResolveMode || resolve->depthResolveMode == VK_RESOLVE_MODE_NONE ||
resolve->stencilResolveMode == VK_RESOLVE_MODE_NONE)) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03186", device,
subpass_loc,
"includes a VkSubpassDescriptionDepthStencilResolve "
"structure. The values of depthResolveMode (%s) and stencilResolveMode (%s) must be identical, or "
"one of them must be VK_RESOLVE_MODE_NONE.\npAttachments[%" PRIu32 "].format is %s",
string_VkResolveModeFlagBits(resolve->depthResolveMode),
string_VkResolveModeFlagBits(resolve->stencilResolveMode), resolve_attachment,
string_VkFormat(resolve_attachment_format));
}
}
// Same VU, but better error message if one of the resolves are ignored
if (resolve_has_depth && !resolve_has_stencil && resolve->depthResolveMode == VK_RESOLVE_MODE_NONE) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03178", device,
ds_resolve_loc,
"is not NULL, but the depth resolve mode is VK_RESOLVE_MODE_NONE (stencil resolve mode is "
"ignored due to format not having stencil component).\npAttachments[%" PRIu32 "].format is %s",
resolve_attachment, string_VkFormat(resolve_attachment_format));
} else if (!resolve_has_depth && resolve_has_stencil && resolve->stencilResolveMode == VK_RESOLVE_MODE_NONE) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03178", device,
ds_resolve_loc,
"is not NULL, but the stencil resolve mode is VK_RESOLVE_MODE_NONE (depth resolve mode is "
"ignored due to format not having depth component).\npAttachments[%" PRIu32 "].format is %s",
resolve_attachment, string_VkFormat(resolve_attachment_format));
} else if (resolve_has_depth && resolve_has_stencil && resolve->depthResolveMode == VK_RESOLVE_MODE_NONE &&
resolve->stencilResolveMode == VK_RESOLVE_MODE_NONE) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03178", device, ds_resolve_loc,
"is not NULL, but both depth and stencil resolve modes are VK_RESOLVE_MODE_NONE.\npAttachments[%" PRIu32
"].format is %s",
resolve_attachment, string_VkFormat(resolve_attachment_format));
}
const uint32_t resolve_depth_size = vkuFormatDepthSize(resolve_attachment_format);
const uint32_t resolve_stencil_size = vkuFormatStencilSize(resolve_attachment_format);
if (resolve_depth_size > 0 &&
((vkuFormatDepthSize(ds_attachment_format) != resolve_depth_size) ||
(vkuFormatDepthNumericalType(ds_attachment_format) != vkuFormatDepthNumericalType(ds_attachment_format)))) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03181", device, ds_resolve_loc,
"has a depth component (size %" PRIu32 ") for pAttachments[%" PRIu32
"].format is %s.\nThe depth component "
"of pDepthStencilAttachment must have the same number of bits (currently %" PRIu32 ") and the same numerical type.",
resolve_depth_size, resolve_attachment, string_VkFormat(resolve_attachment_format),
vkuFormatDepthSize(ds_attachment_format));
}
if (resolve_stencil_size > 0 &&
((vkuFormatStencilSize(ds_attachment_format) != resolve_stencil_size) ||
(vkuFormatStencilNumericalType(ds_attachment_format) != vkuFormatStencilNumericalType(resolve_attachment_format)))) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03182", device, ds_resolve_loc,
"has a stencil component (size %" PRIu32 ") for pAttachments[%" PRIu32
"].format is %s.\nThe stencil component "
"of pDepthStencilAttachment must have the same number of bits (currently %" PRIu32 ") and the same numerical type.",
resolve_stencil_size, resolve_attachment, string_VkFormat(resolve_attachment_format),
vkuFormatStencilSize(ds_attachment_format));
}
if (create_info.pAttachments[ds_attachment].samples == VK_SAMPLE_COUNT_1_BIT) {
skip |=
LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03179", device,
ds_resolve_loc, "is not NULL, however pDepthStencilAttachment has sample count of VK_SAMPLE_COUNT_1_BIT.");
}
if (create_info.pAttachments[resolve_attachment].samples != VK_SAMPLE_COUNT_1_BIT) {
skip |= LogError("VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03180", device,
ds_resolve_loc, "has sample count of VK_SAMPLE_COUNT_1_BIT.");
}
const VkFormatFeatureFlags2 potential_format_features = GetPotentialFormatFeatures(resolve_attachment_format);
if ((potential_format_features & VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
skip |= LogError(
"VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-02651", device, ds_resolve_loc,
"has a format %s which doesn't support VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT\n(supported features: %s).",
string_VkFormat(resolve_attachment_format), string_VkFormatFeatureFlags2(potential_format_features).c_str());
}
if ((subpass.flags & VK_SUBPASS_DESCRIPTION_CUSTOM_RESOLVE_BIT_EXT) != 0) {
skip |= LogError("VUID-VkSubpassDescription2-flags-04908", device, subpass_loc,
"enables shader resolve, which requires the depth/stencil resolve attachment"
" must be VK_ATTACHMENT_UNUSED, but a reference to attachment %" PRIu32 " was found instead.",
resolve_attachment);
}
}
return skip;
}
bool CoreChecks::PreCallValidateCreateRenderPass2(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
const ErrorObject &error_obj) const {
bool skip = false;
skip |= ValidateDeviceQueueSupport(error_obj.location);
const Location create_info_loc = error_obj.location.dot(Field::pCreateInfo);
skip |= ValidateDepthStencilResolve(*pCreateInfo, create_info_loc);
skip |= ValidateFragmentShadingRateAttachments(*pCreateInfo, create_info_loc);
skip |= ValidateCreateRenderPass(*pCreateInfo, error_obj.location);
return skip;
}
bool CoreChecks::ValidateFragmentShadingRateAttachments(const VkRenderPassCreateInfo2 &create_info,
const Location &create_info_loc) const {
bool skip = false;
if (!enabled_features.attachmentFragmentShadingRate) {
return false;
}
for (uint32_t attachment_description = 0; attachment_description < create_info.attachmentCount; ++attachment_description) {
std::vector<uint32_t> used_as_fragment_shading_rate_attachment;
// Prepass to find any use as a fragment shading rate attachment structures and validate them independently
for (uint32_t subpass = 0; subpass < create_info.subpassCount; ++subpass) {
const auto *fragment_shading_rate_attachment =
vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(create_info.pSubpasses[subpass].pNext);
if (!fragment_shading_rate_attachment || !fragment_shading_rate_attachment->pFragmentShadingRateAttachment) {
continue;
}
const Location subpass_loc = create_info_loc.dot(Field::pSubpasses, subpass);
const Location fragment_loc =
subpass_loc.pNext(Struct::VkFragmentShadingRateAttachmentInfoKHR, Field::pFragmentShadingRateAttachment);
const VkAttachmentReference2 &attachment_reference =
*(fragment_shading_rate_attachment->pFragmentShadingRateAttachment);
if (attachment_reference.attachment == attachment_description) {
used_as_fragment_shading_rate_attachment.push_back(subpass);
if (create_info.pAttachments[attachment_reference.attachment].loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-09387", device, fragment_loc.dot(Field::attachment),
"(%" PRIu32 ") has a loadOp of VK_ATTACHMENT_LOAD_OP_CLEAR", attachment_reference.attachment);
}
}
if (attachment_reference.attachment != VK_ATTACHMENT_UNUSED) {
if ((create_info.flags & VK_RENDER_PASS_CREATE_TRANSFORM_BIT_QCOM) != 0) {
skip |=
LogError("VUID-VkRenderPassCreateInfo2-flags-04521", device, fragment_loc.dot(Field::attachment),
"is not VK_ATTACHMENT_UNUSED, but render pass includes VK_RENDER_PASS_CREATE_TRANSFORM_BIT_QCOM");
}
const VkFormatFeatureFlags2 potential_format_features =
GetPotentialFormatFeatures(create_info.pAttachments[attachment_reference.attachment].format);
if (!(potential_format_features & VK_FORMAT_FEATURE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR)) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-04586", device,
create_info_loc.dot(Field::pAttachments, attachment_reference.attachment).dot(Field::format),
"is %s and used in %s as a fragment shading rate attachment, but the format doesn't support "
"VK_FORMAT_FEATURE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR\n(supported features: %s)",
string_VkFormat(create_info.pAttachments[attachment_reference.attachment].format),
subpass_loc.Fields().c_str(), string_VkFormatFeatureFlags2(potential_format_features).c_str());
}
if (attachment_reference.layout != VK_IMAGE_LAYOUT_GENERAL &&
attachment_reference.layout != VK_IMAGE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL_KHR) {
skip |= LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04524", device,
fragment_loc.dot(Field::layout), "has a layout of %s.",
string_VkImageLayout(attachment_reference.layout));
}
const VkExtent2D texel_size = fragment_shading_rate_attachment->shadingRateAttachmentTexelSize;
const Location texel_loc =
subpass_loc.pNext(Struct::VkFragmentShadingRateAttachmentInfoKHR, Field::shadingRateAttachmentTexelSize);
if (!IsPowerOfTwo(texel_size.width)) {
skip |= LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04525", device,
texel_loc.dot(Field::width), "(%" PRIu32 ") is a non-power-of-two.", texel_size.width);
}
if (texel_size.width <
phys_dev_ext_props.fragment_shading_rate_props.minFragmentShadingRateAttachmentTexelSize.width) {
skip |=
LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04527", device,
texel_loc.dot(Field::width),
"(%" PRIu32 ") is lower than the advertised minimum width %" PRIu32 ".", texel_size.width,
phys_dev_ext_props.fragment_shading_rate_props.minFragmentShadingRateAttachmentTexelSize.width);
}
if (texel_size.width >
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSize.width) {
skip |=
LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04526", device,
texel_loc.dot(Field::width),
"(%" PRIu32 ") is higher than the advertised maximum width %" PRIu32 ".", texel_size.width,
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSize.width);
}
if (!IsPowerOfTwo(texel_size.height)) {
skip |= LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04528", device,
texel_loc.dot(Field::height), "(%" PRIu32 ") is a non-power-of-two.", texel_size.height);
}
if (texel_size.height <
phys_dev_ext_props.fragment_shading_rate_props.minFragmentShadingRateAttachmentTexelSize.height) {
skip |=
LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04530", device,
texel_loc.dot(Field::height),
"(%" PRIu32 ") is lower than the advertised minimum height %" PRIu32 ".", texel_size.height,
phys_dev_ext_props.fragment_shading_rate_props.minFragmentShadingRateAttachmentTexelSize.height);
}
if (texel_size.height >
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSize.height) {
skip |=
LogError("VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04529", device,
texel_loc.dot(Field::height),
"(%" PRIu32 ") is higher than the advertised maximum height %" PRIu32 ".", texel_size.height,
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSize.height);
}
uint32_t aspect_ratio = texel_size.width / texel_size.height;
uint32_t inverse_aspect_ratio = texel_size.height / texel_size.width;
if (aspect_ratio >
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) {
skip |= LogError(
"VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04531", device, texel_loc,
"has a texel size of %" PRIu32 " by %" PRIu32 ", which has an aspect ratio %" PRIu32
", which is higher than the advertised maximum aspect ratio %" PRIu32 ".",
texel_size.width, texel_size.height, aspect_ratio,
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSizeAspectRatio);
}
if (inverse_aspect_ratio >
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSizeAspectRatio) {
skip |= LogError(
"VUID-VkFragmentShadingRateAttachmentInfoKHR-pFragmentShadingRateAttachment-04532", device, texel_loc,
"has a texel size of %" PRIu32 " by %" PRIu32 ", which has an inverse aspect ratio of %" PRIu32
", which is higher than the advertised maximum aspect ratio %" PRIu32 ".",
texel_size.width, texel_size.height, inverse_aspect_ratio,
phys_dev_ext_props.fragment_shading_rate_props.maxFragmentShadingRateAttachmentTexelSizeAspectRatio);
}
}
}
// Lambda function turning a vector of integers into a string
auto vector_to_string = [&](std::vector<uint32_t> vector) {
std::stringstream ss;
size_t size = vector.size();
for (size_t i = 0; i < used_as_fragment_shading_rate_attachment.size(); i++) {
if (size == 2 && i == 1) {
ss << " and ";
} else if (size > 2 && i == size - 2) {
ss << ", and ";
} else if (i != 0) {
ss << ", ";
}
ss << vector[i];
}
return ss.str();
};
// Search for other uses of the same attachment
if (!used_as_fragment_shading_rate_attachment.empty()) {
for (uint32_t subpass = 0; subpass < create_info.subpassCount; ++subpass) {
const Location subpass_loc = create_info_loc.dot(Field::pSubpasses, subpass);
const VkSubpassDescription2 &subpass_info = create_info.pSubpasses[subpass];
std::string fsr_attachment_subpasses_string = vector_to_string(used_as_fragment_shading_rate_attachment);
for (uint32_t attachment = 0; attachment < subpass_info.colorAttachmentCount; ++attachment) {
if (subpass_info.pColorAttachments[attachment].attachment == attachment_description) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-04585", device,
subpass_loc.dot(Field::pColorAttachments, attachment).dot(Field::attachment),
"is also used in pAttachments[%" PRIu32
"] as a fragment shading rate attachment in subpass(es) %s",
attachment_description, fsr_attachment_subpasses_string.c_str());
}
}
for (uint32_t attachment = 0; attachment < subpass_info.colorAttachmentCount; ++attachment) {
if (subpass_info.pResolveAttachments &&
subpass_info.pResolveAttachments[attachment].attachment == attachment_description) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-04585", device,
subpass_loc.dot(Field::pResolveAttachments, attachment).dot(Field::attachment),
"is also used in pAttachments[%" PRIu32
"] as a fragment shading rate attachment in subpass(es) %s",
attachment_description, fsr_attachment_subpasses_string.c_str());
}
}
for (uint32_t attachment = 0; attachment < subpass_info.inputAttachmentCount; ++attachment) {
if (subpass_info.pInputAttachments[attachment].attachment == attachment_description) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-04585", device,
subpass_loc.dot(Field::pInputAttachments, attachment).dot(Field::attachment),
"is also used in pAttachments[%" PRIu32
"] as a fragment shading rate attachment in subpass(es) %s",
attachment_description, fsr_attachment_subpasses_string.c_str());
}
}
if (subpass_info.pDepthStencilAttachment) {
if (subpass_info.pDepthStencilAttachment->attachment == attachment_description) {
skip |= LogError("VUID-VkRenderPassCreateInfo2-pAttachments-04585", device,
subpass_loc.dot(Field::pDepthStencilAttachment).dot(Field::attachment),
"is also used in pAttachments[%" PRIu32
"] as a fragment shading rate attachment in subpass(es) %s",
attachment_description, fsr_attachment_subpasses_string.c_str());
}
}
const auto *depth_stencil_resolve_attachment =
vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass_info.pNext);
if (depth_stencil_resolve_attachment && depth_stencil_resolve_attachment->pDepthStencilResolveAttachment) {
if (depth_stencil_resolve_attachment->pDepthStencilResolveAttachment->attachment == attachment_description) {
skip |= LogError(
"VUID-VkRenderPassCreateInfo2-pAttachments-04585", device,
subpass_loc
.pNext(Struct::VkSubpassDescriptionDepthStencilResolve, Field::pDepthStencilResolveAttachment)
.dot(Field::attachment),
"is also used in pAttachments[%" PRIu32 "] as a fragment shading rate attachment in subpass(es) %s",
attachment_description, fsr_attachment_subpasses_string.c_str());
}
}
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateCreateRenderPass2KHR(VkDevice device, const VkRenderPassCreateInfo2 *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass,
const ErrorObject &error_obj) const {
return PreCallValidateCreateRenderPass2(device, pCreateInfo, pAllocator, pRenderPass, error_obj);
}
bool CoreChecks::ValidateRenderingInfoAttachmentDeviceGroup(const vvl::Image &image_state, const VkRenderingInfo &rendering_info,
const LogObjectList &objlist, const Location &loc) const {
bool skip = false;
auto device_group_render_pass_begin_info = vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(rendering_info.pNext);
if (!device_group_render_pass_begin_info || device_group_render_pass_begin_info->deviceRenderAreaCount == 0) {
// Upcasting to handle overflow
const bool x_extent_valid =
static_cast<int64_t>(image_state.create_info.extent.width) >=
static_cast<int64_t>(rendering_info.renderArea.offset.x) + static_cast<int64_t>(rendering_info.renderArea.extent.width);
if (!x_extent_valid) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06079", objlist, loc,
"width (%" PRIu32 ") is less than pRenderingInfo->renderArea.offset.x (%" PRId32
") + pRenderingInfo->renderArea.extent.width (%" PRIu32 ").",
image_state.create_info.extent.width, rendering_info.renderArea.offset.x,
rendering_info.renderArea.extent.width);
}
const bool y_extent_valid = static_cast<int64_t>(image_state.create_info.extent.height) >=
static_cast<int64_t>(rendering_info.renderArea.offset.y) +
static_cast<int64_t>(rendering_info.renderArea.extent.height);
if (!y_extent_valid) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06080", objlist, loc,
"height (%" PRIu32 ") is less than pRenderingInfo->renderArea.offset.y (%" PRId32
") + pRenderingInfo->renderArea.extent.height (%" PRIu32 ").",
image_state.create_info.extent.height, rendering_info.renderArea.offset.y,
rendering_info.renderArea.extent.height);
}
}
return skip;
}
bool CoreChecks::ValidateRenderingAttachmentInfo(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const VkRenderingAttachmentInfo &attachment_info,
const Location &attachment_loc) const {
bool skip = false;
// "If imageView is VK_NULL_HANDLE, and resolveMode is not VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID, other members
// of this structure are ignored"
if (attachment_info.imageView == VK_NULL_HANDLE) {
return false;
}
const auto image_view_state = Get<vvl::ImageView>(attachment_info.imageView);
ASSERT_AND_RETURN_SKIP(image_view_state);
skip |= ValidateRenderingAttachmentInfoResolveMode(commandBuffer, rendering_info, attachment_info, *image_view_state,
attachment_loc);
skip |= ValidateRenderingAttachmentInfoFeedbackLoop(commandBuffer, attachment_info, *image_view_state, attachment_loc);
skip |= ValidateRenderingAttachmentFlagsInfo(commandBuffer, attachment_info, *image_view_state, attachment_loc);
return skip;
}
bool CoreChecks::ValidateRenderingAttachmentInfoResolveMode(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const VkRenderingAttachmentInfo &attachment_info,
const vvl::ImageView &image_view_state,
const Location &attachment_loc) const {
bool skip = false;
// First validate things when resolve mode can be NONE
const VkFormat image_view_format = image_view_state.create_info.format;
if ((!vkuFormatIsSINT(image_view_format) && !vkuFormatIsUINT(image_view_format)) && vkuFormatIsColor(image_view_format) &&
!IsValueIn(attachment_info.resolveMode,
{VK_RESOLVE_MODE_NONE, VK_RESOLVE_MODE_AVERAGE_BIT, VK_RESOLVE_MODE_CUSTOM_BIT_EXT})) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06129", objlist, attachment_loc.dot(Field::resolveMode),
"(%s) must be VK_RESOLVE_MODE_NONE or VK_RESOLVE_MODE_AVERAGE_BIT for non-integer formats (%s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode), string_VkFormat(image_view_format));
}
if ((vkuFormatIsSINT(image_view_format) || vkuFormatIsUINT(image_view_format)) && vkuFormatIsColor(image_view_format) &&
!IsValueIn(attachment_info.resolveMode,
{VK_RESOLVE_MODE_NONE, VK_RESOLVE_MODE_SAMPLE_ZERO_BIT, VK_RESOLVE_MODE_CUSTOM_BIT_EXT})) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06130", objlist, attachment_loc.dot(Field::resolveMode),
"(%s) must be VK_RESOLVE_MODE_NONE or VK_RESOLVE_MODE_SAMPLE_ZERO_BIT for integer formats (%s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode), string_VkFormat(image_view_format));
}
if (attachment_info.resolveMode == VK_RESOLVE_MODE_NONE) {
return skip;
}
auto resolve_view_state = Get<vvl::ImageView>(attachment_info.resolveImageView);
if (resolve_view_state && resolve_view_state->samples != VK_SAMPLE_COUNT_1_BIT) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |=
LogError("VUID-VkRenderingAttachmentInfo-imageView-06864", commandBuffer, attachment_loc.dot(Field::resolveMode),
"%s but resolveImageView has a sample count of %s", string_VkResolveModeFlagBits(attachment_info.resolveMode),
string_VkSampleCountFlagBits(resolve_view_state->samples));
}
if (attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06146", objlist, attachment_loc.dot(Field::resolveImageLayout),
"must not be VK_IMAGE_LAYOUT_PRESENT_SRC_KHR (resolveMode is %s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL_KHR) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
const char *vuid = IsExtEnabled(extensions.vk_khr_fragment_shading_rate) ? "VUID-VkRenderingAttachmentInfo-imageView-06144"
: "VUID-VkRenderingAttachmentInfo-imageView-06139";
skip |= LogError(vuid, objlist, attachment_loc.dot(Field::resolveImageLayout),
"must not be VK_IMAGE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL_KHR "
"(or the alias VK_IMAGE_LAYOUT_SHADING_RATE_OPTIMAL_NV) (resolveMode is %s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06141", objlist, attachment_loc.dot(Field::resolveImageLayout),
"must not be VK_IMAGE_LAYOUT_FRAGMENT_DENSITY_MAP_OPTIMAL_EXT (resolveMode is %s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06142", objlist, attachment_loc.dot(Field::resolveImageLayout),
"must not be VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL (resolveMode is %s)",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (attachment_info.resolveMode != VK_RESOLVE_MODE_CUSTOM_BIT_EXT && resolve_view_state &&
(image_view_format != resolve_view_state->create_info.format)) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView, image_view_state.Handle());
skip |=
LogError("VUID-VkRenderingAttachmentInfo-imageView-06865", objlist, attachment_loc.dot(Field::resolveImageView),
"format (%s) and %s format (%s) are different (resolveMode is %s).",
string_VkFormat(resolve_view_state->create_info.format), attachment_loc.dot(Field::imageView).Fields().c_str(),
string_VkFormat(image_view_format), string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (IsValueIn(attachment_info.resolveImageLayout,
{VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PREINITIALIZED, VK_IMAGE_LAYOUT_ZERO_INITIALIZED_EXT})) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06136", objlist, attachment_loc.dot(Field::resolveImageLayout),
"is %s (resolveMode is %s).", string_VkImageLayout(attachment_info.resolveImageLayout),
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (((attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL) ||
(attachment_info.resolveImageLayout == VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL))) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06137", objlist, attachment_loc.dot(Field::resolveImageLayout),
"is %s (resolveMode is %s).", string_VkImageLayout(attachment_info.resolveImageLayout),
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
const auto msrtss_info = vku::FindStructInPNextChain<VkMultisampledRenderToSingleSampledInfoEXT>(rendering_info.pNext);
if (image_view_state.samples == VK_SAMPLE_COUNT_1_BIT) {
if (!msrtss_info || !msrtss_info->multisampledRenderToSingleSampledEnable) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-06861", objlist, attachment_loc.dot(Field::imageView),
"must not have a VK_SAMPLE_COUNT_1_BIT when resolveMode is %s",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
if (msrtss_info && msrtss_info->multisampledRenderToSingleSampledEnable &&
(attachment_info.resolveImageView != VK_NULL_HANDLE)) {
const LogObjectList objlist(commandBuffer, attachment_info.resolveImageView);
skip |= LogError(
"VUID-VkRenderingAttachmentInfo-imageView-06863", objlist, attachment_loc.dot(Field::resolveMode),
"is %s and VkMultisampledRenderToSingleSampledInfoEXT::multisampledRenderToSingleSampledEnable is VK_TRUE, and "
"%s.imageView has a sample count of VK_SAMPLE_COUNT_1_BIT, and resolveImageView (%s) is not VK_NULL_HANDLE.",
string_VkResolveModeFlagBits(attachment_info.resolveMode), attachment_loc.dot(Field::resolveMode).Fields().c_str(),
FormatHandle(attachment_info.resolveImageView).c_str());
}
}
if (attachment_info.resolveImageView == VK_NULL_HANDLE) {
if (!msrtss_info || !msrtss_info->multisampledRenderToSingleSampledEnable) {
skip |=
LogError("VUID-VkRenderingAttachmentInfo-imageView-06862", commandBuffer, attachment_loc.dot(Field::resolveMode),
"(%s) is not VK_RESOLVE_MODE_NONE, resolveImageView must not be VK_NULL_HANDLE",
string_VkResolveModeFlagBits(attachment_info.resolveMode));
}
}
return skip;
}
bool CoreChecks::ValidateRenderingAttachmentInfoFeedbackLoop(VkCommandBuffer commandBuffer,
const VkRenderingAttachmentInfo &attachment_info,
const vvl::ImageView &image_view_state,
const Location &attachment_loc) const {
bool skip = false;
const auto attachment_feedback_loop_info = vku::FindStructInPNextChain<VkAttachmentFeedbackLoopInfoEXT>(attachment_info.pNext);
bool explicit_enabled = attachment_feedback_loop_info && attachment_feedback_loop_info->feedbackLoopEnable;
if (attachment_info.imageLayout == VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT || explicit_enabled) {
const bool has_feedback_loop = image_view_state.inherited_usage & VK_IMAGE_USAGE_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT;
const bool has_color_ds =
image_view_state.inherited_usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
const bool has_input_sample =
image_view_state.inherited_usage & (VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
if (!has_feedback_loop || !has_color_ds || !has_input_sample) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
if (explicit_enabled) {
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-10780", objlist,
attachment_loc.pNext(Struct::VkAttachmentFeedbackLoopInfoEXT, Field::feedbackLoopEnable),
"is VK_TRUE, but image view usage is %s.",
string_VkImageUsageFlags(image_view_state.inherited_usage).c_str());
} else {
skip |= LogError("VUID-VkRenderingAttachmentInfo-imageView-10780", objlist, attachment_loc.dot(Field::imageLayout),
"is VK_IMAGE_LAYOUT_ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT, but image view usage is %s.",
string_VkImageUsageFlags(image_view_state.inherited_usage).c_str());
}
}
}
return skip;
}
bool CoreChecks::ValidateRenderingAttachmentFlagsInfo(VkCommandBuffer commandBuffer,
const VkRenderingAttachmentInfo &attachment_info,
const vvl::ImageView &image_view_state,
const Location &attachment_loc) const {
bool skip = false;
const auto attachment_flags = vku::FindStructInPNextChain<VkRenderingAttachmentFlagsInfoKHR>(attachment_info.pNext);
if (!attachment_flags) {
return skip;
}
if (attachment_flags->flags & (VK_RENDERING_ATTACHMENT_RESOLVE_SKIP_TRANSFER_FUNCTION_BIT_KHR |
VK_RENDERING_ATTACHMENT_RESOLVE_ENABLE_TRANSFER_FUNCTION_BIT_KHR)) {
if (!vkuFormatIsSRGB(image_view_state.create_info.format)) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-pNext-11752", objlist,
attachment_loc.pNext(Struct::VkRenderingAttachmentFlagsInfoKHR, Field::flags),
"is %s but image view has format %s.",
string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str(),
string_VkFormat(image_view_state.create_info.format));
}
if (attachment_info.resolveMode != VK_RESOLVE_MODE_AVERAGE_BIT) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |=
LogError("VUID-VkRenderingAttachmentInfo-pNext-11753", objlist, attachment_loc.dot(Field::resolveMode),
"is %s but a VkRenderingAttachmentFlagsInfoKHR is included in the attachment pNext chain with flags (%s).",
string_VkResolveModeFlags(attachment_info.resolveMode).c_str(),
string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str());
}
}
if (attachment_flags->flags & VK_RENDERING_ATTACHMENT_INPUT_ATTACHMENT_FEEDBACK_BIT_KHR) {
if (!(image_view_state.image_state->create_info.usage & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
const LogObjectList objlist(commandBuffer, attachment_info.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-pNext-11754", objlist,
attachment_loc.pNext(Struct::VkRenderingAttachmentFlagsInfoKHR, Field::flags),
"is %s but image has usage %s.", string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str(),
string_VkImageUsageFlags(image_view_state.image_state->create_info.usage).c_str());
}
if (!enabled_features.dynamicRenderingLocalRead) {
skip |= LogError("VUID-VkRenderingAttachmentFlagsInfoKHR-flags-11755", commandBuffer,
attachment_loc.pNext(Struct::VkRenderingAttachmentFlagsInfoKHR, Field::flags), "is %s.",
string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str());
}
}
if (attachment_flags->flags & VK_RENDERING_ATTACHMENT_RESOLVE_SKIP_TRANSFER_FUNCTION_BIT_KHR) {
if (attachment_flags->flags & VK_RENDERING_ATTACHMENT_RESOLVE_ENABLE_TRANSFER_FUNCTION_BIT_KHR) {
skip |= LogError("VUID-VkRenderingAttachmentFlagsInfoKHR-flags-11756", commandBuffer,
attachment_loc.pNext(Struct::VkRenderingAttachmentFlagsInfoKHR, Field::flags), "is %s.",
string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str());
}
}
if (attachment_flags->flags & (VK_RENDERING_ATTACHMENT_RESOLVE_SKIP_TRANSFER_FUNCTION_BIT_KHR |
VK_RENDERING_ATTACHMENT_RESOLVE_ENABLE_TRANSFER_FUNCTION_BIT_KHR)) {
if (!phys_dev_ext_props.maintenance10_props.resolveSrgbFormatSupportsTransferFunctionControl) {
skip |= LogError("VUID-VkRenderingAttachmentFlagsInfoKHR-flags-11757", commandBuffer,
attachment_loc.pNext(Struct::VkRenderingAttachmentFlagsInfoKHR, Field::flags),
"is %s but resolveSrgbFormatSupportsTransferFunctionControl is VK_FALSE.",
string_VkRenderingAttachmentFlagsKHR(attachment_flags->flags).c_str());
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingFragmentDensityMap(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const auto *fragment_density_map_attachment_info =
vku::FindStructInPNextChain<VkRenderingFragmentDensityMapAttachmentInfoEXT>(rendering_info.pNext);
if (!fragment_density_map_attachment_info) {
return false;
}
if (!enabled_features.fragmentDensityMapNonSubsampledImages) {
for (uint32_t j = 0; j < rendering_info.colorAttachmentCount; ++j) {
if (rendering_info.pColorAttachments[j].imageView != VK_NULL_HANDLE) {
auto image_view_state = Get<vvl::ImageView>(rendering_info.pColorAttachments[j].imageView);
if (!image_view_state) {
continue;
}
if (!(image_view_state->image_state->create_info.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT)) {
const LogObjectList objlist(commandBuffer, rendering_info.pColorAttachments[j].imageView);
skip |= LogError("VUID-VkRenderingInfo-imageView-06107", objlist,
rendering_info_loc.dot(Field::pColorAttachments, j).dot(Field::imageView),
"must be created with VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT.");
}
}
}
if (rendering_info.pDepthAttachment && (rendering_info.pDepthAttachment->imageView != VK_NULL_HANDLE)) {
auto depth_view_state = Get<vvl::ImageView>(rendering_info.pDepthAttachment->imageView);
if (depth_view_state && !(depth_view_state->image_state->create_info.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT)) {
const LogObjectList objlist(commandBuffer, rendering_info.pDepthAttachment->imageView);
skip |= LogError("VUID-VkRenderingInfo-imageView-06107", objlist,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView),
"must be created with VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT.");
}
}
if (rendering_info.pStencilAttachment && (rendering_info.pStencilAttachment->imageView != VK_NULL_HANDLE)) {
auto stencil_view_state = Get<vvl::ImageView>(rendering_info.pStencilAttachment->imageView);
if (stencil_view_state && !(stencil_view_state->image_state->create_info.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT)) {
const LogObjectList objlist(commandBuffer, rendering_info.pStencilAttachment->imageView);
skip |= LogError("VUID-VkRenderingInfo-imageView-06107", objlist,
rendering_info_loc.dot(Field::pStencilAttachment).dot(Field::imageView),
"must be created with VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT.");
}
}
}
if (fragment_density_map_attachment_info->imageView != VK_NULL_HANDLE) {
const Location view_loc =
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView);
auto fragment_density_map_view_state = Get<vvl::ImageView>(fragment_density_map_attachment_info->imageView);
ASSERT_AND_RETURN_SKIP(fragment_density_map_view_state);
if ((fragment_density_map_view_state->inherited_usage & VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT) == 0) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView,
fragment_density_map_view_state->image_state->Handle());
skip |= LogError("VUID-VkRenderingFragmentDensityMapAttachmentInfoEXT-imageView-06158", objlist, view_loc,
"internal image usage did not include VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT.\n%s",
fragment_density_map_view_state->DescribeImageUsage(*this).c_str());
}
if ((fragment_density_map_view_state->image_state->create_info.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT) > 0) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView,
fragment_density_map_view_state->image_state->Handle());
skip |= LogError("VUID-VkRenderingFragmentDensityMapAttachmentInfoEXT-imageView-06159", objlist, view_loc,
"internal image was created with flags %s.",
string_VkImageCreateFlags(fragment_density_map_view_state->image_state->create_info.flags).c_str());
}
int32_t layer_count = static_cast<int32_t>(fragment_density_map_view_state->normalized_subresource_range.layerCount);
if (layer_count != 1 && !enabled_features.multiview) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView);
skip |= LogError("VUID-VkRenderingFragmentDensityMapAttachmentInfoEXT-apiVersion-07908", objlist, view_loc,
"must have a layer count (%" PRId32 ") equal to 1.", layer_count);
}
if ((rendering_info.viewMask == 0) && (layer_count != 1)) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView);
skip |= LogError("VUID-VkRenderingInfo-imageView-06109", objlist, view_loc,
"must have a layer count (%" PRId32 ") equal to 1 when viewMask is equal to 0", layer_count);
}
if ((rendering_info.viewMask != 0) && (layer_count < MostSignificantBit(rendering_info.viewMask))) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView);
skip |= LogError("VUID-VkRenderingInfo-imageView-06108", objlist, view_loc,
"must have a layer count (%" PRId32
") greater than or equal to the most significant bit in viewMask (0x%" PRIx32 ")",
layer_count, rendering_info.viewMask);
}
const VkComponentMapping components = fragment_density_map_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
const LogObjectList objlist(commandBuffer, fragment_density_map_view_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-imageView-09486", objlist, view_loc,
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
}
const auto *device_group_begin_info = vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(rendering_info.pNext);
const bool non_zero_device_render_area = device_group_begin_info && device_group_begin_info->deviceRenderAreaCount != 0;
if (!non_zero_device_render_area) {
if (fragment_density_map_attachment_info && fragment_density_map_attachment_info->imageView != VK_NULL_HANDLE) {
// Upcasting to handle overflow
const VkRect2D &render_area = rendering_info.renderArea;
const int64_t x_adjusted_extent =
static_cast<int64_t>(render_area.offset.x) + static_cast<int64_t>(render_area.extent.width);
const int64_t y_adjusted_extent =
static_cast<int64_t>(render_area.offset.y) + static_cast<int64_t>(render_area.extent.height);
auto view_state = Get<vvl::ImageView>(fragment_density_map_attachment_info->imageView);
ASSERT_AND_RETURN_SKIP(view_state);
vvl::Image *image_state = view_state->image_state.get();
ASSERT_AND_RETURN_SKIP(image_state);
if (image_state->create_info.extent.width <
vvl::GetQuotientCeil(
x_adjusted_extent,
static_cast<int64_t>(phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.width))) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView, image_state->Handle());
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06112", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView),
"width (%" PRIu32 ") must not be less than (pRenderingInfo->renderArea.offset.x (%" PRId32
") + pRenderingInfo->renderArea.extent.width (%" PRIu32
") ) / VkPhysicalDeviceFragmentDensityMapPropertiesEXT::maxFragmentDensityTexelSize.width (%" PRIu32 ").",
image_state->create_info.extent.width, render_area.offset.x, render_area.extent.width,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.width);
}
if (image_state->create_info.extent.height <
vvl::GetQuotientCeil(
y_adjusted_extent,
static_cast<int64_t>(phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.height))) {
const LogObjectList objlist(commandBuffer, fragment_density_map_attachment_info->imageView, image_state->Handle());
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06114", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView),
"height (%" PRIu32 ") must not be less than (pRenderingInfo->renderArea.offset.y (%" PRId32
") + pRenderingInfo->renderArea.extent.height (%" PRIu32
") ) / VkPhysicalDeviceFragmentDensityMapPropertiesEXT::maxFragmentDensityTexelSize.height (%" PRIu32 ").",
image_state->create_info.extent.height, render_area.offset.y, render_area.extent.height,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.height);
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingFragmentShadingRate(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const auto *rendering_fragment_shading_rate_attachment_info =
vku::FindStructInPNextChain<VkRenderingFragmentShadingRateAttachmentInfoKHR>(rendering_info.pNext);
if (!rendering_fragment_shading_rate_attachment_info ||
rendering_fragment_shading_rate_attachment_info->imageView == VK_NULL_HANDLE) {
return false;
}
auto view_state = Get<vvl::ImageView>(rendering_fragment_shading_rate_attachment_info->imageView);
ASSERT_AND_RETURN_SKIP(view_state);
const LogObjectList objlist(commandBuffer, view_state->Handle());
if (rendering_info.viewMask == 0) {
if (view_state->normalized_subresource_range.layerCount != 1 &&
view_state->normalized_subresource_range.layerCount < rendering_info.layerCount) {
skip |= LogError("VUID-VkRenderingInfo-imageView-06123", objlist, rendering_info_loc.dot(Field::layerCount),
"is (%" PRIu32
") but VkRenderingFragmentShadingRateAttachmentInfoKHR::imageView was created with (%" PRIu32 ").",
rendering_info.layerCount, view_state->normalized_subresource_range.layerCount);
}
} else {
int highest_view_bit = MostSignificantBit(rendering_info.viewMask);
int32_t layer_count = view_state->normalized_subresource_range.layerCount;
if (layer_count != 1 && layer_count < highest_view_bit) {
skip |= LogError("VUID-VkRenderingInfo-imageView-06124", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"has a layerCount (%" PRId32
") but must either is equal to 1 or greater than "
" or equal to the index of the most significant bit (%d) in viewMask (0x%" PRIx32 ")",
layer_count, highest_view_bit, rendering_info.viewMask);
}
}
if ((view_state->inherited_usage & VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR) == 0) {
skip |= LogError("VUID-VkRenderingFragmentShadingRateAttachmentInfoKHR-imageView-06148", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"was not created with VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR.\n%s",
view_state->DescribeImageUsage(*this).c_str());
}
const VkComponentMapping components = view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
skip |= LogError("VUID-VkRenderingInfo-imageView-09485", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
skip |= ValidateBeginRenderingFragmentShadingRateRenderArea(
commandBuffer, *view_state, *rendering_fragment_shading_rate_attachment_info, rendering_info, rendering_info_loc);
return skip;
}
bool CoreChecks::ValidateBeginRenderingFragmentShadingRateRenderArea(
VkCommandBuffer commandBuffer, const vvl::ImageView &view_state,
const VkRenderingFragmentShadingRateAttachmentInfoKHR &fsr_attachment_info, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
// All these VUs can be skipped if all conditions are met
if (enabled_features.maintenance7 && phys_dev_ext_props.maintenance7_props.robustFragmentShadingRateAttachmentAccess &&
view_state.create_info.subresourceRange.baseMipLevel == 0) {
return skip;
}
const LogObjectList objlist(commandBuffer, view_state.Handle());
const auto *device_group_begin_info = vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(rendering_info.pNext);
const bool non_zero_device_render_area = device_group_begin_info && device_group_begin_info->deviceRenderAreaCount != 0;
if (!non_zero_device_render_area) {
const VkRect2D &render_area = rendering_info.renderArea;
// Upcasting to handle overflow
const int64_t x_adjusted_extent =
static_cast<int64_t>(render_area.offset.x) + static_cast<int64_t>(render_area.extent.width);
const int64_t y_adjusted_extent =
static_cast<int64_t>(render_area.offset.y) + static_cast<int64_t>(render_area.extent.height);
if (static_cast<int64_t>(view_state.image_state->create_info.extent.width) <
vvl::GetQuotientCeil(x_adjusted_extent,
static_cast<int64_t>(fsr_attachment_info.shadingRateAttachmentTexelSize.width))) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06119", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"width (%" PRIu32 ") must not be less than (pRenderingInfo->renderArea.offset.x (%" PRId32
") + pRenderingInfo->renderArea.extent.width (%" PRIu32
") ) / shadingRateAttachmentTexelSize.width (%" PRIu32 ").",
view_state.image_state->create_info.extent.width, render_area.offset.x, render_area.extent.width,
fsr_attachment_info.shadingRateAttachmentTexelSize.width);
}
if (static_cast<int64_t>(view_state.image_state->create_info.extent.height) <
vvl::GetQuotientCeil(y_adjusted_extent,
static_cast<int64_t>(fsr_attachment_info.shadingRateAttachmentTexelSize.height))) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06121", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"height (%" PRIu32 ") must not be less than (pRenderingInfo->renderArea.offset.y (%" PRId32
") + pRenderingInfo->renderArea.extent.height (%" PRIu32
") ) / shadingRateAttachmentTexelSize.height (%" PRIu32 ").",
view_state.image_state->create_info.extent.height, render_area.offset.y, render_area.extent.height,
fsr_attachment_info.shadingRateAttachmentTexelSize.height);
}
} else {
if (device_group_begin_info) {
for (uint32_t deviceRenderAreaIndex = 0; deviceRenderAreaIndex < device_group_begin_info->deviceRenderAreaCount;
++deviceRenderAreaIndex) {
const int32_t offset_x = device_group_begin_info->pDeviceRenderAreas[deviceRenderAreaIndex].offset.x;
const uint32_t width = device_group_begin_info->pDeviceRenderAreas[deviceRenderAreaIndex].extent.width;
const int32_t offset_y = device_group_begin_info->pDeviceRenderAreas[deviceRenderAreaIndex].offset.y;
const uint32_t height = device_group_begin_info->pDeviceRenderAreas[deviceRenderAreaIndex].extent.height;
vvl::Image *image_state = view_state.image_state.get();
if (image_state->create_info.extent.width <
vvl::GetQuotientCeil(offset_x + width, fsr_attachment_info.shadingRateAttachmentTexelSize.width)) {
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06120", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"width (%" PRIu32 ") must not be less than (VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].offset.x (%" PRId32 ") + VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].extent.width (%" PRIu32 ") ) / shadingRateAttachmentTexelSize.width (%" PRIu32 ").",
image_state->create_info.extent.width, deviceRenderAreaIndex, offset_x, deviceRenderAreaIndex, width,
fsr_attachment_info.shadingRateAttachmentTexelSize.width);
}
if (image_state->create_info.extent.height <
vvl::GetQuotientCeil(offset_y + height, fsr_attachment_info.shadingRateAttachmentTexelSize.height)) {
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06122", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"height (%" PRIu32 ") must not be less than (VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].offset.y (%" PRId32 ") + VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].extent.height (%" PRIu32
") ) / shadingRateAttachmentTexelSize.height "
"(%" PRIu32 ").",
image_state->create_info.extent.height, deviceRenderAreaIndex, offset_y, deviceRenderAreaIndex, height,
fsr_attachment_info.shadingRateAttachmentTexelSize.height);
}
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingSampleCount(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const VkSampleCountFlagBits unused = VK_SAMPLE_COUNT_FLAG_BITS_MAX_ENUM;
// If the AMD/NV extension are enabled, then we only check color attachments
if (!IsMixSamplingSupported()) {
VkSampleCountFlagBits color_sample_count = unused;
uint32_t first_color_index = 0;
for (uint32_t i = 0; i < rendering_info.colorAttachmentCount; ++i) {
const VkRenderingAttachmentInfo &color_attachment = rendering_info.pColorAttachments[i];
if (color_attachment.imageView == VK_NULL_HANDLE) {
continue;
}
first_color_index = std::min(first_color_index, i);
const auto image_view = Get<vvl::ImageView>(color_attachment.imageView);
ASSERT_AND_CONTINUE(image_view);
color_sample_count = (color_sample_count == unused) ? image_view->samples : color_sample_count;
if (color_sample_count != image_view->samples) {
const LogObjectList objlist(commandBuffer, color_attachment.imageView,
rendering_info.pColorAttachments[first_color_index].imageView);
skip |= LogError("VUID-VkRenderingInfo-multisampledRenderToSingleSampled-06857", objlist,
rendering_info_loc.dot(Field::pColorAttachments, i).dot(Field::imageView),
"was created with %s, but the pColorAttachments[%" PRId32 "]->imageView was created with %s.",
string_VkSampleCountFlagBits(image_view->samples), first_color_index,
string_VkSampleCountFlagBits(color_sample_count));
return skip;
}
}
VkSampleCountFlagBits depth_sample_count = unused;
if (rendering_info.pDepthAttachment && rendering_info.pDepthAttachment->imageView != VK_NULL_HANDLE) {
const auto image_view = Get<vvl::ImageView>(rendering_info.pDepthAttachment->imageView);
ASSERT_AND_RETURN_SKIP(image_view);
depth_sample_count = image_view->samples;
}
VkSampleCountFlagBits stencil_sample_count = unused;
if (rendering_info.pStencilAttachment && rendering_info.pStencilAttachment->imageView != VK_NULL_HANDLE) {
const auto image_view = Get<vvl::ImageView>(rendering_info.pStencilAttachment->imageView);
ASSERT_AND_RETURN_SKIP(image_view);
stencil_sample_count = image_view->samples;
}
// Now we have sample from all 3 (color, depth, stencil), check each combo to produce a helpful message
if (depth_sample_count != stencil_sample_count && depth_sample_count != unused && stencil_sample_count != unused) {
const LogObjectList objlist(commandBuffer, rendering_info.pDepthAttachment->imageView,
rendering_info.pStencilAttachment->imageView);
skip |= LogError("VUID-VkRenderingInfo-multisampledRenderToSingleSampled-06857", objlist,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView),
"was created with %s, but the pStencilAttachment->imageView was created with %s.",
string_VkSampleCountFlagBits(depth_sample_count), string_VkSampleCountFlagBits(stencil_sample_count));
} else if (depth_sample_count != color_sample_count && depth_sample_count != unused && color_sample_count != unused) {
const LogObjectList objlist(commandBuffer, rendering_info.pDepthAttachment->imageView,
rendering_info.pColorAttachments[first_color_index].imageView);
skip |= LogError("VUID-VkRenderingInfo-multisampledRenderToSingleSampled-06857", objlist,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView),
"was created with %s, but the pColorAttachments[%" PRId32 "]->imageView was created with %s.",
string_VkSampleCountFlagBits(depth_sample_count), first_color_index,
string_VkSampleCountFlagBits(color_sample_count));
} else if (stencil_sample_count != color_sample_count && stencil_sample_count != unused && color_sample_count != unused) {
const LogObjectList objlist(commandBuffer, rendering_info.pStencilAttachment->imageView,
rendering_info.pColorAttachments[first_color_index].imageView);
skip |= LogError("VUID-VkRenderingInfo-multisampledRenderToSingleSampled-06857", objlist,
rendering_info_loc.dot(Field::pStencilAttachment).dot(Field::imageView),
"was created with %s, but the pColorAttachments[%" PRId32 "]->imageView was created with %s.",
string_VkSampleCountFlagBits(stencil_sample_count), first_color_index,
string_VkSampleCountFlagBits(color_sample_count));
}
} else if (!enabled_features.multisampledRenderToSingleSampled) {
// If all things are disabled, everything must match
VkSampleCountFlagBits first_sample_count = unused;
for (uint32_t j = 0; j < rendering_info.colorAttachmentCount; ++j) {
const VkRenderingAttachmentInfo &color_attachment = rendering_info.pColorAttachments[j];
if (color_attachment.imageView == VK_NULL_HANDLE) {
continue;
}
const auto image_view = Get<vvl::ImageView>(color_attachment.imageView);
ASSERT_AND_CONTINUE(image_view);
first_sample_count = (first_sample_count == unused) ? image_view->samples : first_sample_count;
if (first_sample_count != image_view->samples) {
const LogObjectList objlist(commandBuffer, color_attachment.imageView);
skip |=
LogError("VUID-VkRenderingInfo-imageView-09429", objlist,
rendering_info_loc.dot(Field::pColorAttachments, j).dot(Field::imageView),
"was created with %s, but pColorAttachments[0].imageView was created with %s.",
string_VkSampleCountFlagBits(image_view->samples), string_VkSampleCountFlagBits(first_sample_count));
}
}
} else if (enabled_features.multisampledRenderToSingleSampled) {
skip |= ValidateBeginRenderingMultisampledRenderToSingleSampled(commandBuffer, rendering_info, rendering_info_loc);
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingDeviceGroup(VkCommandBuffer commandBuffer, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const auto *device_group_begin_info = vku::FindStructInPNextChain<VkDeviceGroupRenderPassBeginInfo>(rendering_info.pNext);
const bool non_zero_device_render_area = device_group_begin_info && device_group_begin_info->deviceRenderAreaCount != 0;
if (!non_zero_device_render_area) {
const VkRect2D &render_area = rendering_info.renderArea;
// if the renderArea was set with garbage, only want to report 1 error
if (render_area.offset.x < 0) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06077", commandBuffer,
rendering_info_loc.dot(Field::renderArea).dot(Field::offset).dot(Field::x),
"is %" PRId32 " (offset can't be negative).", render_area.offset.x);
} else if (render_area.offset.y < 0) {
skip |= LogError("VUID-VkRenderingInfo-pNext-06078", commandBuffer,
rendering_info_loc.dot(Field::renderArea).dot(Field::offset).dot(Field::y),
"is %" PRId32 " (offset can't be negative).", render_area.offset.y);
} else if (render_area.extent.width == 0) {
skip |= LogError("VUID-VkRenderingInfo-None-08994", commandBuffer,
rendering_info_loc.dot(Field::renderArea).dot(Field::extent).dot(Field::width), "is zero.");
} else if (render_area.extent.height == 0) {
skip |= LogError("VUID-VkRenderingInfo-None-08995", commandBuffer,
rendering_info_loc.dot(Field::renderArea).dot(Field::extent).dot(Field::height), "is zero.");
}
// Upcasting to handle overflow
const int64_t x_adjusted_extent =
static_cast<int64_t>(render_area.offset.x) + static_cast<int64_t>(render_area.extent.width);
const int64_t y_adjusted_extent =
static_cast<int64_t>(render_area.offset.y) + static_cast<int64_t>(render_area.extent.height);
if (x_adjusted_extent > phys_dev_props.limits.maxFramebufferWidth) {
skip |= LogError("VUID-VkRenderingInfo-pNext-07815", commandBuffer, rendering_info_loc.dot(Field::renderArea),
"offset.x (%" PRId32 ") + extent.width (%" PRIu32
") is not less than or equal to maxFramebufferWidth (%" PRIu32 ").",
render_area.offset.x, render_area.extent.width, phys_dev_props.limits.maxFramebufferWidth);
}
if (y_adjusted_extent > phys_dev_props.limits.maxFramebufferHeight) {
skip |= LogError("VUID-VkRenderingInfo-pNext-07816", commandBuffer, rendering_info_loc.dot(Field::renderArea),
"offset.y (%" PRId32 ") + extent.height (%" PRIu32
") is not less than or equal to maxFramebufferHeight (%" PRIu32 ").",
render_area.offset.y, render_area.extent.height, phys_dev_props.limits.maxFramebufferHeight);
}
}
if (!device_group_begin_info) return skip;
for (uint32_t dra_i = 0; dra_i < device_group_begin_info->deviceRenderAreaCount; ++dra_i) {
const Location group_loc =
rendering_info_loc.pNext(Struct::VkDeviceGroupRenderPassBeginInfo, Field::pDeviceRenderAreas, dra_i);
const VkRect2D render_area = device_group_begin_info->pDeviceRenderAreas[dra_i];
const int32_t offset_x = render_area.offset.x;
const uint32_t width = render_area.extent.width;
const int32_t offset_y = render_area.offset.y;
const uint32_t height = render_area.extent.height;
if (offset_x < 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06166", commandBuffer,
group_loc.dot(Field::offset).dot(Field::x), "is %" PRId32 " (offset can't be negative).", offset_x);
} else if (offset_y < 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06167", commandBuffer,
group_loc.dot(Field::offset).dot(Field::y), "is %" PRId32 " (offset can't be negative).", offset_y);
} else if (width == 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-extent-08998", commandBuffer,
group_loc.dot(Field::extent).dot(Field::width), "is zero.");
} else if (height == 0) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-extent-08999", commandBuffer,
group_loc.dot(Field::extent).dot(Field::height), "is zero.");
}
if ((offset_x + width) > phys_dev_props.limits.maxFramebufferWidth) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06168", commandBuffer, group_loc,
"sum of offset.x (%" PRId32 ") and extent.width (%" PRIu32
") is greater than maxFramebufferWidth (%" PRIu32 ").",
offset_x, width, phys_dev_props.limits.maxFramebufferWidth);
}
if ((offset_y + height) > phys_dev_props.limits.maxFramebufferHeight) {
skip |= LogError("VUID-VkDeviceGroupRenderPassBeginInfo-offset-06169", commandBuffer, group_loc,
"sum of offset.y (%" PRId32 ") and extent.height (%" PRIu32
") is greater than maxFramebufferHeight (%" PRIu32 ").",
offset_y, height, phys_dev_props.limits.maxFramebufferHeight);
}
for (uint32_t j = 0; j < rendering_info.colorAttachmentCount; ++j) {
if (rendering_info.pColorAttachments[j].imageView == VK_NULL_HANDLE) continue;
auto image_view_state = Get<vvl::ImageView>(rendering_info.pColorAttachments[j].imageView);
ASSERT_AND_CONTINUE(image_view_state);
vvl::Image *image_state = image_view_state->image_state.get();
if (image_state->create_info.extent.width < offset_x + width) {
const LogObjectList objlist(commandBuffer, image_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06083", objlist,
rendering_info_loc.dot(Field::pColorAttachments, j).dot(Field::imageView),
"width (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.x (%" PRId32 ") + renderArea.extent.width (%" PRIu32 ").",
image_state->create_info.extent.width, offset_x, width);
}
if (image_state->create_info.extent.height < offset_y + height) {
const LogObjectList objlist(commandBuffer, image_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06084", objlist,
rendering_info_loc.dot(Field::pColorAttachments, j).dot(Field::imageView),
"height (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.y (%" PRId32 ") + renderArea.extent.height (%" PRIu32 ").",
image_state->create_info.extent.height, offset_y, height);
}
}
if (rendering_info.pDepthAttachment && rendering_info.pDepthAttachment->imageView != VK_NULL_HANDLE) {
auto depth_view_state = Get<vvl::ImageView>(rendering_info.pDepthAttachment->imageView);
ASSERT_AND_RETURN_SKIP(depth_view_state);
vvl::Image *image_state = depth_view_state->image_state.get();
if (image_state->create_info.extent.width < offset_x + width) {
const LogObjectList objlist(commandBuffer, depth_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06083", objlist,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView),
"width (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.x (%" PRId32 ") + renderArea.extent.width (%" PRIu32 ").",
image_state->create_info.extent.width, offset_x, width);
}
if (image_state->create_info.extent.height < offset_y + height) {
const LogObjectList objlist(commandBuffer, depth_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06084", objlist,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView),
"height (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.y (%" PRId32 ") + renderArea.extent.height (%" PRIu32 ").",
image_state->create_info.extent.height, offset_y, height);
}
}
if (rendering_info.pStencilAttachment && rendering_info.pStencilAttachment->imageView != VK_NULL_HANDLE) {
auto stencil_view_state = Get<vvl::ImageView>(rendering_info.pStencilAttachment->imageView);
ASSERT_AND_RETURN_SKIP(stencil_view_state);
vvl::Image *image_state = stencil_view_state->image_state.get();
if (image_state->create_info.extent.width < offset_x + width) {
const LogObjectList objlist(commandBuffer, stencil_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06083", objlist,
rendering_info_loc.dot(Field::pStencilAttachment).dot(Field::imageView),
"width (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.x (%" PRId32 ") + renderArea.extent.width (%" PRIu32 ").",
image_state->create_info.extent.width, offset_x, width);
}
if (image_state->create_info.extent.height < offset_y + height) {
const LogObjectList objlist(commandBuffer, stencil_view_state->Handle(), image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pNext-06084", objlist,
rendering_info_loc.dot(Field::pStencilAttachment).dot(Field::imageView),
"height (%" PRIu32
") must be greater than or equal to"
"renderArea.offset.y (%" PRId32 ") + renderArea.extent.height(%" PRIu32 ").",
image_state->create_info.extent.height, offset_y, height);
}
}
const auto *fragment_density_map_attachment_info =
vku::FindStructInPNextChain<VkRenderingFragmentDensityMapAttachmentInfoEXT>(rendering_info.pNext);
if (fragment_density_map_attachment_info && fragment_density_map_attachment_info->imageView != VK_NULL_HANDLE) {
auto view_state = Get<vvl::ImageView>(fragment_density_map_attachment_info->imageView);
ASSERT_AND_RETURN_SKIP(view_state);
vvl::Image *image_state = view_state->image_state.get();
ASSERT_AND_RETURN_SKIP(image_state);
if (image_state->create_info.extent.width <
vvl::GetQuotientCeil(offset_x + width,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.width)) {
const LogObjectList objlist(commandBuffer, view_state->Handle(), image_state->Handle());
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06113", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView),
"width (%" PRIu32 ") must not be less than (VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].offset.x (%" PRId32 ") + VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].extent.width (%" PRIu32
") ) / VkPhysicalDeviceFragmentDensityMapPropertiesEXT::maxFragmentDensityTexelSize.width (%" PRIu32 ").",
image_state->create_info.extent.width, dra_i, offset_x, dra_i, width,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.width);
}
if (image_state->create_info.extent.height <
vvl::GetQuotientCeil(offset_y + height,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.height)) {
const LogObjectList objlist(commandBuffer, view_state->Handle(), image_state->Handle());
skip |= LogError(
"VUID-VkRenderingInfo-pNext-06115", objlist,
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView),
"height (%" PRIu32 ") must not be less than (VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].offset.y (%" PRId32 ") + VkDeviceGroupRenderPassBeginInfo::pDeviceRenderAreas[%" PRIu32
"].extent.height (%" PRIu32
") ) / VkPhysicalDeviceFragmentDensityMapPropertiesEXT::maxFragmentDensityTexelSize.height (%" PRIu32 ").",
image_state->create_info.extent.height, dra_i, offset_y, dra_i, height,
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.height);
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingMultisampledRenderToSingleSampled(VkCommandBuffer commandBuffer,
const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const auto *msrtss_info = vku::FindStructInPNextChain<VkMultisampledRenderToSingleSampledInfoEXT>(rendering_info.pNext);
if (!msrtss_info) {
return false;
}
for (uint32_t j = 0; j < rendering_info.colorAttachmentCount; ++j) {
if (rendering_info.pColorAttachments[j].imageView != VK_NULL_HANDLE) {
if (const auto image_view_state = Get<vvl::ImageView>(rendering_info.pColorAttachments[j].imageView)) {
skip |= ValidateMultisampledRenderToSingleSampleView(
commandBuffer, *image_view_state, *msrtss_info,
rendering_info_loc.dot(Field::pColorAttachments, j).dot(Field::imageView), rendering_info_loc);
}
}
}
if (rendering_info.pDepthAttachment && rendering_info.pDepthAttachment->imageView != VK_NULL_HANDLE) {
if (const auto depth_view_state = Get<vvl::ImageView>(rendering_info.pDepthAttachment->imageView)) {
skip |= ValidateMultisampledRenderToSingleSampleView(
commandBuffer, *depth_view_state, *msrtss_info,
rendering_info_loc.dot(Field::pDepthAttachment).dot(Field::imageView), rendering_info_loc);
}
}
if (rendering_info.pStencilAttachment && rendering_info.pStencilAttachment->imageView != VK_NULL_HANDLE) {
if (const auto stencil_view_state = Get<vvl::ImageView>(rendering_info.pStencilAttachment->imageView)) {
skip |= ValidateMultisampledRenderToSingleSampleView(
commandBuffer, *stencil_view_state, *msrtss_info,
rendering_info_loc.dot(Field::pStencilAttachment).dot(Field::imageView), rendering_info_loc);
}
}
if (msrtss_info->rasterizationSamples == VK_SAMPLE_COUNT_1_BIT) {
skip |= LogError("VUID-VkMultisampledRenderToSingleSampledInfoEXT-rasterizationSamples-06878", commandBuffer,
rendering_info_loc.pNext(Struct::VkMultisampledRenderToSingleSampledInfoEXT, Field::rasterizationSamples),
"is VK_SAMPLE_COUNT_1_BIT.");
}
return skip;
}
bool CoreChecks::PreCallValidateCmdBeginRendering(VkCommandBuffer commandBuffer, const VkRenderingInfo *pRenderingInfo,
const ErrorObject &error_obj) const {
auto cb_state = GetRead<vvl::CommandBuffer>(commandBuffer);
if (!cb_state) return false;
bool skip = false;
skip |= ValidateCmd(*cb_state, error_obj.location);
const Location rendering_info_loc = error_obj.location.dot(Field::pRenderingInfo);
if (cb_state->IsSecondary() && ((pRenderingInfo->flags & VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT) != 0) &&
!enabled_features.nestedCommandBuffer) {
skip |= LogError("VUID-vkCmdBeginRendering-commandBuffer-06068", commandBuffer, rendering_info_loc.dot(Field::flags),
"must not include VK_RENDERING_CONTENTS_SECONDARY_COMMAND_BUFFERS_BIT in a secondary command buffer.");
}
skip |= ValidateBeginRenderingFragmentDensityMap(commandBuffer, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingFragmentShadingRate(commandBuffer, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingSampleCount(commandBuffer, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingDeviceGroup(commandBuffer, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingColorAttachment(*cb_state, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingDepthAttachment(*cb_state, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingStencilAttachment(*cb_state, *pRenderingInfo, rendering_info_loc);
skip |= ValidateBeginRenderingDepthAndStencilAttachment(commandBuffer, *pRenderingInfo, rendering_info_loc);
if (MostSignificantBit(pRenderingInfo->viewMask) >= static_cast<int32_t>(phys_dev_props_core11.maxMultiviewViewCount)) {
skip |= LogError("VUID-VkRenderingInfo-viewMask-06128", commandBuffer, rendering_info_loc.dot(Field::viewMask),
"(0x%" PRIx32 ") most significant bit must be less than maxMultiviewViewCount (%" PRIu32 ")",
pRenderingInfo->viewMask, phys_dev_props_core11.maxMultiviewViewCount);
}
if (const auto counters_begin_info =
vku::FindStructInPNextChain<VkRenderPassPerformanceCountersByRegionBeginInfoARM>(pRenderingInfo->pNext)) {
const LogObjectList objlist(cb_state->Handle());
uint32_t layer_or_view_count = 0;
if (enabled_features.multiview) {
layer_or_view_count = MostSignificantBit(pRenderingInfo->viewMask);
} else {
layer_or_view_count = pRenderingInfo->layerCount;
}
skip |= ValidateRenderPassPerformanceCountersByRegionBeginInfo(
commandBuffer, *counters_begin_info, objlist, 1u, layer_or_view_count, pRenderingInfo->renderArea, rendering_info_loc);
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingColorAttachment(const vvl::CommandBuffer &cb_state,
const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
const VkCommandBuffer commandBuffer = cb_state.VkHandle();
for (uint32_t i = 0; i < rendering_info.colorAttachmentCount; ++i) {
const VkRenderingAttachmentInfo &color_attachment = rendering_info.pColorAttachments[i];
const Location color_attachment_loc = rendering_info_loc.dot(Field::pColorAttachments, i);
skip |= ValidateRenderingAttachmentInfo(commandBuffer, rendering_info, color_attachment, color_attachment_loc);
skip |= ValidateRenderingAttachmentCurrentLayout(cb_state, color_attachment, VK_IMAGE_ASPECT_COLOR_BIT,
color_attachment_loc, "VUID-vkCmdBeginRendering-pRenderingInfo-09592");
if (color_attachment.imageView != VK_NULL_HANDLE) {
auto image_view_state = Get<vvl::ImageView>(color_attachment.imageView);
ASSERT_AND_CONTINUE(image_view_state);
const vvl::Image &image_state = *image_view_state->image_state;
const LogObjectList objlist(commandBuffer, image_view_state->Handle(), image_state.Handle());
const Location color_image_view = color_attachment_loc.dot(Field::imageView);
if (!(image_view_state->inherited_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
skip |= LogError("VUID-VkRenderingInfo-colorAttachmentCount-06087", objlist, color_image_view,
"must have been created with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.\n%s",
image_view_state->DescribeImageUsage(*this).c_str());
}
const VkComponentMapping components = image_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
skip |= LogError("VUID-VkRenderingInfo-colorAttachmentCount-09479", objlist, color_image_view,
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
if (rendering_info.viewMask == 0 &&
rendering_info.layerCount > image_view_state->normalized_subresource_range.layerCount) {
skip |= LogError("VUID-VkRenderingInfo-viewMask-10859", objlist, color_attachment_loc.dot(Field::layerCount),
"(%" PRIu32 ") is greater than the imageView which was created with a layerCount of %" PRIu32 ".",
rendering_info.layerCount, image_view_state->normalized_subresource_range.layerCount);
}
skip |= ValidateRenderingInfoAttachmentDeviceGroup(image_state, rendering_info, objlist, color_image_view);
}
if (color_attachment.resolveMode == VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID) {
if (!enabled_features.externalFormatResolve) {
skip |= LogError("VUID-VkRenderingAttachmentInfo-externalFormatResolve-09323", commandBuffer,
color_attachment_loc.dot(Field::resolveMode),
"is VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID.");
}
if (rendering_info.colorAttachmentCount != 1) {
skip |= LogError(
"VUID-VkRenderingInfo-colorAttachmentCount-09320", commandBuffer, color_attachment_loc.dot(Field::resolveMode),
"is VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID and colorAttachmentCount is %" PRIu32 ".",
rendering_info.colorAttachmentCount);
break; // only print first index with error
}
const auto *fragment_density_info_ext =
vku::FindStructInPNextChain<VkRenderingFragmentDensityMapAttachmentInfoEXT>(rendering_info.pNext);
if (fragment_density_info_ext && fragment_density_info_ext->imageView != VK_NULL_HANDLE) {
skip |= LogError("VUID-VkRenderingInfo-resolveMode-09321", commandBuffer,
rendering_info_loc.pNext(Struct::VkRenderingFragmentDensityMapAttachmentInfoEXT, Field::imageView),
"is not null (%s).", FormatHandle(fragment_density_info_ext->imageView).c_str());
}
const auto *fragment_shading_rate_info_khr =
vku::FindStructInPNextChain<VkRenderingFragmentShadingRateAttachmentInfoKHR>(rendering_info.pNext);
if (fragment_shading_rate_info_khr && fragment_shading_rate_info_khr->imageView != VK_NULL_HANDLE) {
skip |=
LogError("VUID-VkRenderingInfo-resolveMode-09322", commandBuffer,
rendering_info_loc.pNext(Struct::VkRenderingFragmentShadingRateAttachmentInfoKHR, Field::imageView),
"is not null (%s).", FormatHandle(fragment_shading_rate_info_khr->imageView).c_str());
}
auto resolve_view_state = Get<vvl::ImageView>(color_attachment.resolveImageView);
if (!resolve_view_state) {
skip |= LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09324", commandBuffer,
color_attachment_loc.dot(Field::resolveImageView), "is not valid (%s).",
FormatHandle(color_attachment.resolveImageView).c_str());
} else {
if (device_state->android_external_format_resolve_null_color_attachment_prop &&
resolve_view_state->image_state->create_info.samples != VK_SAMPLE_COUNT_1_BIT) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-nullColorAttachmentWithExternalFormatResolve-09325",
commandBuffer, color_attachment_loc.dot(Field::resolveImageView), "image was created with %s.",
string_VkSampleCountFlagBits(resolve_view_state->image_state->create_info.samples));
}
if (!resolve_view_state->image_state->HasAHBFormat()) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09326", commandBuffer,
color_attachment_loc.dot(Field::resolveImageView), "was not created with an external format.");
}
if (resolve_view_state->create_info.subresourceRange.layerCount != 1) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09327", commandBuffer,
color_attachment_loc.dot(Field::resolveImageView),
"was created with subresourceRange.layerCount of %" PRIu32 ".",
resolve_view_state->create_info.subresourceRange.layerCount);
}
if (rendering_info.viewMask == 0 &&
rendering_info.layerCount > resolve_view_state->normalized_subresource_range.layerCount) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView);
skip |= LogError("VUID-VkRenderingInfo-viewMask-10859", objlist, color_attachment_loc.dot(Field::layerCount),
"(%" PRIu32
") is greater than the resolveImageView which was created with a layerCount of %" PRIu32 ".",
rendering_info.layerCount, resolve_view_state->normalized_subresource_range.layerCount);
}
if (auto color_view_state = Get<vvl::ImageView>(color_attachment.imageView)) {
if (device_state->android_external_format_resolve_null_color_attachment_prop) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView, color_attachment.imageView);
skip |= LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09328", commandBuffer,
color_attachment_loc.dot(Field::imageView), "is not null (%s).",
FormatHandle(color_attachment.imageView).c_str());
} else {
auto it = device_state->ahb_ext_resolve_formats_map.find(resolve_view_state->image_state->ahb_format);
if (it != device_state->ahb_ext_resolve_formats_map.end()) {
if (it->second != color_view_state->create_info.format) {
const LogObjectList objlist(commandBuffer, color_attachment.resolveImageView,
color_attachment.imageView);
skip |=
LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09330", commandBuffer,
color_attachment_loc.dot(Field::imageView),
"has externalFormat %" PRIu64
" which corresponds to needing a color attachment format of %s, but the format is %s.",
resolve_view_state->image_state->ahb_format, string_VkFormat(it->second),
string_VkFormat(color_view_state->create_info.format));
}
}
}
} else if (!device_state->android_external_format_resolve_null_color_attachment_prop) {
skip |= LogError("VUID-VkRenderingAttachmentInfo-resolveMode-09329", commandBuffer,
color_attachment_loc.dot(Field::imageView), "is not valid.");
}
}
}
if (color_attachment.resolveMode != VK_RESOLVE_MODE_NONE) {
if (auto resolve_view_state = Get<vvl::ImageView>(color_attachment.resolveImageView)) {
const VkComponentMapping components = resolve_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
const LogObjectList objlist(commandBuffer, resolve_view_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-colorAttachmentCount-09480", objlist,
color_attachment_loc.dot(Field::resolveImageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
const VkImageUsageFlags image_usage = resolve_view_state->image_state->create_info.usage;
if ((image_usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) == 0) {
const LogObjectList objlist(commandBuffer, resolve_view_state->Handle(),
resolve_view_state->image_state->Handle());
skip |= LogError(
"VUID-VkRenderingInfo-colorAttachmentCount-09476", objlist,
color_attachment_loc.dot(Field::resolveImageView), "image was created with %s (resolveMode is %s).",
string_VkImageUsageFlags(image_usage).c_str(), string_VkResolveModeFlagBits(color_attachment.resolveMode));
}
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingDepthAttachment(const vvl::CommandBuffer &cb_state, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
if (!rendering_info.pDepthAttachment) return skip;
const VkCommandBuffer commandBuffer = cb_state.VkHandle();
const VkRenderingAttachmentInfo &depth_attachment = *rendering_info.pDepthAttachment;
const Location depth_attachment_loc = rendering_info_loc.dot(Field::pDepthAttachment);
skip |= ValidateRenderingAttachmentInfo(commandBuffer, rendering_info, depth_attachment, depth_attachment_loc);
skip |= ValidateRenderingAttachmentCurrentLayout(cb_state, depth_attachment, VK_IMAGE_ASPECT_DEPTH_BIT, depth_attachment_loc,
"VUID-vkCmdBeginRendering-pRenderingInfo-09588");
if (depth_attachment.imageView != VK_NULL_HANDLE) {
auto depth_view_state = Get<vvl::ImageView>(depth_attachment.imageView);
ASSERT_AND_RETURN_SKIP(depth_view_state);
const vvl::Image &image_state = *depth_view_state->image_state;
const LogObjectList objlist(commandBuffer, depth_view_state->Handle(), image_state.Handle());
const Location depth_image_view = depth_attachment_loc.dot(Field::imageView);
if (!(depth_view_state->inherited_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-06088", objlist, depth_attachment_loc.dot(Field::imageView),
"internal image must have been created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT.\n%s",
depth_view_state->DescribeImageUsage(*this).c_str());
}
if (!vkuFormatHasDepth(depth_view_state->create_info.format)) {
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-06547", objlist, depth_attachment_loc.dot(Field::imageView),
"was created with a format (%s) that does not have a depth aspect.",
string_VkFormat(depth_view_state->create_info.format));
}
const VkComponentMapping components = depth_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-09481", objlist, depth_attachment_loc.dot(Field::imageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
if (rendering_info.viewMask == 0 && rendering_info.layerCount > depth_view_state->normalized_subresource_range.layerCount) {
skip |= LogError("VUID-VkRenderingInfo-viewMask-10860", objlist, depth_attachment_loc.dot(Field::layerCount),
"(%" PRIu32 ") is greater than the imageView which was created with a layerCount of %" PRIu32 ".",
rendering_info.layerCount, depth_view_state->normalized_subresource_range.layerCount);
}
skip |= ValidateRenderingInfoAttachmentDeviceGroup(image_state, rendering_info, objlist, depth_image_view);
}
if (depth_attachment.resolveMode != VK_RESOLVE_MODE_NONE) {
if (depth_attachment.resolveMode == VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID) {
skip |=
LogError("VUID-VkRenderingInfo-pDepthAttachment-09318", commandBuffer, depth_attachment_loc.dot(Field::resolveMode),
"is VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID.");
}
if (auto depth_resolve_view_state = Get<vvl::ImageView>(depth_attachment.resolveImageView)) {
const VkComponentMapping components = depth_resolve_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
const LogObjectList objlist(commandBuffer, depth_resolve_view_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-09482", objlist,
depth_attachment_loc.dot(Field::resolveImageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
const VkImageUsageFlags image_usage = depth_resolve_view_state->image_state->create_info.usage;
if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
const LogObjectList objlist(commandBuffer, depth_resolve_view_state->Handle(),
depth_resolve_view_state->image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-09477", objlist,
depth_attachment_loc.dot(Field::resolveImageView),
"image was created with %s (resolveMode is %s).", string_VkImageUsageFlags(image_usage).c_str(),
string_VkResolveModeFlagBits(depth_attachment.resolveMode));
}
if (rendering_info.viewMask == 0 &&
rendering_info.layerCount > depth_resolve_view_state->normalized_subresource_range.layerCount) {
const LogObjectList objlist(commandBuffer, depth_resolve_view_state->Handle());
skip |=
LogError("VUID-VkRenderingInfo-viewMask-10860", objlist, depth_attachment_loc.dot(Field::layerCount),
"(%" PRIu32 ") is greater than the resolveImageView which was created with a layerCount of %" PRIu32
" (resolveMode is %s).",
rendering_info.layerCount, depth_resolve_view_state->normalized_subresource_range.layerCount,
string_VkResolveModeFlagBits(depth_attachment.resolveMode));
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingStencilAttachment(const vvl::CommandBuffer &cb_state, const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
if (!rendering_info.pStencilAttachment) return skip;
const VkCommandBuffer commandBuffer = cb_state.VkHandle();
const VkRenderingAttachmentInfo &stencil_attachment = *rendering_info.pStencilAttachment;
const Location stencil_attachment_loc = rendering_info_loc.dot(Field::pStencilAttachment);
skip |= ValidateRenderingAttachmentInfo(commandBuffer, rendering_info, stencil_attachment, stencil_attachment_loc);
skip |= ValidateRenderingAttachmentCurrentLayout(cb_state, stencil_attachment, VK_IMAGE_ASPECT_STENCIL_BIT,
stencil_attachment_loc, "VUID-vkCmdBeginRendering-pRenderingInfo-09590");
if (stencil_attachment.imageView != VK_NULL_HANDLE) {
auto stencil_view_state = Get<vvl::ImageView>(stencil_attachment.imageView);
ASSERT_AND_RETURN_SKIP(stencil_view_state);
const vvl::Image &image_state = *stencil_view_state->image_state;
const LogObjectList objlist(commandBuffer, stencil_view_state->Handle(), image_state.Handle());
const Location stencil_image_view = stencil_attachment_loc.dot(Field::imageView);
if (!(stencil_view_state->inherited_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-06089", objlist, stencil_attachment_loc.dot(Field::imageView),
"internal image must have been created with VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT.\n%s",
stencil_view_state->DescribeImageUsage(*this).c_str());
}
if (!vkuFormatHasStencil(stencil_view_state->create_info.format)) {
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-06548", objlist, stencil_attachment_loc.dot(Field::imageView),
"was created with a format (%s) that does not have a stencil aspect.",
string_VkFormat(stencil_view_state->create_info.format));
}
const VkComponentMapping components = stencil_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-09483", objlist, stencil_attachment_loc.dot(Field::imageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
if (rendering_info.viewMask == 0 &&
rendering_info.layerCount > stencil_view_state->normalized_subresource_range.layerCount) {
skip |= LogError("VUID-VkRenderingInfo-viewMask-10861", objlist, stencil_attachment_loc.dot(Field::layerCount),
"(%" PRIu32 ") is greater than the imageView which was created with a layerCount of %" PRIu32 ".",
rendering_info.layerCount, stencil_view_state->normalized_subresource_range.layerCount);
}
skip |= ValidateRenderingInfoAttachmentDeviceGroup(image_state, rendering_info, objlist, stencil_image_view);
}
if (stencil_attachment.resolveMode != VK_RESOLVE_MODE_NONE) {
if (stencil_attachment.resolveMode == VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID) {
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-09319", commandBuffer,
stencil_attachment_loc.dot(Field::resolveMode),
"is VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID.");
}
if (auto stencil_resolve_view_state = Get<vvl::ImageView>(stencil_attachment.resolveImageView)) {
const VkComponentMapping components = stencil_resolve_view_state->create_info.components;
if (!IsIdentitySwizzle(components)) {
const LogObjectList objlist(commandBuffer, stencil_resolve_view_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-09484", objlist,
stencil_attachment_loc.dot(Field::resolveImageView),
"has a non-identiy swizzle component, here are the actual swizzle values:\n%s",
string_VkComponentMapping(components).c_str());
}
const VkImageUsageFlags image_usage = stencil_resolve_view_state->image_state->create_info.usage;
if ((image_usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
const LogObjectList objlist(commandBuffer, stencil_resolve_view_state->Handle(),
stencil_resolve_view_state->image_state->Handle());
skip |= LogError("VUID-VkRenderingInfo-pStencilAttachment-09478", objlist,
stencil_attachment_loc.dot(Field::resolveImageView),
"image was created with %s (resolveMode is %s).", string_VkImageUsageFlags(image_usage).c_str(),
string_VkResolveModeFlagBits(stencil_attachment.resolveMode));
}
if (rendering_info.viewMask == 0 &&
rendering_info.layerCount > stencil_resolve_view_state->normalized_subresource_range.layerCount) {
const LogObjectList objlist(commandBuffer, stencil_resolve_view_state->Handle());
skip |=
LogError("VUID-VkRenderingInfo-viewMask-10861", objlist, stencil_attachment_loc.dot(Field::layerCount),
"(%" PRIu32 ") is greater than the resolveImageView which was created with a layerCount of %" PRIu32
" (resolveMode is %s).",
rendering_info.layerCount, stencil_resolve_view_state->normalized_subresource_range.layerCount,
string_VkResolveModeFlagBits(stencil_attachment.resolveMode));
}
}
}
return skip;
}
bool CoreChecks::ValidateBeginRenderingDepthAndStencilAttachment(VkCommandBuffer commandBuffer,
const VkRenderingInfo &rendering_info,
const Location &rendering_info_loc) const {
bool skip = false;
if (!rendering_info.pDepthAttachment || !rendering_info.pStencilAttachment) return skip;
const auto &depth_attachment = *rendering_info.pDepthAttachment;
const auto &stencil_attachment = *rendering_info.pStencilAttachment;
if (depth_attachment.imageView != VK_NULL_HANDLE && stencil_attachment.imageView != VK_NULL_HANDLE) {
if (depth_attachment.imageView != stencil_attachment.imageView) {
const LogObjectList objlist(commandBuffer, depth_attachment.imageView, stencil_attachment.imageView);
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-06085", objlist, rendering_info_loc,
"imageView of pDepthAttachment and pStencilAttachment must be the same.");
}
if ((phys_dev_props_core12.independentResolveNone == VK_FALSE) &&
(depth_attachment.resolveMode != stencil_attachment.resolveMode)) {
const LogObjectList objlist(commandBuffer, depth_attachment.imageView, stencil_attachment.imageView);
skip |=
LogError("VUID-VkRenderingInfo-pDepthAttachment-06104", objlist, rendering_info_loc,
"values of pDepthAttachment->resolveMode (%s) and pStencilAttachment->resolveMode (%s) must be identical.",
string_VkResolveModeFlagBits(depth_attachment.resolveMode),
string_VkResolveModeFlagBits(stencil_attachment.resolveMode));
}
if ((phys_dev_props_core12.independentResolve == VK_FALSE) && (depth_attachment.resolveMode != VK_RESOLVE_MODE_NONE) &&
(stencil_attachment.resolveMode != VK_RESOLVE_MODE_NONE) &&
(stencil_attachment.resolveMode != depth_attachment.resolveMode)) {
const LogObjectList objlist(commandBuffer, depth_attachment.imageView, stencil_attachment.imageView);
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-06105", objlist, rendering_info_loc,
"values of pDepthAttachment->resolveMode (%s) and pStencilAttachment->resolveMode (%s) must "
"be identical, or one of them must be VK_RESOLVE_MODE_NONE.",
string_VkResolveModeFlagBits(depth_attachment.resolveMode),
string_VkResolveModeFlagBits(stencil_attachment.resolveMode));
}
}
if (depth_attachment.resolveMode != VK_RESOLVE_MODE_NONE && stencil_attachment.resolveMode != VK_RESOLVE_MODE_NONE) {
if (depth_attachment.resolveImageView != stencil_attachment.resolveImageView) {
const LogObjectList objlist(commandBuffer, depth_attachment.resolveImageView, stencil_attachment.resolveImageView);
skip |= LogError("VUID-VkRenderingInfo-pDepthAttachment-06086", objlist, rendering_info_loc,
"resolveImageView of pDepthAttachment and pStencilAttachment must be the same.\ndepth resolveMode is "
"%s and stencil resolveMode is %s",
string_VkResolveModeFlagBits(depth_attachment.resolveMode),
string_VkResolveModeFlagBits(stencil_attachment.resolveMode));
}
}
return skip;
}
// Flags validation error if the associated call is made inside a render pass. The apiName routine should ONLY be called outside a
// render pass.
bool CoreChecks::InsideRenderPass(const vvl::CommandBuffer &cb_state, const Location &loc, const char *vuid) const {
bool skip = false;
if (cb_state.active_render_pass) {
if (cb_state.active_render_pass->use_dynamic_rendering) {
skip |=
LogError(vuid, cb_state.Handle(), loc,
"It is invalid to issue this call inside an active render pass instance begun with vkCmdBeginRendering.");
} else if (cb_state.active_render_pass->use_dynamic_rendering_inherited) {
skip |=
LogError(vuid, cb_state.Handle(), loc,
"It is invalid to issue this call inside this secondary command buffer as it was begun with "
"VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT and viewed as being inside a render pass instance begun "
"with vkCmdBeginRendering.");
} else {
skip |= LogError(vuid, cb_state.Handle(), loc, "It is invalid to issue this call inside an active %s.",
FormatHandle(cb_state.active_render_pass->Handle()).c_str());
}
}
return skip;
}
// Flags validation error if the associated call is made outside a render pass. The apiName
// routine should ONLY be called inside a render pass.
bool CoreChecks::OutsideRenderPass(const vvl::CommandBuffer &cb_state, const Location &loc, const char *vuid) const {
bool outside = false;
if ((cb_state.IsPrimary() && (!cb_state.active_render_pass)) ||
(cb_state.IsSecondary() && (!cb_state.active_render_pass) &&
!(cb_state.begin_info_flags & VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT))) {
outside = LogError(vuid, cb_state.Handle(), loc, "This call must be issued inside an active render pass.");
}
return outside;
}
bool CoreChecks::ValidateCmdEndRendering(const vvl::CommandBuffer& cb_state, const ErrorObject &error_obj) const {
bool skip = false;
skip |= ValidateCmd(cb_state, error_obj.location);
if (!cb_state.active_render_pass) {
return skip;
}
const bool is_2 =
error_obj.location.function != Func::vkCmdEndRendering && error_obj.location.function != Func::vkCmdEndRenderingKHR;
if (!cb_state.active_render_pass->UsesDynamicRendering()) {
const char *vuid = is_2 ? "VUID-vkCmdEndRendering2KHR-None-10610" : "VUID-vkCmdEndRendering-None-06161";
skip |= LogError(vuid, cb_state.Handle(), error_obj.location,
"in a render pass instance that was not begun with vkCmdBeginRendering().");
}
if (cb_state.active_render_pass->use_dynamic_rendering_inherited) {
const char *vuid = is_2 ? "VUID-vkCmdEndRendering2KHR-commandBuffer-10611" : "VUID-vkCmdEndRendering-commandBuffer-06162";
skip |= LogError(vuid, cb_state.Handle(), error_obj.location,
"in a render pass instance that was not begun in this command buffer.");
}
if (cb_state.transform_feedback_active) {
const char *vuid = is_2 ? "VUID-vkCmdEndRendering2KHR-None-10612" : "VUID-vkCmdEndRendering-None-06781";
skip |= LogError(vuid, cb_state.Handle(), error_obj.location,
"in a render pass instance that was not begun in this command buffer.");
}
for (const auto &query : cb_state.render_pass_queries) {
const LogObjectList objlist(cb_state.Handle(), query.pool);
const char *vuid = is_2 ? "VUID-vkCmdEndRendering2KHR-None-10613" : "VUID-vkCmdEndRendering-None-06999";
skip |=
LogError(vuid, objlist, error_obj.location, "query %" PRIu32 " from %s was began in the render pass, but never ended.",
query.slot, FormatHandle(query.pool).c_str());
}
return skip;
}
bool CoreChecks::PreCallValidateCmdEndRendering(VkCommandBuffer commandBuffer, const ErrorObject &error_obj) const {
const auto& cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
return ValidateCmdEndRendering(cb_state, error_obj);
}
bool CoreChecks::PreCallValidateCmdEndRendering2KHR(VkCommandBuffer commandBuffer, const VkRenderingEndInfoKHR *pRenderingEndInfo,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
skip |= ValidateCmdEndRendering(cb_state, error_obj);
const auto *rp_state_ptr = cb_state.active_render_pass.get();
if (!rp_state_ptr || !pRenderingEndInfo) {
return skip;
}
if (const auto *fdm_offset_end_info =
vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapOffsetEndInfoEXT>(pRenderingEndInfo->pNext)) {
if (fdm_offset_end_info->fragmentDensityOffsetCount != 0) {
skip |= ValidateFragmentDensityMapOffsetEnd(
cb_state, *rp_state_ptr, *fdm_offset_end_info,
error_obj.location.dot(Field::pRenderingEndInfo).pNext(Struct::VkRenderPassFragmentDensityMapOffsetEndInfoEXT));
}
const auto &cb_sub_state = core::SubState(cb_state);
const uint32_t previous_count = static_cast<uint32_t>(cb_sub_state.fragment_density_offsets.size());
if (previous_count > 0) {
if (fdm_offset_end_info->fragmentDensityOffsetCount != previous_count) {
skip |=
LogError("VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pFragmentDensityOffsets-10730", commandBuffer,
error_obj.location.dot(Field::pRenderingEndInfo)
.pNext(Struct::VkRenderPassFragmentDensityMapOffsetEndInfoEXT, Field::fragmentDensityOffsetCount),
"%" PRIu32 " does not match previous fragmentDensityOffsetCount (%" PRIu32 ") used in the render pass",
fdm_offset_end_info->fragmentDensityOffsetCount, previous_count);
} else {
for (uint32_t i = 0; i < fdm_offset_end_info->fragmentDensityOffsetCount; ++i) {
if (fdm_offset_end_info->pFragmentDensityOffsets[i].x != cb_sub_state.fragment_density_offsets[i].x ||
fdm_offset_end_info->pFragmentDensityOffsets[i].y != cb_sub_state.fragment_density_offsets[i].y) {
skip |= LogError(
"VUID-VkRenderPassFragmentDensityMapOffsetEndInfoEXT-pFragmentDensityOffsets-10730", commandBuffer,
error_obj.location.dot(Field::pRenderingEndInfo)
.pNext(Struct::VkRenderPassFragmentDensityMapOffsetEndInfoEXT, Field::pFragmentDensityOffsets, i),
"is (%s) which does not match previous fragmentDensityOffsetCount[%" PRIu32
"] used in the render pass (%s)",
string_VkOffset2D(fdm_offset_end_info->pFragmentDensityOffsets[i]).c_str(), i,
string_VkOffset2D(cb_sub_state.fragment_density_offsets[i]).c_str());
break;
}
}
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdEndRendering2EXT(VkCommandBuffer commandBuffer, const VkRenderingEndInfoEXT *pRenderingEndInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdEndRendering2KHR(commandBuffer, pRenderingEndInfo, error_obj);
}
bool CoreChecks::PreCallValidateCmdEndRenderingKHR(VkCommandBuffer commandBuffer, const ErrorObject &error_obj) const {
return PreCallValidateCmdEndRendering(commandBuffer, error_obj);
}
bool CoreChecks::ValidateMultisampledRenderToSingleSampleView(VkCommandBuffer commandBuffer, const vvl::ImageView &image_view_state,
const VkMultisampledRenderToSingleSampledInfoEXT &msrtss_info,
const Location &attachment_loc,
const Location &rendering_info_loc) const {
bool skip = false;
if (!msrtss_info.multisampledRenderToSingleSampledEnable) {
return false;
}
if ((image_view_state.samples != VK_SAMPLE_COUNT_1_BIT) && (image_view_state.samples != msrtss_info.rasterizationSamples)) {
const LogObjectList objlist(commandBuffer, image_view_state.Handle());
skip |= LogError("VUID-VkRenderingInfo-imageView-06858", objlist,
rendering_info_loc.pNext(Struct::VkMultisampledRenderToSingleSampledInfoEXT,
Field::multisampledRenderToSingleSampledEnable),
"is %s, but %s was created with %s, which is not VK_SAMPLE_COUNT_1_BIT.",
string_VkSampleCountFlagBits(msrtss_info.rasterizationSamples), attachment_loc.Fields().c_str(),
string_VkSampleCountFlagBits(image_view_state.samples));
}
vvl::Image *image_state = image_view_state.image_state.get();
if ((image_view_state.samples == VK_SAMPLE_COUNT_1_BIT) &&
!(image_state->create_info.flags & VK_IMAGE_CREATE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_BIT_EXT)) {
const LogObjectList objlist(commandBuffer, image_view_state.Handle());
skip |= LogError("VUID-VkRenderingInfo-imageView-06859", objlist, attachment_loc,
"was created with VK_SAMPLE_COUNT_1_BIT but "
"VK_IMAGE_CREATE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_BIT_EXT was not set in "
"pImageCreateInfo.flags when the image used to create the imageView (%s) was created",
FormatHandle(image_state->Handle()).c_str());
}
if (!image_state->image_format_properties.sampleCounts) {
if (GetPhysicalDeviceImageFormatProperties(*image_state, "VUID-VkMultisampledRenderToSingleSampledInfoEXT-pNext-06880",
attachment_loc))
return true;
}
if (!(image_state->image_format_properties.sampleCounts & msrtss_info.rasterizationSamples)) {
const LogObjectList objlist(commandBuffer, image_view_state.Handle());
skip |= LogError(
"VUID-VkMultisampledRenderToSingleSampledInfoEXT-pNext-06880", objlist,
rendering_info_loc.pNext(Struct::VkMultisampledRenderToSingleSampledInfoEXT, Field::rasterizationSamples),
"is %s, but %s format %s does not support sample count %s from an image with imageType: %s, tiling: "
"%s, usage: %s, flags: %s.",
string_VkSampleCountFlagBits(msrtss_info.rasterizationSamples), attachment_loc.Fields().c_str(),
string_VkFormat(image_view_state.create_info.format), string_VkSampleCountFlagBits(msrtss_info.rasterizationSamples),
string_VkImageType(image_state->create_info.imageType), string_VkImageTiling(image_state->create_info.tiling),
string_VkImageUsageFlags(image_state->create_info.usage).c_str(),
string_VkImageCreateFlags(image_state->create_info.flags).c_str());
}
return skip;
}
bool CoreChecks::PreCallValidateCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, const VkRenderingInfoKHR *pRenderingInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdBeginRendering(commandBuffer, pRenderingInfo, error_obj);
}
// If a renderpass is active, verify that the given command type is appropriate for current subpass state
bool CoreChecks::ValidateCmdSubpassState(const vvl::CommandBuffer &cb_state, const Location &loc, const char *vuid) const {
if (!cb_state.active_render_pass || cb_state.active_render_pass->UsesDynamicRendering()) return false;
bool skip = false;
if (cb_state.IsPrimary() && cb_state.active_subpass_contents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS &&
!IsValueIn(loc.function,
{Func::vkCmdExecuteCommands, Func::vkCmdNextSubpass, Func::vkCmdEndRenderPass, Func::vkCmdNextSubpass2,
Func::vkCmdNextSubpass2KHR, Func::vkCmdEndRenderPass2, Func::vkCmdEndRenderPass2KHR})) {
skip |=
LogError(vuid, cb_state.Handle(), loc,
"cannot be called on this primary command buffer because vkCmdBeginRenderPass was called with "
"VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS.\nOnly vkCmdExecuteCommands is allowed in the first subpass "
"until vkCmdNextSubpass or vkCmdEndRenderPass is called.");
}
return skip;
}
bool CoreChecks::ValidateCmdNextSubpass(VkCommandBuffer commandBuffer, const ErrorObject &error_obj) const {
auto cb_state = GetRead<vvl::CommandBuffer>(commandBuffer);
bool skip = false;
const bool use_rp2 = error_obj.location.function != Func::vkCmdNextSubpass;
const char *vuid;
skip |= ValidateCmd(*cb_state, error_obj.location);
if (!cb_state->active_render_pass) {
return skip;
}
auto subpass_count = cb_state->active_render_pass->create_info.subpassCount;
if (cb_state->GetActiveSubpass() == subpass_count - 1) {
vuid = use_rp2 ? "VUID-vkCmdNextSubpass2-None-03102" : "VUID-vkCmdNextSubpass-None-00909";
skip |= LogError(vuid, commandBuffer, error_obj.location, "Attempted to advance beyond final subpass.");
}
if (cb_state->transform_feedback_active) {
vuid = use_rp2 ? "VUID-vkCmdNextSubpass2-None-02350" : "VUID-vkCmdNextSubpass-None-02349";
skip |= LogError(vuid, commandBuffer, error_obj.location, "transform feedback is active.");
}
return skip;
}
bool CoreChecks::PreCallValidateCmdNextSubpass(VkCommandBuffer commandBuffer, VkSubpassContents contents,
const ErrorObject &error_obj) const {
return ValidateCmdNextSubpass(commandBuffer, error_obj);
}
bool CoreChecks::PreCallValidateCmdNextSubpass2KHR(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo,
const VkSubpassEndInfo *pSubpassEndInfo, const ErrorObject &error_obj) const {
return PreCallValidateCmdNextSubpass2(commandBuffer, pSubpassBeginInfo, pSubpassEndInfo, error_obj);
}
bool CoreChecks::PreCallValidateCmdNextSubpass2(VkCommandBuffer commandBuffer, const VkSubpassBeginInfo *pSubpassBeginInfo,
const VkSubpassEndInfo *pSubpassEndInfo, const ErrorObject &error_obj) const {
return ValidateCmdNextSubpass(commandBuffer, error_obj);
}
bool CoreChecks::MatchUsage(uint32_t count, const VkAttachmentReference2 *attachments, const VkFramebufferCreateInfo &fbci,
VkImageUsageFlagBits usage_flag, const char *vuid, const Location &create_info_loc) const {
bool skip = false;
if (!attachments) {
return false;
}
for (uint32_t attach = 0; attach < count; attach++) {
const uint32_t fb_attachment = attachments[attach].attachment;
// Attachment counts are verified elsewhere, but prevent an invalid access
if (fb_attachment == VK_ATTACHMENT_UNUSED || fb_attachment >= fbci.attachmentCount) {
continue;
}
if ((fbci.flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
const VkImageView *image_view = &fbci.pAttachments[fb_attachment];
if (auto view_state = Get<vvl::ImageView>(*image_view)) {
const auto &ici = view_state->image_state->create_info;
auto creation_usage = ici.usage;
const auto stencil_usage_info = vku::FindStructInPNextChain<VkImageStencilUsageCreateInfo>(ici.pNext);
if (stencil_usage_info) {
creation_usage |= stencil_usage_info->stencilUsage;
}
if ((creation_usage & usage_flag) == 0) {
skip |= LogError(vuid, device, create_info_loc.dot(Field::pAttachments, fb_attachment),
"expected usage (%s) conflicts with the image's flags (%s).",
string_VkImageUsageFlagBits(usage_flag), string_VkImageUsageFlags(creation_usage).c_str());
}
}
} else {
const VkFramebufferAttachmentsCreateInfo *fbaci =
vku::FindStructInPNextChain<VkFramebufferAttachmentsCreateInfo>(fbci.pNext);
if (fbaci != nullptr && fbaci->pAttachmentImageInfos != nullptr && fbaci->attachmentImageInfoCount > fb_attachment) {
uint32_t image_usage = fbaci->pAttachmentImageInfos[fb_attachment].usage;
if ((image_usage & usage_flag) == 0) {
skip |= LogError(vuid, device, create_info_loc.dot(Field::pAttachments, fb_attachment),
"expected usage (%s) conflicts with the image's flags (%s).",
string_VkImageUsageFlagBits(usage_flag), string_VkImageUsageFlags(image_usage).c_str());
}
}
}
}
return skip;
}
bool CoreChecks::MsRenderedToSingleSampledValidateFBAttachments(uint32_t count, const VkAttachmentReference2 *attachments,
const VkFramebufferCreateInfo &fbci,
const VkRenderPassCreateInfo2 &rpci, uint32_t subpass,
VkSampleCountFlagBits sample_count,
const Location &create_info_loc) const {
bool skip = false;
for (uint32_t attach = 0; attach < count; attach++) {
const uint32_t fb_attachment = attachments[attach].attachment;
if (fb_attachment == VK_ATTACHMENT_UNUSED || fb_attachment >= fbci.attachmentCount) {
continue;
}
const auto renderpass_samples = rpci.pAttachments[fb_attachment].samples;
if (renderpass_samples == VK_SAMPLE_COUNT_1_BIT) {
const VkImageView *image_view = &fbci.pAttachments[fb_attachment];
auto view_state = Get<vvl::ImageView>(*image_view);
ASSERT_AND_CONTINUE(view_state);
auto image_state = view_state->image_state;
if (!(image_state->create_info.flags & VK_IMAGE_CREATE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_BIT_EXT)) {
skip |= LogError("VUID-VkFramebufferCreateInfo-samples-06881", device, create_info_loc,
"Renderpass subpass %" PRIu32
" enables "
"multisampled-render-to-single-sampled and attachment %" PRIu32
", is specified from with "
"VK_SAMPLE_COUNT_1_BIT samples, but image (%s) was created without "
"VK_IMAGE_CREATE_MULTISAMPLED_RENDER_TO_SINGLE_SAMPLED_BIT_EXT in its pCreateInfo->flags.",
subpass, fb_attachment, FormatHandle(*image_state).c_str());
}
const VkImageCreateInfo image_create_info = image_state->create_info;
if (!image_state->image_format_properties.sampleCounts) {
skip |= GetPhysicalDeviceImageFormatProperties(*image_state.get(), "VUID-VkFramebufferCreateInfo-samples-07009",
create_info_loc);
}
if (!(image_state->image_format_properties.sampleCounts & sample_count)) {
skip |= LogError(
"VUID-VkFramebufferCreateInfo-samples-07009", device, create_info_loc,
"Renderpass subpass %" PRIu32 " enables multisampled-render-to-single-sampled and attachment %" PRIu32
", is specified from with VK_SAMPLE_COUNT_1_BIT samples, but %s was created with\n%s"
"which does not support a rasterizationSamples count of %s",
subpass, fb_attachment, FormatHandle(*image_state).c_str(),
string_VkPhysicalDeviceImageFormatInfo2(image_create_info).c_str(), string_VkSampleCountFlagBits(sample_count));
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateCreateFramebuffer(VkDevice device, const VkFramebufferCreateInfo *pCreateInfo,
const VkAllocationCallbacks *pAllocator, VkFramebuffer *pFramebuffer,
const ErrorObject &error_obj) const {
// TODO : Verify that renderPass FB is created with is compatible with FB
bool skip = false;
skip |= ValidateDeviceQueueSupport(error_obj.location);
const Location create_info_loc = error_obj.location.dot(Field::pCreateInfo);
auto rp_state = Get<vvl::RenderPass>(pCreateInfo->renderPass);
ASSERT_AND_RETURN_SKIP(rp_state);
const VkRenderPassCreateInfo2 *rpci = rp_state->create_info.ptr();
if (rpci->attachmentCount != pCreateInfo->attachmentCount) {
skip |= LogError("VUID-VkFramebufferCreateInfo-attachmentCount-00876", pCreateInfo->renderPass,
create_info_loc.dot(Field::attachmentCount),
"%" PRIu32 " does not match attachmentCount of %" PRIu32 " of %s being used to create Framebuffer.",
pCreateInfo->attachmentCount, rpci->attachmentCount, FormatHandle(pCreateInfo->renderPass).c_str());
return skip; // nothing else to validate
}
const auto *framebuffer_attachments_create_info =
vku::FindStructInPNextChain<VkFramebufferAttachmentsCreateInfo>(pCreateInfo->pNext);
if (framebuffer_attachments_create_info) {
for (const auto [i, attachment_image_info] :
vvl::enumerate(framebuffer_attachments_create_info->pAttachmentImageInfos,
framebuffer_attachments_create_info->attachmentImageInfoCount)) {
const Location attachment_image_info_loc =
create_info_loc.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos, i);
if (attachment_image_info.pNext != nullptr) {
skip |= LogError("VUID-VkFramebufferAttachmentImageInfo-pNext-pNext", device,
attachment_image_info_loc.dot(Field::pNext), "is not NULL.\n%s",
PrintPNextChain(Struct::VkFramebufferAttachmentImageInfo, attachment_image_info.pNext).c_str());
}
for (const auto [j, view_format] :
vvl::enumerate(attachment_image_info.pViewFormats, attachment_image_info.viewFormatCount)) {
// VK_ANDROID_external_format_resolve can have a valid undefined format
if (view_format == VK_FORMAT_UNDEFINED && rp_state->create_info.pAttachments[i].format != VK_FORMAT_UNDEFINED) {
skip |= LogError("VUID-VkFramebufferAttachmentImageInfo-viewFormatCount-09536", device,
attachment_image_info_loc.dot(Field::pViewFormats, j), "is VK_FORMAT_UNDEFINED.");
}
}
}
}
// attachmentCounts match, so make sure corresponding attachment details line up
if ((pCreateInfo->flags & VK_FRAMEBUFFER_CREATE_IMAGELESS_BIT) == 0) {
skip |= ValidateFrameBufferSubpasses(*pCreateInfo, create_info_loc, *rpci);
skip |= ValidateFrameBufferAttachments(*pCreateInfo, create_info_loc, *rp_state, *rpci);
} else if (framebuffer_attachments_create_info) {
skip |= ValidateFrameBufferAttachmentsImageless(*pCreateInfo, create_info_loc, *rpci, *framebuffer_attachments_create_info);
}
if (rp_state->has_multiview_enabled && pCreateInfo->layers != 1) {
skip |=
LogError("VUID-VkFramebufferCreateInfo-renderPass-02531", pCreateInfo->renderPass, create_info_loc.dot(Field::layers),
"is %" PRIu32 " but renderPass (%s) was specified with non-zero view masks.", pCreateInfo->layers,
FormatHandle(pCreateInfo->renderPass).c_str());
}
if (rp_state->create_info.flags & VK_RENDER_PASS_CREATE_PER_LAYER_FRAGMENT_DENSITY_BIT_VALVE) {
if (pCreateInfo->layers > phys_dev_ext_props.fragment_density_map_layered_props.maxFragmentDensityMapLayers) {
skip |=
LogError("VUID-VkFramebufferCreateInfo-renderPass-10830", pCreateInfo->renderPass,
create_info_loc.dot(Field::layers), "is %" PRIu32 " but the maxFragmentDensityMapLayers is %" PRIu32 ".",
pCreateInfo->layers, phys_dev_ext_props.fragment_density_map_layered_props.maxFragmentDensityMapLayers);
}
}
return skip;
}
bool CoreChecks::ValidateFrameBufferAttachments(const VkFramebufferCreateInfo &create_info, const Location &create_info_loc,
const vvl::RenderPass &rp_state, const VkRenderPassCreateInfo2 &rpci) const {
bool skip = false;
const VkImageView *image_views = create_info.pAttachments;
for (uint32_t i = 0; i < create_info.attachmentCount; ++i) {
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, i);
auto view_state = Get<vvl::ImageView>(image_views[i]);
ASSERT_AND_CONTINUE(view_state);
auto &ivci = view_state->create_info;
auto &subresource_range = view_state->normalized_subresource_range;
if (ivci.format != rpci.pAttachments[i].format) {
LogObjectList objlist(create_info.renderPass, image_views[i]);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-00880", objlist, attachment_loc,
"has format of %s that does not match the format of %s used by the corresponding attachment for %s.",
string_VkFormat(ivci.format), string_VkFormat(rpci.pAttachments[i].format),
FormatHandle(create_info.renderPass).c_str());
} else if (ivci.format == VK_FORMAT_UNDEFINED) {
// both have external foramts
const uint64_t attachment_external_format = GetExternalFormat(rpci.pAttachments[i].pNext);
if (view_state->image_state->ahb_format != attachment_external_format) {
LogObjectList objlist(create_info.renderPass, image_views[i]);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-09350", objlist, attachment_loc,
"has externalFormat %" PRIu64 " that does not match the externalFormat of %" PRIu64
" used by the corresponding attachment for %s.",
view_state->image_state->ahb_format, attachment_external_format,
FormatHandle(create_info.renderPass).c_str());
}
}
const auto &ici = view_state->image_state->create_info;
if (ici.samples != rpci.pAttachments[i].samples) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-00881", objlist, attachment_loc,
"has %s samples that do not match the %s samples used by the corresponding attachment for %s.",
string_VkSampleCountFlagBits(ici.samples), string_VkSampleCountFlagBits(rpci.pAttachments[i].samples),
FormatHandle(create_info.renderPass).c_str());
}
// Verify that image memory is valid
if (auto image_data = Get<vvl::Image>(ivci.image)) {
// VU being worked on https://gitlab.khronos.org/vulkan/vulkan/-/merge_requests/5598
skip |= ValidateMemoryIsBoundToImage(LogObjectList(ivci.image), *image_data, attachment_loc,
"UNASSIGNED-VkFramebufferCreateInfo-BoundResourceFreedMemoryAccess");
}
// Verify that view only has a single mip level
if (subresource_range.levelCount != 1) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-00883", objlist, attachment_loc,
"has mip levelCount of %" PRIu32
" but only a single mip level (levelCount == 1) is allowed when creating a Framebuffer.",
subresource_range.levelCount);
}
const uint32_t mip_level = subresource_range.baseMipLevel;
uint32_t mip_width = std::max(1u, ici.extent.width >> mip_level);
uint32_t mip_height = std::max(1u, ici.extent.height >> mip_level);
bool used_as_input_color_resolve_depth_stencil_attachment = false;
bool used_as_fragment_shading_rate_attachment = false;
bool fsr_non_zero_viewmasks = false;
for (uint32_t j = 0; j < rpci.subpassCount; ++j) {
const VkSubpassDescription2 &subpass = rpci.pSubpasses[j];
// if viewmask is zero, will return -1 (so layerCount is always lower)
int highest_view_bit = MostSignificantBit(subpass.viewMask);
for (uint32_t k = 0; k < rpci.pSubpasses[j].inputAttachmentCount; ++k) {
if (subpass.pInputAttachments[k].attachment == i) {
used_as_input_color_resolve_depth_stencil_attachment = true;
break;
}
}
for (uint32_t k = 0; k < rpci.pSubpasses[j].colorAttachmentCount; ++k) {
if (subpass.pColorAttachments[k].attachment == i ||
(subpass.pResolveAttachments && subpass.pResolveAttachments[k].attachment == i)) {
used_as_input_color_resolve_depth_stencil_attachment = true;
break;
}
}
if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment == i) {
used_as_input_color_resolve_depth_stencil_attachment = true;
}
if (used_as_input_color_resolve_depth_stencil_attachment) {
if (static_cast<int32_t>(subresource_range.layerCount) <= highest_view_bit) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-04536", objlist, attachment_loc,
"has a layer count (%" PRIu32
") less than or equal to the highest bit in the view mask (%i) of subpass %" PRIu32 ".",
subresource_range.layerCount, highest_view_bit, j);
}
}
if (enabled_features.attachmentFragmentShadingRate) {
const auto *fsr_attachment = vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(subpass.pNext);
if (fsr_attachment && fsr_attachment->pFragmentShadingRateAttachment &&
fsr_attachment->pFragmentShadingRateAttachment->attachment == i) {
used_as_fragment_shading_rate_attachment = true;
const bool validate_render_area =
!enabled_features.maintenance7 ||
!phys_dev_ext_props.maintenance7_props.robustFragmentShadingRateAttachmentAccess;
if (validate_render_area &&
(mip_width * fsr_attachment->shadingRateAttachmentTexelSize.width) < create_info.width) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04539", objlist, attachment_loc,
"mip level %" PRIu32
" is used as a "
"fragment shading rate attachment in subpass %" PRIu32
", but the product of its "
"width (%" PRIu32
") and the "
"specified shading rate texel width (%" PRIu32
") are smaller than the "
"corresponding framebuffer width (%" PRIu32 ").",
subresource_range.baseMipLevel, j, mip_width,
fsr_attachment->shadingRateAttachmentTexelSize.width, create_info.width);
}
if (validate_render_area &&
(mip_height * fsr_attachment->shadingRateAttachmentTexelSize.height) < create_info.height) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04540", objlist, attachment_loc,
"mip level %" PRIu32
" is used as a "
"fragment shading rate attachment in subpass %" PRIu32
", but the product of its "
"height (%" PRIu32
") and the "
"specified shading rate texel height (%" PRIu32
") are smaller than the corresponding "
"framebuffer height (%" PRIu32 ").",
subresource_range.baseMipLevel, j, mip_height,
fsr_attachment->shadingRateAttachmentTexelSize.height, create_info.height);
}
if (highest_view_bit >= 0) {
fsr_non_zero_viewmasks = true;
}
if (static_cast<int32_t>(subresource_range.layerCount) <= highest_view_bit &&
subresource_range.layerCount != 1) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04537", objlist, attachment_loc,
"has a layer count (%" PRIu32
") less than or equal to the highest bit in the view mask (%i) of subpass %" PRIu32 ".",
subresource_range.layerCount, highest_view_bit, j);
}
}
}
if (enabled_features.fragmentDensityMap && api_version >= VK_API_VERSION_1_1) {
const auto *fdm_attachment = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rpci.pNext);
if (fdm_attachment && fdm_attachment->fragmentDensityMapAttachment.attachment == i) {
int32_t layer_count = view_state->normalized_subresource_range.layerCount;
if (rp_state.has_multiview_enabled && layer_count != 1 && layer_count <= highest_view_bit) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |=
LogError("VUID-VkFramebufferCreateInfo-renderPass-02746", objlist, attachment_loc,
"has a layer count (%" PRId32
") different than 1 or lower than the most significant bit (%d) in viewMask (0x%" PRIx32
""
") but renderPass (%s) was specified with non-zero view masks.",
layer_count, highest_view_bit, subpass.viewMask, FormatHandle(create_info.renderPass).c_str());
}
if (!rp_state.has_multiview_enabled && layer_count != 1) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-02746", objlist, attachment_loc,
"has a layer count (%" PRIu32
") not equal to 1 but renderPass (%s) was not specified with non-zero view masks.",
layer_count, FormatHandle(create_info.renderPass).c_str());
}
}
}
if (enabled_features.externalFormatResolve &&
!device_state->android_external_format_resolve_null_color_attachment_prop && subpass.pResolveAttachments &&
subpass.pResolveAttachments[0].attachment == i && subpass.pColorAttachments) {
const uint64_t attachment_external_format =
GetExternalFormat(rpci.pAttachments[subpass.pResolveAttachments[0].attachment].pNext);
auto it = device_state->ahb_ext_resolve_formats_map.find(attachment_external_format);
if (it != device_state->ahb_ext_resolve_formats_map.end()) {
VkFormat color_format = rpci.pAttachments[subpass.pColorAttachments[0].attachment].format;
if (it->second != color_format) {
LogObjectList objlist(create_info.renderPass, image_views[i]);
skip |= LogError(
"VUID-VkFramebufferCreateInfo-nullColorAttachmentWithExternalFormatResolve-09349", objlist,
attachment_loc,
"subpass[%" PRIu32 "].pResolveAttachments[0].attachment %" PRIu32 " has externalFormat %" PRIu64
" which corresponds to needing a color attachment format of %s, but the format is %s.",
j, i, attachment_external_format, string_VkFormat(it->second), string_VkFormat(color_format));
}
}
}
}
if (enabled_features.fragmentDensityMap) {
const auto *fdm_attachment = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rpci.pNext);
if (fdm_attachment && fdm_attachment->fragmentDensityMapAttachment.attachment != VK_ATTACHMENT_UNUSED) {
if (fdm_attachment->fragmentDensityMapAttachment.attachment == i) {
uint32_t ceiling_width = vvl::GetQuotientCeil(
create_info.width, phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.width);
if (mip_width < ceiling_width) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-02555", objlist, attachment_loc,
"mip level %" PRIu32
" has width "
"smaller than the corresponding the ceiling of framebuffer width / "
"maxFragmentDensityTexelSize.width "
"Here are the respective dimensions for attachment #%" PRIu32
", the ceiling value:\n "
"attachment #%" PRIu32
", framebuffer:\n"
"width: %" PRIu32 ", the ceiling value: %" PRIu32 "\n",
subresource_range.baseMipLevel, i, i, mip_width, ceiling_width);
}
uint32_t ceiling_height = vvl::GetQuotientCeil(
create_info.height, phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize.height);
if (mip_height < ceiling_height) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-02556", objlist, attachment_loc,
"mip level %" PRIu32
" has height smaller than the corresponding the ceiling of framebuffer height / "
"maxFragmentDensityTexelSize.height "
"Here are the respective dimensions for attachment #%" PRIu32
", the ceiling value:\n "
"attachment #%" PRIu32
", framebuffer:\n"
"height: %" PRIu32 ", the ceiling value: %" PRIu32 "\n",
subresource_range.baseMipLevel, i, i, mip_height, ceiling_height);
}
if (view_state->normalized_subresource_range.layerCount != 1 && !IsExtEnabled(extensions.vk_khr_multiview)) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-02746", objlist, attachment_loc,
"is referenced by "
"VkRenderPassFragmentDensityMapCreateInfoEXT::fragmentDensityMapAttachment in "
"the pNext chain, but it was create with subresourceRange.layerCount (%" PRIu32
") different from 1.",
view_state->normalized_subresource_range.layerCount);
}
if ((ici.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT) != 0) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-02552", objlist, attachment_loc,
"must not be created with flag value VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT if it is "
"used as a fragment density map");
}
} else if (!enabled_features.fragmentDensityMapNonSubsampledImages &&
(ici.flags & VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT) == 0) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-02553", objlist, attachment_loc,
"is not created with flag value "
"VK_IMAGE_CREATE_SUBSAMPLED_BIT_EXT and "
"fragmentDensityMapNonSubsampledImages is not enabled");
}
}
}
if (used_as_input_color_resolve_depth_stencil_attachment) {
if (mip_width < create_info.width) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04533", objlist, attachment_loc,
"mip level %" PRIu32 " has width (%" PRIu32
") smaller than the corresponding framebuffer width (%" PRIu32 ").",
mip_level, mip_width, create_info.width);
}
if (mip_height < create_info.height) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04534", objlist, attachment_loc,
"mip level %" PRIu32 " has height (%" PRIu32
") smaller than the corresponding framebuffer height (%" PRIu32 ").",
mip_level, mip_height, create_info.height);
}
uint32_t layerCount = view_state->GetAttachmentLayerCount();
if (layerCount < create_info.layers) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04535", objlist, attachment_loc,
"has a VkImageViewCreateInfo::subresourceRange::layerCount of %" PRIu32
" which is smaller than VkFramebufferCreateInfo::layers (%" PRIu32 ").",
layerCount, create_info.layers);
}
}
if (used_as_fragment_shading_rate_attachment && !fsr_non_zero_viewmasks) {
if (subresource_range.layerCount != 1 && subresource_range.layerCount < create_info.layers) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04538", objlist, attachment_loc,
"has a layer count (%" PRIu32
") "
"smaller than the corresponding framebuffer layer count (%" PRIu32 ").",
subresource_range.layerCount, create_info.layers);
}
}
if (IsIdentitySwizzle(ivci.components) == false) {
LogObjectList objlist(create_info.renderPass, image_views[i]);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-00884", objlist, attachment_loc,
"has non-identy swizzle. All "
"framebuffer attachments must have been created with the identity swizzle. Here are the actual "
"swizzle values:\n%s",
string_VkComponentMapping(ivci.components).c_str());
}
if ((ivci.viewType == VK_IMAGE_VIEW_TYPE_2D) || (ivci.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
auto image_state = Get<vvl::Image>(ivci.image);
if (image_state && image_state->create_info.imageType == VK_IMAGE_TYPE_3D) {
if (vkuFormatIsDepthOrStencil(ivci.format)) {
LogObjectList objlist(create_info.renderPass, image_views[i], ivci.image);
skip |= LogError("VUID-VkFramebufferCreateInfo-pAttachments-00891", objlist, attachment_loc,
"has an image view type of %s which was taken from image %s of type "
"VK_IMAGE_TYPE_3D, but the image view format is a "
"depth/stencil format %s.",
string_VkImageViewType(ivci.viewType), FormatHandle(ivci.image).c_str(),
string_VkFormat(ivci.format));
}
}
}
if (ivci.viewType == VK_IMAGE_VIEW_TYPE_3D) {
LogObjectList objlist(create_info.renderPass, image_views[i]);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04113", objlist, attachment_loc,
"has an image view type of VK_IMAGE_VIEW_TYPE_3D.");
}
}
return skip;
}
bool CoreChecks::ValidateFrameBufferAttachmentsImageless(
const VkFramebufferCreateInfo &create_info, const Location &create_info_loc, const VkRenderPassCreateInfo2 &rpci,
const VkFramebufferAttachmentsCreateInfo &framebuffer_attachments_create_info) const {
bool skip = false;
for (uint32_t i = 0; i < create_info.attachmentCount; ++i) {
const Location attachment_loc = create_info_loc.dot(Field::pAttachments, i);
auto &aii = framebuffer_attachments_create_info.pAttachmentImageInfos[i];
bool format_found = false;
for (uint32_t j = 0; j < aii.viewFormatCount; ++j) {
if (aii.pViewFormats[j] == rpci.pAttachments[i].format) {
format_found = true;
}
}
if (!format_found) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-03205", create_info.renderPass,
create_info_loc.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos, i)
.dot(Field::pViewFormats),
"does not include format %s used by the corresponding attachment for renderPass (%s).",
string_VkFormat(rpci.pAttachments[i].format), FormatHandle(create_info.renderPass).c_str());
}
bool used_as_input_color_resolve_depth_stencil_attachment = false;
bool used_as_fragment_shading_rate_attachment = false;
bool fsr_non_zero_viewmasks = false;
for (uint32_t j = 0; j < rpci.subpassCount; ++j) {
const VkSubpassDescription2 &subpass = rpci.pSubpasses[j];
int highest_view_bit = MostSignificantBit(subpass.viewMask);
for (uint32_t k = 0; k < rpci.pSubpasses[j].inputAttachmentCount; ++k) {
if (subpass.pInputAttachments[k].attachment == i) {
used_as_input_color_resolve_depth_stencil_attachment = true;
break;
}
}
for (uint32_t k = 0; k < rpci.pSubpasses[j].colorAttachmentCount; ++k) {
if (subpass.pColorAttachments[k].attachment == i ||
(subpass.pResolveAttachments && subpass.pResolveAttachments[k].attachment == i)) {
used_as_input_color_resolve_depth_stencil_attachment = true;
break;
}
}
if (subpass.pDepthStencilAttachment && subpass.pDepthStencilAttachment->attachment == i) {
used_as_input_color_resolve_depth_stencil_attachment = true;
}
if (enabled_features.attachmentFragmentShadingRate) {
const auto *fsr_attachment = vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(subpass.pNext);
if (fsr_attachment && fsr_attachment->pFragmentShadingRateAttachment->attachment == i) {
used_as_fragment_shading_rate_attachment = true;
const bool validate_render_area =
!enabled_features.maintenance7 ||
!phys_dev_ext_props.maintenance7_props.robustFragmentShadingRateAttachmentAccess;
if (validate_render_area &&
(aii.width * fsr_attachment->shadingRateAttachmentTexelSize.width) < create_info.width) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04543", create_info.renderPass, attachment_loc,
"is used as a fragment shading rate attachment in subpass %" PRIu32
", but the product of its width (%" PRIu32
") and the "
"specified shading rate texel width (%" PRIu32
") are smaller than the corresponding framebuffer "
"width (%" PRIu32 ").",
j, aii.width, fsr_attachment->shadingRateAttachmentTexelSize.width, create_info.width);
}
if (validate_render_area &&
(aii.height * fsr_attachment->shadingRateAttachmentTexelSize.height) < create_info.height) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04544", create_info.renderPass, attachment_loc,
"is used as a fragment shading rate attachment in subpass %" PRIu32
", but the product of its "
"height (%" PRIu32
") and the "
"specified shading rate texel height (%" PRIu32
") are smaller than the corresponding "
"framebuffer height (%" PRIu32 ").",
j, aii.height, fsr_attachment->shadingRateAttachmentTexelSize.height, create_info.height);
}
if (highest_view_bit >= 0) {
fsr_non_zero_viewmasks = true;
}
if (aii.layerCount != 1 && static_cast<int32_t>(aii.layerCount) <= highest_view_bit) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04587", create_info.renderPass, attachment_loc,
"has a layer count (%" PRIu32
") "
"less than or equal to the highest bit in the view mask (%i) of subpass %" PRIu32 ".",
aii.layerCount, highest_view_bit, j);
}
}
}
if (enabled_features.fragmentDensityMap) {
const auto *fdm_attachment = vku::FindStructInPNextChain<VkRenderPassFragmentDensityMapCreateInfoEXT>(rpci.pNext);
if (fdm_attachment && fdm_attachment->fragmentDensityMapAttachment.attachment == i) {
const auto &maxFragmentDensityTexelSize =
phys_dev_ext_props.fragment_density_map_props.maxFragmentDensityTexelSize;
const uint32_t ceiling_width = vvl::GetQuotientCeil(create_info.width, maxFragmentDensityTexelSize.width);
if (aii.width < ceiling_width) {
LogObjectList objlist(create_info.renderPass);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-03196", objlist, attachment_loc,
"is used as a fragment density map attachment in subpass %" PRIu32
", but the quotient of the framebuffer width (%" PRIu32
") and the allowed maximum fragment density texel width (%" PRIu32
") is greater than the corresponding fragment density attachment "
"width (%" PRIu32 ").",
j, create_info.width, maxFragmentDensityTexelSize.width, aii.width);
}
const uint32_t ceiling_height = vvl::GetQuotientCeil(create_info.height, maxFragmentDensityTexelSize.height);
if (aii.height < ceiling_height) {
LogObjectList objlist(create_info.renderPass);
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-03197", objlist, attachment_loc,
"is used as a fragment density map attachment in subpass %" PRIu32
", but the quotient of the framebuffer height (%" PRIu32
") and the allowed maximum fragment density texel height (%" PRIu32
") is greater than the corresponding fragment density attachment "
"height (%" PRIu32 ").",
j, create_info.height, maxFragmentDensityTexelSize.height, aii.height);
}
}
}
}
if (used_as_input_color_resolve_depth_stencil_attachment) {
if (aii.width < create_info.width) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04541", create_info.renderPass, attachment_loc,
"has a width of only %" PRIu32 ", but framebuffer has a width of %" PRIu32 ".", aii.width,
create_info.width);
}
if (aii.height < create_info.height) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04542", create_info.renderPass, attachment_loc,
"has a height of only %" PRIu32 ", but framebuffer has a height of %" PRIu32 ".", aii.height,
create_info.height);
}
if ((rpci.subpassCount == 0) || (rpci.pSubpasses[0].viewMask == 0)) {
if (aii.layerCount < create_info.layers) {
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-04546", create_info.renderPass, attachment_loc,
"has only %" PRIu32 " layers, but framebuffer has %" PRIu32 " layers.", aii.layerCount,
create_info.layers);
}
}
}
if (used_as_fragment_shading_rate_attachment && !fsr_non_zero_viewmasks) {
if (aii.layerCount != 1 && aii.layerCount < create_info.layers) {
skip |= LogError("VUID-VkFramebufferCreateInfo-flags-04545", create_info.renderPass, attachment_loc,
"has a layer count (%" PRIu32 ") smaller than the corresponding framebuffer layer count (%" PRIu32
").",
aii.layerCount, create_info.layers);
}
}
}
// Validate image usage
uint32_t attachment_index = VK_ATTACHMENT_UNUSED;
for (uint32_t i = 0; i < rpci.subpassCount; ++i) {
const VkSubpassDescription2 &subpass = rpci.pSubpasses[i];
skip |= MatchUsage(subpass.colorAttachmentCount, subpass.pColorAttachments, create_info,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-flags-03201", create_info_loc);
skip |= MatchUsage(subpass.colorAttachmentCount, subpass.pResolveAttachments, create_info,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-flags-03201", create_info_loc);
skip |= MatchUsage(1, subpass.pDepthStencilAttachment, create_info, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
"VUID-VkFramebufferCreateInfo-flags-03202", create_info_loc);
skip |= MatchUsage(subpass.inputAttachmentCount, subpass.pInputAttachments, create_info,
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-flags-03204", create_info_loc);
const auto *depth_stencil_resolve = vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass.pNext);
if (depth_stencil_resolve != nullptr) {
skip |= MatchUsage(1, depth_stencil_resolve->pDepthStencilResolveAttachment, create_info,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-flags-03203",
create_info_loc);
}
const auto *fragment_shading_rate_attachment_info =
vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(subpass.pNext);
if (enabled_features.attachmentFragmentShadingRate && fragment_shading_rate_attachment_info != nullptr) {
skip |= MatchUsage(1, fragment_shading_rate_attachment_info->pFragmentShadingRateAttachment, create_info,
VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR, "VUID-VkFramebufferCreateInfo-flags-04549",
create_info_loc);
}
}
// VUID-VkSubpassDescription2-multiview-06558 forces viewMask to be zero if not using multiView
if ((rpci.subpassCount > 0) && (rpci.pSubpasses[0].viewMask != 0)) {
for (uint32_t i = 0; i < rpci.subpassCount; ++i) {
const VkSubpassDescription2 &subpass = rpci.pSubpasses[i];
const auto *depth_stencil_resolve = vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass.pNext);
uint32_t view_bits = subpass.viewMask;
int highest_view_bit = MostSignificantBit(view_bits);
for (uint32_t j = 0; j < subpass.colorAttachmentCount; ++j) {
attachment_index = subpass.pColorAttachments[j].attachment;
if (attachment_index != VK_ATTACHMENT_UNUSED) {
int32_t layer_count = framebuffer_attachments_create_info.pAttachmentImageInfos[attachment_index].layerCount;
if (layer_count <= highest_view_bit) {
skip |= LogError(
"VUID-VkFramebufferCreateInfo-renderPass-03198", create_info.renderPass,
create_info_loc
.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos, attachment_index)
.dot(Field::layerCount),
"is %" PRId32 ", but the view mask for subpass %" PRIu32
" in renderPass (%s) "
"includes layer %i, with that attachment specified as a color attachment %" PRIu32 ".",
layer_count, i, FormatHandle(create_info.renderPass).c_str(), highest_view_bit, j);
}
}
if (subpass.pResolveAttachments) {
attachment_index = subpass.pResolveAttachments[j].attachment;
if (attachment_index != VK_ATTACHMENT_UNUSED) {
int32_t layer_count =
framebuffer_attachments_create_info.pAttachmentImageInfos[attachment_index].layerCount;
if (layer_count <= highest_view_bit) {
skip |=
LogError("VUID-VkFramebufferCreateInfo-renderPass-03198", create_info.renderPass,
create_info_loc
.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos,
attachment_index)
.dot(Field::layerCount),
"is %" PRId32 ", but the view mask for subpass %" PRIu32
" in renderPass (%s) "
"includes layer %i, with that attachment specified as a resolve attachment %" PRIu32 ".",
layer_count, i, FormatHandle(create_info.renderPass).c_str(), highest_view_bit, j);
}
}
}
}
for (uint32_t j = 0; j < subpass.inputAttachmentCount; ++j) {
attachment_index = subpass.pInputAttachments[j].attachment;
if (attachment_index != VK_ATTACHMENT_UNUSED) {
int32_t layer_count = framebuffer_attachments_create_info.pAttachmentImageInfos[attachment_index].layerCount;
if (layer_count <= highest_view_bit) {
skip |= LogError(
"VUID-VkFramebufferCreateInfo-renderPass-03198", create_info.renderPass,
create_info_loc
.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos, attachment_index)
.dot(Field::layerCount),
"is %" PRId32 ", but the view mask for subpass %" PRIu32
" in renderPass (%s) "
"includes layer %i, with that attachment specified as an input attachment %" PRIu32 ".",
layer_count, i, FormatHandle(create_info.renderPass).c_str(), highest_view_bit, j);
}
}
}
if (subpass.pDepthStencilAttachment != nullptr) {
attachment_index = subpass.pDepthStencilAttachment->attachment;
if (attachment_index != VK_ATTACHMENT_UNUSED) {
int32_t layer_count = framebuffer_attachments_create_info.pAttachmentImageInfos[attachment_index].layerCount;
if (layer_count <= highest_view_bit) {
skip |= LogError(
"VUID-VkFramebufferCreateInfo-renderPass-03198", create_info.renderPass,
create_info_loc
.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos, attachment_index)
.dot(Field::layerCount),
"is %" PRId32 ", but the view mask for subpass %" PRIu32
" in renderPass (%s) "
"includes layer %i, with that attachment specified as a depth/stencil attachment.",
layer_count, i, FormatHandle(create_info.renderPass).c_str(), highest_view_bit);
}
}
if (depth_stencil_resolve != nullptr && depth_stencil_resolve->pDepthStencilResolveAttachment != nullptr) {
attachment_index = depth_stencil_resolve->pDepthStencilResolveAttachment->attachment;
if (attachment_index != VK_ATTACHMENT_UNUSED) {
int32_t layer_count =
framebuffer_attachments_create_info.pAttachmentImageInfos[attachment_index].layerCount;
if (layer_count <= highest_view_bit) {
skip |= LogError("VUID-VkFramebufferCreateInfo-renderPass-03198", create_info.renderPass,
create_info_loc
.pNext(Struct::VkFramebufferAttachmentsCreateInfo, Field::pAttachmentImageInfos,
attachment_index)
.dot(Field::layerCount),
"is %" PRId32 ", but the view mask for subpass %" PRIu32
" in renderPass (%s) "
"includes layer %i, with that attachment specified as a depth/stencil resolve "
"attachment.",
layer_count, i, FormatHandle(create_info.renderPass).c_str(), highest_view_bit);
}
}
}
}
}
}
return skip;
}
bool CoreChecks::ValidateFrameBufferSubpasses(const VkFramebufferCreateInfo &create_info, const Location &create_info_loc,
const VkRenderPassCreateInfo2 &rpci) const {
bool skip = false;
for (uint32_t subpass = 0; subpass < rpci.subpassCount; subpass++) {
const VkSubpassDescription2 &subpass_description = rpci.pSubpasses[subpass];
const auto *ms_rendered_to_single_sampled =
vku::FindStructInPNextChain<VkMultisampledRenderToSingleSampledInfoEXT>(subpass_description.pNext);
// Verify input attachments:
skip |= MatchUsage(subpass_description.inputAttachmentCount, subpass_description.pInputAttachments, create_info,
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-pAttachments-00879", create_info_loc);
// Verify color attachments:
skip |= MatchUsage(subpass_description.colorAttachmentCount, subpass_description.pColorAttachments, create_info,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, "VUID-VkFramebufferCreateInfo-pAttachments-00877", create_info_loc);
// Verify depth/stencil attachments:
skip |= MatchUsage(1, subpass_description.pDepthStencilAttachment, create_info, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
"VUID-VkFramebufferCreateInfo-pAttachments-02633", create_info_loc);
// Verify depth/stecnil resolve
if (const auto *ds_resolve =
vku::FindStructInPNextChain<VkSubpassDescriptionDepthStencilResolve>(subpass_description.pNext)) {
skip |=
MatchUsage(1, ds_resolve->pDepthStencilResolveAttachment, create_info, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
"VUID-VkFramebufferCreateInfo-pAttachments-02634", create_info_loc);
}
// Verify fragment shading rate attachments
if (enabled_features.attachmentFragmentShadingRate) {
const auto *fragment_shading_rate_attachment_info =
vku::FindStructInPNextChain<VkFragmentShadingRateAttachmentInfoKHR>(subpass_description.pNext);
if (fragment_shading_rate_attachment_info) {
skip |= MatchUsage(1, fragment_shading_rate_attachment_info->pFragmentShadingRateAttachment, create_info,
VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR,
"VUID-VkFramebufferCreateInfo-flags-04548", create_info_loc);
}
}
if (ms_rendered_to_single_sampled && ms_rendered_to_single_sampled->multisampledRenderToSingleSampledEnable) {
skip |= MsRenderedToSingleSampledValidateFBAttachments(
subpass_description.inputAttachmentCount, subpass_description.pInputAttachments, create_info, rpci, subpass,
ms_rendered_to_single_sampled->rasterizationSamples, create_info_loc);
skip |= MsRenderedToSingleSampledValidateFBAttachments(
subpass_description.colorAttachmentCount, subpass_description.pColorAttachments, create_info, rpci, subpass,
ms_rendered_to_single_sampled->rasterizationSamples, create_info_loc);
if (subpass_description.pDepthStencilAttachment) {
skip |= MsRenderedToSingleSampledValidateFBAttachments(
1, subpass_description.pDepthStencilAttachment, create_info, rpci, subpass,
ms_rendered_to_single_sampled->rasterizationSamples, create_info_loc);
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateDestroyFramebuffer(VkDevice device, VkFramebuffer framebuffer,
const VkAllocationCallbacks *pAllocator, const ErrorObject &error_obj) const {
bool skip = false;
if (auto framebuffer_state = Get<vvl::Framebuffer>(framebuffer)) {
skip |= ValidateObjectNotInUse(framebuffer_state.get(), error_obj.location, "VUID-vkDestroyFramebuffer-framebuffer-00892");
}
return skip;
}
bool CoreChecks::ValidateInheritanceInfoFramebuffer(const vvl::CommandBuffer &cb_state,
const vvl::CommandBuffer &secondary_cb_state,
const VkCommandBufferInheritanceInfo &secondary_inheritance_info,
const Location &loc) const {
bool skip = false;
VkFramebuffer primary_fb = cb_state.active_framebuffer ? cb_state.active_framebuffer->VkHandle() : VK_NULL_HANDLE;
VkFramebuffer secondary_fb = secondary_inheritance_info.framebuffer;
if (secondary_fb != VK_NULL_HANDLE && primary_fb != secondary_fb) {
const LogObjectList objlist(cb_state.Handle(), secondary_cb_state.Handle(), secondary_fb, primary_fb);
skip |= LogError("VUID-vkCmdExecuteCommands-pCommandBuffers-00099", objlist, loc,
"called w/ invalid secondary %s which has a %s"
" that is not the same as the primary command buffer's current active %s.",
FormatHandle(secondary_cb_state.Handle()).c_str(), FormatHandle(secondary_fb).c_str(),
FormatHandle(primary_fb).c_str());
}
return skip;
}
// TODO - loc_info makes no sense coming from a secondary command buffer
bool CoreChecks::ValidateRenderingAttachmentLocations(const VkRenderingAttachmentLocationInfo &location_info,
const LogObjectList objlist, const Location &loc_info) const {
bool skip = false;
if (location_info.pColorAttachmentLocations) {
vvl::unordered_map<uint32_t, uint32_t> unique;
for (uint32_t i = 0; i < location_info.colorAttachmentCount; ++i) {
const uint32_t location = location_info.pColorAttachmentLocations[i];
const Location loc = loc_info.dot(Struct::VkRenderingAttachmentLocationInfo, Field::pColorAttachmentLocations, i);
if (!enabled_features.dynamicRenderingLocalRead && location != i) {
skip |= LogError("VUID-VkRenderingAttachmentLocationInfo-dynamicRenderingLocalRead-09512", objlist, loc,
"is %" PRIu32 " while expected to be %" PRIu32
" because the dynamicRenderingLocalRead feature is not enabled",
location, i);
}
if (location == VK_ATTACHMENT_UNUSED) {
continue;
}
if (unique.find(location) != unique.end()) {
skip |= LogError("VUID-VkRenderingAttachmentLocationInfo-pColorAttachmentLocations-09513", objlist, loc,
"(%" PRIu32 ") has same value as pColorAttachmentLocations[%" PRIu32 "] (%" PRIu32 ").", location,
unique[location], location);
} else
unique[location] = i;
if (location >= phys_dev_props.limits.maxColorAttachments) {
skip |= LogError("VUID-VkRenderingAttachmentLocationInfo-pColorAttachmentLocations-09515", objlist, loc,
"(%" PRIu32 ") is greater than maxColorAttachments (%" PRIu32 ")", location,
phys_dev_props.limits.maxColorAttachments);
}
}
}
if (location_info.colorAttachmentCount > phys_dev_props.limits.maxColorAttachments) {
skip |=
LogError("VUID-VkRenderingAttachmentLocationInfo-colorAttachmentCount-09514", objlist,
loc_info.dot(Field::colorAttachmentCount), "(%" PRIu32 ") is greater than maxColorAttachments (%" PRIu32 ").",
location_info.colorAttachmentCount, phys_dev_props.limits.maxColorAttachments);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdSetRenderingAttachmentLocations(VkCommandBuffer commandBuffer,
const VkRenderingAttachmentLocationInfo *pLocationInfo,
const ErrorObject &error_obj) const {
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
bool skip = false;
if (!enabled_features.dynamicRenderingLocalRead) {
skip |= LogError("VUID-vkCmdSetRenderingAttachmentLocations-dynamicRenderingLocalRead-09509", commandBuffer,
error_obj.location, "dynamicRenderingLocalRead was not enabled.");
}
skip |= ValidateCmd(cb_state, error_obj.location);
const auto *rp_state_ptr = cb_state.active_render_pass.get();
if (!rp_state_ptr) {
return skip; // called outside a render pass (validated elsewhere)
}
const auto &rp_state = *rp_state_ptr;
if (!rp_state.use_dynamic_rendering) {
const LogObjectList objlist(commandBuffer, rp_state.VkHandle());
if (!rp_state.use_dynamic_rendering_inherited) {
skip |= LogError("VUID-vkCmdSetRenderingAttachmentLocations-commandBuffer-09511", commandBuffer, error_obj.location,
"is called inside vkCmdBeginRenderPass, but this command is only used for dynamic rendering "
"(vkCmdBeginRendering).");
} else {
assert(cb_state.IsSecondary());
skip |= LogError("VUID-vkCmdSetRenderingAttachmentLocations-commandBuffer-09511", objlist, error_obj.location,
"is not allowed in secondary command buffers using an inherited (VkCommandBufferInheritanceInfo) "
"render pass, vkCmdBeginRendering needs to have been called prior to this command.");
}
}
if (pLocationInfo->colorAttachmentCount != cb_state.GetDynamicRenderingColorAttachmentCount()) {
skip |= LogError("VUID-vkCmdSetRenderingAttachmentLocations-pLocationInfo-09510", commandBuffer,
error_obj.location.dot(Field::pLocationInfo).dot(Field::colorAttachmentCount),
"(%" PRIu32 ") is not equal to %s::colorAttachmentCount (%" PRIu32 ") when render pass began",
pLocationInfo->colorAttachmentCount,
rp_state.use_dynamic_rendering_inherited ? "VkCommandBufferInheritanceRenderingInfo" : "VkRenderingInfo",
cb_state.GetDynamicRenderingColorAttachmentCount());
}
skip |= ValidateRenderingAttachmentLocations(*pLocationInfo, commandBuffer, error_obj.location.dot(Field::pLocationInfo));
return skip;
}
bool CoreChecks::PreCallValidateCmdSetRenderingAttachmentLocationsKHR(VkCommandBuffer commandBuffer,
const VkRenderingAttachmentLocationInfoKHR *pLocationInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdSetRenderingAttachmentLocations(commandBuffer, pLocationInfo, error_obj);
}
// TODO - loc_info makes no sense coming from a secondary command buffer
bool CoreChecks::ValidateRenderingInputAttachmentIndices(const VkRenderingInputAttachmentIndexInfo &index_info,
const LogObjectList objlist, const Location &loc_info) const {
bool skip = false;
if (!enabled_features.dynamicRenderingLocalRead) {
if (index_info.pDepthInputAttachmentIndex) {
if (*index_info.pDepthInputAttachmentIndex != VK_ATTACHMENT_UNUSED) {
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-dynamicRenderingLocalRead-09520", objlist,
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pDepthInputAttachmentIndex, 0),
"is %" PRIu32 " but must be VK_ATTACHMENT_UNUSED", *index_info.pDepthInputAttachmentIndex);
}
}
if (index_info.pStencilInputAttachmentIndex) {
if (*index_info.pStencilInputAttachmentIndex != VK_ATTACHMENT_UNUSED) {
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-dynamicRenderingLocalRead-09521", objlist,
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pStencilInputAttachmentIndex, 0),
"is %" PRIu32 " but must be VK_ATTACHMENT_UNUSED", *index_info.pStencilInputAttachmentIndex);
}
}
}
if (index_info.pColorAttachmentInputIndices) {
std::map<uint32_t, uint32_t> unique;
for (uint32_t i = 0; i < index_info.colorAttachmentCount; ++i) {
const uint32_t index = index_info.pColorAttachmentInputIndices[i];
if (index == VK_ATTACHMENT_UNUSED) {
continue;
} else if (!enabled_features.dynamicRenderingLocalRead) {
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-dynamicRenderingLocalRead-09519", objlist,
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pColorAttachmentInputIndices, i),
"is %" PRIu32 " but must be VK_ATTACHMENT_UNUSED", index);
}
if (unique.find(index) != unique.end()) {
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-pColorAttachmentInputIndices-09522", objlist,
loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pColorAttachmentInputIndices, i),
"(%" PRIu32 ") has same value as in pColorAttachmentInputIndices[%" PRIu32 "] (%" PRIu32 ").",
index, unique[index], index_info.pColorAttachmentInputIndices[unique[index]]);
} else
unique[index] = i;
}
if (index_info.pDepthInputAttachmentIndex && *index_info.pDepthInputAttachmentIndex != VK_ATTACHMENT_UNUSED &&
unique.find(*index_info.pDepthInputAttachmentIndex) != unique.end()) {
const Location loc = loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pDepthInputAttachmentIndex, 0);
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-pColorAttachmentInputIndices-09523", objlist, loc,
"(%" PRIu32 ") has same value as in pColorAttachmentInputIndices[%" PRIu32 "] (%" PRIu32 ").",
*index_info.pDepthInputAttachmentIndex, unique[*index_info.pDepthInputAttachmentIndex],
index_info.pColorAttachmentInputIndices[unique[*index_info.pDepthInputAttachmentIndex]]);
}
if (index_info.pStencilInputAttachmentIndex && *index_info.pStencilInputAttachmentIndex != VK_ATTACHMENT_UNUSED &&
unique.find(*index_info.pStencilInputAttachmentIndex) != unique.end()) {
const Location loc = loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::pStencilInputAttachmentIndex, 0);
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-pColorAttachmentInputIndices-09524", objlist, loc,
"(%" PRIu32 ") has same value as in pColorAttachmentInputIndices[%" PRIu32 "] (%" PRIu32 ").",
*index_info.pStencilInputAttachmentIndex, unique[*index_info.pStencilInputAttachmentIndex],
index_info.pColorAttachmentInputIndices[unique[*index_info.pStencilInputAttachmentIndex]]);
}
}
if (index_info.colorAttachmentCount > phys_dev_props.limits.maxColorAttachments) {
const Location loc = loc_info.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::colorAttachmentCount);
skip |= LogError("VUID-VkRenderingInputAttachmentIndexInfo-colorAttachmentCount-09525", objlist, loc,
"(%" PRIu32 ") is greater than maxColorAttachments (%" PRIu32 ").", index_info.colorAttachmentCount,
phys_dev_props.limits.maxColorAttachments);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdSetRenderingInputAttachmentIndices(VkCommandBuffer commandBuffer,
const VkRenderingInputAttachmentIndexInfo *pLocationInfo,
const ErrorObject &error_obj) const {
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
bool skip = false;
if (!enabled_features.dynamicRenderingLocalRead) {
skip |= LogError("VUID-vkCmdSetRenderingInputAttachmentIndices-dynamicRenderingLocalRead-09516", commandBuffer,
error_obj.location, "dynamicRenderingLocalRead was not enabled.");
}
skip |= ValidateCmd(cb_state, error_obj.location);
const auto *rp_state_ptr = cb_state.active_render_pass.get();
if (!rp_state_ptr) {
return skip; // called outside a render pass (validated elsewhere)
}
const auto &rp_state = *rp_state_ptr;
if (!rp_state.use_dynamic_rendering) {
const LogObjectList objlist(commandBuffer, rp_state.VkHandle());
if (!rp_state.use_dynamic_rendering_inherited) {
skip |= LogError("VUID-vkCmdSetRenderingInputAttachmentIndices-commandBuffer-09518", objlist, error_obj.location,
"is called inside vkCmdBeginRenderPass, but this command is only used for dynamic rendering "
"(vkCmdBeginRendering).");
} else {
assert(cb_state.IsSecondary());
skip |= LogError("VUID-vkCmdSetRenderingInputAttachmentIndices-commandBuffer-09518", objlist, error_obj.location,
"is not allowed in secondary command buffers using an inherited (VkCommandBufferInheritanceInfo) "
"render pass, vkCmdBeginRendering needs to have been called prior to this command.");
}
}
if (pLocationInfo->colorAttachmentCount != cb_state.GetDynamicRenderingColorAttachmentCount()) {
const Location loc = error_obj.location.dot(Struct::VkRenderingInputAttachmentIndexInfo, Field::colorAttachmentCount);
skip |= LogError("VUID-vkCmdSetRenderingInputAttachmentIndices-pInputAttachmentIndexInfo-09517", commandBuffer, loc,
"(%" PRIu32 ") is not equal to %s::colorAttachmentCount (%" PRIu32 ") when render pass began",
pLocationInfo->colorAttachmentCount,
rp_state.use_dynamic_rendering_inherited ? "VkCommandBufferInheritanceRenderingInfo" : "VkRenderingInfo",
cb_state.GetDynamicRenderingColorAttachmentCount());
}
skip |= ValidateRenderingInputAttachmentIndices(*pLocationInfo, commandBuffer, error_obj.location);
return skip;
}
bool CoreChecks::PreCallValidateCmdSetRenderingInputAttachmentIndicesKHR(
VkCommandBuffer commandBuffer, const VkRenderingInputAttachmentIndexInfoKHR *pLocationInfo,
const ErrorObject &error_obj) const {
return PreCallValidateCmdSetRenderingInputAttachmentIndices(commandBuffer, pLocationInfo, error_obj);
}
bool CoreChecks::ValidateCustomResolveCreateInfoEXT(const VkCustomResolveCreateInfoEXT &create_info, const Location &loc) const {
bool skip = false;
if (create_info.colorAttachmentCount > phys_dev_props.limits.maxColorAttachments) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-colorAttachmentCount-11507", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::colorAttachmentCount),
"(%" PRIu32
") must be less than or equal to "
"maxColorAttachments (%" PRIu32 ").",
create_info.colorAttachmentCount, phys_dev_props.limits.maxColorAttachments);
}
for (uint32_t i = 0; i < create_info.colorAttachmentCount; i++) {
const VkFormat color_format = create_info.pColorAttachmentFormats[i];
if (color_format == VK_FORMAT_UNDEFINED) {
continue;
}
if (!vkuFormatIsColor(color_format)) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-pColorAttachmentFormats-11510", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::pColorAttachmentFormats, i),
"(%s) is not a valid color format.", string_VkFormat(color_format));
} else {
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(color_format);
if ((format_features & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV)) ==
0) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-pColorAttachmentFormats-11510", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::pColorAttachmentFormats, i),
"(%s) is missing VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT or "
"VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV support\n(supported features: %s)",
string_VkFormat(color_format), string_VkFormatFeatureFlags2(format_features).c_str());
}
}
}
if (create_info.depthAttachmentFormat != VK_FORMAT_UNDEFINED) {
if (!vkuFormatHasDepth(create_info.depthAttachmentFormat)) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-depthAttachmentFormat-11508", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::depthAttachmentFormat),
"(%s) is not a valid depth format.", string_VkFormat(create_info.depthAttachmentFormat));
} else {
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(create_info.depthAttachmentFormat);
if ((format_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-depthAttachmentFormat-11509", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::depthAttachmentFormat),
"(%s) is missing VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT support\n(supported features: %s)",
string_VkFormat(create_info.depthAttachmentFormat),
string_VkFormatFeatureFlags2(format_features).c_str());
}
}
}
if (create_info.stencilAttachmentFormat != VK_FORMAT_UNDEFINED) {
if (!vkuFormatHasStencil(create_info.stencilAttachmentFormat)) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-stencilAttachmentFormat-11511", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::stencilAttachmentFormat),
"(%s) is not a valid stencil format.", string_VkFormat(create_info.stencilAttachmentFormat));
} else {
const VkFormatFeatureFlags2 format_features = GetPotentialFormatFeatures(create_info.stencilAttachmentFormat);
if ((format_features & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) == 0) {
skip |= LogError("VUID-VkCustomResolveCreateInfoEXT-stencilAttachmentFormat-11512", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::stencilAttachmentFormat),
"(%s) is missing VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT support\n(supported features: %s)",
string_VkFormat(create_info.stencilAttachmentFormat),
string_VkFormatFeatureFlags2(format_features).c_str());
}
}
if (create_info.depthAttachmentFormat != VK_FORMAT_UNDEFINED &&
create_info.stencilAttachmentFormat != VK_FORMAT_UNDEFINED &&
create_info.stencilAttachmentFormat != create_info.depthAttachmentFormat) {
skip |=
LogError("VUID-VkCustomResolveCreateInfoEXT-depthAttachmentFormat-11513", device,
loc.pNext(Struct::VkCustomResolveCreateInfoEXT, Field::stencilAttachmentFormat),
"(%s) is not the same as depthAttachmentFormat (%s).",
string_VkFormat(create_info.stencilAttachmentFormat), string_VkFormat(create_info.depthAttachmentFormat));
}
}
return skip;
}
|