Commit Graph

77 Commits

Author SHA1 Message Date
David Rosca 1e2ac489a4 lavu/hwcontext_vaapi: Use vaMapBuffer2 for mapping image buffers
This allows some optimizations in driver, such as not having to read
back the data if write-only mapping is requested.
2024-04-29 11:08:41 +08:00
Andreas Rheinhardt 3e669b24e2 avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals
This is possible because the lifetime of these structures coincide.
It has the advantage of allowing to remove AVHWFramesInternal
from the public header; given that AVHWFramesInternal.priv is no more,
most accesses to AVHWFramesInternal are no more; indeed, the only
field accessed of it outside of hwcontext.c is the internal frame pool,
making this commit very simple.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-07 08:53:31 -03:00
Andreas Rheinhardt 870d9730d6 avutil/hwcontext_vaapi: Allocate pub and priv frames hwctx together
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VAAPIFramesContext as one no longer has to
go through AVHWFramesInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-20 19:08:23 +01:00
Andreas Rheinhardt 520c1b0a7c avutil/hwcontext_vaapi: Allocate public and priv device hwctx together
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VAAPIDeviceContext as one no longer has to
go through AVHWDeviceInternal.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-20 19:08:14 +01:00
Haihao Xiang d36d9994e4 lavu/hwcontext_vaapi: ignore nonexistent device in default DRM device selection
It is possible that renderD128 doesn't exist but renderD129 is
available in a system (see [1]). This change can make sure the default
DRM device selection works even if renderD128 doesn't exist.

[1] https://github.com/intel/intel-device-plugins-for-kubernetes/blob/main/cmd/gpu_plugin/README.md#issues-with-media-workloads-on-multi-gpu-setups

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2023-12-05 10:09:55 +08:00
Zhao Zhili 105657540b avutil/hwcontext_vaapi: return ENOSYS for unsupported operation
av_hwframe_transfer_data try with src_ctx first. If the operation
failed with AVERROR(ENOSYS), it will try again with dst_ctx. Return
AVERROR(EINVAL) makes the second step being skipped.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
2023-10-29 13:58:52 +08:00
David Rosca 2ec58055f5 lavu/hwcontext_vaapi: Add vaapi_drm_format_map support for x2rgb10
Support for allocating frames with x2rgb10 format was added
in c00264f501, this adds support for importing DMA-BUFs.
2023-08-17 12:06:09 +08:00
Sil Vilerino d54127c41a lavu/hwcontext_vaapi: Add Windows/VAAPI support with vaGetDisplayWin32
Libva 2.17+ adds a new libva-win32 node and Mesa 22.3 adds a VAAPI driver
based on Direct3D 12 for Windows. Both of them are available at:
https://www.nuget.org/packages/Microsoft.Direct3D.VideoAccelerationCompatibilityPack

Initial review at https://github.com/intel-media-ci/ffmpeg/pull/619/

Signed-off-by: Sil Vilerino <sivileri@microsoft.com>
Reviewed-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Reviewed-by: Wu, Tong1 <tong1.wu@intel.com>
2023-04-24 13:24:41 +08:00
Fei Wang 15992a040d lavu/hwcontext_vaapi: sync surface before export its DRM handle
According to description of vaExportSurfaceHandle in libva, vaSyncSurface
must be called if the contents of the surface will be read.

Fixes ticket #9967.

Reviewed-by: Zhao Zhili <zhilizhao@tencent.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2023-02-27 13:42:06 +08:00
Brian Norris b62940bec3 lavu/hwcontext_vaapi: Skip 'vgem' driver
There can be more than one available render node, and it's not
guaranteed the first node we come across is the correct one. In
particular, 'vgem' devices are common, and are
never VAAPI-enabled and thus not valid here.

We have a 'kernel_driver' arg already for specifying a single driver we
*do* want, but it doesn't support a negation, nor a list. It's easier
just to automatically skip 'vgem' anyway, to avoid foisting this burden
on users.

This has precedent in libva-utils already:

  bfb6b98ed62a exclude vgem node and invalid drm node in vainfo
  bfb6b98ed6

Signed-off-by: Brian Norris <briannorris@chromium.org>
2022-12-08 14:30:04 +08:00
Carl Eugen Hoyos 882a17068f lavu/hwcontext_vaapi: Fix type specifier for uintptr_t
Fixes a format specifier warning on x86_32 Linux.
Fixes part of ticket #9986.
2022-10-23 20:51:42 +02:00
Philip Langdale b982dd0d83 lavc/vaapi: Add support for remaining 10/12bit profiles
With the necessary pixel formats defined, we can now expose support for
the remaining 10/12bit combinations that VAAPI can handle.

