use KHR_xcb_surface, because KHR_xlib_surface creation hangs...
authorJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 21 Dec 2021 14:29:40 +0000 (16:29 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Tue, 21 Dec 2021 14:29:40 +0000 (16:29 +0200)
Makefile
src/vk.c

index 3ed975a..99e37f3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,7 +9,7 @@ spirv = $(sdr:.glsl=.spv)
 warn = -pedantic -Wall -Wno-unused-variable
 
 CFLAGS = $(warn) -g -MMD
-LDFLAGS = -lvulkan -lX11
+LDFLAGS = -lvulkan -lX11 -lX11-xcb
 
 $(bin): $(obj) $(spirv)
        $(CC) -o $@ $(obj) $(LDFLAGS)
@@ -24,4 +24,4 @@ $(bin): $(obj) $(spirv)
 
 .PHONY: clean
 clean:
-       rm -f $(src) $(obj) $(spirv)
+       rm -f $(bin) $(obj) $(spirv)
index e07dbf9..101eaa8 100644 (file)
--- a/src/vk.c
+++ b/src/vk.c
@@ -8,7 +8,9 @@
 #ifdef __WIN32__
 #include <vulkan/vulkan_win32.h>
 #else
-#include <vulkan/vulkan_xlib.h>
+/*#include <vulkan/vulkan_xlib.h>*/
+#include <X11/Xlib-xcb.h>
+#include <vulkan/vulkan_xcb.h>
 #endif
 
 static int create_instance(void);
@@ -87,7 +89,8 @@ static struct {
 #ifdef __WIN32__
        {"VK_KHR_win32_surface", 1},
 #else
-       {"VK_KHR_xlib_surface", 1},
+       /*{"VK_KHR_xlib_surface", 1},*/
+       {"VK_KHR_xcb_surface", 1},
 #endif
        {"VK_KHR_debug_report", 0}
 };
@@ -162,6 +165,9 @@ static int create_instance(void)
 
 static int create_surface(void)
 {
+       int res;
+
+       /*
        VkXlibSurfaceCreateInfoKHR xinf = {0};
        xinf.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
        xinf.dpy = dpy;
@@ -171,6 +177,16 @@ static int create_surface(void)
                fprintf(stderr, "failed to create Xlib window surface\n");
                return -1;
        }
+       */
+       VkXcbSurfaceCreateInfoKHR xinf = {0};
+       xinf.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
+       xinf.connection = XGetXCBConnection(dpy);
+       xinf.window = (xcb_window_t)win;
+
+       if((res = vkCreateXcbSurfaceKHR(vk, &xinf, 0, &vksurf)) != 0) {
+               fprintf(stderr, "failed to create XCB window surface (%d)\n", res);
+               return -1;
+       }
        return 0;
 }