From 7d73f0dcadf5637c6041b602096fef8155a146ba Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 19 Jun 2016 15:31:53 +0200 Subject: [PATCH] Vulkan: Add physical device retrieval Former-commit-id: 5c0e8256123fcfe5d3563b224bdcc11efa645fd3 [formerly cecb3404e98b1be4a5176fe27c1dec533e16701a] Former-commit-id: a2fa7f6d96e3fe6f43af97b5c882d939a947fb9a --- include/Nazara/Vulkan/VkPhysicalDevice.hpp | 28 +++++++++++++++ include/Nazara/Vulkan/Vulkan.hpp | 6 ++++ src/Nazara/Vulkan/Vulkan.cpp | 41 ++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 include/Nazara/Vulkan/VkPhysicalDevice.hpp diff --git a/include/Nazara/Vulkan/VkPhysicalDevice.hpp b/include/Nazara/Vulkan/VkPhysicalDevice.hpp new file mode 100644 index 000000000..e62a9e684 --- /dev/null +++ b/include/Nazara/Vulkan/VkPhysicalDevice.hpp @@ -0,0 +1,28 @@ +// Copyright (C) 2016 Jérôme Leclercq +// This file is part of the "Nazara Engine - Vulkan" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_VULKAN_VKPHYSICALDEVICE_HPP +#define NAZARA_VULKAN_VKPHYSICALDEVICE_HPP + +#include +#include + +namespace Nz +{ + namespace Vk + { + struct PhysicalDevice + { + VkPhysicalDevice device; + VkPhysicalDeviceFeatures features; + VkPhysicalDeviceMemoryProperties memoryProperties; + VkPhysicalDeviceProperties properties; + std::vector queues; + }; + } +} + +#endif // NAZARA_VULKAN_VKPHYSICALDEVICE_HPP diff --git a/include/Nazara/Vulkan/Vulkan.hpp b/include/Nazara/Vulkan/Vulkan.hpp index d5667ce95..289a1b225 100644 --- a/include/Nazara/Vulkan/Vulkan.hpp +++ b/include/Nazara/Vulkan/Vulkan.hpp @@ -13,7 +13,10 @@ #include #include #include +#include #include +#include +#include namespace Nz { @@ -27,6 +30,8 @@ namespace Nz static Vk::Instance& GetInstance(); + static const std::vector& GetPhysicalDevices(); + static bool Initialize(); static bool IsInitialized(); @@ -39,6 +44,7 @@ namespace Nz private: static std::list s_devices; + static std::vector s_physDevices; static Vk::Instance s_instance; static ParameterList s_initializationParameters; static unsigned int s_moduleReferenceCounter; diff --git a/src/Nazara/Vulkan/Vulkan.cpp b/src/Nazara/Vulkan/Vulkan.cpp index f97cc635f..d73e2e21f 100644 --- a/src/Nazara/Vulkan/Vulkan.cpp +++ b/src/Nazara/Vulkan/Vulkan.cpp @@ -19,6 +19,11 @@ namespace Nz return s_instance; } + const std::vector& Vulkan::GetPhysicalDevices() + { + return s_physDevices; + } + bool Vulkan::Initialize() { if (s_moduleReferenceCounter > 0) @@ -147,6 +152,41 @@ namespace Nz return false; } + std::vector physDevices; + if (!s_instance.EnumeratePhysicalDevices(&physDevices)) + { + NazaraError("Failed to enumerate physical devices"); + return false; + } + + s_physDevices.reserve(physDevices.size()); + + for (std::size_t i = 0; i < physDevices.size(); ++i) + { + VkPhysicalDevice physDevice = physDevices[i]; + + Vk::PhysicalDevice deviceInfo; + if (!s_instance.GetPhysicalDeviceQueueFamilyProperties(physDevice, &deviceInfo.queues)) + { + NazaraWarning("Failed to query physical device queue family properties"); + continue; + } + + deviceInfo.device = physDevice; + + s_instance.GetPhysicalDeviceFeatures(physDevice, &deviceInfo.features); + s_instance.GetPhysicalDeviceMemoryProperties(physDevice, &deviceInfo.memoryProperties); + s_instance.GetPhysicalDeviceProperties(physDevice, &deviceInfo.properties); + + s_physDevices.emplace_back(std::move(deviceInfo)); + } + + if (s_physDevices.empty()) + { + NazaraError("No valid physical device found"); + return false; + } + onExit.Reset(); NazaraNotice("Initialized: Vulkan module"); @@ -332,6 +372,7 @@ namespace Nz } std::list Vulkan::s_devices; + std::vector Vulkan::s_physDevices; Vk::Instance Vulkan::s_instance; ParameterList Vulkan::s_initializationParameters; unsigned int Vulkan::s_moduleReferenceCounter = 0;