From: Lynne via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Lynne <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] Miscellaneous small Vulkan fixes (PR #20761)
Date: Mon, 27 Oct 2025 10:47:09 -0000
Message-ID: <176156202981.81.16361665454271303784@7d278768979e> (raw)
PR #20761 opened by Lynne
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20761
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20761.patch
Support for one new extension, image alignment for subsampled images.
>From 48e0b65d6fb4b7a64f575815b3a1952a3eb94187 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Sat, 18 Oct 2025 05:57:05 +0200
Subject: [PATCH 1/4] hwcontext_vulkan: add support for
VK_EXT_zero_initialize_device_memory
---
libavutil/hwcontext_vulkan.c | 16 ++++++++++++++++
libavutil/vulkan_functions.h | 1 +
libavutil/vulkan_loader.h | 3 +++
3 files changed, 20 insertions(+)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index ae4b07c698..45ca628070 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -82,6 +82,10 @@ typedef struct VulkanDeviceFeatures {
VkPhysicalDeviceShaderSubgroupRotateFeaturesKHR subgroup_rotate;
VkPhysicalDeviceHostImageCopyFeaturesEXT host_image_copy;
+#ifdef VK_EXT_zero_initialize_device_memory
+ VkPhysicalDeviceZeroInitializeDeviceMemoryFeaturesEXT zero_initialize;
+#endif
+
#ifdef VK_KHR_shader_expect_assume
VkPhysicalDeviceShaderExpectAssumeFeaturesKHR expect_assume;
#endif
@@ -225,6 +229,11 @@ static void device_features_init(AVHWDeviceContext *ctx, VulkanDeviceFeatures *f
FF_VK_STRUCT_EXT(s, &feats->device, &feats->host_image_copy, FF_VK_EXT_HOST_IMAGE_COPY,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_IMAGE_COPY_FEATURES_EXT);
+#ifdef VK_EXT_zero_initialize_device_memory
+ FF_VK_STRUCT_EXT(s, &feats->device, &feats->zero_initialize, FF_VK_EXT_ZERO_INITIALIZE,
+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ZERO_INITIALIZE_DEVICE_MEMORY_FEATURES_EXT);
+#endif
+
#ifdef VK_KHR_shader_expect_assume
FF_VK_STRUCT_EXT(s, &feats->device, &feats->expect_assume, FF_VK_EXT_EXPECT_ASSUME,
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_EXPECT_ASSUME_FEATURES_KHR);
@@ -311,6 +320,10 @@ static void device_features_copy_needed(VulkanDeviceFeatures *dst, VulkanDeviceF
COPY_VAL(subgroup_rotate.shaderSubgroupRotate);
COPY_VAL(host_image_copy.hostImageCopy);
+#ifdef VK_EXT_zero_initialize_device_memory
+ COPY_VAL(zero_initialize.zeroInitializeDeviceMemory);
+#endif
+
COPY_VAL(video_maintenance_1.videoMaintenance1);
#ifdef VK_KHR_video_maintenance2
COPY_VAL(video_maintenance_2.videoMaintenance2);
@@ -642,6 +655,9 @@ static const VulkanOptExtension optional_device_exts[] = {
{ VK_KHR_COOPERATIVE_MATRIX_EXTENSION_NAME, FF_VK_EXT_COOP_MATRIX },
{ VK_EXT_SHADER_OBJECT_EXTENSION_NAME, FF_VK_EXT_SHADER_OBJECT },
{ VK_KHR_SHADER_SUBGROUP_ROTATE_EXTENSION_NAME, FF_VK_EXT_SUBGROUP_ROTATE },
+#ifdef VK_EXT_zero_initialize_device_memory
+ { VK_EXT_ZERO_INITIALIZE_DEVICE_MEMORY_EXTENSION_NAME, FF_VK_EXT_ZERO_INITIALIZE },
+#endif
#ifdef VK_KHR_shader_expect_assume
{ VK_KHR_SHADER_EXPECT_ASSUME_EXTENSION_NAME, FF_VK_EXT_EXPECT_ASSUME },
#endif
diff --git a/libavutil/vulkan_functions.h b/libavutil/vulkan_functions.h
index 4d20b7d806..d6a88160f8 100644
--- a/libavutil/vulkan_functions.h
+++ b/libavutil/vulkan_functions.h
@@ -50,6 +50,7 @@ typedef uint64_t FFVulkanExtensions;
#define FF_VK_EXT_EXPECT_ASSUME (1ULL << 16) /* VK_KHR_shader_expect_assume */
#define FF_VK_EXT_SUBGROUP_ROTATE (1ULL << 17) /* VK_KHR_shader_subgroup_rotate */
#define FF_VK_EXT_HOST_IMAGE_COPY (1ULL << 18) /* VK_EXT_host_image_copy */
+#define FF_VK_EXT_ZERO_INITIALIZE (1ULL << 19) /* VK_EXT_zero_initialize_device_memory */
/* Video extensions */
#define FF_VK_EXT_VIDEO_QUEUE (1ULL << 36) /* VK_KHR_video_queue */
diff --git a/libavutil/vulkan_loader.h b/libavutil/vulkan_loader.h
index 3207511663..dc558f9d64 100644
--- a/libavutil/vulkan_loader.h
+++ b/libavutil/vulkan_loader.h
@@ -60,6 +60,9 @@ static inline uint64_t ff_vk_extensions_to_mask(const char * const *extensions,
{ VK_EXT_SHADER_OBJECT_EXTENSION_NAME, FF_VK_EXT_SHADER_OBJECT },
{ VK_KHR_SHADER_SUBGROUP_ROTATE_EXTENSION_NAME, FF_VK_EXT_SUBGROUP_ROTATE },
{ VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME, FF_VK_EXT_HOST_IMAGE_COPY },
+#ifdef VK_EXT_zero_initialize_device_memory
+ { VK_EXT_ZERO_INITIALIZE_DEVICE_MEMORY_EXTENSION_NAME, FF_VK_EXT_ZERO_INITIALIZE },
+#endif
{ VK_KHR_VIDEO_MAINTENANCE_1_EXTENSION_NAME, FF_VK_EXT_VIDEO_MAINTENANCE_1 },
#ifdef VK_KHR_video_maintenance2
{ VK_KHR_VIDEO_MAINTENANCE_2_EXTENSION_NAME, FF_VK_EXT_VIDEO_MAINTENANCE_2 },
--
2.49.1
>From e7566cc5baa86c536904b96b31084c4b1e4a0739 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Thu, 16 Oct 2025 03:11:32 +0200
Subject: [PATCH 2/4] vulkan_decode: align images to the subsampling
Normally, the Vulkan drivers handle this. But Vulkan decided "nah".
This requires API users to crop out odd-numbered images with subsampling.
---
libavcodec/vulkan_decode.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index cbf2ab8194..d22ccc21aa 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -1130,8 +1130,9 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
}
}
- frames_ctx->width = avctx->coded_width;
- frames_ctx->height = avctx->coded_height;
+ const AVPixFmtDescriptor *pdesc = av_pix_fmt_desc_get(frames_ctx->sw_format);
+ frames_ctx->width = FFALIGN(avctx->coded_width, 1 << pdesc->log2_chroma_w);
+ frames_ctx->height = FFALIGN(avctx->coded_height, 1 << pdesc->log2_chroma_h);
frames_ctx->format = AV_PIX_FMT_VULKAN;
hwfc->format[0] = vkfmt;
@@ -1338,8 +1339,8 @@ int ff_vk_decode_init(AVCodecContext *avctx)
dpb_frames = (AVHWFramesContext *)ctx->common.dpb_hwfc_ref->data;
dpb_frames->format = s->frames->format;
dpb_frames->sw_format = s->frames->sw_format;
- dpb_frames->width = avctx->coded_width;
- dpb_frames->height = avctx->coded_height;
+ dpb_frames->width = s->frames->width;
+ dpb_frames->height = s->frames->height;
dpb_hwfc = dpb_frames->hwctx;
dpb_hwfc->create_pnext = (void *)ff_vk_find_struct(ctx->s.hwfc->create_pnext,
--
2.49.1
>From f71c2bcc4bc9032e85f2c0e8c933e4eb3c7f235f Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Fri, 17 Oct 2025 14:12:11 +0200
Subject: [PATCH 3/4] vulkan/rangecoder: ifdef out encode and decode chunks
There's little code sharing between them.
---
libavcodec/vulkan/rangecoder.comp | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/libavcodec/vulkan/rangecoder.comp b/libavcodec/vulkan/rangecoder.comp
index b6b6c0490f..98ff743b2e 100644
--- a/libavcodec/vulkan/rangecoder.comp
+++ b/libavcodec/vulkan/rangecoder.comp
@@ -31,6 +31,19 @@ struct RangeCoder {
uint8_t outstanding_byte;
};
+void rac_init(out RangeCoder r, u8buf data, uint buf_size)
+{
+ r.bytestream_start = uint64_t(data);
+ r.bytestream = uint64_t(data);
+ r.bytestream_end = uint64_t(data) + buf_size;
+ r.low = 0;
+ r.range = 0xFF00;
+ r.outstanding_count = uint16_t(0);
+ r.outstanding_byte = uint8_t(0xFF);
+}
+
+#if !defined(DECODE)
+
#ifdef FULL_RENORM
/* Full renorm version that can handle outstanding_byte == 0xFF */
void renorm_encoder(inout RangeCoder c)
@@ -165,16 +178,7 @@ uint32_t rac_terminate(inout RangeCoder c)
return uint32_t(uint64_t(c.bytestream) - uint64_t(c.bytestream_start));
}
-void rac_init(out RangeCoder r, u8buf data, uint buf_size)
-{
- r.bytestream_start = uint64_t(data);
- r.bytestream = uint64_t(data);
- r.bytestream_end = uint64_t(data) + buf_size;
- r.low = 0;
- r.range = 0xFF00;
- r.outstanding_count = uint16_t(0);
- r.outstanding_byte = uint8_t(0xFF);
-}
+#else
/* Decoder */
uint overread = 0;
@@ -239,3 +243,5 @@ bool get_rac_equi(inout RangeCoder c)
{
return get_rac_internal(c, c.range >> 1);
}
+
+#endif
--
2.49.1
>From 8787bd1a49997e6e8cb9fa1adc41b9068c9e7edd Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Sun, 26 Oct 2025 22:46:35 +0100
Subject: [PATCH 4/4] lavc/hwaccels: properly order list
---
libavcodec/hwaccels.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 0894d84a9c..638a7bfb1d 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -67,8 +67,8 @@ extern const struct FFHWAccel ff_mpeg4_vaapi_hwaccel;
extern const struct FFHWAccel ff_mpeg4_vdpau_hwaccel;
extern const struct FFHWAccel ff_mpeg4_videotoolbox_hwaccel;
extern const struct FFHWAccel ff_prores_videotoolbox_hwaccel;
-extern const struct FFHWAccel ff_prores_raw_vulkan_hwaccel;
extern const struct FFHWAccel ff_prores_vulkan_hwaccel;
+extern const struct FFHWAccel ff_prores_raw_vulkan_hwaccel;
extern const struct FFHWAccel ff_vc1_d3d11va_hwaccel;
extern const struct FFHWAccel ff_vc1_d3d11va2_hwaccel;
extern const struct FFHWAccel ff_vc1_d3d12va_hwaccel;
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
reply other threads:[~2025-10-27 10:47 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=176156202981.81.16361665454271303784@7d278768979e \
--to=ffmpeg-devel@ffmpeg.org \
--cc=code@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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