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
|
// SPDX-License-Identifier: MIT
/*
* Copyright © 2022 Intel Corporation
*/
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <malloc.h>
#include <cairo.h>
#include "drm.h"
#include "i915/gem_create.h"
#include "igt.h"
#include "igt_syncobj.h"
#include "intel_blt.h"
#include "intel_mocs.h"
#include "intel_pat.h"
#include "xe/xe_ioctl.h"
#include "xe/xe_query.h"
#include "xe/xe_util.h"
#define BITRANGE(start, end) (end - start + 1)
#define GET_CMDS_INFO(__fd) intel_get_cmds_info(intel_get_drm_devid(__fd))
#define MEM_COPY_MOCS_SHIFT 25
/* Blitter tiling definitions sanity checks */
static_assert(T_LINEAR == I915_TILING_NONE, "Linear definitions have to match");
static_assert(T_XMAJOR == I915_TILING_X, "TileX definitions have to match");
static_assert(T_YMAJOR == I915_TILING_Y, "TileY definitions have to match");
static_assert(T_YFMAJOR == I915_TILING_Yf, "TileYf definitions have to match");
enum blt_special_mode {
SM_NONE,
SM_FULL_RESOLVE,
SM_PARTIAL_RESOLVE,
SM_RESERVED,
};
enum blt_aux_mode {
AM_AUX_NONE,
AM_AUX_CCS_E = 5,
};
enum blt_target_mem {
TM_LOCAL_MEM,
TM_SYSTEM_MEM,
};
struct gen12_block_copy_data {
struct {
uint32_t length: BITRANGE(0, 7);
uint32_t rsvd1: BITRANGE(8, 8);
uint32_t multisamples: BITRANGE(9, 11);
uint32_t special_mode: BITRANGE(12, 13);
uint32_t rsvd0: BITRANGE(14, 18);
uint32_t color_depth: BITRANGE(19, 21);
uint32_t opcode: BITRANGE(22, 28);
uint32_t client: BITRANGE(29, 31);
} dw00;
union {
struct {
uint32_t dst_pitch: BITRANGE(0, 17);
uint32_t dst_aux_mode: BITRANGE(18, 20);
uint32_t pxp: BITRANGE(21, 21);
uint32_t dst_mocs_index: BITRANGE(22, 27);
uint32_t dst_ctrl_surface_type: BITRANGE(28, 28);
uint32_t dst_compression: BITRANGE(29, 29);
uint32_t dst_tiling: BITRANGE(30, 31);
} dw01;
struct {
uint32_t dst_pitch: BITRANGE(0, 17);
uint32_t dst_aux_mode: BITRANGE(18, 20);
uint32_t pxp: BITRANGE(21, 21);
uint32_t dst_mocs_index: BITRANGE(22, 27);
uint32_t dst_ctrl_surface_type: BITRANGE(28, 28);
uint32_t dst_compression: BITRANGE(29, 29);
uint32_t dst_tiling: BITRANGE(30, 31);
} dw01_xe2;
};
struct {
int32_t dst_x1: BITRANGE(0, 15);
int32_t dst_y1: BITRANGE(16, 31);
} dw02;
struct {
int32_t dst_x2: BITRANGE(0, 15);
int32_t dst_y2: BITRANGE(16, 31);
} dw03;
struct {
uint32_t dst_address_lo;
} dw04;
struct {
uint32_t dst_address_hi;
} dw05;
struct {
uint32_t dst_x_offset: BITRANGE(0, 13);
uint32_t rsvd1: BITRANGE(14, 15);
uint32_t dst_y_offset: BITRANGE(16, 29);
uint32_t rsvd0: BITRANGE(30, 30);
uint32_t dst_target_memory: BITRANGE(31, 31);
} dw06;
struct {
int32_t src_x1: BITRANGE(0, 15);
int32_t src_y1: BITRANGE(16, 31);
} dw07;
union {
struct {
uint32_t src_pitch: BITRANGE(0, 17);
uint32_t src_aux_mode: BITRANGE(18, 20);
uint32_t pxp: BITRANGE(21, 21);
uint32_t src_mocs_index: BITRANGE(22, 27);
uint32_t src_ctrl_surface_type: BITRANGE(28, 28);
uint32_t src_compression: BITRANGE(29, 29);
uint32_t src_tiling: BITRANGE(30, 31);
} dw08;
struct {
uint32_t src_pitch: BITRANGE(0, 17);
uint32_t pad0: BITRANGE(18, 20);
uint32_t pxp: BITRANGE(21, 21);
uint32_t pad1: BITRANGE(22, 23);
uint32_t src_mocs_index: BITRANGE(24, 27);
uint32_t pad2: BITRANGE(28, 29);
uint32_t src_tiling: BITRANGE(30, 31);
} dw08_xe2;
};
struct {
uint32_t src_address_lo;
} dw09;
struct {
uint32_t src_address_hi;
} dw10;
struct {
uint32_t src_x_offset: BITRANGE(0, 13);
uint32_t rsvd1: BITRANGE(14, 15);
uint32_t src_y_offset: BITRANGE(16, 29);
uint32_t rsvd0: BITRANGE(30, 30);
uint32_t src_target_memory: BITRANGE(31, 31);
} dw11;
};
struct gen12_block_copy_data_ext {
struct {
uint32_t src_compression_format: BITRANGE(0, 4);
uint32_t src_clear_value_enable: BITRANGE(5, 5);
uint32_t src_clear_address_low: BITRANGE(6, 31);
} dw12;
union {
/* DG2, XEHP */
uint32_t src_clear_address_hi0;
/* Others */
uint32_t src_clear_address_hi1;
} dw13;
struct {
uint32_t dst_compression_format: BITRANGE(0, 4);
uint32_t dst_clear_value_enable: BITRANGE(5, 5);
uint32_t dst_clear_address_low: BITRANGE(6, 31);
} dw14;
union {
/* DG2, XEHP */
uint32_t dst_clear_address_hi0;
/* Others */
uint32_t dst_clear_address_hi1;
} dw15;
struct {
uint32_t dst_surface_height: BITRANGE(0, 13);
uint32_t dst_surface_width: BITRANGE(14, 27);
uint32_t rsvd0: BITRANGE(28, 28);
uint32_t dst_surface_type: BITRANGE(29, 31);
} dw16;
struct {
uint32_t dst_lod: BITRANGE(0, 3);
uint32_t dst_surface_qpitch: BITRANGE(4, 18);
uint32_t rsvd0: BITRANGE(19, 20);
uint32_t dst_surface_depth: BITRANGE(21, 31);
} dw17;
struct {
uint32_t dst_horizontal_align: BITRANGE(0, 1);
uint32_t rsvd0: BITRANGE(2, 2);
uint32_t dst_vertical_align: BITRANGE(3, 4);
uint32_t rsvd1: BITRANGE(5, 7);
uint32_t dst_mip_tail_start_lod: BITRANGE(8, 11);
uint32_t rsvd2: BITRANGE(12, 17);
uint32_t dst_depth_stencil_resource: BITRANGE(18, 18);
uint32_t rsvd3: BITRANGE(19, 20);
uint32_t dst_array_index: BITRANGE(21, 31);
} dw18;
struct {
uint32_t src_surface_height: BITRANGE(0, 13);
uint32_t src_surface_width: BITRANGE(14, 27);
uint32_t rsvd0: BITRANGE(28, 28);
uint32_t src_surface_type: BITRANGE(29, 31);
} dw19;
struct {
uint32_t src_lod: BITRANGE(0, 3);
uint32_t src_surface_qpitch: BITRANGE(4, 18);
uint32_t rsvd0: BITRANGE(19, 20);
uint32_t src_surface_depth: BITRANGE(21, 31);
} dw20;
struct {
uint32_t src_horizontal_align: BITRANGE(0, 1);
uint32_t rsvd0: BITRANGE(2, 2);
uint32_t src_vertical_align: BITRANGE(3, 4);
uint32_t rsvd1: BITRANGE(5, 7);
uint32_t src_mip_tail_start_lod: BITRANGE(8, 11);
uint32_t rsvd2: BITRANGE(12, 17);
uint32_t src_depth_stencil_resource: BITRANGE(18, 18);
uint32_t rsvd3: BITRANGE(19, 20);
uint32_t src_array_index: BITRANGE(21, 31);
} dw21;
};
/**
* blt_supports_command:
* @cmds_info: Copy commands description struct
* @cmd: Blitter command enum
*
* Checks if @cmds_info has an entry of supported tiling formats for @cmd command.
*
* Returns: true if it does, false otherwise
*/
bool blt_supports_command(const struct intel_cmds_info *cmds_info,
enum blt_cmd_type cmd)
{
igt_require_f(cmds_info, "No config found for the platform\n");
return blt_get_cmd_info(cmds_info, cmd);
}
/**
* blt_cmd_supports_tiling:
* @cmds_info: Copy commands description struct
* @cmd: Blitter command enum
* @tiling: tiling format enum
*
* Checks if a @cmd entry of @cmds_info lists @tiling. It also returns false if
* no information about the command is stored.
*
* Returns: true if it does, false otherwise
*/
bool blt_cmd_supports_tiling(const struct intel_cmds_info *cmds_info,
enum blt_cmd_type cmd,
enum blt_tiling_type tiling)
{
struct blt_cmd_info const *cmd_info;
if (!cmds_info)
return false;
cmd_info = blt_get_cmd_info(cmds_info, cmd);
/* no config means no support for that tiling */
if (!cmd_info)
return false;
return cmd_info->supported_tiling & BIT(tiling);
}
/**
* blt_cmd_has_property:
* @cmds_info: Copy commands description struct
* @cmd: Blitter command enum
* @prop: property flag
*
* Checks if a @cmd entry of @cmds_info has @prop property. The properties can
* be freely combined, but the function will return true for platforms for
* which all properties defined in the bit flag are present. The function
* returns false if no information about the command is stored.
*
* Returns: true if it does, false otherwise
*/
bool blt_cmd_has_property(const struct intel_cmds_info *cmds_info,
enum blt_cmd_type cmd, uint32_t prop)
{
struct blt_cmd_info const *cmd_info;
cmd_info = blt_get_cmd_info(cmds_info, cmd);
if (!cmd_info)
return false;
return cmd_info->flags & prop;
}
/**
* blt_has_block_copy
* @fd: drm fd
*
* Check if block copy is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_block_copy(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, XY_BLOCK_COPY);
}
/**
* blt_has_mem_copy
* @fd: drm fd
*
* Check if mem copy is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_mem_copy(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, MEM_COPY);
}
/**
* blt_has_mem_set
* @fd: drm fd
*
* Check if mem set is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_mem_set(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, MEM_SET);
}
/**
* blt_has_fast_copy
* @fd: drm fd
*
* Check if fast copy is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_fast_copy(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, XY_FAST_COPY);
}
/**
* blt_has_xy_src_copy
* @fd: drm fd
*
* Check if XY src copy is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_xy_src_copy(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, XY_SRC_COPY);
}
/**
* blt_has_xy_color
* @fd: drm fd
*
* Check if XY_COLOR_BLT is supported by @fd device
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_has_xy_color(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_supports_command(cmds_info, XY_COLOR_BLT);
}
/**
* blt_fast_copy_supports_tiling
* @fd: drm fd
* @tiling: tiling format
*
* Check if fast copy provided by @fd device supports @tiling format
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_fast_copy_supports_tiling(int fd, enum blt_tiling_type tiling)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_cmd_supports_tiling(cmds_info, XY_FAST_COPY, tiling);
}
/**
* blt_block_copy_supports_tiling
* @fd: drm fd
* @tiling: tiling format
*
* Check if block copy provided by @fd device supports @tiling format
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_block_copy_supports_tiling(int fd, enum blt_tiling_type tiling)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_cmd_supports_tiling(cmds_info, XY_BLOCK_COPY, tiling);
}
/**
* blt_xy_src_copy_supports_tiling
* @fd: drm fd
* @tiling: tiling format
*
* Check if XY src copy provided by @fd device supports @tiling format
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_xy_src_copy_supports_tiling(int fd, enum blt_tiling_type tiling)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_cmd_supports_tiling(cmds_info, XY_SRC_COPY, tiling);
}
/**
* blt_block_copy_supports_compression
* @fd: drm fd
*
* Check if block copy provided by @fd device supports compression.
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_block_copy_supports_compression(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_cmd_has_property(cmds_info, XY_BLOCK_COPY,
BLT_CMD_SUPPORTS_COMPRESSION);
}
/**
* blt_platform_has_flat_ccs_enabled
* @fd: drm fd
*
* Check if platform provided by @fd device has flat-ccs enabled.
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_platform_has_flat_ccs_enabled(int fd)
{
return igt_debugfs_search(fd, "info", "has_flat_ccs yes");
}
/**
* blt_uses_extended_block_copy
* @fd: drm fd
*
* Check if block copy provided by @fd device uses an extended version
* of the command.
*
* Returns:
* true if it does, false otherwise.
*/
bool blt_uses_extended_block_copy(int fd)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
return blt_cmd_has_property(cmds_info, XY_BLOCK_COPY, BLT_CMD_EXTENDED);
}
/**
* render_supports_tiling
* @fd: drm fd
* @tiling: tiling format
* @compression: check tiling which will be compressed
*
* Check if render provided by @fd device supports @tiling format wrt
* @compression
*
* Returns:
* true if it does, false otherwise.
*/
bool render_supports_tiling(int fd, enum blt_tiling_type tiling, bool compression)
{
const struct intel_cmds_info *cmds_info = GET_CMDS_INFO(fd);
igt_assert(cmds_info);
if (!cmds_info->render_tilings) {
igt_warn("Render tilings are not defined\n");
return false;
}
if (!compression)
return cmds_info->render_tilings->supported_tiling & BIT(tiling);
return cmds_info->render_tilings->supported_compressed_tiling & BIT(tiling);
}
/**
* blt_tiling_name:
* @tiling: tiling id
*
* Returns:
* name of @tiling passed. Useful to build test names.
*/
const char *blt_tiling_name(enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR: return "linear";
case T_XMAJOR: return "xmajor";
case T_YMAJOR: return "ymajor";
case T_TILE4: return "tile4";
case T_TILE64: return "tile64";
case T_YFMAJOR: return "yfmajor";
case T_YSMAJOR: return "ysmajor";
default:
break;
}
igt_warn("invalid tiling passed: %d\n", tiling);
return NULL;
}
static int __block_tiling(enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR: return 0;
case T_XMAJOR: return 1;
case T_YMAJOR: return 1;
case T_TILE4: return 2;
case T_YFMAJOR: return 2;
case T_TILE64: return 3;
default:
break;
}
igt_warn("invalid tiling passed: %d\n", tiling);
return 0;
}
/**
* blt_tile_to_i915_tile:
* @tiling: tiling id
*
* Returns:
* id of tiling introduced in i915 like I915_TILING_* used for example
* in render-copy code.
*/
int blt_tile_to_i915_tile(enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR: return I915_TILING_NONE;
case T_XMAJOR: return I915_TILING_X;
case T_YMAJOR: return I915_TILING_Y;
case T_TILE4: return I915_TILING_4;
case T_TILE64: return I915_TILING_64;
case T_YFMAJOR: return I915_TILING_Yf;
case T_YSMAJOR: return I915_TILING_Ys;
default:
break;
}
igt_warn("invalid tiling passed: %d\n", tiling);
return 0;
}
/**
* i915_tile_to_blt_tile:
* @tiling: tiling id
*
* Returns:
* id of blt tiling like T_LINEAR, T_XMAJOR, etc
*/
enum blt_tiling_type i915_tile_to_blt_tile(uint32_t tiling)
{
switch (tiling) {
case I915_TILING_NONE: return T_LINEAR;
case I915_TILING_X: return T_XMAJOR;
case I915_TILING_Y: return T_YMAJOR;
case I915_TILING_4: return T_TILE4;
case I915_TILING_64: return T_TILE64;
case I915_TILING_Yf: return T_YFMAJOR;
case I915_TILING_Ys: return T_YSMAJOR;
default:
igt_assert_f(0, "Unknown tiling!\n");
}
}
/**
* blt_get_min_stride
* @width: width in pixels
* @bpp: bits per pixel
* @tiling: tiling
*
* Function calculates minimum posibble stride in bytes for width, bpp
* and tiling.
*
* Returns:
* minimum possible stride in bytes.
*/
uint32_t blt_get_min_stride(uint32_t width, uint32_t bpp,
enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR:
return width * bpp / 8;
case T_XMAJOR:
return ALIGN(width * bpp / 8, 512);
case T_TILE64:
if (bpp == 8)
return ALIGN(width, 256);
else if (bpp == 16 || bpp == 32)
return ALIGN(width * bpp / 8, 512);
return ALIGN(width * bpp / 8, 1024);
default:
return ALIGN(width * bpp / 8, 128);
}
}
/**
* blt_get_aligned_height
* @height: height in pixels
* @bpp: bits per pixel (used for Tile64 due to different tile organization
* in pixels)
* @tiling: tiling
*
* Function returns aligned height for specific tiling. Height returned is
* important from memory allocation perspective, because each tiling has
* specific memory constraints.
*
* Returns:
* height (rows) expected for specific tiling
*/
uint32_t blt_get_aligned_height(uint32_t height, uint32_t bpp,
enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR:
return height;
case T_XMAJOR:
return ALIGN(height, 8);
case T_TILE64:
if (bpp == 8)
return ALIGN(height, 256);
else if (bpp == 16 || bpp == 32)
return ALIGN(height, 128);
return ALIGN(height, 64);
default:
return ALIGN(height, 32);
}
}
static int __special_mode(const struct blt_copy_data *blt)
{
if (blt->src.handle == blt->dst.handle &&
blt->src.compression && !blt->dst.compression)
return SM_FULL_RESOLVE;
return SM_NONE;
}
static int __memory_type(int fd, enum intel_driver driver, uint32_t region)
{
if (driver == INTEL_DRIVER_I915) {
igt_assert_f(IS_DEVICE_MEMORY_REGION(region) ||
IS_SYSTEM_MEMORY_REGION(region),
"Invalid region: %x\n", region);
} else {
igt_assert_f(XE_IS_VRAM_MEMORY_REGION(fd, region) ||
XE_IS_SYSMEM_MEMORY_REGION(fd, region),
"Invalid region: %x\n", region);
}
if (driver == INTEL_DRIVER_I915 && IS_DEVICE_MEMORY_REGION(region))
return TM_LOCAL_MEM;
else if (driver == INTEL_DRIVER_XE && XE_IS_VRAM_MEMORY_REGION(fd, region))
return TM_LOCAL_MEM;
return TM_SYSTEM_MEM;
}
static enum blt_aux_mode __aux_mode(int fd,
enum intel_driver driver,
const struct blt_copy_object *obj)
{
if (driver == INTEL_DRIVER_I915 && obj->compression == COMPRESSION_ENABLED) {
igt_assert_f(IS_DEVICE_MEMORY_REGION(obj->region),
"XY_BLOCK_COPY_BLT supports compression "
"on device memory only\n");
return AM_AUX_CCS_E;
} else if (driver == INTEL_DRIVER_XE && obj->compression == COMPRESSION_ENABLED) {
igt_assert_f(XE_IS_VRAM_MEMORY_REGION(fd, obj->region),
"XY_BLOCK_COPY_BLT supports compression "
"on device memory only\n");
return AM_AUX_CCS_E;
}
return AM_AUX_NONE;
}
static bool __new_tile_y_type(enum blt_tiling_type tiling)
{
return tiling == T_TILE4 || tiling == T_YFMAJOR;
}
static void fill_data(struct gen12_block_copy_data *data,
const struct blt_copy_data *blt,
uint64_t src_offset, uint64_t dst_offset,
bool extended_command, unsigned int ip_ver)
{
data->dw00.client = 0x2;
data->dw00.opcode = 0x41;
data->dw00.color_depth = blt->color_depth;
data->dw00.special_mode = __special_mode(blt);
data->dw00.length = extended_command ? 20 : 10;
if (ip_ver >= IP_VER(20, 0)) {
data->dw01_xe2.dst_pitch = blt->dst.pitch - 1;
data->dw01_xe2.dst_mocs_index = blt->dst.mocs_index;
data->dw01_xe2.dst_tiling = __block_tiling(blt->dst.tiling);
} else {
if (__special_mode(blt) == SM_FULL_RESOLVE)
data->dw01.dst_aux_mode = __aux_mode(blt->fd, blt->driver, &blt->src);
else
data->dw01.dst_aux_mode = __aux_mode(blt->fd, blt->driver, &blt->dst);
data->dw01.dst_pitch = blt->dst.pitch - 1;
data->dw01.dst_mocs_index = blt->dst.mocs_index;
data->dw01.dst_compression = blt->dst.compression;
data->dw01.dst_tiling = __block_tiling(blt->dst.tiling);
if (blt->dst.compression)
data->dw01.dst_ctrl_surface_type = blt->dst.compression_type;
}
data->dw02.dst_x1 = blt->dst.x1;
data->dw02.dst_y1 = blt->dst.y1;
data->dw03.dst_x2 = blt->dst.x2;
data->dw03.dst_y2 = blt->dst.y2;
data->dw04.dst_address_lo = dst_offset;
data->dw05.dst_address_hi = dst_offset >> 32;
data->dw06.dst_x_offset = blt->dst.x_offset;
data->dw06.dst_y_offset = blt->dst.y_offset;
data->dw06.dst_target_memory = __memory_type(blt->fd, blt->driver, blt->dst.region);
data->dw07.src_x1 = blt->src.x1;
data->dw07.src_y1 = blt->src.y1;
if (ip_ver >= IP_VER(20, 0)) {
data->dw08_xe2.src_pitch = blt->src.pitch - 1;
data->dw08_xe2.src_mocs_index = blt->src.mocs_index;
data->dw08_xe2.src_tiling = __block_tiling(blt->src.tiling);
} else {
data->dw08.src_pitch = blt->src.pitch - 1;
data->dw08.src_aux_mode = __aux_mode(blt->fd, blt->driver, &blt->src);
data->dw08.src_mocs_index = blt->src.mocs_index;
data->dw08.src_compression = blt->src.compression;
data->dw08.src_tiling = __block_tiling(blt->src.tiling);
if (blt->src.compression)
data->dw08.src_ctrl_surface_type = blt->src.compression_type;
}
data->dw09.src_address_lo = src_offset;
data->dw10.src_address_hi = src_offset >> 32;
data->dw11.src_x_offset = blt->src.x_offset;
data->dw11.src_y_offset = blt->src.y_offset;
data->dw11.src_target_memory = __memory_type(blt->fd, blt->driver, blt->src.region);
}
static void fill_data_ext(struct gen12_block_copy_data_ext *dext,
const struct blt_block_copy_data_ext *ext)
{
dext->dw12.src_compression_format = ext->src.compression_format;
dext->dw12.src_clear_value_enable = ext->src.clear_value_enable;
dext->dw12.src_clear_address_low = ext->src.clear_address;
dext->dw13.src_clear_address_hi0 = ext->src.clear_address >> 32;
dext->dw14.dst_compression_format = ext->dst.compression_format;
dext->dw14.dst_clear_value_enable = ext->dst.clear_value_enable;
dext->dw14.dst_clear_address_low = ext->dst.clear_address;
dext->dw15.dst_clear_address_hi0 = ext->dst.clear_address >> 32;
dext->dw16.dst_surface_width = ext->dst.surface_width - 1;
dext->dw16.dst_surface_height = ext->dst.surface_height - 1;
dext->dw16.dst_surface_type = ext->dst.surface_type;
dext->dw17.dst_lod = ext->dst.lod;
dext->dw17.dst_surface_depth = ext->dst.surface_depth;
dext->dw17.dst_surface_qpitch = ext->dst.surface_qpitch;
dext->dw18.dst_horizontal_align = ext->dst.horizontal_align;
dext->dw18.dst_vertical_align = ext->dst.vertical_align;
dext->dw18.dst_mip_tail_start_lod = ext->dst.mip_tail_start_lod;
dext->dw18.dst_depth_stencil_resource = ext->dst.depth_stencil_resource;
dext->dw18.dst_array_index = ext->dst.array_index;
dext->dw19.src_surface_width = ext->src.surface_width - 1;
dext->dw19.src_surface_height = ext->src.surface_height - 1;
dext->dw19.src_surface_type = ext->src.surface_type;
dext->dw20.src_lod = ext->src.lod;
dext->dw20.src_surface_depth = ext->src.surface_depth;
dext->dw20.src_surface_qpitch = ext->src.surface_qpitch;
dext->dw21.src_horizontal_align = ext->src.horizontal_align;
dext->dw21.src_vertical_align = ext->src.vertical_align;
dext->dw21.src_mip_tail_start_lod = ext->src.mip_tail_start_lod;
dext->dw21.src_depth_stencil_resource = ext->src.depth_stencil_resource;
dext->dw21.src_array_index = ext->src.array_index;
}
static void dump_bb_cmd(struct gen12_block_copy_data *data, unsigned int ip_ver)
{
uint32_t *cmd = (uint32_t *) data;
int src_mocs_idx, dst_mocs_idx;
if (ip_ver >= IP_VER(20, 0)) {
src_mocs_idx = data->dw08_xe2.src_mocs_index;
dst_mocs_idx = data->dw01_xe2.dst_mocs_index;
} else {
src_mocs_idx = data->dw08.src_mocs_index;
dst_mocs_idx = data->dw01.dst_mocs_index;
}
igt_info("details:\n");
igt_info(" dw00: [%08x] <client: 0x%x, opcode: 0x%x, color depth: %d, "
"special mode: %d, length: %d>\n",
cmd[0],
data->dw00.client, data->dw00.opcode, data->dw00.color_depth,
data->dw00.special_mode, data->dw00.length);
igt_info(" dw01: [%08x] dst <pitch: %d, aux: %d, mocs_idx: %d, compr: %d, "
"tiling: %d, ctrl surf type: %d>\n",
cmd[1], data->dw01.dst_pitch, data->dw01.dst_aux_mode,
dst_mocs_idx, data->dw01.dst_compression,
data->dw01.dst_tiling, data->dw01.dst_ctrl_surface_type);
igt_info(" dw02: [%08x] dst geom <x1: %d, y1: %d>\n",
cmd[2], data->dw02.dst_x1, data->dw02.dst_y1);
igt_info(" dw03: [%08x] <x2: %d, y2: %d>\n",
cmd[3], data->dw03.dst_x2, data->dw03.dst_y2);
igt_info(" dw04: [%08x] dst offset lo (0x%x)\n",
cmd[4], data->dw04.dst_address_lo);
igt_info(" dw05: [%08x] dst offset hi (0x%x)\n",
cmd[5], data->dw05.dst_address_hi);
igt_info(" dw06: [%08x] dst <x offset: 0x%x, y offset: 0x%0x, target mem: %d>\n",
cmd[6], data->dw06.dst_x_offset, data->dw06.dst_y_offset,
data->dw06.dst_target_memory);
igt_info(" dw07: [%08x] src geom <x1: %d, y1: %d>\n",
cmd[7], data->dw07.src_x1, data->dw07.src_y1);
igt_info(" dw08: [%08x] src <pitch: %d, aux: %d, mocs_idx: %d, compr: %d, "
"tiling: %d, ctrl surf type: %d>\n",
cmd[8], data->dw08.src_pitch, data->dw08.src_aux_mode,
src_mocs_idx, data->dw08.src_compression,
data->dw08.src_tiling, data->dw08.src_ctrl_surface_type);
igt_info(" dw09: [%08x] src offset lo (0x%x)\n",
cmd[9], data->dw09.src_address_lo);
igt_info(" dw10: [%08x] src offset hi (0x%x)\n",
cmd[10], data->dw10.src_address_hi);
igt_info(" dw11: [%08x] src <x offset: 0x%x, y offset: 0x%0x, target mem: %d>\n",
cmd[11], data->dw11.src_x_offset, data->dw11.src_y_offset,
data->dw11.src_target_memory);
}
static void dump_bb_ext(struct gen12_block_copy_data_ext *data)
{
uint32_t *cmd = (uint32_t *) data;
igt_info("ext details:\n");
igt_info(" dw12: [%08x] src <compression fmt: %d, clear value enable: %d, "
"clear address low: 0x%x>\n",
cmd[0],
data->dw12.src_compression_format,
data->dw12.src_clear_value_enable,
data->dw12.src_clear_address_low);
igt_info(" dw13: [%08x] src clear address hi: 0x%x\n",
cmd[1], data->dw13.src_clear_address_hi0);
igt_info(" dw14: [%08x] dst <compression fmt: %d, clear value enable: %d, "
"clear address low: 0x%x>\n",
cmd[2],
data->dw14.dst_compression_format,
data->dw14.dst_clear_value_enable,
data->dw14.dst_clear_address_low);
igt_info(" dw15: [%08x] dst clear address hi: 0x%x\n",
cmd[3], data->dw15.dst_clear_address_hi0);
igt_info(" dw16: [%08x] dst surface <width: %d, height: %d, type: %d>\n",
cmd[4], data->dw16.dst_surface_width,
data->dw16.dst_surface_height, data->dw16.dst_surface_type);
igt_info(" dw17: [%08x] dst surface <lod: %d, depth: %d, qpitch: %d>\n",
cmd[5], data->dw17.dst_lod,
data->dw17.dst_surface_depth, data->dw17.dst_surface_qpitch);
igt_info(" dw18: [%08x] dst <halign: %d, valign: %d, mip tail: %d, "
"depth stencil: %d, array index: %d>\n",
cmd[6],
data->dw18.dst_horizontal_align,
data->dw18.dst_vertical_align,
data->dw18.dst_mip_tail_start_lod,
data->dw18.dst_depth_stencil_resource,
data->dw18.dst_array_index);
igt_info(" dw19: [%08x] src surface <width: %d, height: %d, type: %d>\n",
cmd[7], data->dw19.src_surface_width,
data->dw19.src_surface_height, data->dw19.src_surface_type);
igt_info(" dw20: [%08x] src surface <lod: %d, depth: %d, qpitch: %d>\n",
cmd[8], data->dw20.src_lod,
data->dw20.src_surface_depth, data->dw20.src_surface_qpitch);
igt_info(" dw21: [%08x] src <halign: %d, valign: %d, mip tail: %d, "
"depth stencil: %d, array index: %d>\n",
cmd[9],
data->dw21.src_horizontal_align,
data->dw21.src_vertical_align,
data->dw21.src_mip_tail_start_lod,
data->dw21.src_depth_stencil_resource,
data->dw21.src_array_index);
}
static void *bo_map(int fd, uint32_t handle, uint64_t size,
enum intel_driver driver)
{
if (driver == INTEL_DRIVER_XE)
return xe_bo_map(fd, handle, size);
return gem_mmap__device_coherent(fd, handle, 0, size,
PROT_READ | PROT_WRITE);
}
/**
* blt_copy_init:
* @fd: drm fd
* @blt: structure for initialization
*
* Function is zeroing @blt and sets fd and driver fields (INTEL_DRIVER_I915 or
* INTEL_DRIVER_XE).
*/
void blt_copy_init(int fd, struct blt_copy_data *blt)
{
memset(blt, 0, sizeof(*blt));
blt->fd = fd;
blt->driver = get_intel_driver(fd);
}
/**
* emit_blt_block_copy:
* @fd: drm fd
* @ahnd: allocator handle
* @blt: basic blitter data (for TGL/DG1 which doesn't support ext version)
* @ext: extended blitter data (for DG2+, supports flatccs compression)
* @bb_pos: position at which insert block copy commands
* @emit_bbe: emit MI_BATCH_BUFFER_END after block-copy or not
*
* Function inserts block-copy blit into batch at @bb_pos. Allows concatenating
* with other commands to achieve pipelining.
*
* Returns:
* Next write position in batch.
*/
uint64_t emit_blt_block_copy(int fd,
uint64_t ahnd,
const struct blt_copy_data *blt,
const struct blt_block_copy_data_ext *ext,
uint64_t bb_pos,
bool emit_bbe)
{
unsigned int ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
struct gen12_block_copy_data data = {};
struct gen12_block_copy_data_ext dext = {};
uint64_t dst_offset, src_offset, bb_offset;
uint32_t bbe = MI_BATCH_BUFFER_END;
uint8_t *bb;
igt_assert_f(ahnd, "block-copy supports softpin only\n");
igt_assert_f(blt, "block-copy requires data to do blit\n");
src_offset = get_offset_pat_index(ahnd, blt->src.handle, blt->src.size,
0, blt->src.pat_index);
src_offset += blt->src.plane_offset;
dst_offset = get_offset_pat_index(ahnd, blt->dst.handle, blt->dst.size,
0, blt->dst.pat_index);
dst_offset += blt->dst.plane_offset;
bb_offset = get_offset(ahnd, blt->bb.handle, blt->bb.size, 0);
fill_data(&data, blt, src_offset, dst_offset, ext, ip_ver);
bb = bo_map(fd, blt->bb.handle, blt->bb.size, blt->driver);
igt_assert(bb_pos + sizeof(data) < blt->bb.size);
memcpy(bb + bb_pos, &data, sizeof(data));
bb_pos += sizeof(data);
if (ext) {
fill_data_ext(&dext, ext);
igt_assert(bb_pos + sizeof(dext) < blt->bb.size);
memcpy(bb + bb_pos, &dext, sizeof(dext));
bb_pos += sizeof(dext);
}
if (emit_bbe) {
igt_assert(bb_pos + sizeof(uint32_t) < blt->bb.size);
memcpy(bb + bb_pos, &bbe, sizeof(bbe));
bb_pos += sizeof(uint32_t);
}
if (blt->print_bb) {
igt_info("[BLOCK COPY]\n");
igt_info("src offset: %" PRIx64 ", dst offset: %" PRIx64
", bb offset: %" PRIx64 "\n",
src_offset, dst_offset, bb_offset);
dump_bb_cmd(&data, ip_ver);
if (ext)
dump_bb_ext(&dext);
}
munmap(bb, blt->bb.size);
return bb_pos;
}
/**
* blt_block_copy:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @blt: basic blitter data (for TGL/DG1 which doesn't support ext version)
* @ext: extended blitter data (for DG2+, supports flatccs compression)
*
* Function does blit between @src and @dst described in @blt object.
*
* Returns:
* execbuffer status.
*/
int blt_block_copy(int fd,
const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_copy_data *blt,
const struct blt_block_copy_data_ext *ext)
{
struct drm_i915_gem_execbuffer2 execbuf = {};
struct drm_i915_gem_exec_object2 obj[3] = {};
uint64_t dst_offset, src_offset, bb_offset;
int ret;
igt_assert_f(ahnd, "block-copy supports softpin only\n");
igt_assert_f(blt, "block-copy requires data to do blit\n");
igt_assert_neq(blt->driver, 0);
src_offset = get_offset_pat_index(ahnd, blt->src.handle, blt->src.size,
0, blt->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, blt->dst.handle, blt->dst.size,
0, blt->dst.pat_index);
bb_offset = get_offset(ahnd, blt->bb.handle, blt->bb.size, 0);
emit_blt_block_copy(fd, ahnd, blt, ext, 0, true);
if (blt->driver == INTEL_DRIVER_XE) {
intel_ctx_xe_exec(ctx, ahnd, CANONICAL(bb_offset));
} else {
obj[0].offset = CANONICAL(dst_offset);
obj[1].offset = CANONICAL(src_offset);
obj[2].offset = CANONICAL(bb_offset);
obj[0].handle = blt->dst.handle;
obj[1].handle = blt->src.handle;
obj[2].handle = blt->bb.handle;
obj[0].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE |
EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[1].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[2].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
execbuf.buffer_count = 3;
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.rsvd1 = ctx ? ctx->id : 0;
execbuf.flags = e ? e->flags : I915_EXEC_BLT;
ret = __gem_execbuf(fd, &execbuf);
}
return ret;
}
/*
* Function calculates CCS bytes used for the surface. Size field in
* ctrl-surf-copy command struct is for Xe and Xe2 10-bit length, so caller
* has to divide ccs copy of bigger surfaces to couple of separate commands.
* This function returns total size of ccs data used for the surface.
*/
static uint32_t __ccs_size(int fd, const struct blt_ctrl_surf_copy_data *surf)
{
uint32_t src_size, dst_size;
uint16_t ccsratio = CCS_RATIO(fd);
src_size = surf->src.access_type == DIRECT_ACCESS ?
surf->src.size : surf->src.size / ccsratio;
dst_size = surf->dst.access_type == DIRECT_ACCESS ?
surf->dst.size : surf->dst.size / ccsratio;
igt_assert_f(src_size <= dst_size, "dst size must be >= src size for CCS copy\n");
return src_size;
}
struct gen12_ctrl_surf_copy_data {
struct {
uint32_t length: BITRANGE(0, 7);
uint32_t size_of_ctrl_copy: BITRANGE(8, 17);
uint32_t rsvd0: BITRANGE(18, 19);
uint32_t dst_access_type: BITRANGE(20, 20);
uint32_t src_access_type: BITRANGE(21, 21);
uint32_t opcode: BITRANGE(22, 28);
uint32_t client: BITRANGE(29, 31);
} dw00;
struct {
uint32_t src_address_lo;
} dw01;
struct {
uint32_t src_address_hi: BITRANGE(0, 24);
uint32_t pxp: BITRANGE(25, 25);
uint32_t src_mocs_index: BITRANGE(26, 31);
} dw02;
struct {
uint32_t dst_address_lo;
} dw03;
struct {
uint32_t dst_address_hi: BITRANGE(0, 24);
uint32_t pxp: BITRANGE(25, 25);
uint32_t dst_mocs_index: BITRANGE(26, 31);
} dw04;
};
struct xe2_ctrl_surf_copy_data {
struct {
uint32_t length: BITRANGE(0, 7);
uint32_t rsvd0: BITRANGE(8, 8);
uint32_t size_of_ctrl_copy: BITRANGE(9, 18);
uint32_t rsvd1: BITRANGE(19, 19);
uint32_t dst_access_type: BITRANGE(20, 20);
uint32_t src_access_type: BITRANGE(21, 21);
uint32_t opcode: BITRANGE(22, 28);
uint32_t client: BITRANGE(29, 31);
} dw00;
struct {
uint32_t src_address_lo;
} dw01;
struct {
uint32_t src_address_hi: BITRANGE(0, 24);
uint32_t pxp: BITRANGE(25, 27);
uint32_t src_mocs_index: BITRANGE(28, 31);
} dw02;
struct {
uint32_t dst_address_lo;
} dw03;
struct {
uint32_t dst_address_hi: BITRANGE(0, 24);
uint32_t pxp: BITRANGE(25, 27);
uint32_t dst_mocs_index: BITRANGE(28, 31);
} dw04;
};
union ctrl_surf_copy_data {
struct gen12_ctrl_surf_copy_data gen12;
struct xe2_ctrl_surf_copy_data xe2;
};
static void xe2_dump_bb_surf_ctrl_cmd(const struct xe2_ctrl_surf_copy_data *data)
{
uint32_t *cmd = (uint32_t *) data;
igt_info("details:\n");
igt_info(" dw00: [%08x] <client: 0x%x, opcode: 0x%x, "
"src/dst access type: <%d, %d>, size of ctrl copy: %u, length: %d>\n",
cmd[0],
data->dw00.client, data->dw00.opcode,
data->dw00.src_access_type, data->dw00.dst_access_type,
data->dw00.size_of_ctrl_copy, data->dw00.length);
igt_info(" dw01: [%08x] src offset lo (0x%x)\n",
cmd[1], data->dw01.src_address_lo);
igt_info(" dw02: [%08x] src offset hi (0x%x), src mocs idx: %u\n",
cmd[2], data->dw02.src_address_hi, data->dw02.src_mocs_index);
igt_info(" dw03: [%08x] dst offset lo (0x%x)\n",
cmd[3], data->dw03.dst_address_lo);
igt_info(" dw04: [%08x] dst offset hi (0x%x), src mocs idx: %u\n",
cmd[4], data->dw04.dst_address_hi, data->dw04.dst_mocs_index);
}
static void dump_bb_surf_ctrl_cmd(const struct gen12_ctrl_surf_copy_data *data)
{
uint32_t *cmd = (uint32_t *) data;
igt_info("details:\n");
igt_info(" dw00: [%08x] <client: 0x%x, opcode: 0x%x, "
"src/dst access type: <%d, %d>, size of ctrl copy: %u, length: %d>\n",
cmd[0],
data->dw00.client, data->dw00.opcode,
data->dw00.src_access_type, data->dw00.dst_access_type,
data->dw00.size_of_ctrl_copy, data->dw00.length);
igt_info(" dw01: [%08x] src offset lo (0x%x)\n",
cmd[1], data->dw01.src_address_lo);
igt_info(" dw02: [%08x] src offset hi (0x%x), src mocs idx: %u\n",
cmd[2], data->dw02.src_address_hi, data->dw02.src_mocs_index);
igt_info(" dw03: [%08x] dst offset lo (0x%x)\n",
cmd[3], data->dw03.dst_address_lo);
igt_info(" dw04: [%08x] dst offset hi (0x%x), dst mocs idx: %u\n",
cmd[4], data->dw04.dst_address_hi, data->dw04.dst_mocs_index);
}
/**
* blt_ctrl_surf_copy_init:
* @fd: drm fd
* @surf: structure for initialization
*
* Function is zeroing @surf and sets fd and driver fields (INTEL_DRIVER_I915 or
* INTEL_DRIVER_XE).
*/
void blt_ctrl_surf_copy_init(int fd, struct blt_ctrl_surf_copy_data *surf)
{
memset(surf, 0, sizeof(*surf));
surf->fd = fd;
surf->driver = get_intel_driver(fd);
}
/**
* emit_blt_ctrl_surf_copy:
* @fd: drm fd
* @ahnd: allocator handle
* @surf: blitter data for ctrl-surf-copy
* @bb_pos: position at which insert block copy commands
* @emit_bbe: emit MI_BATCH_BUFFER_END after ctrl-surf-copy or not
*
* Function emits ctrl-surf-copy blit between @src and @dst described in
* @blt object at @bb_pos. Allows concatenating with other commands to
* achieve pipelining.
*
* Returns:
* Next write position in batch.
*/
uint64_t emit_blt_ctrl_surf_copy(int fd,
uint64_t ahnd,
const struct blt_ctrl_surf_copy_data *surf,
uint64_t bb_pos,
bool emit_bbe)
{
unsigned int ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
union ctrl_surf_copy_data data = { };
size_t data_sz;
uint64_t dst_offset, src_offset, bb_offset, alignment;
uint32_t bbe = MI_BATCH_BUFFER_END;
uint32_t *bb;
uint32_t ccs_per_page, max_blocks, src_step, dst_step;
int32_t left_blocks;
igt_assert_f(ahnd, "ctrl-surf-copy supports softpin only\n");
igt_assert_f(surf, "ctrl-surf-copy requires data to do ctrl-surf-copy blit\n");
alignment = 1ull << 16;
src_offset = get_offset_pat_index(ahnd, surf->src.handle, surf->src.size,
alignment, surf->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, surf->dst.handle, surf->dst.size,
alignment, surf->dst.pat_index);
bb_offset = get_offset(ahnd, surf->bb.handle, surf->bb.size, alignment);
bb = bo_map(fd, surf->bb.handle, surf->bb.size, surf->driver);
/*
* Copying in/out CCS data is limited by bitfield size_of_ctrl_copy size
* what means operation on bigger surface needs to be handled on couple
* of ctrl-surf-copy commands.
*
* Instead of hardcoding maximum number of blocks copied in single
* command we may calculate it from bitfield size (Xe and Xe2 differs
* in bitfield location [and in future platforms potentially size]).
*/
if (ip_ver >= IP_VER(20, 0)) {
ccs_per_page = SZ_4K / CCS_RATIO(fd);
data.xe2.dw00.client = 0x2;
data.xe2.dw00.opcode = 0x48;
data.xe2.dw00.src_access_type = surf->src.access_type;
data.xe2.dw00.dst_access_type = surf->dst.access_type;
data.xe2.dw00.length = 0x3;
data.xe2.dw00.size_of_ctrl_copy = -1;
max_blocks = data.xe2.dw00.size_of_ctrl_copy + 1;
/*
* For Xe2+ each size_of_ctrl_copy increment covers 4K page size
* of surface, which in turn is covered by 8B of CCS data.
*/
src_step = surf->src.access_type == DIRECT_ACCESS ? ccs_per_page : SZ_4K;
src_step *= max_blocks;
dst_step = surf->dst.access_type == DIRECT_ACCESS ? ccs_per_page : SZ_4K;
dst_step *= max_blocks;
data.xe2.dw02.src_mocs_index = surf->src.mocs_index;
data.xe2.dw04.dst_mocs_index = surf->dst.mocs_index;
data_sz = sizeof(data.xe2);
} else {
ccs_per_page = SZ_64K / CCS_RATIO(fd);
data.gen12.dw00.client = 0x2;
data.gen12.dw00.opcode = 0x48;
data.gen12.dw00.src_access_type = surf->src.access_type;
data.gen12.dw00.dst_access_type = surf->dst.access_type;
data.gen12.dw00.length = 0x3;
data.gen12.dw00.size_of_ctrl_copy = -1;
max_blocks = data.gen12.dw00.size_of_ctrl_copy + 1;
/*
* For Xe each size_of_ctrl_copy increment covers 64K page size
* of surface, which in turn is covered by 256B of CCS data.
*/
src_step = surf->src.access_type == DIRECT_ACCESS ? ccs_per_page : SZ_64K;
src_step *= max_blocks;
dst_step = surf->dst.access_type == DIRECT_ACCESS ? ccs_per_page : SZ_64K;
dst_step *= max_blocks;
data.gen12.dw02.src_mocs_index = surf->src.mocs_index;
data.gen12.dw04.dst_mocs_index = surf->dst.mocs_index;
data_sz = sizeof(data.gen12);
}
left_blocks = __ccs_size(fd, surf) / ccs_per_page;
while (left_blocks > 0) {
int32_t nblocks = min_t(int32_t, left_blocks, max_blocks);
if (ip_ver >= IP_VER(20, 0)) {
data.xe2.dw00.size_of_ctrl_copy = nblocks - 1;
data.xe2.dw01.src_address_lo = src_offset;
data.xe2.dw02.src_address_hi = src_offset >> 32;
data.xe2.dw03.dst_address_lo = dst_offset;
data.xe2.dw04.dst_address_hi = dst_offset >> 32;
} else {
data.gen12.dw00.size_of_ctrl_copy = nblocks - 1;
data.gen12.dw01.src_address_lo = src_offset;
data.gen12.dw02.src_address_hi = src_offset >> 32;
data.gen12.dw03.dst_address_lo = dst_offset;
data.gen12.dw04.dst_address_hi = dst_offset >> 32;
}
left_blocks -= max_blocks;
dst_offset += dst_step;
src_offset += src_step;
igt_assert(bb_pos + data_sz < surf->bb.size);
memcpy(bb + bb_pos, &data, data_sz);
bb_pos += data_sz;
if (surf->print_bb) {
igt_info("[CTRL SURF]:\n");
igt_info("src offset: 0x%" PRIx64 ", dst offset: 0x%" PRIx64
", bb offset: 0x%" PRIx64 ", copy nblocks: 0x%x\n",
src_offset, dst_offset, bb_offset, nblocks);
if (ip_ver >= IP_VER(20, 0))
xe2_dump_bb_surf_ctrl_cmd(&data.xe2);
else
dump_bb_surf_ctrl_cmd(&data.gen12);
}
}
if (emit_bbe) {
igt_assert(bb_pos + sizeof(uint32_t) < surf->bb.size);
memcpy(bb + bb_pos, &bbe, sizeof(bbe));
bb_pos += sizeof(uint32_t);
}
munmap(bb, surf->bb.size);
return bb_pos;
}
/**
* blt_ctrl_surf_copy:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @surf: blitter data for ctrl-surf-copy
*
* Function does ctrl-surf-copy blit between @src and @dst described in
* @blt object.
*
* Returns:
* execbuffer status.
*/
int blt_ctrl_surf_copy(int fd,
const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_ctrl_surf_copy_data *surf)
{
struct drm_i915_gem_execbuffer2 execbuf = {};
struct drm_i915_gem_exec_object2 obj[3] = {};
uint64_t dst_offset, src_offset, bb_offset, alignment;
igt_assert_f(ahnd, "ctrl-surf-copy supports softpin only\n");
igt_assert_f(surf, "ctrl-surf-copy requires data to do ctrl-surf-copy blit\n");
igt_assert_neq(surf->driver, 0);
alignment = 1ull << 16;
src_offset = get_offset_pat_index(ahnd, surf->src.handle, surf->src.size,
alignment, surf->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, surf->dst.handle, surf->dst.size,
alignment, surf->dst.pat_index);
bb_offset = get_offset(ahnd, surf->bb.handle, surf->bb.size, alignment);
emit_blt_ctrl_surf_copy(fd, ahnd, surf, 0, true);
if (surf->driver == INTEL_DRIVER_XE) {
intel_ctx_xe_exec(ctx, ahnd, CANONICAL(bb_offset));
} else {
obj[0].offset = CANONICAL(dst_offset);
obj[1].offset = CANONICAL(src_offset);
obj[2].offset = CANONICAL(bb_offset);
obj[0].handle = surf->dst.handle;
obj[1].handle = surf->src.handle;
obj[2].handle = surf->bb.handle;
obj[0].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE |
EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[1].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[2].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
execbuf.buffer_count = 3;
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.flags = e ? e->flags : I915_EXEC_BLT;
execbuf.rsvd1 = ctx ? ctx->id : 0;
gem_execbuf(fd, &execbuf);
put_offset(ahnd, surf->dst.handle);
put_offset(ahnd, surf->src.handle);
put_offset(ahnd, surf->bb.handle);
}
return 0;
}
struct gen12_fast_copy_data {
struct {
uint32_t length: BITRANGE(0, 7);
uint32_t rsvd1: BITRANGE(8, 12);
uint32_t dst_tiling: BITRANGE(13, 14);
uint32_t rsvd0: BITRANGE(15, 19);
uint32_t src_tiling: BITRANGE(20, 21);
uint32_t opcode: BITRANGE(22, 28);
uint32_t client: BITRANGE(29, 31);
} dw00;
union {
struct {
uint32_t dst_pitch: BITRANGE(0, 15);
uint32_t rsvd1: BITRANGE(16, 23);
uint32_t color_depth: BITRANGE(24, 26);
uint32_t rsvd0: BITRANGE(27, 27);
uint32_t dst_memory: BITRANGE(28, 28);
uint32_t src_memory: BITRANGE(29, 29);
uint32_t dst_type_y: BITRANGE(30, 30);
uint32_t src_type_y: BITRANGE(31, 31);
} dw01;
struct {
uint32_t dst_pitch: BITRANGE(0, 15);
uint32_t rsvd0: BITRANGE(16, 16);
uint32_t pxp: BITRANGE(17, 17);
uint32_t rsvd1: BITRANGE(18, 19);
uint32_t dst_mocs_index: BITRANGE(20, 23);
uint32_t color_depth: BITRANGE(24, 26);
uint32_t rsvd2: BITRANGE(27, 29);
uint32_t dst_type_y: BITRANGE(30, 30);
uint32_t src_type_y: BITRANGE(31, 31);
} dw01_xe2;
};
struct {
int32_t dst_x1: BITRANGE(0, 15);
int32_t dst_y1: BITRANGE(16, 31);
} dw02;
struct {
int32_t dst_x2: BITRANGE(0, 15);
int32_t dst_y2: BITRANGE(16, 31);
} dw03;
struct {
uint32_t dst_address_lo;
} dw04;
struct {
uint32_t dst_address_hi;
} dw05;
struct {
int32_t src_x1: BITRANGE(0, 15);
int32_t src_y1: BITRANGE(16, 31);
} dw06;
union {
struct {
uint32_t src_pitch: BITRANGE(0, 15);
uint32_t rsvd0: BITRANGE(16, 31);
} dw07;
struct {
uint32_t src_pitch: BITRANGE(0, 15);
uint32_t rsvd0: BITRANGE(16, 16);
uint32_t pxp: BITRANGE(17, 17);
uint32_t rsvd1: BITRANGE(18, 19);
uint32_t src_mocs_index: BITRANGE(20, 23);
uint32_t rsvd2: BITRANGE(24, 31);
} dw07_xe2;
};
struct {
uint32_t src_address_lo;
} dw08;
struct {
uint32_t src_address_hi;
} dw09;
};
static int __fast_tiling(enum blt_tiling_type tiling)
{
switch (tiling) {
case T_LINEAR: return 0;
case T_XMAJOR: return 1;
case T_YMAJOR: return 2;
case T_TILE4: return 2;
case T_YFMAJOR: return 2;
case T_TILE64: return 3;
default:
break;
}
igt_warn("invalid tiling passed: %d\n", tiling);
return 0;
}
static int __fast_color_depth(enum blt_color_depth depth)
{
switch (depth) {
case CD_8bit: return 0;
case CD_16bit: return 1;
case CD_32bit: return 3;
case CD_64bit: return 4;
case CD_96bit:
igt_assert_f(0, "Unsupported depth\n");
break;
case CD_128bit: return 5;
};
return 0;
}
static void dump_bb_fast_cmd(struct gen12_fast_copy_data *data)
{
uint32_t *cmd = (uint32_t *) data;
igt_info("BB details:\n");
igt_info(" dw00: [%08x] <client: 0x%x, opcode: 0x%x, src tiling: %d, "
"dst tiling: %d, length: %d>\n",
cmd[0], data->dw00.client, data->dw00.opcode,
data->dw00.src_tiling, data->dw00.dst_tiling, data->dw00.length);
igt_info(" dw01: [%08x] dst <pitch: %d, color depth: %d, dst memory: %d, "
"src memory: %d,\n"
"\t\t\tdst type tile: %d (0-legacy, 1-tile4),\n"
"\t\t\tsrc type tile: %d (0-legacy, 1-tile4)>\n",
cmd[1], data->dw01.dst_pitch, data->dw01.color_depth,
data->dw01.dst_memory, data->dw01.src_memory,
data->dw01.dst_type_y, data->dw01.src_type_y);
igt_info(" dw02: [%08x] dst geom <x1: %d, y1: %d>\n",
cmd[2], data->dw02.dst_x1, data->dw02.dst_y1);
igt_info(" dw03: [%08x] <x2: %d, y2: %d>\n",
cmd[3], data->dw03.dst_x2, data->dw03.dst_y2);
igt_info(" dw04: [%08x] dst offset lo (0x%x)\n",
cmd[4], data->dw04.dst_address_lo);
igt_info(" dw05: [%08x] dst offset hi (0x%x)\n",
cmd[5], data->dw05.dst_address_hi);
igt_info(" dw06: [%08x] src geom <x1: %d, y1: %d>\n",
cmd[6], data->dw06.src_x1, data->dw06.src_y1);
igt_info(" dw07: [%08x] src <pitch: %d>\n",
cmd[7], data->dw07.src_pitch);
igt_info(" dw08: [%08x] src offset lo (0x%x)\n",
cmd[8], data->dw08.src_address_lo);
igt_info(" dw09: [%08x] src offset hi (0x%x)\n",
cmd[9], data->dw09.src_address_hi);
}
/**
* emit_blt_fast_copy:
* @fd: drm fd
* @ahnd: allocator handle
* @blt: blitter data for fast-copy (same as for block-copy but doesn't use
* compression fields).
* @bb_pos: position at which insert block copy commands
* @emit_bbe: emit MI_BATCH_BUFFER_END after fast-copy or not
*
* Function emits fast-copy blit between @src and @dst described in @blt object
* at @bb_pos. Allows concatenating with other commands to
* achieve pipelining.
*
* Returns:
* Next write position in batch.
*/
uint64_t emit_blt_fast_copy(int fd,
uint64_t ahnd,
const struct blt_copy_data *blt,
uint64_t bb_pos,
bool emit_bbe)
{
unsigned int ip_ver = intel_graphics_ver(intel_get_drm_devid(fd));
struct gen12_fast_copy_data data = {};
uint64_t dst_offset, src_offset, bb_offset;
uint32_t bbe = MI_BATCH_BUFFER_END;
uint32_t *bb;
data.dw00.client = 0x2;
data.dw00.opcode = 0x42;
data.dw00.dst_tiling = __fast_tiling(blt->dst.tiling);
data.dw00.src_tiling = __fast_tiling(blt->src.tiling);
data.dw00.length = 8;
if (ip_ver >= IP_VER(20, 0)) {
data.dw01_xe2.dst_pitch = blt->dst.pitch;
data.dw01_xe2.dst_mocs_index = blt->dst.mocs_index;
data.dw01_xe2.color_depth = __fast_color_depth(blt->color_depth);
/* Undefined behavior to leave as 0, must be set to 1 */
data.dw01_xe2.dst_type_y = 1;
data.dw01_xe2.src_type_y = 1;
} else {
data.dw01.dst_pitch = blt->dst.pitch;
data.dw01.color_depth = __fast_color_depth(blt->color_depth);
data.dw01.dst_memory = __memory_type(blt->fd, blt->driver, blt->dst.region);
data.dw01.src_memory = __memory_type(blt->fd, blt->driver, blt->src.region);
data.dw01.dst_type_y = __new_tile_y_type(blt->dst.tiling) ? 1 : 0;
data.dw01.src_type_y = __new_tile_y_type(blt->src.tiling) ? 1 : 0;
}
data.dw02.dst_x1 = blt->dst.x1;
data.dw02.dst_y1 = blt->dst.y1;
data.dw03.dst_x2 = blt->dst.x2;
data.dw03.dst_y2 = blt->dst.y2;
src_offset = get_offset_pat_index(ahnd, blt->src.handle, blt->src.size,
0, blt->src.pat_index);
src_offset += blt->src.plane_offset;
dst_offset = get_offset_pat_index(ahnd, blt->dst.handle, blt->dst.size, 0,
blt->dst.pat_index);
dst_offset += blt->dst.plane_offset;
bb_offset = get_offset(ahnd, blt->bb.handle, blt->bb.size, 0);
data.dw04.dst_address_lo = dst_offset;
data.dw05.dst_address_hi = dst_offset >> 32;
data.dw06.src_x1 = blt->src.x1;
data.dw06.src_y1 = blt->src.y1;
if (ip_ver >= IP_VER(20, 0)) {
data.dw07_xe2.src_pitch = blt->src.pitch;
data.dw07_xe2.src_mocs_index = blt->src.mocs_index;
} else {
data.dw07.src_pitch = blt->src.pitch;
}
data.dw08.src_address_lo = src_offset;
data.dw09.src_address_hi = src_offset >> 32;
bb = bo_map(fd, blt->bb.handle, blt->bb.size, blt->driver);
igt_assert(bb_pos + sizeof(data) < blt->bb.size);
memcpy(bb + bb_pos, &data, sizeof(data));
bb_pos += sizeof(data);
if (emit_bbe) {
igt_assert(bb_pos + sizeof(uint32_t) < blt->bb.size);
memcpy(bb + bb_pos, &bbe, sizeof(bbe));
bb_pos += sizeof(uint32_t);
}
if (blt->print_bb) {
igt_info("[FAST COPY]\n");
igt_info("src offset: %" PRIx64 ", dst offset: %" PRIx64
", bb offset: %" PRIx64 "\n",
src_offset, dst_offset, bb_offset);
dump_bb_fast_cmd(&data);
}
munmap(bb, blt->bb.size);
return bb_pos;
}
/**
* blt_fast_copy:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @blt: blitter data for fast-copy (same as for block-copy but doesn't use
* compression fields).
*
* Function does fast blit between @src and @dst described in @blt object.
*
* Returns:
* execbuffer status.
*/
int blt_fast_copy(int fd,
const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_copy_data *blt)
{
struct drm_i915_gem_execbuffer2 execbuf = {};
struct drm_i915_gem_exec_object2 obj[3] = {};
uint64_t dst_offset, src_offset, bb_offset;
int ret;
igt_assert_f(ahnd, "fast-copy supports softpin only\n");
igt_assert_f(blt, "fast-copy requires data to do fast-copy blit\n");
igt_assert_neq(blt->driver, 0);
src_offset = get_offset_pat_index(ahnd, blt->src.handle, blt->src.size,
0, blt->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, blt->dst.handle, blt->dst.size,
0, blt->dst.pat_index);
bb_offset = get_offset(ahnd, blt->bb.handle, blt->bb.size, 0);
emit_blt_fast_copy(fd, ahnd, blt, 0, true);
if (blt->driver == INTEL_DRIVER_XE) {
intel_ctx_xe_exec(ctx, ahnd, CANONICAL(bb_offset));
} else {
obj[0].offset = CANONICAL(dst_offset);
obj[1].offset = CANONICAL(src_offset);
obj[2].offset = CANONICAL(bb_offset);
obj[0].handle = blt->dst.handle;
obj[1].handle = blt->src.handle;
obj[2].handle = blt->bb.handle;
obj[0].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE |
EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[1].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[2].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
execbuf.buffer_count = 3;
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.rsvd1 = ctx ? ctx->id : 0;
execbuf.flags = e ? e->flags : I915_EXEC_BLT;
ret = __gem_execbuf(fd, &execbuf);
put_offset(ahnd, blt->dst.handle);
put_offset(ahnd, blt->src.handle);
put_offset(ahnd, blt->bb.handle);
}
return ret;
}
/**
* blt_mem_init:
* @fd: drm fd
* @mem: structure for initialization
*
* Function is zeroing @mem and sets fd and driver fields (INTEL_DRIVER_I915 or
* INTEL_DRIVER_XE).
*/
void blt_mem_init(int fd, struct blt_mem_data *mem)
{
memset(mem, 0, sizeof(*mem));
mem->fd = fd;
mem->driver = get_intel_driver(fd);
}
static void emit_blt_mem_copy(int fd, uint64_t ahnd, const struct blt_mem_data *mem)
{
uint64_t dst_offset, src_offset;
int i;
uint32_t *batch;
uint32_t optype;
src_offset = get_offset_pat_index(ahnd, mem->src.handle, mem->src.size,
0, mem->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, mem->dst.handle, mem->dst.size,
0, mem->dst.pat_index);
batch = bo_map(fd, mem->bb.handle, mem->bb.size, mem->driver);
optype = mem->src.type == M_MATRIX ? 1 << 17 : 0;
i = 0;
batch[i++] = MEM_COPY_CMD | optype;
batch[i++] = mem->src.width - 1;
batch[i++] = mem->src.height - 1;
batch[i++] = mem->src.pitch - 1;
batch[i++] = mem->dst.pitch - 1;
batch[i++] = src_offset;
batch[i++] = src_offset << 32;
batch[i++] = dst_offset;
batch[i++] = dst_offset << 32;
batch[i++] = mem->src.mocs_index << MEM_COPY_MOCS_SHIFT | mem->dst.mocs_index;
batch[i++] = MI_BATCH_BUFFER_END;
munmap(batch, mem->bb.size);
}
/**
* blt_mem_copy:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @blt: blitter data for mem-copy.
*
* Function does mem blit between @src and @dst described in @blt object.
*
* Returns:
* execbuffer status.
*/
int blt_mem_copy(int fd, const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_mem_data *mem)
{
struct drm_i915_gem_execbuffer2 execbuf = {};
struct drm_i915_gem_exec_object2 obj[3] = {};
uint64_t dst_offset, src_offset, bb_offset;
int ret;
src_offset = get_offset_pat_index(ahnd, mem->src.handle, mem->src.size,
0, mem->src.pat_index);
dst_offset = get_offset_pat_index(ahnd, mem->dst.handle, mem->dst.size,
0, mem->dst.pat_index);
bb_offset = get_offset(ahnd, mem->bb.handle, mem->bb.size, 0);
emit_blt_mem_copy(fd, ahnd, mem);
if (mem->driver == INTEL_DRIVER_XE) {
intel_ctx_xe_exec(ctx, ahnd, CANONICAL(bb_offset));
} else {
obj[0].offset = CANONICAL(dst_offset);
obj[1].offset = CANONICAL(src_offset);
obj[2].offset = CANONICAL(bb_offset);
obj[0].handle = mem->dst.handle;
obj[1].handle = mem->src.handle;
obj[2].handle = mem->bb.handle;
obj[0].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE |
EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[1].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[2].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
execbuf.buffer_count = 3;
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.rsvd1 = ctx ? ctx->id : 0;
execbuf.flags = e ? e->flags : I915_EXEC_BLT;
ret = __gem_execbuf(fd, &execbuf);
put_offset(ahnd, mem->dst.handle);
put_offset(ahnd, mem->src.handle);
put_offset(ahnd, mem->bb.handle);
}
return ret;
}
static void emit_blt_mem_set(int fd, uint64_t ahnd, const struct blt_mem_data *mem,
uint8_t fill_data)
{
uint64_t dst_offset;
int b;
uint32_t *batch;
uint32_t value;
dst_offset = get_offset_pat_index(ahnd, mem->dst.handle, mem->dst.size,
0, mem->dst.pat_index);
batch = bo_map(fd, mem->bb.handle, mem->bb.size, mem->driver);
value = (uint32_t)fill_data << 24;
b = 0;
batch[b++] = MEM_SET_CMD;
batch[b++] = mem->dst.width - 1;
batch[b++] = mem->dst.height - 1;
batch[b++] = mem->dst.pitch - 1;
batch[b++] = dst_offset;
batch[b++] = dst_offset << 32;
batch[b++] = value | mem->dst.mocs_index;
batch[b++] = MI_BATCH_BUFFER_END;
munmap(batch, mem->bb.size);
}
/**
* blt_mem_set:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @blt: blitter data for mem-set.
*
* Function does mem set blit in described @blt object.
*
* Returns:
* execbuffer status.
*/
int blt_mem_set(int fd, const intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_mem_data *mem,
uint8_t fill_data)
{
struct drm_i915_gem_execbuffer2 execbuf = {};
struct drm_i915_gem_exec_object2 obj[2] = {};
uint64_t dst_offset, bb_offset;
int ret;
dst_offset = get_offset_pat_index(ahnd, mem->dst.handle, mem->dst.size,
0, mem->dst.pat_index);
bb_offset = get_offset(ahnd, mem->bb.handle, mem->bb.size, 0);
emit_blt_mem_set(fd, ahnd, mem, fill_data);
if (mem->driver == INTEL_DRIVER_XE) {
intel_ctx_xe_exec(ctx, ahnd, CANONICAL(bb_offset));
} else {
obj[0].offset = CANONICAL(dst_offset);
obj[1].offset = CANONICAL(bb_offset);
obj[0].handle = mem->dst.handle;
obj[1].handle = mem->bb.handle;
obj[0].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_WRITE |
EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
obj[1].flags = EXEC_OBJECT_PINNED | EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
execbuf.buffer_count = 2;
execbuf.buffers_ptr = to_user_pointer(obj);
execbuf.rsvd1 = ctx ? ctx->id : 0;
execbuf.flags = e ? e->flags : I915_EXEC_BLT;
ret = __gem_execbuf(fd, &execbuf);
put_offset(ahnd, mem->dst.handle);
put_offset(ahnd, mem->bb.handle);
}
return ret;
}
void blt_set_geom(struct blt_copy_object *obj, uint32_t pitch,
int16_t x1, int16_t y1, int16_t x2, int16_t y2,
uint16_t x_offset, uint16_t y_offset)
{
obj->pitch = pitch;
obj->x1 = x1;
obj->y1 = y1;
obj->x2 = x2;
obj->y2 = y2;
obj->x_offset = x_offset;
obj->y_offset = y_offset;
}
void blt_set_batch(struct blt_copy_batch *batch,
uint32_t handle, uint64_t size, uint32_t region)
{
batch->handle = handle;
batch->size = size;
batch->region = region;
}
struct blt_copy_object *
blt_create_object(const struct blt_copy_data *blt, uint32_t region,
uint32_t width, uint32_t height, uint32_t bpp, uint8_t mocs_index,
enum blt_tiling_type tiling,
enum blt_compression compression,
enum blt_compression_type compression_type,
bool create_mapping)
{
struct blt_copy_object *obj;
uint32_t stride, aligned_height;
uint64_t size;
uint32_t handle;
uint8_t pat_index = DEFAULT_PAT_INDEX;
igt_assert_f(blt->driver, "Driver isn't set, have you called blt_copy_init()?\n");
stride = blt_get_min_stride(width, bpp, tiling);
aligned_height = blt_get_aligned_height(height, bpp, tiling);
size = stride * aligned_height;
/* blitter command expects stride in dwords on tiled surfaces */
if (tiling)
stride /= 4;
obj = calloc(1, sizeof(*obj));
obj->size = size;
if (blt->driver == INTEL_DRIVER_XE) {
uint64_t flags = 0;
uint16_t cpu_caching = __xe_default_cpu_caching(blt->fd, region, flags);
if (create_mapping && region != system_memory(blt->fd))
flags |= DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM;
if (intel_gen(intel_get_drm_devid(blt->fd)) >= 20 && compression) {
pat_index = intel_get_pat_idx_uc_comp(blt->fd);
cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
}
size = ALIGN(size, xe_get_default_alignment(blt->fd));
handle = xe_bo_create_caching(blt->fd, 0, size, region, flags, cpu_caching);
} else {
igt_assert(__gem_create_in_memory_regions(blt->fd, &handle,
&size, region) == 0);
}
blt_set_object(obj, handle, size, region, mocs_index, pat_index, tiling,
compression, compression_type);
blt_set_geom(obj, stride, 0, 0, width, height, 0, 0);
if (create_mapping)
obj->ptr = bo_map(blt->fd, handle, size, blt->driver);
return obj;
}
static void __blt_destroy_object(int fd, uint64_t ahnd, struct blt_copy_object *obj)
{
if (obj->ptr)
munmap(obj->ptr, obj->size);
gem_close(fd, obj->handle);
if (ahnd)
intel_allocator_free(ahnd, obj->handle);
free(obj);
}
void blt_destroy_object(int fd, struct blt_copy_object *obj)
{
__blt_destroy_object(fd, 0, obj);
}
void blt_destroy_object_and_alloc_free(int fd, uint64_t ahnd,
struct blt_copy_object *obj)
{
__blt_destroy_object(fd, ahnd, obj);
}
void blt_set_object(struct blt_copy_object *obj,
uint32_t handle, uint64_t size, uint32_t region,
uint8_t mocs_index, uint8_t pat_index, enum blt_tiling_type tiling,
enum blt_compression compression,
enum blt_compression_type compression_type)
{
obj->handle = handle;
obj->size = size;
obj->region = region;
obj->mocs_index = mocs_index;
obj->pat_index = pat_index;
obj->tiling = tiling;
obj->compression = compression;
obj->compression_type = compression_type;
}
void blt_set_mem_object(struct blt_mem_object *obj,
uint32_t handle, uint64_t size, uint32_t pitch,
uint32_t width, uint32_t height, uint32_t region,
uint8_t mocs_index, uint8_t pat_index,
enum blt_memop_type type, enum blt_compression compression)
{
obj->handle = handle;
obj->region = region;
obj->size = size;
obj->mocs_index = mocs_index;
obj->pat_index = pat_index;
obj->type = type;
obj->compression = compression;
obj->width = width;
obj->height = height;
obj->pitch = pitch;
}
void blt_set_object_ext(struct blt_block_copy_object_ext *obj,
uint8_t compression_format,
uint16_t surface_width, uint16_t surface_height,
enum blt_surface_type surface_type)
{
obj->compression_format = compression_format;
obj->surface_width = surface_width;
obj->surface_height = surface_height;
obj->surface_type = surface_type;
/* Ensure mip tail won't overlap lod */
obj->mip_tail_start_lod = 0xf;
}
void blt_set_copy_object(struct blt_copy_object *obj,
const struct blt_copy_object *orig)
{
memcpy(obj, orig, sizeof(*obj));
}
void blt_set_ctrl_surf_object(struct blt_ctrl_surf_copy_object *obj,
uint32_t handle, uint32_t region, uint64_t size,
uint8_t mocs_index, uint8_t pat_index,
enum blt_access_type access_type)
{
obj->handle = handle;
obj->region = region;
obj->size = size;
obj->mocs_index = mocs_index;
obj->pat_index = pat_index;
obj->access_type = access_type;
}
/**
* blt_surface_fill_rect:
* @fd: drm fd
* @obj: blitter copy object (@blt_copy_object) to fill with gradient pattern
* @width: width
* @height: height
*
* Function fills surface @width x @height * 24bpp with color gradient
* (internally uses ARGB where A == 0xff, see Cairo docs).
*/
void blt_surface_fill_rect(int fd, const struct blt_copy_object *obj,
uint32_t width, uint32_t height)
{
cairo_surface_t *surface;
cairo_pattern_t *pat;
cairo_t *cr;
void *map = obj->ptr;
if (!map)
map = gem_mmap__device_coherent(fd, obj->handle, 0,
obj->size, PROT_READ | PROT_WRITE);
surface = cairo_image_surface_create_for_data(map,
CAIRO_FORMAT_RGB24,
width, height,
obj->pitch);
cr = cairo_create(surface);
cairo_rectangle(cr, 0, 0, width, height);
cairo_clip(cr);
pat = cairo_pattern_create_mesh();
cairo_mesh_pattern_begin_patch(pat);
cairo_mesh_pattern_move_to(pat, 0, 0);
cairo_mesh_pattern_line_to(pat, width, 0);
cairo_mesh_pattern_line_to(pat, width, height);
cairo_mesh_pattern_line_to(pat, 0, height);
cairo_mesh_pattern_set_corner_color_rgb(pat, 0, 1.0, 0.0, 0.0);
cairo_mesh_pattern_set_corner_color_rgb(pat, 1, 0.0, 1.0, 0.0);
cairo_mesh_pattern_set_corner_color_rgb(pat, 2, 0.0, 0.0, 1.0);
cairo_mesh_pattern_set_corner_color_rgb(pat, 3, 1.0, 1.0, 1.0);
cairo_mesh_pattern_end_patch(pat);
cairo_rectangle(cr, 0, 0, width, height);
cairo_set_source(cr, pat);
cairo_fill(cr);
cairo_pattern_destroy(pat);
cairo_destroy(cr);
cairo_surface_destroy(surface);
if (!obj->ptr)
munmap(map, obj->size);
}
/**
* blt_surface_info:
* @info: information header
* @obj: blitter copy object (@blt_copy_object) to print surface info
*/
void blt_surface_info(const char *info, const struct blt_copy_object *obj)
{
igt_info("[%s]\n", info);
igt_info("surface <handle: %u, size: %llx, region: %x, mocs_idx: %x>\n",
obj->handle, (long long) obj->size, obj->region, obj->mocs_index);
igt_info(" <tiling: %s, compression: %u, compression type: %d>\n",
blt_tiling_name(obj->tiling), obj->compression, obj->compression_type);
igt_info(" <pitch: %u, offset [x: %u, y: %u] geom [<%d,%d> <%d,%d>]>\n",
obj->pitch, obj->x_offset, obj->y_offset,
obj->x1, obj->y1, obj->x2, obj->y2);
}
/**
* blt_surface_get_flatccs_data:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @obj: object from which flatccs data will be extracted
*
* Function executes ctrl-surf-copy to extract object ccs data from flatccs
* area. Memory for the result ccs data are allocated in the function and must
* be freed by the caller.
*/
void blt_surface_get_flatccs_data(int fd,
intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_copy_object *obj,
uint32_t **ccsptr, uint64_t *sizeptr)
{
struct blt_ctrl_surf_copy_data surf = {};
uint32_t bb, ccs, *ccsmap;
uint64_t bb_size, ccssize = obj->size / CCS_RATIO(fd);
uint32_t *ccscopy;
uint32_t sysmem;
uint8_t uc_mocs = intel_get_uc_mocs_index(fd);
uint8_t comp_pat_index = DEFAULT_PAT_INDEX;
igt_assert(ccsptr);
igt_assert(sizeptr);
blt_ctrl_surf_copy_init(fd, &surf);
ccscopy = (uint32_t *)malloc(ccssize);
igt_assert(ccscopy);
if (surf.driver == INTEL_DRIVER_XE) {
uint16_t cpu_caching;
uint64_t ccs_bo_size;
sysmem = system_memory(fd);
cpu_caching = __xe_default_cpu_caching(fd, sysmem, 0);
ccs_bo_size = ALIGN(ccssize, xe_get_default_alignment(fd));
if (intel_gen(intel_get_drm_devid(fd)) >= 20 && obj->compression) {
comp_pat_index = intel_get_pat_idx_uc_comp(fd);
cpu_caching = DRM_XE_GEM_CPU_CACHING_WC;
}
ccs = xe_bo_create_caching(fd, 0, ccs_bo_size, sysmem, 0, cpu_caching);
bb_size = xe_bb_size(fd, SZ_4K);
bb = xe_bo_create(fd, 0, bb_size, sysmem, 0);
} else {
sysmem = REGION_SMEM;
ccs = gem_create(fd, ccssize);
bb_size = 4096;
igt_assert_eq(__gem_create(fd, &bb_size, &bb), 0);
}
blt_set_ctrl_surf_object(&surf.src, obj->handle, obj->region, obj->size,
uc_mocs, comp_pat_index, BLT_INDIRECT_ACCESS);
blt_set_ctrl_surf_object(&surf.dst, ccs, sysmem, ccssize, uc_mocs,
DEFAULT_PAT_INDEX, DIRECT_ACCESS);
blt_set_batch(&surf.bb, bb, bb_size, sysmem);
blt_ctrl_surf_copy(fd, ctx, e, ahnd, &surf);
if (surf.driver == INTEL_DRIVER_XE) {
intel_ctx_xe_sync(ctx, true);
ccsmap = xe_bo_map(fd, ccs, surf.dst.size);
} else {
gem_sync(fd, surf.dst.handle);
ccsmap = gem_mmap__device_coherent(fd, ccs, 0, surf.dst.size,
PROT_READ | PROT_WRITE);
}
memcpy(ccscopy, ccsmap, ccssize);
munmap(ccsmap, surf.dst.size);
gem_close(fd, ccs);
gem_close(fd, bb);
put_offset(ahnd, ccs);
put_offset(ahnd, bb);
if (surf.driver == INTEL_DRIVER_XE)
intel_allocator_bind(ahnd, 0, 0);
*ccsptr = ccscopy;
*sizeptr = ccssize;
}
/**
* blt_surface_is_compressed:
* @fd: drm fd
* @ctx: intel_ctx_t context
* @e: blitter engine for @ctx
* @ahnd: allocator handle
* @obj: object to check
*
* Function extracts object ccs data and check it contains any non-zero
* value what means surface is compressed. Returns true if it is, otherwise
* false.
*/
bool blt_surface_is_compressed(int fd,
intel_ctx_t *ctx,
const struct intel_execution_engine2 *e,
uint64_t ahnd,
const struct blt_copy_object *obj)
{
uint64_t size;
uint32_t *ptr;
bool is_compressed = false;
blt_surface_get_flatccs_data(fd, ctx, e, ahnd, obj, &ptr, &size);
for (int i = 0; i < size / sizeof(*ptr); i++) {
if (ptr[i] != 0) {
is_compressed = true;
break;
}
}
free(ptr);
return is_compressed;
}
/**
* blt_surface_to_png:
* @fd: drm fd
* @run_id: prefix id to allow grouping files stored from single run
* @fileid: file identifier
* @obj: blitter copy object (@blt_copy_object) to save to png
* @width: width
* @height: height
* @bpp: bits per pixel
*
* Function save surface to png file. Assumes ARGB format where A == 0xff.
*/
void blt_surface_to_png(int fd, uint32_t run_id, const char *fileid,
const struct blt_copy_object *obj,
uint32_t width, uint32_t height, uint32_t bpp)
{
cairo_surface_t *surface;
cairo_status_t ret;
uint32_t dump_width = width, dump_height = height;
uint8_t *map = (uint8_t *) obj->ptr;
int format;
int stride = obj->tiling ? obj->pitch * 4 : obj->pitch;
char filename[FILENAME_MAX];
bool is_xe = is_xe_device(fd);
if (obj->tiling) {
dump_width = obj->pitch;
dump_height = blt_get_aligned_height(height, bpp, obj->tiling);
}
snprintf(filename, FILENAME_MAX-1, "%d-%s-%s-%ux%u-%s.png",
run_id, fileid, blt_tiling_name(obj->tiling), width, height,
obj->compression ? "compressed" : "uncompressed");
if (!map) {
if (is_xe)
map = xe_bo_map(fd, obj->handle, obj->size);
else
map = gem_mmap__device_coherent(fd, obj->handle, 0,
obj->size, PROT_READ);
}
format = CAIRO_FORMAT_RGB24;
surface = cairo_image_surface_create_for_data(map, format,
dump_width, dump_height,
stride);
ret = cairo_surface_write_to_png(surface, filename);
if (ret)
igt_info("Cairo ret: %d (%s)\n", ret, cairo_status_to_string(ret));
igt_assert(ret == CAIRO_STATUS_SUCCESS);
cairo_surface_destroy(surface);
if (!obj->ptr)
munmap(map, obj->size);
}
static int compare_nxn(const struct blt_copy_object *surf1,
const struct blt_copy_object *surf2,
int xsize, int ysize, int bx, int by)
{
int x, y, corrupted;
uint32_t pos, px1, px2;
corrupted = 0;
for (y = 0; y < ysize; y++) {
for (x = 0; x < xsize; x++) {
pos = bx * xsize + by * ysize * surf1->pitch / 4;
pos += x + y * surf1->pitch / 4;
px1 = surf1->ptr[pos];
px2 = surf2->ptr[pos];
if (px1 != px2)
corrupted++;
}
}
return corrupted;
}
/**
* blt_dump_corruption_info_32b:
* @surf1: first surface
* @surf2: second surface
*
* Function dumps ascii representation of the surfaces corruption. Comparison
* is performed on 8x8 32bpp color pixel blocks. Number of differences on
* such block varies from 0 (no corruption) to 64 (pixels on those surfaces
* differs). It is added then to '0' ascii character to point the corruption
* occurred, for non affected block '.' is printed out.
*
* Idea of this function is to determine character of the differences between
* two surfaces without generating difference image.
*
* Currently function assumes both @surf1 and @surf2 are 32-bit color surfaces.
*/
void blt_dump_corruption_info_32b(const struct blt_copy_object *surf1,
const struct blt_copy_object *surf2)
{
const int xsize = 8, ysize = 8;
int w, h, bx, by, corrupted;
igt_assert(surf1->x1 == surf2->x1 && surf1->x2 == surf2->x2);
igt_assert(surf1->y1 == surf2->y1 && surf1->y2 == surf2->y2);
w = surf1->x2;
h = surf1->y2;
igt_info("dump corruption - width: %d, height: %d, sizex: %x, sizey: %x\n",
surf1->x2, surf1->y2, xsize, ysize);
for (by = 0; by < h / ysize; by++) {
for (bx = 0; bx < w / xsize; bx++) {
corrupted = compare_nxn(surf1, surf2, xsize, ysize, bx, by);
if (corrupted == 0)
igt_info(".");
else
igt_info("%c", '0' + corrupted);
}
igt_info("\n");
}
}
|