| 147 | */ |
| 148 | template <vkb::BindingType bindingType> |
| 149 | class BufferBlock |
| 150 | { |
| 151 | public: |
| 152 | using BufferUsageFlagsType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferUsageFlags, VkBufferUsageFlags>::type; |
| 153 | using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type; |
| 154 | |
| 155 | public: |
| 156 | BufferBlock() = delete; |
| 157 | BufferBlock(BufferBlock const &rhs) = delete; |
| 158 | BufferBlock(BufferBlock &&rhs) = default; |
| 159 | BufferBlock &operator=(BufferBlock const &rhs) = delete; |
| 160 | BufferBlock &operator=(BufferBlock &&rhs) = default; |
| 161 | |
| 162 | BufferBlock(vkb::core::Device<bindingType> &device, DeviceSizeType size, BufferUsageFlagsType usage, VmaMemoryUsage memory_usage); |
| 163 | |
| 164 | /** |
| 165 | * @return An usable view on a portion of the underlying buffer |
| 166 | */ |
| 167 | BufferAllocation<bindingType> allocate(DeviceSizeType size); |
| 168 | |
| 169 | /** |
| 170 | * @brief check if this BufferBlock can allocate a given amount of memory |
| 171 | * @param size the number of bytes to check |
| 172 | * @return \c true if \a size bytes can be allocated from this \c BufferBlock, otherwise \c false. |
| 173 | */ |
| 174 | bool can_allocate(DeviceSizeType size) const; |
| 175 | |
| 176 | DeviceSizeType get_size() const; |
| 177 | void reset(); |
| 178 | |
| 179 | private: |
| 180 | /** |
| 181 | * @ brief Determine the current aligned offset. |
| 182 | * @return The current aligned offset. |
| 183 | */ |
| 184 | vk::DeviceSize aligned_offset() const; |
| 185 | vk::DeviceSize determine_alignment(vk::BufferUsageFlags usage, vk::PhysicalDeviceLimits const &limits) const; |
| 186 | |
| 187 | private: |
| 188 | vkb::core::BufferCpp buffer; |
| 189 | vk::DeviceSize alignment = 0; // Memory alignment, it may change according to the usage |
| 190 | vk::DeviceSize offset = 0; // Current offset, it increases on every allocation |
| 191 | }; |
| 192 | |
| 193 | using BufferBlockC = BufferBlock<vkb::BindingType::C>; |
| 194 | using BufferBlockCpp = BufferBlock<vkb::BindingType::Cpp>; |
nothing calls this directly
no outgoing calls
no test coverage detected