mpo-overview.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. ========================
  2. Multiplane Overlay (MPO)
  3. ========================
  4. .. note:: You will get more from this page if you have already read the
  5. 'Documentation/gpu/amdgpu/display/dcn-overview.rst'.
  6. Multiplane Overlay (MPO) allows for multiple framebuffers to be composited via
  7. fixed-function hardware in the display controller rather than using graphics or
  8. compute shaders for composition. This can yield some power savings if it means
  9. the graphics/compute pipelines can be put into low-power states. In summary,
  10. MPO can bring the following benefits:
  11. * Decreased GPU and CPU workload - no composition shaders needed, no extra
  12. buffer copy needed, GPU can remain idle.
  13. * Plane independent page flips - No need to be tied to global compositor
  14. page-flip present rate, reduced latency, independent timing.
  15. .. note:: Keep in mind that MPO is all about power-saving; if you want to learn
  16. more about power-save in the display context, check the link:
  17. `Power <https://gitlab.freedesktop.org/pq/color-and-hdr/-/blob/main/doc/power.rst>`__.
  18. Multiplane Overlay is only available using the DRM atomic model. The atomic
  19. model only uses a single userspace IOCTL for configuring the display hardware
  20. (modesetting, page-flipping, etc) - drmModeAtomicCommit. To query hardware
  21. resources and limitations userspace also calls into drmModeGetResources which
  22. reports back the number of planes, CRTCs, and connectors. There are three types
  23. of DRM planes that the driver can register and work with:
  24. * ``DRM_PLANE_TYPE_PRIMARY``: Primary planes represent a "main" plane for a
  25. CRTC, primary planes are the planes operated upon by CRTC modesetting and
  26. flipping operations.
  27. * ``DRM_PLANE_TYPE_CURSOR``: Cursor planes represent a "cursor" plane for a
  28. CRTC. Cursor planes are the planes operated upon by the cursor IOCTLs
  29. * ``DRM_PLANE_TYPE_OVERLAY``: Overlay planes represent all non-primary,
  30. non-cursor planes. Some drivers refer to these types of planes as "sprites"
  31. internally.
  32. To illustrate how it works, let's take a look at a device that exposes the
  33. following planes to userspace:
  34. * 4 Primary planes (1 per CRTC).
  35. * 4 Cursor planes (1 per CRTC).
  36. * 1 Overlay plane (shared among CRTCs).
  37. .. note:: Keep in mind that different ASICs might expose other numbers of
  38. planes.
  39. For this hardware example, we have 4 pipes (if you don't know what AMD pipe
  40. means, look at 'Documentation/gpu/amdgpu/display/dcn-overview.rst', section
  41. "AMD Hardware Pipeline"). Typically most AMD devices operate in a pipe-split
  42. configuration for optimal single display output (e.g., 2 pipes per plane).
  43. A typical MPO configuration from userspace - 1 primary + 1 overlay on a single
  44. display - will see 4 pipes in use, 2 per plane.
  45. At least 1 pipe must be used per plane (primary and overlay), so for this
  46. hypothetical hardware that we are using as an example, we have an absolute
  47. limit of 4 planes across all CRTCs. Atomic commits will be rejected for display
  48. configurations using more than 4 planes. Again, it is important to stress that
  49. every DCN has different restrictions; here, we are just trying to provide the
  50. concept idea.
  51. Plane Restrictions
  52. ==================
  53. AMDGPU imposes restrictions on the use of DRM planes in the driver.
  54. Atomic commits will be rejected for commits which do not follow these
  55. restrictions:
  56. * Overlay planes must be in ARGB8888 or XRGB8888 format
  57. * Planes cannot be placed outside of the CRTC destination rectangle
  58. * Planes cannot be downscaled more than 1/4x of their original size
  59. * Planes cannot be upscaled more than 16x of their original size
  60. Not every property is available on every plane:
  61. * Only primary planes have color-space and non-RGB format support
  62. * Only overlay planes have alpha blending support
  63. Cursor Restrictions
  64. ===================
  65. Before we start to describe some restrictions around cursor and MPO, see the
  66. below image:
  67. .. kernel-figure:: mpo-cursor.svg
  68. The image on the left side represents how DRM expects the cursor and planes to
  69. be blended. However, AMD hardware handles cursors differently, as you can see
  70. on the right side; basically, our cursor cannot be drawn outside its associated
  71. plane as it is being treated as part of the plane. Another consequence of that
  72. is that cursors inherit the color and scale from the plane.
  73. As a result of the above behavior, do not use legacy API to set up the cursor
  74. plane when working with MPO; otherwise, you might encounter unexpected
  75. behavior.
  76. In short, AMD HW has no dedicated cursor planes. A cursor is attached to
  77. another plane and therefore inherits any scaling or color processing from its
  78. parent plane.
  79. Use Cases
  80. =========
  81. Picture-in-Picture (PIP) playback - Underlay strategy
  82. -----------------------------------------------------
  83. Video playback should be done using the "primary plane as underlay" MPO
  84. strategy. This is a 2 planes configuration:
  85. * 1 YUV DRM Primary Plane (e.g. NV12 Video)
  86. * 1 RGBA DRM Overlay Plane (e.g. ARGB8888 desktop). The compositor should
  87. prepare the framebuffers for the planes as follows:
  88. - The overlay plane contains general desktop UI, video player controls, and video subtitles
  89. - Primary plane contains one or more videos
  90. .. note:: Keep in mind that we could extend this configuration to more planes,
  91. but that is currently not supported by our driver yet (maybe if we have a
  92. userspace request in the future, we can change that).
  93. See below a single-video example:
  94. .. kernel-figure:: single-display-mpo.svg
  95. .. note:: We could extend this behavior to more planes, but that is currently
  96. not supported by our driver.
  97. The video buffer should be used directly for the primary plane. The video can
  98. be scaled and positioned for the desktop using the properties: CRTC_X, CRTC_Y,
  99. CRTC_W, and CRTC_H. The primary plane should also have the color encoding and
  100. color range properties set based on the source content:
  101. * ``COLOR_RANGE``, ``COLOR_ENCODING``
  102. The overlay plane should be the native size of the CRTC. The compositor must
  103. draw a transparent cutout for where the video should be placed on the desktop
  104. (i.e., set the alpha to zero). The primary plane video will be visible through
  105. the underlay. The overlay plane's buffer may remain static while the primary
  106. plane's framebuffer is used for standard double-buffered playback.
  107. The compositor should create a YUV buffer matching the native size of the CRTC.
  108. Each video buffer should be composited onto this YUV buffer for direct YUV
  109. scanout. The primary plane should have the color encoding and color range
  110. properties set based on the source content: ``COLOR_RANGE``,
  111. ``COLOR_ENCODING``. However, be mindful that the source color space and
  112. encoding match for each video since it affect the entire plane.
  113. The overlay plane should be the native size of the CRTC. The compositor must
  114. draw a transparent cutout for where each video should be placed on the desktop
  115. (i.e., set the alpha to zero). The primary plane videos will be visible through
  116. the underlay. The overlay plane's buffer may remain static while compositing
  117. operations for video playback will be done on the video buffer.
  118. This kernel interface is validated using IGT GPU Tools. The following tests can
  119. be run to validate positioning, blending, scaling under a variety of sequences
  120. and interactions with operations such as DPMS and S3:
  121. - ``kms_plane@plane-panning-bottom-right-pipe-*-planes``
  122. - ``kms_plane@plane-panning-bottom-right-suspend-pipe-*-``
  123. - ``kms_plane@plane-panning-top-left-pipe-*-``
  124. - ``kms_plane@plane-position-covered-pipe-*-``
  125. - ``kms_plane@plane-position-hole-dpms-pipe-*-``
  126. - ``kms_plane@plane-position-hole-pipe-*-``
  127. - ``kms_plane_multiple@atomic-pipe-*-tiling-``
  128. - ``kms_plane_scaling@pipe-*-plane-scaling``
  129. - ``kms_plane_alpha_blend@pipe-*-alpha-basic``
  130. - ``kms_plane_alpha_blend@pipe-*-alpha-transparant-fb``
  131. - ``kms_plane_alpha_blend@pipe-*-alpha-opaque-fb``
  132. - ``kms_plane_alpha_blend@pipe-*-constant-alpha-min``
  133. - ``kms_plane_alpha_blend@pipe-*-constant-alpha-mid``
  134. - ``kms_plane_alpha_blend@pipe-*-constant-alpha-max``
  135. Multiple Display MPO
  136. --------------------
  137. AMDGPU supports display MPO when using multiple displays; however, this feature
  138. behavior heavily relies on the compositor implementation. Keep in mind that
  139. usespace can define different policies. For example, some OSes can use MPO to
  140. protect the plane that handles the video playback; notice that we don't have
  141. many limitations for a single display. Nonetheless, this manipulation can have
  142. many more restrictions for a multi-display scenario. The below example shows a
  143. video playback in the middle of two displays, and it is up to the compositor to
  144. define a policy on how to handle it:
  145. .. kernel-figure:: multi-display-hdcp-mpo.svg
  146. Let's discuss some of the hardware limitations we have when dealing with
  147. multi-display with MPO.
  148. Limitations
  149. ~~~~~~~~~~~
  150. For simplicity's sake, for discussing the hardware limitation, this
  151. documentation supposes an example where we have two displays and video playback
  152. that will be moved around different displays.
  153. * **Hardware limitations**
  154. From the DCN overview page, each display requires at least one pipe and each
  155. MPO plane needs another pipe. As a result, when the video is in the middle of
  156. the two displays, we need to use 2 pipes. See the example below where we avoid
  157. pipe split:
  158. - 1 display (1 pipe) + MPO (1 pipe), we will use two pipes
  159. - 2 displays (2 pipes) + MPO (1-2 pipes); we will use 4 pipes. MPO in the
  160. middle of both displays needs 2 pipes.
  161. - 3 Displays (3 pipes) + MPO (1-2 pipes), we need 5 pipes.
  162. If we use MPO with multiple displays, the userspace has to decide to enable
  163. multiple MPO by the price of limiting the number of external displays supported
  164. or disable it in favor of multiple displays; it is a policy decision. For
  165. example:
  166. * When ASIC has 3 pipes, AMD hardware can NOT support 2 displays with MPO
  167. * When ASIC has 4 pipes, AMD hardware can NOT support 3 displays with MPO
  168. Let's briefly explore how userspace can handle these two display configurations
  169. on an ASIC that only supports three pipes. We can have:
  170. .. kernel-figure:: multi-display-hdcp-mpo-less-pipe-ex.svg
  171. - Total pipes are 3
  172. - User lights up 2 displays (2 out of 3 pipes are used)
  173. - User launches video (1 pipe used for MPO)
  174. - Now, if the user moves the video in the middle of 2 displays, one part of the
  175. video won't be MPO since we have used 3/3 pipes.
  176. * **Scaling limitation**
  177. MPO cannot handle scaling less than 0.25 and more than x16. For example:
  178. If 4k video (3840x2160) is playing in windowed mode, the physical size of the
  179. window cannot be smaller than (960x540).
  180. .. note:: These scaling limitations might vary from ASIC to ASIC.
  181. * **Size Limitation**
  182. The minimum MPO size is 12px.