[FFmpeg-cvslog] avfilter/vf_transpose: fix un-checked potential memory allocation failure
ffmpeg | branch: master | Wu Jianhua | Thu Dec 9 17:36:52 2021 +0800| [ceeff7ae8d918cd54a9b1c8deb85184da53f1250] | committer: Lynne avfilter/vf_transpose: fix un-checked potential memory allocation failure Signed-off-by: Wu Jianhua > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ceeff7ae8d918cd54a9b1c8deb85184da53f1250 --- libavfilter/vf_transpose.c | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index f9f0d70cd5..b964daeee3 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -328,6 +328,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, static int filter_frame(AVFilterLink *inlink, AVFrame *in) { +int err = 0; AVFilterContext *ctx = inlink->dst; TransContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; @@ -339,10 +340,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { -av_frame_free(&in); -return AVERROR(ENOMEM); +err = AVERROR(ENOMEM); +goto fail; } -av_frame_copy_props(out, in); + +err = av_frame_copy_props(out, in); +if (err < 0) +goto fail; if (in->sample_aspect_ratio.num == 0) { out->sample_aspect_ratio = in->sample_aspect_ratio; @@ -356,6 +360,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) FFMIN(outlink->h, ff_filter_get_nb_threads(ctx))); av_frame_free(&in); return ff_filter_frame(outlink, out); + +fail: +av_frame_free(&in); +av_frame_free(&out); +return err; } #define OFFSET(x) offsetof(TransContext, x) ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] hwcontext_vaapi: Use PRIME_2 memory type for modifiers.
ffmpeg | branch: master | Bas Nieuwenhuizen | Tue Dec 7 17:05:49 2021 +0800| [e050959103f375e6494937fa28ef2c4d2d15c9ef] | committer: Lynne 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 > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e050959103f375e6494937fa28ef2c4d2d15c9ef --- libavutil/hwcontext_vaapi.c | 158 1 file changed, 114 insertions(+), 44 deletions(-) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 83e542876d..75acc851d6 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -79,6 +79,9 @@ typedef struct VAAPIFramesContext { unsigned int rt_format; // Whether vaDeriveImage works. int derive_works; +// Caches whether VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 is unsupported for +// surface imports. +int prime_2_import_unsupported; } VAAPIFramesContext; typedef struct VAAPIMapping { @@ -1022,32 +1025,17 @@ static void vaapi_unmap_from_drm(AVHWFramesContext *dst_fc, static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst, const AVFrame *src, int flags) { +VAAPIFramesContext *src_vafc = src_fc->internal->priv; AVHWFramesContext *dst_fc = (AVHWFramesContext*)dst->hw_frames_ctx->data; AVVAAPIDeviceContext *dst_dev = dst_fc->device_ctx->hwctx; const AVDRMFrameDescriptor *desc; const VAAPIFormatDescriptor *format_desc; VASurfaceID surface_id; -VAStatus vas; +VAStatus vas = VA_STATUS_SUCCESS; +int use_prime2; uint32_t va_fourcc; -int err, i, j, k; - -unsigned long buffer_handle; -VASurfaceAttribExternalBuffers buffer_desc; -VASurfaceAttrib attrs[2] = { -{ -.type = VASurfaceAttribMemoryType, -.flags = VA_SURFACE_ATTRIB_SETTABLE, -.value.type= VAGenericValueTypeInteger, -.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME, -}, -{ -.type = VASurfaceAttribExternalBufferDescriptor, -.flags = VA_SURFACE_ATTRIB_SETTABLE, -.value.type= VAGenericValueTypePointer, -.value.value.p = &buffer_desc, -} -}; +int err, i, j; desc = (AVDRMFrameDescriptor*)src->data[0]; @@ -1083,35 +1071,117 @@ static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst, format_desc = vaapi_format_from_fourcc(va_fourcc); av_assert0(format_desc); -buffer_handle = desc->objects[0].fd; -buffer_desc.pixel_format = va_fourcc; -buffer_desc.width= src_fc->width; -buffer_desc.height = src_fc->height; -buffer_desc.data_size= desc->objects[0].size; -buffer_desc.buffers = &buffer_handle; -buffer_desc.num_buffers = 1; -buffer_desc.flags= 0; - -k = 0; -for (i = 0; i < desc->nb_layers; i++) { -for (j = 0; j < desc->layers[i].nb_planes; j++) { -buffer_desc.pitches[k] = desc->layers[i].planes[j].pitch; -buffer_desc.offsets[k] = desc->layers[i].planes[j].offset; -++k; +use_prime2 = !src_vafc->prime_2_import_unsupported && + desc->objects[0].format_modifier != DRM_FORMAT_MOD_INVALID; +if (use_prime2) { +VADRMPRIMESurfaceDescriptor prime_desc; +VASurfaceAttrib prime_attrs[2] = { +{ +.type = VASurfaceAttribMemoryType, +.flags = VA_SURFACE_ATTRIB_SETTABLE, +.value.type= VAGenericValueTypeInteger, +.value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2, +}, +{ +.type = VASurfaceAttribExternalBufferDescriptor, +.flags = VA_SURFACE_ATTRIB_SETTABLE, +.value.type= VAGenericValueTypePointer, +.value.value.p = &prime_desc, +} +}; +prime_desc.fourcc = va_fourcc; +prime_desc.width = src_fc->width; +prime_desc.height = src_fc->height; +prime_desc.num_objects = desc->nb_objects; +for (i = 0; i < desc->nb_objects; ++i) { +prime_desc.objects[i].fd =
[FFmpeg-cvslog] avfilter: add a transpose_vulkan filter
ffmpeg | branch: master | Wu Jianhua | Thu Dec 9 17:36:51 2021 +0800| [58816f6927745d3512b26efcc7e5d88bee249e53] | committer: Lynne avfilter: add a transpose_vulkan filter The following command is on how to apply transpose_vulkan filter: ffmpeg -init_hw_device vulkan -i input.264 -vf \ hwupload=extra_hw_frames=16,transpose_vulkan,hwdownload,format=yuv420p output.264 Signed-off-by: Wu Jianhua > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=58816f6927745d3512b26efcc7e5d88bee249e53 --- configure | 1 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_transpose_vulkan.c | 316 ++ 4 files changed, 319 insertions(+) diff --git a/configure b/configure index 04f319b197..a7593ec2db 100755 --- a/configure +++ b/configure @@ -3718,6 +3718,7 @@ tonemap_vaapi_filter_deps="vaapi VAProcFilterParameterBufferHDRToneMapping" tonemap_opencl_filter_deps="opencl const_nan" transpose_opencl_filter_deps="opencl" transpose_vaapi_filter_deps="vaapi VAProcPipelineCaps_rotation_flags" +transpose_vulkan_filter_deps="vulkan spirv_compiler" unsharp_opencl_filter_deps="opencl" uspp_filter_deps="gpl avcodec" vaguedenoiser_filter_deps="gpl" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index c8082c4a2f..8744cc3c63 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -483,6 +483,7 @@ OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o OBJS-$(CONFIG_TRANSPOSE_NPP_FILTER) += vf_transpose_npp.o OBJS-$(CONFIG_TRANSPOSE_OPENCL_FILTER) += vf_transpose_opencl.o opencl.o opencl/transpose.o OBJS-$(CONFIG_TRANSPOSE_VAAPI_FILTER)+= vf_transpose_vaapi.o vaapi_vpp.o +OBJS-$(CONFIG_TRANSPOSE_VULKAN_FILTER) += vf_transpose_vulkan.o vulkan.o vulkan_filter.o OBJS-$(CONFIG_TRIM_FILTER) += trim.o OBJS-$(CONFIG_UNPREMULTIPLY_FILTER) += vf_premultiply.o framesync.o OBJS-$(CONFIG_UNSHARP_FILTER)+= vf_unsharp.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index b1af2cbcc8..9e16b4e71e 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -462,6 +462,7 @@ extern const AVFilter ff_vf_transpose; extern const AVFilter ff_vf_transpose_npp; extern const AVFilter ff_vf_transpose_opencl; extern const AVFilter ff_vf_transpose_vaapi; +extern const AVFilter ff_vf_transpose_vulkan; extern const AVFilter ff_vf_trim; extern const AVFilter ff_vf_unpremultiply; extern const AVFilter ff_vf_unsharp; diff --git a/libavfilter/vf_transpose_vulkan.c b/libavfilter/vf_transpose_vulkan.c new file mode 100644 index 00..c9bae413c3 --- /dev/null +++ b/libavfilter/vf_transpose_vulkan.c @@ -0,0 +1,316 @@ +/* + * copyright (c) 2021 Wu Jianhua + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/random_seed.h" +#include "libavutil/opt.h" +#include "vulkan_filter.h" +#include "internal.h" + +#define CGS 32 + +typedef struct TransposeVulkanContext { +FFVulkanContext vkctx; +FFVkQueueFamilyCtx qf; +FFVkExecContext *exec; +FFVulkanPipeline *pl; + +VkDescriptorImageInfo input_images[3]; +VkDescriptorImageInfo output_images[3]; + +int initialized; +} TransposeVulkanContext; + +static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) +{ +int err = 0; +FFVkSPIRVShader *shd; +TransposeVulkanContext *s = ctx->priv; +FFVulkanContext *vkctx = &s->vkctx; +const int planes = av_pix_fmt_count_planes(s->vkctx.output_format); + +FFVulkanDescriptorSetBinding image_descs[] = { +{ +.name = "input_images", +.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, +.dimensions = 2, +.elems = planes, +.stages = VK_SHADER_STAGE_COMPUTE_BIT, +.updater= s->input_images, +}, +{ +.name = "output_images", +.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, +.mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format), +.mem_quali = "writeonly", +.dimensions = 2, +.elems = planes, +.stages = VK_SHADER_STAGE_COMPUTE_BI
[FFmpeg-cvslog] libavutil/hwcontext_vaapi: Add a new nv12 format map to support vulkan frame
ffmpeg | branch: master | Wenbin Chen | Tue Dec 7 17:05:50 2021 +0800| [f3c9847c2754b7a43eb721c95e356a53085c2491] | committer: Lynne 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 > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f3c9847c2754b7a43eb721c95e356a53085c2491 --- libavutil/hwcontext_vaapi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 75acc851d6..994b744e4d 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -992,6 +992,7 @@ static const struct { } vaapi_drm_format_map[] = { #ifdef DRM_FORMAT_R8 DRM_MAP(NV12, 2, DRM_FORMAT_R8, DRM_FORMAT_RG88), +DRM_MAP(NV12, 2, DRM_FORMAT_R8, DRM_FORMAT_GR88), #endif DRM_MAP(NV12, 1, DRM_FORMAT_NV12), #if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16) ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] hwcontext_vulkan: add support for allocating all planes in a single allocation
ffmpeg | branch: master | Wenbin Chen | Tue Dec 7 17:05:51 2021 +0800| [bd6ef73399f3f2fcd59ae2ff358954bb536540f2] | committer: Lynne 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 Further-modifications-by: Lynne > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bd6ef73399f3f2fcd59ae2ff358954bb536540f2 --- libavutil/hwcontext_vulkan.c | 76 ++-- libavutil/hwcontext_vulkan.h | 31 -- 2 files changed, 103 insertions(+), 4 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index a0437c9661..ffd4f0e643 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -103,8 +103,14 @@ typedef struct VulkanDevicePriv { /* Settings */ int use_linear_images; +/* Option to allocate all image planes in a single allocation */ +int contiguous_planes; + /* Nvidia */ int dev_is_nvidia; + +/* Intel */ +int dev_is_intel; } VulkanDevicePriv; typedef struct VulkanFramesPriv { @@ -1374,6 +1380,12 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, if (opt_d) p->use_linear_images = strtol(opt_d->value, NULL, 10); +opt_d = av_dict_get(opts, "contiguous_planes", NULL, 0); +if (opt_d) +p->contiguous_planes = strtol(opt_d->value, NULL, 10); +else +p->contiguous_planes = -1; + hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames; hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount; @@ -1424,6 +1436,7 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) p->hprops.minImportedHostPointerAlignment); p->dev_is_nvidia = (p->props.properties.vendorID == 0x10de); +p->dev_is_intel = (p->props.properties.vendorID == 0x8086); vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL); if (!queue_num) { @@ -1742,9 +1755,14 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f, AVHWDeviceContext *ctx = hwfc->device_ctx; VulkanDevicePriv *p = ctx->internal->priv; FFVulkanFunctions *vk = &p->vkfn; +AVVulkanFramesContext *hwfctx = hwfc->hwctx; const int planes = av_pix_fmt_count_planes(hwfc->sw_format); VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } }; +VkMemoryRequirements cont_memory_requirements = { 0 }; +int cont_mem_size_list[AV_NUM_DATA_POINTERS] = { 0 }; +int cont_mem_size = 0; + AVVulkanDeviceContext *hwctx = ctx->hwctx; for (int i = 0; i < planes; i++) { @@ -1771,6 +1789,27 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f, req.memoryRequirements.size = FFALIGN(req.memoryRequirements.size, p->props.properties.limits.minMemoryMapAlignment); +if (hwfctx->flags & AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) { +if (ded_req.requiresDedicatedAllocation) { +av_log(hwfc, AV_LOG_ERROR, "Cannot allocate all planes in a single allocation, " + "device requires dedicated image allocation!\n"); +return AVERROR(EINVAL); +} else if (!i) { +cont_memory_requirements = req.memoryRequirements; +} else if (cont_memory_requirements.memoryTypeBits != + req.memoryRequirements.memoryTypeBits) { +av_log(hwfc, AV_LOG_ERROR, "The memory requirements differ between plane 0 " + "and %i, cannot allocate in a single region!\n", + i); +return AVERROR(EINVAL); +} + +cont_mem_size_list[i] = FFALIGN(req.memoryRequirements.size, +req.memoryRequirements.alignment); +cont_mem_size += cont_mem_size_list[i]; +continue; +} + /* In case the implementation prefers/requires dedicated allocation */ use_ded_mem = ded_req.prefersDedicatedAllocation | ded_req.requiresDedicatedAllocation; @@ -1792,6 +1831,29 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f, bind_info[i].memory = f->mem[i]; } +if (hwfctx->flags & AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) { +cont_mem
[FFmpeg-cvslog] hwcontext_vulkan: add support for mapping frames with planes in a single VkDeviceMemory
ffmpeg | branch: master | Wenbin Chen | Tue Dec 7 17:05:52 2021 +0800| [0d524b170ec4bf762e11c49743d813de650d409a] | committer: Lynne 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 Further-modifications-by: Lynne > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0d524b170ec4bf762e11c49743d813de650d409a --- libavutil/hwcontext_vulkan.c | 11 +-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index ffd4f0e643..728f800bb2 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -2332,9 +2332,10 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags) { VkResult ret; -int err, mapped_mem_count = 0; +int err, mapped_mem_count = 0, mem_planes = 0; AVVkFrame *f = (AVVkFrame *)src->data[0]; AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx; +AVVulkanFramesContext *hwfctx = hwfc->hwctx; const int planes = av_pix_fmt_count_planes(hwfc->sw_format); VulkanDevicePriv *p = hwfc->device_ctx->internal->priv; FFVulkanFunctions *vk = &p->vkfn; @@ -2361,7 +2362,8 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst, dst->width = src->width; dst->height = src->height; -for (int i = 0; i < planes; i++) { +mem_planes = hwfctx->flags & AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY ? 1 : planes; +for (int i = 0; i < mem_planes; i++) { ret = vk->MapMemory(hwctx->act_dev, f->mem[i], 0, VK_WHOLE_SIZE, 0, (void **)&dst->data[i]); if (ret != VK_SUCCESS) { @@ -2373,6 +2375,11 @@ static int vulkan_map_frame_to_mem(AVHWFramesContext *hwfc, AVFrame *dst, mapped_mem_count++; } +if (hwfctx->flags & AV_VK_FRAME_FLAG_CONTIGUOUS_MEMORY) { +for (int i = 0; i < planes; i++) +dst->data[i] = dst->data[0] + f->offset[i]; +} + /* Check if the memory contents matter */ if (((flags & AV_HWFRAME_MAP_READ) || !(flags & AV_HWFRAME_MAP_OVERWRITE)) && !(f->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) { ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] lavu: bump minor version and add doc/APIchanges entry for Vulkan changes
ffmpeg | branch: master | Lynne | Fri Dec 10 16:34:52 2021 +0100| [f45cbb775e47c9991cb518841b2c094e1046dff9] | committer: Lynne lavu: bump minor version and add doc/APIchanges entry for Vulkan changes > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f45cbb775e47c9991cb518841b2c094e1046dff9 --- doc/APIchanges | 3 +++ libavutil/version.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 2914ad6734..2d41d67818 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2021-11-10 - xx - lavu 57.11.100 - hwcontext_vulkan.h + Add AVVkFrame.offset and AVVulkanFramesContext.flags. + 2021-11-xx - xx - lavfi 8.19.100 - avfilter.h Add AVFILTER_FLAG_METADATA_ONLY. diff --git a/libavutil/version.h b/libavutil/version.h index 017fc277a6..0e7b36865a 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 10 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 11 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] hwcontext_vulkan: support creating DRM-tiled images and autodetecting modifiers
ffmpeg | branch: master | Wenbin Chen | Tue Dec 7 17:05:53 2021 +0800| [83fe28221e92921f74d99ed15c258a3c79f4441d] | committer: Lynne 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 Further-modifications-by: Lynne > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=83fe28221e92921f74d99ed15c258a3c79f4441d --- libavutil/hwcontext_vulkan.c | 163 --- libavutil/hwcontext_vulkan.h | 11 ++- 2 files changed, 165 insertions(+), 9 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 728f800bb2..507c4f4454 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -120,6 +120,9 @@ typedef struct VulkanFramesPriv { /* Image transfers */ VulkanExecCtx upload_ctx; VulkanExecCtx download_ctx; + +/* Modifier info list to free at uninit */ +VkImageDrmFormatModifierListCreateInfoEXT *modifier_info; } VulkanFramesPriv; typedef struct AVVkFrameInternal { @@ -240,6 +243,31 @@ const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p) return NULL; } +static const void *vk_find_struct(const void *chain, VkStructureType stype) +{ +const VkBaseInStructure *in = chain; +while (in) { +if (in->sType == stype) +return in; + +in = in->pNext; +} + +return NULL; +} + +static void vk_link_struct(void *chain, void *in) +{ +VkBaseOutStructure *out = chain; +if (!in) +return; + +while (out->pNext) +out = out->pNext; + +out->pNext = in; +} + static int pixfmt_is_supported(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p, int linear) { @@ -2099,6 +2127,13 @@ static void try_export_flags(AVHWFramesContext *hwfc, AVVulkanDeviceContext *dev_hwctx = hwfc->device_ctx->hwctx; VulkanDevicePriv *p = hwfc->device_ctx->internal->priv; FFVulkanFunctions *vk = &p->vkfn; + +const VkImageDrmFormatModifierListCreateInfoEXT *drm_mod_info = +vk_find_struct(hwctx->create_pnext, + VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_LIST_CREATE_INFO_EXT); +int has_mods = hwctx->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT && drm_mod_info; +int nb_mods; + VkExternalImageFormatProperties eprops = { .sType = VK_STRUCTURE_TYPE_EXTERNAL_IMAGE_FORMAT_PROPERTIES_KHR, }; @@ -2106,9 +2141,18 @@ static void try_export_flags(AVHWFramesContext *hwfc, .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, .pNext = &eprops, }; +VkPhysicalDeviceImageDrmFormatModifierInfoEXT phy_dev_mod_info = { +.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_DRM_FORMAT_MODIFIER_INFO_EXT, +.pNext = NULL, +.pQueueFamilyIndices = p->qfs, +.queueFamilyIndexCount = p->num_qfs, +.sharingMode = p->num_qfs > 1 ? VK_SHARING_MODE_CONCURRENT : + VK_SHARING_MODE_EXCLUSIVE, +}; VkPhysicalDeviceExternalImageFormatInfo enext = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO, .handleType = exp, +.pNext = has_mods ? &phy_dev_mod_info : NULL, }; VkPhysicalDeviceImageFormatInfo2 pinfo = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, @@ -2120,11 +2164,18 @@ static void try_export_flags(AVHWFramesContext *hwfc, .flags = VK_IMAGE_CREATE_ALIAS_BIT, }; -ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev, - &pinfo, &props); -if (ret == VK_SUCCESS) { -*iexp |= exp; -*comp_handle_types |= eprops.externalMemoryProperties.compatibleHandleTypes; +nb_mods = has_mods ? drm_mod_info->drmFormatModifierCount : 1; +for (int i = 0; i < nb_mods; i++) { +if (has_mods) +phy_dev_mod_info.drmFormatModifier = drm_mod_info->pDrmFormatModifiers[i]; + +ret = vk->GetPhysicalDeviceImageFormatProperties2(dev_hwctx->phys_dev, +&pinfo, &props); + +if (ret == VK_SUCCESS) { +*iexp |= exp; +*comp_handle_types |= eprops.externalMemoryProperties.compatibleHandleTypes; +} } } @@ -2195,6 +2246,12 @@ static void vulkan_frames_uninit(AVHWFramesContext *hwfc) { VulkanFramesPriv *fp = hwfc->internal->priv; +if (fp->modifier_info) { +
[FFmpeg-cvslog] hwcontext_vulkan: stricter semaphore number requirements
ffmpeg | branch: master | Lynne | Fri Dec 10 16:29:03 2021 +0100| [0747768728b9bc67bc2883425fa7a315457708da] | committer: Lynne hwcontext_vulkan: stricter semaphore number requirements Always require one semaphore per sw_format plane. This is what the implementation uses and relies upon throughout. This was a leftover from an earlier revision that was never needed. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0747768728b9bc67bc2883425fa7a315457708da --- libavutil/hwcontext_vulkan.h | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h index 8de79f5f33..df86c85b3c 100644 --- a/libavutil/hwcontext_vulkan.h +++ b/libavutil/hwcontext_vulkan.h @@ -241,12 +241,10 @@ typedef struct AVVkFrame { VkImageLayout layout[AV_NUM_DATA_POINTERS]; /** - * Synchronization timeline semaphores. Must not be freed manually. - * Must be waited on at every submission using the value in sem_value, - * and must be signalled at every submission, using an incremented value. - * - * Could be less than the amount of images: either one per VkDeviceMemory - * or one for the entire frame. All others will be set to VK_NULL_HANDLE. + * Synchronization timeline semaphores, one for each sw_format plane. + * Must not be freed manually. Must be waited on at every submission using + * the value in sem_value, and must be signalled at every submission, + * using an incremented value. */ VkSemaphore sem[AV_NUM_DATA_POINTERS]; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] hwcontext_vulkan: wait on semaphores when exporting to DRM
ffmpeg | branch: master | Lynne | Fri Dec 10 17:16:49 2021 +0100| [0c1d47a6b39ba19c0883e6322ca509eb8e73e875] | committer: Lynne hwcontext_vulkan: wait on semaphores when exporting to DRM There is no synchronization method for DRM yet. > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0c1d47a6b39ba19c0883e6322ca509eb8e73e875 --- libavutil/hwcontext_vulkan.c | 11 +++ 1 file changed, 11 insertions(+) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 507c4f4454..83a7527198 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -3301,6 +3301,11 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst, VkImageDrmFormatModifierPropertiesEXT drm_mod = { .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT, }; +VkSemaphoreWaitInfo wait_info = { +.sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, +.flags = 0x0, +.semaphoreCount = planes, +}; AVDRMFrameDescriptor *drm_desc = av_mallocz(sizeof(*drm_desc)); if (!drm_desc) @@ -3310,6 +3315,12 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst, if (err < 0) goto end; +/* Wait for the operation to finish so we can cleanly export it. */ +wait_info.pSemaphores = f->sem; +wait_info.pValues = f->sem_value; + +vk->WaitSemaphores(hwctx->act_dev, &wait_info, UINT64_MAX); + err = ff_hwframe_map_create(src->hw_frames_ctx, dst, src, &vulkan_unmap_to_drm, drm_desc); if (err < 0) goto end; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avfilter/vf_transpose_vulkan: add clock and cclock option
ffmpeg | branch: master | Wu Jianhua | Sat Dec 11 03:05:00 2021 +0800| [f106c7228503241d044fb404d1012047d6452f74] | committer: Lynne avfilter/vf_transpose_vulkan: add clock and cclock option The following command is on how to apply cclock option: ffmpeg -init_hw_device vulkan -i input.264 -vf \ hwupload=extra_hw_frames=16,transpose_vulkan=dir=cclock,hwdownload,format=yuv420p \ output.264 The following command is on how to apply clock_flip option: ffmpeg -init_hw_device vulkan -i input.264 -vf \ hwupload=extra_hw_frames=16,transpose_vulkan=dir=clock_flip,hwdownload,format=yuv420p \ output.264 The following command is on how to apply clock option: ffmpeg -init_hw_device vulkan -i input.264 -vf \ hwupload=extra_hw_frames=16,transpose_vulkan=dir=clock,hwdownload,format=yuv420p \ output.264 Signed-off-by: Wu Jianhua > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f106c7228503241d044fb404d1012047d6452f74 --- libavfilter/vf_transpose_vulkan.c | 25 + 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_transpose_vulkan.c b/libavfilter/vf_transpose_vulkan.c index c9bae413c3..eceb9b9011 100644 --- a/libavfilter/vf_transpose_vulkan.c +++ b/libavfilter/vf_transpose_vulkan.c @@ -21,6 +21,7 @@ #include "libavutil/opt.h" #include "vulkan_filter.h" #include "internal.h" +#include "transpose.h" #define CGS 32 @@ -33,6 +34,7 @@ typedef struct TransposeVulkanContext { VkDescriptorImageInfo input_images[3]; VkDescriptorImageInfo output_images[3]; +int dir; int initialized; } TransposeVulkanContext; @@ -86,13 +88,20 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) GLSLC(0, void main() ); GLSLC(0, { ); GLSLC(1, ivec2 size; ); -GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy);); +GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); ); for (int i = 0; i < planes; i++) { GLSLC(0, ); -GLSLF(1, size = imageSize(output_images[%i]); ,i); +GLSLF(1, size = imageSize(output_images[%i]);,i); GLSLC(1, if (IS_WITHIN(pos, size)) { ); -GLSLF(2, vec4 res = texture(input_images[%i], pos.yx);,i); -GLSLF(2, imageStore(output_images[%i], pos, res); ,i); +if (s->dir == TRANSPOSE_CCLOCK) +GLSLF(2, vec4 res = texture(input_images[%i], ivec2(size.y - pos.y, pos.x)); ,i); +else if (s->dir == TRANSPOSE_CLOCK_FLIP || s->dir == TRANSPOSE_CLOCK) { +GLSLF(2, vec4 res = texture(input_images[%i], ivec2(size.yx - pos.yx)); ,i); +if (s->dir == TRANSPOSE_CLOCK) +GLSLC(2, pos = ivec2(pos.x, size.y - pos.y); ); +} else +GLSLF(2, vec4 res = texture(input_images[%i], pos.yx); ,i); +GLSLF(2, imageStore(output_images[%i], pos, res);,i); GLSLC(1, } ); } GLSLC(0, } ); @@ -279,7 +288,15 @@ fail: return err; } +#define OFFSET(x) offsetof(TransposeVulkanContext, x) +#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) + static const AVOption transpose_vulkan_options[] = { +{ "dir", "set transpose direction", OFFSET(dir), AV_OPT_TYPE_INT, { .i64 = TRANSPOSE_CCLOCK_FLIP }, 0, 7, FLAGS, "dir" }, +{ "cclock_flip", "rotate counter-clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK_FLIP }, .flags=FLAGS, .unit = "dir" }, +{ "clock", "rotate clockwise",0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK }, .flags=FLAGS, .unit = "dir" }, +{ "cclock", "rotate counter-clockwise",0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK }, .flags=FLAGS, .unit = "dir" }, +{ "clock_flip", "rotate clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK_FLIP }, .flags=FLAGS, .unit = "dir" }, { NULL } }; ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-cvslog] avfilter/vf_transpose_vulkan: simplify config_props_output function
ffmpeg | branch: master | Wu Jianhua | Sat Dec 11 03:05:03 2021 +0800| [f176669a374c16d45bb0b8464de3b8a73f791e2d] | committer: Lynne avfilter/vf_transpose_vulkan: simplify config_props_output function It's no need to assign outlink here, which has been done in ff_vk_filter_config_output already. Signed-off-by: Wu Jianhua > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f176669a374c16d45bb0b8464de3b8a73f791e2d --- libavfilter/vf_transpose_vulkan.c | 11 +-- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/libavfilter/vf_transpose_vulkan.c b/libavfilter/vf_transpose_vulkan.c index eceb9b9011..ce83cf0fd7 100644 --- a/libavfilter/vf_transpose_vulkan.c +++ b/libavfilter/vf_transpose_vulkan.c @@ -262,7 +262,6 @@ static av_cold void transpose_vulkan_uninit(AVFilterContext *avctx) static int config_props_output(AVFilterLink *outlink) { -int err = 0; AVFilterContext *avctx = outlink->src; TransposeVulkanContext *s = avctx->priv; FFVulkanContext *vkctx = &s->vkctx; @@ -271,21 +270,13 @@ static int config_props_output(AVFilterLink *outlink) vkctx->output_width = inlink->h; vkctx->output_height = inlink->w; -RET(ff_vk_filter_config_output(outlink)); - -outlink->w = inlink->h; -outlink->h = inlink->w; - if (inlink->sample_aspect_ratio.num) outlink->sample_aspect_ratio = av_div_q((AVRational) { 1, 1 }, inlink->sample_aspect_ratio); else outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; -err = 0; - -fail: -return err; +return ff_vk_filter_config_output(outlink); } #define OFFSET(x) offsetof(TransposeVulkanContext, x) ___ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".