| 95 | } |
| 96 | |
| 97 | void ResourceManager::ClearAsyncModelData_() { |
| 98 | static constexpr size_t maxModelBytesPerFrame = 1024 * 1024 * 2; |
| 99 | // First generate GPU data for some of the meshes |
| 100 | size_t totalBytes = 0; |
| 101 | std::vector<MeshPtr> removeFromGpuDataQueue; |
| 102 | for (auto mesh : generateMeshGpuDataQueue_) { |
| 103 | mesh->FinalizeData(); |
| 104 | totalBytes += mesh->GetGpuSizeBytes(); |
| 105 | removeFromGpuDataQueue.push_back(mesh); |
| 106 | if (removeFromGpuDataQueue.size() > 5 || totalBytes >= maxModelBytesPerFrame) break; |
| 107 | //if (totalBytes >= maxModelBytesPerFrame) break; |
| 108 | } |
| 109 | |
| 110 | for (auto mesh : removeFromGpuDataQueue) generateMeshGpuDataQueue_.erase(mesh); |
| 111 | |
| 112 | if (totalBytes > 0) STRATUS_LOG << "Processed " << totalBytes << " bytes of mesh data: " << removeFromGpuDataQueue.size() << " meshes" << std::endl; |
| 113 | |
| 114 | // If none other left to finalize, end early |
| 115 | if (pendingFinalize_.size() == 0) return; |
| 116 | |
| 117 | //constexpr size_t maxBytes = 1024 * 1024 * 10; // 10 mb per frame |
| 118 | std::vector<std::string> toDelete; |
| 119 | for (auto& mpair : pendingFinalize_) { |
| 120 | if (mpair.second.Completed() && !mpair.second.Failed()) { |
| 121 | toDelete.push_back(mpair.first); |
| 122 | auto ptr = mpair.second.GetPtr(); |
| 123 | |
| 124 | ClearAsyncModelData_(ptr); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | for (const std::string& name : toDelete) { |
| 129 | pendingFinalize_.erase(name); |
| 130 | } |
| 131 | |
| 132 | if (meshFinalizeQueue_.size() == 0) return; |
| 133 | |
| 134 | //size_t totalBytes = 0; |
| 135 | std::vector<MeshPtr> meshesToDelete(meshFinalizeQueue_.size()); |
| 136 | size_t idx = 0; |
| 137 | for (auto& mesh : meshFinalizeQueue_) { |
| 138 | meshesToDelete[idx] = mesh; |
| 139 | ++idx; |
| 140 | } |
| 141 | |
| 142 | meshFinalizeQueue_.clear(); |
| 143 | |
| 144 | // for (MeshPtr mesh : _meshFinalizeQueue) { |
| 145 | // mesh->FinalizeData(); |
| 146 | // totalBytes += mesh->GetGpuSizeBytes(); |
| 147 | // meshesToDelete.push_back(mesh); |
| 148 | // //if (totalBytes >= maxBytes) break; |
| 149 | // } |
| 150 | |
| 151 | std::vector<Async<bool>> waiting; |
| 152 | const size_t numThreads = INSTANCE(TaskSystem)->Size(); |
| 153 | for (size_t i = 0; i < numThreads; ++i) { |
| 154 | const size_t threadIndex = i; |
nothing calls this directly
no test coverage detected