| 223 | |
| 224 | template <vkb::BindingType bindingType> |
| 225 | inline vkb::BufferAllocationCpp RenderFrame<bindingType>::allocate_buffer_impl(vk::BufferUsageFlags usage, vk::DeviceSize size, size_t thread_index) |
| 226 | { |
| 227 | // Find a pool for this usage |
| 228 | auto buffer_pool_it = buffer_pools.find(usage); |
| 229 | if (buffer_pool_it == buffer_pools.end()) |
| 230 | { |
| 231 | LOGE("No buffer pool for buffer usage {} ", vk::to_string(usage)); |
| 232 | return vkb::BufferAllocationCpp{}; |
| 233 | } |
| 234 | |
| 235 | assert(thread_index < buffer_pool_it->second.size()); |
| 236 | auto &buffer_pool = buffer_pool_it->second[thread_index].first; |
| 237 | auto &buffer_block = buffer_pool_it->second[thread_index].second; |
| 238 | |
| 239 | bool want_minimal_block = (buffer_allocation_strategy == BufferAllocationStrategy::OneAllocationPerBuffer); |
| 240 | |
| 241 | if (want_minimal_block || !buffer_block || !buffer_block->can_allocate(size)) |
| 242 | { |
| 243 | // If we are creating a buffer for each allocation of there is no block associated with the pool or the current block is too small |
| 244 | // for this allocation, request a new buffer block |
| 245 | buffer_block = &buffer_pool.request_buffer_block(size, want_minimal_block); |
| 246 | } |
| 247 | |
| 248 | return buffer_block->allocate(to_u32(size)); |
| 249 | } |
| 250 | |
| 251 | template <vkb::BindingType bindingType> |
| 252 | inline void RenderFrame<bindingType>::clear_descriptors() |