diff mbox

[FFmpeg-devel] libavutil/hwcontext_opencl.c: fix bug in `opencl_get_plane_format`

Message ID 20190405230545.26890-1-cldfire3@gmail.com
State Superseded
Headers show

Commit Message

Jarek Samic April 5, 2019, 11:05 p.m. UTC
The `opencl_get_plane_format` function was incorrectly determining the
value used to set the image channel order. This resulted in all RGB
pixel formats being set to the `CL_RGBA` pixel format, regardless of
whether or not they actually *were* RGBA.

This patch fixes the issue by using the `offset` field on components
rather than the loop index to determine the value of `order` for RGB
pixel formats (and leaves the formula to determine `order` the same for
other formats so as not to break those cases).

Signed-off-by: Jarek Samic <cldfire3@gmail.com>
---
I'm including this in the email (but not the commit description) to
make this patch easier to review. In order to make sure I was fixing
the bug and not messing up channel order mapping for any of the other
formats, I set up a few quick print statements within the function
after the `order` value was set.

Here's the output without this patch:

```
[AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
[AVHWDeviceContext @ _] Format yuv420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
[AVHWDeviceContext @ _] Format yuv422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
[AVHWDeviceContext @ _] Format yuv444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
[AVHWDeviceContext @ _] Format yuv410p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
[AVHWDeviceContext @ _] Format yuv411p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
[AVHWDeviceContext @ _] Format gray supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
[AVHWDeviceContext @ _] Format yuvj420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
[AVHWDeviceContext @ _] Format yuvj422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
[AVHWDeviceContext @ _] Format yuvj444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
[AVHWDeviceContext @ _] Format nv12 supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
[AVHWDeviceContext @ _] Format nv21 supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: argb, plane: 0
[AVHWDeviceContext @ _] Format argb supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
[AVHWDeviceContext @ _] Format rgba supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: abgr, plane: 0
[AVHWDeviceContext @ _] Format abgr supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: bgra, plane: 0
[AVHWDeviceContext @ _] Format bgra supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
[AVHWDeviceContext @ _] Format gray16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
[AVHWDeviceContext @ _] Format yuv440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
[AVHWDeviceContext @ _] Format yuvj440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
[AVHWDeviceContext @ _] Format yuva420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv444p16le supported.
[opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
[AVHWDeviceContext @ _] Format ya8 supported.
[opencl_get_plane_format] order_num: 2, pixel_format: gbrp, plane: 0
[opencl_get_plane_format] order_num: 3, pixel_format: gbrp, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
[AVHWDeviceContext @ _] Format gbrp supported.
[opencl_get_plane_format] order_num: 2, pixel_format: gbrp16le, plane: 0
[opencl_get_plane_format] order_num: 3, pixel_format: gbrp16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
[AVHWDeviceContext @ _] Format gbrp16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
[AVHWDeviceContext @ _] Format yuva422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
[AVHWDeviceContext @ _] Format yuva444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva444p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
[AVHWDeviceContext @ _] Format nv16 supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
[AVHWDeviceContext @ _] Format rgba64le supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: bgra64le, plane: 0
[AVHWDeviceContext @ _] Format bgra64le supported.
[opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
[AVHWDeviceContext @ _] Format ya16le supported.
[opencl_get_plane_format] order_num: 2, pixel_format: gbrap, plane: 0
[opencl_get_plane_format] order_num: 3, pixel_format: gbrap, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: gbrap, plane: 3
[AVHWDeviceContext @ _] Format gbrap supported.
[opencl_get_plane_format] order_num: 2, pixel_format: gbrap16le, plane: 0
[opencl_get_plane_format] order_num: 3, pixel_format: gbrap16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: gbrap16le, plane: 3
[AVHWDeviceContext @ _] Format gbrap16le supported.
[opencl_get_plane_format] order_num: 123, pixel_format: 0rgb, plane: 0
[opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
[opencl_get_plane_format] order_num: 123, pixel_format: 0bgr, plane: 0
[opencl_get_plane_format] order_num: 123, pixel_format: bgr0, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
[AVHWDeviceContext @ _] Format yuvj411p supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
[AVHWDeviceContext @ _] Format ayuv64le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
[AVHWDeviceContext @ _] Format p010le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
[AVHWDeviceContext @ _] Format p016le supported.
```

