vk_instance: Set moltenvk configuration

This commit is contained in:
GPUCode 2023-08-13 19:28:28 +03:00
parent 6c391971c6
commit ba9f1f8ae9
4 changed files with 1121 additions and 0 deletions

View file

@ -242,6 +242,9 @@ target_include_directories(vma SYSTEM INTERFACE ./vma/include)
# vulkan-headers # vulkan-headers
add_library(vulkan-headers INTERFACE) add_library(vulkan-headers INTERFACE)
target_include_directories(vulkan-headers SYSTEM INTERFACE ./vulkan-headers/include) target_include_directories(vulkan-headers SYSTEM INTERFACE ./vulkan-headers/include)
if (APPLE)
target_include_directories(vulkan-headers SYSTEM INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/MoltenVK)
endif()
# adrenotools # adrenotools
if (ANDROID) if (ANDROID)

1071
externals/moltenvk/mvk_config.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,10 @@
#include <vk_mem_alloc.h> #include <vk_mem_alloc.h>
#ifdef __APPLE__
#include <mvk_config.h>
#endif
namespace Vulkan { namespace Vulkan {
namespace { namespace {
@ -537,6 +541,12 @@ bool Instance::CreateDevice() {
#undef PROP_GET #undef PROP_GET
#undef FEAT_SET #undef FEAT_SET
#ifdef __APPLE__
if (!SetMoltenVkConfig()) {
LOG_WARNING(Render_Vulkan, "Unable to set MoltenVK configuration");
}
#endif
try { try {
device = physical_device.createDeviceUnique(device_chain.get()); device = physical_device.createDeviceUnique(device_chain.get());
} catch (vk::ExtensionNotPresentError& err) { } catch (vk::ExtensionNotPresentError& err) {
@ -597,4 +607,38 @@ void Instance::CollectToolingInfo() {
} }
} }
bool Instance::SetMoltenVkConfig() {
#ifdef __APPLE__
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;
}
mvk_config.synchronousQueueSubmits = Settings::values.async_presentation.GetValue();
mvk_config.resumeLostDevice = true;
mvk_config.shouldMaximizeConcurrentCompilation = true;
if (_vkSetMoltenVKConfigurationMVK(VK_NULL_HANDLE, &mvk_config, &mvk_config_size) !=
VK_SUCCESS) {
return false;
}
#endif
return true;
}
} // namespace Vulkan } // namespace Vulkan

View file

@ -256,6 +256,9 @@ private:
void CollectTelemetryParameters(); void CollectTelemetryParameters();
void CollectToolingInfo(); void CollectToolingInfo();
/// Sets MoltenVK configuration to the desired state.
bool SetMoltenVkConfig();
private: private:
std::shared_ptr<Common::DynamicLibrary> library; std::shared_ptr<Common::DynamicLibrary> library;
vk::UniqueInstance instance; vk::UniqueInstance instance;