81 lines
1.4 KiB
C
81 lines
1.4 KiB
C
|
|
#if !defined(LD_VULKAN_CORE_H_)
|
||
|
|
#define LD_VULKAN_CORE_H_
|
||
|
|
|
||
|
|
#if OS_WINDOWS
|
||
|
|
#define VK_USE_PLATFORM_WIN32_KHR 1
|
||
|
|
|
||
|
|
#if defined(CreateSemaphore)
|
||
|
|
// Sigh
|
||
|
|
#undef CreateSemaphore
|
||
|
|
#endif
|
||
|
|
#elif OS_LINUX
|
||
|
|
#define VK_USE_PLATFORM_XLIB_KHR 1
|
||
|
|
#define VK_USE_PLATFORM_WAYLAND_KHR 1
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#define VK_NO_PROTOTYPES 1
|
||
|
|
#include <vulkan/vulkan.h>
|
||
|
|
|
||
|
|
#define VK_FRAMES_IN_FLIGHT 2
|
||
|
|
|
||
|
|
typedef struct Vk_Frame Vk_Frame;
|
||
|
|
struct Vk_Frame {
|
||
|
|
VkCommandPool pool;
|
||
|
|
VkCommandBuffer cmd;
|
||
|
|
|
||
|
|
VkSemaphore acquire, complete;
|
||
|
|
VkFence fence;
|
||
|
|
|
||
|
|
U32 image; // swapchain image index
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct Vk_Context Vk_Context;
|
||
|
|
struct Vk_Context {
|
||
|
|
void *lib;
|
||
|
|
PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
|
||
|
|
PFN_vkCreateInstance CreateInstance;
|
||
|
|
|
||
|
|
#define VK_INSTANCE_FUNCTIONS
|
||
|
|
#define VK_DEVICE_FUNCTIONS
|
||
|
|
#define VK_FUNC(x) PFN_vk##x x
|
||
|
|
#include "functions.h"
|
||
|
|
#undef VK_FUNC
|
||
|
|
|
||
|
|
VkResult err;
|
||
|
|
VkInstance instance;
|
||
|
|
|
||
|
|
VkSurfaceKHR surface;
|
||
|
|
|
||
|
|
VkPhysicalDevice gpu;
|
||
|
|
VkDevice device;
|
||
|
|
|
||
|
|
U32 n_frames; // monotonically increasing
|
||
|
|
Vk_Frame frames[VK_FRAMES_IN_FLIGHT];
|
||
|
|
|
||
|
|
struct {
|
||
|
|
U32 family;
|
||
|
|
VkQueue handle;
|
||
|
|
} queue;
|
||
|
|
|
||
|
|
struct {
|
||
|
|
VkSwapchainKHR handle;
|
||
|
|
|
||
|
|
U32 n_images;
|
||
|
|
VkImage images[8];
|
||
|
|
VkImageView views[8];
|
||
|
|
|
||
|
|
VkSurfaceFormatKHR format;
|
||
|
|
|
||
|
|
U32 width;
|
||
|
|
U32 height;
|
||
|
|
} swapchain;
|
||
|
|
};
|
||
|
|
|
||
|
|
extern Vk_Context vk;
|
||
|
|
|
||
|
|
static bool Vk_Setup(SDL_Window *window);
|
||
|
|
static Vk_Frame *Vk_FrameBegin(SDL_Window *window);
|
||
|
|
static void Vk_FrameEnd();
|
||
|
|
|
||
|
|
#endif // LD_VULKAN_CORE_H_
|