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
3737 if (frames_ref) {
3838 int no_storage = 0;
3939 FFVulkanFunctions *vk;
40+ VkImageUsageFlagBits usage_req;
4041 const VkFormat *sub = av_vkfmt_from_pixfmt(sw_format);
4142
4243 frames_ctx = (AVHWFramesContext *)frames_ref->data;
@@ -57,18 +58,41 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, · 14 unmodified lines
5758 if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL)
5859 goto skip;
5960
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−
6561 s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
6662 vk_dev->nb_enabled_dev_extensions);
63+
64+ /* More advanced format checks */
6765 err = ff_vk_load_functions(device_ctx, &s->vkfn, s->extensions, 1, 1);
6866 if (err < 0)
6967 return err;
7068 vk = &s->vkfn;
7169
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+
7296 /* Check if the subformats can do storage */
7397 for (int i = 0; sub[i] != VK_FORMAT_UNDEFINED; i++) {
7498 VkFormatProperties2 prop = {
@@ -113,13 +137,6 @@ skip: · 38 unmodified lines
113137 frames_ctx->width = width;
114138 frames_ctx->height = height;
115139
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−
123140 err = av_hwframe_ctx_init(frames_ref);
124141 if (err < 0) {
125142 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