]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/commands_backend.h
7c98b15f0d061bbe7ea43bce73e8ae9559c1996a
[libs/gl.git] / source / backends / vulkan / commands_backend.h
1 #ifndef MSP_GL_COMMANDS_BACKEND_H_
2 #define MSP_GL_COMMANDS_BACKEND_H_
3
4 #include <vector>
5 #include "fence.h"
6 #include "handles.h"
7 #include "rect.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Batch;
13 union ClearValue;
14 class Device;
15 class Framebuffer;
16 class PipelineState;
17 class QueryPool;
18 class Semaphore;
19 class SwapChain;
20
21 class VulkanCommands
22 {
23 protected:
24         struct CommandBuffers
25         {
26                 std::vector<VkCommandBuffer> buffers;
27                 unsigned next_buffer = 0;
28         };
29
30         struct CommandPool
31         {
32                 Device &device;
33                 VkCommandPool pool = 0;
34                 CommandBuffers primary;
35                 CommandBuffers secondary;
36                 Fence fence;
37                 bool in_use = false;
38                 
39                 CommandPool(Device &);
40                 CommandPool(CommandPool &&);
41                 ~CommandPool();
42         };
43
44         Device &device;
45         std::vector<CommandPool> command_pools;
46         unsigned frame_index = 0;
47         VkCommandBuffer primary_buffer = 0;
48         VkCommandBuffer pass_buffer = 0;
49         const PipelineState *pipeline_state = 0;
50         const PipelineState *last_pipeline = 0;
51         const Framebuffer *framebuffer = 0;
52         Rect viewport = Rect::max();
53         bool fb_is_swapchain = false;
54         bool discard_fb_contents = false;
55         std::vector<char> pass_begin_info;
56
57         VulkanCommands();
58         ~VulkanCommands();
59
60         void begin_buffer(VkRenderPass);
61         void begin_render_pass(bool, const ClearValue *);
62         void end_render_pass();
63
64         void begin_frame(unsigned);
65         void submit_frame();
66         void submit_frame(Semaphore *, Semaphore *);
67
68         void use_pipeline(const PipelineState *);
69         void clear(const ClearValue *);
70         void draw(const Batch &);
71         void draw_instanced(const Batch &, unsigned);
72         void dispatch(unsigned, unsigned, unsigned);
73         void resolve_multisample(Framebuffer &);
74
75         void begin_query(const QueryPool &, unsigned);
76         void end_query(const QueryPool &, unsigned);
77 };
78
79 using CommandsBackend = VulkanCommands;
80
81 } // namespace GL
82 } // namespace Msp
83
84 #endif
85