162306a36Sopenharmony_ci======================== 262306a36Sopenharmony_ciMultiplane Overlay (MPO) 362306a36Sopenharmony_ci======================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci.. note:: You will get more from this page if you have already read the 662306a36Sopenharmony_ci 'Documentation/gpu/amdgpu/display/dcn-overview.rst'. 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci 962306a36Sopenharmony_ciMultiplane Overlay (MPO) allows for multiple framebuffers to be composited via 1062306a36Sopenharmony_cifixed-function hardware in the display controller rather than using graphics or 1162306a36Sopenharmony_cicompute shaders for composition. This can yield some power savings if it means 1262306a36Sopenharmony_cithe graphics/compute pipelines can be put into low-power states. In summary, 1362306a36Sopenharmony_ciMPO can bring the following benefits: 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci* Decreased GPU and CPU workload - no composition shaders needed, no extra 1662306a36Sopenharmony_ci buffer copy needed, GPU can remain idle. 1762306a36Sopenharmony_ci* Plane independent page flips - No need to be tied to global compositor 1862306a36Sopenharmony_ci page-flip present rate, reduced latency, independent timing. 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci.. note:: Keep in mind that MPO is all about power-saving; if you want to learn 2162306a36Sopenharmony_ci more about power-save in the display context, check the link: 2262306a36Sopenharmony_ci `Power <https://gitlab.freedesktop.org/pq/color-and-hdr/-/blob/main/doc/power.rst>`__. 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciMultiplane Overlay is only available using the DRM atomic model. The atomic 2562306a36Sopenharmony_cimodel only uses a single userspace IOCTL for configuring the display hardware 2662306a36Sopenharmony_ci(modesetting, page-flipping, etc) - drmModeAtomicCommit. To query hardware 2762306a36Sopenharmony_ciresources and limitations userspace also calls into drmModeGetResources which 2862306a36Sopenharmony_cireports back the number of planes, CRTCs, and connectors. There are three types 2962306a36Sopenharmony_ciof DRM planes that the driver can register and work with: 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci* ``DRM_PLANE_TYPE_PRIMARY``: Primary planes represent a "main" plane for a 3262306a36Sopenharmony_ci CRTC, primary planes are the planes operated upon by CRTC modesetting and 3362306a36Sopenharmony_ci flipping operations. 3462306a36Sopenharmony_ci* ``DRM_PLANE_TYPE_CURSOR``: Cursor planes represent a "cursor" plane for a 3562306a36Sopenharmony_ci CRTC. Cursor planes are the planes operated upon by the cursor IOCTLs 3662306a36Sopenharmony_ci* ``DRM_PLANE_TYPE_OVERLAY``: Overlay planes represent all non-primary, 3762306a36Sopenharmony_ci non-cursor planes. Some drivers refer to these types of planes as "sprites" 3862306a36Sopenharmony_ci internally. 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ciTo illustrate how it works, let's take a look at a device that exposes the 4162306a36Sopenharmony_cifollowing planes to userspace: 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci* 4 Primary planes (1 per CRTC). 4462306a36Sopenharmony_ci* 4 Cursor planes (1 per CRTC). 4562306a36Sopenharmony_ci* 1 Overlay plane (shared among CRTCs). 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci.. note:: Keep in mind that different ASICs might expose other numbers of 4862306a36Sopenharmony_ci planes. 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciFor this hardware example, we have 4 pipes (if you don't know what AMD pipe 5162306a36Sopenharmony_cimeans, look at 'Documentation/gpu/amdgpu/display/dcn-overview.rst', section 5262306a36Sopenharmony_ci"AMD Hardware Pipeline"). Typically most AMD devices operate in a pipe-split 5362306a36Sopenharmony_ciconfiguration for optimal single display output (e.g., 2 pipes per plane). 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciA typical MPO configuration from userspace - 1 primary + 1 overlay on a single 5662306a36Sopenharmony_cidisplay - will see 4 pipes in use, 2 per plane. 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciAt least 1 pipe must be used per plane (primary and overlay), so for this 5962306a36Sopenharmony_cihypothetical hardware that we are using as an example, we have an absolute 6062306a36Sopenharmony_cilimit of 4 planes across all CRTCs. Atomic commits will be rejected for display 6162306a36Sopenharmony_ciconfigurations using more than 4 planes. Again, it is important to stress that 6262306a36Sopenharmony_cievery DCN has different restrictions; here, we are just trying to provide the 6362306a36Sopenharmony_ciconcept idea. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciPlane Restrictions 6662306a36Sopenharmony_ci================== 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ciAMDGPU imposes restrictions on the use of DRM planes in the driver. 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciAtomic commits will be rejected for commits which do not follow these 7162306a36Sopenharmony_cirestrictions: 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci* Overlay planes must be in ARGB8888 or XRGB8888 format 7462306a36Sopenharmony_ci* Planes cannot be placed outside of the CRTC destination rectangle 7562306a36Sopenharmony_ci* Planes cannot be downscaled more than 1/4x of their original size 7662306a36Sopenharmony_ci* Planes cannot be upscaled more than 16x of their original size 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ciNot every property is available on every plane: 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci* Only primary planes have color-space and non-RGB format support 8162306a36Sopenharmony_ci* Only overlay planes have alpha blending support 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciCursor Restrictions 8462306a36Sopenharmony_ci=================== 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciBefore we start to describe some restrictions around cursor and MPO, see the 8762306a36Sopenharmony_cibelow image: 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci.. kernel-figure:: mpo-cursor.svg 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciThe image on the left side represents how DRM expects the cursor and planes to 9262306a36Sopenharmony_cibe blended. However, AMD hardware handles cursors differently, as you can see 9362306a36Sopenharmony_cion the right side; basically, our cursor cannot be drawn outside its associated 9462306a36Sopenharmony_ciplane as it is being treated as part of the plane. Another consequence of that 9562306a36Sopenharmony_ciis that cursors inherit the color and scale from the plane. 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciAs a result of the above behavior, do not use legacy API to set up the cursor 9862306a36Sopenharmony_ciplane when working with MPO; otherwise, you might encounter unexpected 9962306a36Sopenharmony_cibehavior. 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ciIn short, AMD HW has no dedicated cursor planes. A cursor is attached to 10262306a36Sopenharmony_cianother plane and therefore inherits any scaling or color processing from its 10362306a36Sopenharmony_ciparent plane. 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciUse Cases 10662306a36Sopenharmony_ci========= 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciPicture-in-Picture (PIP) playback - Underlay strategy 10962306a36Sopenharmony_ci----------------------------------------------------- 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ciVideo playback should be done using the "primary plane as underlay" MPO 11262306a36Sopenharmony_cistrategy. This is a 2 planes configuration: 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci* 1 YUV DRM Primary Plane (e.g. NV12 Video) 11562306a36Sopenharmony_ci* 1 RGBA DRM Overlay Plane (e.g. ARGB8888 desktop). The compositor should 11662306a36Sopenharmony_ci prepare the framebuffers for the planes as follows: 11762306a36Sopenharmony_ci - The overlay plane contains general desktop UI, video player controls, and video subtitles 11862306a36Sopenharmony_ci - Primary plane contains one or more videos 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci.. note:: Keep in mind that we could extend this configuration to more planes, 12162306a36Sopenharmony_ci but that is currently not supported by our driver yet (maybe if we have a 12262306a36Sopenharmony_ci userspace request in the future, we can change that). 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciSee below a single-video example: 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci.. kernel-figure:: single-display-mpo.svg 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci.. note:: We could extend this behavior to more planes, but that is currently 12962306a36Sopenharmony_ci not supported by our driver. 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ciThe video buffer should be used directly for the primary plane. The video can 13262306a36Sopenharmony_cibe scaled and positioned for the desktop using the properties: CRTC_X, CRTC_Y, 13362306a36Sopenharmony_ciCRTC_W, and CRTC_H. The primary plane should also have the color encoding and 13462306a36Sopenharmony_cicolor range properties set based on the source content: 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci* ``COLOR_RANGE``, ``COLOR_ENCODING`` 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ciThe overlay plane should be the native size of the CRTC. The compositor must 13962306a36Sopenharmony_cidraw a transparent cutout for where the video should be placed on the desktop 14062306a36Sopenharmony_ci(i.e., set the alpha to zero). The primary plane video will be visible through 14162306a36Sopenharmony_cithe underlay. The overlay plane's buffer may remain static while the primary 14262306a36Sopenharmony_ciplane's framebuffer is used for standard double-buffered playback. 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_ciThe compositor should create a YUV buffer matching the native size of the CRTC. 14562306a36Sopenharmony_ciEach video buffer should be composited onto this YUV buffer for direct YUV 14662306a36Sopenharmony_ciscanout. The primary plane should have the color encoding and color range 14762306a36Sopenharmony_ciproperties set based on the source content: ``COLOR_RANGE``, 14862306a36Sopenharmony_ci``COLOR_ENCODING``. However, be mindful that the source color space and 14962306a36Sopenharmony_ciencoding match for each video since it affect the entire plane. 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ciThe overlay plane should be the native size of the CRTC. The compositor must 15262306a36Sopenharmony_cidraw a transparent cutout for where each video should be placed on the desktop 15362306a36Sopenharmony_ci(i.e., set the alpha to zero). The primary plane videos will be visible through 15462306a36Sopenharmony_cithe underlay. The overlay plane's buffer may remain static while compositing 15562306a36Sopenharmony_cioperations for video playback will be done on the video buffer. 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciThis kernel interface is validated using IGT GPU Tools. The following tests can 15862306a36Sopenharmony_cibe run to validate positioning, blending, scaling under a variety of sequences 15962306a36Sopenharmony_ciand interactions with operations such as DPMS and S3: 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci- ``kms_plane@plane-panning-bottom-right-pipe-*-planes`` 16262306a36Sopenharmony_ci- ``kms_plane@plane-panning-bottom-right-suspend-pipe-*-`` 16362306a36Sopenharmony_ci- ``kms_plane@plane-panning-top-left-pipe-*-`` 16462306a36Sopenharmony_ci- ``kms_plane@plane-position-covered-pipe-*-`` 16562306a36Sopenharmony_ci- ``kms_plane@plane-position-hole-dpms-pipe-*-`` 16662306a36Sopenharmony_ci- ``kms_plane@plane-position-hole-pipe-*-`` 16762306a36Sopenharmony_ci- ``kms_plane_multiple@atomic-pipe-*-tiling-`` 16862306a36Sopenharmony_ci- ``kms_plane_scaling@pipe-*-plane-scaling`` 16962306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-alpha-basic`` 17062306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-alpha-transparant-fb`` 17162306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-alpha-opaque-fb`` 17262306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-constant-alpha-min`` 17362306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-constant-alpha-mid`` 17462306a36Sopenharmony_ci- ``kms_plane_alpha_blend@pipe-*-constant-alpha-max`` 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ciMultiple Display MPO 17762306a36Sopenharmony_ci-------------------- 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ciAMDGPU supports display MPO when using multiple displays; however, this feature 18062306a36Sopenharmony_cibehavior heavily relies on the compositor implementation. Keep in mind that 18162306a36Sopenharmony_ciuserspace can define different policies. For example, some OSes can use MPO to 18262306a36Sopenharmony_ciprotect the plane that handles the video playback; notice that we don't have 18362306a36Sopenharmony_cimany limitations for a single display. Nonetheless, this manipulation can have 18462306a36Sopenharmony_cimany more restrictions for a multi-display scenario. The below example shows a 18562306a36Sopenharmony_civideo playback in the middle of two displays, and it is up to the compositor to 18662306a36Sopenharmony_cidefine a policy on how to handle it: 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci.. kernel-figure:: multi-display-hdcp-mpo.svg 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ciLet's discuss some of the hardware limitations we have when dealing with 19162306a36Sopenharmony_cimulti-display with MPO. 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ciLimitations 19462306a36Sopenharmony_ci~~~~~~~~~~~ 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ciFor simplicity's sake, for discussing the hardware limitation, this 19762306a36Sopenharmony_cidocumentation supposes an example where we have two displays and video playback 19862306a36Sopenharmony_cithat will be moved around different displays. 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci* **Hardware limitations** 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ciFrom the DCN overview page, each display requires at least one pipe and each 20362306a36Sopenharmony_ciMPO plane needs another pipe. As a result, when the video is in the middle of 20462306a36Sopenharmony_cithe two displays, we need to use 2 pipes. See the example below where we avoid 20562306a36Sopenharmony_cipipe split: 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci- 1 display (1 pipe) + MPO (1 pipe), we will use two pipes 20862306a36Sopenharmony_ci- 2 displays (2 pipes) + MPO (1-2 pipes); we will use 4 pipes. MPO in the 20962306a36Sopenharmony_ci middle of both displays needs 2 pipes. 21062306a36Sopenharmony_ci- 3 Displays (3 pipes) + MPO (1-2 pipes), we need 5 pipes. 21162306a36Sopenharmony_ci 21262306a36Sopenharmony_ciIf we use MPO with multiple displays, the userspace has to decide to enable 21362306a36Sopenharmony_cimultiple MPO by the price of limiting the number of external displays supported 21462306a36Sopenharmony_cior disable it in favor of multiple displays; it is a policy decision. For 21562306a36Sopenharmony_ciexample: 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci* When ASIC has 3 pipes, AMD hardware can NOT support 2 displays with MPO 21862306a36Sopenharmony_ci* When ASIC has 4 pipes, AMD hardware can NOT support 3 displays with MPO 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ciLet's briefly explore how userspace can handle these two display configurations 22162306a36Sopenharmony_cion an ASIC that only supports three pipes. We can have: 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci.. kernel-figure:: multi-display-hdcp-mpo-less-pipe-ex.svg 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci- Total pipes are 3 22662306a36Sopenharmony_ci- User lights up 2 displays (2 out of 3 pipes are used) 22762306a36Sopenharmony_ci- User launches video (1 pipe used for MPO) 22862306a36Sopenharmony_ci- Now, if the user moves the video in the middle of 2 displays, one part of the 22962306a36Sopenharmony_ci video won't be MPO since we have used 3/3 pipes. 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci* **Scaling limitation** 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ciMPO cannot handle scaling less than 0.25 and more than x16. For example: 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ciIf 4k video (3840x2160) is playing in windowed mode, the physical size of the 23662306a36Sopenharmony_ciwindow cannot be smaller than (960x540). 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci.. note:: These scaling limitations might vary from ASIC to ASIC. 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci* **Size Limitation** 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ciThe minimum MPO size is 12px. 243