Skip to content
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

Merged
merged 5 commits into from Jan 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 52 additions & 13 deletions rpcs3/Emu/RSX/VK/VKHelpers.h
Expand Up @@ -3,6 +3,7 @@
#include "stdafx.h"
#include <exception>
#include <string>
#include <cstring>
#include <functional>
#include <vector>
#include <memory>
Expand Down Expand Up @@ -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;
Copy link
Contributor

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


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:
Expand Down Expand Up @@ -1216,21 +1241,35 @@ 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))
{
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))
{
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
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");
Expand All @@ -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)
Expand Down