Physical Device creation complete.

This commit is contained in:
Anish Bhobe 2024-06-16 11:47:29 +02:00
parent 20cf0876eb
commit 2f4db7ffaf
3 changed files with 36 additions and 5 deletions

View File

@ -15,7 +15,7 @@ enum class QueueSupportFlagBits {
ePresent = 0b1000,
};
using QueueSupportFlags = vk::Flags<QueueSupportFlagBits>{};
using QueueSupportFlags = vk::Flags<QueueSupportFlagBits>;
struct QueueFamilyInfo {
u32 index;

View File

@ -19,7 +19,7 @@ struct Window final {
~Window();
bool should_close() const noexcept {
[[nodiscard]] bool should_close() const noexcept {
return glfwWindowShouldClose(window);
}

View File

@ -1,11 +1,42 @@
#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 **) {
GlfwContext *glfw = new GlfwContext();
Context *context = new Context("Aster", VERSION);
Window *window = new Window("Aster1", context, { 640, 480 });
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()) {
}