// ============================================= // Aster: helpers.cpp // Copyright (c) 2020-2025 Anish Bhobe // ============================================= #include "helpers.h" #include "aster/core/device.h" #include "aster/core/physical_device.h" #include constexpr QueueSupportFlags REQUIRED_QUEUE_SUPPORT = QueueSupportFlags{} | QueueSupportFlagBits::eGraphics | QueueSupportFlagBits::eCompute | QueueSupportFlagBits::ePresent | QueueSupportFlagBits::eTransfer; bool IsSuitableDevice(PhysicalDevice const *physicalDevice) { bool const hasAllRequiredQueues = std::ranges::any_of(physicalDevice->m_QueueFamilies, [](auto const &queueFamilyProp) { return (queueFamilyProp.m_Support & REQUIRED_QUEUE_SUPPORT) == REQUIRED_QUEUE_SUPPORT; }); bool const isNotCpu = physicalDevice->m_DeviceProperties.deviceType != vk::PhysicalDeviceType::eCpu; bool const hasPresentMode = !physicalDevice->m_PresentModes.empty(); bool const hasSurfaceFormat = !physicalDevice->m_SurfaceFormats.empty(); return hasSurfaceFormat && hasPresentMode && isNotCpu && hasAllRequiredQueues; } PhysicalDevice FindSuitableDevice(PhysicalDevices const &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(PhysicalDevice const *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); }