ugh
[vktest3] / src / vk.h
1 #ifndef VK_H_
2 #define VK_H_
3
4 #include <X11/Xlib.h>
5 #include <vulkan/vulkan.h>
6
7 enum {
8         VKINIT_DEPTH    = 1,
9         VKINIT_STENCIL  = 2,
10         VKINIT_RAY              = 0x100
11 };
12
13 /* queue capability flags for vk_find_qfamily and vk_init_queue */
14 enum {
15         VKQ_GFX                 = 1,
16         VKQ_COMPUTE             = 2,
17         VKQ_PRESENT             = 4,
18         VKQ_XFER                = 8
19 };
20
21 /* shader types
22  * arranged so that: (1 << VKSDR_FOO) == VK_SHADER_STAGE_FOO_BIT
23  */
24 enum {
25         VKSDR_VERTEX    = 0,
26         VKSDR_TESS_CTL  = 1,
27         VKSDR_TESS_EVAL = 2,
28         VKSDR_GEOM              = 3,
29         VKSDR_PIXEL             = 4,
30         VKSDR_COMPUTE   = 5,
31
32         VKSDR_TASK              = 6,
33         VKSDR_MESH              = 7,
34
35         VKSDR_RAYGEN    = 8,
36         VKSDR_ANYHIT    = 9,
37         VKSDR_CLOSESTHIT = 10,
38         VKSDR_MISS              = 11,
39         VKSDR_ISECT             = 12,
40
41         VKSDR_MAX
42 };
43 #define VKSDR_STAGE(x)  (1 << (x))
44
45 /* primitives */
46 enum {
47         VKPRIM_POINTS           = VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
48         VKPRIM_LINES            = VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
49         VKPRIM_TRIANGLES        = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
50 };
51
52 void vk_init_xwin(Display *dpy, Window win);
53 void vk_init_queue(unsigned int qflags, int count);
54
55 int vk_init(unsigned int flags, unsigned int *usedflags);
56 void vk_cleanup(void);
57
58 int vk_reshape(int xsz, int ysz);
59
60 /* returns the number of swapchain images */
61 int vk_num_swap_images(void);
62 VkImageView vk_swap_image(int idx);
63 /* returns the image index, or -1 on failure. Pass optional semaphore to signal */
64 int vk_next_swap_image(VkSemaphore sem);
65
66 int vk_submit(VkQueue q, VkCommandBuffer cmdbuf, VkSemaphore semwait, VkSemaphore semsig);
67 int vk_present(VkQueue q, int imgid, VkSemaphore semwait);
68
69 int vk_find_qfamily(unsigned int flags);
70 VkQueue vk_getq_fam(int fam, int n);
71 VkQueue vk_getq(unsigned int flags, int n);
72
73 VkCommandBuffer vk_create_cmdbuf_fam(int qfam, int level);
74 VkCommandBuffer vk_create_cmdbuf(unsigned int qflags, int level);
75 /* return one of the swap-chain command buffers */
76 VkCommandBuffer vk_get_cmdbuf(int imgid);
77
78 int vk_create_rpass(void);
79 void vk_free_rpass(int rp);
80 void vk_rpass_colorbuf(int rp, int fmt, int n);
81 void vk_rpass_msaa(int rp, int nsamp);
82 void vk_rpass_clear(int rp, int clear);
83 VkRenderPass vk_rpass(int rp);
84
85 int vk_create_fb(void);
86 void vk_free_fb(int fb);
87 void vk_fb_size(int fb, int x, int y);
88 void vk_fb_rpass(int fb, int rpass);
89 void vk_fb_images(int fb, int n, ...);
90 VkFramebuffer vk_fb(int fb);
91
92 int vk_create_pipeln(void);
93 void vk_free_pipeln(int pp);
94 void vk_pipeln_rpass(int pp, VkRenderPass rp);
95 void vk_pipeln_viewport(int pp, int x, int y, int width, int height);
96 void vk_pipeln_scissor(int pp, int x, int y, int width, int height);
97 void vk_pipeln_shader(int pp, int type, VkShaderModule sdr);
98 /* TODO: vertex input */
99 void vk_pipeln_prim(int pp, int prim);
100 void vk_pipeln_polymode(int pp, int mode);
101 void vk_pipeln_cull(int pp, int cull);
102 void vk_pipeln_frontface(int pp, int ff);
103 void vk_pipeln_linewidth(int pp, int w);
104 void vk_pipeln_multisample(int pp, int nsamples);
105 void vk_pipeln_colormask(int pp, int r, int g, int b, int a);
106 void vk_pipeln_depthmask(int pp, int z);
107 void vk_pipeln_stencilmask(int pp, int s);
108 void vk_pipeln_zbuffer(int pp, int enable);
109 void vk_pipeln_zbuffer_op(int pp, int op);
110 void vk_pipeln_stencil(int pp, int enable);
111 void vk_pipeln_stencil_op(int pp, int sfail, int zfail, int zpass);
112 void vk_pipeln_stencil_func(int pp, int op, unsigned int ref, unsigned int mask);
113 void vk_pipeln_blend(int pp, int enable);
114 void vk_pipeln_blendfunc(int pp, int src, int dst);
115 VkPipeline vk_pipeln(int pp);
116
117 VkShaderModule vk_load_shader(const char *fname);
118 void vk_free_shader(VkShaderModule sdr);
119
120 VkSemaphore vk_create_sem(void);
121 void vk_free_sem(VkSemaphore sem);
122
123 /* random helpers */
124 void vk_rect(VkRect2D *r, int x, int y, int w, int h);
125
126 #endif  /* VK_H_ */