Update DeviceManager

This commit is contained in:
2021-07-21 01:59:11 +02:00
parent cfbf31cb77
commit 58f2efb360
6 changed files with 100 additions and 43 deletions

View File

@@ -1,44 +1,42 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <stdexcept>
#include <memory>
#include <vector>
#include "Base/ICloseable.hpp"
#include "Device.hpp"
#include <vulkan/vulkan.hpp>
namespace openVulkanoCpp
namespace openVulkanoCpp::Vulkan
{
namespace Vulkan
class Device;
class DeviceManager final
{
std::vector<std::shared_ptr<Device>> devices;
class DeviceManager : virtual public ICloseable
public:
DeviceManager() = default;
DeviceManager(const vk::Instance& instance)
{
std::vector<Device> devices;
public:
void Init(const vk::Instance& instance)
{
devices = std::vector<Device>();
for (auto& physicalDevice : instance.enumeratePhysicalDevices())
{
devices.emplace_back(physicalDevice);
}
}
Init(instance);
}
Device* GetCompatibleDevice(const std::vector<std::string>& deviceExtensions)
{
for (auto& device : devices)
{
if (device.IsExtensionAvailable(deviceExtensions)) return &device;
}
throw std::runtime_error("No device with required extensions found!");
}
~DeviceManager() = default;
void Close() override
{
for (auto& device : devices)
{
device.Close();
}
devices.clear();
}
};
}
void Init(const vk::Instance& instance);
std::shared_ptr<Device> GetCompatibleDevice(const vk::ArrayProxy<const std::string>& deviceExtensions);
std::string ProduceMissingDeviceCompatibilityReport(const vk::ArrayProxy<const std::string>& deviceExtensions);
void Close()
{
devices.clear();
}
};
}