]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/synchronizer.h
Redesign asynchronous buffer uploads
[libs/gl.git] / source / backends / vulkan / synchronizer.h
1 #ifndef MSP_GL_VULKAN_SYNCHRONIZER_H_
2 #define MSP_GL_VULKAN_SYNCHRONIZER_H_
3
4 #include <cstdint>
5 #include <vector>
6 #include "handles.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Synchronizer
12 {
13 private:
14         struct ImageAccess
15         {
16                 VkImage image = 0;
17                 unsigned aspect;
18                 int level = -1;
19                 unsigned current_layout;
20                 unsigned pending_layout;
21         };
22
23         struct BufferAccess
24         {
25                 VkBuffer buffer = 0;
26                 std::size_t offset = 0;
27                 std::size_t size = 0;
28                 bool was_written = false;
29                 bool pending_write = false;
30         };
31
32         Device &device;
33         std::vector<BufferAccess> buffer_accesses;
34         std::vector<ImageAccess> image_accesses;
35
36 public:
37         Synchronizer(Device &);
38
39         void write_buffer(VkBuffer, std::size_t, std::size_t, bool = false);
40         void split_image_mipmap(VkImage, unsigned, unsigned);
41         void change_image_layout(VkImage, unsigned, int, unsigned, bool);
42         void reset();
43         void barrier(VkCommandBuffer);
44
45 private:
46         bool is_write_layout(unsigned);
47 };
48
49 } // namespace GL
50 } // namespace Msp
51
52 #endif