New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect Vulkan Xlib/Wayland surface support at runtime #4048
Changes from 3 commits
62b1399
fde0549
d820474
a6ba1f3
cfc618b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
#include "stdafx.h" | ||
#include <exception> | ||
#include <string> | ||
#include <cstring> | ||
#include <functional> | ||
#include <vector> | ||
#include <memory> | ||
|
@@ -1135,6 +1136,29 @@ 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,21 +1240,32 @@ namespace vk | |
app.apiVersion = VK_MAKE_VERSION(1, 0, 0); | ||
|
||
//Set up instance information | ||
const char *requested_extensions[] = | ||
{ | ||
VK_KHR_SURFACE_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 | ||
VK_KHR_WIN32_SURFACE_EXTENSION_NAME, | ||
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); | ||
#else | ||
VK_KHR_XLIB_SURFACE_EXTENSION_NAME, | ||
#endif | ||
supported_extensions support; | ||
bool found_surface_ext = false; | ||
if (support.is_supported(VK_KHR_XLIB_SURFACE_EXTENSION_NAME)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. brace on newline |
||
extensions.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); | ||
found_surface_ext = true; | ||
} | ||
#ifdef VK_USE_PLATFORM_WAYLAND_KHR | ||
VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, | ||
if (support.is_supported(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); | ||
found_surface_ext = true; | ||
} | ||
#endif | ||
if (!found_surface_ext) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
LOG_ERROR(RSX, "Could not find a supported Vulkan surface extension"); | ||
return 0; | ||
} | ||
#endif | ||
VK_EXT_DEBUG_REPORT_EXTENSION_NAME, | ||
}; | ||
|
||
std::vector<const char *> layers; | ||
|
||
if (!fast && g_cfg.video.debug_output) | ||
layers.push_back("VK_LAYER_LUNARG_standard_validation"); | ||
|
@@ -1240,8 +1275,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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space after the return here