]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/commands_backend.h
Reuse previously allocated command buffers
[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
8 namespace Msp {
9 namespace GL {
10
11 class Batch;
12 union ClearValue;
13 class Device;
14 class Framebuffer;
15 class PipelineState;
16 class QueryPool;
17 struct Rect;
18 class Semaphore;
19 class SwapChain;
20
21 class VulkanCommands
22 {
23 protected:
24         struct CommandPool
25         {
26                 Device &device;
27                 VkCommandPool pool = 0;
28                 std::vector<VkCommandBuffer> buffers;
29                 unsigned next_buffer = 0;
30                 Fence fence;
31                 bool in_use = false;
32                 
33                 CommandPool(Device &);
34                 CommandPool(CommandPool &&);
35                 ~CommandPool();
36         };
37
38         Device &device;
39         std::vector<CommandPool> command_pools;
40         CommandPool *current_pool = 0;
41         VkCommandBuffer current_buffer = 0;
42         const PipelineState *pipeline_state = 0;
43         const Framebuffer *framebuffer = 0;
44         const Rect *viewport = 0;
45
46         VulkanCommands();
47         ~VulkanCommands();
48
49         void begin_buffer();
50         void begin_render_pass(bool, const ClearValue *);
51         void end_render_pass();
52
53         void begin_frame(unsigned);
54         void submit_frame();
55         void submit_frame(Semaphore *, Semaphore *);
56
57         void use_pipeline(const PipelineState *);
58         void clear(const ClearValue *);
59         void draw(const Batch &);
60         void draw_instanced(const Batch &, unsigned);
61         void resolve_multisample(Framebuffer &);
62
63         void begin_query(const QueryPool &, unsigned);
64         void end_query(const QueryPool &, unsigned);
65 };
66
67 using CommandsBackend = VulkanCommands;
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif
73