MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / Allocated

Class Allocated

framework/core/allocated.h:124–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122 */
123template <vkb::BindingType bindingType, typename HandleType>
124class Allocated : public vkb::core::VulkanResource<bindingType, HandleType>
125{
126 public:
127 using ParentType = vkb::core::VulkanResource<bindingType, HandleType>;
128
129 using BufferType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Buffer, VkBuffer>::type;
130 using BufferCreateInfoType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferCreateInfo, VkBufferCreateInfo>::type;
131 using DeviceMemoryType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceMemory, VkDeviceMemory>::type;
132 using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
133 using ImageCreateInfoType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::ImageCreateInfo, VkImageCreateInfo>::type;
134 using ImageType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Image, VkImage>::type;
135
136 public:
137 Allocated() = delete;
138 Allocated(const Allocated &) = delete;
139 Allocated(Allocated &&other) noexcept;
140 Allocated &operator=(Allocated const &other) = delete;
141 Allocated &operator=(Allocated &&other) = default;
142
143 protected:
144 /**
145 * @brief The VMA-specific constructor for new objects. This should only be visible to derived classes.
146 * @param allocation_create_info All of the non-resource-specific information needed by the VMA to allocate the memory.
147 * @param args Additional constructor arguments needed for the derived class. Typically a `VkImageCreateInfo` or `VkBufferCreateInfo` struct.
148 */
149 template <typename... Args>
150 Allocated(const VmaAllocationCreateInfo &allocation_create_info, Args &&...args);
151
152 /**
153 * @brief This constructor is used when the handle is already created, and the user wants to wrap it in an `Allocated` object.
154 * @note This constructor is used when the API provides us a pre-existing handle to something we didn't actually allocate, for instance
155 * when we allocate a swapchain and access the images in it. In these cases the `allocation` member variable will remain null for the
156 * lifetime of the wrapper object (which is NOT necessarily the lifetime of the handle) and the wrapper will make no attempt to apply
157 * RAII semantics.
158 */
159 Allocated(HandleType handle, vkb::core::Device<bindingType> *device_ = nullptr);
160
161 public:
162 const HandleType *get() const;
163
164 /**
165 * @brief Flushes memory if it is NOT `HOST_COHERENT` (which also implies `HOST_VISIBLE`).
166 * This is a no-op for `HOST_COHERENT` memory.
167 *
168 * @param offset The offset into the memory to flush. Defaults to 0.
169 * @param size The size of the memory to flush. Defaults to the entire block of memory.
170 */
171 void flush(DeviceSizeType offset = 0, DeviceSizeType size = VK_WHOLE_SIZE);
172
173 /**
174 * @brief Retrieves a pointer to the host visible memory as an unsigned byte array.
175 * @return The pointer to the host visible memory.
176 * @note This performs no checking that the memory is actually mapped, so it's possible to get a nullptr
177 */
178 const uint8_t *get_data() const;
179 /**
180 * @brief Retrieves the raw Vulkan memory object.
181 * @return The Vulkan memory object.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected