Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] hwcontext_vulkan: add the VK_IMAGE_USAGE_SAMPLED_BIT bit to new images
@ 2023-10-05 21:26 Lynne
  2023-10-05 21:27 ` Philip Langdale via ffmpeg-devel
  0 siblings, 1 reply; 3+ messages in thread
From: Lynne @ 2023-10-05 21:26 UTC (permalink / raw)
  To: Ffmpeg Devel

[-- Attachment #1: Type: text/plain, Size: 50 bytes --]

This fixes filtering on Nvidia.

Patch attached.


[-- Attachment #2: 0001-hwcontext_vulkan-properly-support-STORAGE-usage-for-.patch --]
[-- Type: text/x-diff, Size: 9514 bytes --]

From 2ea0d50049bae792477c53780b3cfd0e3863d914 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Thu, 5 Oct 2023 20:25:33 +0200
Subject: [PATCH] hwcontext_vulkan: properly support STORAGE usage for
 mutliplane images

Fixes multiplane support on Nvidia.

Also, remove the ENCODE usage, even if the driver signals it as supported.
Currently, it's not used, and when it is used, it'll be gated behind
two extension checks.
---
 libavfilter/vulkan_filter.c  | 24 +++++++++++++++---------
 libavutil/hwcontext_vulkan.c | 36 ++++++++++++++++++++++++------------
 2 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/libavfilter/vulkan_filter.c b/libavfilter/vulkan_filter.c
index b4d8f952b5..f3f40465be 100644
--- a/libavfilter/vulkan_filter.c
+++ b/libavfilter/vulkan_filter.c
@@ -42,18 +42,23 @@ int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s,
         vk_frames = frames_ctx->hwctx;
         vk_dev = device_ctx->hwctx;
 
-        /* Basic format validation */
+        /* Width and height mismatch */
         if (width != frames_ctx->width ||
-            height != frames_ctx->height ||
-            sw_format != frames_ctx->sw_format ||
-            (vk_frames->tiling != VK_IMAGE_TILING_LINEAR &&
-             vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL) ||
-            !(vk_frames->usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
+            height != frames_ctx->height)
+            goto skip;
+
+        /* Format mismatch */
+        if (sw_format != frames_ctx->sw_format)
             goto skip;
-        }
 
-        if (vk_frames->usage & VK_IMAGE_USAGE_STORAGE_BIT)
-            goto accept;
+        /* Unusual tiling mismatch. Don't let linear through either. */
+        if (vk_frames->tiling != VK_IMAGE_TILING_OPTIMAL)
+            goto skip;
+
+        /* Usage mismatch */
+        if ((vk_frames->usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT)) !=
+                                (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT))
+            goto skip;
 
         s->extensions = ff_vk_extensions_to_mask(vk_dev->enabled_dev_extensions,
                                                  vk_dev->nb_enabled_dev_extensions);
@@ -110,6 +115,7 @@ accept:
         vk_frames = frames_ctx->hwctx;
         vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
         vk_frames->usage  = VK_IMAGE_USAGE_SAMPLED_BIT |
+                            VK_IMAGE_USAGE_STORAGE_BIT |
                             VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
                             VK_IMAGE_USAGE_TRANSFER_DST_BIT;
 
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index c676f4fc57..b955ec483e 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -282,9 +282,11 @@ FN_MAP_TO(VkImageUsageFlags, usage, VkFormatFeatureFlagBits2, feats)
 
 static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
                               VkImageTiling tiling,
-                              VkFormat fmts[AV_NUM_DATA_POINTERS],
-                              int *nb_images, VkImageAspectFlags *aspect,
-                              VkImageUsageFlags *supported_usage, int disable_multiplane)
+                              VkFormat fmts[AV_NUM_DATA_POINTERS], /* Output format list */
+                              int *nb_images,                      /* Output number of images */
+                              VkImageAspectFlags *aspect,          /* Output aspect */
+                              VkImageUsageFlags *supported_usage,  /* Output supported usage */
+                              int disable_multiplane, int need_storage)
 {
     AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
     VulkanDevicePriv *priv = dev_ctx->internal->priv;
@@ -301,6 +303,7 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
             };
             VkFormatFeatureFlagBits2 feats_primary, feats_secondary;
             int basics_primary = 0, basics_secondary = 0;
+            int storage_primary = 0, storage_secondary = 0;
 
             vk->GetPhysicalDeviceFormatProperties2(hwctx->phys_dev,
                                                    vk_formats_list[i].vkf,
@@ -310,6 +313,7 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
                              prop.formatProperties.linearTilingFeatures :
                              prop.formatProperties.optimalTilingFeatures;
             basics_primary = (feats_primary & basic_flags) == basic_flags;
+            storage_primary = !!(feats_primary & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT);
 
             if (vk_formats_list[i].vkf != vk_formats_list[i].fallback[0]) {
                 vk->GetPhysicalDeviceFormatProperties2(hwctx->phys_dev,
@@ -319,11 +323,15 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
                                   prop.formatProperties.linearTilingFeatures :
                                   prop.formatProperties.optimalTilingFeatures;
                 basics_secondary = (feats_secondary & basic_flags) == basic_flags;
+                storage_secondary = !!(feats_secondary & VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT);
             } else {
                 basics_secondary = basics_primary;
+                storage_secondary = storage_primary;
             }
 
-            if (basics_primary && !(disable_multiplane && vk_formats_list[i].vk_planes > 1)) {
+            if (basics_primary &&
+                !(disable_multiplane && vk_formats_list[i].vk_planes > 1) &&
+                (!need_storage || (need_storage && (storage_primary | storage_secondary)))) {
                 if (fmts)
                     fmts[0] = vk_formats_list[i].vkf;
                 if (nb_images)
@@ -331,9 +339,12 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
                 if (aspect)
                     *aspect = vk_formats_list[i].aspect;
                 if (supported_usage)
-                    *supported_usage = map_feats_to_usage(feats_primary);
+                    *supported_usage = map_feats_to_usage(feats_primary) |
+                                       ((need_storage && (storage_primary | storage_secondary)) ?
+                                        VK_IMAGE_USAGE_STORAGE_BIT : 0);
                 return 0;
-            } else if (basics_secondary) {
+            } else if (basics_secondary &&
+                       (!need_storage || (need_storage && storage_secondary))) {
                 if (fmts) {
                     for (int j = 0; j < vk_formats_list[i].nb_images_fallback; j++)
                         fmts[j] = vk_formats_list[i].fallback[j];
@@ -1640,7 +1651,7 @@ static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx,
         count += vkfmt_from_pixfmt2(ctx, vk_formats_list[i].pixfmt,
                                     p->use_linear_images ? VK_IMAGE_TILING_LINEAR :
                                                            VK_IMAGE_TILING_OPTIMAL,
-                                    NULL, NULL, NULL, NULL, 0) >= 0;
+                                    NULL, NULL, NULL, NULL, 0, 0) >= 0;
     }
 
 #if CONFIG_CUDA
@@ -1658,7 +1669,7 @@ static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx,
         if (vkfmt_from_pixfmt2(ctx, vk_formats_list[i].pixfmt,
                                p->use_linear_images ? VK_IMAGE_TILING_LINEAR :
                                                       VK_IMAGE_TILING_OPTIMAL,
-                               NULL, NULL, NULL, NULL, 0) >= 0) {
+                               NULL, NULL, NULL, NULL, 0, 0) >= 0) {
             constraints->valid_sw_formats[count++] = vk_formats_list[i].pixfmt;
         }
     }
@@ -2294,7 +2305,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
         /* Check if the sw_format itself is supported */
         err = vkfmt_from_pixfmt2(hwfc->device_ctx, hwfc->sw_format,
                                  hwctx->tiling, NULL,
-                                 NULL, NULL, &supported_usage, 0);
+                                 NULL, NULL, &supported_usage, 0,
+                                 hwctx->usage & VK_IMAGE_USAGE_STORAGE_BIT);
         if (err < 0) {
             av_log(hwfc, AV_LOG_ERROR, "Unsupported sw format: %s!\n",
                    av_get_pix_fmt_name(hwfc->sw_format));
@@ -2304,7 +2316,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
         err = vkfmt_from_pixfmt2(hwfc->device_ctx, hwfc->sw_format,
                                  hwctx->tiling, hwctx->format, NULL,
                                  NULL, &supported_usage,
-                                 disable_multiplane);
+                                 disable_multiplane,
+                                 hwctx->usage & VK_IMAGE_USAGE_STORAGE_BIT);
         if (err < 0)
             return err;
     }
@@ -2314,8 +2327,7 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
         hwctx->usage = supported_usage & (VK_BUFFER_USAGE_TRANSFER_DST_BIT |
                                           VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
                                           VK_IMAGE_USAGE_STORAGE_BIT       |
-                                          VK_IMAGE_USAGE_SAMPLED_BIT       |
-                                          VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR);
+                                          VK_IMAGE_USAGE_SAMPLED_BIT);
     }
 
     /* Image creation flags.
-- 
2.42.0


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-05 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-05 21:26 [FFmpeg-devel] [PATCH] hwcontext_vulkan: add the VK_IMAGE_USAGE_SAMPLED_BIT bit to new images Lynne
2023-10-05 21:27 ` Philip Langdale via ffmpeg-devel
2023-10-05 22:03   ` Lynne

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git