diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 06b25113ba..1e7f7e318c 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -29,8 +29,10 @@ add_subdirectory(freetype2 freetype2 EXCLUDE_FROM_ALL) add_library(Freetype::Freetype ALIAS freetype) # alias target for MSDFGEN not trying to find freetype system-wide but rather to use the logical target available in our build tree # msdfgen + +set(MSDFGEN_USE_SKIA OFF) set(MSDFGEN_USE_VCPKG OFF) -set(MSDFGEN_CORE_ONLY OFF) # if turned on then MSDFGEN will be built without dependencies like freetype or skia +set(MSDFGEN_CORE_ONLY OFF) set(MSDFGEN_INSTALL OFF) set(MSDFGEN_BUILD_STANDALONE OFF) set(MSDFGEN_USE_CPP11 ON) @@ -76,7 +78,7 @@ add_subdirectory(volk volk EXCLUDE_FROM_ALL) target_include_directories(volk PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include") target_include_directories(volk_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include") -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") add_subdirectory(pstl pstl EXCLUDE_FROM_ALL) endif() @@ -100,11 +102,16 @@ file(LOCK "${CMAKE_CURRENT_SOURCE_DIR}/zlib" DIRECTORY RELEASE RESULT_VARIABLE N set(SKIP_INSTALL_ALL ${_OLD_SKIP_INSTALL_ALL}) set(BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS}) +if(APPLE) + target_compile_options(zlibstatic PUBLIC "-includeunistd.h") +endif() + get_target_property(ZLIB_SOURCE_DIR zlibstatic "SOURCE_DIR") get_target_property(ZLIB_BINARY_DIR zlibstatic "BINARY_DIR") get_filename_component(_ORIGINAL_SOURCE_ "${ZLIB_SOURCE_DIR}" ABSOLUTE) get_filename_component(_COPY_BIN_SOURCE_ "${ZLIB_BINARY_DIR}/copy_source" ABSOLUTE) +# TODO: add coresponding custom command and mark proper dependencies [zlib_copy] add_custom_target(zlib_copy COMMAND ${CMAKE_COMMAND} -E rm -Rf "${_COPY_BIN_SOURCE_}" COMMAND ${CMAKE_COMMAND} -E copy_directory "${_ORIGINAL_SOURCE_}" "${_COPY_BIN_SOURCE_}" @@ -331,6 +338,31 @@ add_library(aesGladman OBJECT aesGladman/sha1.c ) +# MacOS patches +if(APPLE) + set(_NBL_MACOS_PATCH_INCLUDE_ "${CMAKE_CURRENT_BINARY_DIR}/macos/include" CACHE INTERNAL "") + + set(_NBL_MACOS_BYTESWAP_H_ +"#if defined(__APPLE__)\n\ +// Mac OS X / Darwin features\n\ +#include \n\n\ +#define bswap_16(x) OSSwapInt16(x)\n\ +#define bswap_32(x) OSSwapInt32(x)\n\ +#define bswap_64(x) OSSwapInt64(x)\n\ +#endif // __APPLE__" + ) + + set(_NBL_MACOS_ENDIAN_H_ +"#if defined(__APPLE__)\n\ +#include \n\ +#endif // __APPLE__" + ) + + file(WRITE "${_NBL_MACOS_PATCH_INCLUDE_}/byteswap.h" "${_NBL_MACOS_BYTESWAP_H_}") + file(WRITE "${_NBL_MACOS_PATCH_INCLUDE_}/endian.h" "${_NBL_MACOS_ENDIAN_H_}") + + include_directories(BEFORE SYSTEM "${_NBL_MACOS_PATCH_INCLUDE_}") +endif() add_subdirectory(argparse argparse EXCLUDE_FROM_ALL) option(GLM_TEST_ENABLE_SIMD_SSE4_2 "Enable SSE 4.2 optimizations" ON) diff --git a/3rdparty/dxc/CMakeLists.txt b/3rdparty/dxc/CMakeLists.txt index d17b2d8908..e215a7e9ba 100644 --- a/3rdparty/dxc/CMakeLists.txt +++ b/3rdparty/dxc/CMakeLists.txt @@ -115,6 +115,9 @@ else() endif() endif() +# this whole shit needs to be changed, +# leaving it till we get to relocatable packages + set(DXC_INCLUDE_DIRECTORIES $,${NBL_DXC_DEBUG_INCLUDE_DIRECTORIES},${NBL_DXC_RELEASE_INCLUDE_DIRECTORIES}> CACHE INTERNAL "" FORCE) @@ -142,14 +145,6 @@ set(DXC_DLL_NAME $,${_NBL_DXC_DEBUG_DLL_NAME_},${_NBL_DXC_RELEASE_DLL_NAME_}> CACHE INTERNAL "" FORCE) -set(DXC_COMPILE_FLAGS_RELEASE "") -set(DXC_COMPILE_FLAGS_RWDI "") -set(DXC_COMPILE_FLAGS_DEBUG "") - -set(DXC_COMPILE_FLAGS - $<$:${DXC_COMPILE_FLAGS_RELEASE}>$<$:${DXC_COMPILE_FLAGS_DEBUG}>$<$:${DXC_COMPILE_FLAGS_RWDI}> -CACHE INTERNAL "" FORCE) - get_filename_component(_SPIRV_BR_BUNDLE_SEARCH_DIRECTORY_ "${DXC_SPIRV_HEADERS_DIR}/include" ABSOLUTE) get_filename_component(_SPIRV_BR_OUTPUT_DIRECTORY_SOURCE_ "${CMAKE_CURRENT_BINARY_DIR}/src" ABSOLUTE) get_filename_component(_SPIRV_BR_OUTPUT_DIRECTORY_HEADER_ "${CMAKE_CURRENT_BINARY_DIR}/include" ABSOLUTE) diff --git a/3rdparty/pstl/.DS_Store b/3rdparty/pstl/.DS_Store new file mode 100644 index 0000000000..82ad257caf Binary files /dev/null and b/3rdparty/pstl/.DS_Store differ diff --git a/3rdparty/pstl/CMakeLists.txt b/3rdparty/pstl/CMakeLists.txt index 27ecb83ee4..dfd363a22f 100644 --- a/3rdparty/pstl/CMakeLists.txt +++ b/3rdparty/pstl/CMakeLists.txt @@ -1,59 +1,67 @@ -if(NBL_BUILD_DPL AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # only non-multi-generators and clang ifsupported - get_filename_component(CCBD_ABSOLUTE "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE) - - if (NBL_BUILD_DPL) - set(_NBL_BUILD_DPL_ ${NBL_BUILD_DPL}) - endif() - - set(TBB_INSTALL_VARS ON CACHE BOOL "" FORCE) - set(TBB_TEST OFF CACHE BOOL "" FORCE) - set(TBB_STRICT ON CACHE BOOL "" FORCE) - set(PREVIOUS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) - set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) - set(TBB_SANITIZE "" CACHE STRING "" FORCE) - add_subdirectory(oneTBB oneTBB EXCLUDE_FROM_ALL) - - if(PREVIOUS_BUILD_SHARED_LIBS) - set(BUILD_SHARED_LIBS ${PREVIOUS_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) - else() - unset(BUILD_SHARED_LIBS CACHE) - endif() - - set(ONETBB_BUILD ${CCBD_ABSOLUTE}/oneTBB) - set(ONETBB_INSTALL_DIR ${ONETBB_BUILD}/install CACHE STRING "oneTBB install directory" FORCE) - - add_custom_target(onetbb_build - COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component devel -v --config $ --prefix ${ONETBB_INSTALL_DIR} - COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component runtime -v --config $ --prefix ${ONETBB_INSTALL_DIR} - DEPENDS tbb tbbmalloc tbbmalloc_proxy - COMMENT "Building oneTBB..." - ) - - set(ONEDPL_BUILD ${CCBD_ABSOLUTE}/oneDPL/build) - set(ONEDPL_INSTALL_DIR ${ONEDPL_BUILD}/install CACHE STRING "oneDPL install directory" FORCE) - - set(CMAKE_ARGS_ONEDPL - -DCMAKE_BUILD_TYPE:STRING=$ - -DONETBB_INSTALL_DIR:PATH=${ONETBB_INSTALL_DIR} +get_filename_component(CCBD_ABSOLUTE "${CMAKE_CURRENT_BINARY_DIR}" ABSOLUTE) + +set(_NBL_BUILD_DPL_ ON CACHE BOOL "") + +set(TBB_INSTALL_VARS ON CACHE BOOL "" FORCE) +set(TBB_TEST OFF CACHE BOOL "" FORCE) +set(TBB_STRICT ON CACHE BOOL "" FORCE) +set(PREVIOUS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) +set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) +set(TBB_SANITIZE "" CACHE STRING "" FORCE) + +add_subdirectory(oneTBB oneTBB EXCLUDE_FROM_ALL) +target_compile_options(tbb PUBLIC + -Wno-conversion +) + +if(PREVIOUS_BUILD_SHARED_LIBS) + set(BUILD_SHARED_LIBS ${PREVIOUS_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) +else() + unset(BUILD_SHARED_LIBS CACHE) +endif() + +set(ONETBB_BUILD ${CCBD_ABSOLUTE}/oneTBB) +set(ONETBB_INSTALL_DIR ${ONETBB_BUILD}/install CACHE STRING "oneTBB install directory" FORCE) + +add_custom_target(onetbb_build + COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component devel -v --config $ --prefix ${ONETBB_INSTALL_DIR} + COMMAND ${CMAKE_COMMAND} --install ${ONETBB_BUILD} --component runtime -v --config $ --prefix ${ONETBB_INSTALL_DIR} + COMMENT "Building oneTBB..." +) +add_dependencies(onetbb_build tbb tbbmalloc) + +if(NOT (APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")) + add_dependencies(onetbb_build tbbmalloc_proxy) +endif() + +set(ONEDPL_BUILD ${CCBD_ABSOLUTE}/oneDPL/build) +set(ONEDPL_INSTALL_DIR ${ONEDPL_BUILD}/install CACHE STRING "oneDPL install directory" FORCE) + +set(CMAKE_ARGS_ONEDPL + -DCMAKE_BUILD_TYPE:STRING=$ + -DONETBB_INSTALL_DIR:PATH=${ONETBB_INSTALL_DIR} +) + +if(ANDROID) + list(APPEND CMAKE_ARGS_ONEDPL + -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE} + -DANDROID_ABI:STRING=${ANDROID_ABI} + -DANDROID_PLATFORM:STRING=${ANDROID_PLATFORM} ) - - if(ANDROID) - list(APPEND CMAKE_ARGS_ONEDPL - -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE} - -DANDROID_ABI:STRING=${ANDROID_ABI} - -DANDROID_PLATFORM:STRING=${ANDROID_PLATFORM} - ) - endif() - - ExternalProject_Add(oneDPL - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/oneDPL - BINARY_DIR ${ONEDPL_BUILD} - CMAKE_ARGS ${CMAKE_ARGS_ONEDPL} - BUILD_COMMAND cmake --build ${ONEDPL_BUILD} - INSTALL_COMMAND cmake --install ${ONEDPL_BUILD} --prefix ${ONEDPL_INSTALL_DIR} - USES_TERMINAL_BUILD 1 - COMMENT "Building oneDPL..." +elseif(APPLE) + list(APPEND CMAKE_ARGS_ONEDPL + "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}" ) - - add_dependencies(oneDPL onetbb_build) -endif() \ No newline at end of file +endif() + +ExternalProject_Add(oneDPL + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/oneDPL + BINARY_DIR ${ONEDPL_BUILD} + CMAKE_ARGS ${CMAKE_ARGS_ONEDPL} + BUILD_COMMAND cmake --build ${ONEDPL_BUILD} --config $ + INSTALL_COMMAND cmake --install ${ONEDPL_BUILD} --config $ -v --prefix ${ONEDPL_INSTALL_DIR} + USES_TERMINAL_BUILD 1 + COMMENT "Building oneDPL..." +) + +add_dependencies(oneDPL onetbb_build) diff --git a/3rdparty/pstl/oneDPL/CMakeLists.txt b/3rdparty/pstl/oneDPL/CMakeLists.txt index 27c4f7850f..614c885c53 100644 --- a/3rdparty/pstl/oneDPL/CMakeLists.txt +++ b/3rdparty/pstl/oneDPL/CMakeLists.txt @@ -1,18 +1,35 @@ -cmake_minimum_required(VERSION 3.20) -include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/toolchains/android/build.cmake) +cmake_minimum_required(VERSION 3.26) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - if(NOT DEFINED ONETBB_INSTALL_DIR) - message(FATAL_ERROR "oneDPL submodule requires valid ONETBB_INSTALL_DIR!") - endif() - - set(TBB_DIR ${ONETBB_INSTALL_DIR}/lib/cmake/TBB CACHE INTERNAL "" FORCE) - set(ONEDPL_BACKEND tbb CACHE STRING "" FORCE) - add_subdirectory(oneDPL oneDPL) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) - if(ANDROID) - add_compile_options( - $<$:-glldb> - ) - endif() -endif() \ No newline at end of file +# assume built-in pthreads on MacOS +if(APPLE) + set(CMAKE_THREAD_LIBS_INIT "-lpthread") + set(CMAKE_HAVE_THREADS_LIBRARY 1) + set(CMAKE_USE_WIN32_THREADS_INIT 0) + set(CMAKE_USE_PTHREADS_INIT 1) + set(THREADS_PREFER_PTHREAD_FLAG ON CACHE BOOL "") +endif() + +if(ANDROID) + include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/toolchains/android/build.cmake) +endif() + +if(NOT DEFINED ONETBB_INSTALL_DIR) + message(FATAL_ERROR "oneDPL submodule requires valid ONETBB_INSTALL_DIR!") +endif() + +set(TBB_DIR ${ONETBB_INSTALL_DIR}/lib/cmake/TBB CACHE INTERNAL "" FORCE) +set(ONEDPL_BACKEND tbb CACHE STRING "" FORCE) +set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH ON CACHE BOOL "") +set(ONE_DPL_INSTALL_OVERRIDE "${CMAKE_CURRENT_BINARY_DIR}/output" CACHE STRING "" FORCE) +find_package(Threads REQUIRED) + +add_subdirectory(oneDPL oneDPL) + +if(ANDROID) + add_compile_options( + $<$:-glldb> + ) +endif() diff --git a/3rdparty/pstl/oneDPL/oneDPL b/3rdparty/pstl/oneDPL/oneDPL index 0bd676a2e4..db48d5ed68 160000 --- a/3rdparty/pstl/oneDPL/oneDPL +++ b/3rdparty/pstl/oneDPL/oneDPL @@ -1 +1 @@ -Subproject commit 0bd676a2e45074c7d5c59242eb6c36bc76a52aa8 +Subproject commit db48d5ed68ced6ada4d0b3d34a387e678d71a1e3 diff --git a/3rdparty/zlib b/3rdparty/zlib index cacf7f1d4e..04f42ceca4 160000 --- a/3rdparty/zlib +++ b/3rdparty/zlib @@ -1 +1 @@ -Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f +Subproject commit 04f42ceca40f73e2978b50e93806c2a18c1281fc diff --git a/CMakeLists.txt b/CMakeLists.txt index 17a9008083..9e589d3a5d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,21 @@ # For conditions of distribution and use, see copyright notice in nabla.h.in or nabla.h cmake_minimum_required(VERSION 3.29) +cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0112 NEW) cmake_policy(SET CMP0141 NEW) # https://cmake.org/cmake/help/latest/policy/CMP0141.html#policy:CMP0141 cmake_policy(SET CMP0118 NEW) # https://cmake.org/cmake/help/latest/policy/CMP0118.html#policy:CMP0118 +if(APPLE) + set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "" FORCE) + + if("${CMAKE_GENERATOR}" STREQUAL "Xcode") + if(NOT "${CMAKE_GENERATOR_TOOLSET}" STREQUAL "buildsystem=1") + message("Nabla build isn't supported with new Xcode buildsystem, you must specify CMake generator toolset as '-T buildsystem=1' in order to use legacy Xcode build system") + endif() + endif() +endif() + set(NBL_BUILD_ANDROID OFF) include(ExternalProject) @@ -30,14 +41,13 @@ endif() if(NBL_STATIC_BUILD) message(STATUS "Static Nabla build enabled!") else() + # TODO: needs correcting those checks if(WIN32 AND MSVC) if(NBL_DYNAMIC_MSVC_RUNTIME) message(STATUS "Shared Nabla build enabled!") else() message(FATAL_ERROR "Turn NBL_DYNAMIC_MSVC_RUNTIME on! For dynamic Nabla builds dynamic MSVC runtime is mandatory!") endif() - else() - message(FATAL_ERROR "Nabla can't be built with shared libraries! Please make sure you are targetting Windows OS and MSVC compiler!") endif() endif() @@ -148,6 +158,8 @@ if(WIN32) set(_NBL_PLATFORM_WINDOWS_ 1) elseif(ANDROID) set(_NBL_PLATFORM_ANDROID_ 1) +elseif(APPLE) + set(_NBL_PLATFORM_MACOS_ 1) elseif(UNIX) set(_NBL_PLATFORM_LINUX_ 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") @@ -159,6 +171,9 @@ else() set(_NBL_SHARED_BUILD_ ON CACHE INTERNAL "") endif() +#uncomment in the future +#option(NBL_TARGET_ARCH_ARM "Build for ARM?" OFF) + option(NBL_BUILD_DPL "Enable DPL (Dynamic Parallelism Library)" OFF) option(NBL_PCH "Enable pre-compiled header" ON) option(NBL_FAST_MATH "Enable fast low-precision math" ON) diff --git a/CMakePresets.json b/CMakePresets.json index 04a6177b14..03e323ae2a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -152,11 +152,6 @@ "inherits": "user-configure-static-base", "cacheVariables": { "NBL_DYNAMIC_MSVC_RUNTIME": "OFF" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" } }, { @@ -165,11 +160,6 @@ "inherits": "user-configure-dynamic-base", "cacheVariables": { "NBL_DYNAMIC_MSVC_RUNTIME": "ON" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" } }, { @@ -178,7 +168,12 @@ "displayName": "[USER]: Static library target, Visual Studio 17 2022 generator, MSVC v143 toolset", "description": "Configure as static library with Visual Studio 17 2022 generator and MSVC v143 toolset", "generator": "Visual Studio 17 2022", - "toolset": "v143" + "toolset": "v143", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } }, { "name": "user-configure-dynamic-msvc", @@ -186,7 +181,12 @@ "displayName": "[USER]: Dynamic library target, Visual Studio 17 2022 generator, MSVC v143 toolset", "description": "Configure as dynamic library with Visual Studio 17 2022 generator and MSVC v143 toolset", "generator": "Visual Studio 17 2022", - "toolset": "v143" + "toolset": "v143", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } }, { "name": "user-configure-static-ninja-multi", diff --git a/cmake/adjust/flags.cmake b/cmake/adjust/flags.cmake index 731ecb21f0..df35f9a078 100644 --- a/cmake/adjust/flags.cmake +++ b/cmake/adjust/flags.cmake @@ -13,6 +13,8 @@ macro(_NBL_IMPL_GET_FLAGS_PROFILE_) include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/unix/gnu.cmake") elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/unix/clang.cmake") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + include("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/template/unix/apple-clang.cmake") else() message(WARNING "UNTESTED COMPILER DETECTED, EXPECT WRONG OPTIMIZATION FLAGS! SUBMIT ISSUE ON GITHUB https://github.com/Devsh-Graphics-Programming/Nabla/issues") endif() diff --git a/cmake/adjust/template/unix/apple-clang.cmake b/cmake/adjust/template/unix/apple-clang.cmake new file mode 100644 index 0000000000..41ec16125b --- /dev/null +++ b/cmake/adjust/template/unix/apple-clang.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/clang.cmake") \ No newline at end of file diff --git a/cmake/common.cmake b/cmake/common.cmake index d7d2322fcd..46defe6832 100755 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -435,8 +435,10 @@ function(nbl_install_program_spec _TRGT _RELATIVE_DESTINATION) install(PROGRAMS $ DESTINATION ${_DEST_GE_} CONFIGURATIONS ${_CONFIGURATION_} COMPONENT Runtimes) endforeach() - install(PROGRAMS $ DESTINATION debug/runtime/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT Runtimes) # TODO: write cmake script with GE to detect if target in configuration has PDB files generated then add install rule - + if(MSVC) + install(PROGRAMS $ DESTINATION debug/runtime/${_RELATIVE_DESTINATION} CONFIGURATIONS Debug COMPONENT Runtimes) # TODO: write cmake script with GE to detect if target in configuration has PDB files generated then add install rule + endif() + get_property(_DEFINED_PROPERTY_ TARGET ${_TRGT} PROPERTY NBL_PACKAGE_RUNTIME_DLL_DIR_PATH @@ -1057,7 +1059,7 @@ macro(nbl_android_create_apk _TARGET) set(NBL_APK_OBJ_DIR obj) set(NBL_APK_BIN_DIR bin) set(NBL_APK_ASSETS_DIR assets) - + if(EXISTS ${ASSET_SOURCE_DIR}) add_custom_command( OUTPUT ${APK_FILE} @@ -1281,4 +1283,4 @@ endmacro() macro(write_source_definitions NBL_FILE NBL_WRAPPER_CODE_TO_WRITE) file(WRITE "${NBL_FILE}" "${NBL_WRAPPER_CODE_TO_WRITE}") -endmacro() \ No newline at end of file +endmacro() diff --git a/cmake/submodules/update.cmake b/cmake/submodules/update.cmake index bafcc359ff..0377ab427d 100644 --- a/cmake/submodules/update.cmake +++ b/cmake/submodules/update.cmake @@ -2,7 +2,7 @@ include(ProcessorCount) find_package(Git REQUIRED) option(NBL_UPDATE_GIT_SUBMODULE "Turn this ON to let CMake update all public submodules for you" ON) -option(NBL_FORCE_ON_UPDATE_GIT_SUBMODULE "Submodules will be updated with --force flag if NBL_FORCE_UPDATE_GIT_SUBMODULE is turned ON, use with caution - if there are any uncommited files in submodules' working tree they will be removed!" OFF) +option(NBL_FORCE_ON_UPDATE_GIT_SUBMODULE "Submodules will be updated with --force flag if NBL_FORCE_UPDATE_GIT_SUBMODULE is turned ON + ALL SUBMODULES' CONTENT will be WIPED, use with caution - if there are any uncommited files in submodules' working tree they will be removed!" OFF) option(NBL_SYNC_ON_UPDATE_GIT_SUBMODULE "Sync initialized submodule paths if NBL_FORCE_UPDATE_GIT_SUBMODULE is turned ON, this is useful when any submodule remote path got modified and you want to apply this modification to your local repository. Turning NBL_FORCE_ON_UPDATE_GIT_SUBMODULE implies this option" OFF) option(NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE "Turn this ON to attempt to update private Nabla submodules" OFF) option(NBL_UPDATE_GIT_SUBMODULE_NO_SEPARATE_SHELL "Turn this ON to prevent CMake from executing git submodules update or sync in a separate shell - be aware that the interaction with shell will be impossible in case of paraphrase prompt request of your key!" ON) @@ -39,166 +39,112 @@ function(NBL_UPDATE_SUBMODULES) set(NBL_FORCE "") endif() - macro(NBL_WRAPPER_COMMAND_EXCLUSIVE GIT_RELATIVE_ENTRY GIT_SUBMODULE_PATH SHOULD_RECURSIVE EXCLUDE_SUBMODULE_PATHS) - set(EXCLUDE_SUBMODULE_PATHS ${EXCLUDE_SUBMODULE_PATHS}) - set(SHOULD_RECURSIVE ${SHOULD_RECURSIVE}) - - if("${EXCLUDE_SUBMODULE_PATHS}" STREQUAL "") + function(NBL_EXCLUSIVE_UPDATE_EXECUTE GIT_RELATIVE_ENTRY GIT_SUBMODULE_PATH SHOULD_RECURSIVE EXCLUDE_SUBMODULE_PATHS) + if(EXCLUDE_SUBMODULE_PATHS STREQUAL "") set(NBL_EXCLUDE "") else() foreach(EXCLUDE_SUBMODULE_PATH ${EXCLUDE_SUBMODULE_PATHS}) - string(APPEND NBL_EXCLUDE "-c submodule.\"${EXCLUDE_SUBMODULE_PATH}\".update=none ") + string(APPEND NBL_EXCLUDE "-c;submodule.\"${EXCLUDE_SUBMODULE_PATH}\".update=none;") endforeach() string(STRIP "${NBL_EXCLUDE}" NBL_EXCLUDE) endif() + list(APPEND NBL_COMMAND "${GIT_EXECUTABLE}" -C "${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}" ${NBL_EXCLUDE} submodule update --init -j ${_GIT_SUBMODULES_JOBS_AMOUNT_} ${NBL_FORCE}) + if(SHOULD_RECURSIVE) - set(_NBL_EXECUTE_COMMAND_ "\"${GIT_EXECUTABLE}\" -C \"${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}\" ${NBL_EXCLUDE} submodule update --init -j ${_GIT_SUBMODULES_JOBS_AMOUNT_} ${NBL_FORCE} --recursive ${NBL_SHALLOW} ${GIT_SUBMODULE_PATH}") - else() - set(_NBL_EXECUTE_COMMAND_ "\"${GIT_EXECUTABLE}\" -C \"${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}\" ${NBL_EXCLUDE} submodule update --init -j ${_GIT_SUBMODULES_JOBS_AMOUNT_} ${NBL_FORCE} ${NBL_SHALLOW} ${GIT_SUBMODULE_PATH}") + list(APPEND NBL_COMMAND --recursive) endif() - - string(APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "${_NBL_EXECUTE_COMMAND_}\n") - - unset(NBL_EXCLUDE) - endmacro() - - set(_NBL_UPDATE_SUBMODULES_CMD_NAME_ "nbl-update-submodules") - set(_NBL_UPDATE_SUBMODULES_CMD_FILE_ "${NBL_ROOT_PATH_BINARY}/${_NBL_UPDATE_SUBMODULES_CMD_NAME_}.cmd") - get_filename_component(_NBL_UPDATE_IMPL_CMAKE_FILE_ "${NBL_ROOT_PATH_BINARY}/${_NBL_UPDATE_SUBMODULES_CMD_NAME_}.cmake" ABSOLUTE) - - # Proxy script for inclusive submodule updating - string(APPEND NBL_IMPL_SCRIPT "set(NBL_ROOT_PATH \"${NBL_ROOT_PATH}\")\nset(_GIT_SUBMODULES_JOBS_AMOUNT_ ${_GIT_SUBMODULES_JOBS_AMOUNT_})\nset(GIT_EXECUTABLE \"${GIT_EXECUTABLE}\")\nset(NBL_SHALLOW \"${NBL_SHALLOW}\")\nset(NBL_FORCE \"${NBL_FORCE}\")\n\n") - string(APPEND NBL_IMPL_SCRIPT -[=[ -if(NOT DEFINED GIT_RELATIVE_ENTRY) - message(FATAL_ERROR "GIT_RELATIVE_ENTRY must be defined to use this script!") -endif() -if(NOT DEFINED INCLUDE_SUBMODULE_PATHS) - message(FATAL_ERROR "INCLUDE_SUBMODULE_PATHS must be defined to use this script!") -endif() + list(APPEND NBL_COMMAND ${NBL_SHALLOW} ${GIT_SUBMODULE_PATH}) -# update an inclusive submodule first -execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${NBL_ROOT_PATH}" submodule update --init "${GIT_RELATIVE_ENTRY}") + execute_process(COMMAND ${NBL_COMMAND}) + endfunction() + + function(NBL_INCLUSIVE_UPDATE_EXECUTE GIT_RELATIVE_ENTRY INCLUDE_SUBMODULE_PATHS) + execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${NBL_ROOT_PATH}" submodule update --init "${GIT_RELATIVE_ENTRY}") -if("${INCLUDE_SUBMODULE_PATHS}" STREQUAL "") - set(NBL_SUBMODULE_UPDATE_CONFIG_ENTRY "") -else() - execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}" config --file .gitmodules --get-regexp path - OUTPUT_VARIABLE NBL_OUTPUT_VARIABLE - ) + if("${INCLUDE_SUBMODULE_PATHS}" STREQUAL "") + set(NBL_SUBMODULE_UPDATE_CONFIG_ENTRY "") + else() + execute_process(COMMAND "${GIT_EXECUTABLE}" -C "${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}" config --file .gitmodules --get-regexp path + OUTPUT_VARIABLE NBL_OUTPUT_VARIABLE + ) - string(REGEX REPLACE "\n" ";" NBL_SUBMODULE_CONFIG_LIST "${NBL_OUTPUT_VARIABLE}") - - foreach(NBL_SUBMODULE_NAME ${NBL_SUBMODULE_CONFIG_LIST}) - string(REGEX MATCH "submodule\\.(.*)\\.path" NBL_SUBMODULE_NAME "${NBL_SUBMODULE_NAME}") - list(APPEND NBL_ALL_SUBMODULES "${CMAKE_MATCH_1}") - endforeach() - - foreach(NBL_SUBMODULE_NAME ${NBL_ALL_SUBMODULES}) - list(FIND INCLUDE_SUBMODULE_PATHS "${NBL_SUBMODULE_NAME}" NBL_FOUND) - - if("${NBL_FOUND}" STREQUAL "-1") - list(APPEND NBL_CONFIG_SETUP_CMD "-c;submodule.${NBL_SUBMODULE_NAME}.update=none") # filter submodules - only those on the INCLUDE_SUBMODULE_PATHS list will be updated when recursive update is requested, all left will be skipped + string(REGEX REPLACE "\n" ";" NBL_SUBMODULE_CONFIG_LIST "${NBL_OUTPUT_VARIABLE}") + + foreach(NBL_SUBMODULE_NAME ${NBL_SUBMODULE_CONFIG_LIST}) + string(REGEX MATCH "submodule\\.(.*)\\.path" NBL_SUBMODULE_NAME "${NBL_SUBMODULE_NAME}") + list(APPEND NBL_ALL_SUBMODULES "${CMAKE_MATCH_1}") + endforeach() + + foreach(NBL_SUBMODULE_NAME ${NBL_ALL_SUBMODULES}) + list(FIND INCLUDE_SUBMODULE_PATHS "${NBL_SUBMODULE_NAME}" NBL_FOUND) + + if("${NBL_FOUND}" STREQUAL "-1") + list(APPEND NBL_CONFIG_SETUP_CMD "-c;submodule.${NBL_SUBMODULE_NAME}.update=none") # filter submodules - only those on the INCLUDE_SUBMODULE_PATHS list will be updated when recursive update is requested, all left will be skipped + endif() + endforeach() endif() - endforeach() -endif() -execute_process(COMMAND "${GIT_EXECUTABLE}" ${NBL_CONFIG_SETUP_CMD} submodule update --init -j ${_GIT_SUBMODULES_JOBS_AMOUNT_} --recursive ${NBL_SHALLOW} ${NBL_FORCE} - WORKING_DIRECTORY "${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}" -) -]=] -) - file(WRITE "${_NBL_UPDATE_IMPL_CMAKE_FILE_}" "${NBL_IMPL_SCRIPT}") - - macro(NBL_WRAPPER_COMMAND_INCLUSIVE GIT_RELATIVE_ENTRY INCLUDE_SUBMODULE_PATHS) - string(APPEND _NBL_UPDATE_SUBMODULES_COMMANDS_ "\"${CMAKE_COMMAND}\" \"-DGIT_RELATIVE_ENTRY=${GIT_RELATIVE_ENTRY}\" \"-DINCLUDE_SUBMODULE_PATHS=${INCLUDE_SUBMODULE_PATHS}\" -P \"${_NBL_UPDATE_IMPL_CMAKE_FILE_}\"\n") - endmacro() + execute_process(COMMAND "${GIT_EXECUTABLE}" ${NBL_CONFIG_SETUP_CMD} submodule update --init -j ${_GIT_SUBMODULES_JOBS_AMOUNT_} --recursive ${NBL_SHALLOW} ${NBL_FORCE} + WORKING_DIRECTORY "${NBL_ROOT_PATH}/${GIT_RELATIVE_ENTRY}" + ) + endfunction() if(NBL_UPDATE_GIT_SUBMODULE) - execute_process(COMMAND ${CMAKE_COMMAND} -E echo "All submodules are about to get updated and initialized in repository because NBL_UPDATE_GIT_SUBMODULE is turned ON!") + execute_process(COMMAND ${CMAKE_COMMAND} -E echo "NBL_UPDATE_GIT_SUBMODULE is turned ON, updating submodules.") + if(NBL_SYNC_ON_UPDATE_GIT_SUBMODULE) + execute_process(COMMAND "${GIT_EXECUTABLE}" submodule sync --recursive + WORKING_DIRECTORY "${NBL_ROOT_PATH}" + ) + endif() + + if(NBL_FORCE_ON_UPDATE_GIT_SUBMODULE) + execute_process(COMMAND "${GIT_EXECUTABLE}" submodule foreach --recursive "${GIT_EXECUTABLE}" clean -fdx + WORKING_DIRECTORY "${NBL_ROOT_PATH}" + ) + + execute_process(COMMAND "${GIT_EXECUTABLE}" submodule foreach --recursive "${GIT_EXECUTABLE}" reset --hard + WORKING_DIRECTORY "${NBL_ROOT_PATH}" + ) + endif() + include("${THIRD_PARTY_SOURCE_DIR}/boost/dep/wave.cmake") - macro(NBL_IMPL_INIT_COMMON_SUBMODULES) - # 3rdparty except boost & gltf - set(NBL_3RDPARTY_MODULES_TO_SKIP - 3rdparty/boost/superproject # a lot of submodules we don't use - 3rdparty/glTFSampleModels # more then 2GB waste of space (disk + .gitmodules data) - ) - NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./3rdparty TRUE "${NBL_3RDPARTY_MODULES_TO_SKIP}") - - # boost's 3rdparties, special case - set(NBL_BOOST_LIBS_TO_INIT ${NBL_BOOST_LIBS} wave numeric_conversion) # wave and all of its deps, numeric_conversion is nested in conversion submodule (for some reason boostdep tool doesn't output it properly) - foreach(NBL_TARGET ${NBL_BOOST_LIBS_TO_INIT}) - list(APPEND NBL_BOOST_SUBMODULES_TO_INIT ${NBL_TARGET}) - endforeach() - NBL_WRAPPER_COMMAND_INCLUSIVE(3rdparty/boost/superproject "${NBL_BOOST_SUBMODULES_TO_INIT}") - - # tests - NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./tests FALSE "") - endmacro() + # 3rdparty except boost & gltf + set(NBL_3RDPARTY_MODULES_TO_SKIP + 3rdparty/boost/superproject # a lot of submodules we don't use + 3rdparty/glTFSampleModels # more then 2GB waste of space (disk + .gitmodules data) + ) + + NBL_EXCLUSIVE_UPDATE_EXECUTE("" ./3rdparty TRUE "${NBL_3RDPARTY_MODULES_TO_SKIP}") - NBL_IMPL_INIT_COMMON_SUBMODULES() + # boost's 3rdparties, special case + set(NBL_BOOST_LIBS_TO_INIT ${NBL_BOOST_LIBS} wave numeric_conversion) # wave and all of its deps, numeric_conversion is nested in conversion submodule (for some reason boostdep tool doesn't output it properly) + foreach(NBL_TARGET ${NBL_BOOST_LIBS_TO_INIT}) + list(APPEND NBL_BOOST_SUBMODULES_TO_INIT ${NBL_TARGET}) + endforeach() + + NBL_INCLUSIVE_UPDATE_EXECUTE(3rdparty/boost/superproject "${NBL_BOOST_SUBMODULES_TO_INIT}") + + # tests + NBL_EXCLUSIVE_UPDATE_EXECUTE("" ./tests FALSE "") if(NBL_UPDATE_GIT_SUBMODULE_INCLUDE_PRIVATE) - NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./examples_tests TRUE "") + NBL_EXCLUSIVE_UPDATE_EXECUTE("" ./examples_tests TRUE "") else() - # NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./ci TRUE "") TODO: enable it once we merge Ditt, etc + # NBL_EXCLUSIVE_UPDATE_EXECUTE("" ./ci TRUE "") TODO: enable it once we merge Ditt, etc # examples and their media if(NBL_BUILD_EXAMPLES) - NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./examples_tests FALSE "") - NBL_WRAPPER_COMMAND_EXCLUSIVE(examples_tests ./media FALSE "") + NBL_EXCLUSIVE_UPDATE_EXECUTE("" ./examples_tests FALSE "") + NBL_EXCLUSIVE_UPDATE_EXECUTE(examples_tests ./media FALSE "") endif() endif() - - file(WRITE "${_NBL_UPDATE_SUBMODULES_CMD_FILE_}" "${_NBL_UPDATE_SUBMODULES_COMMANDS_}") - - if(WIN32) - if(NBL_UPDATE_GIT_SUBMODULE_NO_SEPARATE_SHELL) - set(UPDATE_COMMAND - nbl-update-submodules.cmd - ) - - execute_process(COMMAND ${UPDATE_COMMAND} - WORKING_DIRECTORY "${NBL_ROOT_PATH_BINARY}" - RESULT_VARIABLE _NBL_TMP_RET_CODE_ - ) - else() - find_package(GitBash REQUIRED) - - execute_process(COMMAND "${GIT_BASH_EXECUTABLE}" "-c" -[=[ ->&2 echo "" -clear -./nbl-update-submodules.cmd 2>&1 | tee nbl-update-submodules.log -sleep 1 -clear -tput setaf 2; echo -e "Submodules have been updated! -Created nbl-update-submodules.log in your build directory." -]=] - WORKING_DIRECTORY ${NBL_ROOT_PATH_BINARY} - OUTPUT_VARIABLE _NBL_TMP_OUTPUT_ - RESULT_VARIABLE _NBL_TMP_RET_CODE_ - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE - ) - - unset(_NBL_TMP_OUTPUT_) - unset(_NBL_TMP_RET_CODE_) - - message(STATUS "Generated \"${NBL_ROOT_PATH_BINARY}/nbl-update-submodules.log\"") - endif() - - message(STATUS "Submodules have been updated!") - else() - execute_process(COMMAND "${_NBL_UPDATE_SUBMODULES_CMD_FILE_}") - endif() else() - execute_process(COMMAND ${CMAKE_COMMAND} -E echo "NBL_UPDATE_GIT_SUBMODULE is turned OFF therefore submodules won't get updated.") + execute_process(COMMAND "${CMAKE_COMMAND}" -E echo "NBL_UPDATE_GIT_SUBMODULE is turned OFF, submodules won't get updated.") endif() endfunction() diff --git a/include/nbl/asset/IDescriptorSetLayout.h b/include/nbl/asset/IDescriptorSetLayout.h index ab870c0fae..18e8fabd7b 100644 --- a/include/nbl/asset/IDescriptorSetLayout.h +++ b/include/nbl/asset/IDescriptorSetLayout.h @@ -182,7 +182,13 @@ class IDescriptorSetLayout : public virtual core::IReferenceCounted // TODO: tr core::bitflag createFlags; core::bitflag stageFlags; uint32_t count; - + + SBuildInfo(uint32_t _binding, core::bitflag _createFlags, core::bitflag _stageFlags, uint32_t _count) + : binding(_binding), createFlags(_createFlags), stageFlags(_stageFlags), count(_count) {} + SBuildInfo(SBuildInfo&& other) + : binding(other.binding), createFlags(other.createFlags), stageFlags(other.stageFlags), count(other.count) {} + + SBuildInfo& operator=(const SBuildInfo& other) = default; inline bool operator< (const SBuildInfo& other) const { return binding < other.binding; } }; diff --git a/include/nbl/config/BuildConfigOptions.h.in b/include/nbl/config/BuildConfigOptions.h.in index ff6f08a9c8..13aeabe859 100644 --- a/include/nbl/config/BuildConfigOptions.h.in +++ b/include/nbl/config/BuildConfigOptions.h.in @@ -18,6 +18,7 @@ #cmakedefine _NBL_PLATFORM_LINUX_ #cmakedefine _NBL_PLATFORM_OSX_ #cmakedefine _NBL_PLATFORM_ANDROID_ +#cmakedefine _NBL_PLATFORM_MACOS_ // graphics API backend #cmakedefine _NBL_COMPILE_WITH_VULKAN_ @@ -112,4 +113,4 @@ #include "define.h" #endif // __NBL_BUILDING_NABLA__ -#endif // __NBL_BUILD_CONFIG_OPTIONS_H_INCLUDED__ \ No newline at end of file +#endif // __NBL_BUILD_CONFIG_OPTIONS_H_INCLUDED__ diff --git a/include/nbl/core/decl/compile_config.h b/include/nbl/core/decl/compile_config.h index 851bc4e4a6..216e1e58ee 100644 --- a/include/nbl/core/decl/compile_config.h +++ b/include/nbl/core/decl/compile_config.h @@ -16,7 +16,7 @@ // this actually includes file depending on build type (Debug/Release) #include "BuildConfigOptions.h" -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_MACOS_) # define _NBL_POSIX_API_ // Android is not 100% POSIX, but it's close enough #elif defined(_NBL_PLATFORM_WINDOWS_) # define _NBL_WINDOWS_API_ diff --git a/include/nbl/core/execution.h b/include/nbl/core/execution.h index 9c67dc3a5e..54e01e4856 100644 --- a/include/nbl/core/execution.h +++ b/include/nbl/core/execution.h @@ -5,7 +5,7 @@ #ifndef _NBL_CORE_EXECUTION_H_INCLUDED_ #define _NBL_CORE_EXECUTION_H_INCLUDED_ -#if __has_include () +#if __has_include () and not defined(__clang__) #include #include #else @@ -26,9 +26,11 @@ inline auto highLevelF(Args&&... args) -> decltype(lowLevelF(std::forward( namespace nbl::core { -#if __has_include() +#if __has_include() and not defined(__clang__) namespace execution = std::execution; +#include + ALIAS_TEMPLATE_FUNCTION(for_each_n, std::for_each_n) ALIAS_TEMPLATE_FUNCTION(for_each, std::for_each) ALIAS_TEMPLATE_FUNCTION(swap_ranges, std::swap_ranges) @@ -42,7 +44,7 @@ ALIAS_TEMPLATE_FUNCTION(nth_element, std::nth_element) //template //const auto swap_ranges = std::swap_ranges<_ExPo, _FwdIt1, _FwdIt2>; #else -namespace execution = oneapi::dpl::execution; +namespace execution = oneapi::dpl::execution; // TODO: fix those targets it in order to make Nabla compile again with any clang ALIAS_TEMPLATE_FUNCTION(for_each_n, oneapi::dpl::for_each_n) ALIAS_TEMPLATE_FUNCTION(for_each, oneapi::dpl::for_each) diff --git a/include/nbl/core/math/glslFunctions.tcc b/include/nbl/core/math/glslFunctions.tcc index 205585965b..cd994bb8f9 100644 --- a/include/nbl/core/math/glslFunctions.tcc +++ b/include/nbl/core/math/glslFunctions.tcc @@ -10,6 +10,10 @@ #include "nbl/core/math/floatutil.tcc" #include "matrix4SIMD.h" +#if defined(__clang__) +#include +#endif //__clang__ + #include #include @@ -368,7 +372,11 @@ NBL_FORCE_INLINE vectorSIMDf cyl_bessel_i(const vectorSIMDf& v, con template NBL_FORCE_INLINE T cyl_bessel_i(const T& v, const T& x) { - return std::cyl_bessel_i(double(v),double(x)); + #if defined(__clang__) + return boost::math::cyl_bessel_i(double(v),double(x)); + #else + return std::cyl_bessel_i(double(v),double(x)); + #endif } template<> @@ -379,7 +387,11 @@ NBL_FORCE_INLINE vectorSIMDf d_cyl_bessel_i(const vectorSIMDf& v, c template NBL_FORCE_INLINE T d_cyl_bessel_i(const T& v, const T& x) { - return 0.5*(std::cyl_bessel_i(double(v)-1.0,double(x))+std::cyl_bessel_i(double(v)+1.0,double(x))); + #if defined(__clang__) + return 0.5*(boost::math::cyl_bessel_i(double(v)-1.0,double(x))+boost::math::cyl_bessel_i(double(v)+1.0,double(x))); + #else + return 0.5*(std::cyl_bessel_i(double(v)-1.0,double(x))+std::cyl_bessel_i(double(v)+1.0,double(x))); + #endif } #endif diff --git a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h index 8b0bf51e2e..f18b599a21 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h +++ b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h @@ -3,7 +3,7 @@ namespace nbl::system { -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_MACOS_) class CFileViewVirtualAllocatorPOSIX : public IFileViewAllocator { public: @@ -15,4 +15,4 @@ class CFileViewVirtualAllocatorPOSIX : public IFileViewAllocator #endif } -#endif \ No newline at end of file +#endif diff --git a/include/nbl/system/CSystemMacOS.h b/include/nbl/system/CSystemMacOS.h new file mode 100644 index 0000000000..d3be9f5fac --- /dev/null +++ b/include/nbl/system/CSystemMacOS.h @@ -0,0 +1,21 @@ +#ifndef _NBL_SYSTEM_C_SYSTEM_MACOS_H_INCLUDED_ +#define _NBL_SYSTEM_C_SYSTEM_MACOS_H_INCLUDED_ + +#include "nbl/system/ISystem.h" +#include "nbl/system/ISystemPOSIX.h" + +namespace nbl::system +{ +#ifdef _NBL_PLATFORM_MACOS_ + +class CSystemMacOS final : public ISystemPOSIX +{ + public: + inline CSystemMacOS() : ISystemPOSIX() {} + + NBL_API2 SystemInfo getSystemInfo() const override; +}; +#endif // _NBL_PLATFORM_MACOS_ +} + +#endif // _NBL_SYSTEM_C_SYSTEM_MACOS_H_INCLUDED_ diff --git a/include/nbl/system/IAsyncQueueDispatcher.h b/include/nbl/system/IAsyncQueueDispatcher.h index d5b0cb8a1a..8fa345a660 100644 --- a/include/nbl/system/IAsyncQueueDispatcher.h +++ b/include/nbl/system/IAsyncQueueDispatcher.h @@ -448,7 +448,7 @@ class IAsyncQueueDispatcher : public IThreadHandler, pro public: inline IAsyncQueueDispatcher() {} - inline IAsyncQueueDispatcher(base_t::start_on_construction_t) : base_t(base_t::start_on_construction) {} + inline IAsyncQueueDispatcher(typename base_t::start_on_construction_t) : base_t(base_t::start_on_construction) {} using mutex_t = typename base_t::mutex_t; using lock_t = typename base_t::lock_t; diff --git a/include/nbl/system/IFileViewAllocator.h b/include/nbl/system/IFileViewAllocator.h index aedeb6320b..2731b42aa2 100644 --- a/include/nbl/system/IFileViewAllocator.h +++ b/include/nbl/system/IFileViewAllocator.h @@ -61,11 +61,11 @@ class CNullAllocator : public IFileViewAllocator #ifdef _NBL_PLATFORM_WINDOWS_ #include "nbl/system/CFileViewVirtualAllocatorWin32.h" using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorWin32; -#elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_MACOS_) #include "nbl/system/CFileViewVirtualAllocatorPOSIX.h" using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorPOSIX; #else #error "Unsupported platform!" #endif -#endif \ No newline at end of file +#endif diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 553ae05c0e..0d167ca0ed 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -246,6 +246,110 @@ class NBL_API2 ISystem : public core::IReferenceCounted }; struct SRequestType { + + SRequestType() + { + std::memset(this, 0, sizeof(SRequestType)); + } + + ~SRequestType() {} + + //! SRequestParams_READ to SRequestType because of std::variant type-safe union + + SRequestType(SRequestParams_READ& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_READ)); + } + + SRequestType(const SRequestParams_READ& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_READ)); + } + + SRequestType& operator=(SRequestParams_READ& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_READ)); + return *this; + } + + SRequestType& operator=(const SRequestParams_READ& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_READ)); + return *this; + } + + //! SRequestParams_WRITE to SRequestType because of std::variant type-safe union + + SRequestType(SRequestParams_WRITE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_WRITE)); + } + + SRequestType(const SRequestParams_WRITE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_WRITE)); + } + + SRequestType& operator=(SRequestParams_WRITE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_WRITE)); + return *this; + } + + SRequestType& operator=(const SRequestParams_WRITE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_WRITE)); + return *this; + } + + //! SRequestParams_CREATE_FILE to SRequestType because of std::variant type-safe union + + SRequestType(SRequestParams_CREATE_FILE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_CREATE_FILE)); + } + + SRequestType(const SRequestParams_CREATE_FILE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_CREATE_FILE)); + } + + SRequestType& operator=(SRequestParams_CREATE_FILE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_CREATE_FILE)); + return *this; + } + + SRequestType& operator=(const SRequestParams_CREATE_FILE& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_CREATE_FILE)); + return *this; + } + + //! SRequestParams_NOOP to SRequestType because of std::variant type-safe union + + SRequestType(SRequestParams_NOOP& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_NOOP)); + } + + SRequestType(const SRequestParams_NOOP& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_NOOP)); + } + + SRequestType& operator=(SRequestParams_NOOP& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_NOOP)); + return *this; + } + + SRequestType& operator=(const SRequestParams_NOOP& copy) + { + std::memmove(this, ©, sizeof(SRequestParams_NOOP)); + return *this; + } + std::variant< SRequestParams_NOOP, SRequestParams_CREATE_FILE, diff --git a/include/nbl/system/ISystemPOSIX.h b/include/nbl/system/ISystemPOSIX.h index c021aefaa9..9d813c9bc9 100644 --- a/include/nbl/system/ISystemPOSIX.h +++ b/include/nbl/system/ISystemPOSIX.h @@ -9,7 +9,7 @@ namespace nbl::system { -#if defined(_NBL_PLATFORM_LINUX_) || defined (_NBL_PLATFORM_ANDROID_) +#if defined(_NBL_PLATFORM_LINUX_) || defined (_NBL_PLATFORM_ANDROID_) || defined (_NBL_PLATFORM_MACOS_) class ISystemPOSIX : public ISystem { protected: diff --git a/include/nbl/system/declarations.h b/include/nbl/system/declarations.h index 72c6ede273..f3cbb8e183 100644 --- a/include/nbl/system/declarations.h +++ b/include/nbl/system/declarations.h @@ -30,8 +30,10 @@ #elif defined(_NBL_PLATFORM_LINUX_) # include "nbl/system/CColoredStdoutLoggerANSI.h" # include "nbl/system/CSystemLinux.h" +#elif defined(_NBL_PLATFORM_MACOS_) +# include "nbl/system/CSystemMacOS.h" #else #error "Unsupported Platform" #endif // TODO more platforms (android) -#endif \ No newline at end of file +#endif diff --git a/include/nbl/ui/declarations.h b/include/nbl/ui/declarations.h index 4a2bce9552..4d67241623 100644 --- a/include/nbl/ui/declarations.h +++ b/include/nbl/ui/declarations.h @@ -13,6 +13,7 @@ #elif defined(_NBL_BUILD_WITH_WAYLAND) && defined(_NBL_TEST_WAYLAND) # include "nbl/ui/CWindowManagerWayland.h" #elif defined(_NBL_PLATFORM_LINUX_) +#elif defined(_NBL_PLATFORM_MACOS_) #endif // TODO more platforms (android) // clipboards @@ -22,4 +23,4 @@ #include "nbl/ui/IInputEventChannel.h" -#endif \ No newline at end of file +#endif diff --git a/include/nbl/video/surface/CSurfaceVulkan.h b/include/nbl/video/surface/CSurfaceVulkan.h index ddf50a443e..81afbd977e 100644 --- a/include/nbl/video/surface/CSurfaceVulkan.h +++ b/include/nbl/video/surface/CSurfaceVulkan.h @@ -62,7 +62,9 @@ class NBL_API2 CSurfaceVulkanWin32Native final : public CSurfaceNative ${_LIB_REGEXD}") - set(${_LNAME}_LIB_SONAME ${_LIB_REGEXD}) - endif() -endmacro() -]] - if(UNIX AND NOT ANDROID) # TODO: Now we require the `-dev` package or maybe ship headers ourselves? find_package(X11 REQUIRED) @@ -63,12 +29,16 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(PLATFORM android-gcc) endif() - elseif (UNIX AND NOT APPLE) + elseif (UNIX) if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(PLATFORM linux-clang) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") set(PLATFORM linux-gcc) endif() + elseif(APPLE) + if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") + set(PLATFORM macos-clang) + endif() endif() if ("${PLATFORM}" STREQUAL "NOTFOUND") @@ -176,6 +146,7 @@ set(NBL_SYSTEM_SOURCES ${NBL_ROOT_PATH}/src/nbl/system/CSystemAndroid.cpp ${NBL_ROOT_PATH}/src/nbl/system/ISystemPOSIX.cpp ${NBL_ROOT_PATH}/src/nbl/system/CSystemLinux.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CSystemMacOS.cpp ) set(NBL_UI_SOURCES ${NBL_ROOT_PATH}/src/nbl/ui/CWindowWin32.cpp @@ -349,7 +320,7 @@ set(COMMON_INCLUDE_DIRS $ #for dynamically generated jconfig.h ) -# just gather all the header files and later put them into project so it's easy to search for things using IDE +# just gather all the header files and later put them into project so its easy to search for things using IDE file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") @@ -573,16 +544,12 @@ if(_NBL_ENABLE_DXC_COMPILE_TESTS_) add_dependencies(Nabla HLSL_NABLA_COMPILE_TEST) endif() -add_custom_target(dxcompiler +add_custom_command(OUTPUT "${DXC_LIB}" "${DXC_DLL}" COMMAND "${CMAKE_COMMAND}" --build "${DXC_BUILD_DIR}" --target dxcompiler --config $,Debug,Release> -j${_NBL_JOBS_AMOUNT_} - BYPRODUCTS "${DXC_LIB}" "${DXC_DLL}" VERBATIM COMMAND_EXPAND_LISTS ) -add_dependencies(Nabla dxcompiler) -add_dependencies(3rdparty dxcompiler) - if(NBL_STATIC_BUILD) target_link_libraries(Nabla INTERFACE "${DXC_LIB}") else() @@ -768,7 +735,10 @@ if(NBL_STATIC_BUILD) if(_NBL_BUILD_DPL_) nbl_install_program(tbb) nbl_install_program(tbbmalloc) - nbl_install_program(tbbmalloc_proxy) + + if(NOT (APPLE AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")) + nbl_install_program(tbbmalloc_proxy) + endif() endif() else() nbl_install_program_spec(Nabla "nbl") diff --git a/src/nbl/asset/interchange/CImageLoaderJPG.cpp b/src/nbl/asset/interchange/CImageLoaderJPG.cpp index 443913ba69..7026f779fd 100644 --- a/src/nbl/asset/interchange/CImageLoaderJPG.cpp +++ b/src/nbl/asset/interchange/CImageLoaderJPG.cpp @@ -274,7 +274,7 @@ asset::SAssetBundle CImageLoaderJPG::loadAsset(system::IFile* _file, const asset // https://en.wikipedia.org/wiki/YCbCr#JPEG_conversion break; case JCS_CMYK: - _params.logger.log("CMYK color space is unsupported:", system::ILogger::ELL_ERROR, _file->getFileName().string()); + _params.logger.log("CMYK color space is unsupported:", system::ILogger::ELL_ERROR, _file->getFileName().string().c_str()); return {}; break; case JCS_YCCK: // this I have no resources on @@ -336,4 +336,4 @@ asset::SAssetBundle CImageLoaderJPG::loadAsset(system::IFile* _file, const asset } // end namespace video } // end namespace nbl -#endif \ No newline at end of file +#endif diff --git a/src/nbl/asset/interchange/CImageLoaderPNG.cpp b/src/nbl/asset/interchange/CImageLoaderPNG.cpp index 3601d3226b..be906d3edf 100644 --- a/src/nbl/asset/interchange/CImageLoaderPNG.cpp +++ b/src/nbl/asset/interchange/CImageLoaderPNG.cpp @@ -117,7 +117,7 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset _file->read(success, buffer, 0, sizeof(buffer)); if (!success) { - _params.logger.log("LOAD PNG: can't read _file\n", system::ILogger::ELL_ERROR, _file->getFileName().string()); + _params.logger.log("LOAD PNG: can't read _file\n", system::ILogger::ELL_ERROR, _file->getFileName().string().c_str()); return {}; } @@ -347,4 +347,4 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset }// end namespace nbl }//end namespace video -#endif \ No newline at end of file +#endif diff --git a/src/nbl/system/CFilePOSIX.h b/src/nbl/system/CFilePOSIX.h index 9e453dfefd..3392ac046f 100644 --- a/src/nbl/system/CFilePOSIX.h +++ b/src/nbl/system/CFilePOSIX.h @@ -6,7 +6,7 @@ namespace nbl::system { -#if defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_) +#if defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_MACOS_) class CFilePOSIX : public ISystemFile { public: @@ -40,4 +40,4 @@ class CFilePOSIX : public ISystemFile } -#endif // _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED \ No newline at end of file +#endif // _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED diff --git a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp index 0f5175976e..150e31e8b0 100644 --- a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp +++ b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp @@ -2,7 +2,7 @@ using namespace nbl::system; -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_MACOS_) #include void* CFileViewVirtualAllocatorPOSIX::alloc(size_t size) @@ -14,4 +14,4 @@ bool CFileViewVirtualAllocatorPOSIX::dealloc(void* data, size_t size) const auto ret = munmap(data,size); return ret != -1; } -#endif \ No newline at end of file +#endif diff --git a/src/nbl/system/CSystemLinux.cpp b/src/nbl/system/CSystemLinux.cpp index 5a62518b0a..f73e4a5ba7 100644 --- a/src/nbl/system/CSystemLinux.cpp +++ b/src/nbl/system/CSystemLinux.cpp @@ -9,7 +9,7 @@ using namespace nbl::system; ISystem::SystemInfo CSystemLinux::getSystemInfo() const { SystemInfo info; - + // TODO // info.cpuFrequencyHz = 3000000000u; @@ -26,4 +26,4 @@ ISystem::SystemInfo CSystemLinux::getSystemInfo() const return info; } -#endif \ No newline at end of file +#endif diff --git a/src/nbl/system/CSystemMacOS.cpp b/src/nbl/system/CSystemMacOS.cpp new file mode 100644 index 0000000000..2b39945011 --- /dev/null +++ b/src/nbl/system/CSystemMacOS.cpp @@ -0,0 +1,37 @@ +#include "nbl/system/CSystemMacOS.h" + +using namespace nbl; +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_MACOS_ + +#include +#include +#include +#include + +ISystem::SystemInfo CSystemMacOS::getSystemInfo() const +{ + #define BUFFERLEN 128 + + auto getProperty = [](const std::string_view property) -> int32_t + { + std::string buffer; + buffer.resize(BUFFERLEN); + size_t bufferCopyLen = buffer.size(); + sysctlbyname(property.data(), buffer.data(), &bufferCopyLen, nullptr, 0); + return std::stoi(buffer.substr(0, bufferCopyLen)); + }; + + SystemInfo info; + + // info.OSFullName = ; + info.cpuFrequencyHz = 3000000000u; // TODO + info.desktopResX = 0xdeadbeefu; // TODO + info.desktopResY = 0xdeadbeefu; // TODO + info.totalMemory = getProperty("hw.memsize"); //hw.memsize + // info.availableMemory = ; // TODO + + return info; +} +#endif // _NBL_PLATFORM_MACOS_ diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 7e86d15cb0..bf678637a7 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -273,7 +273,7 @@ ISystem::FoundArchiveFile ISystem::findFileInArchive(const system::path& absolut void ISystem::CAsyncQueue::process_request(base_t::future_base_t* _future_base, SRequestType& req) { std::visit([=](auto& visitor) { - using retval_t = std::remove_reference_t::retval_t; + using retval_t = typename std::remove_reference_t::retval_t; visitor(base_t::future_storage_cast(_future_base),m_caller.get()); }, req.params); } @@ -329,5 +329,4 @@ void ISystem::unmountBuiltins() { removeByKey("nbl/builtin"); removeByKey("spirv"); removeByKey("boost"); - -} \ No newline at end of file +} diff --git a/src/nbl/system/ISystemPOSIX.cpp b/src/nbl/system/ISystemPOSIX.cpp index 6692a1e8b9..d803917de2 100644 --- a/src/nbl/system/ISystemPOSIX.cpp +++ b/src/nbl/system/ISystemPOSIX.cpp @@ -6,16 +6,23 @@ using namespace nbl; using namespace nbl::system; -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_MACOS_) #include +#include #include #include core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile(const std::filesystem::path& filename, const core::bitflag flags) { const bool writeAccess = flags.value&IFile::ECF_WRITE; - int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0); + +#if defined(__APPLE__) + int createFlags = (writeAccess ? O_CREAT:0); +#else + int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0); +#endif + switch (flags.value&IFile::ECF_READ_WRITE) { case IFile::ECF_READ: diff --git a/src/nbl/video/IAPIConnection.cpp b/src/nbl/video/IAPIConnection.cpp index 5b3d72760f..1bf4d58b67 100644 --- a/src/nbl/video/IAPIConnection.cpp +++ b/src/nbl/video/IAPIConnection.cpp @@ -27,8 +27,8 @@ IAPIConnection::IAPIConnection(const SFeatures& enabledFeatures) if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) #elif defined(_NBL_PLATFORM_ANDROID_) if (void* mod = dlopen("libVkLayer_GLES_RenderDoc.so", RTLD_NOW | RTLD_NOLOAD)) -#elif defined(_NBL_PLATFORM_LINUX_) - if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) +#elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_MACOS_) + if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) // TODO: check it on MacOS #else #error "Nabla Unsupported Platform!" #endif @@ -38,12 +38,12 @@ IAPIConnection::IAPIConnection(const SFeatures& enabledFeatures) (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); assert(ret == 1); - #elif defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_LINUX_) - pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); + #elif defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_MACOS_) + pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); // TODO: check it on MacOS int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); assert(ret == 1); #endif } } -} \ No newline at end of file +}