MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / main

Function main

examples/render/run.cpp:90–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90int main(int argc, char **argv) {
91
92 constexpr size_t NROWS = 32;
93 constexpr size_t NCOLS = 64;
94
95 std::array<float, NROWS * NCOLS> screen;
96
97 struct Params {
98 float focalLength;
99 uint32_t screenWidth;
100 uint32_t screenHeight;
101 float sphereRadius;
102 float sphereCenterX;
103 float sphereCenterY;
104 float sphereCenterZ;
105 uint32_t time;
106 } params = {/* focal length */ 1.0,
107 NCOLS,
108 NROWS,
109 /* radius */ 1.0,
110 /* x */ 0.0,
111 /* y */ 0.0,
112 /* z */ 3.5,
113 0};
114
115 std::fill(begin(screen), end(screen), 0.0f);
116
117 Context ctx = createContext();
118 Tensor devScreen = createTensor(ctx, {NROWS, NCOLS}, kf32, screen.data());
119 uint32_t zeroTime = getCurrentTimeInMilliseconds();
120
121 Shape wgSize = {16, 16, 1};
122 KernelCode code = {kSDF, wgSize};
123 Kernel renderKernel = createKernel(ctx, code, Bindings{devScreen},
124 cdiv({NCOLS, NROWS, 1}, wgSize), params);
125 printf("\033[2J\033[H");
126 while (true) {
127 std::promise<void> promise;
128 std::future<void> future = promise.get_future();
129 dispatchKernel(ctx, renderKernel, promise);
130 wait(ctx, future);
131 toCPU(ctx, devScreen, screen.data(), sizeof(screen));
132 params.time = getCurrentTimeInMilliseconds() - zeroTime;
133
134 toGPU(ctx, params, renderKernel);
135 resetCommandBuffer(ctx.device, renderKernel);
136
137 static const char intensity[] =
138 "@B%8&WM#$Z0OQLCJUYX/"
139 "\\|()1{}I[]?lzcvunxrjft-+~<>i!_;:*\"^`',. ";
140 // static const char intensity[] = "@%#8$X71x*+=-:^~'.` ";
141
142 // Intensity = depth map, focus on depth of the objects
143 float min = 0.0;
144 float max = params.sphereRadius * 3;
145
146 for (size_t i = 0; i < screen.size(); ++i) {
147 screen[i] = (screen[i] - min) / (max - min);

Callers

nothing calls this directly

Calls 10

createContextFunction · 0.85
createTensorFunction · 0.85
createKernelFunction · 0.85
cdivFunction · 0.85
dispatchKernelFunction · 0.85
waitFunction · 0.85
toCPUFunction · 0.85
toGPUFunction · 0.85
resetCommandBufferFunction · 0.85

Tested by

no test coverage detected