History

vulkan: enable encoding of images if video_maintenance1 is enabled

Vulkan encoding was designed in a very... consolidated way. You had to know the exact codec and profile that the image was going to eventually be encoded as at... image creation time. Unfortunately, as good as our code is, glimpsing into the exact future isn't what its capable of. video_maintenance1 removed that requirement, which only then made encoding images practically possible.

Lynne committed 2 years ago

Commit 18d964f1 parent 46c13833 files · +67 −12Browse files

Showing the changes to libavfilter (1 of 3 files). Show all

Unified · Split

libavfilter/vulkan_filter.c+29−12
@@ -37,6 +37,7 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, · 36 unmodified lines
37 if (frames_ref) {37 if (frames_ref) {
38 int no_storage = 0;38 int no_storage = 0;
39 FFVulkanFunctions *vk;39 FFVulkanFunctions *vk;
40 VkImageUsageFlagBits usage_req;
40 const VkFormat *sub = av_vkfmt_from_pixfmt(sw_format);41 const VkFormat *sub = av_vkfmt_from_pixfmt(sw_format);
41 42
42 frames_ctx = (AVHWFramesContext *)frames_ref->data;43 frames_ctx = (AVHWFramesContext *)frames_ref->data;
@@ -57,18 +58,41 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, · 14 unmodified lines
57 if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL)58 if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL)
58 goto skip;59 goto skip;
59 60
60 /* Usage mismatch */
61 if ((vk_frames->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) !=
62 (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT))
63 goto skip;
64
65 s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,61 s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
66 vk_dev->nb_enabled_dev_extensions);62 vk_dev->nb_enabled_dev_extensions);
63
64 /* More advanced format checks */
67 err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);65 err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
68 if (err < 0)66 if (err < 0)
69 return err;67 return err;
70 vk = &s->vkfn;68 vk = &s->vkfn;
71 69
70 /* Usage mismatch */
71 usage_req = VK_IMAGE_USAGE_SAMPLED_BIT |
72 VK_IMAGE_USAGE_STORAGE_BIT;
73
74 /* If format supports hardware encoding, make sure
75 * the context includes it. */
76 if (vk_frames->format[1] == VK_FORMAT_UNDEFINED &&
77 (s->extensions & (FF_VK_EXT_VIDEO_ENCODE_QUEUE |
78 FF_VK_EXT_VIDEO_MAINTENANCE_1))) {
79 VkFormatProperties3 fprops = {
80 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3,
81 };
82 VkFormatProperties2 prop = {
83 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
84 .pNext = &fprops,
85 };
86 vk->GetPhysicalDeviceFormatProperties2(vk_dev->phys_dev,
87 vk_frames->format[0],
88 &prop);
89 if (fprops.optimalTilingFeatures & VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR)
90 usage_req |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
91 }
92
93 if ((vk_frames->usage & usage_req) != usage_req)
94 goto skip;
95
72 /* Check if the subformats can do storage */96 /* Check if the subformats can do storage */
73 for (int i = 0; sub[i] != VK_FORMAT_UNDEFINED; i++) {97 for (int i = 0; sub[i] != VK_FORMAT_UNDEFINED; i++) {
74 VkFormatProperties2 prop = {98 VkFormatProperties2 prop = {
@@ -113,13 +137,6 @@ skip: · 38 unmodified lines
113 frames_ctx->width = width;137 frames_ctx->width = width;
114 frames_ctx->height = height;138 frames_ctx->height = height;
115 139
116 vk_frames = frames_ctx->hwctx;
117 vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
118 vk_frames->usage = VK_IMAGE_USAGE_SAMPLED_BIT |
119 VK_IMAGE_USAGE_STORAGE_BIT |
120 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
121 VK_IMAGE_USAGE_TRANSFER_DST_BIT;
122
123 err = av_hwframe_ctx_init(frames_ref);140 err = av_hwframe_ctx_init(frames_ref);
124 if (err < 0) {141 if (err < 0) {
125 av_buffer_unref(&frames_ref);142 av_buffer_unref(&frames_ref);

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