From bee257d4466f581204a3f9a4b2e350544d437c92 Mon Sep 17 00:00:00 2001 From: Balazs OROSZI Date: Sun, 30 Oct 2016 03:03:20 +0100 Subject: [PATCH 01/20] DirectShowSource: Sensible defaults for CMake baseclasses lib, removed dx include path --- plugins/DirectShowSource/CMakeLists.txt | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/plugins/DirectShowSource/CMakeLists.txt b/plugins/DirectShowSource/CMakeLists.txt index b391243a0..bd8156d1d 100644 --- a/plugins/DirectShowSource/CMakeLists.txt +++ b/plugins/DirectShowSource/CMakeLists.txt @@ -5,15 +5,17 @@ CMAKE_MINIMUM_REQUIRED( VERSION 2.8.11 ) set(PluginName "DirectShowSource") set(ProjectName "Plugin${PluginName}") -# We need these variables set by the user to compile successfully -set(DSHOWSRC_BASECLASSES_PATH "C:/Program Files/Microsoft SDKs/Windows/v7.0/Samples/multimedia/directshow/baseclasses" CACHE STRING "Folder path to the DirectShow example baseclasses.") -#set(DSHOWSRC_BASECLASSES_PATH "C:/Program Files (x86)/Microsoft SDKs/Windows/v7.1A/Samples/multimedia/directshow/baseclasses" CACHE STRING "Folder path to the DirectShow example baseclasses.") -if(CMAKE_SIZEOF_VOID_P EQUAL 4) -set(DSHOWSRC_BASECLASSES_LIB "c:/Program Files/Microsoft SDKs/Windows/v7.0/Samples/multimedia/directshow/baseclasses/Release_MBCS/strmbase.lib" CACHE FILEPATH "File path to the DirectShow example baseclasses precompiled static library ('strmbase.lib').") -else() -set(DSHOWSRC_BASECLASSES_LIB "c:/Program Files/Microsoft SDKs/Windows/v7.0/Samples/multimedia/directshow/baseclasses/x64/Release_MBCS/strmbase.lib" CACHE FILEPATH "File path to the DirectShow example baseclasses precompiled static library ('strmbase.lib').") +# Sensible defaults that should just work if WINSDK is installed and baseclasses built +set(DEFAULT_BASECLASSES_PATH "C:/Program Files/Microsoft SDKs/Windows/v7.1/Samples/multimedia/directshow/baseclasses") +if(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32-bit + set(DEFAULT_BASECLASSES_LIB "${DEFAULT_BASECLASSES_PATH}/Release/strmbase.lib") +else() # 64-bit + set(DEFAULT_BASECLASSES_LIB "${DEFAULT_BASECLASSES_PATH}/x64/Release/strmbase.lib") endif() -set(DSHOWSRC_DX_INCLUDE_PATH "C:/Program Files/Microsoft DirectX SDK (August 2009)/Include" CACHE STRING "Include folder path to the DirectX headers.") + +# We need these variables set by the user to compile successfully +set(DSHOWSRC_BASECLASSES_PATH "${DEFAULT_BASECLASSES_PATH}" CACHE STRING "Folder path to the DirectShow example baseclasses.") +set(DSHOWSRC_BASECLASSES_LIB "${DEFAULT_BASECLASSES_LIB}" CACHE FILEPATH "File path to the DirectShow example baseclasses precompiled static library ('strmbase.lib').") # Create library project(${ProjectName}) @@ -27,15 +29,8 @@ set_target_properties(${ProjectName} PROPERTIES "OUTPUT_NAME" ${PluginName}) # Library dependencies target_link_libraries(${ProjectName} "Winmm.lib" "Quartz.lib" "Ole32.lib" "User32.lib" "Oleaut32.lib" "Advapi32.lib" ${DSHOWSRC_BASECLASSES_LIB}) -# Allow back permissive C++ Standard conformance, because old DX headers would fail to compile otherwise -if( MSVC_IDE ) # Check for Visual Studio -remove_definitions("/permissive-") -endif() - - - # Include directories -target_include_directories(${ProjectName} PRIVATE ${AvsCore_SOURCE_DIR} ${DSHOWSRC_BASECLASSES_PATH} ${DSHOWSRC_DX_INCLUDE_PATH}) +target_include_directories(${ProjectName} PRIVATE ${AvsCore_SOURCE_DIR} ${DSHOWSRC_BASECLASSES_PATH}) if (MSVC_IDE) # Copy output to a common folder for easy deployment From 5bbda7dfd4ff8f30f55d9e392c0ae0b959b2f7bc Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Wed, 27 Sep 2017 11:12:50 -0400 Subject: [PATCH 02/20] PluginManager.cpp: fix header include for non-Windows 'Imagehlp.h' exists in MinGW, as 'imagehlp.h'. Windows is case insensitive, so it doesn't care about the case of the filename, but 'Imagehlp.h' will cause a failure when crosscompiling from a case sensitive system like Linux or OSX. --- avs_core/core/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avs_core/core/PluginManager.cpp b/avs_core/core/PluginManager.cpp index 02bd15476..c11b60a5a 100644 --- a/avs_core/core/PluginManager.cpp +++ b/avs_core/core/PluginManager.cpp @@ -5,7 +5,7 @@ #include "strings.h" #include "InternalEnvironment.h" #include -#include +#include typedef const char* (__stdcall *AvisynthPluginInit3Func)(IScriptEnvironment* env, const AVS_Linkage* const vectors); typedef const char* (__stdcall *AvisynthPluginInit2Func)(IScriptEnvironment* env); From 8dbf4b81594b18122ef1ddad343bfa88357e8d50 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 30 Sep 2017 19:55:26 -0400 Subject: [PATCH 03/20] capi.h: partially protect against MSVC/GCC compatibility breakage If a program that talks to the C-interface uses the GCC compliant header, it becomes unable to use MSVC builds of AviSynth+. But to build with GCC, those changes are necessary. Guard against this by wrapping the change in a BUILDING_AVSCORE ifdef block so that client programs will use the old calling conventions. Unfortunately, this comes with the caveat that 32-bit GCC builds of AviSynth+ will not work with the client program. 64-bit GCC builds are unaffected. --- avs_core/include/avs/capi.h | 44 ++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/avs_core/include/avs/capi.h b/avs_core/include/avs/capi.h index f45bdcbde..8799bf1fb 100644 --- a/avs_core/include/avs/capi.h +++ b/avs_core/include/avs/capi.h @@ -39,16 +39,44 @@ # define EXTERN_C #endif -#ifdef MSVC -#ifndef AVSC_USE_STDCALL -# define AVSC_CC __cdecl -#else -# define AVSC_CC __stdcall -#endif -#else -# define AVSC_CC +#ifdef BUILDING_AVSCORE +# if defined(GCC) && defined(X86_32) +# define AVSC_CC +# else // MSVC builds and 64-bit GCC +# ifndef AVSC_USE_STDCALL +# define AVSC_CC __cdecl +# else +# define AVSC_CC __stdcall +# endif +# endif +#else // needed for programs that talk to AviSynth+ +# ifndef AVSC_WIN32_GCC32 // see comment below +# ifndef AVSC_USE_STDCALL +# define AVSC_CC __cdecl +# else +# define AVSC_CC __stdcall +# endif +# else +# define AVSC_CC +# endif #endif +// On 64-bit Windows, there's only one calling convention, +// so there is no difference between MSVC and GCC. On 32-bit, +// this isn't true. The convention that GCC needs to use to +// even build AviSynth+ as 32-bit makes anything that uses +// it incompatible with 32-bit MSVC builds of AviSynth+. +// The AVSC_WIN32_GCC32 define is meant to provide a user +// switchable way to make builds of FFmpeg to test 32-bit +// GCC builds of AviSynth+ without having to screw around +// with alternate headers, while still default to the usual +// situation of using 32-bit MSVC builds of AviSynth+. + +// Hopefully, this situation will eventually be resolved +// and a broadly compatible solution will arise so the +// same 32-bit FFmpeg build can handle either MSVC or GCC +// builds of AviSynth+. + #define AVSC_INLINE static __inline #ifdef BUILDING_AVSCORE From 8cd223caa49f124df6327c7ea3f2857904840c86 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 17 Feb 2018 22:40:17 -0500 Subject: [PATCH 04/20] CMakeLists.txt: use quotes when more than one flag is used --- avs_core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avs_core/CMakeLists.txt b/avs_core/CMakeLists.txt index 6823b1701..77dd1eeeb 100644 --- a/avs_core/CMakeLists.txt +++ b/avs_core/CMakeLists.txt @@ -54,7 +54,7 @@ elseif (MINGW) # special AVX2 option for source files with *_avx2.cpp pattern file(GLOB_RECURSE SRCS_AVX2 "*_avx2.cpp") - set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS -mavx2 -mfma) + set_source_files_properties(${SRCS_AVX2} PROPERTIES COMPILE_FLAGS "-mavx2 -mfma") endif() # Specify include directories From 2617d34dbe9be963b3bc60336d03a69510182dae Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sun, 25 Sep 2016 18:19:56 -0400 Subject: [PATCH 05/20] CMakeLists: change MSVC_IDE to MSVC Fixes building when using Ninja as the generator. Since Ninja relies on the regular install rules, the copy operations for regular VS usage remain MSVC_IDE. --- CMakeLists.txt | 2 +- avs_core/CMakeLists.txt | 2 +- avs_core/Files.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f28fe9bf0..c875882b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(CMAKE_CONFIGURATION_TYPES) set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING "Reset the configurations to what we need" FORCE) endif() -IF( MSVC_IDE ) # Check for Visual Studio +IF( MSVC ) # Check for Visual Studio #1800 = VS 12.0 (v120 toolset) #1900 = VS 14.0 (v140 toolset) diff --git a/avs_core/CMakeLists.txt b/avs_core/CMakeLists.txt index 77dd1eeeb..6922f8a94 100644 --- a/avs_core/CMakeLists.txt +++ b/avs_core/CMakeLists.txt @@ -63,7 +63,7 @@ target_include_directories("AvsCore" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_compile_definitions("AvsCore" PRIVATE BUILDING_AVSCORE) # Windows DLL dependencies -if (MSVC_IDE) +if (MSVC) target_link_libraries("AvsCore" "Winmm.lib" "Vfw32.lib" "Msacm32.lib" "Gdi32.lib" "User32.lib" "Advapi32.lib" "Ole32.lib" "ImageHlp.lib") elseif (MINGW) target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp.lib") diff --git a/avs_core/Files.cmake b/avs_core/Files.cmake index 87a6387ed..b78383b05 100644 --- a/avs_core/Files.cmake +++ b/avs_core/Files.cmake @@ -39,7 +39,7 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "filters/exprfilter/*.h" ) -IF( MSVC_IDE ) +IF( MSVC ) # Export definitions in general are not needed on x64 and only cause warnings, # unfortunately we still must need a .def file for some COM functions. if(CMAKE_SIZEOF_VOID_P EQUAL 8) From 690cab434a2192735a4555332eacc14b42b485c3 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 24 Sep 2016 12:27:27 -0400 Subject: [PATCH 06/20] CMakeLists: simplify Windows link target requirements --- avs_core/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/avs_core/CMakeLists.txt b/avs_core/CMakeLists.txt index 6922f8a94..cb22248a1 100644 --- a/avs_core/CMakeLists.txt +++ b/avs_core/CMakeLists.txt @@ -63,10 +63,8 @@ target_include_directories("AvsCore" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_compile_definitions("AvsCore" PRIVATE BUILDING_AVSCORE) # Windows DLL dependencies -if (MSVC) - target_link_libraries("AvsCore" "Winmm.lib" "Vfw32.lib" "Msacm32.lib" "Gdi32.lib" "User32.lib" "Advapi32.lib" "Ole32.lib" "ImageHlp.lib") -elseif (MINGW) - target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp.lib") +if (MSVC OR MINGW) + target_link_libraries("AvsCore" "uuid" "winmm" "vfw32" "msacm32" "gdi32" "user32" "advapi32" "ole32" "imagehlp") endif() if (MSVC_IDE) From 3ab9a89f805cb98ccc21a241494a53cfa16ed9cd Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sun, 25 Sep 2016 19:05:54 -0400 Subject: [PATCH 07/20] CMakeLists: don't use toolset with Ninja --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c875882b4..2ddfdc982 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,4 +104,4 @@ configure_file( IMMEDIATE @ONLY) add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) \ No newline at end of file + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) From 03973fe7e7c18c643640bf049997f43cb2a156ca Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 24 Sep 2016 14:25:02 -0400 Subject: [PATCH 08/20] Files.cmake: enable using *.def under MinGW too --- avs_core/Files.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avs_core/Files.cmake b/avs_core/Files.cmake index b78383b05..1ff852500 100644 --- a/avs_core/Files.cmake +++ b/avs_core/Files.cmake @@ -39,7 +39,7 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "filters/exprfilter/*.h" ) -IF( MSVC ) +IF( MSVC OR MINGW ) # Export definitions in general are not needed on x64 and only cause warnings, # unfortunately we still must need a .def file for some COM functions. if(CMAKE_SIZEOF_VOID_P EQUAL 8) From 2cf607463467edc97fe99ec7f73bb0a39f877a21 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 24 Sep 2016 14:26:03 -0400 Subject: [PATCH 09/20] avisynth*.def: fix syntax errors under MinGW --- avs_core/core/avisynth.def | 2 +- avs_core/core/avisynth64.def | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/avs_core/core/avisynth.def b/avs_core/core/avisynth.def index 259eb3918..add53ad04 100644 --- a/avs_core/core/avisynth.def +++ b/avs_core/core/avisynth.def @@ -1,4 +1,4 @@ -LIBRARY +LIBRARY AviSynth.dll EXPORTS DllGetClassObject PRIVATE DllCanUnloadNow PRIVATE diff --git a/avs_core/core/avisynth64.def b/avs_core/core/avisynth64.def index 6851f636a..0f035e58f 100644 --- a/avs_core/core/avisynth64.def +++ b/avs_core/core/avisynth64.def @@ -1,4 +1,4 @@ -LIBRARY +LIBRARY AviSynth.dll EXPORTS DllGetClassObject PRIVATE DllCanUnloadNow PRIVATE From a01e552fb7a374f47b7ca2a6d0d9c0d9b8f93bb2 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sun, 18 Feb 2018 19:05:01 -0500 Subject: [PATCH 10/20] memcpy_amd.cpp: silence warnings in comments that use single quotes --- avs_core/core/memcpy_amd.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/avs_core/core/memcpy_amd.cpp b/avs_core/core/memcpy_amd.cpp index 66657d3f7..e0d4e7765 100644 --- a/avs_core/core/memcpy_amd.cpp +++ b/avs_core/core/memcpy_amd.cpp @@ -91,18 +91,18 @@ void memcpy_amd(void *dest, const void *src, size_t n) cmp ecx, TINY_BLOCK_COPY jb $memcpy_ic_3 ; tiny? skip mmx copy - cmp ecx, 32*1024 ; don't align between 32k-64k because + cmp ecx, 32*1024 ; // don't align between 32k-64k because jbe $memcpy_do_align ; it appears to be slower cmp ecx, 64*1024 jbe $memcpy_align_done $memcpy_do_align: - mov ecx, 8 ; a trick that's faster than rep movsb... + mov ecx, 8 ; // a trick that's faster than rep movsb... sub ecx, edi ; align destination to qword and ecx, 111b ; get the low bits sub ebx, ecx ; update copy count neg ecx ; set up to jump into the array add ecx, offset $memcpy_align_done - jmp ecx ; jump to array of movsb's + jmp ecx ; // jump to array of movsb's align 4 movsb @@ -159,7 +159,7 @@ align 16 and ecx, 1111b ; only look at the "remainder" bits neg ecx ; set up to jump into the array add ecx, offset $memcpy_last_few - jmp ecx ; jump to array of movsd's + jmp ecx ; // jump to array of movsd's $memcpy_uc_test: cmp ecx, UNCACHED_COPY/64 ; big enough? use block prefetch copy @@ -222,7 +222,7 @@ align 16 dec eax ; count down the cache lines jnz $memcpy_bp_2 ; keep grabbing more lines into cache - mov eax, CACHEBLOCK ; now that it's in cache, do the copy + mov eax, CACHEBLOCK ; // now that it's in cache, do the copy align 16 $memcpy_bp_3: movq mm0, [esi ] ; read 64 bits @@ -270,10 +270,10 @@ align 4 movsd movsd -$memcpy_last_few: ; dword aligned from before movsd's +$memcpy_last_few: ; // dword aligned from before movsd's mov ecx, ebx ; has valid low 2 bits of the byte count and ecx, 11b ; the last few cows must come home - jz $memcpy_final ; no more, let's leave + jz $memcpy_final ; // no more, let's leave rep movsb ; the last 1, 2, or 3 bytes $memcpy_final: From f4ef04b6c9da6164f317dabc3251d096e213e127 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sun, 18 Feb 2018 20:25:11 -0500 Subject: [PATCH 11/20] CMakeLists.txt: use stdcall fixup --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ddfdc982..d248f17c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ ELSE() # c++17: if constexpr() and others from gcc 7 SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" ) # or -std=c++17 w/o gnu c++17 extensions SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native" ) + SET( CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup" ) ENDIF() From fac8340c0f15da96564d923fd05d6d26955c7d48 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Mon, 26 Feb 2018 06:44:37 -0500 Subject: [PATCH 12/20] script.cpp: sprintf_s under MinGW-w64 requires Secure API This is a quick-and-dirty way of working around this issue. A better solution would be a header/source combination that defines our own secure functions if Windows doesn't provide them. The problem with MinGW-w64, though, is that the presence of the Secure API causes other compatibility issues to be pervasive. --- avs_core/core/parser/script.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/avs_core/core/parser/script.cpp b/avs_core/core/parser/script.cpp index 5a865a368..a7e111d49 100644 --- a/avs_core/core/parser/script.cpp +++ b/avs_core/core/parser/script.cpp @@ -49,6 +49,10 @@ #include "../InternalEnvironment.h" #include +#ifndef MINGW_HAS_SECURE_API +#define sprintf_s sprintf +#endif + /******************************************************************** From cd92f9777df85a3476a20a625c7e42bb97fe4d7f Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Sat, 4 Aug 2018 22:05:28 -0400 Subject: [PATCH 13/20] CMakeLists.txt: use CPU_ARCH to allow user-selected MSVC SIMD level Still defaults to SSE2, but can now be set higher or lower when configuring, instead of hand-editing CMakeLists.txt. --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d248f17c1..b96879684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,18 +68,22 @@ IF( MSVC ) # Check for Visual Studio # Enable CRT heap debugging - only effective in debug builds add_definitions("/D _CRTDBG_MAP_ALLOC") - + add_definitions("/D __SSE2__") if(CMAKE_SIZEOF_VOID_P EQUAL 4) - # VC++ enables the SSE2 instruction set by default even on 32-bits. Step back a bit. - #add_definitions("/arch:SSE") - add_definitions("/arch:SSE2") # Better use this one, it's 2017 now, and helps optimizing hbd stuff still in C - endif() + # CPU_ARCH can be overridden with the corresponding values when using MSVC: + # IA32 (disabled), + # SSE (Pentium III and higher, 1999), + # SSE2 (Pentium 4 and higher, 2000/2001), + # AVX (Sandy Bridge and higher, 2011), + # AVX2 (Haswell and higher, 2013) + set(MSVC_CPU_ARCH "SSE2" CACHE STRING "Set MSVC architecture optimization level (default: SSE2)") + endif() # Set additional optimization flags - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oy /Ot /GS- /Oi /arch:${MSVC_CPU_ARCH}") # Set C++17 flag set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c++17") From 0cc8f6b878c8d81cd1b78014aa5e71fcca5a7f60 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 10 Aug 2018 08:43:10 -0400 Subject: [PATCH 14/20] plugins/CMakeLists.txt: allow Ninja/NMake to build DirectShowSource --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 7fcba2aff..b0ae113d2 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -12,7 +12,7 @@ if (BUILD_IMAGESEQ) add_subdirectory("ImageSeq") endif() -if (MSVC_IDE OR MINGW) +if (MSVC OR MINGW) if(BUILD_DIRECTSHOWSOURCE) add_subdirectory("DirectShowSource") endif() From d5ef8da7e3293be4e994244a8ac28e3005b8995c Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 10 Aug 2018 08:45:27 -0400 Subject: [PATCH 15/20] Files.cmake: Conditionally enable building avisynth.rc --- avs_core/Files.cmake | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/avs_core/Files.cmake b/avs_core/Files.cmake index 1ff852500..13c5cd446 100644 --- a/avs_core/Files.cmake +++ b/avs_core/Files.cmake @@ -13,7 +13,6 @@ FILE(GLOB AvsCore_Sources RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "core/*.c" "core/*.cpp" "core/*.h" - "core/avisynth.rc" "core/parser/*.c" "core/parser/*.cpp" @@ -47,4 +46,9 @@ IF( MSVC OR MINGW ) else() LIST(APPEND AvsCore_Sources "core/avisynth.def") endif() -ENDIF() \ No newline at end of file +ENDIF() + +IF( MSVC_IDE ) + # Ninja, unfortunately, seems to have some issues with using rc.exe + LIST(APPEND AvsCore_Sources "core/avisynth.rc") +ENDIF() From 3ace499dcc54c47954baac52ffa90b81395b6994 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 10 Aug 2018 08:47:39 -0400 Subject: [PATCH 16/20] CMakeLists.txt: Only use toolsets with MSVC_IDE --- CMakeLists.txt | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b96879684..d0d358b50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,25 +30,27 @@ IF( MSVC ) # Check for Visual Studio file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Output/system") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Output/c_api") - IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2") - #1900 is reported - message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}") - set(CLANG_IN_VS "1") - ENDIF() + IF(MSVC_IDE) + IF(CMAKE_GENERATOR_TOOLSET STREQUAL "v141_clang_c2") + #1900 is reported + message("v141_clang_c2 toolset was specified via -T. Reported MSVC_VERSION is: ${MSVC_VERSION}") + set(CLANG_IN_VS "1") + ENDIF() - # We want our project to also run on Windows XP - # 1900 (VS2015) is not supported but we leave here - IF(MSVC_VERSION VERSION_LESS 1910 ) - IF(NOT CLANG_IN_VS STREQUAL "1") - set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015 - # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics - add_definitions("/Zc:threadSafeInit-") - ENDIF() - ELSE() - IF(NOT CLANG_IN_VS STREQUAL "1") - set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017 - # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics - add_definitions("/Zc:threadSafeInit-") + # We want our project to also run on Windows XP + # 1900 (VS2015) is not supported but we leave here + IF(MSVC_VERSION VERSION_LESS 1910 ) + IF(NOT CLANG_IN_VS STREQUAL "1") + set(CMAKE_GENERATOR_TOOLSET "v140_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2015 + # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics + add_definitions("/Zc:threadSafeInit-") + ENDIF() + ELSE() + IF(NOT CLANG_IN_VS STREQUAL "1") + set(CMAKE_GENERATOR_TOOLSET "v141_xp" CACHE STRING "The compiler toolset to use for Visual Studio." FORCE) # VS2017 + # https://connect.microsoft.com/VisualStudio/feedback/details/1789709/visual-c-2015-runtime-broken-on-windows-server-2003-c-11-magic-statics + add_definitions("/Zc:threadSafeInit-") + ENDIF() ENDIF() ENDIF() From 39a12f18e679772f39ae4b931d9cf019378a7c2e Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 10 Aug 2018 08:50:32 -0400 Subject: [PATCH 17/20] CMakeLists.txt: Silence EHsc->EHa warning when using Ninja/NMake --- CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0d358b50..b8c4b51fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,10 +60,11 @@ IF( MSVC ) # Check for Visual Studio set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-inconsistent-missing-override") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override") ELSE() - # Enable C++ with SEH exceptions - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /EHa") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHa") - # or add_compile_options( /EHa ) for CMake>=3? + # Enable C++ with SEH exceptions + # Avoid an obnoxious 'overrriding /EHsc with /EHa' warning when + # using something other than MSBuild + STRING( REPLACE "/EHsc" "/EHa" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + STRING( REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") ENDIF() # Prevent VC++ from complaining about not using MS-specific functions add_definitions("/D _CRT_SECURE_NO_WARNINGS /D _SECURE_SCL=0") From 8ab8eb00367b5351d9be79ac4c295d2634021478 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 15 Mar 2019 19:18:44 -0400 Subject: [PATCH 18/20] PluginManager.cpp: [MSVC|GCC] should only load [MSVC|GCC] plugins The better way to accomplish this would be to detect it at runtime and simply not autoload those plugins if the compiler for AviSynth itself doesn't match it, but this is the next best option. This commit simply tells GCC builds of AviSynth to use the value of the PluginDir+GCC registry entry to find plugins, and ignore PluginDir and PluginDir+. Vice-versa for MSVC builds. C plugins are an exception to this, since those can be loaded with either MSVC- or GCC-built AviSynth+. I'd suggest either having duplicate copies, or using symbolic links for those. --- avs_core/core/PluginManager.cpp | 241 +++++++++++++++++--------------- 1 file changed, 126 insertions(+), 115 deletions(-) diff --git a/avs_core/core/PluginManager.cpp b/avs_core/core/PluginManager.cpp index c11b60a5a..074eabf27 100644 --- a/avs_core/core/PluginManager.cpp +++ b/avs_core/core/PluginManager.cpp @@ -5,15 +5,19 @@ #include "strings.h" #include "InternalEnvironment.h" #include -#include +#include typedef const char* (__stdcall *AvisynthPluginInit3Func)(IScriptEnvironment* env, const AVS_Linkage* const vectors); typedef const char* (__stdcall *AvisynthPluginInit2Func)(IScriptEnvironment* env); typedef const char* (AVSC_CC *AvisynthCPluginInitFunc)(AVS_ScriptEnvironment* env); const char RegAvisynthKey[] = "Software\\Avisynth"; +#if defined (__GNUC__) +const char RegPluginDirPlus_GCC[] = "PluginDir+GCC"; +#else const char RegPluginDirClassic[] = "PluginDir2_5"; const char RegPluginDirPlus[] = "PluginDir+"; +#endif /* --------------------------------------------------------------------------------- @@ -79,25 +83,25 @@ static std::string GetFullPathNameWrap(const std::string &f) delete [] fullPathName; return result; } - -static bool IsParameterTypeSpecifier(char c) { - switch (c) { - case 'b': case 'i': case 'f': case 's': case 'c': case '.': -#ifdef NEW_AVSVALUE - case 'a': // Arrays as function parameters -#endif - return true; - default: - return false; + +static bool IsParameterTypeSpecifier(char c) { + switch (c) { + case 'b': case 'i': case 'f': case 's': case 'c': case '.': +#ifdef NEW_AVSVALUE + case 'a': // Arrays as function parameters +#endif + return true; + default: + return false; } } -static bool IsParameterTypeModifier(char c) { - switch (c) { - case '+': case '*': - return true; - default: - return false; +static bool IsParameterTypeModifier(char c) { + switch (c) { + case '+': case '*': + return true; + default: + return false; } } @@ -229,86 +233,86 @@ bool AVSFunction::empty() const bool AVSFunction::IsScriptFunction() const { -#ifdef DEBUG_GSCRIPTCLIP_MT - /* - if (!strcmp(this->name, "YPlaneMax")) - return true; - if (!strcmp(this->name, "YPlaneMin")) - return true; - if (!strcmp(this->name, "LumaDifference")) - return true; - */ -/* - if (!stricmp(this->name, "yplanemax")) - return true; - if (!stricmp(this->name, "yplanemin")) - return true; - if (!stricmp(this->name, "lumadifference")) - return true; - */ - //if (!stricmp(this->name, "srestore_inside_1")) - // return true; -#endif - return ( (apply == &(ScriptFunction::Execute)) +#ifdef DEBUG_GSCRIPTCLIP_MT + /* + if (!strcmp(this->name, "YPlaneMax")) + return true; + if (!strcmp(this->name, "YPlaneMin")) + return true; + if (!strcmp(this->name, "LumaDifference")) + return true; + */ +/* + if (!stricmp(this->name, "yplanemax")) + return true; + if (!stricmp(this->name, "yplanemin")) + return true; + if (!stricmp(this->name, "lumadifference")) + return true; + */ + //if (!stricmp(this->name, "srestore_inside_1")) + // return true; +#endif + return ( (apply == &(ScriptFunction::Execute)) || (apply == &Eval) || (apply == &EvalOop) || (apply == &Import) ); } -#ifdef DEBUG_GSCRIPTCLIP_MT -bool AVSFunction::IsRuntimeScriptFunction() const -{ - - if (!strcmp(this->name, "YPlaneMax")) - return true; - if (!strcmp(this->name, "YPlaneMin")) - return true; - if (!strcmp(this->name, "LumaDifference")) - return true; - - //if (!stricmp(this->name, "srestore_inside_1")) - // return true; - - return (apply == &(ScriptFunction::Execute)); -} -#endif - +#ifdef DEBUG_GSCRIPTCLIP_MT +bool AVSFunction::IsRuntimeScriptFunction() const +{ + + if (!strcmp(this->name, "YPlaneMax")) + return true; + if (!strcmp(this->name, "YPlaneMin")) + return true; + if (!strcmp(this->name, "LumaDifference")) + return true; + + //if (!stricmp(this->name, "srestore_inside_1")) + // return true; + + return (apply == &(ScriptFunction::Execute)); +} +#endif + bool AVSFunction::SingleTypeMatch(char type, const AVSValue& arg, bool strict) { switch (type) { case '.': return true; case 'b': return arg.IsBool(); case 'i': return arg.IsInt(); - case 'f': return arg.IsFloat() && (!strict || !arg.IsInt()); - case 's': return arg.IsString(); - case 'c': return arg.IsClip(); -#ifdef NEW_AVSVALUE - case 'a': return arg.IsArray(); // PF 161028 AVS+ script arrays -#endif - default: return false; - } + case 'f': return arg.IsFloat() && (!strict || !arg.IsInt()); + case 's': return arg.IsString(); + case 'c': return arg.IsClip(); +#ifdef NEW_AVSVALUE + case 'a': return arg.IsArray(); // PF 161028 AVS+ script arrays +#endif + default: return false; + } } bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_t num_args, bool strict, IScriptEnvironment* env) { bool optional = false; - /* - { "StackHorizontal", BUILTIN_FUNC_PREFIX, "cc+", StackHorizontal::Create }, - { "Spline", BUILTIN_FUNC_PREFIX, "[x]ff+[cubic]b", Spline }, - { "Select", BUILTIN_FUNC_PREFIX, "i.+", Select }, - { "Array", BUILTIN_FUNC_PREFIX, ".#", ArrayCreate }, // # instead of +: creates script array - - { "IsArray", BUILTIN_FUNC_PREFIX, ".", IsArray }, - { "ArrayGet", BUILTIN_FUNC_PREFIX, "ai", ArrayGet }, - { "ArrayGet", BUILTIN_FUNC_PREFIX, "as", ArrayGet }, - { "ArraySize", BUILTIN_FUNC_PREFIX, "a", ArraySize }, - */ - // arguments are provided in a flattened way (flattened=array elements extracted) - // e.g. string array is provided here string,string,string - size_t i = 0; - while (i < num_args) { - + /* + { "StackHorizontal", BUILTIN_FUNC_PREFIX, "cc+", StackHorizontal::Create }, + { "Spline", BUILTIN_FUNC_PREFIX, "[x]ff+[cubic]b", Spline }, + { "Select", BUILTIN_FUNC_PREFIX, "i.+", Select }, + { "Array", BUILTIN_FUNC_PREFIX, ".#", ArrayCreate }, // # instead of +: creates script array + + { "IsArray", BUILTIN_FUNC_PREFIX, ".", IsArray }, + { "ArrayGet", BUILTIN_FUNC_PREFIX, "ai", ArrayGet }, + { "ArrayGet", BUILTIN_FUNC_PREFIX, "as", ArrayGet }, + { "ArraySize", BUILTIN_FUNC_PREFIX, "a", ArraySize }, + */ + // arguments are provided in a flattened way (flattened=array elements extracted) + // e.g. string array is provided here string,string,string + size_t i = 0; + while (i < num_args) { + if (*param_types == '\0') { // more args than params return false; @@ -332,37 +336,37 @@ bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_ if (param_types[1] == '*') { // skip over initial test of type for '*' (since zero matches is ok) ++param_types; - } - - switch (*param_types) { - case 'b': case 'i': case 'f': case 's': case 'c': -#ifdef NEW_AVSVALUE - case 'a': // PF Arrays -#endif - if ( (!optional || args[i].Defined()) - && !SingleTypeMatch(*param_types, args[i], strict)) - return false; + } + + switch (*param_types) { + case 'b': case 'i': case 'f': case 's': case 'c': +#ifdef NEW_AVSVALUE + case 'a': // PF Arrays +#endif + if ( (!optional || args[i].Defined()) + && !SingleTypeMatch(*param_types, args[i], strict)) + return false; // fall through case '.': ++param_types; - ++i; - break; - case '+': case '*': -#ifdef NEW_AVSVALUE - if (param_types[-1] != '.' && args[i].IsArray()) { // PF new Arrays - // all elements in the array should match with the type char preceding '+*' - // only one array level is enough - for (int j = 0; j < args[i].ArraySize(); j++) - { - if (!SingleTypeMatch(param_types[-1], args[i][j], strict)) - return false; - } - // we're done with the + or * - ++param_types; - ++i; - } - else -#endif + ++i; + break; + case '+': case '*': +#ifdef NEW_AVSVALUE + if (param_types[-1] != '.' && args[i].IsArray()) { // PF new Arrays + // all elements in the array should match with the type char preceding '+*' + // only one array level is enough + for (int j = 0; j < args[i].ArraySize(); j++) + { + if (!SingleTypeMatch(param_types[-1], args[i][j], strict)) + return false; + } + // we're done with the + or * + ++param_types; + ++i; + } + else +#endif if (!SingleTypeMatch(param_types[-1], args[i], strict)) { // we're done with the + or * ++param_types; @@ -378,13 +382,13 @@ bool AVSFunction::TypeMatch(const char* param_types, const AVSValue* args, size_ // We're out of args. We have a match if one of the following is true: // (a) we're out of params. - // (b) remaining params are named i.e. optional. - // (c) we're at a '+' or '*' and any remaining params are optional. - - if (*param_types == '+' || *param_types == '*') - param_types += 1; - - if (*param_types == '\0' || *param_types == '[') + // (b) remaining params are named i.e. optional. + // (c) we're at a '+' or '*' and any remaining params are optional. + + if (*param_types == '+' || *param_types == '*') + param_types += 1; + + if (*param_types == '\0' || *param_types == '[') return true; while (param_types[1] == '*') { @@ -515,6 +519,12 @@ void PluginManager::AddAutoloadDir(const std::string &dirPath, bool toFront) replace_beginning(dir, "PROGRAMDIR", ExeFileDir); std::string plugin_dir; +#if defined (__GNUC__) + if (GetRegString(HKEY_CURRENT_USER, RegAvisynthKey, RegPluginDirPlus_GCC, &plugin_dir)) + replace_beginning(dir, "USER_PLUS_PLUGINS", plugin_dir); + if (GetRegString(HKEY_LOCAL_MACHINE, RegAvisynthKey, RegPluginDirPlus_GCC, &plugin_dir)) + replace_beginning(dir, "MACHINE_PLUS_PLUGINS", plugin_dir); +#else if (GetRegString(HKEY_CURRENT_USER, RegAvisynthKey, RegPluginDirPlus, &plugin_dir)) replace_beginning(dir, "USER_PLUS_PLUGINS", plugin_dir); if (GetRegString(HKEY_LOCAL_MACHINE, RegAvisynthKey, RegPluginDirPlus, &plugin_dir)) @@ -523,6 +533,7 @@ void PluginManager::AddAutoloadDir(const std::string &dirPath, bool toFront) replace_beginning(dir, "USER_CLASSIC_PLUGINS", plugin_dir); if (GetRegString(HKEY_LOCAL_MACHINE, RegAvisynthKey, RegPluginDirClassic, &plugin_dir)) replace_beginning(dir, "MACHINE_CLASSIC_PLUGINS", plugin_dir); +#endif // replace backslashes with forward slashes replace(dir, '\\', '/'); From cf1a4915f46f3abbc3aadc8c6864f69aad3e4984 Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 15 Mar 2019 19:40:53 -0400 Subject: [PATCH 19/20] convolution.cpp: fix out-of-scope build error --- avs_core/filters/convolution.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/avs_core/filters/convolution.cpp b/avs_core/filters/convolution.cpp index a156a39a6..ec05e722c 100644 --- a/avs_core/filters/convolution.cpp +++ b/avs_core/filters/convolution.cpp @@ -76,6 +76,17 @@ extern const AVSFunction Convolution_filters[] = { }; +template +__forceinline int static_clip(int value) { + if (value < mi) { + return mi; + } + if (value > ma) { + return ma; + } + return value; +} + /***************************************** ****** General Convolution 2D filter ***** *****************************************/ @@ -634,17 +645,6 @@ void GeneralConvolution::setMatrix(const char * _matrix, bool _isInteger, IScrip env->ThrowError("GeneralConvolution: matrix incomplete, possible size %dx%d but element count %d", dim, dim, nSize); } -template -__forceinline int static_clip(int value) { - if (value < mi) { - return mi; - } - if (value > ma) { - return ma; - } - return value; -} - PVideoFrame __stdcall GeneralConvolution::GetFrame(int n, IScriptEnvironment* env) { int h = vi.height; From 3bb92dbfe6a26994bcd7bc47ad8191792382122c Mon Sep 17 00:00:00 2001 From: Stephen Hutchinson Date: Fri, 15 Mar 2019 19:41:26 -0400 Subject: [PATCH 20/20] histogram.h: add stdint.h include Fixes a build error due to the use of uint16_t --- avs_core/filters/histogram.h | 1 + 1 file changed, 1 insertion(+) diff --git a/avs_core/filters/histogram.h b/avs_core/filters/histogram.h index 3bf031b37..737d756b3 100644 --- a/avs_core/filters/histogram.h +++ b/avs_core/filters/histogram.h @@ -36,6 +36,7 @@ #include #include +#include "stdint.h" /******************************************************************** ********************************************************************/