101 lines
3.2 KiB
C
101 lines
3.2 KiB
C
|
#ifndef INCLUDE_WAYLANDCLIENT_CAT_VULKAN_H_
|
||
|
#define INCLUDE_WAYLANDCLIENT_CAT_VULKAN_H_
|
||
|
|
||
|
#include <vulkan/vulkan.h>
|
||
|
|
||
|
#include "dynarray.h"
|
||
|
#include "types.h"
|
||
|
|
||
|
#define CHECK_VK_RESULT(_expr) \
|
||
|
do { \
|
||
|
VkResult result = _expr; \
|
||
|
if (result != VK_SUCCESS) { \
|
||
|
meow("Error executing %s: %i\n", #_expr, result); \
|
||
|
} \
|
||
|
} while (0);
|
||
|
|
||
|
#define GET_EXTENSION_FUNCTION($instance, _id) \
|
||
|
((PFN_##_id)(vkGetInstanceProcAddr($instance, #_id)))
|
||
|
|
||
|
#define MAX_FRAMES_IN_FLIGHT 2
|
||
|
|
||
|
dyn_array_define(da_VK_FORMAT, enum VkFormat);
|
||
|
dyn_array_define(da_Kitty, struct Kitty *);
|
||
|
|
||
|
struct VertexBuffer {
|
||
|
void *data;
|
||
|
VkBuffer buffer;
|
||
|
VkDeviceMemory memory;
|
||
|
uint32_t count;
|
||
|
int vertex_size;
|
||
|
int binding;
|
||
|
struct da_VK_FORMAT format;
|
||
|
};
|
||
|
|
||
|
struct InFlightObjects {
|
||
|
VkSemaphore image_available_semaphore;
|
||
|
VkSemaphore render_finished_semaphore;
|
||
|
VkFence in_flight_fence;
|
||
|
VkCommandBuffer command_buffer;
|
||
|
};
|
||
|
|
||
|
struct SwapchainElm {
|
||
|
VkImage image;
|
||
|
VkImageView image_view;
|
||
|
VkFramebuffer framebuffer;
|
||
|
};
|
||
|
|
||
|
struct Vk {
|
||
|
VkInstance instance;
|
||
|
|
||
|
VkPhysicalDevice phys_device;
|
||
|
VkDevice device;
|
||
|
|
||
|
VkDebugUtilsMessengerEXT debug_messenger;
|
||
|
|
||
|
VkSurfaceKHR vulkan_surface;
|
||
|
|
||
|
uint32_t queue_family_index_present;
|
||
|
VkQueue queue_present;
|
||
|
uint32_t queue_family_index_graphics;
|
||
|
VkQueue queue_graphics;
|
||
|
float queue_priority;
|
||
|
|
||
|
VkCommandPool command_pool;
|
||
|
VkFormat format;
|
||
|
uint32_t image_count;
|
||
|
VkSwapchainKHR swapchain;
|
||
|
struct SwapchainElm *elements;
|
||
|
struct InFlightObjects flights[MAX_FRAMES_IN_FLIGHT];
|
||
|
int current_frame;
|
||
|
uint32_t width;
|
||
|
uint32_t heigh;
|
||
|
VkRenderPass render_pass;
|
||
|
|
||
|
struct da_Kitty kitties;
|
||
|
};
|
||
|
|
||
|
struct Vk *init_vk(void *data, int width, int heigh,
|
||
|
VkSurfaceKHR (*surface)(void *, VkInstance));
|
||
|
void uninit_vk(struct Vk *state);
|
||
|
void vk_draw(struct Vk *state);
|
||
|
void vk_resize(struct Vk *state, int width, int heigh);
|
||
|
|
||
|
void create_buffer(struct Vk *state, VkDeviceSize size,
|
||
|
VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
|
||
|
VkBuffer *buffer, VkDeviceMemory *buffer_memory);
|
||
|
void copy_buffer(struct Vk *state, VkBuffer src_buffer, VkBuffer dst_buffer,
|
||
|
VkDeviceSize size);
|
||
|
void create_image(struct Vk *state, struct IVec2 dims, VkFormat format,
|
||
|
VkImageTiling tiling, VkImageUsageFlags usage,
|
||
|
VkMemoryPropertyFlags properties, VkImage *image,
|
||
|
VkDeviceMemory *memory);
|
||
|
void transition_image_layout(struct Vk *state, VkImage image, VkFormat format,
|
||
|
VkImageLayout old_layout,
|
||
|
VkImageLayout new_layout);
|
||
|
void copy_buffer_to_image(struct Vk *state, VkBuffer buffer, VkImage image,
|
||
|
struct IVec2 size);
|
||
|
VkShaderModule create_shader_module(struct Vk *state, uint32_t *data, int size);
|
||
|
|
||
|
#endif // INCLUDE_WAYLANDCLIENT_CAT_VULKAN_H_
|