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;
125 bool vk_init_ctx(struct vk_ctx *ctx,
128 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
132 void vk_cleanup_ctx(struct vk_ctx *ctx,
138 vk_create_image(struct vk_ctx *ctx,
139 struct vk_att_props *props,
140 struct vk_image_obj *img_obj);
142 vk_destroy_image(struct vk_ctx *ctx,
143 struct vk_image_obj *img_obj);
146 vk_fill_image_props(struct vk_ctx *ctx,
147 uint32_t w, uint32_t h,
149 uint32_t num_samples,
153 VkImageTiling tiling,
154 VkImageLayout in_layout,
155 VkImageLayout end_layout,
159 struct vk_att_props *props);
164 vk_create_buffer(struct vk_ctx *ctx,
167 VkBufferUsageFlagBits usage,
171 vk_destroy_buffer(struct vk_ctx *ctx,
174 vk_update_buffer_data(struct vk_ctx *ctx,
180 vk_create_ext_buffer(struct vk_ctx *ctx,
182 VkBufferUsageFlagBits usage,
186 /* semaphores and fences */
189 vk_create_semaphores(struct vk_ctx *ctx,
191 struct vk_semaphores *semaphores);
193 vk_destroy_semaphores(struct vk_ctx *ctx,
194 struct vk_semaphores *semaphores);
197 vk_create_fences(struct vk_ctx *ctx,
199 VkFenceCreateFlagBits flags,
203 vk_destroy_fences(struct vk_ctx *ctc,
210 vk_create_renderer(struct vk_ctx *ctx,
212 unsigned int vs_size,
214 unsigned int fs_size,
216 uint32_t num_samples,
220 struct vk_attachment *color_att,
221 struct vk_attachment *depth_att,
222 struct vk_vertex_info *vert_info,
223 struct vk_renderer *renderer);
226 vk_destroy_renderer(struct vk_ctx *ctx,
227 struct vk_renderer *pipeline);
231 vk_create_cmd_buffer(struct vk_ctx *ctx);
234 vk_record_cmd_buffer(struct vk_ctx *ctx,
235 VkCommandBuffer cmd_buf,
236 struct vk_renderer *renderer,
238 uint32_t vk_fb_color_count,
241 struct vk_attachment *atts,
246 vk_reset_cmd_buf(struct vk_cmd_buffer *cmd_buf);
249 vk_destroy_cmd_bufs(struct vk_ctx *ctx,
250 uint32_t num_buffers,
251 VkCommandBuffer *buffers);
254 vk_draw(struct vk_ctx *ctx,
255 struct vk_semaphores *semaphores,
256 uint32_t num_buffers,
257 VkCommandBuffer *cmd_buf);
260 vk_clear_color(struct vk_ctx *ctx,
261 VkCommandBuffer cmd_buf,
263 struct vk_renderer *renderer,
265 uint32_t vk_fb_color_count,
266 struct vk_semaphores *semaphores,
267 bool has_wait, bool has_signal,
268 struct vk_attachment *attachments,
269 uint32_t n_attachments,
270 float x, float y, float w, float h);
275 vk_create_swapchain(struct vk_ctx *ctx,
276 int width, int height,
279 struct vk_swapchain *old_swapchain,
280 struct vk_swapchain *swapchain);
282 vk_destroy_swapchain(struct vk_ctx *ctx,
283 struct vk_swapchain *swapchain);
286 vk_present_queue(struct vk_swapchain *swapchain,
289 VkSemaphore wait_sema);
294 vk_copy_image_to_buffer(struct vk_ctx *ctx,
295 VkCommandBuffer cmd_buf,
296 struct vk_attachment *src_img,
297 struct vk_buf *dst_bo,
301 vk_transition_image_layout(struct vk_attachment *img_att,
302 VkCommandBuffer cmd_buf,
303 VkImageLayout old_layout,
304 VkImageLayout new_layout,
305 uint32_t src_queue_family_index,
306 uint32_t dst_queue_family_index);