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
1515
1616 API changes, most recent first:
1717
18+2020-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+
1822 2020-04-22 - 0e1db79e37 - lavc 58.81.100 - packet.h
1923 - lavu 56.43.100 - dovi_meta.h
2024 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
445445 /* Try to create the instance */
446446 ret = vkCreateInstance(&inst_props, hwctx->alloc, &hwctx->inst);
447447
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−
453448 /* Check for errors */
454449 if (ret != VK_SUCCESS) {
455450 av_log(ctx, AV_LOG_ERROR, "Instance creation failure: %s\n",
456451 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);
457455 return AVERROR_EXTERNAL;
458456 }
459457
@@ -476,6 +474,9 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts) · 16 unmodified lines
476474 hwctx->alloc, &p->debug_ctx);
477475 }
478476
477+ hwctx->enabled_inst_extensions = inst_props.ppEnabledExtensionNames;
478+ hwctx->nb_enabled_inst_extensions = inst_props.enabledExtensionCount;
479+
479480 return 0;
480481 }
481482
@@ -781,6 +782,14 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) · 299 unmodified lines
781782 }
782783
783784 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);
784793 }
785794
786795 static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
@@ -841,13 +850,12 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, · 54 unmodified lines
841850 ret = vkCreateDevice(hwctx->phys_dev, &dev_info, hwctx->alloc,
842851 &hwctx->act_dev);
843852
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−
848853 if (ret != VK_SUCCESS) {
849854 av_log(ctx, AV_LOG_ERROR, "Device creation failure: %s\n",
850855 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);
851859 err = AVERROR_EXTERNAL;
852860 goto end;
853861 }
@@ -857,6 +865,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx, · 3 unmodified lines
857865 if (opt_d)
858866 p->use_linear_images = strtol(opt_d->value, NULL, 10);
859867
868+ hwctx->enabled_dev_extensions = dev_info.ppEnabledExtensionNames;
869+ hwctx->nb_enabled_dev_extensions = dev_info.enabledExtensionCount;
870+
860871 end:
861872 return err;
862873 }
@@ -868,6 +879,17 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) · 5 unmodified lines
868879 AVVulkanDeviceContext *hwctx = ctx->hwctx;
869880 VulkanDevicePriv *p = ctx->internal->priv;
870881
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+
871893 vkGetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &queue_num, NULL);
872894 if (!queue_num) {
873895 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
3939 */
4040 const VkAllocationCallbacks *alloc;
4141 /**
42− * Instance
42+ * Vulkan instance. Must be at least version 1.1.
4343 */
4444 VkInstance inst;
4545 /**
@@ -65,6 +65,25 @@ typedef struct AVVulkanDeviceContext { · 19 unmodified lines
6565 * Queue family index for compute ops
6666 */
6767 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;
6887 } AVVulkanDeviceContext;
6988
7089 /**
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 56
82−#define LIBAVUTIL_VERSION_MINOR 43
82+#define LIBAVUTIL_VERSION_MINOR 44
8383 #define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #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