mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Move profiler call out of hot path in ClientMap (#16056)
This commit is contained in:
parent
6c339c62c6
commit
2c83c67b7d
1 changed files with 25 additions and 2 deletions
|
@ -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
|
* Copy a list of mesh buffers into the draw order, while potentially
|
||||||
* merging some.
|
* merging some.
|
||||||
|
@ -879,7 +900,7 @@ static u32 transformBuffersToDrawOrder(
|
||||||
// try to take from cache
|
// try to take from cache
|
||||||
auto it2 = dynamic_buffers.find(key);
|
auto it2 = dynamic_buffers.find(key);
|
||||||
if (it2 != dynamic_buffers.end()) {
|
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();
|
const auto &use_mat = to_merge.front().second->getMaterial();
|
||||||
assert(!it2->second.buf.empty());
|
assert(!it2->second.buf.empty());
|
||||||
for (auto *buf : it2->second.buf) {
|
for (auto *buf : it2->second.buf) {
|
||||||
|
@ -889,7 +910,7 @@ static u32 transformBuffersToDrawOrder(
|
||||||
}
|
}
|
||||||
it2->second.age = 0;
|
it2->second.age = 0;
|
||||||
} else if (!key.empty()) {
|
} else if (!key.empty()) {
|
||||||
g_profiler->avg("CM::transformBuffersToDO: cache hit rate", 0);
|
buffer_transform_stats.increment(false);
|
||||||
// merge and save to cache
|
// merge and save to cache
|
||||||
auto &put_buffers = dynamic_buffers[key];
|
auto &put_buffers = dynamic_buffers[key];
|
||||||
scene::SMeshBuffer *tmp = nullptr;
|
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);
|
g_profiler->avg(prefix + "merged buffers in cache [#]", cached_count);
|
||||||
|
|
||||||
|
buffer_transform_stats.commit(g_profiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass == scene::ESNRP_TRANSPARENT) {
|
if (pass == scene::ESNRP_TRANSPARENT) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue