X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fvk.h;h=58a88efa5df2f847eaf3a75f87983eb973e4c607;hb=739a8266145a78fdc015ac74c890474f023b1fd1;hp=dfe6aa685ec307030df1984581bafeac8f717ea3;hpb=e123e37a567080a67a1d59837f52cada1b02c951;p=vkrt diff --git a/src/vk.h b/src/vk.h index dfe6aa6..58a88ef 100644 --- a/src/vk.h +++ b/src/vk.h @@ -5,15 +5,15 @@ #include #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + struct vk_ctx { VkInstance inst; + VkPhysicalDevice pdev; VkDevice dev; VkCommandPool cmd_pool; - VkCommandBuffer *cmd_buffers; - uint32_t num_cmd_buffers; VkQueue queue; int qfam_idx; @@ -22,26 +22,6 @@ struct vk_ctx uint8_t driverUUID[VK_UUID_SIZE]; }; -struct vk_cmd_buffer -{ - 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_atts; - struct vk_attachment *atts; -}; - struct vk_att_props { uint32_t w; @@ -64,6 +44,25 @@ struct vk_att_props bool need_export; }; +struct vk_swapchain +{ + VkSwapchainKHR swapchain; + VkSurfaceFormatKHR surf_fmt; + + /* image properties */ + /* FIXME: do I really need those 2?*/ + VkFormat image_fmt; + VkExtent2D extent2d; + + struct vk_att_props img_props; + + uint32_t num_images; + VkImage *images; + VkImageView *views; +}; + +/* for allocated images */ + struct vk_mem_obj { VkDeviceMemory mem; VkDeviceSize mem_sz; @@ -104,7 +103,6 @@ struct vk_renderer VkRenderPass renderpass; VkShaderModule vs; VkShaderModule fs; - VkFramebuffer fb; struct vk_vertex_info vertex_info; }; @@ -121,6 +119,10 @@ struct vk_semaphores VkSemaphore frame_done; }; +#ifdef __cplusplus +extern "C" { +#endif + /* context */ bool vk_init_ctx(struct vk_ctx *ctx, @@ -130,10 +132,13 @@ 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); +void vk_cleanup_ctx(struct vk_ctx *ctx); /* images */ +bool +vk_create_ext_image(struct vk_ctx *ctx, + struct vk_att_props *props, + struct vk_image_obj *img); bool vk_create_image(struct vk_ctx *ctx, @@ -144,6 +149,14 @@ vk_destroy_image(struct vk_ctx *ctx, struct vk_image_obj *img_obj); bool +vk_create_image_view(struct vk_ctx *ctx, + VkImage image, + VkImageViewType view_type, + VkFormat format, + bool is_swapchain, + VkImageView *image_view); + +bool vk_fill_image_props(struct vk_ctx *ctx, uint32_t w, uint32_t h, uint32_t depth, @@ -159,6 +172,15 @@ vk_fill_image_props(struct vk_ctx *ctx, bool need_export, struct vk_att_props *props); +struct vk_attachment +vk_create_attachment_from_obj(struct vk_image_obj *obj, + struct vk_att_props *props); + +struct vk_attachment +vk_create_attachment(VkImage image, + VkImageView view, + struct vk_att_props *props); + /* buffers */ bool @@ -194,18 +216,27 @@ 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 +vk_create_framebuffer(struct vk_ctx *ctx, + int width, int height, + int num_color_atts, + VkImageView *color_views, + VkImageView *depth_view, + VkRenderPass rb, + VkFramebuffer *fb); + +bool +vk_create_renderpass(struct vk_ctx *ctx, + uint32_t num_color_atts, + struct vk_att_props *color_props, + struct vk_att_props *depth_props, + VkRenderPass *renderpass); bool vk_create_renderer(struct vk_ctx *ctx, @@ -218,8 +249,8 @@ vk_create_renderer(struct vk_ctx *ctx, bool enable_depth, bool enable_stencil, int num_color_att, - struct vk_attachment *color_att, - struct vk_attachment *depth_att, + struct vk_att_props *color_props, + struct vk_att_props *depth_props, struct vk_vertex_info *vert_info, struct vk_renderer *renderer); @@ -227,7 +258,11 @@ void vk_destroy_renderer(struct vk_ctx *ctx, struct vk_renderer *pipeline); -/* draw */ +/* fences and command buffers */ +bool +vk_create_fence(struct vk_ctx *ctx, + VkFence *fence); + VkCommandBuffer vk_create_cmd_buffer(struct vk_ctx *ctx); @@ -238,19 +273,18 @@ vk_record_cmd_buffer(struct vk_ctx *ctx, struct vk_buf *vbo, uint32_t vk_fb_color_count, float *vk_fb_color, + VkFramebuffer fb, 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); +vk_destroy_cmd_buffers(struct vk_ctx *ctx, + uint32_t num_buffers, + VkCommandBuffer *buffers); +/* draw */ void vk_draw(struct vk_ctx *ctx, struct vk_semaphores *semaphores, @@ -264,12 +298,20 @@ vk_clear_color(struct vk_ctx *ctx, struct vk_renderer *renderer, float *vk_fb_color, uint32_t vk_fb_color_count, + VkFramebuffer fb, struct vk_semaphores *semaphores, bool has_wait, bool has_signal, struct vk_attachment *attachments, uint32_t n_attachments, float x, float y, float w, float h); +void +vk_set_viewport(struct vk_ctx *ctx, + VkCommandBuffer cmd_buf, + float x, float y, + float w, float h, + float near, float far); + /* swapchain */ bool @@ -284,7 +326,7 @@ vk_destroy_swapchain(struct vk_ctx *ctx, struct vk_swapchain *swapchain); bool -vk_present_queue(struct vk_swapchain *swapchain, +vk_queue_present(struct vk_swapchain *swapchain, VkQueue queue, uint32_t image_idx, VkSemaphore wait_sema); @@ -306,4 +348,9 @@ vk_transition_image_layout(struct vk_attachment *img_att, uint32_t src_queue_family_index, uint32_t dst_queue_family_index); + +#ifdef __cplusplus +} +#endif + #endif /* VK_H */