4 #include <vulkan/vulkan.h>
7 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
11 VkPhysicalDevice pdev;
14 VkCommandPool cmd_pool;
15 VkCommandBuffer cmd_buf;
20 uint8_t deviceUUID[VK_UUID_SIZE];
21 uint8_t driverUUID[VK_UUID_SIZE];
24 struct vk_swap_image_obj
27 VkImageView image_view;
32 VkSwapchainKHR swapchain;
34 VkSurfaceFormatKHR surf_fmt;
36 /* image properties */
41 struct vk_swap_image_obj *images;
55 VkImageUsageFlagBits usage;
58 VkImageLayout in_layout;
59 VkImageLayout end_layout;
75 struct vk_mem_obj mobj;
79 struct vk_image_obj obj;
80 struct vk_image_props props;
88 VkPrimitiveTopology topology;
94 struct vk_mem_obj mobj;
100 VkPipelineLayout pipeline_layout;
101 VkRenderPass renderpass;
106 struct vk_vertex_info vertex_info;
117 VkSemaphore frame_ready;
118 VkSemaphore frame_done;
123 bool vk_init_ctx(struct vk_ctx *ctx);
124 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx);
125 void vk_cleanup_ctx(struct vk_ctx *ctx);
130 vk_create_image(struct vk_ctx *ctx,
131 struct vk_image_props *props,
132 struct vk_image_obj *img_obj);
134 vk_destroy_image(struct vk_ctx *ctx,
135 struct vk_image_obj *img_obj);
138 vk_fill_ext_image_props(struct vk_ctx *ctx,
139 uint32_t w, uint32_t h,
141 uint32_t num_samples,
145 VkImageTiling tiling,
146 VkImageLayout in_layout,
147 VkImageLayout end_layout,
149 struct vk_image_props *props);
152 vk_create_attachment_from_swapchain_image(struct vk_ctx *ctx,
153 VkImage *swapchain_img,
154 VkImageView *swapchain_view,
155 struct vk_image_props *swapchain_props,
156 struct vk_image_att *color_att);
161 vk_create_buffer(struct vk_ctx *ctx,
164 VkBufferUsageFlagBits usage,
168 vk_destroy_buffer(struct vk_ctx *ctx,
171 vk_update_buffer_data(struct vk_ctx *ctx,
177 vk_create_ext_buffer(struct vk_ctx *ctx,
179 VkBufferUsageFlagBits usage,
186 vk_create_semaphores(struct vk_ctx *ctx,
188 struct vk_semaphores *semaphores);
190 vk_destroy_semaphores(struct vk_ctx *ctx,
191 struct vk_semaphores *semaphores);
196 vk_create_renderer(struct vk_ctx *ctx,
198 unsigned int vs_size,
200 unsigned int fs_size,
203 struct vk_image_att *color_att,
204 struct vk_image_att *depth_att,
205 struct vk_vertex_info *vert_info,
206 struct vk_renderer *renderer);
209 vk_destroy_renderer(struct vk_ctx *ctx,
210 struct vk_renderer *pipeline);
215 vk_draw(struct vk_ctx *ctx,
217 struct vk_renderer *renderer,
219 uint32_t vk_fb_color_count,
220 struct vk_semaphores *semaphores,
221 struct vk_image_att *attachments,
222 uint32_t n_attachments,
223 float x, float y, float w, float h);
226 vk_clear_color(struct vk_ctx *ctx,
228 struct vk_renderer *renderer,
230 uint32_t vk_fb_color_count,
231 struct vk_semaphores *semaphores,
232 bool has_wait, bool has_signal,
233 struct vk_image_att *attachments,
234 uint32_t n_attachments,
235 float x, float y, float w, float h);
240 vk_create_swapchain(struct vk_ctx *ctx,
241 int width, int height,
244 struct vk_swapchain *old_swapchain,
245 struct vk_swapchain *swapchain);
247 vk_destroy_swapchain(struct vk_ctx *ctx,
248 struct vk_swapchain *swapchain);
253 vk_copy_image_to_buffer(struct vk_ctx *ctx,
254 struct vk_image_att *src_img,
255 struct vk_buf *dst_bo,
259 vk_transition_image_layout(struct vk_image_att *img_att,
260 VkCommandBuffer cmd_buf,
261 VkImageLayout old_layout,
262 VkImageLayout new_layout,
263 uint32_t src_queue_family_index,
264 uint32_t dst_queue_family_index);