X-Git-Url: https://eleni.mutantstargoat.com/git/?p=vkrt;a=blobdiff_plain;f=src%2Fvk.h;fp=src%2Fvk.h;h=ff5c02588812e0f4eaa5a4f1b0b43d3142e77dec;hp=140f525fc1773ace4ee1cc3cc0db35e45ffa7870;hb=9c5fa12eb2c6db6c8a3fbd280bab8951cf51f0a0;hpb=c5fcb12273c24f6e24d459ad184f662ef9abefea diff --git a/src/vk.h b/src/vk.h index 140f525..ff5c025 100644 --- a/src/vk.h +++ b/src/vk.h @@ -7,18 +7,24 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) struct vk_ctx { - VkInstance inst; - VkPhysicalDevice pdev; - VkDevice dev; + VkInstance inst; + VkPhysicalDevice pdev; + VkDevice dev; - VkCommandPool cmd_pool; - VkCommandBuffer cmd_buf; + VkCommandPool cmd_pool; + VkCommandBuffer cmd_buf; - VkQueue queue; - int qfam_idx; + VkQueue queue; + int qfam_idx; - uint8_t deviceUUID[VK_UUID_SIZE]; - uint8_t driverUUID[VK_UUID_SIZE]; + uint8_t deviceUUID[VK_UUID_SIZE]; + uint8_t driverUUID[VK_UUID_SIZE]; +}; + +struct vk_swap_image_obj +{ + VkImage image; + VkImageView image_view; }; struct vk_swapchain @@ -26,83 +32,90 @@ struct vk_swapchain VkSwapchainKHR swapchain; VkSurfaceKHR surface; VkSurfaceFormatKHR surf_fmt; - uint32_t num_images; + + /* image properties */ + VkFormat image_fmt; VkExtent2D extent2d; + + uint32_t num_images; + struct vk_swap_image_obj *images; }; struct vk_image_props { - uint32_t w; - uint32_t h; - uint32_t depth; + uint32_t w; + uint32_t h; + uint32_t depth; - uint32_t num_samples; - uint32_t num_levels; - uint32_t num_layers; + uint32_t num_samples; + uint32_t num_levels; + uint32_t num_layers; - VkFormat format; - VkImageUsageFlagBits usage; - VkImageTiling tiling; + VkFormat format; + VkImageUsageFlagBits usage; + VkImageTiling tiling; - VkImageLayout in_layout; - VkImageLayout end_layout; + VkImageLayout in_layout; + VkImageLayout end_layout; bool need_export; }; struct vk_mem_obj { - VkDeviceMemory mem; - VkDeviceSize mem_sz; - bool dedicated; + VkDeviceMemory mem; + VkDeviceSize mem_sz; + + bool dedicated; }; struct vk_image_obj { - VkImage img; + VkImage img; VkImageView img_view; - struct vk_mem_obj mobj; + + struct vk_mem_obj mobj; }; struct vk_image_att { - struct vk_image_obj obj; - struct vk_image_props props; + struct vk_image_obj obj; + struct vk_image_props props; }; struct vk_vertex_info { - int num_verts; - int num_components; + int num_verts; + int num_components; - VkPrimitiveTopology topology; + VkPrimitiveTopology topology; }; struct vk_buf { - VkBuffer buf; - struct vk_mem_obj mobj; + VkBuffer buf; + struct vk_mem_obj mobj; }; struct vk_renderer { - VkPipeline pipeline; - VkPipelineLayout pipeline_layout; - VkRenderPass renderpass; - VkShaderModule vs; - VkShaderModule fs; - VkFramebuffer fb; - - struct vk_vertex_info vertex_info; + VkPipeline pipeline; + VkPipelineLayout pipeline_layout; + VkRenderPass renderpass; + VkShaderModule vs; + VkShaderModule fs; + VkFramebuffer fb; + + struct vk_vertex_info vertex_info; }; struct vk_dims { - float w; - float h; + float w; + float h; }; struct vk_semaphores { - VkSemaphore frame_ready; - VkSemaphore frame_done; + VkSemaphore frame_ready; + VkSemaphore frame_done; }; /* context */ @@ -115,92 +128,99 @@ void vk_cleanup_ctx(struct vk_ctx *ctx); bool vk_create_image(struct vk_ctx *ctx, - struct vk_image_props *props, - struct vk_image_obj *img_obj); + struct vk_image_props *props, + struct vk_image_obj *img_obj); void vk_destroy_image(struct vk_ctx *ctx, - struct vk_image_obj *img_obj); - + 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, + 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); + 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); /* buffers */ bool vk_create_buffer(struct vk_ctx *ctx, bool is_external, - uint32_t sz, - VkBufferUsageFlagBits usage, - void *pnext, - struct vk_buf *bo); + uint32_t sz, + VkBufferUsageFlagBits usage, + void *pnext, + struct vk_buf *bo); void vk_destroy_buffer(struct vk_ctx *ctx, - struct vk_buf *bo); + struct vk_buf *bo); bool vk_update_buffer_data(struct vk_ctx *ctx, - void *data, - uint32_t data_sz, - struct vk_buf *bo); + void *data, + uint32_t data_sz, + struct vk_buf *bo); bool vk_create_ext_buffer(struct vk_ctx *ctx, - uint32_t sz, - VkBufferUsageFlagBits usage, - struct vk_buf *bo); + uint32_t sz, + VkBufferUsageFlagBits usage, + struct vk_buf *bo); /* semaphores */ bool vk_create_semaphores(struct vk_ctx *ctx, - struct vk_semaphores *semaphores); + bool is_external, + struct vk_semaphores *semaphores); void vk_destroy_semaphores(struct vk_ctx *ctx, - struct vk_semaphores *semaphores); + struct vk_semaphores *semaphores); /* renderer */ bool vk_create_renderer(struct vk_ctx *ctx, - const char *vs_src, - unsigned int vs_size, - const char *fs_src, - unsigned int fs_size, - bool enable_depth, - bool enable_stencil, - struct vk_image_att *color_att, - struct vk_image_att *depth_att, - struct vk_vertex_info *vert_info, - struct vk_renderer *renderer); + const char *vs_src, + unsigned int vs_size, + const char *fs_src, + unsigned int fs_size, + bool enable_depth, + bool enable_stencil, + struct vk_image_att *color_att, + struct vk_image_att *depth_att, + struct vk_vertex_info *vert_info, + struct vk_renderer *renderer); void vk_destroy_renderer(struct vk_ctx *ctx, - struct vk_renderer *pipeline); + struct vk_renderer *pipeline); /* draw */ 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); + 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); void vk_clear_color(struct vk_ctx *ctx, @@ -219,7 +239,9 @@ vk_clear_color(struct vk_ctx *ctx, bool vk_create_swapchain(struct vk_ctx *ctx, int width, int height, - int num_qfam, + bool vsync, + VkSurfaceKHR surf, + struct vk_swapchain *old_swapchain, struct vk_swapchain *swapchain); void vk_destroy_swapchain(struct vk_ctx *ctx, @@ -229,16 +251,16 @@ vk_destroy_swapchain(struct vk_ctx *ctx, void vk_copy_image_to_buffer(struct vk_ctx *ctx, - struct vk_image_att *src_img, - struct vk_buf *dst_bo, - float w, float h); + struct vk_image_att *src_img, + struct vk_buf *dst_bo, + float w, float h); void vk_transition_image_layout(struct vk_image_att *img_att, - VkCommandBuffer cmd_buf, - VkImageLayout old_layout, - VkImageLayout new_layout, - uint32_t src_queue_family_index, - uint32_t dst_queue_family_index); + VkCommandBuffer cmd_buf, + VkImageLayout old_layout, + VkImageLayout new_layout, + uint32_t src_queue_family_index, + uint32_t dst_queue_family_index); #endif /* VK_H */