VPP  0.8
A high-level modern C++ API for Vulkan
vppBuffer.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 
43 class Buf
44 {
45 public:
51  {
52  SOURCE = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
53  TARGET = VK_BUFFER_USAGE_TRANSFER_DST_BIT,
54  UNITEX = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT,
55  STORTEX = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT,
56  UNIFORM = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
57  STORAGE = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
58  INDEX = VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
59  VERTEX = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
60  INDIRECT = VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
61  };
62 
63  enum ECreationFlags
64  {
65  SPARSE_BINDING = VK_BUFFER_CREATE_SPARSE_BINDING_BIT,
66  SPARSE_RESIDENCY = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT,
67  SPARSE_ALIASED = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT
68  };
69 
71  Buf();
72 
76  Buf (
77  VkDeviceSize bufferSize,
78  unsigned int usageMask,
79  const Device& hDevice,
80  unsigned int flags = 0 );
81 
88  Buf (
89  VkDeviceSize bufferSize,
90  unsigned int usageMask,
91  const Device& hDevice,
92  const std::vector< unsigned int >& queueFamilyIndices,
93  unsigned int flags = 0 );
94 
96  operator bool() const;
97 
99  VkBuffer handle() const;
100 
102  const Device& device() const;
103 
105  VkDeviceSize size() const;
106 
108  unsigned int getUsage() const;
109 
111  template< class MemoryT >
112  MemoryT bindMemory ( const MemProfile& memProfile ) const;
113 };
114 
115 // -----------------------------------------------------------------------------
116 
185 template< unsigned int USAGE >
186 class Buffer : public Buf
187 {
188 public:
189  static const unsigned int usage = USAGE;
190 
192  Buffer();
193 
197  Buffer (
198  VkDeviceSize size,
199  const Device& hDevice,
200  unsigned int flags = 0,
201  unsigned int addUsage = 0 );
202 
209  Buffer (
210  VkDeviceSize size,
211  const Device& hDevice,
212  const std::vector< unsigned int >& queueFamilyIndices,
213  unsigned int flags = 0,
214  unsigned int addUsage = 0 );
215 
219  template< unsigned int USAGE2 >
220  Buffer ( const Buffer< USAGE2 >& other );
221 };
222 
223 // -----------------------------------------------------------------------------
224 
227 
230 
233 
234 // -----------------------------------------------------------------------------
235 } // namespace vpp
236 // -----------------------------------------------------------------------------
EUsageFlags
Buffer usage flags. Can be bitwise-combined to create multipurpose buffers.
Definition: vppBuffer.hpp:50
Buffer< Buf::INDIRECT > IndirectBuffer
Predefined class for indirect buffers, used in indirect draws.
Definition: vppBuffer.hpp:232
Represents logical rendering device.
Definition: vppDevice.hpp:49
Buffer< Buf::INDEX > IndexBuffer
Predefined class for index buffers, used in indexed draws.
Definition: vppBuffer.hpp:226
unsigned int getUsage() const
Retrieves usage flags of the buffer.
Vertex index array for indexed primitives.
Definition: vppBuffer.hpp:58
The VPP namespace.
Definition: main.hpp:1
const Device & device() const
Retrieves the device associated with the buffer.
Buffer()
Constructs null reference.
Vertex attributes array.
Definition: vppBuffer.hpp:59
Read & write formatted data (storage texel buffer).
Definition: vppBuffer.hpp:55
Buf()
Constructs null reference.
VkDeviceSize size() const
Retrieves the size of the buffer.
Buffer holding indirect draw ranges.
Definition: vppBuffer.hpp:60
VkBuffer handle() const
Retrieves Vulkan handle of the buffer.
Buffer< Buf::VERTEX > VertexBuffer
Predefined class for vertex buffers.
Definition: vppBuffer.hpp:229
Generic class representing Vulkan buffers.
Definition: vppBuffer.hpp:43
Read-only formatted data (uniform texel buffer).
Definition: vppBuffer.hpp:54
Source buffer for transfer operations.
Definition: vppBuffer.hpp:52
Read & write array (storage buffer).
Definition: vppBuffer.hpp:57
Read-only common data (uniform buffer).
Definition: vppBuffer.hpp:56
Typed Vulkan buffer of specified purpose. Most functions operating on buffers require typed buffer...
Definition: vppBuffer.hpp:186
Target buffer for transfer operations.
Definition: vppBuffer.hpp:53
MemoryT bindMemory(const MemProfile &memProfile) const
Allocates and binds memory for the buffer.