#ifndef GPU_H #define GPU_H #include "linear_alg.h" #include "model.h" #define GLFW_INCLUDE_VULKAN #include #define MAX_FRAMES_IN_FLIGHT 4 typedef struct { mat4_t view; mat4_t proj; } vp_t; typedef struct { VkInstance inst; VkSurfaceKHR surface; VkPhysicalDevice physical_dev; VkDevice dev; VkQueue queue; VkSwapchainKHR swapchain; VkExtent2D swapchain_extent; uint32_t swapchain_img_count; VkImageView swapchain_img_views[MAX_FRAMES_IN_FLIGHT]; VkImage depth_img; VkDeviceMemory depth_img_mem; VkImageView depth_img_view; VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT]; VkShaderModule model_vert_shader; VkShaderModule frag_shader; VkDescriptorSetLayout desc_set_layout; VkDescriptorPool desc_pool; VkRenderPass render_pass; VkPipelineLayout model_pipeline_layout; VkPipeline model_pipeline; VkCommandPool cmd_pool; VkCommandBuffer cmd_buf; VkFence in_flight; VkSemaphore render_fin; VkSemaphore img_avail; VkBuffer staging_buf; VkDeviceMemory staging_mem; void *staging_ptr; VkCommandPool transient_cmd_pool; uint32_t active_img_index; } gpu_ctx_t; typedef struct { mat4_t *transform_ptr; mat4_t *bone_ptr; VkBuffer vertex_buf; VkDeviceMemory vertex_mem; VkBuffer index_buf; VkDeviceMemory index_mem; VkDescriptorSet desc_sets[MAX_FRAMES_IN_FLIGHT]; VkBuffer transform_buf; VkDeviceMemory transform_mem; VkBuffer bone_buf; VkDeviceMemory bone_mem; size_t index_count; size_t bone_count; } gpu_model_t; void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name); void gpu_cleanup(const gpu_ctx_t *ctx); void gpu_model_load( const gpu_ctx_t *ctx, const model_t *model, gpu_model_t *out); void gpu_model_cleanup(const gpu_ctx_t *ctx, const gpu_model_t *model); void gpu_render_begin(gpu_ctx_t *ctx, vp_t vp); void gpu_render_model( const gpu_ctx_t *ctx, const gpu_model_t *model, const mat4_t *bone_matrices, mat4_t transform); void gpu_render_submit(gpu_ctx_t *ctx); #endif