diff --git a/aster/CMakeLists.txt b/aster/CMakeLists.txt index db069e5..10b4f66 100644 --- a/aster/CMakeLists.txt +++ b/aster/CMakeLists.txt @@ -31,6 +31,8 @@ set(SOURCE_FILES add_library(aster_core STATIC ${SOURCE_FILES} ${HEADER_FILES}) set_property(TARGET aster_core PROPERTY CXX_STANDARD 20) +target_precompile_headers(aster_core PUBLIC global.h) + target_include_directories(aster_core PUBLIC ${CMAKE_SOURCE_DIR}) target_link_libraries(aster_core PUBLIC glm::glm-header-only) diff --git a/aster/device.cpp b/aster/device.cpp index 0b69429..242d1f7 100644 --- a/aster/device.cpp +++ b/aster/device.cpp @@ -5,14 +5,19 @@ #include "device.h" +#include "context.h" +#include "physical_device.h" + #include +#include constexpr eastl::array DEVICE_EXTENSIONS = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; Device::Device(const Context *context, PhysicalDevice *physicalDevice, const vk::PhysicalDeviceFeatures *enabledFeatures, - const eastl::vector &queueAllocations, NameString name) + const eastl::vector &queueAllocations, NameString &&name) : m_Name(std::move(name)) + , m_PhysicalDevice(physicalDevice->m_PhysicalDevice) { // Shouldn't have more than 4 deviceQueueFamilies in use anyway. Else we can heap eastl::fixed_vector deviceQueueCreateInfos; @@ -43,7 +48,7 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice, .pEnabledFeatures = enabledFeatures, }; - vk::Result result = physicalDevice->m_PhysicalDevice.createDevice(&deviceCreateInfo, nullptr, &m_Device); + vk::Result result = m_PhysicalDevice.createDevice(&deviceCreateInfo, nullptr, &m_Device); ERROR_IF(failed(result), "Could not initialize Vulkan Device. Cause: {}", result) THEN_ABORT(result) ELSE_DEBUG("{} ({}) Initialized.", m_Name, physicalDevice->m_DeviceProperties.deviceName.data()); @@ -54,8 +59,7 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice, }; const VmaAllocatorCreateInfo allocatorCreateInfo = { - .flags = 0, - .physicalDevice = physicalDevice->m_PhysicalDevice, + .physicalDevice = m_PhysicalDevice, .device = m_Device, .pVulkanFunctions = &vmaVulkanFunctions, .instance = context->m_Instance, @@ -81,4 +85,5 @@ Device::~Device() } m_Device.destroy(nullptr); DEBUG("Device '{}' Destroyed", m_Name); + m_PhysicalDevice = nullptr; } \ No newline at end of file diff --git a/aster/device.h b/aster/device.h index 943d643..dbc2c09 100644 --- a/aster/device.h +++ b/aster/device.h @@ -6,7 +6,11 @@ #pragma once #include "global.h" -#include "physical_device.h" + +#include + +struct Context; +struct PhysicalDevice; struct QueueAllocation { @@ -16,14 +20,12 @@ struct QueueAllocation struct Device final { - using NameString = eastl::fixed_string; - NameString m_Name; + vk::PhysicalDevice m_PhysicalDevice = nullptr; vk::Device m_Device = nullptr; VmaAllocator m_Allocator = nullptr; Device(const Context *context, PhysicalDevice *physicalDevice, const vk::PhysicalDeviceFeatures *enabledFeatures, - const eastl::vector &queueAllocations, NameString name); - + const eastl::vector &queueAllocations, NameString &&name); ~Device(); }; diff --git a/aster/global.h b/aster/global.h index 9d3f4d7..181bb24 100644 --- a/aster/global.h +++ b/aster/global.h @@ -60,6 +60,8 @@ toCstr(const T &val) return buffer.c_str(); } +using NameString = eastl::fixed_string; + // TODO: Check why inline namespaces aren't working in MSVC 19.27.29110 using namespace std::literals::string_literals; using namespace std::literals::string_view_literals; diff --git a/aster/physical_device.cpp b/aster/physical_device.cpp index 7f2f449..a570c4c 100644 --- a/aster/physical_device.cpp +++ b/aster/physical_device.cpp @@ -5,6 +5,9 @@ #include "physical_device.h" +#include "context.h" +#include "window.h" + [[nodiscard]] eastl::vector getSurfaceFormats(const vk::SurfaceKHR surface, const vk::PhysicalDevice physicalDevice) { diff --git a/aster/physical_device.h b/aster/physical_device.h index 496afe1..5f824f8 100644 --- a/aster/physical_device.h +++ b/aster/physical_device.h @@ -6,9 +6,11 @@ #pragma once #include "global.h" -#include "window.h" #include +struct Window; +struct Context; + enum class QueueSupportFlagBits { eGraphics = 0b0001, diff --git a/aster/window.h b/aster/window.h index ed3d0bb..36a0594 100644 --- a/aster/window.h +++ b/aster/window.h @@ -5,10 +5,11 @@ #pragma once -#include "context.h" #include "global.h" #include +struct Context; + struct Window final { // fields