Commit Graph

125 Commits

Author SHA1 Message Date
Niklas Haas
9675e54b02
avutil/hwcontext_vulkan: add libplacebo required features
For compatibility with vf_libplacebo
2023-05-29 00:41:55 +02:00
Lynne
51b7fe81be
hwcontext_vulkan: enable additional device properties 2023-05-29 00:41:51 +02:00
Lynne
33fc919bb7
hwcontext_vulkan: remove duplicate code, port to use generic vulkan utils
The temporary AVFrame on staack enables us to use the common
dependency/dispatch code in prepare_frame().
The prepare_frame() function is used for both frame initialization
and frame import/export queue family transfer operations.
In the former case, no AVFrame exists yet, so, as this is purely
libavutil code, we create a temporary frame on stack. Otherwise,
we'd need to allocate multiple frames somewhere, one for each
possible command buffer dispatch.
2023-05-29 00:41:51 +02:00
Lynne
94e17a63a4
hwcontext_vulkan: don't change properties if prepare_frame fails 2023-05-29 00:41:50 +02:00
Lynne
32fc36ee61
hwcontext_vulkan: remove linear+host_visible "fast" path
The idea was that it's faster to map linear images and copy them
via regular memcpy. This is a very niche use, plus very inconsistently
useful, as it would only really be faster on a few Intel GPUs.
Even then, using the non-cached memcpy would've been better.

Instead, scrap this code. Drivers are better at figuring out
what copy to use, and if we're host-mapping, it should actually be
just as fast, if not faster.
2023-05-29 00:41:50 +02:00
Lynne
48f85de0e7
hwcontext_vulkan: rewrite to support multiplane surfaces
This commit adds proper handling of multiplane images throughout
all of the hwcontext code. To avoid breakage of individual
components, the change is performed as a single commit.
2023-05-29 00:41:49 +02:00
Lynne
9b385b480f
hwcontext_vulkan: enable GPU-assisted validation when debugging 2023-05-29 00:41:41 +02:00
Lynne
d4cb48dd00
hwcontext_vulkan: support PREP_MODE_DECODING in prepare_frame() 2023-05-29 00:41:41 +02:00
Lynne
6dfa29a58d
hwcontext_vulkan: add functions for video decoding 2023-05-29 00:41:40 +02:00
Lynne
571756bf2f
hwcontext_vulkan: use VK_EXT_physical_device_drm to derive DRM to Vulkan
Finally, a way to directly identify a Vulkan device from a DRM device!
2023-05-29 00:41:40 +02:00
Lynne
e11fd1abdb
hwcontext_vulkan: do not require libdrm to map VAAPI devices
VAAPI is sadly on the way of becoming multiplaform.
2023-05-29 00:41:39 +02:00
Lynne
f50bc930a4
hwcontext_vulkan: add support for descriptor buffers 2023-05-29 00:41:39 +02:00
Lynne
c5702abf71
hwcontext_vulkan: report nonCoherentAtomSize 2023-05-29 00:41:39 +02:00
Lynne
b0af92572f
hwcontext_vulkan: fix minor type issue in VulkanQueueCtx.buf_deps_alloc_size 2023-05-29 00:41:38 +02:00
Lynne
211c910aca
hwcontext_vulkan: rename and expand vk_pixfmt_map to append VK_NULL_FORMAT 2023-05-29 00:41:38 +02:00
Lynne
e0f2d2e702
hwcontext_vulkan: remove contiguous memory path/mode
The hack was added to enable exporting of vulkan images to DRM.
On Intel hardware, specifically for DRM images, all planes must be
allocated next to each other, due to hardware limitation, so the hack
used a single large allocation and suballocated all planes from it.

By natively supporting multiplane images, the driver is what decides
the layout, so exporting just works.

It's a hack because it conflicted heavily with image allocation, and
with the whole ecosystem in general, before multiplane images were
supported, which just made it redundant.

This is also the commit which broke the hwcontext hardest and prompted
the entire rewrite in the first place.
2023-05-29 00:41:37 +02:00
Lynne
46a77c6496
hwcontext_vulkan: support threadsafe queue and frame operations 2023-05-29 00:41:37 +02:00
Lynne
2a1fd2814f
hwcontext_vulkan: use portability subset if available 2023-05-29 00:41:37 +02:00
Lynne
74b202b839
hwcontext_vulkan: enable VK_KHR_synchronization2 if supported 2023-05-29 00:41:36 +02:00
Lynne
fddfb0ebf8
hwcontext_vulkan: enable support for YCbCr samplers 2023-05-29 00:41:36 +02:00
Lynne
59707cc485
hwcontext_vulkan: initialize and require instance version 1.3
This just bumps the required loader library version (libvulkan).
All device-related features, such as video decoding, atomics, etc.
are still optional and the code deals with their loss on a local level
(e.g. the decoder or filter checks for the features it needs, not
the hwcontext).

