VPP  0.8
A high-level modern C++ API for Vulkan
vppDeviceMemory.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 
40 {
41 public:
46  {
52  };
53 
57  MemProfile ( ECharacteristic eChar );
58 };
59 
60 // -----------------------------------------------------------------------------
61 // -----------------------------------------------------------------------------
67 {
68 public:
69  DeviceMemory();
70 
71  enum EProperties
72  {
73  DEVICE_LOCAL = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
74  HOST_VISIBLE = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
75  HOST_COHERENT = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
76  HOST_CACHED = VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
77  LAZILY_ALLOCATED = VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT
78  };
79 
80  DeviceMemory (
81  VkDeviceSize size,
82  std::uint32_t typeMask,
83  const MemProfile& memProfile,
84  Device hDevice );
85 
86  VkDeviceMemory handle() const;
87  bool valid() const;
88  std::uint32_t properties() const;
89  VkDeviceSize size() const;
90 
91  bool isHostVisible() const;
92  bool isHostCoherent() const;
93 
94  static size_t availableMemory (
95  const MemProfile& memProfile,
96  Device hDevice );
97 };
98 
99 // -----------------------------------------------------------------------------
105 {
106 public:
108 
110  VkDeviceSize size,
111  std::uint32_t typeMask,
112  const MemProfile& memProfile,
113  Device hDevice );
114 
115  MappableDeviceMemory ( const DeviceMemory& mem );
116 
117  unsigned char* beginMapped() const;
118  unsigned char* endMapped() const;
119 
120  VkResult map ( VkDeviceSize offset = 0, VkDeviceSize size = VK_WHOLE_SIZE );
121  void unmap();
122 
123  void syncFromDevice();
124  void syncToDevice();
125 
126  void load ( const void* pBegin, size_t size );
127 };
128 
129 // -----------------------------------------------------------------------------
136 template< class ResourceT, class MemoryT >
138 {
139 public:
141  MemoryBinding();
142 
144  MemoryBinding (
145  const ResourceT& res,
146  const MemProfile& memProfile );
147 
149  const ResourceT& resource() const;
150 
152  MemoryT& memory();
153 };
154 
155 // -----------------------------------------------------------------------------
165 template< class ResourceT >
167  const ResourceT& res, const MemProfile& memProfile );
168 
169 // -----------------------------------------------------------------------------
179 template< class ResourceT >
181  const ResourceT& res, const MemProfile& memProfile );
182 
183 // -----------------------------------------------------------------------------
184 } // namespace vpp
185 // -----------------------------------------------------------------------------
MemProfile(ECharacteristic eChar)
The constructor - not explicit, you can use the enumeration directly.
Definition: vppDeviceMemory.hpp:66
Represents logical rendering device.
Definition: vppDevice.hpp:49
Definition: vppDeviceMemory.hpp:104
ECharacteristic
Enumeration specifying the characteristic of requested memory.
Definition: vppDeviceMemory.hpp:45
The VPP namespace.
Definition: main.hpp:1
Like HOST_STATIC, but always uncached.
Definition: vppDeviceMemory.hpp:50
Memory resides physically on GPU and is hidden from CPU (but fast).
Definition: vppDeviceMemory.hpp:47
MemoryBinding< ResourceT, DeviceMemory > bindDeviceMemory(const ResourceT &res, const MemProfile &memProfile)
Binds specified buffer to a DeviceMemory memory, and returns MemoryBinding object.
const ResourceT & resource() const
Retrieves the buffer.
A compound object containing references to a buffer and memory bound to it.
Definition: vppDeviceMemory.hpp:137
Memory resides physically on CPU side and is accessible to GPU, likely slower than GPU-local memory...
Definition: vppDeviceMemory.hpp:48
In this context, same as DEVICE_STATIC.
Definition: vppDeviceMemory.hpp:51
Memory resides physically on GPU and is visible to CPU. If that scenario is not supported by the hard...
Definition: vppDeviceMemory.hpp:49
MemoryBinding< ResourceT, MappableDeviceMemory > bindMappableMemory(const ResourceT &res, const MemProfile &memProfile)
Binds specified buffer to a MappableDeviceMemory memory, and returns MemoryBinding object...
MemoryT & memory()
Retrieves the memory object.
Abstraction of GPU-interoperable memory types.
Definition: vppDeviceMemory.hpp:39
MemoryBinding()
Constructs null reference.