Skip to content

Commit

Permalink
renderer_vulkan: Update to support MoltenVK 1.2.7 (#7335)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveice10 authored Jan 9, 2024
1 parent 015e42b commit 2ce0a9e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 1,130 deletions.
2 changes: 1 addition & 1 deletion CMakeModules/DownloadExternals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function(download_moltenvk)
set(MOLTENVK_TAR "${CMAKE_BINARY_DIR}/externals/MoltenVK.tar")
if (NOT EXISTS ${MOLTENVK_DIR})
if (NOT EXISTS ${MOLTENVK_TAR})
file(DOWNLOAD https://github.com/KhronosGroup/MoltenVK/releases/latest/download/MoltenVK-all.tar
file(DOWNLOAD https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.7-rc1/MoltenVK-all.tar
${MOLTENVK_TAR} SHOW_PROGRESS)
endif()

Expand Down
3 changes: 0 additions & 3 deletions externals/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,6 @@ if(USE_SYSTEM_VULKAN_HEADERS)
else()
target_include_directories(vulkan-headers SYSTEM INTERFACE ./vulkan-headers/include)
endif()
if (APPLE)
target_include_directories(vulkan-headers SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK)
endif()

# adrenotools
if (ANDROID AND "arm64" IN_LIST ARCHITECTURE)
Expand Down
1,071 changes: 0 additions & 1,071 deletions externals/moltenvk/mvk_config.h

This file was deleted.

2 changes: 1 addition & 1 deletion externals/vulkan-headers
Submodule vulkan-headers updated 68 files
+0 −1 .github/ISSUE_TEMPLATE/bug_report.md
+12 −0 .github/dependabot.yml
+0 −1 .github/pull_request_template.md
+16 −64 .github/workflows/ci.yml
+7 −1 BUILD.gn
+5 −0 CMakeLists.txt
+0 −1 CONTRIBUTING.md
+0 −105 INTEGRATION.md
+6 −10 README.md
+2 −1 include/vk_video/vulkan_video_codec_h264std.h
+1 −1 include/vk_video/vulkan_video_codec_h264std_decode.h
+7 −6 include/vk_video/vulkan_video_codec_h264std_encode.h
+2 −1 include/vk_video/vulkan_video_codec_h265std.h
+1 −1 include/vk_video/vulkan_video_codec_h265std_decode.h
+20 −19 include/vk_video/vulkan_video_codec_h265std_encode.h
+1 −1 include/vk_video/vulkan_video_codecs_common.h
+1 −1 include/vulkan/vk_platform.h
+1,949 −231 include/vulkan/vulkan.cppm
+1 −1 include/vulkan/vulkan.h
+4,490 −1,681 include/vulkan/vulkan.hpp
+27 −1 include/vulkan/vulkan_android.h
+1 −593 include/vulkan/vulkan_beta.h
+1,502 −214 include/vulkan/vulkan_core.h
+1 −1 include/vulkan/vulkan_directfb.h
+994 −533 include/vulkan/vulkan_enums.hpp
+2,084 −800 include/vulkan/vulkan_extension_inspection.hpp
+2 −1 include/vulkan/vulkan_format_traits.hpp
+1 −1 include/vulkan/vulkan_fuchsia.h
+3,162 −2,359 include/vulkan/vulkan_funcs.hpp
+1 −1 include/vulkan/vulkan_ggp.h
+1,073 −299 include/vulkan/vulkan_handles.hpp
+1,262 −414 include/vulkan/vulkan_hash.hpp
+297 −0 include/vulkan/vulkan_hpp_macros.hpp
+1 −1 include/vulkan/vulkan_ios.h
+1 −1 include/vulkan/vulkan_macos.h
+1 −1 include/vulkan/vulkan_metal.h
+4,654 −2,759 include/vulkan/vulkan_raii.hpp
+1 −1 include/vulkan/vulkan_screen.h
+1,080 −0 include/vulkan/vulkan_shared.hpp
+616 −172 include/vulkan/vulkan_static_assertions.hpp
+9,807 −2,814 include/vulkan/vulkan_structs.hpp
+520 −330 include/vulkan/vulkan_to_string.hpp
+1 −1 include/vulkan/vulkan_vi.h
+32 −26 include/vulkan/vulkan_video.hpp
+1 −1 include/vulkan/vulkan_wayland.h
+1 −1 include/vulkan/vulkan_win32.h
+1 −1 include/vulkan/vulkan_xcb.h
+1 −1 include/vulkan/vulkan_xlib.h
+1 −1 include/vulkan/vulkan_xlib_xrandr.h
+1 −1 registry/apiconventions.py
+1 −1 registry/cgenerator.py
+3 −4 registry/generator.py
+0 −1,116 registry/genvk.py
+9 −30 registry/parse_dependency.py
+6 −88 registry/profiles/VP_KHR_roadmap_2022.json
+1 −1 registry/reg.py
+87 −5 registry/spec_tools/conventions.py
+1 −2 registry/spec_tools/util.py
+43,631 −18,698 registry/validusage.json
+31 −27 registry/video.xml
+1,327 −513 registry/vk.xml
+15 −3 registry/vkconventions.py
+25 −38 tests/CMakeLists.txt
+0 −30 tests/add_subdirectory/CMakeLists.txt
+0 −30 tests/find_package/CMakeLists.txt
+73 −0 tests/integration/CMakeLists.txt
+2 −2 tests/vk_icd.c
+2 −2 tests/vk_layer.c
48 changes: 0 additions & 48 deletions src/video_core/renderer_vulkan/vk_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

#include <vk_mem_alloc.h>

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

namespace Vulkan {

namespace {
Expand Down Expand Up @@ -606,12 +602,6 @@ bool Instance::CreateDevice() {
#undef PROP_GET
#undef FEAT_SET

#ifdef __APPLE__
if (!SetMoltenVkConfig()) {
LOG_WARNING(Render_Vulkan, "Unable to set MoltenVK configuration");
}
#endif

try {
device = physical_device.createDeviceUnique(device_chain.get());
} catch (vk::ExtensionNotPresentError& err) {
Expand Down Expand Up @@ -689,42 +679,4 @@ void Instance::CollectToolingInfo() {
}
}

bool Instance::SetMoltenVkConfig() {
#ifdef __APPLE__
std::size_t mvk_config_size = sizeof(MVKConfiguration);
MVKConfiguration mvk_config{};

const auto _vkGetMoltenVKConfigurationMVK =
library->GetSymbol<PFN_vkGetMoltenVKConfigurationMVK>("vkGetMoltenVKConfigurationMVK");
if (!_vkGetMoltenVKConfigurationMVK) {
return false;
}

const auto _vkSetMoltenVKConfigurationMVK =
library->GetSymbol<PFN_vkSetMoltenVKConfigurationMVK>("vkSetMoltenVKConfigurationMVK");
if (!_vkSetMoltenVKConfigurationMVK) {
return false;
}

if (_vkGetMoltenVKConfigurationMVK(VK_NULL_HANDLE, &mvk_config, &mvk_config_size) !=
VK_SUCCESS) {
return false;
}

// Use synchronous queue submits if async presentation is enabled, to avoid threading
// indirection.
mvk_config.synchronousQueueSubmits = Settings::values.async_presentation.GetValue();
// If the device is lost, make an attempt to resume if possible to avoid crashes.
mvk_config.resumeLostDevice = true;
// Maximize concurrency to improve shader compilation performance.
mvk_config.shouldMaximizeConcurrentCompilation = true;

if (_vkSetMoltenVKConfigurationMVK(VK_NULL_HANDLE, &mvk_config, &mvk_config_size) !=
VK_SUCCESS) {
return false;
}
#endif
return true;
}

} // namespace Vulkan
3 changes: 0 additions & 3 deletions src/video_core/renderer_vulkan/vk_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ class Instance {
void CollectTelemetryParameters(Core::TelemetrySession& telemetry);
void CollectToolingInfo();

/// Sets MoltenVK configuration to the desired state.
bool SetMoltenVkConfig();

private:
std::shared_ptr<Common::DynamicLibrary> library;
vk::UniqueInstance instance;
Expand Down
49 changes: 46 additions & 3 deletions src/video_core/renderer_vulkan/vk_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ std::vector<const char*> GetInstanceExtensions(Frontend::WindowSystemType window

// Add the windowing system specific extension
std::vector<const char*> extensions;
extensions.reserve(6);
extensions.reserve(7);

#if defined(__APPLE__)
extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
// For configuring MoltenVK.
extensions.push_back(VK_EXT_LAYER_SETTINGS_EXTENSION_NAME);
#endif

switch (window_type) {
Expand Down Expand Up @@ -281,10 +283,21 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library,
throw std::runtime_error("Failed to load Vulkan driver library");
}

const auto vkGetInstanceProcAddr =
auto vkGetInstanceProcAddr =
library.GetSymbol<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
if (!vkGetInstanceProcAddr) {
#ifdef __APPLE__
// MoltenVK now hides most Vulkan symbols by default to avoid clashes,
// so we may need to use the ICD hook instead.
vkGetInstanceProcAddr =
library.GetSymbol<PFN_vkGetInstanceProcAddr>("vk_icdGetInstanceProcAddr");
if (!vkGetInstanceProcAddr) {
throw std::runtime_error(
"Failed GetSymbol vkGetInstanceProcAddr or vk_icdGetInstanceProcAddr");
}
#else
throw std::runtime_error("Failed GetSymbol vkGetInstanceProcAddr");
#endif
}
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);

Expand Down Expand Up @@ -315,7 +328,7 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library,
layers.push_back("VK_LAYER_LUNARG_api_dump");
}

const vk::InstanceCreateInfo instance_ci = {
vk::InstanceCreateInfo instance_ci = {
.flags = GetInstanceFlags(),
.pApplicationInfo = &application_info,
.enabledLayerCount = static_cast<u32>(layers.size()),
Expand All @@ -324,6 +337,36 @@ vk::UniqueInstance CreateInstance(const Common::DynamicLibrary& library,
.ppEnabledExtensionNames = extensions.data(),
};

#ifdef __APPLE__
// Use synchronous queue submits if async presentation is enabled, to avoid threading
// indirection.
const auto synchronous_queue_submits = Settings::values.async_presentation.GetValue();
// If the device is lost, make an attempt to resume if possible to avoid crashes.
constexpr auto resume_lost_device = true;
// Maximize concurrency to improve shader compilation performance.
constexpr auto maximize_concurrent_compilation = true;

constexpr auto layer_name = "MoltenVK";
const vk::LayerSettingEXT layer_settings[] = {
{layer_name, "MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS", vk::LayerSettingTypeEXT::eBool32, 1,
&synchronous_queue_submits},
{layer_name, "MVK_CONFIG_RESUME_LOST_DEVICE", vk::LayerSettingTypeEXT::eBool32, 1,
&resume_lost_device},
{layer_name, "MVK_CONFIG_SHOULD_MAXIMIZE_CONCURRENT_COMPILATION",
vk::LayerSettingTypeEXT::eBool32, 1, &maximize_concurrent_compilation},
};
const vk::LayerSettingsCreateInfoEXT layer_settings_ci = {
.pNext = nullptr,
.settingCount = static_cast<uint32_t>(std::size(layer_settings)),
.pSettings = layer_settings,
};

if (std::find(extensions.begin(), extensions.end(), VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) !=
extensions.end()) {
instance_ci.pNext = &layer_settings_ci;
}
#endif

auto instance = vk::createInstanceUnique(instance_ci);

VULKAN_HPP_DEFAULT_DISPATCHER.init(*instance);
Expand Down

0 comments on commit 2ce0a9e

Please sign in to comment.