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;
34 VkSurfaceFormatKHR surf_fmt;
36 /* image properties */
41 struct vk_attachment *atts;
55 VkImageUsageFlagBits usage;
58 VkImageLayout in_layout;
59 VkImageLayout end_layout;
77 struct vk_mem_obj mobj;
80 struct vk_attachment {
81 struct vk_image_obj obj;
82 struct vk_att_props props;
90 VkPrimitiveTopology topology;
96 struct vk_mem_obj mobj;
102 VkPipelineLayout pipeline_layout;
103 VkRenderPass renderpass;
108 struct vk_vertex_info vertex_info;
119 VkSemaphore frame_ready;
120 VkSemaphore frame_done;
129 bool vk_init_ctx(struct vk_ctx *ctx,
132 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
136 void vk_cleanup_ctx(struct vk_ctx *ctx,
142 vk_create_image(struct vk_ctx *ctx,
143 struct vk_att_props *props,
144 struct vk_image_obj *img_obj);
146 vk_destroy_image(struct vk_ctx *ctx,
147 struct vk_image_obj *img_obj);
150 vk_fill_image_props(struct vk_ctx *ctx,
151 uint32_t w, uint32_t h,
153 uint32_t num_samples,
157 VkImageTiling tiling,
158 VkImageLayout in_layout,
159 VkImageLayout end_layout,
163 struct vk_att_props *props);
168 vk_create_buffer(struct vk_ctx *ctx,
171 VkBufferUsageFlagBits usage,
175 vk_destroy_buffer(struct vk_ctx *ctx,
178 vk_update_buffer_data(struct vk_ctx *ctx,
184 vk_create_ext_buffer(struct vk_ctx *ctx,
186 VkBufferUsageFlagBits usage,
190 /* semaphores and fences */
193 vk_create_semaphores(struct vk_ctx *ctx,
195 struct vk_semaphores *semaphores);
197 vk_destroy_semaphores(struct vk_ctx *ctx,
198 struct vk_semaphores *semaphores);
201 vk_create_fences(struct vk_ctx *ctx,
203 VkFenceCreateFlagBits flags,
207 vk_destroy_fences(struct vk_ctx *ctc,
214 vk_create_renderer(struct vk_ctx *ctx,
216 unsigned int vs_size,
218 unsigned int fs_size,
220 uint32_t num_samples,
224 struct vk_attachment *color_att,
225 struct vk_attachment *depth_att,
226 struct vk_vertex_info *vert_info,
227 struct vk_renderer *renderer);
230 vk_destroy_renderer(struct vk_ctx *ctx,
231 struct vk_renderer *pipeline);
235 vk_create_cmd_buffer(struct vk_ctx *ctx);
238 vk_record_cmd_buffer(struct vk_ctx *ctx,
239 VkCommandBuffer cmd_buf,
240 struct vk_renderer *renderer,
242 uint32_t vk_fb_color_count,
245 struct vk_attachment *atts,
250 vk_reset_cmd_buf(struct vk_cmd_buffer *cmd_buf);
253 vk_destroy_cmd_bufs(struct vk_ctx *ctx,
254 uint32_t num_buffers,
255 VkCommandBuffer *buffers);
258 vk_draw(struct vk_ctx *ctx,
259 struct vk_semaphores *semaphores,
260 uint32_t num_buffers,
261 VkCommandBuffer *cmd_buf);
264 vk_clear_color(struct vk_ctx *ctx,
265 VkCommandBuffer cmd_buf,
267 struct vk_renderer *renderer,
269 uint32_t vk_fb_color_count,
270 struct vk_semaphores *semaphores,
271 bool has_wait, bool has_signal,
272 struct vk_attachment *attachments,
273 uint32_t n_attachments,
274 float x, float y, float w, float h);
279 vk_create_swapchain(struct vk_ctx *ctx,
280 int width, int height,
283 struct vk_swapchain *old_swapchain,
284 struct vk_swapchain *swapchain);
286 vk_destroy_swapchain(struct vk_ctx *ctx,
287 struct vk_swapchain *swapchain);
290 vk_present_queue(struct vk_swapchain *swapchain,
293 VkSemaphore wait_sema);
298 vk_copy_image_to_buffer(struct vk_ctx *ctx,
299 VkCommandBuffer cmd_buf,
300 struct vk_attachment *src_img,
301 struct vk_buf *dst_bo,
305 vk_transition_image_layout(struct vk_attachment *img_att,
306 VkCommandBuffer cmd_buf,
307 VkImageLayout old_layout,
308 VkImageLayout new_layout,
309 uint32_t src_queue_family_index,
310 uint32_t dst_queue_family_index);