summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--render/directx/renderer.c25
-rw-r--r--render/vulkan/context.c113
-rw-r--r--render/vulkan/context.h27
-rw-r--r--render/vulkan/device.c51
-rw-r--r--render/vulkan/device.h31
-rw-r--r--render/vulkan/fence.c41
-rw-r--r--render/vulkan/fence.h29
-rw-r--r--render/vulkan/framebuffer.c27
-rw-r--r--render/vulkan/framebuffer.h25
-rw-r--r--render/vulkan/image.c29
-rw-r--r--render/vulkan/image.h25
-rw-r--r--render/vulkan/renderpass.c45
-rw-r--r--render/vulkan/renderpass.h47
-rw-r--r--render/vulkan/swapchain.c48
-rw-r--r--render/vulkan/swapchain.h28
-rw-r--r--render/vulkan/vk_types.h99
-rw-r--r--render/vulkan/vkassert.h21
17 files changed, 556 insertions, 155 deletions
diff --git a/render/directx/renderer.c b/render/directx/renderer.c
index c0cac9c..8820441 100644
--- a/render/directx/renderer.c
+++ b/render/directx/renderer.c
@@ -1,17 +1,38 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include <rune/core/abort.h>
#include <rune/core/logging.h>
#include <rune/render/renderer.h>
#ifdef _WIN32
-struct rune_renderer* select_render_directx(struct rune_window *window) {
+struct rune_renderer* select_render_directx(window_t *window) {
log_output(LOG_FATAL, "DirectX support has not yet been implemented");
rune_abort();
}
#else
-struct rune_renderer* select_render_directx(struct rune_window *window) {
+struct rune_renderer* select_render_directx(window_t *window) {
log_output(LOG_FATAL, "DirectX is not supported on this platform");
rune_abort();
}
diff --git a/render/vulkan/context.c b/render/vulkan/context.c
index eaf4cf3..5d78dd4 100644
--- a/render/vulkan/context.c
+++ b/render/vulkan/context.c
@@ -1,7 +1,29 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "context.h"
#include "vkassert.h"
#include <rune/core/logging.h>
#include <rune/core/alloc.h>
+#include <rune/core/config.h>
#include <stdlib.h>
#include <string.h>
@@ -29,18 +51,28 @@ VKAPI_ATTR VkBool32 VKAPI_CALL _vulkan_db_callback(
return VK_FALSE;
}
-int _init_vkdebugger(struct vkcontext *context) {
+int _init_vkdebugger(vkcontext_t *context) {
log_output(LOG_INFO, "Initializing Vulkan debugger");
- uint32_t log_severity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
- VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
- VkDebugUtilsMessengerCreateInfoEXT dbinfo = {VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
- dbinfo.messageSeverity = log_severity;
+
+ VkDebugUtilsMessengerCreateInfoEXT dbinfo;
+ dbinfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
+ dbinfo.pNext = NULL;
+ dbinfo.flags = 0;
+ dbinfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
+ VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT;
dbinfo.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
dbinfo.pfnUserCallback = _vulkan_db_callback;
dbinfo.pUserData = NULL;
- PFN_vkCreateDebugUtilsMessengerEXT func = (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(context->instance, "vkCreateDebugUtilsMessengerEXT");
+
+ PFN_vkCreateDebugUtilsMessengerEXT func =
+ (PFN_vkCreateDebugUtilsMessengerEXT)
+ vkGetInstanceProcAddr(context->instance,
+ "vkCreateDebugUtilsMessengerEXT");
+
if (func == NULL) {
log_output(LOG_ERROR, "Failed to create Vulkan debugger");
return -1;
@@ -50,63 +82,80 @@ int _init_vkdebugger(struct vkcontext *context) {
res = func(context->instance, &dbinfo, NULL, &context->db_messenger);
if (res != VK_SUCCESS) {
char *err_str = get_vkerr_str(res);
- log_output(LOG_ERROR, "Cannot create a Vulkan debug session: %s", err_str);
+ log_output(LOG_ERROR, "Debug session error: %s", err_str);
free(err_str);
return -1;
}
return 0;
}
-struct vkcontext* create_vkcontext(struct vklayer_container *vklayers, struct ext_container *ext) {
- log_output(LOG_DEBUG, "Initializing Vulkan");
- VkApplicationInfo app_info = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
+vkcontext_t* create_vkcontext(vklayer_container_t *vklayers, ext_container_t *ext) {
+ vkcontext_t *ret = rune_calloc(0, sizeof(vkcontext_t));
+ ret->surface = rune_alloc(sizeof(vksurface_t));
+
+ VkApplicationInfo app_info;
+ app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
+ app_info.pNext = NULL;
app_info.apiVersion = VK_API_VERSION_1_2;
- app_info.pApplicationName = "RuneClient";
- app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
+ app_info.pApplicationName = rune_get_app_name();
+ int *app_ver = rune_get_app_ver();
+ app_info.applicationVersion = VK_MAKE_VERSION(app_ver[0],
+ app_ver[1],
+ app_ver[2]);
app_info.pEngineName = "RuneEngine";
- app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
+ app_info.engineVersion = VK_MAKE_VERSION(RUNE_VER_MAJOR,
+ RUNE_VER_MINOR,
+ RUNE_VER_PATCH);
- VkInstanceCreateInfo cinfo = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
+ VkInstanceCreateInfo cinfo;
+ cinfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
+ cinfo.pNext = NULL;
+ cinfo.flags = 0;
cinfo.pApplicationInfo = &app_info;
cinfo.enabledExtensionCount = ext->ext_count;
cinfo.ppEnabledExtensionNames = ext->extensions;
cinfo.pNext = NULL;
- struct vkcontext *ret = rune_calloc(0, sizeof(struct vkcontext));
- ret->surface = rune_alloc(sizeof(struct vksurface));
- VkResult res;
- res = vkCreateInstance(&cinfo, NULL, &ret->instance);
- if (res != VK_SUCCESS) {
- char *err_str = get_vkerr_str(res);
- log_output(LOG_FATAL, "Cannot create a Vulkan instance: %s", err_str);
- free(err_str);
- rune_free(ret);
- ret = NULL;
- }
-
if (vklayers != NULL) {
log_output(LOG_INFO, "Validation layers enabled");
- _init_vkdebugger(ret);
cinfo.enabledLayerCount = vklayers->vklayer_count;
cinfo.ppEnabledLayerNames = vklayers->vklayer_names;
} else {
log_output(LOG_INFO, "Validation layers disabled");
+ cinfo.enabledLayerCount = 0;
+ cinfo.ppEnabledLayerNames = NULL;
+ }
+
+ VkResult res;
+ res = vkCreateInstance(&cinfo, NULL, &ret->instance);
+ if (res != VK_SUCCESS) {
+ char *err_str = get_vkerr_str(res);
+ log_output(LOG_FATAL, "Cannot create a Vulkan instance: %s", err_str);
+ rune_abort();
}
+
+ if (vklayers != NULL)
+ _init_vkdebugger(ret);
return ret;
}
-void destroy_vkcontext(struct vkcontext *context) {
+void destroy_vkcontext(vkcontext_t *context) {
log_output(LOG_DEBUG, "Closing Vulkan instance");
- PFN_vkDestroyDebugUtilsMessengerEXT func = (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(context->instance, "vkDestroyDebugUtilsMessengerEXT");
- func(context->instance, context->db_messenger, NULL);
+ if (rune_get_vk_debug() == 1) {
+ PFN_vkDestroyDebugUtilsMessengerEXT func =
+ (PFN_vkDestroyDebugUtilsMessengerEXT)
+ vkGetInstanceProcAddr(context->instance,
+ "vkDestroyDebugUtilsMessengerEXT");
+ func(context->instance, context->db_messenger, NULL);
+ }
vkDestroySurfaceKHR(context->instance, context->surface->handle, NULL);
vkDestroyInstance(context->instance, NULL);
rune_free(context->surface);
rune_free(context);
}
-struct vklayer_container* init_vklayers(struct ext_container *ext) {
+vklayer_container_t* init_vklayers(ext_container_t *ext) {
const char** new_extensions = rune_alloc(sizeof(char*) * ext->ext_count++);
for (uint32_t i = 0; i < ext->ext_count-1; i++)
new_extensions[i] = ext->extensions[i];
@@ -118,7 +167,7 @@ struct vklayer_container* init_vklayers(struct ext_container *ext) {
VkLayerProperties layer_props[layer_count];
vkEnumerateInstanceLayerProperties(&layer_count, layer_props);
- struct vklayer_container *ret = rune_alloc(sizeof(struct vklayer_container));
+ vklayer_container_t *ret = rune_alloc(sizeof(vklayer_container_t));
ret->vklayer_count = 1;
ret->vklayer_names = rune_alloc(sizeof(char*) * ret->vklayer_count);
ret->vklayer_names[0] = "VK_LAYER_KHRONOS_validation";
diff --git a/render/vulkan/context.h b/render/vulkan/context.h
index e671223..15817e8 100644
--- a/render/vulkan/context.h
+++ b/render/vulkan/context.h
@@ -1,11 +1,32 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKCONTEXT_H
#define VKCONTEXT_H
#include "vk_types.h"
-struct vkcontext* create_vkcontext(struct vklayer_container *vklayers, struct ext_container *ext);
-void destroy_vkcontext(struct vkcontext *context);
+vkcontext_t* create_vkcontext(vklayer_container_t *vklayers, ext_container_t *ext);
+void destroy_vkcontext(vkcontext_t *context);
-struct vklayer_container* init_vklayers(struct ext_container *ext);
+vklayer_container_t* init_vklayers(ext_container_t *ext);
#endif
diff --git a/render/vulkan/device.c b/render/vulkan/device.c
index 1254f76..583fb54 100644
--- a/render/vulkan/device.c
+++ b/render/vulkan/device.c
@@ -1,3 +1,24 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "device.h"
#include "vkassert.h"
#include <rune/core/alloc.h>
@@ -103,7 +124,7 @@ VkPhysicalDevice _select_pdev(VkInstance instance, VkSurfaceKHR surface) {
return NULL;
}
-void _create_queue(struct vkdev *dev, int qfam_index, int queue_index) {
+void _create_queue(vkdev_t *dev, int qfam_index, int queue_index) {
vkGetDeviceQueue(dev->ldev, qfam_index, queue_index, &dev->queues[qfam_index].handle);
if (dev->queues[qfam_index].handle == NULL) {
log_output(LOG_FATAL, "Error creating required Vulkan queue");
@@ -111,20 +132,20 @@ void _create_queue(struct vkdev *dev, int qfam_index, int queue_index) {
}
}
-struct vkdev* create_vkdev(VkInstance instance, VkSurfaceKHR surface) {
+vkdev_t* create_vkdev(VkInstance instance, VkSurfaceKHR surface) {
VkPhysicalDevice pdev = _select_pdev(instance, surface);
if (pdev == NULL) {
log_output(LOG_FATAL, "No device meets minimum requirements for rendering");
rune_abort();
}
- struct vkdev *dev = rune_calloc(0, sizeof(struct vkdev));
+ vkdev_t *dev = rune_calloc(0, sizeof(vkdev_t));
dev->pdev = pdev;
- dev->queues[0].index = gfx_qfam;
- dev->queues[1].index = tsfr_qfam;
- dev->queues[2].index = comp_qfam;
- dev->queues[3].index = pres_qfam;
+ dev->queues[0].qfam = gfx_qfam;
+ dev->queues[1].qfam = tsfr_qfam;
+ dev->queues[2].qfam = comp_qfam;
+ dev->queues[3].qfam = 0;
float queue_priority = 1.0f;
VkDeviceQueueCreateInfo qcinfos[3];
@@ -132,7 +153,7 @@ struct vkdev* create_vkdev(VkInstance instance, VkSurfaceKHR surface) {
qcinfos[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
qcinfos[i].pNext = NULL;
qcinfos[i].flags = 0;
- qcinfos[i].queueFamilyIndex = dev->queues[i].index;
+ qcinfos[i].queueFamilyIndex = dev->queues[i].qfam;
qcinfos[i].queueCount = 1;
qcinfos[i].pQueuePriorities = &queue_priority;
}
@@ -157,23 +178,27 @@ struct vkdev* create_vkdev(VkInstance instance, VkSurfaceKHR surface) {
for (uint32_t i = 0; i < 3; i++)
_create_queue(dev, i, 0);
+ // FIXME: This is a dirty hack and should be fixed
+ dev->queues[3].handle = dev->queues[0].handle;
+
VkCommandPoolCreateInfo pcinfo;
pcinfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
pcinfo.pNext = NULL;
pcinfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
- pcinfo.queueFamilyIndex = dev->queues[0].index;
+ pcinfo.queueFamilyIndex = dev->queues[0].qfam;
vkassert(vkCreateCommandPool(dev->ldev, &pcinfo, NULL, &dev->cmd_pool));
log_output(LOG_DEBUG, "Initialized new logical device");
return dev;
}
-void destroy_vkdev(struct vkdev *dev) {
+void destroy_vkdev(vkdev_t *dev) {
+ vkDestroyCommandPool(dev->ldev, dev->cmd_pool, NULL);
vkDestroyDevice(dev->ldev, NULL);
rune_free(dev);
}
-void get_swapchain_data(struct vkdev *dev, VkSurfaceKHR *surface) {
+void get_swapchain_data(vkdev_t *dev, VkSurfaceKHR *surface) {
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(dev->pdev, *surface, &dev->scdata.capabilities);
vkGetPhysicalDeviceSurfaceFormatsKHR(dev->pdev, *surface, &dev->scdata.format_count, NULL);
@@ -185,7 +210,7 @@ void get_swapchain_data(struct vkdev *dev, VkSurfaceKHR *surface) {
vkGetPhysicalDeviceSurfacePresentModesKHR(dev->pdev, *surface, &dev->scdata.present_count, dev->scdata.present_modes);
}
-int get_depth_format(struct vkdev *dev) {
+int get_depth_format(vkdev_t *dev) {
const uint64_t count = 3;
VkFormat formats[3] = {
VK_FORMAT_D32_SFLOAT_S8_UINT,
@@ -207,7 +232,7 @@ int get_depth_format(struct vkdev *dev) {
return 0;
}
-uint32_t get_memory_index(struct vkdev *dev, uint32_t type, uint32_t flags) {
+uint32_t get_memory_index(vkdev_t *dev, uint32_t type, uint32_t flags) {
VkPhysicalDeviceMemoryProperties mem_props;
vkGetPhysicalDeviceMemoryProperties(dev->pdev, &mem_props);
diff --git a/render/vulkan/device.h b/render/vulkan/device.h
index 6e3f5aa..b375c5b 100644
--- a/render/vulkan/device.h
+++ b/render/vulkan/device.h
@@ -1,13 +1,34 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKDEVICE_H
#define VKDEVICE_H
#include "vk_types.h"
-struct vkdev* create_vkdev(VkInstance instance, VkSurfaceKHR surface);
-void destroy_vkdev(struct vkdev *dev);
+vkdev_t* create_vkdev(VkInstance instance, VkSurfaceKHR surface);
+void destroy_vkdev(vkdev_t *dev);
-void get_swapchain_data(struct vkdev *dev, VkSurfaceKHR *surface);
-int get_depth_format(struct vkdev *dev);
-uint32_t get_memory_index(struct vkdev *dev, uint32_t type, uint32_t flags);
+void get_swapchain_data(vkdev_t *dev, VkSurfaceKHR *surface);
+int get_depth_format(vkdev_t *dev);
+uint32_t get_memory_index(vkdev_t *dev, uint32_t type, uint32_t flags);
#endif
diff --git a/render/vulkan/fence.c b/render/vulkan/fence.c
index 538bc9d..cee022e 100644
--- a/render/vulkan/fence.c
+++ b/render/vulkan/fence.c
@@ -1,10 +1,31 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "fence.h"
#include "vkassert.h"
#include <rune/core/logging.h>
#include <rune/core/alloc.h>
-struct vkfence* create_vkfence(struct vkdev *dev, uint8_t signal) {
- struct vkfence *ret = rune_alloc(sizeof(struct vkfence));
+vkfence_t* create_vkfence(vkdev_t *dev, uint8_t signal) {
+ vkfence_t *ret = rune_alloc(sizeof(vkfence_t));
VkFenceCreateInfo fcinfo;
fcinfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
@@ -17,7 +38,7 @@ struct vkfence* create_vkfence(struct vkdev *dev, uint8_t signal) {
return ret;
}
-void destroy_vkfence(struct vkfence *fence, struct vkdev *dev) {
+void destroy_vkfence(vkfence_t *fence, vkdev_t *dev) {
if (fence->handle != NULL) {
vkDestroyFence(dev->ldev, fence->handle, NULL);
fence->handle = NULL;
@@ -25,15 +46,15 @@ void destroy_vkfence(struct vkfence *fence, struct vkdev *dev) {
rune_free(fence);
}
-uint8_t fence_lock(struct vkfence *fence, struct vkdev *dev, uint64_t timeout) {
- if (fence->signal)
- return 1;
+int fence_lock(vkfence_t *fence, vkdev_t *dev, uint64_t timeout) {
+ if (fence->signal == 1)
+ return 0;
VkResult res = vkWaitForFences(dev->ldev, 1, &fence->handle, VK_TRUE, timeout);
switch (res) {
case VK_SUCCESS:
fence->signal = 1;
- return 1;
+ return 0;
case VK_TIMEOUT:
log_output(LOG_WARN, "Vulkan fence timed out");
break;
@@ -51,13 +72,13 @@ uint8_t fence_lock(struct vkfence *fence, struct vkdev *dev, uint64_t timeout) {
break;
}
- return 0;
+ return -1;
}
-void fence_unlock(struct vkfence *fence, struct vkdev *dev) {
+void fence_unlock(vkfence_t *fence, vkdev_t *dev) {
if (fence->signal == 0)
return;
vkassert(vkResetFences(dev->ldev, 1, &fence->handle));
- fence->signal = 1;
+ fence->signal = 0;
}
diff --git a/render/vulkan/fence.h b/render/vulkan/fence.h
index 16e309d..49a04fe 100644
--- a/render/vulkan/fence.h
+++ b/render/vulkan/fence.h
@@ -1,12 +1,33 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKFENCE_H
#define VKFENCE_H
#include "vk_types.h"
-struct vkfence* create_vkfence(struct vkdev *dev, uint8_t signal);
-void destroy_vkfence(struct vkfence *fence, struct vkdev *dev);
+vkfence_t* create_vkfence(vkdev_t *dev, uint8_t signal);
+void destroy_vkfence(vkfence_t *fence, vkdev_t *dev);
-uint8_t fence_lock(struct vkfence *fence, struct vkdev *dev, uint64_t timeout);
-void fence_unlock(struct vkfence *fence, struct vkdev *dev);
+int fence_lock(vkfence_t *fence, vkdev_t *dev, uint64_t timeout);
+void fence_unlock(vkfence_t *fence, vkdev_t *dev);
#endif
diff --git a/render/vulkan/framebuffer.c b/render/vulkan/framebuffer.c
index 755af29..697bbb9 100644
--- a/render/vulkan/framebuffer.c
+++ b/render/vulkan/framebuffer.c
@@ -1,10 +1,31 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "framebuffer.h"
#include "vkassert.h"
#include <rune/core/alloc.h>
#include <rune/core/logging.h>
-struct vkframebuffer* create_vkframebuffer(struct vkdev *dev, struct vkrendpass *rendpass, uint32_t width, uint32_t height, uint32_t at_count, VkImageView *at) {
- struct vkframebuffer *ret = rune_alloc(sizeof(struct vkframebuffer));
+vkframebuffer_t* create_vkframebuffer(vkdev_t *dev, vkrendpass_t *rendpass, uint32_t width, uint32_t height, uint32_t at_count, VkImageView *at) {
+ vkframebuffer_t *ret = rune_alloc(sizeof(vkframebuffer_t));
ret->at_count = at_count;
ret->attachments = rune_alloc(sizeof(VkImageView) * at_count);
for (uint32_t i = 0; i < at_count; i++)
@@ -26,7 +47,7 @@ struct vkframebuffer* create_vkframebuffer(struct vkdev *dev, struct vkrendpass
return ret;
}
-void destroy_vkframebuffer(struct vkframebuffer *framebuffer, struct vkdev *dev) {
+void destroy_vkframebuffer(vkframebuffer_t *framebuffer, vkdev_t *dev) {
vkDestroyFramebuffer(dev->ldev, framebuffer->handle, NULL);
if (framebuffer->attachments)
rune_free(framebuffer->attachments);
diff --git a/render/vulkan/framebuffer.h b/render/vulkan/framebuffer.h
index a5bfd59..dbf914d 100644
--- a/render/vulkan/framebuffer.h
+++ b/render/vulkan/framebuffer.h
@@ -1,9 +1,30 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKFRAMEBUFFER_H
#define VKFRAMEBUFFER_H
#include "vk_types.h"
-struct vkframebuffer* create_vkframebuffer(struct vkdev *dev, struct vkrendpass *rendpass, uint32_t width, uint32_t height, uint32_t at_count, VkImageView *at);
-void destroy_vkframebuffer(struct vkframebuffer *framebuffer, struct vkdev *dev);
+vkframebuffer_t* create_vkframebuffer(vkdev_t *dev, vkrendpass_t *rendpass, uint32_t width, uint32_t height, uint32_t at_count, VkImageView *at);
+void destroy_vkframebuffer(vkframebuffer_t *framebuffer, vkdev_t *dev);
#endif
diff --git a/render/vulkan/image.c b/render/vulkan/image.c
index 41548f6..0334e94 100644
--- a/render/vulkan/image.c
+++ b/render/vulkan/image.c
@@ -1,9 +1,30 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "image.h"
#include "device.h"
#include "vkassert.h"
#include <rune/core/alloc.h>
-int _create_image_view(struct vkimage *image, struct vkdev *dev, VkFormat format, VkImageAspectFlags aflags) {
+int _create_image_view(vkimage_t *image, vkdev_t *dev, VkFormat format, VkImageAspectFlags aflags) {
VkImageViewCreateInfo vcinfo;
vcinfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
vcinfo.pNext = NULL;
@@ -23,8 +44,8 @@ int _create_image_view(struct vkimage *image, struct vkdev *dev, VkFormat format
vkassert(vkCreateImageView(dev->ldev, &vcinfo, NULL, &image->view));
}
-struct vkimage* create_vkimage(struct vkdev *dev, VkFormat format, uint32_t width, uint32_t height, uint32_t usage, uint32_t mem_flags, uint32_t aflags, int create_view) {
- struct vkimage *ret = rune_alloc(sizeof(struct vkimage));
+vkimage_t* create_vkimage(vkdev_t *dev, VkFormat format, uint32_t width, uint32_t height, uint32_t usage, uint32_t mem_flags, uint32_t aflags, int create_view) {
+ vkimage_t *ret = rune_alloc(sizeof(vkimage_t));
ret->width = width;
ret->height = height;
@@ -67,7 +88,7 @@ struct vkimage* create_vkimage(struct vkdev *dev, VkFormat format, uint32_t widt
return ret;
}
-void destroy_vkimage(struct vkimage *image, struct vkdev *dev) {
+void destroy_vkimage(vkimage_t *image, vkdev_t *dev) {
if (image->view)
vkDestroyImageView(dev->ldev, image->view, NULL);
if (image->memory)
diff --git a/render/vulkan/image.h b/render/vulkan/image.h
index 7b96695..067025d 100644
--- a/render/vulkan/image.h
+++ b/render/vulkan/image.h
@@ -1,9 +1,30 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKIMAGE_H
#define VKIMAGE_H
#include "vk_types.h"
-struct vkimage* create_vkimage(struct vkdev *dev, VkFormat format, uint32_t width, uint32_t height, uint32_t usage, uint32_t mem_flags, uint32_t aflags, int create_view);
-void destroy_vkimage(struct vkimage *image, struct vkdev *dev);
+vkimage_t* create_vkimage(vkdev_t *dev, VkFormat format, uint32_t width, uint32_t height, uint32_t usage, uint32_t mem_flags, uint32_t aflags, int create_view);
+void destroy_vkimage(vkimage_t *image, vkdev_t *dev);
#endif
diff --git a/render/vulkan/renderpass.c b/render/vulkan/renderpass.c
index 339983d..ea3dd5b 100644
--- a/render/vulkan/renderpass.c
+++ b/render/vulkan/renderpass.c
@@ -1,9 +1,30 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "renderpass.h"
#include "vkassert.h"
#include <rune/core/alloc.h>
-struct vkcmdbuffer* create_vkcmdbuffer(struct vkdev *dev, int primary) {
- struct vkcmdbuffer *ret = rune_calloc(0, sizeof(struct vkcmdbuffer));
+vkcmdbuffer_t* create_vkcmdbuffer(vkdev_t *dev, int primary) {
+ vkcmdbuffer_t *ret = rune_calloc(0, sizeof(vkcmdbuffer_t));
VkCommandBufferAllocateInfo ainfo;
ainfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
@@ -16,11 +37,11 @@ struct vkcmdbuffer* create_vkcmdbuffer(struct vkdev *dev, int primary) {
ainfo.commandBufferCount = 1;
vkassert(vkAllocateCommandBuffers(dev->ldev, &ainfo, &ret->handle));
- ret->state = CMDBUF_READY;
+ ret->state = CMDBUF_INITIAL;
return ret;
}
-void destroy_vkcmdbuffer(struct vkcmdbuffer *cmdbuffer, struct vkdev *dev) {
+void destroy_vkcmdbuffer(vkcmdbuffer_t *cmdbuffer, vkdev_t *dev) {
vkFreeCommandBuffers(dev->ldev, dev->cmd_pool, 1, &cmdbuffer->handle);
rune_free(cmdbuffer);
}
@@ -37,12 +58,12 @@ void cmdbuf_begin(struct vkcmdbuffer *cmdbuffer, int single, int rpass_cont, int
if (sim_use)
binfo.flags |= VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
vkassert(vkBeginCommandBuffer(cmdbuffer->handle, &binfo));
- cmdbuffer->state = CMDBUF_RECORD;
+ cmdbuffer->state = CMDBUF_RECORDING;
}
void cmdbuf_end(struct vkcmdbuffer *cmdbuffer) {
vkassert(vkEndCommandBuffer(cmdbuffer->handle));
- cmdbuffer->state = CMDBUF_ENDREC;
+ cmdbuffer->state = CMDBUF_READY;
}
struct vkcmdbuffer* cmdbuf_begin_single_use(struct vkdev *dev) {
@@ -51,7 +72,7 @@ struct vkcmdbuffer* cmdbuf_begin_single_use(struct vkdev *dev) {
return ret;
}
-void cmdbuf_end_single_use(struct vkcmdbuffer *cmdbuffer, struct vkdev *dev, VkQueue queue) {
+void cmdbuf_end_single_use(vkcmdbuffer_t *cmdbuffer, vkdev_t *dev, VkQueue queue) {
cmdbuf_end(cmdbuffer);
VkSubmitInfo sinfo;
sinfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -69,7 +90,7 @@ void cmdbuf_end_single_use(struct vkcmdbuffer *cmdbuffer, struct vkdev *dev, VkQ
destroy_vkcmdbuffer(cmdbuffer, dev);
}
-struct vkrendpass* create_vkrendpass(struct vkdev *dev, struct vkswapchain *swapchain, vec4 area, vec4 color, float depth, uint32_t stencil) {
+vkrendpass_t* create_vkrendpass(vkdev_t *dev, vkswapchain_t *swapchain, vec4 area, vec4 color, float depth, uint32_t stencil) {
VkAttachmentDescription atdesc[2];
atdesc[0].flags = 0;
atdesc[0].format = swapchain->format_khr.format;
@@ -119,7 +140,7 @@ struct vkrendpass* create_vkrendpass(struct vkdev *dev, struct vkswapchain *swap
dep.dstAccessMask = 0;
dep.dependencyFlags = 0;
- struct vkrendpass *ret = rune_alloc(sizeof(struct vkrendpass));
+ vkrendpass_t *ret = rune_alloc(sizeof(vkrendpass_t));
ret->color[0] = color[0];
ret->color[1] = color[1];
ret->color[2] = color[2];
@@ -146,7 +167,7 @@ struct vkrendpass* create_vkrendpass(struct vkdev *dev, struct vkswapchain *swap
return ret;
}
-void destroy_vkrendpass(struct vkrendpass *rendpass, struct vkdev *dev) {
+void destroy_vkrendpass(vkrendpass_t *rendpass, vkdev_t *dev) {
if (rendpass->handle)
vkDestroyRenderPass(dev->ldev, rendpass->handle, NULL);
rune_free(rendpass);
@@ -174,10 +195,10 @@ void renderpass_begin(struct vkcmdbuffer *buf, struct vkrendpass *rendpass, VkFr
binfo.pClearValues = cvals;
vkCmdBeginRenderPass(buf->handle, &binfo, VK_SUBPASS_CONTENTS_INLINE);
- buf->state = CMDBUF_RPASS;
+ buf->state = CMDBUF_IN_RENDERPASS;
}
void renderpass_end(struct vkcmdbuffer *buf, struct vkrendpass *rendpass) {
vkCmdEndRenderPass(buf->handle);
- buf->state = CMDBUF_RECORD;
+ buf->state = CMDBUF_RECORDING;
}
diff --git a/render/vulkan/renderpass.h b/render/vulkan/renderpass.h
index 2a27821..1524438 100644
--- a/render/vulkan/renderpass.h
+++ b/render/vulkan/renderpass.h
@@ -1,26 +1,49 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKRENDERPASS_H
#define VKRENDERPASS_H
#include "vk_types.h"
enum cmdbuf_state {
+ CMDBUF_INITIAL,
+ CMDBUF_RECORDING,
+ CMDBUF_IN_RENDERPASS,
CMDBUF_READY,
- CMDBUF_RECORD,
- CMDBUF_RPASS,
- CMDBUF_ENDREC,
- CMDBUF_SUBMIT
+ CMDBUF_SUBMITTED,
};
-struct vkcmdbuffer* create_vkcmdbuffer(struct vkdev *dev, int primary);
-void destroy_vkcmdbuffer(struct vkcmdbuffer *cmdbuffer, struct vkdev *dev);
+vkcmdbuffer_t* create_vkcmdbuffer(vkdev_t *dev, int primary);
+void destroy_vkcmdbuffer(vkcmdbuffer_t *cmdbuffer, vkdev_t *dev);
-void cmdbuf_begin(struct vkcmdbuffer *cmdbuffer, int single, int rpass_cont, int sim_use);
-void cmdbuf_end(struct vkcmdbuffer *cmdbuffer);
+void cmdbuf_begin(vkcmdbuffer_t *cmdbuffer, int single, int rpass_cont, int sim_use);
+void cmdbuf_end(vkcmdbuffer_t *cmdbuffer);
+void cmdbuf_submit(vkcmdbuffer_t *cmdbuffer, VkSemaphore *signal, VkSemaphore *wait, VkQueue queue_handle, VkFence fence_handle);
+void cmdbuf_reset(vkcmdbuffer_t *cmdbuffer);
-struct vkrendpass* create_vkrendpass(struct vkdev *dev, struct vkswapchain *swapchain, vec4 area, vec4 color, float depth, uint32_t stencil);
-void destroy_vkrendpass(struct vkrendpass *rendpass, struct vkdev *dev);
+vkrendpass_t* create_vkrendpass(vkdev_t *dev, vkswapchain_t *swapchain, vec4 area, vec4 color, float depth, uint32_t stencil);
+void destroy_vkrendpass(vkrendpass_t *rendpass, vkdev_t *dev);
-void renderpass_begin(struct vkcmdbuffer *buf, struct vkrendpass *rendpass, VkFramebuffer framebuf);
-void renderpass_end(struct vkcmdbuffer *buf, struct vkrendpass *rendpass);
+void renderpass_begin(vkcmdbuffer_t *buf, vkrendpass_t *rendpass, VkFramebuffer framebuf);
+void renderpass_end(vkcmdbuffer_t *buf, vkrendpass_t *rendpass);
#endif
diff --git a/render/vulkan/swapchain.c b/render/vulkan/swapchain.c
index 7d655a3..055d36f 100644
--- a/render/vulkan/swapchain.c
+++ b/render/vulkan/swapchain.c
@@ -1,3 +1,24 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#include "swapchain.h"
#include "image.h"
#include "device.h"
@@ -6,8 +27,8 @@
#include <rune/core/alloc.h>
#include <rune/util/stubbed.h>
-struct vkswapchain* create_swapchain(struct vksurface *surface, struct vkdev *dev) {
- struct vkswapchain *swapchain = rune_alloc(sizeof(struct vkswapchain));
+vkswapchain_t* create_swapchain(vksurface_t *surface, vkdev_t *dev) {
+ vkswapchain_t *swapchain = rune_alloc(sizeof(vkswapchain_t));
VkExtent2D sc_extent = {surface->width, surface->height};
swapchain->max_frames = 2;
get_swapchain_data(dev, &surface->handle);
@@ -38,8 +59,8 @@ struct vkswapchain* create_swapchain(struct vksurface *surface, struct vkdev *de
cinfo.presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
cinfo.clipped = VK_TRUE;
cinfo.oldSwapchain = NULL;
- if (dev->queues[0].index != dev->queues[3].index) {
- uint32_t qfams[] = {dev->queues[0].index, dev->queues[3].index};
+ if (dev->queues[0].qfam != dev->queues[3].qfam) {
+ uint32_t qfams[] = {dev->queues[0].qfam, dev->queues[3].qfam};
cinfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
cinfo.queueFamilyIndexCount = 2;
cinfo.pQueueFamilyIndices = qfams;
@@ -88,7 +109,7 @@ struct vkswapchain* create_swapchain(struct vksurface *surface, struct vkdev *de
return swapchain;
}
-void destroy_swapchain(struct vkswapchain *swapchain, struct vkdev *dev) {
+void destroy_swapchain(vkswapchain_t *swapchain, vkdev_t *dev) {
for (uint32_t i = 0; i < swapchain->img_count; i++)
vkDestroyImageView(dev->ldev, swapchain->views[i], NULL);
destroy_vkimage(swapchain->depth_attachment, dev);
@@ -97,15 +118,26 @@ void destroy_swapchain(struct vkswapchain *swapchain, struct vkdev *dev) {
rune_free(swapchain->views);
}
-void vkswapchain_present(struct vkswapchain *swapchain, struct vkdev *dev) {
+int32_t vkswapchain_get_next_img(vkswapchain_t *swapchain, vkdev_t *dev, uint64_t tmout, VkFence fence, VkSemaphore img_available) {
+ uint32_t ret = 0;
+ VkResult res = vkAcquireNextImageKHR(dev->ldev, swapchain->handle, tmout, img_available, fence, &ret);
+ if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) {
+ log_output(LOG_ERROR, "Error on getting next image index");
+ return -1;
+ }
+
+ return (int32_t)ret;
+}
+
+void vkswapchain_present(vkswapchain_t *swapchain, vkdev_t *dev, VkSemaphore *render_complete, uint32_t *img_index) {
VkPresentInfoKHR pinfo;
pinfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
pinfo.pNext = NULL;
pinfo.waitSemaphoreCount = 1;
- pinfo.pWaitSemaphores = &swapchain->render_complete;
+ pinfo.pWaitSemaphores = render_complete;
pinfo.swapchainCount = 1;
pinfo.pSwapchains = &swapchain->handle;
- pinfo.pImageIndices = &dev->queues[3].index;
+ pinfo.pImageIndices = img_index;
pinfo.pResults = NULL;
VkResult res = vkQueuePresentKHR(dev->queues[3].handle, &pinfo);
diff --git a/render/vulkan/swapchain.h b/render/vulkan/swapchain.h
index 716aadd..7c2e2a5 100644
--- a/render/vulkan/swapchain.h
+++ b/render/vulkan/swapchain.h
@@ -1,11 +1,33 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKSWAPCHAIN_H
#define VKSWAPCHAIN_H
#include "vk_types.h"
-struct vkswapchain* create_swapchain(struct vksurface *surface, struct vkdev *dev);
-void destroy_swapchain(struct vkswapchain *swapchain, struct vkdev *dev);
+vkswapchain_t* create_swapchain(vksurface_t *surface, vkdev_t *dev);
+void destroy_swapchain(vkswapchain_t *swapchain, vkdev_t *dev);
-void vkswapchain_present(struct vkswapchain *swapchain, struct vkdev *dev);
+int32_t vkswapchain_get_next_img(vkswapchain_t *swapchain, vkdev_t *dev, uint64_t tmout, VkFence fence, VkSemaphore img_available);
+void vkswapchain_present(vkswapchain_t *swapchain, vkdev_t *dev, VkSemaphore *render_complete, uint32_t *img_index);
#endif
diff --git a/render/vulkan/vk_types.h b/render/vulkan/vk_types.h
index 6e99bca..c7610c9 100644
--- a/render/vulkan/vk_types.h
+++ b/render/vulkan/vk_types.h
@@ -1,3 +1,24 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VK_TYPES_H
#define VK_TYPES_H
@@ -6,106 +27,104 @@
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
-struct vkqueue {
- uint32_t index;
+typedef struct vkqueue {
uint32_t qfam;
VkQueue handle;
-};
+} vkqueue_t;
-struct vksurface {
+typedef struct vksurface {
VkSurfaceKHR handle;
uint32_t width;
uint32_t height;
-};
+} vksurface_t;
-struct vkcmdbuffer {
+typedef struct vkcmdbuffer {
VkCommandBuffer handle;
int state;
-};
+} vkcmdbuffer_t;
-struct vkfence {
+typedef struct vkfence {
VkFence handle;
int signal;
-};
+} vkfence_t;
-struct vkimage {
+typedef struct vkimage {
VkImage handle;
VkDeviceMemory memory;
VkImageView view;
uint32_t width;
uint32_t height;
-};
+} vkimage_t;
-struct ext_container {
+typedef struct ext_container {
const char** extensions;
uint32_t ext_count;
-};
+} ext_container_t;
-struct vklayer_container {
+typedef struct vklayer_container {
const char** vklayer_names;
uint32_t vklayer_count;
-};
+} vklayer_container_t;
-struct vkswapchain_data {
+typedef struct vkswapchain_data {
VkSurfaceCapabilitiesKHR capabilities;
VkSurfaceFormatKHR *formats;
VkPresentModeKHR *present_modes;
uint32_t format_count;
uint32_t present_count;
-};
+} vkswapchain_data_t;
-struct vkrendpass {
+typedef struct vkrendpass {
VkRenderPass handle;
vec4 area;
vec4 color;
float depth;
uint32_t stencil;
-};
+} vkrendpass_t;
-struct vkframebuffer {
+typedef struct vkframebuffer {
VkFramebuffer handle;
uint32_t at_count;
VkImageView *attachments;
- struct vkrendpass *rendpass;
-};
+ vkrendpass_t *rendpass;
+} vkframebuffer_t;
-struct vkdev {
+typedef struct vkdev {
VkPhysicalDevice pdev;
VkDevice ldev;
- struct vkswapchain_data scdata;
- struct vkqueue queues[4];
+ vkswapchain_data_t scdata;
+ vkqueue_t queues[4];
VkCommandPool cmd_pool;
VkFormat depth_format;
-};
+} vkdev_t;
-struct vkswapchain {
+typedef struct vkswapchain {
VkSwapchainKHR handle;
VkSurfaceFormatKHR format_khr;
VkFormat format;
- VkSemaphore render_complete;
VkImage *images;
VkImageView *views;
- struct vkimage *depth_attachment;
+ vkimage_t *depth_attachment;
uint8_t max_frames;
uint32_t frame;
uint32_t img_count;
-};
+} vkswapchain_t;
-struct vkcontext {
+typedef struct vkcontext {
VkInstance instance;
VkDebugUtilsMessengerEXT db_messenger;
VkSemaphore *queue_semaphores;
VkSemaphore *image_semaphores;
- struct vksurface *surface;
- struct vkswapchain *swapchain;
- struct vkrendpass *rendpass;
- struct vkdev *dev;
- struct vkcmdbuffer** cmdbuffers;
- struct vkframebuffer** framebuffers;
- struct vkfence** fences_in_flight;
- struct vkfence** images_in_flight;
+ vksurface_t *surface;
+ vkswapchain_t *swapchain;
+ vkrendpass_t *rendpass;
+ vkdev_t *dev;
+ vkcmdbuffer_t** cmdbuffers;
+ vkframebuffer_t** framebuffers;
+ vkfence_t** fences_in_flight;
+ vkfence_t** images_in_flight;
uint32_t num_fences_in_flight;
uint32_t img_index;
-};
+} vkcontext_t;
#endif
diff --git a/render/vulkan/vkassert.h b/render/vulkan/vkassert.h
index b708732..ca0a89d 100644
--- a/render/vulkan/vkassert.h
+++ b/render/vulkan/vkassert.h
@@ -1,3 +1,24 @@
+/*
+ * Rune Game Engine
+ * Copyright 2024 Danny Holman <dholman@gymli.org>
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
#ifndef VKASSERT_H
#define VKASSERT_H