ffmpeg-cvslog
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
November 2025
- 1 participants
- 206 discussions
[ffmpeg] branch master updated. f7aaa8ecb5 forgejo/workflows: make test shared/static mode more human readable
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via f7aaa8ecb51a5b7d54e6cfb61c15009939a40820 (commit)
from 231f735d55b6954f75a4bd24a166ff7a9baa5429 (commit)
- Log -----------------------------------------------------------------
commit f7aaa8ecb51a5b7d54e6cfb61c15009939a40820
Author: Timo Rothenpieler <timo(a)rothenpieler.org>
AuthorDate: Tue Nov 25 14:14:47 2025 +0100
Commit: Timo Rothenpieler <timo(a)rothenpieler.org>
CommitDate: Wed Nov 26 23:21:11 2025 +0000
forgejo/workflows: make test shared/static mode more human readable
diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml
index 1b2aaaa3b4..799d2c356a 100644
--- a/.forgejo/workflows/test.yml
+++ b/.forgejo/workflows/test.yml
@@ -10,14 +10,14 @@ jobs:
fail-fast: false
matrix:
runner: [linux-aarch64]
- shared: ['false']
+ shared: ['static']
bits: ['64']
include:
- runner: linux-amd64
- shared: 'false'
+ shared: 'static'
bits: '32'
- runner: linux-amd64
- shared: 'true'
+ shared: 'shared'
bits: '64'
runs-on: ${{ matrix.runner }}
steps:
@@ -27,7 +27,7 @@ jobs:
run: |
./configure --enable-gpl --enable-nonfree --enable-memory-poisoning --assert-level=2 \
$([ "${{ matrix.bits }}" != "32" ] || echo --arch=x86_32 --extra-cflags=-m32 --extra-cxxflags=-m32 --extra-ldflags=-m32) \
- $([ "${{ matrix.shared }}" != "true" ] || echo --enable-shared --disable-static) \
+ $([ "${{ matrix.shared }}" != "shared" ] || echo --enable-shared --disable-static) \
|| CFGRES=$? && CFGRES=$?
cat ffbuild/config.log
exit $CFGRES
-----------------------------------------------------------------------
Summary of changes:
.forgejo/workflows/test.yml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
hooks/post-receive
--
1
0
[ffmpeg] branch master updated. 231f735d55 vulkan_dpx: use host visible allocation for host image copy buffer
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via 231f735d55b6954f75a4bd24a166ff7a9baa5429 (commit)
via 162e07da6188ec999f4ce8e7c86fa81d588c8773 (commit)
from faa382e5b196f2acb5bc5b159aaf06682291328b (commit)
- Log -----------------------------------------------------------------
commit 231f735d55b6954f75a4bd24a166ff7a9baa5429
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 18:33:10 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 18:33:10 2025 +0100
vulkan_dpx: use host visible allocation for host image copy buffer
Fixes black screen on Nvidia.
diff --git a/libavcodec/vulkan_dpx.c b/libavcodec/vulkan_dpx.c
index 465ed17194..8978b78db4 100644
--- a/libavcodec/vulkan_dpx.c
+++ b/libavcodec/vulkan_dpx.c
@@ -102,7 +102,8 @@ static int host_upload_image(AVCodecContext *avctx,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
NULL, size,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
if (err < 0)
return err;
commit 162e07da6188ec999f4ce8e7c86fa81d588c8773
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 18:32:25 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 18:32:25 2025 +0100
vulkan_dpx: fix "upoad" typo
diff --git a/libavcodec/vulkan_dpx.c b/libavcodec/vulkan_dpx.c
index 1af417fdf7..465ed17194 100644
--- a/libavcodec/vulkan_dpx.c
+++ b/libavcodec/vulkan_dpx.c
@@ -50,9 +50,9 @@ typedef struct DecodePushData {
int padded_10bit;
} DecodePushData;
-static int host_upoad_image(AVCodecContext *avctx,
- FFVulkanDecodeContext *dec, DPXDecContext *dpx,
- const uint8_t *src, uint32_t size)
+static int host_upload_image(AVCodecContext *avctx,
+ FFVulkanDecodeContext *dec, DPXDecContext *dpx,
+ const uint8_t *src, uint32_t size)
{
int err;
VkImage temp;
@@ -163,7 +163,7 @@ static int vk_dpx_start_frame(AVCodecContext *avctx,
FFVulkanDecodePicture *vp = &pp->vp;
if (ctx->s.extensions & FF_VK_EXT_HOST_IMAGE_COPY)
- host_upoad_image(avctx, dec, dpx, buffer, size);
+ host_upload_image(avctx, dec, dpx, buffer, size);
/* Host map the frame data if supported */
if (!vp->slices_buf &&
-----------------------------------------------------------------------
Summary of changes:
libavcodec/vulkan_dpx.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
hooks/post-receive
--
1
0
[ffmpeg] branch master updated. faa382e5b1 avformat/iamf_parse: ensure the stream count in a scalable channel representation is equal to the audio element's stream count
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via faa382e5b196f2acb5bc5b159aaf06682291328b (commit)
via 554ae5ada98cd44686ade995102d3aa2295d7b09 (commit)
from 3bcf2be06c8cfe6834b287327c2d3bb891c7440d (commit)
- Log -----------------------------------------------------------------
commit faa382e5b196f2acb5bc5b159aaf06682291328b
Author: James Almer <jamrial(a)gmail.com>
AuthorDate: Tue Nov 25 12:42:30 2025 -0300
Commit: James Almer <jamrial(a)gmail.com>
CommitDate: Wed Nov 26 12:01:17 2025 -0300
avformat/iamf_parse: ensure the stream count in a scalable channel representation is equal to the audio element's stream count
Signed-off-by: James Almer <jamrial(a)gmail.com>
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 737e3f7404..597d800be0 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -480,6 +480,9 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
av_channel_layout_copy(&layer->ch_layout, &ch_layout);
}
+ if (k != audio_element->nb_substreams)
+ return AVERROR_INVALIDDATA;
+
return 0;
}
commit 554ae5ada98cd44686ade995102d3aa2295d7b09
Author: James Almer <jamrial(a)gmail.com>
AuthorDate: Tue Nov 25 10:26:27 2025 -0300
Commit: James Almer <jamrial(a)gmail.com>
CommitDate: Wed Nov 26 12:01:17 2025 -0300
avformat/iamf_parse: ensure each layout in an scalable channel representation has an increasing number of channels
Fixes issue #21013
Signed-off-by: James Almer <jamrial(a)gmail.com>
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 50acd7cf5a..737e3f7404 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -406,6 +406,9 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
.nb_channels = substream_count +
coupled_substream_count };
+ if (i && ch_layout.nb_channels <= audio_element->element->layers[i-1]->ch_layout.nb_channels)
+ return AVERROR_INVALIDDATA;
+
for (int j = 0; j < substream_count; j++) {
IAMFSubStream *substream = &audio_element->substreams[k++];
-----------------------------------------------------------------------
Summary of changes:
libavformat/iamf_parse.c | 6 ++++++
1 file changed, 6 insertions(+)
hooks/post-receive
--
1
0
[ffmpeg] branch master updated. 3bcf2be06c Changelog: bump lavc minor and add entry for the DPX Vulkan hwaccel
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via 3bcf2be06c8cfe6834b287327c2d3bb891c7440d (commit)
via 531ce713a0e848069d18311e38977b5bf8b9499d (commit)
via a9acae202a064d6c745f6d826b008cd31d0bd9d0 (commit)
via 61ae1ec85fc5d1442e5010c0cf92dfa62c45d912 (commit)
via bc07d03d069e263f8bf754f3b7c377cc9e859a00 (commit)
via 7af5b5cec33832f12515df0e5fe45a2aad437ca2 (commit)
via a811a6885a342abf3fb5bd61753e5d4ebd17114d (commit)
via 0db891366d8e501356ac3caee776af448ad50e68 (commit)
via edb844510ee72a03a87fef3671b5152cdacfef92 (commit)
via bb30a0d0d8b14147649ac945b76a2fc05f916d67 (commit)
via 0c20edaa7ac63b56bb29ba8bfa5f6b4cb22aa418 (commit)
via a160e4a9e204578e05c552a85a8502151f0a657c (commit)
via 3934089de2c3bc4d2f6f37a0f4949c4fea864d5d (commit)
via 8c0314d44afc1062c61c5a21d215175bdef6c5f7 (commit)
via 56dea1a9e80f23a81a06ec75ca7528fce1ee1f1b (commit)
via a1154b74a4a3635e4106aba9b1c4c0efdd35e07c (commit)
via be9998674aeea8fc4110918a7e15e6d7f7f37357 (commit)
via 615b26f1b1ac4000667b4ad58db1ee112bc811f5 (commit)
via 3ddcf042b2cc469f4321daf170d1ecab194e5802 (commit)
via 23cfcf93d22cffbaf683df43152740bbbc893bcd (commit)
via d36d88dcbb131aeb0af3465fe8d9d1fe9959f593 (commit)
via 6c3984db7fdcfc9d97e7db3d419a601eb1440fad (commit)
via d288d4a24ee9eac79201cfd1e5c7d80c8f1bb9a7 (commit)
via 5c89528342b72cef57019aa01b9ef0f8fa401cc3 (commit)
via 686951849b2a1a4f2683478c59042edb94ab527b (commit)
via fc2dd6c75157a040bd1d057b865a18ede32228a8 (commit)
via 58d26c2055180ebf8013308d6011f563f7529c1e (commit)
from 38a5fcc02c2ef1bcb37d2e53eddde8eccc0c75ed (commit)
- Log -----------------------------------------------------------------
commit 3bcf2be06c8cfe6834b287327c2d3bb891c7440d
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Tue Nov 25 17:04:06 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:43 2025 +0100
Changelog: bump lavc minor and add entry for the DPX Vulkan hwaccel
diff --git a/Changelog b/Changelog
index 3757eac2e4..e4f7e123d4 100644
--- a/Changelog
+++ b/Changelog
@@ -12,6 +12,7 @@ version <next>:
- ffmpeg CLI tiled HEIF support
- D3D12 AV1 encoder
- ProRes Vulkan hwaccel
+- DPX Vulkan hwaccel
version 8.0:
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 4b7ec515fe..d0980e28de 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 19
+#define LIBAVCODEC_VERSION_MINOR 20
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
commit 531ce713a0e848069d18311e38977b5bf8b9499d
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Oct 29 15:27:47 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:43 2025 +0100
dpxdec: add a Vulkan hwaccel
diff --git a/configure b/configure
index 7ef50095a3..fd6f602e1d 100755
--- a/configure
+++ b/configure
@@ -3262,6 +3262,8 @@ av1_videotoolbox_hwaccel_deps="videotoolbox"
av1_videotoolbox_hwaccel_select="av1_decoder"
av1_vulkan_hwaccel_deps="vulkan"
av1_vulkan_hwaccel_select="av1_decoder"
+dpx_vulkan_hwaccel_deps="vulkan spirv_compiler"
+dpx_vulkan_hwaccel_select="dpx_decoder"
ffv1_vulkan_hwaccel_deps="vulkan spirv_compiler"
ffv1_vulkan_hwaccel_select="ffv1_decoder"
h263_vaapi_hwaccel_deps="vaapi"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fba9f0aff0..45c8237181 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1050,6 +1050,7 @@ OBJS-$(CONFIG_AV1_VAAPI_HWACCEL) += vaapi_av1.o
OBJS-$(CONFIG_AV1_VDPAU_HWACCEL) += vdpau_av1.o
OBJS-$(CONFIG_AV1_VIDEOTOOLBOX_HWACCEL) += videotoolbox_av1.o
OBJS-$(CONFIG_AV1_VULKAN_HWACCEL) += vulkan_decode.o vulkan_av1.o
+OBJS-$(CONFIG_DPX_VULKAN_HWACCEL) += vulkan_decode.o vulkan_dpx.o
OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL) += vulkan_decode.o ffv1_vulkan.o vulkan_ffv1.o
OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o
OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL) += videotoolbox.o
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 47efcb7572..7355b50f7a 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -837,7 +837,12 @@ const FFCodec ff_dpx_decoder = {
.close = decode_end,
UPDATE_THREAD_CONTEXT(update_thread_context),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.hw_configs = (const AVCodecHWConfigInternal *const []) {
+#if CONFIG_DPX_VULKAN_HWACCEL
+ HWACCEL_VULKAN(dpx),
+#endif
NULL
},
};
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 638a7bfb1d..3de191288a 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -28,6 +28,7 @@ extern const struct FFHWAccel ff_av1_vaapi_hwaccel;
extern const struct FFHWAccel ff_av1_vdpau_hwaccel;
extern const struct FFHWAccel ff_av1_videotoolbox_hwaccel;
extern const struct FFHWAccel ff_av1_vulkan_hwaccel;
+extern const struct FFHWAccel ff_dpx_vulkan_hwaccel;
extern const struct FFHWAccel ff_ffv1_vulkan_hwaccel;
extern const struct FFHWAccel ff_h263_vaapi_hwaccel;
extern const struct FFHWAccel ff_h263_videotoolbox_hwaccel;
diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile
index 16a4116ef1..26e8e147c2 100644
--- a/libavcodec/vulkan/Makefile
+++ b/libavcodec/vulkan/Makefile
@@ -23,6 +23,10 @@ OBJS-$(CONFIG_PRORES_VULKAN_HWACCEL) += vulkan/common.o \
vulkan/prores_vld.o \
vulkan/prores_idct.o
+OBJS-$(CONFIG_DPX_VULKAN_HWACCEL) += vulkan/common.o \
+ vulkan/dpx_unpack.o \
+ vulkan/dpx_copy.o
+
VULKAN = $(subst $(SRC_PATH)/,,$(wildcard $(SRC_PATH)/libavcodec/vulkan/*.comp))
.SECONDARY: $(VULKAN:.comp=.c)
libavcodec/vulkan/%.c: TAG = VULKAN
diff --git a/libavcodec/vulkan/dpx_copy.comp b/libavcodec/vulkan/dpx_copy.comp
new file mode 100644
index 0000000000..da0a11db93
--- /dev/null
+++ b/libavcodec/vulkan/dpx_copy.comp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+TYPE read_data(uint off)
+{
+#ifdef BIG_ENDIAN
+ return TYPE_REVERSE(data[off]);
+#else
+ return data[off];
+#endif
+}
+
+void main(void)
+{
+ ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
+ if (!IS_WITHIN(pos, imageSize(dst[0])))
+ return;
+
+ uint offs = (pos.y*imageSize(dst[0]).x + pos.x)*COMPONENTS;
+#if NB_IMAGES == 1
+ TYPE_VEC val;
+ for (int i = 0; i < COMPONENTS; i++)
+ val[i] = read_data(offs + i);
+ val >>= SHIFT;
+ imageStore(dst[0], pos, val);
+#else
+ const ivec4 fmt_lut = ivec4(2, 0, 1, 3);
+ for (int i = 0; i < COMPONENTS; i++) {
+ TYPE val = read_data(offs + i);
+ val >>= SHIFT;
+ imageStore(dst[fmt_lut[i]], pos, TYPE_VEC(val));
+ }
+#endif
+}
diff --git a/libavcodec/vulkan/dpx_unpack.comp b/libavcodec/vulkan/dpx_unpack.comp
new file mode 100644
index 0000000000..5a44de87bf
--- /dev/null
+++ b/libavcodec/vulkan/dpx_unpack.comp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+uint32_t read_data(uint off)
+{
+#ifdef BIG_ENDIAN
+ return reverse4(data[off]);
+#else
+ return data[off];
+#endif
+}
+
+#ifdef PACKED_10BIT
+i16vec4 parse_packed_in_32(ivec2 pos, int stride)
+{
+ uint32_t d = read_data(pos.y*stride + pos.x);
+ i16vec4 v;
+ d = d << 10 | d >> 22 & 0x3FFFFF;
+ v[0] = int16_t(d & 0x3FF);
+ d = d << 10 | d >> 22 & 0x3FFFFF;
+ v[1] = int16_t(d & 0x3FF);
+ d = d << 10 | d >> 22 & 0x3FFFFF;
+ v[2] = int16_t(d & 0x3FF);
+ v[3] = int16_t(0);
+ return v;
+}
+#else
+i16vec4 parse_packed_in_32(ivec2 pos, int stride)
+{
+ uint line_off = pos.y*(stride*BITS_PER_COMP*COMPONENTS +
+ (need_align << 3));
+ uint pix_off = pos.x*BITS_PER_COMP*COMPONENTS;
+
+ uint off = (line_off + pix_off >> 5);
+ uint bit = pix_off & 0x1f;
+
+ uint32_t d0 = read_data(off + 0);
+ uint32_t d1 = read_data(off + 1);
+
+ uint64_t combined = (uint64_t(d1) << 32) | d0;
+ combined >>= bit;
+
+ return i16vec4(combined,
+ combined >> (BITS_PER_COMP*1),
+ combined >> (BITS_PER_COMP*2),
+ combined >> (BITS_PER_COMP*3)) &
+ int16_t((1 << BITS_PER_COMP) - 1);
+}
+#endif
+
+void main(void)
+{
+ ivec2 pos = ivec2(gl_GlobalInvocationID.xy);
+ if (!IS_WITHIN(pos, imageSize(dst[0])))
+ return;
+
+ i16vec4 p = parse_packed_in_32(pos, imageSize(dst[0]).x);
+
+#if NB_IMAGES == 1
+ imageStore(dst[0], pos, p);
+#else
+ const ivec4 fmt_lut = COMPONENTS == 1 ? ivec4(0) : ivec4(2, 0, 1, 3);
+ for (uint i = 0; i < COMPONENTS; i++)
+ imageStore(dst[fmt_lut[i]], pos, i16vec4(p[i]));
+#endif
+}
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index d22ccc21aa..d6f6ec8c3b 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -26,6 +26,7 @@
#define DECODER_IS_SDR(codec_id) \
(((codec_id) == AV_CODEC_ID_FFV1) || \
+ ((codec_id) == AV_CODEC_ID_DPX) || \
((codec_id) == AV_CODEC_ID_PRORES_RAW) || \
((codec_id) == AV_CODEC_ID_PRORES))
@@ -50,6 +51,9 @@ extern const FFVulkanDecodeDescriptor ff_vk_dec_prores_raw_desc;
#if CONFIG_PRORES_VULKAN_HWACCEL
extern const FFVulkanDecodeDescriptor ff_vk_dec_prores_desc;
#endif
+#if CONFIG_DPX_VULKAN_HWACCEL
+extern const FFVulkanDecodeDescriptor ff_vk_dec_dpx_desc;
+#endif
static const FFVulkanDecodeDescriptor *dec_descs[] = {
#if CONFIG_H264_VULKAN_HWACCEL
@@ -73,6 +77,9 @@ static const FFVulkanDecodeDescriptor *dec_descs[] = {
#if CONFIG_PRORES_VULKAN_HWACCEL
&ff_vk_dec_prores_desc,
#endif
+#if CONFIG_DPX_VULKAN_HWACCEL
+ &ff_vk_dec_dpx_desc,
+#endif
};
typedef struct FFVulkanDecodeProfileData {
@@ -1117,10 +1124,19 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
/* This should be more efficient for downloading and using */
frames_ctx->sw_format = AV_PIX_FMT_RGBA64;
break;
+ case AV_PIX_FMT_RGB48LE:
+ case AV_PIX_FMT_RGB48BE: /* DPX outputs RGB48BE, so we need both */
+ /* Almost nothing supports native 3-component RGB */
+ frames_ctx->sw_format = AV_PIX_FMT_GBRP16;
+ break;
+ case AV_PIX_FMT_RGBA64BE: /* DPX again, fix for little-endian systems */
+ frames_ctx->sw_format = AV_PIX_FMT_RGBA64;
+ break;
case AV_PIX_FMT_GBRP10:
/* This saves memory bandwidth when downloading */
frames_ctx->sw_format = AV_PIX_FMT_X2BGR10;
break;
+ case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_BGR0:
/* mpv has issues with bgr0 mapping, so just remap it */
frames_ctx->sw_format = AV_PIX_FMT_RGB0;
diff --git a/libavcodec/vulkan_dpx.c b/libavcodec/vulkan_dpx.c
new file mode 100644
index 0000000000..1af417fdf7
--- /dev/null
+++ b/libavcodec/vulkan_dpx.c
@@ -0,0 +1,475 @@
+/*
+ * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "vulkan_decode.h"
+#include "hwaccel_internal.h"
+
+#include "dpx.h"
+#include "libavutil/vulkan_spirv.h"
+#include "libavutil/mem.h"
+
+extern const char *ff_source_common_comp;
+extern const char *ff_source_dpx_unpack_comp;
+extern const char *ff_source_dpx_copy_comp;
+
+const FFVulkanDecodeDescriptor ff_vk_dec_dpx_desc = {
+ .codec_id = AV_CODEC_ID_DPX,
+ .decode_extension = FF_VK_EXT_PUSH_DESCRIPTOR,
+ .queue_flags = VK_QUEUE_COMPUTE_BIT,
+};
+
+typedef struct DPXVulkanDecodePicture {
+ FFVulkanDecodePicture vp;
+} DPXVulkanDecodePicture;
+
+typedef struct DPXVulkanDecodeContext {
+ FFVulkanShader shader;
+ AVBufferPool *frame_data_pool;
+} DPXVulkanDecodeContext;
+
+typedef struct DecodePushData {
+ int stride;
+ int need_align;
+ int padded_10bit;
+} DecodePushData;
+
+static int host_upoad_image(AVCodecContext *avctx,
+ FFVulkanDecodeContext *dec, DPXDecContext *dpx,
+ const uint8_t *src, uint32_t size)
+{
+ int err;
+ VkImage temp;
+
+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
+ DPXVulkanDecodeContext *dxv = ctx->sd_ctx;
+ VkPhysicalDeviceLimits *limits = &ctx->s.props.properties.limits;
+ FFVulkanFunctions *vk = &ctx->s.vkfn;
+
+ DPXVulkanDecodePicture *pp = dpx->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &pp->vp;
+
+ int unpack = (avctx->bits_per_raw_sample == 12 && !dpx->packing) ||
+ avctx->bits_per_raw_sample == 10;
+ if (unpack)
+ return 0;
+
+ VkImageCreateInfo create_info = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = avctx->bits_per_raw_sample == 8 ? VK_FORMAT_R8_UINT :
+ avctx->bits_per_raw_sample == 32 ? VK_FORMAT_R32_UINT :
+ VK_FORMAT_R16_UINT,
+ .extent.width = dpx->frame->width*dpx->components,
+ .extent.height = dpx->frame->height,
+ .extent.depth = 1,
+ .mipLevels = 1,
+ .arrayLayers = 1,
+ .tiling = VK_IMAGE_TILING_LINEAR,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .usage = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .pQueueFamilyIndices = &ctx->qf[0].idx,
+ .queueFamilyIndexCount = 1,
+ .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+ };
+
+ if (create_info.extent.width >= limits->maxImageDimension2D ||
+ create_info.extent.height >= limits->maxImageDimension2D)
+ return 0;
+
+ vk->CreateImage(ctx->s.hwctx->act_dev, &create_info, ctx->s.hwctx->alloc,
+ &temp);
+
+ err = ff_vk_get_pooled_buffer(&ctx->s, &dxv->frame_data_pool,
+ &vp->slices_buf,
+ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
+ VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
+ NULL, size,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
+ if (err < 0)
+ return err;
+
+ FFVkBuffer *vkb = (FFVkBuffer *)vp->slices_buf->data;
+ VkBindImageMemoryInfo bind_info = {
+ .sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
+ .image = temp,
+ .memory = vkb->mem,
+ };
+ vk->BindImageMemory2(ctx->s.hwctx->act_dev, 1, &bind_info);
+
+ VkHostImageLayoutTransitionInfo layout_change = {
+ .sType = VK_STRUCTURE_TYPE_HOST_IMAGE_LAYOUT_TRANSITION_INFO,
+ .image = temp,
+ .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .newLayout = VK_IMAGE_LAYOUT_GENERAL,
+ .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .subresourceRange.layerCount = 1,
+ .subresourceRange.levelCount = 1,
+ };
+ vk->TransitionImageLayoutEXT(ctx->s.hwctx->act_dev, 1, &layout_change);
+
+ VkMemoryToImageCopy copy_region = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_TO_IMAGE_COPY,
+ .pHostPointer = src,
+ .imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .imageSubresource.layerCount = 1,
+ .imageExtent = (VkExtent3D){ dpx->frame->width*dpx->components,
+ dpx->frame->height,
+ 1 },
+ };
+ VkCopyMemoryToImageInfo copy_info = {
+ .sType = VK_STRUCTURE_TYPE_COPY_MEMORY_TO_IMAGE_INFO,
+ .flags = VK_HOST_IMAGE_COPY_MEMCPY_BIT_EXT,
+ .dstImage = temp,
+ .dstImageLayout = VK_IMAGE_LAYOUT_GENERAL,
+ .regionCount = 1,
+ .pRegions = ©_region,
+ };
+ vk->CopyMemoryToImageEXT(ctx->s.hwctx->act_dev, ©_info);
+
+ vk->DestroyImage(ctx->s.hwctx->act_dev, temp, ctx->s.hwctx->alloc);
+
+ return 0;
+}
+
+static int vk_dpx_start_frame(AVCodecContext *avctx,
+ const AVBufferRef *buffer_ref,
+ av_unused const uint8_t *buffer,
+ av_unused uint32_t size)
+{
+ int err;
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
+ DPXDecContext *dpx = avctx->priv_data;
+
+ DPXVulkanDecodePicture *pp = dpx->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &pp->vp;
+
+ if (ctx->s.extensions & FF_VK_EXT_HOST_IMAGE_COPY)
+ host_upoad_image(avctx, dec, dpx, buffer, size);
+
+ /* Host map the frame data if supported */
+ if (!vp->slices_buf &&
+ ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
+ ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, (uint8_t *)buffer,
+ buffer_ref,
+ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
+ VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
+
+ /* Prepare frame to be used */
+ err = ff_vk_decode_prepare_frame_sdr(dec, dpx->frame, vp, 1,
+ FF_VK_REP_NATIVE, 0);
+ if (err < 0)
+ return err;
+
+ return 0;
+}
+
+static int vk_dpx_decode_slice(AVCodecContext *avctx,
+ const uint8_t *data,
+ uint32_t size)
+{
+ DPXDecContext *dpx = avctx->priv_data;
+
+ DPXVulkanDecodePicture *pp = dpx->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &pp->vp;
+
+ if (!vp->slices_buf) {
+ int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
+ NULL, NULL);
+ if (err < 0)
+ return err;
+ }
+
+ return 0;
+}
+
+static int vk_dpx_end_frame(AVCodecContext *avctx)
+{
+ int err;
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
+ FFVulkanFunctions *vk = &ctx->s.vkfn;
+
+ DPXDecContext *dpx = avctx->priv_data;
+ DPXVulkanDecodeContext *dxv = ctx->sd_ctx;
+
+ DPXVulkanDecodePicture *pp = dpx->hwaccel_picture_private;
+ FFVulkanDecodePicture *vp = &pp->vp;
+
+ FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
+
+ VkImageMemoryBarrier2 img_bar[8];
+ int nb_img_bar = 0;
+
+ FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
+ ff_vk_exec_start(&ctx->s, exec);
+
+ /* Prepare deps */
+ RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, dpx->frame,
+ VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
+ VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
+
+ err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
+ dpx->frame);
+ if (err < 0)
+ return err;
+
+ RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
+ vp->slices_buf = NULL;
+
+ AVVkFrame *vkf = (AVVkFrame *)dpx->frame->data[0];
+ for (int i = 0; i < 4; i++) {
+ vkf->layout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
+ vkf->access[i] = VK_ACCESS_2_NONE;
+ }
+
+ ff_vk_frame_barrier(&ctx->s, exec, dpx->frame, img_bar, &nb_img_bar,
+ VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
+ VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
+ VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
+ VK_IMAGE_LAYOUT_GENERAL,
+ VK_QUEUE_FAMILY_IGNORED);
+
+ vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
+ .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
+ .pImageMemoryBarriers = img_bar,
+ .imageMemoryBarrierCount = nb_img_bar,
+ });
+ nb_img_bar = 0;
+
+ FFVulkanShader *shd = &dxv->shader;
+ ff_vk_shader_update_img_array(&ctx->s, exec, shd,
+ dpx->frame, vp->view.out,
+ 0, 0,
+ VK_IMAGE_LAYOUT_GENERAL,
+ VK_NULL_HANDLE);
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, shd,
+ 0, 1, 0,
+ slices_buf,
+ 0, slices_buf->size,
+ VK_FORMAT_UNDEFINED);
+
+ ff_vk_exec_bind_shader(&ctx->s, exec, shd);
+
+ /* Update push data */
+ DecodePushData pd = (DecodePushData) {
+ .stride = dpx->stride,
+ .need_align = dpx->need_align,
+ .padded_10bit = !dpx->unpadded_10bit,
+ };
+
+ ff_vk_shader_update_push_const(&ctx->s, exec, shd,
+ VK_SHADER_STAGE_COMPUTE_BIT,
+ 0, sizeof(pd), &pd);
+
+ vk->CmdDispatch(exec->buf,
+ FFALIGN(dpx->frame->width, shd->lg_size[0])/shd->lg_size[0],
+ FFALIGN(dpx->frame->height, shd->lg_size[1])/shd->lg_size[1],
+ 1);
+
+ err = ff_vk_exec_submit(&ctx->s, exec);
+ if (err < 0)
+ return err;
+
+fail:
+ return 0;
+}
+
+static int init_shader(AVCodecContext *avctx, FFVulkanContext *s,
+ FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
+ FFVulkanShader *shd, int bits)
+{
+ int err;
+ DPXDecContext *dpx = avctx->priv_data;
+ FFVulkanDescriptorSetBinding *desc_set;
+ AVHWFramesContext *dec_frames_ctx;
+ dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
+ int planes = av_pix_fmt_count_planes(dec_frames_ctx->sw_format);
+
+ uint8_t *spv_data;
+ size_t spv_len;
+ void *spv_opaque = NULL;
+
+ RET(ff_vk_shader_init(s, shd, "dpx",
+ VK_SHADER_STAGE_COMPUTE_BIT,
+ (const char *[]) { "GL_EXT_buffer_reference",
+ "GL_EXT_buffer_reference2" }, 2,
+ 512, 1, 1,
+ 0));
+
+ /* Common codec header */
+ GLSLD(ff_source_common_comp);
+
+ GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
+ GLSLC(1, int stride; );
+ GLSLC(1, int need_align; );
+ GLSLC(1, int padded_10bit; );
+ GLSLC(0, }; );
+ GLSLC(0, );
+ ff_vk_shader_add_push_const(shd, 0, sizeof(DecodePushData),
+ VK_SHADER_STAGE_COMPUTE_BIT);
+
+ int unpack = (avctx->bits_per_raw_sample == 12 && !dpx->packing) ||
+ avctx->bits_per_raw_sample == 10;
+
+ desc_set = (FFVulkanDescriptorSetBinding []) {
+ {
+ .name = "dst",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+ .dimensions = 2,
+ .mem_quali = "writeonly",
+ .mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
+ FF_VK_REP_NATIVE),
+ .elems = planes,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ },
+ {
+ .name = "data_buf",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ .mem_quali = "readonly",
+ .buf_content = (unpack || bits == 32) ? "uint32_t data[];" :
+ bits == 8 ? "uint8_t data[];" : "uint16_t data[];",
+ },
+ };
+ RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0));
+
+ if (dpx->endian)
+ GLSLC(0, #define BIG_ENDIAN );
+ GLSLF(0, #define COMPONENTS (%i) ,dpx->components);
+ GLSLF(0, #define BITS_PER_COMP (%i) ,bits);
+ GLSLF(0, #define NB_IMAGES (%i) ,planes);
+ if (unpack) {
+ if (bits == 10)
+ GLSLC(0, #define PACKED_10BIT );
+ GLSLD(ff_source_dpx_unpack_comp);
+ } else {
+ GLSLF(0, #define SHIFT (%i) ,FFALIGN(bits, 8) - bits);
+ GLSLF(0, #define TYPE uint%i_t ,FFALIGN(bits, 8));
+ GLSLF(0, #define TYPE_VEC u%ivec4 ,FFALIGN(bits, 8));
+ GLSLF(0, #define TYPE_REVERSE(x) (reverse%i(x)), FFALIGN(bits, 8)/8);
+ GLSLD(ff_source_dpx_copy_comp);
+ }
+
+ RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
+ &spv_opaque));
+ RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
+
+ RET(ff_vk_shader_register_exec(s, pool, shd));
+
+fail:
+ if (spv_opaque)
+ spv->free_shader(spv, &spv_opaque);
+
+ return err;
+}
+
+static void vk_decode_dpx_uninit(FFVulkanDecodeShared *ctx)
+{
+ DPXVulkanDecodeContext *fv = ctx->sd_ctx;
+
+ ff_vk_shader_free(&ctx->s, &fv->shader);
+
+ av_buffer_pool_uninit(&fv->frame_data_pool);
+
+ av_freep(&fv);
+}
+
+static int vk_decode_dpx_init(AVCodecContext *avctx)
+{
+ int err;
+ DPXDecContext *dpx = avctx->priv_data;
+ FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+
+ switch (dpx->pix_fmt) {
+ case AV_PIX_FMT_GRAY10:
+ case AV_PIX_FMT_GRAY12:
+ case AV_PIX_FMT_GBRAP10:
+ case AV_PIX_FMT_GBRAP12:
+ case AV_PIX_FMT_UYVY422:
+ case AV_PIX_FMT_YUV444P:
+ case AV_PIX_FMT_YUVA444P:
+ return AVERROR(ENOTSUP);
+ case AV_PIX_FMT_GBRP10:
+ if (dpx->unpadded_10bit)
+ return AVERROR(ENOTSUP);
+ /* fallthrough */
+ default:
+ break;
+ }
+
+ FFVkSPIRVCompiler *spv = ff_vk_spirv_init();
+ if (!spv) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
+ return AVERROR_EXTERNAL;
+ }
+
+ err = ff_vk_decode_init(avctx);
+ if (err < 0)
+ return err;
+
+ FFVulkanDecodeShared *ctx = dec->shared_ctx;
+ DPXVulkanDecodeContext *dxv = ctx->sd_ctx = av_mallocz(sizeof(*dxv));
+ if (!dxv) {
+ err = AVERROR(ENOMEM);
+ goto fail;
+ }
+
+ ctx->sd_ctx_free = &vk_decode_dpx_uninit;
+
+ RET(init_shader(avctx, &ctx->s, &ctx->exec_pool,
+ spv, &dxv->shader, avctx->bits_per_raw_sample));
+
+fail:
+ spv->uninit(&spv);
+
+ return err;
+}
+
+static void vk_dpx_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
+{
+ AVHWDeviceContext *dev_ctx = _hwctx.nc;
+
+ DPXVulkanDecodePicture *pp = data;
+ FFVulkanDecodePicture *vp = &pp->vp;
+
+ ff_vk_decode_free_frame(dev_ctx, vp);
+}
+
+const FFHWAccel ff_dpx_vulkan_hwaccel = {
+ .p.name = "dpx_vulkan",
+ .p.type = AVMEDIA_TYPE_VIDEO,
+ .p.id = AV_CODEC_ID_DPX,
+ .p.pix_fmt = AV_PIX_FMT_VULKAN,
+ .start_frame = &vk_dpx_start_frame,
+ .decode_slice = &vk_dpx_decode_slice,
+ .end_frame = &vk_dpx_end_frame,
+ .free_frame_priv = &vk_dpx_free_frame_priv,
+ .frame_priv_data_size = sizeof(DPXVulkanDecodePicture),
+ .init = &vk_decode_dpx_init,
+ .update_thread_context = &ff_vk_update_thread_context,
+ .decode_params = &ff_vk_params_invalidate,
+ .flush = &ff_vk_decode_flush,
+ .uninit = &ff_vk_decode_uninit,
+ .frame_params = &ff_vk_frame_params,
+ .priv_data_size = sizeof(FFVulkanDecodeContext),
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_THREAD_SAFE,
+};
commit a9acae202a064d6c745f6d826b008cd31d0bd9d0
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Oct 29 14:24:10 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:42 2025 +0100
dpxdec: add hardware decoding hooks
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 96d4647389..47efcb7572 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -29,6 +29,11 @@
#include "decode.h"
#include "dpx.h"
+#include "thread.h"
+#include "hwconfig.h"
+#include "hwaccel_internal.h"
+#include "config_components.h"
+
static unsigned int read16(const uint8_t **ptr, int is_big)
{
unsigned int temp;
@@ -257,11 +262,26 @@ static void unpack_frame(AVCodecContext *avctx, AVFrame *p, const uint8_t *buf,
}
}
+static enum AVPixelFormat get_pixel_format(AVCodecContext *avctx,
+ enum AVPixelFormat pix_fmt)
+{
+ enum AVPixelFormat pix_fmts[] = {
+#if CONFIG_DPX_VULKAN_HWACCEL
+ AV_PIX_FMT_VULKAN,
+#endif
+ pix_fmt,
+ AV_PIX_FMT_NONE,
+ };
+
+ return ff_get_format(avctx, pix_fmts);
+}
+
static int decode_frame(AVCodecContext *avctx, AVFrame *p,
int *got_frame, AVPacket *avpkt)
{
DPXDecContext *dpx = avctx->priv_data;
+ enum AVPixelFormat pix_fmt;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
uint32_t header_version, version = 0;
@@ -631,96 +651,96 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
case 4080:
case 6081:
case 6080:
- avctx->pix_fmt = AV_PIX_FMT_GRAY8;
+ pix_fmt = AV_PIX_FMT_GRAY8;
break;
case 6121:
case 6120:
- avctx->pix_fmt = AV_PIX_FMT_GRAY12;
+ pix_fmt = AV_PIX_FMT_GRAY12;
break;
case 1320:
case 2320:
case 3320:
case 4320:
case 6320:
- avctx->pix_fmt = AV_PIX_FMT_GRAYF32LE;
+ pix_fmt = AV_PIX_FMT_GRAYF32LE;
break;
case 1321:
case 2321:
case 3321:
case 4321:
case 6321:
- avctx->pix_fmt = AV_PIX_FMT_GRAYF32BE;
+ pix_fmt = AV_PIX_FMT_GRAYF32BE;
break;
case 50081:
case 50080:
- avctx->pix_fmt = AV_PIX_FMT_RGB24;
+ pix_fmt = AV_PIX_FMT_RGB24;
break;
case 52081:
case 52080:
- avctx->pix_fmt = AV_PIX_FMT_ABGR;
+ pix_fmt = AV_PIX_FMT_ABGR;
break;
case 51081:
case 51080:
- avctx->pix_fmt = AV_PIX_FMT_RGBA;
+ pix_fmt = AV_PIX_FMT_RGBA;
break;
case 50100:
case 50101:
- avctx->pix_fmt = AV_PIX_FMT_GBRP10;
+ pix_fmt = AV_PIX_FMT_GBRP10;
break;
case 51100:
case 51101:
- avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
+ pix_fmt = AV_PIX_FMT_GBRAP10;
break;
case 50120:
case 50121:
- avctx->pix_fmt = AV_PIX_FMT_GBRP12;
+ pix_fmt = AV_PIX_FMT_GBRP12;
break;
case 51120:
case 51121:
- avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
+ pix_fmt = AV_PIX_FMT_GBRAP12;
break;
case 6100:
case 6101:
- avctx->pix_fmt = AV_PIX_FMT_GRAY10;
+ pix_fmt = AV_PIX_FMT_GRAY10;
break;
case 6161:
- avctx->pix_fmt = AV_PIX_FMT_GRAY16BE;
+ pix_fmt = AV_PIX_FMT_GRAY16BE;
break;
case 6160:
- avctx->pix_fmt = AV_PIX_FMT_GRAY16LE;
+ pix_fmt = AV_PIX_FMT_GRAY16LE;
break;
case 50161:
- avctx->pix_fmt = AV_PIX_FMT_RGB48BE;
+ pix_fmt = AV_PIX_FMT_RGB48BE;
break;
case 50160:
- avctx->pix_fmt = AV_PIX_FMT_RGB48LE;
+ pix_fmt = AV_PIX_FMT_RGB48LE;
break;
case 51161:
- avctx->pix_fmt = AV_PIX_FMT_RGBA64BE;
+ pix_fmt = AV_PIX_FMT_RGBA64BE;
break;
case 51160:
- avctx->pix_fmt = AV_PIX_FMT_RGBA64LE;
+ pix_fmt = AV_PIX_FMT_RGBA64LE;
break;
case 50320:
- avctx->pix_fmt = AV_PIX_FMT_GBRPF32LE;
+ pix_fmt = AV_PIX_FMT_GBRPF32LE;
break;
case 50321:
- avctx->pix_fmt = AV_PIX_FMT_GBRPF32BE;
+ pix_fmt = AV_PIX_FMT_GBRPF32BE;
break;
case 51320:
- avctx->pix_fmt = AV_PIX_FMT_GBRAPF32LE;
+ pix_fmt = AV_PIX_FMT_GBRAPF32LE;
break;
case 51321:
- avctx->pix_fmt = AV_PIX_FMT_GBRAPF32BE;
+ pix_fmt = AV_PIX_FMT_GBRAPF32BE;
break;
case 100081:
- avctx->pix_fmt = AV_PIX_FMT_UYVY422;
+ pix_fmt = AV_PIX_FMT_UYVY422;
break;
case 102081:
- avctx->pix_fmt = AV_PIX_FMT_YUV444P;
+ pix_fmt = AV_PIX_FMT_YUV444P;
break;
case 103081:
- avctx->pix_fmt = AV_PIX_FMT_YUVA444P;
+ pix_fmt = AV_PIX_FMT_YUVA444P;
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported format %d\n",
@@ -728,6 +748,16 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
return AVERROR_PATCHWELCOME;
}
+ if (pix_fmt != dpx->pix_fmt) {
+ dpx->pix_fmt = pix_fmt;
+
+ ret = get_pixel_format(avctx, pix_fmt);
+ if (ret < 0)
+ return ret;
+
+ avctx->pix_fmt = ret;
+ }
+
ff_set_sar(avctx, avctx->sample_aspect_ratio);
if ((ret = ff_get_buffer(avctx, p, 0)) < 0)
@@ -737,13 +767,65 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
buf = avpkt->data + offset;
dpx->frame = p;
- unpack_frame(avctx, p, buf, dpx->components, dpx->endian);
+ /* Start */
+ if (avctx->hwaccel) {
+ const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
+
+ ret = ff_hwaccel_frame_priv_alloc(avctx, &dpx->hwaccel_picture_private);
+ if (ret < 0)
+ return ret;
+
+ ret = hwaccel->start_frame(avctx, avpkt->buf, buf, avpkt->size - offset);
+ if (ret < 0)
+ return ret;
+
+ ret = hwaccel->decode_slice(avctx, buf, avpkt->size - offset);
+ if (ret < 0)
+ return ret;
+
+ ret = hwaccel->end_frame(avctx);
+ if (ret < 0)
+ return ret;
+
+ av_refstruct_unref(&dpx->hwaccel_picture_private);
+ } else {
+ unpack_frame(avctx, p, buf, dpx->components, dpx->endian);
+ }
+
+ p->pict_type = AV_PICTURE_TYPE_I;
+ p->flags |= AV_FRAME_FLAG_KEY;
*got_frame = 1;
return buf_size;
}
+#if HAVE_THREADS
+static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
+{
+ DPXDecContext *ssrc = src->priv_data;
+ DPXDecContext *sdst = dst->priv_data;
+
+ sdst->pix_fmt = ssrc->pix_fmt;
+
+ return 0;
+}
+#endif
+
+static av_cold int decode_end(AVCodecContext *avctx)
+{
+ DPXDecContext *dpx = avctx->priv_data;
+ av_refstruct_unref(&dpx->hwaccel_picture_private);
+ return 0;
+}
+
+static av_cold int decode_init(AVCodecContext *avctx)
+{
+ DPXDecContext *dpx = avctx->priv_data;
+ dpx->pix_fmt = AV_PIX_FMT_NONE;
+ return 0;
+}
+
const FFCodec ff_dpx_decoder = {
.p.name = "dpx",
CODEC_LONG_NAME("DPX (Digital Picture Exchange) image"),
@@ -751,5 +833,11 @@ const FFCodec ff_dpx_decoder = {
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_DPX,
FF_CODEC_DECODE_CB(decode_frame),
- .p.capabilities = AV_CODEC_CAP_DR1,
+ .init = decode_init,
+ .close = decode_end,
+ UPDATE_THREAD_CONTEXT(update_thread_context),
+ .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+ .hw_configs = (const AVCodecHWConfigInternal *const []) {
+ NULL
+ },
};
diff --git a/libavcodec/dpx.h b/libavcodec/dpx.h
index 35e8aa690f..c9d95af1f1 100644
--- a/libavcodec/dpx.h
+++ b/libavcodec/dpx.h
@@ -23,6 +23,7 @@
#define AVCODEC_DPX_H
#include "libavutil/frame.h"
+#include "libavutil/pixfmt.h"
enum DPX_TRC {
DPX_TRC_USER_DEFINED = 0,
@@ -58,6 +59,8 @@ enum DPX_COL_SPEC {
typedef struct DPXDecContext {
AVFrame *frame;
+ void *hwaccel_picture_private;
+ enum AVPixelFormat pix_fmt;
int packing;
int stride;
commit 61ae1ec85fc5d1442e5010c0cf92dfa62c45d912
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 9 11:11:54 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:42 2025 +0100
dpxdec: move data parsing into a separate function
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index c8981bbf3a..96d4647389 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -118,6 +118,145 @@ static uint16_t read12in32(const uint8_t **ptr, uint32_t *lbuf,
}
}
+static void unpack_frame(AVCodecContext *avctx, AVFrame *p, const uint8_t *buf,
+ int elements, int endian)
+{
+ int i, x, y;
+ DPXDecContext *dpx = avctx->priv_data;
+
+ uint8_t *ptr[AV_NUM_DATA_POINTERS];
+ unsigned int rgbBuffer = 0;
+ int n_datum = 0;
+
+ for (i=0; i<AV_NUM_DATA_POINTERS; i++)
+ ptr[i] = p->data[i];
+
+ switch (avctx->bits_per_raw_sample) {
+ case 10:
+ for (x = 0; x < avctx->height; x++) {
+ uint16_t *dst[4] = {(uint16_t*)ptr[0],
+ (uint16_t*)ptr[1],
+ (uint16_t*)ptr[2],
+ (uint16_t*)ptr[3]};
+ int shift = elements > 1 ? dpx->packing == 1 ? 22 : 20 : dpx->packing == 1 ? 2 : 0;
+ for (y = 0; y < avctx->width; y++) {
+ if (elements >= 3)
+ *dst[2]++ = read10in32(&buf, &rgbBuffer,
+ &n_datum, endian, shift);
+ if (elements == 1)
+ *dst[0]++ = read10in32_gray(&buf, &rgbBuffer,
+ &n_datum, endian, shift);
+ else
+ *dst[0]++ = read10in32(&buf, &rgbBuffer,
+ &n_datum, endian, shift);
+ if (elements >= 2)
+ *dst[1]++ = read10in32(&buf, &rgbBuffer,
+ &n_datum, endian, shift);
+ if (elements == 4)
+ *dst[3]++ =
+ read10in32(&buf, &rgbBuffer,
+ &n_datum, endian, shift);
+ }
+ if (!dpx->unpadded_10bit)
+ n_datum = 0;
+ for (i = 0; i < elements; i++)
+ ptr[i] += p->linesize[i];
+ }
+ break;
+ case 12:
+ for (x = 0; x < avctx->height; x++) {
+ uint16_t *dst[4] = {(uint16_t*)ptr[0],
+ (uint16_t*)ptr[1],
+ (uint16_t*)ptr[2],
+ (uint16_t*)ptr[3]};
+ int shift = dpx->packing == 1 ? 4 : 0;
+ for (y = 0; y < avctx->width; y++) {
+ if (dpx->packing) {
+ if (elements >= 3)
+ *dst[2]++ = read16(&buf, endian) >> shift & 0xFFF;
+ *dst[0]++ = read16(&buf, endian) >> shift & 0xFFF;
+ if (elements >= 2)
+ *dst[1]++ = read16(&buf, endian) >> shift & 0xFFF;
+ if (elements == 4)
+ *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
+ } else {
+ if (elements >= 3)
+ *dst[2]++ = read12in32(&buf, &rgbBuffer,
+ &n_datum, endian);
+ *dst[0]++ = read12in32(&buf, &rgbBuffer,
+ &n_datum, endian);
+ if (elements >= 2)
+ *dst[1]++ = read12in32(&buf, &rgbBuffer,
+ &n_datum, endian);
+ if (elements == 4)
+ *dst[3]++ = read12in32(&buf, &rgbBuffer,
+ &n_datum, endian);
+ }
+ }
+ n_datum = 0;
+ for (i = 0; i < elements; i++)
+ ptr[i] += p->linesize[i];
+ // Jump to next aligned position
+ buf += dpx->need_align;
+ }
+ break;
+ case 32:
+ if (elements == 1) {
+ av_image_copy_plane(ptr[0], p->linesize[0],
+ buf, dpx->stride,
+ elements * avctx->width * 4, avctx->height);
+ } else {
+ for (y = 0; y < avctx->height; y++) {
+ ptr[0] = p->data[0] + y * p->linesize[0];
+ ptr[1] = p->data[1] + y * p->linesize[1];
+ ptr[2] = p->data[2] + y * p->linesize[2];
+ ptr[3] = p->data[3] + y * p->linesize[3];
+ for (x = 0; x < avctx->width; x++) {
+ AV_WN32(ptr[2], AV_RN32(buf));
+ AV_WN32(ptr[0], AV_RN32(buf + 4));
+ AV_WN32(ptr[1], AV_RN32(buf + 8));
+ if (avctx->pix_fmt == AV_PIX_FMT_GBRAPF32BE ||
+ avctx->pix_fmt == AV_PIX_FMT_GBRAPF32LE) {
+ AV_WN32(ptr[3], AV_RN32(buf + 12));
+ buf += 4;
+ ptr[3] += 4;
+ }
+
+ buf += 12;
+ ptr[2] += 4;
+ ptr[0] += 4;
+ ptr[1] += 4;
+ }
+ }
+ }
+ break;
+ case 16:
+ elements *= 2;
+ case 8:
+ if ( avctx->pix_fmt == AV_PIX_FMT_YUVA444P
+ || avctx->pix_fmt == AV_PIX_FMT_YUV444P) {
+ for (x = 0; x < avctx->height; x++) {
+ ptr[0] = p->data[0] + x * p->linesize[0];
+ ptr[1] = p->data[1] + x * p->linesize[1];
+ ptr[2] = p->data[2] + x * p->linesize[2];
+ ptr[3] = p->data[3] + x * p->linesize[3];
+ for (y = 0; y < avctx->width; y++) {
+ *ptr[1]++ = *buf++;
+ *ptr[0]++ = *buf++;
+ *ptr[2]++ = *buf++;
+ if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P)
+ *ptr[3]++ = *buf++;
+ }
+ }
+ } else {
+ av_image_copy_plane(ptr[0], p->linesize[0],
+ buf, dpx->stride,
+ elements * avctx->width, avctx->height);
+ }
+ break;
+ }
+}
+
static int decode_frame(AVCodecContext *avctx, AVFrame *p,
int *got_frame, AVPacket *avpkt)
{
@@ -125,21 +264,17 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- uint8_t *ptr[AV_NUM_DATA_POINTERS];
uint32_t header_version, version = 0;
char creator[101] = { 0 };
char input_device[33] = { 0 };
unsigned int offset;
int magic_num;
- int x, y, i, j, ret;
+ int i, j, ret;
int w, h, descriptor;
int yuv, color_trc, color_spec;
int encoding;
- unsigned int rgbBuffer = 0;
- int n_datum = 0;
-
if (avpkt->size <= 1634) {
av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n");
return AVERROR_INVALIDDATA;
@@ -602,135 +737,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
buf = avpkt->data + offset;
dpx->frame = p;
- int elements = dpx->components;
- int endian = dpx->endian;
- for (i=0; i<AV_NUM_DATA_POINTERS; i++)
- ptr[i] = p->data[i];
-
- switch (avctx->bits_per_raw_sample) {
- case 10:
- for (x = 0; x < avctx->height; x++) {
- uint16_t *dst[4] = {(uint16_t*)ptr[0],
- (uint16_t*)ptr[1],
- (uint16_t*)ptr[2],
- (uint16_t*)ptr[3]};
- int shift = elements > 1 ? dpx->packing == 1 ? 22 : 20 : dpx->packing == 1 ? 2 : 0;
- for (y = 0; y < avctx->width; y++) {
- if (elements >= 3)
- *dst[2]++ = read10in32(&buf, &rgbBuffer,
- &n_datum, endian, shift);
- if (elements == 1)
- *dst[0]++ = read10in32_gray(&buf, &rgbBuffer,
- &n_datum, endian, shift);
- else
- *dst[0]++ = read10in32(&buf, &rgbBuffer,
- &n_datum, endian, shift);
- if (elements >= 2)
- *dst[1]++ = read10in32(&buf, &rgbBuffer,
- &n_datum, endian, shift);
- if (elements == 4)
- *dst[3]++ =
- read10in32(&buf, &rgbBuffer,
- &n_datum, endian, shift);
- }
- if (!dpx->unpadded_10bit)
- n_datum = 0;
- for (i = 0; i < elements; i++)
- ptr[i] += p->linesize[i];
- }
- break;
- case 12:
- for (x = 0; x < avctx->height; x++) {
- uint16_t *dst[4] = {(uint16_t*)ptr[0],
- (uint16_t*)ptr[1],
- (uint16_t*)ptr[2],
- (uint16_t*)ptr[3]};
- int shift = dpx->packing == 1 ? 4 : 0;
- for (y = 0; y < avctx->width; y++) {
- if (dpx->packing) {
- if (elements >= 3)
- *dst[2]++ = read16(&buf, endian) >> shift & 0xFFF;
- *dst[0]++ = read16(&buf, endian) >> shift & 0xFFF;
- if (elements >= 2)
- *dst[1]++ = read16(&buf, endian) >> shift & 0xFFF;
- if (elements == 4)
- *dst[3]++ = read16(&buf, endian) >> shift & 0xFFF;
- } else {
- if (elements >= 3)
- *dst[2]++ = read12in32(&buf, &rgbBuffer,
- &n_datum, endian);
- *dst[0]++ = read12in32(&buf, &rgbBuffer,
- &n_datum, endian);
- if (elements >= 2)
- *dst[1]++ = read12in32(&buf, &rgbBuffer,
- &n_datum, endian);
- if (elements == 4)
- *dst[3]++ = read12in32(&buf, &rgbBuffer,
- &n_datum, endian);
- }
- }
- n_datum = 0;
- for (i = 0; i < elements; i++)
- ptr[i] += p->linesize[i];
- // Jump to next aligned position
- buf += dpx->need_align;
- }
- break;
- case 32:
- if (elements == 1) {
- av_image_copy_plane(ptr[0], p->linesize[0],
- buf, dpx->stride,
- elements * avctx->width * 4, avctx->height);
- } else {
- for (y = 0; y < avctx->height; y++) {
- ptr[0] = p->data[0] + y * p->linesize[0];
- ptr[1] = p->data[1] + y * p->linesize[1];
- ptr[2] = p->data[2] + y * p->linesize[2];
- ptr[3] = p->data[3] + y * p->linesize[3];
- for (x = 0; x < avctx->width; x++) {
- AV_WN32(ptr[2], AV_RN32(buf));
- AV_WN32(ptr[0], AV_RN32(buf + 4));
- AV_WN32(ptr[1], AV_RN32(buf + 8));
- if (avctx->pix_fmt == AV_PIX_FMT_GBRAPF32BE ||
- avctx->pix_fmt == AV_PIX_FMT_GBRAPF32LE) {
- AV_WN32(ptr[3], AV_RN32(buf + 12));
- buf += 4;
- ptr[3] += 4;
- }
-
- buf += 12;
- ptr[2] += 4;
- ptr[0] += 4;
- ptr[1] += 4;
- }
- }
- }
- break;
- case 16:
- elements *= 2;
- case 8:
- if ( avctx->pix_fmt == AV_PIX_FMT_YUVA444P
- || avctx->pix_fmt == AV_PIX_FMT_YUV444P) {
- for (x = 0; x < avctx->height; x++) {
- ptr[0] = p->data[0] + x * p->linesize[0];
- ptr[1] = p->data[1] + x * p->linesize[1];
- ptr[2] = p->data[2] + x * p->linesize[2];
- ptr[3] = p->data[3] + x * p->linesize[3];
- for (y = 0; y < avctx->width; y++) {
- *ptr[1]++ = *buf++;
- *ptr[0]++ = *buf++;
- *ptr[2]++ = *buf++;
- if (avctx->pix_fmt == AV_PIX_FMT_YUVA444P)
- *ptr[3]++ = *buf++;
- }
- }
- } else {
- av_image_copy_plane(ptr[0], p->linesize[0],
- buf, dpx->stride,
- elements * avctx->width, avctx->height);
- }
- break;
- }
+ unpack_frame(avctx, p, buf, dpx->components, dpx->endian);
*got_frame = 1;
commit bc07d03d069e263f8bf754f3b7c377cc9e859a00
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 9 10:52:20 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:42 2025 +0100
dpx: add a context
This simply adds a context with 4 fields to enable hardware unpacking.
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 1b1ada316a..c8981bbf3a 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -121,6 +121,8 @@ static uint16_t read12in32(const uint8_t **ptr, uint32_t *lbuf,
static int decode_frame(AVCodecContext *avctx, AVFrame *p,
int *got_frame, AVPacket *avpkt)
{
+ DPXDecContext *dpx = avctx->priv_data;
+
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
uint8_t *ptr[AV_NUM_DATA_POINTERS];
@@ -129,11 +131,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
char input_device[33] = { 0 };
unsigned int offset;
- int magic_num, endian;
- int x, y, stride, i, j, ret;
- int w, h, bits_per_color, descriptor, elements, packing;
+ int magic_num;
+ int x, y, i, j, ret;
+ int w, h, descriptor;
int yuv, color_trc, color_spec;
- int encoding, need_align = 0, unpadded_10bit = 0;
+ int encoding;
unsigned int rgbBuffer = 0;
int n_datum = 0;
@@ -149,15 +151,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
/* Check if the files "magic number" is "SDPX" which means it uses
* big-endian or XPDS which is for little-endian files */
if (magic_num == AV_RL32("SDPX")) {
- endian = 0;
+ dpx->endian = 0;
} else if (magic_num == AV_RB32("SDPX")) {
- endian = 1;
+ dpx->endian = 1;
} else {
av_log(avctx, AV_LOG_ERROR, "DPX marker not found\n");
return AVERROR_INVALIDDATA;
}
- offset = read32(&buf, endian);
+ offset = read32(&buf, dpx->endian);
if (avpkt->size <= offset) {
av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n");
return AVERROR_INVALIDDATA;
@@ -174,7 +176,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Check encryption
buf = avpkt->data + 660;
- ret = read32(&buf, endian);
+ ret = read32(&buf, dpx->endian);
if (ret != 0xFFFFFFFF) {
avpriv_report_missing_feature(avctx, "Encryption");
av_log(avctx, AV_LOG_WARNING, "The image is encrypted and may "
@@ -183,8 +185,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Need to end in 0x304 offset from start of file
buf = avpkt->data + 0x304;
- w = read32(&buf, endian);
- h = read32(&buf, endian);
+ w = read32(&buf, dpx->endian);
+ h = read32(&buf, dpx->endian);
if ((ret = ff_set_dimensions(avctx, w, h)) < 0)
return ret;
@@ -197,23 +199,22 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Need to end in 0x323 to read the bits per color
buf += 3;
- avctx->bits_per_raw_sample =
- bits_per_color = buf[0];
+ avctx->bits_per_raw_sample = buf[0];
buf++;
- packing = read16(&buf, endian);
- encoding = read16(&buf, endian);
+ dpx->packing = read16(&buf, dpx->endian);
+ encoding = read16(&buf, dpx->endian);
if (encoding) {
avpriv_report_missing_feature(avctx, "Encoding %d", encoding);
return AVERROR_PATCHWELCOME;
}
- if (bits_per_color > 31)
+ if (avctx->bits_per_raw_sample > 31)
return AVERROR_INVALIDDATA;
buf += 820;
- avctx->sample_aspect_ratio.num = read32(&buf, endian);
- avctx->sample_aspect_ratio.den = read32(&buf, endian);
+ avctx->sample_aspect_ratio.num = read32(&buf, dpx->endian);
+ avctx->sample_aspect_ratio.den = read32(&buf, dpx->endian);
if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)
av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den,
avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den,
@@ -224,7 +225,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
/* preferred frame rate from Motion-picture film header */
if (offset >= 1724 + 4) {
buf = avpkt->data + 1724;
- i = read32(&buf, endian);
+ i = read32(&buf, dpx->endian);
if(i && i != 0xFFFFFFFF) {
AVRational q = av_d2q(av_int2float(i), 4096);
if (q.num > 0 && q.den > 0)
@@ -236,7 +237,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
if (offset >= 1940 + 4 &&
!(avctx->framerate.num && avctx->framerate.den)) {
buf = avpkt->data + 1940;
- i = read32(&buf, endian);
+ i = read32(&buf, dpx->endian);
if(i && i != 0xFFFFFFFF) {
AVRational q = av_d2q(av_int2float(i), 4096);
if (q.num > 0 && q.den > 0)
@@ -253,7 +254,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
buf = avpkt->data + 1920;
// read32 to native endian, av_bswap32 to opposite of native for
// compatibility with av_timecode_make_smpte_tc_string2 etc
- tc = av_bswap32(read32(&buf, endian));
+ tc = av_bswap32(read32(&buf, dpx->endian));
if (i != 0xFFFFFFFF) {
AVFrameSideData *tcside;
@@ -277,21 +278,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
/* color range from television header */
if (offset >= 1964 + 4) {
buf = avpkt->data + 1952;
- i = read32(&buf, endian);
+ i = read32(&buf, dpx->endian);
buf = avpkt->data + 1964;
- j = read32(&buf, endian);
+ j = read32(&buf, dpx->endian);
if (i != 0xFFFFFFFF && j != 0xFFFFFFFF) {
float minCV, maxCV;
minCV = av_int2float(i);
maxCV = av_int2float(j);
- if (bits_per_color >= 1 &&
- minCV == 0.0f && maxCV == ((1U<<bits_per_color) - 1)) {
+ if (avctx->bits_per_raw_sample >= 1 &&
+ minCV == 0.0f && maxCV == ((1U<<avctx->bits_per_raw_sample) - 1)) {
avctx->color_range = AVCOL_RANGE_JPEG;
- } else if (bits_per_color >= 8 &&
- minCV == (1 <<(bits_per_color - 4)) &&
- maxCV == (235<<(bits_per_color - 8))) {
+ } else if (avctx->bits_per_raw_sample >= 8 &&
+ minCV == (1 <<(avctx->bits_per_raw_sample - 4)) &&
+ maxCV == (235<<(avctx->bits_per_raw_sample - 8))) {
avctx->color_range = AVCOL_RANGE_MPEG;
}
}
@@ -303,28 +304,28 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
case 3: // B
case 4: // A
case 6: // Y
- elements = 1;
+ dpx->components = 1;
yuv = 1;
break;
case 50: // RGB
- elements = 3;
+ dpx->components = 3;
yuv = 0;
break;
case 52: // ABGR
case 51: // RGBA
- elements = 4;
+ dpx->components = 4;
yuv = 0;
break;
case 100: // UYVY422
- elements = 2;
+ dpx->components = 2;
yuv = 1;
break;
case 102: // UYV444
- elements = 3;
+ dpx->components = 3;
yuv = 1;
break;
case 103: // UYVA4444
- elements = 4;
+ dpx->components = 4;
yuv = 1;
break;
default:
@@ -332,40 +333,40 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
return AVERROR_PATCHWELCOME;
}
- switch (bits_per_color) {
+ switch (avctx->bits_per_raw_sample) {
case 8:
- stride = avctx->width * elements;
+ dpx->stride = avctx->width * dpx->components;
break;
case 10:
- if (!packing) {
+ if (!dpx->packing) {
av_log(avctx, AV_LOG_ERROR, "Packing to 32bit required\n");
return -1;
}
- stride = (avctx->width * elements + 2) / 3 * 4;
+ dpx->stride = (avctx->width * dpx->components + 2) / 3 * 4;
break;
case 12:
- stride = avctx->width * elements;
- if (packing) {
- stride *= 2;
+ dpx->stride = avctx->width * dpx->components;
+ if (dpx->packing) {
+ dpx->stride *= 2;
} else {
- stride *= 3;
- if (stride % 8) {
- stride /= 8;
- stride++;
- stride *= 8;
+ dpx->stride *= 3;
+ if (dpx->stride % 8) {
+ dpx->stride /= 8;
+ dpx->stride++;
+ dpx->stride *= 8;
}
- stride /= 2;
+ dpx->stride /= 2;
}
break;
case 16:
- stride = 2 * avctx->width * elements;
+ dpx->stride = 2 * avctx->width * dpx->components;
break;
case 32:
- stride = 4 * avctx->width * elements;
+ dpx->stride = 4 * avctx->width * dpx->components;
break;
case 1:
case 64:
- avpriv_report_missing_feature(avctx, "Depth %d", bits_per_color);
+ avpriv_report_missing_feature(avctx, "Depth %d", avctx->bits_per_raw_sample);
return AVERROR_PATCHWELCOME;
default:
return AVERROR_INVALIDDATA;
@@ -458,8 +459,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Some devices do not pad 10bit samples to whole 32bit words per row
if (!memcmp(input_device, "Scanity", 7) ||
!memcmp(creator, "Lasergraphics Inc.", 18)) {
- if (bits_per_color == 10)
- unpadded_10bit = 1;
+ if (avctx->bits_per_raw_sample == 10)
+ dpx->unpadded_10bit = 1;
}
// Table 3c: Runs will always break at scan line boundaries. Packing
@@ -467,24 +468,24 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Unfortunately, the encoder produced invalid files, so attempt
// to detect it
// Also handle special case with unpadded content
- need_align = FFALIGN(stride, 4);
- if (need_align*avctx->height + (int64_t)offset > avpkt->size &&
- (!unpadded_10bit || (avctx->width * avctx->height * elements + 2) / 3 * 4 + (int64_t)offset > avpkt->size)) {
+ dpx->need_align = FFALIGN(dpx->stride, 4);
+ if (dpx->need_align*avctx->height + (int64_t)offset > avpkt->size &&
+ (!dpx->unpadded_10bit || (avctx->width * avctx->height * dpx->components + 2) / 3 * 4 + (int64_t)offset > avpkt->size)) {
// Alignment seems unappliable, try without
- if (stride*avctx->height + (int64_t)offset > avpkt->size || unpadded_10bit) {
+ if (dpx->stride*avctx->height + (int64_t)offset > avpkt->size || dpx->unpadded_10bit) {
av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n");
return AVERROR_INVALIDDATA;
} else {
av_log(avctx, AV_LOG_INFO, "Decoding DPX without scanline "
"alignment.\n");
- need_align = 0;
+ dpx->need_align = 0;
}
} else {
- need_align -= stride;
- stride = FFALIGN(stride, 4);
+ dpx->need_align -= dpx->stride;
+ dpx->stride = FFALIGN(dpx->stride, 4);
}
- switch (1000 * descriptor + 10 * bits_per_color + endian) {
+ switch (1000 * descriptor + 10 * avctx->bits_per_raw_sample + dpx->endian) {
case 1081:
case 1080:
case 2081:
@@ -588,7 +589,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unsupported format %d\n",
- 1000 * descriptor + 10 * bits_per_color + endian);
+ 1000 * descriptor + 10 * avctx->bits_per_raw_sample + dpx->endian);
return AVERROR_PATCHWELCOME;
}
@@ -599,18 +600,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
// Move pointer to offset from start of file
buf = avpkt->data + offset;
+ dpx->frame = p;
+ int elements = dpx->components;
+ int endian = dpx->endian;
for (i=0; i<AV_NUM_DATA_POINTERS; i++)
ptr[i] = p->data[i];
- switch (bits_per_color) {
+ switch (avctx->bits_per_raw_sample) {
case 10:
for (x = 0; x < avctx->height; x++) {
uint16_t *dst[4] = {(uint16_t*)ptr[0],
(uint16_t*)ptr[1],
(uint16_t*)ptr[2],
(uint16_t*)ptr[3]};
- int shift = elements > 1 ? packing == 1 ? 22 : 20 : packing == 1 ? 2 : 0;
+ int shift = elements > 1 ? dpx->packing == 1 ? 22 : 20 : dpx->packing == 1 ? 2 : 0;
for (y = 0; y < avctx->width; y++) {
if (elements >= 3)
*dst[2]++ = read10in32(&buf, &rgbBuffer,
@@ -629,7 +633,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
read10in32(&buf, &rgbBuffer,
&n_datum, endian, shift);
}
- if (!unpadded_10bit)
+ if (!dpx->unpadded_10bit)
n_datum = 0;
for (i = 0; i < elements; i++)
ptr[i] += p->linesize[i];
@@ -641,9 +645,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
(uint16_t*)ptr[1],
(uint16_t*)ptr[2],
(uint16_t*)ptr[3]};
- int shift = packing == 1 ? 4 : 0;
+ int shift = dpx->packing == 1 ? 4 : 0;
for (y = 0; y < avctx->width; y++) {
- if (packing) {
+ if (dpx->packing) {
if (elements >= 3)
*dst[2]++ = read16(&buf, endian) >> shift & 0xFFF;
*dst[0]++ = read16(&buf, endian) >> shift & 0xFFF;
@@ -669,13 +673,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
for (i = 0; i < elements; i++)
ptr[i] += p->linesize[i];
// Jump to next aligned position
- buf += need_align;
+ buf += dpx->need_align;
}
break;
case 32:
if (elements == 1) {
av_image_copy_plane(ptr[0], p->linesize[0],
- buf, stride,
+ buf, dpx->stride,
elements * avctx->width * 4, avctx->height);
} else {
for (y = 0; y < avctx->height; y++) {
@@ -722,7 +726,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
}
} else {
av_image_copy_plane(ptr[0], p->linesize[0],
- buf, stride,
+ buf, dpx->stride,
elements * avctx->width, avctx->height);
}
break;
@@ -736,6 +740,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
const FFCodec ff_dpx_decoder = {
.p.name = "dpx",
CODEC_LONG_NAME("DPX (Digital Picture Exchange) image"),
+ .priv_data_size = sizeof(DPXDecContext),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_DPX,
FF_CODEC_DECODE_CB(decode_frame),
diff --git a/libavcodec/dpx.h b/libavcodec/dpx.h
index 800c651e5a..35e8aa690f 100644
--- a/libavcodec/dpx.h
+++ b/libavcodec/dpx.h
@@ -22,6 +22,8 @@
#ifndef AVCODEC_DPX_H
#define AVCODEC_DPX_H
+#include "libavutil/frame.h"
+
enum DPX_TRC {
DPX_TRC_USER_DEFINED = 0,
DPX_TRC_PRINTING_DENSITY = 1,
@@ -54,4 +56,15 @@ enum DPX_COL_SPEC {
/* 12 = N/A */
};
+typedef struct DPXDecContext {
+ AVFrame *frame;
+
+ int packing;
+ int stride;
+ int endian;
+ int components;
+ int unpadded_10bit;
+ int need_align;
+} DPXDecContext;
+
#endif /* AVCODEC_DPX_H */
commit 7af5b5cec33832f12515df0e5fe45a2aad437ca2
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Tue Nov 25 17:20:10 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:42 2025 +0100
vulkan_prores_raw: use the native image representation
It allows us to easily synchronize the software and hardware
decoders, by removing the abstraction the Vulkan layer added by changing
the values written.
diff --git a/libavcodec/vulkan/prores_raw_decode.comp b/libavcodec/vulkan/prores_raw_decode.comp
index 069aef638c..809d787466 100644
--- a/libavcodec/vulkan/prores_raw_decode.comp
+++ b/libavcodec/vulkan/prores_raw_decode.comp
@@ -101,7 +101,8 @@ int16_t get_value(int16_t codebook)
void store_val(ivec2 offs, int blk, int c, int16_t v)
{
- imageStore(dst, offs + 2*ivec2(blk*8 + (c & 7), c >> 3), ivec4(v));
+ imageStore(dst, offs + 2*ivec2(blk*8 + (c & 7), c >> 3),
+ ivec4(v & 0xFFFF));
}
void read_dc_vals(ivec2 offs, int nb_blocks)
diff --git a/libavcodec/vulkan/prores_raw_idct.comp b/libavcodec/vulkan/prores_raw_idct.comp
index d069a6e3c4..29ddf3b9e8 100644
--- a/libavcodec/vulkan/prores_raw_idct.comp
+++ b/libavcodec/vulkan/prores_raw_idct.comp
@@ -135,7 +135,7 @@ void main(void)
uint64_t pkt_offset = uint64_t(pkt_data) + td.offset;
u8vec2buf hdr_data = u8vec2buf(pkt_offset);
- float qscale = float(pack16(hdr_data[0].v.yx)) / 2.0f;
+ int qscale = pack16(hdr_data[0].v.yx);
const ivec2 offs = td.pos + ivec2(COMP_ID & 1, COMP_ID >> 1);
const uint w = min(tile_size.x, frame_size.x - td.pos.x) / 2;
@@ -146,10 +146,11 @@ void main(void)
[[unroll]]
for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x) {
- int16_t v = int16_t(imageLoad(dst, offs + 2*ivec2(BLOCK_ID*8, 0) + scan[i])[0]);
- blocks[BLOCK_ID][COMP_ID*64 + i] = (v / 16384.0) *
- (float(qmat_buf[i]) / 295.0) *
- idct_scale[i] * qscale;
+ int v = int(imageLoad(dst, offs + 2*ivec2(BLOCK_ID*8, 0) + scan[i])[0]);
+ float vf = float(sign_extend(v, 16)) / 32768.0;
+ vf *= qmat_buf[i] * qscale;
+ blocks[BLOCK_ID][COMP_ID*64 + i] = (vf / (64*4.56)) *
+ idct_scale[i];
}
barrier();
@@ -163,7 +164,9 @@ void main(void)
barrier();
[[unroll]]
for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x) {
- int v = int(round(blocks[BLOCK_ID][COMP_ID*64 + i]*16384.0));
+ int v = int(round(blocks[BLOCK_ID][COMP_ID*64 + i]*4095.0));
+ v = clamp(v, 0, 4095);
+ v <<= 4;
imageStore(dst,
offs + 2*ivec2(BLOCK_ID*8 + (i & 7), i >> 3),
ivec4(v));
diff --git a/libavcodec/vulkan_prores_raw.c b/libavcodec/vulkan_prores_raw.c
index bd3c8b6e46..cd025d25e6 100644
--- a/libavcodec/vulkan_prores_raw.c
+++ b/libavcodec/vulkan_prores_raw.c
@@ -96,7 +96,7 @@ static int vk_prores_raw_start_frame(AVCodecContext *avctx,
/* Prepare frame to be used */
err = ff_vk_decode_prepare_frame_sdr(dec, prr->frame, vp, 1,
- FF_VK_REP_INT, 0);
+ FF_VK_REP_NATIVE, 0);
if (err < 0)
return err;
@@ -314,7 +314,7 @@ static int add_common_data(AVCodecContext *avctx, FFVulkanContext *s,
.name = "dst",
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
.mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
- FF_VK_REP_INT),
+ FF_VK_REP_NATIVE),
.mem_quali = writeonly ? "writeonly" : NULL,
.dimensions = 2,
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
commit a811a6885a342abf3fb5bd61753e5d4ebd17114d
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sat Nov 15 14:15:19 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:42 2025 +0100
vulkan_prores_raw: read the header length rather than assuming its 8
In all known samples, it is equal to 8.
diff --git a/libavcodec/vulkan/prores_raw_decode.comp b/libavcodec/vulkan/prores_raw_decode.comp
index 08447e3961..069aef638c 100644
--- a/libavcodec/vulkan/prores_raw_decode.comp
+++ b/libavcodec/vulkan/prores_raw_decode.comp
@@ -206,12 +206,13 @@ void main(void)
uint64_t pkt_offset = uint64_t(pkt_data) + td.offset;
u8vec2buf hdr_data = u8vec2buf(pkt_offset);
+ int header_len = hdr_data[0].v.x >> 3;
ivec4 size = ivec4(td.size,
pack16(hdr_data[2].v.yx),
pack16(hdr_data[1].v.yx),
pack16(hdr_data[3].v.yx));
- size[0] = size[0] - size[1] - size[2] - size[3] - 8;
+ size[0] = size[0] - size[1] - size[2] - size[3] - header_len;
if (expectEXT(size[0] < 0, false))
return;
@@ -224,7 +225,7 @@ void main(void)
0,
size[2] + size[1]);
- init_get_bits(gb, u8buf(pkt_offset + 8 + comp_offset[COMP_ID]),
+ init_get_bits(gb, u8buf(pkt_offset + header_len + comp_offset[COMP_ID]),
size[COMP_ID]);
read_dc_vals(offs, nb_blocks);
commit 0db891366d8e501356ac3caee776af448ad50e68
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Mon Nov 24 19:14:34 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
vulkan_prores_raw: fix dynamically non-uniform accesses to pushconsts
The Vulkan spec requires that all accesses to push data are uniform for
all invocations (e.g. can't be based on gl_WorkGroupID or gl_LocalInvocationID).
diff --git a/libavcodec/vulkan/prores_raw_idct.comp b/libavcodec/vulkan/prores_raw_idct.comp
index e692792301..d069a6e3c4 100644
--- a/libavcodec/vulkan/prores_raw_idct.comp
+++ b/libavcodec/vulkan/prores_raw_idct.comp
@@ -141,11 +141,14 @@ void main(void)
const uint w = min(tile_size.x, frame_size.x - td.pos.x) / 2;
const uint nb_blocks = w / 8;
+ /* We have to do non-uniform access, so copy it */
+ uint8_t qmat_buf[64] = qmat;
+
[[unroll]]
for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x) {
int16_t v = int16_t(imageLoad(dst, offs + 2*ivec2(BLOCK_ID*8, 0) + scan[i])[0]);
blocks[BLOCK_ID][COMP_ID*64 + i] = (v / 16384.0) *
- (float(qmat[i]) / 295.0) *
+ (float(qmat_buf[i]) / 295.0) *
idct_scale[i] * qscale;
}
commit edb844510ee72a03a87fef3671b5152cdacfef92
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Thu Nov 13 12:02:22 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
vulkan_prores_raw: use regular descriptors for tile data instead of BDA
Regular descriptors are faster.
diff --git a/libavcodec/vulkan_prores_raw.c b/libavcodec/vulkan_prores_raw.c
index 3b6d617eec..bd3c8b6e46 100644
--- a/libavcodec/vulkan_prores_raw.c
+++ b/libavcodec/vulkan_prores_raw.c
@@ -38,7 +38,7 @@ const FFVulkanDecodeDescriptor ff_vk_dec_prores_raw_desc = {
typedef struct ProResRAWVulkanDecodePicture {
FFVulkanDecodePicture vp;
- AVBufferRef *tile_data;
+ AVBufferRef *frame_data_buf;
uint32_t nb_tiles;
} ProResRAWVulkanDecodePicture;
@@ -46,11 +46,10 @@ typedef struct ProResRAWVulkanDecodeContext {
FFVulkanShader decode;
FFVulkanShader idct;
- AVBufferPool *tile_data_pool;
+ AVBufferPool *frame_data_pool;
} ProResRAWVulkanDecodeContext;
typedef struct DecodePushData {
- VkDeviceAddress tile_data;
VkDeviceAddress pkt_data;
int32_t frame_size[2];
int32_t tile_size[2];
@@ -85,8 +84,8 @@ static int vk_prores_raw_start_frame(AVCodecContext *avctx,
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
/* Allocate tile data */
- err = ff_vk_get_pooled_buffer(&ctx->s, &prv->tile_data_pool,
- &pp->tile_data,
+ err = ff_vk_get_pooled_buffer(&ctx->s, &prv->frame_data_pool,
+ &pp->frame_data_buf,
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
NULL, prr->nb_tiles*sizeof(TileData),
@@ -113,8 +112,8 @@ static int vk_prores_raw_decode_slice(AVCodecContext *avctx,
ProResRAWVulkanDecodePicture *pp = prr->hwaccel_picture_private;
FFVulkanDecodePicture *vp = &pp->vp;
- FFVkBuffer *tile_data_buf = (FFVkBuffer *)pp->tile_data->data;
- TileData *td = (TileData *)tile_data_buf->mapped_mem;
+ FFVkBuffer *frame_data_buf = (FFVkBuffer *)pp->frame_data_buf->data;
+ TileData *td = (TileData *)frame_data_buf->mapped_mem;
FFVkBuffer *slices_buf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL;
td[pp->nb_tiles].pos[0] = prr->tiles[pp->nb_tiles].x;
@@ -150,7 +149,7 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
FFVulkanDecodePicture *vp = &pp->vp;
FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data;
- FFVkBuffer *tile_data = (FFVkBuffer *)pp->tile_data->data;
+ FFVkBuffer *frame_data_buf = (FFVkBuffer *)pp->frame_data_buf->data;
VkImageMemoryBarrier2 img_bar[8];
int nb_img_bar = 0;
@@ -168,8 +167,8 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
if (err < 0)
return err;
- RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &pp->tile_data, 1, 0));
- pp->tile_data = NULL;
+ RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &pp->frame_data_buf, 1, 0));
+ pp->frame_data_buf = NULL;
RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
vp->slices_buf = NULL;
@@ -220,12 +219,16 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
0, 0,
VK_IMAGE_LAYOUT_GENERAL,
VK_NULL_HANDLE);
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
+ 0, 1, 0,
+ frame_data_buf,
+ 0, prr->nb_tiles*sizeof(TileData),
+ VK_FORMAT_UNDEFINED);
ff_vk_exec_bind_shader(&ctx->s, exec, decode_shader);
/* Update push data */
DecodePushData pd_decode = (DecodePushData) {
- .tile_data = tile_data->address,
.pkt_data = slices_buf->address,
.frame_size[0] = avctx->width,
.frame_size[1] = avctx->height,
@@ -253,6 +256,11 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
0, 0,
VK_IMAGE_LAYOUT_GENERAL,
VK_NULL_HANDLE);
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, idct_shader,
+ 0, 1, 0,
+ frame_data_buf,
+ 0, prr->nb_tiles*sizeof(TileData),
+ VK_FORMAT_UNDEFINED);
ff_vk_exec_bind_shader(&ctx->s, exec, idct_shader);
ff_vk_shader_update_push_const(&ctx->s, exec, idct_shader,
VK_SHADER_STAGE_COMPUTE_BIT,
@@ -284,14 +292,13 @@ static int add_common_data(AVCodecContext *avctx, FFVulkanContext *s,
/* Common codec header */
GLSLD(ff_source_common_comp);
- GLSLC(0, layout(buffer_reference, buffer_reference_align = 16) buffer TileData { );
+ GLSLC(0, struct TileData { );
GLSLC(1, ivec2 pos; );
GLSLC(1, uint offset; );
GLSLC(1, uint size; );
GLSLC(0, }; );
GLSLC(0, );
GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
- GLSLC(1, TileData tile_data; );
GLSLC(1, u8buf pkt_data; );
GLSLC(1, ivec2 frame_size; );
GLSLC(1, ivec2 tile_size; );
@@ -312,9 +319,17 @@ static int add_common_data(AVCodecContext *avctx, FFVulkanContext *s,
.dimensions = 2,
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
},
+ {
+ .name = "frame_data_buf",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ .mem_layout = "scalar",
+ .mem_quali = "readonly",
+ .buf_content = "TileData tile_data[];",
+ },
};
- return ff_vk_shader_add_descriptor_set(s, shd, desc_set, 1, 0, 0);
+ return ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0, 0);
}
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s,
@@ -392,7 +407,7 @@ static void vk_decode_prores_raw_uninit(FFVulkanDecodeShared *ctx)
ff_vk_shader_free(&ctx->s, &fv->decode);
ff_vk_shader_free(&ctx->s, &fv->idct);
- av_buffer_pool_uninit(&fv->tile_data_pool);
+ av_buffer_pool_uninit(&fv->frame_data_pool);
av_freep(&fv);
}
@@ -442,6 +457,8 @@ static void vk_prores_raw_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
FFVulkanDecodePicture *vp = &pp->vp;
ff_vk_decode_free_frame(dev_ctx, vp);
+
+ av_buffer_unref(&pp->frame_data_buf);
}
const FFHWAccel ff_prores_raw_vulkan_hwaccel = {
commit bb30a0d0d8b14147649ac945b76a2fc05f916d67
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 12 15:04:38 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
vulkan_prores_raw: split up decoding and DCT
This commit optimizes the Vulkan decoder by splitting up decoding
from iDCT, and merging the few tables needed directly into the shader.
The speedup on Intel is 10x.
diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile
index ec3015fee6..16a4116ef1 100644
--- a/libavcodec/vulkan/Makefile
+++ b/libavcodec/vulkan/Makefile
@@ -15,7 +15,8 @@ OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL) += vulkan/common.o \
vulkan/ffv1_dec_setup.o vulkan/ffv1_dec.o
OBJS-$(CONFIG_PRORES_RAW_VULKAN_HWACCEL) += vulkan/common.o \
- vulkan/prores_raw.o
+ vulkan/prores_raw_decode.o \
+ vulkan/prores_raw_idct.o
OBJS-$(CONFIG_PRORES_VULKAN_HWACCEL) += vulkan/common.o \
vulkan/prores_reset.o \
diff --git a/libavcodec/vulkan/prores_raw.comp b/libavcodec/vulkan/prores_raw.comp
deleted file mode 100644
index 89eece3c7e..0000000000
--- a/libavcodec/vulkan/prores_raw.comp
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * ProRes RAW decoder
- *
- * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
- *
- * This file is part of FFmpeg.
- *
- * FFmpeg is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * FFmpeg is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with FFmpeg; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#define I16(x) (int16_t(x))
-
-#define COMP_ID (gl_LocalInvocationID.z)
-#define BLOCK_ID (gl_LocalInvocationID.y)
-#define ROW_ID (gl_LocalInvocationID.x)
-
-GetBitContext gb;
-shared float btemp[gl_WorkGroupSize.z][16][64] = { };
-shared float block[gl_WorkGroupSize.z][16][64];
-
-void idct8_horiz(const uint row_id)
-{
- float t0, t1, t2, t3, t4, t5, t6, t7, u8;
- float u0, u1, u2, u3, u4, u5, u6, u7;
-
- /* Input */
- t0 = block[COMP_ID][BLOCK_ID][8*row_id + 0];
- u4 = block[COMP_ID][BLOCK_ID][8*row_id + 1];
- t2 = block[COMP_ID][BLOCK_ID][8*row_id + 2];
- u6 = block[COMP_ID][BLOCK_ID][8*row_id + 3];
- t1 = block[COMP_ID][BLOCK_ID][8*row_id + 4];
- u5 = block[COMP_ID][BLOCK_ID][8*row_id + 5];
- t3 = block[COMP_ID][BLOCK_ID][8*row_id + 6];
- u7 = block[COMP_ID][BLOCK_ID][8*row_id + 7];
-
- /* Embedded scaled inverse 4-point Type-II DCT */
- u0 = t0 + t1;
- u1 = t0 - t1;
- u3 = t2 + t3;
- u2 = (t2 - t3)*(1.4142135623730950488016887242097f) - u3;
- t0 = u0 + u3;
- t3 = u0 - u3;
- t1 = u1 + u2;
- t2 = u1 - u2;
-
- /* Embedded scaled inverse 4-point Type-IV DST */
- t5 = u5 + u6;
- t6 = u5 - u6;
- t7 = u4 + u7;
- t4 = u4 - u7;
- u7 = t7 + t5;
- u5 = (t7 - t5)*(1.4142135623730950488016887242097f);
- u8 = (t4 + t6)*(1.8477590650225735122563663787936f);
- u4 = u8 - t4*(1.0823922002923939687994464107328f);
- u6 = u8 - t6*(2.6131259297527530557132863468544f);
- t7 = u7;
- t6 = t7 - u6;
- t5 = t6 + u5;
- t4 = t5 - u4;
-
- /* Butterflies */
- u0 = t0 + t7;
- u7 = t0 - t7;
- u6 = t1 + t6;
- u1 = t1 - t6;
- u2 = t2 + t5;
- u5 = t2 - t5;
- u4 = t3 + t4;
- u3 = t3 - t4;
-
- /* Output */
- btemp[COMP_ID][BLOCK_ID][0*8 + row_id] = u0;
- btemp[COMP_ID][BLOCK_ID][1*8 + row_id] = u1;
- btemp[COMP_ID][BLOCK_ID][2*8 + row_id] = u2;
- btemp[COMP_ID][BLOCK_ID][3*8 + row_id] = u3;
- btemp[COMP_ID][BLOCK_ID][4*8 + row_id] = u4;
- btemp[COMP_ID][BLOCK_ID][5*8 + row_id] = u5;
- btemp[COMP_ID][BLOCK_ID][6*8 + row_id] = u6;
- btemp[COMP_ID][BLOCK_ID][7*8 + row_id] = u7;
-}
-
-void idct8_vert(const uint row_id)
-{
- float t0, t1, t2, t3, t4, t5, t6, t7, u8;
- float u0, u1, u2, u3, u4, u5, u6, u7;
-
- /* Input */
- t0 = btemp[COMP_ID][BLOCK_ID][8*row_id + 0] + 0.5f; // NOTE
- u4 = btemp[COMP_ID][BLOCK_ID][8*row_id + 1];
- t2 = btemp[COMP_ID][BLOCK_ID][8*row_id + 2];
- u6 = btemp[COMP_ID][BLOCK_ID][8*row_id + 3];
- t1 = btemp[COMP_ID][BLOCK_ID][8*row_id + 4];
- u5 = btemp[COMP_ID][BLOCK_ID][8*row_id + 5];
- t3 = btemp[COMP_ID][BLOCK_ID][8*row_id + 6];
- u7 = btemp[COMP_ID][BLOCK_ID][8*row_id + 7];
-
- /* Embedded scaled inverse 4-point Type-II DCT */
- u0 = t0 + t1;
- u1 = t0 - t1;
- u3 = t2 + t3;
- u2 = (t2 - t3)*(1.4142135623730950488016887242097f) - u3;
- t0 = u0 + u3;
- t3 = u0 - u3;
- t1 = u1 + u2;
- t2 = u1 - u2;
-
- /* Embedded scaled inverse 4-point Type-IV DST */
- t5 = u5 + u6;
- t6 = u5 - u6;
- t7 = u4 + u7;
- t4 = u4 - u7;
- u7 = t7 + t5;
- u5 = (t7 - t5)*(1.4142135623730950488016887242097f);
- u8 = (t4 + t6)*(1.8477590650225735122563663787936f);
- u4 = u8 - t4*(1.0823922002923939687994464107328f);
- u6 = u8 - t6*(2.6131259297527530557132863468544f);
- t7 = u7;
- t6 = t7 - u6;
- t5 = t6 + u5;
- t4 = t5 - u4;
-
- /* Butterflies */
- u0 = t0 + t7;
- u7 = t0 - t7;
- u6 = t1 + t6;
- u1 = t1 - t6;
- u2 = t2 + t5;
- u5 = t2 - t5;
- u4 = t3 + t4;
- u3 = t3 - t4;
-
- /* Output */
- block[COMP_ID][BLOCK_ID][0*8 + row_id] = u0;
- block[COMP_ID][BLOCK_ID][1*8 + row_id] = u1;
- block[COMP_ID][BLOCK_ID][2*8 + row_id] = u2;
- block[COMP_ID][BLOCK_ID][3*8 + row_id] = u3;
- block[COMP_ID][BLOCK_ID][4*8 + row_id] = u4;
- block[COMP_ID][BLOCK_ID][5*8 + row_id] = u5;
- block[COMP_ID][BLOCK_ID][6*8 + row_id] = u6;
- block[COMP_ID][BLOCK_ID][7*8 + row_id] = u7;
-}
-
-int16_t get_value(int16_t codebook)
-{
- const int16_t switch_bits = codebook >> 8;
- const int16_t rice_order = codebook & I16(0xf);
- const int16_t exp_order = (codebook >> 4) & I16(0xf);
-
- uint32_t b = show_bits(gb, 32);
- if (expectEXT(b == 0, false))
- return I16(0);
- int16_t q = I16(31) - I16(findMSB(b));
-
- if ((b & 0x80000000) != 0) {
- skip_bits(gb, 1 + rice_order);
- return I16((b & 0x7FFFFFFF) >> (31 - rice_order));
- }
-
- if (q <= switch_bits) {
- skip_bits(gb, q + rice_order + 1);
- return I16((q << rice_order) +
- (((b << (q + 1)) >> 1) >> (31 - rice_order)));
- }
-
- int16_t bits = exp_order + (q << 1) - switch_bits;
- skip_bits(gb, bits);
- return I16((b >> (32 - bits)) +
- ((switch_bits + 1) << rice_order) -
- (1 << exp_order));
-}
-
-#define TODCCODEBOOK(x) ((x + 1) >> 1)
-
-void read_dc_vals(const uint nb_blocks)
-{
- int16_t dc, dc_add;
- int16_t prev_dc = I16(0), sign = I16(0);
-
- /* Special handling for first block */
- dc = get_value(I16(700));
- prev_dc = (dc >> 1) ^ -(dc & I16(1));
- btemp[COMP_ID][0][0] = prev_dc;
-
- for (uint n = 1; n < nb_blocks; n++) {
- if (expectEXT(left_bits(gb) <= 0, false))
- break;
-
- uint8_t dc_codebook;
- if ((n & 15) == 1)
- dc_codebook = uint8_t(100);
- else
- dc_codebook = dc_cb[min(TODCCODEBOOK(dc), 13 - 1)];
-
- dc = get_value(dc_codebook);
-
- sign = sign ^ dc & int16_t(1);
- dc_add = (-sign ^ I16(TODCCODEBOOK(dc))) + sign;
- sign = I16(dc_add < 0);
- prev_dc += dc_add;
-
- btemp[COMP_ID][n][0] = prev_dc;
- }
-}
-
-void read_ac_vals(const uint nb_blocks)
-{
- const uint nb_codes = nb_blocks << 6;
- const uint log2_nb_blocks = findMSB(nb_blocks);
- const uint block_mask = (1 << log2_nb_blocks) - 1;
-
- int16_t ac, rn, ln;
- int16_t ac_codebook = I16(49);
- int16_t rn_codebook = I16( 0);
- int16_t ln_codebook = I16(66);
- int16_t sign;
- int16_t val;
-
- for (uint n = nb_blocks; n <= nb_codes;) {
- if (expectEXT(left_bits(gb) <= 0, false))
- break;
-
- ln = get_value(ln_codebook);
- for (uint i = 0; i < ln; i++) {
- if (expectEXT(left_bits(gb) <= 0, false))
- break;
-
- if (expectEXT(n >= nb_codes, false))
- break;
-
- ac = get_value(ac_codebook);
- ac_codebook = ac_cb[min(ac, 95 - 1)];
- sign = -int16_t(get_bit(gb));
-
- val = ((ac + I16(1)) ^ sign) - sign;
- btemp[COMP_ID][n & block_mask][n >> log2_nb_blocks] = val;
-
- n++;
- }
-
- if (expectEXT(n >= nb_codes, false))
- break;
-
- rn = get_value(rn_codebook);
- rn_codebook = rn_cb[min(rn, 28 - 1)];
-
- n += rn + 1;
- if (expectEXT(n >= nb_codes, false))
- break;
-
- if (expectEXT(left_bits(gb) <= 0, false))
- break;
-
- ac = get_value(ac_codebook);
- sign = -int16_t(get_bit(gb));
-
- val = ((ac + I16(1)) ^ sign) - sign;
- btemp[COMP_ID][n & block_mask][n >> log2_nb_blocks] = val;
-
- ac_codebook = ac_cb[min(ac, 95 - 1)];
- ln_codebook = ln_cb[min(ac, 15 - 1)];
-
- n++;
- }
-}
-
-void main(void)
-{
- const uint tile_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x;
- TileData td = tile_data[tile_idx];
-
- if (expectEXT(td.pos.x >= frame_size.x, false))
- return;
-
- uint64_t pkt_offset = uint64_t(pkt_data) + td.offset;
- u8vec2buf hdr_data = u8vec2buf(pkt_offset);
- float qscale = float(pack16(hdr_data[0].v.yx)) / 2.0f;
-
- ivec4 size = ivec4(td.size,
- pack16(hdr_data[2].v.yx),
- pack16(hdr_data[1].v.yx),
- pack16(hdr_data[3].v.yx));
- size[0] = size[0] - size[1] - size[2] - size[3] - 8;
- if (expectEXT(size[0] < 0, false))
- return;
-
- const ivec2 offs = td.pos + ivec2(COMP_ID & 1, COMP_ID >> 1);
- const uint w = min(tile_size.x, frame_size.x - td.pos.x) / 2;
- const uint nb_blocks = w / 8;
-
- const ivec4 comp_offset = ivec4(size[2] + size[1] + size[3],
- size[2],
- 0,
- size[2] + size[1]);
-
- if (BLOCK_ID == 0 && ROW_ID == 0) {
- init_get_bits(gb, u8buf(pkt_offset + 8 + comp_offset[COMP_ID]),
- size[COMP_ID]);
- read_dc_vals(nb_blocks);
- read_ac_vals(nb_blocks);
- }
-
- barrier();
-
- [[unroll]]
- for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x)
- block[COMP_ID][BLOCK_ID][i] = (btemp[COMP_ID][BLOCK_ID][scan[i]] / 16384.0) *
- (float(qmat[i]) / 295.0) *
- idct_8x8_scales[i] * qscale;
-
- barrier();
-
-#ifdef PARALLEL_ROWS
- idct8_horiz(ROW_ID);
-
- barrier();
-
- idct8_vert(ROW_ID);
-#else
- for (uint j = 0; j < 8; j++)
- idct8_horiz(j);
-
- barrier();
-
- for (uint j = 0; j < 8; j++)
- idct8_vert(j);
-#endif
-
- barrier();
-
- [[unroll]]
- for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x)
- imageStore(dst,
- offs + 2*ivec2(BLOCK_ID*8 + (i & 7), i >> 3),
- vec4(block[COMP_ID][BLOCK_ID][i]));
-}
diff --git a/libavcodec/vulkan/prores_raw_decode.comp b/libavcodec/vulkan/prores_raw_decode.comp
new file mode 100644
index 0000000000..08447e3961
--- /dev/null
+++ b/libavcodec/vulkan/prores_raw_decode.comp
@@ -0,0 +1,232 @@
+/*
+ * ProRes RAW decoder
+ *
+ * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define U8(x) (uint8_t(x))
+#define I16(x) (int16_t(x))
+
+#define COMP_ID (gl_LocalInvocationID.x)
+
+GetBitContext gb;
+
+#define DC_CB_MAX 12
+const uint8_t dc_cb[DC_CB_MAX + 1] = {
+ U8(16), U8(33), U8(50), U8(51), U8(51), U8(51),
+ U8(68), U8(68), U8(68), U8(68), U8(68), U8(68), U8(118)
+};
+
+#define AC_CB_MAX 94
+const int16_t ac_cb[AC_CB_MAX + 1] = {
+ I16( 0), I16(529), I16(273), I16(273), I16(546), I16(546),
+ I16(546), I16(290), I16(290), I16(290), I16(563), I16(563),
+ I16(563), I16(563), I16(563), I16(563), I16(563), I16(563),
+ I16(307), I16(307), I16(580), I16(580), I16(580), I16(580),
+ I16(580), I16(580), I16(580), I16(580), I16(580), I16(580),
+ I16(580), I16(580), I16(580), I16(580), I16(580), I16(580),
+ I16(580), I16(580), I16(580), I16(580), I16(580), I16(580),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(853), I16(853),
+ I16(853), I16(853), I16(853), I16(853), I16(358)
+};
+
+#define RN_CB_MAX 27
+const int16_t rn_cb[RN_CB_MAX + 1] = {
+ I16(512), I16(256), I16( 0), I16( 0), I16(529), I16(529), I16(273),
+ I16(273), I16( 17), I16( 17), I16( 33), I16( 33), I16(546), I16( 34),
+ I16( 34), I16( 34), I16( 34), I16( 34), I16( 34), I16( 34), I16( 34),
+ I16( 34), I16( 34), I16( 34), I16( 34), I16( 50), I16( 50), I16( 68),
+};
+
+#define LN_CB_MAX 14
+const int16_t ln_cb[LN_CB_MAX + 1] = {
+ I16( 256), I16( 273), I16( 546), I16( 546), I16( 290), I16( 290), I16( 1075),
+ I16(1075), I16( 563), I16( 563), I16( 563), I16( 563), I16( 563), I16( 563),
+ I16( 51)
+};
+
+int16_t get_value(int16_t codebook)
+{
+ const int16_t switch_bits = codebook >> 8;
+ const int16_t rice_order = codebook & I16(0xf);
+ const int16_t exp_order = (codebook >> 4) & I16(0xf);
+
+ uint32_t b = show_bits(gb, 32);
+ if (expectEXT(b == 0, false))
+ return I16(0);
+ int16_t q = I16(31) - I16(findMSB(b));
+
+ if ((b & 0x80000000) != 0) {
+ skip_bits(gb, 1 + rice_order);
+ return I16((b & 0x7FFFFFFF) >> (31 - rice_order));
+ }
+
+ if (q <= switch_bits) {
+ skip_bits(gb, q + rice_order + 1);
+ return I16((q << rice_order) +
+ (((b << (q + 1)) >> 1) >> (31 - rice_order)));
+ }
+
+ int16_t bits = exp_order + (q << 1) - switch_bits;
+ skip_bits(gb, bits);
+ return I16((b >> (32 - bits)) +
+ ((switch_bits + 1) << rice_order) -
+ (1 << exp_order));
+}
+
+#define TODCCODEBOOK(x) ((x + 1) >> 1)
+
+void store_val(ivec2 offs, int blk, int c, int16_t v)
+{
+ imageStore(dst, offs + 2*ivec2(blk*8 + (c & 7), c >> 3), ivec4(v));
+}
+
+void read_dc_vals(ivec2 offs, int nb_blocks)
+{
+ int16_t dc, dc_add;
+ int16_t prev_dc = I16(0), sign = I16(0);
+
+ /* Special handling for first block */
+ dc = get_value(I16(700));
+ prev_dc = (dc >> 1) ^ -(dc & I16(1));
+ store_val(offs, 0, 0, prev_dc);
+
+ for (int n = 1; n < nb_blocks; n++) {
+ if (expectEXT(left_bits(gb) <= 0, false))
+ break;
+
+ uint8_t dc_codebook;
+ if ((n & 15) == 1)
+ dc_codebook = uint8_t(100);
+ else
+ dc_codebook = dc_cb[min(TODCCODEBOOK(dc), 13 - 1)];
+
+ dc = get_value(dc_codebook);
+
+ sign = sign ^ dc & int16_t(1);
+ dc_add = (-sign ^ I16(TODCCODEBOOK(dc))) + sign;
+ sign = I16(dc_add < 0);
+ prev_dc += dc_add;
+
+ store_val(offs, n, 0, prev_dc);
+ }
+}
+
+void read_ac_vals(ivec2 offs, int nb_blocks)
+{
+ const int nb_codes = nb_blocks << 6;
+ const int log2_nb_blocks = findMSB(nb_blocks);
+ const int block_mask = (1 << log2_nb_blocks) - 1;
+
+ int16_t ac, rn, ln;
+ int16_t ac_codebook = I16(49);
+ int16_t rn_codebook = I16( 0);
+ int16_t ln_codebook = I16(66);
+ int16_t sign;
+ int16_t val;
+
+ for (int n = nb_blocks; n <= nb_codes;) {
+ if (expectEXT(left_bits(gb) <= 0, false))
+ break;
+
+ ln = get_value(ln_codebook);
+ for (int i = 0; i < ln; i++) {
+ if (expectEXT(left_bits(gb) <= 0, false))
+ break;
+
+ if (expectEXT(n >= nb_codes, false))
+ break;
+
+ ac = get_value(ac_codebook);
+ ac_codebook = ac_cb[min(ac, 95 - 1)];
+ sign = -int16_t(get_bit(gb));
+
+ val = ((ac + I16(1)) ^ sign) - sign;
+ store_val(offs, n & block_mask, n >> log2_nb_blocks, val);
+
+ n++;
+ }
+
+ if (expectEXT(n >= nb_codes, false))
+ break;
+
+ rn = get_value(rn_codebook);
+ rn_codebook = rn_cb[min(rn, 28 - 1)];
+
+ n += rn + 1;
+ if (expectEXT(n >= nb_codes, false))
+ break;
+
+ if (expectEXT(left_bits(gb) <= 0, false))
+ break;
+
+ ac = get_value(ac_codebook);
+ sign = -int16_t(get_bit(gb));
+
+ val = ((ac + I16(1)) ^ sign) - sign;
+ store_val(offs, n & block_mask, n >> log2_nb_blocks, val);
+
+ ac_codebook = ac_cb[min(ac, 95 - 1)];
+ ln_codebook = ln_cb[min(ac, 15 - 1)];
+
+ n++;
+ }
+}
+
+void main(void)
+{
+ const uint tile_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x;
+ TileData td = tile_data[tile_idx];
+
+ if (expectEXT(td.pos.x >= frame_size.x, false))
+ return;
+
+ uint64_t pkt_offset = uint64_t(pkt_data) + td.offset;
+ u8vec2buf hdr_data = u8vec2buf(pkt_offset);
+
+ ivec4 size = ivec4(td.size,
+ pack16(hdr_data[2].v.yx),
+ pack16(hdr_data[1].v.yx),
+ pack16(hdr_data[3].v.yx));
+ size[0] = size[0] - size[1] - size[2] - size[3] - 8;
+ if (expectEXT(size[0] < 0, false))
+ return;
+
+ const ivec2 offs = td.pos + ivec2(COMP_ID & 1, COMP_ID >> 1);
+ const int w = min(tile_size.x, frame_size.x - td.pos.x) / 2;
+ const int nb_blocks = w / 8;
+
+ const ivec4 comp_offset = ivec4(size[2] + size[1] + size[3],
+ size[2],
+ 0,
+ size[2] + size[1]);
+
+ init_get_bits(gb, u8buf(pkt_offset + 8 + comp_offset[COMP_ID]),
+ size[COMP_ID]);
+
+ read_dc_vals(offs, nb_blocks);
+ read_ac_vals(offs, nb_blocks);
+}
diff --git a/libavcodec/vulkan/prores_raw_idct.comp b/libavcodec/vulkan/prores_raw_idct.comp
new file mode 100644
index 0000000000..e692792301
--- /dev/null
+++ b/libavcodec/vulkan/prores_raw_idct.comp
@@ -0,0 +1,168 @@
+/*
+ * ProRes RAW decoder
+ *
+ * Copyright (c) 2025 Lynne <dev(a)lynne.ee>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define COMP_ID (gl_LocalInvocationID.z)
+#define BLOCK_ID (gl_LocalInvocationID.y)
+#define ROW_ID (gl_LocalInvocationID.x)
+
+shared float blocks[16][4*64];
+
+const ivec2 scan[64] = {
+ ivec2( 0, 0), ivec2( 4, 0), ivec2( 0, 2), ivec2( 4, 2),
+ ivec2( 0, 8), ivec2( 4, 8), ivec2( 6, 8), ivec2( 2, 10),
+ ivec2( 2, 0), ivec2( 6, 0), ivec2( 2, 2), ivec2( 6, 2),
+ ivec2( 2, 8), ivec2( 8, 8), ivec2( 0, 10), ivec2( 4, 10),
+ ivec2( 8, 0), ivec2(12, 0), ivec2( 8, 2), ivec2(12, 2),
+ ivec2(10, 8), ivec2(14, 8), ivec2( 6, 10), ivec2( 2, 12),
+ ivec2(10, 0), ivec2(14, 0), ivec2(10, 2), ivec2(14, 2),
+ ivec2(12, 8), ivec2( 8, 10), ivec2( 0, 12), ivec2( 4, 12),
+ ivec2( 0, 4), ivec2( 4, 4), ivec2( 6, 4), ivec2( 2, 6),
+ ivec2(10, 10), ivec2(14, 10), ivec2( 6, 12), ivec2( 2, 14),
+ ivec2( 2, 4), ivec2( 8, 4), ivec2( 0, 6), ivec2( 4, 6),
+ ivec2(12, 10), ivec2( 8, 12), ivec2( 0, 14), ivec2( 4, 14),
+ ivec2(10, 4), ivec2(14, 4), ivec2( 6, 6), ivec2(12, 6),
+ ivec2(10, 12), ivec2(14, 12), ivec2( 6, 14), ivec2(12, 14),
+ ivec2(12, 4), ivec2( 8, 6), ivec2(10, 6), ivec2(14, 6),
+ ivec2(12, 12), ivec2( 8, 14), ivec2(10, 14), ivec2(14, 14),
+};
+
+const float idct_scale[64] = {
+ 0.1250000000000000, 0.1733799806652684, 0.1633203706095471, 0.1469844503024199,
+ 0.1250000000000000, 0.0982118697983878, 0.0676495125182746, 0.0344874224103679,
+ 0.1733799806652684, 0.2404849415639108, 0.2265318615882219, 0.2038732892122293,
+ 0.1733799806652684, 0.1362237766939547, 0.0938325693794663, 0.0478354290456362,
+ 0.1633203706095471, 0.2265318615882219, 0.2133883476483184, 0.1920444391778541,
+ 0.1633203706095471, 0.1283199917898342, 0.0883883476483185, 0.0450599888754343,
+ 0.1469844503024199, 0.2038732892122293, 0.1920444391778541, 0.1728354290456362,
+ 0.1469844503024199, 0.1154849415639109, 0.0795474112858021, 0.0405529186026822,
+ 0.1250000000000000, 0.1733799806652684, 0.1633203706095471, 0.1469844503024199,
+ 0.1250000000000000, 0.0982118697983878, 0.0676495125182746, 0.0344874224103679,
+ 0.0982118697983878, 0.1362237766939547, 0.1283199917898342, 0.1154849415639109,
+ 0.0982118697983878, 0.0771645709543638, 0.0531518809229535, 0.0270965939155924,
+ 0.0676495125182746, 0.0938325693794663, 0.0883883476483185, 0.0795474112858021,
+ 0.0676495125182746, 0.0531518809229535, 0.0366116523516816, 0.0186644585125857,
+ 0.0344874224103679, 0.0478354290456362, 0.0450599888754343, 0.0405529186026822,
+ 0.0344874224103679, 0.0270965939155924, 0.0186644585125857, 0.0095150584360892,
+};
+
+void idct8(uint block, uint offset, uint stride)
+{
+ float t0, t1, t2, t3, t4, t5, t6, t7, u8;
+ float u0, u1, u2, u3, u4, u5, u6, u7;
+
+ /* Input */
+ t0 = blocks[block][0*stride + offset];
+ u4 = blocks[block][1*stride + offset];
+ t2 = blocks[block][2*stride + offset];
+ u6 = blocks[block][3*stride + offset];
+ t1 = blocks[block][4*stride + offset];
+ u5 = blocks[block][5*stride + offset];
+ t3 = blocks[block][6*stride + offset];
+ u7 = blocks[block][7*stride + offset];
+
+ /* Embedded scaled inverse 4-point Type-II DCT */
+ u0 = t0 + t1;
+ u1 = t0 - t1;
+ u3 = t2 + t3;
+ u2 = (t2 - t3)*(1.4142135623730950488016887242097f) - u3;
+ t0 = u0 + u3;
+ t3 = u0 - u3;
+ t1 = u1 + u2;
+ t2 = u1 - u2;
+
+ /* Embedded scaled inverse 4-point Type-IV DST */
+ t5 = u5 + u6;
+ t6 = u5 - u6;
+ t7 = u4 + u7;
+ t4 = u4 - u7;
+ u7 = t7 + t5;
+ u5 = (t7 - t5)*(1.4142135623730950488016887242097f);
+ u8 = (t4 + t6)*(1.8477590650225735122563663787936f);
+ u4 = u8 - t4*(1.0823922002923939687994464107328f);
+ u6 = u8 - t6*(2.6131259297527530557132863468544f);
+ t7 = u7;
+ t6 = t7 - u6;
+ t5 = t6 + u5;
+ t4 = t5 - u4;
+
+ /* Butterflies */
+ u0 = t0 + t7;
+ u7 = t0 - t7;
+ u6 = t1 + t6;
+ u1 = t1 - t6;
+ u2 = t2 + t5;
+ u5 = t2 - t5;
+ u4 = t3 + t4;
+ u3 = t3 - t4;
+
+ /* Output */
+ blocks[block][0*stride + offset] = u0;
+ blocks[block][1*stride + offset] = u1;
+ blocks[block][2*stride + offset] = u2;
+ blocks[block][3*stride + offset] = u3;
+ blocks[block][4*stride + offset] = u4;
+ blocks[block][5*stride + offset] = u5;
+ blocks[block][6*stride + offset] = u6;
+ blocks[block][7*stride + offset] = u7;
+}
+
+void main(void)
+{
+ const uint tile_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x;
+ TileData td = tile_data[tile_idx];
+
+ if (expectEXT(td.pos.x >= frame_size.x, false))
+ return;
+
+ uint64_t pkt_offset = uint64_t(pkt_data) + td.offset;
+ u8vec2buf hdr_data = u8vec2buf(pkt_offset);
+ float qscale = float(pack16(hdr_data[0].v.yx)) / 2.0f;
+
+ const ivec2 offs = td.pos + ivec2(COMP_ID & 1, COMP_ID >> 1);
+ const uint w = min(tile_size.x, frame_size.x - td.pos.x) / 2;
+ const uint nb_blocks = w / 8;
+
+ [[unroll]]
+ for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x) {
+ int16_t v = int16_t(imageLoad(dst, offs + 2*ivec2(BLOCK_ID*8, 0) + scan[i])[0]);
+ blocks[BLOCK_ID][COMP_ID*64 + i] = (v / 16384.0) *
+ (float(qmat[i]) / 295.0) *
+ idct_scale[i] * qscale;
+ }
+
+ barrier();
+ idct8(BLOCK_ID, COMP_ID*64 + ROW_ID*8, 1);
+
+ blocks[BLOCK_ID][COMP_ID*64 + ROW_ID] += 0.5;
+
+ barrier();
+ idct8(BLOCK_ID, COMP_ID*64 + ROW_ID, 8);
+
+ barrier();
+ [[unroll]]
+ for (uint i = gl_LocalInvocationID.x; i < 64; i += gl_WorkGroupSize.x) {
+ int v = int(round(blocks[BLOCK_ID][COMP_ID*64 + i]*16384.0));
+ imageStore(dst,
+ offs + 2*ivec2(BLOCK_ID*8 + (i & 7), i >> 3),
+ ivec4(v));
+ }
+}
diff --git a/libavcodec/vulkan_prores_raw.c b/libavcodec/vulkan_prores_raw.c
index 78bbddc614..3b6d617eec 100644
--- a/libavcodec/vulkan_prores_raw.c
+++ b/libavcodec/vulkan_prores_raw.c
@@ -26,7 +26,8 @@
#include "libavutil/mem.h"
extern const char *ff_source_common_comp;
-extern const char *ff_source_prores_raw_comp;
+extern const char *ff_source_prores_raw_decode_comp;
+extern const char *ff_source_prores_raw_idct_comp;
const FFVulkanDecodeDescriptor ff_vk_dec_prores_raw_desc = {
.codec_id = AV_CODEC_ID_PRORES_RAW,
@@ -43,17 +44,16 @@ typedef struct ProResRAWVulkanDecodePicture {
typedef struct ProResRAWVulkanDecodeContext {
FFVulkanShader decode;
+ FFVulkanShader idct;
AVBufferPool *tile_data_pool;
-
- FFVkBuffer uniform_buf;
} ProResRAWVulkanDecodeContext;
typedef struct DecodePushData {
VkDeviceAddress tile_data;
VkDeviceAddress pkt_data;
- uint32_t frame_size[2];
- uint32_t tile_size[2];
+ int32_t frame_size[2];
+ int32_t tile_size[2];
uint8_t qmat[64];
} DecodePushData;
@@ -97,7 +97,7 @@ static int vk_prores_raw_start_frame(AVCodecContext *avctx,
/* Prepare frame to be used */
err = ff_vk_decode_prepare_frame_sdr(dec, prr->frame, vp, 1,
- FF_VK_REP_FLOAT, 0);
+ FF_VK_REP_INT, 0);
if (err < 0)
return err;
@@ -173,9 +173,13 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
RET(ff_vk_exec_add_dep_buf(&ctx->s, exec, &vp->slices_buf, 1, 0));
vp->slices_buf = NULL;
+ AVVkFrame *vkf = (AVVkFrame *)prr->frame->data[0];
+ vkf->layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
+ vkf->access[0] = VK_ACCESS_2_NONE;
+
ff_vk_frame_barrier(&ctx->s, exec, prr->frame, img_bar, &nb_img_bar,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
- VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
+ VK_PIPELINE_STAGE_2_CLEAR_BIT,
VK_ACCESS_2_TRANSFER_WRITE_BIT,
VK_IMAGE_LAYOUT_GENERAL,
VK_QUEUE_FAMILY_IGNORED);
@@ -187,6 +191,29 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
});
nb_img_bar = 0;
+ vk->CmdClearColorImage(exec->buf, vkf->img[0],
+ VK_IMAGE_LAYOUT_GENERAL,
+ &((VkClearColorValue) { 0 }),
+ 1, &((VkImageSubresourceRange) {
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .levelCount = 1,
+ .layerCount = 1,
+ }));
+
+ ff_vk_frame_barrier(&ctx->s, exec, prr->frame, img_bar, &nb_img_bar,
+ VK_PIPELINE_STAGE_2_CLEAR_BIT,
+ VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
+ VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
+ VK_IMAGE_LAYOUT_GENERAL,
+ VK_QUEUE_FAMILY_IGNORED);
+
+ vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
+ .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
+ .pImageMemoryBarriers = img_bar,
+ .imageMemoryBarrierCount = nb_img_bar,
+ });
+ nb_img_bar = 0;
+
FFVulkanShader *decode_shader = &prv->decode;
ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
prr->frame, vp->view.out,
@@ -212,6 +239,34 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
vk->CmdDispatch(exec->buf, prr->nb_tw, prr->nb_th, 1);
+ ff_vk_frame_barrier(&ctx->s, exec, prr->frame, img_bar, &nb_img_bar,
+ VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
+ VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
+ VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
+ VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
+ VK_IMAGE_LAYOUT_GENERAL,
+ VK_QUEUE_FAMILY_IGNORED);
+
+ FFVulkanShader *idct_shader = &prv->idct;
+ ff_vk_shader_update_img_array(&ctx->s, exec, idct_shader,
+ prr->frame, vp->view.out,
+ 0, 0,
+ VK_IMAGE_LAYOUT_GENERAL,
+ VK_NULL_HANDLE);
+ ff_vk_exec_bind_shader(&ctx->s, exec, idct_shader);
+ ff_vk_shader_update_push_const(&ctx->s, exec, idct_shader,
+ VK_SHADER_STAGE_COMPUTE_BIT,
+ 0, sizeof(pd_decode), &pd_decode);
+
+ vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
+ .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
+ .pImageMemoryBarriers = img_bar,
+ .imageMemoryBarrierCount = nb_img_bar,
+ });
+ nb_img_bar = 0;
+
+ vk->CmdDispatch(exec->buf, prr->nb_tw, prr->nb_th, 1);
+
err = ff_vk_exec_submit(&ctx->s, exec);
if (err < 0)
return err;
@@ -220,34 +275,11 @@ fail:
return 0;
}
-static int init_decode_shader(ProResRAWContext *prr, FFVulkanContext *s,
- FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
- FFVulkanShader *shd, int version)
+static int add_common_data(AVCodecContext *avctx, FFVulkanContext *s,
+ FFVulkanShader *shd, int writeonly)
{
- int err;
- FFVulkanDescriptorSetBinding *desc_set;
- int parallel_rows = 1;
-
- uint8_t *spv_data;
- size_t spv_len;
- void *spv_opaque = NULL;
-
- if (s->props.properties.limits.maxComputeWorkGroupInvocations < 512 ||
- s->props.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
- parallel_rows = 0;
-
- RET(ff_vk_shader_init(s, shd, "prores_raw",
- VK_SHADER_STAGE_COMPUTE_BIT,
- (const char *[]) { "GL_EXT_buffer_reference",
- "GL_EXT_buffer_reference2",
- "GL_EXT_null_initializer" }, 3,
- parallel_rows ? 8 : 1 /* 8x8 transforms, 8-point width */,
- version == 0 ? 8 : 16 /* Horizontal blocks */,
- 4 /* Components */,
- 0));
-
- if (parallel_rows)
- GLSLC(0, #define PARALLEL_ROWS );
+ AVHWFramesContext *dec_frames_ctx;
+ dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
/* Common codec header */
GLSLD(ff_source_common_comp);
@@ -261,73 +293,84 @@ static int init_decode_shader(ProResRAWContext *prr, FFVulkanContext *s,
GLSLC(0, layout(push_constant, scalar) uniform pushConstants { );
GLSLC(1, TileData tile_data; );
GLSLC(1, u8buf pkt_data; );
- GLSLC(1, uvec2 frame_size; );
- GLSLC(1, uvec2 tile_size; );
+ GLSLC(1, ivec2 frame_size; );
+ GLSLC(1, ivec2 tile_size; );
GLSLC(1, uint8_t qmat[64]; );
GLSLC(0, }; );
GLSLC(0, );
ff_vk_shader_add_push_const(shd, 0, sizeof(DecodePushData),
VK_SHADER_STAGE_COMPUTE_BIT);
+ FFVulkanDescriptorSetBinding *desc_set;
desc_set = (FFVulkanDescriptorSetBinding []) {
{
.name = "dst",
.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
- .mem_layout = "r16",
- .mem_quali = "writeonly",
+ .mem_layout = ff_vk_shader_rep_fmt(dec_frames_ctx->sw_format,
+ FF_VK_REP_INT),
+ .mem_quali = writeonly ? "writeonly" : NULL,
.dimensions = 2,
.stages = VK_SHADER_STAGE_COMPUTE_BIT,
},
};
- RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 1, 0, 0));
- desc_set = (FFVulkanDescriptorSetBinding []) {
- {
- .name = "dct_scale_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "float idct_8x8_scales[64];",
- },
- {
- .name = "scan_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "uint8_t scan[64];",
- },
- {
- .name = "dc_cb_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "uint8_t dc_cb[13];",
- },
- {
- .name = "ac_cb_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "int16_t ac_cb[95];",
- },
- {
- .name = "rn_cb_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "int16_t rn_cb[28];",
- },
- {
- .name = "ln_cb_buf",
- .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_layout = "scalar",
- .buf_content = "int16_t ln_cb[15];",
- },
- };
- RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 6, 1, 0));
+ return ff_vk_shader_add_descriptor_set(s, shd, desc_set, 1, 0, 0);
+}
+
+static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s,
+ FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
+ FFVulkanShader *shd, int version)
+{
+ int err;
+ uint8_t *spv_data;
+ size_t spv_len;
+ void *spv_opaque = NULL;
- GLSLD(ff_source_prores_raw_comp);
+ RET(ff_vk_shader_init(s, shd, "prores_raw",
+ VK_SHADER_STAGE_COMPUTE_BIT,
+ (const char *[]) { "GL_EXT_buffer_reference",
+ "GL_EXT_buffer_reference2",
+ "GL_EXT_null_initializer" }, 3,
+ 4, 1, 1, 0));
+
+ RET(add_common_data(avctx, s, shd, 1));
+
+ GLSLD(ff_source_prores_raw_decode_comp);
+
+ RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
+ &spv_opaque));
+ RET(ff_vk_shader_link(s, shd, spv_data, spv_len, "main"));
+
+ RET(ff_vk_shader_register_exec(s, pool, shd));
+
+fail:
+ if (spv_opaque)
+ spv->free_shader(spv, &spv_opaque);
+
+ return err;
+}
+
+static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s,
+ FFVkExecPool *pool, FFVkSPIRVCompiler *spv,
+ FFVulkanShader *shd, int version)
+{
+ int err;
+ uint8_t *spv_data;
+ size_t spv_len;
+ void *spv_opaque = NULL;
+
+ RET(ff_vk_shader_init(s, shd, "prores_raw",
+ VK_SHADER_STAGE_COMPUTE_BIT,
+ (const char *[]) { "GL_EXT_buffer_reference",
+ "GL_EXT_buffer_reference2" }, 2,
+ 8,
+ version == 0 ? 8 : 16 /* Horizontal blocks */,
+ 4 /* Components */,
+ 0));
+
+ RET(add_common_data(avctx, s, shd, 0));
+
+ GLSLD(ff_source_prores_raw_idct_comp);
RET(spv->compile_shader(s, spv, shd, &spv_data, &spv_len, "main",
&spv_opaque));
@@ -347,8 +390,7 @@ static void vk_decode_prores_raw_uninit(FFVulkanDecodeShared *ctx)
ProResRAWVulkanDecodeContext *fv = ctx->sd_ctx;
ff_vk_shader_free(&ctx->s, &fv->decode);
-
- ff_vk_free_buf(&ctx->s, &fv->uniform_buf);
+ ff_vk_shader_free(&ctx->s, &fv->idct);
av_buffer_pool_uninit(&fv->tile_data_pool);
@@ -381,87 +423,10 @@ static int vk_decode_prores_raw_init(AVCodecContext *avctx)
ctx->sd_ctx_free = &vk_decode_prores_raw_uninit;
/* Setup decode shader */
- RET(init_decode_shader(prr, &ctx->s, &ctx->exec_pool, spv, &prv->decode,
+ RET(init_decode_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &prv->decode,
prr->version));
-
- /* Size in bytes of each codebook table */
- size_t cb_size[5] = {
- 13*sizeof(uint8_t),
- 95*sizeof(int16_t),
- 28*sizeof(int16_t),
- 15*sizeof(int16_t),
- };
-
- /* Offset of each codebook table */
- size_t cb_offset[5];
- size_t ua = ctx->s.props.properties.limits.minUniformBufferOffsetAlignment;
- cb_offset[0] = 64*sizeof(float) + 64*sizeof(uint8_t);
- cb_offset[1] = cb_offset[0] + FFALIGN(cb_size[0], ua);
- cb_offset[2] = cb_offset[1] + FFALIGN(cb_size[1], ua);
- cb_offset[3] = cb_offset[2] + FFALIGN(cb_size[2], ua);
- cb_offset[4] = cb_offset[3] + FFALIGN(cb_size[3], ua);
-
- RET(ff_vk_create_buf(&ctx->s, &prv->uniform_buf,
- 64*sizeof(float) + 64*sizeof(uint8_t) + cb_offset[4] + 256,
- NULL, NULL,
- VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
- VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
-
- uint8_t *uniform_buf;
- RET(ff_vk_map_buffer(&ctx->s, &prv->uniform_buf, &uniform_buf, 0));
-
- /* DCT scales */
- float *dct_scale_buf = (float *)uniform_buf;
- double idct_8_scales[8] = {
- cos(4.0*M_PI/16.0) / 2.0,
- cos(1.0*M_PI/16.0) / 2.0,
- cos(2.0*M_PI/16.0) / 2.0,
- cos(3.0*M_PI/16.0) / 2.0,
- cos(4.0*M_PI/16.0) / 2.0,
- cos(5.0*M_PI/16.0) / 2.0,
- cos(6.0*M_PI/16.0) / 2.0,
- cos(7.0*M_PI/16.0) / 2.0,
- };
- for (int i = 0; i < 64; i++)
- dct_scale_buf[i] = (float)(idct_8_scales[i >> 3] *
- idct_8_scales[i & 7]);
-
- /* Scan table */
- uint8_t *scan_buf = uniform_buf + 64*sizeof(float);
- for (int i = 0; i < 64; i++)
- scan_buf[prr->scan[i]] = i;
-
- /* Codebooks */
- memcpy(uniform_buf + cb_offset[0], ff_prores_raw_dc_cb,
- sizeof(ff_prores_raw_dc_cb));
- memcpy(uniform_buf + cb_offset[1], ff_prores_raw_ac_cb,
- sizeof(ff_prores_raw_ac_cb));
- memcpy(uniform_buf + cb_offset[2], ff_prores_raw_rn_cb,
- sizeof(ff_prores_raw_rn_cb));
- memcpy(uniform_buf + cb_offset[3], ff_prores_raw_ln_cb,
- sizeof(ff_prores_raw_ln_cb));
-
- RET(ff_vk_unmap_buffer(&ctx->s, &prv->uniform_buf, 1));
-
- /* Done; update descriptors */
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode, 1, 0, 0,
- &prv->uniform_buf,
- 0, 64*sizeof(float),
- VK_FORMAT_UNDEFINED));
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode, 1, 1, 0,
- &prv->uniform_buf,
- 64*sizeof(float), 64*sizeof(uint8_t),
- VK_FORMAT_UNDEFINED));
- for (int j = 0; j < 4; j++)
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode, 1, 2 + j, 0,
- &prv->uniform_buf,
- cb_offset[j], cb_size[j],
- VK_FORMAT_UNDEFINED));
+ RET(init_idct_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &prv->idct,
+ prr->version));
fail:
spv->uninit(&spv);
commit 0c20edaa7ac63b56bb29ba8bfa5f6b4cb22aa418
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 23 20:10:11 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
vulkan_prores: initialize only the necessary shaders on init
diff --git a/libavcodec/vulkan_prores_raw.c b/libavcodec/vulkan_prores_raw.c
index 7a1f97a640..78bbddc614 100644
--- a/libavcodec/vulkan_prores_raw.c
+++ b/libavcodec/vulkan_prores_raw.c
@@ -42,7 +42,7 @@ typedef struct ProResRAWVulkanDecodePicture {
} ProResRAWVulkanDecodePicture;
typedef struct ProResRAWVulkanDecodeContext {
- FFVulkanShader decode[2];
+ FFVulkanShader decode;
AVBufferPool *tile_data_pool;
@@ -187,7 +187,7 @@ static int vk_prores_raw_end_frame(AVCodecContext *avctx)
});
nb_img_bar = 0;
- FFVulkanShader *decode_shader = &prv->decode[prr->version];
+ FFVulkanShader *decode_shader = &prv->decode;
ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader,
prr->frame, vp->view.out,
0, 0,
@@ -346,8 +346,7 @@ static void vk_decode_prores_raw_uninit(FFVulkanDecodeShared *ctx)
{
ProResRAWVulkanDecodeContext *fv = ctx->sd_ctx;
- ff_vk_shader_free(&ctx->s, &fv->decode[0]);
- ff_vk_shader_free(&ctx->s, &fv->decode[1]);
+ ff_vk_shader_free(&ctx->s, &fv->decode);
ff_vk_free_buf(&ctx->s, &fv->uniform_buf);
@@ -359,8 +358,8 @@ static void vk_decode_prores_raw_uninit(FFVulkanDecodeShared *ctx)
static int vk_decode_prores_raw_init(AVCodecContext *avctx)
{
int err;
- ProResRAWContext *prr = avctx->priv_data;
FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
+ ProResRAWContext *prr = avctx->priv_data;
FFVkSPIRVCompiler *spv = ff_vk_spirv_init();
if (!spv) {
@@ -382,8 +381,8 @@ static int vk_decode_prores_raw_init(AVCodecContext *avctx)
ctx->sd_ctx_free = &vk_decode_prores_raw_uninit;
/* Setup decode shader */
- RET(init_decode_shader(prr, &ctx->s, &ctx->exec_pool, spv, &prv->decode[0], 0));
- RET(init_decode_shader(prr, &ctx->s, &ctx->exec_pool, spv, &prv->decode[1], 1));
+ RET(init_decode_shader(prr, &ctx->s, &ctx->exec_pool, spv, &prv->decode,
+ prr->version));
/* Size in bytes of each codebook table */
size_t cb_size[5] = {
@@ -447,24 +446,22 @@ static int vk_decode_prores_raw_init(AVCodecContext *avctx)
RET(ff_vk_unmap_buffer(&ctx->s, &prv->uniform_buf, 1));
/* Done; update descriptors */
- for (int i = 0; i < 2; i++) {
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode[i], 1, 0, 0,
- &prv->uniform_buf,
- 0, 64*sizeof(float),
- VK_FORMAT_UNDEFINED));
+ RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
+ &prv->decode, 1, 0, 0,
+ &prv->uniform_buf,
+ 0, 64*sizeof(float),
+ VK_FORMAT_UNDEFINED));
+ RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
+ &prv->decode, 1, 1, 0,
+ &prv->uniform_buf,
+ 64*sizeof(float), 64*sizeof(uint8_t),
+ VK_FORMAT_UNDEFINED));
+ for (int j = 0; j < 4; j++)
RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode[i], 1, 1, 0,
+ &prv->decode, 1, 2 + j, 0,
&prv->uniform_buf,
- 64*sizeof(float), 64*sizeof(uint8_t),
+ cb_offset[j], cb_size[j],
VK_FORMAT_UNDEFINED));
- for (int j = 0; j < 4; j++)
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &prv->decode[i], 1, 2 + j, 0,
- &prv->uniform_buf,
- cb_offset[j], cb_size[j],
- VK_FORMAT_UNDEFINED));
- }
fail:
spv->uninit(&spv);
commit a160e4a9e204578e05c552a85a8502151f0a657c
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 23 20:11:58 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
prores_raw: call ff_get_format if the version changes
diff --git a/libavcodec/prores_raw.c b/libavcodec/prores_raw.c
index 7017480336..01f1bbd2fb 100644
--- a/libavcodec/prores_raw.c
+++ b/libavcodec/prores_raw.c
@@ -327,8 +327,8 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *frame, int *got_frame_ptr,
AVPacket *avpkt)
{
- int ret, dimensions_changed = 0;
ProResRAWContext *s = avctx->priv_data;
+ int ret, dimensions_changed = 0, old_version = s->version;
DECLARE_ALIGNED(32, uint8_t, qmat)[64];
memset(qmat, 1, 64);
@@ -395,7 +395,8 @@ static int decode_frame(AVCodecContext *avctx,
avctx->coded_height = FFALIGN(h, 16);
enum AVPixelFormat pix_fmt = AV_PIX_FMT_BAYER_RGGB16;
- if (pix_fmt != s->pix_fmt || dimensions_changed) {
+ if (pix_fmt != s->pix_fmt || dimensions_changed ||
+ s->version != old_version) {
s->pix_fmt = pix_fmt;
ret = get_pixel_format(avctx, pix_fmt);
@@ -525,6 +526,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
ProResRAWContext *rdst = dst->priv_data;
rdst->pix_fmt = rsrc->pix_fmt;
+ rdst->version = rsrc->version;
return 0;
}
commit 3934089de2c3bc4d2f6f37a0f4949c4fea864d5d
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 23 20:05:47 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
vulkan_prores: initialize only the necessary shaders on init
diff --git a/libavcodec/vulkan_prores.c b/libavcodec/vulkan_prores.c
index b252550f7c..0c704c3d1c 100644
--- a/libavcodec/vulkan_prores.c
+++ b/libavcodec/vulkan_prores.c
@@ -47,11 +47,9 @@ typedef struct ProresVulkanDecodePicture {
} ProresVulkanDecodePicture;
typedef struct ProresVulkanDecodeContext {
- struct ProresVulkanShaderVariants {
- FFVulkanShader reset;
- FFVulkanShader vld;
- FFVulkanShader idct;
- } shaders[2]; /* Progressive/interlaced */
+ FFVulkanShader reset;
+ FFVulkanShader vld;
+ FFVulkanShader idct;
AVBufferPool *metadata_pool;
} ProresVulkanDecodeContext;
@@ -163,7 +161,6 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
ProresVkParameters pd;
FFVkBuffer *slice_data, *metadata;
- struct ProresVulkanShaderVariants *shaders;
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
VkBufferMemoryBarrier2 buf_bar[2];
int nb_img_bar = 0, nb_buf_bar = 0, err;
@@ -179,8 +176,6 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
slice_data = (FFVkBuffer *)vp->slices_buf->data;
metadata = (FFVkBuffer *)pp->metadata_buf->data;
- shaders = &pv->shaders[pr->frame_type != 0];
-
pd = (ProresVkParameters) {
.slice_data = slice_data->address,
.bitstream_size = pp->bitstream_size,
@@ -253,14 +248,14 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
nb_img_bar = nb_buf_bar = 0;
/* Reset */
- ff_vk_shader_update_img_array(&ctx->s, exec, &shaders->reset,
+ ff_vk_shader_update_img_array(&ctx->s, exec, &pv->reset,
pr->frame, vp->view.out,
0, 0,
VK_IMAGE_LAYOUT_GENERAL,
VK_NULL_HANDLE);
- ff_vk_exec_bind_shader(&ctx->s, exec, &shaders->reset);
- ff_vk_shader_update_push_const(&ctx->s, exec, &shaders->reset,
+ ff_vk_exec_bind_shader(&ctx->s, exec, &pv->reset);
+ ff_vk_shader_update_push_const(&ctx->s, exec, &pv->reset,
VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(pd), &pd);
@@ -284,24 +279,24 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
nb_img_bar = nb_buf_bar = 0;
/* Entropy decode */
- ff_vk_shader_update_desc_buffer(&ctx->s, exec, &shaders->vld,
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->vld,
0, 0, 0,
metadata, 0,
pp->slice_offsets_sz,
VK_FORMAT_UNDEFINED);
- ff_vk_shader_update_desc_buffer(&ctx->s, exec, &shaders->vld,
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->vld,
0, 1, 0,
metadata, pp->slice_offsets_sz,
pp->mb_params_sz,
VK_FORMAT_UNDEFINED);
- ff_vk_shader_update_img_array(&ctx->s, exec, &shaders->vld,
+ ff_vk_shader_update_img_array(&ctx->s, exec, &pv->vld,
pr->frame, vp->view.out,
0, 2,
VK_IMAGE_LAYOUT_GENERAL,
VK_NULL_HANDLE);
- ff_vk_exec_bind_shader(&ctx->s, exec, &shaders->vld);
- ff_vk_shader_update_push_const(&ctx->s, exec, &shaders->vld,
+ ff_vk_exec_bind_shader(&ctx->s, exec, &pv->vld);
+ ff_vk_shader_update_push_const(&ctx->s, exec, &pv->vld,
VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(pd), &pd);
@@ -341,19 +336,19 @@ static int vk_prores_end_frame(AVCodecContext *avctx)
nb_img_bar = nb_buf_bar = 0;
/* Inverse transform */
- ff_vk_shader_update_desc_buffer(&ctx->s, exec, &shaders->idct,
+ ff_vk_shader_update_desc_buffer(&ctx->s, exec, &pv->idct,
0, 0, 0,
metadata, pp->slice_offsets_sz,
pp->mb_params_sz,
VK_FORMAT_UNDEFINED);
- ff_vk_shader_update_img_array(&ctx->s, exec, &shaders->idct,
+ ff_vk_shader_update_img_array(&ctx->s, exec, &pv->idct,
pr->frame, vp->view.out,
0, 1,
VK_IMAGE_LAYOUT_GENERAL,
VK_NULL_HANDLE);
- ff_vk_exec_bind_shader(&ctx->s, exec, &shaders->idct);
- ff_vk_shader_update_push_const(&ctx->s, exec, &shaders->idct,
+ ff_vk_exec_bind_shader(&ctx->s, exec, &pv->idct);
+ ff_vk_shader_update_push_const(&ctx->s, exec, &pv->idct,
VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(pd), &pd);
@@ -439,13 +434,10 @@ fail:
static void vk_decode_prores_uninit(FFVulkanDecodeShared *ctx)
{
ProresVulkanDecodeContext *pv = ctx->sd_ctx;
- int i;
- for (i = 0; i < FF_ARRAY_ELEMS(pv->shaders); ++i) {
- ff_vk_shader_free(&ctx->s, &pv->shaders[i].reset);
- ff_vk_shader_free(&ctx->s, &pv->shaders[i].vld);
- ff_vk_shader_free(&ctx->s, &pv->shaders[i].idct);
- }
+ ff_vk_shader_free(&ctx->s, &pv->reset);
+ ff_vk_shader_free(&ctx->s, &pv->vld);
+ ff_vk_shader_free(&ctx->s, &pv->idct);
av_buffer_pool_uninit(&pv->metadata_pool);
@@ -456,12 +448,13 @@ static int vk_decode_prores_init(AVCodecContext *avctx)
{
FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
FFVulkanDecodeShared *ctx = NULL;
+ ProresContext *pr = avctx->priv_data;
AVHWFramesContext *out_frames_ctx;
ProresVulkanDecodeContext *pv;
FFVkSPIRVCompiler *spv;
FFVulkanDescriptorSetBinding *desc_set;
- int max_num_mbs, i, err;
+ int max_num_mbs, err;
max_num_mbs = (avctx->coded_width >> 4) * (avctx->coded_height >> 4);
@@ -486,80 +479,75 @@ static int vk_decode_prores_init(AVCodecContext *avctx)
ctx->sd_ctx_free = vk_decode_prores_uninit;
- for (i = 0; i < FF_ARRAY_ELEMS(pv->shaders); ++i) { /* Progressive/interlaced */
- struct ProresVulkanShaderVariants *shaders = &pv->shaders[i];
-
- desc_set = (FFVulkanDescriptorSetBinding []) {
- {
- .name = "dst",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
- .dimensions = 2,
- .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
- FF_VK_REP_NATIVE),
- .mem_quali = "writeonly",
- .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- },
- };
- RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &shaders->reset,
- "prores_dec_reset", "main", desc_set, 1,
- ff_source_prores_reset_comp, 0x080801, i));
-
- desc_set = (FFVulkanDescriptorSetBinding []) {
- {
- .name = "slice_offsets_buf",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_quali = "readonly",
- .buf_content = "uint32_t slice_offsets",
- .buf_elems = max_num_mbs + 1,
- },
- {
- .name = "quant_idx_buf",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_quali = "writeonly",
- .buf_content = "uint8_t quant_idx",
- .buf_elems = max_num_mbs,
- },
- {
- .name = "dst",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
- .dimensions = 2,
- .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
- FF_VK_REP_NATIVE),
- .mem_quali = "writeonly",
- .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- },
- };
- RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &shaders->vld,
- "prores_dec_vld", "main", desc_set, 3,
- ff_source_prores_vld_comp, 0x080801, i));
-
- desc_set = (FFVulkanDescriptorSetBinding []) {
- {
- .name = "quant_idx_buf",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- .mem_quali = "readonly",
- .buf_content = "uint8_t quant_idx",
- .buf_elems = max_num_mbs,
- },
- {
- .name = "dst",
- .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
- .dimensions = 2,
- .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
- FF_VK_REP_NATIVE),
- .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
- .stages = VK_SHADER_STAGE_COMPUTE_BIT,
- },
- };
- RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &shaders->idct,
- "prores_dec_idct", "main", desc_set, 2,
- ff_source_prores_idct_comp, 0x200201, i));
- }
+ desc_set = (FFVulkanDescriptorSetBinding []) {
+ {
+ .name = "dst",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+ .dimensions = 2,
+ .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
+ FF_VK_REP_NATIVE),
+ .mem_quali = "writeonly",
+ .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ },
+ };
+ RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &pv->reset,
+ "prores_dec_reset", "main", desc_set, 1,
+ ff_source_prores_reset_comp, 0x080801, pr->frame_type != 0));
+ desc_set = (FFVulkanDescriptorSetBinding []) {
+ {
+ .name = "slice_offsets_buf",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ .mem_quali = "readonly",
+ .buf_content = "uint32_t slice_offsets",
+ .buf_elems = max_num_mbs + 1,
+ },
+ {
+ .name = "quant_idx_buf",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ .mem_quali = "writeonly",
+ .buf_content = "uint8_t quant_idx",
+ .buf_elems = max_num_mbs,
+ },
+ {
+ .name = "dst",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+ .dimensions = 2,
+ .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
+ FF_VK_REP_NATIVE),
+ .mem_quali = "writeonly",
+ .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ },
+ };
+ RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &pv->vld,
+ "prores_dec_vld", "main", desc_set, 3,
+ ff_source_prores_vld_comp, 0x080801, pr->frame_type != 0));
+
+ desc_set = (FFVulkanDescriptorSetBinding []) {
+ {
+ .name = "quant_idx_buf",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ .mem_quali = "readonly",
+ .buf_content = "uint8_t quant_idx",
+ .buf_elems = max_num_mbs,
+ },
+ {
+ .name = "dst",
+ .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
+ .dimensions = 2,
+ .mem_layout = ff_vk_shader_rep_fmt(out_frames_ctx->sw_format,
+ FF_VK_REP_NATIVE),
+ .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
+ .stages = VK_SHADER_STAGE_COMPUTE_BIT,
+ },
+ };
+ RET(init_shader(avctx, &ctx->s, &ctx->exec_pool, spv, &pv->idct,
+ "prores_dec_idct", "main", desc_set, 2,
+ ff_source_prores_idct_comp, 0x200201, pr->frame_type != 0));
err = 0;
commit 8c0314d44afc1062c61c5a21d215175bdef6c5f7
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 23 20:00:21 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:41 2025 +0100
proresdec: call ff_get_format if the interlacing changes
Decoders need to track all state that hwaccels may be intersted in,
and trigger a reconfiguration if it changes.
diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c
index 5c6b505527..b971d17972 100644
--- a/libavcodec/proresdec.c
+++ b/libavcodec/proresdec.c
@@ -189,6 +189,7 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
int version;
const uint8_t *ptr;
enum AVPixelFormat pix_fmt;
+ int old_frame_type = ctx->frame_type;
hdr_size = AV_RB16(buf);
ff_dlog(avctx, "header size %d\n", hdr_size);
@@ -251,7 +252,8 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
}
}
- if (pix_fmt != ctx->pix_fmt || dimensions_changed) {
+ if (pix_fmt != ctx->pix_fmt || dimensions_changed ||
+ ctx->frame_type != old_frame_type) {
#define HWACCEL_MAX (CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL + CONFIG_PRORES_VULKAN_HWACCEL)
#if HWACCEL_MAX
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
@@ -856,6 +858,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
ProresContext *cdst = dst->priv_data;
cdst->pix_fmt = csrc->pix_fmt;
+ cdst->frame_type = csrc->frame_type;
return 0;
}
commit 56dea1a9e80f23a81a06ec75ca7528fce1ee1f1b
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sat Nov 22 22:37:17 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
vulkan_ffv1: initialize only the necessary shaders on init
The decoder will reinit the hwaccel upon pixfmt/dimension changes,
so we can remove the f->use32bit and is_rgb variants of all shaders.
This speeds up init time.
diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c
index 4787a06e97..7d1e0c9ba7 100644
--- a/libavcodec/vulkan_ffv1.c
+++ b/libavcodec/vulkan_ffv1.c
@@ -59,11 +59,11 @@ typedef struct FFv1VulkanDecodePicture {
} FFv1VulkanDecodePicture;
typedef struct FFv1VulkanDecodeContext {
- AVBufferRef *intermediate_frames_ref[2]; /* 16/32 bit */
+ AVBufferRef *intermediate_frames_ref;
FFVulkanShader setup;
- FFVulkanShader reset[2]; /* AC/Golomb */
- FFVulkanShader decode[2][2][2]; /* 16/32 bit, AC/Golomb, Normal/RGB */
+ FFVulkanShader reset;
+ FFVulkanShader decode;
FFVkBuffer rangecoder_static_buf;
FFVkBuffer quant_buf;
@@ -239,7 +239,7 @@ static int vk_ffv1_start_frame(AVCodecContext *avctx,
if (!vp->dpb_frame)
return AVERROR(ENOMEM);
- err = av_hwframe_get_buffer(fv->intermediate_frames_ref[f->use32bit],
+ err = av_hwframe_get_buffer(fv->intermediate_frames_ref,
vp->dpb_frame, 0);
if (err < 0)
return err;
@@ -472,7 +472,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
}
/* Reset shader */
- reset_shader = &fv->reset[f->ac == AC_GOLOMB_RICE];
+ reset_shader = &fv->reset;
ff_vk_shader_update_desc_buffer(&ctx->s, exec, reset_shader,
1, 0, 0,
slice_state,
@@ -525,7 +525,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
f->plane_count);
/* Decode */
- decode_shader = &fv->decode[f->use32bit][f->ac == AC_GOLOMB_RICE][is_rgb];
+ decode_shader = &fv->decode;
ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader,
1, 0, 0,
slice_state,
@@ -821,7 +821,7 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s,
FFVulkanShader *shd,
AVHWFramesContext *dec_frames_ctx,
AVHWFramesContext *out_frames_ctx,
- int use32bit, int ac, int rgb)
+ int ac, int rgb)
{
int err;
FFVulkanDescriptorSetBinding *desc_set;
@@ -829,6 +829,7 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s,
uint8_t *spv_data;
size_t spv_len;
void *spv_opaque = NULL;
+
int use_cached_reader = ac != AC_GOLOMB_RICE &&
s->driver_props.driverID == VK_DRIVER_ID_MESA_RADV;
@@ -877,7 +878,7 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s,
RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 1, 0));
- define_shared_code(shd, use32bit);
+ define_shared_code(shd, f->use32bit);
if (ac == AC_GOLOMB_RICE)
GLSLD(ff_source_ffv1_vlc_comp);
@@ -973,18 +974,11 @@ static void vk_decode_ffv1_uninit(FFVulkanDecodeShared *ctx)
{
FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
- ff_vk_shader_free(&ctx->s, &fv->setup);
-
- for (int i = 0; i < 2; i++) /* 16/32 bit */
- av_buffer_unref(&fv->intermediate_frames_ref[i]);
+ av_buffer_unref(&fv->intermediate_frames_ref);
- for (int i = 0; i < 2; i++) /* AC/Golomb */
- ff_vk_shader_free(&ctx->s, &fv->reset[i]);
-
- for (int i = 0; i < 2; i++) /* 16/32 bit */
- for (int j = 0; j < 2; j++) /* AC/Golomb */
- for (int k = 0; k < 2; k++) /* Normal/RGB */
- ff_vk_shader_free(&ctx->s, &fv->decode[i][j][k]);
+ ff_vk_shader_free(&ctx->s, &fv->setup);
+ ff_vk_shader_free(&ctx->s, &fv->reset);
+ ff_vk_shader_free(&ctx->s, &fv->decode);
ff_vk_free_buf(&ctx->s, &fv->quant_buf);
ff_vk_free_buf(&ctx->s, &fv->rangecoder_static_buf);
@@ -1029,38 +1023,33 @@ static int vk_decode_ffv1_init(AVCodecContext *avctx)
ctx->sd_ctx_free = &vk_decode_ffv1_uninit;
+ AVHWFramesContext *hwfc = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
+ AVHWFramesContext *dctx = hwfc;
+ enum AVPixelFormat sw_format = hwfc->sw_format;
+ int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
+ !(sw_format == AV_PIX_FMT_YA8);
+
/* Intermediate frame pool for RCT */
- for (int i = 0; i < 2; i++) { /* 16/32 bit */
- RET(init_indirect(avctx, &ctx->s, &fv->intermediate_frames_ref[i],
- i ? AV_PIX_FMT_GBRAP32 : AV_PIX_FMT_GBRAP16));
+ if (is_rgb) {
+ RET(init_indirect(avctx, &ctx->s, &fv->intermediate_frames_ref,
+ f->use32bit ? AV_PIX_FMT_GBRAP32 : AV_PIX_FMT_GBRAP16));
+ dctx = (AVHWFramesContext *)fv->intermediate_frames_ref->data;
}
/* Setup shader */
RET(init_setup_shader(f, &ctx->s, &ctx->exec_pool, spv, &fv->setup));
- /* Reset shaders */
- for (int i = 0; i < 2; i++) { /* AC/Golomb */
- RET(init_reset_shader(f, &ctx->s, &ctx->exec_pool,
- spv, &fv->reset[i], !i ? AC_RANGE_CUSTOM_TAB : 0));
- }
+ /* Reset shader */
+ RET(init_reset_shader(f, &ctx->s, &ctx->exec_pool,
+ spv, &fv->reset, f->ac));
/* Decode shaders */
- for (int i = 0; i < 2; i++) { /* 16/32 bit */
- for (int j = 0; j < 2; j++) { /* AC/Golomb */
- for (int k = 0; k < 2; k++) { /* Normal/RGB */
- AVHWFramesContext *dec_frames_ctx;
- dec_frames_ctx = k ? (AVHWFramesContext *)fv->intermediate_frames_ref[i]->data :
- (AVHWFramesContext *)avctx->hw_frames_ctx->data;
- RET(init_decode_shader(f, &ctx->s, &ctx->exec_pool,
- spv, &fv->decode[i][j][k],
- dec_frames_ctx,
- (AVHWFramesContext *)avctx->hw_frames_ctx->data,
- i,
- !j ? AC_RANGE_CUSTOM_TAB : AC_GOLOMB_RICE,
- k));
- }
- }
- }
+ RET(init_decode_shader(f, &ctx->s, &ctx->exec_pool,
+ spv, &fv->decode,
+ dctx,
+ hwfc,
+ f->ac,
+ is_rgb));
/* Range coder data */
RET(ff_ffv1_vk_init_state_transition_data(&ctx->s,
@@ -1090,22 +1079,16 @@ static int vk_decode_ffv1_init(AVCodecContext *avctx)
VK_FORMAT_UNDEFINED));
/* Update decode global descriptors */
- for (int i = 0; i < 2; i++) { /* 16/32 bit */
- for (int j = 0; j < 2; j++) { /* AC/Golomb */
- for (int k = 0; k < 2; k++) { /* Normal/RGB */
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &fv->decode[i][j][k], 0, 0, 0,
- &fv->rangecoder_static_buf,
- 0, fv->rangecoder_static_buf.size,
- VK_FORMAT_UNDEFINED));
- RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
- &fv->decode[i][j][k], 0, 1, 0,
- &fv->quant_buf,
- 0, fv->quant_buf.size,
- VK_FORMAT_UNDEFINED));
- }
- }
- }
+ RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
+ &fv->decode, 0, 0, 0,
+ &fv->rangecoder_static_buf,
+ 0, fv->rangecoder_static_buf.size,
+ VK_FORMAT_UNDEFINED));
+ RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
+ &fv->decode, 0, 1, 0,
+ &fv->quant_buf,
+ 0, fv->quant_buf.size,
+ VK_FORMAT_UNDEFINED));
fail:
spv->uninit(&spv);
commit a1154b74a4a3635e4106aba9b1c4c0efdd35e07c
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sun Nov 23 19:49:01 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
ffv1dec: call ff_get_format if the EC coding changes
Decoders need to track all state that hwaccels may be intersted in,
and trigger a reconfiguration if it changes.
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index adf76b0644..8a48e8e682 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -140,6 +140,7 @@ typedef struct FFV1Context {
enum AVPixelFormat pix_fmt;
enum AVPixelFormat configured_pix_fmt;
int configured_width, configured_height;
+ int configured_ac;
const AVFrame *cur_enc_frame;
int plane_count;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a70cd74af4..630a60595d 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -509,13 +509,15 @@ static int read_header(FFV1Context *f, RangeCoder *c)
if (f->configured_pix_fmt != f->pix_fmt ||
f->configured_width != f->avctx->width ||
- f->configured_height != f->avctx->height) {
+ f->configured_height != f->avctx->height ||
+ f->configured_ac != f->ac) {
f->avctx->pix_fmt = get_pixel_format(f);
if (f->avctx->pix_fmt < 0)
return AVERROR(EINVAL);
f->configured_pix_fmt = f->pix_fmt;
f->configured_width = f->avctx->width;
f->configured_height = f->avctx->height;
+ f->configured_ac = f->ac;
}
ff_dlog(f->avctx, "%d %d %d\n",
@@ -921,6 +923,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
fdst->colorspace = fsrc->colorspace;
fdst->pix_fmt = fsrc->pix_fmt;
fdst->configured_pix_fmt = fsrc->configured_pix_fmt;
+ fdst->configured_ac = fsrc->configured_ac;
fdst->ec = fsrc->ec;
fdst->intra = fsrc->intra;
commit be9998674aeea8fc4110918a7e15e6d7f7f37357
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Sat Nov 22 13:13:43 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
vulkan_ffv1/prores: remove unnecessary slice buffer unref
The slice buffer is already unref'd by ff_vk_decode_free_frame().
diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c
index 1aa63c0dd3..4787a06e97 100644
--- a/libavcodec/vulkan_ffv1.c
+++ b/libavcodec/vulkan_ffv1.c
@@ -1146,7 +1146,6 @@ static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
i, status, crc_res);
}
- av_buffer_unref(&vp->slices_buf);
av_buffer_unref(&fp->slice_state);
av_buffer_unref(&fp->slice_offset_buf);
av_buffer_unref(&fp->slice_status_buf);
diff --git a/libavcodec/vulkan_prores.c b/libavcodec/vulkan_prores.c
index 42e8fa0b06..b252550f7c 100644
--- a/libavcodec/vulkan_prores.c
+++ b/libavcodec/vulkan_prores.c
@@ -573,11 +573,9 @@ static void vk_prores_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
{
AVHWDeviceContext *dev_ctx = _hwctx.nc;
ProresVulkanDecodePicture *pp = data;
- FFVulkanDecodePicture *vp = &pp->vp;
ff_vk_decode_free_frame(dev_ctx, &pp->vp);
- av_buffer_unref(&vp->slices_buf);
av_buffer_unref(&pp->metadata_buf);
}
commit 615b26f1b1ac4000667b4ad58db1ee112bc811f5
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 13:06:11 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
vulkan_ffv1: fix swapped colors for x2bgr10
diff --git a/libavcodec/vulkan/ffv1_dec.comp b/libavcodec/vulkan/ffv1_dec.comp
index eb795dcba4..b726491e98 100644
--- a/libavcodec/vulkan/ffv1_dec.comp
+++ b/libavcodec/vulkan/ffv1_dec.comp
@@ -214,6 +214,9 @@ void writeout_rgb(in SliceContext sc, ivec2 sp, int w, int y, bool apply_rct)
if (expectEXT(apply_rct, true))
pix = transform_sample(pix, sc.slice_rct_coef);
+ else
+ pix = ivec4(pix[fmt_lut[0]], pix[fmt_lut[1]],
+ pix[fmt_lut[2]], pix[fmt_lut[3]]);
imageStore(dst[0], pos, pix);
if (planar_rgb != 0) {
diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c
index 1ed9d7dd6c..1aa63c0dd3 100644
--- a/libavcodec/vulkan_ffv1.c
+++ b/libavcodec/vulkan_ffv1.c
@@ -450,8 +450,6 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx)
if (sw_format == AV_PIX_FMT_GBRP10 || sw_format == AV_PIX_FMT_GBRP12 ||
sw_format == AV_PIX_FMT_GBRP14)
memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
- else if (sw_format == AV_PIX_FMT_X2BGR10)
- memcpy(pd.fmt_lut, (int [4]) { 0, 2, 1, 3 }, 4*sizeof(int));
else
ff_vk_set_perm(sw_format, pd.fmt_lut, 0);
commit 3ddcf042b2cc469f4321daf170d1ecab194e5802
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 12:59:24 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
ffv1enc_vulkan: add support for x2bgr10/x2rgb10
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 8e5ebe773c..5daa3aa0cd 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -914,6 +914,8 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx,
case AV_PIX_FMT_GBRP9:
if (!avctx->bits_per_raw_sample)
s->bits_per_raw_sample = 9;
+ case AV_PIX_FMT_X2BGR10:
+ case AV_PIX_FMT_X2RGB10:
case AV_PIX_FMT_GBRP10:
case AV_PIX_FMT_GBRAP10:
if (!avctx->bits_per_raw_sample && !s->bits_per_raw_sample)
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 1a1d7d0f8d..c3d8c1d0d9 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1600,6 +1600,12 @@ void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv)
lut[2] = 0;
lut[3] = 3;
break;
+ case AV_PIX_FMT_X2BGR10:
+ lut[0] = 0;
+ lut[1] = 2;
+ lut[2] = 1;
+ lut[3] = 3;
+ break;
default:
lut[0] = 0;
lut[1] = 1;
commit 23cfcf93d22cffbaf683df43152740bbbc893bcd
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Mon Nov 24 22:34:51 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:40 2025 +0100
vulkan: change ff_vk_frame_barrier access and stage type to sync2
Cleans up a compiler warning.
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index c7f86d524c..1a1d7d0f8d 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -2043,11 +2043,11 @@ fail:
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e,
AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar,
- VkPipelineStageFlags src_stage,
- VkPipelineStageFlags dst_stage,
- VkAccessFlagBits new_access,
- VkImageLayout new_layout,
- uint32_t new_qf)
+ VkPipelineStageFlags2 src_stage,
+ VkPipelineStageFlags2 dst_stage,
+ VkAccessFlagBits2 new_access,
+ VkImageLayout new_layout,
+ uint32_t new_qf)
{
int found = -1;
AVVkFrame *vkf = (AVVkFrame *)pic->data[0];
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index bdc20e4645..868788c2a4 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -507,10 +507,10 @@ int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e,
AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar,
- VkPipelineStageFlags src_stage,
- VkPipelineStageFlags dst_stage,
- VkAccessFlagBits new_access,
- VkImageLayout new_layout,
+ VkPipelineStageFlags2 src_stage,
+ VkPipelineStageFlags2 dst_stage,
+ VkAccessFlagBits2 new_access,
+ VkImageLayout new_layout,
uint32_t new_qf);
/**
commit d36d88dcbb131aeb0af3465fe8d9d1fe9959f593
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Tue Nov 18 12:09:51 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
vulkan/common: add reverse2 endian reversal macro
diff --git a/libavcodec/vulkan/common.comp b/libavcodec/vulkan/common.comp
index 6825693fa3..eda92ce28d 100644
--- a/libavcodec/vulkan/common.comp
+++ b/libavcodec/vulkan/common.comp
@@ -79,6 +79,9 @@ uint64_t align64(uint64_t src, uint64_t a)
return src + a - res;
}
+#define reverse2(src) \
+ (pack16(unpack8(uint16_t(src)).yx))
+
#define reverse4(src) \
(pack32(unpack8(uint32_t(src)).wzyx))
commit 6c3984db7fdcfc9d97e7db3d419a601eb1440fad
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 5 10:31:18 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
vulkan/common: add a function to flush/invalidate a buffer and use it
Just for convenience.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index eaa499aa73..a2caaa0959 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -4237,29 +4237,10 @@ static int copy_buffer_data(AVHWFramesContext *hwfc, AVBufferRef *buf,
AVFrame *swf, VkBufferImageCopy *region,
int planes, int upload)
{
- VkResult ret;
+ int err;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
- FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = &p->p;
-
FFVkBuffer *vkbuf = (FFVkBuffer *)buf->data;
- const VkMappedMemoryRange flush_info = {
- .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
- .memory = vkbuf->mem,
- .size = VK_WHOLE_SIZE,
- };
-
- if (!upload && !(vkbuf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
- ret = vk->InvalidateMappedMemoryRanges(hwctx->act_dev, 1,
- &flush_info);
- if (ret != VK_SUCCESS) {
- av_log(hwfc, AV_LOG_ERROR, "Failed to invalidate buffer data: %s\n",
- ff_vk_ret2str(ret));
- return AVERROR_EXTERNAL;
- }
- }
-
if (upload) {
for (int i = 0; i < planes; i++)
av_image_copy_plane(vkbuf->mapped_mem + region[i].bufferOffset,
@@ -4268,7 +4249,21 @@ static int copy_buffer_data(AVHWFramesContext *hwfc, AVBufferRef *buf,
swf->linesize[i],
swf->linesize[i],
region[i].imageExtent.height);
+
+ err = ff_vk_flush_buffer(&p->vkctx, vkbuf, 0, VK_WHOLE_SIZE, 1);
+ if (err != VK_SUCCESS) {
+ av_log(hwfc, AV_LOG_ERROR, "Failed to flush buffer data: %s\n",
+ av_err2str(err));
+ return AVERROR_EXTERNAL;
+ }
} else {
+ err = ff_vk_flush_buffer(&p->vkctx, vkbuf, 0, VK_WHOLE_SIZE, 0);
+ if (err != VK_SUCCESS) {
+ av_log(hwfc, AV_LOG_ERROR, "Failed to invalidate buffer data: %s\n",
+ av_err2str(err));
+ return AVERROR_EXTERNAL;
+ }
+
for (int i = 0; i < planes; i++)
av_image_copy_plane(swf->data[i],
swf->linesize[i],
@@ -4278,16 +4273,6 @@ static int copy_buffer_data(AVHWFramesContext *hwfc, AVBufferRef *buf,
region[i].imageExtent.height);
}
- if (upload && !(vkbuf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
- ret = vk->FlushMappedMemoryRanges(hwctx->act_dev, 1,
- &flush_info);
- if (ret != VK_SUCCESS) {
- av_log(hwfc, AV_LOG_ERROR, "Failed to flush buffer data: %s\n",
- ff_vk_ret2str(ret));
- return AVERROR_EXTERNAL;
- }
- }
-
return 0;
}
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 54448a32e5..c7f86d524c 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1167,6 +1167,37 @@ int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[],
return 0;
}
+int ff_vk_flush_buffer(FFVulkanContext *s, FFVkBuffer *buf,
+ size_t offset, size_t mem_size,
+ int flush)
+{
+ VkResult ret;
+ FFVulkanFunctions *vk = &s->vkfn;
+
+ if (buf->host_ref || buf->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
+ return 0;
+
+ const VkMappedMemoryRange flush_data = {
+ .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
+ .memory = buf->mem,
+ .offset = offset,
+ .size = mem_size,
+ };
+
+ if (flush)
+ ret = vk->FlushMappedMemoryRanges(s->hwctx->act_dev, 1, &flush_data);
+ else
+ ret = vk->InvalidateMappedMemoryRanges(s->hwctx->act_dev, 1, &flush_data);
+
+ if (ret != VK_SUCCESS) {
+ av_log(s, AV_LOG_ERROR, "Failed to flush memory: %s\n",
+ ff_vk_ret2str(ret));
+ return AVERROR_EXTERNAL;
+ }
+
+ return 0;
+}
+
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers,
int flush)
{
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index e1c9a5792f..bdc20e4645 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -523,6 +523,13 @@ int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size,
void *pNext, void *alloc_pNext,
VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
+/**
+ * Flush or invalidate a single buffer, with a given size and offset.
+ */
+int ff_vk_flush_buffer(FFVulkanContext *s, FFVkBuffer *buf,
+ size_t offset, size_t mem_size,
+ int flush);
+
/**
* Buffer management code.
*/
commit d288d4a24ee9eac79201cfd1e5c7d80c8f1bb9a7
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 14:30:21 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
hwcontext_vulkan: use vkTransitionImageLayoutEXT to switch layouts
Falls back to regular submit-based layout switching if unsupported.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 1418c1ea3f..eaa499aa73 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2465,7 +2465,42 @@ enum PrepMode {
PREP_MODE_ENCODING_DPB,
};
-static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
+static void switch_new_props(enum PrepMode pmode, VkImageLayout *new_layout,
+ VkAccessFlags2 *new_access)
+{
+ switch (pmode) {
+ case PREP_MODE_GENERAL:
+ *new_layout = VK_IMAGE_LAYOUT_GENERAL;
+ *new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
+ case PREP_MODE_WRITE:
+ *new_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ *new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
+ case PREP_MODE_EXTERNAL_IMPORT:
+ *new_layout = VK_IMAGE_LAYOUT_GENERAL;
+ *new_access = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
+ break;
+ case PREP_MODE_EXTERNAL_EXPORT:
+ *new_layout = VK_IMAGE_LAYOUT_GENERAL;
+ *new_access = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
+ break;
+ case PREP_MODE_DECODING_DST:
+ *new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR;
+ *new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
+ case PREP_MODE_DECODING_DPB:
+ *new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR;
+ *new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
+ case PREP_MODE_ENCODING_DPB:
+ *new_layout = VK_IMAGE_LAYOUT_VIDEO_ENCODE_DPB_KHR;
+ *new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
+ break;
+ }
+}
+
+static int switch_layout(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
AVVkFrame *frame, enum PrepMode pmode)
{
int err;
@@ -2474,10 +2509,16 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
int nb_img_bar = 0;
- uint32_t dst_qf = p->nb_img_qfs > 1 ? VK_QUEUE_FAMILY_IGNORED : p->img_qfs[0];
VkImageLayout new_layout;
VkAccessFlags2 new_access;
+ switch_new_props(pmode, &new_layout, &new_access);
+
+ uint32_t dst_qf = p->nb_img_qfs > 1 ? VK_QUEUE_FAMILY_IGNORED : p->img_qfs[0];
VkPipelineStageFlagBits2 src_stage = VK_PIPELINE_STAGE_2_NONE;
+ if (pmode == PREP_MODE_EXTERNAL_EXPORT) {
+ dst_qf = VK_QUEUE_FAMILY_EXTERNAL_KHR;
+ src_stage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
+ }
/* This is dirty - but it works. The vulkan.c dependency system doesn't
* free non-refcounted frames, and non-refcounted hardware frames cannot
@@ -2501,39 +2542,6 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
if (err < 0)
return err;
- switch (pmode) {
- case PREP_MODE_GENERAL:
- new_layout = VK_IMAGE_LAYOUT_GENERAL;
- new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
- break;
- case PREP_MODE_WRITE:
- new_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
- new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
- break;
- case PREP_MODE_EXTERNAL_IMPORT:
- new_layout = VK_IMAGE_LAYOUT_GENERAL;
- new_access = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
- break;
- case PREP_MODE_EXTERNAL_EXPORT:
- new_layout = VK_IMAGE_LAYOUT_GENERAL;
- new_access = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT;
- dst_qf = VK_QUEUE_FAMILY_EXTERNAL_KHR;
- src_stage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
- break;
- case PREP_MODE_DECODING_DST:
- new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR;
- new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
- break;
- case PREP_MODE_DECODING_DPB:
- new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR;
- new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
- break;
- case PREP_MODE_ENCODING_DPB:
- new_layout = VK_IMAGE_LAYOUT_VIDEO_ENCODE_DPB_KHR;
- new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
- break;
- }
-
ff_vk_frame_barrier(&p->vkctx, exec, &tmp_frame, img_bar, &nb_img_bar,
src_stage,
VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
@@ -2555,6 +2563,67 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
return 0;
}
+static int switch_layout_host(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
+ AVVkFrame *frame, enum PrepMode pmode)
+{
+ VkResult ret;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
+ FFVulkanFunctions *vk = &p->vkctx.vkfn;
+ VkHostImageLayoutTransitionInfo layout_change[AV_NUM_DATA_POINTERS];
+ int nb_images = ff_vk_count_images(frame);
+
+ VkImageLayout new_layout;
+ VkAccessFlags2 new_access;
+ switch_new_props(pmode, &new_layout, &new_access);
+
+ int i;
+ for (i = 0; i < p->vkctx.host_image_props.copyDstLayoutCount; i++) {
+ if (p->vkctx.host_image_props.pCopyDstLayouts[i] == new_layout)
+ break;
+ }
+ if (i == p->vkctx.host_image_props.copyDstLayoutCount)
+ return AVERROR(ENOTSUP);
+
+ for (i = 0; i < nb_images; i++) {
+ layout_change[i] = (VkHostImageLayoutTransitionInfo) {
+ .sType = VK_STRUCTURE_TYPE_HOST_IMAGE_LAYOUT_TRANSITION_INFO,
+ .image = frame->img[i],
+ .oldLayout = frame->layout[i],
+ .newLayout = new_layout,
+ .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .subresourceRange.layerCount = 1,
+ .subresourceRange.levelCount = 1,
+ };
+ frame->layout[i] = new_layout;
+ }
+
+ ret = vk->TransitionImageLayoutEXT(p->vkctx.hwctx->act_dev,
+ nb_images, layout_change);
+ if (ret != VK_SUCCESS) {
+ av_log(hwfc, AV_LOG_ERROR, "Unable to prepare frame: %s\n",
+ ff_vk_ret2str(ret));
+ return AVERROR_EXTERNAL;
+ }
+
+ return 0;
+}
+
+static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
+ AVVkFrame *frame, enum PrepMode pmode)
+{
+ int err = 0;
+ AVVulkanFramesContext *hwfc_vk = hwfc->hwctx;
+ if (hwfc_vk->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT &&
+ (pmode != PREP_MODE_EXTERNAL_EXPORT) &&
+ (pmode != PREP_MODE_EXTERNAL_IMPORT))
+ err = switch_layout_host(hwfc, ectx, frame, pmode);
+
+ if (err != AVERROR(ENOTSUP))
+ return err;
+
+ return switch_layout(hwfc, ectx, frame, pmode);
+}
+
static inline void get_plane_wh(uint32_t *w, uint32_t *h, enum AVPixelFormat format,
int frame_w, int frame_h, int plane)
{
commit 5c89528342b72cef57019aa01b9ef0f8fa401cc3
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 13:48:17 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
hwcontext_vulkan: disable host image transfers for Nvidia devices
Nvidia's binary drivers have a very buggy implementation that is
yet to be fixed.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index efee6c72ac..1418c1ea3f 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2082,9 +2082,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
/* Re-query device capabilities, in case the device was created externally */
vk->GetPhysicalDeviceMemoryProperties(hwctx->phys_dev, &p->mprops);
- /* Only use host image transfers if ReBAR is enabled */
- p->disable_host_transfer = !vulkan_device_has_rebar(ctx);
-
end:
av_free(qf_vid);
av_free(qf);
@@ -2915,19 +2912,14 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
return err;
}
- /* Nvidia is violating the spec because they thought no one would use this. */
- if (p->dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY &&
- (((fmt->nb_images == 1) && (fmt->vk_planes > 1)) ||
- (av_pix_fmt_desc_get(hwfc->sw_format)->nb_components == 1)))
- supported_usage &= ~VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT;
-
/* Image usage flags */
hwctx->usage |= supported_usage & (VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_STORAGE_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT);
- if ((p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY) && !p->disable_host_transfer)
+ if (p->vkctx.extensions & FF_VK_EXT_HOST_IMAGE_COPY &&
+ !(p->dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY))
hwctx->usage |= supported_usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT;
/* Enables encoding of images, if supported by format and extensions */
@@ -4481,7 +4473,8 @@ static int vulkan_transfer_frame(AVHWFramesContext *hwfc,
if (swf->width > hwfc->width || swf->height > hwfc->height)
return AVERROR(EINVAL);
- if (hwctx->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT)
+ if (hwctx->usage & VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT &&
+ !(p->dprops.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY))
return vulkan_transfer_host(hwfc, hwf, swf, upload);
for (int i = 0; i < av_pix_fmt_count_planes(swf->format); i++) {
commit 686951849b2a1a4f2683478c59042edb94ab527b
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Wed Nov 26 13:47:15 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
hwcontext_vulkan: re-enable host image copy extension
We'll slowly start to use it in the code in safe places
rather than globally.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 0408b9c117..efee6c72ac 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -154,9 +154,6 @@ typedef struct VulkanDevicePriv {
/* Disable multiplane images */
int disable_multiplane;
- /* Disable host image transfer */
- int disable_host_transfer;
-
/* Prefer memcpy over dynamic host pointer imports */
int avoid_host_import;
@@ -656,6 +653,7 @@ 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 },
+ { 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
@@ -750,6 +748,26 @@ static VkBool32 VKAPI_CALL vk_dbg_callback(VkDebugUtilsMessageSeverityFlagBitsEX
av_free((void *)props); \
}
+static int vulkan_device_has_rebar(AVHWDeviceContext *ctx)
+{
+ VulkanDevicePriv *p = ctx->hwctx;
+ VkDeviceSize max_vram = 0, max_visible_vram = 0;
+
+ /* Get device memory properties */
+ av_assert0(p->mprops.memoryTypeCount);
+ for (int i = 0; i < p->mprops.memoryTypeCount; i++) {
+ const VkMemoryType type = p->mprops.memoryTypes[i];
+ const VkMemoryHeap heap = p->mprops.memoryHeaps[type.heapIndex];
+ if (!(type.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
+ continue;
+ max_vram = FFMAX(max_vram, heap.size);
+ if (type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
+ max_visible_vram = FFMAX(max_visible_vram, heap.size);
+ }
+
+ return max_vram - max_visible_vram < 1024; /* 1 kB tolerance */
+}
+
enum FFVulkanDebugMode {
FF_VULKAN_DEBUG_NONE = 0,
/* Standard GPU-assisted validation */
@@ -830,6 +848,11 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
!strcmp(tstr, VK_EXT_DESCRIPTOR_BUFFER_EXTENSION_NAME))
continue;
+ /* Check if the device has ReBAR for host image copies */
+ if (!strcmp(tstr, VK_EXT_HOST_IMAGE_COPY_EXTENSION_NAME) &&
+ !vulkan_device_has_rebar(ctx))
+ continue;
+
if (dev &&
((debug_mode == FF_VULKAN_DEBUG_VALIDATE) ||
(debug_mode == FF_VULKAN_DEBUG_PRINTF) ||
@@ -1707,25 +1730,6 @@ static void vulkan_device_uninit(AVHWDeviceContext *ctx)
ff_vk_uninit(&p->vkctx);
}
-static int vulkan_device_has_rebar(AVHWDeviceContext *ctx)
-{
- VulkanDevicePriv *p = ctx->hwctx;
- VkDeviceSize max_vram = 0, max_visible_vram = 0;
-
- /* Get device memory properties */
- for (int i = 0; i < p->mprops.memoryTypeCount; i++) {
- const VkMemoryType type = p->mprops.memoryTypes[i];
- const VkMemoryHeap heap = p->mprops.memoryHeaps[type.heapIndex];
- if (!(type.propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
- continue;
- max_vram = FFMAX(max_vram, heap.size);
- if (type.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
- max_visible_vram = FFMAX(max_visible_vram, heap.size);
- }
-
- return max_vram - max_visible_vram < 1024; /* 1 kB tolerance */
-}
-
static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
VulkanDeviceSelection *dev_select,
int disable_multiplane,
@@ -1751,6 +1755,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
if ((err = find_device(ctx, dev_select)))
goto end;
+ /* Get supported memory types */
+ vk->GetPhysicalDeviceMemoryProperties(hwctx->phys_dev, &p->mprops);
+
/* Find and enable extensions for the physical device */
if ((err = check_extensions(ctx, 1, opts, &dev_info.ppEnabledExtensionNames,
&dev_info.enabledExtensionCount, debug_mode))) {
@@ -1760,9 +1767,6 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
goto end;
}
- /* Get supported memory types */
- vk->GetPhysicalDeviceMemoryProperties(hwctx->phys_dev, &p->mprops);
-
/* Get all supported features for the physical device */
device_features_init(ctx, &supported_feats);
vk->GetPhysicalDeviceFeatures2(hwctx->phys_dev, &supported_feats.device);
commit fc2dd6c75157a040bd1d057b865a18ede32228a8
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Thu Nov 13 12:09:11 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:39 2025 +0100
hwcontext_vulkan: enable runtime descriptor sizing
We were already using this in places, but it seems validation
layers finally got support to detect it.
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index a6bf9a590b..0408b9c117 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -307,6 +307,7 @@ static void device_features_copy_needed(VulkanDeviceFeatures *dst, VulkanDeviceF
COPY_VAL(vulkan_1_2.vulkanMemoryModel);
COPY_VAL(vulkan_1_2.vulkanMemoryModelDeviceScope);
COPY_VAL(vulkan_1_2.uniformBufferStandardLayout);
+ COPY_VAL(vulkan_1_2.runtimeDescriptorArray);
COPY_VAL(vulkan_1_3.dynamicRendering);
COPY_VAL(vulkan_1_3.maintenance4);
commit 58d26c2055180ebf8013308d6011f563f7529c1e
Author: Lynne <dev(a)lynne.ee>
AuthorDate: Tue Nov 25 17:03:27 2025 +0100
Commit: Lynne <dev(a)lynne.ee>
CommitDate: Wed Nov 26 15:16:34 2025 +0100
Changelog: add ProRes Vulkan hwaccel to the list
Forgotten when it got merged.
diff --git a/Changelog b/Changelog
index 4648899ca3..3757eac2e4 100644
--- a/Changelog
+++ b/Changelog
@@ -11,6 +11,7 @@ version <next>:
- drawvg filter via libcairo
- ffmpeg CLI tiled HEIF support
- D3D12 AV1 encoder
+- ProRes Vulkan hwaccel
version 8.0:
-----------------------------------------------------------------------
Summary of changes:
Changelog | 2 +
configure | 2 +
libavcodec/Makefile | 1 +
libavcodec/dpx.c | 533 ++++++++++++---------
libavcodec/dpx.h | 16 +
libavcodec/ffv1.h | 1 +
libavcodec/ffv1dec.c | 5 +-
libavcodec/ffv1enc.c | 2 +
libavcodec/hwaccels.h | 1 +
libavcodec/prores_raw.c | 6 +-
libavcodec/proresdec.c | 5 +-
libavcodec/version.h | 2 +-
libavcodec/vulkan/Makefile | 7 +-
libavcodec/vulkan/common.comp | 3 +
.../vulkan/{prores_reset.comp => dpx_copy.comp} | 39 +-
libavcodec/vulkan/dpx_unpack.comp | 83 ++++
libavcodec/vulkan/ffv1_dec.comp | 3 +
libavcodec/vulkan/prores_raw.comp | 347 --------------
libavcodec/vulkan/prores_raw_decode.comp | 234 +++++++++
libavcodec/vulkan/prores_raw_idct.comp | 174 +++++++
libavcodec/vulkan_decode.c | 16 +
libavcodec/vulkan_dpx.c | 475 ++++++++++++++++++
libavcodec/vulkan_ffv1.c | 104 ++--
libavcodec/vulkan_prores.c | 192 ++++----
libavcodec/vulkan_prores_raw.c | 351 +++++++-------
libavutil/hwcontext_vulkan.c | 254 ++++++----
libavutil/vulkan.c | 47 +-
libavutil/vulkan.h | 15 +-
28 files changed, 1879 insertions(+), 1041 deletions(-)
copy libavcodec/vulkan/{prores_reset.comp => dpx_copy.comp} (52%)
create mode 100644 libavcodec/vulkan/dpx_unpack.comp
delete mode 100644 libavcodec/vulkan/prores_raw.comp
create mode 100644 libavcodec/vulkan/prores_raw_decode.comp
create mode 100644 libavcodec/vulkan/prores_raw_idct.comp
create mode 100644 libavcodec/vulkan_dpx.c
hooks/post-receive
--
1
0
[ffmpeg] branch master updated. 38a5fcc02c fftools/ffmpeg_filter: close all no-longer needed inputs
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via 38a5fcc02c2ef1bcb37d2e53eddde8eccc0c75ed (commit)
via 623669a02cd6cdc5598801bf31fd77199e61bae1 (commit)
from 92f2f9ea5c49e94814693861a7e9e47c993fca2e (commit)
- Log -----------------------------------------------------------------
commit 38a5fcc02c2ef1bcb37d2e53eddde8eccc0c75ed
Author: Niklas Haas <git(a)haasn.dev>
AuthorDate: Wed Sep 24 15:23:04 2025 +0200
Commit: Niklas Haas <ffmpeg(a)haasn.dev>
CommitDate: Wed Nov 26 13:15:16 2025 +0000
fftools/ffmpeg_filter: close all no-longer needed inputs
Currently, the thread loop of ffmpeg_filter essentially works like this:
while (1) {
frame, idx = get_from_decoder();
err = send_to_filter_graph(frame);
if (err) { // i.e. EOF
close_input(idx);
continue;
}
while (filtered_frame = get_filtered_frame())
send_to_encoder(filtered_frame);
}
The exact details are not 100% correct since the actual control flow is a bit
more complicated as a result of the scheduler, but this is the general flow.
Notably, this leaves the possibility of leaving a no-longer-needed input
permanently open if the filter graph starts producing infinite frames (during
the second loop) *after* it finishes reading from an input, e.g. in a filter
graph like -af atrim,apad.
This patch avoids this issue by always querying the status of all filter graph
inputs and explicitly closing any that were closed downstream; after each round
of reading output frames. As a result, information about the filtergraph being
closed can now propagate back upstream, even if the filter is no longer
requesting any input frames (i.e. input_idx == fg->nb_inputs).
Fixes: https://trac.ffmpeg.org/ticket/11061
See-Also: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20457#issuecomment-6208
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 9f962e6b8c..d5ae59ec03 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -2616,6 +2616,16 @@ finish:
fps->dropped_keyframe |= fps->last_dropped && (frame->flags & AV_FRAME_FLAG_KEY);
}
+static void close_input(InputFilterPriv *ifp)
+{
+ FilterGraphPriv *fgp = fgp_from_fg(ifp->ifilter.graph);
+
+ if (!ifp->eof) {
+ sch_filter_receive_finish(fgp->sch, fgp->sch_idx, ifp->ifilter.index);
+ ifp->eof = 1;
+ }
+}
+
static int close_output(OutputFilterPriv *ofp, FilterGraphThread *fgt)
{
FilterGraphPriv *fgp = fgp_from_fg(ofp->ofilter.graph);
@@ -3343,7 +3353,7 @@ static int filter_thread(void *arg)
if (ret == AVERROR_EOF) {
av_log(fg, AV_LOG_VERBOSE, "Input %u no longer accepts new data\n",
input_idx);
- sch_filter_receive_finish(fgp->sch, fgp->sch_idx, input_idx);
+ close_input(ifp);
continue;
}
if (ret < 0)
@@ -3362,6 +3372,13 @@ read_frames:
av_err2str(ret));
goto finish;
}
+
+ // ensure all inputs no longer accepting data are closed
+ for (int i = 0; fgt.graph && i < fg->nb_inputs; i++) {
+ InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]);
+ if (av_buffersrc_get_status(ifp->ifilter.filter))
+ close_input(ifp);
+ }
}
for (unsigned i = 0; i < fg->nb_outputs; i++) {
commit 623669a02cd6cdc5598801bf31fd77199e61bae1
Author: Niklas Haas <git(a)haasn.dev>
AuthorDate: Wed Sep 24 15:14:29 2025 +0200
Commit: Niklas Haas <ffmpeg(a)haasn.dev>
CommitDate: Wed Nov 26 13:15:16 2025 +0000
avfilter/buffersrc: add av_buffersrc_get_status()
There is currently no way for API users to know that a buffersrc is no longer
accepting input, except by trying to feed it a frame and seeing what happens.
Of course, this is not possible if the user does not *have* a frame to feed,
but may still wish to know if the filter is still accepting input or not.
Since passing `frame == NULL` to `av_buffersrc_add_frame()` is already treated
as closing the input, we are left with no choice but to introduce a new
function for this.
We don't explicitly return the result of `ff_outlink_get_status()` to avoid
leaking internal status codes, and instead translate them all to AVERROR(EOF).
diff --git a/doc/APIchanges b/doc/APIchanges
index 93c6f92704..239137f1f2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
+2025-09-xx - xxxxxxxxxx - lavfi 11.10.100 - buffersrc.h
+ Add av_buffersrc_get_status().
+
2025-11-18 - xxxxxxxxxx - lavu 60.19.100 - hwcontext_amf.h
avutil/hwcontext_amf: add lock and unlock for AVAMFDeviceContext.
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index 30f4df83a1..b18d3f24dd 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -286,6 +286,16 @@ int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags)
return (flags & AV_BUFFERSRC_FLAG_PUSH) ? push_frame(ctx->graph) : 0;
}
+int av_buffersrc_get_status(AVFilterContext *ctx)
+{
+ BufferSourceContext *s = ctx->priv;
+
+ if (!s->eof && ff_outlink_get_status(ctx->outputs[0]))
+ s->eof = 1;
+
+ return s->eof ? AVERROR(EOF) : 0;
+}
+
static av_cold int init_video(AVFilterContext *ctx)
{
BufferSourceContext *c = ctx->priv;
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 54de1fd1f2..c7225b6752 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -216,6 +216,14 @@ int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
*/
int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
+/**
+ * Returns 0 or a negative AVERROR code. Currently, this will only ever
+ * return AVERROR(EOF), to indicate that the buffer source has been closed,
+ * either as a result of av_buffersrc_close(), or because the downstream
+ * filter is no longer accepting new data.
+ */
+int av_buffersrc_get_status(AVFilterContext *ctx);
+
/**
* @}
*/
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 77f38cb9b4..4a69d6be98 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,7 +31,7 @@
#include "version_major.h"
-#define LIBAVFILTER_VERSION_MINOR 9
+#define LIBAVFILTER_VERSION_MINOR 10
#define LIBAVFILTER_VERSION_MICRO 100
-----------------------------------------------------------------------
Summary of changes:
doc/APIchanges | 3 +++
fftools/ffmpeg_filter.c | 19 ++++++++++++++++++-
libavfilter/buffersrc.c | 10 ++++++++++
libavfilter/buffersrc.h | 8 ++++++++
libavfilter/version.h | 2 +-
5 files changed, 40 insertions(+), 2 deletions(-)
hooks/post-receive
--
1
0
[ffmpeg] branch release/8.0 updated. af737ace1e avutil/hwcontext_d3d12va: fix buf size when call av_buffer_create
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, release/8.0 has been updated
via af737ace1ee93fef49fe201c851359b0bf1b989b (commit)
from 565d14e4ffa2e43a7299bd20841e241c23c5847d (commit)
- Log -----------------------------------------------------------------
commit af737ace1ee93fef49fe201c851359b0bf1b989b
Author: Zhao Zhili <quinkblack(a)foxmail.com>
AuthorDate: Fri Nov 7 14:35:01 2025 +0800
Commit: Zhao Zhili <quink(a)noreply.code.ffmpeg.org>
CommitDate: Wed Nov 26 09:59:43 2025 +0000
avutil/hwcontext_d3d12va: fix buf size when call av_buffer_create
(cherry picked from commit 36e5576a44b36698614e95956c5cb6b213c29ef3)
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 6507cf69c1..9ffd17b4cc 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -267,7 +267,7 @@ static AVBufferRef *d3d12va_pool_alloc(void *opaque, size_t size)
if (!frame->sync_ctx.event)
goto fail;
- buf = av_buffer_create((uint8_t *)frame, sizeof(frame), free_texture, NULL, 0);
+ buf = av_buffer_create((uint8_t *)frame, sizeof(*frame), free_texture, NULL, 0);
if (!buf)
goto fail;
-----------------------------------------------------------------------
Summary of changes:
libavutil/hwcontext_d3d12va.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
hooks/post-receive
--
1
0
[ffmpeg] branch master updated. 92f2f9ea5c avcodec/d3d12va_encode: D3D12 AV1 encoding support
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via 92f2f9ea5c49e94814693861a7e9e47c993fca2e (commit)
from 81362b319ea7244d8d17110adfa59f10c7e78268 (commit)
- Log -----------------------------------------------------------------
commit 92f2f9ea5c49e94814693861a7e9e47c993fca2e
Author: Araz Iusubov <Primeadvice(a)gmail.com>
AuthorDate: Mon Nov 10 17:23:25 2025 +0100
Commit: Tong Wu <wutong1208(a)outlook.com>
CommitDate: Wed Nov 26 09:58:44 2025 +0000
avcodec/d3d12va_encode: D3D12 AV1 encoding support
Implement AV1 hardware encoding
using Direct3D 12 Video API (D3D12VA).
diff --git a/Changelog b/Changelog
index b4c23ac1ee..4648899ca3 100644
--- a/Changelog
+++ b/Changelog
@@ -10,6 +10,7 @@ version <next>:
- D3D12 H.264 encoder
- drawvg filter via libcairo
- ffmpeg CLI tiled HEIF support
+- D3D12 AV1 encoder
version 8.0:
diff --git a/configure b/configure
index 99734e9d03..7ef50095a3 100755
--- a/configure
+++ b/configure
@@ -3444,6 +3444,8 @@ amrwb_mediacodec_decoder_select="amr_parser"
av1_amf_encoder_deps="amf"
av1_amf_decoder_deps="amf"
av1_cuvid_decoder_deps="cuvid CUVIDAV1PICPARAMS"
+av1_d3d12va_encoder_deps="d3d12va d3d12va_av1_headers"
+av1_d3d12va_encoder_select="cbs_av1 d3d12va_encode"
av1_mediacodec_decoder_deps="mediacodec"
av1_mediacodec_encoder_deps="mediacodec"
av1_mediacodec_encoder_select="extract_extradata_bsf"
@@ -6958,6 +6960,7 @@ check_type "windows.h d3d12video.h" "ID3D12VideoDecoder"
check_type "windows.h d3d12video.h" "ID3D12VideoEncoder"
test_code cc "windows.h d3d12video.h" "D3D12_FEATURE_VIDEO feature = D3D12_FEATURE_VIDEO_ENCODER_CODEC" && \
test_code cc "windows.h d3d12video.h" "D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS req" && enable d3d12_encoder_feature
+test_code cc "windows.h d3d12video.h" "D3D12_VIDEO_ENCODER_CODEC c = D3D12_VIDEO_ENCODER_CODEC_AV1; (void)c;" && enable d3d12va_av1_headers
check_type "windows.h" "DPI_AWARENESS_CONTEXT" -D_WIN32_WINNT=0x0A00
check_type "windows.h security.h schnlsp.h" SecPkgContext_KeyingMaterialInfo -DSECURITY_WIN32
check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 0cd2408865..fba9f0aff0 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -274,6 +274,7 @@ OBJS-$(CONFIG_AURA_DECODER) += cyuv.o
OBJS-$(CONFIG_AURA2_DECODER) += aura.o
OBJS-$(CONFIG_AV1_DECODER) += av1dec.o av1_parse.o
OBJS-$(CONFIG_AV1_CUVID_DECODER) += cuviddec.o
+OBJS-$(CONFIG_AV1_D3D12VA_ENCODER) += d3d12va_encode_av1.o av1_levels.o
OBJS-$(CONFIG_AV1_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_AV1_MEDIACODEC_ENCODER) += mediacodecenc.o
OBJS-$(CONFIG_AV1_NVENC_ENCODER) += nvenc_av1.o nvenc.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 251ffae390..cce23d1541 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -855,6 +855,7 @@ extern const FFCodec ff_libaom_av1_decoder;
/* hwaccel hooks only, so prefer external decoders */
extern const FFCodec ff_av1_decoder;
extern const FFCodec ff_av1_cuvid_decoder;
+extern const FFCodec ff_av1_d3d12va_encoder;
extern const FFCodec ff_av1_mediacodec_decoder;
extern const FFCodec ff_av1_mediacodec_encoder;
extern const FFCodec ff_av1_nvenc_encoder;
diff --git a/libavcodec/d3d12va_encode.c b/libavcodec/d3d12va_encode.c
index aa8a5982be..d28447c3c9 100644
--- a/libavcodec/d3d12va_encode.c
+++ b/libavcodec/d3d12va_encode.c
@@ -29,6 +29,7 @@
#include "libavutil/hwcontext_d3d12va_internal.h"
#include "libavutil/hwcontext_d3d12va.h"
+#include "config_components.h"
#include "avcodec.h"
#include "d3d12va_encode.h"
#include "encode.h"
@@ -144,6 +145,12 @@ static int d3d12va_encode_create_metadata_buffers(AVCodecContext *avctx,
{
D3D12VAEncodeContext *ctx = avctx->priv_data;
int width = sizeof(D3D12_VIDEO_ENCODER_OUTPUT_METADATA) + sizeof(D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA);
+#if CONFIG_AV1_D3D12VA_ENCODER
+ if (ctx->codec->d3d12_codec == D3D12_VIDEO_ENCODER_CODEC_AV1) {
+ width += sizeof(D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES)
+ + sizeof(D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES);
+ }
+#endif
D3D12_HEAP_PROPERTIES encoded_meta_props = { .Type = D3D12_HEAP_TYPE_DEFAULT }, resolved_meta_props;
D3D12_HEAP_TYPE resolved_heap_type = D3D12_HEAP_TYPE_READBACK;
HRESULT hr;
@@ -211,7 +218,7 @@ static int d3d12va_encode_issue(AVCodecContext *avctx,
.RateControl = ctx->rc,
.PictureTargetResolution = ctx->resolution,
.SelectedLayoutMode = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
- .FrameSubregionsLayoutData = { 0 },
+ .FrameSubregionsLayoutData = ctx->subregions_layout,
.CodecGopSequence = ctx->gop,
},
.pInputFrame = pic->input_surface->texture,
@@ -732,16 +739,21 @@ end:
static int d3d12va_encode_output(AVCodecContext *avctx,
FFHWBaseEncodePicture *base_pic, AVPacket *pkt)
{
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
- D3D12VAEncodePicture *pic = base_pic->priv;
- AVPacket *pkt_ptr = pkt;
- int err;
+ D3D12VAEncodePicture *pic = base_pic->priv;
+ AVPacket *pkt_ptr = pkt;
+ int err = 0;
err = d3d12va_encode_wait(avctx, base_pic);
if (err < 0)
return err;
- err = d3d12va_encode_get_coded_data(avctx, pic, pkt);
+ if (ctx->codec->get_coded_data)
+ err = ctx->codec->get_coded_data(avctx, pic, pkt);
+ else
+ err = d3d12va_encode_get_coded_data(avctx, pic, pkt);
+
if (err < 0)
return err;
@@ -1129,6 +1141,9 @@ static int d3d12va_encode_init_gop_structure(AVCodecContext *avctx)
union {
D3D12_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT_H264 h264;
D3D12_VIDEO_ENCODER_CODEC_PICTURE_CONTROL_SUPPORT_HEVC hevc;
+#if CONFIG_AV1_D3D12VA_ENCODER
+ D3D12_VIDEO_ENCODER_CODEC_AV1_PICTURE_CONTROL_SUPPORT av1;
+#endif
} codec_support;
support.NodeIndex = 0;
@@ -1146,6 +1161,13 @@ static int d3d12va_encode_init_gop_structure(AVCodecContext *avctx)
support.PictureSupport.pHEVCSupport = &codec_support.hevc;
break;
+#if CONFIG_AV1_D3D12VA_ENCODER
+ case D3D12_VIDEO_ENCODER_CODEC_AV1:
+ memset(&codec_support.av1, 0, sizeof(codec_support.av1));
+ support.PictureSupport.DataSize = sizeof(codec_support.av1);
+ support.PictureSupport.pAV1Support = &codec_support.av1;
+ break;
+#endif
default:
av_assert0(0);
}
@@ -1171,6 +1193,13 @@ static int d3d12va_encode_init_gop_structure(AVCodecContext *avctx)
ref_l1 = support.PictureSupport.pHEVCSupport->MaxL1ReferencesForB;
break;
+#if CONFIG_AV1_D3D12VA_ENCODER
+ case D3D12_VIDEO_ENCODER_CODEC_AV1:
+ ref_l0 = support.PictureSupport.pAV1Support->MaxUniqueReferencesPerFrame;
+ // AV1 doesn't use traditional L1 references like H.264/HEVC
+ ref_l1 = 0;
+ break;
+#endif
default:
av_assert0(0);
}
@@ -1521,6 +1550,12 @@ int ff_d3d12va_encode_init(AVCodecContext *avctx)
if (err < 0)
goto fail;
+ if (ctx->codec->set_tile) {
+ err = ctx->codec->set_tile(avctx);
+ if (err < 0)
+ goto fail;
+ }
+
err = d3d12va_encode_init_rate_control(avctx);
if (err < 0)
goto fail;
diff --git a/libavcodec/d3d12va_encode.h b/libavcodec/d3d12va_encode.h
index 5bd1eedb7f..b7cfea0582 100644
--- a/libavcodec/d3d12va_encode.h
+++ b/libavcodec/d3d12va_encode.h
@@ -264,6 +264,8 @@ typedef struct D3D12VAEncodeContext {
D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE gop;
D3D12_VIDEO_ENCODER_LEVEL_SETTING level;
+
+ D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA subregions_layout;
} D3D12VAEncodeContext;
typedef struct D3D12VAEncodeType {
@@ -306,6 +308,11 @@ typedef struct D3D12VAEncodeType {
*/
int (*set_level)(AVCodecContext *avctx);
+ /**
+ * Set codec-specific tile setting.
+ */
+ int (*set_tile)(AVCodecContext *avctx);
+
/**
* The size of any private data structure associated with each
* picture (can be zero if not required).
@@ -327,6 +334,12 @@ typedef struct D3D12VAEncodeType {
*/
int (*write_sequence_header)(AVCodecContext *avctx,
char *data, size_t *data_len);
+
+ /**
+ * Fill the coded data into AVPacket
+ */
+ int (*get_coded_data)(AVCodecContext *avctx,
+ D3D12VAEncodePicture *pic, AVPacket *pkt);
} D3D12VAEncodeType;
int ff_d3d12va_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt);
diff --git a/libavcodec/d3d12va_encode_av1.c b/libavcodec/d3d12va_encode_av1.c
new file mode 100644
index 0000000000..e7a115a2ee
--- /dev/null
+++ b/libavcodec/d3d12va_encode_av1.c
@@ -0,0 +1,1182 @@
+/*
+ * Direct3D 12 HW acceleration video encoder
+ *
+ * Copyright (c) 2024 Intel Corporation
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/opt.h"
+#include "libavutil/common.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/hwcontext_d3d12va_internal.h"
+
+#include "config_components.h"
+#include "avcodec.h"
+#include "cbs.h"
+#include "cbs_av1.h"
+#include "av1_levels.h"
+#include "codec_internal.h"
+#include "d3d12va_encode.h"
+#include "encode.h"
+#include "hw_base_encode.h"
+
+#include <d3d12.h>
+#include <d3d12video.h>
+
+#ifndef D3D12_VIDEO_ENCODER_AV1_INVALID_DPB_RESOURCE_INDEX
+#define D3D12_VIDEO_ENCODER_AV1_INVALID_DPB_RESOURCE_INDEX ( 0xff )
+#endif
+
+typedef struct D3D12VAHWBaseEncodeAV1 {
+ AV1RawOBU raw_sequence_header;
+ AV1RawOBU raw_frame_header;
+ AV1RawOBU raw_tile_group;
+} D3D12VAHWBaseEncodeAV1;
+
+typedef struct D3D12VAHWBaseEncodeAV1Opts {
+ int tier; // 0: Main tier, 1: High tier
+ int level; // AV1 level (2.0-7.3 map to 0-23)
+
+ int enable_cdef; // Constrained Directional Enhancement Filter
+ int enable_restoration; // loop restoration
+ int enable_superres; // super-resolution
+ int enable_ref_frame_mvs;
+
+ int enable_jnt_comp;
+ int enable_128x128_superblock;
+
+ int enable_warped_motion;
+ int enable_intra_edge_filter;
+ int enable_interintra_compound;
+ int enable_masked_compound;
+ int enable_filter_intra;
+
+ int enable_loop_filter;
+ int enable_loop_filter_delta;
+ int enable_dual_filter;
+
+ int enable_palette;
+ int enable_intra_block_copy;
+} D3D12VAHWBaseEncodeAV1Opts;
+
+typedef struct D3D12VAEncodeAV1Picture {
+ uint8_t temporal_id;
+ uint8_t spatial_id;
+ uint8_t show_frame;
+ uint8_t frame_type;
+ uint16_t last_idr_frame;
+ uint8_t slot;
+} D3D12VAEncodeAV1Picture;
+
+typedef struct D3D12VAEncodeAV1Context {
+ D3D12VAEncodeContext common;
+ // User options.
+ int qp;
+ int profile;
+ int level;
+ int tier;
+
+ uint8_t q_idx_idr;
+ uint8_t q_idx_p;
+
+ // Writer structures.
+ D3D12VAHWBaseEncodeAV1 units;
+ D3D12VAHWBaseEncodeAV1Opts unit_opts;
+
+ CodedBitstreamContext *cbc;
+ CodedBitstreamFragment current_obu;
+ D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAGS post_encode_values_flag;
+ AVFifo *picture_header_list;
+} D3D12VAEncodeAV1Context;
+
+typedef struct D3D12VAEncodeAV1Level {
+ uint8_t level;
+ D3D12_VIDEO_ENCODER_AV1_LEVELS d3d12_level;
+} D3D12VAEncodeAV1Level;
+
+
+static const D3D12VAEncodeAV1Level av1_levels[] = {
+ { 0, D3D12_VIDEO_ENCODER_AV1_LEVELS_2_0 },
+ { 1, D3D12_VIDEO_ENCODER_AV1_LEVELS_2_1 },
+ { 2, D3D12_VIDEO_ENCODER_AV1_LEVELS_2_2 },
+ { 3, D3D12_VIDEO_ENCODER_AV1_LEVELS_2_3 },
+ { 4, D3D12_VIDEO_ENCODER_AV1_LEVELS_3_0 },
+ { 5, D3D12_VIDEO_ENCODER_AV1_LEVELS_3_1 },
+ { 6, D3D12_VIDEO_ENCODER_AV1_LEVELS_3_2 },
+ { 7, D3D12_VIDEO_ENCODER_AV1_LEVELS_3_3 },
+ { 8, D3D12_VIDEO_ENCODER_AV1_LEVELS_4_0 },
+ { 9, D3D12_VIDEO_ENCODER_AV1_LEVELS_4_1 },
+ { 10, D3D12_VIDEO_ENCODER_AV1_LEVELS_4_2 },
+ { 11, D3D12_VIDEO_ENCODER_AV1_LEVELS_4_3 },
+ { 12, D3D12_VIDEO_ENCODER_AV1_LEVELS_5_0 },
+ { 13, D3D12_VIDEO_ENCODER_AV1_LEVELS_5_1 },
+ { 14, D3D12_VIDEO_ENCODER_AV1_LEVELS_5_2 },
+ { 15, D3D12_VIDEO_ENCODER_AV1_LEVELS_5_3 },
+ { 16, D3D12_VIDEO_ENCODER_AV1_LEVELS_6_0 },
+ { 17, D3D12_VIDEO_ENCODER_AV1_LEVELS_6_1 },
+ { 18, D3D12_VIDEO_ENCODER_AV1_LEVELS_6_2 },
+ { 19, D3D12_VIDEO_ENCODER_AV1_LEVELS_6_3 },
+ { 20, D3D12_VIDEO_ENCODER_AV1_LEVELS_7_0 },
+ { 21, D3D12_VIDEO_ENCODER_AV1_LEVELS_7_1 },
+ { 22, D3D12_VIDEO_ENCODER_AV1_LEVELS_7_2 },
+ { 23, D3D12_VIDEO_ENCODER_AV1_LEVELS_7_3 },
+};
+
+static const D3D12_VIDEO_ENCODER_AV1_PROFILE profile_main = D3D12_VIDEO_ENCODER_AV1_PROFILE_MAIN;
+static const D3D12_VIDEO_ENCODER_AV1_PROFILE profile_high = D3D12_VIDEO_ENCODER_AV1_PROFILE_HIGH;
+static const D3D12_VIDEO_ENCODER_AV1_PROFILE profile_professional = D3D12_VIDEO_ENCODER_AV1_PROFILE_PROFESSIONAL;
+
+#define D3D_PROFILE_DESC(name) \
+ { sizeof(D3D12_VIDEO_ENCODER_AV1_PROFILE), { .pAV1Profile = (D3D12_VIDEO_ENCODER_AV1_PROFILE *)&profile_ ## name } }
+static const D3D12VAEncodeProfile d3d12va_encode_av1_profiles[] = {
+ { AV_PROFILE_AV1_MAIN, 8, 3, 1, 1, D3D_PROFILE_DESC(main) },
+ { AV_PROFILE_AV1_MAIN, 10, 3, 1, 1, D3D_PROFILE_DESC(main) },
+ { AV_PROFILE_AV1_HIGH, 10, 3, 1, 1, D3D_PROFILE_DESC(high) },
+ { AV_PROFILE_AV1_PROFESSIONAL, 8, 3, 1, 1, D3D_PROFILE_DESC(professional) },
+ { AV_PROFILE_AV1_PROFESSIONAL, 10, 3, 1, 1, D3D_PROFILE_DESC(professional) },
+ { AV_PROFILE_AV1_PROFESSIONAL, 12, 3, 1, 1, D3D_PROFILE_DESC(professional) },
+ { AV_PROFILE_UNKNOWN },
+};
+
+static int d3d12va_encode_av1_write_obu(AVCodecContext *avctx,
+ char *data, size_t *data_len,
+ CodedBitstreamFragment *obu)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ int err = 0;
+
+ err = ff_cbs_write_fragment_data(priv->cbc, obu);
+ if (err < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to write packed OBU data.\n");
+ return err;
+ }
+
+ memcpy(data, obu->data, obu->data_size);
+ *data_len = (8 * obu->data_size) - obu->data_bit_padding;
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_add_obu(AVCodecContext* avctx,
+ CodedBitstreamFragment* au,
+ CodedBitstreamUnitType obu_type,
+ void* obu_unit)
+{
+ int err = 0;
+
+ err = ff_cbs_insert_unit_content(au, -1, obu_type, obu_unit, NULL);
+ if (err < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to add OBU unit: "
+ "type = %d.\n", obu_type);
+ return err;
+ }
+ return 0;
+}
+
+static int d3d12va_encode_av1_write_sequence_header(AVCodecContext *avctx,
+ char *data, size_t *data_len)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ CodedBitstreamFragment *obu = &priv->current_obu;
+ int err = 0;
+
+ priv->units.raw_sequence_header.header.obu_type = AV1_OBU_SEQUENCE_HEADER;
+ err = d3d12va_encode_av1_add_obu(avctx, obu, AV1_OBU_SEQUENCE_HEADER, &priv->units.raw_sequence_header);
+ if (err < 0)
+ goto fail;
+
+ err = d3d12va_encode_av1_write_obu(avctx, data, data_len, obu);
+
+fail:
+ ff_cbs_fragment_reset(obu);
+ return err;
+}
+
+static int d3d12va_encode_av1_update_current_frame_picture_header(AVCodecContext *avctx,
+ D3D12VAEncodePicture *pic,
+ AV1RawOBU *frameheader_obu)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ AV1RawFrameHeader *fh = &frameheader_obu->obu.frame_header;
+ uint8_t *data = NULL;
+ HRESULT hr = S_OK;
+ int err = 0;
+ D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES *post_encode_values = NULL;
+
+ // Update the frame header according to the picture post_encode_values
+ hr = ID3D12Resource_Map(pic->resolved_metadata, 0, NULL, (void **)&data);
+ if (FAILED(hr)) {
+ err = AVERROR_UNKNOWN;
+ return err;
+ }
+ post_encode_values = (D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES*) (data +
+ sizeof(D3D12_VIDEO_ENCODER_OUTPUT_METADATA) +
+ sizeof(D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA) +
+ sizeof(D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES));
+
+ if (priv->post_encode_values_flag & D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAG_QUANTIZATION) {
+ fh->base_q_idx = post_encode_values->Quantization.BaseQIndex;
+ fh->delta_q_y_dc = post_encode_values->Quantization.YDCDeltaQ;
+ fh->delta_q_u_dc = post_encode_values->Quantization.UDCDeltaQ;
+ fh->delta_q_u_ac = post_encode_values->Quantization.UACDeltaQ;
+ fh->delta_q_v_dc = post_encode_values->Quantization.VDCDeltaQ;
+ fh->delta_q_v_ac = post_encode_values->Quantization.VACDeltaQ;
+ fh->using_qmatrix = post_encode_values->Quantization.UsingQMatrix;
+ fh->qm_y = post_encode_values->Quantization.QMY;
+ fh->qm_u = post_encode_values->Quantization.QMU;
+ fh->qm_v = post_encode_values->Quantization.QMV;
+ }
+
+ if (priv->post_encode_values_flag & D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAG_LOOP_FILTER) {
+ fh->loop_filter_level[0] = post_encode_values->LoopFilter.LoopFilterLevel[0];
+ fh->loop_filter_level[1] = post_encode_values->LoopFilter.LoopFilterLevel[1];
+ fh->loop_filter_level[2] = post_encode_values->LoopFilter.LoopFilterLevelU;
+ fh->loop_filter_level[3] = post_encode_values->LoopFilter.LoopFilterLevelV;
+ fh->loop_filter_sharpness = post_encode_values->LoopFilter.LoopFilterSharpnessLevel;
+ fh->loop_filter_delta_enabled = post_encode_values->LoopFilter.LoopFilterDeltaEnabled;
+ if (fh->loop_filter_delta_enabled) {
+ for (int i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
+ fh->loop_filter_ref_deltas[i] = post_encode_values->LoopFilter.RefDeltas[i];
+ fh->update_ref_delta[i] = post_encode_values->LoopFilter.RefDeltas[i];
+ }
+ for (int i = 0; i < 2; i++) {
+ fh->loop_filter_mode_deltas[i] = post_encode_values->LoopFilter.ModeDeltas[i];
+ fh->update_mode_delta[i] = post_encode_values->LoopFilter.ModeDeltas[i];
+ }
+ }
+ }
+ if (priv->post_encode_values_flag & D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAG_CDEF_DATA) {
+ fh->cdef_damping_minus_3 = post_encode_values->CDEF.CdefDampingMinus3;
+ fh->cdef_bits = post_encode_values->CDEF.CdefBits;
+ for (int i = 0; i < 8; i++) {
+ fh->cdef_y_pri_strength[i] = post_encode_values->CDEF.CdefYPriStrength[i];
+ fh->cdef_y_sec_strength[i] = post_encode_values->CDEF.CdefYSecStrength[i];
+ fh->cdef_uv_pri_strength[i] = post_encode_values->CDEF.CdefUVPriStrength[i];
+ fh->cdef_uv_sec_strength[i] = post_encode_values->CDEF.CdefUVSecStrength[i];
+ }
+ }
+ if (priv->post_encode_values_flag & D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAG_QUANTIZATION_DELTA) {
+ fh->delta_q_present = post_encode_values->QuantizationDelta.DeltaQPresent;
+ fh->delta_q_res = post_encode_values->QuantizationDelta.DeltaQRes;
+ }
+
+ if (priv->post_encode_values_flag & D3D12_VIDEO_ENCODER_AV1_POST_ENCODE_VALUES_FLAG_REFERENCE_INDICES) {
+ for (int i = 0; i < AV1_REFS_PER_FRAME; i++) {
+ fh->ref_frame_idx[i] = post_encode_values->ReferenceIndices[i];
+ }
+ }
+
+ ID3D12Resource_Unmap(pic->resolved_metadata, 0, NULL);
+ return 0;
+}
+
+static int d3d12va_encode_av1_write_picture_header(AVCodecContext *avctx,
+ D3D12VAEncodePicture *pic,
+ char *data, size_t *data_len)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ CodedBitstreamFragment *obu = &priv->current_obu;
+ AV1RawOBU *frameheader_obu = av_mallocz(sizeof(AV1RawOBU));
+ int err = 0;
+
+ av_fifo_read(priv->picture_header_list, frameheader_obu, 1);
+ err = d3d12va_encode_av1_update_current_frame_picture_header(avctx, pic,frameheader_obu);
+ if (err < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to update current frame picture header: %d.\n", err);
+ return err;
+ }
+
+ // Add the frame header OBU
+ frameheader_obu->header.obu_has_size_field = 1;
+
+ err = d3d12va_encode_av1_add_obu(avctx, obu, AV1_OBU_FRAME_HEADER, frameheader_obu);
+ if (err < 0)
+ goto fail;
+ err = d3d12va_encode_av1_write_obu(avctx, data, data_len, obu);
+
+fail:
+ ff_cbs_fragment_reset(obu);
+ av_freep(&frameheader_obu);
+ return err;
+}
+
+static int d3d12va_encode_av1_write_tile_group(AVCodecContext *avctx,
+ uint8_t* tile_group,
+ uint32_t tile_group_size,
+ char *data, size_t *data_len)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ CodedBitstreamFragment *obu = &priv->current_obu;
+ AV1RawOBU *tile_group_obu = &priv->units.raw_tile_group;
+ AV1RawTileGroup *tg = &tile_group_obu->obu.tile_group;
+ int err = 0;
+
+ tg->tile_data.data = tile_group;
+ tg->tile_data.data_ref = NULL;
+ tg->tile_data.data_size = tile_group_size;
+ tile_group_obu->header.obu_has_size_field = 1;
+ tile_group_obu->header.obu_type = AV1_OBU_TILE_GROUP;
+
+ err = d3d12va_encode_av1_add_obu(avctx, obu, AV1_OBU_TILE_GROUP, tile_group_obu);
+ if (err < 0)
+ goto fail;
+ err = d3d12va_encode_av1_write_obu(avctx, data, data_len, obu);
+
+fail:
+ ff_cbs_fragment_reset(obu);
+ return err;
+}
+
+static int d3d12va_encode_av1_get_buffer_size(AVCodecContext *avctx,
+ D3D12VAEncodePicture *pic, size_t *size)
+{
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12_VIDEO_ENCODER_OUTPUT_METADATA *meta = NULL;
+ D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA *subregion_meta = NULL;
+ uint8_t *data = NULL;
+ HRESULT hr = S_OK;
+ int err = 0;
+
+ hr = ID3D12Resource_Map(pic->resolved_metadata, 0, NULL, (void **)&data);
+ if (FAILED(hr)) {
+ err = AVERROR_UNKNOWN;
+ return err;
+ }
+
+ subregion_meta = (D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA*)(data + sizeof(D3D12_VIDEO_ENCODER_OUTPUT_METADATA));
+ if (subregion_meta->bSize == 0) {
+ av_log(avctx, AV_LOG_ERROR, "No subregion metadata found\n");
+ err = AVERROR(EINVAL);
+ return err;
+ }
+ *size = subregion_meta->bSize;
+
+ ID3D12Resource_Unmap(pic->resolved_metadata, 0, NULL);
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_get_coded_data(AVCodecContext *avctx,
+ D3D12VAEncodePicture *pic, AVPacket *pkt)
+{
+ int err = 0;
+ uint8_t *ptr = NULL;
+ uint8_t *mapped_data = NULL;
+ size_t total_size = 0;
+ HRESULT hr = S_OK;
+ size_t av1_pic_hd_size = 0;
+ int tile_group_extra_size = 0;
+ size_t bit_len = 0;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+
+ char pic_hd_data[MAX_PARAM_BUFFER_SIZE] = { 0 };
+
+ err = d3d12va_encode_av1_get_buffer_size(avctx, pic, &total_size);
+ if (err < 0)
+ goto end;
+
+ // Update the picture header and calculate the picture header size
+ memset(pic_hd_data, 0, sizeof(pic_hd_data));
+ err = d3d12va_encode_av1_write_picture_header(avctx, pic, pic_hd_data, &av1_pic_hd_size);
+ if (err < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to write picture header: %d.\n", err);
+ return err;
+ }
+ av1_pic_hd_size /= 8;
+ av_log(avctx, AV_LOG_DEBUG, "AV1 picture header size: %zu bytes.\n", av1_pic_hd_size);
+
+
+ tile_group_extra_size = (av_log2(total_size) + 7) / 7 + 1; // 1 byte for obu header, rest for tile group LEB128 size
+ av_log(avctx, AV_LOG_DEBUG, "Tile group extra size: %d bytes.\n", tile_group_extra_size);
+
+ total_size += (pic->header_size + tile_group_extra_size + av1_pic_hd_size);
+ av_log(avctx, AV_LOG_DEBUG, "Output buffer size %"SIZE_SPECIFIER"\n", total_size);
+
+ hr = ID3D12Resource_Map(pic->output_buffer, 0, NULL, (void **)&mapped_data);
+ if (FAILED(hr)) {
+ err = AVERROR_UNKNOWN;
+ goto end;
+ }
+
+ err = ff_get_encode_buffer(avctx, pkt, total_size, 0);
+ if (err < 0)
+ goto end;
+ ptr = pkt->data;
+
+ memcpy(ptr, mapped_data, pic->header_size);
+
+ ptr += pic->header_size;
+ mapped_data += pic->aligned_header_size;
+ total_size -= pic->header_size;
+
+ memcpy(ptr, pic_hd_data, av1_pic_hd_size);
+ ptr += av1_pic_hd_size;
+ total_size -= av1_pic_hd_size;
+ av_log(avctx, AV_LOG_DEBUG, "AV1 total_size after write picture header: %d.\n", total_size);
+
+ total_size -= tile_group_extra_size;
+ err = d3d12va_encode_av1_write_tile_group(avctx, mapped_data, total_size, ptr, &bit_len);
+ if (err < 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to write tile group: %d.\n", err);
+ goto end;
+ }
+ assert((total_size + tile_group_extra_size) * 8 == bit_len);
+
+ ID3D12Resource_Unmap(pic->output_buffer, 0, NULL);
+
+end:
+ av_buffer_unref(&pic->output_buffer_ref);
+ pic->output_buffer = NULL;
+ return err;
+}
+
+static int d3d12va_hw_base_encode_init_params_av1(FFHWBaseEncodeContext *base_ctx,
+ AVCodecContext *avctx,
+ D3D12VAHWBaseEncodeAV1 *common,
+ D3D12VAHWBaseEncodeAV1Opts *opts)
+{
+ AV1RawOBU *seqheader_obu = &common->raw_sequence_header;
+ AV1RawSequenceHeader *seq = &seqheader_obu->obu.sequence_header;
+ const AVPixFmtDescriptor *desc;
+
+ seq->seq_profile = avctx->profile;
+ if (!seq->seq_force_screen_content_tools)
+ seq->seq_force_integer_mv = AV1_SELECT_INTEGER_MV;
+ seq->seq_tier[0] = opts->tier;
+
+ desc = av_pix_fmt_desc_get(base_ctx->input_frames->sw_format);
+ seq->color_config = (AV1RawColorConfig){
+ .high_bitdepth = desc->comp[0].depth == 8 ? 0 : 1,
+ .color_primaries = avctx->color_primaries,
+ .transfer_characteristics = avctx->color_trc,
+ .matrix_coefficients = avctx->colorspace,
+ .color_description_present_flag = (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
+ avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
+ avctx->colorspace != AVCOL_SPC_UNSPECIFIED),
+ .color_range = avctx->color_range == AVCOL_RANGE_JPEG,
+ .subsampling_x = desc->log2_chroma_w,
+ .subsampling_y = desc->log2_chroma_h,
+ };
+
+ switch (avctx->chroma_sample_location) {
+ case AVCHROMA_LOC_LEFT:
+ seq->color_config.chroma_sample_position = AV1_CSP_VERTICAL;
+ break;
+ case AVCHROMA_LOC_TOPLEFT:
+ seq->color_config.chroma_sample_position = AV1_CSP_COLOCATED;
+ break;
+ default:
+ seq->color_config.chroma_sample_position = AV1_CSP_UNKNOWN;
+ break;
+ }
+
+ if (avctx->level != AV_LEVEL_UNKNOWN) {
+ seq->seq_level_idx[0] = avctx->level;
+ }
+ else {
+ const AV1LevelDescriptor *level;
+ float framerate;
+
+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ framerate = avctx->framerate.num / avctx->framerate.den;
+ else
+ framerate = 0;
+
+ //currently only supporting 1 tile
+ level = ff_av1_guess_level(avctx->bit_rate, opts->tier,
+ base_ctx->surface_width, base_ctx->surface_height,
+ /*priv->tile_rows*/1 * 1/*priv->tile_cols*/,
+ /*priv->tile_cols*/1, framerate);
+ if (level) {
+ av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
+ seq->seq_level_idx[0] = level->level_idx;
+ }
+ else {
+ av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
+ "any normal level, using maximum parameters level by default.\n");
+ seq->seq_level_idx[0] = 31;
+ seq->seq_tier[0] = 1;
+ }
+ }
+
+ // Still picture mode
+ seq->still_picture = (base_ctx->gop_size == 1);
+ seq->reduced_still_picture_header = seq->still_picture;
+
+ // Feature flags
+ seq->enable_filter_intra = opts->enable_filter_intra;
+ seq->enable_intra_edge_filter = opts->enable_intra_edge_filter;
+ seq->enable_interintra_compound = opts->enable_interintra_compound;
+ seq->enable_masked_compound = opts->enable_masked_compound;
+ seq->enable_warped_motion = opts->enable_warped_motion;
+ seq->enable_dual_filter = opts->enable_dual_filter;
+ seq->enable_order_hint = !seq->still_picture;
+ if (seq->enable_order_hint) {
+ seq->order_hint_bits_minus_1 = 7;
+ }
+ seq->enable_jnt_comp = opts->enable_jnt_comp && seq->enable_order_hint;
+ seq->enable_ref_frame_mvs = opts->enable_ref_frame_mvs && seq->enable_order_hint;
+ seq->enable_superres = opts->enable_superres;
+ seq->enable_cdef = opts->enable_cdef;
+ seq->enable_restoration = opts->enable_restoration;
+
+ return 0;
+
+}
+
+static int d3d12va_encode_av1_init_sequence_params(AVCodecContext *avctx)
+{
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ AVD3D12VAFramesContext *hwctx = base_ctx->input_frames->hwctx;
+ AV1RawOBU *seqheader_obu = &priv->units.raw_sequence_header;
+ AV1RawSequenceHeader *seq = &priv->units.raw_sequence_header.obu.sequence_header;
+
+ D3D12_VIDEO_ENCODER_AV1_PROFILE profile = D3D12_VIDEO_ENCODER_AV1_PROFILE_MAIN;
+ D3D12_VIDEO_ENCODER_AV1_LEVEL_TIER_CONSTRAINTS level = { 0 };
+ HRESULT hr;
+ int err;
+
+ D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT1 support = {
+ .NodeIndex = 0,
+ .Codec = D3D12_VIDEO_ENCODER_CODEC_AV1,
+ .InputFormat = hwctx->format,
+ .RateControl = ctx->rc,
+ .IntraRefresh = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE,
+ .SubregionFrameEncoding = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
+ .ResolutionsListCount = 1,
+ .pResolutionList = &ctx->resolution,
+ .CodecGopSequence = ctx->gop,
+ .MaxReferenceFramesInDPB = AV1_NUM_REF_FRAMES,
+ .CodecConfiguration = ctx->codec_conf,
+ .SuggestedProfile.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_PROFILE),
+ .SuggestedProfile.pAV1Profile = &profile,
+ .SuggestedLevel.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_LEVEL_TIER_CONSTRAINTS),
+ .SuggestedLevel.pAV1LevelSetting = &level,
+ .pResolutionDependentSupport = &ctx->res_limits,
+ .SubregionFrameEncodingData.pTilesPartition_AV1 = ctx->subregions_layout.pTilesPartition_AV1,
+ };
+
+ hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_SUPPORT1,
+ &support, sizeof(support));
+
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to check encoder support(%lx).\n", (long)hr);
+ return AVERROR(EINVAL);
+ }
+
+ if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK)) {
+ av_log(avctx, AV_LOG_ERROR, "Driver does not support some request D3D12VA AV1 features. %#x\n",
+ support.ValidationFlags);
+ return AVERROR(EINVAL);
+ }
+
+ if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RECONSTRUCTED_FRAMES_REQUIRE_TEXTURE_ARRAYS) {
+ ctx->is_texture_array = 1;
+ av_log(avctx, AV_LOG_DEBUG, "D3D12 video encode on this device uses texture array mode.\n");
+ }
+
+ memset(seqheader_obu, 0, sizeof(*seqheader_obu));
+ seq->seq_profile = profile;
+ seq->seq_level_idx[0] = level.Level;
+ seq->seq_tier[0] = level.Tier;
+
+ seq->max_frame_width_minus_1 = ctx->resolution.Width - 1;
+ seq->max_frame_height_minus_1 = ctx->resolution.Height - 1;
+ seq->frame_width_bits_minus_1 = av_log2(ctx->resolution.Width);
+ seq->frame_height_bits_minus_1 = av_log2(ctx->resolution.Height);
+
+ seqheader_obu->header.obu_type = AV1_OBU_SEQUENCE_HEADER;
+
+ err = d3d12va_hw_base_encode_init_params_av1(base_ctx, avctx,
+ &priv->units, &priv->unit_opts);
+ if (err < 0)
+ return err;
+
+ if (avctx->level == AV_LEVEL_UNKNOWN)
+ avctx->level = level.Level;
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_get_encoder_caps(AVCodecContext *avctx)
+{
+ HRESULT hr = S_OK;
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+
+ D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION *config;
+ D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION_SUPPORT av1_caps;
+
+ D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
+ .NodeIndex = 0,
+ .Codec = D3D12_VIDEO_ENCODER_CODEC_AV1,
+ .Profile = ctx->profile->d3d12_profile,
+ .CodecSupportLimits.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION_SUPPORT),
+ };
+
+ codec_caps.CodecSupportLimits.pAV1Support = &av1_caps;
+
+ hr = ID3D12VideoDevice3_CheckFeatureSupport(ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
+ &codec_caps, sizeof(codec_caps));
+ if (!(SUCCEEDED(hr) && codec_caps.IsSupported))
+ return AVERROR(EINVAL);
+
+ ctx->codec_conf.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION);
+ ctx->codec_conf.pAV1Config = av_mallocz(ctx->codec_conf.DataSize);
+ if (!ctx->codec_conf.pAV1Config)
+ return AVERROR(ENOMEM);
+
+ priv->post_encode_values_flag = av1_caps.PostEncodeValuesFlags;
+ config = ctx->codec_conf.pAV1Config;
+
+ config->FeatureFlags = D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_NONE;
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_128x128_SUPERBLOCK) {
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_128x128_SUPERBLOCK;
+ priv->unit_opts.enable_128x128_superblock = 1;
+ }
+
+ base_ctx->surface_width = FFALIGN(avctx->width, priv->unit_opts.enable_128x128_superblock ? 128 : 64);
+ base_ctx->surface_height = FFALIGN(avctx->height, priv->unit_opts.enable_128x128_superblock ? 128 : 64);
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_LOOP_RESTORATION_FILTER) {
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_LOOP_RESTORATION_FILTER;
+ priv->unit_opts.enable_loop_filter = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_PALETTE_ENCODING) {
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_PALETTE_ENCODING;
+ priv->unit_opts.enable_palette = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_INTRA_BLOCK_COPY) {
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_INTRA_BLOCK_COPY;
+ priv->unit_opts.enable_intra_block_copy = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_LOOP_FILTER_DELTAS) {
+ // Loop filter deltas
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_LOOP_FILTER_DELTAS;
+ priv->unit_opts.enable_loop_filter_delta = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_CDEF_FILTERING) {
+ // CDEF (Constrained Directional Enhancement Filter)
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_CDEF_FILTERING;
+ priv->unit_opts.enable_cdef = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_DUAL_FILTER) {
+ // Dual filter
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_DUAL_FILTER;
+ priv->unit_opts.enable_dual_filter = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_JNT_COMP) {
+ // Joint compound prediction
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_JNT_COMP;
+ priv->unit_opts.enable_jnt_comp = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_FRAME_REFERENCE_MOTION_VECTORS) {
+ // Frame reference motion vectors
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_FRAME_REFERENCE_MOTION_VECTORS;
+ priv->unit_opts.enable_ref_frame_mvs = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_SUPER_RESOLUTION) {
+ // Super-resolution
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_SUPER_RESOLUTION;
+ priv->unit_opts.enable_superres = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_WARPED_MOTION) {
+ // Warped motion
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_WARPED_MOTION;
+ priv->unit_opts.enable_warped_motion = 1;
+ }
+
+ if (av1_caps.SupportedFeatureFlags & D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_INTERINTRA_COMPOUND) {
+ // Inter-intra compound prediction
+ config->FeatureFlags |= D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_INTERINTRA_COMPOUND;
+ priv->unit_opts.enable_interintra_compound = 1;
+ }
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_configure(AVCodecContext *avctx)
+{
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ int err = 0;
+ int fixed_qp_key, fixed_qp_inter;
+
+ err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_AV1, avctx);
+ if (err < 0)
+ return err;
+
+ if (ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
+ D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
+ fixed_qp_inter = av_clip_uintp2(ctx->rc_quality, 8);
+
+ if (avctx->i_quant_factor > 0.0)
+ fixed_qp_key = av_clip_uintp2((avctx->i_quant_factor * fixed_qp_inter +
+ avctx->i_quant_offset) + 0.5, 8);
+ else
+ fixed_qp_key = fixed_qp_inter;
+
+ av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
+ "%d / %d for Key / Inter frames.\n",
+ fixed_qp_key, fixed_qp_inter);
+
+ ctx->rc.ConfigParams.DataSize = sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
+ cqp_ctl = av_mallocz(ctx->rc.ConfigParams.DataSize);
+ if (!cqp_ctl)
+ return AVERROR(ENOMEM);
+
+ cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_key;
+ cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_inter;
+ cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_inter;
+
+ ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
+
+ priv->q_idx_idr = fixed_qp_key;
+ priv->q_idx_p = fixed_qp_inter;
+
+ }
+
+ // GOP configuration for AV1
+ ctx->gop.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_SEQUENCE_STRUCTURE);
+ ctx->gop.pAV1SequenceStructure = av_mallocz(ctx->gop.DataSize);
+ if (!ctx->gop.pAV1SequenceStructure)
+ return AVERROR(ENOMEM);
+
+ ctx->gop.pAV1SequenceStructure->IntraDistance = base_ctx->gop_size;
+ ctx->gop.pAV1SequenceStructure->InterFramePeriod = base_ctx->b_per_p + 1;
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_set_level(AVCodecContext *avctx)
+{
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ int i = 0;
+
+ ctx->level.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_LEVEL_TIER_CONSTRAINTS);
+ ctx->level.pAV1LevelSetting = av_mallocz(ctx->level.DataSize);
+ if (!ctx->level.pAV1LevelSetting)
+ return AVERROR(ENOMEM);
+
+ if (avctx->level != AV_LEVEL_UNKNOWN) {
+ for (i = 0; i < FF_ARRAY_ELEMS(av1_levels); i++) {
+ if (avctx->level == av1_levels[i].level) {
+ ctx->level.pAV1LevelSetting->Level = av1_levels[i].d3d12_level;
+ break;
+ }
+ }
+
+ if (i == FF_ARRAY_ELEMS(av1_levels) ) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid AV1 level %d.\n", avctx->level);
+ return AVERROR(EINVAL);
+ }
+ } else {
+ ctx->level.pAV1LevelSetting->Level = D3D12_VIDEO_ENCODER_AV1_LEVELS_5_2;
+ avctx->level = D3D12_VIDEO_ENCODER_AV1_LEVELS_5_2;
+ av_log(avctx, AV_LOG_DEBUG, "Using default AV1 level 5.2\n");
+ }
+
+ if (priv->tier == 1 || avctx->bit_rate > 30000000) {
+ ctx->level.pAV1LevelSetting->Tier = D3D12_VIDEO_ENCODER_AV1_TIER_HIGH;
+ av_log(avctx, AV_LOG_DEBUG, "Using AV1 High tier\n");
+ } else {
+ ctx->level.pAV1LevelSetting->Tier = D3D12_VIDEO_ENCODER_AV1_TIER_MAIN;
+ av_log(avctx, AV_LOG_DEBUG, "Using AV1 Main tier\n");
+ }
+
+ if (priv->tier >= 0) {
+ ctx->level.pAV1LevelSetting->Tier = priv->tier == 0 ?
+ D3D12_VIDEO_ENCODER_AV1_TIER_MAIN :
+ D3D12_VIDEO_ENCODER_AV1_TIER_HIGH;
+ }
+
+ av_log(avctx, AV_LOG_DEBUG, "AV1 level set to %d, tier: %s\n",
+ ctx->level.pAV1LevelSetting->Level,
+ ctx->level.pAV1LevelSetting->Tier == D3D12_VIDEO_ENCODER_AV1_TIER_MAIN ? "Main" : "High");
+
+ return 0;
+}
+
+static int d3d12va_encode_av1_set_tile(AVCodecContext *avctx)
+{
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+
+ ctx->subregions_layout.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES);
+ D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES *tiles_layout = av_mallocz(ctx->subregions_layout.DataSize);
+ ctx->subregions_layout.pTilesPartition_AV1 = tiles_layout;
+
+ // Currently only support 1 tile
+ tiles_layout->RowCount = 1;
+ tiles_layout->ColCount = 1;
+
+ return 0;
+}
+
+static void d3d12va_encode_av1_free_picture_params(D3D12VAEncodePicture *pic)
+{
+ if (!pic->pic_ctl.pAV1PicData)
+ return;
+
+ av_freep(&pic->pic_ctl.pAV1PicData);
+}
+
+static int d3d12va_encode_av1_init_picture_params(AVCodecContext *avctx,
+ FFHWBaseEncodePicture *pic)
+{
+ FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodePicture *d3d12va_pic = pic->priv;
+ D3D12VAEncodeAV1Picture *hpic = pic->codec_priv;
+ CodedBitstreamAV1Context *cbctx = priv->cbc->priv_data;
+ AV1RawOBU *frameheader_obu = &priv->units.raw_frame_header;
+ AV1RawFrameHeader *fh = &frameheader_obu->obu.frame_header;
+
+ FFHWBaseEncodePicture *ref;
+ D3D12VAEncodeAV1Picture *href;
+ int i;
+
+ static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] =
+ { 1, 0, 0, 0, -1, 0, -1, -1 };
+
+ memset(frameheader_obu, 0, sizeof(*frameheader_obu));
+
+ frameheader_obu->header.obu_type = AV1_OBU_FRAME_HEADER;
+
+ d3d12va_pic->pic_ctl.DataSize = sizeof(D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_CODEC_DATA);
+ d3d12va_pic->pic_ctl.pAV1PicData = av_mallocz(d3d12va_pic->pic_ctl.DataSize);
+ if (!d3d12va_pic->pic_ctl.pAV1PicData)
+ return AVERROR(ENOMEM);
+
+ // Initialize frame type and reference frame management
+ switch(pic->type) {
+ case FF_HW_PICTURE_TYPE_IDR:
+ fh->frame_type = AV1_FRAME_KEY;
+ fh->refresh_frame_flags = 0xFF;
+ fh->base_q_idx = priv->q_idx_idr;
+ hpic->slot = 0;
+ hpic->last_idr_frame = pic->display_order;
+ fh->tx_mode = AV1_TX_MODE_LARGEST;
+ break;
+
+ case FF_HW_PICTURE_TYPE_P:
+ fh->frame_type = AV1_FRAME_INTER;
+ fh->base_q_idx = priv->q_idx_p;
+ fh->tx_mode = AV1_TX_MODE_SELECT;
+
+ ref = pic->refs[0][pic->nb_refs[0] - 1];
+ href = ref->codec_priv;
+
+ /**
+ * The encoder uses a simple alternating reference frame strategy:
+ * - For P-frames, it uses the last reconstructed frame as a reference.
+ * - To simplify the reference model of the encoder, the encoder alternates between
+ * two reference frame slots (typically slot 0 and slot 1) for storing reconstructed
+ * images and providing prediction references for the next frame.
+ */
+ if (base_ctx->ref_l0 > 1) {
+ hpic->slot = !href->slot;
+ } else {
+ hpic->slot = 0;
+ }
+ hpic->last_idr_frame = href->last_idr_frame;
+ fh->refresh_frame_flags = 1 << hpic->slot;
+
+ // Set the nearest frame in L0 as all reference frame.
+ for (i = 0; i < AV1_REFS_PER_FRAME; i++)
+ fh->ref_frame_idx[i] = href->slot;
+
+ fh->primary_ref_frame = href->slot;
+ fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
+
+ // Set the 2nd nearest frame in L0 as Golden frame.
+ if (pic->nb_refs[0] > 1) {
+ ref = pic->refs[0][pic->nb_refs[0] - 2];
+ href = ref->codec_priv;
+ // Reference frame index 3 is the GOLDEN_FRAME
+ fh->ref_frame_idx[3] = href->slot;
+ fh->ref_order_hint[href->slot] = ref->display_order - href->last_idr_frame;
+ } else if (base_ctx->ref_l0 == 1) {
+ fh->ref_order_hint[!href->slot] = cbctx->ref[!href->slot].order_hint;
+ }
+ break;
+
+ case FF_HW_PICTURE_TYPE_B:
+ av_log(avctx, AV_LOG_ERROR, "D3D12 AV1 video encode on this device requires B-frame support, "
+ "but it's not implemented.\n");
+ return AVERROR_PATCHWELCOME;
+ default:
+ av_log(avctx, AV_LOG_ERROR, "Unsupported picture type %d.\n", pic->type);
+ }
+
+
+ cbctx->seen_frame_header = 0;
+
+ fh->show_frame = pic->display_order <= pic->encode_order;
+ fh->showable_frame = fh->frame_type != AV1_FRAME_KEY;
+ fh->order_hint = pic->display_order - hpic->last_idr_frame;
+ fh->frame_width_minus_1 = ctx->resolution.Width - 1;
+ fh->frame_height_minus_1 = ctx->resolution.Height - 1;
+ fh->render_width_minus_1 = fh->frame_width_minus_1;
+ fh->render_height_minus_1 = fh->frame_height_minus_1;
+ fh->is_filter_switchable = 1;
+ fh->interpolation_filter = AV1_INTERPOLATION_FILTER_SWITCHABLE;
+ fh->uniform_tile_spacing_flag = 1;
+ fh->width_in_sbs_minus_1[0] = (ctx->resolution.Width + 63 >> 6) -1; // 64x64 superblock size
+ fh->height_in_sbs_minus_1[0] = (ctx->resolution.Height + 63 >> 6) -1; // 64x64 superblock size
+
+ memcpy(fh->loop_filter_ref_deltas, default_loop_filter_ref_deltas,
+ AV1_TOTAL_REFS_PER_FRAME * sizeof(int8_t));
+
+ if (fh->frame_type == AV1_FRAME_KEY && fh->show_frame)
+ fh->error_resilient_mode = 1;
+
+ if (fh->frame_type == AV1_FRAME_KEY || fh->error_resilient_mode)
+ fh->primary_ref_frame = AV1_PRIMARY_REF_NONE;
+
+ d3d12va_pic->pic_ctl.pAV1PicData->FrameType = fh->frame_type;
+ d3d12va_pic->pic_ctl.pAV1PicData->TxMode = fh->tx_mode;
+ d3d12va_pic->pic_ctl.pAV1PicData->RefreshFrameFlags = fh->refresh_frame_flags;
+ d3d12va_pic->pic_ctl.pAV1PicData->TemporalLayerIndexPlus1 = hpic->temporal_id + 1;
+ d3d12va_pic->pic_ctl.pAV1PicData->SpatialLayerIndexPlus1 = hpic->spatial_id + 1;
+ d3d12va_pic->pic_ctl.pAV1PicData->PictureIndex = pic->display_order;
+ d3d12va_pic->pic_ctl.pAV1PicData->InterpolationFilter = D3D12_VIDEO_ENCODER_AV1_INTERPOLATION_FILTERS_SWITCHABLE;
+ d3d12va_pic->pic_ctl.pAV1PicData->PrimaryRefFrame = fh->primary_ref_frame;
+ if (fh->error_resilient_mode)
+ d3d12va_pic->pic_ctl.pAV1PicData->Flags |= D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_FLAG_ENABLE_ERROR_RESILIENT_MODE;
+
+ if (pic->type == FF_HW_PICTURE_TYPE_IDR)
+ {
+ for (int i = 0; i < AV1_NUM_REF_FRAMES; i++) {
+ d3d12va_pic->pic_ctl.pAV1PicData->ReferenceFramesReconPictureDescriptors[i].ReconstructedPictureResourceIndex =
+ D3D12_VIDEO_ENCODER_AV1_INVALID_DPB_RESOURCE_INDEX;
+ }
+ } else if (pic->type == FF_HW_PICTURE_TYPE_P) {
+ for (i = 0; i < pic->nb_refs[0]; i++) {
+ FFHWBaseEncodePicture *ref_pic = pic->refs[0][i];
+ d3d12va_pic->pic_ctl.pAV1PicData->ReferenceFramesReconPictureDescriptors[i].ReconstructedPictureResourceIndex =
+ ((D3D12VAEncodeAV1Picture*)ref_pic->codec_priv)->slot;
+ }
+ }
+ // Set reference frame management
+ memset(d3d12va_pic->pic_ctl.pAV1PicData->ReferenceIndices, 0, sizeof(UINT) * AV1_REFS_PER_FRAME);
+ if (pic->type == FF_HW_PICTURE_TYPE_P) {
+ for (i = 0; i < AV1_REFS_PER_FRAME; i++)
+ d3d12va_pic->pic_ctl.pAV1PicData->ReferenceIndices[i] = fh->ref_frame_idx[i];
+ }
+
+ int ret = av_fifo_write(priv->picture_header_list, &priv->units.raw_frame_header, 1);
+
+ return 0;
+}
+
+
+static const D3D12VAEncodeType d3d12va_encode_type_av1 = {
+ .profiles = d3d12va_encode_av1_profiles,
+
+ .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_AV1,
+
+ .flags = FF_HW_FLAG_B_PICTURES |
+ FF_HW_FLAG_B_PICTURE_REFERENCES |
+ FF_HW_FLAG_NON_IDR_KEY_PICTURES,
+
+ .default_quality = 25,
+
+ .get_encoder_caps = &d3d12va_encode_av1_get_encoder_caps,
+
+ .configure = &d3d12va_encode_av1_configure,
+
+ .set_level = &d3d12va_encode_av1_set_level,
+
+ .set_tile = &d3d12va_encode_av1_set_tile,
+
+ .picture_priv_data_size = sizeof(D3D12VAEncodeAV1Picture),
+
+ .init_sequence_params = &d3d12va_encode_av1_init_sequence_params,
+
+ .init_picture_params = &d3d12va_encode_av1_init_picture_params,
+
+ .free_picture_params = &d3d12va_encode_av1_free_picture_params,
+
+ .write_sequence_header = &d3d12va_encode_av1_write_sequence_header,
+
+#ifdef CONFIG_AV1_D3D12VA_ENCODER
+ .get_coded_data = &d3d12va_encode_av1_get_coded_data,
+#endif
+};
+
+static int d3d12va_encode_av1_init(AVCodecContext *avctx)
+{
+ D3D12VAEncodeContext *ctx = avctx->priv_data;
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+
+ ctx->codec = &d3d12va_encode_type_av1;
+
+ if (avctx->profile == AV_PROFILE_UNKNOWN)
+ avctx->profile = priv->profile;
+ if (avctx->level == AV_LEVEL_UNKNOWN)
+ avctx->level = priv->level;
+
+ if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
+ "in 8-bit unsigned integer.\n", avctx->level);
+ return AVERROR(EINVAL);
+ }
+
+ if (priv->qp > 0)
+ ctx->explicit_qp = priv->qp;
+
+ priv->picture_header_list = av_fifo_alloc2(2, sizeof(AV1RawOBU), AV_FIFO_FLAG_AUTO_GROW);
+
+ return ff_d3d12va_encode_init(avctx);
+}
+
+static int d3d12va_encode_av1_close(AVCodecContext *avctx)
+{
+ D3D12VAEncodeAV1Context *priv = avctx->priv_data;
+
+ ff_cbs_fragment_free(&priv->current_obu);
+ ff_cbs_close(&priv->cbc);
+
+ av_freep(&priv->common.codec_conf.pAV1Config);
+ av_freep(&priv->common.gop.pAV1SequenceStructure);
+ av_freep(&priv->common.level.pAV1LevelSetting);
+ av_freep(&priv->common.subregions_layout.pTilesPartition_AV1);
+
+ av_fifo_freep2(&priv->picture_header_list);
+
+ return ff_d3d12va_encode_close(avctx);
+}
+
+#define OFFSET(x) offsetof(D3D12VAEncodeAV1Context, x)
+#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
+static const AVOption d3d12va_encode_av1_options[] = {
+ HW_BASE_ENCODE_COMMON_OPTIONS,
+ D3D12VA_ENCODE_RC_OPTIONS,
+
+ { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
+ OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
+
+ { "profile", "Set profile (general_profile_idc)",
+ OFFSET(profile), AV_OPT_TYPE_INT,
+ { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
+
+#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+ { .i64 = value }, 0, 0, FLAGS, "profile"
+ { PROFILE("main", AV_PROFILE_AV1_MAIN) },
+ { PROFILE("high", AV_PROFILE_AV1_HIGH) },
+ { PROFILE("professional", AV_PROFILE_AV1_PROFESSIONAL) },
+#undef PROFILE
+
+ { "tier", "Set tier (general_tier_flag)",
+ OFFSET(unit_opts.tier), AV_OPT_TYPE_INT,
+ { .i64 = 0 }, 0, 1, FLAGS, "tier" },
+ { "main", NULL, 0, AV_OPT_TYPE_CONST,
+ { .i64 = 0 }, 0, 0, FLAGS, "tier" },
+ { "high", NULL, 0, AV_OPT_TYPE_CONST,
+ { .i64 = 1 }, 0, 0, FLAGS, "tier" },
+
+ { "level", "Set level (general_level_idc)",
+ OFFSET(level), AV_OPT_TYPE_INT,
+ { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
+
+#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
+ { .i64 = value }, 0, 0, FLAGS, "level"
+ { LEVEL("2.0", 0) },
+ { LEVEL("2.1", 1) },
+ { LEVEL("2.2", 2) },
+ { LEVEL("2.3", 3) },
+ { LEVEL("3.0", 4) },
+ { LEVEL("3.1", 5) },
+ { LEVEL("3.2", 6) },
+ { LEVEL("3.3", 7) },
+ { LEVEL("4.0", 8) },
+ { LEVEL("4.1", 9) },
+ { LEVEL("4.2", 10) },
+ { LEVEL("4.3", 11) },
+ { LEVEL("5.0", 12) },
+ { LEVEL("5.1", 13) },
+ { LEVEL("5.2", 14) },
+ { LEVEL("5.3", 15) },
+ { LEVEL("6.0", 16) },
+ { LEVEL("6.1", 17) },
+ { LEVEL("6.2", 18) },
+ { LEVEL("6.3", 19) },
+ { LEVEL("7.0", 20) },
+ { LEVEL("7.1", 21) },
+ { LEVEL("7.2", 22) },
+ { LEVEL("7.3", 23) },
+#undef LEVEL
+ { NULL },
+};
+
+static const FFCodecDefault d3d12va_encode_av1_defaults[] = {
+ { "b", "0" },
+ { "bf", "0" },
+ { "g", "120" },
+ { "i_qfactor", "1" },
+ { "i_qoffset", "0" },
+ { "b_qfactor", "1" },
+ { "b_qoffset", "0" },
+ { "qmin", "-1" },
+ { "qmax", "-1" },
+ { "refs", "0" },
+ { NULL },
+};
+
+static const AVClass d3d12va_encode_av1_class = {
+ .class_name = "av1_d3d12va",
+ .item_name = av_default_item_name,
+ .option = d3d12va_encode_av1_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+const FFCodec ff_av1_d3d12va_encoder = {
+ .p.name = "av1_d3d12va",
+ CODEC_LONG_NAME("D3D12VA av1 encoder"),
+ .p.type = AVMEDIA_TYPE_VIDEO,
+ .p.id = AV_CODEC_ID_AV1,
+ .priv_data_size = sizeof(D3D12VAEncodeAV1Context),
+ .init = &d3d12va_encode_av1_init,
+ FF_CODEC_RECEIVE_PACKET_CB(&ff_d3d12va_encode_receive_packet),
+ .close = &d3d12va_encode_av1_close,
+ .p.priv_class = &d3d12va_encode_av1_class,
+ .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
+ AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
+ .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
+ FF_CODEC_CAP_INIT_CLEANUP,
+ .defaults = d3d12va_encode_av1_defaults,
+ CODEC_PIXFMTS(AV_PIX_FMT_D3D12),
+ .hw_configs = ff_d3d12va_encode_hw_configs,
+ .p.wrapper_name = "d3d12va",
+};
-----------------------------------------------------------------------
Summary of changes:
Changelog | 1 +
configure | 3 +
libavcodec/Makefile | 1 +
libavcodec/allcodecs.c | 1 +
libavcodec/d3d12va_encode.c | 45 +-
libavcodec/d3d12va_encode.h | 13 +
libavcodec/d3d12va_encode_av1.c | 1182 +++++++++++++++++++++++++++++++++++++++
7 files changed, 1241 insertions(+), 5 deletions(-)
create mode 100644 libavcodec/d3d12va_encode_av1.c
hooks/post-receive
--
1
0
[ffmpeg-web] branch master updated. 110517d web/download: add FFmpeg 5.1.8
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, master has been updated
via 110517df787e38a8a8f9546a7daafa3da84163c9 (commit)
from bd18dec670eefafad4b0fb09c26c426279393632 (commit)
- Log -----------------------------------------------------------------
commit 110517df787e38a8a8f9546a7daafa3da84163c9
Author: Michael Niedermayer <michael(a)niedermayer.cc>
AuthorDate: Wed Nov 26 04:15:45 2025 +0100
Commit: Michael Niedermayer <michael(a)niedermayer.cc>
CommitDate: Wed Nov 26 04:15:45 2025 +0100
web/download: add FFmpeg 5.1.8
diff --git a/src/download b/src/download
index add46fd..723a9a1 100644
--- a/src/download
+++ b/src/download
@@ -449,10 +449,10 @@ libpostproc 57. 3.100</pre>
</div> <!-- col -->
</div> <!-- row -->
- <h3 id="release_5.1">FFmpeg 5.1.7 "Riemann"</h3>
+ <h3 id="release_5.1">FFmpeg 5.1.8 "Riemann"</h3>
<p>
- 5.1.7 was released on 2025-08-14. It is the latest stable FFmpeg release
+ 5.1.8 was released on 2025-11-26. It is the latest stable FFmpeg release
from the 5.1 release branch, which was cut from master on 2022-07-13.
</p>
<p>It includes the following library versions:
@@ -468,19 +468,19 @@ libswresample 4. 7.100
libpostproc 56. 6.100</pre>
<div class="row">
<div class="col-md-3">
- <a class="btn btn-success" href="releases/ffmpeg-5.1.7.tar.xz">Download xz tarball</a>
- <small><a href="releases/ffmpeg-5.1.7.tar.xz.asc">PGP signature</a></small>
+ <a class="btn btn-success" href="releases/ffmpeg-5.1.8.tar.xz">Download xz tarball</a>
+ <small><a href="releases/ffmpeg-5.1.8.tar.xz.asc">PGP signature</a></small>
</div> <!-- col -->
<div class="col-md-3">
- <a class="btn btn-success" href="releases/ffmpeg-5.1.7.tar.bz2">Download bzip2 tarball</a>
- <small><a href="releases/ffmpeg-5.1.7.tar.bz2.asc">PGP signature</a></small>
+ <a class="btn btn-success" href="releases/ffmpeg-5.1.8.tar.bz2">Download bzip2 tarball</a>
+ <small><a href="releases/ffmpeg-5.1.8.tar.bz2.asc">PGP signature</a></small>
</div> <!-- col -->
<div class="col-md-3">
- <a class="btn btn-success" href="releases/ffmpeg-5.1.7.tar.gz">Download gzip tarball</a>
- <small><a href="releases/ffmpeg-5.1.7.tar.gz.asc">PGP signature</a></small>
+ <a class="btn btn-success" href="releases/ffmpeg-5.1.8.tar.gz">Download gzip tarball</a>
+ <small><a href="releases/ffmpeg-5.1.8.tar.gz.asc">PGP signature</a></small>
</div> <!-- col -->
<div class="col-md-3 text-right">
- <small><a href="https://git.ffmpeg.org/gitweb/ffmpeg.git/shortlog/n5.1.7">Changelog</a></small>
+ <small><a href="https://git.ffmpeg.org/gitweb/ffmpeg.git/shortlog/n5.1.8">Changelog</a></small>
<a class="btn btn-success" href="https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/refs/heads/release/5.1:/RELEA…">Release Notes</a>
</div> <!-- col -->
</div> <!-- row -->
-----------------------------------------------------------------------
Summary of changes:
src/download | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
hooks/post-receive
--
1
0
The annotated tag, n5.1.8 has been created
at 28ba36f6584510ed7849963d51a4f1a86e78e1d4 (tag)
tagging 9bc0bcce7a03701025d7002271ddc2ce4f351908 (commit)
replaces n5.1.7
tagged by Michael Niedermayer
on Wed Nov 26 03:34:37 2025 +0100
- Log -----------------------------------------------------------------
FFmpeg 5.1.8 release
-----BEGIN PGP SIGNATURE-----
iHUEABYKAB0WIQTdHsno3ghcYps+GEaxjokos5SNZAUCaSZnSQAKCRCxjokos5SN
ZICEAQDjZsZF8uTABSooDcSzLwmw5xdkKwAPWvsh5DQpOgCxRgD/T2JaCn+OD/Xs
2O7nFbfg0T4uD5hxzZ5Bh3Kffh2HnQM=
=j7mj
-----END PGP SIGNATURE-----
Andreas Rheinhardt (3):
avformat/aviobuf: Keep checksum_ptr consistent in avio_seek()
fftools/ffmpeg_mux_init: Fix double-free on error
avformat/avidec: Fix integer overflow iff ULONG_MAX < INT64_MAX
Bin Peng (1):
lavc/aarch64: Fix addp overflow in ff_pred16x16_plane_neon_10
James Almer (1):
avcodec/x86/pngdsp: add missing emms at the end of add_png_paeth_prediction
Lynne (1):
aacenc_tns: clamp filter direction energy measurement
Michael Niedermayer (24):
avcodec/utvideodec: Clear plane_start array
avcodec/sanm: Check w,h,left,top
avformat/lrcdec: Fix fate-sub-lrc-ms-remux on x86-32
avcodec/aac/aacdec: dont allow ff_aac_output_configure() allocating a new frame if it has no frame
avcodec/dxv: Check coded_height, to avoid invalid av_clip()
avcodec/mjpegdec: Explain buf_size/width/height check
avcodec/exr: Round dc_w/h up
avcodec/exr: check ac_size
avcodec/exr: Check that DWA has 3 channels
swscale/output: Fix integer overflow in yuv2ya16_X_c_template()
avformat/rtpenc_h264_hevc: Check space for nal_length_size in ff_rtp_send_h264_hevc()
avcodec/g723_1enc: Make min_err 64bit
avformat/rtmpproto_ Check tcurl and flashver length
avformat/rtmpproto: consider command line argument lengths
avformat/sctp: Check size in sctp_write()
avcodec/exr: Simple check for available channels
avcodec/exr: spelling
avformat/http: Fix off by 1 error
avformat/rtpdec_rfc4175: Fix memleak of sampling
avformat/rtpdec_rfc4175: Check dimensions
avformat/rtpdec_rfc4175: Only change PayloadContext on success
avcodec/utvideodec: Set B for the width= 1 case in restore_median_planar_il()
avfilter/vf_drawtext: Account for bbox text seperator
Update for 5.1.8
Zhao Zhili (1):
avutil/common: cast GET_BYTE/GET_16BIT returned value
veygax (1):
avcodec/exr: use tile dimensions in pxr24 UINT case
-----------------------------------------------------------------------
hooks/post-receive
--
1
0
[ffmpeg] branch release/5.1 updated. 9bc0bcce7a Update for 5.1.8
by ffmpeg-git@ffmpeg.org 26 Nov '25
by ffmpeg-git@ffmpeg.org 26 Nov '25
26 Nov '25
The branch, release/5.1 has been updated
via 9bc0bcce7a03701025d7002271ddc2ce4f351908 (commit)
from fb52923679d5f713dda140006e317d89a992eca5 (commit)
- Log -----------------------------------------------------------------
commit 9bc0bcce7a03701025d7002271ddc2ce4f351908
Author: Michael Niedermayer <michael(a)niedermayer.cc>
AuthorDate: Wed Nov 26 02:54:17 2025 +0100
Commit: Michael Niedermayer <michael(a)niedermayer.cc>
CommitDate: Wed Nov 26 02:54:17 2025 +0100
Update for 5.1.8
Signed-off-by: Michael Niedermayer <michael(a)niedermayer.cc>
diff --git a/Changelog b/Changelog
index ae4c6fc9dc..9412175402 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,39 @@
Entries are sorted chronologically from oldest to youngest within each release,
releases are sorted from youngest to oldest.
+version 5.1.8:
+ avutil/common: cast GET_BYTE/GET_16BIT returned value
+ avfilter/vf_drawtext: Account for bbox text seperator
+ avcodec/utvideodec: Set B for the width= 1 case in restore_median_planar_il()
+ avformat/rtpdec_rfc4175: Only change PayloadContext on success
+ avformat/rtpdec_rfc4175: Check dimensions
+ avformat/rtpdec_rfc4175: Fix memleak of sampling
+ avformat/http: Fix off by 1 error
+ avcodec/exr: spelling
+ avcodec/exr: use tile dimensions in pxr24 UINT case
+ avcodec/exr: Simple check for available channels
+ avformat/sctp: Check size in sctp_write()
+ avformat/rtmpproto: consider command line argument lengths
+ avformat/rtmpproto_ Check tcurl and flashver length
+ avcodec/g723_1enc: Make min_err 64bit
+ avformat/rtpenc_h264_hevc: Check space for nal_length_size in ff_rtp_send_h264_hevc()
+ swscale/output: Fix integer overflow in yuv2ya16_X_c_template()
+ avcodec/exr: Check that DWA has 3 channels
+ avcodec/exr: check ac_size
+ avcodec/exr: Round dc_w/h up
+ avcodec/mjpegdec: Explain buf_size/width/height check
+ avformat/avidec: Fix integer overflow iff ULONG_MAX < INT64_MAX
+ fftools/ffmpeg_mux_init: Fix double-free on error
+ avformat/aviobuf: Keep checksum_ptr consistent in avio_seek()
+ aacenc_tns: clamp filter direction energy measurement
+ avcodec/dxv: Check coded_height, to avoid invalid av_clip()
+ avcodec/aac/aacdec: dont allow ff_aac_output_configure() allocating a new frame if it has no frame
+ avformat/lrcdec: Fix fate-sub-lrc-ms-remux on x86-32
+ avcodec/sanm: Check w,h,left,top
+ avcodec/utvideodec: Clear plane_start array
+ lavc/aarch64: Fix addp overflow in ff_pred16x16_plane_neon_10
+ avcodec/x86/pngdsp: add missing emms at the end of add_png_paeth_prediction
+
version 5.1.7:
avcodec/exr: Check rle_raw_data and surroundings
diff --git a/RELEASE b/RELEASE
index cbad66a094..d4bda08b51 100644
--- a/RELEASE
+++ b/RELEASE
@@ -1 +1 @@
-5.1.7
+5.1.8
diff --git a/doc/Doxyfile b/doc/Doxyfile
index 7f6d4d2328..235afc36f6 100644
--- a/doc/Doxyfile
+++ b/doc/Doxyfile
@@ -38,7 +38,7 @@ PROJECT_NAME = FFmpeg
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = 5.1.7
+PROJECT_NUMBER = 5.1.8
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
-----------------------------------------------------------------------
Summary of changes:
Changelog | 33 +++++++++++++++++++++++++++++++++
RELEASE | 2 +-
doc/Doxyfile | 2 +-
3 files changed, 35 insertions(+), 2 deletions(-)
hooks/post-receive
--
1
0