1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0+ 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=================================== 4*4882a593Smuzhiyun Arm Framebuffer Compression (AFBC) 5*4882a593Smuzhiyun=================================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunAFBC is a proprietary lossless image compression protocol and format. 8*4882a593SmuzhiyunIt provides fine-grained random access and minimizes the amount of 9*4882a593Smuzhiyundata transferred between IP blocks. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunAFBC can be enabled on drivers which support it via use of the AFBC 12*4882a593Smuzhiyunformat modifiers defined in drm_fourcc.h. See DRM_FORMAT_MOD_ARM_AFBC(*). 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunAll users of the AFBC modifiers must follow the usage guidelines laid 15*4882a593Smuzhiyunout in this document, to ensure compatibility across different AFBC 16*4882a593Smuzhiyunproducers and consumers. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunComponents and Ordering 19*4882a593Smuzhiyun======================= 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunAFBC streams can contain several components - where a component 22*4882a593Smuzhiyuncorresponds to a color channel (i.e. R, G, B, X, A, Y, Cb, Cr). 23*4882a593SmuzhiyunThe assignment of input/output color channels must be consistent 24*4882a593Smuzhiyunbetween the encoder and the decoder for correct operation, otherwise 25*4882a593Smuzhiyunthe consumer will interpret the decoded data incorrectly. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunFurthermore, when the lossless colorspace transform is used 28*4882a593Smuzhiyun(AFBC_FORMAT_MOD_YTR, which should be enabled for RGB buffers for 29*4882a593Smuzhiyunmaximum compression efficiency), the component order must be: 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun * Component 0: R 32*4882a593Smuzhiyun * Component 1: G 33*4882a593Smuzhiyun * Component 2: B 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunThe component ordering is communicated via the fourcc code in the 36*4882a593Smuzhiyunfourcc:modifier pair. In general, component '0' is considered to 37*4882a593Smuzhiyunreside in the least-significant bits of the corresponding linear 38*4882a593Smuzhiyunformat. For example, COMP(bits): 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun * DRM_FORMAT_ABGR8888 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun * Component 0: R(8) 43*4882a593Smuzhiyun * Component 1: G(8) 44*4882a593Smuzhiyun * Component 2: B(8) 45*4882a593Smuzhiyun * Component 3: A(8) 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun * DRM_FORMAT_BGR888 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun * Component 0: R(8) 50*4882a593Smuzhiyun * Component 1: G(8) 51*4882a593Smuzhiyun * Component 2: B(8) 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun * DRM_FORMAT_YUYV 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun * Component 0: Y(8) 56*4882a593Smuzhiyun * Component 1: Cb(8, 2x1 subsampled) 57*4882a593Smuzhiyun * Component 2: Cr(8, 2x1 subsampled) 58*4882a593Smuzhiyun 59*4882a593SmuzhiyunIn AFBC, 'X' components are not treated any differently from any other 60*4882a593Smuzhiyuncomponent. Therefore, an AFBC buffer with fourcc DRM_FORMAT_XBGR8888 61*4882a593Smuzhiyunencodes with 4 components, like so: 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun * DRM_FORMAT_XBGR8888 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun * Component 0: R(8) 66*4882a593Smuzhiyun * Component 1: G(8) 67*4882a593Smuzhiyun * Component 2: B(8) 68*4882a593Smuzhiyun * Component 3: X(8) 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunPlease note, however, that the inclusion of a "wasted" 'X' channel is 71*4882a593Smuzhiyunbad for compression efficiency, and so it's recommended to avoid 72*4882a593Smuzhiyunformats containing 'X' bits. If a fourth component is 73*4882a593Smuzhiyunrequired/expected by the encoder/decoder, then it is recommended to 74*4882a593Smuzhiyuninstead use an equivalent format with alpha, setting all alpha bits to 75*4882a593Smuzhiyun'1'. If there is no requirement for a fourth component, then a format 76*4882a593Smuzhiyunwhich doesn't include alpha can be used, e.g. DRM_FORMAT_BGR888. 77*4882a593Smuzhiyun 78*4882a593SmuzhiyunNumber of Planes 79*4882a593Smuzhiyun================ 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunFormats which are typically multi-planar in linear layouts (e.g. YUV 82*4882a593Smuzhiyun420), can be encoded into one, or multiple, AFBC planes. As with 83*4882a593Smuzhiyuncomponent order, the encoder and decoder must agree about the number 84*4882a593Smuzhiyunof planes in order to correctly decode the buffer. The fourcc code is 85*4882a593Smuzhiyunused to determine the number of encoded planes in an AFBC buffer, 86*4882a593Smuzhiyunmatching the number of planes for the linear (unmodified) format. 87*4882a593SmuzhiyunWithin each plane, the component ordering also follows the fourcc 88*4882a593Smuzhiyuncode: 89*4882a593Smuzhiyun 90*4882a593SmuzhiyunFor example: 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun * DRM_FORMAT_YUYV: nplanes = 1 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun * Plane 0: 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun * Component 0: Y(8) 97*4882a593Smuzhiyun * Component 1: Cb(8, 2x1 subsampled) 98*4882a593Smuzhiyun * Component 2: Cr(8, 2x1 subsampled) 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun * DRM_FORMAT_NV12: nplanes = 2 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun * Plane 0: 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun * Component 0: Y(8) 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun * Plane 1: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun * Component 0: Cb(8, 2x1 subsampled) 109*4882a593Smuzhiyun * Component 1: Cr(8, 2x1 subsampled) 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunCross-device interoperability 112*4882a593Smuzhiyun============================= 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunFor maximum compatibility across devices, the table below defines 115*4882a593Smuzhiyuncanonical formats for use between AFBC-enabled devices. Formats which 116*4882a593Smuzhiyunare listed here must be used exactly as specified when using the AFBC 117*4882a593Smuzhiyunmodifiers. Formats which are not listed should be avoided. 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun.. flat-table:: AFBC formats 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun * - Fourcc code 122*4882a593Smuzhiyun - Description 123*4882a593Smuzhiyun - Planes/Components 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun * - DRM_FORMAT_ABGR2101010 126*4882a593Smuzhiyun - 10-bit per component RGB, with 2-bit alpha 127*4882a593Smuzhiyun - Plane 0: 4 components 128*4882a593Smuzhiyun * Component 0: R(10) 129*4882a593Smuzhiyun * Component 1: G(10) 130*4882a593Smuzhiyun * Component 2: B(10) 131*4882a593Smuzhiyun * Component 3: A(2) 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun * - DRM_FORMAT_ABGR8888 134*4882a593Smuzhiyun - 8-bit per component RGB, with 8-bit alpha 135*4882a593Smuzhiyun - Plane 0: 4 components 136*4882a593Smuzhiyun * Component 0: R(8) 137*4882a593Smuzhiyun * Component 1: G(8) 138*4882a593Smuzhiyun * Component 2: B(8) 139*4882a593Smuzhiyun * Component 3: A(8) 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun * - DRM_FORMAT_BGR888 142*4882a593Smuzhiyun - 8-bit per component RGB 143*4882a593Smuzhiyun - Plane 0: 3 components 144*4882a593Smuzhiyun * Component 0: R(8) 145*4882a593Smuzhiyun * Component 1: G(8) 146*4882a593Smuzhiyun * Component 2: B(8) 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun * - DRM_FORMAT_BGR565 149*4882a593Smuzhiyun - 5/6-bit per component RGB 150*4882a593Smuzhiyun - Plane 0: 3 components 151*4882a593Smuzhiyun * Component 0: R(5) 152*4882a593Smuzhiyun * Component 1: G(6) 153*4882a593Smuzhiyun * Component 2: B(5) 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun * - DRM_FORMAT_ABGR1555 156*4882a593Smuzhiyun - 5-bit per component RGB, with 1-bit alpha 157*4882a593Smuzhiyun - Plane 0: 4 components 158*4882a593Smuzhiyun * Component 0: R(5) 159*4882a593Smuzhiyun * Component 1: G(5) 160*4882a593Smuzhiyun * Component 2: B(5) 161*4882a593Smuzhiyun * Component 3: A(1) 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun * - DRM_FORMAT_VUY888 164*4882a593Smuzhiyun - 8-bit per component YCbCr 444, single plane 165*4882a593Smuzhiyun - Plane 0: 3 components 166*4882a593Smuzhiyun * Component 0: Y(8) 167*4882a593Smuzhiyun * Component 1: Cb(8) 168*4882a593Smuzhiyun * Component 2: Cr(8) 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun * - DRM_FORMAT_VUY101010 171*4882a593Smuzhiyun - 10-bit per component YCbCr 444, single plane 172*4882a593Smuzhiyun - Plane 0: 3 components 173*4882a593Smuzhiyun * Component 0: Y(10) 174*4882a593Smuzhiyun * Component 1: Cb(10) 175*4882a593Smuzhiyun * Component 2: Cr(10) 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun * - DRM_FORMAT_YUYV 178*4882a593Smuzhiyun - 8-bit per component YCbCr 422, single plane 179*4882a593Smuzhiyun - Plane 0: 3 components 180*4882a593Smuzhiyun * Component 0: Y(8) 181*4882a593Smuzhiyun * Component 1: Cb(8, 2x1 subsampled) 182*4882a593Smuzhiyun * Component 2: Cr(8, 2x1 subsampled) 183*4882a593Smuzhiyun 184*4882a593Smuzhiyun * - DRM_FORMAT_NV16 185*4882a593Smuzhiyun - 8-bit per component YCbCr 422, two plane 186*4882a593Smuzhiyun - Plane 0: 1 component 187*4882a593Smuzhiyun * Component 0: Y(8) 188*4882a593Smuzhiyun Plane 1: 2 components 189*4882a593Smuzhiyun * Component 0: Cb(8, 2x1 subsampled) 190*4882a593Smuzhiyun * Component 1: Cr(8, 2x1 subsampled) 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun * - DRM_FORMAT_Y210 193*4882a593Smuzhiyun - 10-bit per component YCbCr 422, single plane 194*4882a593Smuzhiyun - Plane 0: 3 components 195*4882a593Smuzhiyun * Component 0: Y(10) 196*4882a593Smuzhiyun * Component 1: Cb(10, 2x1 subsampled) 197*4882a593Smuzhiyun * Component 2: Cr(10, 2x1 subsampled) 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun * - DRM_FORMAT_P210 200*4882a593Smuzhiyun - 10-bit per component YCbCr 422, two plane 201*4882a593Smuzhiyun - Plane 0: 1 component 202*4882a593Smuzhiyun * Component 0: Y(10) 203*4882a593Smuzhiyun Plane 1: 2 components 204*4882a593Smuzhiyun * Component 0: Cb(10, 2x1 subsampled) 205*4882a593Smuzhiyun * Component 1: Cr(10, 2x1 subsampled) 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun * - DRM_FORMAT_YUV420_8BIT 208*4882a593Smuzhiyun - 8-bit per component YCbCr 420, single plane 209*4882a593Smuzhiyun - Plane 0: 3 components 210*4882a593Smuzhiyun * Component 0: Y(8) 211*4882a593Smuzhiyun * Component 1: Cb(8, 2x2 subsampled) 212*4882a593Smuzhiyun * Component 2: Cr(8, 2x2 subsampled) 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun * - DRM_FORMAT_YUV420_10BIT 215*4882a593Smuzhiyun - 10-bit per component YCbCr 420, single plane 216*4882a593Smuzhiyun - Plane 0: 3 components 217*4882a593Smuzhiyun * Component 0: Y(10) 218*4882a593Smuzhiyun * Component 1: Cb(10, 2x2 subsampled) 219*4882a593Smuzhiyun * Component 2: Cr(10, 2x2 subsampled) 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun * - DRM_FORMAT_NV12 222*4882a593Smuzhiyun - 8-bit per component YCbCr 420, two plane 223*4882a593Smuzhiyun - Plane 0: 1 component 224*4882a593Smuzhiyun * Component 0: Y(8) 225*4882a593Smuzhiyun Plane 1: 2 components 226*4882a593Smuzhiyun * Component 0: Cb(8, 2x2 subsampled) 227*4882a593Smuzhiyun * Component 1: Cr(8, 2x2 subsampled) 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun * - DRM_FORMAT_P010 230*4882a593Smuzhiyun - 10-bit per component YCbCr 420, two plane 231*4882a593Smuzhiyun - Plane 0: 1 component 232*4882a593Smuzhiyun * Component 0: Y(10) 233*4882a593Smuzhiyun Plane 1: 2 components 234*4882a593Smuzhiyun * Component 0: Cb(10, 2x2 subsampled) 235*4882a593Smuzhiyun * Component 1: Cr(10, 2x2 subsampled) 236