VPP  0.8
A high-level modern C++ API for Vulkan
vppCommandBuffer.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 
69 {
70 public:
72  CommandBuffer();
73 
75  CommandBuffer ( VkCommandBuffer hBuffer );
76 
78  VkCommandBuffer handle() const;
79 
81  operator bool () const;
82 
84  VkResult reset();
85 
91  VkResult release();
92 
93  enum EBeginFlags
94  {
95  ONE_TIME_SUBMIT = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
96  RENDER_PASS_CONTINUE = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT,
97  SIMULTANEOUS_USE = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
98  };
99 
105  VkResult begin ( std::uint32_t flags = 0 );
106 
111  VkResult end();
112 };
113 
114 // -----------------------------------------------------------------------------
115 // -----------------------------------------------------------------------------
116 
118 {
119 public:
120  inline RenderingCommandContext ( VkCommandBuffer commandBufferHandle ) :
121  d_commandBufferHandle ( commandBufferHandle ),
122  d_pPrevContext ( s_pThis )
123  {
124  s_pThis = this;
125  }
126 
127  inline ~RenderingCommandContext()
128  {
129  s_pThis = d_pPrevContext;
130  }
131 
132  static inline VkCommandBuffer getCommandBufferHandle()
133  {
134  if ( ! s_pThis )
135  throw XUsageError (
136  "Invalid command call in non-rendering context. "
137  "Perhaps you forgot to specify command buffer explicitly." );
138 
139  return s_pThis->d_commandBufferHandle;
140  }
141 
142 private:
143  static thread_local RenderingCommandContext* s_pThis;
144  VkCommandBuffer d_commandBufferHandle;
145  RenderingCommandContext* d_pPrevContext;
146 };
147 
148 // -----------------------------------------------------------------------------
149 } // namespace vpp
150 // -----------------------------------------------------------------------------
151 
152 #endif // INC_VPPCOMMANDBUFFER_HPP
VkResult release()
Frees individual command buffer.
VkResult end()
Ends command recording for this buffer.
The VPP namespace.
Definition: main.hpp:1
VkResult begin(std::uint32_t flags=0)
Sets the buffer in the recording state.
Represents a sequence of Vulkan commands.
Definition: vppCommandBuffer.hpp:68
VkCommandBuffer handle() const
Retrieves the Vulkan handle.
Definition: vppCommandBuffer.hpp:117
CommandBuffer()
Constructs a null, invalid command buffer.
VkResult reset()
Resets the state of individual command buffer for reusing.