diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index 5098818ec..aad5c700d 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -805,6 +805,27 @@ void MeshBufListMaps::addFromBlock(v3s16 block_pos, MapBlockMesh *block_mesh, } } +namespace { + // there is no convenient scope this would fit, so it's global + struct { + u32 total = 0, cache_miss = 0; + + inline void increment(bool hit) + { + total++; + cache_miss += hit ? 0 : 1; + } + inline void commit(Profiler *profiler) + { + if (total == 0) + return; + float rate = (total - cache_miss) / (float)total; + profiler->avg("CM::transformBuffers...: cache hit rate [%]", 100 * rate); + *this = {0, 0}; + } + } buffer_transform_stats; +} + /** * Copy a list of mesh buffers into the draw order, while potentially * merging some. @@ -879,7 +900,7 @@ static u32 transformBuffersToDrawOrder( // try to take from cache auto it2 = dynamic_buffers.find(key); if (it2 != dynamic_buffers.end()) { - g_profiler->avg("CM::transformBuffersToDO: cache hit rate", 1); + buffer_transform_stats.increment(true); const auto &use_mat = to_merge.front().second->getMaterial(); assert(!it2->second.buf.empty()); for (auto *buf : it2->second.buf) { @@ -889,7 +910,7 @@ static u32 transformBuffersToDrawOrder( } it2->second.age = 0; } else if (!key.empty()) { - g_profiler->avg("CM::transformBuffersToDO: cache hit rate", 0); + buffer_transform_stats.increment(false); // merge and save to cache auto &put_buffers = dynamic_buffers[key]; scene::SMeshBuffer *tmp = nullptr; @@ -1114,6 +1135,8 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) } } g_profiler->avg(prefix + "merged buffers in cache [#]", cached_count); + + buffer_transform_stats.commit(g_profiler); } if (pass == scene::ESNRP_TRANSPARENT) {