diff --git a/CMakeLists.txt b/CMakeLists.txt index a92854af1..c461929d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,15 +47,53 @@ elseif(UNIX) add_compile_definitions(SDL2=1) endif() - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdeclspec -fms-extensions") - if (USE_LIBCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi") - endif() + add_compile_options( + -fdeclspec + -fms-extensions + + -Wuninitialized + #-Wwrite-strings + #-Winit-self + #-Wreturn-type + #-Wreorder + #-Werror=delete-non-virtual-dtor + #-Werror + #uncomment this to stop the compilation at the first error + # -Wfatal-errors + + # turn off some warnings we don't want + -Wno-nullability-completeness # _Nonnull etc. are only supported on Clang + ) + if (USE_LIBCXX) + add_compile_options( + $<$:-stdlib=libc++> + ) + add_link_options( + -stdlib=libc++ + ) + endif() elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -else() +# add some warnings and set them as errors +# read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html + add_compile_options( + -Wuninitialized + -Wmaybe-uninitialized + -Wwrite-strings + -Winit-self + -Wreturn-type + $<$:-Wreorder> + $<$:-Werror=delete-non-virtual-dtor> + -Werror + + # some GCC versions have bugs triggering this warning + -Wno-stringop-overflow + # this is just silly + -Wno-format-zero-length + + #uncomment this to stop the compilation at the first error + # -Wfatal-errors + ) endif() diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 4b83872b1..4e502ef9e 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -7,7 +7,7 @@ #include "DummyVisualizer.h" // some application parameters can be overwritten in the executable by finding the 256 byte long pattern in the first member: -extern ApplicationExeCustomization exe_customization = { +ApplicationExeCustomization exe_customization = { "Wicked Editor ", wi::Color(130, 210, 220, 255), wi::Color(17, 30, 43, 255) diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 49f6fed60..933a9b6d9 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -4767,8 +4767,8 @@ void ExportModel_GLTF(const std::string& filename, Scene& scene) // Build accessors - size_t morph_pos_accessor_index; - if(buf_d_morph_pos_size > 0) + size_t morph_pos_accessor_index = 0; + if (buf_d_morph_pos_size > 0) { // Sparse accessor indices auto is_sparse = (m_morph.sparse_indices_positions.size() > 0); @@ -4798,22 +4798,22 @@ void ExportModel_GLTF(const std::string& filename, Scene& scene) morph_pos_accessor_builder.componentType = TINYGLTF_COMPONENT_TYPE_FLOAT; morph_pos_accessor_builder.count = (is_sparse) ? mesh.vertex_positions.size() : m_morph.vertex_positions.size(); morph_pos_accessor_builder.type = TINYGLTF_TYPE_VEC3; - if(is_sparse) + if (is_sparse) { auto& sparse = morph_pos_accessor_builder.sparse; sparse.isSparse = true; sparse.count = (int)m_morph.sparse_indices_positions.size(); - + sparse.indices.bufferView = morph_sparse_bufferView_index; sparse.indices.componentType = TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT; - + sparse.values.bufferView = morph_pos_bufferView_index; } state.gltfModel.accessors.push_back(morph_pos_accessor_builder); } - size_t morph_norm_accessor_index; - if(buf_d_morph_norm_size > 0) + size_t morph_norm_accessor_index = 0; + if (buf_d_morph_norm_size > 0) { // Sparse accessor indices auto is_sparse = (m_morph.sparse_indices_normals.size() > 0); @@ -4845,15 +4845,15 @@ void ExportModel_GLTF(const std::string& filename, Scene& scene) // morph_norm_accessor_builder.count = (is_sparse) ? mesh.vertex_normals.size() : m_morph.vertex_normals.size(); morph_norm_accessor_builder.count = (is_sparse) ? mesh.vertex_positions.size() : m_morph.vertex_normals.size(); morph_norm_accessor_builder.type = TINYGLTF_TYPE_VEC3; - if(is_sparse) + if (is_sparse) { auto& sparse = morph_norm_accessor_builder.sparse; sparse.isSparse = true; sparse.count = (int)m_morph.sparse_indices_normals.size(); - + sparse.indices.bufferView = morph_sparse_bufferView_index; sparse.indices.componentType = TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT; - + sparse.values.bufferView = morph_norm_bufferView_index; } state.gltfModel.accessors.push_back(morph_norm_accessor_builder); diff --git a/Editor/ModelImporter_OBJ.cpp b/Editor/ModelImporter_OBJ.cpp index fa759d6b6..b885809fc 100644 --- a/Editor/ModelImporter_OBJ.cpp +++ b/Editor/ModelImporter_OBJ.cpp @@ -2,9 +2,15 @@ #include "wiScene.h" #include "ModelImporter.h" +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif #define TINYOBJLOADER_IMPLEMENTATION #include "tiny_obj_loader.h" - +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif using namespace wi::graphics; using namespace wi::scene; using namespace wi::ecs; diff --git a/Samples/Example_ImGui_Docking/main_Windows.cpp b/Samples/Example_ImGui_Docking/main_Windows.cpp index 3320c11ba..e0a874612 100644 --- a/Samples/Example_ImGui_Docking/main_Windows.cpp +++ b/Samples/Example_ImGui_Docking/main_Windows.cpp @@ -111,7 +111,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) float sizeadjust = 0.93; float screen_width = GetSystemMetrics(SM_CXSCREEN); float screen_height = GetSystemMetrics(SM_CYSCREEN); - RECT rect = { (screen_width -(screen_width * sizeadjust)), (screen_height -(screen_height * sizeadjust)), screen_width * sizeadjust, screen_height * sizeadjust}; + RECT rect = { (long)(screen_width -(screen_width * sizeadjust)), (long)(screen_height -(screen_height * sizeadjust)), (long)(screen_width * sizeadjust), (long)(screen_height * sizeadjust)}; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, true); HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, diff --git a/Samples/Template_Windows/CMakeLists.txt b/Samples/Template_Windows/CMakeLists.txt index 3f2fa6b8a..1bcc1d2e9 100644 --- a/Samples/Template_Windows/CMakeLists.txt +++ b/Samples/Template_Windows/CMakeLists.txt @@ -14,7 +14,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ) if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + add_compile_options(/MP) endif() set_target_properties(${PROJECT_NAME} PROPERTIES diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index 00d5094d0..9a06c7446 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -7,6 +7,18 @@ include(GNUInstallDirs) set(INSTALL_LOCAL_CONFIGDIR "${CMAKE_BINARY_DIR}/cmake") set(INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/WickedEngine") +# Use same options as Jolt +# Select X86 processor features to use (if everything is off it will be SSE2 compatible) +option(USE_SSE4_1 "Enable SSE4.1" ON) +option(USE_SSE4_2 "Enable SSE4.2" ON) +option(USE_AVX "Enable AVX" ON) +option(USE_AVX2 "Enable AVX2" ON) +option(USE_AVX512 "Enable AVX512" OFF) +option(USE_LZCNT "Enable LZCNT" ON) +option(USE_TZCNT "Enable TZCNT" ON) +option(USE_F16C "Enable F16C" ON) +option(USE_FMADD "Enable FMADD" ON) + if (WICKED_DYNAMIC_LIBRARY) set(WICKED_LIBRARY_TYPE SHARED) message(STATUS "Building WickedEngine as a shared library") @@ -55,6 +67,11 @@ add_subdirectory(Utility) add_compile_definitions(JPH_DEBUG_RENDERER=1) set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) include(${PHYSICS_REPO_ROOT}/Jolt/Jolt.cmake) +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # Jolt triggers a bug in some GCC versions, so we need to disable the warning + target_compile_options(Jolt PRIVATE -Wno-stringop-overflow) +endif() + set_target_properties(Jolt PROPERTIES POSITION_INDEPENDENT_CODE ${WICKED_PIC} ) @@ -69,10 +86,6 @@ add_library(${TARGET_NAME} ${WICKED_LIBRARY_TYPE} ${HEADER_FILES} ) -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj") -endif() - add_library(WickedEngine ALIAS ${TARGET_NAME}) set_target_properties(${TARGET_NAME} PROPERTIES PUBLIC_HEADER "${HEADER_FILES}" @@ -90,12 +103,58 @@ set(WICKEDENGINE_STATIC_LIBRARIES Utility ) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + if ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86" OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + if (USE_AVX512) + target_compile_options(${TARGET_NAME} PUBLIC /arch:AVX512) + elseif (USE_AVX2) + target_compile_options(${TARGET_NAME} PUBLIC /arch:AVX2) + elseif (USE_AVX) + target_compile_options(${TARGET_NAME} PUBLIC /arch:AVX) + endif() + endif() +elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") + if (USE_AVX512) + target_compile_options(${TARGET_NAME} PUBLIC -mavx512f -mavx512vl -mavx512dq -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) + elseif (USE_AVX2) + target_compile_options(${TARGET_NAME} PUBLIC -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) + elseif (USE_AVX) + target_compile_options(${TARGET_NAME} PUBLIC -mavx -mpopcnt) + elseif (USE_SSE4_2) + target_compile_options(${TARGET_NAME} PUBLIC -msse4.2 -mpopcnt) + elseif (USE_SSE4_1) + target_compile_options(${TARGET_NAME} PUBLIC -msse4.1) + else() + target_compile_options(${TARGET_NAME} PUBLIC -msse2) + endif() + if (USE_LZCNT) + target_compile_options(${TARGET_NAME} PUBLIC -mlzcnt) + endif() + if (USE_TZCNT) + target_compile_options(${TARGET_NAME} PUBLIC -mbmi) + endif() + if (USE_F16C) + target_compile_options(${TARGET_NAME} PUBLIC -mf16c) + endif() + if (USE_FMADD) + target_compile_options(${TARGET_NAME} PUBLIC -mfma) + endif() + + target_compile_options(${TARGET_NAME} PUBLIC -mfpmath=sse) +endif() + if (WIN32) target_compile_definitions(${TARGET_NAME} PUBLIC UNICODE _UNICODE ) - target_compile_options(${TARGET_NAME} PRIVATE /W3) + if (MSVC) + add_compile_options( + /W3 + /MP + /bigobj + ) + endif() set(LIBDXCOMPILER "dxcompiler.dll") else () @@ -114,38 +173,6 @@ else () ) set(WICKEDENGINE_STATIC_LIBRARIES ${WICKEDENGINE_STATIC_LIBRARIES} FAudio) - if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(${TARGET_NAME} PRIVATE - -Wuninitialized - #-Wwrite-strings - #-Winit-self - #-Wreturn-type - #-Wreorder - #-Werror=delete-non-virtual-dtor - #-Werror - #uncomment this to stop the compilation at the first error - # -Wfatal-errors - - # turn off some warnings we don't want - -Wno-nullability-completeness # _Nonnull etc. are only supported on Clang - ) - elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # add some warnings and set them as errors - # read more details here: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html - target_compile_options(${TARGET_NAME} PRIVATE - -Wuninitialized - -Wmaybe-uninitialized - -Wwrite-strings - -Winit-self - -Wreturn-type - -Wreorder - -Werror=delete-non-virtual-dtor - -Werror - #uncomment this to stop the compilation at the first error - # -Wfatal-errors - ) - endif() - target_link_libraries(${TARGET_NAME} PRIVATE dl) set(LIBDXCOMPILER "libdxcompiler.so") diff --git a/WickedEngine/wiMath.h b/WickedEngine/wiMath.h index b17b3401a..b4b29126c 100644 --- a/WickedEngine/wiMath.h +++ b/WickedEngine/wiMath.h @@ -5,12 +5,13 @@ #include #include +#define _XM_FMA3_INTRINSICS_ +#define _XM_F16C_INTRINSICS_ + #if __has_include("DirectXMath.h") // In this case, DirectXMath is coming from Windows SDK. // It is better to use this on Windows as some Windows libraries could depend on the same // DirectXMath headers -#define _XM_F16C_INTRINSICS_ -#define _XM_FMA3_INTRINSICS_ #include #include #include diff --git a/WickedEngine/wiScene_Components.h b/WickedEngine/wiScene_Components.h index 9fd252052..9917bddbd 100644 --- a/WickedEngine/wiScene_Components.h +++ b/WickedEngine/wiScene_Components.h @@ -1981,7 +1981,7 @@ namespace wi::scene // These are maintained for top-down chained update by spring dependency system: wi::vector children; - wi::ecs::Entity entity; + wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY; TransformComponent* transform = nullptr; TransformComponent* parent_transform = nullptr;