Here's the output with this patch:

```
[AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
[AVHWDeviceContext @ _] Format yuv420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
[AVHWDeviceContext @ _] Format yuv422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
[AVHWDeviceContext @ _] Format yuv444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
[AVHWDeviceContext @ _] Format yuv410p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
[AVHWDeviceContext @ _] Format yuv411p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
[AVHWDeviceContext @ _] Format gray supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
[AVHWDeviceContext @ _] Format yuvj420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
[AVHWDeviceContext @ _] Format yuvj422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
[AVHWDeviceContext @ _] Format yuvj444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
[AVHWDeviceContext @ _] Format nv12 supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
[AVHWDeviceContext @ _] Format nv21 supported.
[opencl_get_plane_format] order_num: 2341, pixel_format: argb, plane: 0
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
[AVHWDeviceContext @ _] Format rgba supported.
[opencl_get_plane_format] order_num: 4321, pixel_format: abgr, plane: 0
[opencl_get_plane_format] order_num: 3214, pixel_format: bgra, plane: 0
[AVHWDeviceContext @ _] Format bgra supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
[AVHWDeviceContext @ _] Format gray16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
[AVHWDeviceContext @ _] Format yuv440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
[AVHWDeviceContext @ _] Format yuvj440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
[AVHWDeviceContext @ _] Format yuva420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv444p16le supported.
[opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
[AVHWDeviceContext @ _] Format ya8 supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
[AVHWDeviceContext @ _] Format gbrp supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
[AVHWDeviceContext @ _] Format gbrp16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
[AVHWDeviceContext @ _] Format yuva422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
[AVHWDeviceContext @ _] Format yuva444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
[opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva444p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
[AVHWDeviceContext @ _] Format nv16 supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
[AVHWDeviceContext @ _] Format rgba64le supported.
[opencl_get_plane_format] order_num: 3214, pixel_format: bgra64le, plane: 0
[opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
[AVHWDeviceContext @ _] Format ya16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 3
[AVHWDeviceContext @ _] Format gbrap supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 3
[AVHWDeviceContext @ _] Format gbrap16le supported.
[opencl_get_plane_format] order_num: 234, pixel_format: 0rgb, plane: 0
[opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
[opencl_get_plane_format] order_num: 432, pixel_format: 0bgr, plane: 0
[opencl_get_plane_format] order_num: 321, pixel_format: bgr0, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
[opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
[opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
[AVHWDeviceContext @ _] Format yuvj411p supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
[AVHWDeviceContext @ _] Format ayuv64le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
[AVHWDeviceContext @ _] Format p010le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
[opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
[AVHWDeviceContext @ _] Format p016le supported.
```

Feel free to compare the two with your favorite diff tool. You'll notice
that the various RGB formats (RGBA, ARGB, BGRA...) are now having the
correct channel order assigned and that the channel order for the other
formats is unchanged.

 libavutil/hwcontext_opencl.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Mark Thompson April 7, 2019, 9:16 p.m. UTC | #1
On 06/04/2019 00:05, Jarek Samic wrote:
> The `opencl_get_plane_format` function was incorrectly determining the
> value used to set the image channel order. This resulted in all RGB
> pixel formats being set to the `CL_RGBA` pixel format, regardless of
> whether or not they actually *were* RGBA.
> 
> This patch fixes the issue by using the `offset` field on components
> rather than the loop index to determine the value of `order` for RGB
> pixel formats (and leaves the formula to determine `order` the same for
> other formats so as not to break those cases).
> 
> Signed-off-by: Jarek Samic <cldfire3@gmail.com>
> ---
> I'm including this in the email (but not the commit description) to
> make this patch easier to review. In order to make sure I was fixing
> the bug and not messing up channel order mapping for any of the other
> formats, I set up a few quick print statements within the function
> after the `order` value was set.
> 
> Here's the output without this patch:
> 
> ```
> [AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
> [AVHWDeviceContext @ _] Format yuv410p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
> [AVHWDeviceContext @ _] Format yuv411p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
> [AVHWDeviceContext @ _] Format gray supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
> [AVHWDeviceContext @ _] Format nv12 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
> [AVHWDeviceContext @ _] Format nv21 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: argb, plane: 0
> [AVHWDeviceContext @ _] Format argb supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
> [AVHWDeviceContext @ _] Format rgba supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: abgr, plane: 0
> [AVHWDeviceContext @ _] Format abgr supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: bgra, plane: 0
> [AVHWDeviceContext @ _] Format bgra supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
> [AVHWDeviceContext @ _] Format gray16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
> [AVHWDeviceContext @ _] Format yuv440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p16le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
> [AVHWDeviceContext @ _] Format ya8 supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrp, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrp, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
> [AVHWDeviceContext @ _] Format gbrp supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrp16le, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrp16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
> [AVHWDeviceContext @ _] Format gbrp16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
> [AVHWDeviceContext @ _] Format nv16 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
> [AVHWDeviceContext @ _] Format rgba64le supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: bgra64le, plane: 0
> [AVHWDeviceContext @ _] Format bgra64le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
> [AVHWDeviceContext @ _] Format ya16le supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrap, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrap, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: gbrap, plane: 3
> [AVHWDeviceContext @ _] Format gbrap supported.
> [opencl_get_plane_format] order_num: 2, pixel_format: gbrap16le, plane: 0
> [opencl_get_plane_format] order_num: 3, pixel_format: gbrap16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: gbrap16le, plane: 3
> [AVHWDeviceContext @ _] Format gbrap16le supported.
> [opencl_get_plane_format] order_num: 123, pixel_format: 0rgb, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: 0bgr, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: bgr0, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj411p supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
> [AVHWDeviceContext @ _] Format ayuv64le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
> [AVHWDeviceContext @ _] Format p010le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
> [AVHWDeviceContext @ _] Format p016le supported.
> ```
> 
> Here's the output with this patch:
> 
> ```
> [AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv410p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv410p, plane: 2
> [AVHWDeviceContext @ _] Format yuv410p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv411p, plane: 2
> [AVHWDeviceContext @ _] Format yuv411p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
> [AVHWDeviceContext @ _] Format gray supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj420p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj422p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj444p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv12, plane: 1
> [AVHWDeviceContext @ _] Format nv12 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv21, plane: 1
> [AVHWDeviceContext @ _] Format nv21 supported.
> [opencl_get_plane_format] order_num: 2341, pixel_format: argb, plane: 0
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
> [AVHWDeviceContext @ _] Format rgba supported.
> [opencl_get_plane_format] order_num: 4321, pixel_format: abgr, plane: 0
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra, plane: 0
> [AVHWDeviceContext @ _] Format bgra supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
> [AVHWDeviceContext @ _] Format gray16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv440p, plane: 2
> [AVHWDeviceContext @ _] Format yuv440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj440p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj440p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv420p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv422p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuv444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuv444p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p16le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
> [AVHWDeviceContext @ _] Format ya8 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
> [AVHWDeviceContext @ _] Format gbrp supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
> [AVHWDeviceContext @ _] Format gbrp16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva420p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva420p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva420p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva422p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva422p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva422p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuva444p16le, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuva444p16le, plane: 2
> [opencl_get_plane_format] order_num: 4, pixel_format: yuva444p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: nv16, plane: 1
> [AVHWDeviceContext @ _] Format nv16 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
> [AVHWDeviceContext @ _] Format rgba64le supported.
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra64le, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
> [AVHWDeviceContext @ _] Format ya16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 3
> [AVHWDeviceContext @ _] Format gbrap supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 3
> [AVHWDeviceContext @ _] Format gbrap16le supported.
> [opencl_get_plane_format] order_num: 234, pixel_format: 0rgb, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
> [opencl_get_plane_format] order_num: 432, pixel_format: 0bgr, plane: 0
> [opencl_get_plane_format] order_num: 321, pixel_format: bgr0, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
> [opencl_get_plane_format] order_num: 2, pixel_format: yuvj411p, plane: 1
> [opencl_get_plane_format] order_num: 3, pixel_format: yuvj411p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj411p supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: ayuv64le, plane: 0
> [AVHWDeviceContext @ _] Format ayuv64le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p010le, plane: 1
> [AVHWDeviceContext @ _] Format p010le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
> [opencl_get_plane_format] order_num: 23, pixel_format: p016le, plane: 1
> [AVHWDeviceContext @ _] Format p016le supported.
> ```
> 
> Feel free to compare the two with your favorite diff tool. You'll notice
> that the various RGB formats (RGBA, ARGB, BGRA...) are now having the
> correct channel order assigned and that the channel order for the other
> formats is unchanged.
> 
>  libavutil/hwcontext_opencl.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index b116c5b708..b6c389b95d 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -1376,6 +1376,7 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
>      int channels = 0, order = 0, depth = 0, step = 0;
>      int wsub, hsub, alpha;
>      int c;
> +    int add_to_ord;
>  
>      if (plane >= AV_NUM_DATA_POINTERS)
>          return AVERROR(ENOENT);
> @@ -1419,7 +1420,23 @@ static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
>          // from the same component.
>          if (step && comp->step != step)
>              return AVERROR(EINVAL);
> -        order = order * 10 + c + 1;
> +
> +        if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
> +            // If the format is RGB we determine the order number using the
> +            // component's offset values
> +
> +            // Here we handle 8 vs 16 bit components
> +            if (comp->depth <= 8) {
> +                add_to_ord = comp->offset;
> +            } else {
> +                add_to_ord = comp->offset / 2;
> +            }
> +        } else {
> +            // Otherwise we maintain the previous behavior that used the loop
> +            // index
> +            add_to_ord = c;
> +        }> +        order = order * 10 + add_to_ord + 1;

