-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
229 lines (199 loc) · 6.8 KB
/
Copy pathmain.cpp
File metadata and controls
229 lines (199 loc) · 6.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <vector>
#include <memory>
#include <fstream>
#include <iomanip>
#include <sstream>
#include "Image2d.h"
#include "Renderer/eye_ray.h"
#include "tests/tests.h"
#include "utils/mesh/mesh.h"
#include "benchmark_backend/benchmark_backend.h"
using LiteImage::Image2D;
extern double g_buildTime; // used to get build time from deep underground of code
extern uint64_t g_buildTris; // used to get total tris processed by builder
constexpr bool MEASURE_FRAMES = false;
int main(int argc, const char** argv)
{
if (argc > 1)
{
if (std::string(argv[1]) == "-tests_litert")
{
std::vector<int> test_ids = {};
for (int i=2; i<argc; i++)
test_ids.push_back(std::stoi(argv[i]));
perform_tests_litert(test_ids);
return 0;
}
else if (std::string(argv[1]) == "-intersection_benchmark")
{
benchmark_framed_octree_intersection();
return 0;
}
else if (std::string(argv[1]) == "-benchmark" && argc > 2)
{
std::string mesh_name = argv[2];
std::string supported_type = argc == 3 ? "" : argv[3];
unsigned flags = BENCHMARK_FLAG_RENDER_RT;
if (supported_type == "build")
{
flags = BENCHMARK_FLAG_BUILD;
supported_type = "";
}
main_benchmark("saves/"+mesh_name, mesh_name, flags, supported_type);
return 0;
}
else if (std::string(argv[1]) == "-sbs_benchmark" && argc > 2)
{
std::string mesh_name = argv[2];
unsigned flags = BENCHMARK_FLAG_RENDER_RT;
SBS_benchmark("saves/"+mesh_name, mesh_name, flags);
return 0;
}
else if (std::string(argv[1]) == "-backend_benchmark")
{
if (std::string(argv[2]) == "build")
{
BenchmarkBackend::build_model(argv[3]);
}
else if (std::string(argv[2]) == "render")
{
BenchmarkBackend::getMetrics(argv[3]);
}
return 0;
}
else if (std::string(argv[1]) == "-tests_dr")
{
std::vector<int> test_ids = {};
for (int i=2; i<argc; i++)
test_ids.push_back(std::stoi(argv[i]));
perform_tests_diff_render(test_ids);
return 0;
}
else if (std::string(argv[1]) == "-benchmark_dr")
{
benchmark_dr_optimization();
}
else if (std::string(argv[1]) == "-rtx_benchmark" && argc > 2)
{
std::string mesh_name = argv[2];
std::string supported_type = argc == 3 ? "" : argv[3];
std::string device_str = argc == 4 ? "GPU" : argv[4];
unsigned device = DEVICE_CPU;
if (device_str == "GPU")
device = DEVICE_GPU;
else if (device_str == "GPU_RTX" || device_str == "RTX")
device = DEVICE_GPU_RTX;
unsigned flags = BENCHMARK_FLAG_RENDER_RT;
if (supported_type == "build")
{
flags = BENCHMARK_FLAG_BUILD;
supported_type = "";
}
rtx_benchmark("saves/"+mesh_name, mesh_name, flags, supported_type, device);
return 0;
}
else if (std::string(argv[1]) == "-check_model" && argc > 2)
{
check_model(argv[2]);
return 0;
}
else if(std::string(argv[1]) == "--check-models" && argc > 3)
{
check_models(argv[2], argv[3]);
return 0;
}
}
//auto mesh = cmesh4::LoadMeshFromVSGF((scenes_folder_path+"scenes/01_simple_scenes/data/teapot.vsgf").c_str());
//cmesh4::create_triangle_list_grid(mesh, LiteMath::uint3(32,32,32));
//return 0;
// perform_tests_litert({9});
//benchmark_framed_octree_intersection();
// return 0;
uint32_t WIDTH = 1024;
uint32_t HEIGHT = 1024;
const char* scenePath = "scenes/03_gs_scenes/lego.xml";
const char* accelStruct = "BVH2Common";
const char* buildFormat = "cbvh_embree2";
const char* layout = "SuperTreeletAlignedMerged4"; ///"opt";
const char* outImageFile = "z_out.bmp";
int NUM_LAUNCHES = 1;
Image2D<uint32_t> image(WIDTH, HEIGHT);
std::shared_ptr<IRenderer> pRender = nullptr;
std::cout << "[main]: init renderer ..." << std::endl;
{
pRender = CreateMultiRenderer(DEVICE_GPU);
auto accelStructImpl = CreateSceneRT(accelStruct, buildFormat, layout);
pRender->SetAccelStruct(accelStructImpl);
}
pRender->SetViewport(0,0,WIDTH,HEIGHT);
g_buildTime = 0.0;
bool loaded = false;
std::cout << "[main]: load scene '" << scenePath << "'" << std::endl;
loaded = pRender->LoadScene(scenePath);
std::cout << "Implementation: " << pRender->Name() << "; builder = '" << buildFormat << "'" << std::endl;
MultiRenderPreset preset;
preset.render_mode = MULTI_RENDER_MODE_GS;
dynamic_cast<MultiRenderer*>(pRender.get())->SetPreset(preset);
pRender->CommitDeviceData();
pRender->Clear(WIDTH, HEIGHT, "color");
if(!loaded)
{
std::cout << "can't load scene '" << scenePath << "'" << std::endl;
return -1;
}
// you may update presents if you want, but don't forget to call 'UpdateMembersPlainData' after that
//pImpl->SetPrestes(...);
//pImpl->UpdateMembersPlainData();
float timings[4] = {0,0,0,0};
float timeAvg = 0.0f;
float timeMin = 100000000000000.0f;
std::vector<float> allTimes;
const int NUM_ITERS = MEASURE_FRAMES ? 1 : NUM_LAUNCHES;
const int NUM_FRAMES = MEASURE_FRAMES ? NUM_LAUNCHES : 1;
for(int launchId = 0; launchId < NUM_ITERS; launchId++)
{
std::cout << "[main]: do rendering ..." << std::endl;
pRender->Render(image.data(), WIDTH, HEIGHT, "color", NUM_FRAMES);
std::cout << std::endl;
pRender->GetExecutionTime("CastRaySingleBlock", timings);
std::cout << "CastRaySingleBlock(exec) = " << timings[0] << " ms" << std::endl;
allTimes.push_back(timings[0]);
timeAvg += timings[0];
timeMin = std::min(timeMin, timings[0]);
}
timeAvg /= float(NUM_LAUNCHES);
if(MEASURE_FRAMES)
timeMin = timeAvg;
std::cout << "[main]: save image to file ..." << std::endl;
LiteImage::SaveImage(outImageFile, image);
float summDiffSquare = 0.0f;
for(float time : allTimes)
summDiffSquare += (time - timeAvg)*(time - timeAvg);
float timeErr = std::sqrt(summDiffSquare/float(allTimes.size()-1));
if(MEASURE_FRAMES)
timeErr = 0.0f;
// save stats to file
//
const char* sceneName = "unknown";
std::string scenePathStr = std::string(scenePath);
auto posSlash = scenePathStr.find_last_of('\\');
if (posSlash == std::string::npos)
posSlash = scenePathStr.find_last_of('/');
auto posDot = scenePathStr.find_last_of('.');
std::string scenePathStr2 = scenePathStr.substr(posSlash + 1, posDot - posSlash - 1);
sceneName = scenePathStr2.c_str();
const char* timeFileName = "z_timings.csv";
std::ofstream fout;
std::ifstream fin(timeFileName);
if (!fin.is_open())
{
fout.open(timeFileName);
fout << "Render;Resolution;Scene;TrisNum(build);Build;Accel;Layout;TimeMin(ms);TimeAvg(ms);TimeErr(ms);TimeBuild(ms);MEM(MB);PSNR;Test;" << std::endl;
}
else
{
fin.close();
fout.open(timeFileName, std::ios::app);
}
return 0;
}