drm: drm_fourcc: add 10/12/16bit software decoder YCbCr formats
Subsystems (2)
PATCH v2 1/1 drm: drm_fourcc: add 10/12/16bit software decoder YCbCr formats
This adds FOURCCs for 3-plane 10/12/16bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.
Unlike formats typically used by hardware decoders the 10/12bit formats use a LSB alignment. In order to allow fast implementations in GL and Vulkan the padding must contain only zeros, so the float representation can be calculated by multiplying with 2^6=64 or 2^4=16 respectively.
WIP MRs for Mesa, Vulkan and Gstreamer can be found at:
- https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34303
- https://github.com/rmader/Vulkan-Docs/commits/ycbcr-16bit-lsb-formats/
- https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8540
The naming scheme follows the 'P' and 'Q' formats. The 'S' stands for 'software' and was selected in order to make remembering easy.
The 'Sx16' formats could as well be 'Qx16'. We stick with 'S' as 16bit software decoders are likely much more common than hardware ones for the foreseeable future.
---
Changes in v2:
- Added 16bit formats for completeness and because they are used by certain ffmpeg decoders
- Changed the initial character to "S"
- Some minor changes to the commit message
--- drivers/gpu/drm/drm_fourcc.c | 27 +++++++++++++++++++++++++++ include/uapi/drm/drm_fourcc.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
drivers/gpu/drm/drm_fourcc.c +27 -0
@@ -346,6 +346,33 @@ const struct drm_format_info *__drm_format_info(u32 format) { .format = DRM_FORMAT_P030, .depth = 0, .num_planes = 2, .char_per_block = { 4, 8, 0 }, .block_w = { 3, 3, 0 }, .block_h = { 1, 1, 0 }, .hsub = 2, .vsub = 2, .is_yuv = true}, + { .format = DRM_FORMAT_S010, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 2, .is_yuv = true}, + { .format = DRM_FORMAT_S210, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 1, .is_yuv = true}, + { .format = DRM_FORMAT_S410, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 1, .vsub = 1, .is_yuv = true}, + { .format = DRM_FORMAT_S012, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 2, .is_yuv = true}, + { .format = DRM_FORMAT_S212, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 1, .is_yuv = true}, + { .format = DRM_FORMAT_S412, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 1, .vsub = 1, .is_yuv = true}, + { .format = DRM_FORMAT_S016, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 2, .is_yuv = true}, + { .format = DRM_FORMAT_S216, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 2, .vsub = 1, .is_yuv = true}, + { .format = DRM_FORMAT_S416, .depth = 0, .num_planes = 3, + .char_per_block = { 2, 2, 2 }, .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, + .hsub = 1, .vsub = 1, .is_yuv = true}, }; unsigned int i;
include/uapi/drm/drm_fourcc.h +34 -0
@@ -377,6 +377,40 @@ extern "C" {*/ #define DRM_FORMAT_Q401 fourcc_code('Q', '4', '0', '1') +/* +* 3 plane YCbCr LSB aligned +* In order to use these formats in a similar fashion to MSB aligned ones +* implementation can multiply the values by 2^6=64. +* index 0 = Y plane, [15:0] x:Y [6:10] little endian +* index 1 = Cr plane, [15:0] x:Cr [6:10] little endian +* index 2 = Cb plane, [15:0] x:Cb [6:10] little endian +*/ +#define DRM_FORMAT_S010 fourcc_code('S', '0', '1', '0')/* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_S210 fourcc_code('S', '2', '1', '0')/* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_S410 fourcc_code('S', '4', '1', '0')/* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */ + +/* +* 3 plane YCbCr LSB aligned +* In order to use these formats in a similar fashion to MSB aligned ones +* implementation can multiply the values by 2^4=16. +* index 0 = Y plane, [15:0] x:Y [4:12] little endian +* index 1 = Cr plane, [15:0] x:Cr [4:12] little endian +* index 2 = Cb plane, [15:0] x:Cb [4:12] little endian +*/ +#define DRM_FORMAT_S012 fourcc_code('S', '0', '1', '2')/* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */ +#define DRM_FORMAT_S212 fourcc_code('S', '2', '1', '2')/* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */ +#define DRM_FORMAT_S412 fourcc_code('S', '4', '1', '2')/* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */ + +/* +* 3 plane YCbCr +* index 0 = Y plane, [15:0] Y little endian +* index 1 = Cr plane, [15:0] Cr little endian +* index 2 = Cb plane, [15:0] Cb little endian +*/ +#define DRM_FORMAT_S016 fourcc_code('S', '0', '1', '6')/* 2x2 subsampled Cb (1) and Cr (2) planes 16 bits per channel */ +#define DRM_FORMAT_S216 fourcc_code('S', '2', '1', '6')/* 2x1 subsampled Cb (1) and Cr (2) planes 16 bits per channel */ +#define DRM_FORMAT_S416 fourcc_code('S', '4', '1', '6')/* non-subsampled Cb (1) and Cr (2) planes 16 bits per channel */ +/* * 3 plane YCbCr * index 0: Y plane, [7:0] Y
Signature · 1 line
2.49.0
Hey there,
Quoted 5 lines · Robert Mader
Unlike formats typically used by hardware decoders the 10/12bit formats use a LSB alignment. In order to allow fast implementations in GL and Vulkan the padding must contain only zeros, so the float representation can be calculated by multiplying with 2^6=64 or 2^4=16 respectively.
[...]
include/uapi/drm/drm_fourcc.h extern "C" { · line 390
Quoted 11 lines
include/uapi/drm/drm_fourcc.h +11
-0+/* +* 3 plane YCbCr LSB aligned +* In order to use these formats in a similar fashion to MSB aligned ones +* implementation can multiply the values by 2^6=64. +* index 0 = Y plane, [15:0] x:Y [6:10] little endian +* index 1 = Cr plane, [15:0] x:Cr [6:10] little endian +* index 2 = Cb plane, [15:0] x:Cb [6:10] little endian +*/ +#define DRM_FORMAT_S010 fourcc_code('S', '0', '1', '0')/* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_S210 fourcc_code('S', '2', '1', '0')/* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_S410 fourcc_code('S', '4', '1', '0')/* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
The format spec here (and for the others) forgets to mention that the X channel MBZ. In every other channel, X denotes 'may contain arbitrary nonsense so don't read it, and feel free to write whatever to it'. I think you might want to write this out as 'Z:Y' or something instead of 'x:Y'. But honestly I'd expect people to still get this wrong and fill it with all sorts of fun values.
Otherwise this looks good to me though; thanks for typing it up. A VKMS implementation would be really nice for this if you've got the time.
Cheers,
Daniel