-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
150 lines (126 loc) · 3.4 KB
/
Copy pathmain.cpp
File metadata and controls
150 lines (126 loc) · 3.4 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
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <functional>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <glm/glm.hpp>
#include "PerfFramework.h"
#include "PerfTimer.h"
#include "Voxels.h"
// Techniquess
#include "DisplayLists.h"
#include "Vaos.h"
#include "GeometryShader.h"
#include "QuadGeom.h"
#include "Instanced.h"
#include "CompactDisplayLists.h"
#include "HybridInstanced.h"
#include "SignedDistanceFields.h"
#include "LayerMarching.h"
#include "LayerMarchingCompressed.h"
#include "SdfShape.h"
#include "SdfJump.h"
#include "SdfJumpSphere.h"
using namespace glm;
using namespace std;
typedef PerfRecord(*PerfTestFn)(VoxelSet& model, glm::ivec3 gridSize, glm::vec3 voxelSpacing);
static map<string, PerfTestFn> tests = {
{ "dl", RunDisplayListsTest },
{ "cdl", RunCompactDisplayListsTest },
{ "vao", RunVaosTest },
{ "gs", RunGeometryShaderTest },
{ "qgs", RunQuadGeometryShaderTest },
{ "inst", RunInstancedTest },
{ "hyi", RunHybridInstancedTest },
{ "sdf", RunSdfTest },
{ "sdfs", RunSdfShapeTest },
{ "sdfj", RunSdfJumpTest },
{ "sdfjs", RunSdfJumpSphereTest },
{ "lm", RunLayerMarchingTest },
{ "lmc", RunLayerMarchingCompressedTest },
};
template <typename T>
string Join(T iterable, string delim) {
int count = 0;
string result = "";
for (auto& t : iterable) {
if (count > 0) {
result += delim;
}
result += t;
++count;
}
return result;
}
template <typename T>
string JoinFirst(T iterable, string delim) {
int count = 0;
string result = "";
for (auto& t : iterable) {
if (count > 0) {
result += delim;
}
result += t.first;
++count;
}
return result;
}
void Usage() {
cerr << "VoxelPerf [-t] <" << JoinFirst(tests, "|") << "> <width> <height> <depth>" << endl;
}
extern std::map<string, string> g_commandLineOptions;
int main(int argc, char** argv) {
//map<string, string> options;
vector<string> arguments;
for (int i = 0; i < argc; ++i) {
string arg = argv[i];
if (arg.size() > 0 && arg[0] == '-') {
if (arg.find('=') != string::npos) {
size_t splitIdx = arg.find('=');
string key = arg.substr(1, splitIdx - 1);
string val = arg.substr(splitIdx + 1, arg.size() - splitIdx - 1);
g_commandLineOptions.insert({ key, val });
} else {
g_commandLineOptions.insert({ arg.substr(1, arg.size() - 1), "" });
}
} else {
arguments.push_back(arg);
}
}
if (arguments.size() != 5) {
Usage();
exit(EXIT_FAILURE);
}
string testType = arguments[1];
if (!tests.count(testType)) {
Usage();
exit(EXIT_FAILURE);
}
int w = atoi(arguments[2].c_str());
int h = atoi(arguments[3].c_str());
int d = atoi(arguments[4].c_str());
if (w <= 0 || h <= 0 || d <= 0) {
Usage();
exit(EXIT_FAILURE);
}
VoxelSet model({ 32,32,32 });
if (IsOptionSet("t")) {
// Make a trivial example
model.At({31, 31, 31}) = vec4(0.8f, 0.6f, 0.2f, 1);
} else {
model.MakeSphere();
}
ivec3 voxelGrid(w, h, d);
vec3 voxelSpacing(32, 32, 32);
voxelSpacing *= VOXEL_SIZE;
int numObjects = voxelGrid.x * voxelGrid.y * voxelGrid.z;
PerfRecord record = tests[testType](model, voxelGrid, voxelSpacing);
cout << testType << ", " << numObjects << ", " << record.averageFrameTimeMs << ", " << record.gpuMemUsed << ", " << record.mainMemUsed << endl;
exit(EXIT_SUCCESS);
}