[FFmpeg-cvslog] hwcontext_vulkan: add support for Vulkan encoding
Lynne
git at videolan.org
Sun Aug 11 06:21:17 EEST 2024
ffmpeg | branch: master | Lynne <dev at lynne.ee> | Wed Dec 28 06:31:11 2022 +0100| [2ce0e51503d9178b190660ede8e716f6a134c2ec] | committer: Lynne
hwcontext_vulkan: add support for Vulkan encoding
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2ce0e51503d9178b190660ede8e716f6a134c2ec
---
libavutil/hwcontext_vulkan.c | 10 ++++++++++
libavutil/vulkan_functions.h | 9 +++++++++
libavutil/vulkan_loader.h | 3 +++
3 files changed, 22 insertions(+)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index ebd6e083e4..05fadd1b55 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -437,8 +437,11 @@ static const VulkanOptExtension optional_device_exts[] = {
/* Video encoding/decoding */
{ VK_KHR_VIDEO_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_QUEUE },
+ { VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_QUEUE },
{ VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_QUEUE },
+ { VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_H264 },
{ VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_H264 },
+ { VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_H265 },
{ VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_H265 },
{ VK_KHR_VIDEO_DECODE_AV1_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_AV1 },
};
@@ -2078,6 +2081,7 @@ enum PrepMode {
PREP_MODE_EXTERNAL_IMPORT,
PREP_MODE_DECODING_DST,
PREP_MODE_DECODING_DPB,
+ PREP_MODE_ENCODING_DPB,
};
static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
@@ -2139,6 +2143,10 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR;
new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
break;
+ case PREP_MODE_ENCODING_DPB:
+ new_layout = VK_IMAGE_LAYOUT_VIDEO_ENCODE_DPB_KHR;
+ new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
}
ff_vk_frame_barrier(&p->vkctx, exec, &tmp_frame, img_bar, &nb_img_bar,
@@ -2399,6 +2407,8 @@ static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_DECODING_DPB);
else if (hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)
err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_DECODING_DST);
+ else if (hwctx->usage & VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR)
+ err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_ENCODING_DPB);
else
err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_WRITE);
if (err)
diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 20711b130d..5fbde96cfe 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -49,6 +49,10 @@ typedef enum FFVulkanExtensions {
FF_VK_EXT_OPTICAL_FLOW = 1ULL << 17, /* VK_NV_optical_flow */
FF_VK_EXT_SHADER_OBJECT = 1ULL << 18, /* VK_EXT_shader_object */
+ FF_VK_EXT_VIDEO_ENCODE_QUEUE = 1ULL << 28, /* VK_KHR_video_encode_queue */
+ FF_VK_EXT_VIDEO_ENCODE_H264 = 1ULL << 29, /* VK_KHR_video_encode_h264 */
+ FF_VK_EXT_VIDEO_ENCODE_H265 = 1ULL << 30, /* VK_KHR_video_encode_h265 */
+
FF_VK_EXT_NO_FLAG = 1ULL << 31,
} FFVulkanExtensions;
@@ -196,6 +200,11 @@ typedef enum FFVulkanExtensions {
\
/* Video decoding */ \
MACRO(1, 1, FF_VK_EXT_VIDEO_DECODE_QUEUE, CmdDecodeVideoKHR) \
+ \
+ /* Video encoding */ \
+ MACRO(1, 1, FF_VK_EXT_VIDEO_ENCODE_QUEUE, CmdEncodeVideoKHR) \
+ MACRO(1, 1, FF_VK_EXT_VIDEO_ENCODE_QUEUE, GetEncodedVideoSessionParametersKHR) \
+ MACRO(1, 0, FF_VK_EXT_VIDEO_ENCODE_QUEUE, GetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR) \
\
/* Pipeline */ \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreatePipelineLayout) \
diff --git a/libavutil/vulkan_loader.h b/libavutil/vulkan_loader.h
index befed51860..f75569340f 100644
--- a/libavutil/vulkan_loader.h
+++ b/libavutil/vulkan_loader.h
@@ -57,8 +57,11 @@ static inline uint64_t ff_vk_extensions_to_mask(const char * const *extensions,
#endif
{ VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME, FF_VK_EXT_DESCRIPTOR_BUFFER, },
{ VK_KHR_VIDEO_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_QUEUE },
+ { VK_KHR_VIDEO_ENCODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_QUEUE },
{ VK_KHR_VIDEO_DECODE_QUEUE_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_QUEUE },
+ { VK_KHR_VIDEO_ENCODE_H264_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_H264 },
{ VK_KHR_VIDEO_DECODE_H264_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_H264 },
+ { VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME, FF_VK_EXT_VIDEO_ENCODE_H265 },
{ VK_KHR_VIDEO_DECODE_H265_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_H265 },
{ VK_KHR_VIDEO_DECODE_AV1_EXTENSION_NAME, FF_VK_EXT_VIDEO_DECODE_AV1 },
};
More information about the ffmpeg-cvslog
mailing list