diff --git a/common.h b/common.h index d3edbeb..c1c5556 100644 --- a/common.h +++ b/common.h @@ -3,11 +3,14 @@ #include #include #include -#include +#if defined(HAVE_VULKAN_INTEL_H) #include #include #include +#include +#endif + #include #if defined(ENABLE_XCB) @@ -24,8 +27,6 @@ #define VK_PROTOTYPES #include -#include - #include "esUtil.h" #define printflike(a, b) __attribute__((format(printf, (a), (b)))) @@ -33,7 +34,10 @@ #define MAX_NUM_IMAGES 5 struct vkcube_buffer { +#if defined(HAVE_VULKAN_INTEL_H) struct gbm_bo *gbm_bo; + uint32_t fb; +#endif VkDeviceMemory mem; VkImage image; VkImageView view; @@ -41,7 +45,6 @@ struct vkcube_buffer { VkFence fence; VkCommandBuffer cmd_buffer; - uint32_t fb; uint32_t stride; }; @@ -57,8 +60,12 @@ struct vkcube { bool protected; +#if defined(HAVE_VULKAN_INTEL_H) int fd; + drmModeCrtc *crtc; + drmModeConnector *connector; struct gbm_device *gbm_device; +#endif #if defined(ENABLE_XCB) struct { @@ -89,8 +96,6 @@ struct vkcube { VkSwapchainKHR swap_chain; - drmModeCrtc *crtc; - drmModeConnector *connector; uint32_t width, height; VkInstance instance; diff --git a/main.c b/main.c index 7bb4a7e..472acac 100644 --- a/main.c +++ b/main.c @@ -37,32 +37,37 @@ #define _DEFAULT_SOURCE /* for major() */ +#include #include #include -#include #include +#if defined(ENABLE_WAYLAND) +#include +#endif +#if defined(ENABLE_WAYLAND) || defined(HAVE_VULKAN_INTEL_H) #include -#include -#include -#include -#include -#include +#include +#endif +#if defined(HAVE_VULKAN_INTEL_H) +#include #include -#include #include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#endif #include "common.h" enum display_mode { DISPLAY_MODE_AUTO = 0, DISPLAY_MODE_HEADLESS, +#if defined(HAVE_VULKAN_INTEL_H) DISPLAY_MODE_KMS, +#endif #if defined(ENABLE_WAYLAND) DISPLAY_MODE_WAYLAND, #endif @@ -451,12 +456,10 @@ init_headless(struct vkcube *vc) return 0; } -#ifdef HAVE_VULKAN_INTEL_H +#if defined(HAVE_VULKAN_INTEL_H) /* KMS display code - render to kernel modesetting fb */ -#include - static struct termios save_tio; static void @@ -669,25 +672,12 @@ mainloop_vt(struct vkcube *vc) } } -#else - -static int -init_kms(struct vkcube *vc) -{ - return -1; -} - -static void -mainloop_vt(struct vkcube *vc) -{ -} - #endif -/* Swapchain-based code - shared between XCB and Wayland */ - #if defined(ENABLE_XCB) || defined(ENABLE_WAYLAND) +/* Swapchain-based code - shared between XCB and Wayland */ + static VkFormat choose_surface_format(struct vkcube *vc) { @@ -804,9 +794,10 @@ create_swapchain(struct vkcube *vc) } } -/* XCB display code - render to X window */ #if defined(ENABLE_XCB) +/* XCB display code - render to X window */ + static xcb_atom_t get_atom(struct xcb_connection_t *conn, const char *name) { @@ -1025,10 +1016,11 @@ mainloop_xcb(struct vkcube *vc) } } #endif -/* Wayland display code - render to Wayland window */ #if defined(ENABLE_WAYLAND) +/* Wayland display code - render to Wayland window */ + static void handle_xdg_surface_configure(void *data, struct xdg_surface *surface, uint32_t serial) @@ -1568,9 +1560,11 @@ display_mode_from_string(const char *s, enum display_mode *mode) } else if (streq(s, "headless")) { *mode = DISPLAY_MODE_HEADLESS; return true; +#if defined(HAVE_VULKAN_INTEL_H) } else if (streq(s, "kms")) { *mode = DISPLAY_MODE_KMS; return true; +#endif #if defined(ENABLE_WAYLAND) } else if (streq(s, "wayland")) { *mode = DISPLAY_MODE_WAYLAND; @@ -1715,23 +1709,33 @@ init_display(struct vkcube *vc) display_mode = DISPLAY_MODE_WAYLAND; if (init_wayland(vc) == -1) { fprintf(stderr, "failed to initialize wayland, falling back " - "to xcb\n"); #endif #if defined(ENABLE_XCB) +#if defined(ENABLE_WAYLAND) + "to xcb\n"); +#endif display_mode = DISPLAY_MODE_XCB; if (init_xcb(vc) == -1) { fprintf(stderr, "failed to initialize xcb, falling back " +#endif +#if defined(HAVE_VULKAN_INTEL_H) +#if defined(ENABLE_WAYLAND) || defined(ENABLE_XCB) "to kms\n"); #endif display_mode = DISPLAY_MODE_KMS; if (init_kms(vc) == -1) { - fprintf(stderr, "failed to initialize kms, falling " - "back to headless\n"); + fprintf(stderr, "failed to initialize kms, falling back " +#endif +#if defined(ENABLE_WAYLAND) || defined(ENABLE_XCB) || defined(HAVE_VULKAN_INTEL_H) + "to headless\n"); +#endif display_mode = DISPLAY_MODE_HEADLESS; if (init_headless(vc) == -1) { fail("failed to initialize headless mode"); } +#if defined(HAVE_VULKAN_INTEL_H) } +#endif #if defined(ENABLE_XCB) } #endif @@ -1747,10 +1751,12 @@ init_display(struct vkcube *vc) if (init_khr(vc) == -1) fail("fail to initialize khr"); break; +#if defined(HAVE_VULKAN_INTEL_H) case DISPLAY_MODE_KMS: if (init_kms(vc) == -1) fail("failed to initialize kms"); break; +#endif #if defined(ENABLE_WAYLAND) case DISPLAY_MODE_WAYLAND: if (init_wayland(vc) == -1) @@ -1783,9 +1789,11 @@ mainloop(struct vkcube *vc) mainloop_xcb(vc); break; #endif +#if defined(HAVE_VULKAN_INTEL_H) case DISPLAY_MODE_KMS: mainloop_vt(vc); break; +#endif case DISPLAY_MODE_KHR: mainloop_khr(vc); break; @@ -1804,7 +1812,9 @@ int main(int argc, char *argv[]) parse_args(argc, argv); vc.model = cube_model; +#if defined(HAVE_VULKAN_INTEL_H) vc.gbm_device = NULL; +#endif #if defined(ENABLE_XCB) vc.xcb.window = XCB_NONE; #endif diff --git a/meson.build b/meson.build index 6b92e7b..7137c66 100644 --- a/meson.build +++ b/meson.build @@ -7,14 +7,15 @@ dep_m = cc.find_library('m', required : false) dep_vulkan = dependency('vulkan') dep_libpng = dependency('libpng') -dep_libdrm = dependency('libdrm') -dep_gbm = dependency('gbm') +dep_libdrm = dependency('libdrm', required : get_option('kms') == 'true') +dep_gbm = dependency('gbm', required : get_option('kms') == 'true') dep_wayland_client = dependency('wayland-client', required : get_option('wayland') == 'true') dep_wayland_protocols = dependency('wayland-protocols', version : '>= 1.12', required : get_option('wayland') == 'true') dep_xcb = dependency('xcb', required : get_option('xcb') == 'true') defs = [] -if cc.has_header('vulkan/vulkan_intel.h', dependencies: dep_vulkan) +if dep_libdrm.found() and dep_gbm.found() and cc.has_header('vulkan/vulkan_intel.h', dependencies: dep_vulkan) + message('kms enabled') defs += '-DHAVE_VULKAN_INTEL_H' endif diff --git a/meson_options.txt b/meson_options.txt index 5e21a15..4983595 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ +option('kms', type : 'combo', choices : ['auto', 'true', 'false'], value : 'auto') option('xcb', type : 'combo', choices : ['auto', 'true', 'false'], value : 'auto') option('wayland', type : 'combo', choices : ['auto', 'true', 'false'], value : 'auto')