#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 model; mat4_t view; mat4_t proj; } mvp_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 vert_shader; VkShaderModule frag_shader; VkDescriptorSetLayout desc_set_layout; VkDescriptorPool desc_pool; VkPipelineLayout pipeline_layout; VkRenderPass render_pass; VkPipeline 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 { mvp_t *mvp_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 mvp_buf; VkDeviceMemory mvp_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); void gpu_render_model( const gpu_ctx_t *ctx, const gpu_model_t *model, const mvp_t *mvp, const mat4_t *bone_matrices); void gpu_render_submit(gpu_ctx_t *ctx); #endif