Program Listing for File device_info.hpp

Return to documentation for file (inexor/vulkan-renderer/tools/device_info.hpp)

#pragma once

#include <volk.h>

#include <cstdint>
#include <span>
#include <string>
#include <vector>

namespace inexor::vulkan_renderer::wrapper {
// Forward declaration
class Instance;
} // namespace inexor::vulkan_renderer::wrapper

namespace inexor::vulkan_renderer::tools {

// Using declaration
using wrapper::Instance;

struct DeviceInfo {
    std::string name;
    VkPhysicalDevice physical_device{nullptr};
    VkPhysicalDeviceType type{VK_PHYSICAL_DEVICE_TYPE_OTHER};
    VkDeviceSize total_device_local{0};
    VkPhysicalDeviceFeatures features{};
    std::vector<VkExtensionProperties> extensions;
    bool presentation_supported{false};
    bool swapchain_supported{false};
};

[[nodiscard]] DeviceInfo build_device_info(VkPhysicalDevice physical_device, VkSurfaceKHR surface);

[[nodiscard]] bool compare_physical_devices(VkPhysicalDeviceFeatures &required_features,
                                            std::span<const char *> required_extensions, const DeviceInfo &lhs,
                                            const DeviceInfo &rhs);

[[nodiscard]] std::uint32_t device_type_rating(const DeviceInfo &info);

[[nodiscard]] std::vector<VkBool32> get_device_features_as_vector(const VkPhysicalDeviceFeatures &features);

[[nodiscard]] std::string get_physical_device_name(VkPhysicalDevice physical_device);

[[nodiscard]] bool is_gpu_suitable(const DeviceInfo &info, const VkPhysicalDeviceFeatures &required_features,
                                   const std::span<const char *> required_extensions, bool print_info = false);

[[nodiscard]] bool is_extension_supported(const std::vector<VkExtensionProperties> &extensions,
                                          const std::string &extension_name);

[[nodiscard]] VkPhysicalDevice pick_best_physical_device(std::vector<DeviceInfo> &&physical_device_infos,
                                                         const VkPhysicalDeviceFeatures &required_features,
                                                         const std::span<const char *> required_extensions);

[[nodiscard]] VkPhysicalDevice pick_best_physical_device(const Instance &inst, VkSurfaceKHR surface,
                                                         const VkPhysicalDeviceFeatures &required_features,
                                                         const std::span<const char *> required_extensions);

} // namespace inexor::vulkan_renderer::tools