X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvk.h;h=6d4b05ebe915745be2427658e485472ae0a6acc3;hb=63c91ee81f2e7d6218a424d5856132b3e8c5d8ac;hp=ff5c02588812e0f4eaa5a4f1b0b43d3142e77dec;hpb=9c5fa12eb2c6db6c8a3fbd280bab8951cf51f0a0;p=vkrt diff --git a/src/vk.h b/src/vk.h index ff5c025..6d4b05e 100644 --- a/src/vk.h +++ b/src/vk.h @@ -12,7 +12,8 @@ struct vk_ctx VkDevice dev; VkCommandPool cmd_pool; - VkCommandBuffer cmd_buf; + VkCommandBuffer *cmd_buffers; + uint32_t num_cmd_buffers; VkQueue queue; int qfam_idx; @@ -21,27 +22,26 @@ struct vk_ctx uint8_t driverUUID[VK_UUID_SIZE]; }; -struct vk_swap_image_obj +struct vk_cmd_buffer { - VkImage image; - VkImageView image_view; + VkCommandBuffer buffer; + VkSubmitInfo submit_info; }; struct vk_swapchain { VkSwapchainKHR swapchain; - VkSurfaceKHR surface; VkSurfaceFormatKHR surf_fmt; /* image properties */ VkFormat image_fmt; VkExtent2D extent2d; - uint32_t num_images; - struct vk_swap_image_obj *images; + uint32_t num_atts; + struct vk_attachment *atts; }; -struct vk_image_props +struct vk_att_props { uint32_t w; uint32_t h; @@ -58,6 +58,8 @@ struct vk_image_props VkImageLayout in_layout; VkImageLayout end_layout; + bool is_depth; + bool is_swapchain; bool need_export; }; @@ -75,9 +77,9 @@ struct vk_image_obj { struct vk_mem_obj mobj; }; -struct vk_image_att { +struct vk_attachment { struct vk_image_obj obj; - struct vk_image_props props; + struct vk_att_props props; }; struct vk_vertex_info @@ -120,40 +122,41 @@ struct vk_semaphores /* context */ -bool vk_init_ctx(struct vk_ctx *ctx); -bool vk_init_ctx_for_rendering(struct vk_ctx *ctx); -void vk_cleanup_ctx(struct vk_ctx *ctx); +bool vk_init_ctx(struct vk_ctx *ctx, + bool enable_layers); + +bool vk_init_ctx_for_rendering(struct vk_ctx *ctx, + bool enable_cache, + bool enable_layers); + +void vk_cleanup_ctx(struct vk_ctx *ctx, + bool enable_layers); /* images */ bool vk_create_image(struct vk_ctx *ctx, - struct vk_image_props *props, + struct vk_att_props *props, struct vk_image_obj *img_obj); void vk_destroy_image(struct vk_ctx *ctx, struct vk_image_obj *img_obj); bool -vk_fill_ext_image_props(struct vk_ctx *ctx, - uint32_t w, uint32_t h, - uint32_t depth, - uint32_t num_samples, - uint32_t num_levels, - uint32_t num_layers, - VkFormat format, - VkImageTiling tiling, - VkImageLayout in_layout, - VkImageLayout end_layout, - bool need_export, - struct vk_image_props *props); - -bool -vk_create_attachment_from_swapchain_image(struct vk_ctx *ctx, - VkImage *swapchain_img, - VkImageView *swapchain_view, - struct vk_image_props *swapchain_props, - struct vk_image_att *color_att); +vk_fill_image_props(struct vk_ctx *ctx, + uint32_t w, uint32_t h, + uint32_t depth, + uint32_t num_samples, + uint32_t num_levels, + uint32_t num_layers, + VkFormat format, + VkImageTiling tiling, + VkImageLayout in_layout, + VkImageLayout end_layout, + bool is_swapchain, + bool is_depth, + bool need_export, + struct vk_att_props *props); /* buffers */ @@ -180,7 +183,7 @@ vk_create_ext_buffer(struct vk_ctx *ctx, struct vk_buf *bo); -/* semaphores */ +/* semaphores and fences */ bool vk_create_semaphores(struct vk_ctx *ctx, @@ -190,6 +193,17 @@ void vk_destroy_semaphores(struct vk_ctx *ctx, struct vk_semaphores *semaphores); +bool +vk_create_fences(struct vk_ctx *ctx, + int num_cmd_buf, + VkFenceCreateFlagBits flags, + VkFence *fences); + +void +vk_destroy_fences(struct vk_ctx *ctc, + int num_fences, + VkFence *fences); + /* renderer */ bool @@ -198,10 +212,13 @@ vk_create_renderer(struct vk_ctx *ctx, unsigned int vs_size, const char *fs_src, unsigned int fs_size, + int w, int h, + uint32_t num_samples, bool enable_depth, bool enable_stencil, - struct vk_image_att *color_att, - struct vk_image_att *depth_att, + int num_color_att, + struct vk_attachment *color_att, + struct vk_attachment *depth_att, struct vk_vertex_info *vert_info, struct vk_renderer *renderer); @@ -210,27 +227,45 @@ vk_destroy_renderer(struct vk_ctx *ctx, struct vk_renderer *pipeline); /* draw */ +VkCommandBuffer +vk_create_cmd_buffer(struct vk_ctx *ctx); + +bool +vk_record_cmd_buffer(struct vk_ctx *ctx, + VkCommandBuffer cmd_buf, + struct vk_renderer *renderer, + struct vk_buf *vbo, + uint32_t vk_fb_color_count, + float *vk_fb_color, + uint32_t num_atts, + struct vk_attachment *atts, + float x, float y, + float w, float h); + +void +vk_reset_cmd_buf(struct vk_cmd_buffer *cmd_buf); + +void +vk_destroy_cmd_bufs(struct vk_ctx *ctx, + uint32_t num_buffers, + VkCommandBuffer *buffers); void vk_draw(struct vk_ctx *ctx, - struct vk_buf *vbo, - struct vk_renderer *renderer, - float *vk_fb_color, - uint32_t vk_fb_color_count, struct vk_semaphores *semaphores, - struct vk_image_att *attachments, - uint32_t n_attachments, - float x, float y, float w, float h); + uint32_t num_buffers, + VkCommandBuffer *cmd_buf); void vk_clear_color(struct vk_ctx *ctx, + VkCommandBuffer cmd_buf, struct vk_buf *vbo, struct vk_renderer *renderer, float *vk_fb_color, uint32_t vk_fb_color_count, struct vk_semaphores *semaphores, bool has_wait, bool has_signal, - struct vk_image_att *attachments, + struct vk_attachment *attachments, uint32_t n_attachments, float x, float y, float w, float h); @@ -247,16 +282,23 @@ void vk_destroy_swapchain(struct vk_ctx *ctx, struct vk_swapchain *swapchain); +bool +vk_present_queue(struct vk_swapchain *swapchain, + VkQueue queue, + uint32_t image_idx, + VkSemaphore wait_sema); + /* transitions */ void vk_copy_image_to_buffer(struct vk_ctx *ctx, - struct vk_image_att *src_img, + VkCommandBuffer cmd_buf, + struct vk_attachment *src_img, struct vk_buf *dst_bo, float w, float h); void -vk_transition_image_layout(struct vk_image_att *img_att, +vk_transition_image_layout(struct vk_attachment *img_att, VkCommandBuffer cmd_buf, VkImageLayout old_layout, VkImageLayout new_layout,