Skip to content

Commit

Permalink
started work on vk swapchains
Browse files Browse the repository at this point in the history
  • Loading branch information
Maploop committed Mar 1, 2024
1 parent 7d1e4bc commit 20c7817
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 10 deletions.
11 changes: 8 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"editor.fontFamily": "Liberation Mono",
"editor.fontSize": 15,
"editor.fontWeight": "1",
"workbench.editor.showTabs": "single",
"workbench.editor.showTabs": "multiple",
"workbench.colorCustomizations": {
"editorCursor.foreground": "#ffffff",
"editor.lineHighlightBackground": "#2e1638"
Expand All @@ -21,7 +21,7 @@
"C_Cpp.vcFormat.space.pointerReferenceAlignment": "left",
"C_Cpp.clang_format_sortIncludes": false,
"C_Cpp.vcFormat.indent.namespaceContents": true,
"editor.cursorStyle": "line-thin",
"editor.cursorStyle": "block",
"window.zoomLevel": 0,
"editor.tabCompletion": "on",
"todohighlight.isEnable": true,
Expand Down Expand Up @@ -66,6 +66,11 @@
"darray.h": "c",
"input.h": "c",
"logger.h": "c",
"vulkan_types.inl": "c"
"vulkan_types.inl": "c",
"stdio.h": "c",
"string.h": "c",
"cmemory.h": "c",
"stat.h": "c",
"filesystem.h": "c"
}
}
Binary file modified bin/engine.dll
Binary file not shown.
Binary file modified bin/engine.ilk
Binary file not shown.
Binary file modified bin/engine.pdb
Binary file not shown.
Binary file modified bin/testbed.exe
Binary file not shown.
Binary file modified bin/testbed.ilk
Binary file not shown.
Binary file modified bin/testbed.pdb
Binary file not shown.
5 changes: 3 additions & 2 deletions engine/src/core/logger.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include "logger.h"
#include "asserts.h"
#include "platform/platform.h"
#include "core/cstring.h"

// TODO: Temporary
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

b8 initialize_logging() {
// TODO: Create log file
return TRUE;
}
void shutdown_logging() {
// TODO: Perform any cleanups and write queued entries.

}

KAPI void log_output(log_level level, const char* message, ...) {
Expand All @@ -37,6 +37,7 @@ KAPI void log_output(log_level level, const char* message, ...) {
} else {
platform_console_write(out_message2, level);
}

}

void report_assertion_failure(const char* expression, const char* message, const char* file, i32 line) {
Expand Down
2 changes: 2 additions & 0 deletions engine/src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ STATIC_ASSERT(sizeof(f64) == 8, "Expected f64 to be 8 bytes.");

#define TRUE 1
#define FALSE 0
#define false 0
#define true 1

// Platform detection
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
Expand Down
11 changes: 10 additions & 1 deletion engine/src/renderer/vulkan/vulkan_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ b8 vulkan_renderer_backend_initialize(renderer_backend* backend, const char* app
}

void vulkan_renderer_backend_shutdown(renderer_backend* backend) {
CDEBUG("Destroying Vulkan debugger...");
CDEBUG("Destroying Vulkan device...");
vulkan_device_destroy(&context);

if (context.surface) {
CDEBUG("Destroying Vulkan surface...");
vkDestroySurfaceKHR(context.instance, context.surface, context.allocator);
context.surface = 0;
}

CDEBUG("Destroying Vulkan debugger...")
if (context.debug_messenger) {
PFN_vkDestroyDebugUtilsMessengerEXT func =
(PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(context.instance, "vkDestroyDebugUtilsMessengerEXT");
Expand Down
7 changes: 4 additions & 3 deletions engine/src/renderer/vulkan/vulkan_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ b8 vulkan_device_create(vulkan_context* context) {
queue_create_infos[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
queue_create_infos[i].queueFamilyIndex = indices[i];
queue_create_infos[i].queueCount = 1;
if (indices[i] == context->device.graphics_queue_index) {
queue_create_infos[i].queueCount = 2;
}
// NOTE: Enable this in the future
// if (indices[i] == context->device.graphics_queue_index) {
// queue_create_infos[i].queueCount = 2;
// }
queue_create_infos[i].flags = 0;
queue_create_infos[i].pNext = 0;
f32 queue_priority = 1.0f;
Expand Down
21 changes: 21 additions & 0 deletions engine/src/renderer/vulkan/vulkan_swapchain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "vulkan_swapchain.h"

#include "core/logger.h"
#include "core/cmemory.h"
#include "vulkan_device.h"

void create(vulkan_context* context, u32 width, u32 height, vulkan_swapchain* swapchain);
void destroy(vulkan_context* context, vulkan_swapchain* swapchain);

void vulkan_swapchain_create(vulkan_context* context, u32 width, u32 height, vulkan_swapchain* out_swapchain) {
create(context, width, height, out_swapchain);
}

void vulkan_swapchain_recreate(vulkan_context* context, u32 width, u32 height, vulkan_swapchain* out_swapchain) {
destroy(context, out_swapchain);
create(context, width, height, out_swapchain);
}

void vulkan_swapchain_destroy(vulkan_context* context, vulkan_swapchain* swapchain) {
destroy(context, swapchain);
}
16 changes: 16 additions & 0 deletions engine/src/renderer/vulkan/vulkan_swapchain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "vulkan_types.inl"
#include "core/asserts.h"

void vulkan_swapchain_create(vulkan_context* context, u32 width, u32 height, vulkan_swapchain* out_swapchain);

void vulkan_swapchain_recreate(vulkan_context* context, u32 width, u32 height, vulkan_swapchain* out_swapchain);

void vulkan_swapchain_destroy(vulkan_context* context, vulkan_swapchain* swapchain);

b8 vulkan_swapchina_acquire_image_next(vulkan_context* context, vulkan_swapchain* swapchain,
u64 timeout_ns, VkSemaphore image_available_semaphore, VkFence fence, u32* out_image_index);

void vulkan_swapchain_present(vulkan_context* context, vulkan_swapchain* swapchain, VkQueue graphics_queue, VkQueue present_queue,
VkSemaphore render_complete_semaphore, u32 present_image_index);
9 changes: 9 additions & 0 deletions engine/src/renderer/vulkan/vulkan_types.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ typedef struct vulkan_device {
VkPhysicalDeviceMemoryProperties memory;
} vulkan_device;

typedef struct vulkan_swapchain {
VkSurfaceFormatKHR* image_format;
u8 max_frames_in_flight;
VkSwapchainKHR handle;
u32 image_count;
VkImage* images;
VkImageView* views;
} vulkan_swapchain;

typedef struct vulkan_context {
VkInstance instance;
VkAllocationCallbacks* allocator;
Expand Down
2 changes: 1 addition & 1 deletion testbed/src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ b8 create_game(game* out_game) {
out_game->app_config.start_pos_y = 100;
out_game->app_config.start_width = 1280;
out_game->app_config.start_height = 720;
out_game->app_config.name = "Cora Engine Gamma TESTBED-A";
out_game->app_config.name = "FR Engine Testbed";

out_game->update = game_update;
out_game->initialize = game_initialize;
Expand Down

0 comments on commit 20c7817

Please sign in to comment.