Added memory arena

Fixed frames in flight validation error in vulkan
Added some utility macros
Added function decorator macros
Added some consolidation headers/code include files
This commit is contained in:
2025-10-04 00:46:26 +01:00
parent 9f2ef576b9
commit 5f07239374
13 changed files with 429 additions and 12 deletions

View File

@@ -294,10 +294,16 @@ bool Vk_Setup(SDL_Window *window) {
vk.GetSwapchainImagesKHR(vk.device, vk.swapchain.handle, &n_images, 0);
vk.GetSwapchainImagesKHR(vk.device, vk.swapchain.handle, &n_images, vk.swapchain.images);
vk.in_flight = n_images + 1;
if (n_images != vk.swapchain.n_images) {
printf("[Warn] :: Swapchain image count mismatch\n");
vk.swapchain.n_images = n_images;
}
else if (n_images >= VK_MAX_FRAMES_IN_FLIGHT) {
printf("[Warn] :: Min image count too high: %d\n", n_images);
vk.in_flight = VK_MAX_FRAMES_IN_FLIGHT;
}
VkImageViewCreateInfo create_info = { 0 };
create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
@@ -314,7 +320,7 @@ bool Vk_Setup(SDL_Window *window) {
}
}
for (U32 it = 0; it < VK_FRAMES_IN_FLIGHT && vk.err == VK_SUCCESS; ++it) {
for (U32 it = 0; it < vk.in_flight && vk.err == VK_SUCCESS; ++it) {
Vk_Frame *frame = &vk.frames[it];
VkCommandPoolCreateInfo pool = { 0 };
@@ -353,7 +359,7 @@ bool Vk_Setup(SDL_Window *window) {
Vk_Frame *Vk_FrameBegin(SDL_Window *window) {
(void) window; // might need this for the resize later
Vk_Frame *frame = &vk.frames[vk.n_frames & 1];
Vk_Frame *frame = &vk.frames[vk.n_frames % vk.in_flight];
vk.WaitForFences(vk.device, 1, &frame->fence, VK_TRUE, UINT64_MAX);
@@ -372,7 +378,7 @@ Vk_Frame *Vk_FrameBegin(SDL_Window *window) {
}
void Vk_FrameEnd() {
Vk_Frame *frame = &vk.frames[vk.n_frames & 1];
Vk_Frame *frame = &vk.frames[vk.n_frames % vk.in_flight];
vk.EndCommandBuffer(frame->cmd);

View File

@@ -13,10 +13,16 @@
#define VK_USE_PLATFORM_WAYLAND_KHR 1
#endif
#if defined(function)
#undef function
#endif
#define VK_NO_PROTOTYPES 1
#include <vulkan/vulkan.h>
#define VK_FRAMES_IN_FLIGHT 2
#define function static
#define VK_MAX_FRAMES_IN_FLIGHT 8
typedef struct Vk_Frame Vk_Frame;
struct Vk_Frame {
@@ -49,8 +55,10 @@ struct Vk_Context {
VkPhysicalDevice gpu;
VkDevice device;
U32 n_frames; // monotonically increasing
Vk_Frame frames[VK_FRAMES_IN_FLIGHT];
U32 n_frames; // monotonically increasing
U32 in_flight; // number of frames in flight, number of swapchain images + 1
Vk_Frame frames[VK_MAX_FRAMES_IN_FLIGHT];
struct {
U32 family;
@@ -73,8 +81,9 @@ struct Vk_Context {
extern Vk_Context vk;
static bool Vk_Setup(SDL_Window *window);
static Vk_Frame *Vk_FrameBegin(SDL_Window *window);
static void Vk_FrameEnd();
function bool Vk_Setup(SDL_Window *window);
function Vk_Frame *Vk_FrameBegin(SDL_Window *window);
function void Vk_FrameEnd();
#endif // LD_VULKAN_CORE_H_

View File

@@ -38,6 +38,7 @@
VK_FUNC(QueuePresentKHR);
VK_FUNC(BeginCommandBuffer);
VK_FUNC(EndCommandBuffer);
VK_FUNC(DeviceWaitIdle);
VK_FUNC(CmdPipelineBarrier2);
VK_FUNC(CmdBeginRendering);