From 552ada02d7086dac422e437e03a3d761c05317c8 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Sun, 30 Jan 2022 12:39:09 -0500 Subject: [PATCH] macOS Vulkan: Check and disable MoltenVK's use of Metal argument buffers for shader allocation scalability (cherry picked from commit 939ab3b6396bd7196ce7f0c16cf59c83ebdc6a4e) --- neo/cmake-xcode-vulkan-debug.sh | 7 ++++--- neo/renderer/Vulkan/RenderBackend_VK.cpp | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/neo/cmake-xcode-vulkan-debug.sh b/neo/cmake-xcode-vulkan-debug.sh index 31464dcc..3d8a1e3d 100755 --- a/neo/cmake-xcode-vulkan-debug.sh +++ b/neo/cmake-xcode-vulkan-debug.sh @@ -4,6 +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 imageViewFormatSwizzle which may be required on older macOS versions or hardware (see vulkaninfo) -# note 3: env variable VK_LAYER_MESSAGE_ID_FILTER=0xb408bc0b suppresses validation layer error messages caused by exceeding 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;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: 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 diff --git a/neo/renderer/Vulkan/RenderBackend_VK.cpp b/neo/renderer/Vulkan/RenderBackend_VK.cpp index c0f901d4..b4943741 100644 --- a/neo/renderer/Vulkan/RenderBackend_VK.cpp +++ b/neo/renderer/Vulkan/RenderBackend_VK.cpp @@ -815,17 +815,26 @@ static void CreateLogicalDeviceAndQueues() vkGetPhysicalDeviceFeatures2( vkcontext.physicalDevice, &deviceFeatures2 ); #if defined(USE_MoltenVK) - // SRS - Check if we have native image swizzling, and if not, enable MoltenVK's emulation + MVKConfiguration pConfig; + size_t pConfigSize = sizeof( pConfig ); + + ID_VK_CHECK( vkGetMoltenVKConfigurationMVK( vkcontext.instance, &pConfig, &pConfigSize ) ); + + // SRS - If we don't have native image view swizzle, enable MoltenVK's image view swizzle feature if( portabilityFeatures.imageViewFormatSwizzle == VK_FALSE ) { - MVKConfiguration pConfig; - size_t pConfigSize = sizeof( pConfig ); - - idLib::Printf( "Enabling MoltenVK fullImageViewSwizzle...\n" ); - ID_VK_CHECK( vkGetMoltenVKConfigurationMVK( vkcontext.instance, &pConfig, &pConfigSize ) ); + idLib::Printf( "Enabling MoltenVK's image view swizzle...\n" ); pConfig.fullImageViewSwizzle = VK_TRUE; ID_VK_CHECK( vkSetMoltenVKConfigurationMVK( vkcontext.instance, &pConfig, &pConfigSize ) ); } + + // SRS - If MoltenVK's Metal argument buffer feature is on, disable it for sampler scalability + if( pConfig.useMetalArgumentBuffers == VK_TRUE ) + { + idLib::Printf( "Disabling MoltenVK's Metal argument buffers...\n" ); + pConfig.useMetalArgumentBuffers = VK_FALSE; + ID_VK_CHECK( vkSetMoltenVKConfigurationMVK( vkcontext.instance, &pConfig, &pConfigSize ) ); + } #endif #else VkPhysicalDeviceFeatures deviceFeatures = {};