From aefa2a9573f7a774472a756e59bba5849fa66f97 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 19 Aug 2018 22:20:08 +0200 Subject: [PATCH] Display dialog when CPU doesn't support AVX/AVX2. --- profiler/build/win32/Tracy.vcxproj | 1 + profiler/build/win32/Tracy.vcxproj.filters | 3 ++ profiler/src/winmain.cpp | 37 ++++++++++++++++++++++ profiler/src/winmainArchDiscovery.cpp | 22 +++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 profiler/src/winmainArchDiscovery.cpp diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 3e866506..c8b1153e 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -114,6 +114,7 @@ NotSet NotSet + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 884f0256..918e550e 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -78,6 +78,9 @@ src + + src + diff --git a/profiler/src/winmain.cpp b/profiler/src/winmain.cpp index 40f456e0..fd3c35f2 100644 --- a/profiler/src/winmain.cpp +++ b/profiler/src/winmain.cpp @@ -1,11 +1,48 @@ #ifdef _WIN32 # include # include +# include +# include + +namespace tracy +{ +bool DiscoveryAVX(); +bool DiscoveryAVX2(); +} int main( int argc, char** argv ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd, int nCmd ) { + { + uint32_t regs[4]; + __cpuidex( (int*)regs, 0, 0 ); + const uint32_t maxLeaf = regs[0]; + bool cpuHasAVX = false; + bool cpuHasAVX2 = false; + if( maxLeaf >= 1 ) + { + __cpuidex( (int*)regs, 1, 0 ); + cpuHasAVX = ( regs[2] & 0x10000000 ) != 0; + } + if( maxLeaf >= 7 ) + { + __cpuidex( (int*)regs, 7, 0 ); + cpuHasAVX2 = ( regs[1] & 0x00000020 ) != 0; + } + + if( tracy::DiscoveryAVX2() && !cpuHasAVX2 ) + { + MessageBoxA( nullptr, "This program is compiled with AVX2 instruction set, but your CPU doesn't support it. You must recompile with lower instruction set.\n\nIn Visual Studio go to Project properties -> C/C++ -> Code Generation -> Enable Enhanced Instruction Set and select appropriate value for your CPU.", "Wrong CPU architecture", MB_ICONERROR ); + return 0; + } + if( tracy::DiscoveryAVX() && !cpuHasAVX ) + { + MessageBoxA( nullptr, "This program is compiled with AVX instruction set, but your CPU doesn't support it. You must recompile with lower instruction set.\n\nIn Visual Studio go to Project properties -> C/C++ -> Code Generation -> Enable Enhanced Instruction Set and select appropriate value for your CPU.", "Wrong CPU architecture", MB_ICONERROR ); + return 0; + } + } + return main( __argc, __argv ); } #endif diff --git a/profiler/src/winmainArchDiscovery.cpp b/profiler/src/winmainArchDiscovery.cpp new file mode 100644 index 00000000..826fd9fd --- /dev/null +++ b/profiler/src/winmainArchDiscovery.cpp @@ -0,0 +1,22 @@ +#ifdef _WIN32 +namespace tracy +{ + bool DiscoveryAVX() + { +#ifdef __AVX__ + return true; +#else + return false; +#endif + } + + bool DiscoveryAVX2() + { +#ifdef __AVX2__ + return true; +#else + return false; +#endif + } +} +#endif