Repository navigation
Expand file tree
/
Copy pathbase.hpp
More file actions
258 lines (190 loc) · 6.65 KB
/
Copy pathbase.hpp
File metadata and controls
258 lines (190 loc) · 6.65 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/**
* @file liblava/base/base.hpp
* @brief Vulkan base types
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/core/version.hpp"
#include "liblava/util/math.hpp"
// clang-format off
#define VK_NO_PROTOTYPES
#include "vulkan/vulkan.h"
#include "volk.h"
// clang-format on
namespace lava {
/// Vulkan version
using VkVersion = ui32;
/// Vulkan object handle
using VkObjectHandle = ui64;
/// List of Vulkan formats
using VkFormats = std::vector<VkFormat>;
/// List of Vulkan images
using VkImages = std::vector<VkImage>;
/// Reference to list of Vulkan images
using VkImagesRef = VkImages const&;
/// List of Vulkan images views
using VkImageViews = std::vector<VkImageView>;
/// List of Vulkan frame buffers
using VkFramebuffers = std::vector<VkFramebuffer>;
/// List of Vulkan command pools
using VkCommandPools = std::vector<VkCommandPool>;
/// List of Vulkan command buffers
using VkCommandBuffers = std::vector<VkCommandBuffer>;
/// List of Vulkan fences
using VkFences = std::vector<VkFence>;
/// List of Vulkan semaphores
using VkSemaphores = std::vector<VkSemaphore>;
/// List of Vulkan present modes
using VkPresentModeKHRs = std::vector<VkPresentModeKHR>;
/// List of Vulkan descriptor sets
using VkDescriptorSets = std::vector<VkDescriptorSet>;
/// List of Vulkan descriptor set layouts
using VkDescriptorSetLayouts = std::vector<VkDescriptorSetLayout>;
/// List of Vulkan descriptor set layout bindings
using VkDescriptorSetLayoutBindings = std::vector<VkDescriptorSetLayoutBinding>;
/// List of Vulkan descriptor pool sizes
using VkDescriptorPoolSizes = std::vector<VkDescriptorPoolSize>;
/// Reference to a list of Vulkan descritpr pool sizes
using VkDescriptorPoolSizesRef = VkDescriptorPoolSizes const&;
/// List of Vulkan push constant ranges
using VkPushConstantRanges = std::vector<VkPushConstantRange>;
/// List of Vulkan attachment references
using VkAttachmentReferences = std::vector<VkAttachmentReference>;
/// List of Vulkan clear values
using VkClearValues = std::vector<VkClearValue>;
/// List of Vulkan pipeline shader stage create infos
using VkPipelineShaderStageCreateInfos = std::vector<VkPipelineShaderStageCreateInfo>;
/// List of Vulkan specialization map entries
using VkSpecializationMapEntries = std::vector<VkSpecializationMapEntry>;
/// List of Vulkan vertex input binding descriptions
using VkVertexInputBindingDescriptions = std::vector<VkVertexInputBindingDescription>;
/// List of Vulkan vertex input attribute descriptions
using VkVertexInputAttributeDescriptions = std::vector<VkVertexInputAttributeDescription>;
/// List of Vulkan pipeline color blend attachment states
using VkPipelineColorBlendAttachmentStates = std::vector<VkPipelineColorBlendAttachmentState>;
/// List of Vulkan pipeline stage flags
using VkPipelineStageFlagsList = std::vector<VkPipelineStageFlags>;
/// List of Vulkan dynamic states
using VkDynamicStates = std::vector<VkDynamicState>;
/// List of Vulkan queue family properties
using VkQueueFamilyPropertiesList = std::vector<VkQueueFamilyProperties>;
/// List of Vulkan extension properties
using VkExtensionPropertiesList = std::vector<VkExtensionProperties>;
/// List of Vulkan layer properties
using VkLayerPropertiesList = std::vector<VkLayerProperties>;
/// List of Vulkan extension properties
using VkExtensionPropertiesList = std::vector<VkExtensionProperties>;
/// List of Vulkan physical devices
using VkPhysicalDevices = std::vector<VkPhysicalDevice>;
/**
* @brief Check a Vulkan result
* @param result Result to check
* @return Okay or error
*/
bool check(VkResult result);
/**
* @brief Check if a Vulkan result failed
* @param result Result to check
* @return Error or okay
*/
inline bool failed(VkResult result) {
return !check(result);
}
/**
* @brief Convert a Vulkan result to string
* @param result Result to convert
* @return string String of result
*/
string to_string(VkResult result);
/**
* @brief Convert a Vulkan version to string
* @param version Version to convert
* @return string String of version
*/
string vk_version_to_string(VkVersion version);
/**
* @brief Convert a Vulkan version to semantic version
* @param version Vulkan version to convert
* @return sem_version Converted semantic version
*/
sem_version to_version(VkVersion version);
/**
* @brief Convert a semantic version to Vulkan version
* @param version Semantic version to convert
* @return VkVersion Converted Vulkan version
*/
VkVersion to_vk_version(sem_version version);
/**
* @brief Vulkan API versions
*/
enum class api_version : index {
v1_0 = 0,
v1_1,
v1_2,
v1_3
};
/**
* @brief Convert a Vulkan version to API version
* @param version Vulkan version to convert
* @return api_version Converted API version
*/
api_version to_api_version(VkVersion version);
/**
* @brief Vulkan result
*/
struct vk_result {
/// State of result
bool state = false;
/// Value of result
VkResult value = VK_NOT_READY;
/**
* @brief Check result
* @return Okay or error
*/
operator bool() {
return state;
}
};
/// Build failed
constexpr bool const build_failed = false;
/// Build done
constexpr bool const build_done = true;
/// List of Vulkan attachments (image views)
using VkAttachments = std::vector<VkImageViews>;
/// Reference of Vulkan attachments (image views)
using VkAttachmentsRef = VkAttachments const&;
/**
* @brief Target callback
*/
struct target_callback {
/// Const pointer to target callback
using c_ptr = target_callback const*;
/// List of target callbacks
using list = std::vector<target_callback*>;
/// Const list of target callbacks
using c_list = std::vector<c_ptr>;
/// Created function
using created_func = std::function<bool(VkAttachmentsRef, rect::ref)>;
/// Called on target created
created_func on_created;
/// Destroy function
using destroyed_func = std::function<void()>;
/// Called on target destroyed
destroyed_func on_destroyed;
};
/// Limit of Vulkan description sets
constexpr ui32 const Vk_Limit_DescriptorSets = 4;
/// Limit of Vulkan bindings
constexpr ui32 const Vk_Limit_Bindings = 16;
/// Limit of Vulkan attachments
constexpr ui32 const Vk_Limit_Attachments = 8;
/// Limit of Vulkan vertex attributes
constexpr ui32 const Vk_Limit_VertexAttribs = 16;
/// Limit of Vulkan vertex buffers
constexpr ui32 const Vk_Limit_VertexBuffers = 4;
/// Limit of Vulkan push constant size
constexpr ui32 const Vk_Limit_PushConstant_Size = 128;
/// Limit of Vulkan UBO size
constexpr ui32 const Vk_Limit_UBO_Size = 16 * 1024;
} // namespace lava