16c49df92SRodrigo Siqueira======================== 26c49df92SRodrigo SiqueiraMultiplane Overlay (MPO) 36c49df92SRodrigo Siqueira======================== 46c49df92SRodrigo Siqueira 56c49df92SRodrigo Siqueira.. note:: You will get more from this page if you have already read the 66c49df92SRodrigo Siqueira 'Documentation/gpu/amdgpu/display/dcn-overview.rst'. 76c49df92SRodrigo Siqueira 86c49df92SRodrigo Siqueira 96c49df92SRodrigo SiqueiraMultiplane Overlay (MPO) allows for multiple framebuffers to be composited via 106c49df92SRodrigo Siqueirafixed-function hardware in the display controller rather than using graphics or 116c49df92SRodrigo Siqueiracompute shaders for composition. This can yield some power savings if it means 126c49df92SRodrigo Siqueirathe graphics/compute pipelines can be put into low-power states. In summary, 136c49df92SRodrigo SiqueiraMPO can bring the following benefits: 146c49df92SRodrigo Siqueira 156c49df92SRodrigo Siqueira* Decreased GPU and CPU workload - no composition shaders needed, no extra 166c49df92SRodrigo Siqueira buffer copy needed, GPU can remain idle. 176c49df92SRodrigo Siqueira* Plane independent page flips - No need to be tied to global compositor 186c49df92SRodrigo Siqueira page-flip present rate, reduced latency, independent timing. 196c49df92SRodrigo Siqueira 206c49df92SRodrigo Siqueira.. note:: Keep in mind that MPO is all about power-saving; if you want to learn 216c49df92SRodrigo Siqueira more about power-save in the display context, check the link: 226c49df92SRodrigo Siqueira `Power <https://gitlab.freedesktop.org/pq/color-and-hdr/-/blob/main/doc/power.rst>`__. 236c49df92SRodrigo Siqueira 246c49df92SRodrigo SiqueiraMultiplane Overlay is only available using the DRM atomic model. The atomic 256c49df92SRodrigo Siqueiramodel only uses a single userspace IOCTL for configuring the display hardware 266c49df92SRodrigo Siqueira(modesetting, page-flipping, etc) - drmModeAtomicCommit. To query hardware 276c49df92SRodrigo Siqueiraresources and limitations userspace also calls into drmModeGetResources which 286c49df92SRodrigo Siqueirareports back the number of planes, CRTCs, and connectors. There are three types 296c49df92SRodrigo Siqueiraof DRM planes that the driver can register and work with: 306c49df92SRodrigo Siqueira 316c49df92SRodrigo Siqueira* ``DRM_PLANE_TYPE_PRIMARY``: Primary planes represent a "main" plane for a 326c49df92SRodrigo Siqueira CRTC, primary planes are the planes operated upon by CRTC modesetting and 336c49df92SRodrigo Siqueira flipping operations. 346c49df92SRodrigo Siqueira* ``DRM_PLANE_TYPE_CURSOR``: Cursor planes represent a "cursor" plane for a 356c49df92SRodrigo Siqueira CRTC. Cursor planes are the planes operated upon by the cursor IOCTLs 366c49df92SRodrigo Siqueira* ``DRM_PLANE_TYPE_OVERLAY``: Overlay planes represent all non-primary, 376c49df92SRodrigo Siqueira non-cursor planes. Some drivers refer to these types of planes as "sprites" 386c49df92SRodrigo Siqueira internally. 396c49df92SRodrigo Siqueira 406c49df92SRodrigo SiqueiraTo illustrate how it works, let's take a look at a device that exposes the 416c49df92SRodrigo Siqueirafollowing planes to userspace: 426c49df92SRodrigo Siqueira 436c49df92SRodrigo Siqueira* 4 Primary planes (1 per CRTC). 446c49df92SRodrigo Siqueira* 4 Cursor planes (1 per CRTC). 456c49df92SRodrigo Siqueira* 1 Overlay plane (shared among CRTCs). 466c49df92SRodrigo Siqueira 476c49df92SRodrigo Siqueira.. note:: Keep in mind that different ASICs might expose other numbers of 486c49df92SRodrigo Siqueira planes. 496c49df92SRodrigo Siqueira 506c49df92SRodrigo SiqueiraFor this hardware example, we have 4 pipes (if you don't know what AMD pipe 516c49df92SRodrigo Siqueirameans, look at 'Documentation/gpu/amdgpu/display/dcn-overview.rst', section 526c49df92SRodrigo Siqueira"AMD Hardware Pipeline"). Typically most AMD devices operate in a pipe-split 536c49df92SRodrigo Siqueiraconfiguration for optimal single display output (e.g., 2 pipes per plane). 546c49df92SRodrigo Siqueira 556c49df92SRodrigo SiqueiraA typical MPO configuration from userspace - 1 primary + 1 overlay on a single 566c49df92SRodrigo Siqueiradisplay - will see 4 pipes in use, 2 per plane. 576c49df92SRodrigo Siqueira 586c49df92SRodrigo SiqueiraAt least 1 pipe must be used per plane (primary and overlay), so for this 596c49df92SRodrigo Siqueirahypothetical hardware that we are using as an example, we have an absolute 606c49df92SRodrigo Siqueiralimit of 4 planes across all CRTCs. Atomic commits will be rejected for display 616c49df92SRodrigo Siqueiraconfigurations using more than 4 planes. Again, it is important to stress that 626c49df92SRodrigo Siqueiraevery DCN has different restrictions; here, we are just trying to provide the 636c49df92SRodrigo Siqueiraconcept idea. 646c49df92SRodrigo Siqueira 656c49df92SRodrigo SiqueiraPlane Restrictions 666c49df92SRodrigo Siqueira================== 676c49df92SRodrigo Siqueira 686c49df92SRodrigo SiqueiraAMDGPU imposes restrictions on the use of DRM planes in the driver. 696c49df92SRodrigo Siqueira 706c49df92SRodrigo SiqueiraAtomic commits will be rejected for commits which do not follow these 716c49df92SRodrigo Siqueirarestrictions: 726c49df92SRodrigo Siqueira 736c49df92SRodrigo Siqueira* Overlay planes must be in ARGB8888 or XRGB8888 format 746c49df92SRodrigo Siqueira* Planes cannot be placed outside of the CRTC destination rectangle 756c49df92SRodrigo Siqueira* Planes cannot be downscaled more than 1/4x of their original size 766c49df92SRodrigo Siqueira* Planes cannot be upscaled more than 16x of their original size 776c49df92SRodrigo Siqueira 786c49df92SRodrigo SiqueiraNot every property is available on every plane: 796c49df92SRodrigo Siqueira 806c49df92SRodrigo Siqueira* Only primary planes have color-space and non-RGB format support 816c49df92SRodrigo Siqueira* Only overlay planes have alpha blending support 826c49df92SRodrigo Siqueira 836c49df92SRodrigo SiqueiraCursor Restrictions 846c49df92SRodrigo Siqueira=================== 856c49df92SRodrigo Siqueira 866c49df92SRodrigo SiqueiraBefore we start to describe some restrictions around cursor and MPO, see the 876c49df92SRodrigo Siqueirabelow image: 886c49df92SRodrigo Siqueira 896c49df92SRodrigo Siqueira.. kernel-figure:: mpo-cursor.svg 906c49df92SRodrigo Siqueira 916c49df92SRodrigo SiqueiraThe image on the left side represents how DRM expects the cursor and planes to 926c49df92SRodrigo Siqueirabe blended. However, AMD hardware handles cursors differently, as you can see 936c49df92SRodrigo Siqueiraon the right side; basically, our cursor cannot be drawn outside its associated 946c49df92SRodrigo Siqueiraplane as it is being treated as part of the plane. Another consequence of that 956c49df92SRodrigo Siqueirais that cursors inherit the color and scale from the plane. 966c49df92SRodrigo Siqueira 976c49df92SRodrigo SiqueiraAs a result of the above behavior, do not use legacy API to set up the cursor 986c49df92SRodrigo Siqueiraplane when working with MPO; otherwise, you might encounter unexpected 996c49df92SRodrigo Siqueirabehavior. 1006c49df92SRodrigo Siqueira 1016c49df92SRodrigo SiqueiraIn short, AMD HW has no dedicated cursor planes. A cursor is attached to 1026c49df92SRodrigo Siqueiraanother plane and therefore inherits any scaling or color processing from its 1036c49df92SRodrigo Siqueiraparent plane. 1046c49df92SRodrigo Siqueira 1056c49df92SRodrigo SiqueiraUse Cases 1066c49df92SRodrigo Siqueira========= 1076c49df92SRodrigo Siqueira 1086c49df92SRodrigo SiqueiraPicture-in-Picture (PIP) playback - Underlay strategy 1096c49df92SRodrigo Siqueira----------------------------------------------------- 1106c49df92SRodrigo Siqueira 1116c49df92SRodrigo SiqueiraVideo playback should be done using the "primary plane as underlay" MPO 1126c49df92SRodrigo Siqueirastrategy. This is a 2 planes configuration: 1136c49df92SRodrigo Siqueira 1146c49df92SRodrigo Siqueira* 1 YUV DRM Primary Plane (e.g. NV12 Video) 1156c49df92SRodrigo Siqueira* 1 RGBA DRM Overlay Plane (e.g. ARGB8888 desktop). The compositor should 1166c49df92SRodrigo Siqueira prepare the framebuffers for the planes as follows: 1176c49df92SRodrigo Siqueira - The overlay plane contains general desktop UI, video player controls, and video subtitles 1186c49df92SRodrigo Siqueira - Primary plane contains one or more videos 1196c49df92SRodrigo Siqueira 1206c49df92SRodrigo Siqueira.. note:: Keep in mind that we could extend this configuration to more planes, 1216c49df92SRodrigo Siqueira but that is currently not supported by our driver yet (maybe if we have a 1226c49df92SRodrigo Siqueira userspace request in the future, we can change that). 1236c49df92SRodrigo Siqueira 1246c49df92SRodrigo SiqueiraSee below a single-video example: 1256c49df92SRodrigo Siqueira 1266c49df92SRodrigo Siqueira.. kernel-figure:: single-display-mpo.svg 1276c49df92SRodrigo Siqueira 1286c49df92SRodrigo Siqueira.. note:: We could extend this behavior to more planes, but that is currently 1296c49df92SRodrigo Siqueira not supported by our driver. 1306c49df92SRodrigo Siqueira 1316c49df92SRodrigo SiqueiraThe video buffer should be used directly for the primary plane. The video can 1326c49df92SRodrigo Siqueirabe scaled and positioned for the desktop using the properties: CRTC_X, CRTC_Y, 1336c49df92SRodrigo SiqueiraCRTC_W, and CRTC_H. The primary plane should also have the color encoding and 1346c49df92SRodrigo Siqueiracolor range properties set based on the source content: 1356c49df92SRodrigo Siqueira 1366c49df92SRodrigo Siqueira* ``COLOR_RANGE``, ``COLOR_ENCODING`` 1376c49df92SRodrigo Siqueira 1386c49df92SRodrigo SiqueiraThe overlay plane should be the native size of the CRTC. The compositor must 1396c49df92SRodrigo Siqueiradraw a transparent cutout for where the video should be placed on the desktop 1406c49df92SRodrigo Siqueira(i.e., set the alpha to zero). The primary plane video will be visible through 1416c49df92SRodrigo Siqueirathe underlay. The overlay plane's buffer may remain static while the primary 1426c49df92SRodrigo Siqueiraplane's framebuffer is used for standard double-buffered playback. 1436c49df92SRodrigo Siqueira 1446c49df92SRodrigo SiqueiraThe compositor should create a YUV buffer matching the native size of the CRTC. 1456c49df92SRodrigo SiqueiraEach video buffer should be composited onto this YUV buffer for direct YUV 1466c49df92SRodrigo Siqueirascanout. The primary plane should have the color encoding and color range 1476c49df92SRodrigo Siqueiraproperties set based on the source content: ``COLOR_RANGE``, 1486c49df92SRodrigo Siqueira``COLOR_ENCODING``. However, be mindful that the source color space and 1496c49df92SRodrigo Siqueiraencoding match for each video since it affect the entire plane. 1506c49df92SRodrigo Siqueira 1516c49df92SRodrigo SiqueiraThe overlay plane should be the native size of the CRTC. The compositor must 1526c49df92SRodrigo Siqueiradraw a transparent cutout for where each video should be placed on the desktop 1536c49df92SRodrigo Siqueira(i.e., set the alpha to zero). The primary plane videos will be visible through 1546c49df92SRodrigo Siqueirathe underlay. The overlay plane's buffer may remain static while compositing 1556c49df92SRodrigo Siqueiraoperations for video playback will be done on the video buffer. 1566c49df92SRodrigo Siqueira 1576c49df92SRodrigo SiqueiraThis kernel interface is validated using IGT GPU Tools. The following tests can 1586c49df92SRodrigo Siqueirabe run to validate positioning, blending, scaling under a variety of sequences 1596c49df92SRodrigo Siqueiraand interactions with operations such as DPMS and S3: 1606c49df92SRodrigo Siqueira 1616c49df92SRodrigo Siqueira- ``kms_plane@plane-panning-bottom-right-pipe-*-planes`` 1626c49df92SRodrigo Siqueira- ``kms_plane@plane-panning-bottom-right-suspend-pipe-*-`` 1636c49df92SRodrigo Siqueira- ``kms_plane@plane-panning-top-left-pipe-*-`` 1646c49df92SRodrigo Siqueira- ``kms_plane@plane-position-covered-pipe-*-`` 1656c49df92SRodrigo Siqueira- ``kms_plane@plane-position-hole-dpms-pipe-*-`` 1666c49df92SRodrigo Siqueira- ``kms_plane@plane-position-hole-pipe-*-`` 1676c49df92SRodrigo Siqueira- ``kms_plane_multiple@atomic-pipe-*-tiling-`` 1686c49df92SRodrigo Siqueira- ``kms_plane_scaling@pipe-*-plane-scaling`` 1696c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-alpha-basic`` 1706c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-alpha-transparant-fb`` 1716c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-alpha-opaque-fb`` 1726c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-constant-alpha-min`` 1736c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-constant-alpha-mid`` 1746c49df92SRodrigo Siqueira- ``kms_plane_alpha_blend@pipe-*-constant-alpha-max`` 1756c49df92SRodrigo Siqueira 1766c49df92SRodrigo SiqueiraMultiple Display MPO 1776c49df92SRodrigo Siqueira-------------------- 1786c49df92SRodrigo Siqueira 1796c49df92SRodrigo SiqueiraAMDGPU supports display MPO when using multiple displays; however, this feature 1806c49df92SRodrigo Siqueirabehavior heavily relies on the compositor implementation. Keep in mind that 181*d56b699dSBjorn Helgaasuserspace can define different policies. For example, some OSes can use MPO to 1826c49df92SRodrigo Siqueiraprotect the plane that handles the video playback; notice that we don't have 1836c49df92SRodrigo Siqueiramany limitations for a single display. Nonetheless, this manipulation can have 1846c49df92SRodrigo Siqueiramany more restrictions for a multi-display scenario. The below example shows a 1856c49df92SRodrigo Siqueiravideo playback in the middle of two displays, and it is up to the compositor to 1866c49df92SRodrigo Siqueiradefine a policy on how to handle it: 1876c49df92SRodrigo Siqueira 1886c49df92SRodrigo Siqueira.. kernel-figure:: multi-display-hdcp-mpo.svg 1896c49df92SRodrigo Siqueira 1906c49df92SRodrigo SiqueiraLet's discuss some of the hardware limitations we have when dealing with 1916c49df92SRodrigo Siqueiramulti-display with MPO. 1926c49df92SRodrigo Siqueira 1936c49df92SRodrigo SiqueiraLimitations 1946c49df92SRodrigo Siqueira~~~~~~~~~~~ 1956c49df92SRodrigo Siqueira 1966c49df92SRodrigo SiqueiraFor simplicity's sake, for discussing the hardware limitation, this 1976c49df92SRodrigo Siqueiradocumentation supposes an example where we have two displays and video playback 1986c49df92SRodrigo Siqueirathat will be moved around different displays. 1996c49df92SRodrigo Siqueira 2006c49df92SRodrigo Siqueira* **Hardware limitations** 2016c49df92SRodrigo Siqueira 2026c49df92SRodrigo SiqueiraFrom the DCN overview page, each display requires at least one pipe and each 2036c49df92SRodrigo SiqueiraMPO plane needs another pipe. As a result, when the video is in the middle of 2046c49df92SRodrigo Siqueirathe two displays, we need to use 2 pipes. See the example below where we avoid 2056c49df92SRodrigo Siqueirapipe split: 2066c49df92SRodrigo Siqueira 2076c49df92SRodrigo Siqueira- 1 display (1 pipe) + MPO (1 pipe), we will use two pipes 2086c49df92SRodrigo Siqueira- 2 displays (2 pipes) + MPO (1-2 pipes); we will use 4 pipes. MPO in the 2096c49df92SRodrigo Siqueira middle of both displays needs 2 pipes. 2106c49df92SRodrigo Siqueira- 3 Displays (3 pipes) + MPO (1-2 pipes), we need 5 pipes. 2116c49df92SRodrigo Siqueira 2126c49df92SRodrigo SiqueiraIf we use MPO with multiple displays, the userspace has to decide to enable 2136c49df92SRodrigo Siqueiramultiple MPO by the price of limiting the number of external displays supported 2146c49df92SRodrigo Siqueiraor disable it in favor of multiple displays; it is a policy decision. For 2156c49df92SRodrigo Siqueiraexample: 2166c49df92SRodrigo Siqueira 2176c49df92SRodrigo Siqueira* When ASIC has 3 pipes, AMD hardware can NOT support 2 displays with MPO 2186c49df92SRodrigo Siqueira* When ASIC has 4 pipes, AMD hardware can NOT support 3 displays with MPO 2196c49df92SRodrigo Siqueira 2206c49df92SRodrigo SiqueiraLet's briefly explore how userspace can handle these two display configurations 2216c49df92SRodrigo Siqueiraon an ASIC that only supports three pipes. We can have: 2226c49df92SRodrigo Siqueira 2236c49df92SRodrigo Siqueira.. kernel-figure:: multi-display-hdcp-mpo-less-pipe-ex.svg 2246c49df92SRodrigo Siqueira 2256c49df92SRodrigo Siqueira- Total pipes are 3 2266c49df92SRodrigo Siqueira- User lights up 2 displays (2 out of 3 pipes are used) 2276c49df92SRodrigo Siqueira- User launches video (1 pipe used for MPO) 2286c49df92SRodrigo Siqueira- Now, if the user moves the video in the middle of 2 displays, one part of the 2296c49df92SRodrigo Siqueira video won't be MPO since we have used 3/3 pipes. 2306c49df92SRodrigo Siqueira 2316c49df92SRodrigo Siqueira* **Scaling limitation** 2326c49df92SRodrigo Siqueira 2336c49df92SRodrigo SiqueiraMPO cannot handle scaling less than 0.25 and more than x16. For example: 2346c49df92SRodrigo Siqueira 2356c49df92SRodrigo SiqueiraIf 4k video (3840x2160) is playing in windowed mode, the physical size of the 2366c49df92SRodrigo Siqueirawindow cannot be smaller than (960x540). 2376c49df92SRodrigo Siqueira 2386c49df92SRodrigo Siqueira.. note:: These scaling limitations might vary from ASIC to ASIC. 2396c49df92SRodrigo Siqueira 2406c49df92SRodrigo Siqueira* **Size Limitation** 2416c49df92SRodrigo Siqueira 2426c49df92SRodrigo SiqueiraThe minimum MPO size is 12px. 243