diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 7625c060..3029f889 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -29,6 +29,12 @@ option(USE_PRECOMPILED_HEADERS option(OPENAL "Use OpenAL soft instead of XAudio2" OFF) +option(FFMPEG + "Use FMPEG to render Bink videos" ON) + +option(BINKDEC + "Use included libbinkdec to render Bink videos" OFF) + option(SPIRV_SHADERC "Compile SPIR-V shader byte code using shaderc instead of using Glslang directly" OFF) @@ -72,18 +78,10 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)" OR CMAKE_OSX_AR endif() # SRS - Turn off MMX/SSE intrinsics when cross-compiling from Apple x86_64 to arm64 -if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)|(e2k)|(E2K)" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "(arm64)|(x64)") +if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)|(e2k)|(E2K)" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES "arm64") option(USE_INTRINSICS_SSE "Compile using SSE intrinsics (e.g mmx, sse, msse2)" ON) - - option(FFMPEG "Use FMPEG to render Bink videos" ON) - - option(BINKDEC "Use included libbinkdec to render Bink videos" OFF) else() option(USE_INTRINSICS_SSE "Compile using SSE intrinsics (e.g mmx, sse, msse2)" OFF) - - option(FFMPEG "Use FMPEG to render Bink videos" OFF) - - option(BINKDEC "Use included libbinkdec to render Bink videos" ON) endif() if(FFMPEG AND BINKDEC) @@ -94,14 +92,10 @@ if(UNIX) set(OPENAL ON) set(USE_DX12 OFF) set(USE_VULKAN ON) - set(USE_NVRHI ON) - #set(FFMPEG OFF) - #set(BINKDEC ON) # SRS - Disable precompiled headers when cross-compiling on OSX, e.g. when creating universal binaries - if((CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64" AND CMAKE_OSX_ARCHITECTURES MATCHES "arm64" ) OR - # (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64" AND CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") - (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64") OR (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x64")) + if((CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_OSX_ARCHITECTURES MATCHES "arm64" ) OR + (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64" AND CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")) set(USE_PRECOMPILED_HEADERS OFF) endif() endif() @@ -384,6 +378,8 @@ if(USE_VULKAN) if(APPLE) # SRS - Enable Beta extensions for VULKAN_SDK portability subset features on OSX add_definitions(-DVK_ENABLE_BETA_EXTENSIONS) + # SRS - Explicitly define dxc path so find_package(DXCspirv) uses the specified Vulkan SDK location on OSX + set(DXC_SPIRV_EXECUTABLE $ENV{VULKAN_SDK}/bin/dxc CACHE FILEPATH "Path to SPIR-V shader compiler." FORCE) # SRS - Optionally link directly to MoltenVK headers/library for runtime config functions on OSX if(USE_MoltenVK) add_definitions(-DUSE_MoltenVK) @@ -1087,7 +1083,7 @@ file(GLOB SDL_INCLUDES sys/sdl/*.h) file(GLOB SDL_SOURCES sys/sdl/*.cpp) if(UNIX) - #if(USE_VULKAN OR USE_VULKAN) + #if(USE_VULKAN) get_filename_component(sdl_glimp_cpp_full_path ${CMAKE_CURRENT_SOURCE_DIR}/sys/sdl/sdl_glimp.cpp ABSOLUTE) list(REMOVE_ITEM SDL_SOURCES "${sdl_glimp_cpp_full_path}") #else() @@ -1679,7 +1675,6 @@ else() add_definitions(-DUSE_FFMPEG) include_directories(${FFMPEG_INCLUDE_DIR}) - link_directories(${FFMPEG_LIBRARIES_DIRS}) endif() find_package(SDL2 REQUIRED) diff --git a/neo/cmake-macos-opengl-release.sh b/neo/cmake-macos-opengl-release.sh deleted file mode 100755 index 7981fd5b..00000000 --- a/neo/cmake-macos-opengl-release.sh +++ /dev/null @@ -1,6 +0,0 @@ -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 -DFFMPEG=OFF -DBINKDEC=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 deleted file mode 100755 index ce82e714..00000000 --- a/neo/cmake-macos-opengl-retail.sh +++ /dev/null @@ -1,6 +0,0 @@ -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 -DFFMPEG=OFF -DBINKDEC=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-release.sh b/neo/cmake-macos-vulkan-release.sh index d95ccba1..9c9db4cb 100755 --- a/neo/cmake-macos-vulkan-release.sh +++ b/neo/cmake-macos-vulkan-release.sh @@ -3,4 +3,4 @@ rm -rf build-vulkan mkdir build-vulkan cd build-vulkan # 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 -DFFMPEG=OFF -DBINKDEC=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 +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG -DNO_MULTI_CONFIG" -DCMAKE_OSX_DEPLOYMENT_TARGET=12.1 -DFFMPEG=OFF -DBINKDEC=ON -DUSE_VULKAN=ON -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 8292b1b1..386796b0 100755 --- a/neo/cmake-macos-vulkan-retail.sh +++ b/neo/cmake-macos-vulkan-retail.sh @@ -3,4 +3,4 @@ rm -rf build-vulkan mkdir build-vulkan cd build-vulkan # 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 -DFFMPEG=OFF -DBINKDEC=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 +cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG -DNO_MULTI_CONFIG -DID_RETAIL" -DCMAKE_OSX_DEPLOYMENT_TARGET=12.1 -DFFMPEG=OFF -DBINKDEC=ON -DUSE_VULKAN=ON -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-debug.sh b/neo/cmake-xcode-opengl-debug.sh deleted file mode 100755 index fa5e1453..00000000 --- a/neo/cmake-xcode-opengl-debug.sh +++ /dev/null @@ -1,5 +0,0 @@ -cd .. -rm -rf xcode-opengl-debug -mkdir xcode-opengl-debug -cd xcode-opengl-debug -cmake -G Xcode -DCMAKE_BUILD_TYPE=Debug -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-opengl-release.sh b/neo/cmake-xcode-opengl-release.sh deleted file mode 100755 index 90b06348..00000000 --- a/neo/cmake-xcode-opengl-release.sh +++ /dev/null @@ -1,5 +0,0 @@ -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" -DSDL2=ON -DFFMPEG=OFF -DBINKDEC=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-opengl-universal.sh b/neo/cmake-xcode-opengl-universal.sh deleted file mode 100755 index f5794814..00000000 --- a/neo/cmake-xcode-opengl-universal.sh +++ /dev/null @@ -1,6 +0,0 @@ -cd .. -rm -rf xcode-opengl-universal -mkdir xcode-opengl-universal -cd xcode-opengl-universal -# note: universal openal-soft library and include paths assume MacPorts install locations -cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DSDL2=ON -DFFMPEG=OFF -DBINKDEC=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DOPENAL_LIBRARY=/opt/local/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/opt/local/include ../neo -Wno-dev diff --git a/neo/cmake-xcode-vulkan-debug.sh b/neo/cmake-xcode-vulkan-debug.sh index 3d8a1e3d..6e9489a0 100755 --- a/neo/cmake-xcode-vulkan-debug.sh +++ b/neo/cmake-xcode-vulkan-debug.sh @@ -4,7 +4,7 @@ mkdir xcode-vulkan-debug cd xcode-vulkan-debug # note 1: remove or set -DCMAKE_SUPPRESS_REGENERATION=OFF to reenable ZERO_CHECK target which checks for CMakeLists.txt changes and re-runs CMake before builds # however, if ZERO_CHECK is reenabled **must** add VULKAN_SDK location to Xcode Custom Paths (under Prefs/Locations) otherwise build failures may occur -# note 2: env variable MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1 enables MoltenVK's image view swizzle which may be required on older macOS versions or hardware (see vulkaninfo) -# note 3: env variable MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=0 disables MoltenVK's use of Metal argument buffers, which then removes the limit on sampler allocation -# note 4: env variable VK_LAYER_MESSAGE_ID_FILTER=0xb408bc0b suppresses validation layer error messages caused by exceeding the maxSamplerAllocationCount limit -cmake -G Xcode -DCMAKE_BUILD_TYPE=Debug -DSDL2=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_XCODE_SCHEME_ENVIRONMENT="MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1;MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=0;VK_LAYER_MESSAGE_ID_FILTER=0xb408bc0b" -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 +# note 2: policy CMAKE_POLICY_DEFAULT_CMP0142=NEW suppresses non-existant per-config suffixes on Xcode library search paths, works for cmake version 3.25 and later +#note 3: env variable MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1 enables MoltenVK's image view swizzle which may be required on older macOS versions or hardware (see vulkaninfo) +# note 4: env variable MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=2 enables MoltenVK's use of Metal argument buffers only if VK_EXT_descriptor_indexing is enabled +cmake -G Xcode -DCMAKE_BUILD_TYPE=Debug -DUSE_VULKAN=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_XCODE_SCHEME_ENVIRONMENT="MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE=1;MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=2" -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -DCMAKE_POLICY_DEFAULT_CMP0142=NEW -Wno-dev diff --git a/neo/cmake-xcode-vulkan-release.sh b/neo/cmake-xcode-vulkan-release.sh index 8c0befcd..fe0aba3c 100755 --- a/neo/cmake-xcode-vulkan-release.sh +++ b/neo/cmake-xcode-vulkan-release.sh @@ -2,6 +2,7 @@ cd .. rm -rf xcode-vulkan-release mkdir xcode-vulkan-release cd xcode-vulkan-release -# remove or set -DCMAKE_SUPPRESS_REGENERATION=OFF to reenable ZERO_CHECK target which checks for CMakeLists.txt changes and re-runs CMake before builds -# however, if ZERO_CHECK is reenabled **must** add VULKAN_SDK location to Xcode Custom Paths (under Prefs/Locations) otherwise build failures may occur -cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DSDL2=ON -DFFMPEG=OFF -DBINKDEC=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 +# note 1: remove or set -DCMAKE_SUPPRESS_REGENERATION=OFF to reenable ZERO_CHECK target which checks for CMakeLists.txt changes and re-runs CMake before builds +# however, if ZERO_CHECK is reenabled **must** add VULKAN_SDK location to Xcode Custom Paths (under Prefs/Locations) otherwise build failures may occur +# note 2: policy CMAKE_POLICY_DEFAULT_CMP0142=NEW suppresses non-existant per-config suffixes on Xcode library search paths, works for cmake version 3.25 and later +cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DFFMPEG=OFF -DBINKDEC=ON -DUSE_VULKAN=ON -DUSE_MoltenVK=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_XCODE_SCHEME_ENABLE_GPU_API_VALIDATION=OFF -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/usr/local/opt/openal-soft/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/usr/local/opt/openal-soft/include ../neo -DCMAKE_POLICY_DEFAULT_CMP0142=NEW -Wno-dev diff --git a/neo/cmake-xcode-vulkan-universal.sh b/neo/cmake-xcode-vulkan-universal.sh index 30d88cdd..7e82faaa 100755 --- a/neo/cmake-xcode-vulkan-universal.sh +++ b/neo/cmake-xcode-vulkan-universal.sh @@ -2,7 +2,8 @@ cd .. rm -rf xcode-vulkan-universal mkdir xcode-vulkan-universal cd xcode-vulkan-universal -# remove or set -DCMAKE_SUPPRESS_REGENERATION=OFF to reenable ZERO_CHECK target which checks for CMakeLists.txt changes and re-runs CMake before builds -# however, if ZERO_CHECK is reenabled **must** add VULKAN_SDK location to Xcode Custom Paths (under Prefs/Locations) otherwise build failures may occur -# note: universal openal-soft library and include paths assume MacPorts install locations -cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DSDL2=ON -DFFMPEG=OFF -DBINKDEC=ON -DUSE_VULKAN=ON -DSPIRV_SHADERC=OFF -DUSE_MoltenVK=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/opt/local/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/opt/local/include ../neo -Wno-dev +# note 1: remove or set -DCMAKE_SUPPRESS_REGENERATION=OFF to reenable ZERO_CHECK target which checks for CMakeLists.txt changes and re-runs CMake before builds +# however, if ZERO_CHECK is reenabled **must** add VULKAN_SDK location to Xcode Custom Paths (under Prefs/Locations) otherwise build failures may occur +# note 2: policy CMAKE_POLICY_DEFAULT_CMP0142=NEW suppresses non-existant per-config suffixes on Xcode library search paths, works for cmake version 3.25 and later +# note 3: universal openal-soft library and include paths assume MacPorts install locations +cmake -G Xcode -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_CONFIGURATION_TYPES="Release;MinSizeRel;RelWithDebInfo" -DFFMPEG=OFF -DBINKDEC=ON -DUSE_VULKAN=ON -DUSE_MoltenVK=ON -DCMAKE_XCODE_GENERATE_SCHEME=ON -DCMAKE_XCODE_SCHEME_ENABLE_GPU_API_VALIDATION=OFF -DCMAKE_SUPPRESS_REGENERATION=ON -DOPENAL_LIBRARY=/opt/local/lib/libopenal.dylib -DOPENAL_INCLUDE_DIR=/opt/local/include ../neo -DCMAKE_POLICY_DEFAULT_CMP0142=NEW -Wno-dev diff --git a/neo/compileshaders.cmake b/neo/compileshaders.cmake index 575cacda..69f405f1 100644 --- a/neo/compileshaders.cmake +++ b/neo/compileshaders.cmake @@ -100,7 +100,7 @@ function(compile_shaders) --compiler ${FXC_EXECUTABLE}) endif() - if (params_SPIRV_DXC AND USE_NVRHI_VULKAN) + if (params_SPIRV_DXC AND USE_VULKAN) if (NOT DXC_SPIRV_EXECUTABLE) message(FATAL_ERROR "compile_shaders: DXC for SPIR-V not found --- please set DXC_SPIRV_EXECUTABLE to the full path to the DXC binary") endif() diff --git a/neo/renderer/Model_local.h b/neo/renderer/Model_local.h index 48dc426f..c25e423d 100644 --- a/neo/renderer/Model_local.h +++ b/neo/renderer/Model_local.h @@ -218,7 +218,7 @@ class idRenderModelMD5 : public idRenderModelStatic { friend class idRenderModelGLTF; public: - void InitFromFile( const char* fileName, const idImportOptions* options ); + void InitFromFile( const char* fileName, const idImportOptions* options ) override; bool LoadBinaryModel( idFile* file, const ID_TIME_T sourceTimeStamp ) override; void WriteBinaryModel( idFile* file, ID_TIME_T* _timeStamp = NULL ) const override; dynamicModel_t IsDynamicModel() const override; diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index e113f8f7..4c16a3a2 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -1422,7 +1422,7 @@ struct glimpParms_t // Helper functions for using SDL2 and Vulkan on Linux. std::vector get_required_extensions(); #if defined( USE_NVRHI ) - bool CreateSDLWindowSurface( VkInstance instance, VkSurfaceKHR* surface ); + vk::Result CreateSDLWindowSurface( vk::Instance instance, vk::SurfaceKHR* surface ); #else extern vulkanContext_t vkcontext; #endif diff --git a/neo/shaders/builtin/video/bink.ps.hlsl b/neo/shaders/builtin/video/bink.ps.hlsl index cb8b78ba..264ed8ab 100644 --- a/neo/shaders/builtin/video/bink.ps.hlsl +++ b/neo/shaders/builtin/video/bink.ps.hlsl @@ -30,11 +30,11 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -Texture2D t_Y : register( t0 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_Cr : register( t1 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_Cb : register( t2 VK_DESCRIPTOR_SET( 1 ) ); +Texture2D t_Y : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Cr : register( t1 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Cb : register( t2 VK_DESCRIPTOR_SET( 0 ) ); -SamplerState LinearSampler : register( s0 VK_DESCRIPTOR_SET( 2 ) ); +SamplerState LinearSampler : register( s0 VK_DESCRIPTOR_SET( 1 ) ); struct PS_IN { @@ -67,4 +67,4 @@ void main( PS_IN fragment, out PS_OUT result ) color *= rpColor; result.color = sRGBAToLinearRGBA( color ); -} \ No newline at end of file +} diff --git a/neo/shaders/builtin/video/bink_gui.ps.hlsl b/neo/shaders/builtin/video/bink_gui.ps.hlsl index bc9eb3da..9a10845c 100644 --- a/neo/shaders/builtin/video/bink_gui.ps.hlsl +++ b/neo/shaders/builtin/video/bink_gui.ps.hlsl @@ -30,11 +30,11 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* -Texture2D t_Y : register( t0 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_Cr : register( t1 VK_DESCRIPTOR_SET( 1 ) ); -Texture2D t_Cb : register( t2 VK_DESCRIPTOR_SET( 1 ) ); +Texture2D t_Y : register( t0 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Cr : register( t1 VK_DESCRIPTOR_SET( 0 ) ); +Texture2D t_Cb : register( t2 VK_DESCRIPTOR_SET( 0 ) ); -SamplerState LinearSampler : register( s0 VK_DESCRIPTOR_SET( 2 ) ); +SamplerState LinearSampler : register( s0 VK_DESCRIPTOR_SET( 1 ) ); struct PS_IN { float4 position : SV_Position; @@ -69,4 +69,4 @@ void main( PS_IN fragment, out PS_OUT result ) float4 color = ( binkImage * fragment.color ) + fragment.texcoord1; result.color.xyz = color.xyz * color.w; result.color.w = color.w; -} \ No newline at end of file +} diff --git a/neo/sys/DeviceManager_VK.cpp b/neo/sys/DeviceManager_VK.cpp index e0166340..1a1d9c41 100644 --- a/neo/sys/DeviceManager_VK.cpp +++ b/neo/sys/DeviceManager_VK.cpp @@ -30,6 +30,10 @@ #include #include +// SRS - optionally needed for VK_MVK_MOLTENVK_EXTENSION_NAME and MoltenVK runtime config visibility +#if defined(__APPLE__) && defined( USE_MoltenVK ) + #include +#endif #include // Define the Vulkan dynamic dispatcher - this needs to occur in exactly one cpp file in the program. @@ -475,7 +479,7 @@ void DeviceManager_VK::installDebugCallback() .setPfnCallback( vulkanDebugCallback ) .setPUserData( this ); - vk::Result res = m_VulkanInstance.createDebugReportCallbackEXT( &info, nullptr, &m_DebugReportCallback ); + const vk::Result res = m_VulkanInstance.createDebugReportCallbackEXT( &info, nullptr, &m_DebugReportCallback ); assert( res == vk::Result::eSuccess ); } @@ -673,7 +677,7 @@ bool DeviceManager_VK::findQueueFamilies( vk::PhysicalDevice physicalDevice, vk: vk::Bool32 presentSupported; // SRS - Use portable implmentation for detecting presentation support vs. Windows-specific Vulkan call if( queueFamily.queueCount > 0 && - vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevice, i, surface, &presentSupported ) == VK_SUCCESS ) + physicalDevice.getSurfaceSupportKHR( i, surface, &presentSupported ) == vk::Result::eSuccess ) { if( presentSupported ) { @@ -907,26 +911,22 @@ bool DeviceManager_VK::createDevice() */ bool DeviceManager_VK::createWindowSurface() { - VkResult err = VK_SUCCESS; - // Create the platform-specific surface #if defined( VULKAN_USE_PLATFORM_SDL ) // SRS - Support generic SDL platform for linux and macOS - if( !CreateSDLWindowSurface( m_VulkanInstance, ( VkSurfaceKHR* )&m_WindowSurface ) ) - { - err = VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; - } + const vk::Result res = CreateSDLWindowSurface( m_VulkanInstance, &m_WindowSurface ); + #elif defined( VK_USE_PLATFORM_WIN32_KHR ) - VkWin32SurfaceCreateInfoKHR surfaceCreateInfo = {}; - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - surfaceCreateInfo.hinstance = ( HINSTANCE )windowInstance; - surfaceCreateInfo.hwnd = ( HWND )windowHandle; - err = vkCreateWin32SurfaceKHR( m_VulkanInstance, &surfaceCreateInfo, nullptr, ( VkSurfaceKHR* )&m_WindowSurface ); + auto surfaceCreateInfo = vk::Win32SurfaceCreateInfoKHR() + .setHinstance( ( HINSTANCE )windowInstance ) + .setHwnd( ( HWND )windowHandle ); + + const vk::Result res = m_VulkanInstance.createWin32SurfaceKHR( &surfaceCreateInfo, nullptr, &m_WindowSurface ); #endif - if( err != VK_SUCCESS ) + if( res != vk::Result::eSuccess ) { - common->FatalError( "Failed to create a Vulkan window surface, error code = %s", nvrhi::vulkan::resultToString( err ) ); + common->FatalError( "Failed to create a Vulkan window surface, error code = %s", nvrhi::vulkan::resultToString( res ) ); return false; } @@ -1034,12 +1034,17 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain() enabledExtensions.instance.insert( VK_EXT_DEBUG_REPORT_EXTENSION_NAME ); #if defined(__APPLE__) && defined( USE_MoltenVK ) enabledExtensions.layers.insert( "MoltenVK" ); -#else - enabledExtensions.layers.insert( "VK_LAYER_KHRONOS_validation" ); -#endif } - const vk::DynamicLoader dl; + // SRS - when USE_MoltenVK defined, load libMoltenVK vs. the default libvulkan + static const vk::DynamicLoader dl( "libMoltenVK.dylib" ); +#else + enabledExtensions.layers.insert( "VK_LAYER_KHRONOS_validation" ); + } + + // SRS - make static so ~DynamicLoader() does not prematurely unload vulkan dynamic lib + static const vk::DynamicLoader dl; +#endif const PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = // NOLINT(misc-misplaced-const) dl.getProcAddress( "vkGetInstanceProcAddr" ); VULKAN_HPP_DEFAULT_DISPATCHER.init( vkGetInstanceProcAddr ); @@ -1075,6 +1080,36 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain() CHECK( createWindowSurface() ); CHECK( pickPhysicalDevice() ); CHECK( findQueueFamilies( m_VulkanPhysicalDevice, m_WindowSurface ) ); + + // SRS - when USE_MoltenVK defined, set MoltenVK runtime configuration parameters on macOS +#if defined(__APPLE__) && defined( USE_MoltenVK ) + vk::PhysicalDeviceFeatures2 deviceFeatures2; + vk::PhysicalDevicePortabilitySubsetFeaturesKHR portabilityFeatures; + deviceFeatures2.setPNext( &portabilityFeatures ); + m_VulkanPhysicalDevice.getFeatures2( &deviceFeatures2 ); + + MVKConfiguration pConfig; + size_t pConfigSize = sizeof( pConfig ); + + vkGetMoltenVKConfigurationMVK( m_VulkanInstance, &pConfig, &pConfigSize ); + + // SRS - If we don't have native image view swizzle, enable MoltenVK's image view swizzle feature + if( portabilityFeatures.imageViewFormatSwizzle == VK_FALSE ) + { + idLib::Printf( "Enabling MoltenVK's image view swizzle...\n" ); + pConfig.fullImageViewSwizzle = VK_TRUE; + vkSetMoltenVKConfigurationMVK( m_VulkanInstance, &pConfig, &pConfigSize ); + } + + // SRS - Turn MoltenVK's Metal argument buffer feature on for descriptor indexing only + if( pConfig.useMetalArgumentBuffers == MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS_NEVER ) + { + idLib::Printf( "Enabling MoltenVK's Metal argument buffers for descriptor indexing...\n" ); + pConfig.useMetalArgumentBuffers = MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS_DESCRIPTOR_INDEXING; + vkSetMoltenVKConfigurationMVK( m_VulkanInstance, &pConfig, &pConfigSize ); + } +#endif + CHECK( createDevice() ); auto vecInstanceExt = stringSetToVector( enabledExtensions.instance ); diff --git a/neo/sys/posix/posix_main.cpp b/neo/sys/posix/posix_main.cpp index 254bd450..481bf32d 100644 --- a/neo/sys/posix/posix_main.cpp +++ b/neo/sys/posix/posix_main.cpp @@ -101,6 +101,7 @@ const char* Sys_DefaultSavePath() if( base_path ) { savepath = SDL_strdup( base_path ); + savepath.StripTrailing( '/' ); SDL_free( base_path ); } #else @@ -410,8 +411,9 @@ Sys_DefaultBasePath Get the default base path - binary image path -- MacOS app bundle resources directory path // SRS - Added MacOS app bundle resources path - current directory +- macOS app bundle resources directory path // SRS - added macOS app bundle resources path +- build directory path // SRS - added build directory path - hardcoded Try to be intelligent: if there is no BASE_GAMEDIR, try the next path ================ @@ -419,11 +421,12 @@ Try to be intelligent: if there is no BASE_GAMEDIR, try the next path const char* Sys_DefaultBasePath() { struct stat st; - idStr testbase; + idStr testbase, exepath = {}; basepath = Sys_EXEPath(); if( basepath.Length() ) { basepath.StripFilename(); + exepath = basepath; testbase = basepath; testbase += "/"; testbase += BASE_GAMEDIR; @@ -435,20 +438,6 @@ const char* Sys_DefaultBasePath() { common->Printf( "no '%s' directory in exe path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } -#if defined(__APPLE__) // SRS - - Added check for MacOS app bundle resources path - basepath += "/../Resources"; - testbase = basepath; - testbase += "/"; - testbase += BASE_GAMEDIR; - if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) - { - return basepath.c_str(); - } - else - { - common->Printf( "no '%s' directory in MacOS app bundle resources path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); - } -#endif } if( basepath != Posix_Cwd() ) { @@ -465,6 +454,41 @@ const char* Sys_DefaultBasePath() common->Printf( "no '%s' directory in cwd path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); } } + if( exepath.Length() ) + { +#if defined(__APPLE__) + // SRS - Check for macOS app bundle resources path + basepath = exepath + "/../Resources"; + testbase = basepath; + testbase += "/"; + testbase += BASE_GAMEDIR; + if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) + { + return basepath.c_str(); + } + else + { + common->Printf( "no '%s' directory in macOS app bundle resources path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); + } +#endif + // SRS - Check for macOS/linux build path (directory structure with build dir and possible config suffix) +#if defined(__APPLE__) && !defined( NO_MULTI_CONFIG ) + basepath = exepath + "/../.."; // for macOS Xcode builds with Debug/Release/etc config suffix +#else + basepath = exepath + "/.."; // for linux and macOS single-config makefile builds +#endif + testbase = basepath; + testbase += "/"; + testbase += BASE_GAMEDIR; + if( stat( testbase.c_str(), &st ) != -1 && S_ISDIR( st.st_mode ) ) + { + return basepath.c_str(); + } + else + { + common->Printf( "no '%s' directory in build path %s, skipping\n", BASE_GAMEDIR, basepath.c_str() ); + } + } common->Printf( "WARNING: using hardcoded default base path %s\n", DEFAULT_BASEPATH ); return DEFAULT_BASEPATH; } diff --git a/neo/sys/sdl/sdl_vkimp.cpp b/neo/sys/sdl/sdl_vkimp.cpp index e0ea779e..9f139885 100644 --- a/neo/sys/sdl/sdl_vkimp.cpp +++ b/neo/sys/sdl/sdl_vkimp.cpp @@ -41,10 +41,6 @@ If you have questions concerning this license or the applicable additional terms #include #include #include -// SRS - optinally needed for VK_MVK_MOLTENVK_EXTENSION_NAME visibility -#if defined(__APPLE__) && defined(USE_MoltenVK) - #include -#endif #include #include "renderer/RenderCommon.h" @@ -94,15 +90,15 @@ std::vector get_required_extensions() #if defined( USE_NVRHI ) // SRS - Helper function for creating SDL Vulkan surface within DeviceManager_VK() when NVRHI enabled -bool CreateSDLWindowSurface( VkInstance instance, VkSurfaceKHR* surface ) +vk::Result CreateSDLWindowSurface( vk::Instance instance, vk::SurfaceKHR* surface ) { - if( !SDL_Vulkan_CreateSurface( window, instance, surface ) ) + if( !SDL_Vulkan_CreateSurface( window, ( VkInstance )instance, ( VkSurfaceKHR* )surface ) ) { common->Warning( "Error while creating SDL Vulkan surface: %s", SDL_GetError() ); - return false; + return vk::Result::eErrorSurfaceLostKHR; } - return true; + return vk::Result::eSuccess; } bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, const char* windowTitle )