fraunhoferhhi / vvdec

VVdeC, the Fraunhofer Versatile Video Decoder
https://www.hhi.fraunhofer.de/en/departments/vca/technologies-and-solutions/h266-vvc.html
BSD 3-Clause Clear License
453 stars 91 forks source link

vvdecapp build shared can not be executed by old CPU #107

Closed ZenKiyoshi closed 2 years ago

ZenKiyoshi commented 2 years ago

I have 2 PC: new AMD R5 3600 and old Intel i5 2500s, both use Windows.

I build vvdec on AMD R5 3600 PC using MSYS2 mingw64 environment.

My steps: git clone https://github.com/fraunhoferhhi/vvdec mkdir build && cd build

// build static cmake .. -DBUILD_SHARED_LIBS=0 -DCMAKE_BUILD_TYPE=Release -G "MSYS Makefiles" vvdecapp.exe file is generated and need follow dll files to be ran: libgcc_s_seh-1.dll, libstdc++-6.dll, libwinpthread-1.dll. It can be executed by both AMD R5 3600 and Intel i5 2500s cpu.

// build shared cmake .. -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -G "MSYS Makefiles" vvdecapp.exe and libvvdec.dll are generated, also need 3 dll files above to be ran. This time, AMD R5 3600 runs fine.
Intel i5 2500s doesn't.

Untitled

If I build shared with -DVVDEC_ENABLE_X86_SIMD=OFF cmake .. -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -G "MSYS Makefiles" -DVVDEC_ENABLE_X86_SIMD=OFF Intel i5 2500s can run it, but decrease performance.

I install MSYS2 on i5 2500s PC and try building shared without -DVVDEC_ENABLE_X86_SIMD=OFF i5 2500s still can't run it.

i5 2500s can run vvdecapp with static build, so SIMD does work fine on this cpu, but not build shared.

adamjw24 commented 2 years ago

Thats very strange. Does this generate a stack-trace or something (is there a gdb for windows)? Would be very helpful. Maybe a profile build could provide more info (RelWithDebInfo) on where and what problem occures.

ZenKiyoshi commented 2 years ago

Thats very strange. Does this generate a stack-trace or something (is there a gdb for windows)? Would be very helpful. Maybe a profile build could provide more info (RelWithDebInfo) on where and what problem occures.

I'm not a software development, I quite don't understand what you mention about.

Sorry, I can't help much.

adamjw24 commented 2 years ago

Thats alright. I'll see if we can reproduce it eventually.

Possibly related to: https://github.com/fraunhoferhhi/vvdec/pull/8

adamjw24 commented 2 years ago

What output does the vvdecapp produce when you run it? Does it always crash or only when you specify a bitstream to decode? What happens when you run it explicitely specifing --simd 0 or --simd 1 (or --simd 2)? Please provide as much info as possible. I don't have the CPU at hand so it will be hard to reproduce.

Also help would be appreciated from anyone with a similar CPU who could reproduce the issue and provide a stacktrace.

adamjw24 commented 2 years ago

The AMD R5 3600, as far as I understand, supports AVX2, so it seems there are some AVX2 instructions out there that break the compatibility with non-AVX2 CPUs. I'll see if I can find a CPU like that. Which compiler do you use in the MSYS2?

ZenKiyoshi commented 2 years ago

The AMD R5 3600, as far as I understand, supports AVX2

Yes, AMD R5 3600 does support AVX2. I5 2500s has been 10 years old already and it's latest instruction is AVX(1).

Which compiler do you use in the MSYS2?

mingw-w64-x86_64-gcc

msys2-gcc

Does it always crash or only when you specify a bitstream to decode? What happens when you run it explicitely specifing --simd 0 or --simd 1 (or --simd 2)?

I just type "vvdecapp.exe" in cmd, no any thing else, hit enter and it crashes immediately also throwing error message box (like image in first post). Or double click on vvdecapp.exe file.

adamjw24 commented 2 years ago

Could you type vvdecapp.exe --simd 0 and report what happens? That is strange that the decoder app does not produce any output before exiting.

ZenKiyoshi commented 2 years ago

Could you type vvdecapp.exe --simd 0 and report what happens? That is strange that the decoder app does not produce any output before exiting.

It just crashes for each time I try and no any output.

vvdec-1

. . On static build vvdec will show input error if I don't give it bitsteam file. With --simd 4, vvdec show error, because i5 2500s doesn't have AVX2.

vvdec-static

With --simd 3 (static build) i5 2500s has AVX(1), but vvdecapp still shows error.

vvdec-simd-3

adamjw24 commented 2 years ago

I went around the office yesterday to try and find the oldest working computer. I found one or two candidates I might get my hands on next week, that don't have AVX2 - if that's even the actual problem. Keep you posted.

K-os commented 2 years ago

I have an old laptop at home with a similarly old CPU. I can test it on that machine tomorrow.

Which version of Windows are you using? Could that be the problem?

ZenKiyoshi commented 2 years ago

