Commit Graph
100 Commits
Author SHA1 Message Date
Lynne e6a12a5214 vulkan_av1: remove an invalid debug print
Leftover.
2023-07-21 20:04:21 +02:00
Lynne 3e3d46309b lavu/vulkan: remove unused field from the execution pool structure 2023-07-21 20:04:21 +02:00
Lynne 97890c2b55 lavu/vulkan: remove threadsafe buffer index load and fix a signed overflow
It's not needed anymore.
2023-07-21 20:04:20 +02:00
Lynne c06ad641ec lavc/vulkan_decode: use a single execution pool per thread
The spec says command buffer pools must be externally synchronized
objects.

This still lets us pool some, just not as much.
2023-07-21 20:04:15 +02:00
Lynne 9ff834c2a0 bwdif_vulkan: clamp the temporarily interpolated sample spatially
This makes the filter output match that of the C version.
It was left intentionally while we figured out if it was better
or not, and while it makes certain samples better, it makes static
samples jump around slightly.
2023-07-04 00:52:19 +02:00
Lynne c39e861a3d vulkan_h264: check if slices_buf exists on end_frame
The issue is that while decode_slice is guaranteed to never get
called without start_frame, end_frame is not. Moreover, it is
not guaranteed it won't be called twice.

On a badly-broken sample, this is what happens, which leads to
a segfault, as vp->slices_buf doesn't exist, as it has been handed
off for decoding already and isn't owned by the frame.

Return an error as it's indicative that it's a corrupt stream rather
than just missing any slices.

Prevents a segfault.
2023-06-25 03:11:38 +02:00
Lynne 997d8a7e73 vulkan_decode: reject decoding of frames with no slices
As per the spec:
VUID-VkVideoDecodeH264PictureInfoKHR-sliceCount-arraylength
sliceCount must be greater than 0

VUID-VkVideoDecodeH265PictureInfoKHR-sliceSegmentCount-arraylength
sliceSegmentCount must be greater than 0

This particularly happens with seeking in field-coded H264.
2023-06-22 18:18:53 +02:00
Lynne 4ff303a7b8 vulkan_decode: simplify and make session parameter generation more robust
This commit scraps a bool to signal to recreate the session parameters,
but instead destroys them, forcing them to be recreated.

As this can happen between start_frame and end_frame, do this
at both places.
2023-06-22 18:17:54 +02:00
Lynne ba8a803236 vulkan_decode: clean up slice handling
Move the slice offsets buffer to the thread decode context.
It isn't part of the resources for frame decoding, the driver
has to process and finish with it at submission time.
That way, it doesn't need to be alloc'd + freed on every frame.
2023-06-22 18:17:54 +02:00
Lynne 237c400727 vulkan_decode: remove unused fields 2023-06-22 18:17:53 +02:00
Lynne d9af84426b vulkan_decode: fix small memory leak
This requires using the new AVHWFramesContext.opaque field, as
otherwise, the profile attached to the decoder will be freed
before the frames context, rendering the frames context useless.
2023-06-22 18:17:53 +02:00
Lynne 13ff3aa9e7 vulkan_decode: use the hwfc->user_opaque field to store the profile 2023-06-22 18:17:47 +02:00
Lynne ca818ab51c vulkan_h264: filter out constrained/inter flags from the profile index
As the comment says, Vulkan signals all the constrant_set flags,
and does not want them OR'd onto the profile IDC.
So just unset them.
2023-06-15 22:00:42 +02:00
Lynne d0f1d937fe hwcontext_vulkan: free temporary array once unneeded
Fixes a small memory leak.
This also prevents leaks on malloc/mutex init errors.
2023-06-15 22:00:41 +02:00
Lynne b4d5baa8b0 hwcontext_vulkan: call ff_vk_uninit() on device uninit
This fixes three memory leaks from ff_vk_load_props().
2023-06-15 22:00:41 +02:00
Lynne f30b979ca2 pthread_frame: uninit the hwaccel of each frame thread
The issue is that with a threadsafe hwaccel and multiple enabled
frame threads, hwaccel->uninit() is never called.
Previously, the function was guaranteed to never have any threads
with hwaccel contexts, so it never bothered to uninit any.
2023-06-15 22:00:40 +02:00
Lynne eff565dc19 hwcontext_vulkan: tune execution pools
Having less in-flight resources is better in this case.
2023-06-07 23:59:17 +02:00
Lynne 24c4307b80 vulkan_decode: halve execution pool size
Determined experimentally, on various videos and hardware.
On Intel, using less resources in-flight is around 15% faster,
with similar results on Nvidia hardware.
2023-06-07 23:59:17 +02:00
Lynne 5f1be341c2 vulkan: discard dependencies when explicitly waiting for execution
This reduces memory needed dramatically, as unneeded resources
can be immediately returned to the pool.
Although waitforfences is threadsafe, we add a mutex wait around
it, as the mutex fence in combination with waitforfences assures
us that no other thread will reset the fence in the meanwhile
whilst the mutex is locked. This allows is to call
ff_vk_exec_discard_deps.
2023-06-07 23:59:16 +02:00
Lynne 975cd48bb3 vulkan: synchronize access to execution pool fences
vkResetFences is specified as being user-synchronized
(yet vkWaitFences, is not).
2023-06-07 23:59:16 +02:00
Lynne 697382168d hevcdec: remove redundant bits_used_for_short_term_rps field
It was introduced for Vulkan, but it is equivalent to
short_term_ref_pic_set_size when !short_term_ref_pic_set_sps_flag,
and when !!short_term_ref_pic_set_sps_flag, Vulkan hardcodes a zero
anyway.
2023-06-07 23:59:12 +02:00
Lynne 9f9534f5b6 vulkan_decode: fix typo when setting AV1 capabilities
All pNext chained structs in Vulkan are defined as void *, so it doesn't
help catch this.
2023-05-29 23:26:10 +02:00
Lynne e71cd18049 vulkan_decode: do not align the image dimensions
According to Dave Airlie:

