vsg  1.1.0
VulkanSceneGraph library
Event.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2020 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/commands/PipelineBarrier.h>
16 
17 namespace vsg
18 {
19 
21  class VSG_DECLSPEC Event : public Inherit<Object, Event>
22  {
23  public:
24  explicit Event(Device* device, VkEventCreateFlags flags = 0);
25 
26  operator VkEvent() const { return _event; }
27  VkEvent vk() const { return _event; }
28 
30  void set();
31 
33  void reset();
34 
36  VkResult status();
37 
38  protected:
39  virtual ~Event();
40 
41  VkEvent _event;
42  ref_ptr<Device> _device;
43  };
44  VSG_type_name(vsg::Event);
45 
46  using Events = std::vector<ref_ptr<Event>>;
47 
49  class VSG_DECLSPEC SetEvent : public Inherit<Command, SetEvent>
50  {
51  public:
52  SetEvent(ref_ptr<Event> in_event, VkPipelineStageFlags in_stageMask);
53 
54  ref_ptr<Event> event;
55  VkPipelineStageFlags stageMask;
56 
57  void record(CommandBuffer& commandBuffer) const override;
58 
59  protected:
60  virtual ~SetEvent();
61  };
62  VSG_type_name(vsg::SetEvent);
63 
65  class VSG_DECLSPEC ResetEvent : public Inherit<Command, ResetEvent>
66  {
67  public:
68  ResetEvent(ref_ptr<Event> in_event, VkPipelineStageFlags in_stageMask);
69 
70  ref_ptr<Event> event;
71  VkPipelineStageFlags stageMask;
72 
73  void record(CommandBuffer& commandBuffer) const override;
74 
75  protected:
76  virtual ~ResetEvent();
77  };
78  VSG_type_name(vsg::ResetEvent);
79 
81  class VSG_DECLSPEC WaitEvents : public Inherit<Command, WaitEvents>
82  {
83  public:
84  WaitEvents();
85 
86  template<typename... Args>
87  WaitEvents(VkPipelineStageFlags in_srcStageMask, VkPipelineStageFlags in_destStageMask, Args&&... args) :
88  srcStageMask(in_srcStageMask),
89  dstStageMask(in_destStageMask)
90  {
91  (add(args), ...);
92  }
93 
94  void record(CommandBuffer& commandBuffer) const override;
95 
96  void add(ref_ptr<Event> event) { events.emplace_back(event); }
97  void add(ref_ptr<MemoryBarrier> mb) { memoryBarriers.emplace_back(mb); }
98  void add(ref_ptr<BufferMemoryBarrier> bmb) { bufferMemoryBarriers.emplace_back(bmb); }
99  void add(ref_ptr<ImageMemoryBarrier> imb) { imageMemoryBarriers.emplace_back(imb); }
100 
101  VkPipelineStageFlags srcStageMask;
102  VkPipelineStageFlags dstStageMask;
103 
104  Events events;
105  MemoryBarriers memoryBarriers;
106  BufferMemoryBarriers bufferMemoryBarriers;
107  ImageMemoryBarriers imageMemoryBarriers;
108 
109  protected:
110  virtual ~WaitEvents();
111  };
112  VSG_type_name(vsg::WaitEvents);
113 
114 } // namespace vsg
CommandBuffer encapsulates VkCommandBuffer.
Definition: CommandBuffer.h:27
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
Encapsulation of VkEvent.
Definition: Event.h:22
void set()
set the state of the vkEvent to signaled
void reset()
set the state of the vkEvent to unsignalled.
VkResult status()
get the status of the vkEvent, return VK_EVENT_SET for a signaled event, VK_EVENT_RESET for unsignall...
Definition: Inherit.h:28
Command class encapsulating vkCmdResetEvent.
Definition: Event.h:66
Command class encapsulating vkCmdSetEvent.
Definition: Event.h:50
Command class encapsulating vkCmdWaitEvents.
Definition: Event.h:82
Definition: ref_ptr.h:22