VPP  0.7
A high-level modern C++ API for Vulkan
vppSynchronization.hpp
1 /*
2  Copyright 2016-2018 SOFT-ERG, Przemek Kuczmierczyk (www.softerg.com)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice,
9  this list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 // -----------------------------------------------------------------------------
28 namespace vpp {
29 // -----------------------------------------------------------------------------
30 
41 class Fence
42 {
43 public:
45  Fence();
46 
51  Fence ( const Device& hDevice, bool bSignaled = false );
52 
54  VkFence handle() const;
55 
57  const Device& device() const;
58 
60  bool isSignaled() const;
61 
63  void reset();
64 
66  static void reset ( std::vector< Fence >* pFences );
67 
76  bool wait ( std::uint64_t timeoutNs = std::numeric_limits< std::uint64_t >::max() ) const;
77 
86  static bool waitAll (
87  std::vector< Fence >* pFences,
88  std::uint64_t timeoutNs = std::numeric_limits< std::uint64_t >::max() );
89 
98  static bool waitOne (
99  std::vector< Fence >* pFences,
100  std::uint64_t timeoutNs = std::numeric_limits< std::uint64_t >::max() );
101 
103  static bool waitAll (
104  const Device& hDevice,
105  std::vector< VkFence >* pFences,
106  std::uint64_t timeoutNs = std::numeric_limits< std::uint64_t >::max() );
107 
109  static bool waitOne (
110  const Device& hDevice,
111  std::vector< VkFence >* pFences,
112  std::uint64_t timeoutNs = std::numeric_limits< std::uint64_t >::max() );
113 };
114 
115 // -----------------------------------------------------------------------------
128 {
129 public:
131  Semaphore();
132 
145  Semaphore ( const Device& hDevice );
146 
148  VkSemaphore handle() const;
149 
151  const Device& device() const;
152 };
153 
154 // -----------------------------------------------------------------------------
161 class Event
162 {
163 public:
165  Event ( const Device& hDevice );
166 
168  VkEvent handle() const;
169 
171  const Device& device() const;
172 
174  void signal ( bool bSignal );
175 
177  bool isSignaled() const;
178 
190  void cmdSignal (
191  bool bSignal,
192  VkPipelineStageFlags stageMask,
193  CommandBuffer hCommandBuffer = CommandBuffer() );
194 
218  void cmdWait (
219  VkPipelineStageFlags srcStageMask,
220  VkPipelineStageFlags dstStageMask,
221  CommandBuffer hCommandBuffer = CommandBuffer() );
222 
243  void cmdWait (
244  VkPipelineStageFlags srcStageMask,
245  VkPipelineStageFlags dstStageMask,
246  const Barriers& barriers,
247  CommandBuffer hCommandBuffer = CommandBuffer() );
248 };
249 
250 // -----------------------------------------------------------------------------
251 } // namespace vpp
252 // -----------------------------------------------------------------------------
Represents logical rendering device.
Definition: vppDevice.hpp:49
Fence()
Constructs null reference.
const Device & device() const
Retrieves the device.
void cmdWait(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, CommandBuffer hCommandBuffer=CommandBuffer())
Generates a command to wait for signaled event state.
The VPP namespace.
Definition: main.hpp:1
const Device & device() const
Retrieves the device.
Represents a sequence of Vulkan commands.
Definition: vppCommandBuffer.hpp:68
const Device & device() const
Retrieves the device.
VkFence handle() const
Retrieves the Vulkan handle.
void cmdSignal(bool bSignal, VkPipelineStageFlags stageMask, CommandBuffer hCommandBuffer=CommandBuffer())
Generates a command to set signaled or unsignaled event state.
Allows the GPU to wait for another GPU operation to finish.
Definition: vppSynchronization.hpp:127
Allows the CPU to wait for GPU operation to finish.
Definition: vppSynchronization.hpp:41
bool isSignaled() const
Checks whether the event is signaled.
Allows the GPU to wait for certain condition on CPU or GPU side to occur.
Definition: vppSynchronization.hpp:161
static bool waitOne(std::vector< Fence > *pFences, std::uint64_t timeoutNs=std::numeric_limits< std::uint64_t >::max())
Waits until one of given fences becomes signaled.
static bool waitAll(std::vector< Fence > *pFences, std::uint64_t timeoutNs=std::numeric_limits< std::uint64_t >::max())
Waits until all given fences become signaled.
bool isSignaled() const
Checks whether the fence is currently in signaled state.
bool wait(std::uint64_t timeoutNs=std::numeric_limits< std::uint64_t >::max()) const
Waits until the fence becomes signaled.
Event(const Device &hDevice)
Constructs null reference.
VkEvent handle() const
Retrieves the Vulkan handle.
void signal(bool bSignal)
Sets the signaled or unsignaled state of the event.
void reset()
Resets the fence to unsignaled state.
Semaphore()
Constructs null reference.
VkSemaphore handle() const
Retrieves the Vulkan handle.