Window 10 Pro 21H2, build 19044.1889 (both 2 PC)

My binary files: https://mega.nz/folder/l1liBQIR#j7QgZSlb8VYlX1wpCtV1EQ

I just reinstalled Window on i5 2500s PC on this early year. It's main purposes are web browser, movies. I don't install any programs could intervene deep in system. I usually use vvdec to decode some videos I encode from AMD machine, but it's static build vvdec.

Until I try to build shared and issue happens. I found this issue when try MPV build from VVCEASY. That is a MPV build with vvdec intergrated, so I don't need run command every time I watch vvc video. It run on my AMD machine, but not i5 one.

So, I started build my own vvdec intergrated MPV and face the same result, It ran on my AMD, not i5. I went back, test FFmpeg, it also didn't, then vvdec and found out vvdec didn't run from beginning. If I build FFmpeg and MPV without vvdec, they can run on i5 PC.

The reason I build shared because FFmpeg don't recognize static build vvdec when run ./configure --enable-libvvdec, it only reconiges the shared build.

MartinEesmaa commented 2 years ago

@ZenKiyoshi, I think I definitely agree with you. I tried same thing to build ffmpeg vvc static build, but not recognised or found. Also, I tried build vvdecapp of static, but it does not link for some reason using MSYS2 MinGW only.

Cross compilation of Windows in Linux worked with static without DLL mess. Cross compiled files of vvenc & vvdec: https://mega.nz/folder/GtUg0LxC#bVCANqxakq4AHgf-3OoNuA

Trying cross compile vvdec with FFmpeg, does not detect only static.

Build with RelWithDebInfo using MSYS2 and share to developers:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo .. -G "MinGW Makefiles"
K-os commented 2 years ago

I was able to reproduce the error on an old laptop. For some reason the compiler outputs code that uses an unsupported instruction. If I build without link-time optimization the problem disappears. My impression is, that the cause of the problem is a compiler bug.

To disable link-time optimization either: make release-shared disable-lto=1 or: add -DVVDEC_ENABLE_LINK_TIME_OPT=OFF to your cmake invocation

MartinEesmaa commented 2 years ago

@K-os, it seems worked to build FFmpeg vvc without reason, but only vvenc did not recognised of FFmpeg. https://github.com/MartinEesmaa/FFmpeg-FixVVC

cmake -DVVENC_ENABLE_LINK_TIME_OPT=OFF -DBUILD_SHARED_LIBS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/mingw64 -G "MinGW Makefiles" ..

error log:

marti@martinhero13 MINGW64 ~/FFmpeg-FixVVC
$ ./configure --enable-libfdk-aac --enable-libvvenc --enable-libvvdec --enable-static --disable-shared --enable-pic --enable-libxml2 --enable-zlib --extra-libs='-lpthread -lm -lz' --extra-ldexeflags=-static --pkg-config-flags=-static --disable-w32threads --extra-version=VVCEasy
ERROR: libvvenc >= 1.4.0 not found using pkg-config

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.
K-os commented 2 years ago

@MartinEesmaa did you build vvenc? This error has nothing to do with how you compiled vvdec.

MartinEesmaa commented 2 years ago

@MartinEesmaa did you build vvenc? This error has nothing to do with how you compiled vvdec.

I built vvenc without lto and tried to use --enable-libvvenc on my ffmpeg vvc repository and won't recognise, but libvvdec is recognized by FFmpeg vvc. vvenc & vvdec without lto are also working fine.

adamjw24 commented 2 years ago

@MartinEesmaa did you build vvenc? This error has nothing to do with how you compiled vvdec.

I built vvenc without lto and tried to use --enable-libvvenc on my ffmpeg vvc repository and won't recognise, but libvvdec is recognized by FFmpeg vvc. vvenc & vvdec without lto are also working fine.

Why build it static tho? Didn't you state that FFmpeg only works with dynamic builds? FFmpeg not recognizing static builds is a different issue and should not be discussed in this thread

ZenKiyoshi commented 2 years ago

@K-os I compile again and my i5 2500s can run vvdec shared build now.

One more thing. i5 2500s does have AVX(1), so I think it could run vvdec with --simd 3 but vvdec only allows --simd 2 on this cpu.

vvdec-simd-3

K-os commented 2 years ago

Oh yes. AVX detection is disabled for all windows builds, because Visual Studio used to produce code that resulted in invalid instructions. It should probably only be disabled for Visual Studio builds.

But I don't think there would be a significant performance improvement, since there is no specific AVX code in vvdec. It will only allow the compiler to optimize some code using AVX instructions.

You can give it a try by removing the #ifndef _WIN32 and #endif in CommonDefX86.cpp lines 187 and 190: https://github.com/fraunhoferhhi/vvdec/blob/3956df5c91fceda76b2f095c999e3ef2b8e8870c/source/Lib/CommonLib/x86/CommonDefX86.cpp#L187-L190 But leave the ext = AVX; there.