forked from Dynamitos/Seele
More windowing changes for renderdoc
This commit is contained in:
1 parent
7af42b9bad
commit
b6a449d8e3
3 files changed
+283
-62
No files matched your search
@@ -16,10 +16,12 @@
|
||||
#include "RenderPass.h"
|
||||
#include "Shader.h"
|
||||
#include "Window.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
#include <cstring>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
#define VMA_IMPLEMENTATION
|
||||
@@ -28,6 +30,63 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
namespace {
|
||||
std::vector<VkExtensionProperties> enumerateInstanceExtensions() {
|
||||
uint32_t extensionCount = 0;
|
||||
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr));
|
||||
std::vector<VkExtensionProperties> extensions(extensionCount);
|
||||
if (extensionCount > 0) {
|
||||
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data()));
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
bool hasInstanceExtension(const std::vector<VkExtensionProperties>& extensions, const char* extensionName) {
|
||||
for (const auto& extension : extensions) {
|
||||
if (std::strcmp(extension.extensionName, extensionName) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void applyCommonGlfwInitHints() {
|
||||
#if defined(GLFW_WAYLAND_LIBDECOR) && defined(GLFW_WAYLAND_DISABLE_LIBDECOR)
|
||||
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);
|
||||
#endif
|
||||
}
|
||||
|
||||
void initializeGlfwForVulkan() {
|
||||
applyCommonGlfwInitHints();
|
||||
if (!glfwInit()) {
|
||||
throw std::runtime_error("Failed to initialize GLFW");
|
||||
}
|
||||
if (!glfwVulkanSupported()) {
|
||||
throw std::runtime_error("GLFW: Vulkan not supported");
|
||||
}
|
||||
|
||||
#if defined(GLFW_PLATFORM_WAYLAND) && defined(GLFW_PLATFORM_X11)
|
||||
const auto availableExtensions = enumerateInstanceExtensions();
|
||||
const bool hasWaylandSurface = hasInstanceExtension(availableExtensions, "VK_KHR_wayland_surface");
|
||||
const bool hasXlibSurface = hasInstanceExtension(availableExtensions, "VK_KHR_xlib_surface");
|
||||
const bool hasXcbSurface = hasInstanceExtension(availableExtensions, "VK_KHR_xcb_surface");
|
||||
|
||||
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND && !hasWaylandSurface && (hasXlibSurface || hasXcbSurface)) {
|
||||
std::cerr << "Warning: Vulkan loader does not expose VK_KHR_wayland_surface on this run. Reinitializing GLFW on X11 backend." << std::endl;
|
||||
glfwTerminate();
|
||||
applyCommonGlfwInitHints();
|
||||
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
|
||||
if (!glfwInit()) {
|
||||
throw std::runtime_error("Failed to reinitialize GLFW on X11 backend");
|
||||
}
|
||||
if (!glfwVulkanSupported()) {
|
||||
throw std::runtime_error("GLFW: Vulkan not supported after switching to X11 backend");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
thread_local PCommandPool Seele::Vulkan::Graphics::graphicsCommands = nullptr;
|
||||
thread_local PCommandPool Seele::Vulkan::Graphics::computeCommands = nullptr;
|
||||
thread_local PCommandPool Seele::Vulkan::Graphics::transferCommands = nullptr;
|
||||
@@ -675,31 +734,46 @@ Array<const char*> Graphics::getRequiredExtensions() {
|
||||
message += ": ";
|
||||
message += glfwError;
|
||||
}
|
||||
extensions.add(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
extensions.add(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
|
||||
std::cerr << "Warning: " << message << ". Falling back to a default set of extensions." << std::endl;
|
||||
std::cerr << "Warning: " << message << ". Falling back to platform-specific surface extensions." << std::endl;
|
||||
|
||||
extensions.addUnique(VK_KHR_SURFACE_EXTENSION_NAME);
|
||||
|
||||
#if defined(GLFW_PLATFORM_WAYLAND) && defined(GLFW_PLATFORM_X11)
|
||||
const int platform = glfwGetPlatform();
|
||||
if (platform == GLFW_PLATFORM_WAYLAND) {
|
||||
extensions.addUnique("VK_KHR_wayland_surface");
|
||||
} else if (platform == GLFW_PLATFORM_X11) {
|
||||
extensions.addUnique("VK_KHR_xlib_surface");
|
||||
extensions.addUnique("VK_KHR_xcb_surface");
|
||||
} else {
|
||||
extensions.addUnique("VK_KHR_wayland_surface");
|
||||
extensions.addUnique("VK_KHR_xlib_surface");
|
||||
extensions.addUnique("VK_KHR_xcb_surface");
|
||||
}
|
||||
#else
|
||||
bool isWayland = std::getenv("WAYLAND_DISPLAY") != nullptr;
|
||||
if (isWayland) {
|
||||
extensions.addUnique("VK_KHR_wayland_surface");
|
||||
} else {
|
||||
extensions.addUnique("VK_KHR_xlib_surface");
|
||||
extensions.addUnique("VK_KHR_xcb_surface");
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// GLFW successfully reported extensions
|
||||
for (unsigned int i = 0; i < glfwExtensionCount; i++) {
|
||||
extensions.addUnique(glfwExtensions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < glfwExtensionCount; i++) {
|
||||
extensions.add(glfwExtensions[i]);
|
||||
}
|
||||
#ifdef ENABLE_VALIDATION
|
||||
extensions.add(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
extensions.addUnique(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
#endif
|
||||
return extensions;
|
||||
}
|
||||
|
||||
void Graphics::initInstance(GraphicsInitializer initInfo) {
|
||||
#if defined(GLFW_WAYLAND_LIBDECOR) && defined(GLFW_WAYLAND_DISABLE_LIBDECOR)
|
||||
// Work around libdecor runtime regressions on some Wayland stacks.
|
||||
glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);
|
||||
#endif
|
||||
if (!glfwInit()) {
|
||||
throw std::runtime_error("Failed to initialize GLFW");
|
||||
}
|
||||
if (!glfwVulkanSupported()) {
|
||||
throw std::runtime_error("GLFW: Vulkan not supported");
|
||||
}
|
||||
initializeGlfwForVulkan();
|
||||
VkApplicationInfo appInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||
.pNext = nullptr,
|
||||
@@ -712,10 +786,10 @@ void Graphics::initInstance(GraphicsInitializer initInfo) {
|
||||
|
||||
Array<const char*> extensions = getRequiredExtensions();
|
||||
for (uint32 i = 0; i < initInfo.instanceExtensions.size(); ++i) {
|
||||
extensions.add(initInfo.instanceExtensions[i]);
|
||||
extensions.addUnique(initInfo.instanceExtensions[i]);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
extensions.add("VK_KHR_portability_enumeration");
|
||||
extensions.addUnique("VK_KHR_portability_enumeration");
|
||||
#endif
|
||||
Array<const char*> layers = initInfo.layers;
|
||||
VkInstanceCreateInfo info = {
|
||||
|
||||
Reference in new issue
Block a user