Specifically, we are adding support for:

* HEVC
** 12bit 420
** 10bit 422
** 12bit 422
** 10bit 444
** 12bit 444

* VP9
** 10bit 444
** 12bit 444

These obviously require actual hardware support to be usable, but where
that exists, it is now enabled.

Note that unlike YUVA/YUVX, the Intel driver does not formally expose
support for the alphaless formats XV30 and XV360, and so we are
implicitly discarding the alpha from the decoder and passing undefined
values for the alpha to the encoder. If a future encoder iteration was
to actually do something with the alpha bits, we would need to use a
formal alpha capable format or the encoder would need to explicitly
accept the alphaless format.
2022-09-03 16:19:40 -07:00
Philip Langdale caf26a8a12 lavc/vaapi: Switch preferred 8bit 444 format to VUYX
As vaapi doesn't actually do anything useful with the alpha channel,
and we have an alphaless format available, let's use that instead.

The changes here are mostly 1:1 switching, but do note the explicit
change in the number of declared channels from 4 to 3 to reflect that
the alpha is being ignored.
2022-08-25 19:04:10 -07:00
Philip Langdale 2b720676e0 lavu/hwcontext_vaapi: Map the AYUV format
This is the format used by Intel VAAPI for 8bit 4:4:4 content.
2022-08-03 14:10:12 -07:00
Ingo Brückl 02111be0c1 libavutil/hwcontext_vaapi: Re-enable support for libva v1
Commit e050959103 implemented passing in
modifiers by using the PRIME_2 memory type, which only exists in v2 of
the library.

To still support v1 of the library, conditionally compile using
VA_CHECK_VERSION() for both the new code and the old code before
the commit.

Note PRIME_2 memory was introduced from VA-API 1.1, so use
VA_CHECK_VERSION(1, 1, 0) instead of VA_CHECK_VERSION(2, 0, 0) (Haihao)

Signed-off-by: Ingo Brückl <ib@wupperonline.de>
Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2022-04-06 17:12:26 +08:00
Wenbin Chen f3c9847c27 libavutil/hwcontext_vaapi: Add a new nv12 format map to support vulkan frame
Vulkan will map nv12 to R8 and GR88, so add this map to vaapi to support
vulkan frame.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
2021-12-10 17:03:48 +01:00
Bas Nieuwenhuizen e050959103 hwcontext_vaapi: Use PRIME_2 memory type for modifiers.
This way we can pass explicit modifiers in. Sometimes the
modifier matters for the number of memory planes that
libva accepts, in particular when dealing with
driver-compressed textures. Furthermore the driver might
not actually be able to determine the implicit modifier
if all the buffer-passing has used explicit modifier.
All these issues should be resolved by passing in the
modifier, and for that we switch to using the PRIME_2
memory type.

Tested with experimental radeonsi patches for modifiers
and kmsgrab. Also tested with radeonsi without the
patches to double-check it works without PRIME_2 support.

v2:
  Cache PRIME_2 support to avoid doing two calls every time on
  libva drivers that do not support it.

v3:
  Remove prime2_vas usage.

Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
2021-12-10 17:03:39 +01:00
Andreas Rheinhardt ef6a9e5e31 avutil/buffer: Switch AVBuffer API to size_t
Announced in 14040a1d91.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:13 -03:00
James Almer e36eb94048 avutil: use the buffer_size_t typedef where required
Signed-off-by: James Almer <jamrial@gmail.com>
2021-03-10 20:26:37 -03:00
Mark Thompson 303d252a4b hwcontext_vaapi: Don't require a render node when deriving from DRM
The V4L2 driver does not actually have an associated DRM device at all, so
users work around the requirement by giving libva an unrelated display-only
device instead (which is fine, because it doesn't actually do anything with
that device).  This was broken by bc9b6358fb
forcing a render node, because the display-only device did not have an
associated render node to use.  Fix that by just passing through the
original non-render DRM fd if we can't find a render node.

Reported-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Tested-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
2020-08-31 21:42:14 +01:00
Haihao Xiang fa3da243e6 hwcontext_vaapi: remove duplicate formats from sw_format list
hwcontext_vaapi maps different VA fourcc to the same pix_fmt for U/V
plane swap cases, however duplicate formats are not expected in sw_format
list when merging formats.

For example:
ffmpeg -loglevel debug -init_hw_device vaapi -filter_hw_device vaapi0 \
-f lavfi -i smptebars -vf \
"hwupload=derive_device=vaapi,scale_vaapi,hwdownload,format=yuv420p" \
-vframes 1 -f null -