Bumping the required version essentially packs all maintenance
extensions which correct the spec rather than requiring to enable
them individually.
2023-05-29 00:41:36 +02:00
Kacper Michajłow
cc76e8340d lavu/vulkan: fix handle type for 32-bit targets
Fixes compilation with clang which errors out on Wint-conversion.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
2023-03-07 22:55:07 +02:00
Martin Storsjö
f9620d74cd vulkan: Fix win/i386 calling convention
This fixes the following error when compiling with a modern
version of Clang for Windows/i386:

src/libavutil/hwcontext_vulkan.c:738:32: error: incompatible function pointer types initializing 'PFN_vkDebugUtilsMessengerCallbackEXT' (aka 'unsigned int (*)(enum VkDebugUtilsMessageSeverityFlagBitsEXT, unsigned int, const struct VkDebugUtilsMessengerCallbackDataEXT *, void *) __attribute__((stdcall))') with an expression of type 'VkBool32 (VkDebugUtilsMessageSeverityFlagBitsEXT, VkDebugUtilsMessageTypeFlagsEXT, const VkDebugUtilsMessengerCallbackDataEXT *, void *)' (aka 'unsigned int (enum VkDebugUtilsMessageSeverityFlagBitsEXT, unsigned int, const struct VkDebugUtilsMessengerCallbackDataEXT *, void *)') [-Wincompatible-function-pointer-types]
            .pfnUserCallback = vk_dbg_callback,
                               ^~~~~~~~~~~~~~~

Signed-off-by: Martin Storsjö <martin@martin.st>
2023-03-07 18:16:02 +02:00
Lynne
eb0455d646
hwcontext_vulkan: remove optional encode/decode extensions from the list
They're not currently used, so they don't need to be there.
Vulkan stabilized the decode extensions less than a week ago, and their
name prefixes were changed from EXT to KHR. It's a bit too soon to be
depending on it, so rather than bumping, just remove these for now.
2022-12-25 01:09:39 +01:00
Philip Langdale
2f9b8bbd1f lavu/hwcontext_vulkan: support mapping VUYX, P012, and XV36
If we want to be able to map between VAAPI and Vulkan (to do Vulkan
filtering), we need to have matching formats on each side.

The mappings here are not exact. In the same way that P010 is still
mapped to full 16 bit formats, P012 has to be mapped that way as well.

Similarly, VUYX has to be mapped to an alpha-equipped format, and XV36
has to be mapped to a fully 16bit alpha-equipped format.

While Vulkan seems to fundamentally lack formats with an undefined,
but physically present, alpha channel, it has have 10X6 and 12X4
formats that you could imagine using for P010, P012 and XV36, but these
formats don't support the STORAGE usage flag. Today, hwcontext_vulkan
requires all formats to be storable because it wants to be able to use
them to create writable images. Until that changes, which might happen,
we have to restrict the set of formats we use.

