-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathinstance.hpp
217 lines (176 loc) · 4.92 KB
/
instance.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/**
* @file liblava/base/instance.hpp
* @brief Vulkan instance
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/base/physical_device.hpp"
namespace lava {
/**
* @brief Vulkan instance information
*/
struct instance_info {
/// Reference to a instance
using ref = instance_info const&;
/// Name of application
name app_name = _lava_;
/// Name of engine
name engine_name = _liblava_;
/// Version of application
sem_version app_version;
/// Version of engine
sem_version engine_version;
/// Required Vulkan API version
api_version req_api_version = api_version::v1_0;
};
/**
* @brief Vulkan instance
*/
struct instance : no_copy_no_move {
/**
* @brief Instance create parameters
*/
struct create_param {
/// Reference to instance create parameters
using ref = create_param const&;
/// List of layers to enable
names layers{};
/// List of extensions to enable
names extensions{};
};
/**
* @brief Debug configuration
*/
struct debug_config {
/// Reference to debug configuration
using ref = debug_config const&;
/// Validation
bool validation = false;
/// Renderdoc
bool render_doc = false;
/// Verbose logging
bool verbose = false;
/// Debug utils
bool utils = false;
};
/**
* @brief Instance singleton
* @return instance& Instance
*/
static instance& singleton() {
static instance instance;
return instance;
}
/**
* @brief Create a new instance
* @param param Create parameters
* @param debug Debug configuration
* @param info Instance information
* @return Create was successful or failed
*/
bool create(create_param& param,
debug_config::ref debug,
instance_info::ref info);
/**
* @brief Destroy the instance
*/
void destroy();
/**
* @brief Get the physical devices
* @return physical_device::s_list const& List of physical devices
*/
physical_device::s_list const& get_physical_devices() const {
return m_physical_devices;
}
/**
* @brief Get the first physical device
* @return physical_device::ref Physcial device
*/
physical_device::ref get_first_physical_device() const {
return *m_physical_devices.front().get();
}
/**
* @brief Get the Vulkan instance
* @return VkInstance Vulkan instance
*/
VkInstance get() const {
return m_vk_instance;
}
/**
* @brief Get the debug configuration
* @return debug_config::ref Debug configuration
*/
debug_config::ref get_debug_config() const {
return m_debug;
}
/**
* @brief Get the instance information
* @return instance_info::ref Instance information
*/
instance_info::ref get_info() const {
return m_info;
}
private:
/**
* @brief Construct a new instance
*/
explicit instance() = default;
/**
* @brief Destroy the instance
*/
~instance();
/**
* @brief Check the debug configuration and create parameters
* @param param Create parameters
* @return Check was successful or failed
*/
bool check_debug(create_param& param) const;
/**
* @brief Enumerate all available physical devices
* @return Enumerate was successful or failed
*/
bool enumerate_physical_devices();
/**
* @brief Create a debug messenger
* @return Create was successful or failed
*/
bool create_debug_messenger();
/**
* @brief Destroy the debug messenger
*/
void destroy_debug_messenger();
/// Vulkan instance
VkInstance m_vk_instance = nullptr;
/// List of all physical devices
physical_device::s_list m_physical_devices;
/// Debug configuration
debug_config m_debug;
/// Instance information
instance_info m_info;
/// Debug utils messenger
VkDebugUtilsMessengerEXT m_debug_messenger = VK_NULL_HANDLE;
};
/**
* @brief Check instance create parameters
* @param param Create parameters
* @return Check was successful or failed
*/
bool check(instance::create_param::ref param);
/**
* @brief Get the instance version
* @return sem_version Version
*/
sem_version get_instance_version();
/**
* @brief Enumerate enabled layer properties
* @return VkLayerPropertiesList List of layer properties
*/
VkLayerPropertiesList enumerate_layer_properties();
/**
* @brief Enumerate enabled extension properties
* @param layer_name Name of layer
* @return VkExtensionPropertiesList List of extension properties
*/
VkExtensionPropertiesList enumerate_extension_properties(name layer_name = nullptr);
} // namespace lava