forked from PixarAnimationStudios/OpenSubdiv
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwasmtime_runner.cpp
More file actions
133 lines (111 loc) · 4.44 KB
/
Copy pathwasmtime_runner.cpp
File metadata and controls
133 lines (111 loc) · 4.44 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
#include "opensubdiv/far/topologyDescriptor.h"
#include "opensubdiv/far/primvarRefiner.h"
#include <cstdio>
#include <chrono>
#include <vector>
// Simple vertex implementation
struct Vertex {
Vertex() { }
Vertex(Vertex const & src) {
_position[0] = src._position[0];
_position[1] = src._position[1];
_position[2] = src._position[2];
}
void Clear( void * =0 ) {
_position[0]=_position[1]=_position[2]=0.0f;
}
void AddWithWeight(Vertex const & src, float weight) {
_position[0]+=weight*src._position[0];
_position[1]+=weight*src._position[1];
_position[2]+=weight*src._position[2];
}
void SetPosition(float x, float y, float z) {
_position[0]=x;
_position[1]=y;
_position[2]=z;
}
const float * GetPosition() const {
return _position;
}
private:
float _position[3];
};
// Cube mesh data
static float g_verts[8][3] = {{ -0.5f, -0.5f, 0.5f },
{ 0.5f, -0.5f, 0.5f },
{ -0.5f, 0.5f, 0.5f },
{ 0.5f, 0.5f, 0.5f },
{ -0.5f, 0.5f, -0.5f },
{ 0.5f, 0.5f, -0.5f },
{ -0.5f, -0.5f, -0.5f },
{ 0.5f, -0.5f, -0.5f }};
static int g_nverts = 8, g_nfaces = 6;
static int g_vertsperface[6] = { 4, 4, 4, 4, 4, 4 };
static int g_vertIndices[24] = { 0, 1, 3, 2,
2, 3, 5, 4,
4, 5, 7, 6,
6, 7, 1, 0,
1, 7, 5, 3,
6, 0, 2, 4 };
using namespace OpenSubdiv;
int main() {
printf("OpenSubdiv Wasmtime Benchmark\n");
printf("==============================\n\n");
// Detect build type based on compilation flags
#ifdef __wasm_simd128__
printf("Build Type: CPU-SIMD (WebAssembly SIMD128)\n");
#else
printf("Build Type: CPU-Basic\n");
#endif
printf("\nRunning subdivision benchmark...\n");
// Create topology descriptor
typedef Far::TopologyDescriptor Descriptor;
Sdc::SchemeType type = Sdc::SCHEME_CATMARK;
Sdc::Options options;
options.SetVtxBoundaryInterpolation(Sdc::Options::VTX_BOUNDARY_EDGE_ONLY);
Descriptor desc;
desc.numVertices = g_nverts;
desc.numFaces = g_nfaces;
desc.numVertsPerFace = g_vertsperface;
desc.vertIndicesPerFace = g_vertIndices;
// Run multiple iterations for timing
const int iterations = 1000;
auto start = std::chrono::high_resolution_clock::now();
for (int iter = 0; iter < iterations; ++iter) {
// Create topology refiner
Far::TopologyRefiner * refiner = Far::TopologyRefinerFactory<Descriptor>::Create(desc,
Far::TopologyRefinerFactory<Descriptor>::Options(type, options));
// Refine the topology
int maxLevel = 3;
refiner->RefineUniform(Far::TopologyRefiner::UniformOptions(maxLevel));
// Allocate vertex buffer
std::vector<Vertex> vertices(refiner->GetNumVerticesTotal());
// Initialize coarse vertices
Vertex * verts = &vertices[0];
for (int i=0; i<g_nverts; ++i) {
verts[i].SetPosition(g_verts[i][0], g_verts[i][1], g_verts[i][2]);
}
// Perform subdivision
Far::PrimvarRefiner primvarRefiner(*refiner);
Vertex * src = verts;
for (int level = 1; level <= maxLevel; ++level) {
Vertex * dst = src + refiner->GetLevel(level-1).GetNumVertices();
primvarRefiner.Interpolate(level, src, dst);
src = dst;
}
delete refiner;
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = end - start;
printf("\nResults:\n");
printf("--------\n");
printf("Iterations: %d\n", iterations);
printf("Total time: %.2f ms\n", elapsed.count());
printf("Average time per iteration: %.4f ms\n", elapsed.count() / iterations);
printf("Subdivisions per second: %.0f\n", (iterations * 1000.0) / elapsed.count());
// Final mesh stats from last iteration
printf("\nFinal Mesh Stats (Level 3):\n");
printf("Base mesh: 8 vertices, 6 faces\n");
printf("Refined mesh: ~386 vertices, ~384 faces\n");
return 0;
}