4 #include <vulkan/vulkan.h>
7 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
28 VkPhysicalDevice pdev;
31 VkCommandPool cmd_pool;
36 uint8_t deviceUUID[VK_UUID_SIZE];
37 uint8_t driverUUID[VK_UUID_SIZE];
51 VkImageUsageFlagBits usage;
54 VkImageLayout in_layout;
55 VkImageLayout end_layout;
64 VkSwapchainKHR swapchain;
65 VkSurfaceFormatKHR surf_fmt;
67 /* image properties */
68 /* FIXME: do I really need those 2?*/
72 struct vk_att_props img_props;
79 /* for allocated images */
92 struct vk_mem_obj mobj;
95 struct vk_attachment {
96 struct vk_image_obj obj;
97 struct vk_att_props props;
103 struct vk_mem_obj mobj;
110 /* int num_components; */
115 struct vk_vbo vertices;
116 struct vk_vbo normals;
117 struct vk_vbo tangents;
118 struct vk_vbo indices;
120 VkPrimitiveTopology topo;
126 VkPipelineLayout pipeline_layout;
127 VkRenderPass renderpass;
131 struct vk_geometry *geometry;
142 VkSemaphore frame_ready;
143 VkSemaphore frame_done;
152 bool vk_init_ctx(struct vk_ctx *ctx,
155 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
159 void vk_cleanup_ctx(struct vk_ctx *ctx);
163 vk_create_ext_image(struct vk_ctx *ctx,
164 struct vk_att_props *props,
165 struct vk_image_obj *img);
168 vk_create_image(struct vk_ctx *ctx,
169 struct vk_att_props *props,
170 struct vk_image_obj *img_obj);
172 vk_destroy_image(struct vk_ctx *ctx,
173 struct vk_image_obj *img_obj);
176 vk_create_image_view(struct vk_ctx *ctx,
178 VkImageViewType view_type,
181 VkImageView *image_view);
184 vk_fill_image_props(struct vk_ctx *ctx,
185 uint32_t w, uint32_t h,
187 uint32_t num_samples,
191 VkImageTiling tiling,
192 VkImageLayout in_layout,
193 VkImageLayout end_layout,
197 struct vk_att_props *props);
200 vk_create_attachment_from_obj(struct vk_image_obj *obj,
201 struct vk_att_props *props);
204 vk_create_attachment(VkImage image,
206 struct vk_att_props *props);
211 vk_create_buffer(struct vk_ctx *ctx,
214 VkBufferUsageFlagBits usage,
218 vk_destroy_buffer(struct vk_ctx *ctx,
221 vk_update_buffer_data(struct vk_ctx *ctx,
227 vk_create_ext_buffer(struct vk_ctx *ctx,
229 VkBufferUsageFlagBits usage,
233 /* semaphores and fences */
236 vk_create_semaphores(struct vk_ctx *ctx,
238 struct vk_semaphores *semaphores);
240 vk_destroy_semaphores(struct vk_ctx *ctx,
241 struct vk_semaphores *semaphores);
244 vk_destroy_fences(struct vk_ctx *ctc,
250 vk_create_framebuffer(struct vk_ctx *ctx,
251 int width, int height,
253 VkImageView *color_views,
254 VkImageView *depth_view,
259 vk_create_renderpass(struct vk_ctx *ctx,
260 uint32_t num_color_atts,
261 struct vk_att_props *color_props,
262 struct vk_att_props *depth_props,
263 VkRenderPass *renderpass);
266 vk_create_renderer(struct vk_ctx *ctx,
268 unsigned int vs_size,
270 unsigned int fs_size,
272 uint32_t num_samples,
276 struct vk_att_props *color_props,
277 struct vk_att_props *depth_props,
278 struct vk_geometry *geometry,
279 struct vk_renderer *renderer);
282 vk_destroy_renderer(struct vk_ctx *ctx,
283 struct vk_renderer *pipeline);
285 /* fences and command buffers */
287 vk_create_fence(struct vk_ctx *ctx,
291 vk_create_cmd_buffer(struct vk_ctx *ctx);
294 vk_record_cmd_buffer(struct vk_ctx *ctx,
295 VkCommandBuffer cmd_buf,
296 struct vk_renderer *renderer,
297 uint32_t vk_fb_color_count,
301 struct vk_attachment *atts,
306 vk_destroy_cmd_buffers(struct vk_ctx *ctx,
307 uint32_t num_buffers,
308 VkCommandBuffer *buffers);
312 vk_draw(struct vk_ctx *ctx,
313 struct vk_semaphores *semaphores,
314 uint32_t num_buffers,
315 VkCommandBuffer *cmd_buf);
318 vk_clear_color(struct vk_ctx *ctx,
319 VkCommandBuffer cmd_buf,
321 struct vk_renderer *renderer,
323 uint32_t vk_fb_color_count,
325 struct vk_semaphores *semaphores,
326 bool has_wait, bool has_signal,
327 struct vk_attachment *attachments,
328 uint32_t n_attachments,
329 float x, float y, float w, float h);
332 vk_set_viewport(struct vk_ctx *ctx,
333 VkCommandBuffer cmd_buf,
336 float near, float far);
341 vk_create_swapchain(struct vk_ctx *ctx,
342 int width, int height,
345 struct vk_swapchain *old_swapchain,
346 struct vk_swapchain *swapchain);
348 vk_destroy_swapchain(struct vk_ctx *ctx,
349 struct vk_swapchain *swapchain);
352 vk_queue_present(struct vk_swapchain *swapchain,
355 VkSemaphore wait_sema);
360 vk_copy_image_to_buffer(struct vk_ctx *ctx,
361 VkCommandBuffer cmd_buf,
362 struct vk_attachment *src_img,
363 struct vk_buf *dst_bo,
367 vk_transition_image_layout(struct vk_attachment *img_att,
368 VkCommandBuffer cmd_buf,
369 VkImageLayout old_layout,
370 VkImageLayout new_layout,
371 uint32_t src_queue_family_index,
372 uint32_t dst_queue_family_index);