Line data Source code
1 : #include "image.hpp"
2 :
3 : namespace wren::vk {
4 :
5 0 : auto Image::create(const ::vk::Device& device, const VmaAllocator& allocator,
6 : const ::vk::Format& format, const math::Vec2f& size,
7 : const ::vk::ImageUsageFlags& usage) -> expected<Image> {
8 0 : Image image;
9 :
10 0 : ::vk::ImageCreateInfo image_info(
11 0 : {}, ::vk::ImageType::e2D, format,
12 0 : ::vk::Extent3D(static_cast<uint32_t>(size.x()),
13 0 : static_cast<uint32_t>(size.y()), 1),
14 : 1, 1);
15 0 : image_info.setUsage(usage);
16 0 : image_info.setSharingMode(::vk::SharingMode::eExclusive);
17 :
18 0 : VmaAllocationCreateInfo alloc_info{};
19 0 : alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
20 0 : auto info = static_cast<VkImageCreateInfo>(image_info);
21 :
22 0 : VkImage tmp_image = nullptr;
23 0 : vmaCreateImage(allocator, &info, &alloc_info, &tmp_image, &image.alloc_,
24 : nullptr);
25 :
26 0 : image.image_ = tmp_image;
27 :
28 0 : return image;
29 : }
30 :
31 : } // namespace wren::vk
|