f9cbf94835d0b0adc0d3a73c93d34ec57d60a097
[demo] / src / vulkan / vkutil.h
1 #ifndef VKUTIL_H_
2 #define VKUTIL_H_
3
4 #include <vulkan/vulkan.h>
5
6 extern VkSwapchainKHR vkswapchain;
7 extern VkImage *vkswapchain_images;
8 extern VkSurfaceKHR vksurface;
9 extern VkInstance vkinst;
10 extern VkPhysicalDevice vkpdev;
11 extern VkDevice vkdev;
12 extern VkQueue vkq;
13 extern VkCommandPool vkcmdpool;
14 extern VkCommandBuffer vkcmdbuf;        /* primary command buffer */
15 extern int vkqfamily;
16 extern int vknext_swapchain_image;
17
18 struct vku_buffer {
19         VkBuffer buf;
20         VkDeviceMemory mem_pool;
21         int mem_start, mem_size;
22 };
23
24 /* extensions */
25 bool vku_have_extension(const char *name);
26 bool vku_have_device_extension(const char *name);
27
28 /* device */
29 bool vku_create_device();
30 void vku_cleanup();
31
32 /* command buffers */
33 VkCommandBuffer vku_alloc_cmdbuf(VkCommandPool pool, VkCommandBufferLevel level);
34 void vku_free_cmdbuf(VkCommandPool pool, VkCommandBuffer buf);
35
36 void vku_begin_cmdbuf(VkCommandBuffer buf, unsigned int flags);
37 void vku_end_cmdbuf(VkCommandBuffer buf);
38 void vku_reset_cmdbuf(VkCommandBuffer buf);
39
40 void vku_submit_cmdbuf(VkQueue q, VkCommandBuffer buf, VkFence done_fence);
41
42 /* swapchain */
43 VkSwapchainKHR vku_create_swapchain(VkSurfaceKHR surf, int xsz, int ysz, int n,
44                 VkPresentModeKHR pmode, VkSwapchainKHR prev);
45 VkImage *vku_get_swapchain_images(VkSwapchainKHR sc, int *count);
46 int vku_get_next_image(VkSwapchainKHR sc);
47 void vku_present(VkSwapchainKHR sc, int img_idx);
48
49 /* buffers */
50 vku_buffer *vku_create_buffer(int sz, unsigned int usage);
51 void vku_destroy_buffer(vku_buffer *buf);
52
53 void vku_cmd_copybuf(VkCommandBuffer cmdbuf, VkBuffer dest, int doffs,
54         VkBuffer src, int soffs, int size);
55
56 /* other */
57 const char *vku_get_vulkan_error_str(VkResult error);
58
59 #endif // VKUTIL_H_