Vulkan: Add physical device retrieval
Former-commit-id: 5c0e8256123fcfe5d3563b224bdcc11efa645fd3 [formerly cecb3404e98b1be4a5176fe27c1dec533e16701a] Former-commit-id: a2fa7f6d96e3fe6f43af97b5c882d939a947fb9a
This commit is contained in:
parent
a6f223a396
commit
7d73f0dcad
|
|
@ -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 <vulkan/vulkan.h>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
struct PhysicalDevice
|
||||
{
|
||||
VkPhysicalDevice device;
|
||||
VkPhysicalDeviceFeatures features;
|
||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
std::vector<VkQueueFamilyProperties> queues;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // NAZARA_VULKAN_VKPHYSICALDEVICE_HPP
|
||||
|
|
@ -13,7 +13,10 @@
|
|||
#include <Nazara/Vulkan/Config.hpp>
|
||||
#include <Nazara/Vulkan/VkDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkInstance.hpp>
|
||||
#include <Nazara/Vulkan/VkPhysicalDevice.hpp>
|
||||
#include <Nazara/Vulkan/VkSurface.hpp>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -27,6 +30,8 @@ namespace Nz
|
|||
|
||||
static Vk::Instance& GetInstance();
|
||||
|
||||
static const std::vector<Vk::PhysicalDevice>& GetPhysicalDevices();
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
|
@ -39,6 +44,7 @@ namespace Nz
|
|||
|
||||
private:
|
||||
static std::list<Vk::Device> s_devices;
|
||||
static std::vector<Vk::PhysicalDevice> s_physDevices;
|
||||
static Vk::Instance s_instance;
|
||||
static ParameterList s_initializationParameters;
|
||||
static unsigned int s_moduleReferenceCounter;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ namespace Nz
|
|||
return s_instance;
|
||||
}
|
||||
|
||||
const std::vector<Vk::PhysicalDevice>& Vulkan::GetPhysicalDevices()
|
||||
{
|
||||
return s_physDevices;
|
||||
}
|
||||
|
||||
bool Vulkan::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter > 0)
|
||||
|
|
@ -147,6 +152,41 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
std::vector<VkPhysicalDevice> 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<Vk::Device> Vulkan::s_devices;
|
||||
std::vector<Vk::PhysicalDevice> Vulkan::s_physDevices;
|
||||
Vk::Instance Vulkan::s_instance;
|
||||
ParameterList Vulkan::s_initializationParameters;
|
||||
unsigned int Vulkan::s_moduleReferenceCounter = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue