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
|
/* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (C) 2015-2024 Google Inc.
* Modifications Copyright (C) 2020-2024 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 <vulkan/utility/vk_format_utils.h>
#include <vulkan/vk_enum_string_helper.h>
#include <vulkan/vulkan_core.h>
#include "core_checks/cc_buffer_address.h"
#include "core_checks/cc_state_tracker.h"
#include "drawdispatch/drawdispatch_vuids.h"
#include "core_validation.h"
#include "error_message/error_strings.h"
#include "error_message/logging.h"
#include "generated/error_location_helper.h"
#include "generated/spirv_grammar_helper.h"
#include "generated/vk_extension_helper.h"
#include "state_tracker/buffer_state.h"
#include "state_tracker/image_state.h"
#include "state_tracker/last_bound_state.h"
#include "state_tracker/shader_object_state.h"
#include "state_tracker/descriptor_sets.h"
#include "state_tracker/render_pass_state.h"
#include "state_tracker/shader_module.h"
#include "state_tracker/cmd_buffer_state.h"
#include "state_tracker/pipeline_state.h"
#include "utils/assert_utils.h"
#include "utils/math_utils.h"
#include "utils/image_utils.h"
#include "containers/container_utils.h"
using vvl::DrawDispatchVuid;
using vvl::GetDrawDispatchVuid;
bool CoreChecks::ValidateGraphicsIndexedCmd(const vvl::CommandBuffer &cb_state, const vvl::Buffer *index_buffer_state,
const DrawDispatchVuid &vuid) const {
bool skip = false;
// maintenance6 allows null buffers to be bound
if (!index_buffer_state && !cb_state.index_buffer_binding.bound) {
const char *extra =
enabled_features.maintenance6
? "Even with maintenance6, you need to set the buffer in vkCmdBindIndexBuffer to be VK_NULL_HANDLE, not "
"calling vkCmdBindIndexBuffer still has the buffer as undeclared."
: "With maintenance6, you are allowed to set the buffer in vkCmdBindIndexBuffer to be VK_NULL_HANDLE.";
skip |= LogError(
vuid.index_binding_07312, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"no vkCmdBindIndexBuffer call has bound an index buffer to this command buffer prior to this indexed draw. %s", extra);
} else if (index_buffer_state) {
skip |= ValidateProtectedBuffer(cb_state, *index_buffer_state, vuid.loc(), vuid.unprotected_command_buffer_02707,
" (Buffer is the index buffer)");
}
return skip;
}
bool CoreChecks::ValidateCmdDrawInstance(const LastBound &last_bound_state, uint32_t instanceCount, uint32_t firstInstance,
const DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const auto *pipeline_state = last_bound_state.pipeline_state;
// Verify maxMultiviewInstanceIndex
if (cb_state.active_render_pass && cb_state.active_render_pass->has_multiview_enabled &&
((static_cast<uint64_t>(instanceCount) + static_cast<uint64_t>(firstInstance)) >
static_cast<uint64_t>(phys_dev_props_core11.maxMultiviewInstanceIndex))) {
skip |=
LogError(vuid.max_multiview_instance_index_02688, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"render pass instance has multiview enabled, and maxMultiviewInstanceIndex: %" PRIu32
", but instanceCount: %" PRIu32 " and firstInstance: %" PRIu32 ".",
phys_dev_props_core11.maxMultiviewInstanceIndex, instanceCount, firstInstance);
}
// supportsNonZeroFirstInstance was added from the EXT to KHR (not 1.4) version of VK_KHR_vertex_attribute_divisor
// If not using the KHR or 1.4 version, we don't check for these VUs
if (IsExtEnabled(extensions.vk_khr_vertex_attribute_divisor)) {
if (pipeline_state && pipeline_state->GraphicsCreateInfo().pVertexInputState) {
const auto *vertex_input_divisor_state = vku::FindStructInPNextChain<VkPipelineVertexInputDivisorStateCreateInfo>(
pipeline_state->GraphicsCreateInfo().pVertexInputState->pNext);
if (vertex_input_divisor_state && phys_dev_props_core14.supportsNonZeroFirstInstance == VK_FALSE &&
firstInstance != 0u) {
for (uint32_t i = 0; i < vertex_input_divisor_state->vertexBindingDivisorCount; ++i) {
if (vertex_input_divisor_state->pVertexBindingDivisors[i].divisor != 1u) {
skip |= LogError(
vuid.vertex_input_09461, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkPipelineVertexInputDivisorStateCreateInfo::pVertexBindingDivisors[%" PRIu32 "].divisor is %" PRIu32
" and firstInstance is %" PRIu32 ", but supportsNonZeroFirstInstance is VK_FALSE.",
i, vertex_input_divisor_state->pVertexBindingDivisors[i].divisor, firstInstance);
break; // only report first instance of the error
}
}
}
}
if (last_bound_state.IsDynamic(CB_DYNAMIC_STATE_VERTEX_INPUT_EXT)) {
if (cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_VERTEX_INPUT_EXT) &&
phys_dev_props_core14.supportsNonZeroFirstInstance == VK_FALSE && firstInstance != 0u) {
for (const auto &binding_state : cb_state.dynamic_state_value.vertex_bindings) {
const auto &desc = binding_state.second.desc;
if (desc.divisor != 1u) {
skip |=
LogError(vuid.vertex_input_09462, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"vkCmdSetVertexInputEXT set pVertexBindingDivisors[%" PRIu32 "] (binding %" PRIu32
") divisor as %" PRIu32 ", but firstInstance is %" PRIu32
" and supportsNonZeroFirstInstance is VK_FALSE.",
binding_state.second.index, desc.binding, desc.divisor, firstInstance);
break;
}
}
}
}
}
return skip;
}
// VTG = Vertex Tessellation Geometry
bool CoreChecks::ValidateVTGShaderStages(const LastBound &last_bound_state, const DrawDispatchVuid &vuid) const {
bool skip = false;
if (last_bound_state.pipeline_state &&
last_bound_state.pipeline_state->active_shaders & (VK_SHADER_STAGE_TASK_BIT_EXT | VK_SHADER_STAGE_MESH_BIT_EXT)) {
skip |= LogError(
vuid.invalid_mesh_shader_stages_06481, last_bound_state.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"The bound graphics pipeline must not have been created with "
"VK_SHADER_STAGE_TASK_BIT_EXT or VK_SHADER_STAGE_MESH_BIT_EXT. Active shader stages on the bound pipeline are %s.",
string_VkShaderStageFlags(last_bound_state.pipeline_state->active_shaders).c_str());
}
return skip;
}
bool CoreChecks::ValidateMeshShaderStage(const LastBound &last_bound_state, const DrawDispatchVuid &vuid, bool is_NV) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const auto *pipeline_state = last_bound_state.pipeline_state;
if (pipeline_state && !(pipeline_state->active_shaders & VK_SHADER_STAGE_MESH_BIT_EXT)) {
skip |= LogError(vuid.missing_mesh_shader_stages_07080, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"The current pipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS must contain a shader stage using the "
"%s Execution Model. Active shader stages on the bound pipeline are %s.",
is_NV ? "MeshNV" : "MeshEXT", string_VkShaderStageFlags(pipeline_state->active_shaders).c_str());
}
if (pipeline_state &&
(pipeline_state->active_shaders & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT |
VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT | VK_SHADER_STAGE_GEOMETRY_BIT))) {
skip |= LogError(vuid.mesh_shader_stages_06480, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"The bound graphics pipeline must not have been created with "
"VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, "
"VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT or VK_SHADER_STAGE_GEOMETRY_BIT. Active shader stages on the "
"bound pipeline are %s.",
string_VkShaderStageFlags(pipeline_state->active_shaders).c_str());
}
for (const auto &query : cb_state.active_queries) {
const auto query_pool_state = Get<vvl::QueryPool>(query.pool);
if (!query_pool_state) continue;
if (query_pool_state->create_info.queryType == VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT) {
skip |= LogError(vuid.xfb_queries_07074, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"Query with type %s is active.", string_VkQueryType(query_pool_state->create_info.queryType));
}
if (query_pool_state->create_info.queryType == VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT) {
skip |= LogError(vuid.pg_queries_07075, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"Query with type %s is active.", string_VkQueryType(query_pool_state->create_info.queryType));
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount,
uint32_t firstVertex, uint32_t firstInstance, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdDrawInstance(last_bound_state, instanceCount, firstInstance, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMultiEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
const VkMultiDrawInfoEXT *pVertexInfo, uint32_t instanceCount,
uint32_t firstInstance, uint32_t stride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdDrawInstance(last_bound_state, instanceCount, firstInstance, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
if (!enabled_features.multiDraw) {
skip |= LogError("VUID-vkCmdDrawMultiEXT-None-04933", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location, "The multiDraw feature was not enabled.");
}
if (drawCount > phys_dev_ext_props.multi_draw_props.maxMultiDrawCount) {
skip |=
LogError("VUID-vkCmdDrawMultiEXT-drawCount-04934", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount), "(%" PRIu32 ") must be less than maxMultiDrawCount (%" PRIu32 ").",
drawCount, phys_dev_ext_props.multi_draw_props.maxMultiDrawCount);
}
if (drawCount > 1) {
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawMultiEXT-drawCount-09628", stride,
Struct::VkMultiDrawInfoEXT, sizeof(VkMultiDrawInfoEXT), error_obj.location);
}
if (drawCount != 0 && !pVertexInfo) {
skip |= LogError("VUID-vkCmdDrawMultiEXT-drawCount-04935", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount), "is %" PRIu32 " but pVertexInfo is NULL.", drawCount);
}
return skip;
}
bool CoreChecks::ValidateCmdDrawIndexedBufferSize(const vvl::CommandBuffer &cb_state, const vvl::Buffer &index_buffer_state,
uint32_t indexCount, uint32_t firstIndex, const Location &loc,
const char *first_index_vuid) const {
bool skip = false;
if (enabled_features.robustBufferAccess2) {
return skip;
}
const uint32_t index_size = GetIndexAlignment(cb_state.index_buffer_binding.index_type);
// This doesn't exactly match the pseudocode of the VUID, but the binding size is the *bound* size, such that the offset
// has already been accounted for (subtracted from the buffer size), and is consistent with the use of
// BufferBinding::size for vertex buffer bindings (which record the *bound* size, not the size of the bound buffer)
VkDeviceSize end_offset = static_cast<VkDeviceSize>(index_size * (firstIndex + indexCount));
if (end_offset > cb_state.index_buffer_binding.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(index_buffer_state.Handle());
skip |= LogError(first_index_vuid, objlist, loc,
"index size (%" PRIu32 ") * (firstIndex (%" PRIu32 ") + indexCount (%" PRIu32
")) "
"+ binding offset (%" PRIuLEAST64 ") = an ending offset of %" PRIuLEAST64
" bytes, which is greater than the index buffer size (%" PRIuLEAST64 ").",
index_size, firstIndex, indexCount, cb_state.index_buffer_binding.offset,
end_offset + cb_state.index_buffer_binding.offset,
cb_state.index_buffer_binding.size + cb_state.index_buffer_binding.offset);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndexed(VkCommandBuffer commandBuffer, uint32_t indexCount, uint32_t instanceCount,
uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdDrawInstance(last_bound_state, instanceCount, firstInstance, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
{
const auto index_buffer_state = Get<vvl::Buffer>(cb_state.index_buffer_binding.buffer);
skip |= ValidateGraphicsIndexedCmd(cb_state, index_buffer_state.get(), vuid);
if (index_buffer_state) {
skip |= ValidateCmdDrawIndexedBufferSize(cb_state, *index_buffer_state, indexCount, firstIndex, error_obj.location,
"VUID-vkCmdDrawIndexed-robustBufferAccess2-08798");
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMultiIndexedEXT(VkCommandBuffer commandBuffer, uint32_t drawCount,
const VkMultiDrawIndexedInfoEXT *pIndexInfo, uint32_t instanceCount,
uint32_t firstInstance, uint32_t stride, const int32_t *pVertexOffset,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdDrawInstance(last_bound_state, instanceCount, firstInstance, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
if (!enabled_features.multiDraw) {
skip |= LogError("VUID-vkCmdDrawMultiIndexedEXT-None-04937", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location, "multiDraw feature was not enabled.");
}
if (drawCount > phys_dev_ext_props.multi_draw_props.maxMultiDrawCount) {
skip |= LogError("VUID-vkCmdDrawMultiIndexedEXT-drawCount-04939", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") must be less than VkPhysicalDeviceMultiDrawPropertiesEXT::maxMultiDrawCount (%" PRIu32 ").",
drawCount, phys_dev_ext_props.multi_draw_props.maxMultiDrawCount);
}
bool invalid_stride = false;
if (drawCount > 1) {
invalid_stride = ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawMultiIndexedEXT-drawCount-09629", stride,
Struct::VkMultiDrawIndexedInfoEXT, sizeof(VkMultiDrawIndexedInfoEXT),
error_obj.location);
}
skip |= invalid_stride;
const auto index_buffer_state = Get<vvl::Buffer>(cb_state.index_buffer_binding.buffer);
skip |= ValidateGraphicsIndexedCmd(cb_state, index_buffer_state.get(), vuid);
// only index into pIndexInfo if we know parameters are sane
if (drawCount != 0 && !pIndexInfo) {
skip |= LogError("VUID-vkCmdDrawMultiIndexedEXT-drawCount-04940", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount), "is %" PRIu32 " but pIndexInfo is NULL.", drawCount);
} else if (index_buffer_state) {
// Continuing on from this point invokes undefined behavior due to invalid stride size.
if (invalid_stride) {
return skip;
}
const auto info_bytes = reinterpret_cast<const char *>(pIndexInfo);
for (uint32_t i = 0; i < drawCount; i++) {
const auto info_ptr = reinterpret_cast<const VkMultiDrawIndexedInfoEXT *>(info_bytes + i * stride);
skip |= ValidateCmdDrawIndexedBufferSize(cb_state, *index_buffer_state, info_ptr->indexCount, info_ptr->firstIndex,
error_obj.location.dot(Field::pIndexInfo, i),
"VUID-vkCmdDrawMultiIndexedEXT-robustBufferAccess2-08798");
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
uint32_t drawCount, uint32_t stride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
if (drawCount > 1) {
skip |=
ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawIndirect-drawCount-00476", stride,
Struct::VkDrawIndirectCommand, sizeof(VkDrawIndirectCommand), error_obj.location);
skip |= ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawIndirect-drawCount-00488", stride,
Struct::VkDrawIndirectCommand, sizeof(VkDrawIndirectCommand), drawCount, offset,
*indirect_buffer_state, error_obj.location);
} else if ((drawCount == 1) && (offset + sizeof(VkDrawIndirectCommand)) > indirect_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(buffer);
skip |= LogError("VUID-vkCmdDrawIndirect-drawCount-00487", objlist, error_obj.location.dot(Field::drawCount),
"is 1 and (offset + sizeof(VkDrawIndirectCommand)) (%" PRIu64
") is not less than "
"or equal to the size of buffer (%" PRIu64 ").",
(offset + sizeof(VkDrawIndirectCommand)), indirect_buffer_state->create_info.size);
}
}
if (!enabled_features.multiDrawIndirect && ((drawCount > 1))) {
skip |= LogError("VUID-vkCmdDrawIndirect-drawCount-02718", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") must be 0 or 1 if multiDrawIndirect feature is not enabled.", drawCount);
}
if (drawCount > phys_dev_props.limits.maxDrawIndirectCount) {
skip |= LogError("VUID-vkCmdDrawIndirect-drawCount-02719", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") is not less than or equal to the maximum allowed (%" PRIu32 ").", drawCount,
phys_dev_props.limits.maxDrawIndirectCount);
}
if (offset & 3) {
skip |= LogError("VUID-vkCmdDrawIndirect-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 ") must be a multiple of 4.", offset);
}
// TODO: If the drawIndirectFirstInstance feature is not enabled, all the firstInstance members of the
// VkDrawIndirectCommand structures accessed by this command must be 0, which will require access to the contents of 'buffer'.
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
uint32_t drawCount, uint32_t stride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
{
const auto index_buffer_state = Get<vvl::Buffer>(cb_state.index_buffer_binding.buffer);
skip |= ValidateGraphicsIndexedCmd(cb_state, index_buffer_state.get(), vuid);
}
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
if (drawCount > 1) {
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawIndexedIndirect-drawCount-00528", stride,
Struct::VkDrawIndexedIndirectCommand, sizeof(VkDrawIndexedIndirectCommand),
error_obj.location);
skip |= ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawIndexedIndirect-drawCount-00540", stride,
Struct::VkDrawIndexedIndirectCommand, sizeof(VkDrawIndexedIndirectCommand),
drawCount, offset, *indirect_buffer_state, error_obj.location);
} else if ((drawCount == 1) && (offset + sizeof(VkDrawIndexedIndirectCommand)) > indirect_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(buffer);
skip |= LogError("VUID-vkCmdDrawIndexedIndirect-drawCount-00539", objlist, error_obj.location.dot(Field::drawCount),
"is 1 and (offset + sizeof(VkDrawIndexedIndirectCommand)) (%" PRIu64
") is not less than "
"or equal to the size of buffer (%" PRIu64 ").",
(offset + sizeof(VkDrawIndexedIndirectCommand)), indirect_buffer_state->create_info.size);
}
if (offset & 3) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirect-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 ") must be a multiple of 4.", offset);
}
}
if (!enabled_features.multiDrawIndirect && ((drawCount > 1))) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirect-drawCount-02718", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") must be 0 or 1 if multiDrawIndirect feature is not enabled.", drawCount);
}
if (drawCount > phys_dev_props.limits.maxDrawIndirectCount) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirect-drawCount-02719", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") is not less than or equal to the maximum allowed (%" PRIu32 ").", drawCount,
phys_dev_props.limits.maxDrawIndirectCount);
}
// TODO: If the drawIndirectFirstInstance feature is not enabled, all the firstInstance members of the
// VkDrawIndexedIndirectCommand structures accessed by this command must be 0, which will require access to the contents of
// 'buffer'.
return skip;
}
bool CoreChecks::PreCallValidateCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
uint32_t groupCountZ, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundCompute();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
if (groupCountX > phys_dev_props.limits.maxComputeWorkGroupCount[0]) {
skip |= LogError("VUID-vkCmdDispatch-groupCountX-00386", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::groupCountX),
"(%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").", groupCountX,
phys_dev_props.limits.maxComputeWorkGroupCount[0]);
}
if (groupCountY > phys_dev_props.limits.maxComputeWorkGroupCount[1]) {
skip |= LogError("VUID-vkCmdDispatch-groupCountY-00387", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::groupCountY),
"(%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").", groupCountY,
phys_dev_props.limits.maxComputeWorkGroupCount[1]);
}
if (groupCountZ > phys_dev_props.limits.maxComputeWorkGroupCount[2]) {
skip |= LogError("VUID-vkCmdDispatch-groupCountZ-00388", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::groupCountZ),
"(%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").", groupCountZ,
phys_dev_props.limits.maxComputeWorkGroupCount[2]);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDispatchBase(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY,
uint32_t groupCountZ, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundCompute();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
// Paired if {} else if {} tests used to avoid any possible uint underflow
uint32_t limit = phys_dev_props.limits.maxComputeWorkGroupCount[0];
if (baseGroupX >= limit) {
skip |=
LogError("VUID-vkCmdDispatchBase-baseGroupX-00421", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupX),
"(%" PRIu32 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").", baseGroupX, limit);
} else if (groupCountX > (limit - baseGroupX)) {
skip |=
LogError("VUID-vkCmdDispatchBase-groupCountX-00424", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupX),
"(%" PRIu32 ") + groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 ").",
baseGroupX, groupCountX, limit);
}
limit = phys_dev_props.limits.maxComputeWorkGroupCount[1];
if (baseGroupY >= limit) {
skip |=
LogError("VUID-vkCmdDispatchBase-baseGroupX-00422", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupY),
"(%" PRIu32 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").", baseGroupY, limit);
} else if (groupCountY > (limit - baseGroupY)) {
skip |=
LogError("VUID-vkCmdDispatchBase-groupCountY-00425", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupY),
"(%" PRIu32 ") + groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 ").",
baseGroupY, groupCountY, limit);
}
limit = phys_dev_props.limits.maxComputeWorkGroupCount[2];
if (baseGroupZ >= limit) {
skip |=
LogError("VUID-vkCmdDispatchBase-baseGroupZ-00423", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupZ),
"(%" PRIu32 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").", baseGroupZ, limit);
} else if (groupCountZ > (limit - baseGroupZ)) {
skip |=
LogError("VUID-vkCmdDispatchBase-groupCountZ-00426", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::baseGroupZ),
"(%" PRIu32 ") + groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 ").",
baseGroupZ, groupCountZ, limit);
}
if (baseGroupX || baseGroupY || baseGroupZ) {
if (last_bound_state.pipeline_state) {
if (!(last_bound_state.pipeline_state->create_flags & VK_PIPELINE_CREATE_DISPATCH_BASE)) {
skip |= LogError("VUID-vkCmdDispatchBase-baseGroupX-00427", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location,
"If any of baseGroupX (%" PRIu32 "), baseGroupY (%" PRIu32 "), or baseGroupZ (%" PRIu32
") are not zero, then the bound compute pipeline "
"must have been created with the VK_PIPELINE_CREATE_DISPATCH_BASE flag",
baseGroupX, baseGroupY, baseGroupZ);
}
} else {
const auto *shader_object = last_bound_state.GetShaderObjectState(ShaderObjectStage::COMPUTE);
if (shader_object && ((shader_object->create_info.flags & VK_SHADER_CREATE_DISPATCH_BASE_BIT_EXT) == 0)) {
skip |= LogError("VUID-vkCmdDispatchBase-baseGroupX-00427", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location,
"If any of baseGroupX (%" PRIu32 "), baseGroupY (%" PRIu32 "), or baseGroupZ (%" PRIu32
") are not zero, then the bound compute shader object "
"must have been created with the VK_SHADER_CREATE_DISPATCH_BASE_BIT_EXT flag",
baseGroupX, baseGroupY, baseGroupZ);
}
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY,
uint32_t baseGroupZ, uint32_t groupCountX, uint32_t groupCountY,
uint32_t groupCountZ, const ErrorObject &error_obj) const {
return PreCallValidateCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ,
error_obj);
}
bool CoreChecks::PreCallValidateCmdDispatchIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundCompute();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
if (offset & 3) {
skip |= LogError("VUID-vkCmdDispatchIndirect-offset-02710", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location.dot(Field::offset), "(%" PRIu64 ") must be a multiple of 4.", offset);
}
if ((offset + sizeof(VkDispatchIndirectCommand)) > indirect_buffer_state->create_info.size) {
skip |= LogError("VUID-vkCmdDispatchIndirect-offset-00407", cb_state.GetObjectList(VK_SHADER_STAGE_COMPUTE_BIT),
error_obj.location,
"The (offset + sizeof(VkDispatchIndirectCommand)) (%" PRIu64
") is greater than the size of the buffer (%" PRIu64 ").",
offset + sizeof(VkDispatchIndirectCommand), indirect_buffer_state->create_info.size);
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
if (offset & 3) {
skip |= LogError("VUID-vkCmdDrawIndirectCount-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 "), is not a multiple of 4.", offset);
}
if (countBufferOffset & 3) {
skip |=
LogError("VUID-vkCmdDrawIndirectCount-countBufferOffset-02716", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::countBufferOffset), "(%" PRIu64 "), is not a multiple of 4.", countBufferOffset);
}
if ((extensions.vk_khr_draw_indirect_count != kEnabledByCreateinfo) &&
((api_version >= VK_API_VERSION_1_2) && (enabled_features.drawIndirectCount == VK_FALSE))) {
skip |= LogError("VUID-vkCmdDrawIndirectCount-None-04445", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location,
"Starting in Vulkan 1.2 the VkPhysicalDeviceVulkan12Features::drawIndirectCount must be enabled to "
"call this command.");
}
{
auto count_buffer_state = Get<vvl::Buffer>(countBuffer);
ASSERT_AND_RETURN_SKIP(count_buffer_state);
skip |= ValidateIndirectCountCmd(cb_state, *count_buffer_state, countBufferOffset, vuid);
}
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawIndirectCount-stride-03110", stride,
Struct::VkDrawIndirectCommand, sizeof(VkDrawIndirectCommand), error_obj.location);
if (maxDrawCount > 1) {
skip |= ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawIndirectCount-maxDrawCount-03111", stride,
Struct::VkDrawIndirectCommand, sizeof(VkDrawIndirectCommand), maxDrawCount,
offset, *indirect_buffer_state, error_obj.location);
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride, const ErrorObject &error_obj) const {
return PreCallValidateCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride,
error_obj);
}
bool CoreChecks::PreCallValidateCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset,
uint32_t maxDrawCount, uint32_t stride,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
if (offset & 3) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirectCount-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 "), is not a multiple of 4.", offset);
}
if (countBufferOffset & 3) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirectCount-countBufferOffset-02716",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::countBufferOffset),
"(%" PRIu64 "), is not a multiple of 4.", countBufferOffset);
}
if ((extensions.vk_khr_draw_indirect_count != kEnabledByCreateinfo) &&
((api_version >= VK_API_VERSION_1_2) && (enabled_features.drawIndirectCount == VK_FALSE))) {
skip |= LogError("VUID-vkCmdDrawIndexedIndirectCount-None-04445", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location,
"Starting in Vulkan 1.2 the VkPhysicalDeviceVulkan12Features::drawIndirectCount must be enabled to "
"call this command.");
}
{
auto count_buffer_state = Get<vvl::Buffer>(countBuffer);
ASSERT_AND_RETURN_SKIP(count_buffer_state);
skip |= ValidateIndirectCountCmd(cb_state, *count_buffer_state, countBufferOffset, vuid);
}
{
const auto index_buffer_state = Get<vvl::Buffer>(cb_state.index_buffer_binding.buffer);
skip |= ValidateGraphicsIndexedCmd(cb_state, index_buffer_state.get(), vuid);
}
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
if (maxDrawCount > 1) {
skip |= ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawIndexedIndirectCount-maxDrawCount-03143", stride,
Struct::VkDrawIndexedIndirectCommand, sizeof(VkDrawIndexedIndirectCommand),
maxDrawCount, offset, *indirect_buffer_state, error_obj.location);
}
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawIndexedIndirectCount-stride-03142", stride,
Struct::VkDrawIndexedIndirectCommand, sizeof(VkDrawIndexedIndirectCommand),
error_obj.location);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset,
uint32_t maxDrawCount, uint32_t stride,
const ErrorObject &error_obj) const {
return PreCallValidateCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount,
stride, error_obj);
}
bool CoreChecks::PreCallValidateCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, uint32_t instanceCount,
uint32_t firstInstance, VkBuffer counterBuffer,
VkDeviceSize counterBufferOffset, uint32_t counterOffset,
uint32_t vertexStride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdDrawInstance(last_bound_state, instanceCount, firstInstance, vuid);
skip |= ValidateVTGShaderStages(last_bound_state, vuid);
if (!enabled_features.transformFeedback) {
skip |= LogError("VUID-vkCmdDrawIndirectByteCountEXT-transformFeedback-02287",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location,
"transformFeedback feature is not enabled.");
}
if (IsExtEnabled(extensions.vk_ext_transform_feedback) && !phys_dev_ext_props.transform_feedback_props.transformFeedbackDraw) {
skip |= LogError("VUID-vkCmdDrawIndirectByteCountEXT-transformFeedbackDraw-02288",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location,
"VkPhysicalDeviceTransformFeedbackPropertiesEXT::transformFeedbackDraw is not supported");
}
if ((vertexStride <= 0) || (vertexStride > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride)) {
skip |= LogError("VUID-vkCmdDrawIndirectByteCountEXT-vertexStride-02289",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::vertexStride),
"(%" PRIu32 ") must be between 0 and maxTransformFeedbackBufferDataStride (%" PRIu32 ").", vertexStride,
phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride);
}
if (SafeModulo(counterBufferOffset, 4) != 0) {
skip |= LogError(
"VUID-vkCmdDrawIndirectByteCountEXT-counterBufferOffset-04568", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::counterBufferOffset), "(%" PRIu64 ") must be a multiple of 4.", counterBufferOffset);
}
// VUs being added in https://gitlab.khronos.org/vulkan/vulkan/-/merge_requests/6310
if (SafeModulo(counterOffset, 4) != 0) {
skip |= LogError("VUID-vkCmdDrawIndirectByteCountEXT-counterOffset-09474",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::counterOffset),
"(%" PRIu32 ") must be a multiple of 4.", counterOffset);
}
if (SafeModulo(vertexStride, 4) != 0) {
skip |= LogError("VUID-vkCmdDrawIndirectByteCountEXT-vertexStride-09475",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::vertexStride),
"(%" PRIu32 ") must be a multiple of 4.", vertexStride);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdTraceRaysNV(VkCommandBuffer commandBuffer, VkBuffer raygenShaderBindingTableBuffer,
VkDeviceSize raygenShaderBindingOffset, VkBuffer missShaderBindingTableBuffer,
VkDeviceSize missShaderBindingOffset, VkDeviceSize missShaderBindingStride,
VkBuffer hitShaderBindingTableBuffer, VkDeviceSize hitShaderBindingOffset,
VkDeviceSize hitShaderBindingStride, VkBuffer callableShaderBindingTableBuffer,
VkDeviceSize callableShaderBindingOffset, VkDeviceSize callableShaderBindingStride,
uint32_t width, uint32_t height, uint32_t depth,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundRayTracing();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
if (SafeModulo(callableShaderBindingOffset, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupBaseAlignment) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-callableShaderBindingOffset-02462",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::callableShaderBindingOffset),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
}
if (SafeModulo(callableShaderBindingStride, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupHandleSize) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02465",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::callableShaderBindingStride),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
}
if (callableShaderBindingStride > phys_dev_ext_props.ray_tracing_props_nv.maxShaderGroupStride) {
skip |= LogError("VUID-vkCmdTraceRaysNV-callableShaderBindingStride-02468",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::callableShaderBindingStride),
"must be less than or equal to "
"VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride. ");
}
// hitShader
if (SafeModulo(hitShaderBindingOffset, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupBaseAlignment) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-hitShaderBindingOffset-02460",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::hitShaderBindingOffset),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
}
if (SafeModulo(hitShaderBindingStride, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupHandleSize) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02464",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::hitShaderBindingStride),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
}
if (hitShaderBindingStride > phys_dev_ext_props.ray_tracing_props_nv.maxShaderGroupStride) {
skip |= LogError("VUID-vkCmdTraceRaysNV-hitShaderBindingStride-02467",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::hitShaderBindingStride),
"must be less than or equal to "
"VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride.");
}
// missShader
if (SafeModulo(missShaderBindingOffset, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupBaseAlignment) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-missShaderBindingOffset-02458",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::missShaderBindingOffset),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
}
if (SafeModulo(missShaderBindingStride, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupHandleSize) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-missShaderBindingStride-02463",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::missShaderBindingStride),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupHandleSize.");
}
if (missShaderBindingStride > phys_dev_ext_props.ray_tracing_props_nv.maxShaderGroupStride) {
skip |= LogError("VUID-vkCmdTraceRaysNV-missShaderBindingStride-02466",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::missShaderBindingStride),
"must be less than or equal to "
"VkPhysicalDeviceRayTracingPropertiesNV::maxShaderGroupStride.");
}
// raygenShader
if (SafeModulo(raygenShaderBindingOffset, phys_dev_ext_props.ray_tracing_props_nv.shaderGroupBaseAlignment) != 0) {
skip |= LogError("VUID-vkCmdTraceRaysNV-raygenShaderBindingOffset-02456",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::raygenShaderBindingOffset),
"must be a multiple of "
"VkPhysicalDeviceRayTracingPropertiesNV::shaderGroupBaseAlignment.");
}
if (width > phys_dev_props.limits.maxComputeWorkGroupCount[0]) {
skip |= LogError("VUID-vkCmdTraceRaysNV-width-02469", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::width),
"must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[0].");
}
if (height > phys_dev_props.limits.maxComputeWorkGroupCount[1]) {
skip |= LogError("VUID-vkCmdTraceRaysNV-height-02470", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::height),
"must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[1].");
}
if (depth > phys_dev_props.limits.maxComputeWorkGroupCount[2]) {
skip |= LogError("VUID-vkCmdTraceRaysNV-depth-02471", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR),
error_obj.location.dot(Field::depth),
"must be less than or equal to VkPhysicalDeviceLimits::maxComputeWorkGroupCount[2].");
}
auto callable_shader_buffer_state = Get<vvl::Buffer>(callableShaderBindingTableBuffer);
if (callable_shader_buffer_state && callableShaderBindingOffset >= callable_shader_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
objlist.add(callableShaderBindingTableBuffer);
skip |= LogError("VUID-vkCmdTraceRaysNV-callableShaderBindingOffset-02461", objlist,
error_obj.location.dot(Field::callableShaderBindingOffset),
"%" PRIu64 " must be less than the size of callableShaderBindingTableBuffer %" PRIu64 " .",
callableShaderBindingOffset, callable_shader_buffer_state->create_info.size);
}
auto hit_shader_buffer_state = Get<vvl::Buffer>(hitShaderBindingTableBuffer);
if (hit_shader_buffer_state && hitShaderBindingOffset >= hit_shader_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
objlist.add(hitShaderBindingTableBuffer);
skip |= LogError("VUID-vkCmdTraceRaysNV-hitShaderBindingOffset-02459", objlist,
error_obj.location.dot(Field::hitShaderBindingOffset),
"%" PRIu64 " must be less than the size of hitShaderBindingTableBuffer %" PRIu64 " .",
hitShaderBindingOffset, hit_shader_buffer_state->create_info.size);
}
auto miss_shader_buffer_state = Get<vvl::Buffer>(missShaderBindingTableBuffer);
if (miss_shader_buffer_state && missShaderBindingOffset >= miss_shader_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
objlist.add(missShaderBindingTableBuffer);
skip |= LogError("VUID-vkCmdTraceRaysNV-missShaderBindingOffset-02457", objlist,
error_obj.location.dot(Field::missShaderBindingOffset),
"%" PRIu64 " must be less than the size of missShaderBindingTableBuffer %" PRIu64 " .",
missShaderBindingOffset, miss_shader_buffer_state->create_info.size);
}
auto raygen_shader_buffer_state = Get<vvl::Buffer>(raygenShaderBindingTableBuffer);
if (raygenShaderBindingOffset >= raygen_shader_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR);
objlist.add(raygenShaderBindingTableBuffer);
skip |= LogError("VUID-vkCmdTraceRaysNV-raygenShaderBindingOffset-02455", objlist,
error_obj.location.dot(Field::raygenShaderBindingOffset),
"%" PRIu64 " must be less than the size of raygenShaderBindingTableBuffer %" PRIu64 " .",
raygenShaderBindingOffset, raygen_shader_buffer_state->create_info.size);
}
return skip;
}
bool CoreChecks::ValidateCmdTraceRaysKHR(const Location &loc, const LastBound &last_bound_state,
const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable) const {
bool skip = false;
const vvl::Pipeline *pipeline_state = last_bound_state.pipeline_state;
if (!pipeline_state) return skip; // possible wasn't bound correctly, check caught elsewhere
const bool is_indirect = loc.function == Func::vkCmdTraceRaysIndirectKHR;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
if (pHitShaderBindingTable) {
const Location table_loc = loc.dot(Field::pHitShaderBindingTable);
if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR) {
if ((pHitShaderBindingTable->size == 0 || pHitShaderBindingTable->stride == 0)) {
const char *vuid =
is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-flags-03514" : "VUID-vkCmdTraceRaysKHR-flags-03514";
skip |= LogError(vuid, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR), table_loc,
"either size (%" PRIu64 ") and stride (%" PRIu64 ") is zero.", pHitShaderBindingTable->size,
pHitShaderBindingTable->stride);
}
}
if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR) {
if ((pHitShaderBindingTable->size == 0 || pHitShaderBindingTable->stride == 0)) {
const char *vuid =
is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-flags-03513" : "VUID-vkCmdTraceRaysKHR-flags-03513";
skip |= LogError(vuid, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR), table_loc,
"either size (%" PRIu64 ") and stride (%" PRIu64 ") is zero.", pHitShaderBindingTable->size,
pHitShaderBindingTable->stride);
}
}
if (pipeline_state->create_flags & VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR) {
// No vuid to check for pHitShaderBindingTable->deviceAddress == 0 with this flag
if (pHitShaderBindingTable->size == 0 || pHitShaderBindingTable->stride == 0) {
const char *vuid =
is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-flags-03512" : "VUID-vkCmdTraceRaysKHR-flags-03512";
skip |= LogError(vuid, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR), table_loc,
"either size (%" PRIu64 ") and stride (%" PRIu64 ") is zero.", pHitShaderBindingTable->size,
pHitShaderBindingTable->stride);
}
}
const char *vuid_binding_table_flag = is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-pHitShaderBindingTable-03688"
: "VUID-vkCmdTraceRaysKHR-pHitShaderBindingTable-03688";
skip |= ValidateRaytracingShaderBindingTable(cb_state, table_loc, vuid_binding_table_flag, *pHitShaderBindingTable);
}
if (pRaygenShaderBindingTable) {
const Location table_loc = loc.dot(Field::pRaygenShaderBindingTable);
const char *vuid_binding_table_flag = is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-pRayGenShaderBindingTable-03681"
: "VUID-vkCmdTraceRaysKHR-pRayGenShaderBindingTable-03681";
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/9368
// TODO - waiting for https://gitlab.khronos.org/vulkan/vulkan/-/issues/4173
if (const auto buffers = GetBuffersByAddress(pRaygenShaderBindingTable->deviceAddress); buffers.empty()) {
skip |= LogError("UNASSIGNED-TraceRays-InvalidRayGenSBTAddress",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR), table_loc.dot(Field::deviceAddress),
"(0x%" PRIx64 ") does not belong to a valid VkBuffer.", pRaygenShaderBindingTable->deviceAddress);
}
skip |= ValidateRaytracingShaderBindingTable(cb_state, table_loc, vuid_binding_table_flag, *pRaygenShaderBindingTable);
}
if (pMissShaderBindingTable) {
const Location table_loc = loc.dot(Field::pMissShaderBindingTable);
const char *vuid_binding_table_flag = is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-pMissShaderBindingTable-03684"
: "VUID-vkCmdTraceRaysKHR-pMissShaderBindingTable-03684";
skip |= ValidateRaytracingShaderBindingTable(cb_state, table_loc, vuid_binding_table_flag, *pMissShaderBindingTable);
}
if (pCallableShaderBindingTable) {
const Location table_loc = loc.dot(Field::pCallableShaderBindingTable);
const char *vuid_binding_table_flag = is_indirect ? "VUID-vkCmdTraceRaysIndirectKHR-pCallableShaderBindingTable-03692"
: "VUID-vkCmdTraceRaysKHR-pCallableShaderBindingTable-03692";
skip |= ValidateRaytracingShaderBindingTable(cb_state, table_loc, vuid_binding_table_flag, *pCallableShaderBindingTable);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdTraceRaysKHR(VkCommandBuffer commandBuffer,
const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable, uint32_t width,
uint32_t height, uint32_t depth, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundRayTracing();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdTraceRaysKHR(error_obj.location, last_bound_state, pRaygenShaderBindingTable, pMissShaderBindingTable,
pHitShaderBindingTable, pCallableShaderBindingTable);
return skip;
}
bool CoreChecks::ValidateCmdTraceRaysIndirect(const Location &loc, const LastBound &last_bound_state,
VkDeviceAddress indirect_device_address) const {
bool skip = false;
const bool is_2khr = loc.function == Func::vkCmdTraceRaysIndirect2KHR;
const char *usage_vuid = is_2khr ? "VUID-vkCmdTraceRaysIndirect2KHR-indirectDeviceAddress-03633"
: "VUID-vkCmdTraceRaysIndirectKHR-indirectDeviceAddress-03633";
BufferAddressValidation<1> buffer_address_validator = {
{{{usage_vuid,
[](const vvl::Buffer &buffer_state) { return (buffer_state.usage & VK_BUFFER_USAGE_2_INDIRECT_BUFFER_BIT) == 0; },
[]() { return "The following buffers are missing VK_BUFFER_USAGE_2_INDIRECT_BUFFER_BIT"; }, kUsageErrorMsgBuffer}}}};
skip |= buffer_address_validator.ValidateDeviceAddress(
*this, loc.dot(Field::indirectDeviceAddress), LogObjectList(last_bound_state.cb_state.Handle()), indirect_device_address);
return skip;
}
bool CoreChecks::PreCallValidateCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer,
const VkStridedDeviceAddressRegionKHR *pRaygenShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pMissShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pHitShaderBindingTable,
const VkStridedDeviceAddressRegionKHR *pCallableShaderBindingTable,
VkDeviceAddress indirectDeviceAddress, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundRayTracing();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdTraceRaysKHR(error_obj.location, last_bound_state, pRaygenShaderBindingTable, pMissShaderBindingTable,
pHitShaderBindingTable, pCallableShaderBindingTable);
skip |= ValidateCmdTraceRaysIndirect(error_obj.location, last_bound_state, indirectDeviceAddress);
return skip;
}
bool CoreChecks::PreCallValidateCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, VkDeviceAddress indirectDeviceAddress,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundRayTracing();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateCmdTraceRaysIndirect(error_obj.location, last_bound_state, indirectDeviceAddress);
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksNV(VkCommandBuffer commandBuffer, uint32_t taskCount, uint32_t firstTask,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, true);
if (taskCount > phys_dev_ext_props.mesh_shader_props_nv.maxDrawMeshTasksCount) {
skip |= LogError(
"VUID-vkCmdDrawMeshTasksNV-taskCount-02119", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::taskCount),
"(0x%" PRIxLEAST32
"), must be less than or equal to VkPhysicalDeviceMeshShaderPropertiesNV::maxDrawMeshTasksCount (0x%" PRIxLEAST32 ").",
taskCount, phys_dev_ext_props.mesh_shader_props_nv.maxDrawMeshTasksCount);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksIndirectNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
uint32_t drawCount, uint32_t stride,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, true);
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
if (drawCount > 1) {
skip |= ValidateCmdDrawStrideWithBuffer(
cb_state, "VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02157", stride, Struct::VkDrawMeshTasksIndirectCommandNV,
sizeof(VkDrawMeshTasksIndirectCommandNV), drawCount, offset, *indirect_buffer_state, error_obj.location);
if (!enabled_features.multiDrawIndirect) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02718",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") must be 0 or 1 if multiDrawIndirect feature is not enabled.", drawCount);
}
if ((stride & 3) || stride < sizeof(VkDrawMeshTasksIndirectCommandNV)) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02146",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::stride),
"(0x%" PRIxLEAST32
"), is not a multiple of 4 or smaller than sizeof (VkDrawMeshTasksIndirectCommandNV).",
stride);
}
} else if (drawCount == 1 &&
((offset + sizeof(VkDrawMeshTasksIndirectCommandNV)) > indirect_buffer_state.get()->create_info.size)) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(buffer);
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02156", objlist, error_obj.location,
"(offset + sizeof(VkDrawMeshTasksIndirectNV)) (%" PRIu64
") is greater than the size of buffer (%" PRIu64 ").",
offset + sizeof(VkDrawMeshTasksIndirectCommandNV), indirect_buffer_state->create_info.size);
}
}
if (offset & 3) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectNV-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 "), is not a multiple of 4.", offset);
}
if (drawCount > phys_dev_props.limits.maxDrawIndirectCount) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectNV-drawCount-02719",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") is not less than or equal to maxDrawIndirectCount (%" PRIu32 ").", drawCount,
phys_dev_props.limits.maxDrawIndirectCount);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksIndirectCountNV(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkBuffer countBuffer, VkDeviceSize countBufferOffset,
uint32_t maxDrawCount, uint32_t stride,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, true);
if (offset & 3) {
skip |=
LogError("VUID-vkCmdDrawMeshTasksIndirectCountNV-offset-02710", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::offset), "(%" PRIu64 "), is not a multiple of 4.", offset);
}
if (countBufferOffset & 3) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectCountNV-countBufferOffset-02716",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::countBufferOffset),
"(%" PRIu64 "), is not a multiple of 4.", countBufferOffset);
}
{
auto count_buffer_state = Get<vvl::Buffer>(countBuffer);
ASSERT_AND_RETURN_SKIP(count_buffer_state);
skip |= ValidateIndirectCountCmd(cb_state, *count_buffer_state, countBufferOffset, vuid);
}
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawMeshTasksIndirectCountNV-stride-02182", stride,
Struct::VkDrawMeshTasksIndirectCommandNV, sizeof(VkDrawMeshTasksIndirectCommandNV),
error_obj.location);
if (maxDrawCount > 1) {
skip |=
ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawMeshTasksIndirectCountNV-maxDrawCount-02183", stride,
Struct::VkDrawMeshTasksIndirectCommandNV, sizeof(VkDrawMeshTasksIndirectCommandNV),
maxDrawCount, offset, *indirect_buffer_state, error_obj.location);
}
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksEXT(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY,
uint32_t groupCountZ, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, false);
if (groupCountX > phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[0]) {
skip |= LogError(
"VUID-vkCmdDrawMeshTasksEXT-TaskEXT-07322", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::groupCountX),
"(0x%" PRIxLEAST32
"), must be less than or equal to VkPhysicalDeviceMeshShaderPropertiesEXT::maxTaskWorkGroupCount[0] (0x%" PRIxLEAST32
").",
groupCountX, phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[0]);
}
if (groupCountY > phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[1]) {
skip |= LogError(
"VUID-vkCmdDrawMeshTasksEXT-TaskEXT-07323", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::groupCountY),
"(0x%" PRIxLEAST32
"), must be less than or equal to VkPhysicalDeviceMeshShaderPropertiesEXT::maxTaskWorkGroupCount[1] (0x%" PRIxLEAST32
").",
groupCountY, phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[1]);
}
if (groupCountZ > phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[2]) {
skip |= LogError(
"VUID-vkCmdDrawMeshTasksEXT-TaskEXT-07324", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
error_obj.location.dot(Field::groupCountZ),
"(0x%" PRIxLEAST32
"), must be less than or equal to VkPhysicalDeviceMeshShaderPropertiesEXT::maxTaskWorkGroupCount[2] (0x%" PRIxLEAST32
").",
groupCountZ, phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupCount[2]);
}
uint32_t maxTaskWorkGroupTotalCount = phys_dev_ext_props.mesh_shader_props_ext.maxTaskWorkGroupTotalCount;
uint64_t invocations = static_cast<uint64_t>(groupCountX) * static_cast<uint64_t>(groupCountY);
// Prevent overflow.
bool fail = false;
if (invocations > vvl::kU32Max || invocations > maxTaskWorkGroupTotalCount) {
fail = true;
}
if (!fail) {
invocations *= static_cast<uint64_t>(groupCountZ);
if (invocations > vvl::kU32Max || invocations > maxTaskWorkGroupTotalCount) {
fail = true;
}
}
if (fail) {
skip |= LogError(
"VUID-vkCmdDrawMeshTasksEXT-TaskEXT-07325", cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location,
"The product of groupCountX (0x%" PRIxLEAST32 "), groupCountY (0x%" PRIxLEAST32 ") and groupCountZ (0x%" PRIxLEAST32
") must be less than or equal to "
"VkPhysicalDeviceMeshShaderPropertiesEXT::maxTaskWorkGroupTotalCount (0x%" PRIxLEAST32 ").",
groupCountX, groupCountY, groupCountZ, maxTaskWorkGroupTotalCount);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksIndirectEXT(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
uint32_t drawCount, uint32_t stride,
const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, false);
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
if (drawCount > 1) {
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawMeshTasksIndirectEXT-drawCount-07088", stride,
Struct::VkDrawMeshTasksIndirectCommandEXT,
sizeof(VkDrawMeshTasksIndirectCommandEXT), error_obj.location);
skip |= ValidateCmdDrawStrideWithBuffer(
cb_state, "VUID-vkCmdDrawMeshTasksIndirectEXT-drawCount-07090", stride, Struct::VkDrawMeshTasksIndirectCommandEXT,
sizeof(VkDrawMeshTasksIndirectCommandEXT), drawCount, offset, *indirect_buffer_state, error_obj.location);
}
if ((drawCount == 1) && (offset + sizeof(VkDrawMeshTasksIndirectCommandEXT)) > indirect_buffer_state->create_info.size) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(buffer);
skip |=
LogError("VUID-vkCmdDrawMeshTasksIndirectEXT-drawCount-07089", objlist, error_obj.location.dot(Field::drawCount),
"is 1 and (offset + sizeof(VkDrawMeshTasksIndirectCommandEXT)) (%" PRIu64
") is not less than "
"or equal to the size of buffer (%" PRIu64 ").",
(offset + sizeof(VkDrawMeshTasksIndirectCommandEXT)), indirect_buffer_state->create_info.size);
}
}
// TODO: vkMapMemory() and check the contents of buffer at offset
// issue #4547 (https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/4547)
if (!enabled_features.multiDrawIndirect && ((drawCount > 1))) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectEXT-drawCount-02718",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::drawCount),
"(%" PRIu32 ") must be 0 or 1 if multiDrawIndirect feature is not enabled.", drawCount);
}
if (drawCount > phys_dev_props.limits.maxDrawIndirectCount) {
skip |= LogError("VUID-vkCmdDrawMeshTasksIndirectEXT-drawCount-02719",
cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), error_obj.location.dot(Field::drawCount),
"%" PRIu32 ") is not less than or equal to maxDrawIndirectCount (%" PRIu32 ").", drawCount,
phys_dev_props.limits.maxDrawIndirectCount);
}
return skip;
}
bool CoreChecks::PreCallValidateCmdDrawMeshTasksIndirectCountEXT(VkCommandBuffer commandBuffer, VkBuffer buffer,
VkDeviceSize offset, VkBuffer countBuffer,
VkDeviceSize countBufferOffset, uint32_t maxDrawCount,
uint32_t stride, const ErrorObject &error_obj) const {
bool skip = false;
const auto &cb_state = *GetRead<vvl::CommandBuffer>(commandBuffer);
const auto &last_bound_state = cb_state.GetLastBoundGraphics();
const DrawDispatchVuid &vuid = GetDrawDispatchVuid(error_obj.location.function);
skip |= ValidateActionState(last_bound_state, vuid);
skip |= ValidateMeshShaderStage(last_bound_state, vuid, false);
auto count_buffer_state = Get<vvl::Buffer>(countBuffer);
ASSERT_AND_RETURN_SKIP(count_buffer_state);
skip |= ValidateMemoryIsBoundToBuffer(commandBuffer, *count_buffer_state, error_obj.location.dot(Field::countBuffer),
vuid.indirect_count_contiguous_memory_02714);
skip |= ValidateBufferUsageFlags(LogObjectList(commandBuffer, countBuffer), *count_buffer_state,
VK_BUFFER_USAGE_2_INDIRECT_BUFFER_BIT, true, vuid.indirect_count_buffer_bit_02715,
error_obj.location.dot(Field::countBuffer));
{
auto indirect_buffer_state = Get<vvl::Buffer>(buffer);
ASSERT_AND_RETURN_SKIP(indirect_buffer_state);
skip |= ValidateIndirectCmd(cb_state, *indirect_buffer_state, vuid);
skip |= ValidateCmdDrawStrideWithStruct(cb_state, "VUID-vkCmdDrawMeshTasksIndirectCountEXT-stride-07096", stride,
Struct::VkDrawMeshTasksIndirectCommandEXT,
sizeof(VkDrawMeshTasksIndirectCommandEXT), error_obj.location);
if (maxDrawCount > 1) {
skip |= ValidateCmdDrawStrideWithBuffer(cb_state, "VUID-vkCmdDrawMeshTasksIndirectCountEXT-maxDrawCount-07097", stride,
Struct::VkDrawMeshTasksIndirectCommandEXT,
sizeof(VkDrawMeshTasksIndirectCommandEXT), maxDrawCount, offset,
*indirect_buffer_state, error_obj.location);
}
}
return skip;
}
// Action command == vkCmdDraw*, vkCmdDispatch*, vkCmdTraceRays*
// This is the main logic shared by all action commands
bool CoreChecks::ValidateActionState(const LastBound &last_bound_state, const DrawDispatchVuid &vuid) const {
const Location &loc = vuid.loc();
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const vvl::Pipeline *pipeline = last_bound_state.pipeline_state;
const VkPipelineBindPoint bind_point = last_bound_state.bind_point;
bool skip = false;
skip |= ValidateCmd(cb_state, loc);
// Quick verify that if there is no pipeline, the shader object is being used
if (!pipeline && !enabled_features.shaderObject) {
return LogError(vuid.pipeline_bound_08606, cb_state.GetObjectList(bind_point), loc,
"A valid %s pipeline must be bound with vkCmdBindPipeline before calling this command.",
string_VkPipelineBindPoint(bind_point));
}
if (bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS) {
skip |= ValidateDrawDynamicState(last_bound_state, vuid);
skip |= ValidateDrawPrimitivesGeneratedQuery(last_bound_state, vuid);
skip |= ValidateDrawProtectedMemory(last_bound_state, vuid);
skip |= ValidateDrawFragmentShadingRate(last_bound_state, vuid);
skip |= ValidateDrawAttachmentColorBlend(last_bound_state, vuid);
skip |= ValidateDrawAttachmentSampleLocation(last_bound_state, vuid);
skip |= ValidateDrawDepthStencilAttachments(last_bound_state, vuid);
skip |= ValidateDrawTessellation(last_bound_state, vuid);
skip |= ValidateDrawVertexBinding(last_bound_state, vuid);
if (cb_state.active_render_pass && cb_state.active_render_pass->UsesDynamicRendering()) {
skip |= ValidateDrawDynamicRenderingFsOutputs(last_bound_state, cb_state, loc);
skip |= ValidateDrawDynamicRenderpassExternalFormatResolve(last_bound_state, *cb_state.active_render_pass, vuid);
const auto &cb_sub_state = core::SubState(cb_state);
skip |= ValidateDrawCustomResolve(last_bound_state, *cb_state.active_render_pass, cb_sub_state, vuid);
}
if (pipeline) {
skip |= ValidateDrawPipeline(last_bound_state, *pipeline, vuid);
} else {
skip |= ValidateDrawShaderObject(last_bound_state, vuid);
}
} else if (bind_point == VK_PIPELINE_BIND_POINT_COMPUTE) {
skip |= InsideRenderPass(cb_state, loc, vuid.compute_inside_rp_10672);
if (!pipeline && !last_bound_state.IsValidShaderObjectBound(ShaderObjectStage::COMPUTE)) {
const bool is_null_bound = last_bound_state.IsValidShaderObjectOrNullBound(ShaderObjectStage::COMPUTE);
return LogError(
vuid.compute_not_bound_10743, cb_state.GetObjectList(bind_point), loc,
"No compute shader is bound, before this dispatch command, you either need to call vkCmdBindPipeline with a valid "
"compute pipeline or vkCmdBindShadersEXT with a valid compute shader object.%s",
is_null_bound ? " (vkCmdBindShadersEXT was called, but it set the compute stage to VK_NULL_HANDLE)" : "");
}
} else if (bind_point == VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR) {
if (pipeline) {
skip |= ValidateTraceRaysDynamicStateSetStatus(last_bound_state, *pipeline, vuid);
}
if (!cb_state.unprotected) {
skip |= LogError(vuid.ray_query_protected_cb_03635, cb_state.GetObjectList(bind_point), loc,
"called in a protected command buffer.");
}
}
if (pipeline) {
skip |= ValidateActionStateDescriptorsPipeline(last_bound_state, bind_point, *pipeline, vuid);
} else if (last_bound_state.cb_state.descriptor_buffer.binding_info.empty()) {
// TODO - VkPipeline have VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT (descriptor_buffer_mode) to know if using descriptor
// buffers, but VK_EXT_shader_object has no flag. For now, if the command buffer ever calls vkCmdBindDescriptorBuffersEXT,
// we just assume things are bound until we add some form of GPU side tracking for descriptor buffers
skip |= ValidateActionStateDescriptorsShaderObject(last_bound_state, bind_point, vuid);
}
skip |= ValidateActionStatePushConstant(last_bound_state, pipeline, vuid);
if (!cb_state.unprotected) {
skip |= ValidateActionStateProtectedMemory(last_bound_state, bind_point, pipeline, vuid);
}
return skip;
}
// Validate the draw-time state for this descriptor set
// We can skip validating the descriptor set if "nothing" has changed since the last validation.
// Same set, no image layout changes, and same "pipeline state" (binding_req_map). If there are
// any dynamic descriptors, always revalidate rather than caching the values. We currently only
// apply this optimization if IsManyDescriptors is true, to avoid the overhead of copying the
// binding_req_map which could potentially be expensive.
static bool NeedDrawStateValidated(const vvl::CommandBuffer &cb_state, const vvl::DescriptorSet *descriptor_set,
const LastBound::DescriptorSetSlot &ds_slot, bool disabled_image_layout_validation) {
return ds_slot.dynamic_offsets.size() > 0 ||
// Revalidate if descriptor set (or contents) has changed
ds_slot.validated_set != descriptor_set || ds_slot.validated_set_change_count != descriptor_set->GetChangeCount() ||
(!disabled_image_layout_validation &&
ds_slot.validated_set_image_layout_change_count != cb_state.image_layout_change_count);
}
bool CoreChecks::ValidateActionStateDescriptorsPipeline(const LastBound &last_bound_state, const VkPipelineBindPoint bind_point,
const vvl::Pipeline &pipeline, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
// If the pipeline is not using any descriptors, then any descriptor state set can be ignored
if (pipeline.active_slots.empty()) {
return skip;
}
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
for (const auto &ds_slot : last_bound_state.ds_slots) {
// TODO - This currently implicitly is checking for VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT being set
if (pipeline.descriptor_buffer_mode) {
if (ds_slot.ds_state && !ds_slot.ds_state->IsPushDescriptor()) {
LogObjectList objlist = cb_state.GetObjectList(bind_point);
objlist.add(ds_slot.ds_state->Handle());
skip |= LogError(vuid.descriptor_buffer_bit_not_set_08115, objlist, vuid.loc(),
"pipeline bound to %s requires a descriptor buffer (because it was created with "
"VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT), but has a bound VkDescriptorSet (%s)",
string_VkPipelineBindPoint(bind_point), FormatHandle(ds_slot.ds_state->Handle()).c_str());
break;
}
} else if (ds_slot.descriptor_buffer_binding.has_value()) {
skip |= LogError(vuid.descriptor_buffer_set_offset_missing_08117, cb_state.GetObjectList(bind_point), vuid.loc(),
"pipeline bound to %s requires a VkDescriptorSet (because it was not created with "
"VK_PIPELINE_CREATE_DESCRIPTOR_BUFFER_BIT_EXT), but has a bound descriptor buffer"
" (index=%" PRIu32 " offset=%" PRIu64 ")",
string_VkPipelineBindPoint(bind_point), ds_slot.descriptor_buffer_binding->index,
ds_slot.descriptor_buffer_binding->offset);
break;
}
}
// Check if the current pipeline is compatible for the maximum used set with the bound sets.
if (pipeline.descriptor_buffer_mode) {
return skip;
}
const auto pipeline_layout = pipeline.PipelineLayoutState();
if (!last_bound_state.IsBoundSetCompatible(pipeline.max_active_slot, *pipeline_layout)) {
// If they never bound any descriptors
if (!last_bound_state.desc_set_pipeline_layout) {
skip |= LogError(vuid.compatible_pipeline_08600, cb_state.GetObjectList(bind_point), vuid.loc(),
"The %s statically uses descriptor set %" PRIu32
", but because a descriptor was never bound, the pipeline layouts are not compatible.\nIf using a "
"descriptor, make sure to call one of vkCmdBindDescriptorSets, vkCmdPushDescriptorSet, "
"vkCmdSetDescriptorBufferOffset, etc for %s",
FormatHandle(pipeline).c_str(), pipeline.max_active_slot, string_VkPipelineBindPoint(bind_point));
return skip;
}
LogObjectList objlist(pipeline.Handle());
const auto layouts = pipeline.PipelineLayoutStateUnion();
// GPL can have multiple pipeline layouts used to build up a single valid compatible set
std::ostringstream pipe_layouts_log;
if (layouts.size() > 1) {
pipe_layouts_log << "a union of layouts [ ";
for (const auto &layout : layouts) {
objlist.add(layout->Handle());
pipe_layouts_log << FormatHandle(*layout) << " ";
}
pipe_layouts_log << "]";
} else {
pipe_layouts_log << FormatHandle(*layouts.front());
}
objlist.add(last_bound_state.desc_set_pipeline_layout->Handle());
std::string range =
pipeline.max_active_slot == 0 ? "set 0 is" : "all sets 0 to " + std::to_string(pipeline.max_active_slot) + " are";
skip |= LogError(vuid.compatible_pipeline_08600, objlist, vuid.loc(),
"The %s (created with %s) statically uses descriptor set %" PRIu32
", but %s not compatible with the pipeline layout bound with %s (%s)\n%s",
FormatHandle(pipeline).c_str(), pipe_layouts_log.str().c_str(), pipeline.max_active_slot, range.c_str(),
String(last_bound_state.desc_set_bound_command),
FormatHandle(last_bound_state.desc_set_pipeline_layout->Handle()).c_str(),
last_bound_state.DescribeNonCompatibleSet(pipeline.max_active_slot, *pipeline_layout).c_str());
} else {
// if the bound set is not compatible, the rest will just be extra redundant errors
for (const auto &[set_index, binding_req_map] : pipeline.active_slots) {
std::string error_string;
const auto ds_slot = last_bound_state.ds_slots[set_index];
if (!ds_slot.ds_state) {
skip |= LogError(vuid.compatible_pipeline_08600, cb_state.GetObjectList(bind_point), vuid.loc(),
"%s uses set %" PRIu32
" but that set is not bound. (Need to use a command like vkCmdBindDescriptorSets to bind the set)",
FormatHandle(pipeline).c_str(), set_index);
} else if (pipeline_layout->set_layouts.list[set_index] &&
!VerifyDescriptorSetIsCompatibile(*ds_slot.ds_state, *pipeline_layout->set_layouts.list[set_index],
error_string)) {
// Set is bound but not compatible w/ corresponding VkPipelineLayoutCreateInfo::pSetLayouts
VkDescriptorSet set_handle = ds_slot.ds_state->VkHandle();
const LogObjectList objlist(cb_state.Handle(), set_handle, pipeline.Handle(), pipeline_layout->Handle());
skip |= LogError(vuid.compatible_pipeline_08600, objlist, vuid.loc(),
"%s bound as set %" PRIu32 " is not compatible with corresponding %s\n%s",
FormatHandle(set_handle).c_str(), set_index, FormatHandle(*pipeline_layout).c_str(),
error_string.c_str());
} else { // Valid set is bound and layout compatible, validate that it's updated
// Pull the set node
const auto *descriptor_set = ds_slot.ds_state.get();
ASSERT_AND_CONTINUE(descriptor_set);
const bool need_validate =
NeedDrawStateValidated(cb_state, descriptor_set, ds_slot, disabled[image_layout_validation]);
if (need_validate) {
skip |= ValidateDrawState(*descriptor_set, set_index, binding_req_map, cb_state, vuid,
LogObjectList(pipeline.Handle()));
}
}
}
}
return skip;
}
bool CoreChecks::ValidateActionStateDescriptorsShaderObject(const LastBound &last_bound_state, const VkPipelineBindPoint bind_point,
const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
// Check if the current shader objects are compatible for the maximum used set with the bound sets.
for (const auto &shader_state : last_bound_state.shader_object_states) {
// If the shader is not using any descriptors, then any descriptor state set can be ignored
if (!shader_state || shader_state->active_slots.empty()) {
continue;
}
if (!last_bound_state.IsBoundSetCompatible(shader_state->max_active_slot, *shader_state)) {
LogObjectList objlist(cb_state.Handle(), shader_state->Handle());
if (!last_bound_state.desc_set_pipeline_layout) {
// If they never bound any descriptors
skip |= LogError(vuid.compatible_pipeline_08600, cb_state.GetObjectList(bind_point), vuid.loc(),
"The %s statically uses descriptor set %" PRIu32
", but because a descriptor was never bound, the pipeline layouts are not compatible.\nIf using "
"a descriptor, make sure to call one of vkCmdBindDescriptorSets, vkCmdPushDescriptorSet, "
"vkCmdSetDescriptorBufferOffset, etc for %s",
FormatHandle(shader_state->Handle()).c_str(), shader_state->max_active_slot,
string_VkPipelineBindPoint(bind_point));
} else {
objlist.add(last_bound_state.desc_set_pipeline_layout->Handle());
std::string range = shader_state->max_active_slot == 0
? "set 0 is"
: "all sets 0 to " + std::to_string(shader_state->max_active_slot) + " are";
skip |= LogError(vuid.compatible_pipeline_08600, objlist, vuid.loc(),
"The %s statically uses descriptor set %" PRIu32
" but %s not compatible with the pipeline layout bound with %s (%s)\n%s",
FormatHandle(shader_state->Handle()).c_str(), shader_state->max_active_slot, range.c_str(),
String(last_bound_state.desc_set_bound_command),
FormatHandle(last_bound_state.desc_set_pipeline_layout->Handle()).c_str(),
last_bound_state.DescribeNonCompatibleSet(shader_state->max_active_slot, *shader_state).c_str());
}
} else {
// if the bound set is not copmatible, the rest will just be extra redundant errors
for (const auto &[set_index, binding_req_map] : shader_state->active_slots) {
std::string error_string;
const auto ds_slot = last_bound_state.ds_slots[set_index];
if (!ds_slot.ds_state) {
const LogObjectList objlist(cb_state.Handle(), shader_state->Handle());
skip |= LogError(vuid.compatible_pipeline_08600, objlist, vuid.loc(),
"%s uses set %" PRIu32 " but that set is not bound.",
FormatHandle(shader_state->Handle()).c_str(), set_index);
} else if (shader_state->set_layouts.list[set_index] &&
!VerifyDescriptorSetIsCompatibile(*ds_slot.ds_state, *shader_state->set_layouts.list[set_index],
error_string)) {
// Set is bound but not compatible w/ corresponding VkShaderCreateInfoEXT::pSetLayouts
VkDescriptorSet set_handle = ds_slot.ds_state->VkHandle();
const LogObjectList objlist(cb_state.Handle(), set_handle, shader_state->Handle());
skip |= LogError(vuid.compatible_pipeline_08600, objlist, vuid.loc(),
"%s bound as set %" PRIu32 " is not compatible with corresponding %s\n%s",
FormatHandle(set_handle).c_str(), set_index, FormatHandle(shader_state->Handle()).c_str(),
error_string.c_str());
} else { // Valid set is bound and layout compatible, validate that it's updated
// Pull the set node
const auto *descriptor_set = ds_slot.ds_state.get();
ASSERT_AND_CONTINUE(descriptor_set);
const bool need_validate =
NeedDrawStateValidated(cb_state, descriptor_set, ds_slot, disabled[image_layout_validation]);
if (need_validate) {
skip |= ValidateDrawState(*descriptor_set, set_index, binding_req_map, cb_state, vuid,
LogObjectList(shader_state->Handle()));
}
}
}
}
}
return skip;
}
bool CoreChecks::ValidateActionStatePushConstant(const LastBound &last_bound_state, const vvl::Pipeline *pipeline,
const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
// Push constants validation for DGC will need to be done in GPU-AV
if (vuid.loc().function == vvl::Func::vkCmdExecuteGeneratedCommandsEXT) {
return skip;
}
// Verify if push constants have been set
// NOTE: Currently not checking whether active push constants are compatible with the active pipeline, nor whether the
// "life times" of push constants are correct.
// Discussion on validity of these checks can be found at https://gitlab.khronos.org/vulkan/vulkan/-/issues/2602.
if (pipeline) {
auto const &pipeline_layout = pipeline->PipelineLayoutState();
if (!cb_state.push_constant_ranges_layout ||
(pipeline_layout->push_constant_ranges_layout == cb_state.push_constant_ranges_layout)) {
for (const auto &stage : pipeline->stage_states) {
if (!stage.entrypoint || !stage.entrypoint->push_constant_variable) {
continue; // no static push constant in shader
}
// Edge case where if the shader is using push constants statically and there never was a vkCmdPushConstants
if (!cb_state.push_constant_ranges_layout && !enabled_features.maintenance4) {
const LogObjectList objlist(cb_state.Handle(), pipeline_layout->Handle(), pipeline->Handle());
skip |= LogError(vuid.push_constants_set_08602, objlist, vuid.loc(),
"Shader in %s uses push-constant statically but vkCmdPushConstants was not called yet for "
"pipeline layout %s.",
string_VkShaderStageFlags(stage.GetStage()).c_str(),
FormatHandle(pipeline_layout->Handle()).c_str());
}
}
}
} else {
if (!cb_state.push_constant_ranges_layout) {
for (const auto &stage : last_bound_state.shader_object_states) {
if (!stage || !stage->entrypoint || !stage->entrypoint->push_constant_variable) {
continue;
}
// Edge case where if the shader is using push constants statically and there never was a vkCmdPushConstants
if (!cb_state.push_constant_ranges_layout && !enabled_features.maintenance4) {
const LogObjectList objlist(cb_state.Handle(), stage->Handle());
skip |= LogError(vuid.push_constants_set_08602, objlist, vuid.loc(),
"Shader in %s uses push-constant statically but vkCmdPushConstants was not called yet.",
string_VkShaderStageFlags(stage->create_info.stage).c_str());
}
}
}
}
return skip;
}
bool CoreChecks::ValidateActionStateProtectedMemory(const LastBound &last_bound_state, const VkPipelineBindPoint bind_point,
const vvl::Pipeline *pipeline, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
if (pipeline) {
for (const auto &stage : pipeline->stage_states) {
// Stage may not have SPIR-V data (e.g. due to the use of shader module identifier or in Vulkan SC)
if (!stage.spirv_state) continue;
if (stage.spirv_state->HasCapability(spv::CapabilityRayQueryKHR)) {
skip |= LogError(vuid.ray_query_04617, cb_state.GetObjectList(bind_point), vuid.loc(),
"Shader in %s uses OpCapability RayQueryKHR but the command buffer is protected.",
string_VkShaderStageFlags(stage.GetStage()).c_str());
}
}
} else {
for (const auto &stage : last_bound_state.shader_object_states) {
if (stage && stage->spirv->HasCapability(spv::CapabilityRayQueryKHR)) {
const LogObjectList objlist(cb_state.Handle(), stage->Handle());
skip |= LogError(vuid.ray_query_04617, objlist, vuid.loc(),
"Shader in %s uses OpCapability RayQueryKHR but the command buffer is protected.",
string_VkShaderStageFlags(stage->create_info.stage).c_str());
}
}
}
return skip;
}
// Note, these don't include the RTX Indirect commands (vkCmdTraceRaysIndirectKHR) because
// they use a VkDeviceAddress instead of a VkBuffer
bool CoreChecks::ValidateIndirectCmd(const vvl::CommandBuffer &cb_state, const vvl::Buffer &buffer_state,
const DrawDispatchVuid &vuid) const {
bool skip = false;
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(buffer_state.Handle());
skip |= ValidateMemoryIsBoundToBuffer(cb_state.VkHandle(), buffer_state, vuid.loc().dot(Field::buffer),
vuid.indirect_contiguous_memory_02708);
skip |= ValidateBufferUsageFlags(objlist, buffer_state, VK_BUFFER_USAGE_2_INDIRECT_BUFFER_BIT, true,
vuid.indirect_buffer_bit_02290, vuid.loc().dot(Field::buffer));
if (cb_state.unprotected == false) {
skip |= LogError(vuid.indirect_protected_cb_02711, objlist, vuid.loc(),
"Indirect commands can't be used in protected command buffers.");
}
return skip;
}
bool CoreChecks::ValidateIndirectCountCmd(const vvl::CommandBuffer &cb_state, const vvl::Buffer &count_buffer_state,
VkDeviceSize count_buffer_offset, const DrawDispatchVuid &vuid) const {
bool skip = false;
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(count_buffer_state.Handle());
skip |= ValidateMemoryIsBoundToBuffer(cb_state.VkHandle(), count_buffer_state, vuid.loc().dot(Field::countBuffer),
vuid.indirect_count_contiguous_memory_02714);
skip |= ValidateBufferUsageFlags(objlist, count_buffer_state, VK_BUFFER_USAGE_2_INDIRECT_BUFFER_BIT, true,
vuid.indirect_count_buffer_bit_02715, vuid.loc().dot(Field::countBuffer));
if (count_buffer_offset + sizeof(uint32_t) > count_buffer_state.create_info.size) {
skip |= LogError(vuid.indirect_count_offset_04129, objlist, vuid.loc(),
"countBufferOffset (%" PRIu64 ") + sizeof(uint32_t) is greater than the buffer size of %" PRIu64 ".",
count_buffer_offset, count_buffer_state.create_info.size);
}
return skip;
}
bool CoreChecks::ValidateDrawPrimitivesGeneratedQuery(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const bool with_rasterizer_discard = enabled_features.primitivesGeneratedQueryWithRasterizerDiscard == VK_TRUE;
const bool with_non_zero_streams = enabled_features.primitivesGeneratedQueryWithNonZeroStreams == VK_TRUE;
if (with_rasterizer_discard && with_non_zero_streams) {
return skip;
}
bool primitives_generated_query = false;
for (const auto &query : cb_state.active_queries) {
auto query_pool_state = Get<vvl::QueryPool>(query.pool);
if (query_pool_state && query_pool_state->create_info.queryType == VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT) {
primitives_generated_query = true;
break;
}
}
if (primitives_generated_query) {
if (!with_rasterizer_discard && last_bound_state.IsRasterizationDisabled()) {
skip |= LogError(vuid.primitives_generated_06708, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"a VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT query is active and pipeline was created with "
"VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable set to VK_TRUE, but "
"primitivesGeneratedQueryWithRasterizerDiscard feature is not enabled.");
}
const vvl::Pipeline *pipeline = last_bound_state.pipeline_state;
if (!with_non_zero_streams && pipeline) {
const auto rasterization_state_stream_ci =
vku::FindStructInPNextChain<VkPipelineRasterizationStateStreamCreateInfoEXT>(pipeline->RasterizationStatePNext());
if (rasterization_state_stream_ci && rasterization_state_stream_ci->rasterizationStream != 0) {
skip |= LogError(vuid.primitives_generated_streams_06709, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"a VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT query is active and pipeline was created with "
"VkPipelineRasterizationStateStreamCreateInfoEXT::rasterizationStream set to %" PRIu32
", but primitivesGeneratedQueryWithNonZeroStreams feature is not enabled.",
rasterization_state_stream_ci->rasterizationStream);
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawProtectedMemory(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
if (!enabled_features.protectedMemory) {
return skip;
}
// Verify vertex & index buffer for unprotected command buffer.
// Because vertex & index buffer is read only, it doesn't need to care protected command buffer case.
for (const auto &vertex_buffer_binding : cb_state.current_vertex_buffer_binding_info) {
if (const auto buffer_state = Get<vvl::Buffer>(vertex_buffer_binding.second.buffer)) {
skip |= ValidateProtectedBuffer(cb_state, *buffer_state, vuid.loc(), vuid.unprotected_command_buffer_02707,
" (Buffer is the vertex buffer)");
}
}
return skip;
}
bool CoreChecks::ValidateDrawFragmentShadingRate(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const auto *pipeline = last_bound_state.pipeline_state;
if (!enabled_features.primitiveFragmentShadingRate ||
phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports) {
return skip;
}
if (pipeline) {
for (auto &stage_state : pipeline->stage_states) {
const VkShaderStageFlagBits stage = stage_state.GetStage();
if (!IsValueIn(stage, {VK_SHADER_STAGE_VERTEX_BIT, VK_SHADER_STAGE_GEOMETRY_BIT, VK_SHADER_STAGE_MESH_BIT_EXT})) {
continue;
}
if (pipeline->IsDynamic(CB_DYNAMIC_STATE_VIEWPORT_WITH_COUNT) && cb_state.dynamic_state_value.viewport_count != 1) {
if (stage_state.entrypoint && stage_state.entrypoint->written_builtin_primitive_shading_rate_khr) {
skip |=
LogError(vuid.viewport_count_primitive_shading_rate_04552, stage_state.module_state->Handle(), vuid.loc(),
"%s shader of currently bound pipeline statically writes to PrimitiveShadingRateKHR built-in, "
"but multiple viewports (%" PRIu32
") are set by the last call to vkCmdSetViewportWithCountEXT,"
"and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
string_VkShaderStageFlagBits(stage), cb_state.dynamic_state_value.viewport_count);
}
}
}
} else {
for (uint32_t stage = 0; stage < kShaderObjectStageCount; ++stage) {
const auto shader_object = last_bound_state.GetShaderObjectState(static_cast<ShaderObjectStage>(stage));
if (shader_object && shader_object->entrypoint &&
shader_object->entrypoint->written_builtin_primitive_shading_rate_khr) {
if (cb_state.dynamic_state_value.viewport_count != 1) {
skip |= LogError(vuid.set_viewport_with_count_08642, cb_state.Handle(), vuid.loc(),
"%s shader of currently bound pipeline statically writes to PrimitiveShadingRateKHR built-in, "
"but multiple viewports (%" PRIu32
") are set by the last call to vkCmdSetViewportWithCountEXT,"
"and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
string_VkShaderStageFlagBits(shader_object->create_info.stage),
cb_state.dynamic_state_value.viewport_count);
}
break;
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawAttachmentColorBlend(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
const bool has_pipeline = last_bound_state.pipeline_state != nullptr;
if (has_pipeline && !last_bound_state.pipeline_state->ColorBlendState()) {
return skip;
}
if (last_bound_state.IsRasterizationDisabled()) {
return skip;
}
if (last_bound_state.IsStageBound(VK_SHADER_STAGE_FRAGMENT_BIT)) {
if (enabled_features.colorWriteEnable && last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT) &&
cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT)) {
// Found in https://gitlab.khronos.org/vulkan/vulkan/-/issues/4116 that not setting all attachment can invalidate
// previous calls, so the last call needs to have set them all
const uint32_t blend_attachment_count = (uint32_t)cb_state.active_color_attachments_index.size();
const uint32_t dynamic_attachment_count = cb_state.dynamic_state_value.color_write_enable_attachment_count;
if (dynamic_attachment_count < blend_attachment_count) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
skip |=
LogError(vuid.dynamic_color_write_enable_count_07750, objlist, vuid.loc(),
"There are currently (%" PRIu32
") active color attachments, but the last call to vkCmdSetColorWriteEnableEXT() only set the color "
"write enables for attachmentCount of %" PRIu32
" and the color write enable state of the remaining attachments is undefined.%s\n%s",
blend_attachment_count, dynamic_attachment_count,
cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_WRITE_ENABLE_EXT).c_str(),
cb_state.DescribeActiveColorAttachment());
}
}
}
const bool dynamic_equation = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT);
const bool dynamic_advanced = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_BLEND_ADVANCED_EXT);
const bool dynamic_blend_enable = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT);
const bool dynamic_write_mask = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT);
const bool dynamic_blend_constants = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_BLEND_CONSTANTS);
for (uint32_t i = 0; i < cb_state.active_attachments.size(); ++i) {
const auto &attachment_info = cb_state.active_attachments[i];
const auto *attachment = attachment_info.image_view;
if (!attachment || !attachment_info.IsColor()) {
continue;
}
const uint32_t color_index = attachment_info.type_index;
if (dynamic_write_mask && cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT) &&
!cb_state.dynamic_state_value.color_write_mask_attachments[color_index]) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.dynamic_color_write_mask_07478, objlist, vuid.loc(),
"vkCmdSetColorWriteMaskEXT was not set for color attachment index %" PRIu32
" for this command buffer.%s\n%s",
color_index, cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_WRITE_MASK_EXT).c_str(),
cb_state.DescribeActiveColorAttachment());
}
if (dynamic_blend_enable && cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT) &&
!cb_state.dynamic_state_value.color_blend_enable_attachments[color_index]) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.dynamic_color_blend_enable_07476, objlist, vuid.loc(),
"vkCmdSetColorBlendEnableEXT was not set for color attachment index %" PRIu32
" for this command buffer.%s\n%s",
color_index, cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT).c_str(),
cb_state.DescribeActiveColorAttachment());
continue; // If no value is set, IsColorBlendEnabled will give garbage
}
// The following all rely on color blend
if (!last_bound_state.IsColorBlendEnabled(color_index)) {
continue;
}
const bool has_blend_bit = attachment->format_features & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
if (!has_blend_bit) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.blend_enable_04727, objlist, vuid.loc(),
"%s was created with %s which doesn't support VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT, but %s\n"
"(supported features: %s)",
attachment_info.Describe(cb_state, i).c_str(), string_VkFormat(attachment->create_info.format),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(),
string_VkFormatFeatureFlags2(attachment->format_features).c_str());
}
// These checks "could" be done in ValidateGraphicsDynamicStateSetStatus, but are exceptions/complex and better done here
// where we also need to check for other things related to the color attachments
if (dynamic_equation && dynamic_advanced) {
// always the case for shader object, can also be done with pipeline
if (!cb_state.dynamic_state_value.color_blend_equation_attachments[color_index] &&
!cb_state.dynamic_state_value.color_blend_advanced_attachments[color_index]) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.dynamic_color_blend_equation_10864, objlist, vuid.loc(),
"%s needs to be set for color attachmet index %" PRIu32 " (%s)\n%s\n%s",
IsExtEnabled(extensions.vk_ext_blend_operation_advanced)
? "Either vkCmdSetColorBlendEquationEXT or vkCmdSetColorBlendAdvancedEXT"
: "vkCmdSetColorBlendEquationEXT",
color_index, attachment_info.Describe(cb_state, i).c_str(),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(),
cb_state.DescribeActiveColorAttachment());
}
} else if (dynamic_equation) {
// Only possible with pipelines
if (!cb_state.dynamic_state_value.color_blend_equation_attachments[color_index]) {
const LogObjectList objlist(cb_state.Handle(), attachment->VkHandle(), last_bound_state.pipeline_state->Handle());
skip |= LogError(
vuid.dynamic_color_blend_equation_10862, objlist, vuid.loc(),
"The pipeline was created with VK_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT, but "
"vkCmdSetColorBlendEquationEXT was never set for color attachment index %" PRIu32 " (%s).%s\n%s\n%s",
color_index, attachment_info.Describe(cb_state, i).c_str(),
cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_BLEND_EQUATION_EXT).c_str(),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(), cb_state.DescribeActiveColorAttachment());
}
} else if (dynamic_advanced) {
// Only possible with pipelines
if (!cb_state.dynamic_state_value.color_blend_advanced_attachments[color_index]) {
const LogObjectList objlist(cb_state.Handle(), attachment->VkHandle(), last_bound_state.pipeline_state->Handle());
skip |= LogError(
vuid.dynamic_color_blend_equation_10863, objlist, vuid.loc(),
"The pipeline was created with VK_DYNAMIC_STATE_COLOR_BLEND_ADVANCED_EXT, but "
"vkCmdSetColorBlendAdvancedEXT was never set for color attachment index %" PRIu32 " (%s).%s\n%s\n%s",
color_index, attachment_info.Describe(cb_state, i).c_str(),
cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_BLEND_ADVANCED_EXT).c_str(),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(), cb_state.DescribeActiveColorAttachment());
}
}
if (dynamic_advanced && cb_state.dynamic_state_value.color_blend_advanced_attachments[color_index]) {
if (cb_state.active_color_attachments_index.size() >
phys_dev_ext_props.blend_operation_advanced_props.advancedBlendMaxColorAttachments) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(
vuid.blend_advanced_07480, objlist, vuid.loc(),
"vkCmdSetColorBlendAdvancedEXT has set color attachment index %" PRIu32
" (%s) to advanced blending, but the total active color attachment count (%zu) is greater than "
"advancedBlendMaxColorAttachments (%" PRIu32 ").%s\n%s\n%s",
color_index, attachment_info.Describe(cb_state, i).c_str(), cb_state.active_color_attachments_index.size(),
phys_dev_ext_props.blend_operation_advanced_props.advancedBlendMaxColorAttachments,
cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_COLOR_BLEND_ADVANCED_EXT).c_str(),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(), cb_state.DescribeActiveColorAttachment());
}
}
if (dynamic_blend_constants && !cb_state.IsDynamicStateSet(CB_DYNAMIC_STATE_BLEND_CONSTANTS) &&
last_bound_state.IsBlendConstantsEnabled(color_index)) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.dynamic_blend_constants_07835, objlist, vuid.loc(),
"%svkCmdSetBlendConstants was never called, but color attachment index %" PRIu32
" (%s) has blending enabled (%s), and the blend factor is constant.\n%s\n%s\n%s",
has_pipeline ? "VK_DYNAMIC_STATE_BLEND_CONSTANT state is dynamic, " : "", color_index,
attachment_info.Describe(cb_state, i).c_str(),
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(),
last_bound_state.DescribeBlendFactorEquation(color_index).c_str(),
cb_state.DescribeInvalidatedState(CB_DYNAMIC_STATE_BLEND_CONSTANTS).c_str(),
cb_state.DescribeActiveColorAttachment());
}
// Validation needing access to spir-v information
// ---
const spirv::EntryPoint *fragment_entry_point = last_bound_state.GetFragmentEntryPoint();
if (fragment_entry_point && last_bound_state.IsDualBlending(color_index)) {
const auto get_max_fragment_location = [fragment_entry_point]() {
uint32_t max_fragment_location = 0;
for (const auto *variable : fragment_entry_point->user_defined_interface_variables) {
if (variable->storage_class != spv::StorageClassOutput) {
continue;
}
if (variable->decorations.location != spirv::kInvalidValue) {
max_fragment_location = std::max(max_fragment_location, variable->decorations.location);
}
}
return max_fragment_location;
};
const uint32_t max_fragment_location = get_max_fragment_location();
if (max_fragment_location >= phys_dev_props.limits.maxFragmentDualSrcAttachments) {
skip |= LogError(vuid.blend_dual_source_09239, cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"color attachment index %" PRIu32
" (%s) is using Dual-Source Blending, but the largest output fragment Location (%" PRIu32
") is not less than maxFragmentDualSrcAttachments (%" PRIu32 ").\n%s\n%s",
color_index, attachment_info.Describe(cb_state, i).c_str(), max_fragment_location,
phys_dev_props.limits.maxFragmentDualSrcAttachments,
last_bound_state.DescribeColorBlendEnabled(color_index).c_str(),
last_bound_state.DescribeBlendFactorEquation(color_index).c_str());
break;
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawAttachmentSampleLocation(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
if (!last_bound_state.IsStageBound(VK_SHADER_STAGE_FRAGMENT_BIT)) {
return skip;
}
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
if (last_bound_state.IsSampleLocationsEnable()) {
for (uint32_t i = 0; i < cb_state.active_attachments.size(); i++) {
const auto &attachment_info = cb_state.active_attachments[i];
const auto *attachment = attachment_info.image_view;
if (!attachment || !attachment_info.IsDepth()) {
continue;
}
if ((attachment->image_state->create_info.flags & VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT) == 0) {
const LogObjectList objlist(cb_state.Handle(), attachment->Handle());
const char *err = last_bound_state.IsDynamic(CB_DYNAMIC_STATE_SAMPLE_LOCATIONS_ENABLE_EXT)
? vuid.sample_locations_enable_07484
: vuid.sample_location_02689;
skip |= LogError(err, objlist, vuid.loc(),
"sampleLocationsEnable is true, but %s (%s created with %s) was not created with "
"VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT.",
attachment_info.Describe(cb_state, i).c_str(), FormatHandle(attachment->Handle()).c_str(),
FormatHandle(attachment->image_state->Handle()).c_str());
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawDepthStencilAttachments(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
for (uint32_t i = 0; i < cb_state.active_attachments.size(); i++) {
const auto &attachment_info = cb_state.active_attachments[i];
const auto *attachment = attachment_info.image_view;
if (!attachment) {
continue;
}
if (attachment_info.IsDepth() && last_bound_state.IsDepthWriteEnable() &&
IsImageLayoutDepthReadOnly(attachment_info.layout)) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(vuid.depth_read_only_06886, objlist, vuid.loc(),
"depthWriteEnable is VK_TRUE, but %s (%s created with %s) has a layout %s which is READ_ONLY.",
attachment_info.Describe(cb_state, i).c_str(), FormatHandle(attachment->Handle()).c_str(),
FormatHandle(attachment->image_state->Handle()).c_str(), string_VkImageLayout(attachment_info.layout));
}
if (attachment_info.IsStencil() && last_bound_state.IsStencilTestEnable()) {
VkStencilOpState front = last_bound_state.GetStencilOpStateFront();
VkStencilOpState back = last_bound_state.GetStencilOpStateBack();
const bool all_keep_op = ((front.failOp == VK_STENCIL_OP_KEEP) && (front.passOp == VK_STENCIL_OP_KEEP) &&
(front.depthFailOp == VK_STENCIL_OP_KEEP) && (back.failOp == VK_STENCIL_OP_KEEP) &&
(back.passOp == VK_STENCIL_OP_KEEP) && (back.depthFailOp == VK_STENCIL_OP_KEEP));
const bool write_mask_enabled = (front.writeMask != 0) && (back.writeMask != 0);
if (!all_keep_op && write_mask_enabled) {
bool is_stencil_layout_read_only = false;
if (attachment_info.separate_stencil_layout != VK_IMAGE_LAYOUT_UNDEFINED) {
is_stencil_layout_read_only = IsImageLayoutStencilReadOnly(attachment_info.separate_stencil_layout);
} else {
is_stencil_layout_read_only = IsImageLayoutStencilReadOnly(attachment_info.layout);
}
if (is_stencil_layout_read_only) {
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
objlist.add(attachment->Handle());
skip |= LogError(
vuid.stencil_read_only_06887, objlist, vuid.loc(),
"%s (%s created with %s) has a layout of %s which is READ_ONLY, but stencilTestEnable is VK_TRUE, "
"writeMask is non-zero, and all stencil ops are not VK_STENCIL_OP_KEEP.\n"
"front:\n%sback:\n%s",
attachment_info.Describe(cb_state, i).c_str(), FormatHandle(attachment->Handle()).c_str(),
FormatHandle(attachment->image_state->Handle()).c_str(), string_VkImageLayout(attachment_info.layout),
string_VkStencilOpState(front).c_str(), string_VkStencilOpState(back).c_str());
}
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawTessellation(const LastBound &last_bound_state, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
if ((last_bound_state.GetAllActiveBoundStages() & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) == 0) {
return skip;
}
const spirv::ExecutionModeSet *tesc_execution_mode = nullptr;
const spirv::ExecutionModeSet *tese_execution_mode = nullptr;
if (last_bound_state.pipeline_state) {
for (const auto &stage_state : last_bound_state.pipeline_state->stage_states) {
const VkShaderStageFlagBits stage = stage_state.GetStage();
if (stage & VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
if (stage_state.entrypoint) {
tesc_execution_mode = &stage_state.entrypoint->execution_mode;
}
} else if (stage & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
if (stage_state.entrypoint) {
tese_execution_mode = &stage_state.entrypoint->execution_mode;
}
}
}
} else {
const auto tesc_shader = last_bound_state.GetShaderObjectState(ShaderObjectStage::TESSELLATION_CONTROL);
if (tesc_shader && tesc_shader->entrypoint) {
tesc_execution_mode = &tesc_shader->entrypoint->execution_mode;
}
const auto tese_shader = last_bound_state.GetShaderObjectState(ShaderObjectStage::TESSELLATION_EVALUATION);
if (tese_shader && tese_shader->entrypoint) {
tese_execution_mode = &tese_shader->entrypoint->execution_mode;
}
}
if (!tesc_execution_mode || !tese_execution_mode) {
return skip; // Occurs if using binary shader object
}
const uint32_t tesc_subdivision = tesc_execution_mode->GetTessellationSubdivision();
const uint32_t tese_subdivision = tese_execution_mode->GetTessellationSubdivision();
if (tesc_subdivision != spirv::kInvalidValue && tese_subdivision != spirv::kInvalidValue &&
tesc_subdivision != tese_subdivision) {
skip |= LogError(vuid.tessellation_subdivision_12239,
last_bound_state.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"The subdivision specified in tessellation control shader (%s) does not match the subdivision in "
"tessellation evaluation shader (%s).",
string_SpvExecutionMode(tesc_subdivision), string_SpvExecutionMode(tese_subdivision));
}
const uint32_t tesc_orientation = tesc_execution_mode->GetTessellationOrientation();
const uint32_t tese_orientation = tese_execution_mode->GetTessellationOrientation();
if (tesc_orientation != spirv::kInvalidValue && tese_orientation != spirv::kInvalidValue &&
tesc_orientation != tese_orientation) {
skip |= LogError(vuid.tessellation_triangles_12240,
last_bound_state.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"The orientation specified in tessellation control shader (%s) does not match the orientation in "
"tessellation evaluation shader (%s).",
string_SpvExecutionMode(tesc_orientation), string_SpvExecutionMode(tese_orientation));
}
const uint32_t tesc_spacing = tesc_execution_mode->GetTessellationSpacing();
const uint32_t tese_spacing = tese_execution_mode->GetTessellationSpacing();
if (tesc_spacing != spirv::kInvalidValue && tese_spacing != spirv::kInvalidValue && tesc_spacing != tese_spacing) {
skip |= LogError(vuid.tessellation_segment_12241, last_bound_state.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"The spacing specified in tessellation control shader (%s) does not match the spacing in "
"tessellation evaluation shader (%s).",
string_SpvExecutionMode(tesc_spacing), string_SpvExecutionMode(tese_spacing));
}
const uint32_t tesc_patch_size = tesc_execution_mode->output_vertices;
const uint32_t tese_patch_size = tese_execution_mode->output_vertices;
if (tesc_patch_size != spirv::kInvalidValue && tese_patch_size != spirv::kInvalidValue && tesc_patch_size != tese_patch_size) {
skip |= LogError(vuid.tessellation_patch_size_12242,
last_bound_state.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"The OutputVertices (patch size) specified in tessellation control shader (%" PRIu32
") does not match the spacing in "
"tessellation evaluation shader (%" PRIu32 ").",
tesc_patch_size, tese_patch_size);
}
return skip;
}
bool CoreChecks::ValidateDrawVertexBinding(const LastBound &last_bound, const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const vvl::CommandBuffer &cb_state = last_bound.cb_state;
if ((last_bound.GetAllActiveBoundStages() & VK_SHADER_STAGE_VERTEX_BIT) == 0) {
return skip;
}
// Since we need to know if the Vertex shader actually declares/uses the Input Location, if the shader validation was disabled,
// there will no SPIR-V to reflect the information from.
if (disabled[shader_validation]) {
return skip;
}
// Vertex bindings validation for DGC will need to be done in GPU-AV
if (vuid.loc().function == vvl::Func::vkCmdExecuteGeneratedCommandsEXT) {
return skip;
}
const bool has_dynamic_descriptions = last_bound.IsDynamic(CB_DYNAMIC_STATE_VERTEX_INPUT_EXT);
const auto &vertex_bindings = has_dynamic_descriptions ? cb_state.dynamic_state_value.vertex_bindings
: last_bound.pipeline_state->vertex_input_state->bindings;
const bool robust_pipeline = last_bound.pipeline_state && last_bound.pipeline_state->uses_pipeline_vertex_robustness;
auto print_binding = [has_dynamic_descriptions](const VertexBindingState binding_description) {
std::stringstream ss;
if (has_dynamic_descriptions) {
ss << "the last call to vkCmdSetVertexInputEXT";
} else {
ss << "the last bound pipeline";
}
ss << " has pVertexBindingDescriptions[" << binding_description.index << "].binding (" << binding_description.desc.binding
<< ") (pointing to Locations [";
const char *separator = "";
for (const auto &location : binding_description.locations) {
ss << separator << location.first;
separator = ", ";
}
ss << "])";
return ss.str();
};
const spirv::EntryPoint *vertex_entry_point = last_bound.GetVertexEntryPoint();
// Can be NULL if pipeline binaries are used
if (!vertex_entry_point) {
return skip;
}
vvl::unordered_set<uint32_t> spirv_input_locations;
for (const auto &pair : vertex_entry_point->input_interface_slots) {
spirv_input_locations.emplace(pair.first.Location());
}
// It is ok to have binding descriptions not used, them and find if there is matching buffer tied to it or not
for (const auto &[binding_index, binding_description] : vertex_bindings) {
// If no attribute points to a binding, it is unused
if (binding_description.locations.empty()) {
continue;
}
bool shader_has_location = false;
for (const auto &location : binding_description.locations) {
if (spirv_input_locations.find(location.first) != spirv_input_locations.end()) {
shader_has_location = true;
break;
}
}
if (!shader_has_location) {
// If the Vertex shader doesn't declare the vertex input, there can be invalid/unbound bindings
continue;
}
const auto *vertex_buffer_binding = vvl::Find(cb_state.current_vertex_buffer_binding_info, binding_index);
if (!vertex_buffer_binding || !vertex_buffer_binding->bound) {
// Likely to not get
skip |=
LogError(vuid.vertex_binding_04007, last_bound.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"%s which didn't have a buffer bound from any vkCmdBindVertexBuffers call in this command buffer.",
print_binding(binding_description).c_str());
continue;
}
// This means the app actively set the buffer to null
// Going to hit VUID-vkCmdBindVertexBuffers-pBuffers-04001 first anyway
if (vertex_buffer_binding->buffer == VK_NULL_HANDLE) {
if (!enabled_features.nullDescriptor) {
skip |=
LogError(vuid.vertex_binding_null_04008, last_bound.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(), "%s which was bound with a buffer of VK_NULL_HANDLE, but nullDescriptor is not enabled.",
print_binding(binding_description).c_str());
}
continue;
}
const auto vertex_buffer_state = Get<vvl::Buffer>(vertex_buffer_binding->buffer);
if (!vertex_buffer_state) {
skip |= LogError(
vuid.vertex_binding_04007, last_bound.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"%s which has an invalid/destroyed buffer bound from a vkCmdBindVertexBuffers call in this command buffer.",
print_binding(binding_description).c_str());
continue;
}
for (const auto &location : binding_description.locations) {
const auto attr_index = location.second.index;
const auto &attr_desc = location.second.desc;
if (last_bound.IsDynamic(CB_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE)) {
const VkDeviceSize attribute_binding_extent = attr_desc.offset + GetVertexInputFormatSize(attr_desc.format);
if (vertex_buffer_binding->stride != 0 && vertex_buffer_binding->stride < attribute_binding_extent) {
skip |= LogError("VUID-vkCmdBindVertexBuffers2-pStrides-06209",
last_bound.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"(attribute binding %" PRIu32 ", attribute location %" PRIu32 ") The pStrides value (%" PRIu64
") parameter in the last call to %s is not 0 "
"and is less than the extent of the binding for the attribute (%" PRIu64 ").",
attr_desc.binding, attr_desc.location, vertex_buffer_binding->stride, String(vuid.function),
attribute_binding_extent);
}
}
if (!enabled_features.robustBufferAccess && !robust_pipeline) {
const VkDeviceSize vertex_buffer_offset = vertex_buffer_binding->offset;
// Use 1 as vertex/instance index to use buffer stride as well
const VkDeviceSize attrib_address = vertex_buffer_offset + vertex_buffer_binding->stride + attr_desc.offset;
VkDeviceSize vtx_attrib_req_alignment = GetVertexInputFormatSize(attr_desc.format);
// TODO - There is no real spec language describing these, but also almost no one supports these formats for vertex
// input and this check should probably just removed and do the safe division always. Will need to run against CTS
// before-and-after to make sure.
if (!vkuFormatIsPacked(attr_desc.format) && !vkuFormatIsCompressed(attr_desc.format) &&
!vkuFormatIsSinglePlane_422(attr_desc.format) && !vkuFormatIsMultiplane(attr_desc.format)) {
vtx_attrib_req_alignment = SafeDivision(vtx_attrib_req_alignment, vkuFormatComponentCount(attr_desc.format));
}
if (SafeModulo(attrib_address, vtx_attrib_req_alignment) != 0) {
LogObjectList objlist(last_bound.cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS));
objlist.add(vertex_buffer_state->Handle());
skip |= LogError(vuid.vertex_binding_attribute_02721, objlist, vuid.loc(),
"Format %s has an alignment of %" PRIu64 " but the alignment of attribAddress (%" PRIu64
") is not aligned in pVertexAttributeDescriptions[%" PRIu32 "] (binding=%" PRIu32
" location=%" PRIu32 ") where attribAddress = vertex buffer offset (%" PRIu64
") + binding stride (%" PRIu64 ") + attribute offset (%" PRIu32 ").",
string_VkFormat(attr_desc.format), vtx_attrib_req_alignment, attrib_address, attr_index,
attr_desc.binding, attr_desc.location, vertex_buffer_offset, vertex_buffer_binding->stride,
attr_desc.offset);
}
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawCustomResolve(const LastBound &last_bound, const vvl::RenderPass &rp_state,
const core::CommandBufferSubState &cb_sub_state,
const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
const VkRenderingFlags rendering_flags = rp_state.GetRenderingFlags();
const vvl::Struct flags_struct = rp_state.use_dynamic_rendering_inherited ? vvl::Struct::VkCommandBufferInheritanceRenderingInfo
: vvl::Struct::VkRenderingInfo;
if (rendering_flags & VK_RENDERING_FRAGMENT_REGION_BIT_EXT) {
if (last_bound.IsSampleShadingEnabled() && last_bound.GetMinSampleShading() != 0.0) {
skip |=
LogError(vuid.custom_resolve_11521, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"%s::flags includes VK_RENDERING_FRAGMENT_REGION_BIT_EXT, but minSampleShading needs to be 0\n%s",
String(flags_struct), last_bound.DescribeSampleShading().c_str());
}
}
const bool rp_has_custom_resolve = (rendering_flags & VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT) != 0;
// The remaining checks are only for pipeline, Shader Object doesn't have an explicit custom resolve info (except FDM)
if (!last_bound.pipeline_state) {
if (last_bound.IsStageBound(VK_SHADER_STAGE_FRAGMENT_BIT) && enabled_features.fragmentDensityMap && rp_has_custom_resolve) {
const AttachmentInfo &fdm_attachment =
cb_sub_state.base.active_attachments[cb_sub_state.base.GetDynamicRenderingAttachmentIndex(
AttachmentInfo::Type::FragmentDensityMap)];
if (fdm_attachment.image_view) {
const auto &shader_object = last_bound.GetShaderObjectState(ShaderObjectStage::FRAGMENT);
if (const auto shader_object_cr_info =
vku::FindStructInPNextChain<VkCustomResolveCreateInfoEXT>(shader_object->create_info.pNext)) {
if (cb_sub_state.custom_resolve.started && !shader_object_cr_info->customResolve) {
skip |= LogError(vuid.custom_resolve_11529,
cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"vkCmdBeginCustomResolveEXT was called in this render pass, %s is an active "
"FragmentDensityMap attachment, but the bound fragment shader object "
"VkCustomResolveCreateInfoEXT::customResolve is VK_FALSE",
FormatHandle(fdm_attachment.image_view->Handle()).c_str());
} else if (!cb_sub_state.custom_resolve.started && shader_object_cr_info->customResolve) {
// Exception if inside the seconary, as the vkCmdBeginCustomResolveEXT can be called prior to
// vkCmdExecuteCommands
if (!cb_sub_state.base.IsSecondary() || !cb_sub_state.custom_resolve.inherited_resolve) {
skip |=
LogError(vuid.custom_resolve_11530,
cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"vkCmdBeginCustomResolveEXT was not yet called in this render pass, %s is an active "
"FragmentDensityMap attachment, but the bound fragment shader object "
"VkCustomResolveCreateInfoEXT::customResolve is VK_TRUE%s",
FormatHandle(fdm_attachment.image_view->Handle()).c_str(),
cb_sub_state.base.IsSecondary()
? "\nFor secondary, this is only valid if VkCommandBufferInheritanceInfo::pNext has "
"VkCustomResolveCreateInfoEXT with customResolve set to VK_TRUE"
: "");
}
}
}
}
}
return skip;
}
const VkCustomResolveCreateInfoEXT *pipeline_cr_info = nullptr;
if (last_bound.pipeline_state->fragment_output_state) {
// Will get normal and GPL Fragment Output pipelines
pipeline_cr_info = vku::FindStructInPNextChain<VkCustomResolveCreateInfoEXT>(
last_bound.pipeline_state->fragment_output_state->parent.GetCreateInfoPNext());
}
if (rp_has_custom_resolve) {
if (!pipeline_cr_info) {
if (!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(vuid.custom_resolve_11522, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"%s::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound pipeline was not "
"created with a VkCustomResolveCreateInfoEXT struct",
String(flags_struct));
}
} else if (cb_sub_state.custom_resolve.started && !pipeline_cr_info->customResolve) {
if (!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(vuid.custom_resolve_11524, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"vkCmdBeginCustomResolveEXT was called in this render pass, but the bound pipeline "
"VkCustomResolveCreateInfoEXT::customResolve is VK_FALSE");
}
} else if (!cb_sub_state.custom_resolve.started && pipeline_cr_info->customResolve) {
// Exception if inside the seconary, as the vkCmdBeginCustomResolveEXT can be called prior to vkCmdExecuteCommands
if (!cb_sub_state.base.IsSecondary() || !cb_sub_state.custom_resolve.inherited_resolve) {
skip |= LogError(vuid.custom_resolve_11525, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"vkCmdBeginCustomResolveEXT was not yet called in this render pass, but the bound pipeline "
"VkCustomResolveCreateInfoEXT::customResolve is VK_TRUE%s",
cb_sub_state.base.IsSecondary()
? "\nFor secondary, this is only valid if VkCommandBufferInheritanceInfo::pNext has "
"VkCustomResolveCreateInfoEXT with customResolve set to VK_TRUE"
: "");
}
}
} else if (pipeline_cr_info) {
skip |= LogError(vuid.custom_resolve_11523, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"%s::flags did not include VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound pipeline was "
"created with a VkCustomResolveCreateInfoEXT struct",
String(flags_struct));
}
// Not what to do for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT cases
if (!rp_has_custom_resolve || !pipeline_cr_info || rp_state.use_dynamic_rendering_inherited) {
return skip;
}
const VkRenderingInfo &rendering_info = *rp_state.dynamic_rendering_begin_rendering_info.ptr();
if (pipeline_cr_info->colorAttachmentCount != rendering_info.colorAttachmentCount &&
!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(vuid.custom_resolve_11861, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"%s::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound pipeline "
"VkCustomResolveCreateInfoEXT::colorAttachmentCount (%" PRIu32
") doesn't match %s::colorAttachmentCount (%" PRIu32 ")",
String(flags_struct), pipeline_cr_info->colorAttachmentCount, String(flags_struct),
rendering_info.colorAttachmentCount);
}
const uint32_t max_used_count = std::min(rendering_info.colorAttachmentCount, pipeline_cr_info->colorAttachmentCount);
for (uint32_t i = 0; i < max_used_count; i++) {
const VkImageView resolve_image_view = rendering_info.pColorAttachments[i].resolveImageView;
if (resolve_image_view != VK_NULL_HANDLE) {
auto resolve_image_view_state = Get<vvl::ImageView>(resolve_image_view);
ASSERT_AND_RETURN_SKIP(resolve_image_view_state);
if (enabled_features.dynamicRenderingUnusedAttachments) {
if (pipeline_cr_info->pColorAttachmentFormats[i] != resolve_image_view_state->create_info.format &&
pipeline_cr_info->pColorAttachmentFormats[i] != VK_FORMAT_UNDEFINED) {
skip |= LogError(
vuid.custom_resolve_11864, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::pColorAttachmentFormats[%" PRIu32
"] (%s) doesn't match VkRenderingInfo::pColorAttachments[%" PRIu32
"]->resolveImageView (%s) created with %s",
i, string_VkFormat(pipeline_cr_info->pColorAttachmentFormats[i]), i,
FormatHandle(resolve_image_view).c_str(), string_VkFormat(resolve_image_view_state->create_info.format));
}
} else if (pipeline_cr_info->pColorAttachmentFormats[i] != resolve_image_view_state->create_info.format) {
skip |= LogError(
vuid.custom_resolve_11862, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::pColorAttachmentFormats[%" PRIu32
"] (%s) doesn't match VkRenderingInfo::pColorAttachments[%" PRIu32 "]->resolveImageView (%s) created with %s",
i, string_VkFormat(pipeline_cr_info->pColorAttachmentFormats[i]), i, FormatHandle(resolve_image_view).c_str(),
string_VkFormat(resolve_image_view_state->create_info.format));
}
} else if (pipeline_cr_info->pColorAttachmentFormats[i] != VK_FORMAT_UNDEFINED &&
!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(
vuid.custom_resolve_11863, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, "
"VkRenderingInfo::pColorAttachments[%" PRIu32
"]->resolveImageView is VK_NULL_HANDLE, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::pColorAttachmentFormats[%" PRIu32 "] (%s) is not VK_FORMAT_UNDEFINED",
i, i, string_VkFormat(pipeline_cr_info->pColorAttachmentFormats[i]));
}
}
if (rendering_info.pDepthAttachment) {
VkImageView resolve_image_view = rendering_info.pDepthAttachment->resolveImageView;
if (resolve_image_view == VK_NULL_HANDLE) {
if (pipeline_cr_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED &&
!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(vuid.custom_resolve_11865, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, "
"VkRenderingInfo::pDepthAttachment->resolveImageView is VK_NULL_HANDLE, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::depthAttachmentFormat (%s) is not VK_FORMAT_UNDEFINED",
string_VkFormat(pipeline_cr_info->depthAttachmentFormat));
}
} else {
auto resolve_image_view_state = Get<vvl::ImageView>(resolve_image_view);
ASSERT_AND_RETURN_SKIP(resolve_image_view_state);
if (enabled_features.dynamicRenderingUnusedAttachments) {
if (pipeline_cr_info->depthAttachmentFormat != resolve_image_view_state->create_info.format &&
pipeline_cr_info->depthAttachmentFormat != VK_FORMAT_UNDEFINED) {
skip |= LogError(
vuid.custom_resolve_11867, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::depthAttachmentFormat (%s) doesn't match "
"VkRenderingInfo::pDepthAttachment->resolveImageView (%s) created with %s",
string_VkFormat(pipeline_cr_info->depthAttachmentFormat), FormatHandle(resolve_image_view).c_str(),
string_VkFormat(resolve_image_view_state->create_info.format));
}
} else if (pipeline_cr_info->depthAttachmentFormat != resolve_image_view_state->create_info.format) {
skip |= LogError(vuid.custom_resolve_11866, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::depthAttachmentFormat (%s) doesn't match "
"VkRenderingInfo::pDepthAttachment->resolveImageView (%s) created with %s",
string_VkFormat(pipeline_cr_info->depthAttachmentFormat), FormatHandle(resolve_image_view).c_str(),
string_VkFormat(resolve_image_view_state->create_info.format));
}
}
}
if (rendering_info.pStencilAttachment) {
VkImageView resolve_image_view = rendering_info.pStencilAttachment->resolveImageView;
if (resolve_image_view == VK_NULL_HANDLE) {
if (pipeline_cr_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED &&
!enabled_features.dynamicRenderingUnusedAttachments) {
skip |= LogError(vuid.custom_resolve_11868, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS),
vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, "
"VkRenderingInfo::pStencilAttachment->resolveImageView is VK_NULL_HANDLE, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::stencilAttachmentFormat (%s) is not VK_FORMAT_UNDEFINED",
string_VkFormat(pipeline_cr_info->stencilAttachmentFormat));
}
} else {
auto resolve_image_view_state = Get<vvl::ImageView>(resolve_image_view);
ASSERT_AND_RETURN_SKIP(resolve_image_view_state);
if (enabled_features.dynamicRenderingUnusedAttachments) {
if (pipeline_cr_info->stencilAttachmentFormat != resolve_image_view_state->create_info.format &&
pipeline_cr_info->stencilAttachmentFormat != VK_FORMAT_UNDEFINED) {
skip |= LogError(
vuid.custom_resolve_11870, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::stencilAttachmentFormat (%s) doesn't match "
"VkRenderingInfo::pStencilAttachment->resolveImageView (%s) created with %s",
string_VkFormat(pipeline_cr_info->stencilAttachmentFormat), FormatHandle(resolve_image_view).c_str(),
string_VkFormat(resolve_image_view_state->create_info.format));
}
} else if (pipeline_cr_info->stencilAttachmentFormat != resolve_image_view_state->create_info.format) {
skip |= LogError(
vuid.custom_resolve_11869, cb_sub_state.base.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS), vuid.loc(),
"VkRenderingInfo::flags includes VK_RENDERING_CUSTOM_RESOLVE_BIT_EXT, but the bound "
"pipeline VkCustomResolveCreateInfoEXT::stencilAttachmentFormat (%s) doesn't match "
"VkRenderingInfo::pStencilAttachment->resolveImageView (%s) created with %s",
string_VkFormat(pipeline_cr_info->stencilAttachmentFormat), FormatHandle(resolve_image_view).c_str(),
string_VkFormat(resolve_image_view_state->create_info.format));
}
}
}
return skip;
}
bool CoreChecks::ValidateDrawDynamicRenderpassExternalFormatResolve(const LastBound &last_bound_state,
const vvl::RenderPass &rp_state,
const vvl::DrawDispatchVuid &vuid) const {
bool skip = false;
if (!last_bound_state.pipeline_state) {
// Need to understand if possible to actually use this extension with Shader Object
// https://gitlab.khronos.org/vulkan/vulkan/-/merge_requests/7510#note_547500
return skip;
}
const uint64_t pipeline_external_format = GetExternalFormat(last_bound_state.pipeline_state->GetCreateInfoPNext());
if (pipeline_external_format == 0) {
return skip;
}
const vvl::CommandBuffer &cb_state = last_bound_state.cb_state;
LogObjectList objlist = cb_state.GetObjectList(VK_PIPELINE_BIND_POINT_GRAPHICS);
const VkRenderingInfo &rendering_info = *(rp_state.dynamic_rendering_begin_rendering_info.ptr());
if (rendering_info.colorAttachmentCount == 1 &&
rendering_info.pColorAttachments[0].resolveMode == VK_RESOLVE_MODE_EXTERNAL_FORMAT_DOWNSAMPLE_BIT_ANDROID) {
if (auto resolve_image_view_state = Get<vvl::ImageView>(rendering_info.pColorAttachments[0].resolveImageView)) {
if (resolve_image_view_state->image_state->ahb_format != pipeline_external_format) {
skip |= LogError(vuid.external_format_resolve_09362, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64
" but the resolveImageView's image was created with externalFormat %" PRIu64 "",
pipeline_external_format, resolve_image_view_state->image_state->ahb_format);
}
}
if (auto color_image_view_state = Get<vvl::ImageView>(rendering_info.pColorAttachments[0].imageView)) {
if (color_image_view_state->image_state->ahb_format != pipeline_external_format) {
skip |= LogError(vuid.external_format_resolve_09363, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64
" but the imageView's image was created with externalFormat %" PRIu64 "",
pipeline_external_format, color_image_view_state->image_state->ahb_format);
}
}
}
if (last_bound_state.IsDynamic(CB_DYNAMIC_STATE_COLOR_BLEND_ENABLE_EXT) &&
cb_state.dynamic_state_value.color_blend_enable_attachments.test(0)) {
skip |= LogError(vuid.external_format_resolve_09364, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 ", but dynamic blend enable for attachment zero was set to VK_TRUE.",
pipeline_external_format);
}
if (last_bound_state.IsDynamic(CB_DYNAMIC_STATE_RASTERIZATION_SAMPLES_EXT) &&
cb_state.dynamic_state_value.rasterization_samples != VK_SAMPLE_COUNT_1_BIT) {
skip |=
LogError(vuid.external_format_resolve_09365, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 ", but dynamic rasterization samples set to %s.",
pipeline_external_format, string_VkSampleCountFlagBits(cb_state.dynamic_state_value.rasterization_samples));
}
if (last_bound_state.IsDynamic(CB_DYNAMIC_STATE_FRAGMENT_SHADING_RATE_KHR)) {
if (cb_state.dynamic_state_value.fragment_size.width != 1) {
skip |= LogError(vuid.external_format_resolve_09368, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 ", but dynamic fragment size width is %" PRIu32 ".",
pipeline_external_format, cb_state.dynamic_state_value.fragment_size.width);
}
if (cb_state.dynamic_state_value.fragment_size.height != 1) {
skip |= LogError(vuid.external_format_resolve_09369, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 ", but dynamic fragment size height is %" PRIu32 ".",
pipeline_external_format, cb_state.dynamic_state_value.fragment_size.height);
}
}
if (auto fragment_entry_point = last_bound_state.GetFragmentEntryPoint()) {
if (fragment_entry_point->execution_mode.Has(spirv::ExecutionModeSet::depth_replacing_bit)) {
skip |= LogError(vuid.external_format_resolve_09372, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 " but the fragment shader declares DepthReplacing.",
pipeline_external_format);
} else if (fragment_entry_point->execution_mode.Has(spirv::ExecutionModeSet::stencil_ref_replacing_bit)) {
skip |= LogError(vuid.external_format_resolve_09372, objlist, vuid.loc(),
"pipeline externalFormat is %" PRIu64 " but the fragment shader declares StencilRefReplacingEXT.",
pipeline_external_format);
}
}
return skip;
}
|