Permalink
Browse files

Get Vulkan going on Linux

  • Loading branch information...
hrydgard committed Dec 15, 2017
1 parent 7f758d5 commit 9007abddbf0d78646b4bc57d21aaf5990746c2f6
Showing with 43 additions and 11 deletions.
  1. +9 −2 CMakeLists.txt
  2. +34 −9 SDL/SDLMain.cpp
View
@@ -106,9 +106,10 @@ else()
message("Normal Build")
endif()
if(LINUX)
message("Using direct to display extension...")
if(LINUX AND VULKAN)
message("Using XCB extension...")
add_definitions(-DVK_USE_PLATFORM_XLIB_KHR)
# add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
endif()
# Doesn't link on some platforms
@@ -1669,6 +1670,12 @@ endif()
set(CoreExtraLibs ${CoreExtraLibs} armips)
# needed for VK_USE_PLATFORM_XCB_KHR only
#if(VULKAN AND NOT WIN32)
# target_link_libraries(native X11-xcb X11)
#endif()
set(GlslangLibs glslang OGLCompiler OSDependent SPIRV SPVRemapper spirv-cross-glsl)
target_link_libraries(${CoreLibName} Common native kirk cityhash sfmt19937 xbrz xxhash ${GlslangLibs}
View
@@ -40,6 +40,11 @@ SDLJoystick *joystick = NULL;
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "SDL_syswm.h"
#elif defined(VK_USE_PLATFORM_XCB_KHR)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xlib-xcb.h>
#include "SDL_syswm.h"
#endif
#if defined(USING_EGL)
@@ -350,6 +355,7 @@ class SDLVulkanGraphicsContext : public GraphicsContext {
}
void Resize() override {
/*
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight());
vulkan_->DestroyObjects();
// TODO: Take from real window dimensions
@@ -358,6 +364,7 @@ class SDLVulkanGraphicsContext : public GraphicsContext {
vulkan_->ReinitSurface(width, height);
vulkan_->InitObjects();
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight());
*/
}
void SwapInterval(int interval) override {
@@ -375,15 +382,11 @@ class SDLVulkanGraphicsContext : public GraphicsContext {
};
bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode, std::string *error_message) {
mode |= SDL_WINDOW_VULKAN;
window = SDL_CreateWindow("Initializing Vulkan...", x, y, pixel_xres, pixel_yres, mode);
SDL_SysWMinfo sys_info;
SDL_VERSION(&sys_info.version);
SDL_GetWindowWMInfo(window, &sys_info);
Display *display = sys_info.info.x11.display;
Window x11_window = sys_info.info.x11.window;
ILOG("Display: %p", display);
if (!window) {
fprintf(stderr, "Error creating SDL window: %s\n", SDL_GetError());
exit(1);
}
init_glslang();
@@ -421,7 +424,29 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int mode,
return false;
}
vulkan_->InitSurface(WINDOWSYSTEM_XLIB, (void *)display, (void *)(intptr_t)x11_window, pixel_xres, pixel_yres);
SDL_SysWMinfo sys_info{};
SDL_VERSION(&sys_info.version); //Set SDL version
if (!SDL_GetWindowWMInfo(window, &sys_info)) {
fprintf(stderr, "Error getting SDL window wm info: %s\n", SDL_GetError());
exit(1);
}
Display *display = sys_info.info.x11.display;
Window x11_window = sys_info.info.x11.window;
switch (sys_info.subsystem) {
case SDL_SYSWM_X11:
break;
default:
fprintf(stderr, "Vulkan subsystem %d not supported\n", sys_info.subsystem);
exit(1);
break;
}
ILOG("Display: %p", display);
#if defined(VK_USE_PLATFORM_XLIB_KHR)
vulkan_->InitSurface(WINDOWSYSTEM_XLIB, (void*)display, (void *)(intptr_t)x11_window, pixel_xres, pixel_yres);
#elif defined(VK_USE_PLATFORM_XCB_KHR)
vulkan_->InitSurface(WINDOWSYSTEM_XCB, (void*)XGetXCBConnection(display), (void *)(intptr_t)x11_window, pixel_xres, pixel_yres);
#endif
if (!vulkan_->InitObjects()) {
*error_message = vulkan_->InitError();

0 comments on commit 9007abd

Please sign in to comment.