-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathformat.hpp
250 lines (223 loc) · 8.25 KB
/
format.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
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
/**
* @file liblava/resource/format.hpp
* @brief Vulkan format
* @authors Lava Block OÜ and contributors
* @copyright Copyright (c) 2018-present, MIT License
*/
#pragma once
#include "liblava/base/device.hpp"
#include <optional>
namespace lava {
/// Optional format
using VkFormat_optional = std::optional<VkFormat>;
/**
* @brief Check if format is depth compatible
* @param format Format to check
* @return Format is depth compatible or not
*/
bool format_depth(VkFormat format);
/**
* @brief Check if format is stencil compatible
* @param format Format to check
* @return Format is stencil compatible or not
*/
bool format_stencil(VkFormat format);
/**
* @brief Check if format is depth or stencil compatible
* @param format Format to check
* @return Format is depth or stencil compatible or not
*/
bool format_depth_stencil(VkFormat format);
/**
* @brief Check if format is sRGB compatible
* @param format Format to check
* @return Format is sRGB compatible or not
*/
bool format_srgb(VkFormat format);
/**
* @brief Check if format has BGR order
* @param format Format to check
* @return Format has BGR order or not
*/
bool format_bgr(VkFormat format);
/**
* @brief Get image aspect mask of format
* @param format Target format
* @return VkImageAspectFlags Image aspect flags
*/
VkImageAspectFlags format_aspect_mask(VkFormat format);
/**
* @brief Get block dimension of format
* @param format Target format
* @param width Block width
* @param height Block height
*/
void format_block_dim(VkFormat format,
ui32& width,
ui32& height);
/**
* @brief Get align dimension of format
* @param format Target format
* @param width Align width
* @param height Align height
*/
void format_align_dim(VkFormat format,
ui32& width,
ui32& height);
/**
* @brief Get format number of blocks
* @param format Target format
* @param width Number blocks width
* @param height Number blocks height
*/
void format_num_blocks(VkFormat format,
ui32& width,
ui32& height);
/**
* @brief Get format block size
* @param format Target format
* @param aspect Target aspect
* @return ui32 Size of block
*/
ui32 format_block_size(VkFormat format,
VkImageAspectFlags aspect);
/**
* @brief Get format block size (with respective aspect mask)
* @param format Target format
* @return ui32 Size of block
*/
inline ui32 format_block_size(VkFormat format) {
return format_block_size(format, format_aspect_mask(format));
};
/**
* @brief Find the supported depth format
* @param physical_device Physical device
* @return VkFormat_optional Optional format
*/
VkFormat_optional find_supported_depth_format(VkPhysicalDevice physical_device);
/**
* @brief Find the supported format
* @param physical_device Physical device
* @param possible_formats List of possible formats
* @param usage Image usage flags
* @return VkFormat_optional Optional format
*/
VkFormat_optional find_supported_format(VkPhysicalDevice physical_device,
VkFormats const& possible_formats,
VkImageUsageFlags usage);
/**
* @brief Get image memory barrier
* @param image Target image
* @param old_layout Old image layout
* @param new_layout New image layout
* @return VkImageMemoryBarrier Image memory barrier
*/
VkImageMemoryBarrier image_memory_barrier(VkImage image,
VkImageLayout old_layout,
VkImageLayout new_layout);
/**
* @brief Set the image layout
* @param device Vulkan device
* @param cmd_buffer Command buffer
* @param image Target image
* @param old_image_layout Old image layout
* @param new_image_layout New image layout
* @param subresource_range Image subresource range
* @param src_stage_mask Source pipeline stage flags
* @param dst_stage_mask Destination pipeline stage flags
*/
void set_image_layout(device::ptr device,
VkCommandBuffer cmd_buffer,
VkImage image,
VkImageLayout old_image_layout,
VkImageLayout new_image_layout,
VkImageSubresourceRange subresource_range,
VkPipelineStageFlags src_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VkPipelineStageFlags dst_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
/**
* @brief Set the image layout
* @param device Vulkan device
* @param cmd_buffer Command buffer
* @param image Target image
* @param aspect_mask Image aspect flags
* @param old_image_layout Old image layout
* @param new_image_layout New image layout
* @param src_stage_mask Source pipeline stage flags
* @param dst_stage_mask Destination pipeline stage flags
*/
void set_image_layout(device::ptr device,
VkCommandBuffer cmd_buffer,
VkImage image,
VkImageAspectFlags aspect_mask,
VkImageLayout old_image_layout,
VkImageLayout new_image_layout,
VkPipelineStageFlags src_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VkPipelineStageFlags dst_stage_mask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
/**
* @brief Insert image memory barrier
* @param device Vulkan device
* @param cmd_buffer Command buffer
* @param image Target image
* @param src_access_mask Source access mask
* @param dst_access_mask Destination access mask
* @param old_image_layout Old image layout
* @param new_image_layout New image layout
* @param src_stage_mask Source pipeline stage flags
* @param dst_stage_mask Destination pipeline stage flags
* @param subresource_range Image subresource range
*/
void insert_image_memory_barrier(device::ptr device,
VkCommandBuffer cmd_buffer,
VkImage image,
VkAccessFlags src_access_mask,
VkAccessFlags dst_access_mask,
VkImageLayout old_image_layout,
VkImageLayout new_image_layout,
VkPipelineStageFlags src_stage_mask,
VkPipelineStageFlags dst_stage_mask,
VkImageSubresourceRange subresource_range);
/**
* @brief Surface format request
*/
struct surface_format_request {
/// List of formats in request order
VkFormats formats = {
VK_FORMAT_B8G8R8A8_UNORM,
VK_FORMAT_R8G8B8A8_UNORM,
VK_FORMAT_B8G8R8_UNORM,
VK_FORMAT_R8G8B8_UNORM,
VK_FORMAT_B8G8R8A8_SRGB,
VK_FORMAT_R8G8B8A8_SRGB,
VK_FORMAT_B8G8R8_SRGB,
VK_FORMAT_R8G8B8_SRGB,
};
/// Color space to request
VkColorSpaceKHR color_space = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
};
/**
* @brief Find the surface format
* @param device Vulkan device
* @param surface Vulkan surface
* @param request Surface format request
* @return VkSurfaceFormatKHR Chosen surface format
*/
VkSurfaceFormatKHR find_surface_format(VkPhysicalDevice device,
VkSurfaceKHR surface,
surface_format_request request = {});
/**
* @brief Check if format supports bltting
* @param device Vulkan physical device
* @param format Format to check
* @return Blitting is supported or not
*/
bool support_blit(VkPhysicalDevice device,
VkFormat format);
/**
* @brief Check if vertex buffer format is supported
* @param device Vulkan physical device
* @param format Format to check
* @return Format is supported or not
*/
bool support_vertex_buffer_format(VkPhysicalDevice device,
VkFormat format);
} // namespace lava