diff options
| author | 2020-05-27 17:59:04 -0300 | |
|---|---|---|
| committer | 2020-05-27 17:59:04 -0300 | |
| commit | b8b6f94ba9a662857c40d819ac40755c7984cb16 (patch) | |
| tree | 82b2c6097f4f4aff94313e06fd87aef5860908fa /src/video_core/texture_cache | |
| parent | texture_cache: Use small vector for surface vectors (diff) | |
| download | yuzu-b8b6f94ba9a662857c40d819ac40755c7984cb16.tar.gz yuzu-b8b6f94ba9a662857c40d819ac40755c7984cb16.tar.xz yuzu-b8b6f94ba9a662857c40d819ac40755c7984cb16.zip | |
texture_cache: Use unordered_map::find instead of operator[] on hot code
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index d7e42697d..99f74e6c4 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -310,18 +310,20 @@ public: | |||
| 310 | dst_surface.first->MarkAsModified(true, Tick()); | 310 | dst_surface.first->MarkAsModified(true, Tick()); |
| 311 | } | 311 | } |
| 312 | 312 | ||
| 313 | TSurface TryFindFramebufferSurface(VAddr addr) { | 313 | TSurface TryFindFramebufferSurface(VAddr addr) const { |
| 314 | if (!addr) { | 314 | if (!addr) { |
| 315 | return nullptr; | 315 | return nullptr; |
| 316 | } | 316 | } |
| 317 | const VAddr page = addr >> registry_page_bits; | 317 | const VAddr page = addr >> registry_page_bits; |
| 318 | std::vector<TSurface>& list = registry[page]; | 318 | const auto it = registry.find(page); |
| 319 | for (auto& surface : list) { | 319 | if (it == registry.end()) { |
| 320 | if (surface->GetCpuAddr() == addr) { | 320 | return nullptr; |
| 321 | return surface; | ||
| 322 | } | ||
| 323 | } | 321 | } |
| 324 | return nullptr; | 322 | const auto& list = it->second; |
| 323 | const auto found = std::find_if(list.begin(), list.end(), [addr](const auto& surface) { | ||
| 324 | return surface->GetCpuAddr() == addr; | ||
| 325 | }); | ||
| 326 | return found != list.end() ? *found : nullptr; | ||
| 325 | } | 327 | } |
| 326 | 328 | ||
| 327 | u64 Tick() { | 329 | u64 Tick() { |
| @@ -1130,18 +1132,20 @@ private: | |||
| 1130 | return {}; | 1132 | return {}; |
| 1131 | } | 1133 | } |
| 1132 | const VAddr cpu_addr_end = cpu_addr + size; | 1134 | const VAddr cpu_addr_end = cpu_addr + size; |
| 1133 | VAddr start = cpu_addr >> registry_page_bits; | ||
| 1134 | const VAddr end = (cpu_addr_end - 1) >> registry_page_bits; | 1135 | const VAddr end = (cpu_addr_end - 1) >> registry_page_bits; |
| 1135 | VectorSurface surfaces; | 1136 | VectorSurface surfaces; |
| 1136 | while (start <= end) { | 1137 | for (VAddr start = cpu_addr >> registry_page_bits; start <= end; ++start) { |
| 1137 | std::vector<TSurface>& list = registry[start]; | 1138 | const auto it = registry.find(start); |
| 1138 | for (auto& surface : list) { | 1139 | if (it == registry.end()) { |
| 1139 | if (!surface->IsPicked() && surface->Overlaps(cpu_addr, cpu_addr_end)) { | 1140 | continue; |
| 1140 | surface->MarkAsPicked(true); | 1141 | } |
| 1141 | surfaces.push_back(surface); | 1142 | for (auto& surface : it->second) { |
| 1143 | if (surface->IsPicked() || !surface->Overlaps(cpu_addr, cpu_addr_end)) { | ||
| 1144 | continue; | ||
| 1142 | } | 1145 | } |
| 1146 | surface->MarkAsPicked(true); | ||
| 1147 | surfaces.push_back(surface); | ||
| 1143 | } | 1148 | } |
| 1144 | start++; | ||
| 1145 | } | 1149 | } |
| 1146 | for (auto& surface : surfaces) { | 1150 | for (auto& surface : surfaces) { |
| 1147 | surface->MarkAsPicked(false); | 1151 | surface->MarkAsPicked(false); |