Skip to contentSkip to conversation

drm: drm_fourcc: add 10/12bit software decoder YCbCr formats

PATCH Superseded Robert Mader 4 participants 8 messages Apr 7, 2025 – May 1, 2025

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm: drm_fourcc: add 10/12bit software decoder YCbCr formats

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64 or 2^4=16.

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
 drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++
 include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++
 2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +18 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +20 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
 #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
 #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010	fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I210	fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I410	fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012	fourcc_code('I', '0', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I212	fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I412	fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+
 
 /*
  * Format Modifiers:
Signature · 1 line
2.49.0
#1 lore raw

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving this forward? I'd be very happy for any feedback to get this landed, thanks! :)

Quoted 85 lines · Robert Mader

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64 or 2^4=16.

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
  drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++
  include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++
  2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +18 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +20 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
  #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
  #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010	fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I210	fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I410	fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012	fourcc_code('I', '0', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I212	fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I412	fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+
 
  /*
   * Format Modifiers:
#2 lore raw
Quoted 4 lines · Robert Mader

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving this forward? I'd be very happy for any feedback to get this landed, thanks! :)

I don't have spare bandwidth at the moment, sorry :-( One comment below though.

Tomi, can you check if there's any overlap with the formats you're adding for the Xilinx FPGA drivers ?

Quoted 11 lines · Robert Mader
Quoted 10 lines

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64 or 2^4=16.

This needs to be documented somewhere.

Quoted 75 lines
Quoted 75 lines

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
  drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++
  include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++
  2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +18 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +20 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
  #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
  #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010	fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I210	fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I410	fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012	fourcc_code('I', '0', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I212	fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I412	fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+
 
  /*
   * Format Modifiers:
Signature · 3 lines
Regards,

Laurent Pinchart
Reviewed-by
#3 lore raw

Hi,

Quoted 11 lines · Laurent Pinchart
Quoted 4 lines · Robert Mader

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving this forward? I'd be very happy for any feedback to get this landed, thanks! :)

I don't have spare bandwidth at the moment, sorry :-( One comment below though.

Tomi, can you check if there's any overlap with the formats you're adding for the Xilinx FPGA drivers ?

No overlap, they are quite different.

Quoted 10 lines
Quoted 10 lines · Robert Mader
Quoted 9 lines

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64

"can be"

Quoted 3 lines
Quoted 1 line
Quoted 1 line

or 2^4=16.

This needs to be documented somewhere.

Tomi

Quoted 76 lines
Quoted 75 lines
Quoted 75 lines

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
   drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++
   include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++
   2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +18 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +20 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
   #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
   #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010	fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I210	fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I410	fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012	fourcc_code('I', '0', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I212	fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I412	fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+
 
   /*
    * Format Modifiers:
#4 lore raw

Hi Tomi

Quoted 28 lines · Tomi Valkeinen

Hi,

Quoted 11 lines · Laurent Pinchart
Quoted 4 lines · Robert Mader

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving this forward? I'd be very happy for any feedback to get this landed, thanks! :)

I don't have spare bandwidth at the moment, sorry :-( One comment below though.

Tomi, can you check if there's any overlap with the formats you're adding for the Xilinx FPGA drivers ?

No overlap, they are quite different.

Quoted 10 lines
Quoted 10 lines · Robert Mader
Quoted 9 lines

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64

Quoted 7 lines

"can be"

Quoted 3 lines
Quoted 1 line
Quoted 1 line

or 2^4=16.

This needs to be documented somewhere.

Thanks a lot! I just send out a v2 - the changes I made were IMO slightly too big to carry that r-b over - I'd be very thankful if you could have another look / renew your r-b :)

Quoted 2 lines

 Tomi

Cheers,

Robert

Quoted 95 lines
Quoted 94 lines
Quoted 93 lines
Quoted 93 lines

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
   drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++ include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++

   2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +4 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +0 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
    #define DRM_FORMAT_YUV444    fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
    #define DRM_FORMAT_YVU444    fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */

   +/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010    fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_I210    fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ +#define DRM_FORMAT_I410    fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */

include/uapi/drm/drm_fourcc.h +8 -0
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012    fourcc_code('I', '0', '1', '2') /* 2x2 

subsampled Cb (1) and Cr (2) planes 12 bits per channel */ +#define DRM_FORMAT_I212    fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */ +#define DRM_FORMAT_I412    fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */ +
      /*
    * Format Modifiers:

#5 lore raw
In reply to Laurent Pinchart

Hey Laurent, thanks for the feedback!

Quoted 17 lines · Laurent Pinchart
Quoted 4 lines · Robert Mader

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving this forward? I'd be very happy for any feedback to get this landed, thanks! :)

I don't have spare bandwidth at the moment, sorry :-( One comment below though.

Tomi, can you check if there's any overlap with the formats you're adding for the Xilinx FPGA drivers ?

Quoted 6 lines · Robert Mader
Quoted 5 lines

This adds FOURCCs for 10/12bit YCbCr formats used by software decoders like ffmpeg, dav1d and libvpx. The intended use-case is buffer sharing between SW-decoders and GPUs by allocating buffers with udmabuf or dma-heaps, avoiding unnecessary copies or format conversions.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

Unlike formats typically used by hardware decoders these 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 calculated by simple multiplicating with 2^6=64 or 2^4=16.

This needs to be documented somewhere.

Ok, will add a short comment in the description.

Quoted 75 lines
Quoted 75 lines
Quoted 75 lines

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 values where inspired by the corresponding VA_FOURCC_I010, however suggestions are very welcome.

---
   drivers/gpu/drm/drm_fourcc.c  | 18 ++++++++++++++++++
   include/uapi/drm/drm_fourcc.h | 20 ++++++++++++++++++++
   2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_fourcc.c +18 -0
index 3a94ca211f9c..917f77703645 100644
@@ -346,6 +346,24 @@ 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_I010,            .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_I210,            .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_I410,            .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_I012,            .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_I212,            .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_I412,            .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 +20 -0
index e41a3cec6a9e..f22c80031595 100644
@@ -397,6 +397,26 @@ extern "C" {
   #define DRM_FORMAT_YUV444	fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
   #define DRM_FORMAT_YVU444	fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I010	fourcc_code('I', '0', '1', '0') /* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I210	fourcc_code('I', '2', '1', '0') /* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+#define DRM_FORMAT_I410	fourcc_code('I', '4', '1', '0') /* non-subsampled Cb (1) and Cr (2) planes 10 bits per channel */
+
+/*
+ * 3 plane YCbCr LSB aligned
+ * 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_I012	fourcc_code('I', '0', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I212	fourcc_code('I', '2', '1', '2') /* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+#define DRM_FORMAT_I412	fourcc_code('I', '4', '1', '2') /* non-subsampled Cb (1) and Cr (2) planes 12 bits per channel */
+
 
   /*
    * Format Modifiers:
#6 lore raw
In reply to Robert Mader

Robert Mader <[email protected]> writes:

Hello Robert,

Quoted 2 lines

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving

I'm not familiar with these formats to do a proper review. Sorry about that...

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
#7 lore raw

Hey Javier, thanks for the reply anyway. FTR., the formats are very similar to DRM_FORMAT_Q410, just with different alignment.

Quoted 9 lines · Javier Martinez Canillas

Robert Mader <[email protected]> writes:

Hello Robert,

Quoted 2 lines

Chris, Javier, Laurent - sorry for the noise, but given you reviewed changes in the respective files before, maybe you can help me moving

I'm not familiar with these formats to do a proper review. Sorry about that...