Hash :
da837830
Author :
Date :
2025-01-30T15:37:56
CL: Fix device queue query validation for 3.0 Was missing 3.0 check for device queue size. Since device queue support is optional for 3.0, device queue query (CL_QUEUE_SIZE) needed device queue support. Adding validation check for that here. Bug: angleproject:42267011 Change-Id: Ibc1d7e00f78df01f131f69047b1390b02b5fa780 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6220894 Reviewed-by: Gowtham Tammana <g.tammana@samsung.com> Commit-Queue: Austin Annestrand <a.annestrand@samsung.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019
//
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationCL.cpp: Validation functions for generic CL entry point parameters
// based on the OpenCL Specification V3.0.7, see https://www.khronos.org/registry/OpenCL/
// Each used CL error code is preceeded by a citation of the relevant rule in the spec.
#include "libANGLE/cl_utils.h"
#include "libANGLE/validationCL_autogen.h"
#include "common/string_utils.h"
#define ANGLE_VALIDATE_VERSION(version, major, minor) \
do \
{ \
if (version < CL_MAKE_VERSION(major##u, minor##u, 0u)) \
{ \
return CL_INVALID_VALUE; \
} \
} while (0)
#define ANGLE_VALIDATE_EXTENSION(extension) \
do \
{ \
if (!extension) \
{ \
return CL_INVALID_VALUE; \
} \
} while (0)
#define ANGLE_VALIDATE(expression) \
do \
{ \
const cl_int _errorCode = expression; \
if (_errorCode != CL_SUCCESS) \
{ \
return _errorCode; \
} \
} while (0)
#define ANGLE_VALIDATE_VERSION_OR_EXTENSION(version, major, minor, extension) \
do \
{ \
if (version < CL_MAKE_VERSION(major##u, minor##u, 0u)) \
{ \
ANGLE_VALIDATE_EXTENSION(extension); \
} \
} while (0)
namespace cl
{
namespace
{
cl_int ValidateContextProperties(const cl_context_properties *properties, const Platform *&platform)
{
platform = nullptr;
bool hasUserSync = false;
if (properties != nullptr)
{
while (*properties != 0)
{
switch (*properties++)
{
case CL_CONTEXT_PLATFORM:
{
// CL_INVALID_PROPERTY if the same property name is specified more than once.
if (platform != nullptr)
{
return CL_INVALID_PROPERTY;
}
cl_platform_id nativePlatform = reinterpret_cast<cl_platform_id>(*properties++);
// CL_INVALID_PLATFORM if platform value specified in properties
// is not a valid platform.
if (!Platform::IsValid(nativePlatform))
{
return CL_INVALID_PLATFORM;
}
platform = &nativePlatform->cast<Platform>();
break;
}
case CL_CONTEXT_INTEROP_USER_SYNC:
{
// CL_INVALID_PROPERTY if the value specified for a supported property name
// is not valid, or if the same property name is specified more than once.
if ((*properties != CL_FALSE && *properties != CL_TRUE) || hasUserSync)
{
return CL_INVALID_PROPERTY;
}
++properties;
hasUserSync = true;
break;
}
default:
{
// CL_INVALID_PROPERTY if context property name in properties
// is not a supported property name.
return CL_INVALID_PROPERTY;
}
}
}
}
return CL_SUCCESS;
}
bool ValidateMemoryFlags(MemFlags flags, const Platform &platform)
{
// CL_MEM_READ_WRITE, CL_MEM_WRITE_ONLY, and CL_MEM_READ_ONLY are mutually exclusive.
MemFlags allowedFlags(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY);
if (!flags.areMutuallyExclusive(CL_MEM_READ_WRITE, CL_MEM_WRITE_ONLY, CL_MEM_READ_ONLY))
{
return false;
}
// CL_MEM_USE_HOST_PTR is mutually exclusive with either of the other two flags.
allowedFlags.set(CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR);
if (!flags.areMutuallyExclusive(CL_MEM_USE_HOST_PTR,
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return false;
}
if (platform.isVersionOrNewer(1u, 2u))
{
// CL_MEM_HOST_WRITE_ONLY, CL_MEM_HOST_READ_ONLY,
// and CL_MEM_HOST_NO_ACCESS are mutually exclusive.
allowedFlags.set(CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS);
if (!flags.areMutuallyExclusive(CL_MEM_HOST_WRITE_ONLY, CL_MEM_HOST_READ_ONLY,
CL_MEM_HOST_NO_ACCESS))
{
return false;
}
}
if (platform.isVersionOrNewer(2u, 0u))
{
allowedFlags.set(CL_MEM_KERNEL_READ_AND_WRITE);
}
if (flags.hasOtherBitsThan(allowedFlags))
{
return false;
}
return true;
}
bool ValidateMapFlags(MapFlags flags, const Platform &platform)
{
MemFlags allowedFlags(CL_MAP_READ | CL_MAP_WRITE);
if (platform.isVersionOrNewer(1u, 2u))
{
// CL_MAP_READ or CL_MAP_WRITE and CL_MAP_WRITE_INVALIDATE_REGION are mutually exclusive.
allowedFlags.set(CL_MAP_WRITE_INVALIDATE_REGION);
if (!flags.areMutuallyExclusive(CL_MAP_WRITE_INVALIDATE_REGION, CL_MAP_READ | CL_MAP_WRITE))
{
return false;
}
}
if (flags.hasOtherBitsThan(allowedFlags))
{
return false;
}
return true;
}
bool ValidateMemoryProperties(const cl_mem_properties *properties)
{
if (properties != nullptr)
{
// OpenCL 3.0 does not define any optional properties.
// This function is reserved for extensions and future use.
if (*properties != 0)
{
return false;
}
}
return true;
}
cl_int ValidateCommandQueueAndEventWaitList(cl_command_queue commandQueue,
bool validateImageSupport,
cl_uint numEvents,
const cl_event *events)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(commandQueue))
{
return CL_INVALID_COMMAND_QUEUE;
}
const CommandQueue &queue = commandQueue->cast<CommandQueue>();
if (!queue.isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
if (validateImageSupport)
{
// CL_INVALID_OPERATION if the device associated with command_queue does not support images.
if (queue.getDevice().getInfo().imageSupport == CL_FALSE)
{
return CL_INVALID_OPERATION;
}
}
// CL_INVALID_EVENT_WAIT_LIST if event_wait_list is NULL and num_events_in_wait_list > 0,
// or event_wait_list is not NULL and num_events_in_wait_list is 0, ...
if ((events == nullptr) != (numEvents == 0u))
{
return CL_INVALID_EVENT_WAIT_LIST;
}
while (numEvents-- != 0u)
{
// or if event objects in event_wait_list are not valid events.
if (!Event::IsValid(*events))
{
return CL_INVALID_EVENT_WAIT_LIST;
}
// CL_INVALID_CONTEXT if the context associated with command_queue
// and events in event_wait_list are not the same.
if (&queue.getContext() != &(*events++)->cast<Event>().getContext())
{
return CL_INVALID_CONTEXT;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueBuffer(const CommandQueue &queue,
cl_mem buffer,
bool hostRead,
bool hostWrite)
{
// CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object.
if (!Buffer::IsValid(buffer))
{
return CL_INVALID_MEM_OBJECT;
}
const Buffer &buf = buffer->cast<Buffer>();
// CL_INVALID_CONTEXT if the context associated with command_queue and buffer are not the same.
if (&queue.getContext() != &buf.getContext())
{
return CL_INVALID_CONTEXT;
}
// CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and offset specified
// when the sub-buffer object is created is not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN
// value (which is in bits!) for device associated with queue.
if (buf.isSubBuffer() &&
(buf.getOffset() % (queue.getDevice().getInfo().memBaseAddrAlign / 8u)) != 0u)
{
return CL_MISALIGNED_SUB_BUFFER_OFFSET;
}
// CL_INVALID_OPERATION if a read function is called on buffer which
// has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostRead && buf.getFlags().intersects(CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_OPERATION if a write function is called on buffer which
// has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostWrite && buf.getFlags().intersects(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateBufferRect(const Buffer &buffer,
const size_t *origin,
const size_t *region,
size_t rowPitch,
size_t slicePitch)
{
// CL_INVALID_VALUE if origin or region is NULL.
if (origin == nullptr || region == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if any region array element is 0.
if (region[0] == 0u || region[1] == 0u || region[2] == 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if row_pitch is not 0 and is less than region[0].
if (rowPitch == 0u)
{
rowPitch = region[0];
}
else if (rowPitch < region[0])
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if slice_pitch is not 0 and is less than
// region[1] x row_pitch and not a multiple of row_pitch.
if (slicePitch == 0u)
{
slicePitch = region[1] * rowPitch;
}
else if (slicePitch < region[1] * rowPitch || (slicePitch % rowPitch) != 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if the region being read or written specified
// by (origin, region, row_pitch, slice_pitch) is out of bounds.
if (!buffer.isRegionValid(
origin[2] * slicePitch + origin[1] * rowPitch + origin[0],
(region[2] - 1u) * slicePitch + (region[1] - 1u) * rowPitch + region[0]))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateHostRect(const size_t *hostOrigin,
const size_t *region,
size_t hostRowPitch,
size_t hostSlicePitch,
const void *ptr)
{
// CL_INVALID_VALUE if host_origin or region is NULL.
if (hostOrigin == nullptr || region == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if any region array element is 0.
if (region[0] == 0u || region[1] == 0u || region[2] == 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if host_row_pitch is not 0 and is less than region[0].
if (hostRowPitch == 0u)
{
hostRowPitch = region[0];
}
else if (hostRowPitch < region[0])
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if host_slice_pitch is not 0 and is less than
// region[1] x host_row_pitch and not a multiple of host_row_pitch.
if (hostSlicePitch != 0u &&
(hostSlicePitch < region[1] * hostRowPitch || (hostSlicePitch % hostRowPitch) != 0u))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if ptr is NULL.
if (ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueImage(const CommandQueue &queue, cl_mem image, bool hostRead, bool hostWrite)
{
// CL_INVALID_MEM_OBJECT if image is not a valid image object.
if (!Image::IsValid(image))
{
return CL_INVALID_MEM_OBJECT;
}
const Image &img = image->cast<Image>();
// CL_INVALID_CONTEXT if the context associated with command_queue and image are not the same.
if (&queue.getContext() != &img.getContext())
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_OPERATION if a read function is called on image which
// has been created with CL_MEM_HOST_WRITE_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostRead && img.getFlags().intersects(CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_OPERATION if a write function is called on image which
// has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS.
if (hostWrite && img.getFlags().intersects(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS))
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateImageForDevice(const Image &image,
const Device &device,
const size_t *origin,
const size_t *region)
{
// CL_INVALID_VALUE if origin or region is NULL.
if (origin == nullptr || region == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if values in origin and region do not follow rules
// described in the argument description for origin and region.
// The values in region cannot be 0.
if (region[0] == 0u || region[1] == 0u || region[2] == 0u)
{
return CL_INVALID_VALUE;
}
switch (image.getType())
{
// If image is a 1D image or 1D image buffer object,
// origin[1] and origin[2] must be 0 and region[1] and region[2] must be 1.
case MemObjectType::Image1D:
case MemObjectType::Image1D_Buffer:
if (origin[1] != 0u || origin[2] != 0u || region[1] != 1u || region[2] != 1u)
{
return CL_INVALID_VALUE;
}
break;
// If image is a 2D image object or a 1D image array object,
// origin[2] must be 0 and region[2] must be 1.
case MemObjectType::Image2D:
case MemObjectType::Image1D_Array:
if (origin[2] != 0u || region[2] != 1u)
{
return CL_INVALID_VALUE;
}
break;
case MemObjectType::Image3D:
case MemObjectType::Image2D_Array:
break;
default:
ASSERT(false);
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// CL_INVALID_VALUE if the region being read or written
// specified by origin and region is out of bounds.
if (!image.isRegionValid(cl::MemOffsets{origin[0], origin[1], origin[2]},
cl::Coordinate{region[0], region[1], region[2]}))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_IMAGE_SIZE if image dimensions (image width, height, specified or compute
// row and/or slice pitch) for image are not supported by device associated with queue.
if (!device.supportsImageDimensions(image.getDescriptor()))
{
return CL_INVALID_IMAGE_SIZE;
}
return CL_SUCCESS;
}
cl_int ValidateHostRegionForImage(const Image &image,
const size_t region[3],
size_t rowPitch,
size_t slicePitch,
const void *ptr)
{
// CL_INVALID_VALUE if row_pitch is not 0 and is less than the element size in bytes x width.
if (rowPitch == 0u)
{
rowPitch = image.getElementSize() * region[0];
}
else if (rowPitch < image.getElementSize() * region[0])
{
return CL_INVALID_VALUE;
}
if (slicePitch != 0u)
{
// TODO(jplate) Follow up with https://github.com/KhronosGroup/OpenCL-Docs/issues/624
// This error is missing in the OpenCL spec.
// slice_pitch must be 0 if image is a 1D or 2D image.
if (image.getType() == MemObjectType::Image1D ||
image.getType() == MemObjectType::Image1D_Buffer ||
image.getType() == MemObjectType::Image2D)
{
return CL_INVALID_VALUE;
}
else if (slicePitch < rowPitch)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if slice_pitch is not 0 and is less than row_pitch x height.
else if (((image.getType() == MemObjectType::Image2D_Array) ||
(image.getType() == MemObjectType::Image3D)) &&
(slicePitch < rowPitch * region[1]))
{
return CL_INVALID_VALUE;
}
}
// CL_INVALID_VALUE if ptr is NULL.
if (ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
} // namespace
// CL 1.0
cl_int ValidateGetPlatformIDs(cl_uint num_entries,
const cl_platform_id *platforms,
const cl_uint *num_platforms)
{
// CL_INVALID_VALUE if num_entries is equal to zero and platforms is not NULL
// or if both num_platforms and platforms are NULL.
if ((num_entries == 0u && platforms != nullptr) ||
(platforms == nullptr && num_platforms == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetPlatformInfo(cl_platform_id platform,
PlatformInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_PLATFORM if platform is not a valid platform.
if (!Platform::IsValidOrDefault(platform))
{
return CL_INVALID_PLATFORM;
}
// CL_INVALID_VALUE if param_name is not one of the supported values.
const cl_version version = platform->cast<Platform>().getVersion();
switch (param_name)
{
case PlatformInfo::HostTimerResolution:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case PlatformInfo::NumericVersion:
case PlatformInfo::ExtensionsWithVersion:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case PlatformInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetDeviceIDs(cl_platform_id platform,
DeviceType device_type,
cl_uint num_entries,
const cl_device_id *devices,
const cl_uint *num_devices)
{
// CL_INVALID_PLATFORM if platform is not a valid platform.
if (!Platform::IsValidOrDefault(platform))
{
return CL_INVALID_PLATFORM;
}
// CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
if (!Device::IsValidType(device_type))
{
return CL_INVALID_DEVICE_TYPE;
}
// CL_INVALID_VALUE if num_entries is equal to zero and devices is not NULL
// or if both num_devices and devices are NULL.
if ((num_entries == 0u && devices != nullptr) || (num_devices == nullptr && devices == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetDeviceInfo(cl_device_id device,
DeviceInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device))
{
return CL_INVALID_DEVICE;
}
const Device &dev = device->cast<Device>();
// CL_INVALID_VALUE if param_name is not one of the supported values
// or if param_name is a value that is available as an extension
// and the corresponding extension is not supported by the device.
const cl_version version = dev.getVersion();
const rx::CLDeviceImpl::Info &info = dev.getInfo();
// Enums ordered within their version block as they appear in the OpenCL spec V3.0.7, table 5
switch (param_name)
{
case DeviceInfo::PreferredVectorWidthHalf:
case DeviceInfo::NativeVectorWidthChar:
case DeviceInfo::NativeVectorWidthShort:
case DeviceInfo::NativeVectorWidthInt:
case DeviceInfo::NativeVectorWidthLong:
case DeviceInfo::NativeVectorWidthFloat:
case DeviceInfo::NativeVectorWidthDouble:
case DeviceInfo::NativeVectorWidthHalf:
case DeviceInfo::HostUnifiedMemory:
case DeviceInfo::OpenCL_C_Version:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case DeviceInfo::ImageMaxBufferSize:
case DeviceInfo::ImageMaxArraySize:
case DeviceInfo::LinkerAvailable:
case DeviceInfo::BuiltInKernels:
case DeviceInfo::PrintfBufferSize:
case DeviceInfo::PreferredInteropUserSync:
case DeviceInfo::ParentDevice:
case DeviceInfo::PartitionMaxSubDevices:
case DeviceInfo::PartitionProperties:
case DeviceInfo::PartitionAffinityDomain:
case DeviceInfo::PartitionType:
case DeviceInfo::ReferenceCount:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case DeviceInfo::MaxReadWriteImageArgs:
case DeviceInfo::ImagePitchAlignment:
case DeviceInfo::ImageBaseAddressAlignment:
case DeviceInfo::MaxPipeArgs:
case DeviceInfo::PipeMaxActiveReservations:
case DeviceInfo::PipeMaxPacketSize:
case DeviceInfo::MaxGlobalVariableSize:
case DeviceInfo::GlobalVariablePreferredTotalSize:
case DeviceInfo::QueueOnDeviceProperties:
case DeviceInfo::QueueOnDevicePreferredSize:
case DeviceInfo::QueueOnDeviceMaxSize:
case DeviceInfo::MaxOnDeviceQueues:
case DeviceInfo::MaxOnDeviceEvents:
case DeviceInfo::SVM_Capabilities:
case DeviceInfo::PreferredPlatformAtomicAlignment:
case DeviceInfo::PreferredGlobalAtomicAlignment:
case DeviceInfo::PreferredLocalAtomicAlignment:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case DeviceInfo::IL_Version:
case DeviceInfo::MaxNumSubGroups:
case DeviceInfo::SubGroupIndependentForwardProgress:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case DeviceInfo::ILsWithVersion:
case DeviceInfo::BuiltInKernelsWithVersion:
case DeviceInfo::NumericVersion:
case DeviceInfo::OpenCL_C_AllVersions:
case DeviceInfo::OpenCL_C_Features:
case DeviceInfo::ExtensionsWithVersion:
case DeviceInfo::AtomicMemoryCapabilities:
case DeviceInfo::AtomicFenceCapabilities:
case DeviceInfo::NonUniformWorkGroupSupport:
case DeviceInfo::WorkGroupCollectiveFunctionsSupport:
case DeviceInfo::GenericAddressSpaceSupport:
case DeviceInfo::DeviceEnqueueCapabilities:
case DeviceInfo::PipeSupport:
case DeviceInfo::PreferredWorkGroupSizeMultiple:
case DeviceInfo::LatestConformanceVersionPassed:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case DeviceInfo::DoubleFpConfig:
// This extension became a core query from OpenCL 1.2 onward.
// Only need to validate for OpenCL versions less than 1.2 here.
ANGLE_VALIDATE_VERSION_OR_EXTENSION(version, 1, 2, info.khrFP64);
break;
case DeviceInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateCreateContext(const cl_context_properties *properties,
cl_uint num_devices,
const cl_device_id *devices,
void(CL_CALLBACK *pfn_notify)(const char *errinfo,
const void *private_info,
size_t cb,
void *user_data),
const void *user_data)
{
// CL_INVALID_VALUE if devices is NULL or if num_devices is equal to zero
// or if pfn_notify is NULL but user_data is not NULL.
if (devices == nullptr || num_devices == 0u || (pfn_notify == nullptr && user_data != nullptr))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in devices is not a valid device.
for (cl_uint i = 0; i < num_devices; ++i)
{
if (!Device::IsValid(devices[i]))
{
return CL_INVALID_DEVICE;
}
}
// Because ANGLE can have one or more platforms here (e.g. passthrough, Vulkan, etc.), if a
// context platform is not explicitly specified in the properties, spec says to default to an
// implementation-defined platform. In ANGLE's case, we can derive the platform from the device
// object.
const Platform *platform = nullptr;
ANGLE_VALIDATE(ValidateContextProperties(properties, platform));
if (platform == nullptr)
{
// Just use/pick the first device's platform object here
platform = &(devices[0])->cast<Device>().getPlatform();
}
// Ensure that each device in device list is derived from the same platform object
for (cl_uint i = 0; i < num_devices; ++i)
{
if (platform != &(devices[i])->cast<Device>().getPlatform())
{
return CL_INVALID_PLATFORM;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreateContextFromType(const cl_context_properties *properties,
DeviceType device_type,
void(CL_CALLBACK *pfn_notify)(const char *errinfo,
const void *private_info,
size_t cb,
void *user_data),
const void *user_data)
{
// CL_INVALID_DEVICE_TYPE if device_type is not a valid value.
if (!Device::IsValidType(device_type))
{
return CL_INVALID_DEVICE_TYPE;
}
const Platform *platform = nullptr;
ANGLE_VALIDATE(ValidateContextProperties(properties, platform));
if (platform == nullptr)
{
platform = Platform::GetDefault();
if (platform == nullptr)
{
return CL_INVALID_PLATFORM;
}
}
if (!platform->hasDeviceType(device_type))
{
return CL_DEVICE_NOT_FOUND;
}
// CL_INVALID_VALUE if pfn_notify is NULL but user_data is not NULL.
if (pfn_notify == nullptr && user_data != nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainContext(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid OpenCL context.
return Context::IsValid(context) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateReleaseContext(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid OpenCL context.
return Context::IsValid(context) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateGetContextInfo(cl_context context,
ContextInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if param_name is not one of the supported values.
if (param_name == ContextInfo::InvalidEnum)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainCommandQueue(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
return CommandQueue::IsValid(command_queue) ? CL_SUCCESS : CL_INVALID_COMMAND_QUEUE;
}
cl_int ValidateReleaseCommandQueue(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
return CommandQueue::IsValid(command_queue) ? CL_SUCCESS : CL_INVALID_COMMAND_QUEUE;
}
cl_int ValidateGetCommandQueueInfo(cl_command_queue command_queue,
CommandQueueInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue
if (!CommandQueue::IsValid(command_queue))
{
return CL_INVALID_COMMAND_QUEUE;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_VALUE if param_name is not one of the supported values.
const cl_version version = queue.getDevice().getVersion();
switch (param_name)
{
case CommandQueueInfo::Size:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case CommandQueueInfo::DeviceDefault:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case CommandQueueInfo::PropertiesArray:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case CommandQueueInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue for param_name.
if (param_name == CommandQueueInfo::Size)
{
if (queue.isOnDevice() && !queue.getDevice().hasDeviceEnqueueCaps())
{
return CL_INVALID_COMMAND_QUEUE;
}
if (queue.getDevice().getPlatform().isVersionOrNewer(3u, 0u) && !queue.isOnDevice())
{
// Device-side enqueue and on-device queues are optional for devices supporting
// OpenCL 3.0. When device-side enqueue is not supported:
// - clGetCommandQueueInfo, passing CL_QUEUE_SIZE Returns CL_INVALID_COMMAND_QUEUE since
// command_queue cannot be a valid device command-queue.
return CL_INVALID_COMMAND_QUEUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreateBuffer(cl_context context, MemFlags flags, size_t size, const void *host_ptr)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if values specified in flags are not valid
// as defined in the Memory Flags table.
if (!ValidateMemoryFlags(flags, ctx.getPlatform()))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_BUFFER_SIZE if size is 0 ...
if (size == 0u)
{
CL_INVALID_BUFFER_SIZE;
}
for (const DevicePtr &device : ctx.getDevices())
{
// or if size is greater than CL_DEVICE_MAX_MEM_ALLOC_SIZE for all devices in context.
if (size > device->getInfo().maxMemAllocSize)
{
return CL_INVALID_BUFFER_SIZE;
}
}
// CL_INVALID_HOST_PTR
// if host_ptr is NULL and CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in flags or
// if host_ptr is not NULL but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
if ((host_ptr != nullptr) != flags.intersects(CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_HOST_PTR;
}
return CL_SUCCESS;
}
cl_int ValidateRetainMemObject(cl_mem memobj)
{
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
return Memory::IsValid(memobj) ? CL_SUCCESS : CL_INVALID_MEM_OBJECT;
}
cl_int ValidateReleaseMemObject(cl_mem memobj)
{
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
return Memory::IsValid(memobj) ? CL_SUCCESS : CL_INVALID_MEM_OBJECT;
}
cl_int ValidateGetSupportedImageFormats(cl_context context,
MemFlags flags,
MemObjectType image_type,
cl_uint num_entries,
const cl_image_format *image_formats,
const cl_uint *num_image_formats)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if flags or image_type are not valid,
if (!ValidateMemoryFlags(flags, ctx.getPlatform()) || !Image::IsTypeValid(image_type))
{
return CL_INVALID_VALUE;
}
// or if num_entries is 0 and image_formats is not NULL.
if (num_entries == 0u && image_formats != nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetMemObjectInfo(cl_mem memobj,
MemInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_MEM_OBJECT if memobj is a not a valid memory object.
if (!Memory::IsValid(memobj))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = memobj->cast<Memory>().getContext().getPlatform().getVersion();
switch (param_name)
{
case MemInfo::AssociatedMemObject:
case MemInfo::Offset:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case MemInfo::UsesSVM_Pointer:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case MemInfo::Properties:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case MemInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetImageInfo(cl_mem image,
ImageInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_MEM_OBJECT if image is a not a valid image object.
if (!Image::IsValid(image))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = image->cast<Image>().getContext().getPlatform().getVersion();
switch (param_name)
{
case ImageInfo::ArraySize:
case ImageInfo::Buffer:
case ImageInfo::NumMipLevels:
case ImageInfo::NumSamples:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case ImageInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateRetainSampler(cl_sampler sampler)
{
// CL_INVALID_SAMPLER if sampler is not a valid sampler object.
return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
}
cl_int ValidateReleaseSampler(cl_sampler sampler)
{
// CL_INVALID_SAMPLER if sampler is not a valid sampler object.
return Sampler::IsValid(sampler) ? CL_SUCCESS : CL_INVALID_SAMPLER;
}
cl_int ValidateGetSamplerInfo(cl_sampler sampler,
SamplerInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_SAMPLER if sampler is a not a valid sampler object.
if (!Sampler::IsValid(sampler))
{
return CL_INVALID_SAMPLER;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = sampler->cast<Sampler>().getContext().getPlatform().getVersion();
switch (param_name)
{
case SamplerInfo::Properties:
ANGLE_VALIDATE_VERSION(version, 3, 0);
break;
case SamplerInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithSource(cl_context context,
cl_uint count,
const char **strings,
const size_t *lengths)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if count is zero or if strings or any entry in strings is NULL.
if (count == 0u || strings == nullptr)
{
return CL_INVALID_VALUE;
}
while (count-- != 0u)
{
if (*strings++ == nullptr)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithBinary(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const size_t *lengths,
const unsigned char **binaries,
const cl_int *binary_status)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero.
// CL_INVALID_VALUE if lengths or binaries is NULL.
if (device_list == nullptr || num_devices == 0u || lengths == nullptr || binaries == nullptr)
{
return CL_INVALID_VALUE;
}
while (num_devices-- != 0u)
{
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with context.
if (!ctx.hasDevice(*device_list++))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if any entry in lengths[i] is zero or binaries[i] is NULL.
if (*lengths++ == 0u || *binaries++ == nullptr)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateRetainProgram(cl_program program)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
return Program::IsValid(program) ? CL_SUCCESS : CL_INVALID_PROGRAM;
}
cl_int ValidateReleaseProgram(cl_program program)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
return Program::IsValid(program) ? CL_SUCCESS : CL_INVALID_PROGRAM;
}
cl_int ValidateBuildProgram(cl_program program,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
const Program &prog = program->cast<Program>();
// CL_INVALID_VALUE if device_list is NULL and num_devices is greater than zero,
// or if device_list is not NULL and num_devices is zero.
if ((device_list != nullptr) != (num_devices != 0u))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with program.
while (num_devices-- != 0u)
{
if (!prog.hasDevice(*device_list++))
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if pfn_notify is NULL but user_data is not NULL.
if (pfn_notify == nullptr && user_data != nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if the build of a program executable for any of the devices listed
// in device_list by a previous call to clBuildProgram for program has not completed.
if (prog.isBuilding())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_OPERATION if there are kernel objects attached to program.
if (prog.hasAttachedKernels())
{
return CL_INVALID_OPERATION;
}
// If program was created with clCreateProgramWithBinary and device does not have a valid
// program binary loaded
std::vector<size_t> binSizes{prog.getDevices().size()};
std::vector<std::vector<unsigned char *>> bins{prog.getDevices().size()};
if (IsError(prog.getInfo(ProgramInfo::BinarySizes, binSizes.size() * sizeof(size_t),
binSizes.data(), nullptr)))
{
return CL_INVALID_PROGRAM;
}
for (size_t i = 0; i < prog.getDevices().size(); ++i)
{
cl_program_binary_type binType;
bins.at(i).resize(binSizes[i]);
if (IsError(prog.getInfo(ProgramInfo::Binaries, sizeof(unsigned char *) * bins.size(),
bins.data(), nullptr)))
{
return CL_INVALID_VALUE;
}
if (IsError(prog.getBuildInfo(prog.getDevices()[i]->getNative(),
ProgramBuildInfo::BinaryType, sizeof(cl_program_binary_type),
&binType, nullptr)))
{
return CL_INVALID_VALUE;
}
if ((binType != CL_PROGRAM_BINARY_TYPE_NONE) && bins[i].empty())
{
return CL_INVALID_BINARY;
}
}
return CL_SUCCESS;
}
cl_int ValidateGetProgramInfo(cl_program program,
ProgramInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
const Program &prog = program->cast<Program>();
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = prog.getContext().getPlatform().getVersion();
switch (param_name)
{
case ProgramInfo::NumKernels:
case ProgramInfo::KernelNames:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case ProgramInfo::IL:
ANGLE_VALIDATE_VERSION(version, 2, 1);
break;
case ProgramInfo::ScopeGlobalCtorsPresent:
case ProgramInfo::ScopeGlobalDtorsPresent:
ANGLE_VALIDATE_VERSION(version, 2, 2);
break;
case ProgramInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
// CL_INVALID_VALUE if size in bytes specified by param_value_size is < size of return type
// as described in the Program Object Queries table and param_value is not NULL.
if (param_value != nullptr)
{
size_t valueSizeRet = 0;
if (IsError(prog.getInfo(param_name, 0, nullptr, &valueSizeRet)) ||
param_value_size < valueSizeRet)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateGetProgramBuildInfo(cl_program program,
cl_device_id device,
ProgramBuildInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
const Program &prog = program->cast<Program>();
// CL_INVALID_DEVICE if device is not in the list of devices associated with program.
if (!prog.hasDevice(device))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = prog.getContext().getPlatform().getVersion();
switch (param_name)
{
case ProgramBuildInfo::BinaryType:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case ProgramBuildInfo::GlobalVariableTotalSize:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case ProgramBuildInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
// CL_INVALID_VALUE if size in bytes specified by param_value_size is < size of return type
// as described in the Program Object Queries table and param_value is not NULL.
if (param_value != nullptr)
{
size_t valueSizeRet = 0;
if (IsError(prog.getBuildInfo(device, param_name, 0, nullptr, &valueSizeRet)) ||
param_value_size < valueSizeRet)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreateKernel(cl_program program, const char *kernel_name)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
cl::Program &prog = program->cast<cl::Program>();
// CL_INVALID_VALUE if kernel_name is NULL.
if (kernel_name == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built executable for program.
std::vector<cl_device_id> associatedDevices;
size_t associatedDeviceCount = 0;
bool isAnyDeviceProgramBuilt = false;
if (IsError(prog.getInfo(ProgramInfo::Devices, 0, nullptr, &associatedDeviceCount)))
{
return CL_INVALID_PROGRAM;
}
associatedDevices.resize(associatedDeviceCount / sizeof(cl_device_id));
if (IsError(prog.getInfo(ProgramInfo::Devices, associatedDeviceCount, associatedDevices.data(),
nullptr)))
{
return CL_INVALID_PROGRAM;
}
for (const cl_device_id &device : associatedDevices)
{
cl_build_status status = CL_BUILD_NONE;
if (IsError(prog.getBuildInfo(device, ProgramBuildInfo::Status, sizeof(cl_build_status),
&status, nullptr)))
{
return CL_INVALID_PROGRAM;
}
if (status == CL_BUILD_SUCCESS)
{
isAnyDeviceProgramBuilt = true;
break;
}
}
if (!isAnyDeviceProgramBuilt)
{
return CL_INVALID_PROGRAM_EXECUTABLE;
}
// CL_INVALID_KERNEL_NAME if kernel_name is not found in program.
std::string kernelNames;
size_t kernelNamesSize = 0;
if (IsError(prog.getInfo(ProgramInfo::KernelNames, 0, nullptr, &kernelNamesSize)))
{
return CL_INVALID_PROGRAM;
}
kernelNames.resize(kernelNamesSize);
if (IsError(
prog.getInfo(ProgramInfo::KernelNames, kernelNamesSize, kernelNames.data(), nullptr)))
{
return CL_INVALID_PROGRAM;
}
std::vector<std::string> tokenizedKernelNames =
angle::SplitString(kernelNames.c_str(), ";", angle::WhitespaceHandling::TRIM_WHITESPACE,
angle::SplitResult::SPLIT_WANT_NONEMPTY);
if (std::find(tokenizedKernelNames.begin(), tokenizedKernelNames.end(), kernel_name) ==
tokenizedKernelNames.end())
{
return CL_INVALID_KERNEL_NAME;
}
return CL_SUCCESS;
}
cl_int ValidateCreateKernelsInProgram(cl_program program,
cl_uint num_kernels,
const cl_kernel *kernels,
const cl_uint *num_kernels_ret)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
// CL_INVALID_VALUE if kernels is not NULL and num_kernels is less than the number of kernels in
// program.
size_t kernelCount = 0;
cl::Program &prog = program->cast<cl::Program>();
if (IsError(prog.getInfo(ProgramInfo::NumKernels, sizeof(size_t), &prog, nullptr)))
{
return CL_INVALID_PROGRAM;
}
if (kernels != nullptr && num_kernels < kernelCount)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainKernel(cl_kernel kernel)
{
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
return Kernel::IsValid(kernel) ? CL_SUCCESS : CL_INVALID_KERNEL;
}
cl_int ValidateReleaseKernel(cl_kernel kernel)
{
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
return Kernel::IsValid(kernel) ? CL_SUCCESS : CL_INVALID_KERNEL;
}
cl_int ValidateSetKernelArg(cl_kernel kernel,
cl_uint arg_index,
size_t arg_size,
const void *arg_value)
{
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
// CL_INVALID_ARG_INDEX if arg_index is not a valid argument index.
if (arg_index >= krnl.getInfo().args.size())
{
return CL_INVALID_ARG_INDEX;
}
if (arg_size == sizeof(cl_mem) && arg_value != nullptr)
{
const std::string &typeName = krnl.getInfo().args[arg_index].typeName;
// CL_INVALID_MEM_OBJECT for an argument declared to be a memory object
// when the specified arg_value is not a valid memory object.
if (typeName == "image1d_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) || image->cast<Image>().getType() != MemObjectType::Image1D)
{
return CL_INVALID_MEM_OBJECT;
}
}
else if (typeName == "image2d_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) || image->cast<Image>().getType() != MemObjectType::Image2D)
{
return CL_INVALID_MEM_OBJECT;
}
}
else if (typeName == "image3d_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) || image->cast<Image>().getType() != MemObjectType::Image3D)
{
return CL_INVALID_MEM_OBJECT;
}
}
else if (typeName == "image1d_array_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) ||
image->cast<Image>().getType() != MemObjectType::Image1D_Array)
{
return CL_INVALID_MEM_OBJECT;
}
}
else if (typeName == "image2d_array_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) ||
image->cast<Image>().getType() != MemObjectType::Image2D_Array)
{
return CL_INVALID_MEM_OBJECT;
}
}
else if (typeName == "image1d_buffer_t")
{
const cl_mem image = *static_cast<const cl_mem *>(arg_value);
if (!Image::IsValid(image) ||
image->cast<Image>().getType() != MemObjectType::Image1D_Buffer)
{
return CL_INVALID_MEM_OBJECT;
}
}
// CL_INVALID_SAMPLER for an argument declared to be of type sampler_t
// when the specified arg_value is not a valid sampler object.
else if (typeName == "sampler_t")
{
static_assert(sizeof(cl_mem) == sizeof(cl_sampler), "api object size check failed");
if (!Sampler::IsValid(*static_cast<const cl_sampler *>(arg_value)))
{
return CL_INVALID_SAMPLER;
}
}
// CL_INVALID_DEVICE_QUEUE for an argument declared to be of type queue_t
// when the specified arg_value is not a valid device queue object.
else if (typeName == "queue_t")
{
static_assert(sizeof(cl_mem) == sizeof(cl_command_queue),
"api object size check failed");
const cl_command_queue queue = *static_cast<const cl_command_queue *>(arg_value);
if (!CommandQueue::IsValid(queue) || !queue->cast<CommandQueue>().isOnDevice())
{
return CL_INVALID_DEVICE_QUEUE;
}
}
}
return CL_SUCCESS;
}
cl_int ValidateGetKernelInfo(cl_kernel kernel,
KernelInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version =
kernel->cast<Kernel>().getProgram().getContext().getPlatform().getVersion();
switch (param_name)
{
case KernelInfo::Attributes:
ANGLE_VALIDATE_VERSION(version, 1, 2);
break;
case KernelInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateGetKernelWorkGroupInfo(cl_kernel kernel,
cl_device_id device,
KernelWorkGroupInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
const Device *dev = nullptr;
if (device != nullptr)
{
// CL_INVALID_DEVICE if device is not in the list of devices associated with kernel ...
if (krnl.getProgram().getContext().hasDevice(device))
{
dev = &device->cast<Device>();
}
else
{
return CL_INVALID_DEVICE;
}
}
else
{
// or if device is NULL but there is more than one device associated with kernel.
if (krnl.getProgram().getContext().getDevices().size() == 1u)
{
dev = krnl.getProgram().getContext().getDevices().front().get();
}
else
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = krnl.getProgram().getContext().getPlatform().getInfo().version;
switch (param_name)
{
case KernelWorkGroupInfo::GlobalWorkSize:
ANGLE_VALIDATE_VERSION(version, 1, 2);
// CL_INVALID_VALUE if param_name is CL_KERNEL_GLOBAL_WORK_SIZE and
// device is not a custom device and kernel is not a built-in kernel.
if (!dev->supportsBuiltInKernel(krnl.getInfo().functionName))
{
return CL_INVALID_VALUE;
}
break;
case KernelWorkGroupInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateWaitForEvents(cl_uint num_events, const cl_event *event_list)
{
// CL_INVALID_VALUE if num_events is zero or event_list is NULL.
if (num_events == 0u || event_list == nullptr)
{
return CL_INVALID_VALUE;
}
const Context *context = nullptr;
while (num_events-- != 0u)
{
// CL_INVALID_EVENT if event objects specified in event_list are not valid event objects.
if (!Event::IsValid(*event_list))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_CONTEXT if events specified in event_list do not belong to the same context.
const Context *eventContext = &(*event_list++)->cast<Event>().getContext();
if (context == nullptr)
{
context = eventContext;
}
else if (context != eventContext)
{
return CL_INVALID_CONTEXT;
}
}
return CL_SUCCESS;
}
cl_int ValidateGetEventInfo(cl_event event,
EventInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_EVENT if event is a not a valid event object.
if (!Event::IsValid(event))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = event->cast<Event>().getContext().getPlatform().getVersion();
switch (param_name)
{
case EventInfo::Context:
ANGLE_VALIDATE_VERSION(version, 1, 1);
break;
case EventInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateRetainEvent(cl_event event)
{
// CL_INVALID_EVENT if event is not a valid event object.
return Event::IsValid(event) ? CL_SUCCESS : CL_INVALID_EVENT;
}
cl_int ValidateReleaseEvent(cl_event event)
{
// CL_INVALID_EVENT if event is not a valid event object.
return Event::IsValid(event) ? CL_SUCCESS : CL_INVALID_EVENT;
}
cl_int ValidateGetEventProfilingInfo(cl_event event,
ProfilingInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_EVENT if event is a not a valid event object.
if (!Event::IsValid(event))
{
return CL_INVALID_EVENT;
}
const Event &evt = event->cast<Event>();
// CL_PROFILING_INFO_NOT_AVAILABLE if event is a user event object,
if (evt.getCommandType() == CL_COMMAND_USER)
{
return CL_PROFILING_INFO_NOT_AVAILABLE;
}
// or if the CL_QUEUE_PROFILING_ENABLE flag is not set for the command-queue.
if (evt.getCommandQueue()->getProperties().excludes(CL_QUEUE_PROFILING_ENABLE))
{
return CL_PROFILING_INFO_NOT_AVAILABLE;
}
// CL_INVALID_VALUE if param_name is not valid.
const cl_version version = evt.getContext().getPlatform().getVersion();
switch (param_name)
{
case ProfilingInfo::CommandComplete:
ANGLE_VALIDATE_VERSION(version, 2, 0);
break;
case ProfilingInfo::InvalidEnum:
return CL_INVALID_VALUE;
default:
// All remaining possible values for param_name are valid for all versions.
break;
}
return CL_SUCCESS;
}
cl_int ValidateFlush(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(command_queue) || !command_queue->cast<CommandQueue>().isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
return CL_SUCCESS;
}
cl_int ValidateFinish(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(command_queue) || !command_queue->cast<CommandQueue>().isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_read,
size_t offset,
size_t size,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
ANGLE_VALIDATE(ValidateEnqueueBuffer(command_queue->cast<CommandQueue>(), buffer, true, false));
// CL_INVALID_VALUE if the region being read or written specified
// by (offset, size) is out of bounds or if ptr is a NULL value.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
size_t offset,
size_t size,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
ANGLE_VALIDATE(ValidateEnqueueBuffer(command_queue->cast<CommandQueue>(), buffer, false, true));
// CL_INVALID_VALUE if the region being read or written specified
// by (offset, size) is out of bounds or if ptr is a NULL value.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || ptr == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBuffer(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_buffer,
size_t src_offset,
size_t dst_offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, src_buffer, false, false));
const Buffer &src = src_buffer->cast<Buffer>();
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, dst_buffer, false, false));
const Buffer &dst = dst_buffer->cast<Buffer>();
// CL_INVALID_VALUE if src_offset, dst_offset, size, src_offset + size or dst_offset + size
// require accessing elements outside the src_buffer and dst_buffer buffer objects respectively.
if (!src.isRegionValid(src_offset, size) || !dst.isRegionValid(dst_offset, size))
{
return CL_INVALID_VALUE;
}
// CL_MEM_COPY_OVERLAP if src_buffer and dst_buffer are the same buffer or sub-buffer object
// and the source and destination regions overlap or if src_buffer and dst_buffer are
// different sub-buffers of the same associated buffer object and they overlap.
if ((src.isSubBuffer() ? src.getParent().get() : &src) ==
(dst.isSubBuffer() ? dst.getParent().get() : &dst))
{
// Only sub-buffers have offsets larger than zero
src_offset += src.getOffset();
dst_offset += dst.getOffset();
if (OverlapRegions(src_offset, dst_offset, size))
{
return CL_MEM_COPY_OVERLAP;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_read,
const size_t *origin,
const size_t *region,
size_t row_pitch,
size_t slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, image, true, false));
const Image &img = image->cast<Image>();
ANGLE_VALIDATE(ValidateImageForDevice(img, queue.getDevice(), origin, region));
ANGLE_VALIDATE(ValidateHostRegionForImage(img, region, row_pitch, slice_pitch, ptr));
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_write,
const size_t *origin,
const size_t *region,
size_t input_row_pitch,
size_t input_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, image, false, true));
const Image &img = image->cast<Image>();
ANGLE_VALIDATE(ValidateImageForDevice(img, queue.getDevice(), origin, region));
ANGLE_VALIDATE(
ValidateHostRegionForImage(img, region, input_row_pitch, input_slice_pitch, ptr));
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyImage(cl_command_queue command_queue,
cl_mem src_image,
cl_mem dst_image,
const size_t *src_origin,
const size_t *dst_origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, src_image, false, false));
const Image &src = src_image->cast<Image>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, dst_image, false, false));
const Image &dst = dst_image->cast<Image>();
// CL_IMAGE_FORMAT_MISMATCH if src_image and dst_image do not use the same image format.
if (src.getFormat().image_channel_order != dst.getFormat().image_channel_order ||
src.getFormat().image_channel_data_type != dst.getFormat().image_channel_data_type)
{
return CL_IMAGE_FORMAT_MISMATCH;
}
ANGLE_VALIDATE(ValidateImageForDevice(src, queue.getDevice(), src_origin, region));
ANGLE_VALIDATE(ValidateImageForDevice(dst, queue.getDevice(), dst_origin, region));
// CL_MEM_COPY_OVERLAP if src_image and dst_image are the same image object
// and the source and destination regions overlap.
if (&src == &dst)
{
const MemObjectType type = src.getType();
// Check overlap in first dimension
if (OverlapRegions(src_origin[0], dst_origin[0], region[0]))
{
if (type == MemObjectType::Image1D || type == MemObjectType::Image1D_Buffer)
{
return CL_MEM_COPY_OVERLAP;
}
// Check overlap in second dimension
if (OverlapRegions(src_origin[1], dst_origin[1], region[1]))
{
if (type == MemObjectType::Image2D || type == MemObjectType::Image1D_Array)
{
return CL_MEM_COPY_OVERLAP;
}
// Check overlap in third dimension
if (OverlapRegions(src_origin[2], dst_origin[2], region[2]))
{
return CL_MEM_COPY_OVERLAP;
}
}
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyImageToBuffer(cl_command_queue command_queue,
cl_mem src_image,
cl_mem dst_buffer,
const size_t *src_origin,
const size_t *region,
size_t dst_offset,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, src_image, false, false));
const Image &src = src_image->cast<Image>();
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, dst_buffer, false, false));
const Buffer &dst = dst_buffer->cast<Buffer>();
// CL_INVALID_MEM_OBJECT if src_image is a 1D image buffer object created from dst_buffer.
if (src.getType() == MemObjectType::Image1D_Buffer && src.getParent() == &dst)
{
return CL_INVALID_MEM_OBJECT;
}
ANGLE_VALIDATE(ValidateImageForDevice(src, queue.getDevice(), src_origin, region));
// CL_INVALID_VALUE if the region specified by dst_offset and dst_offset + dst_cb
// refer to a region outside dst_buffer.
const MemObjectType type = src.getType();
size_t dst_cb = src.getElementSize() * region[0];
if (type != MemObjectType::Image1D && type != MemObjectType::Image1D_Buffer)
{
dst_cb *= region[1];
if (type != MemObjectType::Image2D && type != MemObjectType::Image1D_Array)
{
dst_cb *= region[2];
}
}
if (!dst.isRegionValid(dst_offset, dst_cb))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBufferToImage(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_image,
size_t src_offset,
const size_t *dst_origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, src_buffer, false, false));
const Buffer &src = src_buffer->cast<Buffer>();
ANGLE_VALIDATE(ValidateEnqueueImage(queue, dst_image, false, false));
const Image &dst = dst_image->cast<Image>();
// CL_INVALID_MEM_OBJECT if dst_image is a 1D image buffer object created from src_buffer.
if (dst.getType() == MemObjectType::Image1D_Buffer && dst.getParent() == &src)
{
return CL_INVALID_MEM_OBJECT;
}
ANGLE_VALIDATE(ValidateImageForDevice(dst, queue.getDevice(), dst_origin, region));
// CL_INVALID_VALUE if the region specified by src_offset and src_offset + src_cb
// refer to a region outside src_buffer.
const MemObjectType type = dst.getType();
size_t src_cb = dst.getElementSize() * region[0];
if (type != MemObjectType::Image1D && type != MemObjectType::Image1D_Buffer)
{
src_cb *= region[1];
if (type != MemObjectType::Image2D && type != MemObjectType::Image1D_Array)
{
src_cb *= region[2];
}
}
if (!src.isRegionValid(src_offset, src_cb))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueMapBuffer(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_map,
MapFlags map_flags,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_OPERATION if buffer has been created with CL_MEM_HOST_WRITE_ONLY or
// CL_MEM_HOST_NO_ACCESS and CL_MAP_READ is set in map_flags
// or if buffer has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS
// and CL_MAP_WRITE or CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags.
ANGLE_VALIDATE(
ValidateEnqueueBuffer(queue, buffer, map_flags.intersects(CL_MAP_READ),
map_flags.intersects(CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)));
// CL_INVALID_VALUE if region being mapped given by (offset, size) is out of bounds
// or if size is 0 or if values specified in map_flags are not valid.
if (!buffer->cast<Buffer>().isRegionValid(offset, size) || size == 0u ||
!ValidateMapFlags(map_flags, queue.getContext().getPlatform()))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueMapImage(cl_command_queue command_queue,
cl_mem image,
cl_bool blocking_map,
MapFlags map_flags,
const size_t *origin,
const size_t *region,
const size_t *image_row_pitch,
const size_t *image_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_OPERATION if image has been created with CL_MEM_HOST_WRITE_ONLY or
// CL_MEM_HOST_NO_ACCESS and CL_MAP_READ is set in map_flags
// or if image has been created with CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_NO_ACCESS
// and CL_MAP_WRITE or CL_MAP_WRITE_INVALIDATE_REGION is set in map_flags.
ANGLE_VALIDATE(
ValidateEnqueueImage(queue, image, map_flags.intersects(CL_MAP_READ),
map_flags.intersects(CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)));
const Image &img = image->cast<Image>();
ANGLE_VALIDATE(ValidateImageForDevice(img, queue.getDevice(), origin, region));
// CL_INVALID_VALUE if values specified in map_flags are not valid.
if (!ValidateMapFlags(map_flags, queue.getContext().getPlatform()))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if image_row_pitch is NULL.
if (image_row_pitch == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if image is a 3D image, 1D or 2D image array object
// and image_slice_pitch is NULL.
if ((img.getType() == MemObjectType::Image3D || img.getType() == MemObjectType::Image1D_Array ||
img.getType() == MemObjectType::Image2D_Array) &&
image_slice_pitch == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueUnmapMemObject(cl_command_queue command_queue,
cl_mem memobj,
const void *mapped_ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object or is a pipe object.
if (!Memory::IsValid(memobj))
{
return CL_INVALID_MEM_OBJECT;
}
const Memory &memory = memobj->cast<Memory>();
if (memory.getType() == MemObjectType::Pipe)
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_CONTEXT if context associated with command_queue and memobj are not the same.
if (&queue.getContext() != &memory.getContext())
{
return CL_INVALID_CONTEXT;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueNDRangeKernel(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint work_dim,
const size_t *global_work_offset,
const size_t *global_work_size,
const size_t *local_work_size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
const Device &device = queue.getDevice();
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
// CL_INVALID_CONTEXT if context associated with command_queue and kernel are not the same.
if (&queue.getContext() != &krnl.getProgram().getContext())
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_WORK_DIMENSION if work_dim is not a valid value.
if (work_dim == 0u || work_dim > device.getInfo().maxWorkItemSizes.size())
{
return CL_INVALID_WORK_DIMENSION;
}
// CL_INVALID_GLOBAL_OFFSET if global_work_offset is non-NULL before version 1.1.
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u) && global_work_offset != nullptr)
{
return CL_INVALID_GLOBAL_OFFSET;
}
// CL_INVALID_KERNEL_ARGS if all the kernel arguments have not been set for the kernel
if (!krnl.areAllArgsSet())
{
return CL_INVALID_KERNEL_ARGS;
}
size_t compileWorkGroupSize[3] = {0, 0, 0};
if (IsError(krnl.getWorkGroupInfo(const_cast<cl_device_id>(device.getNative()),
KernelWorkGroupInfo::CompileWorkGroupSize,
sizeof(compileWorkGroupSize), compileWorkGroupSize, nullptr)))
{
return CL_INVALID_VALUE;
}
if (local_work_size != nullptr)
{
// CL_INVALID_WORK_GROUP_SIZE when non-uniform work-groups are not supported, the size of
// each work-group must be uniform. If local_work_size is specified, the values specified in
// global_work_size[0],...,global_work_size[work_dim - 1] must be evenly divisible by
// the corresponding values specified in local_work_size[0],...,
// local_work_size[work_dim-1].
if (!device.supportsNonUniformWorkGroups())
{
for (cl_uint i = 0; i < work_dim; ++i)
{
if (global_work_size[i] % local_work_size[i] != 0)
{
return CL_INVALID_WORK_GROUP_SIZE;
}
}
}
for (cl_uint i = 0; i < work_dim; ++i)
{
// CL_INVALID_WORK_GROUP_SIZE when non-uniform work-groups are not supported, the size
// of each work-group must be uniform. If local_work_size is specified, the values
// specified in global_work_size[0],..., global_work_size[work_dim - 1] must be
// evenly divisible by the corresponding values specified in local_work_size[0],...,
// local_work_size[work_dim-1].
if (local_work_size[i] == 0)
{
return CL_INVALID_WORK_GROUP_SIZE;
}
// CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified and does not match the
// required work-group size for kernel in the program source.
if (compileWorkGroupSize[i] != 0 && local_work_size[i] != compileWorkGroupSize[i])
{
return CL_INVALID_WORK_GROUP_SIZE;
}
}
}
// CL_INVALID_GLOBAL_WORK_SIZE if global_work_size is NULL or if any of the values
// specified in global_work_size[0] ... global_work_size[work_dim - 1] are 0.
// Returning this error code under these circumstances is deprecated by version 2.1.
if (!queue.getContext().getPlatform().isVersionOrNewer(2u, 1u))
{
if (global_work_size == nullptr)
{
return CL_INVALID_GLOBAL_WORK_SIZE;
}
for (cl_uint dim = 0u; dim < work_dim; ++dim)
{
if (global_work_size[dim] == 0u)
{
return CL_INVALID_GLOBAL_WORK_SIZE;
}
}
}
// CL_INVALID_GLOBAL_WORK_SIZE if any of the values specified in global_work_size[0], ...
// global_work_size[work_dim - 1] exceed the maximum value representable by size_t on the device
// on which the kernel-instance will be enqueued.
if (global_work_size != nullptr)
{
for (cl_uint dim = 0u; dim < work_dim; ++dim)
{
if (global_work_size[dim] > UINT32_MAX)
{
// Set hard limit in ANGLE to 2^32 for all backends (regardless of device support).
return CL_INVALID_GLOBAL_WORK_SIZE;
}
}
}
// CL_INVALID_GLOBAL_OFFSET if the value specified in global_work_size + the corresponding
// values in global_work_offset for any dimensions is greater than the maximum value
// representable by size t on the device on which the kernel-instance will be enqueued
if (global_work_offset != nullptr)
{
for (cl_uint dim = 0u; dim < work_dim; ++dim)
{
if (static_cast<uint32_t>((global_work_offset[dim] + global_work_size[dim])) <
global_work_offset[dim])
{
// Set hard limit in ANGLE to 2^32 for all backends (regardless of device support).
return CL_INVALID_GLOBAL_OFFSET;
}
}
}
if (local_work_size != nullptr)
{
size_t numWorkItems = 1u; // Initialize with neutral element for multiplication
// CL_INVALID_WORK_ITEM_SIZE if the number of work-items specified
// in any of local_work_size[0] ... local_work_size[work_dim - 1]
// is greater than the corresponding values specified by
// CL_DEVICE_MAX_WORK_ITEM_SIZES[0] ... CL_DEVICE_MAX_WORK_ITEM_SIZES[work_dim - 1].
for (cl_uint dim = 0u; dim < work_dim; ++dim)
{
if (local_work_size[dim] > device.getInfo().maxWorkItemSizes[dim])
{
return CL_INVALID_WORK_ITEM_SIZE;
}
numWorkItems *= local_work_size[dim];
}
// CL_INVALID_WORK_GROUP_SIZE if local_work_size is specified
// and the total number of work-items in the work-group computed as
// local_work_size[0] x ... local_work_size[work_dim - 1] is greater than the value
// specified by CL_KERNEL_WORK_GROUP_SIZE in the Kernel Object Device Queries table.
if (numWorkItems > krnl.getInfo().workGroups[queue.getDeviceIndex()].workGroupSize)
{
return CL_INVALID_WORK_GROUP_SIZE;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueNativeKernel(cl_command_queue command_queue,
void(CL_CALLBACK *user_func)(void *),
const void *args,
size_t cb_args,
cl_uint num_mem_objects,
const cl_mem *mem_list,
const void **args_mem_loc,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
// CL_INVALID_OPERATION if the device associated with command_queue
// cannot execute the native kernel.
if (queue.getDevice().getInfo().execCapabilities.excludes(CL_EXEC_NATIVE_KERNEL))
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_VALUE if user_func is NULL.
if (user_func == nullptr)
{
return CL_INVALID_VALUE;
}
if (args == nullptr)
{
// CL_INVALID_VALUE if args is a NULL value and cb_args > 0 or num_mem_objects > 0.
if (cb_args > 0u || num_mem_objects > 0u)
{
return CL_INVALID_VALUE;
}
}
else
{
// CL_INVALID_VALUE if args is not NULL and cb_args is 0.
if (cb_args == 0u)
{
return CL_INVALID_VALUE;
}
}
if (num_mem_objects == 0u)
{
// CL_INVALID_VALUE if num_mem_objects = 0 and mem_list or args_mem_loc are not NULL.
if (mem_list != nullptr || args_mem_loc != nullptr)
{
return CL_INVALID_VALUE;
}
}
else
{
// CL_INVALID_VALUE if num_mem_objects > 0 and mem_list or args_mem_loc are NULL.
if (mem_list == nullptr || args_mem_loc == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_MEM_OBJECT if one or more memory objects
// specified in mem_list are not valid or are not buffer objects.
while (num_mem_objects-- != 0u)
{
if (!Buffer::IsValid(*mem_list++))
{
return CL_INVALID_MEM_OBJECT;
}
}
}
return CL_SUCCESS;
}
cl_int ValidateSetCommandQueueProperty(cl_command_queue command_queue,
CommandQueueProperties properties,
cl_bool enable,
const cl_command_queue_properties *old_properties)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command-queue.
if (!CommandQueue::IsValid(command_queue))
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties.hasOtherBitsThan(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
CL_QUEUE_PROFILING_ENABLE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImage2D(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
size_t image_width,
size_t image_height,
size_t image_row_pitch,
const void *host_ptr)
{
const cl_image_desc desc = {CL_MEM_OBJECT_IMAGE2D, image_width, image_height, 0u, 0u,
image_row_pitch, 0u, 0u, 0u, {nullptr}};
return ValidateCreateImage(context, flags, image_format, &desc, host_ptr);
}
cl_int ValidateCreateImage3D(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
size_t image_width,
size_t image_height,
size_t image_depth,
size_t image_row_pitch,
size_t image_slice_pitch,
const void *host_ptr)
{
const cl_image_desc desc = {
CL_MEM_OBJECT_IMAGE3D, image_width, image_height, image_depth, 0u,
image_row_pitch, image_slice_pitch, 0u, 0u, {nullptr}};
return ValidateCreateImage(context, flags, image_format, &desc, host_ptr);
}
cl_int ValidateEnqueueMarker(cl_command_queue command_queue, const cl_event *event)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(command_queue) || !command_queue->cast<CommandQueue>().isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if event is NULL.
if (event == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueWaitForEvents(cl_command_queue command_queue,
cl_uint num_events,
const cl_event *event_list)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(command_queue))
{
return CL_INVALID_COMMAND_QUEUE;
}
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if num_events is 0 or event_list is NULL.
if (num_events == 0u || event_list == nullptr)
{
return CL_INVALID_VALUE;
}
while (num_events-- != 0u)
{
// The documentation for invalid events is missing.
if (!Event::IsValid(*event_list))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_CONTEXT if context associated with command_queue
// and events in event_list are not the same.
if (&queue.getContext() != &(*event_list++)->cast<Event>().getContext())
{
return CL_INVALID_CONTEXT;
}
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueBarrier(cl_command_queue command_queue)
{
// CL_INVALID_COMMAND_QUEUE if command_queue is not a valid host command-queue.
if (!CommandQueue::IsValid(command_queue) || !command_queue->cast<CommandQueue>().isOnHost())
{
return CL_INVALID_COMMAND_QUEUE;
}
return CL_SUCCESS;
}
cl_int ValidateUnloadCompiler()
{
return CL_SUCCESS;
}
cl_int ValidateGetExtensionFunctionAddress(const char *func_name)
{
return func_name != nullptr && *func_name != '\0' ? CL_SUCCESS : CL_INVALID_VALUE;
}
cl_int ValidateCreateCommandQueue(cl_context context,
cl_device_id device,
CommandQueueProperties properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_DEVICE if device is not a valid device or is not associated with context.
if (!context->cast<Context>().hasDevice(device))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties.hasOtherBitsThan(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
CL_QUEUE_PROFILING_ENABLE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateSampler(cl_context context,
cl_bool normalized_coords,
AddressingMode addressing_mode,
FilterMode filter_mode)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValid(context))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if addressing_mode, filter_mode, normalized_coords
// or a combination of these arguements are not valid.
if ((normalized_coords != CL_FALSE && normalized_coords != CL_TRUE) ||
addressing_mode == AddressingMode::InvalidEnum || filter_mode == FilterMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if images are not supported by any device associated with context.
if (!context->cast<Context>().supportsImages())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueTask(cl_command_queue command_queue,
cl_kernel kernel,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
// CL_INVALID_KERNEL if kernel is not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
// CL_INVALID_CONTEXT if context associated with command_queue and kernel are not the same.
if (&command_queue->cast<CommandQueue>().getContext() !=
&kernel->cast<Kernel>().getProgram().getContext())
{
return CL_INVALID_CONTEXT;
}
return CL_SUCCESS;
}
// CL 1.1
cl_int ValidateCreateSubBuffer(cl_mem buffer,
MemFlags flags,
cl_buffer_create_type buffer_create_type,
const void *buffer_create_info)
{
// CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object or is a sub-buffer object.
if (!Buffer::IsValid(buffer))
{
return CL_INVALID_MEM_OBJECT;
}
const Buffer &buf = buffer->cast<Buffer>();
if (buf.isSubBuffer() || !buf.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_MEM_OBJECT;
}
if (!ValidateMemoryFlags(flags, buf.getContext().getPlatform()))
{
return CL_INVALID_VALUE;
}
const MemFlags bufFlags = buf.getFlags();
// CL_INVALID_VALUE if buffer was created with CL_MEM_WRITE_ONLY
// and flags specifies CL_MEM_READ_WRITE or CL_MEM_READ_ONLY,
if ((bufFlags.intersects(CL_MEM_WRITE_ONLY) &&
flags.intersects(CL_MEM_READ_WRITE | CL_MEM_READ_ONLY)) ||
// or if buffer was created with CL_MEM_READ_ONLY
// and flags specifies CL_MEM_READ_WRITE or CL_MEM_WRITE_ONLY,
(bufFlags.intersects(CL_MEM_READ_ONLY) &&
flags.intersects(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) ||
// or if flags specifies CL_MEM_USE_HOST_PTR, CL_MEM_ALLOC_HOST_PTR or CL_MEM_COPY_HOST_PTR.
flags.intersects(CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if buffer was created with CL_MEM_HOST_WRITE_ONLY
// and flags specify CL_MEM_HOST_READ_ONLY,
if ((bufFlags.intersects(CL_MEM_HOST_WRITE_ONLY) && flags.intersects(CL_MEM_HOST_READ_ONLY)) ||
// or if buffer was created with CL_MEM_HOST_READ_ONLY
// and flags specify CL_MEM_HOST_WRITE_ONLY,
(bufFlags.intersects(CL_MEM_HOST_READ_ONLY) && flags.intersects(CL_MEM_HOST_WRITE_ONLY)) ||
// or if buffer was created with CL_MEM_HOST_NO_ACCESS
// and flags specify CL_MEM_HOST_READ_ONLY or CL_MEM_HOST_WRITE_ONLY.
(bufFlags.intersects(CL_MEM_HOST_NO_ACCESS) &&
flags.intersects(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY)))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if the value specified in buffer_create_type is not valid.
if (buffer_create_type != CL_BUFFER_CREATE_TYPE_REGION)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if value(s) specified in buffer_create_info
// (for a given buffer_create_type) is not valid or if buffer_create_info is NULL.
// CL_INVALID_VALUE if the region specified by the cl_buffer_region structure
// passed in buffer_create_info is out of bounds in buffer.
const cl_buffer_region *region = static_cast<const cl_buffer_region *>(buffer_create_info);
if (region == nullptr || !buf.isRegionValid(*region))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_BUFFER_SIZE if the size field of the cl_buffer_region structure
// passed in buffer_create_info is 0.
if (region->size == 0u)
{
return CL_INVALID_BUFFER_SIZE;
}
// CL_MISALIGNED_SUB_BUFFER_OFFSET when the sub-buffer object is created with an offset that is
// not aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value (which is in bits!) for devices associated
// with the context.
const Memory &memory = buffer->cast<Memory>();
for (const DevicePtr &device : memory.getContext().getDevices())
{
if (region->origin % (device->getInfo().memBaseAddrAlign / CHAR_BIT) != 0)
{
return CL_MISALIGNED_SUB_BUFFER_OFFSET;
}
}
return CL_SUCCESS;
}
cl_int ValidateSetMemObjectDestructorCallback(cl_mem memobj,
void(CL_CALLBACK *pfn_notify)(cl_mem memobj,
void *user_data),
const void *user_data)
{
// CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
if (!Memory::IsValid(memobj))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_VALUE if pfn_notify is NULL.
if (pfn_notify == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateUserEvent(cl_context context)
{
// CL_INVALID_CONTEXT if context is not a valid context.
return Context::IsValidAndVersionOrNewer(context, 1u, 1u) ? CL_SUCCESS : CL_INVALID_CONTEXT;
}
cl_int ValidateSetUserEventStatus(cl_event event, cl_int execution_status)
{
// CL_INVALID_EVENT if event is not a valid user event object.
if (!Event::IsValid(event))
{
return CL_INVALID_EVENT;
}
const Event &evt = event->cast<Event>();
if (!evt.getContext().getPlatform().isVersionOrNewer(1u, 1u) ||
evt.getCommandType() != CL_COMMAND_USER)
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if the execution_status is not CL_COMPLETE or a negative integer value.
if (execution_status != CL_COMPLETE && execution_status >= 0)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if the execution_status for event has already been changed
// by a previous call to clSetUserEventStatus.
if (evt.wasStatusChanged())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateSetEventCallback(cl_event event,
cl_int command_exec_callback_type,
void(CL_CALLBACK *pfn_notify)(cl_event event,
cl_int event_command_status,
void *user_data),
const void *user_data)
{
// CL_INVALID_EVENT if event is not a valid event object.
if (!Event::IsValid(event) ||
!event->cast<Event>().getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_EVENT;
}
// CL_INVALID_VALUE if pfn_event_notify is NULL
// or if command_exec_callback_type is not CL_SUBMITTED, CL_RUNNING, or CL_COMPLETE.
if (pfn_notify == nullptr ||
(command_exec_callback_type != CL_SUBMITTED && command_exec_callback_type != CL_RUNNING &&
command_exec_callback_type != CL_COMPLETE))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueReadBufferRect(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_read,
const size_t *buffer_origin,
const size_t *host_origin,
const size_t *region,
size_t buffer_row_pitch,
size_t buffer_slice_pitch,
size_t host_row_pitch,
size_t host_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, buffer, true, false));
ANGLE_VALIDATE(ValidateBufferRect(buffer->cast<Buffer>(), buffer_origin, region,
buffer_row_pitch, buffer_slice_pitch));
ANGLE_VALIDATE(ValidateHostRect(host_origin, region, host_row_pitch, host_slice_pitch, ptr));
return CL_SUCCESS;
}
cl_int ValidateEnqueueWriteBufferRect(cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
const size_t *buffer_origin,
const size_t *host_origin,
const size_t *region,
size_t buffer_row_pitch,
size_t buffer_slice_pitch,
size_t host_row_pitch,
size_t host_slice_pitch,
const void *ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, buffer, false, true));
ANGLE_VALIDATE(ValidateBufferRect(buffer->cast<Buffer>(), buffer_origin, region,
buffer_row_pitch, buffer_slice_pitch));
ANGLE_VALIDATE(ValidateHostRect(host_origin, region, host_row_pitch, host_slice_pitch, ptr));
return CL_SUCCESS;
}
cl_int ValidateEnqueueCopyBufferRect(cl_command_queue command_queue,
cl_mem src_buffer,
cl_mem dst_buffer,
const size_t *src_origin,
const size_t *dst_origin,
const size_t *region,
size_t src_row_pitch,
size_t src_slice_pitch,
size_t dst_row_pitch,
size_t dst_slice_pitch,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 1u))
{
return CL_INVALID_COMMAND_QUEUE;
}
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, src_buffer, false, false));
const Buffer &src = src_buffer->cast<Buffer>();
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, dst_buffer, false, false));
const Buffer &dst = dst_buffer->cast<Buffer>();
ANGLE_VALIDATE(ValidateBufferRect(src, src_origin, region, src_row_pitch, src_slice_pitch));
ANGLE_VALIDATE(ValidateBufferRect(dst, dst_origin, region, dst_row_pitch, dst_slice_pitch));
// CL_INVALID_VALUE if src_buffer and dst_buffer are the same buffer object and src_slice_pitch
// is not equal to dst_slice_pitch or src_row_pitch is not equal to dst_row_pitch.
if (&src == &dst && (src_slice_pitch != dst_slice_pitch || src_row_pitch != dst_row_pitch))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
// CL 1.2
cl_int ValidateCreateSubDevices(cl_device_id in_device,
const cl_device_partition_property *properties,
cl_uint num_devices,
const cl_device_id *out_devices,
const cl_uint *num_devices_ret)
{
// CL_INVALID_DEVICE if in_device is not a valid device.
if (!Device::IsValid(in_device))
{
return CL_INVALID_DEVICE;
}
const Device &device = in_device->cast<Device>();
if (!device.isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid
// or if values specified in properties are valid but not supported by the device
const std::vector<cl_device_partition_property> &devProps =
device.getInfo().partitionProperties;
if (properties == nullptr ||
std::find(devProps.cbegin(), devProps.cend(), *properties) == devProps.cend())
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateRetainDevice(cl_device_id device)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device) || !device->cast<Device>().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
return CL_SUCCESS;
}
cl_int ValidateReleaseDevice(cl_device_id device)
{
// CL_INVALID_DEVICE if device is not a valid device.
if (!Device::IsValid(device) || !device->cast<Device>().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_DEVICE;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImage(cl_context context,
MemFlags flags,
const cl_image_format *image_format,
const cl_image_desc *image_desc,
const void *host_ptr)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 1u, 2u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if values specified in flags are not valid.
if (!ValidateMemoryFlags(flags, ctx.getPlatform()))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in image_format are not valid
// or if image_format is NULL.
if (!IsValidImageFormat(image_format, ctx.getPlatform().getInfo()))
{
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
// CL_INVALID_IMAGE_DESCRIPTOR if image_desc is NULL.
if (image_desc == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
const size_t elemSize = GetElementSize(*image_format);
if (elemSize == 0u)
{
ASSERT(false);
ERR() << "Failed to calculate image element size";
return CL_INVALID_IMAGE_FORMAT_DESCRIPTOR;
}
const size_t rowPitch = image_desc->image_row_pitch != 0u ? image_desc->image_row_pitch
: image_desc->image_width * elemSize;
const size_t imageHeight =
image_desc->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY ? 1u : image_desc->image_height;
const size_t sliceSize = imageHeight * rowPitch;
// CL_INVALID_IMAGE_DESCRIPTOR if values specified in image_desc are not valid.
switch (FromCLenum<MemObjectType>(image_desc->image_type))
{
case MemObjectType::Image1D:
if (image_desc->image_width == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case MemObjectType::Image2D:
if (image_desc->image_width == 0u || image_desc->image_height == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case MemObjectType::Image3D:
if (image_desc->image_width == 0u || image_desc->image_height == 0u ||
image_desc->image_depth == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case MemObjectType::Image1D_Array:
if (image_desc->image_width == 0u || image_desc->image_array_size == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case MemObjectType::Image2D_Array:
if (image_desc->image_width == 0u || image_desc->image_height == 0u ||
image_desc->image_array_size == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
case MemObjectType::Image1D_Buffer:
if (image_desc->image_width == 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
break;
default:
return CL_INVALID_IMAGE_DESCRIPTOR;
}
if (image_desc->image_row_pitch != 0u)
{
// image_row_pitch must be 0 if host_ptr is NULL.
if (host_ptr == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// image_row_pitch can be either 0
// or >= image_width * size of element in bytes if host_ptr is not NULL.
if (image_desc->image_row_pitch < image_desc->image_width * elemSize)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If image_row_pitch is not 0, it must be a multiple of the image element size in bytes.
if ((image_desc->image_row_pitch % elemSize) != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
}
if (image_desc->image_slice_pitch != 0u)
{
// image_slice_pitch must be 0 if host_ptr is NULL.
if (host_ptr == nullptr)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If host_ptr is not NULL, image_slice_pitch can be either 0
// or >= image_row_pitch * image_height for a 2D image array or 3D image
// and can be either 0 or >= image_row_pitch for a 1D image array.
if (image_desc->image_slice_pitch < sliceSize)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// If image_slice_pitch is not 0, it must be a multiple of the image_row_pitch.
if ((image_desc->image_slice_pitch % rowPitch) != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
}
// num_mip_levels and num_samples must be 0.
if (image_desc->num_mip_levels != 0u || image_desc->num_samples != 0u)
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// buffer can be a buffer memory object if image_type is CL_MEM_OBJECT_IMAGE1D_BUFFER or
// CL_MEM_OBJECT_IMAGE2D. buffer can be an image object if image_type is CL_MEM_OBJECT_IMAGE2D.
// Otherwise it must be NULL.
if (image_desc->buffer != nullptr &&
(!Buffer::IsValid(image_desc->buffer) ||
(image_desc->image_type != CL_MEM_OBJECT_IMAGE1D_BUFFER &&
image_desc->image_type != CL_MEM_OBJECT_IMAGE2D)) &&
(!Image::IsValid(image_desc->buffer) || image_desc->image_type != CL_MEM_OBJECT_IMAGE2D))
{
return CL_INVALID_IMAGE_DESCRIPTOR;
}
// CL_INVALID_OPERATION if there are no devices in context that support images.
if (!ctx.supportsImages())
{
return CL_INVALID_OPERATION;
}
// Returns CL_INVALID_OPERATION if no devices in context support creating a 2D image from a
// buffer.
const bool isImage2dFromBuffer =
image_desc->image_type == CL_MEM_OBJECT_IMAGE2D && image_desc->mem_object != NULL;
if (isImage2dFromBuffer && !ctx.supportsImage2DFromBuffer())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_IMAGE_SIZE if image dimensions specified in image_desc exceed the maximum
// image dimensions described in the Device Queries table for all devices in context.
const DevicePtrs &devices = ctx.getDevices();
if (std::find_if(devices.cbegin(), devices.cend(), [&](const DevicePtr &ptr) {
return ptr->supportsNativeImageDimensions(*image_desc);
}) == devices.cend())
{
return CL_INVALID_IMAGE_SIZE;
}
// CL_INVALID_HOST_PTR
// if host_ptr is NULL and CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in flags or
// if host_ptr is not NULL but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
if ((host_ptr != nullptr) != flags.intersects(CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))
{
return CL_INVALID_HOST_PTR;
}
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithBuiltInKernels(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const char *kernel_names)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 1u, 2u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_VALUE if device_list is NULL or num_devices is zero or if kernel_names is NULL.
if (device_list == nullptr || num_devices == 0u || kernel_names == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with context.
for (size_t index = 0u; index < num_devices; ++index)
{
if (!ctx.hasDevice(device_list[index]))
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if kernel_names contains a kernel name
// that is not supported by any of the devices in device_list.
const char *start = kernel_names;
do
{
const char *end = start;
while (*end != '\0' && *end != ';')
{
++end;
}
const size_t length = end - start;
if (length != 0u && !ctx.supportsBuiltInKernel(std::string(start, length)))
{
return CL_INVALID_VALUE;
}
start = end;
} while (*start++ != '\0');
return CL_SUCCESS;
}
cl_int ValidateCompileProgram(cl_program program,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
cl_uint num_input_headers,
const cl_program *input_headers,
const char **header_include_names,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
// CL_INVALID_PROGRAM if program is not a valid program object.
if (!Program::IsValid(program))
{
return CL_INVALID_PROGRAM;
}
const Program &prog = program->cast<Program>();
if (!prog.getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_PROGRAM;
}
// CL_INVALID_OPERATION if we do not have source code.
if (prog.getSource().empty())
{
ERR() << "No OpenCL C source available from program object (" << &prog << ")!";
return CL_INVALID_OPERATION;
}
// CL_INVALID_VALUE if device_list is NULL and num_devices is greater than zero,
// or if device_list is not NULL and num_devices is zero.
if ((device_list != nullptr) != (num_devices != 0u))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with program.
while (num_devices-- != 0u)
{
if (!prog.hasDevice(*device_list++))
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if num_input_headers is zero and header_include_names
// or input_headers are not NULL
// or if num_input_headers is not zero and header_include_names or input_headers are NULL.
if ((num_input_headers != 0u) != (header_include_names != nullptr) ||
(num_input_headers != 0u) != (input_headers != nullptr))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if pfn_notify is NULL but user_data is not NULL.
if (pfn_notify == nullptr && user_data != nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_OPERATION if the build of a program executable for any of the devices listed
// in device_list by a previous call to clBuildProgram for program has not completed.
if (prog.isBuilding())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_OPERATION if there are kernel objects attached to program.
if (prog.hasAttachedKernels())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateLinkProgram(cl_context context,
cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
cl_uint num_input_programs,
const cl_program *input_programs,
void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data),
const void *user_data)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 1u, 2u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_OPERATION if the compilation or build of a program executable for any of the
// devices listed in device_list by a previous call to clCompileProgram or clBuildProgram for
// program has not completed.
for (size_t i = 0; i < num_devices; ++i)
{
Device &device = device_list[i]->cast<Device>();
for (size_t j = 0; j < num_input_programs; ++j)
{
cl_build_status buildStatus = CL_BUILD_NONE;
Program &program = input_programs[j]->cast<Program>();
if (IsError(program.getBuildInfo(device.getNative(), ProgramBuildInfo::Status,
sizeof(cl_build_status), &buildStatus, nullptr)))
{
return CL_INVALID_PROGRAM;
}
if (buildStatus != CL_BUILD_SUCCESS)
{
return CL_INVALID_OPERATION;
}
}
}
// CL_INVALID_OPERATION if the rules for devices containing compiled binaries or libraries as
// described in input_programs argument below are not followed.
//
// All programs specified by input_programs contain a compiled binary or library for the device.
// In this case, a link is performed to generate a program executable for this device.
//
// None of the programs contain a compiled binary or library for that device. In this case, no
// link is performed and there will be no program executable generated for this device.
//
// All other cases will return a CL_INVALID_OPERATION error.
BitField libraryOrObject(CL_PROGRAM_BINARY_TYPE_LIBRARY |
CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT);
for (size_t i = 0; i < num_devices; ++i)
{
bool foundAnyLibraryOrObject = false;
Device &device = device_list[i]->cast<Device>();
for (size_t j = 0; j < num_input_programs; ++j)
{
cl_program_binary_type binaryType = CL_PROGRAM_BINARY_TYPE_NONE;
Program &program = input_programs[j]->cast<Program>();
if (IsError(program.getBuildInfo(device.getNative(), ProgramBuildInfo::BinaryType,
sizeof(cl_program_binary_type), &binaryType, nullptr)))
{
return CL_INVALID_PROGRAM;
}
if (libraryOrObject.excludes(binaryType))
{
if (foundAnyLibraryOrObject)
{
return CL_INVALID_OPERATION;
}
}
else
{
foundAnyLibraryOrObject = true;
}
}
}
// CL_INVALID_VALUE if device_list is NULL and num_devices is greater than zero,
// or if device_list is not NULL and num_devices is zero.
if ((device_list != nullptr) != (num_devices != 0u))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_DEVICE if any device in device_list
// is not in the list of devices associated with context.
while (num_devices-- != 0u)
{
if (!ctx.hasDevice(*device_list++))
{
return CL_INVALID_DEVICE;
}
}
// CL_INVALID_VALUE if num_input_programs is zero or input_programs is NULL.
if (num_input_programs == 0u || input_programs == nullptr)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_PROGRAM if programs specified in input_programs are not valid program objects.
while (num_input_programs-- != 0u)
{
if (!Program::IsValid(*input_programs++))
{
return CL_INVALID_PROGRAM;
}
}
// CL_INVALID_VALUE if pfn_notify is NULL but user_data is not NULL.
if (pfn_notify == nullptr && user_data != nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateUnloadPlatformCompiler(cl_platform_id platform)
{
// CL_INVALID_PLATFORM if platform is not a valid platform.
if (!Platform::IsValid(platform) || !platform->cast<Platform>().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_PLATFORM;
}
return CL_SUCCESS;
}
cl_int ValidateGetKernelArgInfo(cl_kernel kernel,
cl_uint arg_index,
KernelArgInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
// CL_INVALID_KERNEL if kernel is a not a valid kernel object.
if (!Kernel::IsValid(kernel))
{
return CL_INVALID_KERNEL;
}
const Kernel &krnl = kernel->cast<Kernel>();
if (!krnl.getProgram().getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_KERNEL;
}
// CL_INVALID_ARG_INDEX if arg_index is not a valid argument index.
if (arg_index >= krnl.getInfo().args.size())
{
return CL_INVALID_ARG_INDEX;
}
// CL_KERNEL_ARG_INFO_NOT_AVAILABLE if the argument information is not available for kernel.
if (!krnl.getInfo().args[arg_index].isAvailable())
{
return CL_KERNEL_ARG_INFO_NOT_AVAILABLE;
}
// CL_INVALID_VALUE if param_name is not valid.
if (param_name == KernelArgInfo::InvalidEnum)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueFillBuffer(cl_command_queue command_queue,
cl_mem buffer,
const void *pattern,
size_t pattern_size,
size_t offset,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
ANGLE_VALIDATE(ValidateEnqueueBuffer(queue, buffer, false, false));
// CL_INVALID_VALUE if offset or offset + size require accessing
// elements outside the buffer object respectively.
if (!buffer->cast<Buffer>().isRegionValid(offset, size))
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if pattern is NULL or if pattern_size is 0 or
// if pattern_size is not one of { 1, 2, 4, 8, 16, 32, 64, 128 }.
if (pattern == nullptr || pattern_size == 0u || pattern_size > 128u ||
(pattern_size & (pattern_size - 1u)) != 0u)
{
return CL_INVALID_VALUE;
}
// CL_INVALID_VALUE if offset and size are not a multiple of pattern_size.
if ((offset % pattern_size) != 0u || (size % pattern_size) != 0u)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueFillImage(cl_command_queue command_queue,
cl_mem image,
const void *fill_color,
const size_t *origin,
const size_t *region,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, true,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
ANGLE_VALIDATE(ValidateEnqueueImage(queue, image, false, false));
const Image &img = image->cast<Image>();
ANGLE_VALIDATE(ValidateImageForDevice(img, queue.getDevice(), origin, region));
// CL_INVALID_VALUE if fill_color is NULL.
if (fill_color == nullptr)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueMigrateMemObjects(cl_command_queue command_queue,
cl_uint num_mem_objects,
const cl_mem *mem_objects,
MemMigrationFlags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
const CommandQueue &queue = command_queue->cast<CommandQueue>();
if (!queue.getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
// CL_INVALID_VALUE if num_mem_objects is zero or if mem_objects is NULL.
if (num_mem_objects == 0u || mem_objects == nullptr)
{
return CL_INVALID_VALUE;
}
while (num_mem_objects-- != 0u)
{
// CL_INVALID_MEM_OBJECT if any of the memory objects
// in mem_objects is not a valid memory object.
if (!Memory::IsValid(*mem_objects))
{
return CL_INVALID_MEM_OBJECT;
}
// CL_INVALID_CONTEXT if the context associated with command_queue
// and memory objects in mem_objects are not the same.
if (&queue.getContext() != &(*mem_objects++)->cast<Memory>().getContext())
{
return CL_INVALID_CONTEXT;
}
}
// CL_INVALID_VALUE if flags is not 0 or is not any of the values described in the table.
const MemMigrationFlags allowedFlags(CL_MIGRATE_MEM_OBJECT_HOST |
CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED);
if (flags.hasOtherBitsThan(allowedFlags))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueMarkerWithWaitList(cl_command_queue command_queue,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
if (!command_queue->cast<CommandQueue>().getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
return CL_SUCCESS;
}
cl_int ValidateEnqueueBarrierWithWaitList(cl_command_queue command_queue,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
ANGLE_VALIDATE(ValidateCommandQueueAndEventWaitList(command_queue, false,
num_events_in_wait_list, event_wait_list));
if (!command_queue->cast<CommandQueue>().getContext().getPlatform().isVersionOrNewer(1u, 2u))
{
return CL_INVALID_COMMAND_QUEUE;
}
return CL_SUCCESS;
}
cl_int ValidateGetExtensionFunctionAddressForPlatform(cl_platform_id platform,
const char *func_name)
{
if (!Platform::IsValid(platform) || func_name == nullptr || *func_name == '\0')
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
// CL 2.0
cl_int ValidateCreateCommandQueueWithProperties(cl_context context,
cl_device_id device,
const cl_queue_properties *properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_DEVICE if device is not a valid device or is not associated with context.
if (!context->cast<Context>().hasDevice(device) ||
!device->cast<Device>().isVersionOrNewer(2u, 0u))
{
return CL_INVALID_DEVICE;
}
// CL_INVALID_VALUE if values specified in properties are not valid.
if (properties != nullptr)
{
bool isQueueOnDevice = false;
bool hasQueueSize = false;
while (*properties != 0)
{
switch (*properties++)
{
case CL_QUEUE_PROPERTIES:
{
const CommandQueueProperties props(*properties++);
const CommandQueueProperties validProps(
CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE |
CL_QUEUE_ON_DEVICE | CL_QUEUE_ON_DEVICE_DEFAULT);
if (props.hasOtherBitsThan(validProps) ||
// If CL_QUEUE_ON_DEVICE is set, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
// must also be set.
(props.intersects(CL_QUEUE_ON_DEVICE) &&
!props.intersects(CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE)) ||
// CL_QUEUE_ON_DEVICE_DEFAULT can only be used with CL_QUEUE_ON_DEVICE.
(props.intersects(CL_QUEUE_ON_DEVICE_DEFAULT) &&
!props.intersects(CL_QUEUE_ON_DEVICE)))
{
return CL_INVALID_VALUE;
}
isQueueOnDevice = props.intersects(CL_QUEUE_ON_DEVICE);
break;
}
case CL_QUEUE_SIZE:
{
// CL_QUEUE_SIZE must be a value <= CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE.
if (*properties++ > device->cast<Device>().getInfo().queueOnDeviceMaxSize)
{
return CL_INVALID_VALUE;
}
hasQueueSize = true;
break;
}
default:
return CL_INVALID_VALUE;
}
}
// CL_QUEUE_SIZE can only be specified if CL_QUEUE_ON_DEVICE is set in CL_QUEUE_PROPERTIES.
if (hasQueueSize && !isQueueOnDevice)
{
return CL_INVALID_VALUE;
}
}
return CL_SUCCESS;
}
cl_int ValidateCreatePipe(cl_context context,
MemFlags flags,
cl_uint pipe_packet_size,
cl_uint pipe_max_packets,
const cl_pipe_properties *properties)
{
return CL_SUCCESS;
}
cl_int ValidateGetPipeInfo(cl_mem pipe,
PipeInfo param_name,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateSVMAlloc(cl_context context, SVM_MemFlags flags, size_t size, cl_uint alignment)
{
return CL_SUCCESS;
}
cl_int ValidateSVMFree(cl_context context, const void *svm_pointer)
{
return CL_SUCCESS;
}
cl_int ValidateCreateSamplerWithProperties(cl_context context,
const cl_sampler_properties *sampler_properties)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_VALUE if the property name in sampler_properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (sampler_properties != nullptr)
{
bool hasNormalizedCoords = false;
bool hasAddressingMode = false;
bool hasFilterMode = false;
const cl_sampler_properties *propIt = sampler_properties;
while (*propIt != 0)
{
switch (*propIt++)
{
case CL_SAMPLER_NORMALIZED_COORDS:
if (hasNormalizedCoords || (*propIt != CL_FALSE && *propIt != CL_TRUE))
{
return CL_INVALID_VALUE;
}
hasNormalizedCoords = true;
++propIt;
break;
case CL_SAMPLER_ADDRESSING_MODE:
if (hasAddressingMode || FromCLenum<AddressingMode>(static_cast<CLenum>(
*propIt++)) == AddressingMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
hasAddressingMode = true;
break;
case CL_SAMPLER_FILTER_MODE:
if (hasFilterMode || FromCLenum<FilterMode>(static_cast<CLenum>(*propIt++)) ==
FilterMode::InvalidEnum)
{
return CL_INVALID_VALUE;
}
hasFilterMode = true;
break;
default:
return CL_INVALID_VALUE;
}
}
}
// CL_INVALID_OPERATION if images are not supported by any device associated with context.
if (!context->cast<Context>().supportsImages())
{
return CL_INVALID_OPERATION;
}
return CL_SUCCESS;
}
cl_int ValidateSetKernelArgSVMPointer(cl_kernel kernel, cl_uint arg_index, const void *arg_value)
{
return CL_SUCCESS;
}
cl_int ValidateSetKernelExecInfo(cl_kernel kernel,
KernelExecInfo param_name,
size_t param_value_size,
const void *param_value)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMFree(cl_command_queue command_queue,
cl_uint num_svm_pointers,
void *const svm_pointers[],
void(CL_CALLBACK *pfn_free_func)(cl_command_queue queue,
cl_uint num_svm_pointers,
void *svm_pointers[],
void *user_data),
const void *user_data,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMemcpy(cl_command_queue command_queue,
cl_bool blocking_copy,
const void *dst_ptr,
const void *src_ptr,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMemFill(cl_command_queue command_queue,
const void *svm_ptr,
const void *pattern,
size_t pattern_size,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMap(cl_command_queue command_queue,
cl_bool blocking_map,
MapFlags flags,
const void *svm_ptr,
size_t size,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMUnmap(cl_command_queue command_queue,
const void *svm_ptr,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
// CL 2.1
cl_int ValidateSetDefaultDeviceCommandQueue(cl_context context,
cl_device_id device,
cl_command_queue command_queue)
{
return CL_SUCCESS;
}
cl_int ValidateGetDeviceAndHostTimer(cl_device_id device,
const cl_ulong *device_timestamp,
const cl_ulong *host_timestamp)
{
return CL_SUCCESS;
}
cl_int ValidateGetHostTimer(cl_device_id device, const cl_ulong *host_timestamp)
{
return CL_SUCCESS;
}
cl_int ValidateCreateProgramWithIL(cl_context context, const void *il, size_t length)
{
// CL_INVALID_CONTEXT if context is not a valid context.
if (!Context::IsValidAndVersionOrNewer(context, 2u, 1u))
{
return CL_INVALID_CONTEXT;
}
const Context &ctx = context->cast<Context>();
// CL_INVALID_OPERATION if no devices in context support intermediate language programs.
if (!ctx.supportsIL())
{
return CL_INVALID_OPERATION;
}
// CL_INVALID_VALUE if il is NULL or if length is zero.
if (il == nullptr || length == 0u)
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int ValidateCloneKernel(cl_kernel source_kernel)
{
if (!Kernel::IsValid(source_kernel))
{
return CL_INVALID_KERNEL;
}
return CL_SUCCESS;
}
cl_int ValidateGetKernelSubGroupInfo(cl_kernel kernel,
cl_device_id device,
KernelSubGroupInfo param_name,
size_t input_value_size,
const void *input_value,
size_t param_value_size,
const void *param_value,
const size_t *param_value_size_ret)
{
return CL_SUCCESS;
}
cl_int ValidateEnqueueSVMMigrateMem(cl_command_queue command_queue,
cl_uint num_svm_pointers,
const void **svm_pointers,
const size_t *sizes,
MemMigrationFlags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
const cl_event *event)
{
return CL_SUCCESS;
}
// CL 2.2
cl_int ValidateSetProgramReleaseCallback(cl_program program,
void(CL_CALLBACK *pfn_notify)(cl_program program,
void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateSetProgramSpecializationConstant(cl_program program,
cl_uint spec_id,
size_t spec_size,
const void *spec_value)
{
return CL_SUCCESS;
}
// CL 3.0
cl_int ValidateSetContextDestructorCallback(cl_context context,
void(CL_CALLBACK *pfn_notify)(cl_context context,
void *user_data),
const void *user_data)
{
return CL_SUCCESS;
}
cl_int ValidateCreateBufferWithProperties(cl_context context,
const cl_mem_properties *properties,
MemFlags flags,
size_t size,
const void *host_ptr)
{
ANGLE_VALIDATE(ValidateCreateBuffer(context, flags, size, host_ptr));
// CL_INVALID_CONTEXT if context is not a valid context.
if (!context->cast<Context>().getPlatform().isVersionOrNewer(3u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (!ValidateMemoryProperties(properties))
{
return CL_INVALID_PROPERTY;
}
return CL_SUCCESS;
}
cl_int ValidateCreateImageWithProperties(cl_context context,
const cl_mem_properties *properties,
MemFlags flags,
const cl_image_format *image_format,
const cl_image_desc *image_desc,
const void *host_ptr)
{
ANGLE_VALIDATE(ValidateCreateImage(context, flags, image_format, image_desc, host_ptr));
// CL_INVALID_CONTEXT if context is not a valid context.
if (!context->cast<Context>().getPlatform().isVersionOrNewer(3u, 0u))
{
return CL_INVALID_CONTEXT;
}
// CL_INVALID_PROPERTY if a property name in properties is not a supported property name,
// if the value specified for a supported property name is not valid,
// or if the same property name is specified more than once.
if (!ValidateMemoryProperties(properties))
{
return CL_INVALID_PROPERTY;
}
return CL_SUCCESS;
}
// cl_khr_icd
cl_int ValidateIcdGetPlatformIDsKHR(cl_uint num_entries,
const cl_platform_id *platforms,
const cl_uint *num_platforms)
{
if ((num_entries == 0u && platforms != nullptr) ||
(platforms == nullptr && num_platforms == nullptr))
{
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
} // namespace cl