50 lines
1.7 KiB
C++
50 lines
1.7 KiB
C++
#include "aster/constants.h"
|
|
#include "aster/glfw_context.h"
|
|
#include "aster/physical_device.h"
|
|
#include "aster/window.h"
|
|
|
|
constexpr QueueSupportFlags required_queue_support = QueueSupportFlags{} | QueueSupportFlagBits::eGraphics | QueueSupportFlagBits::eCompute | QueueSupportFlagBits::ePresent | QueueSupportFlagBits::eCompute;
|
|
|
|
[[nodiscard]] bool is_suitable_device(const PhysicalDevice *_physical_device) {
|
|
const bool all_required_queues = std::ranges::any_of(_physical_device->queue_families, [](const auto &_qfp) {
|
|
return (_qfp.support & required_queue_support) == required_queue_support;
|
|
});
|
|
|
|
const bool device_type_check = _physical_device->properties.deviceType != vk::PhysicalDeviceType::eCpu;
|
|
|
|
const bool supported_present_mode = !_physical_device->present_modes.empty();
|
|
|
|
const bool supported_format = !_physical_device->surface_formats.empty();
|
|
|
|
return supported_format && supported_present_mode && device_type_check && all_required_queues;
|
|
}
|
|
|
|
PhysicalDevice find_suitable_device(const PhysicalDevices &_physical_devices) {
|
|
for (auto &_physical_device : _physical_devices) {
|
|
if (is_suitable_device(&_physical_device)) {
|
|
return _physical_device;
|
|
}
|
|
}
|
|
throw std::runtime_error("No suitable device found.");
|
|
}
|
|
|
|
int main(int, char **) {
|
|
const auto *glfw = new GlfwContext();
|
|
auto *context = new Context("Aster", VERSION);
|
|
auto *window = new Window("Aster1", context, { 640, 480 });
|
|
|
|
PhysicalDevices physical_devices = { window, context };
|
|
PhysicalDevice device_to_use = find_suitable_device(physical_devices);
|
|
|
|
INFO("Using {} as the primary device.", device_to_use.properties.deviceName.data());
|
|
|
|
while (window->poll()) {
|
|
}
|
|
|
|
delete window;
|
|
delete context;
|
|
delete glfw;
|
|
|
|
return 0;
|
|
}
|