Without this fix, an auto scaler is required for the above command
   Duplicate formats in ff_merge_formats detected
   [auto_scaler_0 @ 0x560df58f4550] Setting 'flags' to value 'bicubic'
   [auto_scaler_0 @ 0x560df58f4550] w:iw h:ih flags:'bicubic' interl:0
   [Parsed_hwupload_0 @ 0x560df58f0ec0] auto-inserting filter
   'auto_scaler_0' between the filter 'graph 0 input from stream 0:0' and
   the filter 'Parsed_hwupload_0'

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2020-07-27 16:06:30 +01:00
Haihao Xiang d951eea6fd hwcontext_vaapi: avoid fd leak in vaapi_device_derive 2020-07-27 15:41:32 +01:00
Fei Wang c00264f501 lavu/hwcontext_vaapi: add vaapi_format_map support for x2rgb10
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
2020-06-12 17:56:15 +01:00
Lynne 2e08b39444
hwcontext: add av_hwdevice_ctx_create_derived_opts
This allows for users who derive devices to set options for the
new device context they derive.
The main use case of this is to allow users to enable extensions
(such as surface drawing extensions) in Vulkan while deriving from
the device their frames are on. That way, users don't need to write
any initialization code themselves, since the Vulkan spec invalidates
mixing instances, physical devices and active devices.
Apart from Vulkan, other hwcontexts ignore the opts argument since they
don't support options at all (or in VAAPI and OpenCL's case, options are
currently only used for device selection, which device_derive overrides).
2020-05-23 19:07:26 +01:00
Mark Thompson bc9b6358fb hwcontext_vaapi: Only accept a render node when deriving from DRM device
If we are given a non-render node, try to find the matching render node and
fail if that isn't possible.

libva will not accept a non-render device which is not DRM master, because
it requires legacy DRM authentication to succeed in that case:
<https://github.com/intel/libva/blob/master/va/drm/va_drm.c#L68-L75>.  This
is annoying for kmsgrab because in most recording situations DRM master is
already held by something else (such as a windowing system), leading to
device derivation not working and forcing the user to create the target
VAAPI device separately.
2020-02-24 00:09:51 +00:00
Linjie Fu f4cd4017bf lavu/hwcontext_vaapi: add vaapi_format_map support for Y210
VA_RT_FORMAT describes the desired sampling format for surface.

When creating surface, VA_RT_FORMAT will be used firstly to choose
the expected fourcc/media_format for the surface. And the fourcc
will be revised by the value of VASurfaceAttribPixelFormat.

Add vaapi_format_map support for new pixel_format Y210.
This is fundamental for both VA-API and QSV.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
2020-02-24 00:09:51 +00:00
Steven Liu 1498e39439 avutil/hwcontext_vaapi: move kernel_driver into CONFIG_LIBDRM
Reviewed-by: Zhong Li <zhong.li@intel.com>
Signed-off-by: Steven Liu <lq@onvideo.cn>
2019-07-11 09:34:57 +08:00
Mark Thompson 0b4696fbe8 hwcontext_vaapi: Try to create devices via DRM before X11
Opening the device via X11 (DRI2/DRI3) rather than opening a DRM render
node directly is only useful if you intend to use the legacy X11 interop
functions.  That's never true for the ffmpeg utility, and a library user
who does want this will likely provide their own display instance rather
than making a new one here.
2019-06-02 23:03:27 +01:00
Mark Thompson 7f3f5a24a1 hwcontext_vaapi: Add option to set driver name
For example: -init_hw_device vaapi:/dev/dri/renderD128,driver=foo

This may be more convenient that using the environment variable, and allows
loading different drivers for different devices in the same process.
2019-06-02 23:03:27 +01:00
Mark Thompson 6b6b8a6371 hwcontext_vaapi: Make default DRM device selection more helpful
Iterate over available render devices and pick the first one which looks
usable.  Adds an option to specify the name of the kernel driver associated
with the desired device, so that it is possible to select a specific type
of device in a multiple-device system without knowing the card numbering.

For example: -init_hw_device vaapi:,kernel_driver=amdgpu will select only
devices using the "amdgpu" driver (as used with recent AMD graphics cards).

