-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvkutil.hpp
66 lines (51 loc) · 2 KB
/
vkutil.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
#pragma once
#include <utility>
#include <optional>
#include <glm/glm.hpp>
#include <littlevk/littlevk.hpp>
struct DeviceRenderContext;
std::optional <std::pair <vk::CommandBuffer, littlevk::SurfaceOperation>>
new_frame(DeviceRenderContext &, size_t);
void end_frame(const vk::Queue &, const littlevk::PresentSyncronization &,
const vk::CommandBuffer &, size_t);
void present_frame(DeviceRenderContext &, const littlevk::SurfaceOperation &, size_t);
void render_pass_begin(const DeviceRenderContext &, const vk::CommandBuffer &,
const littlevk::SurfaceOperation &, const glm::vec4 &);
void render_pass_end(const DeviceRenderContext &, const vk::CommandBuffer &);
// Allocate and copy in one step
template <typename T>
littlevk::Image general_allocator(const vk::Device &device,
const vk::PhysicalDeviceMemoryProperties &memory_properties,
const vk::CommandPool &command_pool,
const vk::Queue &graphics_queue,
littlevk::Deallocator &dal,
const std::vector <T> &buffer, vk::Extent2D extent,
const vk::ImageType type = vk::ImageType::e2D,
const vk::Format format = vk::Format::eR32G32B32A32Sfloat)
{
vk::ImageViewType view = (type == vk::ImageType::e2D)
? vk::ImageViewType::e2D
: vk::ImageViewType::e1D;
littlevk::Image texture;
littlevk::Buffer staging;
std::tie(texture, staging) = bind(device, memory_properties, dal)
.image(extent, format,
vk::ImageUsageFlagBits::eSampled
| vk::ImageUsageFlagBits::eTransferDst,
vk::ImageAspectFlagBits::eColor,
type, view)
.buffer(buffer, vk::BufferUsageFlagBits::eTransferSrc);
littlevk::submit_now(device, command_pool, graphics_queue,
[&](const vk::CommandBuffer &cmd) {
littlevk::transition(cmd, texture,
vk::ImageLayout::eUndefined,
vk::ImageLayout::eTransferDstOptimal);
littlevk::copy_buffer_to_image(cmd, texture, staging,
vk::ImageLayout::eTransferDstOptimal);
littlevk::transition(cmd, texture,
vk::ImageLayout::eTransferDstOptimal,
vk::ImageLayout::eShaderReadOnlyOptimal);
}
);
return texture;
};