vulkan: add support for retrieving queue, query and video properties

This commit is contained in:
Lynne 2022-12-22 17:37:51 +01:00
parent 6eaf3fe69c
commit b15104ed97
No known key found for this signature in database
GPG Key ID: A2FEA5F03F034464
3 changed files with 85 additions and 17 deletions

View File

@ -108,8 +108,9 @@ const char *ff_vk_ret2str(VkResult res)
#undef CASE #undef CASE
} }
void ff_vk_load_props(FFVulkanContext *s) int ff_vk_load_props(FFVulkanContext *s)
{ {
uint32_t qc = 0;
FFVulkanFunctions *vk = &s->vkfn; FFVulkanFunctions *vk = &s->vkfn;
s->driver_props = (VkPhysicalDeviceDriverProperties) { s->driver_props = (VkPhysicalDeviceDriverProperties) {
@ -120,8 +121,48 @@ void ff_vk_load_props(FFVulkanContext *s)
.pNext = &s->driver_props, .pNext = &s->driver_props,
}; };
vk->GetPhysicalDeviceProperties2(s->hwctx->phys_dev, &s->props); vk->GetPhysicalDeviceProperties2(s->hwctx->phys_dev, &s->props);
vk->GetPhysicalDeviceMemoryProperties(s->hwctx->phys_dev, &s->mprops); 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) 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; s->qfs[s->nb_qfs++] = s->hwctx->queue_family_encode_index;
} }
void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, int ff_vk_qf_get_index(FFVulkanContext *s, VkQueueFlagBits dev_family, int *nb)
VkQueueFlagBits dev_family, int nb_queues)
{ {
int ret, num;
switch (dev_family) { switch (dev_family) {
case VK_QUEUE_GRAPHICS_BIT: case VK_QUEUE_GRAPHICS_BIT:
qf->queue_family = s->hwctx->queue_family_index; ret = s->hwctx->queue_family_index;
qf->actual_queues = s->hwctx->nb_graphics_queues; num = s->hwctx->nb_graphics_queues;
break; break;
case VK_QUEUE_COMPUTE_BIT: case VK_QUEUE_COMPUTE_BIT:
qf->queue_family = s->hwctx->queue_family_comp_index; ret = s->hwctx->queue_family_comp_index;
qf->actual_queues = s->hwctx->nb_comp_queues; num = s->hwctx->nb_comp_queues;
break; break;
case VK_QUEUE_TRANSFER_BIT: case VK_QUEUE_TRANSFER_BIT:
qf->queue_family = s->hwctx->queue_family_tx_index; ret = s->hwctx->queue_family_tx_index;
qf->actual_queues = s->hwctx->nb_tx_queues; num = s->hwctx->nb_tx_queues;
break; break;
case VK_QUEUE_VIDEO_ENCODE_BIT_KHR: case VK_QUEUE_VIDEO_ENCODE_BIT_KHR:
qf->queue_family = s->hwctx->queue_family_encode_index; ret = s->hwctx->queue_family_encode_index;
qf->actual_queues = s->hwctx->nb_encode_queues; num = s->hwctx->nb_encode_queues;
break; break;
case VK_QUEUE_VIDEO_DECODE_BIT_KHR: case VK_QUEUE_VIDEO_DECODE_BIT_KHR:
qf->queue_family = s->hwctx->queue_family_decode_index; ret = s->hwctx->queue_family_decode_index;
qf->actual_queues = s->hwctx->nb_decode_queues; num = s->hwctx->nb_decode_queues;
break; break;
default: default:
av_assert0(0); /* Should never happen */ 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) if (!nb_queues)
qf->nb_queues = qf->actual_queues; qf->nb_queues = qf->actual_queues;
else else
qf->nb_queues = nb_queues; qf->nb_queues = nb_queues;
return; return ret;
} }
void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf) void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf)
@ -1669,6 +1724,10 @@ void ff_vk_uninit(FFVulkanContext *s)
{ {
FFVulkanFunctions *vk = &s->vkfn; FFVulkanFunctions *vk = &s->vkfn;
av_freep(&s->query_props);
av_freep(&s->qf_props);
av_freep(&s->video_props);
if (s->spirv_compiler) if (s->spirv_compiler)
s->spirv_compiler->uninit(&s->spirv_compiler); s->spirv_compiler->uninit(&s->spirv_compiler);

View File

@ -216,6 +216,9 @@ typedef struct FFVulkanContext {
VkPhysicalDeviceProperties2 props; VkPhysicalDeviceProperties2 props;
VkPhysicalDeviceDriverProperties driver_props; VkPhysicalDeviceDriverProperties driver_props;
VkPhysicalDeviceMemoryProperties mprops; VkPhysicalDeviceMemoryProperties mprops;
VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
VkQueueFamilyVideoPropertiesKHR *video_props;
VkQueueFamilyProperties2 *qf_props;
AVBufferRef *device_ref; AVBufferRef *device_ref;
AVHWDeviceContext *device; AVHWDeviceContext *device;
@ -263,7 +266,7 @@ const char *ff_vk_ret2str(VkResult res);
/** /**
* Loads props/mprops/driver_props * 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 * Returns 1 if the image is any sort of supported RGB
@ -288,12 +291,17 @@ int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
VkMemoryPropertyFlagBits req_flags, void *alloc_extension, VkMemoryPropertyFlagBits req_flags, void *alloc_extension,
VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem); 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. * Initialize a queue family with a specific number of queues.
* If nb_queues == 0, use however many queues the queue family has. * If nb_queues == 0, use however many queues the queue family has.
*/ */
void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
VkQueueFlagBits dev_family, int nb_queues); VkQueueFlagBits dev_family, int nb_queues);
/** /**
* Rotate through the queues in a queue family. * Rotate through the queues in a queue family.

View File

@ -77,6 +77,7 @@ typedef enum FFVulkanExtensions {
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceFormatProperties2) \ 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, GetPhysicalDeviceImageFormatProperties2) \
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties) \ MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties) \
MACRO(1, 0, FF_VK_EXT_NO_FLAG, GetPhysicalDeviceQueueFamilyProperties2) \
\ \
/* Command pool */ \ /* Command pool */ \
MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateCommandPool) \ MACRO(1, 1, FF_VK_EXT_NO_FLAG, CreateCommandPool) \