Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac: Update MoltenVk to 1.2.7 #15052

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ci/build-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ arch -x86_64 /usr/local/bin/brew reinstall -f --build-from-source gnutls freetyp
arch -x86_64 /usr/local/bin/brew install llvm@16 glew cmake sdl2 vulkan-headers coreutils
arch -x86_64 /usr/local/bin/brew link -f llvm@16 ffmpeg@5

# moltenvk based on commit for 1.2.6 release
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/4ac0cfaca4c2505abe2fcbcc0ce5816572103a6c/Formula/m/molten-vk.rb
# moltenvk based on commit for 1.2.7 release
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/05a8770c483cfddf5b077667a392d846bc2ad719/Formula/m/molten-vk.rb
arch -x86_64 /usr/local/bin/brew install -f --overwrite ./molten-vk.rb
#export MACOSX_DEPLOYMENT_TARGET=12.0
export CXX=clang++
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/MoltenVK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(ExternalProject)

ExternalProject_Add(moltenvk
GIT_REPOSITORY https://github.com/KhronosGroup/MoltenVK.git
GIT_TAG 9e4ee9e
GIT_TAG 66f6ff1
BUILD_IN_SOURCE 1
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK
CONFIGURE_COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK/fetchDependencies" --macos
Expand Down
5 changes: 5 additions & 0 deletions Utilities/StrFmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ std::string wchar_to_utf8(std::wstring_view src)
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#elif defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Expand All @@ -52,6 +55,8 @@ std::u16string utf8_to_utf16(std::string_view src)
}
#ifdef _MSC_VER
#pragma warning(pop)
#elif defined(__clang__)
#pragma clang diagnostic pop
#else
#pragma GCC diagnostic pop
#endif
Expand Down
31 changes: 0 additions & 31 deletions rpcs3/Emu/RSX/VK/vkutils/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include "util/logs.hpp"
#include "Emu/system_config.h"

#ifdef __APPLE__
#include <MoltenVK/mvk_config.h>
#endif

namespace vk
{
// Global shared render device
Expand Down Expand Up @@ -156,33 +152,6 @@ namespace vk
_vkGetPhysicalDeviceProperties2KHR(dev, &properties2);
props = properties2.properties;

#ifdef __APPLE__
if (instance_extensions.is_supported(VK_MVK_MOLTENVK_EXTENSION_NAME))
{
MVKConfiguration mvk_config = {};
size_t mvk_config_size = sizeof(MVKConfiguration);

PFN_vkGetMoltenVKConfigurationMVK _vkGetMoltenVKConfigurationMVK = nullptr;
_vkGetMoltenVKConfigurationMVK = reinterpret_cast<PFN_vkGetMoltenVKConfigurationMVK>(vkGetInstanceProcAddr(parent, "vkGetMoltenVKConfigurationMVK"));
ensure(_vkGetMoltenVKConfigurationMVK);

PFN_vkSetMoltenVKConfigurationMVK _vkSetMoltenVKConfigurationMVK = nullptr;
_vkSetMoltenVKConfigurationMVK = reinterpret_cast<PFN_vkSetMoltenVKConfigurationMVK>(vkGetInstanceProcAddr(parent, "vkSetMoltenVKConfigurationMVK"));
ensure(_vkSetMoltenVKConfigurationMVK);

CHECK_RESULT_EX(_vkGetMoltenVKConfigurationMVK(VK_NULL_HANDLE, &mvk_config, &mvk_config_size), std::string("Could not get MoltenVK configuration."));

mvk_config.resumeLostDevice = true;
mvk_config.fastMathEnabled = g_cfg.video.disable_msl_fast_math.get() ? MVK_CONFIG_FAST_MATH_NEVER : MVK_CONFIG_FAST_MATH_ON_DEMAND;

CHECK_RESULT_EX(_vkSetMoltenVKConfigurationMVK(VK_NULL_HANDLE, &mvk_config, &mvk_config_size), std::string("Could not set MoltenVK configuration."));
}
else
{
rsx_log.error("Cannot set the MoltenVK configuration because VK_MVK_moltenvk is not supported.\nIf you're using MoltenVK through libvulkan, please manually set the appropriate environment variables instead.");
}
#endif

if (descriptor_indexing_support)
{
if (descriptor_indexing_props.maxUpdateAfterBindDescriptorsInAllPools < 800'000)
Expand Down
32 changes: 29 additions & 3 deletions rpcs3/Emu/RSX/VK/vkutils/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include <algorithm>
#include <vector>

#ifdef __APPLE__
#include <MoltenVK/mvk_vulkan.h>
#include <MoltenVK/mvk_private_api.h>
#endif

namespace vk
{
class supported_extensions
Expand Down Expand Up @@ -133,6 +138,16 @@ namespace vk

std::vector<const char*> extensions;
std::vector<const char*> layers;
const void* next_info = nullptr;

#ifdef __APPLE__
kd-11 marked this conversation as resolved.
Show resolved Hide resolved
// Declare MVK variables here to ensure the lifetime within the entire scope
const VkBool32 setting_true = VK_TRUE;
const int32_t setting_fast_math = g_cfg.video.disable_msl_fast_math.get() ? MVK_CONFIG_FAST_MATH_NEVER : MVK_CONFIG_FAST_MATH_ON_DEMAND;

std::vector<VkLayerSettingEXT> mvk_settings;
VkLayerSettingsCreateInfoEXT mvk_layer_settings_create_info{};
#endif

if (!fast)
{
Expand All @@ -151,10 +166,20 @@ namespace vk
}

#ifdef __APPLE__
#define VK_MVK_MOLTENVK_EXTENSION_NAME "VK_MVK_moltenvk"
if (support.is_supported(VK_MVK_MOLTENVK_EXTENSION_NAME))
if (support.is_supported(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME))
{
extensions.push_back(VK_MVK_MOLTENVK_EXTENSION_NAME);
extensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
layers.push_back(kMVKMoltenVKDriverLayerName);

mvk_settings.push_back(VkLayerSettingEXT{ kMVKMoltenVKDriverLayerName, "MVK_CONFIG_RESUME_LOST_DEVICE", VK_LAYER_SETTING_TYPE_BOOL32_EXT, 1, &setting_true });
mvk_settings.push_back(VkLayerSettingEXT{ kMVKMoltenVKDriverLayerName, "MVK_CONFIG_FAST_MATH_ENABLED", VK_LAYER_SETTING_TYPE_INT32_EXT, 1, &setting_fast_math });

mvk_layer_settings_create_info.sType = VK_STRUCTURE_TYPE_LAYER_SETTINGS_CREATE_INFO_EXT;
mvk_layer_settings_create_info.pNext = next_info;
mvk_layer_settings_create_info.settingCount = static_cast<uint32_t>(mvk_settings.size());
mvk_layer_settings_create_info.pSettings = mvk_settings.data();

next_info = &mvk_layer_settings_create_info;
}
#endif

Expand Down Expand Up @@ -210,6 +235,7 @@ namespace vk
instance_info.ppEnabledLayerNames = layers.data();
instance_info.enabledExtensionCount = fast ? 0 : static_cast<u32>(extensions.size());
instance_info.ppEnabledExtensionNames = fast ? nullptr : extensions.data();
instance_info.pNext = next_info;

if (VkResult result = vkCreateInstance(&instance_info, nullptr, &m_instance); result != VK_SUCCESS)
{
Expand Down