* [FFmpeg-devel] [PATCH 1/2] hwcontext_vulkan: enable VK_KHR_video_maintenance1
@ 2024-08-14 18:51 Lynne via ffmpeg-devel
2024-08-14 18:51 ` [FFmpeg-devel] [PATCH 2/2] hwcontext_vulkan: enable encoding of images if video_maintenance1 is enabled Lynne via ffmpeg-devel
0 siblings, 1 reply; 2+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-08-14 18:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
We require it for encoding.
---
libavutil/hwcontext_vulkan.c | 12 +++++++++++-
libavutil/vulkan_functions.h | 1 +
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 3e562716d8..a82355e8bf 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -94,6 +94,7 @@ typedef struct VulkanDevicePriv {
VkPhysicalDeviceCooperativeMatrixFeaturesKHR coop_matrix_features;
VkPhysicalDeviceOpticalFlowFeaturesNV optical_flow_features;
VkPhysicalDeviceShaderObjectFeaturesEXT shader_object_features;
+ VkPhysicalDeviceVideoMaintenance1FeaturesKHR video_maint_1_features;
/* Queues */
pthread_mutex_t **qf_mutex;
@@ -422,6 +423,7 @@ static const VulkanOptExtension optional_device_exts[] = {
{ VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME, FF_VK_EXT_COOP_MATRIX },
{ VK_NV_OPTICAL_FLOW_EXTENSION_NAME, FF_VK_EXT_OPTICAL_FLOW },
{ VK_EXT_SHADER_OBJECT_EXTENSION_NAME, FF_VK_EXT_SHADER_OBJECT },
+ { VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME, FF_VK_EXT_VIDEO_MAINTENANCE_1 },
/* Imports/exports */
{ VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, FF_VK_EXT_EXTERNAL_FD_MEMORY },
@@ -1399,9 +1401,13 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
VkPhysicalDeviceTimelineSemaphoreFeatures timeline_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES,
};
+ VkPhysicalDeviceVideoMaintenance1FeaturesKHR video_maint_1_features = {
+ .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR,
+ .pNext = &timeline_features,
+ };
VkPhysicalDeviceShaderObjectFeaturesEXT shader_object_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT,
- .pNext = &timeline_features,
+ .pNext = &video_maint_1_features,
};
VkPhysicalDeviceOpticalFlowFeaturesNV optical_flow_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_FEATURES_NV,
@@ -1496,6 +1502,8 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
p->device_features_1_3.shaderZeroInitializeWorkgroupMemory = dev_features_1_3.shaderZeroInitializeWorkgroupMemory;
p->device_features_1_3.dynamicRendering = dev_features_1_3.dynamicRendering;
+ p->video_maint_1_features.videoMaintenance1 = video_maint_1_features.videoMaintenance1;
+
p->desc_buf_features.descriptorBuffer = desc_buf_features.descriptorBuffer;
p->desc_buf_features.descriptorBufferPushDescriptors = desc_buf_features.descriptorBufferPushDescriptors;
@@ -1545,6 +1553,8 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_OBJECT_FEATURES_EXT);
OPT_CHAIN(FF_VK_EXT_OPTICAL_FLOW, &p->optical_flow_features,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_OPTICAL_FLOW_FEATURES_NV);
+ OPT_CHAIN(FF_VK_EXT_VIDEO_MAINTENANCE_1, &p->video_maint_1_features,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VIDEO_MAINTENANCE_1_FEATURES_KHR);
#undef OPT_CHAIN
/* Add the enabled features into the pnext chain of device creation */
diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 5fbde96cfe..d4697ec34c 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -49,6 +49,7 @@ 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_MAINTENANCE_1 = 1ULL << 27, /* VK_KHR_video_maintenance1 */
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 */
--
2.45.2.753.g447d99e1c3b
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] hwcontext_vulkan: enable encoding of images if video_maintenance1 is enabled
2024-08-14 18:51 [FFmpeg-devel] [PATCH 1/2] hwcontext_vulkan: enable VK_KHR_video_maintenance1 Lynne via ffmpeg-devel
@ 2024-08-14 18:51 ` Lynne via ffmpeg-devel
0 siblings, 0 replies; 2+ messages in thread
From: Lynne via ffmpeg-devel @ 2024-08-14 18:51 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Lynne
Vulkan encoding was designed in a very... consolidated way.
You had to know the exact codec and profile that the image was going to
eventually be encoded as at... image creation time. Unfortunately, as good
as our code is, glimpsing into the exact future isn't what its capable of.
video_maintenance1 removed that requirement, which only then made encoding
images practically possible.
---
libavcodec/vulkan_decode.c | 10 ++++++++++
libavfilter/vulkan_filter.c | 23 ++++++++++++-----------
libavutil/hwcontext_vulkan.c | 13 +++++++++++++
3 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index c7a32cc439..e73d4f93c2 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -934,6 +934,10 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_
VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT;
+
+ if (ctx->s.extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
+ FF_VK_EXT_VIDEO_MAINTENANCE_1))
+ fmt_info.imageUsage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
}
/* Get the format of the images necessary */
@@ -1023,6 +1027,7 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
AVVulkanFramesContext *hwfc = frames_ctx->hwctx;
FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
FFVulkanDecodeProfileData *prof;
+ FFVulkanDecodeShared *ctx;
frames_ctx->sw_format = AV_PIX_FMT_NONE;
@@ -1059,6 +1064,11 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
if (!dec->dedicated_dpb)
hwfc->usage |= VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR;
+ ctx = dec->shared_ctx;
+ if (ctx->s.extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
+ FF_VK_EXT_VIDEO_MAINTENANCE_1))
+ hwfc->usage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
+
return err;
}
diff --git a/libavfilter/vulkan_filter.c b/libavfilter/vulkan_filter.c
index cef42eeb4d..fd70d90b1a 100644
--- a/libavfilter/vulkan_filter.c
+++ b/libavfilter/vulkan_filter.c
@@ -36,6 +36,7 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s,
if (frames_ref) {
int no_storage = 0;
FFVulkanFunctions *vk;
+ VkImageUsageFlagBits usage_req;
const VkFormat *sub = av_vkfmt_from_pixfmt(sw_format);
frames_ctx = (AVHWFramesContext *)frames_ref->data;
@@ -56,13 +57,20 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s,
if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL)
goto skip;
+ s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
+ vk_dev->nb_enabled_dev_extensions);
+
/* Usage mismatch */
- if ((vk_frames->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) !=
- (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT))
+ usage_req = VK_IMAGE_USAGE_SAMPLED_BIT |
+ VK_IMAGE_USAGE_STORAGE_BIT;
+ if (s->extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
+ FF_VK_EXT_VIDEO_MAINTENANCE_1))
+ usage_req |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
+
+ if ((vk_frames->usage & usage_req) != usage_req)
goto skip;
- s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
- vk_dev->nb_enabled_dev_extensions);
+ /* More advanced format checks */
err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
if (err < 0)
return err;
@@ -112,13 +120,6 @@ skip:
frames_ctx->width = width;
frames_ctx->height = height;
- vk_frames = frames_ctx->hwctx;
- vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
- vk_frames->usage = VK_IMAGE_USAGE_SAMPLED_BIT |
- VK_IMAGE_USAGE_STORAGE_BIT |
- VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
- VK_IMAGE_USAGE_TRANSFER_DST_BIT;
-
err = av_hwframe_ctx_init(frames_ref);
if (err < 0) {
av_buffer_unref(&frames_ref);
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index a82355e8bf..3ccefa9525 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2630,6 +2630,11 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_STORAGE_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT);
+
+ /* Enables encoding of images */
+ if (p->vkctx.extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
+ FF_VK_EXT_VIDEO_MAINTENANCE_1))
+ hwctx->usage |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
}
/* Image creation flags.
@@ -2648,6 +2653,14 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
}
}
+ /* If image has an encode usage, yet there's no profile attached,
+ * and maintenance1 is supported, enable the profile independent
+ * creation flag. */
+ if ((hwctx->usage & VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR) &&
+ !(ff_vk_find_struct(hwctx->create_pnext, VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR)) &&
+ p->video_maint_1_features.videoMaintenance1)
+ hwctx->img_flags |= VK_IMAGE_CREATE_VIDEO_PROFILE_INDEPENDENT_BIT_KHR;
+
if (!hwctx->lock_frame)
hwctx->lock_frame = lock_frame;
--
2.45.2.753.g447d99e1c3b
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-08-14 18:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14 18:51 [FFmpeg-devel] [PATCH 1/2] hwcontext_vulkan: enable VK_KHR_video_maintenance1 Lynne via ffmpeg-devel
2024-08-14 18:51 ` [FFmpeg-devel] [PATCH 2/2] hwcontext_vulkan: enable encoding of images if video_maintenance1 is enabled Lynne via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git