2018-07-11 17:24:30 +02:00
|
|
|
#include <version.h>
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
#include "dxvk_instance.h"
|
2018-05-18 16:47:44 +02:00
|
|
|
#include "dxvk_openvr.h"
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2018-05-16 16:17:39 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
namespace dxvk {
|
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
DxvkInstance::DxvkInstance() {
|
2018-07-11 17:24:30 +02:00
|
|
|
Logger::info(str::format("Game: ", env::getExeName()));
|
|
|
|
Logger::info(str::format("DXVK: ", DXVK_VERSION));
|
|
|
|
|
2018-08-07 16:58:16 +02:00
|
|
|
m_config = Config::getUserConfig();
|
|
|
|
m_config.merge(Config::getAppConfig(env::getExeName()));
|
2018-09-09 13:46:57 +02:00
|
|
|
m_config.logOptions();
|
2018-08-07 14:14:41 +02:00
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
g_vrInstance.initInstanceExtensions();
|
|
|
|
|
|
|
|
m_vkl = new vk::LibraryFn();
|
2018-11-02 14:05:05 +01:00
|
|
|
m_vki = new vk::InstanceFn(true, this->createInstance());
|
2018-06-26 15:51:15 +02:00
|
|
|
|
|
|
|
m_adapters = this->queryAdapters();
|
|
|
|
g_vrInstance.initDeviceExtensions(this);
|
2018-11-20 15:50:01 +01:00
|
|
|
|
|
|
|
m_options = DxvkOptions(m_config);
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxvkInstance::~DxvkInstance() {
|
2017-12-11 19:48:00 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 12:33:26 +02:00
|
|
|
Rc<DxvkAdapter> DxvkInstance::enumAdapters(uint32_t index) const {
|
|
|
|
return index < m_adapters.size()
|
|
|
|
? m_adapters[index]
|
|
|
|
: nullptr;
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkInstance DxvkInstance::createInstance() {
|
2018-07-23 20:07:21 +02:00
|
|
|
DxvkInstanceExtensions insExtensions;
|
|
|
|
|
|
|
|
std::array<DxvkExt*, 3> insExtensionList = {{
|
|
|
|
&insExtensions.khrGetPhysicalDeviceProperties2,
|
|
|
|
&insExtensions.khrSurface,
|
|
|
|
&insExtensions.khrWin32Surface,
|
|
|
|
}};
|
|
|
|
|
|
|
|
DxvkNameSet extensionsEnabled;
|
|
|
|
DxvkNameSet extensionsAvailable = DxvkNameSet::enumInstanceExtensions(m_vkl);
|
2018-05-16 21:38:11 +02:00
|
|
|
|
2018-07-23 20:07:21 +02:00
|
|
|
if (!extensionsAvailable.enableExtensions(
|
|
|
|
insExtensionList.size(),
|
|
|
|
insExtensionList.data(),
|
|
|
|
extensionsEnabled))
|
2018-05-16 21:38:11 +02:00
|
|
|
throw DxvkError("DxvkInstance: Failed to create instance");
|
|
|
|
|
2018-07-23 20:07:21 +02:00
|
|
|
// Enable additional extensions if necessary
|
|
|
|
extensionsEnabled.merge(g_vrInstance.getInstanceExtensions());
|
|
|
|
DxvkNameList extensionNameList = extensionsEnabled.toNameList();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2017-10-11 00:27:33 +02:00
|
|
|
Logger::info("Enabled instance extensions:");
|
2018-07-23 20:07:21 +02:00
|
|
|
this->logNameList(extensionNameList);
|
2018-11-07 21:52:54 +01:00
|
|
|
|
|
|
|
std::string appName = env::getExeName();
|
2017-10-11 00:27:33 +02:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
VkApplicationInfo appInfo;
|
|
|
|
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
|
|
|
appInfo.pNext = nullptr;
|
2018-11-07 21:52:54 +01:00
|
|
|
appInfo.pApplicationName = appName.c_str();
|
2017-10-10 23:32:13 +02:00
|
|
|
appInfo.applicationVersion = 0;
|
|
|
|
appInfo.pEngineName = "DXVK";
|
2018-11-24 10:41:41 +01:00
|
|
|
appInfo.engineVersion = VK_MAKE_VERSION(0, 9, 3);
|
2018-11-07 19:39:38 +01:00
|
|
|
appInfo.apiVersion = VK_MAKE_VERSION(1, 1, 0);
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
VkInstanceCreateInfo info;
|
|
|
|
info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
|
|
|
info.pNext = nullptr;
|
|
|
|
info.flags = 0;
|
|
|
|
info.pApplicationInfo = &appInfo;
|
2018-05-16 22:30:04 +02:00
|
|
|
info.enabledLayerCount = 0;
|
|
|
|
info.ppEnabledLayerNames = nullptr;
|
2018-07-23 20:07:21 +02:00
|
|
|
info.enabledExtensionCount = extensionNameList.count();
|
|
|
|
info.ppEnabledExtensionNames = extensionNameList.names();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
VkInstance result = VK_NULL_HANDLE;
|
2018-11-07 19:39:38 +01:00
|
|
|
VkResult status = m_vkl->vkCreateInstance(&info, nullptr, &result);
|
|
|
|
|
|
|
|
if (status == VK_ERROR_INCOMPATIBLE_DRIVER) {
|
|
|
|
Logger::warn("Failed to create Vulkan 1.1 instance, falling back to 1.0");
|
|
|
|
appInfo.apiVersion = 0; /* some very old drivers may not accept 1.0 */
|
|
|
|
status = m_vkl->vkCreateInstance(&info, nullptr, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != VK_SUCCESS)
|
2017-10-10 23:32:13 +02:00
|
|
|
throw DxvkError("DxvkInstance::createInstance: Failed to create Vulkan instance");
|
2018-11-07 19:39:38 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
std::vector<Rc<DxvkAdapter>> DxvkInstance::queryAdapters() {
|
2018-08-27 14:22:14 +02:00
|
|
|
DxvkDeviceFilter filter;
|
|
|
|
|
2018-06-26 12:33:26 +02:00
|
|
|
uint32_t numAdapters = 0;
|
|
|
|
if (m_vki->vkEnumeratePhysicalDevices(m_vki->instance(), &numAdapters, nullptr) != VK_SUCCESS)
|
|
|
|
throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters");
|
|
|
|
|
|
|
|
std::vector<VkPhysicalDevice> adapters(numAdapters);
|
|
|
|
if (m_vki->vkEnumeratePhysicalDevices(m_vki->instance(), &numAdapters, adapters.data()) != VK_SUCCESS)
|
|
|
|
throw DxvkError("DxvkInstance::enumAdapters: Failed to enumerate adapters");
|
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
std::vector<Rc<DxvkAdapter>> result;
|
2018-08-27 14:22:14 +02:00
|
|
|
for (uint32_t i = 0; i < numAdapters; i++) {
|
|
|
|
Rc<DxvkAdapter> adapter = new DxvkAdapter(this, adapters[i]);
|
|
|
|
|
|
|
|
if (filter.testAdapter(adapter))
|
|
|
|
result.push_back(adapter);
|
|
|
|
}
|
2018-06-26 12:33:26 +02:00
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
std::sort(result.begin(), result.end(),
|
2018-06-26 12:33:26 +02:00
|
|
|
[this] (const Rc<DxvkAdapter>& a, const Rc<DxvkAdapter>& b) -> bool {
|
|
|
|
return a->deviceProperties().deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
|
|
|
|
&& b->deviceProperties().deviceType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU;
|
|
|
|
});
|
2018-06-26 15:51:15 +02:00
|
|
|
|
2018-08-27 14:22:14 +02:00
|
|
|
if (result.size() == 0) {
|
|
|
|
Logger::warn("DXVK: No adapters found. Please check your "
|
|
|
|
"device filter settings and Vulkan setup.");
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:51:15 +02:00
|
|
|
return result;
|
2018-06-26 12:33:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-23 20:07:21 +02:00
|
|
|
void DxvkInstance::logNameList(const DxvkNameList& names) {
|
2017-10-11 00:27:33 +02:00
|
|
|
for (uint32_t i = 0; i < names.count(); i++)
|
|
|
|
Logger::info(str::format(" ", names.name(i)));
|
|
|
|
}
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|