From eb5d40f92c6d2d1d7491c350cbdcef2e8bf96e06 Mon Sep 17 00:00:00 2001 From: gramanas Date: Thu, 6 Jun 2024 13:41:08 +0300 Subject: build changes --- src/b.h | 17 +++++++++++++--- src/render.c | 62 ++++++++++++++++++++++++++++------------------------------- src/vksetup.h | 6 ++++++ 3 files changed, 49 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/b.h b/src/b.h index e89c1cb..82bf223 100644 --- a/src/b.h +++ b/src/b.h @@ -49,6 +49,8 @@ typedef enum { B_INFO, + B_CMD, + B_BUILDING, B_CHANGE, B_WARNING, B_ERROR, @@ -306,7 +308,7 @@ bool b_mkdir_if_not_exists(const char *path) int result = mkdir(path, 0755); if (result < 0) { if (errno == EEXIST) { - b_log(B_INFO, "directory `%s` already exists", path); + //b_log(B_INFO, "directory `%s` already exists", path); return true; } b_log(B_ERROR, "could not create directory `%s`: %s", path, strerror(errno)); @@ -398,7 +400,7 @@ B_Proc b_cmd_run_async(B_Cmd cmd) B_String_Builder sb = {0}; b_cmd_render(cmd, &sb); b_sb_append_null(&sb); - b_log(B_INFO, "CMD: %s", sb.items); + b_log(B_CMD, "%s", sb.items); b_sb_free(sb); memset(&sb, 0, sizeof(sb)); @@ -486,6 +488,12 @@ void b_log(B_Log_Level level, const char *fmt, ...) case B_INFO: fprintf(stderr, "[INFO] "); break; + case B_CMD: + fprintf(stderr, "[CMD] "); + break; + case B_BUILDING: + fprintf(stderr, "[BUILDING] "); + break; case B_CHANGE: fprintf(stderr, "[CHANGE] "); break; @@ -712,7 +720,10 @@ int b_needs_rebuild(const char *output_path, const char **input_paths, size_t in if (stat(output_path, &statbuf) < 0) { // NOTE: if output does not exist it 100% must be rebuilt - if (errno == ENOENT) return 1; + if (errno == ENOENT) { + b_log(B_BUILDING, "%s", output_path); + return 1; + } b_log(B_ERROR, "could not stat %s: %s", output_path, strerror(errno)); return -1; } diff --git a/src/render.c b/src/render.c index 4893d64..2558bd4 100644 --- a/src/render.c +++ b/src/render.c @@ -13,9 +13,9 @@ #include -#define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 -#include "vk_mem_alloc.h" +/* #define VMA_STATIC_VULKAN_FUNCTIONS 0 */ +/* #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 */ +/* #include "vk_mem_alloc.h" */ #define STB_IMAGE_IMPLEMENTATION #include @@ -1626,7 +1626,6 @@ draw_frame() float dt = time - prev_time; - vkWaitForFences(s.vk.device, 1, &s.frames[currentFrame].in_flight_fence, VK_TRUE, UINT64_MAX); uint32_t imageIndex; @@ -1696,47 +1695,44 @@ main(int argc, char* argv[]) init_state(&s); if (!init()) { vk_log(VK_INFO, "Failed to initialize!\n"); + abort(); } - else { - init_vulkan(); - bool quit = false; + init_vulkan(); + bool quit = false; - /* VMA POC */ - VmaVulkanFunctions vulkanFunctions = {0}; - vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr; - vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr; - VmaAllocatorCreateInfo allocatorCreateInfo = {0}; - allocatorCreateInfo.flags = VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; - allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2; - allocatorCreateInfo.physicalDevice = s.vk.physical_device; - allocatorCreateInfo.device = s.vk.device; - allocatorCreateInfo.instance = s.vk.instance; - allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions; + /* VMA POC */ + VmaVulkanFunctions vulkanFunctions = {0}; + vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr; + vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr; - VmaAllocator allocator; - vmaCreateAllocator(&allocatorCreateInfo, &allocator); + VmaAllocatorCreateInfo allocatorCreateInfo = {0}; + allocatorCreateInfo.flags = VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT; + allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2; + allocatorCreateInfo.physicalDevice = s.vk.physical_device; + allocatorCreateInfo.device = s.vk.device; + allocatorCreateInfo.instance = s.vk.instance; + allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions; - // Entire program... + vmaCreateAllocator(&allocatorCreateInfo, &s.vk.allocator); - // At the end, don't forget to: - vmaDestroyAllocator(allocator); + // At the end, don't forget to: - // Game loop - update_camera(0, 0); - while (!quit) { - handle_input(&quit); - imgui_new_frame(s.vk); - draw_frame(); - //SDL_Delay(16); - } + update_camera(0, 0); - close_vulkan(); + // Game loop + while (!quit) { + handle_input(&quit); + imgui_new_frame(s.vk); + draw_frame(); + //SDL_Delay(16); } - // Free resources and close SDL + vmaDestroyAllocator(s.vk.allocator); + + close_vulkan(); closeSDL(); return 0; diff --git a/src/vksetup.h b/src/vksetup.h index 273a785..608975b 100644 --- a/src/vksetup.h +++ b/src/vksetup.h @@ -47,6 +47,10 @@ #include +#define VMA_STATIC_VULKAN_FUNCTIONS 0 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 +#include "vk_mem_alloc.h" + #include "../lib/cglm/include/cglm/cglm.h" #define VK_ARRAY_LEN(arr) sizeof((arr))/sizeof((arr)[0]) @@ -192,6 +196,8 @@ typedef struct vks_context { vks_image color_image; vks_image depth_image; + VmaAllocator allocator; + VkSampleCountFlagBits msaa_samples; } vks_context; -- cgit v1.2.3