| 231 | } |
| 232 | |
| 233 | void VulkanMemoryManager::Deallocate(AllocationPtr ptr) |
| 234 | { |
| 235 | CHECK(ptr, ()); |
| 236 | CHECK(!ptr->m_memoryBlock->m_isBlocked, ()); |
| 237 | auto const resourceIndex = static_cast<size_t>(ptr->m_resourceType); |
| 238 | auto & m = m_memory[resourceIndex]; |
| 239 | auto const it = m.find(ptr->m_blockHash); |
| 240 | CHECK(it != m.end(), ()); |
| 241 | auto blockIt = std::find_if(it->second.begin(), it->second.end(), [&ptr](drape_ptr<MemoryBlock> const & b) |
| 242 | { |
| 243 | ASSERT(ptr->m_memoryBlock != nullptr, ()); |
| 244 | return b->m_memory == ptr->m_memoryBlock->m_memory; |
| 245 | }); |
| 246 | CHECK(blockIt != it->second.end(), ()); |
| 247 | CHECK_GREATER((*blockIt)->m_allocationCounter, 0, ()); |
| 248 | (*blockIt)->m_allocationCounter--; |
| 249 | |
| 250 | if ((*blockIt)->m_allocationCounter == 0) |
| 251 | { |
| 252 | if (m_isInDeallocationSession) |
| 253 | { |
| 254 | // Here we set a bit in the deallocation mask to skip the processing of untouched |
| 255 | // resource collections. |
| 256 | m_deallocationSessionMask |= (1 << resourceIndex); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | drape_ptr<MemoryBlock> memoryBlock = std::move(*blockIt); |
| 261 | it->second.erase(blockIt); |
| 262 | if (m_sizes[resourceIndex] > kDesiredSizeInBytes[resourceIndex]) |
| 263 | { |
| 264 | CHECK_LESS_OR_EQUAL(memoryBlock->m_blockSize, m_sizes[resourceIndex], ()); |
| 265 | m_sizes[resourceIndex] -= memoryBlock->m_blockSize; |
| 266 | DecrementTotalAllocationsCount(); |
| 267 | vkFreeMemory(m_device, memoryBlock->m_memory, nullptr); |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | memoryBlock->m_freeOffset = 0; |
| 272 | auto & fm = m_freeBlocks[resourceIndex]; |
| 273 | fm.push_back(std::move(memoryBlock)); |
| 274 | std::sort(fm.begin(), fm.end(), LessBlockSize()); |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void VulkanMemoryManager::EndDeallocationSession() |
| 281 | { |
no test coverage detected