backup - needs fixing
[demo] / src / vulkan / vkutil.h
1 #ifndef VKUTIL_H_
2 #define VKUTIL_H_
3
4 #include <vulkan/vulkan.h>
5 #include <vector>
6
7 extern VkPipeline *vkgparent_pipeline;
8 extern VkDescriptorSet *vkdescset;
9 extern VkFramebuffer *vkfbufs;
10 extern VkRenderPass vkrpass;
11 extern VkInstance vkinst;
12 extern VkPhysicalDevice vkpdev;
13 extern VkDevice vkdev;
14 extern VkQueue vkq;
15 extern VkCommandPool vkcmdpool;
16 extern VkCommandBuffer vkcmdbuf;        /* primary command buffer */
17 extern int vkqfamily;
18
19 /* presentation */
20 extern VkSurfaceKHR vksurface;
21 extern VkSwapchainKHR vkswapchain;
22 extern int vknum_swapchain_images;
23 extern VkImage *vkswapchain_images;
24 extern VkImageView *vkswapchain_views;
25 extern int vk_curr_swapchain_image;
26 extern VkSemaphore vk_img_avail_sema;
27 extern VkSemaphore vk_rend_done_sema;
28
29 struct vku_buffer {
30         VkBuffer buf;
31         VkDeviceMemory mem_pool;
32         int mem_start, mem_size;
33 };
34
35 /* extensions */
36 bool vku_have_extension(const char *name);
37 bool vku_have_device_extension(const char *name);
38
39 /* device */
40 bool vku_create_device();
41 void vku_cleanup();
42
43 /* semaphores */
44 bool vku_create_semaphores();
45
46 /* command buffers */
47 VkCommandBuffer vku_alloc_cmdbuf(VkCommandPool pool, VkCommandBufferLevel level);
48 void vku_free_cmdbuf(VkCommandPool pool, VkCommandBuffer buf);
49
50 void vku_begin_cmdbuf(VkCommandBuffer buf, unsigned int flags);
51 void vku_end_cmdbuf(VkCommandBuffer buf);
52 void vku_reset_cmdbuf(VkCommandBuffer buf);
53 void vku_submit_cmdbuf(VkQueue q, VkCommandBuffer buf, VkFence done_fence);
54
55 /* swapchain */
56 VkSwapchainKHR vku_create_swapchain(VkSurfaceKHR surf, int xsz, int ysz, int n,
57                 VkPresentModeKHR pmode, VkSwapchainKHR prev);
58 VkImage *vku_get_swapchain_images(VkSwapchainKHR sc, int *count);
59 VkImageView *vku_create_image_views(VkImage *images, int count);
60 int vku_get_next_image(VkSwapchainKHR sc);
61 void vku_present(VkSwapchainKHR sc, int img_idx);
62
63 /* rederpass */
64 bool vku_create_renderpass();
65
66 /* framebuffer */
67 bool vku_create_framebuffers(VkImageView *image_views, int count, int w, int h);
68
69 /* buffers */
70 vku_buffer *vku_create_buffer(int sz, unsigned int usage);
71 void vku_destroy_buffer(vku_buffer *buf);
72 void vku_cmd_copybuf(VkCommandBuffer cmdbuf, VkBuffer dest, int doffs,
73         VkBuffer src, int soffs, int size);
74
75 /* other */
76 const char *vku_get_vulkan_error_str(VkResult error);
77
78 /* pipeline */
79 bool vku_create_graphics_pipeline(VkPipelineLayout *layout);
80
81 /* descriptor set */
82 //bool vku_create_descriptor_set()
83
84 #endif // VKUTIL_H_