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
|
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file cm_device_rt.cpp
//! \brief Contains OS-agnostic CmDevice member functions.
//!
#include "cm_device_rt.h"
#include "cm_queue_rt.h"
#include "cm_surface_manager.h"
#include "cm_program.h"
#include "cm_kernel_rt.h"
#include "cm_task_rt.h"
#include "cm_buffer_rt.h"
#include "cm_thread_space_rt.h"
#include "cm_debug.h"
#include "cm_mem.h"
#include "cm_surface_vme.h"
#include "cm_sampler8x8_state_rt.h"
#include "cm_sampler_rt.h"
#include "cm_group_space.h"
#include "cm_surface_2d_rt.h"
#include "cm_surface_2d_up_rt.h"
#include "cm_surface_3d_rt.h"
#include "cm_vebox_rt.h"
#include "cm_printf_host.h"
#include "cm_execution_adv.h"
struct CM_SET_CAPS
{
CM_SET_TYPE type;
union
{
uint32_t maxValue;
struct
{
uint32_t configRegsiter0;
uint32_t configRegsiter1;
uint32_t configRegsiter2;
uint32_t configRegsiter3;
};
};
};
extern uint64_t HalCm_GetTsFrequency(PMOS_INTERFACE pOsInterface);
namespace CMRT_UMD
{
CSync CmDeviceRT::m_globalCriticalSectionSurf2DUserDataLock = CSync();
//*-----------------------------------------------------------------------------
//| Purpose: Create Cm Device
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::Create(MOS_CONTEXT *umdContext,
CmDeviceRT* &device,
uint32_t options)
{
int32_t result = CM_FAILURE;
if(device != nullptr )
{
// if the Cm Device exists
device->Acquire();
return CM_SUCCESS;
}
device = new (std::nothrow) CmDeviceRT(options);
if( device )
{
device->Acquire(); // increase ref count
result = device->Initialize( umdContext );
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Failed to initialzie CmDevice.");
CmDeviceRT::Destroy( device);
device = nullptr;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to create CmDevice due to out of system memory.");
result = CM_OUT_OF_HOST_MEMORY;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Cm Device Acquire: Increae the m_cmDeviceRefCount
//| Returns: CM_SUCCESS
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::Acquire()
{
// Enter critical section
CLock locker(m_criticalSectionDeviceRefCount);
m_cmDeviceRefCount ++;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Cm Device Relase: Decrease the m_cmDeviceRefCount
//| Returns: Reference count of Cm Device
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::Release()
{
// Enter critical section
CLock locker(m_criticalSectionDeviceRefCount);
m_cmDeviceRefCount --;
return m_cmDeviceRefCount;
}
//*-----------------------------------------------------------------------------
//! Destroy the CmDevice_RT and kernels, samplers and the queue it created.
//! Also destroy all surfaces it created if the surface hasn't been explicitly destroyed.
//! Input :
//! Reference to the pointer to the CmDevice_RT .
//! OUTPUT :
//! CM_SUCCESS if CmDevice_RT is successfully destroyed.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::Destroy(CmDeviceRT* &device)
{
INSERT_API_CALL_LOG();
int32_t result = CM_SUCCESS;
int32_t refCount = device->Release();
if(refCount == 0)
{
CmSafeDelete(device);
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Constructor of CmDevice
//| Returns: None.
//*-----------------------------------------------------------------------------
CmDeviceRT::CmDeviceRT(uint32_t options):
m_mosContext (nullptr),
m_accelData (nullptr),
m_accelSize (0),
m_surfaceMgr( nullptr ),
m_programArray( CM_INIT_PROGRAM_COUNT ),
m_programCount( 0 ),
m_kernelArray( CM_INIT_KERNEL_COUNT ),
m_kernelCount( 0 ),
m_samplerArray( CM_INIT_SAMPLER_COUNT ),
m_sampler8x8Array( CM_INIT_SAMPLER_COUNT ),
m_threadSpaceArray( CM_INIT_THREADSPACE_COUNT ),
m_threadSpaceCount( 0 ),
m_hJITDll(nullptr),
m_fJITCompile(nullptr),
m_fJITCompile_v2(nullptr),
m_fFreeBlock(nullptr),
m_fJITVersion(nullptr),
m_ddiVersion( 0 ),
m_platform(IGFX_UNKNOWN_CORE),
m_cmDeviceRefCount(0),
m_gpuCopyKernelProgram(nullptr),
m_surfInitKernelProgram(nullptr),
m_osSyncEvent (0),
#if USE_EXTENSION_CODE
m_gtpin(nullptr),
#endif
m_isPrintEnabled(false),
m_printBufferMem (nullptr),
m_printBufferUP(nullptr),
m_printBufferSize(0),
m_printBufferIndex(nullptr),
m_threadGroupSpaceArray(CM_INIT_THREADGROUPSPACE_COUNT),
m_threadGroupSpaceCount(0),
m_taskArray(CM_INIT_TASK_COUNT),
m_taskCount(0),
m_veboxArray(CM_INIT_VEBOX_COUNT),
m_veboxCount(0),
m_nGPUFreqOriginal(0),
m_nGPUFreqMin(0),
m_nGPUFreqMax(0),
m_vtuneOn(false),
m_isDriverStoreEnabled(0),
m_hasGpuCopyKernel(false),
m_hasGpuInitKernel(false)
{
//Initialize Dev Create Param
InitDevCreateOption( m_cmHalCreateOption, options );
// Initialize the OS-Specific fields
ConstructOSSpecific(options);
// Create the notifers
m_notifierGroup = MOS_New(CmNotifierGroup);
}
//*-----------------------------------------------------------------------------
//| Purpose: The common part of destructor of CmDevice, that is OS independent
//| Returns: None.
//*-----------------------------------------------------------------------------
void CmDeviceRT::DestructCommon()
{
// Delete Predefined Program
if(m_gpuCopyKernelProgram)
{
DestroyProgram(m_gpuCopyKernelProgram);
}
if(m_surfInitKernelProgram)
{
DestroyProgram(m_surfInitKernelProgram);
}
//Free the surface/memory for print buffer
if(m_printBufferMem)
{
MOS_AlignedFreeMemory(m_printBufferMem);
}
if(m_printBufferUP)
{
DestroyBufferUP(m_printBufferUP);
}
#if USE_EXTENSION_CODE
// Free CmGTPin
MOS_Delete(m_gtpin);
#endif
// Solve resource release dependency issue
// Flush Queue to make sure no task internal and connected resouces left.
m_criticalSectionQueue.Acquire();
for (auto iter = m_queue.begin(); iter != m_queue.end(); iter++)
{
(*iter)->CleanQueue();
}
m_criticalSectionQueue.Release();
for( uint32_t i = 0; i < m_kernelCount; i ++ )
{
CmKernelRT* kernel = (CmKernelRT*)m_kernelArray.GetElement( i );
if( kernel )
{
CmProgramRT* program = nullptr;
kernel->GetCmProgram(program);
uint32_t indexInProgramArray;
for (indexInProgramArray = 0; indexInProgramArray < m_programArray.GetSize(); indexInProgramArray++)
{
if (program == m_programArray.GetElement( indexInProgramArray ))
{
break;
}
}
CmKernelRT::Destroy( kernel, program );
if ((program == nullptr) && (indexInProgramArray < m_programArray.GetSize()))
{
m_programArray.SetElement(indexInProgramArray, nullptr);
}
}
}
m_kernelArray.Delete();
for( uint32_t i = 0; i < m_programArray.GetSize(); i ++ )
{
CmProgramRT* program = (CmProgramRT*)m_programArray.GetElement( i );
while( program ) // Program can be acquired more than once
{
CmProgramRT::Destroy( program );
}
}
m_programArray.Delete();
for( uint32_t i = 0; i < m_samplerArray.GetSize(); i ++ )
{
CmSamplerRT* sampler = (CmSamplerRT *)m_samplerArray.GetElement( i );
if(sampler)
{
SamplerIndex* index = nullptr;
sampler->GetIndex( index );
CM_ASSERT( index );
uint32_t indexValue = index->get_data();
CmSamplerRT::Destroy( sampler );
UnregisterSamplerState( indexValue );
}
}
m_samplerArray.Delete();
for(uint32_t i = 0; i < m_sampler8x8Array.GetSize(); i ++ )
{
CmSampler8x8State_RT* sampler8x8 = (CmSampler8x8State_RT* )m_sampler8x8Array.GetElement( i );
if(sampler8x8)
{
SamplerIndex* index = nullptr;
sampler8x8->GetIndex( index );
CM_ASSERT( index );
uint32_t indexValue = index->get_data();
CmSampler8x8State_RT::Destroy( sampler8x8 );
UnregisterSampler8x8State( indexValue );
}
}
m_sampler8x8Array.Delete();
uint32_t threadSpaceArrayUsedSize = m_threadSpaceArray.GetSize();
for( uint32_t i = 0; i < threadSpaceArrayUsedSize; i ++ )
{
CmThreadSpaceRT* threadSpaceRT = (CmThreadSpaceRT*)m_threadSpaceArray.GetElement( i );
if( threadSpaceRT )
{
CmThreadSpaceRT::Destroy( threadSpaceRT );
}
}
m_threadSpaceArray.Delete();
for( uint32_t i = 0; i < m_threadGroupSpaceCount; i ++ ) // Destroy thread group space array
{
CmThreadGroupSpace* threadGroupSpace = (CmThreadGroupSpace*)m_threadGroupSpaceArray.GetElement( i );
if( threadGroupSpace )
{
CmThreadGroupSpace::Destroy( threadGroupSpace );
}
}
m_threadGroupSpaceArray.Delete();
uint32_t taskArrayUsedSize = m_taskArray.GetSize();
for( uint32_t i = 0; i < taskArrayUsedSize; i ++ ) // Destroy task array
{
CmTaskRT* task = (CmTaskRT*)m_taskArray.GetElement( i );
if( task )
{
CmTaskRT::Destroy( task );
}
}
m_taskArray.Delete();
for( uint32_t i = 0; i < m_veboxCount; i ++ ) // Destroy Vebox array
{
CmVeboxRT* vebox = (CmVeboxRT*)m_veboxArray.GetElement(i);
if (vebox)
{
CmVeboxRT::Destroy(vebox);
}
}
m_veboxArray.Delete();
//Destroy Surface Manager
CmSurfaceManager::Destroy( m_surfaceMgr );
//Destroy Queue: Queue must be released after surface manager
m_criticalSectionQueue.Acquire();
for (auto iter = m_queue.begin(); iter != m_queue.end();)
{
DestroyQueue(*iter);
iter = m_queue.erase(iter);
}
m_criticalSectionQueue.Release();
// Notify the listeners
if (m_notifierGroup != nullptr)
{
m_notifierGroup->NotifyDeviceDestroyed(this);
}
//Free the notifiers
if (m_notifierGroup != nullptr)
{
MOS_Delete(m_notifierGroup);
}
//Free DLL handle if it is there
if (m_hJITDll)
{
MOS_FreeLibrary(m_hJITDll);
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Aux Device and Initialize it
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::Initialize(MOS_CONTEXT *mosContext)
{
int32_t result = InitializeOSSpecific(mosContext);
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Initialize OS specific failure.");
return result;
}
m_surfaceMgr = nullptr;
result = CmSurfaceManager::Create(
this,
m_halMaxValues,
m_halMaxValuesEx,
m_surfaceMgr );
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Error: Create CmSurfaceManager failure.");
return result;
}
result = SetSurfaceArraySizeForAlias();
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Set surface array size failure.");
return result;
}
ReadVtuneProfilingFlag();
// Load Predefined Kernels
CmProgram* tmpProgram = nullptr;
int32_t ret = 0;
ret = LoadPredefinedCopyKernel(tmpProgram);
if (ret == CM_SUCCESS)
{
m_hasGpuCopyKernel = true;
}
ret = LoadPredefinedInitKernel(tmpProgram);
if (ret == CM_SUCCESS)
{
m_hasGpuInitKernel = true;
}
// get the last tracker
PCM_HAL_STATE state = (( PCM_CONTEXT_DATA )m_accelData)->cmHalState;
m_surfaceMgr->SetLatestRenderTrackerAddr(state->renderHal->trackerResource.data);
m_surfaceMgr->SetLatestFastTrackerAddr(state->advExecutor->GetLatestFastTracker());
m_surfaceMgr->SetLatestVeboxTrackerAddr(state->renderHal->veBoxTrackerRes.data);
if (m_notifierGroup != nullptr)
{
m_notifierGroup->NotifyDeviceCreated(this);
}
DEVICE_LOG(this);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Buffer
//| Arguments : size [in] Size of the Buffer
//| surface [in/out] Reference to Pointer to CmBuffer
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateBuffer(uint32_t size, CmBuffer* & surface)
{
INSERT_API_CALL_LOG();
if( ( size < CM_MIN_SURF_WIDTH ) || ( size > CM_MAX_1D_SURF_WIDTH ) )
{
CM_ASSERTMESSAGE("Error: Invalid buffer size.");
return CM_INVALID_WIDTH;
}
CLock locker(m_criticalSectionSurface);
CmBuffer_RT* bufferRT = nullptr;
void *sysMem = nullptr;
int result = m_surfaceMgr->CreateBuffer(size, CM_BUFFER_N, false, bufferRT, nullptr, sysMem, false, CM_DEFAULT_COMPARISON_VALUE);
surface = static_cast< CmBuffer* >(bufferRT);
return result;
}
//!
//! \brief Create a CmBuffer from an existing MOS Resource.
//! \details CmBuffer is a wrapper of that MOS resource. This Mos resource is
//! owned by caller.
//! \param [in] mosResource
//! pointer to MOS resource.
//! \param [in,out] surface
//! reference to pointer of surface to be created.
//! \retval CM_SUCCESS if the CmBuffer is successfully created.
//! \retval CM_INVALID_MOS_RESOURCE_HANDLE if mosResource is nullptr.
//! \retval CM_OUT_OF_HOST_MEMORY if out of system memory
//! \retval CM_EXCEED_SURFACE_AMOUNT if maximum amount of 1D surfaces is exceeded.
//! \retval CM_FAILURE otherwise
//!
CM_RT_API int32_t CmDeviceRT::CreateBuffer(PMOS_RESOURCE mosResource,
CmBuffer* & surface)
{
INSERT_API_CALL_LOG();
if(mosResource == nullptr)
{
return CM_INVALID_MOS_RESOURCE_HANDLE;
}
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
PCM_HAL_STATE state = cmData->cmHalState;
MOS_SURFACE mosSurfDetails;
MOS_ZeroMemory(&mosSurfDetails, sizeof(mosSurfDetails));
int hr = state->osInterface->pfnGetResourceInfo(state->osInterface, mosResource, &mosSurfDetails);
if(hr != MOS_STATUS_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Get resource info failure.");
return hr;
}
if( (mosSurfDetails.dwWidth < CM_MIN_SURF_WIDTH ) || (mosSurfDetails.dwWidth > CM_MAX_1D_SURF_WIDTH ) )
{
CM_ASSERTMESSAGE("Error: Invalid buffer size.");
return CM_INVALID_WIDTH;
}
CLock locker(m_criticalSectionSurface);
CmBuffer_RT* buffer = nullptr;
void* sysMem = nullptr;
int ret = m_surfaceMgr->CreateBuffer(mosSurfDetails.dwWidth, CM_BUFFER_N, false,
buffer, mosResource, sysMem, false, CM_DEFAULT_COMPARISON_VALUE);
surface = static_cast< CmBuffer* >(buffer);
return ret;
}
//*--------------------------------------------------------------------------------------------
//| Purpose: Create BufferUp
//| Arguments : size [in] Size of the Buffer, should be uint32_t-aligned
//| sysMem [in] Pointer to host memory, must be page(4K bytes)-aligned.
//| surface [in/out] Reference to Pointer to CmBufferUP
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateBufferUP(uint32_t size,
void* sysMem,
CmBufferUP* & surface)
{
INSERT_API_CALL_LOG();
// size should be in the valid range and be aligned in uint32_t
if( ( size < CM_MIN_SURF_WIDTH ) || ( size > CM_MAX_1D_SURF_WIDTH ) || (size % sizeof(uint32_t)))
{
CM_ASSERTMESSAGE("Error: Invalid buffer size.\n");
return CM_INVALID_WIDTH;
}
if (nullptr == sysMem)
{
CM_ASSERTMESSAGE("Error: Pointer to host memory is null.\n");
return CM_INVALID_ARG_VALUE;
}
auto uintPtr = reinterpret_cast<uintptr_t>(sysMem);
if (uintPtr & (0x1000 - 1))
{
CM_ASSERTMESSAGE("Error: Pointer to host memory isn't 4K-aligned.\n");
return CM_INVALID_ARG_VALUE;
}
CLock locker(m_criticalSectionSurface);
CmBuffer_RT* bufferRT = nullptr;
int result = m_surfaceMgr->CreateBuffer( size, CM_BUFFER_UP, false, bufferRT, nullptr, sysMem, false, CM_DEFAULT_COMPARISON_VALUE );
surface = static_cast< CmBufferUP* >(bufferRT);
return result;
}
//*----------------------------------------------------------------------------
//| Purpose: Destroy BufferUp
//| Arguments : surface [in] Reference to Pointer to CmBuffer
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroyBufferUP(CmBufferUP* & surface)
{
INSERT_API_CALL_LOG();
CmBuffer_RT* temp = static_cast< CmBuffer_RT* >(surface);
if (nullptr == temp)
{
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionSurface);
int32_t status = m_surfaceMgr->DestroySurface(temp, APP_DESTROY);
if (status != CM_FAILURE) //CM_SURFACE_IN_USE may be returned, which should be treated as SUCCESS.
{
surface = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
return status;
}
//*----------------------------------------------------------------------------
//| Purpose: Forces the BufferUP to be destroyed
//| Arguments : surface [in] Reference to Pointer to CmBuffer
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::ForceDestroyBufferUP(CmBufferUP* & surface)
{
INSERT_API_CALL_LOG();
CmBuffer_RT* temp = static_cast< CmBuffer_RT* >(surface);
if (nullptr == temp)
{
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionSurface);
int32_t status = m_surfaceMgr->DestroySurface(temp, FORCE_DESTROY);
if(status == CM_SUCCESS)
{
surface = nullptr;
}
return status;
}
//*--------------------------------------------------------------------------------------------
//| Purpose: Create Surface 2D UP
//| Arguments : width [in] width of the CmSurface2DUP
//| height [in] height of the CmSurface2DUP
//| format [in] format of the CmSurface2DUP
//|
//| sysMem [in] Pointer to host memory, must be page(4K bytes)-aligned.
//| surface [in/out] Reference to Pointer to CmSurface2DUP
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateSurface2DUP(uint32_t width,
uint32_t height,
CM_SURFACE_FORMAT format,
void* sysMem,
CmSurface2DUP* & surface )
{
INSERT_API_CALL_LOG();
int32_t result = m_surfaceMgr->Surface2DSanityCheck(width, height, format);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Surface2D sanity check failure.\n");
return result;
}
if (sysMem == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to host memory is null.\n");
return CM_INVALID_ARG_VALUE;
}
auto uintPtr = reinterpret_cast<uintptr_t>(sysMem);
if (uintPtr & (0x1000 - 1))
{
CM_ASSERTMESSAGE("Error: Pointer to host memory isn't 4K-aligned.\n");
return CM_INVALID_ARG_VALUE;
}
CmSurface2DUPRT *surfaceRT = nullptr;
CLock locker(m_criticalSectionSurface);
result = m_surfaceMgr->CreateSurface2DUP( width, height, format, sysMem, surfaceRT );
surface = surfaceRT;
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Surface 2D
//| Arguments : width [in] width of the CmSurface2D
//| height [in] height of the CmSurface2D
//| format [in] format of the CmSurface2D
//| surface [in/out] Reference to Pointer to CmSurface2D
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateSurface2D(uint32_t width,
uint32_t height,
CM_SURFACE_FORMAT format,
CmSurface2D* & surface )
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
CmSurface2DRT *surfaceRT = nullptr;
int ret = m_surfaceMgr->CreateSurface2D( width, height, 0, true, format, surfaceRT);
surface = surfaceRT;
return ret;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create shared Surface 2D (OS agnostic)
//| Arguments :
//| mosResource [in] Pointer to Mos resource
//| surface [out] Reference to Pointer to CmSurface2D
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateSurface2D(PMOS_RESOURCE mosResource,
CmSurface2D* & surface )
{
INSERT_API_CALL_LOG();
if(mosResource == nullptr)
{
return CM_INVALID_MOS_RESOURCE_HANDLE;
}
CLock locker(m_criticalSectionSurface);
CmSurface2DRT *surfaceRT = nullptr;
int ret = m_surfaceMgr->CreateSurface2D( mosResource, false, surfaceRT);
surface = surfaceRT;
return ret;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Surface 2D
//| NOTE: Called by CM Wrapper, from CMRT Thin
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT:: CreateSurface2D(PMOS_RESOURCE mosResource,
bool isCmCreated,
CmSurface2D* & surface)
{
INSERT_API_CALL_LOG();
if(mosResource == nullptr)
{
return CM_INVALID_MOS_RESOURCE_HANDLE;
}
CLock locker(m_criticalSectionSurface);
CmSurface2DRT *surfaceRT = nullptr;
int ret = m_surfaceMgr->CreateSurface2D( mosResource, isCmCreated, surfaceRT);
surface = surfaceRT;
return ret;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Surface 2D
//| Arguments :
//| width [in] width of the CmSurface3D
//| height [in] height of the CmSurface3D
//| format [in] format of the CmSurface3D
//| depth [in] depth of the CmSurface3D
//| surface [out] Reference to Pointer to CmSurface3D
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateSurface3D(uint32_t width,
uint32_t height,
uint32_t depth,
CM_SURFACE_FORMAT format,
CmSurface3D* & surface )
{
INSERT_API_CALL_LOG();
if( ( width < CM_MIN_SURF_WIDTH ) || ( width > CM_MAX_3D_SURF_WIDTH ) )
{
CM_ASSERTMESSAGE("Error: Invalid surface 3D width.");
return CM_INVALID_WIDTH;
}
if( ( height < CM_MIN_SURF_HEIGHT ) || ( height > CM_MAX_3D_SURF_HEIGHT ) )
{
CM_ASSERTMESSAGE("Error: Invalid surface 3D height.");
return CM_INVALID_HEIGHT;
}
if( ( depth < CM_MIN_SURF_DEPTH ) || ( depth > CM_MAX_3D_SURF_DEPTH ) )
{
CM_ASSERTMESSAGE("Error: Invalid surface 3D depth.");
return CM_INVALID_DEPTH;
}
CLock locker(m_criticalSectionSurface);
CmSurface3DRT *surfaceRT = nullptr;
int ret = m_surfaceMgr->CreateSurface3D( width, height, depth, format, surfaceRT );
surface = surfaceRT;
return ret;
}
CM_RT_API int32_t CmDeviceRT::DestroySurface( CmBuffer* & surface)
{
CmBuffer_RT* temp = static_cast< CmBuffer_RT* >(surface);
if (nullptr == temp)
{
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionSurface);
int32_t status = m_surfaceMgr->DestroySurface( temp, APP_DESTROY);
if (status != CM_FAILURE) //CM_SURFACE_IN_USE, or CM_SURFACE_CACHED may be returned, which should be treated as SUCCESS.
{
surface = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*----------------------------------------------------------------------------
//| Purpose: Destroy CmSurface2DUP
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroySurface2DUP( CmSurface2DUP* & surface)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
CmSurface2DUPRT *surfaceRT = static_cast<CmSurface2DUPRT *>(surface);
if (nullptr == surfaceRT)
{
return CM_NULL_POINTER;
}
int32_t status = m_surfaceMgr->DestroySurface( surfaceRT, APP_DESTROY );
if (status != CM_FAILURE) //CM_SURFACE_IN_USE, or CM_SURFACE_CACHED may be returned, which should be treated as SUCCESS.
{
surface = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*----------------------------------------------------------------
//| Purpose: Destroys a CmSurface2D object and returns the status.
//*----------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroySurface(CmSurface2D* &surface)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT*>(surface);
if (nullptr == surfaceRT)
{
return CM_NULL_POINTER;
}
int32_t status = m_surfaceMgr->DestroySurface(surfaceRT, APP_DESTROY);
if (status != CM_FAILURE) // CM_SURFACE_IN_USE may be returned, which should be treated as SUCCESS.
{
surface = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*------------------------------------------------------------------
//| Purpose: Destroys a CmSurface3D object and returns the status.
//*------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroySurface( CmSurface3D* & surface)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
CmSurface3DRT *surfaceRT = static_cast<CmSurface3DRT *>(surface);
if (nullptr == surfaceRT)
{
return CM_NULL_POINTER;
}
int32_t status = m_surfaceMgr->DestroySurface( surfaceRT, APP_DESTROY);
if (status != CM_FAILURE) //CM_SURFACE_IN_USE, or CM_SURFACE_CACHED may be returned, which should be treated as SUCCESS.
{
surface = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*----------------------------------------------------------------------------
//| Purpose: Get Current platform information
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::GetGenPlatform( uint32_t &platform )
{
if( m_platform != IGFX_UNKNOWN_CORE)
{
platform = m_platform;
return CM_SUCCESS;
}
platform = IGFX_UNKNOWN_CORE;
int32_t hr = 0;
CM_QUERY_CAPS queryCaps;
uint32_t querySize = sizeof( CM_QUERY_CAPS );
CmSafeMemSet( &queryCaps, 0, sizeof( queryCaps ) );
queryCaps.type = CM_QUERY_GPU;
hr = GetCapsInternal( &queryCaps, &querySize);
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Failed to get current GPU platform information.");
return CM_FAILURE;
}
if (queryCaps.version)
{
platform = queryCaps.version;
}
return CM_SUCCESS;
}
//*----------------------------------------------------------------------------
//| Purpose: Get Surface2D information: pitch and physical size in Video memory
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::GetSurface2DInfo(uint32_t width,
uint32_t height,
CM_SURFACE_FORMAT format,
uint32_t & pitch,
uint32_t & physicalSize)
{
INSERT_API_CALL_LOG();
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_SURFACE2D_UP_PARAM inParam;
PCM_CONTEXT_DATA cmData;
PCM_HAL_STATE cmHalState;
CM_CHK_CMSTATUS_GOTOFINISH(m_surfaceMgr->Surface2DSanityCheck(width, height, format));
CmSafeMemSet( &inParam, 0, sizeof( CM_HAL_SURFACE2D_UP_PARAM ) );
inParam.width = width;
inParam.height = height;
inParam.format = format;
cmData = (PCM_CONTEXT_DATA)GetAccelData();
cmHalState = cmData->cmHalState;
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnGetSurface2DPitchAndSize(cmHalState, &inParam));
pitch = inParam.pitch;
physicalSize = inParam.physicalSize;
finish:
return hr;
}
int32_t CmDeviceRT::GetSurfaceManager( CmSurfaceManager* & surfaceMgr )
{
surfaceMgr = m_surfaceMgr;
return CM_SUCCESS;
}
CSync* CmDeviceRT::GetSurfaceLock()
{
return &m_criticalSectionReadWriteSurface2D;
}
CSync* CmDeviceRT::GetSurfaceCreationLock()
{
return &m_criticalSectionSurface;
}
CSync* CmDeviceRT::GetProgramKernelLock()
{
return &m_criticalSectionProgramKernel;
}
std::vector<CmQueueRT *> &CmDeviceRT::GetQueue()
{
return m_queue;
}
CSync* CmDeviceRT::GetQueueLock()
{
return &m_criticalSectionQueue;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Max values from Device
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetHalMaxValues(CM_HAL_MAX_VALUES* & halMaxValues,
CM_HAL_MAX_VALUES_EX* & halMaxValuesEx)
{
halMaxValues = &m_halMaxValues;
halMaxValuesEx = &m_halMaxValuesEx;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Max values by Caps
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetMaxValueFromCaps(CM_HAL_MAX_VALUES &maxValues,
CM_HAL_MAX_VALUES_EX &maxValuesEx)
{
CM_QUERY_CAPS queryCaps;
uint32_t querySize = sizeof( CM_QUERY_CAPS );
CmSafeMemSet( &queryCaps, 0, sizeof( CM_QUERY_CAPS ) );
queryCaps.type = CM_QUERY_MAX_VALUES;
int32_t hr = GetCapsInternal(&queryCaps, &querySize);
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Failed to get max values by GetCaps.");
return CM_FAILURE;
}
maxValues = queryCaps.maxValues;
maxValues.maxArgsPerKernel = (queryCaps.maxValues.maxArgsPerKernel > CM_MAX_ARGS_PER_KERNEL)?(CM_MAX_ARGS_PER_KERNEL):queryCaps.maxValues.maxArgsPerKernel;
CmSafeMemSet( &queryCaps, 0, sizeof( CM_QUERY_CAPS ) );
queryCaps.type = CM_QUERY_MAX_VALUES_EX;
hr = GetCapsInternal(&queryCaps, &querySize);
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Failed to get max values by GetCaps.");
return CM_FAILURE;
}
maxValuesEx = queryCaps.maxValuesEx;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Caps from Internal
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetCapsInternal(void *caps, uint32_t *size)
{
PCM_QUERY_CAPS queryCaps;
PCM_CONTEXT_DATA cmData;
PCM_HAL_STATE cmHalState;
CM_RETURN_CODE hr = CM_SUCCESS;
if ((!size) || (!caps) || (*size < sizeof(CM_QUERY_CAPS)))
{
CM_ASSERTMESSAGE("Error: Invalid arguments.");
hr = CM_FAILURE;
goto finish;
}
queryCaps = (PCM_QUERY_CAPS)caps;
*size = sizeof(CM_QUERY_CAPS);
if (queryCaps->type == CM_QUERY_VERSION)
{
queryCaps->version = CM_VERSION;
hr = CM_SUCCESS;
goto finish;
}
cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_CHK_NULL_GOTOFINISH_CMERROR(cmData);
cmHalState = cmData->cmHalState;
CM_CHK_NULL_GOTOFINISH_CMERROR(cmHalState);
switch (queryCaps->type)
{
case CM_QUERY_REG_HANDLE:
queryCaps->hRegistration = QueryRegHandleInternal(cmHalState);
break;
case CM_QUERY_MAX_VALUES:
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnGetMaxValues(cmHalState, &queryCaps->maxValues));
break;
case CM_QUERY_MAX_VALUES_EX:
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnGetMaxValuesEx(cmHalState, &queryCaps->maxValuesEx));
break;
case CM_QUERY_GPU:
case CM_QUERY_GT:
case CM_QUERY_MIN_RENDER_FREQ:
case CM_QUERY_MAX_RENDER_FREQ:
case CM_QUERY_STEP:
case CM_QUERY_GPU_FREQ:
hr = QueryGPUInfoInternal(queryCaps);
if (hr != CM_SUCCESS)
goto finish;
break;
case CM_QUERY_SURFACE2D_FORMAT_COUNT:
queryCaps->surface2DCount = CM_MAX_SURFACE2D_FORMAT_COUNT_INTERNAL;
break;
case CM_QUERY_SURFACE2D_FORMATS:
hr = QuerySurface2DFormatsInternal(queryCaps);
if (hr != CM_SUCCESS)
goto finish;
break;
case CM_QUERY_PLATFORM_INFO:
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnGetPlatformInfo(cmHalState, &queryCaps->platformInfo, false));
break;
default:
hr = CM_FAILURE;
goto finish;
}
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//! Get HW capability.
//! Input :
//! 1) Name of cap to query, only CAP_HW_THREAD_COUNT is supported now.
//! 2) size of memory where the cap value should return to.
//! User should make sure the size is larger than the size of cap value which is really returned.
//! 3) Pointer pointing to memory where the cap value should return to
//! Output:
//! 1) size of cap value which is really returned.
//! 2) CM_SUCCESS if cap value is successfully returned.
//! CM_FAILURE otherwise;
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetCaps(CM_DEVICE_CAP_NAME capName,
uint32_t & capValueSize,
void* capValue )
{
PCM_CONTEXT_DATA cmData;
PCM_HAL_STATE cmHalState;
CM_RETURN_CODE hr = CM_SUCCESS;
if (capValue == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to cap value is null.");
return CM_NULL_POINTER;
}
cmData = (PCM_CONTEXT_DATA)GetAccelData();
if(cmData == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to CM context data is null.");
return CM_NULL_POINTER;
}
cmHalState = cmData->cmHalState;
if(cmHalState == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to CM hal state is null.");
return CM_NULL_POINTER;
}
switch( capName )
{
case CAP_KERNEL_COUNT_PER_TASK:
if( capValueSize >= sizeof( m_halMaxValues.maxKernelsPerTask ) )
{
capValueSize = sizeof( m_halMaxValues.maxKernelsPerTask );
CmSafeMemCopy( capValue, &m_halMaxValues.maxKernelsPerTask, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_KERNEL_BINARY_SIZE:
if( capValueSize >= sizeof( m_halMaxValues.maxKernelBinarySize ) )
{
capValueSize = sizeof( m_halMaxValues.maxKernelBinarySize );
CmSafeMemCopy( capValue, &m_halMaxValues.maxKernelBinarySize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SAMPLER_COUNT:
if( capValueSize >= sizeof( m_halMaxValues.maxSamplerTableSize ) )
{
capValueSize = sizeof( m_halMaxValues.maxSamplerTableSize );
CmSafeMemCopy( capValue, &m_halMaxValues.maxSamplerTableSize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SAMPLER_COUNT_PER_KERNEL:
if( capValueSize >= sizeof( m_halMaxValues.maxSamplersPerKernel ) )
{
capValueSize = sizeof( m_halMaxValues.maxSamplersPerKernel );
CmSafeMemCopy( capValue, &m_halMaxValues.maxSamplersPerKernel, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_BUFFER_COUNT:
if( capValueSize >= sizeof( m_halMaxValues.maxBufferTableSize ) )
{
capValueSize = sizeof( m_halMaxValues.maxBufferTableSize );
CmSafeMemCopy( capValue, &m_halMaxValues.maxBufferTableSize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE2D_COUNT:
if( capValueSize >= sizeof( m_halMaxValues.max2DSurfaceTableSize ) )
{
capValueSize = sizeof( m_halMaxValues.max2DSurfaceTableSize );
CmSafeMemCopy( capValue, &m_halMaxValues.max2DSurfaceTableSize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE3D_COUNT:
if( capValueSize >= sizeof( m_halMaxValues.max3DSurfaceTableSize ) )
{
capValueSize = sizeof( m_halMaxValues.max3DSurfaceTableSize );
CmSafeMemCopy( capValue, &m_halMaxValues.max3DSurfaceTableSize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE2DUP_COUNT:
if( capValueSize >= sizeof( m_halMaxValuesEx.max2DUPSurfaceTableSize ) )
{
capValueSize = sizeof( m_halMaxValuesEx.max2DUPSurfaceTableSize );
CmSafeMemCopy( capValue, &m_halMaxValuesEx.max2DUPSurfaceTableSize, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE_COUNT_PER_KERNEL:
if( capValueSize >= sizeof( m_halMaxValues.maxSurfacesPerKernel ) )
{
capValueSize = sizeof( m_halMaxValues.maxSurfacesPerKernel );
CmSafeMemCopy( capValue, &m_halMaxValues.maxSurfacesPerKernel, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_ARG_COUNT_PER_KERNEL:
if( capValueSize >= sizeof( m_halMaxValues.maxArgsPerKernel ) )
{
capValueSize = sizeof( m_halMaxValues.maxArgsPerKernel );
CmSafeMemCopy( capValue, &m_halMaxValues.maxArgsPerKernel, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_ARG_SIZE_PER_KERNEL:
if( capValueSize >= sizeof( m_halMaxValues.maxArgByteSizePerKernel ) )
{
capValueSize = sizeof( m_halMaxValues.maxArgByteSizePerKernel );
CmSafeMemCopy( capValue, &m_halMaxValues.maxArgByteSizePerKernel, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_USER_DEFINED_THREAD_COUNT_PER_TASK:
if( capValueSize >= sizeof( m_halMaxValues.maxUserThreadsPerTask ) )
{
capValueSize = sizeof( m_halMaxValues.maxUserThreadsPerTask );
CmSafeMemCopy( capValue, &m_halMaxValues.maxUserThreadsPerTask, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_USER_DEFINED_THREAD_COUNT_PER_MEDIA_WALKER:
if( capValueSize >= sizeof( m_halMaxValuesEx.maxUserThreadsPerMediaWalker ) )
{
capValueSize = sizeof( m_halMaxValuesEx.maxUserThreadsPerMediaWalker );
CmSafeMemCopy( capValue, &m_halMaxValuesEx.maxUserThreadsPerMediaWalker, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_USER_DEFINED_THREAD_COUNT_PER_THREAD_GROUP:
if( capValueSize >= sizeof( m_halMaxValuesEx.maxUserThreadsPerThreadGroup ) )
{
capValueSize = sizeof( m_halMaxValuesEx.maxUserThreadsPerThreadGroup );
CmSafeMemCopy( capValue, &m_halMaxValuesEx.maxUserThreadsPerThreadGroup, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_USER_DEFINED_THREAD_COUNT_PER_TASK_NO_THREAD_ARG:
if( capValueSize >= sizeof( m_halMaxValues.maxUserThreadsPerTaskNoThreadArg ) )
{
capValueSize = sizeof( m_halMaxValues.maxUserThreadsPerTaskNoThreadArg );
CmSafeMemCopy( capValue, &m_halMaxValues.maxUserThreadsPerTaskNoThreadArg, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_HW_THREAD_COUNT:
if( capValueSize >= sizeof( m_halMaxValues.maxHwThreads ) )
{
capValueSize = sizeof( m_halMaxValues.maxHwThreads );
CmSafeMemCopy( capValue, &m_halMaxValues.maxHwThreads, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE2D_FORMAT_COUNT:
if( capValueSize >= sizeof( uint32_t ) )
{
capValueSize = sizeof( uint32_t );
uint32_t formatCount = CM_MAX_SURFACE2D_FORMAT_COUNT;
CmSafeMemCopy( capValue, &formatCount, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE2D_FORMATS:
return QuerySurface2DFormats(capValue, capValueSize);
case CAP_SURFACE3D_FORMAT_COUNT:
if( capValueSize >= sizeof( uint32_t ) )
{
capValueSize = sizeof( uint32_t );
uint32_t formatCount = CM_MAX_SURFACE3D_FORMAT_COUNT;
CmSafeMemCopy( capValue, &formatCount, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_SURFACE3D_FORMATS:
if( capValueSize >= CM_MAX_SURFACE3D_FORMAT_COUNT * sizeof(CM_SURFACE_FORMAT) )
{
capValueSize = CM_MAX_SURFACE3D_FORMAT_COUNT * sizeof(CM_SURFACE_FORMAT) ;
CM_SURFACE_FORMAT formats[ CM_MAX_SURFACE3D_FORMAT_COUNT ] =
{
CM_SURFACE_FORMAT_X8R8G8B8,
CM_SURFACE_FORMAT_A8R8G8B8,
CM_SURFACE_FORMAT_A16B16G16R16
};
CmSafeMemCopy( capValue, formats, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_GPU_PLATFORM:
if( capValueSize >= sizeof( uint32_t ) )
{
uint32_t platform = PLATFORM_INTEL_UNKNOWN;
capValueSize = sizeof( uint32_t );
cmHalState->cmHalInterface->GetGenPlatformInfo(&platform, nullptr, nullptr);
CmSafeMemCopy( capValue, &platform, capValueSize );
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
case CAP_GT_PLATFORM:
if( capValueSize >= sizeof( uint32_t ) )
{
CM_QUERY_CAPS queryCaps;
queryCaps.type = CM_QUERY_GT;
uint32_t queryCapsSize = sizeof( CM_QUERY_CAPS );
hr = (CM_RETURN_CODE)GetCapsInternal(&queryCaps, &queryCapsSize);
if ( hr != CM_SUCCESS)
{
return hr;
}
capValueSize = sizeof( uint32_t );
uint32_t gtPlatform = queryCaps.genGT;
CmSafeMemCopy( capValue, >Platform, capValueSize );
return hr;
}
else
{
return CM_FAILURE;
}
case CAP_MIN_FREQUENCY:
if( capValueSize >= sizeof( uint32_t ) )
{
CM_QUERY_CAPS queryCaps;
queryCaps.type = CM_QUERY_MIN_RENDER_FREQ;
uint32_t queryCapsSize = sizeof( CM_QUERY_CAPS );
hr = (CM_RETURN_CODE)GetCapsInternal(&queryCaps, &queryCapsSize);
if (hr != CM_SUCCESS)
{
return hr;
}
uint32_t frequency = queryCaps.minRenderFreq;
capValueSize = sizeof( uint32_t );
CmSafeMemCopy( capValue, &frequency, capValueSize );
return hr;
}
else
{
return CM_FAILURE;
}
case CAP_MAX_FREQUENCY:
if( capValueSize >= sizeof( uint32_t ) )
{
CM_QUERY_CAPS queryCaps;
queryCaps.type = CM_QUERY_MAX_RENDER_FREQ;
uint32_t queryCapsSize = sizeof( CM_QUERY_CAPS );
hr = (CM_RETURN_CODE)GetCapsInternal(&queryCaps, &queryCapsSize);
if (hr != CM_SUCCESS)
{
return hr;
}
uint32_t frequency = queryCaps.maxRenderFreq;
capValueSize = sizeof( uint32_t );
CmSafeMemCopy( capValue, &frequency, capValueSize );
return hr;
}
else
{
return CM_FAILURE;
}
case CAP_GPU_CURRENT_FREQUENCY:
if( (m_ddiVersion >= CM_DDI_3_0) && (capValueSize >= sizeof( uint32_t )) )
{
CM_QUERY_CAPS queryCaps;
queryCaps.type = CM_QUERY_GPU_FREQ;
uint32_t queryCapsSize = sizeof( CM_QUERY_CAPS );
hr = (CM_RETURN_CODE)GetCapsInternal(&queryCaps, &queryCapsSize);
if (hr != CM_SUCCESS)
{
return hr;
}
uint32_t frequency = queryCaps.gpuCurrentFreq;
capValueSize = sizeof( uint32_t );
CmSafeMemCopy( capValue, &frequency, capValueSize );
return hr;
}
else
{
return CM_FAILURE;
}
case CAP_PLATFORM_INFO:
if (capValueSize >= sizeof(CM_PLATFORM_INFO))
{
CM_QUERY_CAPS queryCaps;
queryCaps.type = CM_QUERY_PLATFORM_INFO;
uint32_t queryCapsSize = sizeof(CM_QUERY_CAPS);
hr = (CM_RETURN_CODE)GetCapsInternal(&queryCaps, &queryCapsSize);
if (hr != CM_SUCCESS)
{
return hr;
}
capValueSize = sizeof(CM_PLATFORM_INFO);
PCM_PLATFORM_INFO platformInfo = &(queryCaps.platformInfo);
CmSafeMemCopy(capValue, platformInfo, capValueSize);
return hr;
}
else
{
return CM_FAILURE;
}
case CAP_MAX_BUFFER_SIZE:
if (capValueSize >= sizeof(unsigned int))
{
capValueSize = sizeof(unsigned int);
unsigned int maxBufferSize = CM_MAX_1D_SURF_WIDTH;
CmSafeMemCopy(capValue, &maxBufferSize, capValueSize);
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
default:
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Load program from memory
//| Arguments :
//| commonISACode [in] pointer to memory where common isa locates
//| size [in] size of common isa
//| program [in/out] Pointer to CmProgram
//| options [in] options : non-jitter,jitter
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::LoadProgram(void* commonISACode,
const uint32_t size,
CmProgram*& program,
const char* options )
{
INSERT_API_CALL_LOG();
int32_t result;
if ((commonISACode == nullptr) || (size == 0))
{
CM_ASSERTMESSAGE("Error: Invalid common isa code.");
return CM_INVALID_COMMON_ISA;
}
CLock locker(m_criticalSectionProgramKernel);
uint32_t firstfreeslot = m_programArray.GetFirstFreeIndex();
CmProgramRT *programRT = static_cast<CmProgramRT *>(program);
result = CmProgramRT::Create( this, commonISACode, size, programRT, options, firstfreeslot );
if( result == CM_SUCCESS )
{
m_programArray.SetElement( firstfreeslot, programRT );
m_programCount ++;
}
program = programRT;
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Program
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroyProgram(CmProgram* & program)
{
INSERT_API_CALL_LOG();
if( program == nullptr )
{
return CM_FAILURE;
}
CLock locker(m_criticalSectionProgramKernel);
CmProgramRT *programRT = static_cast<CmProgramRT *>(program);
uint32_t indexInProgramArrary = programRT->GetProgramIndex();
if( programRT == m_programArray.GetElement( indexInProgramArrary ) )
{
CmProgramRT::Destroy( programRT );
if( programRT == nullptr )
{
m_programArray.SetElement( indexInProgramArrary, nullptr );
m_programCount--;
program = programRT;
}
return CM_SUCCESS;
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy CmProgram.");
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Kernel
//| Arguments :
//| kernel [out] pointer to CmKernel
//| kernelName [in] string of kernel's name
//| program [in/out] Pointer to CmProgram
//| options [in] options : non-jitter,jitter
//|
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateKernel(CmProgram* program,
const char* kernelName,
CmKernel* & kernel,
const char* options )
{
INSERT_API_CALL_LOG();
if(program == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to CmProgram is null.");
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionProgramKernel);
uint32_t freeSlotInKernelArray = m_kernelArray.GetFirstFreeIndex();
CmProgramRT *programRT = static_cast<CmProgramRT *>(program);
CmKernelRT *kernelRT = static_cast<CmKernelRT *>(kernel);
int32_t result = CmKernelRT::Create( this, programRT, kernelName, freeSlotInKernelArray, m_kernelCount, kernelRT, options );
kernel = kernelRT;
if( result == CM_SUCCESS )
{
m_kernelArray.SetElement( freeSlotInKernelArray, kernel );
m_kernelCount ++;
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Kernel
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroyKernel(CmKernel*& kernel)
{
INSERT_API_CALL_LOG();
if( kernel == nullptr )
{
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionProgramKernel);
CmKernelRT *kernelRT = static_cast<CmKernelRT *>(kernel);
uint32_t indexInKernelArrary = kernelRT->GetKernelIndex();
if( kernelRT == m_kernelArray.GetElement( indexInKernelArrary ) )
{
CmProgramRT* program = nullptr;
kernelRT->GetCmProgram(program);
if ( program == nullptr)
{
CM_ASSERTMESSAGE("Error: Failed to get valid program.");
return CM_NULL_POINTER;
}
uint32_t indexInProgramArray = program->GetProgramIndex();
if (program == m_programArray.GetElement( indexInProgramArray ))
{
CmKernelRT::Destroy( kernelRT, program );
kernel = kernelRT;
if(kernelRT == nullptr)
{
m_kernelArray.SetElement( indexInKernelArrary, nullptr );
}
if (program == nullptr)
{
m_programArray.SetElement(indexInProgramArray, nullptr);
}
// Note: NOT reduce m_kernelCount here, need to make it to loop mode later
return CM_SUCCESS;
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy kernel.");
return CM_FAILURE;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy kernel.");
return CM_FAILURE;
}
return CM_SUCCESS;
}
CM_RT_API int32_t CmDeviceRT::CreateQueue(CmQueue* & queue)
{
INSERT_API_CALL_LOG();
CmQueue *tmpQueue = nullptr;
// For legacy CreateQueue API, we will only return the same queue
m_criticalSectionQueue.Acquire();
for (auto iter = m_queue.begin(); iter != m_queue.end(); iter++)
{
CM_QUEUE_TYPE queueType = (*iter)->GetQueueOption().QueueType;
if (queueType == CM_QUEUE_TYPE_RENDER)
{
queue = (*iter);
m_criticalSectionQueue.Release();
return CM_SUCCESS;
}
}
m_criticalSectionQueue.Release();
CM_QUEUE_CREATE_OPTION queueCreateOption = {};
// Check queue type redirect is needed.
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_CHK_NULL_RETURN_CMERROR(cmData);
CM_CHK_NULL_RETURN_CMERROR(cmData->cmHalState);
CM_CHK_NULL_RETURN_CMERROR(cmData->cmHalState->cmHalInterface);
if (cmData->cmHalState->cmHalInterface->IsRedirectRcsToCcs())
{
queueCreateOption.QueueType = CM_QUEUE_TYPE_COMPUTE;
}
else
{
queueCreateOption.QueueType = CM_QUEUE_TYPE_RENDER;
}
#if (_DEBUG || _RELEASE_INTERNAL)
// Check queue type override for debugging is needed.
MOS_USER_FEATURE_VALUE_DATA UserFeatureData = {0};
if( MOS_UserFeature_ReadValue_ID( nullptr,
__MEDIA_USER_FEATURE_VALUE_MDF_DEFAULT_CM_QUEUE_TYPE_ID,
&UserFeatureData) == MOS_STATUS_SUCCESS )
{
if (UserFeatureData.u32Data == CM_QUEUE_TYPE_RENDER
|| UserFeatureData.u32Data == CM_QUEUE_TYPE_COMPUTE)
{
queueCreateOption.QueueType = (CM_QUEUE_TYPE)UserFeatureData.u32Data;
}
}
#endif
int32_t result = CreateQueueEx(tmpQueue, queueCreateOption);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Failed to create the queue.");
return result;
}
queue = tmpQueue;
return CM_SUCCESS;
}
CM_RT_API int32_t
CmDeviceRT::CreateQueueEx(CmQueue* & queue,
CM_QUEUE_CREATE_OPTION queueCreateOption)
{
INSERT_API_CALL_LOG();
m_criticalSectionQueue.Acquire();
CmQueueRT *queueRT = nullptr;
int32_t result = CmQueueRT::Create(this, queueRT, queueCreateOption);
if (result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Failed to create the queue.");
m_criticalSectionQueue.Release();
return result;
}
m_queue.push_back(queueRT);
queue = queueRT;
m_criticalSectionQueue.Release();
return result;
}
CM_RT_API int32_t CmDeviceRT::CreateTask(CmTask *& task)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionTask);
uint32_t freeSlotInTaskArray = m_taskArray.GetFirstFreeIndex();
CmTaskRT *taskRT = nullptr;
int32_t result = CmTaskRT::Create(this, freeSlotInTaskArray, m_halMaxValues.maxKernelsPerTask, taskRT);
if (result == CM_SUCCESS)
{
m_taskArray.SetElement( freeSlotInTaskArray, taskRT );
m_taskCount ++;
}
task = taskRT;
return result;
}
int32_t CmDeviceRT::DestroyQueue(CmQueueRT* & queue)
{
if(queue == nullptr )
{
return CM_NULL_POINTER;
}
return CmQueueRT::Destroy(queue);
}
CM_RT_API int32_t CmDeviceRT::DestroyTask(CmTask*& task)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionTask);
if( task == nullptr )
{
return CM_FAILURE;
}
CmTaskRT *taskRT = static_cast<CmTaskRT *>(task);
uint32_t index = taskRT->GetIndexInTaskArray();
if(taskRT == (CmTaskRT *)m_taskArray.GetElement( index ))
{
int32_t status = CmTaskRT::Destroy(taskRT);
if(status == CM_SUCCESS)
{
m_taskArray.SetElement( index, nullptr );
task = nullptr;
return CM_SUCCESS;
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy task.");
return status;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy task.");
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//! Create a 2-dimensional dependency board. Each board is corrsponding to a task.
//! Each board unit is notated as a pair of X/Y coordinates, which is in the range of [0, width -1] or [0. heigh-1]
//! Each board uint is correspinding to a thread in the task.
//! Input :
//! 1) width and height of the dependency board
//! OUTPUT :
//! CM_SUCCESS if CmThreadSpace is successfully created.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateThreadSpace(uint32_t width,
uint32_t height,
CmThreadSpace* & threadSpace)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionThreadSpace);
uint32_t freeSlotInThreadSpaceArray = m_threadSpaceArray.GetFirstFreeIndex();
CmThreadSpaceRT *threadSpaceRT = nullptr;
int32_t result = CmThreadSpaceRT::Create( this, freeSlotInThreadSpaceArray, width, height, threadSpaceRT );
if (result == CM_SUCCESS)
{
m_threadSpaceArray.SetElement( freeSlotInThreadSpaceArray, threadSpaceRT );
m_threadSpaceCount ++;
}
threadSpace = threadSpaceRT;
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Thread Space
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroyThreadSpace(CmThreadSpace* & threadSpace)
{
INSERT_API_CALL_LOG();
if( threadSpace == nullptr )
{
return CM_FAILURE;
}
CmThreadSpaceRT *threadSpaceRT = static_cast<CmThreadSpaceRT *>(threadSpace);
uint32_t indexTs = threadSpaceRT->GetIndexInTsArray();
CLock locker(m_criticalSectionThreadSpace);
if(threadSpace == m_threadSpaceArray.GetElement( indexTs ))
{
int32_t status = CmThreadSpaceRT::Destroy( threadSpaceRT );
if(status == CM_SUCCESS)
{
m_threadSpaceArray.SetElement( indexTs, nullptr );
threadSpace = nullptr;
return CM_SUCCESS;
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy thread space.");
return status;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy thread space.");
return CM_FAILURE;
}
}
CM_RT_API int32_t
CmDeviceRT::CreateVmeSurfaceG7_5(CmSurface2D* curSurface,
CmSurface2D** forwardSurfaces,
CmSurface2D** backwardSurfaces,
const uint32_t forwardSurfaceCount,
const uint32_t backwardSurfaceCount,
SurfaceIndex* & vmeIndex)
{
INSERT_API_CALL_LOG();
if(curSurface == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to current surface is null.");
return CM_NULL_POINTER;
}
CmSurface2DRT* currentRT = static_cast<CmSurface2DRT *>(curSurface) ;
CmSurface2DRT** forward = nullptr;
CmSurface2DRT** backward = nullptr;
if( ! currentRT )
{
CM_ASSERTMESSAGE("Error: Pointer to current surface is null.");
return CM_INVALID_ARG_VALUE;
}
if(forwardSurfaces != nullptr)
{
forward = MOS_NewArray( CmSurface2DRT*, forwardSurfaceCount);
if(forward == nullptr)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_OUT_OF_HOST_MEMORY;
}
for(uint32_t i = 0; i< forwardSurfaceCount; i++)
{
forward[i] = static_cast<CmSurface2DRT *>( forwardSurfaces[i] );
if(forward[i] == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid forward surfaces.");
MosSafeDeleteArray(forward);
return CM_INVALID_ARG_VALUE;
}
}
}
if(backwardSurfaces != nullptr)
{
backward = MOS_NewArray(CmSurface2DRT*,backwardSurfaceCount);
if(backward == nullptr)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
MosSafeDeleteArray(forward);
return CM_OUT_OF_HOST_MEMORY;
}
for(uint32_t i = 0; i< backwardSurfaceCount; i++)
{
backward[i] = static_cast<CmSurface2DRT *>( backwardSurfaces[i] );
if(backward[i] == nullptr)
{
CM_ASSERTMESSAGE("Error: Invalid backward surfaces.");
MosSafeDeleteArray(forward);
MosSafeDeleteArray(backward);
return CM_INVALID_ARG_VALUE;
}
}
}
CLock locker(m_criticalSectionSurface);
int32_t status = m_surfaceMgr->CreateVmeSurface(currentRT, forward, backward, forwardSurfaceCount, backwardSurfaceCount, vmeIndex);
MosSafeDeleteArray(forward);
MosSafeDeleteArray(backward);
return status;
}
CM_RT_API int32_t CmDeviceRT::DestroyVmeSurfaceG7_5(SurfaceIndex* & vmeIndex)
{
INSERT_API_CALL_LOG();
return DestroyVmeSurface( vmeIndex );
}
CM_RT_API int32_t CmDeviceRT::SetVmeSurfaceStateParam(SurfaceIndex* vmeIndex, CM_VME_SURFACE_STATE_PARAM *surfStateParam)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
CM_RETURN_CODE hr = CM_SUCCESS;
CmSurface *cmSurface = nullptr;
CmSurfaceVme *vmeSurface = nullptr;
CM_CHK_NULL_GOTOFINISH_CMERROR(vmeIndex);
CM_CHK_NULL_GOTOFINISH_CMERROR(surfStateParam);
m_surfaceMgr->GetSurface(vmeIndex->get_data(), cmSurface);
CM_CHK_NULL_GOTOFINISH_CMERROR(cmSurface);
// check if it is a vme index
if (cmSurface->Type() != CM_ENUM_CLASS_TYPE_CMSURFACEVME)
{
CM_ASSERTMESSAGE("Error: SetVmeSurfaceStateParam only can config VME surfaces.");
return CM_INVALID_ARG_INDEX;
}
vmeSurface = static_cast<CmSurfaceVme *>(cmSurface);
vmeSurface->SetSurfaceStateResolution(surfStateParam->width, surfStateParam->height);
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//! Create a CmSampler.
//! Input :
//! 1) Const Reference to the sampler state data structure.
//! 2) Reference to the pointer to the CmSampler .
//! Output:
//! CM_SUCCESS if the CmSampler is successfully created;
//! CM_OUT_OF_HOST_MEMORY if out of system memory;
//! CM_FAILURE otherwise;
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSampler(const CM_SAMPLER_STATE& samplerState,
CmSampler* & sampler)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSampler);
uint32_t index = 0;
int32_t hr= RegisterSamplerState( samplerState, index );
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Register sampler state failure.");
return CM_EXCEED_SAMPLER_AMOUNT;
}
CmSamplerRT* ptmp = nullptr;
int32_t result = CmSamplerRT::Create( index, ptmp );
if( result == CM_SUCCESS )
{
m_samplerArray.SetElement( index, ptmp );
sampler = static_cast< CmSampler* >(ptmp);
}
else
{
UnregisterSamplerState( index );
}
return result;
}
CM_RT_API int32_t
CmDeviceRT::CreateSamplerEx(const CM_SAMPLER_STATE_EX& samplerState,
CmSampler* & sampler)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSampler);
uint32_t index = 0;
int32_t hr= RegisterSamplerStateEx( samplerState, index );
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Register sampler state failure.");
return CM_EXCEED_SAMPLER_AMOUNT;
}
CmSamplerRT* ptmp = nullptr;
int32_t result = CmSamplerRT::Create( index, ptmp );
if( result == CM_SUCCESS )
{
m_samplerArray.SetElement( index, ptmp );
sampler = static_cast< CmSampler* >(ptmp);
}
else
{
UnregisterSamplerState( index );
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Sampler
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroySampler(CmSampler*& sampler)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSampler);
CmSamplerRT* temp = nullptr;
if(sampler != nullptr)
{
temp = static_cast< CmSamplerRT* >(sampler);
}
else
{
return CM_FAILURE;
}
SamplerIndex* index = nullptr;
temp->GetIndex( index );
CM_ASSERT( index );
uint32_t indexValue = index->get_data();
CM_ASSERT( m_samplerArray.GetElement( indexValue ) == (temp) );
int32_t status = CmSamplerRT::Destroy( temp );
if(status == CM_SUCCESS)
{
UnregisterSamplerState( indexValue );
m_samplerArray.SetElement( indexValue, nullptr );
sampler = nullptr;
}
return status;
}
//*-----------------------------------------------------------------------------
//| Purpose: Register Sampler State in CM devie's table
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::RegisterSamplerState(const CM_SAMPLER_STATE& samplerState,
uint32_t& index)
{
CM_RETURN_CODE hr = CM_SUCCESS;
index = 0;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_HAL_SAMPLER_PARAM param;
MOS_ZeroMemory(¶m, sizeof(CM_HAL_SAMPLER_PARAM));
param.addressU = samplerState.addressU;
param.addressV = samplerState.addressV;
param.addressW = samplerState.addressW;
param.magFilter = samplerState.magFilterType;
param.minFilter = samplerState.minFilterType;
param.handle = 0;
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnRegisterSampler(cmData->cmHalState, ¶m));
index = param.handle;
finish:
return hr;
}
int32_t
CmDeviceRT::RegisterSamplerStateEx(const CM_SAMPLER_STATE_EX& samplerState,
uint32_t& index)
{
CM_RETURN_CODE hr = CM_SUCCESS;
index = 0;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_HAL_SAMPLER_PARAM param;
MOS_ZeroMemory(¶m, sizeof(CM_HAL_SAMPLER_PARAM));
param.addressU = samplerState.addressU;
param.addressV = samplerState.addressV;
param.addressW = samplerState.addressW;
param.magFilter = samplerState.magFilterType;
param.minFilter = samplerState.minFilterType;
param.handle = 0;
param.surfaceFormat = (CM_HAL_PIXEL_TYPE)samplerState.SurfaceFormat;
switch (param.surfaceFormat)
{
case CM_HAL_PIXEL_UINT:
param.borderColorRedU = samplerState.BorderColorRedU;
param.borderColorGreenU = samplerState.BorderColorGreenU;
param.borderColorBlueU = samplerState.BorderColorBlueU;
param.borderColorAlphaU = samplerState.BorderColorAlphaU;
break;
case CM_HAL_PIXEL_SINT:
param.borderColorRedS = samplerState.BorderColorRedS;
param.borderColorGreenS = samplerState.BorderColorGreenS;
param.borderColorBlueS = samplerState.BorderColorBlueS;
param.borderColorAlphaS = samplerState.BorderColorAlphaS;
break;
default:
param.borderColorRedF = samplerState.BorderColorRedF;
param.borderColorGreenF = samplerState.BorderColorGreenF;
param.borderColorBlueF = samplerState.BorderColorBlueF;
param.borderColorAlphaF = samplerState.BorderColorAlphaF;
}
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnRegisterSampler(cmData->cmHalState, ¶m));
index = param.handle;
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Unregister Sampler State in CM devie's table
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::UnregisterSamplerState(uint32_t index)
{
CM_RETURN_CODE hr = CM_SUCCESS;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnUnRegisterSampler(cmData->cmHalState, index));
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler8x8 State
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSampler8x8(const CM_SAMPLER_8X8_DESCR & sampler8x8Descriptor,
CmSampler8x8*& sampler8x8)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSampler8x8);
int32_t result = CM_FAILURE;
if((sampler8x8Descriptor.stateType == CM_SAMPLER8X8_AVS && sampler8x8Descriptor.avs == nullptr) ||
(sampler8x8Descriptor.stateType == CM_SAMPLER8X8_CONV && sampler8x8Descriptor.conv == nullptr) ||
(sampler8x8Descriptor.stateType == CM_SAMPLER8X8_MISC && sampler8x8Descriptor.misc == nullptr) ||
(sampler8x8Descriptor.stateType == CM_SAMPLER8X8_NONE && sampler8x8Descriptor.conv != nullptr) ||
sampler8x8 != nullptr) {
CM_ASSERTMESSAGE("Error: Invalid arguments.");
return CM_INVALID_ARG_VALUE;
}
CmSampler8x8State_RT* ptmp = nullptr;
uint32_t index = 0;
int32_t hr = RegisterSampler8x8State( sampler8x8Descriptor, index );
if( FAILED(hr) )
{
CM_ASSERTMESSAGE("Error: Register sampler8x8 state failure.");
return CM_EXCEED_SAMPLER_AMOUNT;
}
result = CmSampler8x8State_RT::Create( sampler8x8Descriptor, index, ptmp );
if( result == CM_SUCCESS )
{
m_sampler8x8Array.SetElement( index, ptmp );
sampler8x8 = static_cast< CmSampler8x8* >(ptmp);
}
else
{
UnregisterSampler8x8State( index );
}
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Sampler8x8 State
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroySampler8x8(CmSampler8x8*& sampler8x8)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSampler8x8);
CmSampler8x8State_RT* temp = nullptr;
if(sampler8x8)
{
temp = static_cast< CmSampler8x8State_RT* >(sampler8x8);
}
else
{
return CM_FAILURE;
}
SamplerIndex* index = nullptr;
temp->GetIndex( index );
CM_ASSERT( index );
uint32_t indexValue = index->get_data();
CM_ASSERT( m_sampler8x8Array.GetElement( indexValue ) == (temp) );
int32_t status = CmSampler8x8State_RT::Destroy( temp );
if(status == CM_SUCCESS)
{
UnregisterSampler8x8State( indexValue );
m_sampler8x8Array.SetElement( indexValue, nullptr );
sampler8x8 = nullptr;
}
return status;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler8x8 Surface
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSampler8x8Surface(CmSurface2D* surface2D,
SurfaceIndex* & sampler8x8SurfIndex,
CM_SAMPLER8x8_SURFACE sampler8x8Type,
CM_SURFACE_ADDRESS_CONTROL_MODE mode)
{
INSERT_API_CALL_LOG();
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizeperpixel = 0;
CmSurface2DRT* currentRT = static_cast<CmSurface2DRT *>(surface2D);
if( ! currentRT ) {
CM_ASSERTMESSAGE("Error: Pointer to current surface is null.");
return CM_NULL_POINTER;
}
CM_SURFACE_FORMAT format;
currentRT->GetSurfaceDesc(width, height, format, sizeperpixel);
if(format == CM_SURFACE_FORMAT_NV12)
if ((width % 4) != 0 || (height % 4) != 0) { //width or height is not 4 aligned
CM_ASSERTMESSAGE("Error: Width or height is not 4 aligned for nv12 surface.");
return CM_SYSTEM_MEMORY_NOT_4PIXELS_ALIGNED;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSampler8x8Surface( currentRT, sampler8x8SurfIndex, sampler8x8Type, mode, nullptr );
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler8x8 Surface
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSampler8x8SurfaceEx(CmSurface2D* surface2d,
SurfaceIndex* & sampler8x8SurfIndex,
CM_SAMPLER8x8_SURFACE sampler8x8Type,
CM_SURFACE_ADDRESS_CONTROL_MODE mode,
CM_FLAG* flag)
{
INSERT_API_CALL_LOG();
CmSurface2DRT* currentRT = static_cast<CmSurface2DRT *>(surface2d);
if (!currentRT) {
CM_ASSERTMESSAGE("Error: Pointer to current surface is null.");
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSampler8x8Surface(currentRT, sampler8x8SurfIndex, sampler8x8Type, mode, flag);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler Surface 2D with Flag
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSamplerSurface2DEx(CmSurface2D* surface2d,
SurfaceIndex* & samplerSurfaceIndex,
CM_FLAG* flag)
{
INSERT_API_CALL_LOG();
if (!surface2d) {
CM_ASSERTMESSAGE("Error: Pointer to sampler surface 2D is null.");
return CM_NULL_POINTER;
}
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizeperpixel = 0;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
CmSurface2DRT* surface2dRT = static_cast<CmSurface2DRT *>(surface2d);
surface2dRT->GetSurfaceDesc(width, height, format, sizeperpixel);
if (!m_surfaceMgr->IsSupportedForSamplerSurface2D(format))
{
return CM_SURFACE_FORMAT_NOT_SUPPORTED;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSamplerSurface(surface2dRT, samplerSurfaceIndex, flag);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Sampler8x8 Surface
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::DestroySampler8x8Surface(SurfaceIndex* & surfaceIndex)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->DestroySampler8x8Surface( surfaceIndex );
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Coefficient Format Transform
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
#define FloatToS1_6(x) (uint8_t)((char)(x * 64))
void
CmDeviceRT::Sampler8x8CoefficientFormatTransform(
CM_AVS_INTERNEL_NONPIPLINED_STATE* dstAvsState,
CM_AVS_NONPIPLINED_STATE* srcAvsState)
{
int i;
CmSafeMemSet( dstAvsState, 0, sizeof(CM_AVS_INTERNEL_NONPIPLINED_STATE));
dstAvsState->BypassXAF = srcAvsState->BypassXAF;
dstAvsState->BypassYAF = srcAvsState->BypassYAF;
dstAvsState->DefaultSharpLvl = srcAvsState->DefaultSharpLvl;
dstAvsState->bEnableRGBAdaptive = srcAvsState->bEnableRGBAdaptive;
dstAvsState->bAdaptiveFilterAllChannels = srcAvsState->bAdaptiveFilterAllChannels;
if (!srcAvsState->BypassXAF && !srcAvsState->BypassYAF) {
dstAvsState->maxDerivative4Pixels = srcAvsState->maxDerivative4Pixels;
dstAvsState->maxDerivative8Pixels = srcAvsState->maxDerivative8Pixels;
dstAvsState->transitionArea4Pixels = srcAvsState->transitionArea4Pixels;
dstAvsState->transitionArea8Pixels = srcAvsState->transitionArea8Pixels;
}
for (i = 0; i < CM_NUM_COEFF_ROWS_SKL; i++) {
dstAvsState->Tbl0X[i].FilterCoeff_0_0 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_0);
dstAvsState->Tbl0X[i].FilterCoeff_0_1 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_1);
dstAvsState->Tbl0X[i].FilterCoeff_0_2 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_2);
dstAvsState->Tbl0X[i].FilterCoeff_0_3 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_3);
dstAvsState->Tbl0X[i].FilterCoeff_0_4 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_4);
dstAvsState->Tbl0X[i].FilterCoeff_0_5 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_5);
dstAvsState->Tbl0X[i].FilterCoeff_0_6 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_6);
dstAvsState->Tbl0X[i].FilterCoeff_0_7 = FloatToS1_6(srcAvsState->Tbl0X[i].FilterCoeff_0_7);
dstAvsState->Tbl0Y[i].FilterCoeff_0_0 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_0);
dstAvsState->Tbl0Y[i].FilterCoeff_0_1 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_1);
dstAvsState->Tbl0Y[i].FilterCoeff_0_2 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_2);
dstAvsState->Tbl0Y[i].FilterCoeff_0_3 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_3);
dstAvsState->Tbl0Y[i].FilterCoeff_0_4 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_4);
dstAvsState->Tbl0Y[i].FilterCoeff_0_5 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_5);
dstAvsState->Tbl0Y[i].FilterCoeff_0_6 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_6);
dstAvsState->Tbl0Y[i].FilterCoeff_0_7 = FloatToS1_6(srcAvsState->Tbl0Y[i].FilterCoeff_0_7);
dstAvsState->Tbl1X[i].FilterCoeff_0_0 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_0);
dstAvsState->Tbl1X[i].FilterCoeff_0_1 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_1);
dstAvsState->Tbl1X[i].FilterCoeff_0_2 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_2);
dstAvsState->Tbl1X[i].FilterCoeff_0_3 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_3);
dstAvsState->Tbl1X[i].FilterCoeff_0_4 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_4);
dstAvsState->Tbl1X[i].FilterCoeff_0_5 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_5);
dstAvsState->Tbl1X[i].FilterCoeff_0_6 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_6);
dstAvsState->Tbl1X[i].FilterCoeff_0_7 = FloatToS1_6(srcAvsState->Tbl1X[i].FilterCoeff_0_7);
dstAvsState->Tbl1Y[i].FilterCoeff_0_0 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_0);
dstAvsState->Tbl1Y[i].FilterCoeff_0_1 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_1);
dstAvsState->Tbl1Y[i].FilterCoeff_0_2 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_2);
dstAvsState->Tbl1Y[i].FilterCoeff_0_3 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_3);
dstAvsState->Tbl1Y[i].FilterCoeff_0_4 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_4);
dstAvsState->Tbl1Y[i].FilterCoeff_0_5 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_5);
dstAvsState->Tbl1Y[i].FilterCoeff_0_6 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_6);
dstAvsState->Tbl1Y[i].FilterCoeff_0_7 = FloatToS1_6(srcAvsState->Tbl1Y[i].FilterCoeff_0_7);
}
return;
}
//*-----------------------------------------------------------------------------
//| Purpose: Register Sampler8x8 State (Not implemented yet)
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::RegisterSampler8x8State(
const CM_SAMPLER_8X8_DESCR & sampler8x8State,
uint32_t& index)
{
CM_RETURN_CODE hr = CM_SUCCESS;
void *dst = nullptr;
void *src = nullptr;
CM_HAL_SAMPLER_8X8_PARAM param;
CM_AVS_STATE_MSG *cmAvs;
PMHW_SAMPLER_STATE_AVS_PARAM mhwAvs;
CmSafeMemSet(¶m, 0, sizeof(CM_HAL_SAMPLER_8X8_PARAM));
index = 0;
param.handle = 0;
param.sampler8x8State.stateType = sampler8x8State.stateType;
//Initialize the input parameters.
switch(sampler8x8State.stateType)
{
case CM_SAMPLER8X8_AVS:
mhwAvs = &(param.sampler8x8State.avsParam.avsState);
cmAvs = sampler8x8State.avs;
mhwAvs->stateID = (int16_t)-1;
mhwAvs->bEnableAVS = true;
mhwAvs->AvsType = cmAvs->AVSTYPE;
mhwAvs->EightTapAFEnable = cmAvs->EightTapAFEnable;
mhwAvs->BypassIEF = cmAvs->BypassIEF;
mhwAvs->GainFactor = cmAvs->GainFactor;
mhwAvs->GlobalNoiseEstm = cmAvs->GlobalNoiseEstm;
mhwAvs->StrongEdgeThr = cmAvs->StrongEdgeThr;
mhwAvs->WeakEdgeThr = cmAvs->WeakEdgeThr;
mhwAvs->StrongEdgeWght = cmAvs->StrongEdgeWght;
mhwAvs->RegularWght = cmAvs->RegularWght;
mhwAvs->NonEdgeWght = cmAvs->NonEdgeWght;
mhwAvs->bEnableSTDE = 0;
mhwAvs->b8TapAdaptiveEnable = 0;
mhwAvs->bSkinDetailFactor = 0;
// current vphal/mhw use HDCDW flag to control shuffleoutputwriteback, we follow them
mhwAvs->bHdcDwEnable = ( cmAvs->HDCDirectWriteEnable || ( !cmAvs->ShuffleOutputWriteback ) );
mhwAvs->bWritebackStandard = !cmAvs->ShuffleOutputWriteback;
mhwAvs->bEnableIEF = 0;
mhwAvs->wIEFFactor = 0;
mhwAvs->wR3xCoefficient = cmAvs->wR3xCoefficient;
mhwAvs->wR3cCoefficient = cmAvs->wR3cCoefficient;
mhwAvs->wR5xCoefficient = cmAvs->wR5xCoefficient;
mhwAvs->wR5cxCoefficient = cmAvs->wR5cxCoefficient;
mhwAvs->wR5cCoefficient = cmAvs->wR5cCoefficient;
Sampler8x8CoefficientFormatTransform((PCM_AVS_INTERNEL_NONPIPLINED_STATE )&(param.sampler8x8State.avsParam.avsTable), sampler8x8State.avs->AvsState);
break;
case CM_SAMPLER8X8_CONV:
dst = (void *)&(param.sampler8x8State.convolveState);
src = (void *)sampler8x8State.conv;
CmSafeMemCopy( dst, src, sizeof( CM_CONVOLVE_STATE_MSG));
break;
case CM_SAMPLER8X8_MISC:
param.sampler8x8State.miscState.DW0.Height = sampler8x8State.misc->DW0.Height;
param.sampler8x8State.miscState.DW0.Width = sampler8x8State.misc->DW0.Width;
param.sampler8x8State.miscState.DW0.Row0 = sampler8x8State.misc->DW0.Row0;
param.sampler8x8State.miscState.DW1.Row1 = sampler8x8State.misc->DW1.Row1;
param.sampler8x8State.miscState.DW1.Row2 = sampler8x8State.misc->DW1.Row2;
param.sampler8x8State.miscState.DW2.Row3 = sampler8x8State.misc->DW2.Row3;
param.sampler8x8State.miscState.DW2.Row4 = sampler8x8State.misc->DW2.Row4;
param.sampler8x8State.miscState.DW3.Row5 = sampler8x8State.misc->DW3.Row5;
param.sampler8x8State.miscState.DW3.Row6 = sampler8x8State.misc->DW3.Row6;
param.sampler8x8State.miscState.DW4.Row7 = sampler8x8State.misc->DW4.Row7;
param.sampler8x8State.miscState.DW4.Row8 = sampler8x8State.misc->DW4.Row8;
param.sampler8x8State.miscState.DW5.Row9 = sampler8x8State.misc->DW5.Row9;
param.sampler8x8State.miscState.DW5.Row10 = sampler8x8State.misc->DW5.Row10;
param.sampler8x8State.miscState.DW6.Row11 = sampler8x8State.misc->DW6.Row11;
param.sampler8x8State.miscState.DW6.Row12 = sampler8x8State.misc->DW6.Row12;
param.sampler8x8State.miscState.DW7.Row13 = sampler8x8State.misc->DW7.Row13;
param.sampler8x8State.miscState.DW7.Row14 = sampler8x8State.misc->DW7.Row14;
break;
default:
CM_ASSERTMESSAGE("Error: Invalid sampler8x8 state descr.");
return hr;
}
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnRegisterSampler8x8(cmData->cmHalState, ¶m));
index = param.handle >> 16;
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: UnRegister Sampler8x8 State (Not implemented yet)
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::UnregisterSampler8x8State(uint32_t index)
{
CM_RETURN_CODE hr = CM_SUCCESS;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnUnRegisterSampler8x8(cmData->cmHalState, index));
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//! Function to create a thread group space
//! Arguments:
//! 1. Width/height (in unit of thread ) of each thread group
//! 2. Width/height(in unit of group) of thread group space.
//! 3. Reference to the point to CmThreadGroupSpace object to created.
//! Return Value:
//! CM_SUCCESS if the CmThreadGroupSpace is successfully created
//! Notes:
//! The total thread count is width*height*grpWidth*grpHeight.
//! The thread count will check against the thread count set by CmKernel::SetThreadCount if CmKernel::SetThreadCount is called.
//! CmKernel::SetThreadCount needs to be called if CmKernel::SetThreadArg is to be called.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateThreadGroupSpaceEx(uint32_t thrdSpaceWidth,
uint32_t thrdSpaceHeight,
uint32_t thrdSpaceDepth,
uint32_t grpSpaceWidth,
uint32_t grpSpaceHeight,
uint32_t grpSpaceDepth,
CmThreadGroupSpace*& threadGroupSpace)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionThreadGroupSpace);
uint32_t firstfreeslot = m_threadGroupSpaceArray.GetFirstFreeIndex();
int32_t result = CmThreadGroupSpace::Create(this, firstfreeslot, thrdSpaceWidth, thrdSpaceHeight, thrdSpaceDepth, grpSpaceWidth, grpSpaceHeight, grpSpaceDepth, threadGroupSpace);
if (result == CM_SUCCESS)
{
m_threadGroupSpaceArray.SetElement( firstfreeslot, threadGroupSpace );
m_threadGroupSpaceCount ++;
}
return result;
}
CM_RT_API int32_t
CmDeviceRT::CreateThreadGroupSpace(uint32_t thrdSpaceWidth,
uint32_t thrdSpaceHeight,
uint32_t grpSpaceWidth,
uint32_t grpSpaceHeight,
CmThreadGroupSpace*& threadGroupSpace)
{
INSERT_API_CALL_LOG();
int32_t result = CreateThreadGroupSpaceEx(thrdSpaceWidth,
thrdSpaceHeight,
1,
grpSpaceWidth,
grpSpaceHeight,
1,
threadGroupSpace);
return result;
}
CM_RT_API int32_t
CmDeviceRT::DestroyThreadGroupSpace(CmThreadGroupSpace*& threadGroupSpace)
{
INSERT_API_CALL_LOG();
if( threadGroupSpace == nullptr )
{
return CM_FAILURE;
}
uint32_t indexTGs = threadGroupSpace->GetIndexInTGsArray();
CLock locker(m_criticalSectionThreadGroupSpace);
if(threadGroupSpace == static_cast< CmThreadGroupSpace* >(m_threadGroupSpaceArray.GetElement( indexTGs )))
{
int32_t status = CmThreadGroupSpace::Destroy( threadGroupSpace );
if(status == CM_SUCCESS)
{
m_threadGroupSpaceArray.SetElement( indexTGs, nullptr );
threadGroupSpace = nullptr;
return CM_SUCCESS;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy thread group space.");
return CM_FAILURE;
}
return CM_FAILURE;
}
//*-----------------------------------------------------------------------------
//| Purpose: Load Predefined Program, it is used by GPUCopy API
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::LoadPredefinedCopyKernel(CmProgram*& program)
{
PCM_HAL_STATE cmHalState;
int32_t hr = CM_SUCCESS;
cmHalState = ((PCM_CONTEXT_DATA)GetAccelData())->cmHalState;
if(m_gpuCopyKernelProgram)
{
program = m_gpuCopyKernelProgram;
return CM_SUCCESS;
}
void * gpucopyKernelIsa;
uint32_t gpucopyKernelIsaSize;
cmHalState->cmHalInterface->GetCopyKernelIsa(gpucopyKernelIsa, gpucopyKernelIsaSize);
if (gpucopyKernelIsa == nullptr || gpucopyKernelIsaSize == 0)
{
return CM_NOT_IMPLEMENTED;
}
hr = LoadProgram((void *)gpucopyKernelIsa, gpucopyKernelIsaSize, program, "PredefinedGPUKernel");
if (hr != CM_SUCCESS)
{
return hr;
}
m_gpuCopyKernelProgram = program;
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Load Predefined Program, it is used by GPUCopy API
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::LoadPredefinedInitKernel(CmProgram*& program)
{
PCM_HAL_STATE cmHalState;
int32_t hr = CM_SUCCESS;
cmHalState = ((PCM_CONTEXT_DATA)GetAccelData())->cmHalState;
if(m_surfInitKernelProgram)
{
program = m_surfInitKernelProgram;
return CM_SUCCESS;
}
void * gpuinitKernelIsa;
uint32_t gpuinitKernelIsaSize;
cmHalState->cmHalInterface->GetInitKernelIsa(gpuinitKernelIsa, gpuinitKernelIsaSize);
if (gpuinitKernelIsa == nullptr || gpuinitKernelIsaSize == 0)
{
return CM_NOT_IMPLEMENTED;
}
hr = LoadProgram((void *)gpuinitKernelIsa, gpuinitKernelIsaSize, program, "PredefinedGPUKernel");
if (hr != CM_SUCCESS)
{
return hr;
}
m_surfInitKernelProgram = program;
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Return HW stepping infor, Not implemented yet.
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetGenStepInfo(char*& stepinfostr)
{
PCM_HAL_STATE cmHalState;
int32_t hr = CM_SUCCESS;
cmHalState = ((PCM_CONTEXT_DATA)GetAccelData())->cmHalState;
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->cmHalInterface->GetGenStepInfo(stepinfostr));
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler Surface 2D
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSamplerSurface2D(CmSurface2D* Surface2d,
SurfaceIndex* & samplerSurfaceIndex)
{
INSERT_API_CALL_LOG();
if( ! Surface2d ) {
CM_ASSERTMESSAGE("Error: Pointer to sampler surface 2D is null.");
return CM_NULL_POINTER;
}
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizeperpixel = 0;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
CmSurface2DRT* surface2dRT = static_cast<CmSurface2DRT *>(Surface2d);
surface2dRT->GetSurfaceDesc(width, height, format, sizeperpixel);
if (!m_surfaceMgr->IsSupportedForSamplerSurface2D(format))
{
return CM_SURFACE_FORMAT_NOT_SUPPORTED;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSamplerSurface( surface2dRT, samplerSurfaceIndex, nullptr);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler Surface 2D UP
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSamplerSurface2DUP(CmSurface2DUP* surface2dUP,
SurfaceIndex* & samplerSurfaceIndex)
{
INSERT_API_CALL_LOG();
if (!surface2dUP)
{
CM_ASSERTMESSAGE("Error: Pointer to sampler 2D UP is null.");
return CM_NULL_POINTER;
}
uint32_t width = 0;
uint32_t height = 0;
uint32_t sizeperpixel = 0;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
CmSurface2DUPRT *surface2DRT = static_cast<CmSurface2DUPRT *>(surface2dUP);
surface2DRT->GetSurfaceDesc(width, height, format, sizeperpixel);
if (!m_surfaceMgr->IsSupportedForSamplerSurface2D(format))
{
return CM_SURFACE_FORMAT_NOT_SUPPORTED;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSamplerSurface(surface2DRT, samplerSurfaceIndex);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create Sampler Surface 3D
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::CreateSamplerSurface3D(CmSurface3D* p3DSurface,
SurfaceIndex* & samplerSurfaceIndex)
{
INSERT_API_CALL_LOG();
if( ! p3DSurface ) {
CM_ASSERTMESSAGE("Error: Pointer to sampler surface 3D is null.");
return CM_NULL_POINTER;
}
uint32_t width = 0;
uint32_t height = 0;
uint32_t depth = 0;
CM_SURFACE_FORMAT format = CM_SURFACE_FORMAT_INVALID;
CmSurface3DRT *surfaceRT = static_cast<CmSurface3DRT *>(p3DSurface);
surfaceRT->GetProperties(width, height, depth, format);
switch(format)
{
case CM_SURFACE_FORMAT_A8R8G8B8:
case CM_SURFACE_FORMAT_A16B16G16R16:
break;
default:
CM_ASSERTMESSAGE("Error: Unsupported surface format.");
return CM_SURFACE_FORMAT_NOT_SUPPORTED;
}
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->CreateSamplerSurface( surfaceRT, samplerSurfaceIndex);
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy Sampler Surface
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t
CmDeviceRT::DestroySamplerSurface(SurfaceIndex* & samplerSurfaceIndex)
{
INSERT_API_CALL_LOG();
CLock locker(m_criticalSectionSurface);
int32_t result = m_surfaceMgr->DestroySamplerSurface( samplerSurfaceIndex );
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Cm Sampler8x8 pointer
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetSampler8x8(uint32_t index,
CmSampler8x8State_RT *&sampler8x8)
{
if (CM_MAX_SAMPLER_TABLE_SIZE < index)
{
return CM_EXCEED_SAMPLER_AMOUNT;
}
sampler8x8 = (CmSampler8x8State_RT *)m_sampler8x8Array.GetElement(index);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Set L3 config
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::SetL3Config(const L3ConfigRegisterValues *l3Config)
{
INSERT_API_CALL_LOG();
L3ConfigRegisterValues l3Values;
l3Values = *l3Config;
SetCaps(CAP_L3_CONFIG, sizeof(L3ConfigRegisterValues), &l3Values);
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Set L3 suggested config
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::SetSuggestedL3Config(L3_SUGGEST_CONFIG l3SuggestConfig)
{
INSERT_API_CALL_LOG();
CM_RETURN_CODE hr = CM_SUCCESS;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)this->GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->cmHalInterface->SetSuggestedL3Conf(l3SuggestConfig));
finish:
return hr;
}
//!
//! \brief This function can be used to set/limit hardware
//! capabilities- number of threads that HW can run in parallel
//! \details Hardware thread number can be set from 1 to maximum.
//! \param [in] capName
//! Name of cap to set.
//! \param [in] capValueSize
//! The size of the cap value.
//! \param [in] capValue
//! Pointer to the cap value.
//! \retval CM_SUCCESS if cap value is valid and is set correctly.
//! \retval CM_INVALID_HARDWARE_THREAD_NUMBER specific SetCaps error
//! message if cap value is not valid.
//! \retval CM_NOT_IMPLEMENTED for emulation mode.
//! \retval CM_FAILURE otherwise.
//!
int32_t CmDeviceRT::SetCaps(CM_DEVICE_CAP_NAME capName,
size_t capValueSize,
void* capValue)
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_SET_CAPS setCaps;
uint32_t maxValue;
uint32_t size = sizeof(maxValue);
CmSafeMemSet( &setCaps, 0, sizeof( setCaps ) );
switch(capName)
{
case CAP_HW_THREAD_COUNT:
if (capValueSize != sizeof(uint32_t))
{
CM_ASSERTMESSAGE("Error: Failed to set caps with CAP_HW_THREAD_COUNT.");
return CM_INVALID_HARDWARE_THREAD_NUMBER;
}
if( *(int32_t *)capValue <= 0 )
{
CM_ASSERTMESSAGE("Error: Failed to set caps with CAP_HW_THREAD_COUNT.");
return CM_INVALID_HARDWARE_THREAD_NUMBER;
}
GetCaps(CAP_HW_THREAD_COUNT, size, &maxValue);
if ( *(uint32_t *)capValue > maxValue)
{
CM_ASSERTMESSAGE("Error: Failed to set caps with CAP_HW_THREAD_COUNT.");
return CM_INVALID_HARDWARE_THREAD_NUMBER;
}
setCaps.type = CM_SET_MAX_HW_THREADS;
setCaps.maxValue = *(uint32_t *)capValue;
break;
case CAP_L3_CONFIG:
if (capValueSize != sizeof(L3ConfigRegisterValues))
{
CM_ASSERTMESSAGE("Error: Failed to set caps with CAP_L3_CONFIG.");
return CM_INVALIDE_L3_CONFIGURATION;
}
else
{
L3ConfigRegisterValues *l3Config = (L3ConfigRegisterValues *)capValue;
setCaps.configRegsiter0 = l3Config->config_register0;
setCaps.configRegsiter1 = l3Config->config_register1;
setCaps.configRegsiter2 = l3Config->config_register2;
setCaps.configRegsiter3 = l3Config->config_register3;
setCaps.type = CM_SET_HW_L3_CONFIG;
}
break;
default:
CM_ASSERTMESSAGE("Error: Invalid cap name.");
return CM_INVALID_CAP_NAME;
}
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)this->GetAccelData();
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmData->cmHalState->pfnSetCaps(cmData->cmHalState, (PCM_HAL_MAX_SET_CAPS_PARAM)&setCaps));
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Register the Sync Event
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::RegisterSyncEvent(void *syncEventHandle)
{
CM_RETURN_CODE hr = CM_SUCCESS;
CM_HAL_OSSYNC_PARAM syncParam;
syncParam.osSyncEvent = syncEventHandle;
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
PCM_HAL_STATE cmHalState = cmData->cmHalState;
// Call HAL layer to wait for Task finished with event-driven mechanism
CM_CHK_MOSSTATUS_GOTOFINISH_CMERROR(cmHalState->pfnRegisterUMDNotifyEventHandle(cmHalState, &syncParam));
m_osSyncEvent = syncParam.osSyncEvent;
finish:
return hr;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Sync Event
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetOSSyncEventHandle(void *& hOSSyncEvent)
{
hOSSyncEvent = m_osSyncEvent;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create print buffer to support print in cm kernel
//| Returns: result of operation.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::InitPrintBuffer(size_t printbufsize)
{
INSERT_API_CALL_LOG();
if (m_printBufferUP)
{
if (printbufsize == m_printBufferSize)
{
//Reuse existing buffer up
return CM_SUCCESS;
}
else
{
// Free the existing one first
DestroyBufferUP(m_printBufferUP);
MOS_AlignedFreeMemory(m_printBufferMem);
}
}
/// Allocate and Initialize host memory.
m_printBufferSize = printbufsize;
m_printBufferMem = (uint8_t*)MOS_AlignedAllocMemory(m_printBufferSize, 0x1000); //PAGE SIZE
if(!m_printBufferMem)
{
return CM_OUT_OF_HOST_MEMORY;
}
CmSafeMemSet(m_printBufferMem, 0, m_printBufferSize);
*(unsigned int*)m_printBufferMem = PRINT_BUFFER_HEADER_SIZE;
/// Allocate device memory and MemCopy from host to device.
int32_t result = CreateBufferUP((uint32_t)m_printBufferSize, m_printBufferMem, m_printBufferUP);
if (result != CM_SUCCESS || m_printBufferUP == nullptr)
{
m_isPrintEnabled = false;
MOS_AlignedFreeMemory(m_printBufferMem);
return result;
}
m_printBufferUP->GetIndex(m_printBufferIndex);
m_isPrintEnabled = true;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get print buffer memory
//| Returns: result of operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetPrintBufferMem(unsigned char * &printBufferMem) const
{
printBufferMem = m_printBufferMem;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get the print buffer's surface index
//| Returns: The print buffer's surface index
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetPrintBufferIndex(SurfaceIndex *& index) const
{
index = m_printBufferIndex;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether the kernel print is enabled
//| Returns: Whether the kernel print is enabled.
//*-----------------------------------------------------------------------------
bool CmDeviceRT::IsPrintEnable() const
{
return m_isPrintEnabled;
}
//*-----------------------------------------------------------------------------
//| Purpose: Clear print buffer
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::ClearPrintBuffer()
{
//clean memory
CmSafeMemSet(m_printBufferMem, 0, m_printBufferSize);
*(unsigned int*)m_printBufferMem = PRINT_BUFFER_HEADER_SIZE;
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Whether MDF ETW Log On.
//| Returns: Whether MDF ETW Log On.
//*-----------------------------------------------------------------------------
bool CmDeviceRT::IsVtuneLogOn() const
{
return m_vtuneOn;
}
//*-----------------------------------------------------------------------------
//| Purpose: Get Surf2D LookUP Entry
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::GetSurf2DLookUpEntry(uint32_t index,
PCMLOOKUP_ENTRY &lookupEntry)
{
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)GetAccelData();
if(cmData)
{
lookupEntry = &(cmData->cmHalState->surf2DTable[index]);
}
else
{
return CM_FAILURE;
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Create vebox task
//| Returns: CM_SUCCESS if successfully.
//| CM_OUT_OF_HOST_MEMORY if creation is failed.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateVebox(CmVebox* & vebox) //HSW
{
CLock locker(m_criticalSectionVebox);
uint32_t firstfreeslot = m_veboxArray.GetFirstFreeIndex();
CmVeboxRT *veboxRT = nullptr;
int32_t result = CmVeboxRT::Create(this, firstfreeslot, veboxRT);
if (result == CM_SUCCESS)
{
m_veboxArray.SetElement(firstfreeslot, veboxRT);
m_veboxCount++;
}
vebox = veboxRT;
return result;
}
//*-----------------------------------------------------------------------------
//| Purpose: Destroy vebox task
//| Returns: CM_SUCCESS.
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::DestroyVebox(CmVebox* & vebox) //HSW
{
if (vebox == nullptr)
{
return CM_NULL_POINTER;
}
CmVeboxRT *veboxRT = static_cast<CmVeboxRT *>(vebox);
uint32_t index = veboxRT->GetIndexInVeboxArray();
if (veboxRT == m_veboxArray.GetElement(index))
{
int32_t status = CmVeboxRT::Destroy(veboxRT);
if (status == CM_SUCCESS)
{
m_veboxArray.SetElement(index, nullptr);
vebox = nullptr;
return CM_SUCCESS;
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy vebox task.");
return status;
}
}
else
{
CM_ASSERTMESSAGE("Error: Failed to destroy vebox task.");
return CM_FAILURE;
}
}
int32_t CmDeviceRT::DestroySurfaceInPool(uint32_t &freeSurfNum)
{
CLock locker(m_criticalSectionSurface);
freeSurfNum = m_surfaceMgr->TouchSurfaceInPoolForDestroy();
if ((int32_t)freeSurfNum < 0)
{
freeSurfNum = 0;
return CM_FAILURE;
}
return CM_SUCCESS;
}
CM_RT_API int32_t CmDeviceRT::CreateBufferSVM(uint32_t size,
void* & sysMem,
uint32_t accessFlag,
CmBufferSVM* & bufferSVM)
{
INSERT_API_CALL_LOG();
bool isCMRTAllocatedSVMBuffer = true;
//SVM buffer is going to stateless access, no size restriction lik CmBuffer and CmBufferUP
if( size == 0 )
{
CM_ASSERTMESSAGE("Error: Invalid buffer width.");
return CM_INVALID_WIDTH;
}
if ( sysMem )
{
if ((uintptr_t)sysMem & CM_PAGE_ALIGNMENT_MASK)
{
CM_ASSERTMESSAGE("Error: System memory is not page aligned.");
return CM_SYSTEM_MEMORY_NOT_4KPAGE_ALIGNED;
}
isCMRTAllocatedSVMBuffer = false;
}
else //Allocate a 4K page aligned memory
{
sysMem = MOS_AlignedAllocMemory(size, CM_PAGE_ALIGNMENT);
if (!sysMem)
{
CM_ASSERTMESSAGE("Error: Out of system memory.");
return CM_FAILED_TO_ALLOCATE_SVM_BUFFER;
}
isCMRTAllocatedSVMBuffer = true;
}
CLock locker(m_criticalSectionSurface);
CmBuffer_RT* p = nullptr;
int result = m_surfaceMgr->CreateBuffer( size, CM_BUFFER_SVM, isCMRTAllocatedSVMBuffer, p, nullptr, sysMem, false, CM_DEFAULT_COMPARISON_VALUE );
bufferSVM = static_cast< CmBufferSVM* >(p);
return result;
}
CM_RT_API int32_t CmDeviceRT::DestroyBufferSVM(CmBufferSVM* & bufferSVM)
{
INSERT_API_CALL_LOG();
CmBuffer_RT* temp = static_cast< CmBuffer_RT* >(bufferSVM);
if (nullptr == temp)
{
return CM_NULL_POINTER;
}
CLock locker(m_criticalSectionSurface);
int32_t status = m_surfaceMgr->DestroySurface(temp, APP_DESTROY);
if (status != CM_FAILURE) //CM_SURFACE_IN_USE, or CM_SURFACE_CACHED may be returned, which should be treated as SUCCESS.
{
bufferSVM = nullptr;
return CM_SUCCESS;
}
else
{
return CM_FAILURE;
}
}
//*-----------------------------------------------------------------------------
//| Purpose: Creates an alias to CmSurface2D, surface2d
//| Returns: Result of the operation
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateSurface2DAlias(CmSurface2D* surface2d,
SurfaceIndex* &aliasIndex)
{
INSERT_API_CALL_LOG();
int32_t result = CM_SUCCESS;
CLock locker(m_criticalSectionSurface);
if( !surface2d )
{
CM_ASSERTMESSAGE("Error: Pointer to surface 2D is null.");
return CM_NULL_POINTER;
}
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface2d);
result = surfaceRT->Create2DAlias(aliasIndex);
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Failed to create surface 2D alias.");
return result;
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Creates an alias to CmBuffer, buffer
//| Returns: Result of the operation
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::CreateBufferAlias(CmBuffer *buffer,
SurfaceIndex* &aliasIndex)
{
INSERT_API_CALL_LOG();
int32_t result = CM_SUCCESS;
CLock locker(m_criticalSectionSurface);
if( !buffer )
{
CM_ASSERTMESSAGE("Error: Pointer to CmBuffer is null.");
return CM_NULL_POINTER;
}
CmBuffer_RT *bufferRT = static_cast<CmBuffer_RT *>(buffer);
result = bufferRT->CreateBufferAlias(aliasIndex);
if( result != CM_SUCCESS )
{
CM_ASSERTMESSAGE("Failed to create buffer alias.");
return result;
}
return CM_SUCCESS;
}
//*-----------------------------------------------------------------------------
//| Purpose: Initialize Dev Create Option
//| Returns: Result of the operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::InitDevCreateOption(CM_HAL_CREATE_PARAM & cmHalCreateParam,
uint32_t option)
{
uint32_t maxTaskNumber =0;
uint32_t kernelBinarySizeInGSH = 0;
//Flag to disable scratch space
cmHalCreateParam.disableScratchSpace = (option & CM_DEVICE_CREATE_OPTION_SCRATCH_SPACE_MASK);
//Calculate Scratch Space
if(cmHalCreateParam.disableScratchSpace)
{
cmHalCreateParam.scratchSpaceSize = 0;
}
else
{
//Max Scratch Space Size [1:3] of devCreateOption
cmHalCreateParam.scratchSpaceSize = (option & CM_DEVICE_CONFIG_SCRATCH_SPACE_SIZE_MASK) >> CM_DEVICE_CONFIG_SCRATCH_SPACE_SIZE_OFFSET;
}
//Flag to Disable preemption
cmHalCreateParam.disabledMidThreadPreemption = ((option & CM_DEVICE_CONFIG_MIDTHREADPREEMPTION_DISENABLE) >> CM_DEVICE_CONFIG_MIDTHREADPREEMPTION_OFFSET)? true: false;
//flag to enable kernel debug, so, SIP binary can be created during
cmHalCreateParam.enabledKernelDebug = ((option & CM_DEVICE_CONFIG_KERNEL_DEBUG_ENABLE) >> CM_DEVICE_CONFIG_KERNEL_DEBUG_OFFSET)? true: false;
//Calculate Task Number [4:5] of option [00]:4 ; [01]:8 ; [10]:12; [11]:16
maxTaskNumber = (option & CM_DEVICE_CONFIG_TASK_NUM_MASK) >> CM_DEVICE_CONFIG_TASK_NUM_OFFSET;
cmHalCreateParam.maxTaskNumber = (maxTaskNumber + 1) * CM_DEVICE_CONFIG_TASK_NUM_STEP;
// [9:8] Added bits to increase maximum task number. Value plus one is multiplied by value calculated from bits [5:4].
// [00]:1; [01]:2; [10]:3; [11]:4
maxTaskNumber = (option & CM_DEVICE_CONFIG_EXTRA_TASK_NUM_MASK ) >> CM_DEVICE_CONFIG_EXTRA_TASK_NUM_OFFSET;
cmHalCreateParam.maxTaskNumber = (maxTaskNumber + 1) * cmHalCreateParam.maxTaskNumber;
// [10] request slice shutdown
cmHalCreateParam.requestSliceShutdown = (option & CM_DEVICE_CONFIG_SLICESHUTDOWN_ENABLE ) ? true:false;
// [12] request custom gpu context. This flag is deprecated since GPU context is decoupled with cmhal for supporting multiple context.
cmHalCreateParam.requestCustomGpuContext = (option & CM_DEVICE_CONFIG_GPUCONTEXT_ENABLE) ? true:false;
// [20:13] calculate size in GSH reserved for kernel binary
kernelBinarySizeInGSH = (option & CM_DEVICE_CONFIG_KERNELBINARYGSH_MASK) >> CM_DEVICE_CONFIG_KERNELBINARYGSH_OFFSET;
if (kernelBinarySizeInGSH == 0)
kernelBinarySizeInGSH = 1;
kernelBinarySizeInGSH = kernelBinarySizeInGSH * CM_KERNELBINARY_BLOCKSIZE_2MB;
cmHalCreateParam.kernelBinarySizeinGSH = kernelBinarySizeInGSH;
// [30] fast path
cmHalCreateParam.refactor = (option & CM_DEVICE_CONFIG_FAST_PATH_ENABLE)?true:false;
return CM_SUCCESS;
}
bool CmDeviceRT::IsScratchSpaceDisabled()
{
return m_cmHalCreateOption.disableScratchSpace ? true : false;
}
//*-----------------------------------------------------------------------------
//| Purpose: Sets surface array size, needed to assign alias surface index
//| Returns: Result of the operation
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::SetSurfaceArraySizeForAlias()
{
PCM_CONTEXT_DATA cmData = (PCM_CONTEXT_DATA)this->GetAccelData();
m_surfaceMgr->GetSurfaceArraySize(cmData->cmHalState->surfaceArraySize);
return CM_SUCCESS;
}
#if CM_LOG_ON
std::string CmDeviceRT::Log()
{
std::ostringstream oss;
PCM_HAL_STATE cmHalState;
uint64_t timeStampBase = 0;
uint32_t nSize = sizeof(int);
GetCaps( CAP_GPU_CURRENT_FREQUENCY, nSize, &m_nGPUFreqOriginal );
GetCaps( CAP_MIN_FREQUENCY, nSize, &m_nGPUFreqMin );
GetCaps( CAP_MAX_FREQUENCY, nSize, &m_nGPUFreqMax );
int gtInfo;
GetCaps( CAP_GT_PLATFORM, nSize, >Info );
cmHalState = ((PCM_CONTEXT_DATA)GetAccelData())->cmHalState;
CM_CHK_NULL_RETURN(cmHalState,"cmHalState is null pointer");
timeStampBase = HalCm_ConvertTicksToNanoSeconds(cmHalState,1);
oss << "Device Creation "<<std::endl;
// Hw Information
oss << "Platform :" << m_platform << std::endl;
oss << "GT Info :"<< gtInfo << std::endl;
oss << "Frequency Max:" << m_nGPUFreqMax << " Min:" <<m_nGPUFreqMin
<< " Current:"<< m_nGPUFreqOriginal << std::endl;
oss << "Device DDI Version :" << m_ddiVersion << std::endl;
oss << "Max Tasks " << m_halMaxValues.maxTasks << std::endl;
oss << "Max HW Threads " << m_halMaxValues.maxHwThreads<< std::endl;
oss << "Max Args Per Kernel " << m_halMaxValues.maxArgsPerKernel << std::endl;
oss << "Max 2D Surface Table Size " << m_halMaxValues.max2DSurfaceTableSize << std::endl;
oss << "Max Buffer Table Size " << m_halMaxValues.maxBufferTableSize << std::endl;
oss << "Max Threads per Task " << m_halMaxValues.maxUserThreadsPerTask << std::endl;
oss << "Max Threads Per Task no Thread Arg " << m_halMaxValues.maxUserThreadsPerTaskNoThreadArg << std::endl;
oss << "MDF timestamp base " << timeStampBase << "ns" << std::endl;
return oss.str();
}
#endif
#if !(USE_EXTENSION_CODE)
bool CmDeviceRT::CheckGTPinEnabled( )
{
return false;
}
#endif
//*-----------------------------------------------------------------------------
//| Purpose: Internal function to flush print buffer on stdout or file.
//| Returns: result of operation.
//*-----------------------------------------------------------------------------
int32_t CmDeviceRT::FlushPrintBufferInternal(const char *filename)
{
#if CM_KERNEL_PRINTF_ON
FILE * streamOutFile = nullptr;
if (filename == nullptr)
{
streamOutFile = stdout;
}
else
{
int err = MOS_SecureFileOpen(&streamOutFile, filename, "wb");
if (err || streamOutFile == nullptr)
{
CM_ASSERTMESSAGE("Error: Failed to open kernel print dump file.");
return CM_FAILURE;
}
}
if( m_printBufferMem == nullptr ||
m_printBufferSize == 0 ||
m_isPrintEnabled == false)
{
CM_ASSERTMESSAGE("Error: Print buffer is not initialized.");
if (filename && streamOutFile)
fclose(streamOutFile);
return CM_FAILURE;
}
//Dump memory on the screen.
DumpAllThreadOutput(streamOutFile, m_printBufferMem, m_printBufferSize);
//Flush and close stream
fflush(streamOutFile);
if (filename && streamOutFile)
{
fclose(streamOutFile);
streamOutFile = nullptr;
}
//clean memory
CmSafeMemSet(m_printBufferMem, 0, m_printBufferSize);
*(unsigned int*)m_printBufferMem = sizeof(CM_PRINT_HEADER);
return CM_SUCCESS;
#else
return CM_NOT_IMPLEMENTED;
#endif
}
//*-----------------------------------------------------------------------------
//| Purpose: Dump print buffer. Only Avaliable in Release-internal and Debug Mode
//| Returns: CM_SUCCESS
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::FlushPrintBuffer()
{
return FlushPrintBufferInternal(nullptr);
}
//*-----------------------------------------------------------------------------
//| Purpose: Dump print buffer to file. Only Avaliable in Release-internal and Debug Mode
//| Returns: CM_SUCCESS
//*-----------------------------------------------------------------------------
CM_RT_API int32_t CmDeviceRT::FlushPrintBufferIntoFile(const char *filename)
{
return FlushPrintBufferInternal(filename);
}
CM_RT_API int32_t
CmDeviceRT::CreateHevcVmeSurfaceG10(CmSurface2D * curSurface,
CmSurface2D ** forwardSurfaces,
CmSurface2D ** backwardSurfaces,
const uint32_t forwardSurfaceCount,
const uint32_t backwardSurfaceCount,
SurfaceIndex *& vmeIndex)
{
INSERT_API_CALL_LOG();
if ( curSurface == nullptr )
{
CM_ASSERTMESSAGE("Error: Pointer to current surface is null.");
return CM_NULL_POINTER;
}
if (forwardSurfaceCount > CM_NUM_VME_HEVC_REFS || backwardSurfaceCount > CM_NUM_VME_HEVC_REFS)
{
CM_ASSERTMESSAGE("Error: Invalid count of forward or backward surfaces.");
return CM_INVALID_ARG_VALUE;
}
CmSurface2DRT *currentRT = static_cast< CmSurface2DRT * >( curSurface );
CmSurface2DRT** forwardSurfArray = nullptr;
CmSurface2DRT** backwardSurfArray = nullptr;
forwardSurfArray = MOS_NewArray(CmSurface2DRT*, CM_NUM_VME_HEVC_REFS);
if ( forwardSurfArray == nullptr )
{
CM_ASSERTMESSAGE("Error: Failed to create forward surface array.");
return CM_OUT_OF_HOST_MEMORY;
}
if ( forwardSurfaces != nullptr )
{
for ( uint32_t i = 0; i< forwardSurfaceCount; i++ )
{
forwardSurfArray[ i ] = static_cast< CmSurface2DRT * >( forwardSurfaces[ i ] );
if ( forwardSurfArray[ i ] == nullptr )
{
CM_ASSERTMESSAGE("Error: Invalid forward surface array.");
MosSafeDeleteArray( forwardSurfArray );
return CM_INVALID_ARG_VALUE;
}
}
for ( uint32_t i = forwardSurfaceCount; i < CM_NUM_VME_HEVC_REFS; i++ )
{
forwardSurfArray[ i ] = static_cast< CmSurface2DRT * >( forwardSurfaces[ 0 ] );
}
}
else
{
for ( uint32_t i = 0; i < CM_NUM_VME_HEVC_REFS; i++ )
{
forwardSurfArray[ i ] = currentRT;
}
}
backwardSurfArray = MOS_NewArray(CmSurface2DRT*, CM_NUM_VME_HEVC_REFS);
if ( backwardSurfArray == nullptr )
{
CM_ASSERTMESSAGE("Error: Failed to create backward surface array.");
MosSafeDeleteArray( forwardSurfArray );
return CM_OUT_OF_HOST_MEMORY;
}
if ( backwardSurfaces != nullptr )
{
for ( uint32_t i = 0; i< backwardSurfaceCount; i++ )
{
backwardSurfArray[ i ] = static_cast< CmSurface2DRT * >( backwardSurfaces[ i ] );
if ( backwardSurfArray[ i ] == nullptr )
{
CM_ASSERTMESSAGE("Error: Invalid backward surface array.");
MosSafeDeleteArray( forwardSurfArray );
MosSafeDeleteArray( backwardSurfArray );
return CM_INVALID_ARG_VALUE;
}
}
for ( uint32_t i = backwardSurfaceCount; i < CM_NUM_VME_HEVC_REFS; i++ )
{
backwardSurfArray[ i ] = static_cast< CmSurface2DRT * >( backwardSurfaces[ 0 ] );
}
}
else
{
for ( uint32_t i = 0; i < CM_NUM_VME_HEVC_REFS; i++ )
{
backwardSurfArray[ i ] = currentRT;
}
}
int32_t result = m_surfaceMgr->CreateVmeSurface( currentRT, forwardSurfArray, backwardSurfArray, forwardSurfaceCount, backwardSurfaceCount, vmeIndex );
if ( FAILED( result ) )
{
CM_ASSERTMESSAGE("Error: Failed to create HEVC VME surface.");
}
MosSafeDeleteArray( forwardSurfArray );
MosSafeDeleteArray( backwardSurfArray );
return result;
}
CM_RT_API int32_t
CmDeviceRT::DestroyHevcVmeSurfaceG10(SurfaceIndex *& vmeIndex)
{
INSERT_API_CALL_LOG();
return DestroyVmeSurface( vmeIndex );
}
CM_RT_API int32_t CmDeviceRT::CloneKernel(CmKernel* &kernelDest,
CmKernel *kernelSrc)
{
INSERT_API_CALL_LOG();
int32_t hr = CM_SUCCESS;
if (kernelSrc == nullptr)
{
CM_ASSERTMESSAGE("Error: Pointer to src kernel is null");
return CM_NULL_POINTER;
}
CmKernelRT *kernelSrcRT = static_cast<CmKernelRT *>(kernelSrc);
CmKernelRT *kernelDestRT = static_cast<CmKernelRT *>(kernelDest);
hr = kernelSrcRT->CloneKernel(kernelDestRT, m_kernelCount);
kernelDest = kernelDestRT;
return hr;
}
CmDynamicArray* CmDeviceRT::GetKernelArray()
{
return &m_kernelArray;
}
uint32_t *CmDeviceRT::GetKernelCount()
{
return &m_kernelCount;
}
int32_t CmDeviceRT::DestroyVmeSurface(SurfaceIndex *& vmeIndex)
{
CLock locker( m_criticalSectionSurface );
int32_t result = m_surfaceMgr->DestroyVmeSurface( vmeIndex );
return result;
}
int32_t CmDeviceRT::GetVISAVersion(uint32_t& majorVersion,
uint32_t& minorVersion)
{
int32_t result = CM_SUCCESS;
result = GetJITVersionFnt(m_fJITVersion);
if(result != CM_SUCCESS)
{
CM_ASSERTMESSAGE("Error: Failed to get VISA version.");
return result;
}
m_fJITVersion(majorVersion, minorVersion);
return CM_SUCCESS;
}
CM_RT_API int32_t CmDeviceRT::UpdateBuffer(PMOS_RESOURCE mosResource,
CmBuffer* &surface)
{
if (surface)
{
CmBuffer_RT *bufferRT = static_cast<CmBuffer_RT *>(surface);
return bufferRT->UpdateResource(mosResource);
}
else
{
return CreateBuffer(mosResource, surface);
}
}
CM_RT_API int32_t CmDeviceRT::UpdateSurface2D(PMOS_RESOURCE mosResource,
CmSurface2D* &surface)
{
if (surface)
{
CmSurface2DRT *surfaceRT = static_cast<CmSurface2DRT *>(surface);
return surfaceRT->UpdateResource(mosResource);
}
else
{
return CreateSurface2D(mosResource, surface);
}
}
} // namespace
|