4 #include <vulkan/vulkan.h>
7 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
13 VkPhysicalDevice pdev;
16 VkCommandPool cmd_pool;
21 uint8_t deviceUUID[VK_UUID_SIZE];
22 uint8_t driverUUID[VK_UUID_SIZE];
27 VkSwapchainKHR swapchain;
28 VkSurfaceFormatKHR surf_fmt;
30 /* image properties */
35 struct vk_attachment *atts;
49 VkImageUsageFlagBits usage;
52 VkImageLayout in_layout;
53 VkImageLayout end_layout;
71 struct vk_mem_obj mobj;
74 struct vk_attachment {
75 struct vk_image_obj obj;
76 struct vk_att_props props;
84 VkPrimitiveTopology topology;
90 struct vk_mem_obj mobj;
96 VkPipelineLayout pipeline_layout;
97 VkRenderPass renderpass;
102 struct vk_vertex_info vertex_info;
113 VkSemaphore frame_ready;
114 VkSemaphore frame_done;
123 bool vk_init_ctx(struct vk_ctx *ctx,
126 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
130 void vk_cleanup_ctx(struct vk_ctx *ctx);
135 vk_create_image(struct vk_ctx *ctx,
136 struct vk_att_props *props,
137 struct vk_image_obj *img_obj);
139 vk_destroy_image(struct vk_ctx *ctx,
140 struct vk_image_obj *img_obj);
143 vk_fill_image_props(struct vk_ctx *ctx,
144 uint32_t w, uint32_t h,
146 uint32_t num_samples,
150 VkImageTiling tiling,
151 VkImageLayout in_layout,
152 VkImageLayout end_layout,
156 struct vk_att_props *props);
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,
183 /* semaphores and fences */
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);
194 vk_destroy_fences(struct vk_ctx *ctc,
201 vk_create_renderer(struct vk_ctx *ctx,
203 unsigned int vs_size,
205 unsigned int fs_size,
207 uint32_t num_samples,
211 struct vk_attachment *color_att,
212 struct vk_attachment *depth_att,
213 struct vk_vertex_info *vert_info,
214 struct vk_renderer *renderer);
217 vk_destroy_renderer(struct vk_ctx *ctx,
218 struct vk_renderer *pipeline);
220 /* fences and command buffers */
222 vk_create_fence(struct vk_ctx *ctx,
226 vk_create_cmd_buffer(struct vk_ctx *ctx);
229 vk_record_cmd_buffer(struct vk_ctx *ctx,
230 VkCommandBuffer cmd_buf,
231 struct vk_renderer *renderer,
233 uint32_t vk_fb_color_count,
236 struct vk_attachment *atts,
241 vk_destroy_cmd_buffers(struct vk_ctx *ctx,
242 uint32_t num_buffers,
243 VkCommandBuffer *buffers);
247 vk_draw(struct vk_ctx *ctx,
248 struct vk_semaphores *semaphores,
249 uint32_t num_buffers,
250 VkCommandBuffer *cmd_buf);
253 vk_clear_color(struct vk_ctx *ctx,
254 VkCommandBuffer cmd_buf,
256 struct vk_renderer *renderer,
258 uint32_t vk_fb_color_count,
259 struct vk_semaphores *semaphores,
260 bool has_wait, bool has_signal,
261 struct vk_attachment *attachments,
262 uint32_t n_attachments,
263 float x, float y, float w, float h);
266 vk_set_viewport(struct vk_ctx *ctx,
267 VkCommandBuffer cmd_buf,
270 float near, float far);
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_queue_present(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);