> <airlied> but I think ignoring it should be fine, I can't see any
> other way to get the imaeg extents correct for other usage
> <Lynne> what width/height should be used for the images?
> the final presentable dimensions, or the coded dimensions?
> <airlied> if you don't want noise I think the presentable dims
> <airlied> the driver should round up the allocations internally,
> but if you are going to sample from the images then w/h have to be
> the bounds of the image you want
> <airlied> since otherwise there's no way to stop the sampler from
> going outside the edges

Apparently, the alignment values are informative, rather than mandatory,
but the spec's wording makes it sound as if they're mandatory.
2023-05-29 05:12:27 +02:00
Lynne bae92361ed vulkan_decode: check if yuv_sampler exists before freeing it
This prevents multiple NULL accesses - if yuv_sampler exists, then
everything required for it to be destroyed also exists.
2023-05-29 03:23:06 +02:00
Lynne 58f82fc26a vulkan: replace usage of %lu with %"SIZE_SPECIFIER" 2023-05-29 03:22:58 +02:00
Lynne 6018f87599 doc/filtering: add documentation for Vulkan filters
This commit documents most of the Vulkan filters. Some of this was
copy-pasted from equivalent OpenCL filters.
2023-05-29 00:42:04 +02:00
Lynne ea0394fd24 changelog: add new Vulkan features 2023-05-29 00:42:03 +02:00
Lynne f3795e1857 APIchanges: add AVHWAccel changes and bump lavc minor 2023-05-29 00:42:03 +02:00
Lynne db1d022781 APIchanges: add hwcontext_vulkan changes and bump lavu minor 2023-05-29 00:42:02 +02:00
Lynne bef86ba86c APIchanges: add new pixel formats supported and bump lavu minor 2023-05-29 00:42:02 +02:00
Lynne b3fb73af6b swscale: bump minor for implementing support for the new pixfmts 2023-05-29 00:42:02 +02:00
Lynne f701f088f4 vulkan_h264: reject end_frame being called without valid session parameters
When seeking through MBAFF-coded H264, this can happen. Decoding calls end_frame
without calling start_frame. We are unable to decode this, as no frame
state has been set.

Happens for both VAAPI and Vulkan. Could be an issue elsewhere, hence
the individual commit.
2023-05-29 00:42:01 +02:00
Lynne 160a415e22 lavfi: add nlmeans_vulkan filter 2023-05-29 00:42:01 +02:00
Lynne dfff3877b7 vulkan: add support for the atomic float ops extension 2023-05-29 00:42:01 +02:00
Lynne 88e2cca3db tools/cl2c: change to tools/source2c and allow non-OpenCL source files 2023-05-29 00:42:00 +02:00
Lynne 7cfd7e4af4 lavfi: add color_vulkan filter 2023-05-29 00:42:00 +02:00
Lynne 77478f6793 av1dec: add Vulkan hwaccel 2023-05-29 00:42:00 +02:00
Lynne 5dc047716a fate-source: exclude Apache-2 licensed files 2023-05-29 00:41:59 +02:00
Lynne 6ec58ff820 cbs_av1: expose tile col/row starts in SBs 2023-05-29 00:41:59 +02:00
Lynne 36c16a06b2 hevcdec: add Vulkan hwaccel
Thanks to Dave Airlie for figuring out a lot of the parameters.
2023-05-29 00:41:58 +02:00
Lynne a9fbe8b472 h264dec: add Vulkan hwaccel
Thanks to Dave Airlie for figuring out a lot of the parameters.
2023-05-29 00:41:58 +02:00
Lynne 1e8fefff93 libavcodec: add Vulkan common video decoding code 2023-05-29 00:41:57 +02:00
Lynne 023ae6103f libavcodec: add Vulkan common video code 2023-05-29 00:41:57 +02:00
Lynne 6733a1a456 avcodec: add AVHWAccel.flush callback 2023-05-29 00:41:57 +02:00
Lynne be07145109 avcodec: add AVHWAccel.free_frame_priv callback 2023-05-29 00:41:56 +02:00
Lynne 09dc9193ea lavfi: add bwdif_vulkan 2023-05-29 00:41:56 +02:00
Lynne f70f873272 transpose_vulkan: port for the rewrite 2023-05-29 00:41:54 +02:00
Lynne d4b51b5085 scale_vulkan: port for the rewrite 2023-05-29 00:41:54 +02:00
Lynne 8e9ceb1efb overlay_vulkan: port for the rewrite 2023-05-29 00:41:54 +02:00
Lynne 59f21c051d gblur_vulkan: port for the rewrite 2023-05-29 00:41:53 +02:00
Lynne d26cbae3e1 flip_vulkan: port for the rewrite 2023-05-29 00:41:53 +02:00
Lynne 125636608d chromaber_vulkan: port for the rewrite 2023-05-29 00:41:52 +02:00
Lynne 40bf1d525e blend_vulkan: port for the rewrite 2023-05-29 00:41:52 +02:00
Lynne f29850e98f avgblur_vulkan: port for the rewrite 2023-05-29 00:41:52 +02:00
Lynne 05ce6473ac lavfi: add lavfi-only Vulkan infrastructure 2023-05-29 00:41:51 +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 a4d63b46d9 vulkan: make GLSL macro functions semicolumn-safe 2023-05-29 00:41:49 +02:00
Lynne 83024beec2 vulkan: enable forcing of full subgroups 2023-05-29 00:41:49 +02:00
Lynne 758f8b26b9 vulkan: add ff_vk_count_images() 2023-05-29 00:41:48 +02:00
Lynne b5eaeb1f13 vulkan: rewrite to support all necessary features
This commit rewrites the majority of vulkan.c to enable its use
as a general-purpose high-level utility code, usable for decoding,
encoding, and filtering of video frames.

