Refactored Device and Cleaned up includes.

This commit is contained in:
Anish Bhobe 2024-06-26 19:49:46 +02:00
parent f603bd5752
commit c16456c610
7 changed files with 28 additions and 11 deletions

View File

@ -31,6 +31,8 @@ set(SOURCE_FILES
add_library(aster_core STATIC ${SOURCE_FILES} ${HEADER_FILES}) add_library(aster_core STATIC ${SOURCE_FILES} ${HEADER_FILES})
set_property(TARGET aster_core PROPERTY CXX_STANDARD 20) 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_include_directories(aster_core PUBLIC ${CMAKE_SOURCE_DIR})
target_link_libraries(aster_core PUBLIC glm::glm-header-only) target_link_libraries(aster_core PUBLIC glm::glm-header-only)

View File

@ -5,14 +5,19 @@
#include "device.h" #include "device.h"
#include "context.h"
#include "physical_device.h"
#include <EASTL/array.h> #include <EASTL/array.h>
#include <EASTL/fixed_vector.h>
constexpr eastl::array DEVICE_EXTENSIONS = {VK_KHR_SWAPCHAIN_EXTENSION_NAME}; constexpr eastl::array DEVICE_EXTENSIONS = {VK_KHR_SWAPCHAIN_EXTENSION_NAME};
Device::Device(const Context *context, PhysicalDevice *physicalDevice, Device::Device(const Context *context, PhysicalDevice *physicalDevice,
const vk::PhysicalDeviceFeatures *enabledFeatures, const vk::PhysicalDeviceFeatures *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString name) const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name)
: m_Name(std::move(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 // Shouldn't have more than 4 deviceQueueFamilies in use anyway. Else we can heap
eastl::fixed_vector<vk::DeviceQueueCreateInfo, 4> deviceQueueCreateInfos; eastl::fixed_vector<vk::DeviceQueueCreateInfo, 4> deviceQueueCreateInfos;
@ -43,7 +48,7 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice,
.pEnabledFeatures = enabledFeatures, .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) ERROR_IF(failed(result), "Could not initialize Vulkan Device. Cause: {}", result)
THEN_ABORT(result) THEN_ABORT(result)
ELSE_DEBUG("{} ({}) Initialized.", m_Name, physicalDevice->m_DeviceProperties.deviceName.data()); ELSE_DEBUG("{} ({}) Initialized.", m_Name, physicalDevice->m_DeviceProperties.deviceName.data());
@ -54,8 +59,7 @@ Device::Device(const Context *context, PhysicalDevice *physicalDevice,
}; };
const VmaAllocatorCreateInfo allocatorCreateInfo = { const VmaAllocatorCreateInfo allocatorCreateInfo = {
.flags = 0, .physicalDevice = m_PhysicalDevice,
.physicalDevice = physicalDevice->m_PhysicalDevice,
.device = m_Device, .device = m_Device,
.pVulkanFunctions = &vmaVulkanFunctions, .pVulkanFunctions = &vmaVulkanFunctions,
.instance = context->m_Instance, .instance = context->m_Instance,
@ -81,4 +85,5 @@ Device::~Device()
} }
m_Device.destroy(nullptr); m_Device.destroy(nullptr);
DEBUG("Device '{}' Destroyed", m_Name); DEBUG("Device '{}' Destroyed", m_Name);
m_PhysicalDevice = nullptr;
} }

View File

@ -6,7 +6,11 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "physical_device.h"
#include <EASTL/vector.h>
struct Context;
struct PhysicalDevice;
struct QueueAllocation struct QueueAllocation
{ {
@ -16,14 +20,12 @@ struct QueueAllocation
struct Device final struct Device final
{ {
using NameString = eastl::fixed_string<char, 32, false>;
NameString m_Name; NameString m_Name;
vk::PhysicalDevice m_PhysicalDevice = nullptr;
vk::Device m_Device = nullptr; vk::Device m_Device = nullptr;
VmaAllocator m_Allocator = nullptr; VmaAllocator m_Allocator = nullptr;
Device(const Context *context, PhysicalDevice *physicalDevice, const vk::PhysicalDeviceFeatures *enabledFeatures, Device(const Context *context, PhysicalDevice *physicalDevice, const vk::PhysicalDeviceFeatures *enabledFeatures,
const eastl::vector<QueueAllocation> &queueAllocations, NameString name); const eastl::vector<QueueAllocation> &queueAllocations, NameString &&name);
~Device(); ~Device();
}; };

View File

@ -60,6 +60,8 @@ toCstr(const T &val)
return buffer.c_str(); return buffer.c_str();
} }
using NameString = eastl::fixed_string<char, 32, false>;
// TODO: Check why inline namespaces aren't working in MSVC 19.27.29110 // TODO: Check why inline namespaces aren't working in MSVC 19.27.29110
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
using namespace std::literals::string_view_literals; using namespace std::literals::string_view_literals;

View File

@ -5,6 +5,9 @@
#include "physical_device.h" #include "physical_device.h"
#include "context.h"
#include "window.h"
[[nodiscard]] eastl::vector<vk::SurfaceFormatKHR> [[nodiscard]] eastl::vector<vk::SurfaceFormatKHR>
getSurfaceFormats(const vk::SurfaceKHR surface, const vk::PhysicalDevice physicalDevice) getSurfaceFormats(const vk::SurfaceKHR surface, const vk::PhysicalDevice physicalDevice)
{ {

View File

@ -6,9 +6,11 @@
#pragma once #pragma once
#include "global.h" #include "global.h"
#include "window.h"
#include <EASTL/fixed_vector.h> #include <EASTL/fixed_vector.h>
struct Window;
struct Context;
enum class QueueSupportFlagBits enum class QueueSupportFlagBits
{ {
eGraphics = 0b0001, eGraphics = 0b0001,

View File

@ -5,10 +5,11 @@
#pragma once #pragma once
#include "context.h"
#include "global.h" #include "global.h"
#include <EASTL/fixed_string.h> #include <EASTL/fixed_string.h>
struct Context;
struct Window final struct Window final
{ {
// fields // fields