Unverified Commit 6025e66f authored by Lynne's avatar Lynne

hwcontext_vulkan: use the maximum amount of queues for each family

Due to our AVHWDevice infrastructure, where API users are offered a way
to derive contexts rather than always create new one, our filterchains,
being supported by a single hardware device context, can grow to considerable
size.
Hence, in such situations, using the maximum amount of queues the device offers
can be benefitial to eliminating bottlenecks where queue submissions on the
same family have to wait for the previous one to finish.
parent 0e39fce1
...@@ -619,6 +619,7 @@ end: ...@@ -619,6 +619,7 @@ end:
static int search_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd) static int search_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
{ {
uint32_t num; uint32_t num;
float *weights;
VkQueueFamilyProperties *qs = NULL; VkQueueFamilyProperties *qs = NULL;
AVVulkanDeviceContext *hwctx = ctx->hwctx; AVVulkanDeviceContext *hwctx = ctx->hwctx;
int graph_index = -1, comp_index = -1, tx_index = -1; int graph_index = -1, comp_index = -1, tx_index = -1;
...@@ -657,41 +658,53 @@ static int search_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd) ...@@ -657,41 +658,53 @@ static int search_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
(i != comp_index), tx_index) (i != comp_index), tx_index)
#undef SEARCH_FLAGS #undef SEARCH_FLAGS
#define QF_FLAGS(flags) \ #define ADD_QUEUE(fidx, graph, comp, tx) \
((flags) & VK_QUEUE_GRAPHICS_BIT ) ? "(graphics) " : "", \ av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i (total queues: %i) for %s%s%s\n", \
((flags) & VK_QUEUE_COMPUTE_BIT ) ? "(compute) " : "", \ fidx, qs[fidx].queueCount, graph ? "graphics " : "", \
((flags) & VK_QUEUE_TRANSFER_BIT ) ? "(transfer) " : "", \ comp ? "compute " : "", tx ? "transfers " : ""); \
((flags) & VK_QUEUE_SPARSE_BINDING_BIT) ? "(sparse) " : "" av_log(ctx, AV_LOG_VERBOSE, " QF %i flags: %s%s%s%s\n", fidx, \
((qs[fidx].queueFlags) & VK_QUEUE_GRAPHICS_BIT) ? "(graphics) " : "", \
av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i for graphics, " ((qs[fidx].queueFlags) & VK_QUEUE_COMPUTE_BIT) ? "(compute) " : "", \
"flags: %s%s%s%s\n", graph_index, QF_FLAGS(qs[graph_index].queueFlags)); ((qs[fidx].queueFlags) & VK_QUEUE_TRANSFER_BIT) ? "(transfers) " : "", \
((qs[fidx].queueFlags) & VK_QUEUE_SPARSE_BINDING_BIT) ? "(sparse) " : ""); \
pc[cd->queueCreateInfoCount].queueFamilyIndex = fidx; \
pc[cd->queueCreateInfoCount].queueCount = qs[fidx].queueCount; \
weights = av_malloc(qs[fidx].queueCount * sizeof(float)); \
pc[cd->queueCreateInfoCount].pQueuePriorities = weights; \
if (!weights) \
goto fail; \
for (int i = 0; i < qs[fidx].queueCount; i++) \
weights[i] = 1.0f; \
cd->queueCreateInfoCount++;
ADD_QUEUE(graph_index, 1, comp_index < 0, tx_index < 0 && comp_index < 0)
hwctx->queue_family_index = graph_index; hwctx->queue_family_index = graph_index;
hwctx->queue_family_tx_index = graph_index;
hwctx->queue_family_comp_index = graph_index; hwctx->queue_family_comp_index = graph_index;
hwctx->queue_family_tx_index = graph_index;
pc[cd->queueCreateInfoCount++].queueFamilyIndex = graph_index;
if (comp_index != -1) { if (comp_index != -1) {
av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i for compute, " ADD_QUEUE(comp_index, 0, 1, tx_index < 0)
"flags: %s%s%s%s\n", comp_index, QF_FLAGS(qs[comp_index].queueFlags)); hwctx->queue_family_tx_index = comp_index;
hwctx->queue_family_tx_index = comp_index; hwctx->queue_family_comp_index = comp_index;
hwctx->queue_family_comp_index = comp_index;
pc[cd->queueCreateInfoCount++].queueFamilyIndex = comp_index;
} }
if (tx_index != -1) { if (tx_index != -1) {
av_log(ctx, AV_LOG_VERBOSE, "Using queue family %i for transfers, " ADD_QUEUE(tx_index, 0, 0, 1)
"flags: %s%s%s%s\n", tx_index, QF_FLAGS(qs[tx_index].queueFlags)); hwctx->queue_family_tx_index = tx_index;
hwctx->queue_family_tx_index = tx_index;
pc[cd->queueCreateInfoCount++].queueFamilyIndex = tx_index;
} }
#undef QF_FLAGS #undef ADD_QUEUE
av_free(qs); av_free(qs);
return 0; return 0;
fail:
av_freep(&pc[0].pQueuePriorities);
av_freep(&pc[1].pQueuePriorities);
av_freep(&pc[2].pQueuePriorities);
av_free(qs);
return AVERROR(ENOMEM);
} }
static int create_exec_ctx(AVHWDeviceContext *ctx, VulkanExecCtx *cmd, static int create_exec_ctx(AVHWDeviceContext *ctx, VulkanExecCtx *cmd,
...@@ -794,15 +807,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, ...@@ -794,15 +807,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
VulkanDevicePriv *p = ctx->internal->priv; VulkanDevicePriv *p = ctx->internal->priv;
AVVulkanDeviceContext *hwctx = ctx->hwctx; AVVulkanDeviceContext *hwctx = ctx->hwctx;
VkDeviceQueueCreateInfo queue_create_info[3] = { VkDeviceQueueCreateInfo queue_create_info[3] = {
{ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
.pQueuePriorities = (float []){ 1.0f }, { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
.queueCount = 1, }, { .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, },
{ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.pQueuePriorities = (float []){ 1.0f },
.queueCount = 1, },
{ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.pQueuePriorities = (float []){ 1.0f },
.queueCount = 1, },
}; };
VkDeviceCreateInfo dev_info = { VkDeviceCreateInfo dev_info = {
...@@ -836,12 +843,20 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, ...@@ -836,12 +843,20 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
goto end; goto end;
if ((err = check_extensions(ctx, 1, opts, &dev_info.ppEnabledExtensionNames, if ((err = check_extensions(ctx, 1, opts, &dev_info.ppEnabledExtensionNames,
&dev_info.enabledExtensionCount, 0))) &dev_info.enabledExtensionCount, 0))) {
av_free((void *)queue_create_info[0].pQueuePriorities);
av_free((void *)queue_create_info[1].pQueuePriorities);
av_free((void *)queue_create_info[2].pQueuePriorities);
goto end; goto end;
}
ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc, ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc,
&hwctx->act_dev); &hwctx->act_dev);
av_free((void *)queue_create_info[0].pQueuePriorities);
av_free((void *)queue_create_info[1].pQueuePriorities);
av_free((void *)queue_create_info[2].pQueuePriorities);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n", av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n",
vk_ret2str(ret)); vk_ret2str(ret));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment