]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/commands_backend.h
Store simpler states by value in PipelineState
[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 Framebuffer *framebuffer = 0;
51         Rect viewport = Rect::max();
52         bool fb_is_swapchain = false;
53         bool discard_fb_contents = false;
54         std::vector<char> pass_begin_info;
55
56         VulkanCommands();
57         ~VulkanCommands();
58
59         void begin_buffer(VkRenderPass);
60         void begin_render_pass(bool, const ClearValue *);
61         void end_render_pass();
62
63         void begin_frame(unsigned);
64         void submit_frame();
65         void submit_frame(Semaphore *, Semaphore *);
66
67         void use_pipeline(const PipelineState *);
68         void clear(const ClearValue *);
69         void draw(const Batch &);
70         void draw_instanced(const Batch &, unsigned);
71         void resolve_multisample(Framebuffer &);
72
73         void begin_query(const QueryPool &, unsigned);
74         void end_query(const QueryPool &, unsigned);
75 };
76
77 using CommandsBackend = VulkanCommands;
78
79 } // namespace GL
80 } // namespace Msp
81
82 #endif
83