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
|
/*
* Copyright (c) 2015-2025 The Khronos Group Inc.
* Copyright (c) 2015-2025 Valve Corporation
* Copyright (c) 2015-2025 LunarG, Inc.
* Copyright (c) 2015-2025 Google, Inc.
* Modifications Copyright (C) 2020-2021 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
*/
#include "utils/cast_utils.h"
#include "../framework/layer_validation_tests.h"
#include "../framework/pipeline_helper.h"
#include <algorithm>
class NegativeQuery : public QueryTest {};
TEST_F(NegativeQuery, PerformanceCreation) {
TEST_DESCRIPTION("Create performance query without support");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
break;
}
if (counters.empty()) {
GTEST_SKIP() << "No queue reported any performance counter.";
}
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counters.size();
std::vector<uint32_t> counterIndices;
for (uint32_t c = 0; c < counters.size(); c++) counterIndices.push_back(c);
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper();
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool;
// Missing pNext
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-queryType-03222");
query_pool.Init(*m_device, query_pool_ci);
m_errorMonitor->VerifyFound();
query_pool_ci.pNext = &perf_query_pool_ci;
// Invalid counter indices
counterIndices.push_back(counters.size());
perf_query_pool_ci.counterIndexCount++;
perf_query_pool_ci.pCounterIndices = counterIndices.data();
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolPerformanceCreateInfoKHR-pCounterIndices-03321");
query_pool.Init(*m_device, query_pool_ci);
m_errorMonitor->VerifyFound();
perf_query_pool_ci.counterIndexCount--;
counterIndices.pop_back();
// Success
query_pool.Init(*m_device, query_pool_ci);
m_command_buffer.Begin();
// Missing acquire lock
{
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryPool-03223");
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
}
m_command_buffer.End();
}
TEST_F(NegativeQuery, PerformanceCounterCommandbufferScope) {
TEST_DESCRIPTION("Insert a performance query begin/end with respect to the command buffer counter scope");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
std::vector<uint32_t> counterIndices;
// Find a single counter with VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_BUFFER_KHR scope.
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
for (uint32_t counterIdx = 0; counterIdx < counters.size(); counterIdx++) {
if (counters[counterIdx].scope == VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_BUFFER_KHR) {
counterIndices.push_back(counterIdx);
break;
}
}
if (counterIndices.empty()) {
counters.clear();
continue;
}
break;
}
if (counterIndices.empty()) {
GTEST_SKIP() << "No queue reported any performance counter with command buffer scope.";
}
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counterIndices.size();
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper(&perf_query_pool_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(device(), queueFamilyIndex, 0, &queue);
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
// Not the first command.
{
vkt::Buffer buffer(*m_device, 4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdFillBuffer(m_command_buffer, buffer, 0, 4096, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryPool-03224");
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(queue);
}
// Not last command.
{
vkt::Buffer buffer(*m_device, 4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
vk::CmdFillBuffer(m_command_buffer, buffer, 0, 4096, 0);
m_command_buffer.End();
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-queryPool-03227");
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
}
vk::ReleaseProfilingLockKHR(device());
}
TEST_F(NegativeQuery, PerformanceCounterRenderPassScope) {
TEST_DESCRIPTION("Insert a performance query begin/end with respect to the render pass counter scope");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
std::vector<uint32_t> counterIndices;
// Find a single counter with VK_PERFORMANCE_COUNTER_SCOPE_RENDER_PASS_KHR scope.
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
for (uint32_t counterIdx = 0; counterIdx < counters.size(); counterIdx++) {
if (counters[counterIdx].scope == VK_PERFORMANCE_COUNTER_SCOPE_RENDER_PASS_KHR) {
counterIndices.push_back(counterIdx);
break;
}
}
if (counterIndices.empty()) {
counters.clear();
continue;
}
break;
}
if (counterIndices.empty()) {
GTEST_SKIP() << "No queue reported any performance counter with render pass scope.";
}
InitRenderTarget();
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counterIndices.size();
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper(&perf_query_pool_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(device(), queueFamilyIndex, 0, &queue);
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
// Inside a render pass.
{
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryPool-03225");
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.EndRenderPass();
m_command_buffer.End();
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(queue);
}
vk::ReleaseProfilingLockKHR(device());
}
TEST_F(NegativeQuery, PerformanceReleaseProfileLockBeforeSubmit) {
TEST_DESCRIPTION("Verify that we get an error if we release the profiling lock during the recording of performance queries");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
std::vector<uint32_t> counterIndices;
// Find a single counter with VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR scope.
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
for (uint32_t counterIdx = 0; counterIdx < counters.size(); counterIdx++) {
if (counters[counterIdx].scope == VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR) {
counterIndices.push_back(counterIdx);
break;
}
}
if (counterIndices.empty()) {
counters.clear();
continue;
}
break;
}
if (counterIndices.empty()) {
GTEST_SKIP() << "No queue reported any performance counter with render pass scope.";
}
InitRenderTarget();
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counterIndices.size();
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper(&perf_query_pool_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(device(), queueFamilyIndex, 0, &queue);
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
{
m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_command_buffer.End();
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(queue);
}
{
vkt::Buffer buffer(*m_device, 4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_command_buffer.Reset();
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
// Release while recording.
vk::ReleaseProfilingLockKHR(device());
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
m_errorMonitor->SetDesiredError("VUID-vkQueueSubmit-pCommandBuffers-03220");
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
vk::QueueWaitIdle(queue);
}
vk::ReleaseProfilingLockKHR(device());
}
TEST_F(NegativeQuery, PerformanceIncompletePasses) {
TEST_DESCRIPTION("Verify that we get an error if we don't submit a command buffer for each passes before getting the results.");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
AddOptionalExtensions(VK_KHR_VIDEO_QUEUE_EXTENSION_NAME);
// Vulkan 1.1 is a dependency of VK_KHR_video_queue, but both the version and the extension
// is optional from the point of view of this test case
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::hostQueryReset);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
if (IsPlatformMockICD()) {
GTEST_SKIP() << "vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR doesn't match up with profile queues";
}
VkPhysicalDevicePerformanceQueryPropertiesKHR perf_query_props = vku::InitStructHelper();
GetPhysicalDeviceProperties2(perf_query_props);
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
std::vector<uint32_t> counterIndices;
uint32_t nPasses = 0;
// Find all counters with VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR scope.
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
for (uint32_t counterIdx = 0; counterIdx < counters.size(); counterIdx++) {
if (counters[counterIdx].scope == VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR) counterIndices.push_back(counterIdx);
}
if (counterIndices.empty()) continue; // might not be a scope command
VkQueryPoolPerformanceCreateInfoKHR create_info = vku::InitStructHelper();
create_info.queueFamilyIndex = idx;
create_info.counterIndexCount = counterIndices.size();
create_info.pCounterIndices = &counterIndices[0];
vk::GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(Gpu(), &create_info, &nPasses);
if (nPasses < 2) {
counters.clear();
continue;
}
break;
}
if (counterIndices.empty()) {
GTEST_SKIP() << "No queue reported a set of counters that needs more than one pass.";
}
InitRenderTarget();
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counterIndices.size();
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper(&perf_query_pool_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(device(), queueFamilyIndex, 0, &queue);
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
{
const VkDeviceSize buf_size =
std::max((VkDeviceSize)4096, (VkDeviceSize)(sizeof(VkPerformanceCounterResultKHR) * counterIndices.size()));
vkt::Buffer buffer(*m_device, buf_size, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
VkCommandBufferBeginInfo command_buffer_begin_info = vku::InitStructHelper();
command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
vk::ResetQueryPoolEXT(device(), query_pool, 0, 1);
m_command_buffer.Begin(&command_buffer_begin_info);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdFillBuffer(m_command_buffer, buffer, 0, buf_size, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
// Invalid pass index
{
VkPerformanceQuerySubmitInfoKHR perf_submit_info = vku::InitStructHelper();
perf_submit_info.counterPassIndex = nPasses;
VkSubmitInfo submit_info = vku::InitStructHelper(&perf_submit_info);
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
m_errorMonitor->SetDesiredError("VUID-VkPerformanceQuerySubmitInfoKHR-counterPassIndex-03221");
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
}
// Leave the last pass out.
for (uint32_t passIdx = 0; passIdx < (nPasses - 1); passIdx++) {
VkPerformanceQuerySubmitInfoKHR perf_submit_info = vku::InitStructHelper();
perf_submit_info.counterPassIndex = passIdx;
VkSubmitInfo submit_info = vku::InitStructHelper(&perf_submit_info);
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
}
vk::QueueWaitIdle(queue);
std::vector<VkPerformanceCounterResultKHR> results;
results.resize(counterIndices.size());
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09441");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_WAIT_BIT);
m_errorMonitor->VerifyFound();
// submit the last pass
{
VkPerformanceQuerySubmitInfoKHR perf_submit_info = vku::InitStructHelper();
perf_submit_info.counterPassIndex = nPasses - 1;
VkSubmitInfo submit_info = vku::InitStructHelper(&perf_submit_info);
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
}
vk::QueueWaitIdle(queue);
// The stride is too small to return the data
if (counterIndices.size() > 2) {
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-04519");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * (results.size() - 1), 0);
m_errorMonitor->VerifyFound();
}
// Invalid stride
{
std::vector<VkPerformanceCounterResultKHR> results_invalid_stride;
results_invalid_stride.resize(counterIndices.size() * 2);
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-03229");
vk::GetQueryPoolResults(
device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results_invalid_stride.size(),
&results_invalid_stride[0], sizeof(VkPerformanceCounterResultKHR) * results_invalid_stride.size() + 4,
VK_QUERY_RESULT_WAIT_BIT);
m_errorMonitor->VerifyFound();
}
// Invalid flags for vkCmdCopyQueryPoolResults
if (perf_query_props.allowCommandBufferQueryCopies) {
m_command_buffer.Begin(&command_buffer_begin_info);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-09440");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0,
sizeof(VkPerformanceCounterResultKHR) * results.size(),
VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-09440");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0,
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_PARTIAL_BIT);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-09440");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0,
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_64_BIT);
m_errorMonitor->VerifyFound();
if (IsExtensionsEnabled(VK_KHR_VIDEO_QUEUE_EXTENSION_NAME)) {
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-09440");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0,
sizeof(VkPerformanceCounterResultKHR) * results.size(),
VK_QUERY_RESULT_WITH_STATUS_BIT_KHR);
m_errorMonitor->VerifyFound();
}
m_command_buffer.End();
}
// Invalid flags for vkGetQueryPoolResults
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09440");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09440");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_PARTIAL_BIT);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09440");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_64_BIT);
m_errorMonitor->VerifyFound();
if (IsExtensionsEnabled(VK_KHR_VIDEO_QUEUE_EXTENSION_NAME)) {
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09440");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_WITH_STATUS_BIT_KHR);
m_errorMonitor->VerifyFound();
}
vk::GetQueryPoolResults(device(), query_pool, 0, 1, sizeof(VkPerformanceCounterResultKHR) * results.size(), &results[0],
sizeof(VkPerformanceCounterResultKHR) * results.size(), VK_QUERY_RESULT_WAIT_BIT);
}
vk::ReleaseProfilingLockKHR(device());
}
TEST_F(NegativeQuery, PerformanceResetAndBegin) {
TEST_DESCRIPTION("Verify that we get an error if we reset & begin a performance query within the same primary command buffer.");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::hostQueryReset);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
auto queueFamilyProperties = m_device->Physical().queue_properties_;
uint32_t queueFamilyIndex = queueFamilyProperties.size();
std::vector<VkPerformanceCounterKHR> counters;
std::vector<uint32_t> counterIndices;
// Find a single counter with VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR scope.
for (uint32_t idx = 0; idx < queueFamilyProperties.size(); idx++) {
uint32_t nCounters;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, nullptr, nullptr);
if (nCounters == 0) continue;
counters.resize(nCounters);
for (auto &c : counters) {
c = vku::InitStructHelper();
}
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(Gpu(), idx, &nCounters, &counters[0], nullptr);
queueFamilyIndex = idx;
for (uint32_t counterIdx = 0; counterIdx < counters.size(); counterIdx++) {
if (counters[counterIdx].scope == VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR) {
counterIndices.push_back(counterIdx);
break;
}
}
break;
}
if (counterIndices.empty()) {
GTEST_SKIP() << "No queue reported a set of counters that needs more than one pass.";
}
InitRenderTarget();
VkQueryPoolPerformanceCreateInfoKHR perf_query_pool_ci = vku::InitStructHelper();
perf_query_pool_ci.queueFamilyIndex = queueFamilyIndex;
perf_query_pool_ci.counterIndexCount = counterIndices.size();
perf_query_pool_ci.pCounterIndices = &counterIndices[0];
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper(&perf_query_pool_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkQueue queue = VK_NULL_HANDLE;
vk::GetDeviceQueue(device(), queueFamilyIndex, 0, &queue);
{
VkAcquireProfilingLockInfoKHR lock_info = vku::InitStructHelper();
VkResult result = vk::AcquireProfilingLockKHR(device(), &lock_info);
ASSERT_TRUE(result == VK_SUCCESS);
}
{
vkt::Buffer buffer(*m_device, 4096, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
VkCommandBufferBeginInfo command_buffer_begin_info = vku::InitStructHelper();
command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-None-02863");
m_command_buffer.Reset();
m_command_buffer.Begin(&command_buffer_begin_info);
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
{
VkPerformanceQuerySubmitInfoKHR perf_submit_info = vku::InitStructHelper();
perf_submit_info.counterPassIndex = 0;
VkSubmitInfo submit_info = vku::InitStructHelper(&perf_submit_info);
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.pWaitDstStageMask = NULL;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
vk::QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
}
vk::QueueWaitIdle(queue);
m_errorMonitor->VerifyFound();
}
vk::ReleaseProfilingLockKHR(device());
}
TEST_F(NegativeQuery, HostResetNotEnabled) {
TEST_DESCRIPTION("Use vkResetQueryPoolEXT without enabling the feature");
AddRequiredExtensions(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-None-02665");
vk::ResetQueryPoolEXT(device(), query_pool, 0, 1);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, HostResetFirstQuery) {
TEST_DESCRIPTION("Bad firstQuery in vkResetQueryPoolEXT");
AddRequiredExtensions(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::hostQueryReset);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-firstQuery-09436");
vk::ResetQueryPoolEXT(device(), query_pool, 1, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, HostResetBadRange) {
TEST_DESCRIPTION("Bad range in vkResetQueryPoolEXT");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::hostQueryReset);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-firstQuery-09437");
vk::ResetQueryPool(device(), query_pool, 0, 2);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, HostResetQueryPool) {
TEST_DESCRIPTION("Invalid queryPool in vkResetQueryPoolEXT");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::hostQueryReset);
RETURN_IF_SKIP(Init());
// Create and destroy a query pool.
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
VkQueryPool bad_pool = query_pool;
query_pool.destroy();
// Attempt to reuse the query pool handle.
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-queryPool-parameter");
vk::ResetQueryPool(device(), bad_pool, 0, 1);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, HostResetDevice) {
TEST_DESCRIPTION("Device not matching queryPool in vkResetQueryPoolEXT");
SetTargetApiVersion(VK_API_VERSION_1_2);
RETURN_IF_SKIP(InitFramework());
VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset_features = vku::InitStructHelper();
GetPhysicalDeviceFeatures2(host_query_reset_features);
RETURN_IF_SKIP(InitState(nullptr, &host_query_reset_features));
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
// Create a second device with the feature enabled.
vkt::QueueCreateInfoArray queue_info(m_device->Physical().queue_properties_);
auto features = m_device->Physical().Features();
VkDeviceCreateInfo device_create_info = vku::InitStructHelper(&host_query_reset_features);
device_create_info.queueCreateInfoCount = queue_info.Size();
device_create_info.pQueueCreateInfos = queue_info.Data();
device_create_info.pEnabledFeatures = &features;
device_create_info.enabledExtensionCount = m_device_extension_names.size();
device_create_info.ppEnabledExtensionNames = m_device_extension_names.data();
VkDevice second_device;
ASSERT_EQ(VK_SUCCESS, vk::CreateDevice(Gpu(), &device_create_info, nullptr, &second_device));
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-queryPool-parent");
// Run vk::ResetQueryPoolExt on the wrong device.
vk::ResetQueryPool(second_device, query_pool, 0, 1);
m_errorMonitor->VerifyFound();
vk::DestroyDevice(second_device, nullptr);
}
TEST_F(NegativeQuery, CmdBufferQueryPoolDestroyed) {
TEST_DESCRIPTION("Attempt to draw with a command buffer that is invalid due to a query pool dependency being destroyed.");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("VUID-vkQueueSubmit-pCommandBuffers-00070");
// Destroy query pool dependency prior to submit to cause ERROR
query_pool.destroy();
m_default_queue->Submit(m_command_buffer);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, BeginQueryOnTimestampPool) {
TEST_DESCRIPTION("Call CmdBeginQuery on a TIMESTAMP query pool.");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-02804");
VkCommandBufferBeginInfo begin_info = vku::InitStructHelper();
vk::BeginCommandBuffer(m_command_buffer, &begin_info);
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::EndCommandBuffer(m_command_buffer);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, InsideRenderPass) {
RETURN_IF_SKIP(Init());
InitRenderTarget();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-None-07007");
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.EndRenderPass();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, OutsideRenderPass) {
RETURN_IF_SKIP(Init());
InitRenderTarget();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndRenderPass-None-07004");
m_command_buffer.EndRenderPass();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, InsideRenderPassDynamicRendering) {
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::dynamicRendering);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
VkRenderingAttachmentInfo color_attachment = vku::InitStructHelper();
color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkRenderingInfo begin_rendering_info = vku::InitStructHelper();
begin_rendering_info.layerCount = 1;
begin_rendering_info.renderArea = {{0, 0}, {64, 64}};
begin_rendering_info.colorAttachmentCount = 1;
begin_rendering_info.pColorAttachments = &color_attachment;
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_command_buffer.BeginRendering(begin_rendering_info);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-None-07007");
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.EndRendering();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, OutsideRenderPassDynamicRendering) {
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredExtensions(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::dynamicRendering);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
VkRenderingAttachmentInfo color_attachment = vku::InitStructHelper();
color_attachment.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkRenderingInfo begin_rendering_info = vku::InitStructHelper();
begin_rendering_info.layerCount = 1;
begin_rendering_info.renderArea = {{0, 0}, {64, 64}};
begin_rendering_info.colorAttachmentCount = 1;
begin_rendering_info.pColorAttachments = &color_attachment;
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_command_buffer.BeginRendering(begin_rendering_info);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndRendering-None-06999");
m_command_buffer.EndRendering();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PoolCreate) {
TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
RETURN_IF_SKIP(Init());
vkt::QueueCreateInfoArray queue_info(m_device->Physical().queue_properties_);
VkDevice local_device;
VkDeviceCreateInfo device_create_info = vku::InitStructHelper();
auto features = m_device->Physical().Features();
// Intentionally disable pipeline stats
features.pipelineStatisticsQuery = VK_FALSE;
device_create_info.queueCreateInfoCount = queue_info.Size();
device_create_info.pQueueCreateInfos = queue_info.Data();
device_create_info.enabledLayerCount = 0;
device_create_info.ppEnabledLayerNames = NULL;
device_create_info.pEnabledFeatures = &features;
device_create_info.enabledExtensionCount = m_device_extension_names.size();
device_create_info.ppEnabledExtensionNames = m_device_extension_names.data();
VkResult err = vk::CreateDevice(Gpu(), &device_create_info, nullptr, &local_device);
ASSERT_EQ(VK_SUCCESS, err);
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT;
VkQueryPool query_pool;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-queryType-00791");
vk::CreateQueryPool(local_device, &qpci, nullptr, &query_pool);
m_errorMonitor->VerifyFound();
qpci.queryType = VK_QUERY_TYPE_OCCLUSION;
qpci.queryCount = 0;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-queryCount-02763");
vk::CreateQueryPool(local_device, &qpci, nullptr, &query_pool);
m_errorMonitor->VerifyFound();
vk::DestroyDevice(local_device, nullptr);
}
TEST_F(NegativeQuery, Sizes) {
TEST_DESCRIPTION("Invalid size of using queries commands.");
RETURN_IF_SKIP(Init());
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
VkMemoryRequirements mem_reqs = {};
vk::GetBufferMemoryRequirements(device(), buffer, &mem_reqs);
const VkDeviceSize buffer_size = mem_reqs.size;
const uint32_t query_pool_size = 4;
vkt::QueryPool occlusion_query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, query_pool_size);
m_command_buffer.Begin();
// FirstQuery is too large
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-firstQuery-09436");
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-firstQuery-09437");
vk::CmdResetQueryPool(m_command_buffer, occlusion_query_pool, query_pool_size, 1);
m_errorMonitor->VerifyFound();
// Sum of firstQuery and queryCount is too large
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-firstQuery-09437");
vk::CmdResetQueryPool(m_command_buffer, occlusion_query_pool, 1, query_pool_size);
m_errorMonitor->VerifyFound();
// Actually reset all queries so they can be used
vk::CmdResetQueryPool(m_command_buffer, occlusion_query_pool, 0, query_pool_size);
vk::CmdBeginQuery(m_command_buffer, occlusion_query_pool, 0, 0);
// Query index to large
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-query-00810");
vk::CmdEndQuery(m_command_buffer, occlusion_query_pool, query_pool_size);
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, occlusion_query_pool, 0);
// FirstQuery is too large
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-firstQuery-09436");
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-firstQuery-09437");
vk::CmdCopyQueryPoolResults(m_command_buffer, occlusion_query_pool, query_pool_size, 1, buffer, 0, 0, 0);
m_errorMonitor->VerifyFound();
// sum of firstQuery and queryCount is too large
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-firstQuery-09437");
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryCount-09438");
vk::CmdCopyQueryPoolResults(m_command_buffer, occlusion_query_pool, 1, query_pool_size, buffer, 0, 0, 0);
m_errorMonitor->VerifyFound();
// Offset larger than buffer size
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-dstOffset-00819");
vk::CmdCopyQueryPoolResults(m_command_buffer, occlusion_query_pool, 0, 1, buffer, buffer_size + 4, 0, 0);
m_errorMonitor->VerifyFound();
// Buffer does not have enough storage from offset to contain result of each query
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-dstBuffer-00824");
vk::CmdCopyQueryPoolResults(m_command_buffer, occlusion_query_pool, 0, 2, buffer, buffer_size - 4, 4, 0);
m_errorMonitor->VerifyFound();
// Query is not a timestamp type
if (HasZeroTimestampValidBits()) {
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp-timestampValidBits-00829");
}
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp-queryPool-01416");
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, occlusion_query_pool, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
const size_t out_data_size = 16;
uint8_t data[out_data_size];
// FirstQuery is too large
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-firstQuery-09436");
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-firstQuery-09437");
vk::GetQueryPoolResults(device(), occlusion_query_pool, query_pool_size, 1, out_data_size, &data, 4, 0);
m_errorMonitor->VerifyFound();
// Sum of firstQuery and queryCount is too large
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-firstQuery-09437");
vk::GetQueryPoolResults(device(), occlusion_query_pool, 1, query_pool_size, out_data_size, &data, 4, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PreciseBit) {
TEST_DESCRIPTION("Check for correct Query Precise Bit circumstances.");
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
AddRequiredFeature(vkt::Feature::occlusionQueryPrecise);
RETURN_IF_SKIP(Init());
auto features = m_device->Physical().Features();
// Test for precise bit when query type is not OCCLUSION
if (features.occlusionQueryPrecise) {
vkt::Event event(*m_device);
VkQueryPoolCreateInfo query_pool_create_info = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 3);
query_pool_create_info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT |
VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT |
VK_QUERY_PIPELINE_STATISTIC_VERTEX_SHADER_INVOCATIONS_BIT;
vkt::QueryPool query_pool(*m_device, query_pool_create_info);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, query_pool_create_info.queryCount);
m_command_buffer.End();
m_default_queue->SubmitAndWait(m_command_buffer);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-00800");
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, VK_QUERY_CONTROL_PRECISE_BIT);
m_errorMonitor->VerifyFound();
// vk::CmdBeginQuery(m_command_buffer, query_pool, 0, VK_QUERY_CONTROL_PRECISE_BIT);
m_command_buffer.End();
const size_t out_data_size = 64;
uint8_t data[out_data_size];
// The dataSize is too small to return the data
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-dataSize-00817");
vk::GetQueryPoolResults(device(), query_pool, 0, 3, 8, &data, 12, 0);
m_errorMonitor->VerifyFound();
}
// Test for precise bit when precise feature is not available
features.occlusionQueryPrecise = false;
vkt::Device test_device(Gpu(), m_device_extension_names, &features);
VkCommandPoolCreateInfo pool_create_info = vku::InitStructHelper();
pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
VkCommandPool command_pool;
vk::CreateCommandPool(test_device, &pool_create_info, nullptr, &command_pool);
VkCommandBufferAllocateInfo cmd = vku::InitStructHelper();
cmd.commandPool = command_pool;
cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cmd.commandBufferCount = 1;
VkCommandBuffer cmd_buffer;
VkResult err = vk::AllocateCommandBuffers(test_device, &cmd, &cmd_buffer);
ASSERT_EQ(VK_SUCCESS, err);
VkCommandBuffer cmd_buffer2;
err = vk::AllocateCommandBuffers(test_device, &cmd, &cmd_buffer2);
ASSERT_EQ(VK_SUCCESS, err);
VkEvent event;
VkEventCreateInfo event_create_info = vku::InitStructHelper();
vk::CreateEvent(test_device, &event_create_info, nullptr, &event);
VkCommandBufferBeginInfo begin_info = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, nullptr};
vkt::QueryPool query_pool(test_device, VK_QUERY_TYPE_OCCLUSION, 2);
vk::BeginCommandBuffer(cmd_buffer2, &begin_info);
vk::CmdResetQueryPool(cmd_buffer2, query_pool, 0, 2);
vk::EndCommandBuffer(cmd_buffer2);
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &cmd_buffer2;
vk::QueueSubmit(test_device.QueuesWithGraphicsCapability().front()->handle(), 1, &submit_info, VK_NULL_HANDLE);
vk::QueueWaitIdle(test_device.QueuesWithGraphicsCapability().front()->handle());
vk::BeginCommandBuffer(cmd_buffer, &begin_info);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-00800");
vk::CmdBeginQuery(cmd_buffer, query_pool, 0, VK_QUERY_CONTROL_PRECISE_BIT);
m_errorMonitor->VerifyFound();
vk::EndCommandBuffer(cmd_buffer);
const size_t out_data_size = 16;
uint8_t data[out_data_size];
// The dataSize is too small to return the data
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-dataSize-00817");
vk::GetQueryPoolResults(test_device, query_pool, 0, 2, 8, &data, out_data_size / 2, 0);
m_errorMonitor->VerifyFound();
vk::DestroyEvent(test_device, event, nullptr);
vk::DestroyCommandPool(test_device, command_pool, nullptr);
}
TEST_F(NegativeQuery, PoolPartialTimestamp) {
TEST_DESCRIPTION("Request partial result on timestamp query.");
RETURN_IF_SKIP(Init());
InitRenderTarget();
if (HasZeroTimestampValidBits()) {
GTEST_SKIP() << "Device graphic queue has timestampValidBits of 0, skipping.\n";
}
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
// Use setup as a positive test...
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-09439");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0, 8, VK_QUERY_RESULT_PARTIAL_BIT);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
// Submit cmd buffer and wait for it.
VkSubmitInfo submit_info = vku::InitStructHelper();
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &m_command_buffer.handle();
vk::QueueSubmit(m_default_queue->handle(), 1, &submit_info, VK_NULL_HANDLE);
m_default_queue->Wait();
// Attempt to obtain partial results.
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09439");
uint32_t data_space[16];
m_errorMonitor->SetUnexpectedError("Cannot get query results on queryPool");
vk::GetQueryPoolResults(*m_device, query_pool, 0, 1, sizeof(data_space), &data_space, sizeof(uint32_t),
VK_QUERY_RESULT_PARTIAL_BIT);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PerformanceQueryIntel) {
TEST_DESCRIPTION("Call CmdCopyQueryPoolResults for an Intel performance query.");
AddRequiredExtensions(VK_INTEL_PERFORMANCE_QUERY_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
VkInitializePerformanceApiInfoINTEL performance_api_info_intel = vku::InitStructHelper();
vk::InitializePerformanceApiINTEL(device(), &performance_api_info_intel);
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PERFORMANCE_QUERY_INTEL, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryType-02734");
m_command_buffer.Begin();
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0, 8, 0);
m_command_buffer.End();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PoolInUseDestroyedSignaled) {
TEST_DESCRIPTION("Delete in-use query pool.");
RETURN_IF_SKIP(Init());
if (HasZeroTimestampValidBits()) {
GTEST_SKIP() << "Device graphic queue has timestampValidBits of 0, skipping.";
}
InitRenderTarget();
VkQueryPool query_pool;
VkQueryPoolCreateInfo query_pool_ci = vku::InitStructHelper();
query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
query_pool_ci.queryCount = 1;
vk::CreateQueryPool(device(), &query_pool_ci, nullptr, &query_pool);
m_command_buffer.Begin();
// Use query pool to create binding with cmd buffer
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool, 0);
m_command_buffer.End();
// Submit cmd buffer and then destroy query pool while in-flight
m_default_queue->Submit(m_command_buffer);
m_errorMonitor->SetDesiredError("VUID-vkDestroyQueryPool-queryPool-00793");
vk::DestroyQueryPool(*m_device, query_pool, NULL);
m_errorMonitor->VerifyFound();
m_default_queue->Wait();
// Now that cmd buffer done we can safely destroy query_pool
m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
m_errorMonitor->SetUnexpectedError("Unable to remove QueryPool obj");
vk::DestroyQueryPool(*m_device, query_pool, NULL);
}
TEST_F(NegativeQuery, WriteTimeStamp) {
TEST_DESCRIPTION("Test for invalid query slot in query pool.");
AddRequiredExtensions(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::synchronization2);
RETURN_IF_SKIP(Init());
InitRenderTarget();
if (HasZeroTimestampValidBits()) {
GTEST_SKIP() << "Device graphic queue has timestampValidBits of 0, skipping.\n";
}
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp-query-04904");
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, CmdEndQueryIndexedEXTIndex) {
TEST_DESCRIPTION("Test InvalidCmdEndQueryIndexedEXT with invalid index");
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_properties = vku::InitStructHelper();
GetPhysicalDeviceProperties2(transform_feedback_properties);
if (transform_feedback_properties.maxTransformFeedbackStreams < 1) {
GTEST_SKIP() << "maxTransformFeedbackStreams < 1";
}
vkt::QueryPool tf_query_pool(*m_device, VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT, 1);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdBeginQueryIndexedEXT(m_command_buffer, tf_query_pool, 0, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06694");
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06696");
vk::CmdEndQueryIndexedEXT(m_command_buffer, tf_query_pool, 0, transform_feedback_properties.maxTransformFeedbackStreams);
vk::CmdBeginQueryIndexedEXT(m_command_buffer, query_pool, 0, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06695");
vk::CmdEndQueryIndexedEXT(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-None-02342");
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-query-02343");
vk::CmdEndQueryIndexedEXT(m_command_buffer, query_pool, 1, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, CmdEndQueryIndexedEXTPrimitiveGenerated) {
TEST_DESCRIPTION("Test InvalidCmdEndQueryIndexedEXT with invalid index");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQueryWithNonZeroStreams);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQuery);
RETURN_IF_SKIP(Init());
VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_properties = vku::InitStructHelper();
GetPhysicalDeviceProperties2(transform_feedback_properties);
vkt::QueryPool tf_query_pool(*m_device, VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT, 1);
vkt::QueryPool pg_query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-02339");
vk::CmdBeginQueryIndexedEXT(m_command_buffer, tf_query_pool, 0, 0, transform_feedback_properties.maxTransformFeedbackStreams);
m_errorMonitor->VerifyFound();
vk::CmdBeginQueryIndexedEXT(m_command_buffer, tf_query_pool, 0, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06696");
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06694");
vk::CmdEndQueryIndexedEXT(m_command_buffer, tf_query_pool, 0, transform_feedback_properties.maxTransformFeedbackStreams);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06690");
vk::CmdBeginQueryIndexedEXT(m_command_buffer, pg_query_pool, 0, 0, transform_feedback_properties.maxTransformFeedbackStreams);
m_errorMonitor->VerifyFound();
vk::CmdBeginQueryIndexedEXT(m_command_buffer, query_pool, 0, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06695");
vk::CmdEndQueryIndexedEXT(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, TransformFeedbackStream) {
TEST_DESCRIPTION(
"Call CmdBeginQuery with query type transform feedback stream when transformFeedbackQueries is not supported.");
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_props = vku::InitStructHelper();
GetPhysicalDeviceProperties2(transform_feedback_props);
if (transform_feedback_props.transformFeedbackQueries) {
GTEST_SKIP() << "Transform feedback queries are supported";
}
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TRANSFORM_FEEDBACK_STREAM_EXT, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-02328");
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, GetResultsFlags) {
TEST_DESCRIPTION("Test GetQueryPoolResults with invalid pData and stride");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_VIDEO_QUEUE_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
const size_t out_data_size = 16;
uint8_t data[out_data_size];
VkQueryResultFlags flags = VK_QUERY_RESULT_WITH_STATUS_BIT_KHR | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT;
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-flags-09443");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, out_data_size, data + 1, 4, flags);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, GetResultsStride) {
TEST_DESCRIPTION("Test GetQueryPoolResults with invalid queryCount and stride");
SetTargetApiVersion(VK_API_VERSION_1_1);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 2);
uint8_t data[8];
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryCount-09438");
vk::GetQueryPoolResults(device(), query_pool, 0, 2, 8, data, 0, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, ResultStatusOnly) {
TEST_DESCRIPTION("Request result status only query result.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_VIDEO_QUEUE_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_RESULT_STATUS_ONLY_KHR, 1);
if (!query_pool.initialized()) {
GTEST_SKIP() << "Required query not supported";
}
const size_t out_data_size = 16;
uint8_t data[out_data_size];
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryType-09442");
vk::GetQueryPoolResults(device(), query_pool, 0, 1, out_data_size, &data, sizeof(uint32_t), 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, DestroyActiveQueryPool) {
TEST_DESCRIPTION("Destroy query pool after GetQueryPoolResults() without VK_QUERY_RESULT_PARTIAL_BIT returns VK_SUCCESS");
RETURN_IF_SKIP(Init());
if (HasZeroTimestampValidBits()) {
GTEST_SKIP() << "Device graphic queue has timestampValidBits of 0, skipping.";
}
VkQueryPoolCreateInfo query_pool_create_info = vku::InitStructHelper();
query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
query_pool_create_info.queryCount = 1;
VkQueryPool query_pool;
vk::CreateQueryPool(device(), &query_pool_create_info, nullptr, &query_pool);
VkCommandBufferBeginInfo cmd_begin = vku::InitStructHelper();
cmd_begin.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
m_command_buffer.Begin(&cmd_begin);
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
m_command_buffer.End();
m_default_queue->Submit(m_command_buffer);
const size_t out_data_size = 16;
uint8_t data[out_data_size];
VkResult res;
do {
res = vk::GetQueryPoolResults(device(), query_pool, 0, 1, out_data_size, &data, 4, 0);
} while (res != VK_SUCCESS);
// Submit the command buffer again, making query pool in use and invalid to destroy
m_default_queue->Submit(m_command_buffer);
m_errorMonitor->SetDesiredError("VUID-vkDestroyQueryPool-queryPool-00793");
vk::DestroyQueryPool(*m_device, query_pool, nullptr);
m_errorMonitor->VerifyFound();
m_default_queue->Wait();
vk::DestroyQueryPool(*m_device, query_pool, nullptr);
}
TEST_F(NegativeQuery, MultiviewBeginQuery) {
TEST_DESCRIPTION("Test CmdBeginQuery in subpass with multiview");
SetTargetApiVersion(VK_API_VERSION_1_2);
AddRequiredFeature(vkt::Feature::multiview);
RETURN_IF_SKIP(Init());
VkAttachmentDescription attach = {};
attach.format = VK_FORMAT_B8G8R8A8_UNORM;
attach.samples = VK_SAMPLE_COUNT_1_BIT;
attach.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
attach.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
attach.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
attach.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
VkAttachmentReference color_att = {};
color_att.layout = VK_IMAGE_LAYOUT_GENERAL;
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &color_att;
uint32_t viewMasks[] = {0x3u};
uint32_t correlationMasks[] = {0x1u};
VkRenderPassMultiviewCreateInfo rpmv_ci = vku::InitStructHelper();
rpmv_ci.subpassCount = 1;
rpmv_ci.pViewMasks = viewMasks;
rpmv_ci.correlationMaskCount = 1;
rpmv_ci.pCorrelationMasks = correlationMasks;
VkRenderPassCreateInfo rp_ci = vku::InitStructHelper(&rpmv_ci);
rp_ci.attachmentCount = 1;
rp_ci.pAttachments = &attach;
rp_ci.subpassCount = 1;
rp_ci.pSubpasses = &subpass;
vkt::RenderPass render_pass(*m_device, rp_ci);
VkImageCreateInfo image_ci = vku::InitStructHelper();
image_ci.imageType = VK_IMAGE_TYPE_2D;
image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
image_ci.extent.width = 64;
image_ci.extent.height = 64;
image_ci.extent.depth = 1;
image_ci.mipLevels = 1;
image_ci.arrayLayers = 4;
image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
vkt::Image image(*m_device, image_ci, vkt::set_layout);
vkt::ImageView image_view = image.CreateView(VK_IMAGE_VIEW_TYPE_2D_ARRAY, 0, 1, 0, 4);
VkImageView image_view_handle = image_view;
vkt::Framebuffer framebuffer(*m_device, render_pass, 1, &image_view_handle, 64, 64);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 2);
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(render_pass, framebuffer, 64, 64);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-query-00808");
vk::CmdBeginQuery(m_command_buffer, query_pool, 1, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.EndRenderPass();
m_command_buffer.End();
}
TEST_F(NegativeQuery, PipelineStatisticsQuery) {
TEST_DESCRIPTION("Test unsupported pipeline statistics queries");
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
const std::optional<uint32_t> decode_queue_family_index = m_device->QueueFamily(VK_QUEUE_VIDEO_DECODE_BIT_KHR);
const std::optional<uint32_t> compute_queue_family_index = m_device->ComputeOnlyQueueFamily();
if (!decode_queue_family_index && !compute_queue_family_index) {
GTEST_SKIP() << "required queue families not found";
}
if (decode_queue_family_index) {
vkt::CommandPool command_pool(*m_device, decode_queue_family_index.value());
vkt::CommandBuffer command_buffer(*m_device, command_pool);
command_buffer.Begin();
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT;
vkt::QueryPool query_pool(*m_device, qpci);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-00805");
vk::CmdBeginQuery(command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
command_buffer.End();
}
if (compute_queue_family_index) {
vkt::CommandPool command_pool(*m_device, compute_queue_family_index.value());
vkt::CommandBuffer command_buffer(*m_device, command_pool);
command_buffer.Begin();
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_FRAGMENT_SHADER_INVOCATIONS_BIT;
vkt::QueryPool query_pool(*m_device, qpci);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-00804");
vk::CmdBeginQuery(command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
command_buffer.End();
}
}
TEST_F(NegativeQuery, TestGetQueryPoolResultsDataAndStride) {
TEST_DESCRIPTION("Test pData and stride multiple in GetQueryPoolResults");
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-flags-02828");
const size_t out_data_size = 16;
uint8_t data[out_data_size];
vk::GetQueryPoolResults(device(), query_pool, 0, 1, out_data_size, &data, 3, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PrimitivesGenerated) {
TEST_DESCRIPTION("Test unsupported primitives generated queries");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQuery);
RETURN_IF_SKIP(Init());
VkPhysicalDeviceTransformFeedbackPropertiesEXT transform_feedback_properties = vku::InitStructHelper();
GetPhysicalDeviceProperties2(transform_feedback_properties);
const std::optional<uint32_t> compute_queue_family_index = m_device->ComputeOnlyQueueFamily();
if (!compute_queue_family_index) {
GTEST_SKIP() << "required queue family not found, skipping test";
}
vkt::CommandPool command_pool(*m_device, compute_queue_family_index.value());
vkt::CommandBuffer command_buffer(*m_device, command_pool);
command_buffer.Begin();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-06687");
vk::CmdBeginQuery(command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06689");
vk::CmdBeginQueryIndexedEXT(command_buffer, query_pool, 0, 0, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06690");
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06691");
vk::CmdBeginQueryIndexedEXT(m_command_buffer, query_pool, 0, 0, transform_feedback_properties.maxTransformFeedbackStreams);
m_errorMonitor->VerifyFound();
vkt::QueryPool occlusion_query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06692");
vk::CmdBeginQueryIndexedEXT(m_command_buffer, occlusion_query_pool, 0, 0, 1);
m_errorMonitor->VerifyFound();
vk::CmdBeginQueryIndexedEXT(m_command_buffer, query_pool, 0, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQueryIndexedEXT-queryType-06696");
vk::CmdEndQueryIndexedEXT(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PrimitivesGeneratedFeature) {
TEST_DESCRIPTION("Test missing primitives generated query feature");
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryType-06688");
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQueryIndexedEXT-queryType-06693");
vk::CmdBeginQueryIndexedEXT(m_command_buffer, query_pool, 0, 0, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PrimitivesGeneratedDiscardEnabled) {
TEST_DESCRIPTION("Test missing primitivesGeneratedQueryWithRasterizerDiscard feature.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQuery);
RETURN_IF_SKIP(Init());
InitRenderTarget();
VkPipelineRasterizationStateCreateInfo rs_ci = vku::InitStructHelper();
rs_ci.lineWidth = 1.0f;
rs_ci.rasterizerDiscardEnable = VK_TRUE;
CreatePipelineHelper pipe(*this);
pipe.rs_state_ci_ = rs_ci;
// Rasterization discard enable prohibits fragment shader.
pipe.VertexShaderOnly();
pipe.CreateGraphicsPipeline();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-primitivesGeneratedQueryWithRasterizerDiscard-06708");
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
vk::CmdDraw(m_command_buffer, 3, 1, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.EndRenderPass();
m_command_buffer.End();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, PrimitivesGeneratedStreams) {
TEST_DESCRIPTION("Test missing primitivesGeneratedQueryWithNonZeroStreams feature.");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::transformFeedback);
AddRequiredFeature(vkt::Feature::geometryStreams);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQuery);
RETURN_IF_SKIP(Init());
VkPhysicalDeviceTransformFeedbackPropertiesEXT xfb_props = vku::InitStructHelper();
GetPhysicalDeviceProperties2(xfb_props);
if (!xfb_props.transformFeedbackRasterizationStreamSelect) {
GTEST_SKIP() << "VkPhysicalDeviceTransformFeedbackFeaturesEXT::transformFeedbackRasterizationStreamSelect is VK_FALSE";
}
InitRenderTarget();
VkPipelineRasterizationStateStreamCreateInfoEXT rasterization_streams = vku::InitStructHelper();
rasterization_streams.rasterizationStream = 1;
CreatePipelineHelper pipe(*this);
pipe.rs_state_ci_.pNext = &rasterization_streams;
pipe.CreateGraphicsPipeline();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-primitivesGeneratedQueryWithNonZeroStreams-06709");
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
vk::CmdDraw(m_command_buffer, 3, 1, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.EndRenderPass();
m_command_buffer.End();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, CommandBufferMissingOcclusion) {
TEST_DESCRIPTION(
"Test executing secondary command buffer without VkCommandBufferInheritanceInfo::occlusionQueryEnable enabled while "
"occlusion query is active.");
AddRequiredFeature(vkt::Feature::inheritedQueries);
RETURN_IF_SKIP(Init());
InitRenderTarget();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
vkt::CommandBuffer secondary(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
VkCommandBufferInheritanceInfo cbii = vku::InitStructHelper();
cbii.renderPass = m_renderPass;
cbii.framebuffer = Framebuffer();
cbii.occlusionQueryEnable = VK_FALSE; // Invalid
VkCommandBufferBeginInfo cbbi = vku::InitStructHelper();
cbbi.pInheritanceInfo = &cbii;
VkCommandBuffer secondary_handle = secondary;
vk::BeginCommandBuffer(secondary_handle, &cbbi);
vk::EndCommandBuffer(secondary_handle);
m_errorMonitor->SetDesiredError("VUID-vkCmdExecuteCommands-commandBuffer-00102");
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdExecuteCommands(m_command_buffer, 1, &secondary_handle);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, CommandBufferInheritanceFlags) {
TEST_DESCRIPTION("Test executing secondary command buffer with bad VkCommandBufferInheritanceInfo::queryFlags.");
AddRequiredFeature(vkt::Feature::occlusionQueryPrecise);
AddRequiredFeature(vkt::Feature::inheritedQueries);
RETURN_IF_SKIP(Init());
InitRenderTarget();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
vkt::CommandBuffer secondary(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
VkCommandBufferInheritanceInfo cbii = vku::InitStructHelper();
cbii.renderPass = m_renderPass;
cbii.framebuffer = Framebuffer();
cbii.occlusionQueryEnable = VK_TRUE;
cbii.queryFlags = 0;
VkCommandBufferBeginInfo cbbi = vku::InitStructHelper();
cbbi.pInheritanceInfo = &cbii;
VkCommandBuffer secondary_handle = secondary;
vk::BeginCommandBuffer(secondary_handle, &cbbi);
vk::EndCommandBuffer(secondary_handle);
m_errorMonitor->SetDesiredError("VUID-vkCmdExecuteCommands-commandBuffer-00103");
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, VK_QUERY_CONTROL_PRECISE_BIT);
vk::CmdExecuteCommands(m_command_buffer, 1, &secondary_handle);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, MeshShaderQueries) {
TEST_DESCRIPTION("Invalid usage without meshShaderQueries enabled");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_MESH_SHADER_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
VkQueryPool pool = VK_NULL_HANDLE;
VkQueryPoolCreateInfo query_pool_info = vku::InitStructHelper();
query_pool_info.queryType = VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT;
query_pool_info.flags = 0;
query_pool_info.queryCount = 1;
query_pool_info.pipelineStatistics = 0;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-meshShaderQueries-07068");
vk::CreateQueryPool(*m_device, &query_pool_info, nullptr, &pool);
m_errorMonitor->VerifyFound();
query_pool_info.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
query_pool_info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_TASK_SHADER_INVOCATIONS_BIT_EXT;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-meshShaderQueries-07069");
vk::CreateQueryPool(*m_device, &query_pool_info, nullptr, &pool);
m_errorMonitor->VerifyFound();
query_pool_info.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_MESH_SHADER_INVOCATIONS_BIT_EXT;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-meshShaderQueries-07069");
vk::CreateQueryPool(*m_device, &query_pool_info, nullptr, &pool);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, WriteTimestampWithoutQueryPool) {
TEST_DESCRIPTION("call vkCmdWriteTimestamp(2) with queryPool being invalid.");
AddRequiredExtensions(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::synchronization2);
RETURN_IF_SKIP(Init());
if (HasZeroTimestampValidBits()) {
GTEST_SKIP() << "Device graphic queue has timestampValidBits of 0, skipping.\n";
}
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp-queryPool-parameter");
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, bad_query_pool, 0);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp2-queryPool-parameter");
vk::CmdWriteTimestamp2KHR(m_command_buffer, VK_PIPELINE_STAGE_2_NONE, bad_query_pool, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, DestroyWithoutQueryPool) {
TEST_DESCRIPTION("call vkDestryQueryPool with queryPool being invalid.");
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
m_errorMonitor->SetDesiredError("VUID-vkDestroyQueryPool-queryPool-parameter");
vk::DestroyQueryPool(device(), bad_query_pool, nullptr);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, GetQueryPoolResultsWithoutQueryPool) {
TEST_DESCRIPTION("call vkGetQueryPoolResults with queryPool being invalid.");
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
const size_t out_data_size = 16;
uint8_t data[out_data_size];
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-queryPool-parameter");
vk::GetQueryPoolResults(device(), bad_query_pool, 0, 1, out_data_size, &data, 4, 0);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, CmdEndQueryWithoutQueryPool) {
TEST_DESCRIPTION("call vkCmdEndQuery with queryPool being invalid.");
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-queryPool-parameter");
vk::CmdEndQuery(m_command_buffer, bad_query_pool, 0);
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, CmdCopyQueryPoolResultsWithoutQueryPool) {
TEST_DESCRIPTION("call vkCmdCopyQueryPoolResults with queryPool being invalid.");
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
vkt::Buffer buffer(*m_device, 1024, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-queryPool-parameter");
vk::CmdCopyQueryPoolResults(m_command_buffer, bad_query_pool, 0, 1, buffer, 0, 0, VK_QUERY_RESULT_WAIT_BIT);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, CmdResetQueryPoolWithoutQueryPool) {
TEST_DESCRIPTION("call vkCmdResetQueryPool with queryPool being invalid.");
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-queryPool-parameter");
vk::CmdResetQueryPool(m_command_buffer, bad_query_pool, 0, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, ResetQueryPoolWithoutQueryPool) {
TEST_DESCRIPTION("call vkResetQueryPool with queryPool being invalid.");
SetTargetApiVersion(VK_API_VERSION_1_2);
RETURN_IF_SKIP(Init());
VkQueryPool bad_query_pool = CastFromUint64<VkQueryPool>(0xFFFFEEEE);
m_errorMonitor->SetDesiredError("VUID-vkResetQueryPool-queryPool-parameter");
vk::ResetQueryPool(device(), bad_query_pool, 0, 1);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, ActiveEndQuery) {
TEST_DESCRIPTION("Check all queries for vkCmdEndQuery are active");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->SetDesiredError("VUID-vkCmdEndQuery-None-01923");
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, ActiveCmdResetQueryPool) {
TEST_DESCRIPTION("Check all queries for vkCmdResetQueryPool are not active");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-None-02841");
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, ActiveCmdCopyQueryPoolResults) {
TEST_DESCRIPTION("Check all queries for vkCmdCopyQueryPoolResults are not active");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-None-07429");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 0, 0, VK_QUERY_RESULT_WAIT_BIT);
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, CmdExecuteCommandsActiveQueries) {
TEST_DESCRIPTION("Check query types when calling vkCmdExecuteCommands");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_PRIMITIVES_GENERATED_QUERY_EXTENSION_NAME);
AddRequiredExtensions(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::inheritedQueries);
AddRequiredFeature(vkt::Feature::primitivesGeneratedQuery);
RETURN_IF_SKIP(Init());
vkt::CommandPool pool(*m_device, m_device->graphics_queue_node_index_, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
vkt::CommandBuffer secondary(*m_device, pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_PRIMITIVES_GENERATED_EXT, 1);
VkCommandBufferInheritanceInfo cmd_buf_hinfo = vku::InitStructHelper();
VkCommandBufferBeginInfo cmd_buf_info = vku::InitStructHelper();
cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
vk::BeginCommandBuffer(secondary, &cmd_buf_info);
vk::EndCommandBuffer(secondary);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
m_errorMonitor->SetDesiredError("VUID-vkCmdExecuteCommands-commandBuffer-07594");
vk::CmdExecuteCommands(m_command_buffer, 1u, &secondary.handle());
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
}
TEST_F(NegativeQuery, CmdExecuteBeginActiveQuery) {
TEST_DESCRIPTION("Begin a query in secondary command buffer that is already active in primary command buffer");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::inheritedQueries);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 2);
VkCommandBufferInheritanceInfo cbii = vku::InitStructHelper();
cbii.renderPass = m_renderPass;
cbii.occlusionQueryEnable = VK_TRUE;
VkCommandBufferBeginInfo cbbi = vku::InitStructHelper();
cbbi.pInheritanceInfo = &cbii;
vkt::CommandBuffer secondary(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
secondary.Begin(&cbbi);
vk::CmdBeginQuery(secondary, query_pool, 1u, 0u);
vk::CmdEndQuery(secondary, query_pool, 1u);
secondary.End();
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0u, 0u);
m_errorMonitor->SetDesiredError("VUID-vkCmdExecuteCommands-pCommandBuffers-00105");
vk::CmdExecuteCommands(m_command_buffer, 1u, &secondary.handle());
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0u);
m_command_buffer.End();
}
TEST_F(NegativeQuery, PerformanceQueryReset) {
TEST_DESCRIPTION("Invalid performance query pool reset");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
uint32_t counterCount = 0u;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(m_device->Physical(), m_device->graphics_queue_node_index_,
&counterCount, nullptr, nullptr);
std::vector<VkPerformanceCounterKHR> counters(counterCount, vku::InitStruct<VkPerformanceCounterKHR>());
std::vector<VkPerformanceCounterDescriptionKHR> counterDescriptions(counterCount,
vku::InitStruct<VkPerformanceCounterDescriptionKHR>());
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(m_device->Physical(), m_device->graphics_queue_node_index_,
&counterCount, counters.data(), counterDescriptions.data());
uint32_t enabledCounter = counterCount;
for (uint32_t i = 0; i < counterCount; ++i) {
if (counters[i].scope == VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR) {
enabledCounter = i;
break;
}
}
if (enabledCounter == counterCount) {
GTEST_SKIP() << "No counter with scope VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR found";
}
auto query_pool_performance_ci = vku::InitStruct<VkQueryPoolPerformanceCreateInfoKHR>();
query_pool_performance_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
query_pool_performance_ci.counterIndexCount = 1u;
query_pool_performance_ci.pCounterIndices = &enabledCounter;
uint32_t num_passes = 0u;
vk::GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(m_device->Physical(), &query_pool_performance_ci, &num_passes);
auto query_pool_ci = vku::InitStruct<VkQueryPoolCreateInfo>(&query_pool_performance_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1u;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
auto acquire_profiling_lock_info = vku::InitStruct<VkAcquireProfilingLockInfoKHR>();
acquire_profiling_lock_info.timeout = std::numeric_limits<uint64_t>::max();
vk::AcquireProfilingLockKHR(*m_device, &acquire_profiling_lock_info);
{
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0u, 1u);
m_command_buffer.End();
m_default_queue->Submit(m_command_buffer);
m_device->Wait();
}
vkt::CommandBuffer command_buffer(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
command_buffer.Begin();
vk::CmdBeginQuery(command_buffer, query_pool, 0u, 0u);
vk::CmdEndQuery(command_buffer, query_pool, 0u);
command_buffer.End();
for (uint32_t i = 0; i < 2; ++i) {
m_command_buffer.Begin();
if (i == 0) {
vk::CmdBeginQuery(m_command_buffer, query_pool, 0u, 0u);
vk::CmdEndQuery(m_command_buffer, query_pool, 0u);
} else {
vk::CmdExecuteCommands(m_command_buffer, 1u, &command_buffer.handle());
}
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0u, 1u);
m_command_buffer.End();
auto performance_query_submit_info = vku::InitStruct<VkPerformanceQuerySubmitInfoKHR>();
performance_query_submit_info.counterPassIndex = 0u;
auto submit_info = vku::InitStruct<VkSubmitInfo>(&performance_query_submit_info);
submit_info.commandBufferCount = 1u;
submit_info.pCommandBuffers = &m_command_buffer.handle();
m_errorMonitor->SetDesiredError("VUID-vkCmdResetQueryPool-firstQuery-02862");
vk::QueueSubmit(m_default_queue->handle(), 1u, &submit_info, VK_NULL_HANDLE);
m_errorMonitor->VerifyFound();
m_device->Wait();
}
vk::ReleaseProfilingLockKHR(*m_device);
}
TEST_F(NegativeQuery, GetQueryPoolResultsWithoutReset) {
TEST_DESCRIPTION("Get query pool results without ever resetting the query");
SetTargetApiVersion(VK_API_VERSION_1_2);
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_OCCLUSION, 1);
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
uint32_t data = 0u;
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-None-09401");
vk::GetQueryPoolResults(*m_device, query_pool, 0u, 1u, sizeof(uint32_t), &data, sizeof(uint32_t), 0u);
m_errorMonitor->VerifyFound();
m_command_buffer.Begin();
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0u, 1u, buffer, 0u, sizeof(uint32_t), 0u);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-None-09402");
m_default_queue->Submit(m_command_buffer);
m_errorMonitor->VerifyFound();
m_default_queue->Wait();
}
TEST_F(NegativeQuery, InvalidMeshQueryAtDraw) {
TEST_DESCRIPTION("Draw with vertex shader with mesh query active");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_EXT_MESH_SHADER_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::meshShader);
AddRequiredFeature(vkt::Feature::meshShaderQueries);
RETURN_IF_SKIP(Init());
InitRenderTarget();
CreatePipelineHelper pipe(*this);
pipe.CreateGraphicsPipeline();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_MESH_PRIMITIVES_GENERATED_EXT, 1);
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(m_renderPassBeginInfo);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0u, 0u);
vk::CmdBindPipeline(m_command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipe);
m_errorMonitor->SetDesiredError("VUID-vkCmdDraw-stage-07073");
vk::CmdDraw(m_command_buffer, 3u, 1u, 0u, 0u);
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0u);
m_command_buffer.EndRenderPass();
m_command_buffer.End();
}
TEST_F(NegativeQuery, PipelineStatisticsQueryWithSecondaryCmdBuffer) {
TEST_DESCRIPTION("Use a pipeline statistics query in secondary command buffer");
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::inheritedQueries);
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
InitRenderTarget();
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics =
VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT | VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_PRIMITIVES_BIT;
vkt::QueryPool query_pool(*m_device, qpci);
VkCommandBufferInheritanceInfo cbii = vku::InitStructHelper();
cbii.renderPass = m_renderPass;
cbii.framebuffer = Framebuffer();
cbii.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT;
VkCommandBufferBeginInfo cbbi = vku::InitStructHelper();
cbbi.pInheritanceInfo = &cbii;
vkt::CommandBuffer secondary(*m_device, m_command_pool, VK_COMMAND_BUFFER_LEVEL_SECONDARY);
secondary.Begin(&cbbi);
secondary.End();
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0u, 0u);
m_errorMonitor->SetDesiredError("VUID-vkCmdExecuteCommands-commandBuffer-00104");
vk::CmdExecuteCommands(m_command_buffer, 1u, &secondary.handle());
m_errorMonitor->VerifyFound();
vk::CmdEndQuery(m_command_buffer, query_pool, 0u);
m_command_buffer.End();
}
TEST_F(NegativeQuery, PipelineStatisticsZero) {
TEST_DESCRIPTION("Use a pipeline statistics query in secondary command buffer");
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics = 0;
m_errorMonitor->SetDesiredError("VUID-VkQueryPoolCreateInfo-queryType-09534");
vkt::QueryPool query_pool(*m_device, qpci);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, WriteTimestampInsideRenderPass) {
TEST_DESCRIPTION("Call vkCmdWriteTimestamp() inside an active render pass instance");
AddRequiredExtensions(VK_KHR_MULTIVIEW_EXTENSION_NAME);
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredFeature(vkt::Feature::multiview);
RETURN_IF_SKIP(Init());
InitRenderTarget();
VkQueryPoolCreateInfo query_pool_create_info = vku::InitStructHelper();
query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
query_pool_create_info.queryCount = 2;
vkt::QueryPool query_pool(*m_device, query_pool_create_info);
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
uint32_t viewMasks[] = {0x3u};
uint32_t correlationMasks[] = {0x1u};
VkRenderPassMultiviewCreateInfo rpmv_ci = vku::InitStructHelper();
rpmv_ci.subpassCount = 1;
rpmv_ci.pViewMasks = viewMasks;
rpmv_ci.correlationMaskCount = 1;
rpmv_ci.pCorrelationMasks = correlationMasks;
VkRenderPassCreateInfo render_pass_ci = vku::InitStructHelper(&rpmv_ci);
render_pass_ci.subpassCount = 1u;
render_pass_ci.pSubpasses = &subpass;
vkt::RenderPass render_pass(*m_device, render_pass_ci);
VkFramebufferCreateInfo framebuffer_ci = vku::InitStructHelper();
framebuffer_ci.renderPass = render_pass;
framebuffer_ci.width = 32u;
framebuffer_ci.height = 32u;
framebuffer_ci.layers = 1u;
vkt::Framebuffer framebuffer(*m_device, framebuffer_ci);
VkRenderPassBeginInfo render_pass_bi = vku::InitStructHelper();
render_pass_bi.renderPass = render_pass;
render_pass_bi.framebuffer = framebuffer;
render_pass_bi.renderArea = {{0, 0}, {32u, 32u}};
render_pass_bi.clearValueCount = 1u;
render_pass_bi.pClearValues = m_renderPassClearValues.data();
m_command_buffer.Begin();
m_command_buffer.BeginRenderPass(render_pass_bi);
m_errorMonitor->SetDesiredError("VUID-vkCmdWriteTimestamp-query-00831");
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, query_pool, 1);
m_errorMonitor->VerifyFound();
m_command_buffer.EndRenderPass();
m_command_buffer.End();
}
TEST_F(NegativeQuery, Stride) {
TEST_DESCRIPTION("Validate Stride parameter.");
RETURN_IF_SKIP(Init());
uint32_t queue_count;
vk::GetPhysicalDeviceQueueFamilyProperties(Gpu(), &queue_count, nullptr);
std::vector<VkQueueFamilyProperties> queue_props(queue_count);
vk::GetPhysicalDeviceQueueFamilyProperties(Gpu(), &queue_count, queue_props.data());
if (queue_props[m_device->graphics_queue_node_index_].timestampValidBits == 0) {
GTEST_SKIP() << " Device graphic queue has timestampValidBits of 0, skipping.";
}
InitRenderTarget();
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0, 1);
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool, 0);
m_command_buffer.End();
m_default_queue->SubmitAndWait(m_command_buffer);
char data_space;
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-flags-02828");
vk::GetQueryPoolResults(*m_device, query_pool, 0, 1, sizeof(data_space), &data_space, 1, VK_QUERY_RESULT_WAIT_BIT);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-flags-00815");
vk::GetQueryPoolResults(*m_device, query_pool, 0, 1, sizeof(data_space), &data_space, 1,
(VK_QUERY_RESULT_WAIT_BIT | VK_QUERY_RESULT_64_BIT));
m_errorMonitor->VerifyFound();
char data_space4[4] = "";
vk::GetQueryPoolResults(*m_device, query_pool, 0, 1, sizeof(data_space4), &data_space4, 4, VK_QUERY_RESULT_WAIT_BIT);
char data_space8[8] = "";
vk::GetQueryPoolResults(*m_device, query_pool, 0, 1, sizeof(data_space8), &data_space8, 8,
(VK_QUERY_RESULT_WAIT_BIT | VK_QUERY_RESULT_64_BIT));
vkt::Buffer buffer(*m_device, 128, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_command_buffer.Reset();
m_command_buffer.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-flags-00822");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 1, 1, 0);
m_errorMonitor->VerifyFound();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-flags-00823");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 1, 1, VK_QUERY_RESULT_64_BIT);
m_errorMonitor->VerifyFound();
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 4, 4, 0);
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0, 1, buffer, 8, 8, VK_QUERY_RESULT_64_BIT);
}
TEST_F(NegativeQuery, PerfQueryQueueFamilyIndex) {
SetTargetApiVersion(VK_API_VERSION_1_1);
AddRequiredExtensions(VK_KHR_PERFORMANCE_QUERY_EXTENSION_NAME);
AddRequiredFeature(vkt::Feature::performanceCounterQueryPools);
RETURN_IF_SKIP(Init());
vkt::Queue *queue0 = m_default_queue;
auto queue1_family = m_device->ComputeOnlyQueueFamily();
if (!queue1_family.has_value()) {
GTEST_SKIP() << "Can't find two different queue families";
}
assert(queue0->family_index != queue1_family.value());
uint32_t counterCount = 0u;
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(m_device->Physical(), 0, &counterCount, nullptr, nullptr);
std::vector<VkPerformanceCounterKHR> counters(counterCount, vku::InitStruct<VkPerformanceCounterKHR>());
std::vector<VkPerformanceCounterDescriptionKHR> counterDescriptions(counterCount,
vku::InitStruct<VkPerformanceCounterDescriptionKHR>());
vk::EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(m_device->Physical(), 0, &counterCount, counters.data(),
counterDescriptions.data());
std::vector<uint32_t> enabledCounters(128);
const uint32_t enabledCounterCount = std::min(counterCount, static_cast<uint32_t>(enabledCounters.size()));
for (uint32_t i = 0; i < enabledCounterCount; ++i) {
enabledCounters[i] = i;
}
auto query_pool_performance_ci = vku::InitStruct<VkQueryPoolPerformanceCreateInfoKHR>();
query_pool_performance_ci.queueFamilyIndex = queue0->family_index;
query_pool_performance_ci.counterIndexCount = enabledCounterCount;
query_pool_performance_ci.pCounterIndices = enabledCounters.data();
uint32_t num_passes = 0;
vk::GetPhysicalDeviceQueueFamilyPerformanceQueryPassesKHR(m_device->Physical(), &query_pool_performance_ci, &num_passes);
auto query_pool_ci = vku::InitStruct<VkQueryPoolCreateInfo>(&query_pool_performance_ci);
query_pool_ci.queryType = VK_QUERY_TYPE_PERFORMANCE_QUERY_KHR;
query_pool_ci.queryCount = 1;
vkt::QueryPool query_pool(*m_device, query_pool_ci);
VkCommandPoolCreateInfo pool_create_info = vku::InitStructHelper();
pool_create_info.queueFamilyIndex = queue1_family.value();
pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
vkt::CommandPool command_pool(*m_device, pool_create_info);
vkt::CommandBuffer cb(*m_device, command_pool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
auto acquire_profiling_lock_info = vku::InitStruct<VkAcquireProfilingLockInfoKHR>();
acquire_profiling_lock_info.timeout = std::numeric_limits<uint64_t>::max();
vk::AcquireProfilingLockKHR(*m_device, &acquire_profiling_lock_info);
cb.Begin();
vk::CmdResetQueryPool(cb, query_pool, 0u, 1u);
cb.End();
cb.Begin();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-queryPool-07289");
vk::CmdBeginQuery(cb, query_pool, 0, 0);
m_errorMonitor->VerifyFound();
cb.End();
vk::ReleaseProfilingLockKHR(*m_device);
}
TEST_F(NegativeQuery, NoInitReset) {
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
InitRenderTarget();
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 1);
qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT;
vkt::QueryPool query_pool(*m_device, qpci);
m_command_buffer.Begin();
vk::CmdBeginQuery(m_command_buffer, query_pool, 0, 0);
vk::CmdEndQuery(m_command_buffer, query_pool, 0);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("VUID-vkCmdBeginQuery-None-00807");
m_default_queue->SubmitAndWait(m_command_buffer);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, CopyUnavailableQueries) {
TEST_DESCRIPTION("Copy query results when they are not available");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1u);
vkt::Buffer buffer(*m_device, 16u, VK_BUFFER_USAGE_TRANSFER_DST_BIT);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0u, 1u);
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0u, 1u, buffer, 0u, 0u, 0u);
m_command_buffer.End();
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-None-08752");
m_default_queue->SubmitAndWait(m_command_buffer);
m_errorMonitor->VerifyFound();
}
TEST_F(NegativeQuery, QueryResultCopyBufferInvalidFlags) {
TEST_DESCRIPTION("Copy query results to a buffer without transfer dst flag");
RETURN_IF_SKIP(Init());
vkt::QueryPool query_pool(*m_device, VK_QUERY_TYPE_TIMESTAMP, 1u);
vkt::Buffer buffer(*m_device, 16u, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0u, 1u);
vk::CmdWriteTimestamp(m_command_buffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, query_pool, 0u);
m_errorMonitor->SetDesiredError("VUID-vkCmdCopyQueryPoolResults-dstBuffer-00825");
vk::CmdCopyQueryPoolResults(m_command_buffer, query_pool, 0u, 1u, buffer, 0u, 0u, 0u);
m_errorMonitor->VerifyFound();
m_command_buffer.End();
}
TEST_F(NegativeQuery, QueryPoolResultsStride) {
AddRequiredFeature(vkt::Feature::pipelineStatisticsQuery);
RETURN_IF_SKIP(Init());
InitRenderTarget();
VkQueryPoolCreateInfo qpci = vkt::QueryPool::CreateInfo(VK_QUERY_TYPE_PIPELINE_STATISTICS, 2u);
qpci.pipelineStatistics = VK_QUERY_PIPELINE_STATISTIC_INPUT_ASSEMBLY_VERTICES_BIT;
vkt::QueryPool query_pool(*m_device, qpci);
m_command_buffer.Begin();
vk::CmdResetQueryPool(m_command_buffer, query_pool, 0u, 2u);
vk::CmdBeginQuery(m_command_buffer, query_pool, 0u, 0u);
vk::CmdEndQuery(m_command_buffer, query_pool, 0u);
vk::CmdBeginQuery(m_command_buffer, query_pool, 1u, 0u);
vk::CmdEndQuery(m_command_buffer, query_pool, 1u);
m_command_buffer.End();
m_default_queue->SubmitAndWait(m_command_buffer);
uint32_t data_space[4];
m_errorMonitor->SetDesiredError("VUID-vkGetQueryPoolResults-stride-08993");
vk::GetQueryPoolResults(*m_device, query_pool, 0u, 2u, sizeof(uint32_t) * 4, data_space, sizeof(uint32_t),
VK_QUERY_RESULT_WITH_AVAILABILITY_BIT);
m_errorMonitor->VerifyFound();
}
|