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
|
#include "resources/image.h"
#include "vulkan_helper.h"
#include <vulkan/vulkan_core.h>
namespace iris {
VkImageView Image_tt::get_image_view(const ImageViewDesc &desc) {
auto it = image_views.find(desc);
if (it != image_views.end()) {
return it->second;
}
// Not found, create the image view
VkImageViewCreateInfo view_create_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.image = handle,
.viewType = desc.view_type,
.format = desc.format,
.components = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
.g = VK_COMPONENT_SWIZZLE_IDENTITY,
.b = VK_COMPONENT_SWIZZLE_IDENTITY,
.a = VK_COMPONENT_SWIZZLE_IDENTITY,
},
.subresourceRange = {
.aspectMask = desc.aspect_mask,
.baseMipLevel = desc.base_mip_level,
.levelCount = desc.mip_levels,
.baseArrayLayer = desc.base_array_layer,
.layerCount = desc.array_layers,
},
};
VkImageView view;
CHECK_VULKAN(vkCreateImageView(
device,
&view_create_info,
nullptr,
&view));
image_views[desc] = view;
return view;
}
} // namespace iris
|