haasn / libplacebo

Official mirror of libplacebo
http://libplacebo.org/
GNU Lesser General Public License v2.1
524 stars 63 forks source link

Question about UCRT when building Windows Version of MPV #183

Closed CharlesMengCA closed 11 months ago

CharlesMengCA commented 11 months ago

Hi @kasper93,

Current Windows build script has been using UCRT to build the mpv.exe

https://github.com/shinchiro/mpv-winbuild-cmake/commit/4e318980546925534d8504b2f9d01a37592c859b

Do we need to change anything in the meson.build in libplacebo to use the UCRT?

Something need to be changed here?

# Looks like meson in certain configuration returns ' ' instead of empty string
mingw32 = cc.get_define('__MINGW32__').strip()
if host_machine.system() == 'windows' and mingw32 != '' and host_machine.cpu() in ['aarch64', 'arm', 'x86_64']
  # MinGW-w64 math functions are significantly slower than the UCRT ones.
  # In particular powf is over 7 times slower than UCRT counterpart.
  # MinGW-w64 explicitly excludes some math functions from their ucrtbase def
  # file and replaces with own versions. To workaround the issue, generate the
  # import library and link it with UCRT versions of math functions.
  dlltool = find_program('llvm-dlltool', 'dlltool')
  ucrt_math = custom_target('ucrt_math.lib',
                            output : ['ucrt_math.lib'],
                            input : 'ucrt_math.def',
                            command : [dlltool, '-d', '@INPUT@', '-l', '@OUTPUT@'])
  build_deps += declare_dependency(link_with: ucrt_math)
  # MinGW-w64 inlines functions like powf, rewriting them to pow. We want to use
  # the powf specialization from UCRT, so disable inlining.
  add_project_arguments(['-D__CRT__NO_INLINE'], language: ['c', 'cpp'])
endif

Thanks,

kasper93 commented 11 months ago

Current Windows build script has been using UCRT to build the mpv.exe

It doesn't matter. The problem is not UCRT. Mingw-w64 explicitly override some math functions with their own versions, even for UCRT, where they are available and better.

Do we need to change anything in the meson.build in libplacebo to use the UCRT?

The code you quoted is only working when building libplacebo to shared library. Since you are linking statically everything, it is not used. Static libplacebo archive, will use whatever math is available during final link, of mpv.exe in your case.

If you want to have the same behavior you would need to replicate it in your build system, and use custom .lib like we do. Or link libplacebo.dll instead.

CharlesMengCA commented 11 months ago

Thank you very much.