diff --git a/.gitignore b/.gitignore index 6e23d430d9..eed7102c4e 100644 --- a/.gitignore +++ b/.gitignore @@ -216,6 +216,7 @@ wiShaderdump.h # vscode .vscode/settings.json +/.vscode/ # PlayStation *.tlog diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e453c7a7f..192c09b804 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,16 +27,25 @@ option(USE_LIBCXX "Link WickedEngine to llvm libc++ library - only available wit option(WICKED_EDITOR "Build WickedEngine editor" ON) option(WICKED_TESTS "Build WickedEngine tests" ON) option(WICKED_IMGUI_EXAMPLE "Build WickedEngine imgui example" ON) -option(WICKED_ENABLE_IPO "Enable IPO/LTO in non-debug builds" NO) -option(WICKED_EMBED_SHADERS "Embed shaders into the library" NO) +option(WICKED_ENABLE_IPO "Enable IPO/LTO in non-debug builds" OFF) +option(WICKED_EMBED_SHADERS "Embed shaders into the library" OFF) option(WICKED_ENABLE_RTTI "Enable RTTI" NO) -if(UNIX) +if (APPLE) + set(WICKED_TESTS OFF) # no main for macos + set(WICKED_IMGUI_EXAMPLE OFF) # no main for macos + set(WICKED_ENABLE_IPO OFF) +endif() + +if(UNIX AND NOT APPLE) option(WICKED_ENABLE_ASAN "Enable AddressSanitizer in debug builds" OFF) option(WICKED_ENABLE_UBSAN "Enable UndefinedBehaviourSanitizer in debug builds" OFF) option(WICKED_ENABLE_TSAN "Enable ThreadSanitizer in debug builds" OFF) option(WICKED_ENABLE_SAN_ALWAYS "Enable the selected sanitizers in all builds, not just debug" OFF) endif() -if(UNIX) + +if(APPLE) + option(WICKED_MACOS_TEMPLATE "Build WickedEngine MacOS template" ON) +elseif(UNIX) option(WICKED_LINUX_TEMPLATE "Build WickedEngine Linux template" ON) elseif(WIN32) option(WICKED_WINDOWS_TEMPLATE "Build WickedEngine Windows template" ON) @@ -113,6 +122,15 @@ if (WIN32) set(PLATFORM "Windows") add_compile_definitions(WIN32=1) add_compile_definitions(_HAS_EXCEPTIONS=0) +elseif (APPLE) + # set(CMAKE_C_COMPILER /opt/homebrew/opt/llvm/bin/clang) + # set(CMAKE_CXX_COMPILER /opt/homebrew/opt/llvm/bin/clang++) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld") + set(CMAKE_LINKER ld64.lld) + set(PLATFORM "MacOS") + add_compile_definitions(MACOS=1) elseif (UNIX) set(PLATFORM "SDL2") add_compile_definitions(SDL2=1) @@ -147,7 +165,7 @@ else() # security checks disabled in Release: $<$:-fno-stack-protector> $<$:-fcf-protection=none> - $<$,$>>:-fno-stack-clash-protection> # not supported on Windows + $<$,$,$>>>:-fno-stack-clash-protection> # not supported on Windows or macOS $<$:-fno-stack-check> $<$,$>>:-fno-asynchronous-unwind-tables> # seems to crash LUA evaluation on Windows ) @@ -206,6 +224,10 @@ if (WICKED_LINUX_TEMPLATE) add_subdirectory(Samples/Template_Linux) endif() +if (WICKED_MACOS_TEMPLATE) + add_subdirectory(Samples/Template_MacOS) +endif() + if (WICKED_WINDOWS_TEMPLATE) add_subdirectory(Samples/Template_Windows) endif() diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index e2a3d1fb2f..8022e2c411 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -6,8 +6,14 @@ string(REGEX REPLACE "([.+?*])" "\\\\\\1" SDIR "${CMAKE_CURRENT_SOURCE_DIR}") file(GLOB SOURCE_FILES CONFIGURE_DEPENDS *.cpp) list(FILTER SOURCE_FILES EXCLUDE REGEX ${SDIR}/main_.*) list(FILTER SOURCE_FILES EXCLUDE REGEX ${SDIR}/stdafx.*) -list(APPEND SOURCE_FILES main_${PLATFORM}.cpp) +if (APPLE) + list(APPEND SOURCE_FILES main_MacOS.mm) + # The project PCH doesn't work with objective C, so disable it for the mm files. + set_source_files_properties(main_MacOS.mm PROPERTIES SKIP_PRECOMPILE_HEADERS ON) +else() + list(APPEND SOURCE_FILES main_${PLATFORM}.cpp) +endif() if (WIN32) list (APPEND SOURCE_FILES @@ -30,6 +36,22 @@ if (WIN32) set_property(TARGET Editor PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") set(LIB_DXCOMPILER "dxcompiler.dll") +elseif (APPLE) + add_executable(Editor ${SOURCE_FILES}) + + find_library(APPKIT_FRAMEWORK AppKit REQUIRED) + + target_link_libraries(Editor PUBLIC + WickedEngine + ${APPKIT_FRAMEWORK} + ) + set(LIB_DXCOMPILER "libdxcompiler.dylib") + + # needed for proper names in crash stacktrace + set_target_properties(Editor + PROPERTIES + ENABLE_EXPORTS ON + ) else () add_executable(Editor ${SOURCE_FILES}) diff --git a/Samples/Example_ImGui/CMakeLists.txt b/Samples/Example_ImGui/CMakeLists.txt index 451c59dfc4..343b456cb3 100644 --- a/Samples/Example_ImGui/CMakeLists.txt +++ b/Samples/Example_ImGui/CMakeLists.txt @@ -43,6 +43,9 @@ if (WIN32) Example_ImGui_Lib ) set(LIB_DXCOMPILER "dxcompiler.dll") +elseif(APPLE) + # TODO + set(LIB_DXCOMPILER "dxcompiler.dylib") else() list(APPEND SOURCE_FILES main_SDL2.cpp @@ -76,10 +79,10 @@ else() endif () if(WICKED_ENABLE_IPO) -set_target_properties(Example_ImGui PROPERTIES - INTERPROCEDURAL_OPTIMIZATION ON - INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF -) + set_target_properties(Example_ImGui PROPERTIES + INTERPROCEDURAL_OPTIMIZATION ON + INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF + ) endif() if (MSVC) diff --git a/Samples/Example_ImGui_Docking/CMakeLists.txt b/Samples/Example_ImGui_Docking/CMakeLists.txt index a242b0f64c..d966fbecd9 100644 --- a/Samples/Example_ImGui_Docking/CMakeLists.txt +++ b/Samples/Example_ImGui_Docking/CMakeLists.txt @@ -47,6 +47,8 @@ if (WIN32) Example_ImGui_Docking_Lib ) set(LIB_DXCOMPILER "dxcompiler.dll") +elseif(APPLE) + set(LIB_DXCOMPILER "dxcompiler.dylib") else() list(APPEND SOURCE_FILES main_SDL2.cpp diff --git a/Samples/Template_MacOS/CMakeLists.txt b/Samples/Template_MacOS/CMakeLists.txt new file mode 100644 index 0000000000..4ce921c6c4 --- /dev/null +++ b/Samples/Template_MacOS/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.19) +project(Template_MacOS) + +# if the engine is installed system-wise, +# you can set INSTALLED_ENGINE to ON +# moving your project folder wherever you want +set(INSTALLED_ENGINE OFF) +# you may also want to remove the copy mechanism of the startup.lua file + +if (${INSTALLED_ENGINE}) + find_package(WickedEngine REQUIRED) +endif() + +set(SOURCE_FILES + main.mm +) + +set(LIB_DXCOMPILER "libdxcompiler.dylib") + +add_executable(Template_MacOS ${SOURCE_FILES}) + +target_link_libraries(Template_MacOS PUBLIC + $,WickedEngine::WickedEngine,WickedEngine> +) + +if(WICKED_ENABLE_IPO) + set_target_properties(Template_MacOS PROPERTIES + INTERPROCEDURAL_OPTIMIZATION ON + INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF + ) +endif() + +if (${INSTALLED_ENGINE}) + get_property(LIBDXCOMPILER_PATH + TARGET WickedEngine::dxcompiler + PROPERTY IMPORTED_LOCATION) + get_filename_component(WICKED_LIBFOLDER ${LIBDXCOMPILER_PATH} DIRECTORY) +else() + set(LIBDXCOMPILER_PATH "${WICKED_ROOT_DIR}/WickedEngine/${LIB_DXCOMPILER}") +endif() +message("libdxcompiler found at ${LIBDXCOMPILER_PATH}") + +add_custom_command( + TARGET Template_MacOS POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDXCOMPILER_PATH} ${CMAKE_CURRENT_BINARY_DIR} +) diff --git a/Samples/Tests/CMakeLists.txt b/Samples/Tests/CMakeLists.txt index c9254ff6f7..a320a435fd 100644 --- a/Samples/Tests/CMakeLists.txt +++ b/Samples/Tests/CMakeLists.txt @@ -18,6 +18,9 @@ if (WIN32) ) set(LIB_DXCOMPILER "dxcompiler.dll") +elseif(APPLE) + + set(LIB_DXCOMPILER "dxcompiler.dylib") else() list (APPEND SOURCE_FILES main_SDL2.cpp diff --git a/WickedEngine/CMakeLists.txt b/WickedEngine/CMakeLists.txt index dbc09a68df..c902226027 100644 --- a/WickedEngine/CMakeLists.txt +++ b/WickedEngine/CMakeLists.txt @@ -6,21 +6,36 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.31) endif() set(MIN_OpenImageDenoise_VERSION "2.0") +option(CPU_IS_X86_ARCH "Whether the CPU architecture is (a subset of) x86, implying potential instructions are supported" OFF) include(CMakePackageConfigHelpers) include(GNUInstallDirs) set(INSTALL_LOCAL_CONFIGDIR "${CMAKE_BINARY_DIR}/cmake") set(INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/WickedEngine") +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + if ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86" OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + set(CPU_IS_X86_ARCH ON) + else() + set(CPU_IS_X86_ARCH OFF) + endif() +elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") + set(CPU_IS_X86_ARCH ON) +else() + set(CPU_IS_X86_ARCH OFF) +endif() + # 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" OFF) -option(USE_AVX512 "Enable AVX512" OFF) -option(USE_LZCNT "Enable LZCNT" ON) -option(USE_TZCNT "Enable TZCNT" ON) +if (CPU_IS_X86_ARCH) + 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" OFF) + option(USE_AVX512 "Enable AVX512" OFF) + option(USE_LZCNT "Enable LZCNT" ON) + option(USE_TZCNT "Enable TZCNT" ON) +endif() option(USE_F16C "Enable F16C" ON) option(USE_FMADD "Enable FMADD" ON) @@ -38,6 +53,15 @@ if (WIN32) /bigobj ) endif() +elseif (APPLE) + # find_package(Metal ) + find_package(OpenImageDenoise "${MIN_OpenImageDenoise_VERSION}" QUIET) + find_package(Threads REQUIRED) + if(NOT ${OpenImageDenoise_FOUND}) + message("OpenImageDenoise>=${MIN_OpenImageDenoise_VERSION} not found, it will be disabled.") + else() + message("OpenImageDenoise ${OpenImageDenoise_VERSION} Found.") + endif() else () find_package(SDL2 REQUIRED) find_package(OpenImageDenoise "${MIN_OpenImageDenoise_VERSION}" QUIET) @@ -89,7 +113,18 @@ list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/offlineshadercompiler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wiRenderer.cpp ) - +if (APPLE) + list(APPEND SOURCE_FILES + wiInput_Apple.mm + wiAppleHelper.mm + ) + set_source_files_properties( + wiInput_Apple.mm + wiAppleHelper.mm + PROPERTIES + SKIP_PRECOMPILE_HEADERS ON + ) +endif() file(GLOB SHADER_FILES CONFIGURE_DEPENDS shaders/*.hlsl shaders/*.hlsli) # these are all Wicked files except wiRenderer.cpp, which can be compiled @@ -132,6 +167,8 @@ add_library(WickedEngine ALIAS ${TARGET_NAME}) # aliases for backwards compatibility if(WIN32) add_library(WickedEngine_Windows ALIAS ${TARGET_NAME}) +elseif(APPLE) + # Not used else() add_library(WickedEngine_Linux ALIAS ${TARGET_NAME}) endif() @@ -172,60 +209,75 @@ set(WICKEDENGINE_STATIC_LIBRARIES Utility ) -if (USE_AVX512 OR USE_AVX2) - target_compile_definitions(WickedEngine_common PUBLIC _XM_AVX2_INTRINSICS_) -endif() -if (USE_AVX) - target_compile_definitions(WickedEngine_common PUBLIC _XM_AVX_INTRINSICS_) -endif() -if (USE_SSE4_1 OR USE_SSE4_2) - target_compile_definitions(WickedEngine_common PUBLIC _XM_SSE4_INTRINSICS_) -endif() -if (USE_F16C) - target_compile_definitions(WickedEngine_common PUBLIC _XM_F16C_INTRINSICS_) -endif() -if (USE_FMADD) - target_compile_definitions(WickedEngine_common PUBLIC _XM_FMA3_INTRINSICS_) -endif() -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(WickedEngine_common PUBLIC /arch:AVX512) - elseif (USE_AVX2) - target_compile_options(WickedEngine_common PUBLIC /arch:AVX2) - elseif (USE_AVX) - target_compile_options(WickedEngine_common PUBLIC /arch:AVX) - endif() - endif() -elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i386") - if (USE_AVX512) - target_compile_options(WickedEngine_common PUBLIC -mavx512f -mavx512vl -mavx512dq -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) - elseif (USE_AVX2) - target_compile_options(WickedEngine_common PUBLIC -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) - elseif (USE_AVX) - target_compile_options(WickedEngine_common PUBLIC -mavx -mpopcnt) - elseif (USE_SSE4_2) - target_compile_options(WickedEngine_common PUBLIC -msse4.2 -mpopcnt) - elseif (USE_SSE4_1) - target_compile_options(WickedEngine_common PUBLIC -msse4.1) - else() - target_compile_options(WickedEngine_common PUBLIC -msse2) +if (CPU_IS_X86_ARCH) + # DirectXMath only supports these intrinsics for x86. + if (USE_AVX512 OR USE_AVX2) + target_compile_definitions(WickedEngine_common PUBLIC _XM_AVX2_INTRINSICS_) endif() - if (USE_LZCNT) - target_compile_options(WickedEngine_common PUBLIC -mlzcnt) + if (USE_AVX) + target_compile_definitions(WickedEngine_common PUBLIC _XM_AVX_INTRINSICS_) endif() - if (USE_TZCNT) - target_compile_options(WickedEngine_common PUBLIC -mbmi) + if (USE_SSE4_1 OR USE_SSE4_2) + target_compile_definitions(WickedEngine_common PUBLIC _XM_SSE4_INTRINSICS_) endif() if (USE_F16C) - target_compile_options(WickedEngine_common PUBLIC -mf16c) + target_compile_definitions(WickedEngine_common PUBLIC _XM_F16C_INTRINSICS_) endif() if (USE_FMADD) - target_compile_options(WickedEngine_common PUBLIC -mfma) + target_compile_definitions(WickedEngine_common PUBLIC _XM_FMA3_INTRINSICS_) endif() +endif() - target_compile_options(WickedEngine_common PUBLIC -mfpmath=sse) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + if (CPU_IS_X86_ARCH) + if ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x86" OR "${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + if (USE_AVX512) + target_compile_options(WickedEngine_common PUBLIC /arch:AVX512) + elseif (USE_AVX2) + target_compile_options(WickedEngine_common PUBLIC /arch:AVX2) + elseif (USE_AVX) + target_compile_options(WickedEngine_common PUBLIC /arch:AVX) + endif() + endif() + endif() +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + if (CPU_IS_X86_ARCH) + if (USE_AVX512) + target_compile_options(WickedEngine_common PUBLIC -mavx512f -mavx512vl -mavx512dq -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) + elseif (USE_AVX2) + target_compile_options(WickedEngine_common PUBLIC -mavx2 -mbmi -mpopcnt -mlzcnt -mf16c) + elseif (USE_AVX) + target_compile_options(WickedEngine_common PUBLIC -mavx -mpopcnt) + elseif (USE_SSE4_2) + target_compile_options(WickedEngine_common PUBLIC -msse4.2 -mpopcnt) + elseif (USE_SSE4_1) + target_compile_options(WickedEngine_common PUBLIC -msse4.1) + else() + target_compile_options(WickedEngine_common PUBLIC -msse2) + endif() + if (USE_LZCNT) + target_compile_options(WickedEngine_common PUBLIC -mlzcnt) + endif() + if (USE_TZCNT) + target_compile_options(WickedEngine_common PUBLIC -mbmi) + endif() + target_compile_options(WickedEngine_common PUBLIC -mfpmath=sse) + if (USE_F16C) + target_compile_options(WickedEngine_common PUBLIC -mf16c) + message(STATUS "F16C enabled, half-precision floating point support will be available") + else() + message(STATUS "F16C disabled, half-precision floating point support will not be available") + endif() + if (USE_FMADD) + target_compile_options(WickedEngine_common PUBLIC -mfma) + message(STATUS "FMADD enabled, fused multiply-add support will be available") + else() + message(STATUS "FMADD disabled, fused multiply-add support will not be available") + endif() + endif() +else() + message(WARNING "Unknown compiler, no architecture-specific optimizations will be enabled '${CMAKE_CXX_COMPILER_ID}'") endif() target_compile_definitions(WickedEngine_common PUBLIC WICKED_CMAKE_BUILD) @@ -237,6 +289,30 @@ if (WIN32) ) set(LIBDXCOMPILER "dxcompiler.dll") +elseif (APPLE) + target_compile_definitions(WickedEngine_common PUBLIC WI_UNORDERED_MAP_TYPE=2) + + find_library(COREFOUNDATION_FRAMEWORK CoreFoundation REQUIRED) + find_library(APPLICATIONSERVICES_FRAMEWORK ApplicationServices REQUIRED) + find_library(APPKIT_FRAMEWORK AppKit REQUIRED) + find_library(METAL_FRAMEWORK Metal REQUIRED) + find_library(QUARTZCORE_FRAMEWORK QuartzCore REQUIRED) + find_library(GAMECONTROLLER_FRAMEWORK GameController REQUIRED) + + target_link_libraries(WickedEngine_common PUBLIC + Threads::Threads + $<$:OpenImageDenoise> # links OpenImageDenoise only if it's found + ${COREFOUNDATION_FRAMEWORK} + ${APPLICATIONSERVICES_FRAMEWORK} + ${APPKIT_FRAMEWORK} + ${METAL_FRAMEWORK} + ${QUARTZCORE_FRAMEWORK} + ${GAMECONTROLLER_FRAMEWORK} + ) + + target_link_libraries(WickedEngine_common PUBLIC dl) + + set(LIBDXCOMPILER "libdxcompiler.dylib") else () # `ska::flat_hash_map` has issues on linux because of the hash function being identity # in same cases. Use `robin_hood::unordered_flat_map` instead @@ -358,11 +434,11 @@ export(EXPORT Engine-Targets FILE "${CMAKE_BINARY_DIR}/cmake/WickedEngineTargets.cmake" NAMESPACE WickedEngine:: ) - -install(EXPORT Engine-Targets - FILE WickedEngineTargets.cmake - NAMESPACE WickedEngine:: - DESTINATION ${INSTALL_CONFIGDIR}) +# I don't quite get why, but this conflicts with specifying the include dirs in Editor +# install(EXPORT Engine-Targets +# FILE WickedEngineTargets.cmake +# NAMESPACE WickedEngine:: +# DESTINATION ${INSTALL_CONFIGDIR}) set(_CONFIG_INSTALL_DIR_INCLUDE "${WICKED_ROOT_DIR}") set(_CONFIG_INSTALL_DIR_LIB "${WICKED_ROOT_DIR}") @@ -383,7 +459,7 @@ install(FILES ${CMAKE_BINARY_DIR}/cmake/install/WickedEngineConfig.cmake DESTINATION ${INSTALL_CONFIGDIR} ) -# Shaders +# # Shaders install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/shaders DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/WickedEngine" PATTERN "spirv" EXCLUDE diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index a757a75fb6..680d665b50 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -422,7 +422,7 @@ constexpr const char* relative_path(const char* path) constexpr auto relative_path_storage(const char* path) { - StackString ret; + StackString<> ret; ret.push_back(relative_path(path)); return ret; } @@ -430,7 +430,7 @@ constexpr auto relative_path_storage(const char* path) // Extract function name from a string at compile-time constexpr auto extract_function_name(const char* str) { - StackString ret; + StackString<> ret; ret.push_back(str); return ret; } diff --git a/WickedEngine/wiGraphics.h b/WickedEngine/wiGraphics.h index 60e463ada9..ee94534bdd 100644 --- a/WickedEngine/wiGraphics.h +++ b/WickedEngine/wiGraphics.h @@ -132,7 +132,7 @@ namespace wi::graphics INV_SRC1_COLOR, SRC1_ALPHA, INV_SRC1_ALPHA, - }; + }; enum class BlendOp : uint8_t { ADD, @@ -257,7 +257,7 @@ namespace wi::graphics D32_FLOAT, // depth (32-bit) | SRV: R32_FLOAT R32_FLOAT, R32_UINT, - R32_SINT, + R32_SINT, D24_UNORM_S8_UINT, // depth (24-bit) + stencil (8-bit) | SRV: R24_INTERNAL (default or depth aspect), R8_UINT (stencil aspect) R9G9B9E5_SHAREDEXP, @@ -457,7 +457,7 @@ namespace wi::graphics VIDEO_DECODE_H265 = 1 << 21, R9G9B9E5_SHAREDEXP_RENDERABLE = 1 << 22, // indicates supporting R9G9B9E5_SHAREDEXP format for rendering to COPY_BETWEEN_DIFFERENT_IMAGE_ASPECTS_NOT_SUPPORTED = 1 << 23, // indicates that CopyTexture src and dst ImageAspect must match - + // Compat: GENERIC_SPARSE_TILE_POOL = ALIASING_GENERIC, }; @@ -1350,6 +1350,10 @@ namespace wi::graphics { return (pso == other.pso) && (renderpass_hash == other.renderpass_hash); } + constexpr bool operator!=(const PipelineHash& other) const + { + return !(*this == other); + } constexpr uint64_t get_hash() const { union diff --git a/WickedEngine/wiGraphicsDevice_Metal.cpp b/WickedEngine/wiGraphicsDevice_Metal.cpp index fa6231322b..856765724a 100644 --- a/WickedEngine/wiGraphicsDevice_Metal.cpp +++ b/WickedEngine/wiGraphicsDevice_Metal.cpp @@ -8,7 +8,7 @@ #include "wiTimer.h" #include "wiBacklog.h" -#include +#include namespace wi::graphics { diff --git a/WickedEngine/wiGraphicsDevice_Metal.h b/WickedEngine/wiGraphicsDevice_Metal.h index aeba6174d3..5a2bb28d30 100644 --- a/WickedEngine/wiGraphicsDevice_Metal.h +++ b/WickedEngine/wiGraphicsDevice_Metal.h @@ -6,11 +6,11 @@ #include "wiGraphicsDevice.h" #include "wiUnorderedMap.h" -#include -#include +#include +#include #define IR_RUNTIME_METALCPP -#include +#include #include #include diff --git a/WickedEngine/wiInput.cpp b/WickedEngine/wiInput.cpp index 3334915483..8510dbd32b 100644 --- a/WickedEngine/wiInput.cpp +++ b/WickedEngine/wiInput.cpp @@ -116,7 +116,7 @@ namespace wi::input const KeyboardState& GetKeyboardState() { return keyboard; } const MouseState& GetMouseState() { return mouse; } - struct Input + struct Input { BUTTON button = BUTTON_NONE; int playerIndex = 0; @@ -161,7 +161,7 @@ namespace wi::input #ifdef PLATFORM_PS5 wi::input::ps5::Initialize(); #endif // PLATFORM_PS5 - + #ifdef __APPLE__ wi::input::apple::Initialize(); wi::apple::CursorInit(cursor_table_original); @@ -197,7 +197,7 @@ namespace wi::input #if defined(_WIN32) && !defined(PLATFORM_XBOX) wi::input::rawinput::GetMouseState(&mouse); // currently only the relative data can be used from this - wi::input::rawinput::GetKeyboardState(&keyboard); + wi::input::rawinput::GetKeyboardState(&keyboard); // apparently checking the mouse here instead of Down() avoids missing the button presses (review!) mouse.left_button_press |= KEY_DOWN(VK_LBUTTON); @@ -220,14 +220,14 @@ namespace wi::input wi::input::sdlinput::GetMouseState(&mouse); wi::input::sdlinput::GetKeyboardState(&keyboard); #endif - + for (auto& x : mouse_move_events) { mouse.delta_position.x += x.x; mouse.delta_position.y += x.y; } mouse_move_events.clear(); - + for (auto& x : mouse_scroll_events) { mouse.delta_wheel += x; @@ -491,7 +491,7 @@ namespace wi::input cursor_next = CURSOR_DEFAULT; } auto cursorhandle = cursor_table[cursor_next] ? cursor_table[cursor_next] : cursor_table[CURSOR_DEFAULT]; - + #ifdef PLATFORM_WINDOWS_DESKTOP ::SetCursor(cursorhandle); #elif defined(__APPLE__) @@ -577,15 +577,15 @@ namespace wi::input switch (button) { case wi::input::MOUSE_BUTTON_LEFT: - if (mouse.left_button_press) + if (mouse.left_button_press) return true; return false; case wi::input::MOUSE_BUTTON_RIGHT: - if (mouse.right_button_press) + if (mouse.right_button_press) return true; return false; case wi::input::MOUSE_BUTTON_MIDDLE: - if (mouse.middle_button_press) + if (mouse.middle_button_press) return true; return false; #ifdef _WIN32 @@ -610,7 +610,7 @@ namespace wi::input case wi::input::KEYBOARD_BUTTON_LSHIFT: keycode = VK_LSHIFT; break; - case wi::input::KEYBOARD_BUTTON_F1: + case wi::input::KEYBOARD_BUTTON_F1: keycode = VK_F1; break; case wi::input::KEYBOARD_BUTTON_F2: @@ -737,8 +737,10 @@ namespace wi::input keycode = VK_RMENU; break; #endif // _WIN32 - + #ifdef __APPLE__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch" case wi::input::KEYBOARD_BUTTON_UP: keycode = kVK_UpArrow; break; @@ -970,39 +972,40 @@ namespace wi::input case (BUTTON)'Z': keycode = kVK_ANSI_Z; break; - case (BUTTON)'0': - keycode = kVK_ANSI_0; - break; - case (BUTTON)'1': - keycode = kVK_ANSI_1; - break; - case (BUTTON)'2': - keycode = kVK_ANSI_2; - break; - case (BUTTON)'3': - keycode = kVK_ANSI_3; - break; - case (BUTTON)'4': - keycode = kVK_ANSI_4; - break; - case (BUTTON)'5': - keycode = kVK_ANSI_5; - break; - case (BUTTON)'6': - keycode = kVK_ANSI_6; - break; - case (BUTTON)'7': - keycode = kVK_ANSI_7; - break; - case (BUTTON)'8': - keycode = kVK_ANSI_8; - break; - case (BUTTON)'9': - keycode = kVK_ANSI_9; - break; + case (BUTTON)'0': + keycode = kVK_ANSI_0; + break; + case (BUTTON)'1': + keycode = kVK_ANSI_1; + break; + case (BUTTON)'2': + keycode = kVK_ANSI_2; + break; + case (BUTTON)'3': + keycode = kVK_ANSI_3; + break; + case (BUTTON)'4': + keycode = kVK_ANSI_4; + break; + case (BUTTON)'5': + keycode = kVK_ANSI_5; + break; + case (BUTTON)'6': + keycode = kVK_ANSI_6; + break; + case (BUTTON)'7': + keycode = kVK_ANSI_7; + break; + case (BUTTON)'8': + keycode = kVK_ANSI_8; + break; + case (BUTTON)'9': + keycode = kVK_ANSI_9; + break; +#pragma clang diagnostic pop #endif // __APPLE__ - - + + default: break; } #if defined(_WIN32) && !defined(PLATFORM_XBOX) @@ -1211,7 +1214,7 @@ namespace wi::input wi::helper::StringConvert(filename, wfilename, arraysize(wfilename)); cursor_table[cursor] = LoadCursorFromFile(wfilename); #endif // PLATFORM_WINDOWS_DESKTOP - + #if defined(SDL2) || defined(PLATFORM_MACOS) // On other platforms, extract the raw color data from win32 .CUR file and create cursor from that: wi::vector data; @@ -1219,15 +1222,15 @@ namespace wi::input { // Extract only the first image data: ico::ICONDIRENTRY* icondirentry = (ico::ICONDIRENTRY*)(data.data() + sizeof(ico::ICONDIR)); - + int hotspotX = icondirentry->wPlanes; int hotspotY = icondirentry->wBitCount; - + uint8_t* pixeldata = (data.data() + icondirentry->dwImageOffset + sizeof(ico::BITMAPINFOHEADER)); - + const uint32_t width = icondirentry->bWidth; const uint32_t height = icondirentry->bHeight; - + // Convert BGRA to ARGB and flip vertically wi::vector colors; colors.reserve(width * height); @@ -1240,7 +1243,7 @@ namespace wi::input src += 4; } } - + #ifdef SDL2 SDL_Surface* surface = SDL_CreateRGBSurfaceFrom( colors.data(), @@ -1253,7 +1256,7 @@ namespace wi::input 0xff000000, 0x000000ff ); - + if (surface != nullptr) { cursor_table[cursor] = SDL_CreateColorCursor(surface, hotspotX, hotspotY); @@ -1264,7 +1267,7 @@ namespace wi::input #endif // SDL2 } #endif // defined(SDL2) || defined(PLATFORM_MACOS) - + // refresh in case we set the current one: cursor_next = cursor_current; cursor_current = CURSOR_COUNT; diff --git a/WickedEngine/wiShaderCompiler.cpp b/WickedEngine/wiShaderCompiler.cpp index 15c4cbfba3..17619ad063 100644 --- a/WickedEngine/wiShaderCompiler.cpp +++ b/WickedEngine/wiShaderCompiler.cpp @@ -44,7 +44,7 @@ using namespace Microsoft::WRL; #ifdef PLATFORM_APPLE #define SHADERCOMPILER_APPLE_INCLUDED -#include +#include #include "wiGraphicsDevice_Metal.h" #endif // PLATFORM_APPLE @@ -691,9 +691,11 @@ namespace wi::shadercompiler static const IRVersionedRootSignatureDescriptor desc = { .version = IRRootSignatureVersion_1_1, - .desc_1_1.Flags = IRRootSignatureFlags(IRRootSignatureFlagAllowInputAssemblerInputLayout | IRRootSignatureFlagCBVSRVUAVHeapDirectlyIndexed | IRRootSignatureFlagSamplerHeapDirectlyIndexed), - .desc_1_1.NumParameters = arraysize(root_parameters), - .desc_1_1.pParameters = root_parameters, + .desc_1_1 = { + .Flags = IRRootSignatureFlags(IRRootSignatureFlagAllowInputAssemblerInputLayout | IRRootSignatureFlagCBVSRVUAVHeapDirectlyIndexed | IRRootSignatureFlagSamplerHeapDirectlyIndexed), + .NumParameters = arraysize(root_parameters), + .pParameters = root_parameters, + }, //.desc_1_1.NumStaticSamplers = arraysize(static_samplers), //.desc_1_1.pStaticSamplers = static_samplers, }; diff --git a/build_macos.sh b/build_macos.sh new file mode 100644 index 0000000000..e06b20bd38 --- /dev/null +++ b/build_macos.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh +set -e + +CURRENT_DIR="$(dirname $0)" + +# brew install open-image-denoise +# brew install lld + + +cmake -B"${CURRENT_DIR}/build" -GNinja "$CURRENT_DIR" \ +-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ +-DCMAKE_BUILD_TYPE=RelWithDebInfo \ +-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \ +-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \ + +# example: --target Editor --target WickedEngine_ext_shaders +cmake --build "${CURRENT_DIR}/build" "$@"