Finally, when mapping a Vulkan image back to vaapi, I observed that
the VK_FORMAT_R16G16B16A16_UNORM format we have to use for XV36 going
to Vulkan is mapped to Y416 when going to vaapi (which makes sense as
it's the exact matching format) so I had to add an entry for it even
though we don't use it directly.
2022-09-03 16:19:40 -07:00
Zhao Zhili
910a24eb33 avutil/hwcontext_vulkan: fix typo in undef 2022-03-14 17:50:07 +01:00
Zhao Zhili
b5a8b3d45a hwcontext_vulkan: use VkPhysicalDeviceTimelineSemaphoreFeatures
VkPhysicalDeviceVulkan12Features isn't implemented on MoltenVK yet.
VkPhysicalDeviceTimelineSemaphoreFeatures is less versatile but
simple. None of device_features_1_1 nor device_features_1_2 has real
usage yet, keep the code for future.
2022-02-01 22:54:24 +01:00
Anton Khirnov
137c808f1a lavu/hwcontext_vulkan: clear dangling pointers on map failure 2022-01-21 09:44:01 +01:00
Wu Jianhua
c4ecc643bb avutil/hwcontext_vulkan: fixed incorrect memory offset
This commit fixed hwupload in Vulkan:

ffmpeg -init_hw_device vulkan -i test.jpg -vf hwupload,hwdownload,format=yuv420p -y out.jpg

Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
2022-01-05 14:13:39 +01:00
Lynne
b84ce56589 hwcontext_vulkan: remove VK_EXT_hdr_metadata from autoloaded extensions list
We don't use it. Was copied from libplacebo's recommended defaults.
Creates problems with validation on Intel devices, where the driver
still advertizes it, even though it's not usable without a swapchain.
2022-01-03 03:16:45 +01:00
Lynne
0c1d47a6b3
hwcontext_vulkan: wait on semaphores when exporting to DRM
There is no synchronization method for DRM yet.
2021-12-10 17:16:49 +01:00
Wenbin Chen
83fe28221e hwcontext_vulkan: support creating DRM-tiled images and autodetecting modifiers
When vulkan image exports to drm, the tilling need to be
VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT. Now add code to create vulkan
image using this format.

Now the following command line works:

ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -hwaccel_output_format \
vaapi -i input_1080p.264 -vf "hwmap=derive_device=vulkan,format=vulkan, \
scale_vulkan=1920:1080,hwmap=derive_device=vaapi,format=vaapi" -c:v h264_vaapi output.264

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Further-modifications-by: Lynne <dev@lynne.ee>
2021-12-10 17:03:48 +01:00
Wenbin Chen
0d524b170e hwcontext_vulkan: add support for mapping frames with planes in a single VkDeviceMemory
Add support to map vulkan frames to software frames when
using contiguous_planes flag.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Further-modifications-by: Lynne <dev@lynne.ee>
2021-12-10 17:03:48 +01:00
Wenbin Chen
bd6ef73399 hwcontext_vulkan: add support for allocating all planes in a single allocation
VAAPI on Intel can import external frame, but the planes of the external
frames should be in the same drm object. A new option "contiguous_planes"
is added to device. This flag tells device to allocate places in one
memory. When device is derived from vaapi this flag will be enabled.
A new flag frame_flag is also added to AVVulkanFramesContext. User
can use this flag to force enable or disable this behaviour.
A new variable "offset "is added to AVVKFrame. It describe describe the
offset from the memory currently bound to the VkImage.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
Further-modifications-by: Lynne <dev@lynne.ee>
2021-12-10 17:03:48 +01:00
Lynne
c90b3661fa
hwcontext_vulkan: use correct return value for allocation failure 2021-11-27 04:46:41 +01:00
Wu Jianhua
b3624069f0 avutil/hwcontext_vulkan: fully support customizable validation layers
Validation layer is an indispensable part of developing on Vulkan.

The following commands is on how to enable validation layers:

ffmpeg -init_hw_device vulkan=0,debug=1,validation_layers=VK_LAYER_LUNARG_monitor+VK_LAYER_LUNARG_api_dump

Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
2021-11-26 10:36:39 +01:00
Wu Jianhua
7e9e2cf93b avutil/hwcontext_vulkan: check if created before destroying the instance
Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
2021-11-24 11:09:49 +01:00
Wu Jianhua
c2a356d583 avutil/hwcontext_vulkan: check if created before destroying the device
Signed-off-by: Wu Jianhua <jianhua.wu@intel.com>
2021-11-24 11:09:49 +01:00
Lynne
b159975e80
hwcontext_vulkan: check for non-flagged transfer queue families
"All commands that are allowed on a queue that supports transfer
operations are also allowed on a queue that supports either
graphics or compute operations. Thus, if the capabilities of a
queue family include VK_QUEUE_GRAPHICS_BIT or VK_QUEUE_COMPUTE_BIT,
then reporting the VK_QUEUE_TRANSFER_BIT capability separately for
that queue family is optional."
2021-11-20 02:37:41 +01:00
Lynne
d1133e8c44
lavu/vulkan: move common Vulkan code from libavfilter to libavutil 2021-11-19 13:44:45 +01:00
Timo Rothenpieler
2ece70090d avutil/hwcontext_vulkan: add support for exporting memory via Win32 Handles 2021-11-14 12:50:32 +01:00
Lynne
7f6dc9b386
hwcontext_vaapi: don't use the generic mapping struct for DRM/VAAPI
Avoids a per-frame allocation since we don't need the flag field.
2021-11-13 15:13:03 +01:00
Lynne
f388791ff9
hwcontext_vulkan: fix small memory leak when unmapping 2021-11-13 14:47:12 +01:00
Lynne
9dc544cdb4
hwcontext_vulkan: wait for semaphores when unmapping from VAAPI
We don't really want to do a full all-queue blocking wait here, since
this happens once per frame, and this could delay future frames.
2021-11-13 14:22:11 +01:00
Lynne
6a23a5597c
hwcontext_vulkan: print error information on queue submission failure
Makes it clearer what went wrong.
2021-11-13 14:21:36 +01:00
Lynne
c96d1ee401
hwcontext_vulkan: fix DMABUF import format check call
VkExternalImageFormatProperties is required to be present in the .pNext
chain of VkImageFormatProperties2, or some drivers crash (RADV).
2021-11-13 11:12:50 +01:00
Lynne
f74ceb358c
hwcontext_vulkan: improve CUDA error handling 2021-11-13 04:30:33 +01:00
Lynne
0d1992e025
hwcontext_vulkan: close exported memory FD on CUDA import error
Prevents resource leakage.
2021-11-13 00:40:46 +01:00
Lynne
015b487777
hwcontext_vulkan: do not dup() semaphore FDs for CUDA 2021-11-13 00:32:53 +01:00
Lynne
fa28c1b2f9
hwcontext_vulkan: properly migrate queue families with DRM import/export 2021-11-13 00:03:58 +01:00