[FFmpeg-devel] [PATCH] master (PR #20769)
PR #20769 opened by death
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20769
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20769.patch
Remove dependency on dead code elimination + use correct cflags for debug build
in MSVC
See https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20763
>From 3150ac96e2437164fb3adcdbbc6bf118a6abd5e4 Mon Sep 17 00:00:00 2001
From: Piotr Pawlowski
Date: Mon, 27 Oct 2025 18:40:20 +0100
Subject: [PATCH 1/2] avcodec: Fix dependency on compiler performing dead code
elimination
---
libavcodec/avcodec.c | 5 +++--
libavcodec/encode.c | 18 +++---
libavcodec/x86/idctdsp_init.c | 9 ++---
libavcodec/x86/mlpdsp_init.c | 6 --
4 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 0355b7c338..6ef506a4fc 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -438,10 +438,11 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
if (avcodec_is_open(avctx)) {
AVCodecInternal *avci = avctx->internal;
-if (CONFIG_FRAME_THREAD_ENCODER &&
-avci->frame_thread_encoder && avctx->thread_count > 1) {
+#if CONFIG_FRAME_THREAD_ENCODER
+if (avci->frame_thread_encoder && avctx->thread_count > 1) {
ff_frame_thread_encoder_free(avctx);
}
+#endif
if (HAVE_THREADS && avci->thread_ctx)
ff_thread_free(avctx);
if (avci->needs_close && ffcodec(avctx->codec)->close)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 1eca5e38c1..060e63a3d5 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -316,12 +316,16 @@ static int encode_simple_internal(AVCodecContext *avctx,
AVPacket *avpkt)
av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
-if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
+#if CONFIG_FRAME_THREAD_ENCODER
+if (avci->frame_thread_encoder) {
/* This will unref frame. */
ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
-else {
+} else {
ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
}
+#else
+ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
+#endif
if (avci->draining && !got_packet)
avci->draining_done = 1;
@@ -824,11 +828,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
}
-if (CONFIG_FRAME_THREAD_ENCODER) {
-ret = ff_frame_thread_encoder_init(avctx);
-if (ret < 0)
-return ret;
-}
+#if CONFIG_FRAME_THREAD_ENCODER
+ret = ff_frame_thread_encoder_init(avctx);
+if (ret < 0)
+return ret;
+#endif
return 0;
}
diff --git a/libavcodec/x86/idctdsp_init.c b/libavcodec/x86/idctdsp_init.c
index 2d165b975b..d58056ef29 100644
--- a/libavcodec/x86/idctdsp_init.c
+++ b/libavcodec/x86/idctdsp_init.c
@@ -94,8 +94,8 @@ av_cold void ff_idctdsp_init_x86(IDCTDSPContext *c,
AVCodecContext *avctx,
}
#endif
-if (ARCH_X86_64 &&
-!high_bit_depth &&
+#if ARCH_X86_64
+if (!high_bit_depth &&
avctx->lowres == 0 &&
(avctx->idct_algo == FF_IDCT_AUTO ||
avctx->idct_algo == FF_IDCT_SIMPLEAUTO ||
@@ -106,9 +106,11 @@ av_cold void ff_idctdsp_init_x86(IDCTDSPContext *c,
AVCodecContext *avctx,
c->idct_add = ff_simple_idct8_add_sse2;
c->perm_type = FF_IDCT_PERM_TRANSPOSE;
}
+#endif
}
-if (ARCH_X86_64 && avctx->lowres == 0) {
+#if ARCH_X86_64
+if (avctx->lowres == 0) {
if (EXTERNAL_AVX(cpu_flags) &&
!high_bit_depth &&
(avctx->idct_algo == FF_IDCT_AUTO ||
@@ -158,4 +160,5 @@ av_cold void ff_idctdsp_init_x86(IDCTDSPContext *c,
AVCodecContext *avctx,
}
}
}
+#endif
}
diff --git a/libavcodec/x86/mlpdsp_init.c b/libavcodec/x86/mlpdsp_init.c
index 950f996832..21a0e38143 100644
--- a/libavcodec/x86/mlpdsp_init.c
+++ b/libavcodec/x86/mlpdsp_init.c
@@ -200,8 +200,10 @@ av_cold void ff_mlpdsp_init_x86(MLPDSPContext *c)
if (INLINE_MMX(cpu_flags))
c->mlp_filter_channel = mlp_filter_channel_x86;
#endif
-if (ARCH_X86_64 && EXTERNAL_SSE4(cpu_flags))
+#if ARCH_X86_64
+if (EXTERNAL_SSE4(cpu_flags))
c->mlp_rematrix_channel = ff_mlp_rematrix_channel_sse4;
-if (ARCH_X86_64 && EXTERNAL_AVX2_FAST(cpu_flags) && cpu_flags &
AV_CPU_FLAG_BMI2)
+if (EXTERNAL_AVX2_FAST(cpu_flags) && cpu_flags & AV_CPU_FLAG_BMI2)
c->mlp_rematrix_channel = ff_mlp_rematrix_channel_avx2_bmi2;
+#endif // ARCH_X86_64
}
--
2.49.1
>From 8b38b61a5764f0903cec6db8931dd431b14c3976 Mon Sep 17 00:00:00 2001
From: Piotr Pawlowski
Date: Mon, 27 Oct 2025 18:40:55 +0100
Subject: [PATCH 2/2] configure: Use -Od for debug build in MSVC
---
configure | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure b/configure
index 3
[FFmpeg-devel] [PATCH] All: Removed reliance on compiler performing dead code elimination, changed various macro constant checks from if() to #if (PR #20794)
PR #20794 opened by death
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20794
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20794.patch
https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/20763
No-dead-code-elimination patch, try 2
Verified on various MSVC configurations: x86_32, x86_64, ARM64.
Most changes deal with x86 code checking for ARCH_X86_64 and failing to link on
x86_32.
>From 4d5a97dd54fa9e69d095205bb5a9a3b699c13850 Mon Sep 17 00:00:00 2001
From: Piotr Pawlowski
Date: Thu, 30 Oct 2025 14:41:40 +0100
Subject: [PATCH] All: Removed reliance on compiler performing dead code
elimination, changed various macro constant checks from if() to #if
---
libavcodec/avcodec.c | 5 +-
libavcodec/encode.c | 17 +++---
libavcodec/x86/flacdsp_init.c| 16 --
libavcodec/x86/hevc/dsp_init.c | 84 +++-
libavcodec/x86/idctdsp_init.c| 9 ++-
libavcodec/x86/mlpdsp_init.c | 6 +-
libavcodec/x86/v210-init.c | 24 +---
libavcodec/x86/v210enc_init.c| 3 +-
libavfilter/x86/colorspacedsp_init.c | 4 +-
libavfilter/x86/f_ebur128_init.c | 4 +-
libavfilter/x86/vf_atadenoise_init.c | 6 +-
libavfilter/x86/vf_bwdif_init.c | 12 ++--
libavfilter/x86/vf_nlmeans_init.c| 4 +-
libavfilter/x86/vf_ssim_init.c | 4 +-
libavfilter/x86/vf_w3fdif_init.c | 4 +-
15 files changed, 125 insertions(+), 77 deletions(-)
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 0355b7c338..6ef506a4fc 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -438,10 +438,11 @@ av_cold void ff_codec_close(AVCodecContext *avctx)
if (avcodec_is_open(avctx)) {
AVCodecInternal *avci = avctx->internal;
-if (CONFIG_FRAME_THREAD_ENCODER &&
-avci->frame_thread_encoder && avctx->thread_count > 1) {
+#if CONFIG_FRAME_THREAD_ENCODER
+if (avci->frame_thread_encoder && avctx->thread_count > 1) {
ff_frame_thread_encoder_free(avctx);
}
+#endif
if (HAVE_THREADS && avci->thread_ctx)
ff_thread_free(avctx);
if (avci->needs_close && ffcodec(avctx->codec)->close)
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 1eca5e38c1..728b5a8c0b 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -316,12 +316,13 @@ static int encode_simple_internal(AVCodecContext *avctx,
AVPacket *avpkt)
av_assert0(codec->cb_type == FF_CODEC_CB_TYPE_ENCODE);
-if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
+#if CONFIG_FRAME_THREAD_ENCODER
+if (avci->frame_thread_encoder)
/* This will unref frame. */
ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
-else {
+else
+#endif
ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
-}
if (avci->draining && !got_packet)
avci->draining_done = 1;
@@ -824,11 +825,11 @@ int ff_encode_preinit(AVCodecContext *avctx)
memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
}
-if (CONFIG_FRAME_THREAD_ENCODER) {
-ret = ff_frame_thread_encoder_init(avctx);
-if (ret < 0)
-return ret;
-}
+#if CONFIG_FRAME_THREAD_ENCODER
+ret = ff_frame_thread_encoder_init(avctx);
+if (ret < 0)
+return ret;
+#endif
return 0;
}
diff --git a/libavcodec/x86/flacdsp_init.c b/libavcodec/x86/flacdsp_init.c
index fa993d3466..386955ba67 100644
--- a/libavcodec/x86/flacdsp_init.c
+++ b/libavcodec/x86/flacdsp_init.c
@@ -85,8 +85,10 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum
AVSampleFormat fmt, int
c->decorrelate[0] = ff_flac_decorrelate_indep4_16_ssse3;
else if (channels == 6)
c->decorrelate[0] = ff_flac_decorrelate_indep6_16_ssse3;
-else if (ARCH_X86_64 && channels == 8)
+#if ARCH_X86_64
+else if (channels == 8)
c->decorrelate[0] = ff_flac_decorrelate_indep8_16_ssse3;
+#endif
} else if (fmt == AV_SAMPLE_FMT_S32) {
if (channels == 2)
c->decorrelate[0] = ff_flac_decorrelate_indep2_32_ssse3;
@@ -94,8 +96,10 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum
AVSampleFormat fmt, int
c->decorrelate[0] = ff_flac_decorrelate_indep4_32_ssse3;
else if (channels == 6)
c->decorrelate[0] = ff_flac_decorrelate_indep6_32_ssse3;
-else if (ARCH_X86_64 && channels == 8)
+#if ARCH_X86_64
+else if (channels == 8)
c->decorrelate[0] = ff_flac_decorrelate_indep8_32_ssse3;
+#endif
}
}
if (EXTERNAL_SSE4(cpu_flags)) {
@@ -105,15 +109,19 @@ av_cold void ff_flacdsp_init_x86(FLACDSPContext *c, enum
AVSampleFormat fmt, int
}
if (EXTERNAL_AVX(cpu_flags)) {
if (fmt == AV_SAMPLE_FMT_S16) {
-if (ARCH_X86_64 && channels == 8)
+#if ARCH_X86_64
+if (channel
