65 lines
2.1 KiB
C++
65 lines
2.1 KiB
C++
// =============================================
|
|
// Aster: helpers.cpp
|
|
// Copyright (c) 2020-2025 Anish Bhobe
|
|
// =============================================
|
|
|
|
#include "helpers.h"
|
|
|
|
#include "aster/core/device.h"
|
|
#include "aster/core/physical_device.h"
|
|
|
|
#include <EASTL/array.h>
|
|
|
|
constexpr QueueSupportFlags REQUIRED_QUEUE_SUPPORT = QueueSupportFlags{} | QueueSupportFlagBits::eGraphics |
|
|
QueueSupportFlagBits::eCompute | QueueSupportFlagBits::ePresent |
|
|
QueueSupportFlagBits::eTransfer;
|
|
|
|
bool
|
|
IsSuitableDevice(const PhysicalDevice *physicalDevice)
|
|
{
|
|
const bool hasAllRequiredQueues =
|
|
std::ranges::any_of(physicalDevice->m_QueueFamilies, [](const auto &queueFamilyProp) {
|
|
return (queueFamilyProp.m_Support & REQUIRED_QUEUE_SUPPORT) == REQUIRED_QUEUE_SUPPORT;
|
|
});
|
|
|
|
const bool isNotCpu = physicalDevice->m_DeviceProperties.deviceType != vk::PhysicalDeviceType::eCpu;
|
|
|
|
const bool hasPresentMode = !physicalDevice->m_PresentModes.empty();
|
|
|
|
const bool hasSurfaceFormat = !physicalDevice->m_SurfaceFormats.empty();
|
|
|
|
return hasSurfaceFormat && hasPresentMode && isNotCpu && hasAllRequiredQueues;
|
|
}
|
|
|
|
PhysicalDevice
|
|
FindSuitableDevice(const PhysicalDevices &physicalDevices)
|
|
{
|
|
for (auto &physicalDevice : physicalDevices)
|
|
{
|
|
if (IsSuitableDevice(&physicalDevice))
|
|
{
|
|
return physicalDevice;
|
|
}
|
|
}
|
|
|
|
ERROR("No suitable GPU available on the system.")
|
|
THEN_ABORT(vk::Result::eErrorUnknown);
|
|
}
|
|
|
|
QueueAllocation
|
|
FindAppropriateQueueAllocation(const PhysicalDevice *physicalDevice)
|
|
{
|
|
for (auto &queueFamilyInfo : physicalDevice->m_QueueFamilies)
|
|
{
|
|
if ((queueFamilyInfo.m_Support & REQUIRED_QUEUE_SUPPORT) == REQUIRED_QUEUE_SUPPORT)
|
|
{
|
|
return {
|
|
.m_Family = queueFamilyInfo.m_Index,
|
|
.m_Count = queueFamilyInfo.m_Count,
|
|
};
|
|
}
|
|
}
|
|
ERROR("No suitable queue family on the GPU.")
|
|
THEN_ABORT(vk::Result::eErrorUnknown);
|
|
}
|