From 1d35964f82a8bd19842f1229b57f51e21a7e07a8 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 10 Jun 2021 12:01:22 -0400 Subject: [PATCH 1/3] Fix openal-soft includes on macOS; fix default sysroot for cmd line builds --- neo/CMakeLists.txt | 12 +++++++++--- neo/cmake-macos-opengl-debug.sh | 2 +- neo/cmake-macos-opengl-release.sh | 1 + neo/cmake-macos-opengl-retail.sh | 1 + neo/cmake-macos-vulkan-debug.sh | 2 +- neo/cmake-macos-vulkan-release.sh | 1 + neo/cmake-macos-vulkan-retail.sh | 1 + neo/cmake-xcode-opengl-release.sh | 2 +- neo/cmake-xcode-vulkan-release.sh | 2 +- neo/sound/snd_local.h | 3 ++- 10 files changed, 19 insertions(+), 8 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 84b2ee5d..6d169923 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -183,9 +183,9 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang") # SRS - Make sure OSX can find system headers and add support for minimum OSX runtime version if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # SRS - Also add -fasm-blocks otherwise Xcode complains - add_definitions(-fasm-blocks -isysroot "${CMAKE_OSX_SYSROOT}") - if("${CMAKE_OSX_DEPLOYMENT_TARGET}") - add_definitions(-mmacosx-version-min="${CMAKE_OSX_DEPLOYMENT_TARGET}") + add_definitions(-fasm-blocks) + if(CMAKE_OSX_DEPLOYMENT_TARGET) + add_definitions(-isysroot "${CMAKE_OSX_SYSROOT}" -mmacosx-version-min="${CMAKE_OSX_DEPLOYMENT_TARGET}") endif() endif() @@ -1700,6 +1700,12 @@ else() if(OPENAL) find_package(OpenAL REQUIRED) add_definitions(-DUSE_OPENAL) + + # SRS - Added support for OpenAL Soft headers on OSX (vs default macOS SDK headers) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND OPENAL_INCLUDE_DIR MATCHES "openal-soft") + include_directories(${OPENAL_INCLUDE_DIR}) + add_definitions(-DUSE_OPENAL_SOFT_INCLUDES) + endif() list(APPEND RBDOOM3_INCLUDES ${OPENAL_INCLUDES}) list(APPEND RBDOOM3_SOURCES diff --git a/neo/cmake-macos-opengl-debug.sh b/neo/cmake-macos-opengl-debug.sh index 4285d97f..72eb8b98 100755 --- a/neo/cmake-macos-opengl-debug.sh +++ b/neo/cmake-macos-opengl-debug.sh @@ -2,4 +2,4 @@ cd .. rm -rf build mkdir build cd build -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DSDL2=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-macos-opengl-release.sh b/neo/cmake-macos-opengl-release.sh index fe681817..fafae18a 100755 --- a/neo/cmake-macos-opengl-release.sh +++ b/neo/cmake-macos-opengl-release.sh @@ -2,4 +2,5 @@ cd .. rm -rf build mkdir build cd build +# change or remove -DCMAKE_OSX_DEPLOYMENT_TARGET= to match supported runtime targets cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-macos-opengl-retail.sh b/neo/cmake-macos-opengl-retail.sh index 31bfa269..38f6180d 100755 --- a/neo/cmake-macos-opengl-retail.sh +++ b/neo/cmake-macos-opengl-retail.sh @@ -2,4 +2,5 @@ cd .. rm -rf build mkdir build cd build +# change or remove -DCMAKE_OSX_DEPLOYMENT_TARGET= to match supported runtime targets cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-DID_RETAIL" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-macos-vulkan-debug.sh b/neo/cmake-macos-vulkan-debug.sh index db89d46c..77279999 100755 --- a/neo/cmake-macos-vulkan-debug.sh +++ b/neo/cmake-macos-vulkan-debug.sh @@ -2,4 +2,4 @@ cd .. rm -rf build mkdir build cd build -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev \ No newline at end of file +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev \ No newline at end of file diff --git a/neo/cmake-macos-vulkan-release.sh b/neo/cmake-macos-vulkan-release.sh index 19157f2f..08ec6e13 100755 --- a/neo/cmake-macos-vulkan-release.sh +++ b/neo/cmake-macos-vulkan-release.sh @@ -2,4 +2,5 @@ cd .. rm -rf build mkdir build cd build +# change or remove -DCMAKE_OSX_DEPLOYMENT_TARGET= to match supported runtime targets cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DUSE_MoltenVK=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-macos-vulkan-retail.sh b/neo/cmake-macos-vulkan-retail.sh index 26bfd5c7..b43bdcf2 100755 --- a/neo/cmake-macos-vulkan-retail.sh +++ b/neo/cmake-macos-vulkan-retail.sh @@ -2,4 +2,5 @@ cd .. rm -rf build mkdir build cd build +# change or remove -DCMAKE_OSX_DEPLOYMENT_TARGET= to match supported runtime targets cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-DID_RETAIL" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DUSE_MoltenVK=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-xcode-opengl-release.sh b/neo/cmake-xcode-opengl-release.sh index c095d89f..f8cddafd 100755 --- a/neo/cmake-xcode-opengl-release.sh +++ b/neo/cmake-xcode-opengl-release.sh @@ -2,4 +2,4 @@ cd .. rm -rf xcode-opengl-release mkdir xcode-opengl-release cd xcode-opengl-release -cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev +cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DSDL2=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/cmake-xcode-vulkan-release.sh b/neo/cmake-xcode-vulkan-release.sh index b825d56d..1547ef8f 100755 --- a/neo/cmake-xcode-vulkan-release.sh +++ b/neo/cmake-xcode-vulkan-release.sh @@ -2,4 +2,4 @@ cd .. rm -rf xcode-vulkan-release mkdir xcode-vulkan-release cd xcode-vulkan-release -cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DUSE_MoltenVK=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev +cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DUSE_MoltenVK=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev diff --git a/neo/sound/snd_local.h b/neo/sound/snd_local.h index cc1a4c5d..61679ffc 100644 --- a/neo/sound/snd_local.h +++ b/neo/sound/snd_local.h @@ -98,7 +98,8 @@ typedef enum //#define AL_ALEXT_PROTOTYPES -#ifdef __APPLE__ +// SRS - Added check on OSX for OpenAL Soft headers vs macOS SDK headers +#if defined(__APPLE__) && !defined(USE_OPENAL_SOFT_INCLUDES) #include #include #else From ab9857987c6114b3503cc08f4e70771ffc7f6666 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 10 Jun 2021 12:33:17 -0400 Subject: [PATCH 2/3] Add note to macOS vulkan build script re MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE env var --- neo/cmake-macos-vulkan-debug.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neo/cmake-macos-vulkan-debug.sh b/neo/cmake-macos-vulkan-debug.sh index 77279999..ea382737 100755 --- a/neo/cmake-macos-vulkan-debug.sh +++ b/neo/cmake-macos-vulkan-debug.sh @@ -2,4 +2,5 @@ cd .. rm -rf build mkdir build cd build -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev \ No newline at end of file +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -Wno-dev +echo "** NOTE: For this build type must set environment variable MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1 at runtime **" From 4c3a9ad3df611b0171af477e2c80a4e0cf82ed4d Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Fri, 11 Jun 2021 11:12:49 -0400 Subject: [PATCH 3/3] Use custom _aligned_alloc on macOS for better SDK and runtime portability --- neo/renderer/Vulkan/vma.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/neo/renderer/Vulkan/vma.h b/neo/renderer/Vulkan/vma.h index 8982631c..1c526263 100644 --- a/neo/renderer/Vulkan/vma.h +++ b/neo/renderer/Vulkan/vma.h @@ -770,11 +770,9 @@ remove them if not needed. //SRS - Modified from vkQuake2, to compile with C++11 on OSX versions with no aligned_alloc #if defined(__APPLE__) -#if !defined(MAC_OS_X_VERSION_10_16) && defined(__cplusplus) && __cplusplus < 201703L -// For C++14, usr/include/malloc/_malloc.h declares aligned_alloc() only with -// the MacOSX11.0 SDK in Xcode 12 (which is what adds MAC_OS_X_VERSION_10_16). -// For C++17 aligned_alloc is available with the 10.15 SDK already. -void* aligned_alloc( size_t alignment, size_t size ) +//SRS - aligned_alloc available on macOS starting with C++17 on 10.15 SDK, C++14 on 11.0 SDK +//SRS - Instead, use custom _aligned_alloc for portability across macOS SDK and runtime versions +void* _aligned_alloc( size_t alignment, size_t size ) { // alignment must be >= sizeof(void*) if( alignment < sizeof( void* ) ) @@ -789,7 +787,6 @@ void* aligned_alloc( size_t alignment, size_t size ) } return NULL; } -#endif #elif !defined(_WIN32) #include // for aligned_alloc() #endif @@ -825,6 +822,8 @@ void* aligned_alloc( size_t alignment, size_t size ) #ifndef VMA_SYSTEM_ALIGNED_MALLOC #if defined(_WIN32) #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_malloc((size), (alignment))) + #elif defined(__APPLE__) + #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (_aligned_alloc((alignment), (size) )) #else #define VMA_SYSTEM_ALIGNED_MALLOC(size, alignment) (aligned_alloc((alignment), (size) )) #endif