instance.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#pragma once


#include <planet/vk/debug_messenger.hpp>
#include <planet/vk/surface.hpp>
#include <planet/vk/physical_device.hpp>

#include <span>
#include <vector>


namespace planet::vk {


    struct extensions;

Return a filled in structure that can be used to create the instance

19
    VkApplicationInfo application_info();

The Vulkan instance

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    class instance final {
        struct instance_handle {
            VkInstance h;
            ~instance_handle();
        } handle;

        std::vector<physical_device> pdevices;
        physical_device const *gpu_in_use = nullptr;

      public:
        static VkInstanceCreateInfo
                info(extensions &, VkApplicationInfo const &);
        instance(
                extensions const &,
                VkInstanceCreateInfo &,
                std::function<VkSurfaceKHR(VkInstance)>);

        instance(instance const &) = delete;
        instance(instance &&) = delete;
        instance &operator=(instance const &) = delete;
        instance &operator=(instance &&i) = delete;

        VkInstance get() const noexcept { return handle.h; }

        vk::surface surface;

Find a matching memory index

51
52
        std::uint32_t find_memory_type(
                VkMemoryRequirements, VkMemoryPropertyFlags) const;

The debug messenger is automatically used if there are validation layers present

57
58
59
60
61
        vk::debug_messenger debug_messenger;

        std::span<physical_device const> physical_devices() const {
            return pdevices;
        }

The GPU that is currently chosen for use

63
64
65
66
67
68
69
70
71
72
        physical_device const &gpu() const noexcept { return *gpu_in_use; }
        physical_device const &use_gpu(physical_device const &d) noexcept {
            surface.refresh_characteristics(d);
            gpu_in_use = &d;
            return *gpu_in_use;
        }
    };


}