Skip to content

Commit a0e21a6

Browse files
committed
Use new FFmpeg API for passing down Vulkan queues.
1 parent 8e0704f commit a0e21a6

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

video/ffmpeg_hw_device.cpp

+40-11
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,46 @@ struct FFmpegHWDevice::Impl
8484

8585
auto &q = device->get_queue_info();
8686

87-
vk->queue_family_index = int(q.family_indices[Vulkan::QUEUE_INDEX_GRAPHICS]);
88-
vk->queue_family_comp_index = int(q.family_indices[Vulkan::QUEUE_INDEX_COMPUTE]);
89-
vk->queue_family_tx_index = int(q.family_indices[Vulkan::QUEUE_INDEX_TRANSFER]);
90-
vk->queue_family_decode_index = int(q.family_indices[Vulkan::QUEUE_INDEX_VIDEO_DECODE]);
91-
92-
vk->nb_graphics_queues = int(q.counts[Vulkan::QUEUE_INDEX_GRAPHICS]);
93-
vk->nb_comp_queues = int(q.counts[Vulkan::QUEUE_INDEX_COMPUTE]);
94-
vk->nb_tx_queues = int(q.counts[Vulkan::QUEUE_INDEX_TRANSFER]);
95-
vk->nb_decode_queues = int(q.counts[Vulkan::QUEUE_INDEX_VIDEO_DECODE]);
96-
vk->queue_family_encode_index = int(q.family_indices[Vulkan::QUEUE_INDEX_VIDEO_ENCODE]);
97-
vk->nb_encode_queues = int(q.counts[Vulkan::QUEUE_INDEX_VIDEO_ENCODE]);
87+
vk->nb_qf = 0;
88+
89+
const auto alloc_qf = [&](Vulkan::QueueIndices index, VkQueueFlags flags) -> AVVulkanDeviceQueueFamily & {
90+
for (int i = 0; i < vk->nb_qf; i++)
91+
if (vk->qf[i].idx == int(q.family_indices[index]))
92+
return vk->qf[i];
93+
94+
auto &qf = vk->qf[vk->nb_qf++];
95+
qf = {};
96+
qf.idx = int(q.family_indices[index]);
97+
qf.num = std::max<int>(qf.num, int(q.counts[index]));
98+
// Workaround buggy header.
99+
qf.flags = VkQueueFlagBits(qf.flags | flags);
100+
return qf;
101+
};
102+
103+
if (q.family_indices[Vulkan::QUEUE_INDEX_GRAPHICS] != UINT32_MAX)
104+
alloc_qf(Vulkan::QUEUE_INDEX_GRAPHICS, VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT);
105+
if (q.family_indices[Vulkan::QUEUE_INDEX_COMPUTE] != UINT32_MAX)
106+
alloc_qf(Vulkan::QUEUE_INDEX_COMPUTE, VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT);
107+
if (q.family_indices[Vulkan::QUEUE_INDEX_TRANSFER] != UINT32_MAX)
108+
alloc_qf(Vulkan::QUEUE_INDEX_TRANSFER, VK_QUEUE_TRANSFER_BIT);
109+
110+
if (q.family_indices[Vulkan::QUEUE_INDEX_VIDEO_ENCODE] != UINT32_MAX)
111+
{
112+
auto &qf = alloc_qf(Vulkan::QUEUE_INDEX_VIDEO_ENCODE, VK_QUEUE_VIDEO_ENCODE_BIT_KHR);
113+
if (device->get_device_features().supports_video_encode_h264)
114+
qf.video_caps = VkVideoCodecOperationFlagBitsKHR(qf.video_caps | VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_KHR);
115+
if (device->get_device_features().supports_video_encode_h265)
116+
qf.video_caps = VkVideoCodecOperationFlagBitsKHR(qf.video_caps | VK_VIDEO_CODEC_OPERATION_ENCODE_H265_BIT_KHR);
117+
}
118+
119+
if (q.family_indices[Vulkan::QUEUE_INDEX_VIDEO_DECODE] != UINT32_MAX)
120+
{
121+
auto &qf = alloc_qf(Vulkan::QUEUE_INDEX_VIDEO_DECODE, VK_QUEUE_VIDEO_DECODE_BIT_KHR);
122+
if (device->get_device_features().supports_video_decode_h264)
123+
qf.video_caps = VkVideoCodecOperationFlagBitsKHR(qf.video_caps | VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR);
124+
if (device->get_device_features().supports_video_decode_h265)
125+
qf.video_caps = VkVideoCodecOperationFlagBitsKHR(qf.video_caps | VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR);
126+
}
98127

99128
vk->lock_queue = [](AVHWDeviceContext *ctx, uint32_t, uint32_t) {
100129
auto *self = static_cast<Impl *>(ctx->user_opaque);

0 commit comments

Comments
 (0)