[PATCH v2 25/25] drm/xlnx: Compute dumb-buffer sizes with drm_mode_size_dumb()
Tomi Valkeinen
tomi.valkeinen at ideasonboard.com
Sun Jan 19 15:22:51 UTC 2025
On 19/01/2025 16:59, Sui Jingfeng wrote:
>>>> But userspace must be able to continue allocating YUV buffers through
>>>> CREATE_DUMB.
>>>
>>> I think, allocating YUV buffers through CREATE_DUMB interface is just
>>> an *abuse* and *misuse* of this API for now.
>>>
>>> Take the NV12 format as an example, NV12 is YUV420 planar format, have
>>> two planar: the Y-planar and the UV-planar. The Y-planar appear first
>>> in memory as an array of unsigned char values. The Y-planar is followed
>>> immediately by the UV-planar, which is also an array of unsigned char
>>> values that contains packed U (Cb) and V (Cr) samples.
>>>
>>> But the 'drm_mode_create_dumb' structure is only intend to provide
>>> descriptions for *one* planar.
>>>
>>> struct drm_mode_create_dumb {
>>> __u32 height;
>>> __u32 width;
>>> __u32 bpp;
>>> __u32 flags;
>>> __u32 handle;
>>> __u32 pitch;
>>> __u64 size;
>>> };
>>>
>>> An width x height NV12 image takes up width*height*(1 + 1/4 + 1/4)
>>> bytes.
>>>
>>> So we can allocate an *equivalent* sized buffer to store the NV12 raw
>>> data.
>>>
>>> Either 'width * (height * 3/2)' where each pixel take up 8 bits,
>>> or just 'with * height' where each pixels take up 12 bits.
>>>
>>> However, all those math are just equivalents description to the original
>>> NV12 format, neither are concrete correct physical description.
>>
>> I don't see the problem. Allocating dumb buffers, if we don't have any
>> heuristics related to RGB behind it, is essentially just allocating a
>> specific amount of memory, defined by width, height and bitsperpixel.
>>
> I think, the problem will be that the 'width', 'height' and 'bpp'
> are originally used to describe one plane. Those three parameters
> has perfectly defined physical semantics.
>
> But with multi planar formats, take NV12 image as an example,
> for a 2×2 square of pixels, there are 4 Y samples but only 1 U
> sample and 1 V sample. This format requires 4x8+1x8+1x8=48 bits
> to store the 2x2 square.
>
> So its depth is 12 bits per pixel (48 / (2 * 2)).
>
> so my problem is that the mentioned 12bpp in this example only
> make sense in mathematics, it doesn't has a good physical
> interpret. Do you agree with me on this technique point?
>
>> If I want to create an NV12 framebuffer, I allocate two dumb buffers,
>> one for Y and one for UV planes, and size them accordingly. And then
>> create the DRM framebuffer with those.
>>
> Then how you fill the value of the 'width', 'height' and 'bpp' of each
> dumb buffers?
For 640x480-NV12:
plane 0: width = 640, height = 480, bpp = 8
plane 1: width = 640 / 2, height = 480 / 2, bpp = 16
> Why not allocate storage for the whole on one shoot?
You can, if you adjust the parameters accordingly. However, if the
strides of the planes are not equal, I guess it might cause problems on
some platforms.
But I think it's usually simpler to allocate one buffer per plane, and
perhaps even better as it doesn't require as large contiguous memory area.
> The modetest in libdrm can be an good example, send it[1] to you as an
> reference.
Right, so modetest already does it successfully. So... What is the issue?
Everyone agrees that CREATE_DUMB is not the best ioctl to allocate
buffers, and one can't consider it to work identically across the
platforms. But it's what we have and what has been used for ages.
Tomi
More information about the dri-devel
mailing list