The dependency system was rewritten to simplify management of
execution.

The image handling system was rewritten to accomodate multiplane
images.

Due to how related all the new features were, this is a single
commit.
2023-05-29 00:41:48 +02:00
Lynne 721b71da4a vulkan: return current queue index from ff_vk_qf_rotate() 2023-05-29 00:41:48 +02:00
Lynne b15104ed97 vulkan: add support for retrieving queue, query and video properties 2023-05-29 00:41:47 +02:00
Lynne 6eaf3fe69c vulkan: add support for queries 2023-05-29 00:41:47 +02:00
Lynne f3fb1b50bb vulkan: minor indent fix, add support for synchronous submission/waiting 2023-05-29 00:41:46 +02:00
Lynne d386988c39 vulkan: use device properties 2 and add a convenience loader function 2023-05-29 00:41:46 +02:00
Lynne bf69a64135 vulkan: add size tracking to buffer structs 2023-05-29 00:41:46 +02:00
Lynne b18e20a4ee vulkan: do not wait for device idle when destroying buffers
This should be done explicitly.
2023-05-29 00:41:45 +02:00
Lynne 15de0af8f0 vulkan: allow alloc pNext in ff_vk_create_buf 2023-05-29 00:41:45 +02:00
Lynne af48790465 vulkan: support ignoring memory properties when allocating 2023-05-29 00:41:45 +02:00
Lynne 3c2f43d8ee vulkan: expose ff_vk_alloc_mem() 2023-05-29 00:41:44 +02:00
Lynne fa67ccee37 vulkan: add ff_vk_image_create() 2023-05-29 00:41:44 +02:00
Lynne e8fce74abf vulkan: add ff_vk_qf_fill() 2023-05-29 00:41:43 +02:00
Lynne b5e333bba7 vulkan: add pNext argument to ff_vk_create_buf() 2023-05-29 00:41:43 +02:00
Lynne a0d47a2ad9 vulkan: fix comment statement about exec_queue blocking 2023-05-29 00:41:43 +02:00
Lynne 619b1265a2 vulkan: add additional error codes 2023-05-29 00:41:42 +02:00
Lynne 0c9c0e40fb vulkan: define VK_NO_PROTOTYPES
This just disables the vulkan headers from defining any symbols
like vkCmdPipelineBarrier2(). Instead, all functions must be loaded
via the loader and used as function pointers as vk->CmdPipelineBarrier2.

Mostly just forces developers to write correct code, as using the
symbols can be undesirable in case API users define their own
function wrappers via the loader API.
2023-05-29 00:41:42 +02:00
Lynne 92ddd415bc vulkan: lock queues before submitting operations 2023-05-29 00:41:42 +02:00
Lynne 9b385b480f hwcontext_vulkan: enable GPU-assisted validation when debugging 2023-05-29 00:41:41 +02:00
Lynne e5e12c5078 hwcontext_vulkan: load query-related functions
Needed for both encoding and decoding.
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
Lynne 934525eae0 lsws: add in/out support for the new 12-bit 2-plane 422 and 444 pixfmts 2023-05-29 00:41:35 +02:00
Lynne 0bda3340a3 lavu: add 12-bit 2-plane 422 and 444 pixel formats 2023-05-29 00:41:35 +02:00
Lynne 21719c29a2 hevc_ps: expose sps_extension_present_flag 2023-05-29 00:41:35 +02:00