From 246a0ec46a9ecd97e22e585fd044ab28ef4eae27 Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Thu, 22 Aug 2024 10:36:18 +0200 Subject: [PATCH] Fix #126394: ffmpeg on win64 is built without SIMD optimizations Since ee1b2f53cc the ffmpeg libraries for Windows x64 are built effectively without CPU specific SIMD optimizations. `--arch=x64` is not an architecture that ffmpeg configure understands, so it falls back to "nothing is known, turn any architecture specific bits off" code path. Pull Request: https://projects.blender.org/blender/blender/pulls/126396 --- .../build_environment/cmake/ffmpeg.cmake | 2 +- intern/ffmpeg/CMakeLists.txt | 5 ++-- intern/ffmpeg/tests/ffmpeg_cpu_flags.cc | 28 +++++++++++++++++++ tests/gtests/runner/CMakeLists.txt | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 intern/ffmpeg/tests/ffmpeg_cpu_flags.cc diff --git a/build_files/build_environment/cmake/ffmpeg.cmake b/build_files/build_environment/cmake/ffmpeg.cmake index c1e2b695b7a..00cc4ff242f 100644 --- a/build_files/build_environment/cmake/ffmpeg.cmake +++ b/build_files/build_environment/cmake/ffmpeg.cmake @@ -118,7 +118,7 @@ if(WIN32) else() set(FFMPEG_EXTRA_FLAGS ${FFMPEG_EXTRA_FLAGS} - --arch=x64 + --arch=x86_64 --target-os=win32 ) endif() diff --git a/intern/ffmpeg/CMakeLists.txt b/intern/ffmpeg/CMakeLists.txt index b31b96bb219..bd7ae8b0ca9 100644 --- a/intern/ffmpeg/CMakeLists.txt +++ b/intern/ffmpeg/CMakeLists.txt @@ -1,10 +1,11 @@ -# SPDX-FileCopyrightText: 2020 Blender Authors +# SPDX-FileCopyrightText: 2020-2024 Blender Authors # # SPDX-License-Identifier: GPL-2.0-or-later if(WITH_GTESTS) set(TEST_SRC tests/ffmpeg_codecs.cc + tests/ffmpeg_cpu_flags.cc ) set(TEST_INC . @@ -22,5 +23,5 @@ if(WITH_GTESTS) if(WITH_IMAGE_OPENJPEG) set(TEST_LIB ${TEST_LIB} ${OPENJPEG_LIBRARIES}) endif() - blender_add_test_suite_lib(ffmpeg_codecs "${TEST_SRC}" "${TEST_INC}" "${TEST_INC_SYS}" "${TEST_LIB}") + blender_add_test_suite_lib(ffmpeg_libs "${TEST_SRC}" "${TEST_INC}" "${TEST_INC_SYS}" "${TEST_LIB}") endif() diff --git a/intern/ffmpeg/tests/ffmpeg_cpu_flags.cc b/intern/ffmpeg/tests/ffmpeg_cpu_flags.cc new file mode 100644 index 00000000000..2a3d1def27d --- /dev/null +++ b/intern/ffmpeg/tests/ffmpeg_cpu_flags.cc @@ -0,0 +1,28 @@ +/* SPDX-FileCopyrightText: 2024 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "testing/testing.h" + +extern "C" { +#include +} + +namespace ffmpeg::tests { + +TEST(ffmpeg, correct_av_cpu_flags) +{ + int flags = av_get_cpu_flags(); +#if defined(_M_X64) || defined(__x86_64__) + /* x64 expected to have at least up to SSE4.2. */ + EXPECT_TRUE((flags & AV_CPU_FLAG_SSE2) != 0); + EXPECT_TRUE((flags & AV_CPU_FLAG_SSE4) != 0); + EXPECT_TRUE((flags & AV_CPU_FLAG_SSE42) != 0); +#elif defined(__aarch64__) || defined(_M_ARM64) + /* arm64 expected to have at least NEON. */ + EXPECT_TRUE((flags & AV_CPU_FLAG_ARMV8) != 0); + EXPECT_TRUE((flags & AV_CPU_FLAG_NEON) != 0); +#endif +} + +} // namespace ffmpeg::tests diff --git a/tests/gtests/runner/CMakeLists.txt b/tests/gtests/runner/CMakeLists.txt index 9d7b0714ebe..4b627975441 100644 --- a/tests/gtests/runner/CMakeLists.txt +++ b/tests/gtests/runner/CMakeLists.txt @@ -48,7 +48,7 @@ elseif(APPLE) foreach(_lib ${_test_libs}) # We need -force_load for every test library and target_link_libraries will # deduplicate it. So explicitly set as linker option for every test lib. - target_link_libraries(blender_test PRIVATE ${_lib} "-Wl,-force_load,$") + target_link_libraries(blender_test PRIVATE "-Wl,-force_load" ${_lib}) endforeach() endif()