-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.cpp
132 lines (119 loc) · 5.28 KB
/
App.cpp
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
#include <cmath>
#include <iostream>
#include <numeric>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <taichi/cpp/taichi.hpp>
#include <limits>
#define RGBA8 4
constexpr int WIDTH = 512;
constexpr int HEIGHT = 512;
constexpr float DEPTH_VALUE = 1e29;
#ifdef __APPLE__
constexpr TiArch RUNTIME_ARCH = TI_ARCH_METAL;
#else
constexpr TiArch RUNTIME_ARCH = TI_ARCH_VULKAN;
#endif
struct MeshyApp {
// This is different from what used in python script since compiled shaders are compatible with
// dynamic ndarray shape
void run_merge_sdf() {
ti::Runtime runtime(TI_ARCH_VULKAN);
ti::AotModule sdf_module = runtime.load_aot_module("assets/sdf.tcm");
ti::Kernel merge_sdf_init = sdf_module.get_kernel("_merge_sdf_initialize");
ti::Kernel merge_sdf = sdf_module.get_kernel("_merge_sdf");
ti::Kernel merge_sdf_finalize = sdf_module.get_kernel("_merge_sdf_finalize");
std::vector<uint32_t> size_vec{64, 64, 64};
ti::NdArray<float> itm_signed_distance =
runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> signed_distance = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> out_signed_distance =
runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> itm_weight = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> weight = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> out_weight = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> itm_color = runtime.allocate_ndarray<float>(size_vec, {4}, true);
ti::NdArray<uint8_t> color = runtime.allocate_ndarray<uint8_t>(size_vec, {4}, true);
ti::NdArray<float> out_color = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> itm_sphere = runtime.allocate_ndarray<float>({2}, {3}, true);
ti::NdArray<float> sphere = runtime.allocate_ndarray<float>({2}, {3}, true);
merge_sdf_init.clear_args();
merge_sdf_init.push_arg(itm_signed_distance);
merge_sdf_init.push_arg(itm_weight);
merge_sdf_init.push_arg(itm_color);
merge_sdf_init.launch();
runtime.wait();
merge_sdf.clear_args();
merge_sdf.push_arg(itm_signed_distance);
merge_sdf.push_arg(itm_weight);
merge_sdf.push_arg(itm_color);
merge_sdf.push_arg(signed_distance);
merge_sdf.push_arg(weight);
merge_sdf.push_arg(color);
merge_sdf.push_arg(itm_sphere);
merge_sdf.push_arg(sphere);
merge_sdf.launch();
runtime.wait();
merge_sdf_finalize.clear_args();
merge_sdf_finalize.push_arg(out_signed_distance);
merge_sdf_finalize.push_arg(out_weight);
merge_sdf_finalize.push_arg(out_color);
merge_sdf_finalize.push_arg(itm_signed_distance);
merge_sdf_finalize.push_arg(itm_weight);
merge_sdf_finalize.push_arg(itm_color);
merge_sdf_finalize.launch();
runtime.wait();
}
void run_merge_sdf_simplify() {
ti::Runtime runtime(TI_ARCH_VULKAN);
ti::AotModule sdf_module = runtime.load_aot_module("assets/sdf.tcm");
ti::Kernel merge_sdf_init = sdf_module.get_kernel("_merge_sdf_initialize");
ti::Kernel merge_sdf = sdf_module.get_kernel("_merge_sdf");
ti::Kernel merge_sdf_finalize = sdf_module.get_kernel("_merge_sdf_finalize");
std::vector<uint32_t> size_vec{64, 64, 64};
ti::NdArray<float> itm_signed_distance =
runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> itm_weight = runtime.allocate_ndarray<float>(size_vec, {1}, true);
ti::NdArray<float> itm_color = runtime.allocate_ndarray<float>(size_vec, {4}, true);
ti::NdArray<uint8_t> color = runtime.allocate_ndarray<uint8_t>(size_vec, {4}, true);
ti::NdArray<float> sphere = runtime.allocate_ndarray<float>({2}, {3}, true);
/* merge_sdf_init.clear_args();
merge_sdf_init.push_arg(itm_signed_distance);
merge_sdf_init.push_arg(itm_weight);
merge_sdf_init.push_arg(itm_color);
merge_sdf_init.launch();
runtime.wait();*/
merge_sdf.clear_args();
merge_sdf.push_arg(itm_signed_distance);
merge_sdf.push_arg(itm_weight);
merge_sdf.push_arg(itm_color);
merge_sdf.push_arg(itm_signed_distance);
merge_sdf.push_arg(itm_weight);
merge_sdf.push_arg(color);
merge_sdf.push_arg(sphere);
merge_sdf.push_arg(sphere);
merge_sdf.launch();
runtime.wait();
/*merge_sdf_finalize.clear_args();
merge_sdf_finalize.push_arg(itm_signed_distance);
merge_sdf_finalize.push_arg(itm_weight);
merge_sdf_finalize.push_arg(color);
merge_sdf_finalize.push_arg(itm_signed_distance);
merge_sdf_finalize.push_arg(itm_weight);
merge_sdf_finalize.push_arg(itm_color);
merge_sdf_finalize.launch();
runtime.wait();*/
}
};
int main(int argc, const char** argv) {
MeshyApp app;
//M3MeshData mesh_data;
/*app.render_hemisphere_front_m3();
app.run_dbg_make_sphere_m3();*/
app.run_merge_sdf_simplify();
std::cout << "after render" << std::endl;
return 0;
}