kiba-engine
context.h
1 #pragma once
2 
3 #include <vulkan/vulkan.h>
4 
5 #include <kiba/containers/array.h>
6 #include <kiba/defines.h>
7 #include <kiba/platform/window.h>
8 #include <kiba/renderer/vulkan/allocator.h>
9 
10 typedef struct vulkan_instance {
11  VkInstance instance;
12  array_of(const char *) extensions;
13  array_of(const char *) layers;
15 
17  b8 graphics;
18  b8 transfer;
19  b8 present;
20  b8 compute;
21  b8 discrete_gpu;
22  VkPhysicalDeviceFeatures features;
23  array_of(const char *) extensions;
25 
26 typedef struct vulkan_queue {
27  u32 index;
28  VkQueue queue;
29  VkCommandPool command_pool;
30  VkCommandBuffer command_buffer;
31  b8 available;
32 } vulkan_queue;
33 
34 typedef struct vulkan_device {
35  VkPhysicalDevice physical;
36  VkDevice logical;
37  vulkan_queue graphics_queue;
38  vulkan_queue transfer_queue;
39  vulkan_queue present_queue;
40  vulkan_queue compute_queue;
41  vulkan_device_requirements requirements;
43 
45  VkSurfaceFormatKHR format;
46  VkPresentModeKHR present_mode;
48 
49 typedef struct vulkan_swap_chain {
50  vulkan_swap_chain_requirements requirements;
51  VkExtent2D extent;
52  u32 image_count;
53  VkSurfaceTransformFlagBitsKHR transform;
54  VkSwapchainKHR swap_chain;
55  b8 recreate;
56  array_of(VkImage) images;
57  array_of(VkImageView) image_views;
58  array_of(VkFramebuffer) framebuffers;
60 
61 #define VULKAN_MAX_FRAMES_IN_FLIGHT 3
62 
63 typedef struct vulkan_pipeline {
64  VkRenderPass renderpass;
65  VkDescriptorSetLayout descriptor_set_layout;
66  VkDescriptorPool descriptor_pool;
67  VkDescriptorSet descriptor_sets[VULKAN_MAX_FRAMES_IN_FLIGHT];
68  VkPipelineLayout layout;
69  array_of(VkPipelineShaderStageCreateInfo) shaders;
70  VkPipeline graphics_pipeline;
72 
73 typedef struct vulkan_sync {
74  VkSemaphore sp_image_available;
75  VkSemaphore sp_render_finished;
76  VkFence fc_in_flight;
77 } vulkan_sync;
78 
79 typedef struct vulkan_buffer {
80  VkBuffer buffer;
81  VkDeviceMemory memory;
82  void *mapped;
84 
85 typedef struct vulkan_image {
86  VkImage image;
87  VkDeviceMemory memory;
88 } vulkan_image;
89 
90 typedef struct vulkan_context {
91  vulkan_allocator alloc;
92  vulkan_instance instance;
93  VkDebugUtilsMessengerEXT debug_messenger;
94  VkSurfaceKHR surface;
95  vulkan_device device;
96  vulkan_swap_chain swap_chain;
97  vulkan_pipeline pipeline;
98  platform_window *window;
99  vulkan_sync sync;
100  vulkan_buffer vertex_data;
101  vulkan_buffer index_data;
102  u32 index_count;
103  vulkan_buffer uniform_buffers[VULKAN_MAX_FRAMES_IN_FLIGHT];
104  struct {
105  vulkan_image image;
106  VkImageView view;
107  VkSampler sampler; // actually not connected to the specific texture
108  } texture;
109 
110  struct {
111  vulkan_image image;
112  VkImageView view;
113  } depth;
115 
116 b8 vulkan_default_context_create(vulkan_context *context, platform_window *window);
117 void vulkan_context_destroy(vulkan_context *context);
Global typedefs and macros.
Structure holding information about a window.
Definition: window.h:13
Interface to access platform specific windowing functionality.