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];
36 VkImageUsageFlagBits usage;
39 VkImageLayout in_layout;
40 VkImageLayout end_layout;
49 VkSwapchainKHR swapchain;
50 VkSurfaceFormatKHR surf_fmt;
52 /* image properties */
53 /* FIXME: do I really need those 2?*/
57 struct vk_att_props img_props;
64 /* for allocated images */
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;
107 struct vk_vertex_info vertex_info;
118 VkSemaphore frame_ready;
119 VkSemaphore frame_done;
128 bool vk_init_ctx(struct vk_ctx *ctx,
131 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx,
135 void vk_cleanup_ctx(struct vk_ctx *ctx);
139 vk_create_ext_image(struct vk_ctx *ctx,
140 struct vk_att_props *props,
141 struct vk_image_obj *img);
144 vk_create_image(struct vk_ctx *ctx,
145 struct vk_att_props *props,
146 struct vk_image_obj *img_obj);
148 vk_destroy_image(struct vk_ctx *ctx,
149 struct vk_image_obj *img_obj);
152 vk_create_image_view(struct vk_ctx *ctx,
154 VkImageViewType view_type,
157 VkImageView *image_view);
160 vk_fill_image_props(struct vk_ctx *ctx,
161 uint32_t w, uint32_t h,
163 uint32_t num_samples,
167 VkImageTiling tiling,
168 VkImageLayout in_layout,
169 VkImageLayout end_layout,
173 struct vk_att_props *props);
176 vk_create_attachment_from_obj(struct vk_image_obj *obj,
177 struct vk_att_props *props);
180 vk_create_attachment(VkImage image,
182 struct vk_att_props *props);
187 vk_create_buffer(struct vk_ctx *ctx,
190 VkBufferUsageFlagBits usage,
194 vk_destroy_buffer(struct vk_ctx *ctx,
197 vk_update_buffer_data(struct vk_ctx *ctx,
203 vk_create_ext_buffer(struct vk_ctx *ctx,
205 VkBufferUsageFlagBits usage,
209 /* semaphores and fences */
212 vk_create_semaphores(struct vk_ctx *ctx,
214 struct vk_semaphores *semaphores);
216 vk_destroy_semaphores(struct vk_ctx *ctx,
217 struct vk_semaphores *semaphores);
220 vk_destroy_fences(struct vk_ctx *ctc,
226 vk_create_framebuffer(struct vk_ctx *ctx,
227 int width, int height,
229 VkImageView *color_views,
230 VkImageView *depth_view,
235 vk_create_renderpass(struct vk_ctx *ctx,
236 uint32_t num_color_atts,
237 struct vk_att_props *color_props,
238 struct vk_att_props *depth_props,
239 VkRenderPass *renderpass);
242 vk_create_renderer(struct vk_ctx *ctx,
244 unsigned int vs_size,
246 unsigned int fs_size,
248 uint32_t num_samples,
252 struct vk_att_props *color_props,
253 struct vk_att_props *depth_props,
254 struct vk_vertex_info *vert_info,
255 struct vk_renderer *renderer);
258 vk_destroy_renderer(struct vk_ctx *ctx,
259 struct vk_renderer *pipeline);
261 /* fences and command buffers */
263 vk_create_fence(struct vk_ctx *ctx,
267 vk_create_cmd_buffer(struct vk_ctx *ctx);
270 vk_record_cmd_buffer(struct vk_ctx *ctx,
271 VkCommandBuffer cmd_buf,
272 struct vk_renderer *renderer,
274 uint32_t vk_fb_color_count,
278 struct vk_attachment *atts,
283 vk_destroy_cmd_buffers(struct vk_ctx *ctx,
284 uint32_t num_buffers,
285 VkCommandBuffer *buffers);
289 vk_draw(struct vk_ctx *ctx,
290 struct vk_semaphores *semaphores,
291 uint32_t num_buffers,
292 VkCommandBuffer *cmd_buf);
295 vk_clear_color(struct vk_ctx *ctx,
296 VkCommandBuffer cmd_buf,
298 struct vk_renderer *renderer,
300 uint32_t vk_fb_color_count,
302 struct vk_semaphores *semaphores,
303 bool has_wait, bool has_signal,
304 struct vk_attachment *attachments,
305 uint32_t n_attachments,
306 float x, float y, float w, float h);
309 vk_set_viewport(struct vk_ctx *ctx,
310 VkCommandBuffer cmd_buf,
313 float near, float far);
318 vk_create_swapchain(struct vk_ctx *ctx,
319 int width, int height,
322 struct vk_swapchain *old_swapchain,
323 struct vk_swapchain *swapchain);
325 vk_destroy_swapchain(struct vk_ctx *ctx,
326 struct vk_swapchain *swapchain);
329 vk_queue_present(struct vk_swapchain *swapchain,
332 VkSemaphore wait_sema);
337 vk_copy_image_to_buffer(struct vk_ctx *ctx,
338 VkCommandBuffer cmd_buf,
339 struct vk_attachment *src_img,
340 struct vk_buf *dst_bo,
344 vk_transition_image_layout(struct vk_attachment *img_att,
345 VkCommandBuffer cmd_buf,
346 VkImageLayout old_layout,
347 VkImageLayout new_layout,
348 uint32_t src_queue_family_index,
349 uint32_t dst_queue_family_index);