From 175897e7d90665f184d667322525cddeafc6d718 Mon Sep 17 00:00:00 2001 From: Riley King-Saunders Date: Mon, 7 Jul 2025 22:46:21 +1000 Subject: [PATCH] Added cast operator for VkInstance Now maintains a list of enabled extensions --- include/vulkan/basalt_context.h | 6 +++++- src/vulkan/basalt_context.cpp | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/vulkan/basalt_context.h b/include/vulkan/basalt_context.h index e07a142..9eb0861 100644 --- a/include/vulkan/basalt_context.h +++ b/include/vulkan/basalt_context.h @@ -1,6 +1,5 @@ #pragma once #include "vulkan/basalt_window.h" -#include "containers/basalt_darray.h" namespace basalt { @@ -15,9 +14,14 @@ namespace basalt Context(const char* app_name, const basalt::darray& required_layers, const basalt::darray& required_extensions, uint32_t app_version=VK_MAKE_API_VERSION(1, 1, 0, 0), uint32_t vulkan_version = VK_MAKE_API_VERSION(0, 1, 2, 0)); ~Context(); + operator VkInstance(void) const noexcept; + VkInstance inst = VK_NULL_HANDLE; VkAllocationCallbacks* vk_alloc = VK_NULL_HANDLE; VkDebugUtilsMessengerEXT dbg_msger = VK_NULL_HANDLE; + + const char** pp_enabled_layers = nullptr; + u32 num_enabled_layers = 0; bool should_free = true; bool using_validation_layers = false; diff --git a/src/vulkan/basalt_context.cpp b/src/vulkan/basalt_context.cpp index 543524d..97162b5 100644 --- a/src/vulkan/basalt_context.cpp +++ b/src/vulkan/basalt_context.cpp @@ -78,6 +78,10 @@ basalt::Context::Context(const char* app_name, ci.enabledLayerCount = required_layers.m_nelements; ci.ppEnabledLayerNames = required_layers.m_pdata; + this->num_enabled_layers = required_layers.m_nelements; + this->pp_enabled_layers = basalt::mem::allocT(required_layers.m_nelements, MEMORY_TAG_CLASS_ARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY); + memcpy(this->pp_enabled_layers, required_layers.m_pdata, sizeof(const char*) * required_layers.m_nelements); + if (this->using_validation_layers) { dbg_ci.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT; @@ -113,8 +117,13 @@ basalt::Context::~Context() } if (this->inst != VK_NULL_HANDLE && this->should_free) vkDestroyInstance(this->inst, this->vk_alloc); + if (this->pp_enabled_layers) + basalt::mem::dealloc(this->pp_enabled_layers, this->num_enabled_layers * sizeof(const char*), MEMORY_TAG_CLASS_ARRAY | MEMORY_TAG_ZONE_ENGINE | MEMORY_TAG_ALIGN_ANY); } +basalt::Context::operator VkInstance(void) const noexcept +{ return this->inst; } + static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,