mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 18:53:28 +01:00
Detect Vulkan Xlib/Wayland surface support at runtime (#4048)
Detect Vulkan Xlib/Wayland surface support at runtime
This commit is contained in:
parent
d216398596
commit
15d0bdb7cf
@ -3,6 +3,7 @@
|
||||
#include "stdafx.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@ -1135,6 +1136,30 @@ namespace vk
|
||||
}
|
||||
};
|
||||
|
||||
class supported_extensions
|
||||
{
|
||||
private:
|
||||
std::vector<VkExtensionProperties> m_vk_exts;
|
||||
|
||||
public:
|
||||
|
||||
supported_extensions()
|
||||
{
|
||||
uint32_t count;
|
||||
if (vkEnumerateInstanceExtensionProperties(nullptr, &count, nullptr) != VK_SUCCESS)
|
||||
return;
|
||||
|
||||
m_vk_exts.resize(count);
|
||||
vkEnumerateInstanceExtensionProperties(nullptr, &count, m_vk_exts.data());
|
||||
}
|
||||
|
||||
bool is_supported(const char *ext)
|
||||
{
|
||||
return std::any_of(m_vk_exts.cbegin(), m_vk_exts.cend(),
|
||||
[&](const VkExtensionProperties& p) { return std::strcmp(p.extensionName, ext) == 0; });
|
||||
}
|
||||
};
|
||||
|
||||
class context
|
||||
{
|
||||
private:
|
||||
@ -1216,22 +1241,36 @@ namespace vk
|
||||
app.apiVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
|
||||
//Set up instance information
|
||||
const char *requested_extensions[] =
|
||||
{
|
||||
VK_KHR_SURFACE_EXTENSION_NAME,
|
||||
#ifdef _WIN32
|
||||
VK_KHR_WIN32_SURFACE_EXTENSION_NAME,
|
||||
#else
|
||||
VK_KHR_XLIB_SURFACE_EXTENSION_NAME,
|
||||
#endif
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME,
|
||||
#endif
|
||||
VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
|
||||
};
|
||||
|
||||
std::vector<const char *> extensions;
|
||||
std::vector<const char *> layers;
|
||||
|
||||
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||
#ifdef _WIN32
|
||||
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||
#else
|
||||
supported_extensions support;
|
||||
bool found_surface_ext = false;
|
||||
if (support.is_supported(VK_KHR_XLIB_SURFACE_EXTENSION_NAME))
|
||||
{
|
||||
extensions.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
|
||||
found_surface_ext = true;
|
||||
}
|
||||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
|
||||
if (support.is_supported(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME))
|
||||
{
|
||||
extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
|
||||
found_surface_ext = true;
|
||||
}
|
||||
#endif
|
||||
if (!found_surface_ext)
|
||||
{
|
||||
LOG_ERROR(RSX, "Could not find a supported Vulkan surface extension");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!fast && g_cfg.video.debug_output)
|
||||
layers.push_back("VK_LAYER_LUNARG_standard_validation");
|
||||
|
||||
@ -1240,8 +1279,8 @@ namespace vk
|
||||
instance_info.pApplicationInfo = &app;
|
||||
instance_info.enabledLayerCount = static_cast<uint32_t>(layers.size());
|
||||
instance_info.ppEnabledLayerNames = layers.data();
|
||||
instance_info.enabledExtensionCount = fast? 0: sizeof(requested_extensions)/sizeof(char*);
|
||||
instance_info.ppEnabledExtensionNames = fast? nullptr: requested_extensions;
|
||||
instance_info.enabledExtensionCount = fast? 0: static_cast<uint32_t>(extensions.size());
|
||||
instance_info.ppEnabledExtensionNames = fast? nullptr: extensions.data();
|
||||
|
||||
VkInstance instance;
|
||||
if (vkCreateInstance(&instance_info, nullptr, &instance) != VK_SUCCESS)
|
||||
|
Loading…
Reference in New Issue
Block a user