forked from krh/vkcube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
115 lines (92 loc) · 2.47 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdarg.h>
#include <stdnoreturn.h>
#include <sys/time.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
#include <png.h>
#include <xcb/xcb.h>
#include <wayland-client.h>
#include <xdg-shell-unstable-v6-client-protocol.h>
#define VK_USE_PLATFORM_XCB_KHR
#define VK_USE_PLATFORM_WAYLAND_KHR
#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 4
struct vkcube_buffer {
struct gbm_bo *gbm_bo;
VkDeviceMemory mem;
VkImage image;
VkImageView view;
VkFramebuffer framebuffer;
VkFence fence;
VkCommandBuffer cmd_buffer;
uint32_t fb;
uint32_t stride;
};
struct vkcube;
struct model {
void (*init)(struct vkcube *vc);
void (*render)(struct vkcube *vc, struct vkcube_buffer *b);
};
struct vkcube {
struct model model;
int fd;
struct gbm_device *gbm_device;
struct {
xcb_connection_t *conn;
xcb_window_t window;
xcb_atom_t atom_wm_protocols;
xcb_atom_t atom_wm_delete_window;
} xcb;
struct {
struct wl_display *display;
struct wl_compositor *compositor;
struct zxdg_shell_v6 *shell;
struct wl_keyboard *keyboard;
struct wl_seat *seat;
struct wl_surface *surface;
struct zxdg_surface_v6 *xdg_surface;
struct zxdg_toplevel_v6 *xdg_toplevel;
bool wait_for_configure;
} wl;
VkSwapchainKHR swap_chain;
drmModeCrtc *crtc;
drmModeConnector *connector;
uint32_t width, height;
VkInstance instance;
VkPhysicalDevice physical_device;
VkPhysicalDeviceMemoryProperties memory_properties;
VkDevice device;
VkRenderPass render_pass;
VkQueue queue;
VkPipelineLayout pipeline_layout;
VkPipeline pipeline;
VkDeviceMemory mem;
VkBuffer buffer;
VkDescriptorSet descriptor_set;
VkSemaphore semaphore;
VkCommandPool cmd_pool;
void *map;
uint32_t vertex_offset, colors_offset, normals_offset;
struct timeval start_tv;
VkSurfaceKHR surface;
VkFormat image_format;
struct vkcube_buffer buffers[MAX_NUM_IMAGES];
uint32_t image_count;
int current;
};
void noreturn failv(const char *format, va_list args);
void noreturn fail(const char *format, ...) printflike(1, 2) ;
void fail_if(int cond, const char *format, ...) printflike(2, 3);
static inline bool
streq(const char *a, const char *b)
{
return strcmp(a, b) == 0;
}