History

hwcontext_vulkan: expose enabled device and instance extensions

This solves a huge oversight - it lets users reliably use their own AVVulkanDeviceContext. Otherwise, the extensions supplied and enabled are not discoverable by anything outside of hwcontext_vulkan. Also clarifies that any user-supplied VkInstance must be at least 1.1.

Lynne committed 6 years ago

Commit dccd07f1 parent 3c5e5a54 files · +56 −11Browse files

Unified · Split

4 files
  1. doc/APIchanges +4 −0
  2. libavutil/hwcontext_vulkan.c +31 −9
  3. libavutil/hwcontext_vulkan.h +20 −1
  4. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2017-10-21 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182020-05-10 - xxxxxxxxxx - lavu 56.44.100 - hwcontext_vulkan.h
19 Add enabled_inst_extensions, num_enabled_inst_extensions, enabled_dev_extensions
20 and num_enabled_dev_extensions fields to AVVulkanDeviceContext
21
182020-04-22 - 0e1db79e37 - lavc 58.81.100 - packet.h222020-04-22 - 0e1db79e37 - lavc 58.81.100 - packet.h
19 - lavu 56.43.100 - dovi_meta.h23 - lavu 56.43.100 - dovi_meta.h
20 Add AV_PKT_DATA_DOVI_CONF and AVDOVIDecoderConfigurationRecord.24 Add AV_PKT_DATA_DOVI_CONF and AVDOVIDecoderConfigurationRecord.
libavutil/hwcontext_vulkan.c+31−9
@@ -445,15 +445,13 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) · 444 unmodified lines
445 /* Try to create the instance */445 /* Try to create the instance */
446 ret = vkCreateInstance(&inst_props, hwctx->alloc, &hwctx->inst);446 ret = vkCreateInstance(&inst_props, hwctx->alloc, &hwctx->inst);
447 447
448 /* Free used memory */
449 for (int i = 0; i < inst_props.enabledExtensionCount; i++)
450 av_free((void *)inst_props.ppEnabledExtensionNames[i]);
451 av_free((void *)inst_props.ppEnabledExtensionNames);
452
453 /* Check for errors */448 /* Check for errors */
454 if (ret != VK_SUCCESS) {449 if (ret != VK_SUCCESS) {
455 av_log(ctx, AV_LOG_ERROR, "Instance creation failure: %s\n",450 av_log(ctx, AV_LOG_ERROR, "Instance creation failure: %s\n",
456 vk_ret2str(ret));451 vk_ret2str(ret));
452 for (int i = 0; i < inst_props.enabledExtensionCount; i++)
453 av_free((void *)inst_props.ppEnabledExtensionNames[i]);
454 av_free((void *)inst_props.ppEnabledExtensionNames);
457 return AVERROR_EXTERNAL;455 return AVERROR_EXTERNAL;
458 }456 }
459 457
@@ -476,6 +474,9 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) · 16 unmodified lines
476 hwctx->alloc, &p->debug_ctx);474 hwctx->alloc, &p->debug_ctx);
477 }475 }
478 476
477 hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames;
478 hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount;
479
479 return 0;480 return 0;
480}481}
481 482
@@ -781,6 +782,14 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) · 299 unmodified lines
781 }782 }
782 783
783 vkDestroyInstance(hwctx->inst, hwctx->alloc);784 vkDestroyInstance(hwctx->inst, hwctx->alloc);
785
786 for (int i = 0; i < hwctx->nb_enabled_inst_extensions; i++)
787 av_free((void *)hwctx->enabled_inst_extensions[i]);
788 av_free((void *)hwctx->enabled_inst_extensions);
789
790 for (int i = 0; i < hwctx->nb_enabled_dev_extensions; i++)
791 av_free((void *)hwctx->enabled_dev_extensions[i]);
792 av_free((void *)hwctx->enabled_dev_extensions);
784}793}
785 794
786static int vulkan_device_create_internal(AVHWDeviceContext *ctx,795static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
@@ -841,13 +850,12 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, · 54 unmodified lines
841 ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc,850 ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc,
842 &hwctx->act_dev);851 &hwctx->act_dev);
843 852
844 for (int i = 0; i < dev_info.enabledExtensionCount; i++)
845 av_free((void *)dev_info.ppEnabledExtensionNames[i]);
846 av_free((void *)dev_info.ppEnabledExtensionNames);
847
848 if (ret != VK_SUCCESS) {853 if (ret != VK_SUCCESS) {
849 av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n",854 av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n",
850 vk_ret2str(ret));855 vk_ret2str(ret));
856 for (int i = 0; i < dev_info.enabledExtensionCount; i++)
857 av_free((void *)dev_info.ppEnabledExtensionNames[i]);
858 av_free((void *)dev_info.ppEnabledExtensionNames);
851 err = AVERROR_EXTERNAL;859 err = AVERROR_EXTERNAL;
852 goto end;860 goto end;
853 }861 }
@@ -857,6 +865,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, · 3 unmodified lines
857 if (opt_d)865 if (opt_d)
858 p->use_linear_images = strtol(opt_d->value, NULL, 10);866 p->use_linear_images = strtol(opt_d->value, NULL, 10);
859 867
868 hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
869 hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
870
860end:871end:
861 return err;872 return err;
862}873}
@@ -868,6 +879,17 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) · 5 unmodified lines
868 AVVulkanDeviceContext *hwctx = ctx->hwctx;879 AVVulkanDeviceContext *hwctx = ctx->hwctx;
869 VulkanDevicePriv *p = ctx->internal->priv;880 VulkanDevicePriv *p = ctx->internal->priv;
870 881
882 /* Set device extension flags */
883 for (int i = 0; i < hwctx->nb_enabled_dev_extensions; i++) {
884 for (int j = 0; j < FF_ARRAY_ELEMS(optional_device_exts); j++) {
885 if (!strcmp(hwctx->enabled_dev_extensions[i],
886 optional_device_exts[j].name)) {
887 p->extensions |= optional_device_exts[j].flag;
888 break;
889 }
890 }
891 }
892
871 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL);893 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL);
872 if (!queue_num) {894 if (!queue_num) {
873 av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n");895 av_log(ctx, AV_LOG_ERROR, "Failed to get queues!\n");
libavutil/hwcontext_vulkan.h+20−1
@@ -39,7 +39,7 @@ typedef struct AVVulkanDeviceContext { · 38 unmodified lines
39 */39 */
40 const VkAllocationCallbacks *alloc;40 const VkAllocationCallbacks *alloc;
41 /**41 /**
42 * Instance42 * Vulkan instance. Must be at least version 1.1.
43 */43 */
44 VkInstance inst;44 VkInstance inst;
45 /**45 /**
@@ -65,6 +65,25 @@ typedef struct AVVulkanDeviceContext { · 19 unmodified lines
65 * Queue family index for compute ops65 * Queue family index for compute ops
66 */66 */
67 int queue_family_comp_index;67 int queue_family_comp_index;
68 /**
69 * Enabled instance extensions. By default, VK_KHR_surface is enabled if found.
70 * If supplying your own device context, set this to an array of strings, with
71 * each entry containing the specified Vulkan extension string to enable.
72 * Duplicates are possible and accepted.
73 * If no extensions are enabled, set these fields to NULL, and 0 respectively.
74 */
75 const char * const *enabled_inst_extensions;
76 int nb_enabled_inst_extensions;
77 /**
78 * Enabled device extensions. By default, VK_KHR_external_memory_fd,
79 * VK_EXT_external_memory_dma_buf, VK_EXT_image_drm_format_modifier and
80 * VK_KHR_external_semaphore_fd are enabled if found.
81 * If supplying your own device context, these fields takes the same format as
82 * the above fields, with the same conditions that duplicates are possible
83 * and accepted, and that NULL and 0 respectively means no extensions are enabled.
84 */
85 const char * const *enabled_dev_extensions;
86 int nb_enabled_dev_extensions;
68} AVVulkanDeviceContext;87} AVVulkanDeviceContext;
69 88
70/**89/**
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5681#define LIBAVUTIL_VERSION_MAJOR 56
82#define LIBAVUTIL_VERSION_MINOR 4382#define LIBAVUTIL_VERSION_MINOR 44
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t