The RGB test really feels like it shouldn't be necessary here (why should RGB be special?).

Does anything go wrong if you unconditionally add comp->offset / (depth / 8)?  Looking through the cases in your output above, the only change I can see it would make would be to change the order of the chroma plane on the two-plane YUV formats (like NV12) from 23 to 12, but that's still RG so the result would be the same.

>          depth = comp->depth;
>          step  = comp->step;
>          alpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA &&
> 

(A further thought - given a change like that, can the cases not containing a 1 in the switch on order be removed?  They look redundant.)

Thanks,

- Mark
Jarek Samic April 7, 2019, 10:40 p.m. UTC | #2
>
> Does anything go wrong if you unconditionally add comp->offset / (depth /
> 8)?


Yes. Occasionally there is a depth value less than 8:

[opencl_get_plane_format] depth is 2 < 8 for format: rgb8 on plane: 0
[AVHWDeviceContext @ _] Format yuva420p supported.
[opencl_get_plane_format] depth is 5 < 8 for format: rgb565be on plane: 0
[opencl_get_plane_format] depth is 5 < 8 for format: rgb565le on plane: 0

Which causes an FPE (divide-by-zero). If I throw in an if statement to weed
out those cases, that method of calculating the number results in the
following output:

[AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 2
[AVHWDeviceContext @ _] Format yuv420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 2
[AVHWDeviceContext @ _] Format yuv422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 2
[AVHWDeviceContext @ _] Format yuv444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 2
[AVHWDeviceContext @ _] Format yuv410p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 2
[AVHWDeviceContext @ _] Format yuv411p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
[AVHWDeviceContext @ _] Format gray supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 2
[AVHWDeviceContext @ _] Format yuvj420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 2
[AVHWDeviceContext @ _] Format yuvj422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 2
[AVHWDeviceContext @ _] Format yuvj444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
[opencl_get_plane_format] order_num: 12, pixel_format: nv12, plane: 1
[AVHWDeviceContext @ _] Format nv12 supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
[opencl_get_plane_format] order_num: 21, pixel_format: nv21, plane: 1
[opencl_get_plane_format] order_num: 2341, pixel_format: argb, plane: 0
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
[AVHWDeviceContext @ _] Format rgba supported.
[opencl_get_plane_format] order_num: 4321, pixel_format: abgr, plane: 0
[opencl_get_plane_format] order_num: 3214, pixel_format: bgra, plane: 0
[AVHWDeviceContext @ _] Format bgra supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
[AVHWDeviceContext @ _] Format gray16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 2
[AVHWDeviceContext @ _] Format yuv440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 2
[AVHWDeviceContext @ _] Format yuvj440p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 3
[AVHWDeviceContext @ _] Format yuva420p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 2
[AVHWDeviceContext @ _] Format yuv444p16le supported.
[opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
[AVHWDeviceContext @ _] Format ya8 supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
[AVHWDeviceContext @ _] Format gbrp supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
[AVHWDeviceContext @ _] Format gbrp16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 3
[AVHWDeviceContext @ _] Format yuva422p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 3
[AVHWDeviceContext @ _] Format yuva444p supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva420p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva422p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 3
[AVHWDeviceContext @ _] Format yuva444p16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
[opencl_get_plane_format] order_num: 12, pixel_format: nv16, plane: 1
[AVHWDeviceContext @ _] Format nv16 supported.
[opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
[AVHWDeviceContext @ _] Format rgba64le supported.
[opencl_get_plane_format] order_num: 3214, pixel_format: bgra64le, plane: 0
[opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
[AVHWDeviceContext @ _] Format ya16le supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 3
[AVHWDeviceContext @ _] Format gbrap supported.
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
[opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 3
[AVHWDeviceContext @ _] Format gbrap16le supported.
[opencl_get_plane_format] order_num: 234, pixel_format: 0rgb, plane: 0
[opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
[opencl_get_plane_format] order_num: 432, pixel_format: 0bgr, plane: 0
[opencl_get_plane_format] order_num: 321, pixel_format: bgr0, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 2
[AVHWDeviceContext @ _] Format yuvj411p supported.
[opencl_get_plane_format] order_num: 2341, pixel_format: ayuv64le, plane: 0
[opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
[opencl_get_plane_format] order_num: 13, pixel_format: p010le, plane: 1
[opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
[opencl_get_plane_format] order_num: 12, pixel_format: p016le, plane: 1
[AVHWDeviceContext @ _] Format p016le supported.

This is mostly fine, but it looks like nv21, ayuv64le, and p010le are all
having their order numbers changed to broken values.
Mark Thompson April 7, 2019, 11:26 p.m. UTC | #3
On 07/04/2019 23:40, Cld fire wrote:
>>
>> Does anything go wrong if you unconditionally add comp->offset / (depth /
>> 8)?
> 
> 
> Yes. Occasionally there is a depth value less than 8:
> 
> [opencl_get_plane_format] depth is 2 < 8 for format: rgb8 on plane: 0
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] depth is 5 < 8 for format: rgb565be on plane: 0
> [opencl_get_plane_format] depth is 5 < 8 for format: rgb565le on plane: 0
> 
> Which causes an FPE (divide-by-zero). If I throw in an if statement to weed
> out those cases, that method of calculating the number results in the
> following output:
> 
> [AVHWDeviceContext @ _] Maximum supported image size 16384x16384.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv410p, plane: 2
> [AVHWDeviceContext @ _] Format yuv410p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv411p, plane: 2
> [AVHWDeviceContext @ _] Format yuv411p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray, plane: 0
> [AVHWDeviceContext @ _] Format gray supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj420p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj422p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj444p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv12, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: nv12, plane: 1
> [AVHWDeviceContext @ _] Format nv12 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv21, plane: 0
> [opencl_get_plane_format] order_num: 21, pixel_format: nv21, plane: 1
> [opencl_get_plane_format] order_num: 2341, pixel_format: argb, plane: 0
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba, plane: 0
> [AVHWDeviceContext @ _] Format rgba supported.
> [opencl_get_plane_format] order_num: 4321, pixel_format: abgr, plane: 0
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra, plane: 0
> [AVHWDeviceContext @ _] Format bgra supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gray16le, plane: 0
> [AVHWDeviceContext @ _] Format gray16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv440p, plane: 2
> [AVHWDeviceContext @ _] Format yuv440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj440p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj440p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv420p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv422p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuv444p16le, plane: 2
> [AVHWDeviceContext @ _] Format yuv444p16le supported.
> [opencl_get_plane_format] order_num: 12, pixel_format: ya8, plane: 0
> [AVHWDeviceContext @ _] Format ya8 supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp, plane: 2
> [AVHWDeviceContext @ _] Format gbrp supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrp16le, plane: 2
> [AVHWDeviceContext @ _] Format gbrp16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva420p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva420p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva422p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva422p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: yuva444p16le, plane: 3
> [AVHWDeviceContext @ _] Format yuva444p16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: nv16, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: nv16, plane: 1
> [AVHWDeviceContext @ _] Format nv16 supported.
> [opencl_get_plane_format] order_num: 1234, pixel_format: rgba64le, plane: 0
> [AVHWDeviceContext @ _] Format rgba64le supported.
> [opencl_get_plane_format] order_num: 3214, pixel_format: bgra64le, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: ya16le, plane: 0
> [AVHWDeviceContext @ _] Format ya16le supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap, plane: 3
> [AVHWDeviceContext @ _] Format gbrap supported.
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 2
> [opencl_get_plane_format] order_num: 1, pixel_format: gbrap16le, plane: 3
> [AVHWDeviceContext @ _] Format gbrap16le supported.
> [opencl_get_plane_format] order_num: 234, pixel_format: 0rgb, plane: 0
> [opencl_get_plane_format] order_num: 123, pixel_format: rgb0, plane: 0
> [opencl_get_plane_format] order_num: 432, pixel_format: 0bgr, plane: 0
> [opencl_get_plane_format] order_num: 321, pixel_format: bgr0, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: yuvj411p, plane: 2
> [AVHWDeviceContext @ _] Format yuvj411p supported.
> [opencl_get_plane_format] order_num: 2341, pixel_format: ayuv64le, plane: 0
> [opencl_get_plane_format] order_num: 1, pixel_format: p010le, plane: 0
> [opencl_get_plane_format] order_num: 13, pixel_format: p010le, plane: 1
> [opencl_get_plane_format] order_num: 1, pixel_format: p016le, plane: 0
> [opencl_get_plane_format] order_num: 12, pixel_format: p016le, plane: 1
> [AVHWDeviceContext @ _] Format p016le supported.
> 
> This is mostly fine, but it looks like nv21, ayuv64le, and p010le are all
> having their order numbers changed to broken values.

The changes to AYUV and NV21 both make sense - they can be supported because the layout works, but they require special treatment to use beyond just taking the given planes in the order common to other formats.  It doesn't seem unreasonable to drop them because of that?  I don't think any existing code actually supports them (e.g. trying to overlay AYUV on anything is going to mess up totally).

For P010, I guess that division needs to round up?  element_size = (comp->depth + 7) / 8.

Thanks,

- Mark
Jarek Samic April 8, 2019, 12:10 a.m. UTC | #4
>
> For P010, I guess that division needs to round up?
>

Yep, rounding the division up did the trick; thanks!

One last observation before I submit a new patch: I actually missed
previously that the order number is still not lining up for the ARGB format
(the order number that maps to ARGB in the code is currently 4123 while the
new method using the offset and depth is ending up with an order number of
2341). Simply changing the order number that maps to ARGB from 4123 to 2341
seems to work fine; is it okay to make that change or do the mapping
numbers need to remain exactly the same?
Ruiling Song April 8, 2019, 1:11 a.m. UTC | #5
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> Mark Thompson

> Sent: Monday, April 8, 2019 7:27 AM

> To: ffmpeg-devel@ffmpeg.org

> Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_opencl.c: fix bug in

> `opencl_get_plane_format`

> >

> > This is mostly fine, but it looks like nv21, ayuv64le, and p010le are all

> > having their order numbers changed to broken values.

> 

> The changes to AYUV and NV21 both make sense - they can be supported

> because the layout works, but they require special treatment to use beyond just

> taking the given planes in the order common to other formats.  It doesn't seem

> unreasonable to drop them because of that?  I don't think any existing code

> actually supports them (e.g. trying to overlay AYUV on anything is going to mess

> up totally).

I think AYUV can be mapped the same as ARGB.
For NV21, as OpenCL does not support CL_GR. I am ok not supporting this format unless someone strongly require this with a reason.

Thanks!
Ruiling
> 

> For P010, I guess that division needs to round up?  element_size = (comp->depth

> + 7) / 8.

> 

> Thanks,

> 

> - Mark

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

> 

> To unsubscribe, visit link above, or email

> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Ruiling Song April 8, 2019, 1:15 a.m. UTC | #6
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf Of

> Cld fire

> Sent: Monday, April 8, 2019 8:11 AM

> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>

> Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_opencl.c: fix bug in

> `opencl_get_plane_format`

> 

> >

> > For P010, I guess that division needs to round up?

> >

> 

> Yep, rounding the division up did the trick; thanks!

> 

> One last observation before I submit a new patch: I actually missed

> previously that the order number is still not lining up for the ARGB format

> (the order number that maps to ARGB in the code is currently 4123 while the

> new method using the offset and depth is ending up with an order number of

> 2341). Simply changing the order number that maps to ARGB from 4123 to 2341

> seems to work fine; is it okay to make that change or do the mapping

> numbers need to remain exactly the same?

I think we don't need to remain exact as before, you can update the case-values accordingly.
And 2341 seems correct for ARGB.

Thanks!
Ruiling
> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

> 

> To unsubscribe, visit link above, or email

> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox

Patch

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index b116c5b708..b6c389b95d 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -1376,6 +1376,7 @@  static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
     int channels = 0, order = 0, depth = 0, step = 0;
     int wsub, hsub, alpha;
     int c;
+    int add_to_ord;
 
     if (plane >= AV_NUM_DATA_POINTERS)
         return AVERROR(ENOENT);
@@ -1419,7 +1420,23 @@  static int opencl_get_plane_format(enum AVPixelFormat pixfmt,
         // from the same component.
         if (step && comp->step != step)
             return AVERROR(EINVAL);
-        order = order * 10 + c + 1;
+
+        if (desc->flags & AV_PIX_FMT_FLAG_RGB) {
+            // If the format is RGB we determine the order number using the
+            // component's offset values
+
+            // Here we handle 8 vs 16 bit components
+            if (comp->depth <= 8) {
+                add_to_ord = comp->offset;
+            } else {
+                add_to_ord = comp->offset / 2;
+            }
+        } else {
+            // Otherwise we maintain the previous behavior that used the loop
+            // index
+            add_to_ord = c;
+        }
+        order = order * 10 + add_to_ord + 1;
         depth = comp->depth;
         step  = comp->step;
         alpha = (desc->flags & AV_PIX_FMT_FLAG_ALPHA &&