Kernel driver selection requires libdrm to work.
2019-06-02 23:03:10 +01:00
Mark Thompson d2141a9b65 hwcontext_vaapi: Add option to specify connection type
Can be set to "drm" or "x11" to force a specific connection type.
2019-06-02 22:58:22 +01:00
Mark Thompson 40724026b7 hwcontext_vaapi: Improve format mapping
Give the entries in the VAAPI format map table an explicit type and add
functions to do the necessary lookups.  Add another field to this table
indicating whether the chroma planes are swapped (as in YV12), and use
that rather than explicit comparisons where swapping is needed.
2018-09-23 14:42:34 +01:00
Mark Thompson 852c7ba3f8 hwcontext_vaapi: Improve logging around quirk detection
Clarify that the list is the naughty list, and therefore being on it is
not desirable.  The i965 driver does not need to be on the list after
version 2.0 (when the standard parameter buffer rendering behaviour was
changed).
2018-09-23 14:42:34 +01:00
Mark Thompson 8ef51a4092 hwcontext_vaapi: Fix mapping from DRM
This was broken by bed670a1de, which added
an assert that always failed.
2018-05-24 01:20:31 +01:00
Haihao Xiang bed670a1de hwcontext_vaapi: Add an assert in vaapi_map_from_drm()
Every fourcc in vaapi_drm_format_map should be in
vaapi_format_map, so add an assert to ensure we have the right maps.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
2018-05-10 19:52:53 +01:00
Mark Thompson 92a0a6bea9 hwcontext_vaapi: Fix compilation with libva versions < 1.4.0
The BufferHandle API was added in libva 1.4.0 / VAAPI 0.36.0.
2018-04-27 23:29:51 +01:00
Mark Thompson ca9f13bbce hwcontext_vaapi: Pass correct read/write flags when exporting surfaces 2018-03-22 23:18:57 +00:00
Mark Thompson c6bbb8cca7 hwcontext_vaapi: Add support for legacy DRM mapping
The old vaAcquireBufferHandle() API works in fewer cases and provides
less information than the current vaExportSurfaceHandle(), but it exists
on older versions and is already used by the OpenCL code.
2018-03-22 23:18:55 +00:00
Mark Thompson 0f3d1c69b5 hwcontext_vaapi: Always include DRM hwcontext header
Fixes building with VAAPI but not libdrm, which was broken by
389f4c3e0d.  Just unconditionally include
the header, since it doesn't depend on libdrm being present.
2018-03-18 18:34:38 +00:00
Mark Thompson 389f4c3e0d hwcontext_vaapi: Fix condition for DRM device derivation
vaGetDisplayDRM() is required for this code to work, libdrm is not.
2018-03-18 17:55:00 +00:00
Mark Thompson 193e43e619 hwcontext_vaapi: Fix frames context creation with external attributes 2018-02-21 23:38:10 +00:00
Mark Thompson fabcbfba38 hwcontext_vaapi: Add more surface formats
Adds YUV 4:1:1, 4:4:0 and 4:4:4 - these will be needed for JPEG decoding.
2018-02-21 23:38:10 +00:00
Mark Thompson 6e0e3e1d8d hwcontext_vaapi: Do not assume that sw_format is transferable
Drivers can support a format for surfaces without also supporting it for
images, so we can't assume that sw_format is usable for transfer.  This
would previously hit an assert in cases where it isn't.
2017-11-26 15:40:24 +00:00
Jun Zhao 3db5961727 hwcontext_vaapi: add the fourcc of I420 format map.
VA-API 2.0 have enable the I420, so enable this map.

Signed-off-by: Jun Zhao <jun.zhao@intel.com>
Signed-off-by: Mark Thompson <sw@jkqxz.net>
2017-11-20 15:42:50 +00:00
Mark Thompson 1ef4af2d49 hwcontext_vaapi: Fix build with libva 2.0
vaExportSurfaceHandle() wasn't included in the 2.0 release.

Fixes ticket #6828.
2017-11-12 15:38:00 +00:00
Mark Thompson b2f256a9f5 hwcontext_vaapi: Add support for mapping to DRM objects
Uses vaExportSurfaceHandle() from libva2.
2017-10-09 00:46:16 +01:00
Mark Thompson f3602875b3 hwcontext_vaapi: Set message callbacks on internally-created devices
The message callbacks are library-safe in libva2, so we can now use
them.
2017-10-09 00:11:53 +01:00
Mark Thompson 5f39788668 hwcontext_vaapi: Factorise out common connection code
This was duplicated between normal device creation and creation by
derivation from a DRM device.
2017-10-09 00:11:53 +01:00
James Almer 318778de9e Merge commit 'fd9212f2edfe9b107c3c08ba2df5fd2cba5ab9e3'
* commit 'fd9212f2edfe9b107c3c08ba2df5fd2cba5ab9e3':
  Mark some arrays that never change as const.

Merged-by: James Almer <jamrial@gmail.com>
2017-09-26 16:02:40 -03:00
Mark Thompson b0ece2b31f hwcontext_vaapi: Fix DRM format mapping 2017-09-19 22:47:04 +01:00