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_buf;
20 uint8_t deviceUUID[VK_UUID_SIZE];
21 uint8_t driverUUID[VK_UUID_SIZE];
26 VkSwapchainKHR swapchain;
28 VkSurfaceFormatKHR surf_fmt;
30 /* image properties */
35 struct vk_image_obj *images;
49 VkImageUsageFlagBits usage;
52 VkImageLayout in_layout;
53 VkImageLayout end_layout;
69 struct vk_mem_obj mobj;
72 struct vk_image_attachment {
73 struct vk_image_obj obj;
74 struct vk_image_props props;
82 VkPrimitiveTopology topology;
88 struct vk_mem_obj mobj;
94 VkPipelineLayout pipeline_layout;
95 VkRenderPass renderpass;
100 struct vk_vertex_info vertex_info;
111 VkSemaphore frame_ready;
112 VkSemaphore frame_done;
117 bool vk_init_ctx(struct vk_ctx *ctx);
118 bool vk_init_ctx_for_rendering(struct vk_ctx *ctx);
119 void vk_cleanup_ctx(struct vk_ctx *ctx);
124 vk_create_image(struct vk_ctx *ctx,
125 struct vk_image_props *props,
126 struct vk_image_obj *img_obj);
128 vk_destroy_image(struct vk_ctx *ctx,
129 struct vk_image_obj *img_obj);
132 vk_fill_image_props(struct vk_ctx *ctx,
133 uint32_t w, uint32_t h,
135 uint32_t num_samples,
139 VkImageTiling tiling,
140 VkImageLayout in_layout,
141 VkImageLayout end_layout,
143 struct vk_image_props *props);
146 vk_create_attachment_from_swapchain_image(struct vk_ctx *ctx,
147 VkImage *swapchain_img,
148 VkImageView *swapchain_view,
149 struct vk_image_props *swapchain_props,
150 struct vk_image_attachment *color_att);
155 vk_create_buffer(struct vk_ctx *ctx,
158 VkBufferUsageFlagBits usage,
162 vk_destroy_buffer(struct vk_ctx *ctx,
165 vk_update_buffer_data(struct vk_ctx *ctx,
171 vk_create_ext_buffer(struct vk_ctx *ctx,
173 VkBufferUsageFlagBits usage,
177 /* semaphores and fences */
180 vk_create_semaphores(struct vk_ctx *ctx,
182 struct vk_semaphores *semaphores);
184 vk_destroy_semaphores(struct vk_ctx *ctx,
185 struct vk_semaphores *semaphores);
188 vk_create_fences(struct vk_ctx *ctx,
190 VkFenceCreateFlagBits flags,
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,
208 struct vk_image_attachment *color_att,
209 struct vk_image_attachment *depth_att,
210 struct vk_vertex_info *vert_info,
211 struct vk_renderer *renderer);
214 vk_destroy_renderer(struct vk_ctx *ctx,
215 struct vk_renderer *pipeline);
220 vk_draw(struct vk_ctx *ctx,
222 struct vk_renderer *renderer,
224 uint32_t vk_fb_color_count,
225 struct vk_semaphores *semaphores,
226 struct vk_image_attachment *attachments,
227 uint32_t n_attachments,
228 float x, float y, float w, float h);
231 vk_clear_color(struct vk_ctx *ctx,
233 struct vk_renderer *renderer,
235 uint32_t vk_fb_color_count,
236 struct vk_semaphores *semaphores,
237 bool has_wait, bool has_signal,
238 struct vk_image_attachment *attachments,
239 uint32_t n_attachments,
240 float x, float y, float w, float h);
245 vk_create_swapchain(struct vk_ctx *ctx,
246 int width, int height,
249 struct vk_swapchain *old_swapchain,
250 struct vk_swapchain *swapchain);
252 vk_destroy_swapchain(struct vk_ctx *ctx,
253 struct vk_swapchain *swapchain);
258 vk_copy_image_to_buffer(struct vk_ctx *ctx,
259 struct vk_image_attachment *src_img,
260 struct vk_buf *dst_bo,
264 vk_transition_image_layout(struct vk_image_attachment *img_att,
265 VkCommandBuffer cmd_buf,
266 VkImageLayout old_layout,
267 VkImageLayout new_layout,
268 uint32_t src_queue_family_index,
269 uint32_t dst_queue_family_index);