aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2022-12-22 17:37:51 +0100
committerLynne <dev@lynne.ee>2023-05-29 00:41:47 +0200
commitb15104ed97185e3e66d7a29322f656b358f54252 (patch)
treefc2dff5bec8e0188eb1040afde4ad9bf9aa41255
parent6eaf3fe69cc18739e9f2cc54418cf29c1d2c113c (diff)
downloadffmpeg-b15104ed97185e3e66d7a29322f656b358f54252.tar.gz
vulkan: add support for retrieving queue, query and video properties
-rw-r--r--libavutil/vulkan.c87
-rw-r--r--libavutil/vulkan.h14
-rw-r--r--libavutil/vulkan_functions.h1
3 files changed, 85 insertions, 17 deletions
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index de0c300c0e..6c9f91c7ef 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -108,8 +108,9 @@ const char *ff_vk_ret2str(VkResult res)
#undef CASE
}
-void ff_vk_load_props(FFVulkanContext *s)
+int ff_vk_load_props(FFVulkanContext *s)
{
+ uint32_t qc = 0;
FFVulkanFunctions *vk = &s->vkfn;
s->driver_props = (VkPhysicalDeviceDriverProperties) {
@@ -120,8 +121,48 @@ void ff_vk_load_props(FFVulkanContext *s)
.pNext = &s->driver_props,
};
+
vk->GetPhysicalDeviceProperties2(s->hwctx->phys_dev, &s->props);
vk->GetPhysicalDeviceMemoryProperties(s->hwctx->phys_dev, &s->mprops);
+ vk->GetPhysicalDeviceQueueFamilyProperties2(s->hwctx->phys_dev, &qc, s->qf_props);
+
+ if (s->qf_props)
+ return 0;
+
+ s->qf_props = av_calloc(qc, sizeof(*s->qf_props));
+ if (!s->qf_props)
+ return AVERROR(ENOMEM);
+
+ s->query_props = av_calloc(qc, sizeof(*s->query_props));
+ if (!s->qf_props) {
+ av_freep(&s->qf_props);
+ return AVERROR(ENOMEM);
+ }
+
+ s->video_props = av_calloc(qc, sizeof(*s->video_props));
+ if (!s->video_props) {
+ av_freep(&s->qf_props);
+ av_freep(&s->query_props);
+ return AVERROR(ENOMEM);
+ }
+
+ for (uint32_t i = 0; i < qc; i++) {
+ s->query_props[i] = (VkQueueFamilyQueryResultStatusPropertiesKHR) {
+ .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_QUERY_RESULT_STATUS_PROPERTIES_KHR,
+ };
+ s->video_props[i] = (VkQueueFamilyVideoPropertiesKHR) {
+ .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_VIDEO_PROPERTIES_KHR,
+ .pNext = &s->query_props[i],
+ };
+ s->qf_props[i] = (VkQueueFamilyProperties2) {
+ .sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2,
+ .pNext = &s->video_props[i],
+ };
+ }
+
+ vk->GetPhysicalDeviceQueueFamilyProperties2(s->hwctx->phys_dev, &qc, s->qf_props);
+
+ return 0;
}
void ff_vk_qf_fill(FFVulkanContext *s)
@@ -149,40 +190,54 @@ void ff_vk_qf_fill(FFVulkanContext *s)
s->qfs[s->nb_qfs++] = s->hwctx->queue_family_encode_index;
}
-void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
- VkQueueFlagBits dev_family, int nb_queues)
+int ff_vk_qf_get_index(FFVulkanContext *s, VkQueueFlagBits dev_family, int *nb)
{
+ int ret, num;
+
switch (dev_family) {
case VK_QUEUE_GRAPHICS_BIT:
- qf->queue_family = s->hwctx->queue_family_index;
- qf->actual_queues = s->hwctx->nb_graphics_queues;
+ ret = s->hwctx->queue_family_index;
+ num = s->hwctx->nb_graphics_queues;
break;
case VK_QUEUE_COMPUTE_BIT:
- qf->queue_family = s->hwctx->queue_family_comp_index;
- qf->actual_queues = s->hwctx->nb_comp_queues;
+ ret = s->hwctx->queue_family_comp_index;
+ num = s->hwctx->nb_comp_queues;
break;
case VK_QUEUE_TRANSFER_BIT:
- qf->queue_family = s->hwctx->queue_family_tx_index;
- qf->actual_queues = s->hwctx->nb_tx_queues;
+ ret = s->hwctx->queue_family_tx_index;
+ num = s->hwctx->nb_tx_queues;
break;
case VK_QUEUE_VIDEO_ENCODE_BIT_KHR:
- qf->queue_family = s->hwctx->queue_family_encode_index;
- qf->actual_queues = s->hwctx->nb_encode_queues;
+ ret = s->hwctx->queue_family_encode_index;
+ num = s->hwctx->nb_encode_queues;
break;
case VK_QUEUE_VIDEO_DECODE_BIT_KHR:
- qf->queue_family = s->hwctx->queue_family_decode_index;
- qf->actual_queues = s->hwctx->nb_decode_queues;
+ ret = s->hwctx->queue_family_decode_index;
+ num = s->hwctx->nb_decode_queues;
break;
default:
av_assert0(0); /* Should never happen */
}
+ if (nb)
+ *nb = num;
+
+ return ret;
+}
+
+int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
+ VkQueueFlagBits dev_family, int nb_queues)
+{
+ int ret;
+
+ ret = qf->queue_family = ff_vk_qf_get_index(s, dev_family, &qf->actual_queues);
+
if (!nb_queues)
qf->nb_queues = qf->actual_queues;
else
qf->nb_queues = nb_queues;
- return;
+ return ret;
}
void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf)
@@ -1669,6 +1724,10 @@ void ff_vk_uninit(FFVulkanContext *s)
{
FFVulkanFunctions *vk = &s->vkfn;
+ av_freep(&s->query_props);
+ av_freep(&s->qf_props);
+ av_freep(&s->video_props);
+
if (s->spirv_compiler)
s->spirv_compiler->uninit(&s->spirv_compiler);
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 4bd1c9fc00..4c38dbc2e6 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -216,6 +216,9 @@ typedef struct FFVulkanContext {
VkPhysicalDeviceProperties2 props;
VkPhysicalDeviceDriverProperties driver_props;
VkPhysicalDeviceMemoryProperties mprops;
+ VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
+ VkQueueFamilyVideoPropertiesKHR *video_props;
+ VkQueueFamilyProperties2 *qf_props;
AVBufferRef *device_ref;
AVHWDeviceContext *device;
@@ -263,7 +266,7 @@ const char *ff_vk_ret2str(VkResult res);
/**
* Loads props/mprops/driver_props
*/
-void ff_vk_load_props(FFVulkanContext *s);
+int ff_vk_load_props(FFVulkanContext *s);
/**
* Returns 1 if the image is any sort of supported RGB
@@ -289,11 +292,16 @@ int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
/**
+ * Get a queue family index and the number of queues. nb is optional.
+ */
+int ff_vk_qf_get_index(FFVulkanContext *s, VkQueueFlagBits dev_family, int *nb);
+
+/**
* Initialize a queue family with a specific number of queues.
* If nb_queues == 0, use however many queues the queue family has.
*/
-void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
- VkQueueFlagBits dev_family, int nb_queues);
+int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
+ VkQueueFlagBits dev_family, int nb_queues);
/**
* Rotate through the queues in a queue family.
diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 2a7c383dc1..e06d097807 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -77,6 +77,7 @@ typedef enum FFVulkanExtensions {
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceFormatProperties2) \
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceImageFormatProperties2) \
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties) \
+ MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties2) \
\
/* Command pool */ \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateCommandPool) \