renderer_vulkan: Update to support MoltenVK 1.2.7 (#7335)
This commit is contained in:
parent
015e42be05
commit
2ce0a9e899
7 changed files with 48 additions and 1130 deletions
|
@ -15,10 +15,6 @@
|
|||
|
||||
#include <vk_mem_alloc.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mvk_config.h>
|
||||
#endif
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
namespace {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
|
|
@ -289,9 +289,6 @@ private:
|
|||
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;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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()),
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue