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_buffers;
16 uint32_t num_cmd_buffers;
21 uint8_t deviceUUID[VK_UUID_SIZE];
22 uint8_t driverUUID[VK_UUID_SIZE];
27 VkCommandBuffer buffer;
28 VkSubmitInfo submit_info;
33 VkSwapchainKHR swapchain;
35 VkSurfaceFormatKHR surf_fmt;
37 /* image properties */
42 struct vk_attachment *atts;
56 VkImageUsageFlagBits usage;
59 VkImageLayout in_layout;
60 VkImageLayout end_layout;
78 struct vk_mem_obj mobj;
81 struct vk_attachment {
82 struct vk_image_obj obj;
83 struct vk_att_props props;
91 VkPrimitiveTopology topology;
97 struct vk_mem_obj mobj;
103 VkPipelineLayout pipeline_layout;
104 VkRenderPass renderpass;
109 struct vk_vertex_info vertex_info;
120 VkSemaphore frame_ready;
121 VkSemaphore frame_done;
126 bool vk_init_ctx(struct vk_ctx *ctx,
129 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
133 void vk_cleanup_ctx(struct vk_ctx *ctx,
139 vk_create_image(struct vk_ctx *ctx,
140 struct vk_att_props *props,
141 struct vk_image_obj *img_obj);
143 vk_destroy_image(struct vk_ctx *ctx,
144 struct vk_image_obj *img_obj);
147 vk_fill_image_props(struct vk_ctx *ctx,
148 uint32_t w, uint32_t h,
150 uint32_t num_samples,
154 VkImageTiling tiling,
155 VkImageLayout in_layout,
156 VkImageLayout end_layout,
160 struct vk_att_props *props);
165 vk_create_buffer(struct vk_ctx *ctx,
168 VkBufferUsageFlagBits usage,
172 vk_destroy_buffer(struct vk_ctx *ctx,
175 vk_update_buffer_data(struct vk_ctx *ctx,
181 vk_create_ext_buffer(struct vk_ctx *ctx,
183 VkBufferUsageFlagBits usage,
187 /* semaphores and fences */
190 vk_create_semaphores(struct vk_ctx *ctx,
192 struct vk_semaphores *semaphores);
194 vk_destroy_semaphores(struct vk_ctx *ctx,
195 struct vk_semaphores *semaphores);
198 vk_create_fences(struct vk_ctx *ctx,
200 VkFenceCreateFlagBits flags,
204 vk_destroy_fences(struct vk_ctx *ctc,
211 vk_create_renderer(struct vk_ctx *ctx,
213 unsigned int vs_size,
215 unsigned int fs_size,
217 uint32_t num_samples,
221 struct vk_attachment *color_att,
222 struct vk_attachment *depth_att,
223 struct vk_vertex_info *vert_info,
224 struct vk_renderer *renderer);
227 vk_destroy_renderer(struct vk_ctx *ctx,
228 struct vk_renderer *pipeline);
232 vk_create_cmd_buffer(struct vk_ctx *ctx);
235 vk_record_cmd_buffer(struct vk_ctx *ctx,
236 VkCommandBuffer cmd_buf,
237 struct vk_renderer *renderer,
239 uint32_t vk_fb_color_count,
242 struct vk_attachment *atts,
247 vk_reset_cmd_buf(struct vk_cmd_buffer *cmd_buf);
250 vk_destroy_cmd_bufs(struct vk_ctx *ctx,
251 uint32_t num_buffers,
252 VkCommandBuffer *buffers);
255 vk_draw(struct vk_ctx *ctx,
256 struct vk_semaphores *semaphores,
257 uint32_t num_buffers,
258 VkCommandBuffer *cmd_buf);
261 vk_clear_color(struct vk_ctx *ctx,
262 VkCommandBuffer cmd_buf,
264 struct vk_renderer *renderer,
266 uint32_t vk_fb_color_count,
267 struct vk_semaphores *semaphores,
268 bool has_wait, bool has_signal,
269 struct vk_attachment *attachments,
270 uint32_t n_attachments,
271 float x, float y, float w, float h);
276 vk_create_swapchain(struct vk_ctx *ctx,
277 int width, int height,
280 struct vk_swapchain *old_swapchain,
281 struct vk_swapchain *swapchain);
283 vk_destroy_swapchain(struct vk_ctx *ctx,
284 struct vk_swapchain *swapchain);
287 vk_present_queue(struct vk_swapchain *swapchain,
290 VkSemaphore wait_sema);
295 vk_copy_image_to_buffer(struct vk_ctx *ctx,
296 VkCommandBuffer cmd_buf,
297 struct vk_attachment *src_img,
298 struct vk_buf *dst_bo,
302 vk_transition_image_layout(struct vk_attachment *img_att,
303 VkCommandBuffer cmd_buf,
304 VkImageLayout old_layout,
305 VkImageLayout new_layout,
306 uint32_t src_queue_family_index,
307 uint32_t dst_queue_family_index);