Skip to content

Commit 5e8e16b

Browse files
committed
implot for fps
1 parent 5ba12b0 commit 5e8e16b

File tree

14 files changed

+11569
-10
lines changed

14 files changed

+11569
-10
lines changed

Diff for: src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
#include "imgui_impl_glut.h"
6060
#include "imgui_impl_opengl3.h"
61+
#include "util/implot.h"
6162

6263
StopWatchInterface *timer = NULL;
6364
unsigned int width, height;
@@ -321,6 +322,7 @@ void initGL(int argc, char **argv) {
321322
ImGui::CreateContext();
322323
ImGuiIO &io = ImGui::GetIO();
323324
(void) io;
325+
ImPlot::CreateContext();
324326

325327
io.DisplaySize.x = width;
326328
io.DisplaySize.y = height;

Diff for: src/render/draw_caller/rasterizer.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ void Rasterizer::async_rasterize(DrawCallArgs &args, int model_index, Image imag
102102
{
103103
auto &model_args = args.models[model_index];
104104
auto &model = model_args.model;
105-
auto n_grid = model.n_faces / 32 + 1;
106-
auto n_block = dim3(32);
105+
auto n_grid = get_grid_size(model.n_faces);
106+
auto n_block = get_block_size(model.n_faces);
107107

108108
if (model_args.disabled_faces == nullptr) {
109109
switch (model.shader) {

Diff for: src/render/logger/logger.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@
33
//
44
#include "logger.h"
55
#include "../../scene/scene.h"
6+
#include "../../util/const.h"
7+
#include "../../util/implot.h"
68
#include <imgui.h>
79
#include <imgui_internal.h>
10+
#include <filesystem>
811

912
void RenderInterface::draw_widget() {
13+
14+
1015
if (ImGui::CollapsingHeader("FPS"))
1116
{
17+
ImGui::SliderInt("Threads per block", &USE_THREADS, 1, 128);
1218
ImGui::Text("FPS: %f", fps.back());
1319
ImGui::PlotLines("Framerate", &fps[0], fps.size(), 0, nullptr, 0.0f, 100.0f, ImVec2(300, 100));
20+
21+
if (ImGui::Button("Clear average fps"))
22+
{
23+
fps.clear();
24+
}
25+
if (ImGui::Button("Clear average fps per nthreads"))
26+
{
27+
avg_fps_per_nthreads.clear();
28+
}
29+
avg_fps_per_nthreads.display("FPS per nthreads");
1430
}
1531

1632
if (ImGui::CollapsingHeader("Culling")) {
@@ -45,6 +61,7 @@ void RenderInterface::log_fps() {
4561
if (fps.size() > 100) {
4662
fps.erase(fps.begin());
4763
}
64+
avg_fps_per_nthreads.log(USE_THREADS, ImGui::GetIO().Framerate);
4865
}
4966
void RenderInterface::log_before_culling(int n_models) {
5067
n_models_before_culling = n_models;
@@ -68,3 +85,55 @@ bool RenderInterface::is_virtual_geometry_enabled() const {
6885
void RenderInterface::register_vgeometry_manager(VirtualGeometryManager &manager) {
6986
threshold_ptr = &manager.get_threshold_mut();
7087
}
88+
89+
RenderInterface::RenderInterface() {
90+
avg_fps_per_nthreads.log_to("logs/avg_fps_per_nthreads.csv");
91+
}
92+
93+
void AverageLogger::log(float key, float value) {
94+
if (sum.find(key) == sum.end()) {
95+
sum[key] = 0;
96+
count[key] = 0;
97+
}
98+
sum[key] += value;
99+
count[key]++;
100+
file << std::to_string(key) + "," + std::to_string(value) + "\n";
101+
if (count[key] % 100 == 0) {
102+
file << std::flush;
103+
}
104+
}
105+
106+
float AverageLogger::get_average(float key) {
107+
return sum[key] / count[key];
108+
}
109+
110+
void AverageLogger::display(const std::string &title)
111+
{
112+
sorted.clear();
113+
for (auto &p : sum) {
114+
sorted.push_back({p.first, p.second / count[p.first]});
115+
}
116+
std::sort(sorted.begin(), sorted.end(), [](const auto &a, const auto &b) {
117+
return a.first > b.first;
118+
});
119+
120+
keys.clear();
121+
values.clear();
122+
for (auto &p : sorted) {
123+
keys.push_back(p.first);
124+
values.push_back(p.second);
125+
}
126+
127+
if (ImPlot::BeginPlot(title.data())) {
128+
ImPlot::SetupAxes("x","f(x)");
129+
ImPlot::PlotLine("sin(x)", (float *)keys.data(), values.data(), sorted.size());
130+
ImPlot::EndPlot();
131+
}
132+
133+
134+
}
135+
void AverageLogger::clear() {
136+
sum.clear();
137+
count.clear();
138+
std::filesystem::resize_file(filename, 0);
139+
}

Diff for: src/render/logger/logger.h

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@
66
#define COURSE_RENDERER_LOGGER_H
77
#include "../virtual_geometry/manager/virtual_geometry_manger.h"
88
#include <vector>
9+
#include <fstream>
10+
11+
class AverageLogger {
12+
private:
13+
std::ofstream file{};
14+
std::string filename{};
15+
std::map<float, float> sum{};
16+
std::map<float, int> count{};
17+
18+
std::vector<float> keys;
19+
std::vector<float> values;
20+
std::vector<std::pair<float, float>> sorted;
21+
public:
22+
23+
void log_to(const std::string &filename_) {
24+
filename = filename_;
25+
file.open(filename_);
26+
}
27+
28+
void log(float key, float value);
29+
30+
float get_average(float key);
31+
32+
void display(const std::string &title);
33+
34+
void clear();
35+
};
36+
937

1038
class RenderInterface {
1139
protected:
@@ -16,8 +44,10 @@ class RenderInterface {
1644
int n_models_before_culling;
1745
int n_models_after_culling;
1846
int *threshold_ptr = nullptr;
47+
AverageLogger avg_fps_per_nthreads{};
1948

2049
public:
50+
RenderInterface();
2151
bool is_culling_enabled() const;
2252
bool is_virtual_geometry_enabled() const;
2353
void register_vgeometry_manager(VirtualGeometryManager &manager);

Diff for: src/render/virtual_geometry/analyzer/mesh_analyzer.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ void MeshAnalyzer::async_analyze_mesh(const DrawCallArgs &args, const Image &ima
5858
return;
5959
auto &model_args = *model_args_it;
6060
auto &model = model_args.model;
61-
auto n_grid = model.n_faces / 32 + 1;
62-
auto n_block = dim3(32);
61+
auto n_grid = get_grid_size(model.n_faces);
62+
auto n_block = get_block_size(model.n_faces);
6363

6464
if (model.n_faces > capacity) {
6565
capacity = model.n_faces;

Diff for: src/render/virtual_geometry/geometry_upsampler/geometry_upsampler.cu

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44

55
#include "../../../shader/all.h"
6+
#include "../../../util/const.h"
67
#include "../../misc/image.cuh"
78
#include "geometry_upsampler.h"
89

@@ -92,8 +93,8 @@ __global__ void upsample_faces(ModelRef virtual_model, const ModelDrawCallArgs m
9293

9394
void GeometryUpsampler::async_upsample_geometry(const ModelDrawCallArgs &model_args, bool *disabled_faces_for_original, bool *disabled_faces_for_virtual) {
9495
auto &model = model_args.model;
95-
auto n_grid = model.n_faces / 32 + 1;
96-
auto n_block = dim3(32);
96+
auto n_grid = get_grid_size(model.n_faces);
97+
auto n_block = get_block_size(model.n_faces);
9798

9899
cudaMemsetAsync(position, 0, sizeof(int), stream);
99100
cudaMemsetAsync(disabled_faces_for_virtual, 1, sizeof(bool) * virtual_model.n_faces, stream);

Diff for: src/render/zbuffer/zfiller.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ __global__ void set_kernel(ZBuffer buffer, float set_to)
8282
void ZFiller::async_zbuf(DrawCallArgs &args, int model_index) {
8383
auto &model_args = args.models[model_index];
8484
auto &model = model_args.model;
85-
auto n_grid = model.n_faces / 32 + 1;
86-
auto n_block = 32;
85+
auto n_grid = get_grid_size(model.n_faces);
86+
auto n_block = get_block_size(model.n_faces);
8787
switch (model.shader)
8888
{
8989
case RegisteredShaders::Default:

Diff for: src/util/const.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Created by dev on 10/31/22.
3+
//
4+
5+
#include "const.h"
6+
7+
int USE_THREADS = 32;
8+
9+
int get_grid_size(int n)
10+
{
11+
return (n / USE_THREADS) + 1;
12+
}
13+
14+
int get_block_size(int n)
15+
{
16+
return USE_THREADS;
17+
}

Diff for: src/util/const.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
const int MAX_PIXELS_PER_KERNEL = 5000;
99

10-
const int VIRTUAL_GEOMETRY_VERTICES = 10000;
11-
const int VIRTUAL_GEOMETRY_FACES = 100000;
10+
const int VIRTUAL_GEOMETRY_VERTICES = 1000;
11+
12+
extern int USE_THREADS;
13+
14+
int get_grid_size(int n);
15+
16+
int get_block_size(int n);
1217

1318
#endif//COURSE_RENDERER_CONST_H

0 commit comments

Comments
 (0)