From 57fb24bda7183c61c3a790224d61d7145447a7b8 Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Fri, 20 Oct 2023 19:24:26 +0300 Subject: [PATCH 1/7] Fix vcpkg cmake git errors by utilizing existing MSVC vcpkg instead in Windows systems with MSVC. --- CMake/helpers.cmake | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CMake/helpers.cmake b/CMake/helpers.cmake index 55d1795d..d1ac2c84 100644 --- a/CMake/helpers.cmake +++ b/CMake/helpers.cmake @@ -32,14 +32,18 @@ function(att_bootstrap_vcpkg) set(vcpkg_bootstrap_cmd "${VCPKG_ROOT}/bootstrap-vcpkg.sh") endif() - if (NOT EXISTS "${vcpkg_bootstrap_cmd}") - find_program(GIT_CMD git REQUIRED) - execute_process(COMMAND "${GIT_CMD}" clone --filter=tree:0 "https://github.com/microsoft/vcpkg.git" "${VCPKG_ROOT}") + ## If Vcpkg is already installed and set in Windows Environment, stick with it and don't enforce in-house vcpkg. + ## Removes the possibility of vcpkg git errors, it is faster and compiles successfully. (VS 2022 17.7.5) + if(NOT "${vcpkg_default_root}" STREQUAL "$ENV{VCPKG_ROOT}" AND WIN32) + if (NOT EXISTS "${vcpkg_bootstrap_cmd}") + find_program(GIT_CMD git REQUIRED) + execute_process(COMMAND "${GIT_CMD}" clone --filter=tree:0 "https://github.com/microsoft/vcpkg.git" "${VCPKG_ROOT}") - if (NOT EXISTS "${vcpkg_bootstrap_cmd}") - message(FATAL_ERROR "failed to clone vcpkg") + if (NOT EXISTS "${vcpkg_bootstrap_cmd}") + message(FATAL_ERROR "failed to clone vcpkg") + endif() endif() - endif() + endif() if (NOT EXISTS "${vcpkg_cmd}") execute_process(COMMAND "${vcpkg_bootstrap_cmd}" -disableMetrics From 5a3383d74d3fab1c2fb1f2ef68ffa0088667c8a1 Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Fri, 20 Oct 2023 20:02:25 +0300 Subject: [PATCH 2/7] Added default compiler code optimization flags. Terminal compile flags will still override them. --- CMake/helpers.cmake | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CMake/helpers.cmake b/CMake/helpers.cmake index d1ac2c84..5dff4dcf 100644 --- a/CMake/helpers.cmake +++ b/CMake/helpers.cmake @@ -82,7 +82,7 @@ function(att_default_triplet out_triplet) set(${out_triplet} "${triplet}" PARENT_SCOPE) endfunction() -# adds definitions ATT_OS_ and ATT_COMP_ +# adds definitions ATT_OS_ and ATT_COMP_, and specifies compiler-specific optimization flags that prefer runtime performance over size, non-destructive. function(att_target_platform_definitions target) if (WIN32) set(os_name "WINDOWS") @@ -96,10 +96,24 @@ function(att_target_platform_definitions target) if (MSVC) set(comp_name "MSVC") + # Note that any flag specified in build command will overwrite these. Treat them as safe defaults. + # MSVC flags for runtime performance over size, and suggest more aggressive inline functioning to compiler. /favor:AMD64 or INTEL64 may benefit. + # Eigen3 note: /arch:AVX causes crash with Refine tracker calibration, due to Eigen3. 16-byte memory alignment might fix, possibly worse performance than default SSE2. + # You can set /arch to AVX, AVX2 or AVX512 if you don't use calibration refinement. This should increase vectorized loop performance noticably. + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob3 /GA /GL /Qpar /Qpar-report:1 /Qvec-report:1" PARENT_SCOPE) + # Additional linker optimizations as compiler output recommends /LTCG with /GL + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(comp_name "CLANG") + # Clang compiler flags for release. Runtime performance over size. O3 is higher level, but placebo in most cases and increases code size unnecessarily. Should be profiled first. + # TODO : Investigate linker flags for CLang and GCC compilers, and test ftree-vectorize along with fvect-cost-model. flto is experimental but could help. + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(comp_name "GCC") + # GCC compiler flags for release. Runtime performance over size. O3 is higher level, but placebo in most cases and increases code size unnecessarily. Should be profiled first. + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" PARENT_SCOPE) else() set(comp_name "UNKNOWN") endif() From 2c303e306c49d0e326b3c50b92422a7406f54008 Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Fri, 20 Oct 2023 20:23:24 +0300 Subject: [PATCH 3/7] Updated exposure script to be more verbose. --- utilities/set_exposure.bat | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/utilities/set_exposure.bat b/utilities/set_exposure.bat index 2e51fcc8..b8e18c56 100644 --- a/utilities/set_exposure.bat +++ b/utilities/set_exposure.bat @@ -1,16 +1,31 @@ +::Set your IP webcam ip bellow. Do not append http:// or /video here! -::set your IP webcam ip bellow. Do not append http:// or /video here! +set addr=192.168.1.102:8090 -set addr=192.168.1.102:8080 - -::set the wanted exposure. Set this to as low as you can while the image is still bright enough. -::in general, 10000 is enough for regular usage, while 5000 will allow extremely fast movement. +::Set the wanted exposure. Set this to as low as you can while the image is still bright enough. +::In general, 10000 is enough for regular usage, while 5000 will allow extremely fast movement. set exposure=7000 +::Set connection timeout. If you're bothered by CMD file staying open for long even when you're not using an IP webcam, reduce this. Default is 4 seconds. + +set connectionTimeOut=4 +Echo "Looking for IP Webcam... Timeout is %connectionTimeOut% seconds" + +::Check if the IP webcam is alive. +curl -s -I --connect-timeout %connectionTimeOut% %addr% >nul + +::Apply values if IP webcam was found. Otherwise exit immediately so CMD doesn't wait on curl to finish, obstructing view. +if errorlevel 1 ( + Echo "IP Webcam not found, exiting." + timeout /T 2 + exit + ) else ( + curl %addr%/settings/manual_sensor?set=on + ::Change ISO here if your camera supports something higher without getting noisy. It'll help you get a lower exposure value by increasing light sensitivity. Common alternatives are 1600, 3200 etc. -curl %addr%/settings/manual_sensor?set=on -curl %addr%/settings/iso?set=1000 -curl %addr%/settings/exposure_ns?set=%exposure%000 -curl %addr%/settings/focusmode?set=off -curl %addr%/settings/focus_distance?set=1 + curl %addr%/settings/iso?set=1000 + curl %addr%/settings/exposure_ns?set=%exposure%000 + curl %addr%/settings/focusmode?set=off + curl %addr%/settings/focus_distance?set=1 + ) \ No newline at end of file From 1c2a6e7025dbf6ac88d323e42ea167afcd5ccdde Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Fri, 20 Oct 2023 22:29:13 +0300 Subject: [PATCH 4/7] Step-by-step build instructions for Win MSVC that also covers common issues and solutions. --- WindowsBuild_Simple.md | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 WindowsBuild_Simple.md diff --git a/WindowsBuild_Simple.md b/WindowsBuild_Simple.md new file mode 100644 index 00000000..e8858524 --- /dev/null +++ b/WindowsBuild_Simple.md @@ -0,0 +1,69 @@ +Compile steps for Windows: + +__1-__ Download and install Visual Studio 2022 17.8 Preview 2 or newer [(This includes a Msys fix we need)](https://github.com/microsoft/vcpkg/issues/31565#issuecomment-1723267213), check enable building for C/C++ desktop applications during installation. + +__2-__ Copy paste this into the address bar of your browser, to clone and open the master branch in VS2022. When it finishes, confirm Retargeting as shown. +``` +git-client://clone?repo=https%3A%2F%2Fgithub.com%2Fju1ce%2FApril-Tag-VR-FullBody-Tracker +``` + +![image](https://github.com/Skyrion9/April-Tag-VR-FullBody-Tracker/assets/74653117/59955543-1596-4e4a-b804-5a1c8000b3cc) + + + + +We'll switch to Folder view so VS will recognize the project properly. Click on the leftmost icon in Solution Explorer, and click on Folder View. + +![image](https://github.com/Skyrion9/April-Tag-VR-FullBody-Tracker/assets/74653117/6c675ca3-c60d-46e8-9c72-ffb421c78895) + + + + + + +__4-__ Let it rip. Hopefully it'll finish without errors. When you get output : ```[CMake] -- Running vcpkg install - done```, proceed to next step. If you got CXX compiler errors after that line ignore those. VS is trying to use an incorrect install build configuration (of its own making). Remember you can CTRL+F and search for the output mentioned here, as the output window can get cluttered. What's important is vcpkg install finishing. + +If you got ```1> [CMake] CMake Error at scripts/cmake/vcpkg_acquire_msys.cmake:150 (file):``` + +You didn't install the preview version, did you? Go back and do it you lazy sloth you. + +__5-__ In VS, hit View > Terminal and paste the following code into the Developer PowerShell: +``` +cmake -B build +cmake --build build --config Release --target install +``` + +You can find the program in "Install" folder if it compiled successfully. + +## FAQ (Probably?) +There are still ongoing fixes from Microsoft's side, which you won't find out about until you run into an error. Those have been pending for months. This is why Preview version is recommended as it has a fix we need, when the stable version is updated to 17.8 or newer you won't need this. + +__1-__ I still can't compile + +Either use a precompiled exe from Release, or make sure to follow each step exactly, Without alternating to different IDEs etc. Pay attention to Output window and fix anything missing. It's usually a vcpkg bug. In case of missing directory errors, double check your Windows Environment path and add any missing paths that show up in the output. Remember to restart VS and regenerate cache so path changes are recognized. + +Keep in mind, if you get errors at step 4 you can still try step 5. We only need VS to prepare the dependencies for us. It might fail to build, but we bypass this by using the powershell terminal command. You still need to make sure it succeeds in installing vcpkg in the very least ```[CMake] -- Running vcpkg install - done``` + +__1.1-__ If you've an error related to Powershell, I recommend installing Powershell 7. Add it to your User ENV path (Regardless of installation ENV setting. As it adds to System path, but I had to manually add it to User ENV. Alternatively, running VS as admin might fix this and break some other things.) Sometimes VS installer clears up your path. + +Same path addition should fix the default Powershell if you want to skip PS7. + +__1.2-__ [There's a bug where Vcpkg can't install/find Msys](https://github.com/microsoft/vcpkg/issues/31565#issuecomment-1723267213). If your VS 2022 version is older than 17.8, you'll have this error. It is however fixed in 17.8 Preview 2 or newer. + +__2-__ I've an error, how can I get help? + +Double check your steps and make sure you've read through all of this. Reminder Visual Studio installer sometimes resets PATH environment variable when installing in an attempt to tidy it up. If CMake fails to recognize something you've installed, this is probably the reason. You must add anything missing to Path manually. + +Otherwise try [ApriltagVR's discord](https://discord.gg/g2ctkXB4bb). You'll get better help there. + +__3-__ Wow you've read this far? Here's a little reward for you. +``` +@@echo off +start "" "%~dp0AprilTagTrackers.exe" +call "%~dp0\utilities\set_exposure.bat" +exit +``` +Optional batch script to start Apriltag and apply IP Webcam settings simultaneously, unnecessary if you don't use IP Webcam. +Create a notepad file, copy paste the above code in, rename it to "APTGVR_IPCam.bat" file and move it next to AprilTagTrackers.exe and run it as Administrator (Make a shortcut and in properties > shortcut > advanced enable it) + +It'll automatically apply your parameters configured within utilities\set_exposure.bat and launch APTVR, so make sure to update that batch file with your IP Camera parameters first! From cfc5b9bbea13f98c00f2954097ef8f5a14b29ebc Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Sat, 21 Oct 2023 23:01:58 +0300 Subject: [PATCH 5/7] Update README.md, link to Windows build guide --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8dff2cd..752b8850 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev lib ### Windows prerequisites -Open in Visual Studio, or use the Visual Studio Command Prompt. +Open in Visual Studio 17.8 Preview 2 or newer[(Includes a fix)](https://github.com/microsoft/vcpkg/issues/31565#issuecomment-1723267213), and use the Visual Studio Command Prompt. ### Clone and build @@ -70,7 +70,7 @@ cmake -B build cmake --build build --config Release --target install ``` -That should be it! In case you try it before a more detailed guide is up, we are always there to help on the discord server! (link above) +That should be it! [A more detailed guide is up](https://github.com/ju1ce/April-Tag-VR-FullBody-Tracker/blob/master/WindowsBuild_Simple.md), and we are always there to help on the (discord server)[https://discord.gg/g2ctkXB4bb]! ### Troubleshooting From 62c63a922fb4fe16bb026cfce64eeb40adecd763 Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Sun, 22 Oct 2023 01:18:13 +0300 Subject: [PATCH 6/7] Fix missing paranthesis in conditional check -Wrong stash, oops --- CMake/helpers.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMake/helpers.cmake b/CMake/helpers.cmake index 5dff4dcf..a61fce86 100644 --- a/CMake/helpers.cmake +++ b/CMake/helpers.cmake @@ -34,7 +34,7 @@ function(att_bootstrap_vcpkg) ## If Vcpkg is already installed and set in Windows Environment, stick with it and don't enforce in-house vcpkg. ## Removes the possibility of vcpkg git errors, it is faster and compiles successfully. (VS 2022 17.7.5) - if(NOT "${vcpkg_default_root}" STREQUAL "$ENV{VCPKG_ROOT}" AND WIN32) + if(NOT (WIN32 AND "${vcpkg_default_root}" STREQUAL "$ENV{VCPKG_ROOT}")) if (NOT EXISTS "${vcpkg_bootstrap_cmd}") find_program(GIT_CMD git REQUIRED) execute_process(COMMAND "${GIT_CMD}" clone --filter=tree:0 "https://github.com/microsoft/vcpkg.git" "${VCPKG_ROOT}") @@ -43,7 +43,7 @@ function(att_bootstrap_vcpkg) message(FATAL_ERROR "failed to clone vcpkg") endif() endif() - endif() + endif() if (NOT EXISTS "${vcpkg_cmd}") execute_process(COMMAND "${vcpkg_bootstrap_cmd}" -disableMetrics From 4e349689fd4e01ab072fc4d8b66b7857b8ffccf4 Mon Sep 17 00:00:00 2001 From: Skyrion9 Date: Sun, 22 Oct 2023 20:05:31 +0300 Subject: [PATCH 7/7] Move MSVC flags to its own function and remove redundant flags -Added project option to enable additional MSVC flags. Enabled by default, affects only release configuration. --- AprilTagTrackers/CMakeLists.txt | 5 +++++ CMake/helpers.cmake | 35 +++++++++++++++++++-------------- CMakeLists.txt | 1 + 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/AprilTagTrackers/CMakeLists.txt b/AprilTagTrackers/CMakeLists.txt index 980dbf96..262e8d3d 100644 --- a/AprilTagTrackers/CMakeLists.txt +++ b/AprilTagTrackers/CMakeLists.txt @@ -127,6 +127,11 @@ if(ATT_ENABLE_ASAN) att_target_enable_asan(AprilTagTrackers) endif() +# Build with MSVC-specific code optimization flags for release. +if(ATT_ENABLE_MSVC_OPTIMIZATION_FLAGS) + att_target_msvc_release_flags(AprilTagTrackers) +endif() + # Precompiled std and library headers # target_precompile_headers(AprilTagTrackers PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/pch.hpp") diff --git a/CMake/helpers.cmake b/CMake/helpers.cmake index a61fce86..40335145 100644 --- a/CMake/helpers.cmake +++ b/CMake/helpers.cmake @@ -82,7 +82,7 @@ function(att_default_triplet out_triplet) set(${out_triplet} "${triplet}" PARENT_SCOPE) endfunction() -# adds definitions ATT_OS_ and ATT_COMP_, and specifies compiler-specific optimization flags that prefer runtime performance over size, non-destructive. +# adds definitions ATT_OS_ and ATT_COMP_ function(att_target_platform_definitions target) if (WIN32) set(os_name "WINDOWS") @@ -96,24 +96,10 @@ function(att_target_platform_definitions target) if (MSVC) set(comp_name "MSVC") - # Note that any flag specified in build command will overwrite these. Treat them as safe defaults. - # MSVC flags for runtime performance over size, and suggest more aggressive inline functioning to compiler. /favor:AMD64 or INTEL64 may benefit. - # Eigen3 note: /arch:AVX causes crash with Refine tracker calibration, due to Eigen3. 16-byte memory alignment might fix, possibly worse performance than default SSE2. - # You can set /arch to AVX, AVX2 or AVX512 if you don't use calibration refinement. This should increase vectorized loop performance noticably. - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob3 /GA /GL /Qpar /Qpar-report:1 /Qvec-report:1" PARENT_SCOPE) - # Additional linker optimizations as compiler output recommends /LTCG with /GL - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /OPT:REF /OPT:ICF=6 /OPT:LBR /LTCG" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(comp_name "CLANG") - # Clang compiler flags for release. Runtime performance over size. O3 is higher level, but placebo in most cases and increases code size unnecessarily. Should be profiled first. - # TODO : Investigate linker flags for CLang and GCC compilers, and test ftree-vectorize along with fvect-cost-model. flto is experimental but could help. - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(comp_name "GCC") - # GCC compiler flags for release. Runtime performance over size. O3 is higher level, but placebo in most cases and increases code size unnecessarily. Should be profiled first. - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" PARENT_SCOPE) else() set(comp_name "UNKNOWN") endif() @@ -257,6 +243,25 @@ function(att_target_enable_asan target) endif() endfunction() +# Non-destructive MSVC flags that prefer runtime performance over size, and suggests more aggressive inline functioning to compiler. /favor:AMD64 or INTEL64 may benefit. +# You can add /arch to AVX, AVX2 or AVX512 if supported. This should increase vectorized loop performance noticably. +function(att_target_msvc_release_flags target) + if (MSVC) + target_compile_options(${target} PRIVATE + $<$:/Ob3> + $<$:/GA> + $<$:/GL> + $<$:/Qpar> + $<$:/Qpar-report:1> + $<$:/Qvec-report:1> + ) + target_link_options(${target} PRIVATE + $<$:/OPT:ICF=6> + $<$:/LTCG> + ) + endif() +endfunction() + function(att_read_version_file output_var file_path) file(READ "${file_path}" version_text) string(REGEX REPLACE "[ \t\r\n]" "" version_text "${version_text}") diff --git a/CMakeLists.txt b/CMakeLists.txt index 034b9dd2..cd65fff8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ option(ATT_ENABLE_DEBUG_DRIVER "Build and install a debug/testing driver" OFF) option(ATT_DEBUG "Developer mode. Enable custom assert, debug logging, and debugger support. Can be used in release build." OFF) option(ATT_ENABLE_ANALYZER "Enable compiler static analyzers with ATT_DEBUG. CPU intensive." OFF) option(ATT_ENABLE_ASAN "Build with address sanitizer" OFF) +option(ATT_ENABLE_MSVC_OPTIMIZATION_FLAGS "Additional MSVC compiler optimization flags for release build." ON) set(ATT_LOG_LEVEL "1" CACHE STRING "0 - Silent, 1 - Info, 2 - Debug") option(ATT_TEST_ENABLE_ASAN "Build tests with address sanitizer" ON)