[FFmpeg-devel] [PATCH 1/2] hwcontext_vulkan: add a new mechanism to expose used queue families
Lynne
dev at lynne.ee
Tue Jul 9 04:07:12 EEST 2024
The issue with the old mechanism is that we had to introduce new
API each time we needed a new queue family, and all the queue families
were functionally fixed to a given purpose.
Nvidia's GPUs are able to handle video encoding and compute on the
same queue, which results in a speedup when pre-processing is required.
Also, this enables us to expose optical flow queues for frame interpolation.
---
APIChanges and lavu version will be bumped when comitting.
libavutil/hwcontext_vulkan.c | 22 ++++++++++++++++++++++
libavutil/hwcontext_vulkan.h | 22 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index da377aa1a4..ff5d34d042 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -1550,6 +1550,28 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
#undef CHECK_QUEUE
+ /* Update the new queue family fields. If non-zero already,
+ * it means API users have set it. */
+ if (!hwctx->nb_qf) {
+#define ADD_QUEUE(ctx_qf, qc, flag) \
+ do { \
+ if (ctx_qf != -1) { \
+ hwctx->qf[hwctx->nb_qf++] = (AVVulkanDeviceQueueFamily) { \
+ .idx = ctx_qf, \
+ .num = qc, \
+ .flags = flag, \
+ }; \
+ } \
+ } while (0)
+
+ ADD_QUEUE(hwctx->queue_family_index, hwctx->nb_graphics_queues, VK_QUEUE_GRAPHICS_BIT);
+ ADD_QUEUE(hwctx->queue_family_comp_index, hwctx->nb_comp_queues, VK_QUEUE_COMPUTE_BIT);
+ ADD_QUEUE(hwctx->queue_family_tx_index, hwctx->nb_tx_queues, VK_QUEUE_TRANSFER_BIT);
+ ADD_QUEUE(hwctx->queue_family_decode_index, hwctx->nb_decode_queues, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
+ ADD_QUEUE(hwctx->queue_family_encode_index, hwctx->nb_encode_queues, VK_QUEUE_VIDEO_ENCODE_BIT_KHR);
+#undef ADD_QUEUE
+ }
+
if (!hwctx->lock_queue)
hwctx->lock_queue = lock_queue;
if (!hwctx->unlock_queue)
diff --git a/libavutil/hwcontext_vulkan.h b/libavutil/hwcontext_vulkan.h
index cbbd2390c1..28fc2c73ff 100644
--- a/libavutil/hwcontext_vulkan.h
+++ b/libavutil/hwcontext_vulkan.h
@@ -30,6 +30,17 @@
typedef struct AVVkFrame AVVkFrame;
+typedef struct AVVulkanDeviceQueueFamily {
+ /* Queue family index */
+ int idx;
+ /* Number of queues in the queue family in use */
+ int num;
+ /* Queue family capabilities. Must be non-zero.
+ * Flags may be removed to indicate the queue family may not be used
+ * for a given purpose. */
+ VkQueueFlagBits flags;
+} AVVulkanDeviceQueueFamily;
+
/**
* @file
* API-specific header for AV_HWDEVICE_TYPE_VULKAN.
@@ -151,6 +162,17 @@ typedef struct AVVulkanDeviceContext {
* Similar to lock_queue(), unlocks a queue. Must only be called after locking.
*/
void (*unlock_queue)(struct AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index);
+
+ /**
+ * Queue families used. Must be preferentially ordered. List may contain
+ * duplicates, as long as their capability flags do not match.
+ *
+ * For compatibility reasons, all the enabled queue families listed above
+ * (queue_family_(tx/comp/encode/decode)_index) must also be included in
+ * this list until they're removed after deprecation.
+ */
+ AVVulkanDeviceQueueFamily qf[16];
+ int nb_qf;
} AVVulkanDeviceContext;
/**
--
2.45.1.288.g0e0cd299f1
More information about the ffmpeg-devel
mailing list