Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#include <sys/time.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>

#if defined(HAVE_VULKAN_INTEL_H)
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
#include <gbm.h>
#endif

#include <png.h>

#if defined(ENABLE_XCB)
Expand All @@ -24,24 +27,24 @@
#define VK_PROTOTYPES
#include <vulkan/vulkan.h>

#include <gbm.h>

#include "esUtil.h"

#define printflike(a, b) __attribute__((format(printf, (a), (b))))

#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;
VkFramebuffer framebuffer;
VkFence fence;
VkCommandBuffer cmd_buffer;

uint32_t fb;
uint32_t stride;
};

Expand All @@ -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 {
Expand Down Expand Up @@ -89,8 +96,6 @@ struct vkcube {

VkSwapchainKHR swap_chain;

drmModeCrtc *crtc;
drmModeConnector *connector;
uint32_t width, height;

VkInstance instance;
Expand Down
80 changes: 45 additions & 35 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,37 @@

#define _DEFAULT_SOURCE /* for major() */

#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#if defined(ENABLE_WAYLAND)
#include <linux/input.h>
#endif
#if defined(ENABLE_WAYLAND) || defined(HAVE_VULKAN_INTEL_H)
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/stat.h>
#include <signal.h>
#include <poll.h>
#endif
#if defined(HAVE_VULKAN_INTEL_H)
#include <fcntl.h>
#include <linux/kd.h>
#include <linux/vt.h>
#include <linux/major.h>
#include <linux/vt.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <termios.h>
#include <poll.h>
#include <math.h>
#include <assert.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <vulkan/vulkan_intel.h>
#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
Expand Down Expand Up @@ -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 <vulkan/vulkan_intel.h>

static struct termios save_tio;

static void
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -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')