Skip to content

Commit

Permalink
shaders: move tuc stats timer to tuc
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Aug 30, 2023
1 parent 4ad81e6 commit f528908
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
14 changes: 1 addition & 13 deletions editor/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "rotation.inl"
#include "src/RTree-search.hpp"

#include <chrono>
#include <Magnum/Math/Color.h>
#include <Magnum/Math/Vector3.h>
#include <Magnum/GL/Renderer.h>
Expand Down Expand Up @@ -195,18 +194,7 @@ void app::draw()
draw_ui();
render_menu();

using namespace std::chrono_literals;
{
constexpr auto print_every = 4s;

static auto t0 = std::chrono::high_resolution_clock::now();
auto t = std::chrono::high_resolution_clock::now();
if (t - t0 >= print_every)
{
t0 = t;
M->texture_unit_cache().output_stats();
}
}
M->texture_unit_cache().output_stats();
}

clickable* app::find_clickable_scenery(const Optional<Vector2i>& pixel)
Expand Down
31 changes: 20 additions & 11 deletions shaders/texture-unit-cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "compat/assert.hpp"
#include <cstdio>
#include <chrono>
#include <Corrade/Containers/String.h>
#include <Magnum/GL/Texture.h>

Expand Down Expand Up @@ -94,18 +95,26 @@ void texture_unit_cache::unlock(size_t i, bool reuse_immediately)

void texture_unit_cache::output_stats()
{
auto total = cache_hit_count + cache_miss_count;
#if 0
using namespace std::literals;
auto total = cache_hit_count + cache_miss_count;

if (total > 0)
{
[[maybe_unused]] auto ratio = (double)cache_hit_count/(double)(cache_hit_count+cache_miss_count);
//printf("texture-binding: hit rate %.2f%% (%zu binds total)\n", ratio*100, (size_t)total); std::fflush(stdout);
}
if (total > (size_t)10'000)
{
cache_hit_count /= 5;
cache_miss_count /= 5;
}
static auto t0 = std::chrono::high_resolution_clock::now();
auto t = std::chrono::high_resolution_clock::now();

if (t - t0 > 5s) [[unlikely]]
{
t0 = t;
[[maybe_unused]] auto ratio = (double)cache_hit_count/(double)(cache_hit_count+cache_miss_count);
printf("texture-binding: hit rate %.2f%% (%zu binds total)\n", ratio*100, total);
std::fflush(stdout);
}
if (total > (size_t)1e4)
{
cache_hit_count /= 9;
cache_miss_count /= 9;
}
#endif
}

size_t texture_unit_cache::get_unit_count()
Expand Down

0 comments on commit f528908

Please sign in to comment.